I am trying to use a runtime DLL but after I have called LoadLibrary (which is successful) GetProcAddress is returning NULL. I know the DLL is correct as I got it working by including it at load time (inluding the header and lib as well as the dll) in another project.
This is the header file for the DLL:
#define DLLDIR _declspec(dllexport)
void DLLDIR DLLfun1(char*);
int DLLDIR DLLfun2(int);
extern int DLLDIR DLLArg;
class DLLDIR DLLclass
{
public:
DLLclass();
~DLLclass();
int Add(int, int);
int Sub(int, int);
int Arg;
};
And this is the source file where I call GetProcAddress:
#include <iostream>
#include <windows.h>
using namespace std;
typedef void (*FUNC1)(char*);
typedef int (*FUNC2)(int);
int main()
{
FUNC1 pfun1;
FUNC2 pfun2;
HMODULE hMod;
hMod = LoadLibrary(L"RunTime_DLL.dll");
pfun1 = (FUNC1) GetProcAddress(hMod, "DLLfun1");
pfun2 = (FUNC2) GetProcAddress(hMod, "DLLfun2");
DWORD dRes = GetLastError();
(pfun1)("Hello World\n");
int a = (pfun2)(30);
cout << a;
bool bRes = FreeLibrary( hMod );
system("Pause");
}
I called GetLastError and it returned 127 which is:
The specified procedure could not be found. ERROR_PROC_NOT_FOUND
I don't understand why it can't find the function in the DLL! Especially since I have, like I mentioned, used the functions when loading the DLL at load time.
Any help will be great thanks