• Advertisement
Sign in to follow this  

GetProcAddress Function Returns NULL For Hook Proc

This topic is 4841 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'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
Advertisement
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
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
Sign in to follow this  

  • Advertisement