[Mono-list] Marshaling string on Windows returns Garbage??

efontana eric at fontanas.net
Tue Mar 13 12:21:00 UTC 2012


No, it's a std::string (there an above using namespace std) 

FWIW: I tried even doing this:

const char* testValue = "test"
char* s = CoTaskMemAlloc(strlen(testValue)+1);
strcpy(s, testValue);
return s;

That also returns the 8 Question Marks.

Even more interesting, if I change the signature to 
IntPtr CSharp_Return_String and use Marshal.PtrToStringAnsi, the string is
correct!!

If I use the IntPtr method, the C# wrapper will have to call
Mashal.FreeCoTaskMem to avoid
the leak, because I'm forced to allocate the string on the C++ side since
the string is really
embedded in either a std::string or a Qt QString.



--
View this message in context: http://mono.1490590.n4.nabble.com/Marshaling-string-on-Windows-returns-Garbage-tp4468863p4468951.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list