Packing data for a win32 'C' style system call to Winamp. help please!

A

Andy

I am trying to talk to Winamp2 from Perl on Win32 system.
According to winamp docs I need to send a windows message with the
following structure: (To add a file to the playlist)

COPYDATASTRUCT cds;
cds.dwData = IPC_PLAYFILE;
cds.lpData = (void *) "file.mp3";
cds.cbData = strlen((char *) cds.lpData)+1; // include space for
null
SendMessage(hwnd_winamp,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);

Somewhere else I found the structure to be defined as:

COPYDATASTRUCT cds;
cds.dwData = IPC_PLAYFILE;
cds.cbData = lstrlen(filename) + 1;
cds.lpData = (void *) filename;

which makes more sense, because it defines the length of the
filename before giving the pointer to it. However, this is confusing
because surely the order of the structure as it gets packed makes a
difference.

This is my test code, and it doesn't work:

<code start>
use Win32::GUI;

my $IPC_PLAYFILE = 100;
my $mp3file = 'demo.mp3';
my $wparam = pack("I", NULL);

my $dwData = pack("L", $IPC_PLAYFILE);
my $cbData = 9; #Hard coded length + 1 for test
my $lpData = pack("p", $mp3file);
my $lpCopydatastruct = pack("pLp", $dwData, $cbData, $lpData);

print Win32::GUI::SendMessage($winampHandle, WM_COPYDATA, $wparam,
$lpCopydatastruct);
<code end>

I know the winamp handle part is okay, other simple messages work,
but this one requires the c-style structure to be packed and I can't
get it to work. Anyone done stuff like this before, got an example
of how a C structure should be packed. Help please?

Thanks.
 

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,805
Latest member
ClydeHeld1

Latest Threads

Top