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 / August 2006

Tip: Looking for answers? Try searching our database.

Using PInvoke to import unmanaged C++ class library to C# app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hank - 10 Aug 2006 21:59 GMT
Hi expert,
I am writing a C# app which will access a 3rd party unmanaged C++ class
library. the library contains one class with constructor, destructor and
many methods. I search through the web find people talking about DllImport C
type function, that's easy, you just do following:
[DllImport: myLib.dll]
public static extern void myFunc();

But my situation is I need to access CLASS methods not global function,
especially I want to instantiate and destroy an instance by accessing the
Constructor and Destructor(both of them there is no return type), how should
i do it?

Your help is highly appreciated?

Hank
Robert Simpson - 10 Aug 2006 22:09 GMT
Unless you wrote the C++ unmanaged class and can recompile the source code
with additional functionality, what you're asking for cannot be done.

Robert

> Hi expert,
> I am writing a C# app which will access a 3rd party unmanaged C++ class
[quoted text clipped - 12 lines]
>
> Hank
Hank - 10 Aug 2006 22:36 GMT
Robert,
I don't have C++ unmanaged class, it is a third part dll.
The DllImport has a choice called "CallingConvention" which has a enum value
"ThisCall" to let you deal with accessing class members, I just can't find a
good example.

Hang

> Unless you wrote the C++ unmanaged class and can recompile the source code
> with additional functionality, what you're asking for cannot be done.
[quoted text clipped - 17 lines]
>>
>> Hank
Christian Fröschlin - 11 Aug 2006 08:38 GMT
> I don't have C++ unmanaged class, it is a third part dll.
> The DllImport has a choice called "CallingConvention" which has a enum value
> "ThisCall" to let you deal with accessing class members, I just can't find a
> good example.

An example can be found under (mind line wraps):

http://www.codeproject.com/useritems/usingcppdll.asp?df=100&forumid=308246&exp=0
&select=1507950


Although not impossible, it is rather ugly due to name mangling.
It is probably best to write a wrapper DLL in C++, either

o unmanaged, exposing a flattened extern "C" API
o unmanaged, exposing a COM API
o mixed-mode, exposing a managed API

Rate this thread:







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.