You should not need to do anything special, a hwnd
is not a pointer its a HANDLE and for this type 64 bit Windows guarantees that only the lower 32 bits are significant so they can be freely shared.
Determining the bitness of an IntPtr instance using EnumChildWindows
-
31-05-2022 - |
Question
I posted a similar question here but decided to re-post focusing on part of the question.
I am enumerating windows using EnumWindows and EnumChildWindows on a 64 bit Windows 7 from a 32 bit WinForms application. Here is the declaration:
public delegate int EnumWindowsCallback (System.IntPtr hWnd, System.IntPtr lParam);
[DllImport("user32.Dll")]
public static extern bool EnumWindows (EnumWindowsCallback lpEnumCallbackFunc, IntPtr lParam);
[DllImport("user32")]
public static extern bool EnumChildWindows (IntPtr hWnd, EnumWindowsCallback lpEnumCallbackFunc, IntPtr lParam);
I send [Process.GetProcesses()[i].MainWindowHandle]
as a parameter to [EnumWindows]
to enumerate all child windows of all processes.
When [EnumChildWindows]
is called, the [hWnd]
parameter could be a handle to a window running in a 32 or 64 bit process. Since my app is 32 bit, how can I tell whether to call [hWnd.ToInt32()]
or [hWnd.ToInt64()]
. I need to call one of the two functions to compare one IntPtr to another.
Context: Windows 7 (64 bit), VS 2010, WinForms (32 bit).
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow