SetWindowsHookEx Rückgabewert Null



  • Hi,

    ich möchte alle Mausklicks von Windows abfangen, dazu hab ich mir eine DLL gebastelt und eine MouseHook Funktion eingebaut

    der Code wird fehlerfrei kompiliert, aber mein Rückgabewert ist immer NULL
    wenn ich den HOOK installieren will, habe keine Ahnung warum, habt Ihr ne Ahnung was ich da falsch gemacht hab?

    Hier ein bischen Code:

    BOOL CALLBACK InstallMouseHook(void)
    {
    hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, NULL, 0);
    if (hMouseHook == NULL)
    {
    return FALSE;
    }
    return TRUE;

    }

    LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    if(nCode < 0)
    return CallNextHookEx(hMouseHook, nCode, wParam, lParam);

    if(nCode == HC_ACTION)
    {
    if(wParam == WM_LBUTTONDOWN)
    {
    clicks++;
    }
    }

    return CallNextHookEx(MouseHook, nCode, wParam, lParam);
    };



  • Aus MSDN (die letzten 2 Parameter):

    hMod
    [in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
    dwThreadId
    [in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.

    Danach muss einer der 2 Parameter != 0 sein !



  • 🙂
    Danke,

    hab nur den hInstance meiner DLL in den 3 Param rein, dann funzt es.


Anmelden zum Antworten