# VB 5, Winamp Front End... issues with SendMessage API



## NitroNic (Oct 19, 2003)

Having some trouble here. I'm not getting any errors, the problem is I'm not getting the output I expect.

Form1's code is here:


```
Dim hwndWinamp As Long
Const WM_USER = &H400
Const WM_COMMAND = &H111

Private Sub cmdGetTime_Click()
    Dim CurPos As Long
    
    MsgBox (hwndWinamp)
    CurPos = SendMessage(hwndWinamp, WM_USER, 0, 105)
    
    MsgBox (CurPos)
End Sub

Private Sub cmdWindowHandle_Click()

    
    hwndWinamp = FindWindow("Winamp v1.x", vbNullString)
    MsgBox (hwndWinamp)
End Sub
```
There is also a module, whose code is here:


```
'''' Find window handle Number for wINAMP
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long



''''' Message Sending Stuff

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
```
The findwindow part works just fine.

But the part to get the current position in milliseconds... well, the variable CurPos always equals 1. I've tried different parameters, none of them seem to work. So I figure I"m doing something wrong.

Any ideas? I would appreciate pointing out what I (could) have done wrong, not just an example of what's right, especially a long one... because I could stare at it for hours and not find the difference... look right over the mistake.

Thanks in advance!

Nic


----------



## x-cubed (Aug 24, 2004)

I was playing round with your code and found that it was a simple but wierd bug. For some strange reason it is possible to pass constants by reference which causes lots of grief! So the fix is to prefix all message constants in calls to SendMessage with the keyword ByVal, ie:


```
Result = SendMessage(hwndWinamp, WM_USER, 0, ByVal 105)
```
Works great now! :up:


----------



## NitroNic (Oct 19, 2003)

You........... are a genius!!!!!!!! I tried it and it works too. This has been a roadblock for a couple of weeks, I've messed arround with it pretty often, getting no where.

Any explanation as to _why_ passing by value makes it work?

Anyway, thanks again! I'll be sure and give you credit when the application is finished! It's not commercial... but still I'll be showing it off to people  and so anyone who helped (especially THIS MUCH) deserves to be credited.

Nic


----------



## x-cubed (Aug 24, 2004)

Glad I could help!

I assume what VB is doing is that it is passing a pointer to the constant rather than the value of the constant itself.

BTW, if you manage to figure out how to get the name of the file that is currently playing, give me buzz. I've got some demo code that uses ReadProcessMemory to try to read the playlist from the memory allocated to Winamp but it isn't working. I'm wondering if XP's security policy is the issue...


----------



## NitroNic (Oct 19, 2003)

Hmmm... I'll mess arround with it and see if I can get the current file name. The way my application is going to work (at least how I have planned to so far), winamp does nothing but play and receive commands from the front end. SO the front end actually manages, picks, and reads the file names, reads the ID3 tags, and tells winamp to play such and such file.

I'll give it a try though, I'm a windows 2000er for development on this, although the final product will probably be run on something else.


----------



## x-cubed (Aug 24, 2004)

Good luck. Maybe its just buggy code, but the few front-ends for Winamp that I've tried have had trouble recognising when one track finishes and another starts, but if you can keep the front-end in charge of everything you should be fine. 

Have you had a look at the code at VBaccelerator.com? It may be more suited to what you want to do. It will allow you to use the Winamp plugins independently of the main engine. Although if you still want visualisations and stuff it won't be of any use...

My plan is to develop an ActiveX DLL to control Winamp, so that I can control Winamp from anywhere!  Then I can make a variety of front-ends to plug into it including a series of ASPs (Active Server Pages) to allow me to control it over the net!

If you need any help or want to work together on this, I'm more than happy...


----------

