Example #1
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case Win32.WM_COPYDATA:
                Win32.CopyDataStruct st = (Win32.CopyDataStruct)Marshal.PtrToStructure(m.LParam, typeof(Win32.CopyDataStruct));
                string strData          = Marshal.PtrToStringAnsi(st.lpData, st.cbData);
                ParseCommand(strData);
                break;

            default:
                base.WndProc(ref m);    // let the base class deal with it
                break;
            }
        }
Example #2
0
 static void Main()
 {
     if (mutex.WaitOne(TimeSpan.Zero, true))
     {
         #region standaard
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         #endregion
         #region Culture instellen
         string cult = CultureInfo.CurrentCulture.Name;
         Thread.CurrentThread.CurrentUICulture = new CultureInfo(cult);
         Thread.CurrentThread.CurrentCulture   = new CultureInfo(cult);
         #endregion
         MainForm frm = new MainForm();
         MainWindowHandle = (int)frm.Handle;
         Application.Run(frm);
         MainWindowHandle = 0;
         mutex.ReleaseMutex();
     }
     else
     {
         int hwnd = 0;
         while (hwnd == 0)
         {
             Thread.Sleep(600);
             hwnd = MainWindowHandle;
         }
         if (hwnd != 0)
         {
             Win32.CopyDataStruct cds = new Win32.CopyDataStruct();
             try
             {
                 string data = GetFileName();
                 cds.cbData = (data.Length + 1) * 2;                           // number of bytes
                 cds.lpData = Win32.LocalAlloc(0x40, cds.cbData);              // known local-pointer in RAM
                 Marshal.Copy(data.ToCharArray(), 0, cds.lpData, data.Length); // Copy data to preserved local-pointer
                 cds.dwData = (IntPtr)1;
                 Win32.SendMessage((IntPtr)hwnd, Win32.WM_COPYDATA, IntPtr.Zero, ref cds);
             }
             finally
             {
                 cds.Dispose();
             }
         }
     }
 }
Example #3
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case Win32.WM_COPYDATA:
                Win32.CopyDataStruct st = (Win32.CopyDataStruct)Marshal.PtrToStructure(m.LParam, typeof(Win32.CopyDataStruct));
                string strData          = Marshal.PtrToStringUni(st.lpData);
                BSCommon.Utility.CommonInfo.Strconnection = strData;
                //MessageBox.Show(strData);
                break;

            default:
                // let the base class deal with it
                base.WndProc(ref m);
                break;
            }
        }
Example #4
0
        private bool SendCmd(int hwnd, string args)
        {
            listBox1.Items.Add(string.Format("sending message '{0}' to {1}", args, hwnd));

            byte[] bytes;
            Win32.CopyDataStruct cds = new Win32.CopyDataStruct();

            bytes = System.Text.Encoding.ASCII.GetBytes(args + "\x00");

            try
            {
                cds.cbData = bytes.Length;
                cds.lpData = Win32.LocalAlloc(0x40, cds.cbData);
                Marshal.Copy(bytes, 0, cds.lpData, bytes.Length);
                cds.dwData = (IntPtr)3;
                Win32.SendMessage((IntPtr)hwnd, Win32.WM_COPYDATA, IntPtr.Zero, ref cds);
            }
            finally
            {
                cds.Dispose();
            }

            return(true);
        }