Calling Managed code from Native
This was a question from Zain Ghani of FedEx during the Memphis workshop.
Q: How do you call a managed assembly from native C++? Do you have a sample?
A: There’s no direct convention to do this. We support calling native code *from* managed code, but you can’t just call a managed app directly from C++. Going from managed to native is provided via P/Invoke and COM Wrappers (NETCF 2.0).
That said – there are some creative ways to effectively call a managed app from a native app. One way is to use something like the MessageWindow class. This class basically allows you to pass simple windows messages from native to managed, so you as long as the data is simple, you can pass it that way and send notifications to your NETCF app. You can also use something like a named event -- trap it in the managed app and fire it from native code –or - you could use MSMQ to pass data around. There are also ways to use the COM wrapper you build NETCF 2.0 to use delegates to call back into the managed code. There are a number of ways to creatively get data from a native app into a managed app, but we don’t have a direct way to simply make a direct function call from native to managed. There have also been some 3rd party/community libraries that attempt to do this (e.g. – Mirror, etc.)
http://msdn2.microsoft.com/en-us/library/aa446497.aspx
http://msdn2.microsoft.com/en-us/library/aa446485.aspx
http://samples.gotdotnet.com/quickstart/CompactFramework/doc/messagewindow.aspx
Thanks to Reed Robison from the Mobility Premier group.
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using