Groups | Blog | Home
all groups > dotnet interop > october 2006 >

dotnet interop : Bi-Directional Communication from MFC to Managed Com


Larry
10/6/2006 11:28:02 AM
I have an old MFC application that I'm now compiling in .net and have a C#
COM DLL, with a window interface, that I'm accessing with out any problems.
However, how do I get the COM DLL to be able to call back to the MFC
application? I have been looking for an example and I have found nothing.

Also can I pass my MFC window handle to the COM Dll so the message boxes
inside the DLL can use it to stay on top?

William DePalo [MVP VC++]
10/10/2006 1:00:28 AM
[quoted text, click to view]

In general terms, the canonical way to get managed code (e.g. C#) to call
native code (e.g. MFC) is to ensure that the callee is exported from a DLL
and to use Platform/Invoke (aka P/Invoke) to hop the fence between the two
environments:

http://msdn.microsoft.com/msdnmag/issues/03/07/NET/

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkPlatformInvokeTutorial.asp

Another option is to use a managed version of C++ -- MC++ (VS2003) or
C++/CLI (VS2005). What you to is put a component written in one of the
managed versions between the managed C# caller and the native MFC callee.
Because the C++ compiler can generate managed classes, calling from C# into
a C++ class is no more part difficult than calling a VB.Net class. But
because the C++ component can call native code as well, it can make use of
MFC as always.

Regards,
Will


AddThis Social Bookmark Button