The easiest way to interact between C ++ and C # is to use managed C ++ or C ++ / CLI, as it is called. In VisualStudio, create a new C ++ project of the type "CLR Class Library". There is a new syntax for the parts you want to make available for C #, but you can use regular C ++ as usual.
In this example, I use std::vector<int>to show that you can use standard types - however, in a real application, I prefer to use .NET types where possible (in this case a System::Collections::Generic::List<int>).
#pragma unmanaged
#include <vector>
#pragma managed
public ref class CppClass
{
public:
CppClass() : vectorOfInts_(new std::vector<int>)
{}
!CppClass()
{ delete vectorOfInts_; }
void Add(int n)
{ vectorOfInts_->push_back(n); }
private:
std::vector<int>* vectorOfInts_;
};
EDIT: , .