Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a DLL for system wide hooks

Status
Not open for further replies.

Muzzery

Programmer
Jan 11, 2002
72
0
0
GB
Can anybody tell me how to create a DLL file for a System Wide hook please?

I have no idea how it's done.

Thanks,

muzz :)
 
[ul][li]First create a DLL with an exported function that is used as the hooking function.

__declspec(dllexport) LRESULT CALLBACK HookFunction(int code,WPARAM wParam,LPARAM lParam)
{ blah blah....
}
[/li]

[li]Secondly install the system-wide hook. To install the hook, the DLL must be loaded, the hook function's address retrieved, and SetWindowsHookEx called with the function's address.

hHookDll = LoadLibrary("hook");
hHookProc = (HOOKPROC) GetProcAddress(hHookDll, "HookFunction");

// Install the hook to trap all keyboard messages
hSystemHook = SetWindowsHookEx(WM_xxxx,hHookProc,hHookDll,0);
[/li]

[li]Finally, unhook and release when you are done

UnhookWindowsHookEx(hSystemHook);
FreeLibrary(hHookDll);
[/li][/ul]
 
Thanks for the reply. I think i understand how to set the System-Wide hook, but you could you clarify what it is i have to do to write a DLL, and how to do it?

I have VB5 which i know i can use, but i have no idea how to write it.

Thanks

muzz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top