C#.NET: Winamp-Titel auslesen

Winamp-Titel auslesen in C#

Möchte man mit C# wie in Delphi den aktuellen Winamp-Titel auslesen (siehe vorheriger Artikel), kann man sich prinzipiell den selben Methoden bedienen. Der Zugriff auf die WinAPI gestaltet sich allerdings etwas trickiger. Dieser Snippet darf privat und kommerziell verwendet werden. Ich würde mich in beiden Fällen sehr über Feedback freuen!


        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        public static extern IntPtr FindWindow(string strClassName, int nptWindowName);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, long lParam);
        [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
        static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Boolean bInheritHandle, UInt32 dwProcessId);
        [System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [System.Runtime.InteropServices.Out] byte[] lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesRead);
        [System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
        private static extern bool CloseHandle(IntPtr handle);

        private static string GetWinampTitle()
        {
            const uint WM_USER = 0x0400;
            const uint PROCESS_ALL_ACCESS = 0x000F0000 | 0x00100000 | 0xFFF;

            uint ProcessHandle;
            byte[] dat2 = new byte[500];
            IntPtr temp = (IntPtr) 0;

            IntPtr hwndWinamp = FindWindow("Winamp v1.x", 0);
            IntPtr MPointer = SendMessage(hwndWinamp, WM_USER, SendMessage(hwndWinamp, WM_USER, (IntPtr) 0, 125), 212);
            GetWindowThreadProcessId(hwndWinamp, out ProcessHandle);
            hwndWinamp = OpenProcess(PROCESS_ALL_ACCESS,false,ProcessHandle);
            ReadProcessMemory(hwndWinamp, MPointer, dat2, (UIntPtr) 500, temp);
            CloseHandle(hwndWinamp);
            return Convert.ToString(System.Text.Encoding.ASCII.GetString(dat2));
        }

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

*

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.