use C# classes in managed C++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have a set of C# classes and I am trying to instanciate and call them in a
managed C++ project. I have been searching a lot but so far could not find
any example or document on how to this. I have heard people say it is even
possible to wirte a class in C# and subclass it in C++. Can anybody give me a
hint or some link to related usefull documents.

thanks.
 
Normally, it should be painless.

Your C# code and Managed C++ classes HAVE to be in separate dlls (in your
case, the C++ could be in an exe as well).
In the C++ project, right click on the "Reference" folder and add the dll
where the C# project is.

In each C++ file where you will use the C# classes, you can add the "using
namespace <myCSharpNameSpace>" as well.
With this, you should be able to use your C# classes from within Managed
C++.

eg:
throw new BTCommon::BTExceptionEx(strErr->ToString()); // where
BTCommon is my namespace and BTExceptionEx is a class (in C#)


By the way, I remember having problem with intelisense.

Regarding your question about deriving from a C# class, it should be no
problem (I have not try it myself).

José
 
Back
Top