It doesn't happen between two XY, but only from a XY to a Python interactive console. I can't repro, with the same strings, even between a custom Python sender script and a custom receiving one.
So I'm a bit
I can't find any visible flaw in the python code, even if I'm not an expert. Also, you Don are faster at solving bugs than the Python community, so if it's an XY bug I've better chances
ADD: this is the python code, put the right hwnd (the hwnd of the XY that will communicate with the script) at line 68. When it starts, it will immediately send its own hwnd to that XY window, so that you can address the messages to the right window.
Code: Select all
import ctypes
import ctypes.wintypes
import win32api
import win32con
import win32gui
class COPYDATASTRUCT_Send(ctypes.Structure):
_fields_ = [
("dwData", ctypes.wintypes.LPARAM),
("cbData", ctypes.wintypes.DWORD),
("lpData", ctypes.c_char_p)
]
class COPYDATASTRUCT_Receive(ctypes.Structure):
_fields_ = [
("dwData", ctypes.wintypes.LPARAM),
("cbData", ctypes.wintypes.DWORD),
("lpData", ctypes.c_wchar_p)
]
def Send(hwnd, content):
content = bytes(str(content), "utf-16le")
cds = COPYDATASTRUCT_Send()
cds.dwData = 0x400000 #as per Help.pdf, page 436
cds.cbData = ctypes.sizeof(ctypes.create_string_buffer(content))
cds.lpData = ctypes.c_char_p(content)
ctypes.windll.user32.SendMessageW(hwnd, win32con.WM_COPYDATA, 0, ctypes.byref(cds))
class Listener:
def __init__(self):
message_map = {
win32con.WM_COPYDATA: self.OnCopyData
}
wc = win32gui.WNDCLASS()
wc.lpfnWndProc = message_map
wc.lpszClassName = "pYreX"
hinst = wc.hInstance = win32api.GetModuleHandle(None)
classAtom = win32gui.RegisterClass(wc)
self.hwnd = win32gui.CreateWindow (
classAtom,
"pYreX",
0,
0,
0,
win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT,
0,
0,
hinst,
None
)
def OnCopyData(self, hwnd, msg, wparam, lparam):
PCOPYDATASTRUCT_Receive = ctypes.POINTER(COPYDATASTRUCT_Receive)
pCDS = ctypes.cast(lparam, PCOPYDATASTRUCT_Receive)
print(ctypes.wstring_at(pCDS.contents.lpData))
l = Listener()
xy_hwnd = 1442884 #sys.argv[1]
Send(xy_hwnd, l.hwnd)
win32gui.PumpMessages()
XYplorer Beta Club