1

Possible Duplicate:
Possible to call C++ code from C#?

I have C++ class, that have some static method. It is in the dll, that exports class. I need to use static method from C# project. Can I do it without COM?

Community
  • 1
  • 1
HelloHi
  • 165
  • 2
  • 10

2 Answers2

2

COM would be a good way to do it (other than the fact that COM doesn't support static methods...)

Another way is to turn the class into a C++/CLI managed class like this:

public ref class MyClass
{
public:
    static void StaticMethod()
    {
        ...
    }
};

A C++/CLI managed class in a DLL will be visible to C# just as if it were a C# class.

If you don't want to turn the C++ project into a C++/CLI project, you can create a C++/CLI project containing a managed class which just wraps the unmanaged class in the unmanaged C++ project.

user1610015
  • 6,561
  • 2
  • 15
  • 18
1

you have 2 ways:

wrapping the native C++ dll with a C++\CLI one or using PInvoke

makc
  • 2,569
  • 1
  • 18
  • 28