I'm trying to build a wrapper to use cpp code inside c# code, and I want to return custom struct (Class) as output for method2, and std::string for method1, and this is my code in cpp
extern "C" __declspec(dllexport) std::string method1()
{
std::string s;
//Some Code/////////
return s;
}
and this is the method that should return custom struct (or class)
extern "C" __declspec(dllexport) MyStruct method2()
{
MyStruct s;
//Some Code//////
return s;
}
and I tried to write c# code for both of these methods and here is my c# code
[DllImport("<dllPath>", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern string method1(); //Exception
[DllImport("<DllPath>")]
public static extern MyStruct method2(); //Compile Error
Now when I'm trying to run the c# code I get MarshalDirectiveException for method1, and compiling error for method2?
extern "C" __declspec(dllexport) const char *method1()
, and this is the c# code [DllImport("