|
I have the same problem, my C ++ dll header file is as follows:
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);
};
}
Then it can be called in C ++, but encountered problems in C #.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MyCSharpExecRefsDll
{
class Program
{
static void Main (string [] args)
{
myWin32 mywin32 = new myWin32 ();
Console.WriteLine (myWin32.Add (3, 4));
}
public class myWin32
{
[DllImport ("MathFuncsDll1.dll")]
public static extern double Add (double a, double b);
[DllImport ("MathFuncsDll1.dll")]
public static extern double Subtract (double a, double b);
[DllImport ("MathFuncsDll1.dll")]
public static extern double Multiply (double a, double b);
[DllImport ("MathFuncsDll1.dll")]
public static extern double Divide (double a, double b);
}
}
}
When calling, always say there is no such entry.
Unable to find entry point named "Add" in DLL "MathFuncDll1.dll" |
|