开发者

How do I set a system-wide API hook in Delphi?

Does anyone know about system-wide API hooking with Delphi?

I downloaded madCodeHook, but it doesn't have any source, so I don't want use it; I want to program it myself.

I found an article on Code Project, but it i开发者_如何学Gos in C++. Please help me to write it in Delphi 2010.


@Phoenix, you can try uallCollection library, is written in delphi 7 (i've tested in delphi 2007 and it works ok) , and comes with an set of examples wich can download from here and full sourcecode. the only drawback is has not been updated since 07-07-2006, but personally i've tested this library even on Windows 7 and it works ok.


you have to use hook procedures (global : entire system; or local : a single program or thread).

Basically, you'll be calling the following procedures :

  • The SetWindowsHookEx function : to install a hook (monitor system event)
  • The hook function : which is the procedure to be called by windows when the event we "hook" to happens.
  • The UnhookWindowsHookEx function : to remove your hook

Here is a simple example of a local hook monitoring keyboard entries:

//setting up the hook;
//kbHook is a variable of type HHook (unit Windows);
//kbr_Hook is the procedure that will be called once the event happens;
kbHook:=setwindowshookex(WH_KEYBOARD,@kbr_Hook,0,GetCurrentThreadID()); 

MSDN documentation: http://msdn.microsoft.com/en-us/library/ms644990%28VS.85%29.aspx

good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