Ejemplo n.º 1
0
 public static extern IntPtr SendMessageTimeout(IntPtr windowHandle,
     uint Msg,
     IntPtr wParam,
     ref CopyDataStruct lParam,
     SendMessageTimeoutFlags flags,
     uint timeout,
     out IntPtr result);
Ejemplo n.º 2
0
        public static IntPtr CreateCopyDataObj(string message)
        {
            IntPtr lpData = Marshal.StringToHGlobalUni(message);

            CopyDataStruct data = new CopyDataStruct();
            data.dwData = IntPtr.Zero;
            data.cbData = message.Length * 2;
            data.lpData = lpData;

            IntPtr lpStruct = Marshal.AllocHGlobal(Marshal.SizeOf(data));

            Marshal.StructureToPtr(data, lpStruct, false);

            return lpStruct;
        }
Ejemplo n.º 3
0
 public static void SendMessageToWindow(IntPtr hwnd, int message, string parameter)
 {
     CopyDataStruct cds = new CopyDataStruct();
     try
     {
         cds.cbData = (parameter.Length + 1) * 2;
         cds.lpData = UnsafeNativeMethods.LocalAlloc(0x40, cds.cbData);
         Marshal.Copy(parameter.ToCharArray(), 0, cds.lpData, parameter.Length);
         cds.dwData = (IntPtr)1;
         UnsafeNativeMethods.SendMessage(hwnd, message, IntPtr.Zero, ref cds);
     }
     finally
     {
         cds.Dispose();
     }
 }
Ejemplo n.º 4
0
		/// <summary>
		/// Sends string arguments to running instance of World Wind.
		/// </summary>
		/// <param name="args"></param>
		/// <returns></returns>
		public static bool SendArgs(IntPtr targetHWnd, string args)
		{
			if (targetHWnd == IntPtr.Zero)
				return false;

			CopyDataStruct cds = new CopyDataStruct();
			try
			{
				cds.cbData = (args.Length + 1) * 2;
				cds.lpData = NativeMethods.LocalAlloc(0x40, cds.cbData);
				Marshal.Copy(args.ToCharArray(), 0, cds.lpData, args.Length);
				cds.dwData =  (IntPtr) 1;

				return SendMessage( targetHWnd, WM_COPYDATA, /*Handle*/System.IntPtr.Zero, ref cds );
			}
			finally
			{
				cds.Dispose();
			}
		}
Ejemplo n.º 5
0
        protected bool Send(string message)
        {
            targetWindow = IntPtr.Zero;

            // We can't use a simple FindWindow, because the decompiler window title
            // can vary: we must detect its window title starts with a known value;
            // not simply it is equal to a known value. See the EnumWindow method.
            EnumWindows(new EnumWindowsCallback(EnumWindow), 0);

            if (targetWindow != IntPtr.Zero)
            {
                var chars = message.ToCharArray();
                var data = new CopyDataStruct();
                data.Padding = IntPtr.Zero;
                data.Size = chars.Length * 2;
                data.Buffer = Marshal.AllocHGlobal(data.Size);
                Marshal.Copy(chars, 0, data.Buffer, chars.Length);

                var result = SendMessage(targetWindow, WindowMessage, IntPtr.Zero, ref data);
                Marshal.FreeHGlobal(data.Buffer);

                return result;
            }

            return false;
        }
Ejemplo n.º 6
0
 public void SendStartMessage()
 {
     CopyDataStruct copyData = new CopyDataStruct();
     copyData.ID = IntPtr.Zero;
     copyData.Data = IntPtr.Zero;
     copyData.Length = 0;
     SendMessage(windowHandle, WM_COPYDATA, 0, ref copyData);
 }
Ejemplo n.º 7
0
 public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref CopyDataStruct lParam);
Ejemplo n.º 8
0
 private extern static int SendMessage(System.IntPtr hWnd,
                                       int Msg, int wParam, ref CopyDataStruct lParam);
Ejemplo n.º 9
0
        public unsafe void SendMessage(DebugMessage message)
        {
            byte[] data = SerializeMessage(message);

            if(data != null && data.Length > 0) {
                // send message
                CopyDataStruct copyData = new CopyDataStruct();
                copyData.ID = IntPtr.Zero;
                copyData.Length = data.Length;

                fixed(byte* datePointer = data) {
                    copyData.Data = (IntPtr)datePointer;
                    SendMessage(windowHandle, WM_COPYDATA, 0, ref copyData);
                }
            }
        }
Ejemplo n.º 10
0
 public static extern int SendMessage(int hWnd, int Msg, int wParam, ref CopyDataStruct lParam);
