calling cpp file from c#

O

Ohad

Hi,

Can I use c++ source files in my c# project, and in c# call the c++ classes?
If so, how can I do it?

please cc to my mailbox: (e-mail address removed)

Thanks a lot
Ohad
 
W

Willy Denoyette [MVP]

Ohad said:
Hi,

Can I use c++ source files in my c# project, and in c# call the c++
classes?
If so, how can I do it?

No, you can't use C++ in a C# project.
You don't CALL classes, you CREATE INSTANCES of c++ classes and you call
methods of these classes, however, this is not possible from C#. One option
is to wrap your C++ classes with managed C++ classes (using VS2003 MC++)
that delegate the method call's.

Willy.
 
T

thomas

Hi,

I wraped my C++ classes and it works fine.
There is an other problem. I defined two wrapper classes and I want to use
one of these class to construct an instance the other wrapper class. But the
c# compiler complained and throw an error:

e.g.
c++
public __gc Class1 { ... };
public __gc Class2 {
Class2(Class1 c1, Class1 c2) {... }
};

c##

namespace NewNamespace

Class1 a1, b1;
...
Class2 c2 = new Class2(a1, b1); <-- compiler throw an error

error: NewNamespace::Class1 cannot be converted to Class1

Is there anybody whoe know why it not works?

Thanks in advance
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top