[Mono-devel-list] Marshalling char**

Jonathan Pryor jonpryor at vt.edu
Sun May 29 11:24:40 EDT 2005

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:


Syscall.CopyGroup() converts and unmanaged representation into the
Managed representation;


UnixMarshal.PtrToStringArray(), which converts an IntPtr (char**) into a
string[], and


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

More information about the Mono-devel-list mailing list