473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

does PInvoke support for polymorphism ?

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.

Nov 17 '05 #1
4 1649
yaron wrote:
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
Nov 17 '05 #2
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.

Nov 17 '05 #3
yaron wrote:
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#?


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
Nov 17 '05 #4
thanks a lot, it was very helpfull.
"Arnaud Debaene" wrote:
yaron wrote:
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#?


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

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: richard pickworth | last post by:
Can anyone explain polymorphism?(very simply). thanks richard
13
by: Andy Leszczynski | last post by:
wikipedia (http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming) says: """ Python's support for object oriented programming paradigm is vast. It supports...
5
by: Ken | last post by:
Hello Everyone, I think that there is no way to add a network printer in .Net. I have tried ,as an alternative, using windows API AddPrinter. This was not successful. Does anybody have a...
5
by: vertigo | last post by:
Hello I use some win 32 API function for example: HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD...
1
by: Tommy Svensson \(InfoGrafix\) | last post by:
Hi, Can I use P/Invoke to obtain a C++ class type contained in a dll? I know how to get structs and how to pass classes as parameters to native code but how do I get C++ unmanaged classes from a...
0
by: yaron | last post by:
Hi , Is there is any differences in the capabiliies of those 3 approaches IJW, Manage C++ Wrapper classes or PInvoke, for example if i can use polymorphism in all the approaches in my C# Client...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
5
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.