Balloon.NET.Hooks.BaseHook.SetHook C# (CSharp) Method

SetHook() private method

private SetHook ( WindowsHook parent, IntPtr hinstance, int threadID ) : void
parent WindowsHook
hinstance System.IntPtr
threadID int
return void
		internal void SetHook(WindowsHook parent, IntPtr hinstance, int threadID)
		{
			if (handle != IntPtr.Zero)
				Dispose(false);
			
			this.parent = parent;
			
			HookProc proc = new HookProc(this.HookProc);

			handle = SetWindowsHookEx((int)Type, proc, hinstance, threadID);
			
			if (handle == IntPtr.Zero)
			{
				GC.SuppressFinalize(this);
				Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
			}
			
			this.delegateHandle = GCHandle.Alloc(proc);
		}
		

Usage Example

Beispiel #1
0
        private void AddHookEventHandler(HookType type, Type classType, Delegate value)
        {
            BaseHook key = GetHookObjectForType(type);

            if (key == null)
            {
                key = (BaseHook)Activator.CreateInstance(classType, true);

                if (threadID != 0)
                {
                    key.SetHook(this, IntPtr.Zero, threadID);
                }

                hooks.Add(key);
            }

            Events.AddHandler(key, value);
        }