David Wahler
1/12/2008 5:34:00 AM
On Jan 11, 2008 9:14 PM, Henry Baxter <henry.baxter@gmail.com> wrote:
> Hello,
>
> I have been happily using ctypes for a while to do win32 programming. I use the Microsoft documentation to understand the function, then call it with the help of ctypes.
>
> The problem is that the docs says user32.dll has GetWindowLongPtr, but ctypes can't find it using windll.user32.GetWindowLongPtrA or windll.user32.GetWindowLongPtrW or windll.user32.GetWindowLongPtr. Errors look like this:
>
> Traceback (most recent call last):
> File "Z:\experiments\windowsapp3.py", line 106, in <module>
> GetWindowLongPtr = windll.user32.GetWindowLongPtrA
> File "C:\Python25\lib\ctypes\__init__.py", line 353, in __getattr__
> func = self.__getitem__(name)
> File "C:\Python25\lib\ctypes\__init__.py", line 358, in __getitem__
> func = self._FuncPtr((name_or_ordinal, self))
> AttributeError: function 'GetWindowLongPtrA' not found
>
> I have the same problem with the SetWindowLongPtr function.
>
> I can use plenty of other functions (GetParent, CreateWindowExA, DefWindowProcA, and etc) but not these ones.
>
>
> I don't understand what goes on with ctypes under the hood really, so my troubleshooting abilities at this point are quite lacking! I would appreciate any help you could offer.
>
>
> Thanks!
I don't have a copy of the official Win32 headers handy, but the MinGW
version of winuser.h contains this section of code:
WINUSERAPI LONG WINAPI GetWindowLongA(HWND,int);
WINUSERAPI LONG WINAPI GetWindowLongW(HWND,int);
#ifdef _WIN64
WINUSERAPI LONG_PTR WINAPI GetWindowLongPtrA(HWND,int);
WINUSERAPI LONG_PTR WINAPI GetWindowLongPtrW(HWND,int);
#else
#define GetWindowLongPtrA GetWindowLongA
#define GetWindowLongPtrW GetWindowLongW
#endif
which I would take to mean you need to use GetWindowLong on 32-bit
windows, and GetWindowLongPtr on 64-bit windows.
-- David