The following works but I can't figure out if it is adequately allocating memory that it returns back to MM. Please give me some comments.
Code: Select all
function DeviceiTunesListPlaylists(DeviceHandle :Integer): PScanResult;
type
PFileName = ^TFileName;
TFileName = array [0 .. 255] of WideChar;
var
lst: TStringList;
i, size: integer;
name: String;
name2: PFileName;
begin
// list of playlists please
Lst := getListOfPlaylists(dev);
// allocate the memory for the reply back
new(Result);
Result.FileCount := lst.count;
size := lst.count * sizeof(PScanRecord);
GetMem(Result^.Files,size);
log.text(2, 'number and size', lst.count , size);
// iterate through the list ...
for i := 0 to lst.count - 1 do
begin
name := lst[i];
log.text(2, i, 'playlist', name);
new(name2);
StrCopy(@name2[1], PWideChar(name));
new(Result.Files[i]);
Result.Files[i].filename := @name2[1];
Result.Files[i].filesize := 0;
Result.Files[i].lastmodified := 0;
Result.Files[i].track_cookie := 0;
end;