#Region " API "
Private Const PROCESS_VM_READ = (&H10)
<DllImport("User32.dll", EntryPoint:="SendMessage")> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal lParam As Integer, ByVal wParam As Integer) As IntPtr
End Function
<DllImport("kernel32", EntryPoint:="OpenProcess")> _
Public Shared Function OpenProcess(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
End Function
<DllImport("kernel32", EntryPoint:="CloseHandle")> _
Public Shared Function CloseHandle(ByVal hObject As Integer) As Integer
End Function
<DllImport("user32.dll", EntryPoint:="FindWindowA")> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("kernel32", EntryPoint:="ReadProcessMemory")> _
Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, _
ByVal lpBaseAddress As Integer, _
ByRef lpBuffer As Object, _
ByVal nSize As Integer, _
ByRef lpNumberOfBytesWritten As Integer) As Integer
End Function
#End Region
'Constants
Private Const WM_USER As Int32 = &H400
Private Const IPC_GETPLAYLISTFILE = 211
Private Const IPC_GETPLAYLISTTITLE = 212
Public Const WA_TITLE = 212
Public Const WA_TRACK = 125
Private Const IPC_ISPLAYING = 104
Private Const IPC_GETLISTPOS As Long = 125
Public Shared Function FindWinampProcess() As Process
Dim RunningProcesses() As Process = Process.GetProcessesByName("winamp")
If RunningProcesses.Length > 0 Then
'Were Set
Return RunningProcesses(0)
Else
Return Nothing
End If
End Function
Private Function ReadStringPointer(ByVal intProcessId As Integer, ByVal intPointer As Integer) As String
'Read Pointer
Dim ProcessHandle As Integer = OpenProcess(PROCESS_VM_READ, 0, intProcessId)
Debug.WriteLine("ProcessHandle: " & ProcessHandle) 'Seems Like a Vaild Handle
If ProcessHandle = 0 Then
MsgBox("Invaild ProcessHandle")
Exit Function
End If
Dim Buffer As String = New String(Chr(0), 260)
Debug.WriteLine("Before ReadProcessMemory") ' Last Thing Displayed
Dim intRet As Integer = ReadProcessMemory(ProcessHandle, intPointer, Buffer, 260, vbNull) ' Stops Here, Treats it like Application.Exit
Debug.WriteLine("After ReadProcessMemory")
CloseHandle(ProcessHandle)
Debug.WriteLine("After CloseHandle")
MsgBox("Process Handle: " & ProcessHandle & vbCrLf & _
"Return Value: " & intRet)
Return Buffer
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim intProcessId As Integer = FindWinampProcess.Id
Dim intWinamphWnd As Integer = FindWinampProcess.MainWindowHandle.ToInt32
Dim intSongIndex As Integer = SendMessage(New IntPtr(intWinamphWnd), WM_USER, 0, IPC_GETLISTPOS).ToInt32
Dim intPointer As Integer = SendMessage(New IntPtr(intWinamphWnd), WM_USER, intSongIndex, WA_TITLE).ToInt32
MsgBox("Winamp Process ID: " & intProcessId & vbCrLf & _
"Winamp hWnd: " & intWinamphWnd & vbCrLf & _
"Song Index: " & intSongIndex & vbCrLf & _
"Pointer: " & intPointer)
'All This Seems Vaild
MsgBox(ReadStringPointer(intProcessId, intPointer))
MsgBox("Testing") 'THis Never Gets Displayed
'no form nothing
End Sub