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

Simon Brunning SBrunning at
Thu Mar 20 14:04:22 CET 2003

> From:	Roger Erens [SMTP:r.erens at]
> Sent:	Thursday, March 20, 2003 12:50 PM
> To:	python-list at
> Subject:	help with filling a struct for use in win32api.SendMessage()
> Hello,
> 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,
> Roger
> 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
> application. 
>                          DWORD cbData;
> // Specifies the size, in bytes, of the data pointed to by the lpData
> member. 
>                          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 
Uncanny - I was just working on this. Here's an example, getting the text
from an Edit control. Does this help?

import struct
import win32con
import win32gui

def getEditText(hwnd):
    result = []
    bufferlength = struct.pack('i', 255)
    linecount = win32gui.SendMessage(hwnd, win32con.EM_GETLINECOUNT, 0, 0)
    for line in range(linecount):
        linetext = bufferlength + "".ljust(253)
        linelength = win32gui.SendMessage(hwnd, win32con.EM_GETLINE, line,
    return result

Simon Brunning
TriSystems Ltd.
sbrunning at

The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.

More information about the Python-list mailing list