My linux world » cs call unmanaged c/c++ code

cs call unmanaged c/c++ code


C/C++ code

Let’s create Test.dll library :

// Compile with: /LD
int __declspec(dllexport) sum(int a,int b) {
  return a+b;
}

C# code

Import library

 [DllImport("Test.dll"]
  public static extern int sum(int a,int b);

Now you can use it like this

int result = sum(3,4);

Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.