Ejemplo n.º 11
0
        void closeFuckDlg()
        {
            IntPtr hwnd = IntPtr.Zero;
            CopyDataStruct cds = new CopyDataStruct();
            int fromWindowHandler = 0;

            while (hwnd == IntPtr.Zero)
            {
                hwnd = (IntPtr)FindWindow(null, "MxDrawX");
                if(hwnd != IntPtr.Zero)
                {
                    SendMessage(hwnd, 16, fromWindowHandler, ref  cds);
                    break;
                }
            }
        }
Ejemplo n.º 12
0
 public static extern int SendMessage(
     IntPtr hWnd,              //目标窗体句柄
     int Msg,                  //WM_COPYDATA
     int wParam,               //自定义数值
     ref CopyDataStruct lParam //结构体
     );
Ejemplo n.º 13
0
        /// <summary>
        /// Sends string to window by WM_COPYDATA
        /// </summary>
        /// <param name="targetHWnd"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        private static bool SendArgs(IntPtr targetHWnd, string args)
        {
            CopyDataStruct cds = new CopyDataStruct();
            try
            {
                cds.cbData = (args.Length + 1) * 2;
                cds.lpData = LocalAlloc(0x40, cds.cbData);
                Marshal.Copy(args.ToCharArray(), 0, cds.lpData, args.Length);
                cds.dwData = (IntPtr)1;
                SendMessage(targetHWnd, WM_COPYDATA, IntPtr.Zero, ref cds);
            }
            finally
            {
                cds.Dispose();
            }

            return true;
        }
Ejemplo n.º 14
0
 IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 {
     if (msg == WM_COPYDATA)
     {
         CopyDataStruct cds      = (CopyDataStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(lParam, typeof(CopyDataStruct));
         string         jsonData = cds.lpData;
         var            result   = JsonConvert.DeserializeObject <CommonExchangeInfo>(jsonData);
         if (result.Code == "ExchangeBrowseTxTReturnBack")
         {
             if (viewModel.ReturnBtnVisibility == Visibility.Visible && !IsDealingData)
             {
                 Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(() => { ReturnBack(); }));
             }
         }
         else if (result.Code == "DealDataProcessingState")
         {
             string data = result.Data;
             var    info = JsonConvert.DeserializeObject <DealDataProcessingStateInfo>(data);
             IsDealingData = info.IsDealingData;
         }
         else if (result.Code == "ExchangeBrowseTxTProcessing")
         {
             if (!IsCancelDeal)
             {
                 System.Windows.Threading.Dispatcher x     = System.Windows.Threading.Dispatcher.CurrentDispatcher;
                 System.Threading.ThreadStart        start = delegate()
                 {
                     string data = result.Data;
                     var    exchangeBrowseTxTProcessingInfo = JsonConvert.DeserializeObject <ExchangeBrowseTxTProcessingInfo>(data);
                     //处理数据
                     viewModel.CurrentProcessingInfo = exchangeBrowseTxTProcessingInfo;
                     if (viewModel.CurrentProcessingInfo.IsDealFinished)
                     {
                         System.Threading.Thread.Sleep(500);
                         viewModel.DataProcessGridVisibility       = Visibility.Collapsed;
                         viewModel.DataProcessResultGridVisibility = Visibility.Visible;
                         viewModel.TitleLogoVisibility             = Visibility.Collapsed;
                         viewModel.InputCheckGridVisibility        = Visibility.Collapsed;
                         viewModel.ReturnBtnVisibility             = Visibility.Visible;
                         if (viewModel.CurrentProcessingInfo.UnCheckWordsCount == 0)
                         {
                             if (UnReadFilePathsList.Count > 0)
                             {
                                 viewModel.CheckResultText = UnReadFilePathsList.Count + "个文件正被编辑,无法读取.";
                             }
                             else
                             {
                                 viewModel.CheckResultText = "未发现违禁词.";
                             }
                             viewModel.TongJiCheckResultVisibility               = Visibility.Collapsed;
                             viewModel.SinggleWordCheckResultVisibility          = Visibility.Collapsed;
                             viewModel.SinggleWordCheckResultNoUncheckVisibility = Visibility.Collapsed;
                             viewModel.CommonCheckResultVisibility               = Visibility.Visible;
                         }
                         else
                         {
                             if (UnReadFilePathsList.Count == 0)
                             {
                                 viewModel.FileReadFailTipsVisibility = Visibility.Collapsed;
                             }
                             else if (UnReadFilePathsList.Count == 1)
                             {
                                 viewModel.FileReadFailTipsVisibility = Visibility.Visible;
                                 viewModel.FileReadFailTips           = System.IO.Path.GetFileNameWithoutExtension(UnReadFilePathsList.FirstOrDefault());
                                 viewModel.FileReadFailTipsExtention  = System.IO.Path.GetExtension(UnReadFilePathsList.FirstOrDefault());
                             }
                             else
                             {
                                 viewModel.FileReadFailTipsVisibility = Visibility.Visible;
                                 viewModel.FileReadFailTips           = UnReadFilePathsList.Count + "个文件";
                                 viewModel.FileReadFailTipsExtention  = "";
                             }
                             viewModel.CheckResultText =
                                 "共检查" + viewModel.CurrentProcessingInfo.TotalCount + "个文件,发现" + viewModel.CurrentProcessingInfo.UnCheckWordsCount + "个违禁词";
                             viewModel.TongJiCheckResultVisibility               = Visibility.Visible;
                             viewModel.SinggleWordCheckResultVisibility          = Visibility.Collapsed;
                             viewModel.SinggleWordCheckResultNoUncheckVisibility = Visibility.Collapsed;
                             viewModel.CommonCheckResultVisibility               = Visibility.Collapsed;
                         }
                         this.IsDealingData = false;
                         SendDealDataStateToApp();
                     }
                     else
                     {
                         viewModel.DataProcessGridVisibility       = Visibility.Visible;
                         viewModel.InputCheckGridVisibility        = Visibility.Collapsed;
                         viewModel.DataProcessResultGridVisibility = Visibility.Collapsed;
                     }
                 };
                 System.Threading.Thread t = new System.Threading.Thread(start);
                 t.IsBackground = true;
                 t.Start();
             }
         }
     }
     return(hwnd);
 }
