By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

Controlling WinAMP (WM_COPYDATA problem)

P: n/a
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...

Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"The Collector" <th*************@gmail.com> writes:
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
Jul 19 '05 #2

P: n/a
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 )
----------------------------------

it's working like a charm now... I did found some other mistakes, but
the main problem was indeed solved by the 'global' thingy... so simple
(/me bangs head against the wall), thanks very much!

Jul 19 '05 #3

P: n/a
On 30 Jun 2005 11:48:31 -0700, rumours say that "The Collector"
<th*************@gmail.com> might have written:
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")
--
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.