1

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, 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!

1
  • Could you please cite the part of MSDN that confused you? Give a link and a brief quotation. Commented Aug 29, 2010 at 17:27

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I don't know how I missed that, need to sleep more.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.