[python-win32] Passing data in a windows message
Thomas Heller
theller at ctypes.org
Wed Dec 10 19:05:55 CET 2008
Tim Golden schrieb:
> I'm using win32gui.PyGetBufferAddressAndLen to pass the address & length
> of a marshalled object as the wparam / lparam of a windows message.
> Something like this:
>
> address, length = \
> win32gui.PyGetBufferAddressAndLen (buffer (marshal.dumps (message)))
I guess that the argument to PyGetBufferAddressAndLen() go out of scope
here, so they may already be invalid BEFORE you call PostMessage.
> PostMessage (self.hwnd, self.WM_PROGRESS_MESSAGE, length, address)
>
> where "message" here is actually a unicode object. At the other end, I'm
> unpacking the message with PyGetString:
>
> message = marshal.loads (win32gui.PyGetString (lparam, wparam))
>
Since you used PostMessage, the message is simply posted to the thread's
message queue. You have no control when it is processed; so I fear you
must keep the posted 'object' alive even longer.
More information about the python-win32
mailing list