开发者

wrapping MFC application(target mobile device) to create dll for use in c#.NET for interop

开发者 https://www.devze.com 2022-12-17 10:17 出处:网络
I have an MFC application to run on mobile device. Now th开发者_C百科is appliation code need to be reused from C#.

I have an MFC application to run on mobile device. Now th开发者_C百科is appliation code need to be reused from C#. I am trying to create wrappers, dll, and import this dll from c#.

Problem being faced is , my project is not a class library. So i created another MFC class library - (MFC-Shared dll) in the same solution and tried to create wrapper functions in this library . But i am not able to create any objects or access any functions of my application from this library even after adding reference.

Is there any way to access my application code from this library.

Please help


I suggest splitting some of that code into a C++ DLL (not a class library) and then using DllImport attributes in C# to access those functions (see http://msdn.microsoft.com/en-us/library/26thfadc.aspx). You can then still use that DLL in your MFC application by adding a project dependency (add both projects to the same solution first). This way a lib wrapper is automatically created and linked to the MFC application.

A different solution (but probably even more work) is to do Inter Process Communication between your MFC application and a C# client by opening a Named Pipe or a TCP Socket. As protocol you can either create your own (like we did at our company) or go for something like XML-RPC, SOAP, etc. As an example you could try to get gSOAP to work in your MFC server, then define a WSDL file and have the C# client code be autogenerated out of this by Visual Studio.

Another solution is to turn part of your MFC application into a COM DLL. Then both the MFC and the C# clients can use it. But I don't think this solution adds anything more than the 'normal' DLL solution.

Sorry, but I don't know of an easy solution (or at least one that doesn't take a non trivial amount of work).

0

精彩评论

暂无评论...
验证码 换一张
取 消