Guest halfrubbish Posted November 9, 2002 Posted November 9, 2002 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 Quote
*Experts* Merrion Posted November 11, 2002 *Experts* Posted November 11, 2002 asdf = SendMessage(hwndWinamp, "WM_USER", "0", "0") Should these params be quoted? I'd have thought: asdf = SendMessage(hwndWinamp, WM_USER, 0, 0) ? Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Gurus* divil Posted November 11, 2002 *Gurus* Posted November 11, 2002 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Derek Stone Posted November 11, 2002 *Gurus* Posted November 11, 2002 Halfrubbish, you might want to learn a bit about Win32 API functions under .NET here: http://www.elitevb.com/content/01,0075,01/01.aspx Quote Posting Guidelines
Recommended Posts