I am trying to use GetWindowRect or GetWindowPlacement to find the coordinates of a window that I have the handle for, but every time I try to use GetWindowRect, I get this error:
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in testapplication.exe

Additional information: Object reference not set to an instance of an object.
Here is the code I am using:

VB Code:
  1. Dim r As New RECT
  2.     GetWindowRect(hwnd, r)
  3.     MsgBox(r.Left)

hwnd is the window handle, the API calls are all declared public in a module. Here is my converted RECT structure:

VB Code:
  1. Public Structure RECT
  2.         Dim Left As Integer
  3.         Dim Top As Integer
  4.         Dim Right As Integer
  5.         Dim Bottom As Integer
  6.     End Structure

Anyone see why it would give me a null exception error? I know for sure that the window handle is valid because I can use SetForegroundWindow on the same variable and it brings the application to the front of the screen.

Thanks for any help/ideas you can give.