/// <summary> /// parse the passed args. send the first entry of the array to the running instance. /// the entry is send through win32 api and handled in the MainForm. /// /// 2007-10-02 T.Norad: added /// </summary> /// <param name="args">program arguments. maybe a stealthnet link</param> /// <returns>true, if the message was sent to running stealthnet instance</returns> public static Boolean SendStealthNetLinkToOpenClient(String[] args) { Boolean messageSent = false; if (args != null && args.Length > 0) { // get handle of the stealthnet main window to send the link to int handle = Win32APIWrapper.FindWindow(null, String.Format(Constants.Software, Core.Version)); if (handle != 0) { // if a whitespace contained in the link the argument array // is splitted at this whitespace. so we must combine the array // to one string String messageToSent = null; for (int i = 0; i < args.Length; i++) { if (i != 0) { messageToSent += " "; } messageToSent += args[i]; } messageSent = Win32APIWrapper.SendArgs((IntPtr)handle, messageToSent); } } return(messageSent); }
/// <summary> /// Sends string to running instance of passed handle. /// The handle must override the method WndProc /// </summary> /// <param name="targetHWnd">handle to send the message</param> /// <param name="args">message to send</param> /// <returns></returns> public static bool SendArgs(IntPtr targetHWnd, string args) { Win32APIWrapper.CopyDataStruct copyDataStruct = new Win32APIWrapper.CopyDataStruct(); try { copyDataStruct.cbData = (args.Length + 1) * 2; copyDataStruct.lpData = Win32APIWrapper.LocalAlloc(0x40, copyDataStruct.cbData); Marshal.Copy(args.ToCharArray(), 0, copyDataStruct.lpData, args.Length); copyDataStruct.dwData = (IntPtr)1; Win32APIWrapper.SendMessage(targetHWnd, Win32APIWrapper.WM_COPYDATA, IntPtr.Zero, ref copyDataStruct); } finally { copyDataStruct.Dispose(); } return(true); }