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

2010-08-12 Thread Omar Siam
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.
The StringBuilders returned do not contain anything or I have to create
a new StringBuilder for any call to unmanged code because they are stuck
to the first value returned. The structures contain nonsense data after
the second call into the library. What am I missing? How do I compile so
libs to be mono friendly?
I tried to Marshal my structure to an HGlobal IntPtr as the docs say
passing structures by ref to unmanaged code is unsupported (.NET
obviously supports this) but that didn't help. I use mono 2.6.7 on
openSUSE 11.3. Valgrind doesn't say anything about the functions I call
from mono when I run it using a C test program.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


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

2010-08-12 Thread Robert Jordan
On 12.08.2010 16:49, Omar Siam wrote:
 What am I missing? How do I compile so libs to be mono friendly?

Your post is missing a sample :) Post the p/invoke and structure
defs of both sides (managed and unmanaged).

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


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

2010-08-12 Thread Jonathan Pryor
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


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list