Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > WinAMP Question


Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2002, 06:00 AM
Megazoid Megazoid is offline
Regular
 
Join Date: Jul 2002
Location: UK
Posts: 70
Default WinAMP Question

I am currently working on a plugin for winamp 2.81. I have a few API questions, i was wondering if anyone knew the answers to. Please note i am developing this plugin in VB using the GenWrapper which is available for Winamp.

I have managed to create a class that does everything i require (almost).

Here are some of the following functions i wrote:


Function WinAMP_GetPlaylistPosition() As Long

Dim ReturnPos As Long

ReturnPos = SendMessage(hWndWinAMP, WM_USER, 0, WA_GETPLAYPOS)
PositionInPlaylist = ReturnPos
WinAMP_GetPlaylistPosition = ReturnPos

End Function


This above functions get the position in 'tracks' of where i am in the playlist. This dosent locate the the highlighted item, it only returns what i double click.

I NEED to return the filename (complete path) of the items i click within the playlist.

So i managed to find a function in the winamp API that returned what was supposed to be the filename but it returned what looked like a pointer.

http://www.winamp.com/nsdn/winamp2x/dev/sdk/api.jhtml

I managed to locate the information i required on here.

Quote:
211 Retrieves (and returns a pointer in 'ret') a string that contains the filename of a playlist entry (indexed by 'data'). Returns NULL if error, or if 'data' is out of range.
This looked like what i require.

So i wrote this VB function:



Function WinAMP_GetFileName() As Long
Dim ReturnFile As Long

ReturnFile = SendMessage(hWndWinAMP, WM_USER, PositionInPlaylist, WA_GETPLAYLISTFILE)

WinAMP_GetFileName = ReturnFile
Debug.Print StringFromPointer(ReturnFile)
End Function


Public Function StringFromPointer(ByVal lPointer As Long) As String
'
Dim strTemp As String
Dim lRetVal As Long
'
'prepare the strTemp buffer
strTemp = String$(lstrlen(ByVal lPointer), 0)
'
'copy the string into the strTemp buffer
lRetVal = lstrcpy(ByVal strTemp, ByVal lPointer)
'
'return a string
If lRetVal Then StringFromPointer = strTemp
'
End Function


But it returns 'crap' basically. Not the filename it returns this:

MSVW‹ÿP‹} ‹ð…öte‹Fƒx

I cant understand?? I then downloaded the .h file and decided to look through that to find some help.

It said that function ONLY works if its part as a plugin, at this current stage my program is external and not using GenWrapper, all i am doing is sending API calls to WinAMP anyhow. I CANT see why it needs to be a plugin...i have not had problems before getting data from programs using similar methods.

Anyway i checked out the API FAQ and here is what i found:


How do I get the filename (not title) of the current song?
First you must get the current track index from the playlist. Then you can get the filename.


int index = SendMessage(hwnd_winamp, WM_USER, 0, IPC_GETLISTPOS);
char *name = SendMessage(hwnd_winamp, WM_USER, index, IPC_GETPLAYLISTFILE);


This is what i have been doing but with no luck. Can anyone help me on this one? I am a skilled API coder but this one is killing me!

Its holding me back as well...

Thanks in advance folks.

I am awaure of the const' that exports the playlist direct to temp.m3u but i dont want to start playing around with files searching for filenames (even though its simple) i want a clean cut API solution.

- Dave
Reply With Quote
  #2  
Old 11-01-2002, 06:23 AM
Garmour's Avatar
Garmour Garmour is offline
Back for a little while..

Retired Leader
* Expert *
 
Join Date: Oct 2002
Location: Behind you.....Boo
Posts: 2,199
Default

