Mình cũng bị lỗi có mã 1428: Cannot set nonlocal hook without a module handle.
Ở đây, AlexF sử dụng kiểu hook toàn hệ thống, nhưng để thủ tục hook nằm cùng file với hàm main().
nên mới có lỗi đó.
A global hook procedure can be called in the context of any application in the same desktop as the calling thread, so the procedure must be in a separate DLL module.

Mình lấy id của thread hiện tại và cho vào tham số thứ 4, thì ko có lỗi 1428 nữa nhưng ko ra được dòng BAN DA BI HOOK CUC BO BAN PHIM khi mình nhấn và nhả phím Enter. Có cách nào sửa lỗi này ko nhỉ? [IMG]images/smilies/applause.gif[/IMG]


Mã:
#include "stdafx.h"#include <windows.h>#include <stdio.h>#include <tchar.h>#include <conio.h> LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam );int _tmain(int argc, _TCHAR* argv[]){    HINSTANCE appInstance = GetModuleHandle(NULL);    DWORD thread_id = GetCurrentThreadId();    printf("
 0x%X",appInstance);    // Set a global Windows Hook to capture keystrokes    if(SetWindowsHookEx(WH_KEYBOARD, LowLevelKeyboardProc,appInstance, thread_id) == NULL)    {        printf("
Error: %d", GetLastError());        _getch();        return 0;    }    // Get information from the user    MSG msg;    while(GetMessage(&msg,NULL,0,0) > 0)     {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    return 0;} LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam){    if((wParam == 13) && (HC_ACTION == nCode))    {        printf("BAN DANG BI HOOK CUC BO BAN PHIM
");    }    return CallNextHookEx(NULL, nCode,wParam, lParam);    return 0;}