I have a bit of C# code that looks like this:
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, ref Rect rect);
Rect rect = Rect.Zero;
NativeMethods.GetWindowRect(hWnd, ref rect);
However, when I run this code, the rect
variable is still equal to Rect.Zero
(top/bottom/left/right are all zero), even though GetWindowRect()
returned success. This sequence of function calls works just fine when implemented in C++, but not when called in C# through P/Invoke.
I am certain I am calling GetWindowRect()
properly; that is not the problem. The problem is that GetWindowRect()
is always returning a RECT
of {0,0,0,0}
, no matter how I change the function call or how I define the P/Invoke.