473,399 Members | 3,302 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,399 software developers and data experts.

Help! - Reading playlist files from winamp through Windows & Winamp APIs & .NET - Decoding memory contents

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. Through digging and asking around, I managed to read the
memory contents that winamp points to, but I can't seem to be able to
decode them!

In the attached code below that contains all you need to recreate my
problem. The function always returns the following giberish:
"UVßwXjÝw

================================================== ====================

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

Private Const PROCESS_VM_READ As Long = &H10
Private Const IPC_GETPLAYLISTFILE = 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 As IntPtr, 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 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(1000) As Byte
Dim bytesWritten As Integer

If ReadProcessMemory(hWinampProcess, lp, buffer, buffer.Length,
bytesWritten) Then

fileName = System.Text.Encoding.Default.GetString(buffer)
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

Nov 21 '05 #1
1 2318
The error lies in the fact that the lpBase argument of the ReadProcessMemory
declaration should be declared ByVal, not ByRef.

Hope this helps,
Stefan
<pa******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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. Through digging and asking around, I managed to read the
memory contents that winamp points to, but I can't seem to be able to
decode them!

In the attached code below that contains all you need to recreate my
problem. The function always returns the following giberish:
"UVßwXjÝw

================================================== ====================

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

Private Const PROCESS_VM_READ As Long = &H10
Private Const IPC_GETPLAYLISTFILE = 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 As IntPtr, 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 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(1000) As Byte
Dim bytesWritten As Integer

If ReadProcessMemory(hWinampProcess, lp, buffer, buffer.Length,
bytesWritten) Then

fileName = System.Text.Encoding.Default.GetString(buffer)
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
Nov 21 '05 #2

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

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
0
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
27
by: Bruce Dodds | last post by:
I recently started using Access 2003 for the first time. I wanted to pass on some comments about the Help system to Access MVPs who frequent this board. I'm doing this in the hope that some of...
4
by: jerry.ranch | last post by:
Say, on a data entry form a "HELP" cmbBUTTON that bounces the user off to word file that has help, or is there some other way to do it (like a label object with help on another form) Thanks...
4
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! ...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...

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.