communicating different programs

E

Erdem ALKILIÇGiL

hi,
i have an application that uses message maps written in evc++3.0
can i use message window class to see these messages from cf?
Or is there anyway to communicate my application written in CF with
the application written in evc++?
Could you give me any starting point?
regards
 
E

Erdem ALKILIÇGiL

thanks Maarten,
but the MessageWindow does not have a Hwnd property.
Only user can take the handle of the messages(Message.hwnd exists)
How can i find the handle of the messages ?
Maarten Struys said:
If you pass the Window Handle from your MessageWindow to your native app you
can send messages to that handle, resulting in the messages arriving in the
MessageWindow.WndProc function. To pass the handle of your own managed app
you might be able to P/Invoke FindWindow, returning a handle to your
unmanaged app, using MessageWindow.SendMessage and the MessageWindow.Hwnd
property and send that app a WM_USER message containing the managed app's
Window handle. I have not tested this myself, but in theory this should
work.

P/Invoke FindWindow like this (or use the OpenNETCF WinAPI library
http://www.opennetcf.org/winapi.asp):

[DllImport("coredll.dll", EntryPoint="FindWindowW"]

private static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);



--
Regards,

Maarten Struys
PTS Software bv
----
Erdem ALKILIÇGiL said:
hi,
i have an application that uses message maps written in evc++3.0
can i use message window class to see these messages from cf?
Or is there anyway to communicate my application written in CF with
the application written in evc++?
Could you give me any starting point?
regards
 
M

Maarten Struys

I am not sure if I understand you. Let's take a look at this scenario:

I suppose that you derive a class from MessageWindow and bind it to your
main form (the container parameter in the constructor), ok?


public class MyMessageWnd : MessageWindow
{
private const int WM_USER = 0x400;
private const int WM_USER_MY_HNWD = WM_USER + 1;
private const int WM_USER_UNMANAGED_CALLBACK = WM_USER + 1;

private Form1 container;
private IntPtr hWndUnmanaged;
private Message msg;

/// <summary>
/// Constructor of MyMessageWnd. The object stores the "owner" of the
MessageWindow
/// class, to be able to obtain a Windows handle for that particular
owner.
/// </summary>
/// <param name="container">Reference to the class interested in receiving
the Windows messages</param>
public MyMessageWnd(Form1 container)
{
this.container = container;

// perhaps this is not the place to do so, but we are looking for the
unmanaged application here.

hwndUnmanaged = UnmanagedWndAPI.FindWindow("MyUnmanagedClassName",
"MyUnmanagedWindowName");
msg = Message.Create(hwndUnmanaged, WM_USER_MY_HNWD, this.Hwnd,
IntPtr.Zero); // this.Hwnd is our managed window handle, property of
MessageWindow
SendMessage(ref msg); // tell our unmanaged window what handle we
have, so it can send messages back to us.

}

/// <summary>
/// Windows procedure trapping the messages send from unmanaged code
/// </summary>
/// <param name="msg">The actual message that is received</param>
protected override void WndProc(ref Message msg)
{
switch (msg.Msg)
{
case WM_USER_UNMANAGED_CALLBACK :
// Do what you need to do with the message coming from the unmanaged
application.
break;
default:
break;
}
base.WndProc(ref msg);
}
}

public class UnmanagedWndAPI
{
[DllImport("coredll.dll", EntryPoint="FindWindowW")]
public static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);
}


I hope that this little code snippet makes things a little clearer. Just
concentrate on the constructor of MyMessageWindow, that is where I pass our
MessageWindow.Hwnd to the unmanaged application. You would have to find a
suitable place to do so in your own app, although I guess that this code
should work.

--
Regards,

Maarten Struys
PTS Software bv
Erdem ALKILIÇGiL said:
thanks Maarten,
but the MessageWindow does not have a Hwnd property.
Only user can take the handle of the messages(Message.hwnd exists)
How can i find the handle of the messages ?
Maarten Struys said:
If you pass the Window Handle from your MessageWindow to your native app you
can send messages to that handle, resulting in the messages arriving in the
MessageWindow.WndProc function. To pass the handle of your own managed app
you might be able to P/Invoke FindWindow, returning a handle to your
unmanaged app, using MessageWindow.SendMessage and the MessageWindow.Hwnd
property and send that app a WM_USER message containing the managed app's
Window handle. I have not tested this myself, but in theory this should
work.

P/Invoke FindWindow like this (or use the OpenNETCF WinAPI library
http://www.opennetcf.org/winapi.asp):

[DllImport("coredll.dll", EntryPoint="FindWindowW"]

private static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);



--
Regards,

Maarten Struys
PTS Software bv
----
Erdem ALKILIÇGiL said:
hi,
i have an application that uses message maps written in evc++3.0
can i use message window class to see these messages from cf?
Or is there anyway to communicate my application written in CF with
the application written in evc++?
Could you give me any starting point?
regards
 

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