/// <summary> /// This method is executed when the application has started and the /// message loop is running. /// </summary> private static void Bootstrap() { // Determine the other process state. WmOtherProcess other = new WmOtherProcess(); other.FindOtherProcess(); // Another KWM we own is running in our session. if (other.State == WmOtherProcessState.OurInCurrentSession) { // Send the other KWM a message to import the credentials. if (ImportKwsPath != "") { SendMsgToOtherKwm(other, ImportKwsMsgID, ImportKwsPath); } // Show the instance of the other KWM. SendMsgToOtherKwm(other, ForegroundMsgID, ""); // We're done. RequestAppExit(); } // Warn the user. else if (other.State == WmOtherProcessState.NotOurInCurrentSession || other.State == WmOtherProcessState.OurInOtherSession) { String error = (other.State == WmOtherProcessState.NotOurInCurrentSession) ? "A " + KwmStrings.Kwm + " started by another user is already running." : "A " + KwmStrings.Kwm + " started by another user is already running."; WmUi.TellUser(error, "Cannot start " + KwmStrings.Kwm, MessageBoxButtons.OK, MessageBoxIcon.Error); RequestAppExit(); } // Enter the main mode. else { try { if (!EnterMainMode()) { RequestAppExit(); } } catch (Exception ex) { KBase.HandleException(ex, true); } } }
/// <summary> /// Send the message specified to the other KWM specified, if possible. /// </summary> private static void SendMsgToOtherKwm(WmOtherProcess other, UInt32 msgID, String path) { try { // Wait 10 seconds for the other process to finish initializing, // then send the message. if (other.OtherProcess != null && other.OtherWindowHandle != IntPtr.Zero && other.OtherProcess.WaitForInputIdle(10 * 1000)) { KSyscalls.COPYDATASTRUCT cds; cds.dwData = new IntPtr(msgID); cds.lpData = path; cds.cbData = Encoding.Default.GetBytes(path).Length + 1; KSyscalls.SendMessage(other.OtherWindowHandle.ToInt32(), KSyscalls.WM_COPYDATA, 0, ref cds); } } catch (Exception) { } }
/// <summary> /// This method is executed when the application has started and the /// message loop is running. /// </summary> private static void Bootstrap() { // Determine the other process state. WmOtherProcess other = new WmOtherProcess(); other.FindOtherProcess(); // Another KWM we own is running in our session. if (other.State == WmOtherProcessState.OurInCurrentSession) { // Send the other KWM a message to import the credentials. if (ImportKwsPath != "") SendMsgToOtherKwm(other, ImportKwsMsgID, ImportKwsPath); // Show the instance of the other KWM. SendMsgToOtherKwm(other, ForegroundMsgID, ""); // We're done. RequestAppExit(); } // Warn the user. else if (other.State == WmOtherProcessState.NotOurInCurrentSession || other.State == WmOtherProcessState.OurInOtherSession) { String error = (other.State == WmOtherProcessState.NotOurInCurrentSession) ? "A " + KwmStrings.Kwm + " started by another user is already running." : "A " + KwmStrings.Kwm + " started by another user is already running."; WmUi.TellUser(error, "Cannot start " + KwmStrings.Kwm, MessageBoxButtons.OK, MessageBoxIcon.Error); RequestAppExit(); } // Enter the main mode. else { try { if (!EnterMainMode()) RequestAppExit(); } catch (Exception ex) { KBase.HandleException(ex, true); } } }