Can I put LowLevelMouseProc and LowLevelKeyboardProc in the main EXE?

Windows global interceptors must be in the DLL because the hook will be called in the context of another process, so the hook procedure code must be injected into this process. However, there are limitations :

SetWindowsHookExcan be used to inject DLLs into another process. A 32-bit DLL cannot be injected into a 64-bit process, and a 64-bit DLL cannot be injected into a 32-bit process. If the application requires the use of hooks in other processes, it is required that a 32-bit application call SetWindowsHookExto enter a 32-bit DLL into 32-bit processes and a 64-bit application call SetWindowsHookExto enter a 64-bit DLL into 64-bit processes. 32-bit and 64-bit libraries must have different names.

For this reason, I would prefer to use lower-level hooks WH_MOUSE_LLand WH_KEYBOARD_LLinstead of WH_MOUSEand WH_KEYBOARD. As can be seen from their documentation :

This hook is called in the context of the thread that set it. The call is made by sending a message to the one that set the hook. Consequently, the thread that the hook is set to must have a message outline.

This makes me think that these specific capture procedures do not have to be in a separate DLL and can simply live inside the EXE that connected them. However, the documentation forSetWindowsHookEx says:

lpfn

[in] Pointer to a hook procedure. If the parameter dwThreadIdis equal to zero or indicates the identifier of the thread created by another process, the parameter lpfnmust point to the hook procedure in the DLL.

No explicit exception is indicated for two low-level hooks.

.NET, , DLL. , . , , .

- - , DLL EXE?

: ", , ..." ", , ...".

+3
5

dll. , (, Windows Windows). hook .Net. . http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx .

32- SetWindowsHookEx hook 32- 64- SetWindowsHookEx hook 64- .

+3

, . SetWindowsHookEx , .NET.

, , . , DLL.

+2

, , DLL, . , , , .

+1

: , - , . , , , . , , .

0

: . , WH_MOUSE_LL WH_KEYBOARD_LL :

HINSTANCE, SetWindowsHookEx, ?

0

Source: https://habr.com/ru/post/1721330/


All Articles