Interop between C# and C++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

I am very new to the .Net development and now I am facing a challenge that I will need to call a class member function developed in C++ ( visual studio 6) by a C# program
an illusion will be
C+
class a

public
void test()


C

I need to call that test function and I am not sure how

any direction on how to do so and where to find information is highly appreaciated.

Thank

Michael
 
For this simple example something like this should do it:

class Tester
{
[DllImport("test.dll")]
public static extern void Test();

public static void Main()
{
Test();
}
}

(of course the C++ function also needs to be exported)

If it really is just a few simple RPC type calls, this should be OK.
But if you are looking for a more object/component based interaction, it may
be worth looking at wrapping your C++ code as COM objects.
There are plenty of "complications" related to marshalling data to & fro.

The "keywords" to look for on MSDN/Google are "PInvoke" and "COM interop".

Richard.


Michael said:
Hi All,

I am very new to the .Net development and now I am facing a challenge that
I will need to call a class member function developed in C++ ( visual studio
6) by a C# program.
 
There is no way to call C++ instance methods from C#, simply because you
can't create an instance of a native ++ class using C#.
One option is to wrap this class in a managed class using ME C++.

Willy.
 
Back
Top