Use C++ class in C#  
Author Message
LouisPeter





PostPosted: Visual C# General, Use C++ class in C# Top

I have a c++ class implemented in a dll, and then I have my main in C#, where I call the functions of the dll. My problem is to know how to declare and use an object of the class that I have in the dll in c++. I think I have to declare the class also in the c# project and then use the DLLimport command but I'm not sure... Can someone help Thanks

Visual C#11  
 
 
RizwanSharp





PostPosted: Visual C# General, Use C++ class in C# Top

Create a class:

public static class MyNativeClass

{

[DllImport("someDll.dll")] // Your DLL name / complete path from where it should load (better copy in debug or release and use as in example
public static extern void NativeFunction(int number);

// Repeat the same for all your function in that dll

}

not call function from C#

MyNativeClass.NativeFunction(1);

or remove the static keyword to make your class nonstatic, create an object and call like:

MyNativeClass nativeObject = new MyNativeClass();

nativeObject.NativeFunction(1);

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp