GetProcAddress() returning NULL!

Started by
3 comments, last by DOrmisher 15 years, 3 months ago
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
She got a hat and all that hat says is asshole
Advertisement
You're probably experiencing name mangling issues. Try declaring the functions as extern "C" or using .DEF file for the DLL exports.
So from looking at it the code looks ok? What do you mean by using .DEF file for the DLL exports?
She got a hat and all that hat says is asshole
google search for ".def file"
SICrane you are a hero, i messed about with this for 4 hours the other day, adding extern C did work...I've seen it a few times while I've been researching but I didn't think I'd need it.

Thanks again
She got a hat and all that hat says is asshole

This topic is closed to new replies.

Advertisement