473,418 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Use of ReadProcessMemory API function for getting song paths from winamp's playlist


I've been trying for days to write a piece of VB.NET code that will
read from winamp's memory space the paths of the files from the current
winamp playlist.

The GETPLAYLISTFILE command of the winamp API will only return a
pointer to the position of the asked path. An article available on
http://msmvps.com/ch21st/archive/2004/02/26.aspx provides a VB6
implementation of this, using the ReadProcessMemory Windows API
command, but something goes wrong when I transcribe the code to VB.NET!

In the attached code below that contains all you need to recreate my
problem, when the program reaches the "ReadProcessMemory(lpWinamp, lp,
Buffer(0), 260, dwRead)" line it will just exit!!! Can anybody help? I
am annoyed because I know that it will just be due to some stupid
declaration blunder

----------------------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(Me.GetPlaylistFile(0))
End Sub

Dim WinampWindow As Integer
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByVal lParam As Integer) As Integer
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd
As Integer, ByRef lpdwProcessId As Integer) As Integer
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As
Integer) As Integer
Private Const PROCESS_VM_READ As Long = &H10
Public Const IPC_GETPLAYLISTFILE = 211
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject
As Long) As Long
Declare Function ReadProcessMemory Lib "kernel32" Alias
"ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As
Integer, ByRef lpBuffer As Byte(), ByVal nSize As Integer, ByRef
lpNumberOfBytesWritten As Integer) As Integer
Public Function FindWinamp() As Boolean

WinampWindow = FindWindow("Winamp v1.x", vbNullString)
If WinampWindow <> 0 Then
Return True
End If
Return False
End Function
Public Function GetPlaylistFile(ByVal TrackNo As Integer) As String
Dim strFileName As String
Dim lp As Integer
Dim lpWinamp As Integer
Dim PID As Integer

Dim Buffer(260) As Byte
Dim Temp As String

Dim dwRead As Long

FindWinamp()

lp = SendMessage(WinampWindow, &H400, TrackNo,
IPC_GETPLAYLISTFILE)
If lp = 0 Then
Return ""
Exit Function
End If
GetWindowThreadProcessId(WinampWindow, PID)
lpWinamp = OpenProcess(PROCESS_VM_READ, 0, PID)
If lpWinamp = 0 Then
Return ""
Exit Function
End If

Dim tmpString As String
ReadProcessMemory(lpWinamp, lp, Buffer(0), 260, dwRead)

Call CloseHandle(lpWinamp)

'don't yet have a clue what to do from here!
'Temp = StrConv(Buffer, vbUnicode)
'strFileName = Left$(Temp, InStr(Temp, Chr$(0)) - 1)

Return strFileName
End Function

Nov 21 '05 #1
2 6299
On 2005-07-23, pa******@gmail.com <pa******@gmail.com> wrote:

I've been trying for days to write a piece of VB.NET code that will
read from winamp's memory space the paths of the files from the current
winamp playlist.

The GETPLAYLISTFILE command of the winamp API will only return a
pointer to the position of the asked path. An article available on
http://msmvps.com/ch21st/archive/2004/02/26.aspx provides a VB6
implementation of this, using the ReadProcessMemory Windows API
command, but something goes wrong when I transcribe the code to VB.NET!

In the attached code below that contains all you need to recreate my
problem, when the program reaches the "ReadProcessMemory(lpWinamp, lp,
Buffer(0), 260, dwRead)" line it will just exit!!! Can anybody help? I
am annoyed because I know that it will just be due to some stupid
declaration blunder

----------------------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(Me.GetPlaylistFile(0))
End Sub

Dim WinampWindow As Integer
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByVal lParam As Integer) As Integer
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd
As Integer, ByRef lpdwProcessId As Integer) As Integer
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As
Integer) As Integer
Private Const PROCESS_VM_READ As Long = &H10
Public Const IPC_GETPLAYLISTFILE = 211
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject
As Long) As Long
Declare Function ReadProcessMemory Lib "kernel32" Alias
"ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As
Integer, ByRef lpBuffer As Byte(), ByVal nSize As Integer, ByRef
lpNumberOfBytesWritten As Integer) As Integer
Public Function FindWinamp() As Boolean

WinampWindow = FindWindow("Winamp v1.x", vbNullString)
If WinampWindow <> 0 Then
Return True
End If
Return False
End Function
Public Function GetPlaylistFile(ByVal TrackNo As Integer) As String
Dim strFileName As String
Dim lp As Integer
Dim lpWinamp As Integer
Dim PID As Integer

Dim Buffer(260) As Byte
Dim Temp As String

Dim dwRead As Long

FindWinamp()

lp = SendMessage(WinampWindow, &H400, TrackNo,
IPC_GETPLAYLISTFILE)
If lp = 0 Then
Return ""
Exit Function
End If
GetWindowThreadProcessId(WinampWindow, PID)
lpWinamp = OpenProcess(PROCESS_VM_READ, 0, PID)
If lpWinamp = 0 Then
Return ""
Exit Function
End If

