<p>I was using GetWindowLong like this:</p>

<pre><code>[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
</code></pre>

<p>But according to the MSDN docs I am supposed to be using GetWindowLongPtr to be 64bit compatible.
<a href="http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx</a></p>

<p>The MSDN docs for GetWindowLongPtr say that I should define it like this (in C++):</p>

<pre><code>LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);
</code></pre>

<p>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#:</p>

<pre><code>[DllImport("user32.dll")]
private static extern long GetWindowLong(IntPtr hWnd, int nIndex);
</code></pre>

<p>What is right, and how can I ensure proper 64bit compatibility?</p>

You should define GetWindowLongPtr using an IntPtr.  In C/C++ a LONG_PTR is 32-bits on a 32-bit system and 64-bits on a 64-bit system (see
here
).  IntPtr in C# is designed to work the same way (see
here
).
So what you want is:
```
```
[DllImport("user32.dll")]
private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
```
```