Example #1
0
        /// <summary>
        /// override the method to handle adding stealthnet links to downloads.
        /// the message is send by the class program.cs
        /// </summary>
        /// <param name="m">recieved message</param>
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            // respond only to the copydata message
            case Win32APIWrapper.WM_COPYDATA:
                Win32APIWrapper.CopyDataStruct st = (Win32APIWrapper.CopyDataStruct)Marshal.PtrToStructure(m.LParam, typeof(Win32APIWrapper.CopyDataStruct));
                string strData = Marshal.PtrToStringUni(st.lpData);
                try
                {
                    if (strData.EndsWith(".sncollection"))
                    {
                        Core.ParseStealthNetCollection(strData);
                    }
                    else
                    {
                        StealthNetLink stealthNetLink = new StealthNetLink(strData);
                        Core.AddDownload(stealthNetLink.FileHash, stealthNetLink.FileName, stealthNetLink.FileSize, null);
                    }
                }
                catch
                {
                    // ignore invalid links
                }
                break;

            default:
                // let the base class deal with it
                base.WndProc(ref m);
                break;
            }
        }
        /// <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;
        }
Example #3
0
        /// <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);
        }