I have a C++ DLL wrapping other C++ code and am calling from C#.
[DllImport("MyDll.dll")]
static unsafe private extern IntPtr StatusToString();
The function being called is
extern "C" {
__declspec(dllexport)
const char* StatusToString() {
//return std::string("def").c_str();
return "def";
}
}
The calling code is
IntPtr abc = StatusToString();
As shown, with
return "def";
and examining abc in the memory window, abc points to "abc".
However, with the C++ code modified to
return std::string("def").c_str();
and examining abc in the memory window, abc points to garbage.
Why is that and what do I do?
Thanks,
Joe