• Advertisement
Sign in to follow this  

GetProcAddress() returning NULL!

This topic is 3355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
	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;
	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 );

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

Share this post

Link to post
Share on other sites
You're probably experiencing name mangling issues. Try declaring the functions as extern "C" or using .DEF file for the DLL exports.

Share this post

Link to post
Share on other sites
So from looking at it the code looks ok? What do you mean by using .DEF file for the DLL exports?

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement