Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: PaiD on October 19, 2005, 06:40 AM

Title: [VB6 - Solved] Get Winamp's Current Song Title via Memory
Post by: PaiD on October 19, 2005, 06:40 AM
Hello

I was playing with Winamp and I recieve a pointer to where a value is that I want. How would I go about getting the value?


Public Function GetTrackName() As String
Dim hwndWinamp As Long
Dim TrackIndex As Integer, TrackPos As Long, Title As String * 256
hwndWinamp = FindWindow("Winamp v1.x", vbNullString)
'GetTrackName = SendMessage(hwndWinamp, WM_WA_IPC, 0, ByVal IPC_GETLISTLENGTH)
TrackIndex = SendMessage(hwndWinamp, WM_WA_IPC, 0, ByVal IPC_GETLISTPOS)
TrackIndex = TrackIndex + 1
TrackPos = SendMessage(hwndWinamp, WM_WA_IPC, TrackIndex, ByVal IPC_GETPLAYLISTTITLE)
CopyMemory ByVal Title, TrackPos, Len(Title)
GetTrackName = Title
End Function

I currently use CopyMemory Here and when I try this I get '8¯G' returned. TrackPos returns the value '4697912' which is the where the song title is located in memory. Am I reading the memory block wrong? or should I be using ReadProcessMemory and if so, How would I go about using this api?


Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Title: Re: [VB6] CopyMemory or ReadProcessMemory
Post by: l2k-Shadow on October 19, 2005, 12:15 PM
It is quite unnecessary to use CopyMemory OR ReadProcessMemory to retrieve the current song... Use

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Function GetTrackName() As String
Dim strReturn As String * 256, hWnd As Long
hWnd = FindWindow("Winamp v1.x", vbNullString)
If hWnd <> 0 Then
GetWindowText hWnd, strReturn, 256
strReturn = Left$(strReturn, Instr(strReturn, vbNullChar) - 1)
End If
End Function


That should give you a good start.. After this feel free to parse the content of strReturn to suit your needs.
Title: Re: [VB6] CopyMemory or ReadProcessMemory
Post by: Adron on October 19, 2005, 12:35 PM
I thought GetWindowText did not work if you used scrolling song titles in the title bar?
Title: Re: [VB6] CopyMemory or ReadProcessMemory
Post by: PaiD on October 19, 2005, 01:27 PM
l2k-Shadow: Yes I know of this way. But I dont wish to retrieve it that way. Like Ardon says, it wont work if they have it scrolling. Also I was looking at the sdk for winamp that that api is available but only to "in process" plugins not external apps. Also I would like to find out how to get into the memory b/c there are more api calls I could use to make it easier and show more information that is only available to 'plugins'. So any help to find this out will help.


TrackPos = SendMessage(hwndWinamp, WM_WA_IPC, TrackIndex, ByVal IPC_GETPLAYLISTTITLE)

returns a pointer into the memory of Winamp.

Edit: Ok after looking some more on Winamp's forum I found a link (http://msmvps.com/ch21st/archive/2004/02/26.aspx) that explained to me what I had to do. I was close (some what)

Title: Re: [VB6 - Solved] Get Winamp's Current Song Title via Memory
Post by: Warrior on October 19, 2005, 02:57 PM
Yea, in theory you were. Just need a few things done first. Nice job.