Thanks to the ideas suggested by those who responded, I have a little more info on this. I was trying to make a smaller test project that reproduced this so I could submit a bug and found out that the real problem is slightly different than I originally reported. The real problem isn't with simple marshaling of UTF-16 data using the UnmanagedType.LPWStr, but rather the problem is with some SWIG code that uses some function pointer tricks to allow C library functions to return pointers-to-buffers without leaking memory.
The trick I refer to is where the C Library has a pointer-to-function that allocates string data for C# strings. And the C# stub sends a delegate function implementation to the C library to use for this - and thus the string return values are managed by the C# world and not leaked. I've got a very small test project that reproduces this. I'll create a bug and attach it shortly. Two bugs, really. Because as I created this small test project I notice that if I compile the project with MS visual studio it's ok but if I compile with mono the test project crashes well before the spot I'm trying to test at. I'll create two bugs for this and send the links in case any brave souls would like to take a look. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robert Jordan Sent: Friday, June 29, 2007 9:02 PM To: Mono-list@lists.ximian.com Subject: Re: [Mono-list] Trouble with utf-16 marshaling Hi Dan, Maser, Dan wrote: Here are you speaking about "out" marshaling: > It works properly in windows with MS .NET, but doesn't work for me in > linux with mono. I've verified in gdb that the C library is returning > the correct string, but immediately after the C dll returns and mono > does the LPWStr marshaling the string is total garbage characters. I > am under the impression from previous posts that 2-byte UTF-16 should > marshal properly to mono with the LPWStr attribute. In fact it looks > like some of the gdiplus calls use that same thing and work... any ideas > what I can check on because mine doesn't? But your sample is about "in" marshaling: > > For more clarification my C library has a function signature like > this: > > void my_function(unsigned short* myArg); > > And my C# code looks like this: > > > [DllImport("myCLib")] > public static extern void my_function([MarshalAs(UnmanagedType.LPWStr)] > string myArg); Please post, or better: file a bug with a self-contained and compilable sample. Robert _______________________________________________ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list _______________________________________________ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list