[gelöst]Probleme bei SetWinEventHook



  • Für mein aktuelles Projekt bräuchte ich einen WinEventHook, allerdings bereitet mir der als c++ Anfänger Probleme. Hier nun erstmal der Code den ich bis jetzt habe:

    #include "stdafx.h"
    #include <windows.h>
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    
    VOID CALLBACK WinEventsProc( HWINEVENTHOOK /*hWinEventHook*/,
    							DWORD dwEvent,
    							HWND hwnd,
    							LONG idObject, 
    							LONG /*idChild*/, 
    							DWORD /*dwEventThread*/, 
    							DWORD /*dwmsEventTime*/ )
    {
            if (dwEvent == EVENT_OBJECT_CREATE){
    			cout << "Hook not started!";
            }
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
    HWINEVENTHOOK hWINHOOK = SetWinEventHook( EVENT_MIN,
    											EVENT_MAX,
    											NULL,
    											WinEventsProc,
    											0,
    											0,
    											0);
    
    if( hWINHOOK!= NULL )
    {
    	cout << "Wineventhook gestartet";
    	while(true){
    Sleep(100);
    
    	}
    
    }
    return 0;
    }
    

    Ansich müßte hier ja alles stimmen. Das Handle zum Wineventhook ist bei der Ausführung nicht NULL, trotzdem bekomme ich kein einziges Event in meiner Callback-Funktion. Meiner Meinung nach ist der Hook aber auch richtig initialisiert. Nach 2 Tage herumprobieren bin ich nun ziemlich ratlos, und hab keine Ahnung wieso das Ding nicht läuft.
    Bin für jede Hilfe dankbar :p



  • Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x) in das Forum WinAPI verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.


  • Mod

    Wie immer ist es ratsam einfach mal die Doku zu lesen:
    SetWinEventHook
    http://msdn.microsoft.com/en-us/library/dd373640(VS.85).aspx

    The client thread that calls SetWinEventHook must have a message loop in order to receive events.

    Da Du keine hast und Deinen Prozess auch noch mit Sleep blockierst wundert mich nichts

    2. dwFlags==0 ?

    The following flag combinations are valid:

    WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS
    WINEVENT_INCONTEXT | WINEVENT_SKIPOWNTHREAD
    WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS
    WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNTHREAD



  • oh, das mit dem loop hab ich übersehen. ich werde das heute abend nach der arbeit probieren. vielen dank für die hilfe



  • ok geht nun danke


Anmelden zum Antworten