use C# classes in managed C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mehrdad

    #1

    use C# classes in managed C++

    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.

  • José Joye

    #2
    Re: use C# classes in managed C++

    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 <myCSharpNameSp ace>" as well.
    With this, you should be able to use your C# classes from within Managed
    C++.

    eg:
    throw new BTCommon::BTExc eptionEx(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é


    "Mehrdad" <Mehrdad@discus sions.microsoft .com> wrote in message
    news:D73D2DEC-B139-43CA-9847-2428FF43C2E1@mi crosoft.com...[color=blue]
    > 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.
    >[/color]


    Comment

    Working...