Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

P\Invoke Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Hoffer - 01 Sep 2003 19:04 GMT
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++.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.