Ejemplo n.º 15
0
 private static extern int SendMessage(
     IntPtr hWnd,                     // 目标窗口的句柄
     int Msg,                         // 在这里是WM_COPYDATA
     int wParam,                      // 第一个消息参数
     ref CopyDataStruct lParam        // 第二个消息参数
     );
Ejemplo n.º 16
0
        private static void Main(string[] args)
        {
            var filepaths = new List <string>();

            try
            {
                var showHelp = false;

                // First order of business is to parse commandline args
                // Do this before loading configurations because the data directory
                // may be passed as an argument.
                var options = new OptionSet()
                {
                    { "a|app=", "The application's source directory.", v => _appDir = v },
                    { "d|data=", "The application's data storage directory.", v => _dataDir = v },
                    { "vs", "Whether this instance is run from Visual Studio.", v => _runningInVs = v != null },
                    { "h|help", v => showHelp = v != null }
                };
                var extra = options.Parse(args);

                if (showHelp)
                {
                    NativeMethods.AttachConsole(NativeMethods.ATTACH_PARENT_PROCESS);
                    Console.Write(Strings.CmdLineHelpMessage);
                    NativeMethods.FreeConsole();
                    return;
                }

                if (extra.Count > 0)
                {
                    filepaths = extra.Where(arg => File.Exists(arg)).ToList();
                }
            }
            catch (Exception e)
            {
                NativeMethods.AttachConsole(NativeMethods.ATTACH_PARENT_PROCESS);
                Console.Write(Strings.CmdLineParseError, e.Message);
                NativeMethods.FreeConsole();
                return;
            }

            // Initialize
            Init();

            // Allow only a single process in this section at a time.
            if (_mutex.WaitOne(-1, true))
            {
                var instances = GetApplicationInstances();

                if (instances.Any())
                {
                    var firstInstance = instances.First();

                    // This will bring the top most form into the foreground. Top most being the one most recently activated/focused.
                    _ = NativeMethods.SetForegroundWindow(firstInstance.MainWindowHandle);

                    // If the window is minimized then restore it
                    var windowPlacement = NativeMethods.GetPlacement(firstInstance.MainWindowHandle);
                    if (windowPlacement.showCmd == (int)CmdShow.SW_SHOWMINIMIZED)
                    {
                        NativeMethods.ShowWindow(firstInstance.MainWindowHandle, CmdShow.SW_SHOWNORMAL);
                    }

                    if (!SingleInstance)
                    {
                        // Since cef doesn't not allow multiple processes to load the same Data/Cache directory, we must use
                        // the same existing process to open a new window. We do this by sending a message to the existing process.

                        // The top most form will receive and process the message.
                        // Note: The dev console is a separate form and if that is the top most then this will not work.
                        var cds = new CopyDataStruct();
                        try
                        {
                            var data = "Cmd:New Window";
                            cds.cbData = (UIntPtr)((data.Length + 1) * 2);                                     // Number of bytes
                            cds.lpData = NativeMethods.LocalAlloc(LocalMemoryFlags.LMEM_ZEROINIT, cds.cbData); // Known local-pointer in RAM.

                            if (cds.lpData == IntPtr.Zero)
                            {
                                throw new OutOfMemoryException();
                            }

                            Marshal.Copy(data.ToCharArray(), 0, cds.lpData, data.Length); // Copy data to preserved local-pointer
                            cds.dwData = (IntPtr)1;
                            NativeMethods.SendMessage(firstInstance.MainWindowHandle, NativeMethods.WM_COPYDATA, IntPtr.Zero, ref cds);
                        }
                        finally
                        {
                            cds.Dispose();
                        }
                    }

                    if (filepaths.Count > 0)
                    {
                        // Send messages to open the files
                        foreach (var filepath in filepaths)
                        {
                            var cds = new CopyDataStruct();
                            try
                            {
                                var data = "Cmd:Open File:" + filepath;
                                cds.cbData = (UIntPtr)((data.Length + 1) * 2);                                     // Number of bytes
                                cds.lpData = NativeMethods.LocalAlloc(LocalMemoryFlags.LMEM_ZEROINIT, cds.cbData); // Known local-pointer in RAM.

                                if (cds.lpData == IntPtr.Zero)
                                {
                                    throw new OutOfMemoryException();
                                }

                                Marshal.Copy(data.ToCharArray(), 0, cds.lpData, data.Length); // Copy data to preserved local-pointer
                                cds.dwData = (IntPtr)1;
                                NativeMethods.SendMessage(firstInstance.MainWindowHandle, NativeMethods.WM_COPYDATA, IntPtr.Zero, ref cds);
                            }
                            finally
                            {
                                cds.Dispose();
                            }
                        }
                    }

                    _mutex.ReleaseMutex();
                    return;
                }

                // For Windows 7 and above, best to include relevant app.manifest entries as well
                Cef.EnableHighDPISupport();

                using (var settings = new CefSettings()
                {
                    // By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                    CachePath = CacheDirectory
                })
                {
                    settings.RegisterScheme(new CefCustomScheme()
                    {
                        SchemeName           = FileSystemSchemeHandlerFactory.SchemeName,
                        SchemeHandlerFactory = new FileSystemSchemeHandlerFactory()
                    });

                    // Perform dependency check to make sure all relevant resources are in our output directory.
                    Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
                }

                // Setup default json serialization settings.
                JsonConvert.DefaultSettings = () =>
                                              new JsonSerializerSettings
                {
                    DateTimeZoneHandling           = DateTimeZoneHandling.Utc,
                    Formatting                     = Formatting.Indented,
                    NullValueHandling              = NullValueHandling.Ignore,
                    TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
                };

                // Load SqlServer types
                SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

                using (var appContext = new AppContext(filepaths))
                {
                    // Release mutex because WinForms.Application.Run will block
                    _mutex.ReleaseMutex();
                    Application.Run(appContext);
                }
            }
        }
