I'm about to develop a API that should be distributed with a DLL. Because I can't test my code written in the DLL directly, I have to load the DLL within a Test-Project and run it there.
I'm using Visual Studios 2015. There I made a Testproject and within that, I made my Project for the DLL:
Solution-Tree "TestProject"
DLLProject
TestProject
I export a dummy function to test if I am able to load the DLL:
#ifndef EXPORT
#define EXPORT __declspec(dllexport)
#endif
extern "C" {
EXPORT int dummy() {
return 5;
}
}
Then, in my Testproject, I try to load the DLL, extract the function and run it:
#include <windows.h>
#include <iostream>
using namespace std;
typedef int (__stdcall *dll_func)();
int main() {
HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("H:\\path\\to\\project\\Debug\\DLLProject\\DLLProject.dll"));
if (hGetProcIDDLL == NULL) {
cout << "DLL could not be loaded. " << GetLastError() << endl;
return;
}
dll_func f = (dll_func)GetProcAddress(hGetProcIDDLL, "create");
if (f == NULL) {
cout << "Factory function could not be resolved. " << GetLastError() << endl;
return;
}
cout << "Factory function returns: " << f() << endl;
}
I copied almost everything from this question. Unfortunately, when I run my Testproject, my console prints out: "DLL could not be loaded. 4250"
At this point I really don't know what to do because the Error as described here basicly says nothing. With a bit of research, I couldn't get any answers... hope you can help me :D