Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Intercept WM_COPYDATA from C++ program to C#

74 views
Skip to first unread message

Peter Foot [MVP]

unread,
Feb 15, 2006, 5:40:34 AM2/15/06
to
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" <Stefan...@discussions.microsoft.com> wrote in message
news:A8B1FF8D-F5C1-4821...@microsoft.com...
> 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


Stefano Magni

unread,
Feb 15, 2006, 5:50:05 AM2/15/06
to
Ok, thanks very much for answer.
but how retrieve the HWND of the MessageWindow instead the main window from
my C++ app ?

Peter Foot [MVP]

unread,
Feb 15, 2006, 6:12:11 AM2/15/06
to
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" <Stefan...@discussions.microsoft.com> wrote in message

news:44237DEA-F14D-4B6B...@microsoft.com...

0 new messages