API calls.

  • Thread starter Thread starter halfrubbish
  • Start date Start date
H

halfrubbish

Guest
Hi

Iam currently trying to develop a VB.Net app to retrieve the currently playing song title from Winamp when it is running. Winamp supports the windows messages program technique/API. Iam a rather novice programmer and need help with my program. So Far I have the following source code, in theory it should work. However in practice it doesnt. The program compiles fine but doesnt do anything when the code is called. The message sent should return the winamp version number. more info availble at http://www.winamp.com/nsdn/winamp2x/dev/sdk/api.jhtml
Any help will be appreciated. Thanks in advance.


Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim hwndWinamp As Long
Dim asdf
Private Sub Timer1_Timer()
hwndWinamp = FindWindow("Winamp v1.x", vbNullString)
asdf = SendMessage(hwndWinamp, "WM_USER", "0", "0")
TextBox1.Text = asdf
End Sub

End Class
 
API calls, when being ported to VB.NET, often have to be changed. Wherever you see anything declared as a Long, you should change it to Integer. Often, when these Integers are handles to things, they should be IntPtr instead.

As a rough guess, I have changed your API declarations and code to be as follows:

Code:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
 
Dim hwndWinamp As IntPtr 
Dim asdf As Integer

Private Sub Timer1_Timer() 
hwndWinamp = FindWindow("Winamp v1.x", vbNullString) 
asdf = SendMessage(hwndWinamp, WM_USER, 0, 0) 
TextBox1.Text = asdf.ToString()
End Sub

Ive also applied what Merrion said. I assume you have WM_USER declared somewhere with the correct value. If it still doesnt work, make sure you have Option Explicit AND Option Strict turned on, and tell us what error the compiler gives.
 
Back
Top