No idea, but I had a look at the vbsample from the winamp api code section and it does refer to tracks so perhaps that can help (although you've probably already got it).
__________________

....but then, what would I know ?
Reply With Quote
  #3  
Old 11-01-2002, 07:55 AM
Megazoid Megazoid is offline
Regular
 
Join Date: Jul 2002
Location: UK
Posts: 70
Default

already checked that out garmour, its not what i am looking for, but good idea all the same.

Anyone else?
Reply With Quote
  #4  
Old 11-05-2002, 11:48 AM
ChrisNC ChrisNC is offline
Newcomer
 
Join Date: Nov 2002
Location: Charlotte, NC USA
Posts: 15
Default

I got this function from the Winamp Developer's forum. I haven't included the code to get the hwnd of Winamp or my TrimNulls function. You seem to know enough to take care of those tasks.

===============

' Functions used to get the song title and filename from Winamp
Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" _
(ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, _
ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Property Get FileName(Optional lpos As Long = 0) As String
'------------------------------------'
'Retrieves the file name of the track'
'------------------------------------'

Dim TrackPos As Long
Dim MPointer As Long
Dim Temp As Long
Dim TempHandle As Long
Dim hwndWinampP As Long
Dim data As String
Dim ntemp As Long
Dim ptemp As Long


'Check to see if the playlist position is out of range
If < 0 Or > PlayListLength Then
FileName = vbNullString
Exit Property
End If

If = 0 Then 'If no playlist position is specified, then the current song is used
TrackPos = SendMessage(hwndWinAMP, WM_USER, 0, WA_GETPLAYLISTPOS)
Else
TrackPos = lpos - 1
End If

MPointer = SendMessage(hwndWinAMP, WM_USER, TrackPos, WA_FILENAME)
Temp = GetWindowThreadProcessId(hwndWinAMP, TempHandle)
hwndWinampP = OpenProcess(PROCESS_VM_READ, False, TempHandle)
'Create a string of nulls, the filename will be copied from memory to this string
data = String$(256, vbNullChar)
'Read the memory location and store in data
ntemp = ReadProcessMemory(hwndWinampP, MPointer, data, 256, Temp)
ptemp = CloseHandle(hwndWinampP)

'Convert the null terminated string into a normal string
FileName = TrimNull(data)

End Property
Reply With Quote
  #5  
Old 11-05-2002, 12:11 PM
Megazoid Megazoid is offline
Regular
 
Join Date: Jul 2002
Location: UK
Posts: 70
Default

HUGE THANKS CHRIS!

I have not had a chance to test it, going to test it out when i return from work.

Thanks again mate...
Reply With Quote
  #6  
Old 11-05-2002, 12:12 PM
Megazoid Megazoid is offline
Regular
 
Join Date: Jul 2002
Location: UK
Posts: 70
Default

just one more thing, can you list the constants values you are using ? i think i am using the correct ones but not 100% sure.
Reply With Quote
  #7  
Old 11-05-2002, 12:20 PM
ChrisNC ChrisNC is offline
Newcomer
 
Join Date: Nov 2002
Location: Charlotte, NC USA
Posts: 15
Default

My first post has some problems. It seems the software running this forum removes the word p o s (without the spaces). Here is a corrected version. I replaced all occurences of p o s with lpos.

===========

' Functions used to get the song title and filename from Winamp
Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" _
(ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, _
ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Property Get FileName(Optional lpos As Long = 0) As String
'------------------------------------'
'Retrieves the file name of the track'
'------------------------------------'

Dim TrackPos As Long
Dim MPointer As Long
Dim Temp As Long
Dim TempHandle As Long
Dim hwndWinampP As Long
Dim data As String
Dim ntemp As Long
Dim ptemp As Long


'Check to see if the playlist position is out of range
If lpos < 0 Or lpos > PlayListLength Then
FileName = vbNullString
Exit Property
End If

If lpos = 0 Then 'If no playlist position is specified, then the current song is used
TrackPos = SendMessage(hwndWinAMP, WM_USER, 0, WA_GETPLAYLISTPOS)
Else
TrackPos = lpos - 1
End If

MPointer = SendMessage(hwndWinAMP, WM_USER, TrackPos, WA_FILENAME)
Temp = GetWindowThreadProcessId(hwndWinAMP, TempHandle)
hwndWinampP = OpenProcess(PROCESS_VM_READ, False, TempHandle)
'Create a string of nulls, the filename will be copied from memory to this string
data = String$(256, vbNullChar)
'Read the memory location and store in data
ntemp = ReadProcessMemory(hwndWinampP, MPointer, data, 256, Temp)
ptemp = CloseHandle(hwndWinampP)

'Convert the null terminated string into a normal string
FileName = TrimNull(data)

End Property
Reply With Quote
  #8  
Old 11-05-2002, 12:27 PM
ChrisNC ChrisNC is offline
Newcomer
 
Join Date: Nov 2002
Location: Charlotte, NC USA
Posts: 15
Default WinAmp Class Module

Here is my entire WinAmp control class. You can get the constants from there.

The InsertFile method does not work. I haven't been able to convert the C code to the correct VB version. All of the other code should work fine. You'll need to change the WINAMP_PATH constant to point to where you have installed your copy of WinAmp.

Hope this helps.

Chris
Attached Files
File Type: cls clswinampcontrol.cls (39.2 KB, 46 views)
Reply With Quote
  #9  
Old 11-05-2002, 12:53 PM
Megazoid Megazoid is offline
Regular
 
Join Date: Jul 2002
Location: UK
Posts: 70
Default

Very special thanks chris for this. This class is very usful. I already have roughly 90% of those functions written though (using the api list available on winamp.com) but the filename and returning the title, artist, were holding me back badly.

Just one final question (as you seem to know your winamp api well) do you know if its possible to return the index (so i can get it's filename) of the highlighed item within the playlist. I dont actually think this can be accomplused using Winamp API but rather using WinAPI and hooking.

On this subject do you know if its possible to also add a menu entry to winamps playlist menu when you right click on an entry the menu popup (i.e. File info, Play Item(s) menu).

I have downloaded various plugins that accomplish this, i tried using appendmenu api, but never got anywhere.

Back to the playlist stuff, this may sound confusing but what i mean, is when you do a single click on a file within the playlist it dosent execute/play the file, only hightlights it. I would like to be able to be able todo this. Maybe you have some ideas?

You have been of excellent help btw, may i ask if its ok to put your name in the program credits? I see you dont have your full name on this forum, feel free to email it to me (or i can use your alias if you like?).

Thanks in advance Chris.
Reply With Quote
  #10  
Old 11-05-2002, 01:03 PM
vbsolns
Guest
 
Posts: n/a
Default

Your code looks ok to me. The problem as I'm sure you appreciate is returning null terminated string pointers to Visual Basic which doesn't directly understand them (it uses BSTR), but your code should be able to sort this. The only comment I would make is that I don't think you have allocated space for the null terminator in the line:

strTemp = String$(lstrlen(ByVal lPointer), 0)

because lstrlen returns only the character count not including the null terminator, whereas the lstrcpy copies the null as well so perhaps
strTemp = String$(lstrlen(ByVal lPointer)+1, 0)
might help, but I think there may be more to it than that.

Hope this helps.
Reply With Quote
  #11  
Old 11-05-2002, 01:05 PM
ChrisNC ChrisNC is offline
Newcomer
 
Join Date: Nov 2002
Location: Charlotte, NC USA
Posts: 15
Default

I'm just a guy who takes other's work and puts it all together in a nice little package. You don't need to give me credit.

I don't know the answer to any of your other questions. I don't think there is a way to do what you want using the Winamp API. You will have to hook into the Windows messages. I've never done such a thing before. Sorry. Good luck with your program.

You might want to ask more questions on the Winamp developer's forum at http://forums.winamp.com .

Chris
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:

Powered by liquidweb