[python-win32] Passing data in a windows message

Tim Roberts timr at probo.com
Wed Dec 10 19:05:22 CET 2008

Tim Golden wrote:
> 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)))
> PostMessage (self.hwnd, self.WM_PROGRESS_MESSAGE, length, address)
> where "message" here is actually a unicode object.

But, "marshal.dumps" creates a temporary object, "buffer" creates
another temporary to wrap it, but when that statement ends, both
temporary objects no longer have any references, so they will get
garbage collected.  Won't they?  Now, if you had written it this way:

  hold_me = marshal.dumps( message )
  address, length = win32gui.PyGetBufferAddressandLen( buffer(hold_me) )

then I think it would work, because the marshaled buffer still has a

Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

More information about the python-win32 mailing list