Skip to main content
gamedev.net
🔒 Locked

GetProcAddress Function Returns NULL For Hook Proc

Started by LlamaFood 3 replies 1.2k views
Original Post
LlamaFood
LlamaFood
I'm making a global hook but for some reason GetProcAddress is returning NULL. Here's my WM_CREATE msg:
case WM_CREATE:
	HOOKPROC KBhkprc; 
	static HINSTANCE DLL;
	DLL=LoadLibrary((LPCTSTR)("c:\\hook.dll"));
	KBhkprc=(HOOKPROC)GetProcAddress(DLL,"KBHkPrc");
	if(KBhkprc==NULL) {
		MessageBox(0,"GetProcAdress Returns NULL",0,MB_OK);
	}
	kbhook=SetWindowsHookEx(WH_SYSMSGFILTER,KBhkprc,DLL,0);
And here's my DLL header:
#include <windows.h>

__declspec(dllexport) LRESULT __cdecl KBHkPrc(int code,WPARAM wParam,LPARAM lParam);
SiCrane
SiCrane
I'm guessing it's a name mangling issue. Try declaring your KBHkPrc() function as extern "C" in your DLL or using a .DEF file to create the exports.
Jimmy Valavanis
Jimmy Valavanis
and to be source that DLL is loaded add:

	DLL=LoadLibrary((LPCTSTR)("c:\\hook.dll"));	if(DLL==NULL) {		MessageBox(0,"Can not load DLL",0,MB_OK);                return();	}	KBhkprc=(HOOKPROC)GetProcAddress(DLL,"KBHkPrc");	if(KBhkprc==NULL) {		MessageBox(0,"GetProcAdress Returns NULL",0,MB_OK);	}	kbhook=SetWindowsHookEx(WH_SYSMSGFILTER,KBhkprc,DLL,0);
chollida1
chollida1
SiCrane is correct. Alternativly you could export your method using a defs file.

Try opeingin your dll in dependancy walker and see the name it exports.

Cheers
Chris
CheersChris
hplus0603
hplus0603
Use dumpbin to figure out the actual name of your function. Or depends.exe. Both come with Visual Studio.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.