Hi. I'm trying to make a python program that can recieve WM_COPYDATA
messages. Not ideal, but the application I'll be receiving them from
will only send it that way. So I wrote a small program to try to
receive them, and a smaller one to send test messages. It't not
happening for some reason. I'll post both below. The program that
sends the test message finds the receiver ok, and SendMessage returns
0, but the receving program never calls its copydata handler. Any
thoughts? Discalimer: I haven't done windows in years, so am kind of
clueless about it now, but based on what I've seen around google, this
seems ok. Never actually saw an example of someone recieveing
messages though... only sending.
BTW - the try/except thing around UnregisterClass is catching an
invalid handle error for hinst. Not sure where that's coming from,
but it still seems to unregister the class... so I'm happy for now...
at least until I figure out my other issue. Any thougts on this error
are welcome too.
**code**
# Recieving prog
import sys
import win32gui
import win32api
import win32con
class gsWindow:
def __init__(self):
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COPYDATA: self.OnCopyData,
}
wc = win32gui.WNDCLASS()
wc.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
wc.hbrBackground = win32con.COLOR_WINDOW
wc.lpszClassName = "QServer"
wc.lpfnWndProc = message_map
self.hinst = wc.hInstance = win32api.GetModuleHandle(None)
self.cAtom = win32gui.RegisterClass(wc)
print 'hinst: %s' % self.hinst
self.hwnd = win32gui.CreateWindowEx(
win32con.WS_EX_APPWINDOW,
self.cAtom,
"QuoteServer App",
win32con.WS_OVERLAPPED | win32con.WS_SYSMENU,
win32con.CW_USEDEFAULT, 0,
win32con.CW_USEDEFAULT, 0,
0, 0, self.hinst, None)
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWDEFAULT)
win32gui.UpdateWindow(self.hwnd)
def OnCopyData(self, hwnd, msg, wparam, lparam):
print 'copydata(%s, %s, %s, %s)' % (hwnd, msg, wparam, lparam)
def OnDestroy(self, hwnd, msg, wparam, lparam):
win32gui.DestroyWindow(self.hwnd)
try: win32gui.UnregisterClass(self.cAtom, self.hinst)
except: pass
win32gui.PostQuitMessage(0)
def main():
w = gsWindow()
win32gui.PumpMessages()
main()
******
# Sending prog
import struct
import win32con
import win32gui
def main():
wnd = win32gui.FindWindow("QuoteServer", None)
print wnd
result = []
buff = struct.pack('11s', "XXXXX: YYYY")
print win32gui.SendMessage(wnd, win32con.WM_COPYDATA, 0, buff)
return
main() 3 4492
Chris: wc.lpszClassName = "QServer" ... "QuoteServer App", ... wnd = win32gui.FindWindow("QuoteServer", None)
Using the same name helps.
... buff = struct.pack('11s', "XXXXX: YYYY") print win32gui.SendMessage(wnd, win32con.WM_COPYDATA, 0, buff)
Copydata does not take an arbitrary pointer, it requires a correctly
initialized COPYDATASTRUCT. From a Mark Hammond post:
import struct, array
int_buffer = array.array("L", [0])
char_buffer = array.array("c", "the string data")
int_buffer_address = int_buffer.buffer_info()[0]
char_buffer_address, char_buffer_size = char_buffer.buffer_info
copy_struct = struct.pack("pLp", # dword *, dword, char *
int_buffer_address,
char_buffer_size, char_buffer_address)
# find target_hwnd somehow.
win32gui.SendMessage(w, WM_COPYDATA, target_hwnd, copy_struct)
Neil
Yea... I changed it to Qserver while posting, but forgot to do both
spots. But the array and struct thing worked, so its all going now.
Thanks a bunch. Any ideas about the Unregistering error?
"Neil Hodgson" <nh******@bigpond.net.au> wrote in message news:<OL******************@news-server.bigpond.net.au>... Chris:
wc.lpszClassName = "QServer" ... "QuoteServer App", ... wnd = win32gui.FindWindow("QuoteServer", None)
Using the same name helps.
... buff = struct.pack('11s', "XXXXX: YYYY") print win32gui.SendMessage(wnd, win32con.WM_COPYDATA, 0, buff)
Copydata does not take an arbitrary pointer, it requires a correctly initialized COPYDATASTRUCT. From a Mark Hammond post:
import struct, array int_buffer = array.array("L", [0]) char_buffer = array.array("c", "the string data") int_buffer_address = int_buffer.buffer_info()[0] char_buffer_address, char_buffer_size = char_buffer.buffer_info copy_struct = struct.pack("pLp", # dword *, dword, char * int_buffer_address, char_buffer_size, char_buffer_address) # find target_hwnd somehow. win32gui.SendMessage(w, WM_COPYDATA, target_hwnd, copy_struct)
Neil
Chris: Thanks a bunch. Any ideas about the Unregistering error?
Put a trace in the WM_DESTROY handler. You were reentering by calling
DestroyWindow within the WM_DESTROY handler.
Neil This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andy |
last post by:
I am trying to talk to Winamp2 from Perl on Win32 system.
According to winamp docs I need to send a windows message with the
following structure: (To add a file to the playlist)
COPYDATASTRUCT...
|
by: Gordon |
last post by:
Hi
I tried to implement a C++ dll and a Visual Basic .net application, which is able to receive WM_COPYDATA messages from the DLL. Here's my code
DLL
typedef struct _TRANSTA
char teststr...
|
by: James Kunicki |
last post by:
Hi,
I am trying to find if there is a structure in VB.NET that uses
COPDATSTRUCT.
In interfacing to an existing application, the application uses WM_COPYDATA
message
extensively, between...
|
by: **** KiteOregon **** |
last post by:
How do i receive a wm_copydata message from a third party application? I
can't seem to get the data or the message at all in my vb.net application,
what do i need to do.
thanks
--
Just...
|
by: rob |
last post by:
Is there a relatively easy way to send text from a Win32 process to a
..NET process, preferably in VC++ for the Win32 side and C# for .NET.
|
by: Danny |
last post by:
Hi
I want to be able from my csharp button to start an application ( which I
can do) and then somehow send a message to the win32 application that says
"press the button"
The win32...
|
by: Thomas Kehl |
last post by:
Hello.
I use the fallowing Functions to send Message from one Application to
another. This is working correct on a 32bit System. But on a 64Bit System,
the Target-Application will no received...
|
by: xMetalDetectorx |
last post by:
I have two C# Applications. The first application has to send 2 strings to the other application. The first string is just a simple string "abc", while the 2nd string contains a path...
|
by: dantz |
last post by:
Hi everyone, I am trying to combine WM_COPYDATA and Serialization. I am converting an object into string using Serialization then pass that string as the LParam of my COPYDATASTRUCT. I can...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |