C#/C++ простой код библиотеки Си++ подключаю в Си шарп (внутри)
// MathFuncsDll.h
namespace MathFuncs
{
class MyMathFuncs
{
public:
// Returns a + b
static __declspec(dllexport) double Add(double a, double b);
// Returns a - b
static __declspec(dllexport) double Subtract(double a, double b);
// Returns a * b
static __declspec(dllexport) double Multiply(double a, double b);
// Returns a / b
// Throws DivideByZeroException if b is 0
static __declspec(dllexport) double Divide(double a, double b);
};
}
==========
// MathFuncsDll.cpp
// compile with: /EHsc /LD
#include "MathFuncsDll.h"
#include
using namespace std;
namespace MathFuncs
{
double MyMathFuncs::Add(double a, double b)
{
return a + b;
}
double MyMathFuncs::Subtract(double a, double b)
{
return a - b;
}
double MyMathFuncs::Multiply(double a, double b)
{
return a * b;
}
double MyMathFuncs::Divide(double a, double b)
{
if (b == 0)
{
throw new invalid_argument("b cannot be zero!");
}
return a / b;
}
}
==========
==========
[DllImport("MathFuncsDll.dll", CharSet = CharSet.Unicode)]
public static extern double Multiply(double A, double B);
private void button4_Click(object sender, EventArgs e)
{
double temp = Multiply(3, 4);
}
ПИШЕТ МОЛ "Не удается найти точку входа "Multiply" в DLL "MathFuncsDll.dll"."