ctypes, GetWindowLongPtr

Henry Baxter henry.baxter at gmail.com
Sat Jan 12 03:49:40 EST 2008


David,

Quick reply :) That pointed me in the right direction. The documentation I
was reading indicated the use of GetWindowLongPtr, but at compile time (if
one were writing C/C++ code) which particular version (Long/64, or 32 bit)
is chosen. That's where I was getting mixed up - thanks!


Henry

On Jan 11, 2008 9:33 PM, David Wahler <dwahler at gmail.com> wrote:

> On Jan 11, 2008 9:14 PM, Henry Baxter <henry.baxter at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080112/358b5a63/attachment-0001.html>


More information about the Python-list mailing list