Ejemplo n.º 17
0
        private bool SendCommandToCortex( string command )
        {
            if ( ! cortex_active_ )
                return false;

            log_.Debug( "> " + command );

            CopyDataStruct aCDS = new CopyDataStruct();
            aCDS.ID = "1";
            aCDS.Data = command;
            aCDS.Length = aCDS.Data.Length + 1;

            IntPtr lParam = Marshal.AllocCoTaskMem( Marshal.SizeOf( aCDS ) );

            Marshal.StructureToPtr( aCDS, lParam, false );

            IntPtr  aRetVal = SendMessage( cortex_handle_, WM_COPYDATA, this.Handle, lParam );

            Marshal.FreeCoTaskMem( lParam );

            return aRetVal != IntPtr.Zero;
        }
Ejemplo n.º 18
0
 private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref CopyDataStruct lParam);
Ejemplo n.º 19
0
 internal static extern bool SendMessage(
     IntPtr hWnd,
     int Msg,
     IntPtr wParam,
     ref CopyDataStruct lParam);
Ejemplo n.º 20
0
 public static extern string SendMessage(IntPtr hwnd, int msg, int wParam, ref CopyDataStruct lParam);
 public static extern bool SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref CopyDataStruct lParam);
Ejemplo n.º 22
0
 public static extern int SendMessage(
     IntPtr hWnd,                  //目标窗体句柄
     int Msg,                      //WM_COPYDATA
     int wParam,                   //自定义数值
     ref  CopyDataStruct lParam    //结构体
 );
Ejemplo n.º 23
0
 private static extern int SendMessage(
     int hWnd,                         // handle to destination window
     int Msg,                          // message
     int wParam,                       // first message parameter
     ref CopyDataStruct lParam         // second message parameter
     );
Ejemplo n.º 24
0
 private static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint msg, IntPtr wParam, ref CopyDataStruct lParam, uint flags, uint timeout, out IntPtr result);
Ejemplo n.º 25
0
 private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref CopyDataStruct lParam);
Ejemplo n.º 26
0
        private bool SendCmd(string args)
        {
            ResponseBuffer = "";
            byte[] bytes;
            CopyDataStruct cds = new CopyDataStruct();

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

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

            return true;
        }