开发者

Multiple keyboard hooks in .NET and Delphi

I have an application with both .NET and Delphi components I register to a keyboard hook (with SetWindowsHookEx) in both components. I first register in .NET, and later in Delphi.

The problem is, 开发者_StackOverflow中文版the hook delegate in Delphi is called before the hook delegate in .NET.

According to MSDN, the hook chain is just a list, and as I understand the delegates should be called according to the order of registration.

Anyone has an idea what is going on here? Thanks in advance!


You've misunderstood. The hook overview in MSDN describes it like this (emphasis added):

The SetWindowsHookEx function always installs a hook procedure at the beginning of a hook chain. When an event occurs that is monitored by a particular type of hook, the system calls the procedure at the beginning of the hook chain associated with the hook. Each hook procedure in the chain determines whether to pass the event to the next procedure. A hook procedure passes an event to the next procedure by calling the CallNextHookEx function.

Therefore, it's precisely the expected behavior if your Delphi hook is installed last and is called first. There's nothing "going on" at all.


The hook list is not a list, but a chain. Newly installed hook keeps the reference to the previous one. This means that the hook, installed later, is always executed before the hook installed earlier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