Receiving WM_COPYDATA Messages

J

Jochen Hahnen

Hello!

I need to catch some WM_COPYDATA messages sent by an external unmanaged
application. After reading a lot of documentation I tried the following
solution using the MessageWindow class:

public class ReceiveTomTomEvents : MessageWindow
{
const int WM_COPYDATA = 0x004A;
public ReceiveTomTomEvents()
{
}
protected override void WndProc(ref Message msg)
{
switch(msg.Msg)
{
case WM_COPYDATA:
//Do something here
break;
default:
//Do something else
break;
}
// call the base class WndProc for default message handling
base.WndProc(ref msg);
}
}

in my main class I have the following line to instanziate the MessageWindow:

tomtomEvents = new ReceiveTomTomEvents();

My problem is that the case WM_COPYDATA is never riched during debugging
although the documentation of the used dll definitely states that this
type of message is sent ("After the request has been created, a
notification is sent to the external application, in the form of a
Windows WM_COPYDATA message to the main window of the external
application") and I am realy sure that there is such a message!
Instead of this type of messages I receive a lot of messages with code
13(in the default case)!

Is there anything wrong in this code?

By the way the "external application" needs a textfile with some
input-data and there is a field where I have to enter the application
main title. What exactly is meant with application main title? For
example is "Form1" the application main title if the name of my main
window is "Form1"?

Thanks in advance for your efforts!
Jochen
 
A

Alex Feinman [MVP]

Peter Foot said:
The MessageWindow will not receive messages sent to your main application
window. You might be able to access these WM_COPYDATA messages by using
the
But only if WM_COPYDATA is posted, not sent.

Since the notes for your external application mention application name, it
looks like they are looking for your main window by calling FindWindow. In
that case you can P/Invoke SetWindowText on your MessageWindow and set it to
a predefined string, which you will need to specify as the application name.

[DllImport("coredll")]
extern static void SetWindowText(IntPtr hWnd, string szWindowText);
 
J

Jochen Hahnen

Thanks a lot!!! These few lines were everything missing!

Cheers,
Jochen Hahnen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top