Sign in to follow this  
LlamaFood

GetProcAddress Function Returns NULL For Hook Proc

Recommended Posts

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

Share this post


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

Share this post


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



Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this