[Mono-list] Support for marshalling of C# string to unmanaged wchar_t on Linux

Jonathan Pryor jonpryor@vt.edu
Fri, 17 Dec 2004 06:48:54 -0500


Corrections...

On Thu, 2004-12-16 at 21:22 -0500, Jonathan Pryor wrote:
<snip/>
> > Contents of testlib.c
> > ---------------------
> > #include <stdio.h>
> > #include <wchar.h>
> > 
> > typedef struct _id
> > {
> >     int len;
> >     wchar_t name[256];
> 
> Change "name" to the following and things work better:
> 
> 	unsigned char name[256];

This should be "unsigned short", not "unsigned char", obviously.

<snip/>
> >     printf("wcslen returns.. %d\n",strlen(id->name));
> 
> Besides, you're not even using wcslen here, you're using strlen here.
> OF COURSE it'll return "1" -- it'll hit the "null" embedded in the first
> wide character.

Thinking about it, it'll be 0 or 1, depending on the endian-ness of your
platform.  The character 'p' will be 0x0070, so on little-endian
architectures strlen will return 1 while it will return 0 on big-endian
architectures.  Silly me.

 - Jon