WinEventHook: what happen when the thread that installed the event hook ends?

I did some testing and noticed that when the thread that installed an event hook ends (or is killed) the callback function is no longer called, as if the hook ended together with the thread.

However, the documentation says to call UnhookWinEvent from the same thread that installed the event, which is not possible if the thread is no longer alive.

Therefore, if the thread that installed the event hook terminates unexpectedly before calling UnhookWinEvent, what happens? Does some problem occur? Or does the event hook terminate together with the thread, as if UnhookWinEvent had been called?

>Solution :

You probably ought to have read that documentation you linked to:

If the client’s thread ends, the system automatically calls this
function.

Leave a Reply