After a long reading time I didn't get the dll working...
I tried so much different ways but no way worked..
I did the following things: (IDE: VS2013Ultimate)
I added a clean c++ project. There I added 1 header file [header.h]:
#pragma once class myClass{ public: myClass(double varx, double vary); double sumxy(); private: double x; double y; };
I added a body.cpp file:
#pragma once #include "header.h" myClass::myClass(double varx, double vary){ x = varx; y = vary; } double myClass::sumxy(){ return x + y; }
That's all the code I would need. I only want a working example code.
I added one class [main.cpp]:
#include "header.h" #include "body.cpp" extern "C" __declspec(dllexport) double sumxy(double var_x, double var_y){ myClass MC(var_x, var_y); return MC.sumxy(); }
After this I compiled this dll and I got it without any compile errors. `I copied it to the debug folder of the c# Console Application
C# Console Application:
using System.Runtime.InteropServices; //all using directories namespace Klassen_Tester { class Program { [DllImport("CppClassDll.dll")] public static extern double sumxy(double var_x, double var_y); static void Main(string[] args) { Console.WriteLine(sumxy(3, 5).ToString()); Console.ReadLine(); } } }
Please help me. Don't know what to do.. And sorry for my bad english.
Edit: There is an error: System.DllNotFoundException in Klassen_Tester.exe. DLL "CppClassDll.dll" could not be found. HRESULT: 0x8007007E) could not be load.