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

Kala B kalabalun@yahoo.co.in
Fri, 17 Dec 2004 12:59:32 +0000 (GMT)


Hi,
Thanks for your suggestions.

I had actually used wsclen() in the sample code. I was
trying with strlen( and passing the string as
Charset.Auto) as well as wcslen( and passing the
string as Charset.Unicode). So, it was a copy-paste
problem. Sorry about that.

Thanks again,
Regards
Kala B.


 --- Jonathan Pryor <jonpryor@vt.edu> wrote: 
> 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
> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>  

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony