Ian Reynolds
Ian Reynolds

Reputation: 53

Calling C# from C++

I have been looking for a way to call a function written in a C# EXE project (VS 2008) from a C++ DLL project. I can include the C# code as part of the C++ project itself if that is possible. All that I have been able to find is calling the C# DLL from C++.

Ultimately I want to call C# code from VB6 but I ask the question this way because I don't believe the later way is possible without an intermediate step.

Thanks,

Ian

Upvotes: 3

Views: 661

Answers (2)

steveg89
steveg89

Reputation: 1827

You can compile your c++ project with the /CLR option and then call C# from within it. To do that you need to include vcclr.h and then add a using statement for each dll you need to call from.

#include <vcclr.h>
#using <System.dll>

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564811

Ultimately I want to call C# code from VB6 but I ask the question this way because I don't believe the later way is possible without an intermediate step.

You can register the C# classes to be visible to COM, and then call them directly from C++ or VB6.

For details, see the Example COM Class on MSDN, as well as Interoperability.

Upvotes: 6

Related Questions