I have a struct that I've defined in both C# and C++ that looks like so:
C#
Public struct Part{
public int number;
public string name;
}
C++
struct Part{
int number;
std::string name;
}
I have a function that will do many things, but for the sake of simplicity, it will change around the part that was passed in.
C#
[DllImport(@"Part.Interface.dll")]
private static extern void _ChangeAStruct(ref Part part);
public void PassAStruct(){
Part part = new Part();
_ChangeAStruct(ref part);
}
C++
extern "C" __declspec(ddlexport) void __cdecl _ChangeAStruct(Part &part) {
part.number = 42;
part.name = "I am a struct";
}
On the C# side it successfully changes the number but the name returns as null. I have tried to [MarshalAs(UnmanagedType.LPStr)]
on the string but that didn't change anything.
How do I change the structs to pass back "I am a struct"? It has been mentioned that interop cannot handle std::string, but what can it handle?