当我尝试从C ++ DLL调用此函数时,我一直收到System.EntryPointNotFoundException错误。
我正在使用VS 2015,这两个项目都在同一个解决方案中。 C#项目也引用了C ++项目。
DLL的头文件:
// MathLibrary.h - Contains declaration of Function class
#pragma once
#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif
namespace MathLibrary {
// This class is exported from the MathLibrary.dll
class Functions {
public:
// Returns a + b
static MATHLIBRARY_API double Add(double a, double b);
// Returns a * b
static MATHLIBRARY_API double Multiply(double a, double b);
// Returns a + (a * b)
static MATHLIBRARY_API double AddMultiply(double a, double b);
};
}
DLL的类文件:
// MathLibrary.cpp : Defines the exported functions for the DLL application.
// Compile by using: cl /EHsc /DMATHLIBRARY_EXPORTS /LD MathLibrary.cpp
#include "stdafx.h"
#include "MathLibrary.h"
extern "C" {
namespace MathLibrary {
double Functions::Add(double a, double b) {
return a + b;
}
double Functions::Multiply(double a, double b) {
return a * b;
}
double Functions::AddMultiply(double a, double b) {
return a + (a * b);
}
}
}
C#类我尝试从以下函数调用函数:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("K:\\C++\\MathLibraryAndClient\\Debug\\MathLibrary.dll")]
public static extern double Add(double a, double b);
static void Main(string[] args) {
double a; double b;
a = Console.Read();
b = Console.Read();
Add(a, b);
}
}
}
谢谢