Beispiel #1
0
        public static long SendMsg(string str, System.IntPtr desthandle, System.IntPtr sourcehandle, int type, int timeout)
        {
            if ((desthandle == IntPtr.Zero) || (sourcehandle == IntPtr.Zero))
            {
                return(-1);                                                              // fail on invalid handles
            }
            WMUtil.COPYDATASTRUCT cds = new WMUtil.COPYDATASTRUCT();
            cds.dwData = (IntPtr)type;
            str        = str + '\0';
            cds.cbData = str.Length + 1;

            System.IntPtr pData = Marshal.StringToCoTaskMemAnsi(str);

            cds.lpData = pData;

            IntPtr res = IntPtr.Zero;
            IntPtr err = WMUtil.SendMessageTimeout(desthandle, (uint)WM_COPYDATA, (IntPtr)sourcehandle, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, (uint)timeout, out res);

            if (err == IntPtr.Zero)
            {
                return(0);
            }
            Marshal.FreeCoTaskMem(pData);
            return(res.ToInt64());
        }
Beispiel #2
0
        /// <summary>
        /// Sends the MSG.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <param name="desthandle">The desthandle.</param>
        /// <param name="sourcehandle">The sourcehandle.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static long SendMsg(string str, System.IntPtr desthandle, System.IntPtr sourcehandle, int type)
        {
            if ((desthandle == IntPtr.Zero) || (sourcehandle == IntPtr.Zero))
            {
                return(-1); // fail on invalid handles
            }
            WMUtil.COPYDATASTRUCT cds = new WMUtil.COPYDATASTRUCT();
            cds.dwData = (IntPtr)type;
            str        = str + '\0';
            cds.cbData = str.Length + 1;

            System.IntPtr pData = Marshal.StringToCoTaskMemAnsi(str);

            cds.lpData = pData;

            IntPtr res = WMUtil.SendMessage(desthandle, WMUtil.WM_COPYDATA, (int)sourcehandle, ref cds);

            Marshal.FreeCoTaskMem(pData);
            return(res.ToInt64());
        }
Beispiel #3
0
        public static long SendMsg(string str, System.IntPtr desthandle, System.IntPtr sourcehandle, int type, int timeout)
        {
            if ((desthandle == IntPtr.Zero) || (sourcehandle == IntPtr.Zero)) return -1; // fail on invalid handles
            WMUtil.COPYDATASTRUCT cds = new WMUtil.COPYDATASTRUCT();
            cds.dwData = (IntPtr)type;
            str = str + '\0';
            cds.cbData = str.Length + 1;

            System.IntPtr pData = Marshal.StringToCoTaskMemAnsi(str);

            cds.lpData = pData;

            IntPtr res = IntPtr.Zero;
            IntPtr err = WMUtil.SendMessageTimeout(desthandle, (uint)WM_COPYDATA, (IntPtr)sourcehandle,IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, (uint)timeout,out res);
            if (err == IntPtr.Zero)
                return 0;
            Marshal.FreeCoTaskMem(pData);
            return res.ToInt64();
        }
Beispiel #4
0
        /// <summary>
        /// Sends the MSG.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <param name="desthandle">The desthandle.</param>
        /// <param name="sourcehandle">The sourcehandle.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static long SendMsg(string str, System.IntPtr desthandle, System.IntPtr sourcehandle, int type)
        {
            if ((desthandle == IntPtr.Zero) || (sourcehandle == IntPtr.Zero)) return -1; // fail on invalid handles
            WMUtil.COPYDATASTRUCT cds = new WMUtil.COPYDATASTRUCT();
            cds.dwData = (IntPtr)type;
            str = str + '\0';
            cds.cbData = str.Length + 1;

            System.IntPtr pData = Marshal.StringToCoTaskMemAnsi(str);

            cds.lpData = pData;

            IntPtr res = WMUtil.SendMessage(desthandle, WMUtil.WM_COPYDATA, (int)sourcehandle, ref cds);
            Marshal.FreeCoTaskMem(pData);
            return res.ToInt64();
        }