Intercept WM_COPYDATA from C++ program to C#

G

Guest

Hi all,
Is it possible intercept WM_COPYDATA that send from a unmanaged application
to managed application ? Compact Framework haven't WndProc event. Is it
possible intercept my WM_COPYDATA througth MessageWindow class ?

Thanks
Stefano
 
P

Peter Foot [MVP]

Yes, so long as your C++ app is sending to the HWND of the MessageWindow,
not the main window of your application.
You create a class which inherits from MessageWindow, override the WndProc
method and add a handler for WM_COPYDATA you can then use the Marshal class
to copy the COPYDATASTRUCT into managed memory and retrieve the raw data
into a byte[] array or other managed structure.

Peter
 
G

Guest

Ok, thanks very much for answer.
but how retrieve the HWND of the MessageWindow instead the main window from
my C++ app ?

Peter Foot said:
Yes, so long as your C++ app is sending to the HWND of the MessageWindow,
not the main window of your application.
You create a class which inherits from MessageWindow, override the WndProc
method and add a handler for WM_COPYDATA you can then use the Marshal class
to copy the COPYDATASTRUCT into managed memory and retrieve the raw data
into a byte[] array or other managed structure.

Peter

--
Peter Foot
Windows Embedded MVP
www.peterfoot.net | www.inthehand.com

Stefano Magni said:
Hi all,
Is it possible intercept WM_COPYDATA that send from a unmanaged
application
to managed application ? Compact Framework haven't WndProc event. Is it
possible intercept my WM_COPYDATA througth MessageWindow class ?

Thanks
Stefano
 
P

Peter Foot [MVP]

That depends on how your C++ app works, if you wrote it you can implement
the exchange in a number of ways for example:-

Use RegisterWindowMessage to register a unique message id for your app and
then have your MessageWindow broadcast this message and include it's own
hwnd in the wparam
Have a native method call which your managed app P/Invokes into and passes
the hwnd
Set a specific name on your MessageWindow and have your native app use
FindWindow to get the hwnd

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net

Stefano Magni said:
Ok, thanks very much for answer.
but how retrieve the HWND of the MessageWindow instead the main window
from
my C++ app ?

Peter Foot said:
Yes, so long as your C++ app is sending to the HWND of the MessageWindow,
not the main window of your application.
You create a class which inherits from MessageWindow, override the
WndProc
method and add a handler for WM_COPYDATA you can then use the Marshal
class
to copy the COPYDATASTRUCT into managed memory and retrieve the raw data
into a byte[] array or other managed structure.

Peter

--
Peter Foot
Windows Embedded MVP
www.peterfoot.net | www.inthehand.com

Stefano Magni said:
Hi all,
Is it possible intercept WM_COPYDATA that send from a unmanaged
application
to managed application ? Compact Framework haven't WndProc event. Is it
possible intercept my WM_COPYDATA througth MessageWindow class ?

Thanks
Stefano
 

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