Reputation: 900
**unmanaged class**
this is the unmanaged class declaration
#ifdef EXPORT_CLASS
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
public class DLL_EXPORT cppclass
{
private:
string x;
public:
cppclass();
~cppclass();
string native();
};
**UNMANAGED CLASS DEFINITION**
this is the unmanaged class definition
cppclass::cppclass()
{
x="hello";
};
cppclass::~cppclass()
{
};
string cppclass::native()
{
return x;
};
**MANAGED CLASS**
this is the managed class declaration
public __gc class Mclass
{
//private:
public:
cppclass * obj;
public:
Mclass();
~Mclass();
string native();
};
**MANAGED CLASS DEFINITION**
//this is the managed class definition
#include"managed.h"
Mclass::Mclass()
{
obj=new cppclass();
};
Mclass::~Mclass()
{
delete obj;
};
string Mclass::native()
{
return obj->native();
};
Now all this is made into a dll and imported in a c# project
using managed;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
managed.Mclass first = new Mclass();
String x=first.nativ();
Console.Out.WriteLine(x);
}
}
}
error comes that Managed.Mclass.nativ() is not supported by the language
Upvotes: 0
Views: 1503
Reputation: 613461
You are returning a native string from your C++/CLI wrapper class. You need to return a managed .net string instead. The wrapper class must translate parameters and return values of native classes to appropriate managed classes.
Upvotes: 2