-1

I have gone over this two Qs:

Possible to call C++ code from C#?

Wrapping unmanaged C++ with C++/CLI - a proper approach

I also read few things about C++/CLI , but honestly I am pretty confused.

I have a VC++ Project and I want to convert it into a C# Project.

My Qs are:

  1. Do I need to use C++/CLI for this purpose and how?
  2. Do I have to implement a wrapper class for each method of the original Project on my new Project and If not how do I proceed?
Community
  • 1
  • 1
apomene
  • 14,282
  • 9
  • 46
  • 72

1 Answers1

1

1)Yes you need C++/CLI

2) No you don't need to make a wrapper class for each method, you need to make just one wrapper class for each C++(native) class you have, its similar to declare an interface

Wrapping unmanaged C++ with C++/CLI - a proper approach

is an exampe with just one method, but if yuor class written in C++ of type NativeType have another method, for example:

void Method2()

just had on the same class

   void ManagedMethod2()
      { NativePtr->Method2(); } 

so the entire wrapper class will be: #include "NativeType.h"

public ref class ManagedType
{
     NativeType*   NativePtr; 

public:
     ManagedType() : NativePtr(new NativeType()) {}
     ~ManagedType() { delete NativePtr; }

     void ManagedMethod()
      { NativePtr->NativeMethod(); } 

     void ManagedMethod2()
      { NativePtr->Method2(); } 
}; 

always from the link above for call the method2 in C# you will do:

mt.ManagedMethod2();
Community
  • 1
  • 1