[ctypes-users] How to cast a pointer to an LPARAM?
Brought to you by:
theller
|
From: Roger E. <r....@eu...> - 2003-03-26 13:52:34
|
Any help with the following would be highly appreciated:
How do I translate the following (working) piece of code::
import win32gui, win32api, win32con
import struct, array
VRC_MAGIC = 0x53445256
VRC_SHOW = 1
# vrcshow structure
show = struct.pack('L', 1)
#vrcheader structure for use with vrcshow structure
#the Long in the vrcshow structure was packed into 4 characters
header0 = struct.pack('LL4s', VRC_MAGIC, VRC_SHOW, show)
header1 = array.array('c', header0)
header2 = header1.buffer_info()
#copydata structure for use with vrcshow structure
cd0 = struct.pack('LLP', VRC_MAGIC, header2[1], header2[0])
cd1 = array.array('c', cd0)
cd2 = cd1.buffer_info()
hViridis = win32gui.FindWindow('VIRIDIS_DISPATCHER', None)
if hViridis:
win32api.SendMessage(hViridis, win32con.WM_COPYDATA, 0, cd2[0])
into code that uses ctypes (windows-0.4.1)? I've got this now::
import win32gui, win32api, win32con
from ctypes import *
DWORD = c_ulong
BYTE = c_ubyte
VRC_MAGIC = c_ulong(0x53445256)
VRC_SHOW = c_ulong(1)
class VRCSHOW(Structure):
_fields_ = [("Show", DWORD)]
class VRCHEADER(Structure):
_fields_ = [("Magic", DWORD),
("Command", DWORD),
("Data", VRCSHOW)]
class COPYDATASTRUCT(Structure):
_fields_ = [("dwData", DWORD),
("cbData", DWORD),
("lpData", POINTER(VRCHEADER))]
str_vrcshow = VRCSHOW(VRC_SHOW)
str_vrcheader = VRCHEADER(VRC_MAGIC, VRC_SHOW, str_vrcshow)
data = COPYDATASTRUCT(VRC_MAGIC, DWORD(sizeof(str_vrcheader)),
pointer(str_vrcheader))
hViridis = win32gui.FindWindow('VIRIDIS_DISPATCHER', None)
if hViridis:
win32api.SendMessage(hViridis, win32con.WM_COPYDATA, 0, pointer(data))
but running it gives me a TypeError::
Traceback (most recent call last):
File "Z:\src\py\sc.py", line 31, in ?
win32api.SendMessage(hViridis, win32con.WM_COPYDATA, 0, pointer(data))
TypeError: an integer is required
The doc of viridis_dispatcher tells me to call SendMessage like this::
SendMessage(hViridis, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)pData);
I'm trying to do this translation because as a next step, my VRCHEADER
structure needs to be able to contain various other structures besides
VRCSHOW.
Thanks in advance,
Roger
|