[Mono-list] Managed C++ assemblies and Mono
Fri, 10 Jan 2003 16:31:09 -0600
Jason Whittington wrote:
>>I would agree that for a native C interface (e.g., GTK+), that would
>>better. From what I have seen of P/Invoke, however, it seems
>>for use with a C++ API due to all the static methods.
> There's really no other practical way to do interop. This is due to a
> weakness in C++, not a weakness in .NET. C++ was written with
> source-code compatibility in mind, not binary compatibility. As a
> result, C++ compilers are free to handle virtual dispatch and name
> mangling however they like, making binary interop infeasible.
> As for your desire that things be more OO in nature, get over it :).
Would that I could, but that's not an option. I have 500,000+ lines of
extant C++ code representing 6 years of work that I cannot rewrite to be
less object oriented.
> P/Invoke is actually way nicer to work with than, say, JNI. Similar
That is very true. I tried JNI for a different project a while ago, and
it hurt. P/Invoke is leaps and bounds better.
>> What it really
>>comes down to is that I want to write a class in C# that implements an
>>interface defined in unmanaged C++. An instance of the C# class would
>>passed through to unmanaged C++ code. There are a lot of details
>>involved with this, but the inherent object-oriented nature does not
>>to lend itself well to the structure of P/Invoke-style code.
> Easier to say than to actually do. For this to work the runtime and the
> C++ compiler would have to agree on a tightly-specified binary interface
> contract. This has been done before; it was called COM (XPCOM on
> Linux). COM interop is even more complex than P/Invoke, especially
> when you start passing interface references around instead of flat data
> structures. Lifetime management and managed/unmanaged interaction turns
> into a horrible sticky quagmire. Check out Adam Nathan's book or Sam
> Gentile's website  for more discussion.
Thanks for the references. Anything to help me in this quagmire is much
> See Chapter 1 of "Essential COM" "COM as a better C++"
>  ".NET and COM: The Complete Interopability guide"
>  http://radio.weblogs.com/0105852/
> Mono-list maillist - Monofirstname.lastname@example.org
Patrick L. Hartling | Research Assistant, VRAC
email@example.com | 2624 Howe Hall: 1.515.294.4916
http://www.137.org/patrick/ | http://www.vrac.iastate.edu/