Shoutbox

C# - Changing MyMediaMessage - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Skype & Live Messenger (/forumdisplay.php?fid=10)
+----- Thread: C# - Changing MyMediaMessage (/showthread.php?tid=93024)

C# - Changing MyMediaMessage by dezio on 11-26-2009 at 01:01 PM

With the following C#-Code i can change the MediaMessage in Windows Live Messenger. At least not under Windows 7.

Perhaps you can help me to run this code under Windows 7 successfully.

Thanks

DeZio

code:
[DllImport("user32", EntryPoint = "SendMessageA")]
        private static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam);

        [DllImport("user32", EntryPoint = "FindWindowExA")]
        private static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);

        private const short WM_COPYDATA = 74;

        public struct COPYDATASTRUCT
        {
            public int dwData;
            public int cbData;
            public int lpData;
        }

        public COPYDATASTRUCT data;
   
        string actURL = "http://*****";

        public int VarPtr(object e)
        {
            GCHandle GC = GCHandle.Alloc(e, GCHandleType.Pinned);
            int gc = GC.AddrOfPinnedObject().ToInt32();
            GC.Free();
            return gc;
        }

        public void SendMSNMessage(bool enable, string category, string message)
        {
           
            string buffer = "\\0Music\\01\\0{0}\\0" + message + " (" + actURL + ")\\0" + message + "\\0" + message + "\\0\\0\0";
            int handle = 0;

            data.dwData = 0x0547;
            data.lpData = VarPtr(buffer);
            data.cbData = (buffer.Length * 2);

            handle = FindWindowEx(0, handle, "MsnMsgrUIManager", null);

            if (handle > 0)
            {
                //Text = handle.ToString();
                SendMessage(handle, WM_COPYDATA, 0, VarPtr(data));
            }
        }

...
SendMSNMessage(true, "Music", "My Song - My Artist");
...