[Mono-devel-list] Calling unmanaged code from C#

Marcus mathpup at mylinuxisp.com
Fri Feb 6 17:38:18 EST 2004


I believe so. Unfortunately, GCC does not have the equivalent of Visual C++'s 
ability to mix unmanaged and managed code. I see that TIBCO's RV libraries 
are available with both C and C++ APIs. You will probably want to use the C 
API with DllImport. Calling C++ from C# directly with GCC as the C++ compiler 
is difficult-and-non-portable or impossible, without an intermediate C 
support library.

Brief list of problems:

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 memory for the object in the first place seems 
impossible. 

Second, C++ compilers use name-mangling to avoid duplication of symbols when 
several classes define the same method and when overloaded methods are used. 
This mangling is platform dependent. It is possible to use system-specific 
utilities to produce a list of mangled and unmanagled names and then match 
them up to create a conversion table. So this is more of an annoyance than an 
an outright dead-end. 

Third, when optimization is specified, C++ compilers frequently inline any 
methods those bodies are defined within the class scope (and possibly other 
methods as well). Moreover, if every invocation of a method is inlined, some 
compilers do not by default emit an out-of-line copy for the method. This is 
the default for GCC when optimization is selected.



On Friday 06 February 2004 2:56 pm, Matt Davey wrote:
> Hi,
>
> I have an app that runs on MIcrosoft .NET that is build with C# calling a
> Visual C++ Managed wrapper around the TIBCO RV libraries
> (http://www.tibco.com/software/enterprise_backbone/rendezvous.jsp).
>
> I want to move the app to Mono on RedHat. Am I correct is thinking that
> instead of using the managed/unmanaged Visual C++ component on Mono, I
> should build a C# component that wrappers the tibco .so file, and invokes
> methd via DllImport ?




More information about the Mono-devel-list mailing list