|
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
' We request the path of the first name in the list
MsgBox(Me.GetPlaylistFile(0))
End Sub
'API commands, constants etc.
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 Object, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Public Function FindWinamp() As Boolean
'Returns winamp's hwnd
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 Object
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 how to convert the data to text form, never reached
'this point on execution
'Temp = StrConv(Buffer, vbUnicode)
'strFileName = Left$(Temp, InStr(Temp, Chr$(0)) - 1)
Return strFileName
End Function
|
|
|
|
|
pangel83 wrote:
Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Object, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Well, the first thing that sticks out is you're using the wrong type for the buffer. It should be:
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
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) Nope, wasn't that. I re-attach the code, in a more legible form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
MsgBox(Me.GetPlaylistFile(0))<br />
End Sub<br />
<br />
Dim WinampWindow As Integer<br />
Private Const PROCESS_VM_READ As Long = &H10<br />
Public Const IPC_GETPLAYLISTFILE = 211<br />
<br />
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer<br />
<br />
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<br />
<br />
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer<br />
<br />
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer<br />
<br />
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long<br />
<br />
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<br />
<br />
Public Function FindWinamp() As Boolean<br />
WinampWindow = FindWindow("Winamp v1.x", vbNullString)<br />
If WinampWindow <> 0 Then<br />
Return True<br />
End If<br />
Return False<br />
End Function<br />
<br />
<br />
Public Function GetPlaylistFile(ByVal TrackNo As Integer) As String<br />
Dim strFileName As String<br />
Dim lp As Integer<br />
Dim lpWinamp As Integer<br />
Dim PID As Integer<br />
Dim Buffer(260) As Object<br />
Dim Temp As String<br />
Dim dwRead As Long<br />
<br />
FindWinamp()<br />
<br />
lp = SendMessage(WinampWindow, &H400, TrackNo, IPC_GETPLAYLISTFILE)<br />
If lp = 0 Then<br />
Return ""<br />
Exit Function<br />
End If<br />
GetWindowThreadProcessId(WinampWindow, PID)<br />
lpWinamp = OpenProcess(PROCESS_VM_READ, 0, PID)<br />
If lpWinamp = 0 Then<br />
Return ""<br />
Exit Function<br />
End If<br />
<br />
Dim tmpString As String<br />
ReadProcessMemory(lpWinamp, lp, Buffer(0), 260, dwRead)<br />
<br />
Call CloseHandle(lpWinamp)<br />
<br />
'don't yet have a clue what to do from here!<br />
'Temp = StrConv(Buffer, vbUnicode)<br />
'strFileName = Left$(Temp, InStr(Temp, Chr$(0)) - 1)<br />
<br />
Return strFileName<br />
End Function
|
|
|
|
|
I should have been a little more clear. When you declare the array of bytes going to the fuction, you have to call it with an array of bytes too:
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
I can't test the code because I don't use WinAmp...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Still does not work.... I am annoyed because it doesn't even return an exception!
|
|
|
|
|
'don't yet have a clue how to convert the data to text form, never reached
'this point on execution
'Temp = StrConv(Buffer, vbUnicode)
'strFileName = Left$(Temp, InStr(Temp, Chr$(0)) - 1)
Would be somthing like:
Temp = ConvertToStringFromBytes(Buffer)
strFileName = Left(Temp, InStr(Temp, Chr(0)) - 1)
Return strFileName
here's the function :
Public Function ConvertToStringFromBytes(ByRef abData() As Byte) As String
Return System.Text.Encoding.Default.GetString(abData)
End Function
Hope that helps
|
|
|
|
|
Hey, guys I know how to diable taskmanager in windows xp/2000 but I didn't know how to trap alt+f4 in windows xp/2000 ,can i have to program low level keyboard hooking
|
|
|
|
|
See this[^] article by George Mamaladze. It's in C#, but is covertable to VB.NET.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hey dave can the code is in vb available and it should work in windows xp/2000/nt
|
|
|
|
|
Are you trying to do this in VB6 or VB.NET?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
|
Iam making a project for a school and until an d unless password is supplied the user supposed not to leave the form
|
|
|
|
|
So what's the question? What are you having a problem with?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave:
I think the author has put the question in the subject itself. 'not to allow the mouse cursor to go out of Active Window Context'. Something like what you see in VirtualPC, without VirtualPC additions installed.
Deepak Kumar Vasudevan
Personal Web: http://vdeepakkumar.netfirms.com/
I Blog At: http://deepak.blogdrive.com/
|
|
|
|
|
The mouse cursor and the focus are two completely different things. The question still stands...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Can any one can tell me how can i know whic O.S. is running. ie,windows xp/2000/95/98/nt
|
|
|
|
|
system.environment.osversion class
it has platform and a version properties that you can use to determine which os and version.
-jim
|
|
|
|
|
|
|
how can i lock the file so that no one can delete it.
|
|
|
|
|
You set the permissions so that they do not have ownership of the file.
"People who never make mistakes, never do anything."
My blog
http://toddsnotsoamazinglife.blogspot.com/
|
|
|
|
|
I want to know to lock the file or using vb code
|
|
|
|
|
What are you getting at?
You want it so noone can delete the file, ever? Or just when you program is running?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|