| TestCSharpLibrary.cs using System; using System.Runtime.InteropServices;
namespace TestCSharpLibrary { public class TestCSharpLibrary { // From c++ DLL (unmanaged) [DllImport("TestCPPLibrary")] public static extern float TestMultiply(float a, float b);
// From c++ DLL (unmanaged) [DllImport("TestCPPLibrary")] public static extern float TestDivide(float a, float b);
[DllImport("TestCPPLibrary")] public static extern int ReturnInteger(int a);
public static float SharpMultiply(float a, float b) { return (a * b); }
public static float SharpDivide(float a, float b) { if(b==0) { return 0; }
return (a / b); } } }
|
|
TestCPPLibrary.cpp #include "TestCPPLibrary.h" extern "C" { // int i=5;
float TestMultiply(float a, float b) { return a * b; }
float TestDivide(float a, float b) { if (b == 0) { return 0; }
return a / b; }
int ReturnInteger(int a) { return a; } }
|
| TestCPPLibrary.h #ifdef TESTFUNCDLL_EXPORT #define TESTFUNCDLL_API __declspec(dllexport) #else #define TESTFUNCDLL_API __declspec(dllimport)
|