You could try making the argument an out parameter and seeing if that
works. If so, there must be a bug in marshaling strings as return values.
Please file a bug in that case.
//C#
void CSharp_Out_String(out string str);
and
//C++
void CSharp_Out_String(char** str)
{
const char* testValue = "test"
*str = CoTaskMemAlloc(strlen(testValue)+1);
strcpy(*str, testValue);
}
Thanks,
Jonathan
On Tue, Mar 13, 2012 at 8:21 AM, efontana <[email protected]> wrote:
> 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.
> _______________________________________________
> Mono-list maillist - [email protected]
> http://lists.ximian.com/mailman/listinfo/mono-list
>
_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list