[Mono-list] How to create C++ library and call it's functions from C# program?

Jonathan Pryor jonpryor@vt.edu
Thu, 11 Mar 2004 20:16:33 -0500


On Thu, 2004-03-11 at 14:00, Marcus wrote:
> On Friday 12 March 2004 12:14 am, Jonathan Pryor wrote:

<snip/>

> I would also add that the ``extern "C"'' does not help in situations where you 
> need to communicate with C++ classes. In this case, with GCC an intermediate 
> C library is almost certainly necessary. If something similar VS.NET's 
> Managed Extensions for C++ existed for GCC, this might be avoided.
> 
> There at least 3 reasons why an intermediate layer is needed. First, there is 
> no way to create a new instance of a C++ object from outside C++ unless the 
> C++ library provides an appropriate function. There is no obvious way to 
> determine how much memory to allocate for a given C++ object, so even if it 
> were possible to call a C++ constructor directly to initialize the object, 
> allocating the object in the first place seems impossible. 

Finally, it can be noted that the intermediate C library, and a C#
wrapper for the C library, can be automatically generated (with some
programmer assistance).  See the SWIG project:

	http://www.swig.org

 - Jon