I was using GetWindowLong like this:
[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
But according to the MSDN docs I am supposed to be using GetWindowLongPtr to be 64bit compatible. http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx
The MSDN docs for GetWindowLongPtr say that I should define it like this (in C++):
LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);
I used to be using IntPtr as the return type, but what the heck would I use for an equivalent for LONG_PTR? I have also seen GetWindowLong defined as this in C#:
[DllImport("user32.dll")]
private static extern long GetWindowLong(IntPtr hWnd, int nIndex);
What is right, and how can I ensure proper 64bit compatibility?
Unfortunately it's not that easy, because GetWindowLongPtr doesn't exist in 32bit Windows. On 32bit systems GetWindowLongPtr is just a C macro that points to GetWindowLong. If you really need to use GetWindowLongPtr on both 32 and 64 bit systems you'll have to determine the correct one to call at run time. See the description at pinvoke.net