Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling UNIX and Linux shared object file .so from c#

Is there a way for a Shared Object file written in C and built on Unix to be called from C# P/Invoke?

Or do I need to use Java or something like that?

like image 359
Natasha Thapa Avatar asked Aug 16 '11 02:08

Natasha Thapa


1 Answers

Mono has the ability to integrate with native libraries from within C# built on top of dlopen(3). You just have to use the DllImport statement with the name of the library (i.e. 'libform.so.5'), then wrap the native code and data types with a friendly C# class that takes care of all the low-level stuff. This page has a good overview with lots of information on how to deal with marshaling pointers and other unsafe types.

Once you've got your wrapper class written, you can just use that without worrying about the fact that it's using a native shared library underneath.

like image 79
James O'Doherty Avatar answered Oct 24 '22 13:10

James O'Doherty