I have an unmanaged C ++ dll for which I do not have access to the code, but have all the method declarations for.
Lets say for simplicity that .h looks like this:
#include <iostream> #ifndef NUMERIC_LIBRARY #define NUMERIC_LIBRARY class Numeric { public: Numeric(); int Add(int a, int b); ~Numeric(); }; #endif
and method implementation in .cpp file
int Numeric::Add(int a, int b) { return (a + b); }
I just want to call the add function from C ++ to my C # code:
namespace UnmanagedTester { class Program { [DllImport(@"C:\CPP and CSharp Project\UnmanagedNumeric\Debug\numeric.dll", EntryPoint = "Add")] public static extern int Add(int a, int b); static void Main(string[] args) { int sum = Add(2, 3); Console.WriteLine(sum); } } }
After trying to execute, I have the following error:
Cannot find entry point named "Add" to DLL "C: \ CPP and CSharp Project \ UnmanagedNumeric \ Debug \ numeric.dll".
I can not change the code in C ++. I donβt know what is going on. Appreciate your help.
source share