On 12.03.2012 20:51, efontana wrote:
I'm using Embedded Mono and P/Invoke DllImport.   If I have a method which
returns a string


   [DllImport("__Internal", EntryPoint = "CSharp_Test_ReturnString")]
     public extern static string CSharp_Test_ReturnString();

The corresponding "C" method should strdup the string right?

Yes.


extern "C"
{
   char* CSharp_Test_ReturnString()
   {
     QString sv = "QString allocated";
     return strdup((const char*)sv.toAscii());
   }
}

Won't the CLR free that string for me?


It will, but under Windows you must take care which function
you're using for the allocation. By definition, only memory
allocated with CoTaskMemAlloc is safely freed by the CLR,
but I don't know which combination will actually work
with Mono/Windows. You may want to look at the source code.


Robert

_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to