I keep getting a System.EntryPointNotFoundException error when I try to call this function from a C++ DLL.
I'm using VS 2015 and these two projects are in the same solution. The C# project also references the C++ project.
Header file for 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);
};
}
Class file for 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# class I try to call the functions from:
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);
}
}
}
Thank you