473,384 Members | 1,854 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,384 software developers and data experts.

Using a C++ class in C#

Hi.

I have an DLL written as "normal" C++ dll. I has an GetObject function,
which return an c++ class.
Now I whant to use this class (and all its members) in my C# applikation.
I know that C# classes and C++ class are incompatible.
So this is how I whant to solve it: (If possible)

My C# applikation uses a managed C++ class, that is added to my C# project.
The managed C++ class then uses the "old" dll and the C++ class returned by
it. It then has some members functions/Interfaces, that is used by the C#
class.
The managed C++ class allso must use WaitforMultipleObjects(..) (The DLL
uses named events for signaling)

So my Q's are:

1: Is this gonna work ?

2: If it does, how do I add an managed C++ file/class til my C# projects and
how does the C# class use the managed C++ class ? (How does the C# class now
about the managed C++ class)

3: Is there any other pretty solution for this ?

Thomas


Nov 15 '05 #1
4 1745
You can use the tool "RegAsm.exe" that makes .Net compatible with unmanaged
code.
It is found with the Visual Studio.Net folder.

--
Rami Saad
Microsoft GTSC Developer support for Middle East
"Thomas Johansen" <thrawn[NO SPAM]@hest.com___KĘP> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi.

I have an DLL written as "normal" C++ dll. I has an GetObject function,
which return an c++ class.
Now I whant to use this class (and all its members) in my C# applikation.
I know that C# classes and C++ class are incompatible.
So this is how I whant to solve it: (If possible)

My C# applikation uses a managed C++ class, that is added to my C# project. The managed C++ class then uses the "old" dll and the C++ class returned by it. It then has some members functions/Interfaces, that is used by the C#
class.
The managed C++ class allso must use WaitforMultipleObjects(..) (The DLL
uses named events for signaling)

So my Q's are:

1: Is this gonna work ?

2: If it does, how do I add an managed C++ file/class til my C# projects and how does the C# class use the managed C++ class ? (How does the C# class now about the managed C++ class)

3: Is there any other pretty solution for this ?

Thomas

Nov 15 '05 #2
Inline ***
Willy.
"Thomas Johansen" <thrawn[NO SPAM]@hest.com___KĘP> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi.

I have an DLL written as "normal" C++ dll. I has an GetObject function,
which return an c++ class.
Now I whant to use this class (and all its members) in my C# applikation.
I know that C# classes and C++ class are incompatible.
So this is how I whant to solve it: (If possible)

My C# applikation uses a managed C++ class, that is added to my C#
project.
The managed C++ class then uses the "old" dll and the C++ class returned
by
it. It then has some members functions/Interfaces, that is used by the C#
class.
The managed C++ class allso must use WaitforMultipleObjects(..) (The DLL
uses named events for signaling)

So my Q's are:

1: Is this gonna work ? Yes. 2: If it does, how do I add an managed C++ file/class til my C# projects
and
how does the C# class use the managed C++ class ? (How does the C# class
now
about the managed C++ class)
Add a reference to the C++ assembly.


3: Is there any other pretty solution for this ? Isn't this pretty enough?.

Thomas

Nov 15 '05 #3
> Add a reference to the C++ assembly.

In my solution explorer I right click and select Add Reference. I select the
Project tab and press Browse.
Then I select my "old" VS6 DLL and get the following error:

"A Reference to "MyPath\MyDll.dll" could not be added. This is not a valid
assembly or COM component. Only assemblies with extension 'dll' and COM
components can be referenced. Please make sure that the file is accessible,
and that it is a valid assembly or COM component."

I guess its because it has to be an .NET compiled dll or am I wrong here ?
Isn't this pretty enough?. mmh... No.. I dont like it :-) But it's the only way I can think of...

Thomas


Nov 15 '05 #4
Hmmm your question....
< 2: If it does, how do I add an managed C++ file/class til my C# projects
and
how does the C# class use the managed C++ class ? (How does the C# class now
about the managed C++ class)>
Why are you adding a reference to your old VC6 dll? You must add a reference
to your managed C++ assembly not the old VC6 dll.

WIlly.

"Thomas Johansen" <thrawn[NO SPAM]@hest.com___KĘP> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
Add a reference to the C++ assembly.


In my solution explorer I right click and select Add Reference. I select
the
Project tab and press Browse.
Then I select my "old" VS6 DLL and get the following error:

"A Reference to "MyPath\MyDll.dll" could not be added. This is not a valid
assembly or COM component. Only assemblies with extension 'dll' and COM
components can be referenced. Please make sure that the file is
accessible,
and that it is a valid assembly or COM component."

I guess its because it has to be an .NET compiled dll or am I wrong here ?
Isn't this pretty enough?.

mmh... No.. I dont like it :-) But it's the only way I can think of...

> Thomas
>
>
>
>



Nov 15 '05 #5

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

Similar topics

4
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
5
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
8
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
3
by: flat_ross | last post by:
For anyone who is just getting into VB.NET and/or is starting to work with inheritance I would like to point out a potential pitfall. We found this confusion recently when code-reviewing an...
8
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
6
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by...
8
by: =?Utf-8?B?Q2hyaXMgSGFsY3Jvdw==?= | last post by:
Hi there I've successfully added some .NET validation controls to a page (using <asp:RequiredFieldValidator ...), however when I try to set the 'display' property to 'dynamic', my page then...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.