PDA

View Full Version : Winamp API problems


MrPuzzled
25th April 2002, 06:06
Hi,

I've been communicationg with Winamp 2.7 using the Winamp api and Delphi. Everything has worked ok, apart from one call, 211, getting the filename of a track in the playlist.
My code looks like this:

var
PC : PChar;
Index : Integer;
begin
Index := 0;
PC := PChar(SendMessage(hwnd_winamp, WM_USER, Index, 211));
Result := String(PC);
end;

With PC returning the filename string, but this causes an Access Violation, (incidently, I've checked to see if PC is nil (same as NULL in C), it isn't). I also know hwnd_winamp is pointing to the correct window handle, as the other commands work ok.

A description of the command reads as follows:
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.

Anyone help? Or has anyone got a working example of using call in another language, such as C++? Maybe I could port it over.

Thanks

Gourou
25th April 2002, 13:18
http://forums.winamp.com/showthread.php?s=&threadid=85389

MrPuzzled
4th May 2002, 08:06
Hi,

Thanks, with a bit of messing around I got that working (see below), thanks alot. Strange how more than one person was asking the same question around the same time.

Problem I had:
My version of Delphi (4) took didn't like TempHandle in GetWindowThreadProcessId(hwndWinamp,TempHandle); not being a pointer (perhaps Heiko S was using ver 5 or higher), and refused to compile, and unfortunately typecasting it as a pointer seemed to mess it up, as I was still get Access Violations afterwards, but luckily I remember that I'd used GetWindowThreadProcessId before, so I swapped in my code, I eventually ended up with the following, which works fine (hardly any different of course):


Function GetWinampFilename: String;
var
Text, tempStr: String;
hwndWinamp, TempHandle : THandle;
dat2: array[0..500] of Char;
TrackPos: Integer;
MPointer: Pointer;
temp : Cardinal;
ProcessId, ThreadId : integer;
begin
tempStr := '';
hwndWinamp:= FindWindow('Winamp v1.x', nil);
If hwndWinamp <> 0 Then begin
TrackPos:= SendMessage(hwndWinamp,WM_USER,0 , 125);
MPointer:= Pointer(SendMessage(hwndWinamp,WM_USER, TrackPos, 211));
If MPointer <> nil Then begin
ThreadId := GetWindowThreadProcessId(hwndWinamp, @ProcessId);
hwndWinamp := OpenProcess(PROCESS_ALL_ACCESS, False, ProcessId);
If hwndWinamp <> 0 Then begin
ReadProcessMemory(hwndWinamp, MPointer, @dat2, 500, temp);
tempstr := dat2;
CloseHandle(hwndWinamp);
End; // If
End; // If
End; // If
Result:= tempStr;
end;

Incidently, I seem to remember reading that GetWindowThreadProcessId isn't available in Windows NT, so I assume this only works for 9X, 2000 and XP. Although I guess its debatable how many people there are still using Winamp on NT :).


Thanks alot

MrPuzzled
4th May 2002, 08:08
Ugh, seems it doesn't like my tabbed indenting :)

Gourou
4th May 2002, 22:11
:p
never likes my vb code, makes it look all icky without the indents tho :cry: