private static IHookedProcess GetHookedProcess(IntPtr hWndTarget, string moniker) { var createMutex = new Mutex(initiallyOwned: false, name: moniker); // get the mutex try { createMutex.WaitOne(); } catch (AbandonedMutexException) { // no-op, still received mutex } try { // check if it is already installed try { return((IHookedProcess)RotRegistration.GetRegisteredObject(moniker)); } catch (KeyNotFoundException) { // no-op, we need to inject } // install Injector.InstallHook(hWndTarget, typeof(Server.MdiHookTarget), null); return((IHookedProcess)RotRegistration.GetRegisteredObject(moniker)); } finally { createMutex.ReleaseMutex(); } }
internal static HookedProcess GetInstance() { lock (SyncCreateInstance) { if (Instance != null) { return(Instance); } Instance = new HookedProcess(); RotRegistration = new RotRegistration(IpcConstants.GetRotMonikerName(Process.GetCurrentProcess().Id), Instance); return(Instance); } }