I have a very large C++ library that I need to use in .NET, so I want to
create a C# wrapper around this library just like I have done for other C
style dlls. However, this C++ library has no C interface. The C++ library
has build options as a static lib and as a dll. Therefore, the exported
objects and methods, in the dll, are all VC 6.0 name-mangled. What is the
best way to use this in .NET? Some questions I have are...
Is there any support in P/Invoke to marshal to name-mangled exported items?
If not, should I use the static lib, create a C dll, create a C interface
for all the exported items, and then wrap this with .NET?
Are there any tools, that you are aware of, that can help in this wrapping
process? The size of this library is enormous, I think the static release
lib is about 30MB with about 2000 exported classes.
Thanks for any assistance.
Thomas Scheidegger [MVP] - 01 Sep 2003 22:28 GMT
Hi David
> The size of this library is enormous, I think the static release
> lib is about 30MB with about 2000 exported classes.
.NET / C# is a new technology generation,
not just a newer C++ compiler version....
> What is the best way to use this in .NET?
so you don't have a simple, flat, API style interface,
but _real_ C++ classes?
This will not work with PInvoke alone...
Only if you can change the Lib/DLL and add helper functions
for this-pointer handling.
Check sample in .NET SDK for 'CallingConvention.ThisCall':
...FrameworkSDK...\Samples\Technologies\Interop\PlatformInvoke\Custom\CS\ClassMethods.cs
This is only useful for few, simple classes.
Else use 'Managed C++' and write wrappers:
'Managed C++ .NET' (MC++)
http://msdn.microsoft.com/library/en-us/vcmex/html/vcconMCOverview.asp
or in Path:
Studio ....\VC7\managedextensionsspec.doc
\VC7\migration_guide.doc
Read:
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_overview.asp
http://msdn.microsoft.com/library/en-us/dncscol/html/csharp07152002.asp
http://msdn.microsoft.com/library/en-us/dncscol/html/csharp09192002.asp
and for 'Managed C++' with wrappers:
http://msdn.microsoft.com/library/en-us/dncscol/html/csharp12192002.asp
There can't be any (fully automatic) tools for this,
as there are _many_ difference between managed / unmanaged C++.

Signature
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
David Hoffer - 15 Sep 2003 01:00 GMT
Thomas,
Thanks a lot for the information. I will try the Managed C++ proxy
approach.
-dh
> Hi David
>
[quoted text clipped - 13 lines]
> for this-pointer handling.
> Check sample in .NET SDK for 'CallingConvention.ThisCall':
...FrameworkSDK...\Samples\Technologies\Interop\PlatformInvoke\Custom\CS\Cla
ssMethods.cs
> This is only useful for few, simple classes.
>
[quoted text clipped - 15 lines]
> There can't be any (fully automatic) tools for this,
> as there are _many_ difference between managed / unmanaged C++.