> 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