I am writing a custom function to enumerate child windows and return a list of window handles. Here is the declaration of the function as per P/Invoke.
[System.Runtime.InteropServices.DllImport("user32.Dll")]
public static extern bool EnumWindows (EnumWindowsCallback lpEnumCallbackFunc, int lParam);
[System.Runtime.InteropServices.DllImport("user32")]
public static extern bool EnumChildWindows (IntPtr hWnd, EnumWindowsCallback lpEnumCallbackFunc, int lParam);
The problem is that I need to be able to pass an Int32 value in one scenario and IntPtr in another scenario.
- If I change the parameter to IntPtr, can I cast an int to it and reliably cast it back to Int32 later?
- If I leave the parameter as Int32, will IntPtr.ToInt32 always work since my own app is 32 bit but the target process is 64 bit (Windows Sidebar)?