PyWin SendMessage
Thomas Heller
theller at python.net
Thu Sep 29 11:15:10 EDT 2005
"g.franzkowiak" <g.franzkowiak at onlinehome.de> writes:
> Hello everybody,
>
> I've tryed to use an interprocess communication via
> SendMessage on Windows.
> Unfortunately, nothing goes on
>
> #########################################################################
> #! /usr/bin/env python
>
> import win32api, win32ui, win32con
> import struct, array
>
> """
> typedef struct tagCOPYDATASTRUCT { // cds
> DWORD dwData;
> DWORD cbData;
> PVOID lpData;
> } COPYDATASTRUCT;
> """
>
> def packCopyData(nNum, sString):
> int_buffer = array.array("L",[nNum])
> char_buffer = array.array('c', sString)
> int_buffer_address = int_buffer.buffer_info()[0]
> char_buffer_address = char_buffer.buffer_info()[0]
> char_buffer_size = char_buffer.buffer_info()[1]
> copy_struct = struct.pack("pLp", # dword*, dword, char*
> int_buffer_address,
> char_buffer_size,
> char_buffer)
> return copy_struct
After packCopyData(...) returns, the arrays are destroyed, which will
probably void their contents. You must keep them alive until you don't
need the COPYDATASTRUCT instance any longer. For this kind of stuff,
ctypes may be easier to use than pywin32.
Thomas
More information about the Python-list
mailing list