Controlling WinAMP (WM_COPYDATA problem)

T

The Collector

Hi,

I've been looking for almost two full days now to get full control of
WinAMP using python. Simple play/stop functions are no problem. It's
the WM_COPYDATA that's used by IPC_PLAYFILE (=add a file to the
playlist) that's giving me troubles big time!

My latest test code:
---------------------------------------
from win32gui import FindWindow
from win32api import SendMessage
import struct
import array

WM_USER = 0x400 # WM-ID for
a WinAMP user command
WM_COPYDATA = 0x004A # WM-ID for
a WinAMP copyData command
IPC_PLAYFILE = 100 # WM-ID for
WinAMP to add item to WinAMP playlist

hWnd = FindWindow('Winamp v1.x', None) # Find the
WinAMP window-handle (receiver)

def packData( dwData, lpData ):
lpData_ad = array.array('c', lpData).buffer_info()[0] # calculate
the pointer address for the lpData
cbData = array.array('c', lpData).buffer_info()[1] # calculate
the length of the lpData (=cbData)
cds = struct.pack("IIP", dwData, cbData, lpData_ad) # pack
dwData, cbData and lpData into a copyDataStruct
cds_ad = array.array('c', cds).buffer_info()[0] # find the
pointer address of the copyDataStruct
return cds_ad # return
the copyDataStruct pointer-address

def addItemToPlaylist( item ):
uInt = IPC_PLAYFILE # ID for
adding an item to the WinAMP playlist
wParam = 0 # Not
defined (leave at zero)
lParam = packData( uInt, item ) # create
the copyDataStruct-pointer
SendMessage( hWnd, uInt, wParam, lParam ) # Send the
data to the WinAMP window

file = r"C:\Party Animals - Atomic.mp3"
addItemToPlaylist( file )
---------------------------------------

the code runs fine, no errors, but nothing happens!! I've already had a
test in which garbage was added to the playlist, but that's it...

Anybody, any ideas on the problem? tnx...
 
T

Thomas Heller

The Collector said:
Hi,

I've been looking for almost two full days now to get full control of
WinAMP using python. Simple play/stop functions are no problem. It's
the WM_COPYDATA that's used by IPC_PLAYFILE (=add a file to the
playlist) that's giving me troubles big time!

My latest test code:
---------------------------------------
[reformatted the packData function]

def packData( dwData, lpData ):
# calculate the pointer address for the lpData
lpData_ad = array.array('c', lpData).buffer_info()[0]
# calculate the length of the lpData (=cbData)
cbData = array.array('c', lpData).buffer_info()[1]
# pack dwData, cbData and lpData into a copyDataStruct
cds = struct.pack("IIP", dwData, cbData, lpData_ad)
# find the pointer address of the copyDataStruct
cds_ad = array.array('c', cds).buffer_info()[0]
# return the copyDataStruct pointer-address
return cds_ad

From a quick inspection of the packData function:

You need to keep the array instances alive! You only retrieve the
addresses, and the array instances itself are deleted immediately, so
the addresses are no longer valid.

(Hint: ctypes might also be a solution for you - it allows flexible
creation of C compatible data structures)

Thomas
 
T

The Collector

Hi, i changed the code to this:
----------------------------------
from win32gui import FindWindow
from win32api import SendMessage
import struct
import array

hWnd = FindWindow('Winamp v1.x', None)

def packData( dwData, item ):
global cds, lpData
lpData = array.array('c', item)
lpData_ad = lpData.buffer_info()[0]
cbData = lpData.buffer_info()[1]
cds = array.array('c', struct.pack("IIP", dwData, cbData,
lpData_ad) )
cds_ad = cds.buffer_info()[0]
return cds_ad

def addItemToPlaylist( item ):
SendMessage( hWnd, 0x004A, 0, packData( 100, item ) )

file = r"C:\Party Animals - Atomic.mp3"
addItemToPlaylist( file )
 
C

Christos TZOTZIOY Georgiou

Hi,

I've been looking for almost two full days now to get full control of
WinAMP using python. Simple play/stop functions are no problem. It's
the WM_COPYDATA that's used by IPC_PLAYFILE (=add a file to the
playlist) that's giving me troubles big time!

An alternative that could be easier to use is WinAmpCOM (a plugin for
winamp that makes it a COM server, so using pywin32 or ctypes you can
control it with much ease.)

It's available in the www.winamp.com site. (Search for plugin
"winampcom")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top