tags:

views:

191

answers:

1

Hi All,

I have an MFC application to run on mobile device. Now this 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

+1  A: 

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).

crimson13
Thanks for your suggestion. I will definitely try it out.But the problem with this approach is that i may have to restructure my current application, to split it into dll and use from MFC and also call from c#.Is there any possibility where with minimal change to my current application and creating a dll to act as wrapper(which calls my application code) for calling from c#,can solve my problem??
Adam Jones