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 / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

does PInvoke support for polymorphism ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yaron - 11 Jun 2005 13:46 GMT
Hi,

I want to use my unmanaged c++ class library from a c# client.
my unmanaged c++ class library use polymorpism, is this polymorphism also
exported to my c# client via PInvoke ?

thanks.
Carl Daniel [VC++ MVP] - 11 Jun 2005 14:18 GMT
> Hi,
>
> I want to use my unmanaged c++ class library from a c# client.
> my unmanaged c++ class library use polymorpism, is this polymorphism
> also exported to my c# client via PInvoke ?

I'm assuming that you're asking "Can I call a virtual function through a
pointer to a native C++ object via PInvoke?".  The answer to that is no (or
at least, not directly).  MC++ IJW can, however.

To call virtual functions through PInvoke you'd need to write a little
"trampoline" function and export it from your native DLL.  The function
would be a non-member, taking the object pointer and all of the virtual
methods parameters as it's parameters and would perform the virtual function
call.

-cd
yaron - 11 Jun 2005 15:22 GMT
Hi Daniel,

I will give a small scenario:
my unmanaged c++ dll receive method return a pointer to a generic message
base class but it actually can be many different concrete messages class
which derive from the generic message.
i want from my c# client to deal with the concrete message class.

can i cast down the generic message pointer to the concrete message and
access the concrete message fields from c#?

Thanks.
Arnaud Debaene - 11 Jun 2005 17:03 GMT
> Hi Daniel,
>
[quoted text clipped - 6 lines]
> can i cast down the generic message pointer to the concrete message
> and access the concrete message fields from c#?

You'd better do it with a managed C++ (or C++/CLI) adaptation layer :
P/Invoke is well suited for C-style APIs, but it may be difficult to use it
in an OO context.

Arnaud
MVP - VC
yaron - 11 Jun 2005 18:02 GMT
thanks a lot, it was very helpfull.

> > Hi Daniel,
> >
[quoted text clipped - 13 lines]
> Arnaud
> MVP - VC

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.