[Mono-list] Trouble with utf-16 marshaling

Maser, Dan Dan.Maser at inin.com
Fri Jun 29 14:09:36 EDT 2007


   Furthermore, I see in the mono source code that there is a test
function in the mono/mono/tests/libtest.c
 
STDCALL unsigned short*
test_lpwstr_marshal (unsigned short* chars, long length)
{
...
}
 
   Which is basically the same thing I'm doing; further indicating that
this should work.

________________________________

From: mono-list-bounces at lists.ximian.com
[mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Maser, Dan
Sent: Friday, June 29, 2007 9:13 AM
To: mono-list at lists.ximian.com
Subject: [Mono-list] Trouble with utf-16 marshaling




   My situation is this:  I've got a C library that has a lot of UTF-16
inputs and outputs.  The C type is always "unsigned short*" or "const
unsigned short*" (because clearly wchar_t* isn't portable because it's 4
bytes on linux).   All of my C# code has the
"[MarshalAs(UnsignedType.LPWStr)]" attribute specified.

   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?

   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); 

   Thanks in advance for any ideas on what to check! 
      Dan Maser 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070629/177cbb9c/attachment-0001.html 


More information about the Mono-list mailing list