// ------------------------------------------------------
        //
        // Private Methods
        //
        // ------------------------------------------------------

        // Enables the notification of WinEvents.
        // This function must be called once for each WinEvent to track.
        private static void StartListening(ref EventHookParams hp)
        {
            NativeMethods.WinEventProcDef proc = new NativeMethods.WinEventProcDef(WinEventProc);

            uint processId = hp._process;

            // The console window is special.  It does not raise its own WinEvents.  The CSRSS raises the
            // WinEvents for console windows.  When calling SetWinEventHook use the CSRSS process id instead of the
            // console windows process id, so that we receive the WinEvents for the console windows.
            if (IsConsoleProcess((int)processId))
            {
                try
                {
                    processId = CSRSSProcessId;
                }
                catch (Exception e)
                {
                    if (Misc.IsCriticalException(e))
                    {
                        throw;
                    }

                    processId = hp._process;
                }
            }

            hp._procHookHandle = GCHandle.Alloc(proc);
            hp._winEventHook   = Misc.SetWinEventHook(hp._evtId, hp._evtId, IntPtr.Zero, proc, processId, 0, NativeMethods.WINEVENT_OUTOFCONTEXT);
        }
Beispiel #2
0
        private void Init()
        {
            // Keep the garbage collector from moving things around
            _winEventProc = new NativeMethods.WinEventProcDef(WinEventReentrancyFilter);
            _gchThis      = GCHandle.Alloc(_winEventProc);

            _clientCallbacks = new ArrayList(2);
            _qEvents         = new Queue(16, (float)2.0); // (initial cap, growth factor)
            _fFlags          = NativeMethods.WINEVENT_OUTOFCONTEXT;
        }
Beispiel #3
0
 internal static extern IntPtr SetWinEventHook(int eventMin, int eventMax, IntPtr hmodWinEventProc, NativeMethods.WinEventProcDef WinEventReentrancyFilter, uint idProcess, uint idThread, int dwFlags);
Beispiel #4
0
        private void Init()
        {
            // Keep the garbage collector from moving things around
            _winEventProc = new NativeMethods.WinEventProcDef(WinEventReentrancyFilter);
            _gchThis = GCHandle.Alloc(_winEventProc);

            _clientCallbacks = new ArrayList(2);
            _qEvents = new Queue(16, (float)2.0); // (initial cap, growth factor)
            _fFlags = NativeMethods.WINEVENT_OUTOFCONTEXT;
        }
Beispiel #5
0
        // ------------------------------------------------------
        //
        // Private Methods
        //
        // ------------------------------------------------------

        // Enables the notification of WinEvents.
        // This function must be called once for each WinEvent to track.
        private static void StartListening (ref EventHookParams hp)
        {
            NativeMethods.WinEventProcDef proc = new NativeMethods.WinEventProcDef (WinEventProc);

            uint processId = hp._process;
            // The console window is special.  It does not raise its own WinEvents.  The CSRSS raises the
            // WinEvents for console windows.  When calling SetWinEventHook use the CSRSS process id instead of the
            // console windows process id, so that we receive the WinEvents for the console windows.
            if (IsConsoleProcess((int)processId))
            {
                try
                {
                    processId = CSRSSProcessId;
                }
                catch (Exception e)
                {
                    if (Misc.IsCriticalException(e))
                    {
                        throw;
                    }

                    processId = hp._process;
                }
            }

            hp._procHookHandle = GCHandle.Alloc (proc);
            hp._winEventHook = Misc.SetWinEventHook(hp._evtId, hp._evtId, IntPtr.Zero, proc, processId, 0, NativeMethods.WINEVENT_OUTOFCONTEXT);
        }