<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Mobility Touchdown Team Blog : native code</title><link>http://blogs.msdn.com/mobilitytouchdown/archive/tags/native+code/default.aspx</link><description>Tags: native code</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Calling Managed code from Native</title><link>http://blogs.msdn.com/mobilitytouchdown/archive/2007/04/24/calling-managed-code-from-native.aspx</link><pubDate>Wed, 25 Apr 2007 02:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2265715</guid><dc:creator>lokeuei</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mobilitytouchdown/comments/2265715.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mobilitytouchdown/commentrss.aspx?PostID=2265715</wfw:commentRss><description>&lt;P&gt;This was a question from Zain Ghani of FedEx during the Memphis workshop.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;Q: How do you call a managed assembly from native C++? Do you have a sample?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;A:&lt;/STRONG&gt; There’s no direct convention to do this.&amp;nbsp; We support calling native code *from* managed code, but you can’t just call a managed app directly from C++.&amp;nbsp; Going from managed to native is provided via P/Invoke and COM Wrappers (NETCF 2.0).&amp;nbsp; &lt;/P&gt;
&lt;P&gt;That said – there are some creative ways to effectively call a managed app from a native app.&amp;nbsp; One way is to use something like the MessageWindow class.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; There are also ways to use the COM wrapper you build NETCF 2.0 to use delegates to call back into the managed code.&amp;nbsp; 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.&amp;nbsp; There have also been some 3rd party/community libraries that attempt to do this (e.g. – Mirror, etc.)&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/aa446497.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/aa446497.aspx"&gt;http://msdn2.microsoft.com/en-us/library/aa446497.aspx&lt;/A&gt;&lt;BR&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/aa446485.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/aa446485.aspx"&gt;http://msdn2.microsoft.com/en-us/library/aa446485.aspx&lt;/A&gt;&lt;BR&gt;&lt;A href="http://samples.gotdotnet.com/quickstart/CompactFramework/doc/messagewindow.aspx" mce_href="http://samples.gotdotnet.com/quickstart/CompactFramework/doc/messagewindow.aspx"&gt;http://samples.gotdotnet.com/quickstart/CompactFramework/doc/messagewindow.aspx&lt;/A&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Thanks to Reed Robison from the Mobility Premier group.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2265715" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mobilitytouchdown/archive/tags/mobility/default.aspx">mobility</category><category domain="http://blogs.msdn.com/mobilitytouchdown/archive/tags/sdk/default.aspx">sdk</category><category domain="http://blogs.msdn.com/mobilitytouchdown/archive/tags/lab/default.aspx">lab</category><category domain="http://blogs.msdn.com/mobilitytouchdown/archive/tags/native+code/default.aspx">native code</category><category domain="http://blogs.msdn.com/mobilitytouchdown/archive/tags/c_2B002B00_/default.aspx">c++</category><category domain="http://blogs.msdn.com/mobilitytouchdown/archive/tags/managed+code/default.aspx">managed code</category><category domain="http://blogs.msdn.com/mobilitytouchdown/archive/tags/c_2300_/default.aspx">c#</category></item></channel></rss>