Jump to content
Xtreme .Net Talk

Recommended Posts

Guest halfrubbish
Posted

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

  • *Gurus*
Posted

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:

 

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

 

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

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...