Dim tmpString As String
ReadProcessMemory(lpWinamp, lp, Buffer(0), 260, dwRead)

Call CloseHandle(lpWinamp)

'don't yet have a clue what to do from here!
'Temp = StrConv(Buffer, vbUnicode)
'strFileName = Left$(Temp, InStr(Temp, Chr$(0)) - 1)

Return strFileName
End Function

WARNING: Untested, off the cuff conversion...

Private Const PROCESS_VM_READ As Long = &H10
Private Const IPC_GETPLAYLIST = 211

Private Declare Auto Function FindWindow Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr

Private Declare Auto Function SendMessage Lib "user32" _
(ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As IntPtr

Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd, _
ByRef lpdwProcessId As IntPtr) As IntPtr

Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Integer, _
ByVal bIneritHandle As Boolean, _
ByVal dwProcessId As IntPtr) As IntPtr

Private Declare Function ReadProcessMemory Lib "kernel32" _
(ByVal hProcess As IntPtr, _
ByRef lpBase Address As IntPtr, _
ByVal lpBuffer() As Byte, _
ByVal nSize As Integer, _
ByRef lpNumberOfBytesWritten As Integer) As Boolean

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As IntPtr) As Boolean

Private Function FindWinamp () As IntPtr
Return FindWindow ("Winamp v1.x", vbNullString)
End Function

Public Function GetPlaylistFile (ByVal TrackNo As Integer) As String
Dim winampWindow As IntPtr = FindWinamp ()
Dim fileName As String = String.Empty

If Not IsNullPtr (winampWindow) Then

Dim lp As IntPtr = SendMessage ( _
winampWindow, &H400, TrackNo, IPC_GETPLAYLISTFILE)

If Not IsNullPtr (lp) Then

Dim pid As IntPtr

Call GetWindowThreadProcessId (winampWindow, pid)
If Not IsNullPtr (pid) Then

Dim hWinampProcess As IntPtr = OpenProcess ( _
PROCESS_VM_READ, False, pid)

If Not IsNullPtr (hWinampProcess) Then

Dim buffer (260) As Byte
Dim bytesWritten As Integer

If ReadProcessMemory _
(hWinampProcess, _
lp, _
buffer, _
buffer.Length, _
bytesWritten) Then
' At this point, I would have
' to play a bit. But, you would use
' one of the System.Text.Encoding classes
' to convert the byte array to a string...

End If

CloseHandle (hWinampProcess)
End If

End If

End If

End If

Return fileName

End Function

Private Function IsNullPtr (ByVal ptr As IntPtr) As Boolean
Return ptr.Equals (IntPtr.Zero)
End Function

HTH
--
Tom Shelton [MVP]
Nov 21 '05 #2
This gets annoying... Tried most of the classes in System.Text.Encoding
to process the obtained bytes, and I keep getting the following
giberish: "UVßwXjÝw

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Emil | last post by:
This is my problem: I'm writing a script that... 1. creates a customized pls/m3u playlist 2. sends the pls or a m3u playlist to the webbrowser. The browser should open Winamp/Windows Media...
0
by: Jorr.it | last post by:
Who can give me an example how to write a general plugin for Winamp 5 in Visual Basic 6? Only things I want to do is Play, Stop, Pause, Load Playlist and Randomize Playlist. For Winamp 3 there were...
3
by: The Collector | last post by:
Hi, I've been looking for almost two full days now to get full control of WinAMP using python. Simple play/stop functions are no problem. It's the WM_COPYDATA that's used by IPC_PLAYFILE (=add a...
0
by: Andy | last post by:
I am trying to talk to Winamp2 from Perl on Win32 system. According to winamp docs I need to send a windows message with the following structure: (To add a file to the playlist) COPYDATASTRUCT...
1
by: BadOmen | last post by:
This works fine, but I want to be able to make WinAmp3 to play a playlist at startup, how do i do that? This is my playlist... MyPlaylist.b4s //Initsierar activeX Objekt var oShell = new...
9
by: Luke | last post by:
I am trying to convert some VB6 projects to VB.NET, however I'm having trouble finding documentation of a new format for some functions, in specific ReadProcessMemory. Since .NET no longer supports...
5
by: Evolution445 | last post by:
Hi all, I got a problem with my code to check a game's chat position and write text to the game when a command is written by someone on the chat. I haven't figured out yet how to make it send keys...
0
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, can someone postme a running sample of the ReadProcessMemory(...) function. I would like to dump the complete memory of the main module in my application e.g MyApplication.exe into a file....
0
by: =?Utf-8?B?Um9iZXJ0?= | last post by:
I am not a novice user but this one really is a puzzle. When ever I use Media player to burn songs to a blank cd it creates duplicate songs on the CD. Sometimes they are one after another and...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.