[Mono-devel-list] Marshalling char**

Hisham Mardam Bey hisham.mardambey at gmail.com
Sun May 29 20:21:11 EDT 2005


all working now. apparently i had an extra field in a struct which I
was marshalling and mono didnt like it which caused some corruption on
the data.

On 5/29/05, Hisham Mardam Bey <hisham.mardambey at gmail.com> wrote:
> Hey Jonathan,
> 
> When this line runs:
> 
> IntPtr s = Marshal.ReadIntPtr (stringArray, i * IntPtr.Size);
> 
> I get:
> 
> ** ERROR **: Structure field of type String[] can't be marshalled as LPArray
> aborting...
> Aborted
> 
> This is the same error I get with the rest of the calls I tried. (I
> even implemented PtrToStringArray in my own code before looking at
> your reply and it didnt work).
> 
> I'm not using the null terminated version of it as I know how large
> the string is going to be (its an int field in the struct). Any other
> tips or things I need to do to figure out this problem?
> 
> Thank you.
> Best Regards,
> hisham.
> 
> 
> On 5/29/05, Jonathan Pryor <jonpryor at vt.edu> wrote:
> > On Sun, 2005-05-29 at 02:48 +0300, Hisham Mardam Bey wrote:
> > > I wanna try and marshal a char** that is returned in a struct. You can
> > > see the code here:
> > >
> > > http://pastebin.com/291223
> > >
> > > I've tried using Copy and ReadIntPtr to no avail. I might be doing
> > > something wrong.
> >
> > I do not believe that char** can be marshaled without additional
> > assistance; MarshalAsAttribute.SizeParamIndex *might* work for structs,
> > but I don't think so, and that's the type of support the runtime
> > marshaler would need to avoid manual marshaling.
> >
> > Fortunately, it's fairly straightforward to do it manually.  Mono.Unix
> > marshals char** for `struct group`, so you might want to look at:
> >
> > http://mono.myrealbox.com/source/trunk/mcs/class/Mono.Posix/Mono.Unix/Syscall.cs
> >
> > Syscall.CopyGroup() converts and unmanaged representation into the
> > Managed representation;
> >
> > http://mono.myrealbox.com/source/trunk/mcs/class/Mono.Posix/Mono.Unix/UnixMarshal.cs
> >
> > UnixMarshal.PtrToStringArray(), which converts an IntPtr (char**) into a
> > string[], and
> >
> > http://mono.myrealbox.com/source/trunk/mono/support/grp.c
> >
> > copy_group() which converts a Unix `struct group` into the
> > representation shared between Mono.Posix.dll and MonoPosixHelper.  You
> > probably won't need to go through this step, since your structure isn't
> > going to vary between differing Unix platforms.
> >
> >  - Jon
> >
> >
> >
> 
> 
> --
> Hisham Mardam Bey
> MSc (Computer Science)
> http://hisham.cc/
> +9613609386
> Codito Ergo Sum (I Code Therefore I Am)
> 


-- 
Hisham Mardam Bey
MSc (Computer Science)
http://hisham.cc/
+9613609386
Codito Ergo Sum (I Code Therefore I Am)



More information about the Mono-devel-list mailing list