help with filling a struct for use in win32api.SendMessage()

Roger Erens r.erens at
Thu Mar 20 13:49:52 CET 2003


I'd like to make an MS windows application show up and present me some data.
I ought to use the windows API-calls FindWindow and SendMessage, but I don't
really know how to create the arguments needed for the latter call.
Could someone give me some directions about how to construct the 'xxx' in
the code fragment below? Should I use something like ctypes or Pyrex?

Thanks in advance,


hApp = win32gui.FindWindow( 'MyApp', None) # this seems to work
if hApp:
  SendMessage(hApp, win32con.WM_COPYDATA, 0, xxx)

This is the (C) documentation I have for MyApp:

obtain the handle:
hV  = FindWindow( "V", NULL );

if hV is not NULL, commands can be sent:
Status = SendMessage( hV, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)pData );
pData = Pointer to a COPYDATASTRUCT, via windows.h defined as:
      typedef struct tagCOPYDATASTRUCT {
                         DWORD dwData;
// Specifies up to 32 bits of data to be passed to the receiving
                         DWORD cbData;
// Specifies the size, in bytes, of the data pointed to by the lpData
                         PVOID lpData;
// Points to data to be passed to the receiving application. This member can
be NULL. 
                     } COPYDATASTRUCT; 

                     dwData is always 0x53445256
                     cbData is minimal sizeof(VRC_HEADER)
                     lpData always points to a VRC_HEADER structure.

typedef struct { DWORD     Magic;
                 DWORD     Command;
                 BYTE      Data[1];      } VRCHEADER

More information about the Python-list mailing list