[python-win32] Dereferencing lParam pointer
Tim Roberts
timr at probo.com
Thu Feb 25 00:01:45 CET 2010
Ulrich Mierendorff wrote:
>
> I am doing some win32 programming with python and want to modify a
> statusbar of a window. In my code I use
> win32gui.SetWindowLong(statusbar_window, win32con.GWL_WNDPROC,
> mystatusbarproc)
> to set a custom window procedure.
>
> In "def mystatusbarproc(window, message, wParam, lParam)" I wait for
> the commctrl.SB_SETPARTS message:
> http://msdn.microsoft.com/en-us/library/bb760757%28VS.85%29.aspx
>
> The lParam parameter for this message is (according to the
> documentation) a "Pointer to an integer array".
> I thought, python would automatically dereference the pointer for me,
> so that I have a list...
I'm wondering why would you expect that. Python doesn't know anything
about specific window messages. A window message consists of a handle,
a message number, and two integers. The interpretation of those two
integers is entirely dependent on the message number. The wrapper just
hands them off to you for interpretation.
> ...but
> print lParam
> returns values like "1236036" (the type is "int").
> That looks like a memory address to me,
Yes, that's 0x12DC44, which is in the heap.
> but I am not sure. Is there a way to get the array/list?
You will have to use a package like ctypes to do that. Something like this:
lst = ctypes.cast(lParam, ctypes.POINTER(ctypes.c_int))
print lst[0]
print lst[1]
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list