win32 problem with WM_COPYDATA

From: Chris (crjensen_at_gmail.com)
Date: 11/27/04


Date: 26 Nov 2004 15:48:12 -0800

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()



Relevant Pages

  • Re: How to receive DHCP issued routes (option 33)
    ... > routes as a DHCP client? ... > should just be receiving them? ... It should recieve them, and use them. ...
    (linux.redhat)
  • Re: Socket receive question
    ... Nope, you maust call Recieve while you get all data, as many times it needs. ... I'm receiving data from another device that sends data in packages of ... But the receive-method sometimes returns after reading 4378 bytes?? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Outlook 2003 send/recieve problem
    ... them fine but will not recieve unless you do it manually or upon exit. ... > Yes, the same problem, but it's not receiving because mail is stuck. ... > afraid of losing my settings... ...
    (microsoft.public.outlook)
  • Problem in getting the content of email
    ... While receiving the messages I become disconnected, ... message when selecting that mail ... I tried several times by clicking send recieve, except that mail, every mail ... Danish Siddiqui ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: find_symdef() returns invalid value.
    ... find_symdef() sometimes returns invalid value in def and a null in ... defobjout. ... This causes any binary to recieve a segmentation fault and ... cores. ...
    (freebsd-hackers)