473,473 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C++ class in DLL to be imported to C#

Dear all,

I am trying to write a class in C++, exported it in DLL.
Does anyone know how I can import them in C#?

For example:
in C++
class DllExport Abc
{
public:
int foo1;
FILETIME anytime;
};
in C# I would like to access the member variables like this.
....
Abc abc;
abc.foo1=10;

How can I do so? Which version of visual studio should I use to build the
DLL and C# program?

Thanks

Tony Siu Chun Tung

Mar 10 '06 #1
3 1234
> I am trying to write a class in C++, exported it in DLL.
Does anyone know how I can import them in C#?


You would have to write a wrapper class in managed C++, C# can't
directly use native C++ classes.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 10 '06 #2
Dear Mattias,

I am not familiar with managed C++
Could you give us an example of how to write the warpper class for warpping
a class like this? In Which Visual Studio should I write it in?

class DllExport Abc
{
public:
int foo1;
FILETIME anytime;
};

Thanks alot

Tony

"Mattias Sjögren" wrote:
I am trying to write a class in C++, exported it in DLL.
Does anyone know how I can import them in C#?


You would have to write a wrapper class in managed C++, C# can't
directly use native C++ classes.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Mar 10 '06 #3
Search the MSDN docs for "C++ Interop" and you get a bunch of examples.
http://msdn2.microsoft.com/en-us/lib...zx(VS.80).aspx

Willy.

"Tony Siu" <To*****@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
| Dear Mattias,
|
| I am not familiar with managed C++
| Could you give us an example of how to write the warpper class for
warpping
| a class like this? In Which Visual Studio should I write it in?
|
| class DllExport Abc
| {
| public:
| int foo1;
| FILETIME anytime;
| };
|
| Thanks alot
|
| Tony
|
|
|
| "Mattias Sjögren" wrote:
|
| > > I am trying to write a class in C++, exported it in DLL.
| > >Does anyone know how I can import them in C#?
| >
| > You would have to write a wrapper class in managed C++, C# can't
| > directly use native C++ classes.
| >
| >
| > Mattias
| >
| > --
| > Mattias Sjögren [C# MVP] mattias @ mvps.org
| > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| > Please reply only to the newsgroup.
| >
Mar 10 '06 #4

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

Similar topics

7
by: John J. Lee | last post by:
I'm trying to change a base class of a big class hierarchy. The hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class that defines __getattr__ and __setattr__ that I need to...
2
by: Jerry | last post by:
My "main" class is getting a bit long...Is it possble to split a class definition into several files and then import the pieces to get the whole definition? Jerry
1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
10
by: lkrubner | last post by:
I killed last night and a good chunk of today trying to figure out this one particular attempt to get a class and initialize it. My code is using a class method called getObject to include() a file...
23
by: patang | last post by:
When I create my own class, to use the functions of that class I have to create an object of that class and then I can access the functions of that class, for example: dim obj1 as myclass...
0
by: seek help | last post by:
Hello, IDE: VS .NET 2003. Problem: Mangled bits of gc class embedded within native C++ class. Description: I have a gc class, BoxedInfo. This wraps a Value type structure, NotiInfo....
22
by: John Salerno | last post by:
I might be missing something obvious here, but I decided to experiment with writing a program that involves a class, so I'm somewhat new to this in Python. Anyway, what is the best way to create...
10
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in...
1
by: Kevin Walzer | last post by:
I'm trying to create a custom Tkinter widget class, and I'm having some difficulty getting it set up properly. The class is called MacToolbar, saved in its own module MacToolbar.py, and imported...
13
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.