public HookRegistration(HookRegistrationRecord hook, IDcsMarshalledObserver observer, HookManager parent)
            {
                Contract.Requires(observer != null);

                this.HWnd    = hook.HWnd;
                this.Parent  = parent;
                this.Handler = hook.CreateHandler();
                this.Target  = new DcsMarshalledProxy(observer, hook.ResultType);
            }
        public ForeignHook <T> HookWindow <T>(IntPtr hWnd, Type tHandler, object oParam = null)
            where T : class
        {
            Contract.Requires(tHandler != null);
            Contract.Requires(typeof(IMessageHookHandler <T>).IsAssignableFrom(tHandler));

            var source = new DcsMarshalledSource <T>();
            var record = HookRegistrationRecord.Create(hWnd, tHandler, typeof(T), oParam);
            var rh     = Hook.RegisterHook(record, source.ComProxy);

            return(new ForeignHook <T>(rh, source));
        }
        public IWindowHook AddRegistration(HookRegistrationRecord hook, IDcsMarshalledObserver observer)
        {
            Contract.Requires(observer != null);

            var newReg = new HookRegistration(hook, observer, this);

            lock (syncRegistrations)
            {
                Registrations = Registrations.SetItem(hook.HWnd, newReg);
                Debug.WriteLine("Added hook for {0:x8}", hook.HWnd.ToInt32());

                if (Hook == null)
                {
                    Debug.WriteLine("Starting ITP Hook for thread {0}", mainThreadId);
                    Hook = new HookLifetimeManager(Hook_HookCallback);
                }
            }
            return(newReg);
        }
 public IWindowHook RegisterHook(HookRegistrationRecord hook, IDcsMarshalledObserver observer)
 {
     return(HookManager.AddRegistration(hook, observer));
 }