PyWin SendMessage

g.franzkowiak g.franzkowiak at onlinehome.de
Thu Sep 29 16:04:06 CEST 2005


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


# get the window handle
hwnd = win32ui.FindWindow(None, "special window")

# print just for fun
print hwnd

cds = packCopyData(1, '1')
print cds

# try to send it a message
win32api.SendMessage(hwnd,
                     win32con.WM_COPYDATA,
                     0,
                     cds)

#########################################################################

The last parameter shut be an integer, but I think it must be a pointer ?

Any experience or a tip for me ?


gf



More information about the Python-list mailing list