One solution is to create a managed C ++ class library with regular __declspec(dllexport) functions that invoke managed methods in the C # class reference library.
An example is a C ++ code file in a managed C ++ project:
#include "stdafx.h" __declspec(dllexport) int Foo(int bar) { csharpmodule::CSharpModule mod; return mod.Foo(bar); }
C # module (a separate project in the solution):
namespace csharpmodule { public class CSharpModule { public int Foo(int bar) { MessageBox.Show("Foo(" + bar + ")"); return bar; } } }
Note that I demonstrate that this is a real .NET call with a call to System.Windows.Forms.MessageBox.Show .
An example of a basic (non-CLR) Win32 console application:
__declspec(dllimport) int Foo(int bar); int _tmain(int argc, _TCHAR* argv[]) { std::cout << Foo(5) << std::endl; return 0; }
Do not forget to associate the Win32 console application with the .lib file obtained from the assembly of the C ++ managed project.
Aviad P.
source share