public DcsMarshalledProxy(IDcsMarshalledObserver target, Type t) { Contract.Requires(target != null); Contract.Requires(t != null); this.dcs = new DataContractSerializer(t); this.T = t; this.Target = target; }
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 static IWpfWindowHook Hook(WpfHookRegistrationRecord record, IDcsMarshalledObserver observer) { // get visual var hwndSource = HwndSource.FromHwnd(record.HWnd); if (hwndSource == null) { throw new InvalidOperationException($"HwndSource 0x{record.HWnd.ToInt32():x8} not found"); } var rootVisual = hwndSource.RootVisual; if (rootVisual == null) { throw new InvalidOperationException("RootVisual is null"); } // get result source var resultType = record.ResultType; var tObserver = typeof(IObserver <>).MakeGenericType(resultType); var tSource = typeof(DcsMarshalledProxy <>).MakeGenericType(resultType); var tSourceCtor = tSource.GetConstructor(new[] { typeof(IDcsMarshalledObserver) }); var resultSource = tSourceCtor.Invoke(new object[] { observer }); // instantiate hook var tHandler = record.HookType; var tParam = record.ParameterType; if (tParam == null) { var ctor = tHandler.GetConstructor(new[] { typeof(Visual), tObserver }); if (ctor != null) { return((IWpfWindowHook)ctor.Invoke(new object[] { rootVisual, resultSource })); } } else { var ctor = tHandler.GetConstructor(new[] { typeof(Visual), tObserver, tParam }); if (ctor != null) { return((IWpfWindowHook)ctor.Invoke(new object[] { rootVisual, resultSource, record.Parameter })); } } throw new NotSupportedException($"No suitable constructor found. Should be .ctor(System.Windows.Media.Visual, {tObserver.FullName}, {tParam.FullName})"); }
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 IWpfWindowHook RegisterWpfHook(WpfHookRegistrationRecord hook, IDcsMarshalledObserver observer) { return(WpfHookManager.Hook(hook, observer)); }
public IWindowHook RegisterHook(HookRegistrationRecord hook, IDcsMarshalledObserver observer) { return(HookManager.AddRegistration(hook, observer)); }