[Mono-dev] Options needed for imported Linux libraries.

Jonathan Pryor jonpryor at vt.edu
Thu Aug 12 13:20:40 EDT 2010


On Thu, 2010-08-12 at 16:49 +0200, Omar Siam wrote:
> I compiled a C so lib on Linux to do ioctl calls and tried to use it
> with DllImport but when I pass structures by ref or StringBuilder for
> returning char* buffers to my library everything is behaving strange.

http://mono-project.com/Dllimport#Classes_and_Structures_as_Return_Values
http://mono-project.com/Dllimport#Strings_as_Return_Values

In short, don't use StringBuilder as a method return type.  Use
StringBuilder as a parameter type, and you _may_ need to use the [Out]
parameter attribute on the StringBuilder.

> I tried to Marshal my structure to an HGlobal IntPtr as the docs say
> passing structures by ref to unmanaged code is unsupported

Where do the docs say this?

As Robert Jordan mentioned, having the managed and native function
signatures would be very helpful.

 - Jon




More information about the Mono-devel-list mailing list