If you're already calling LoadResource
and LockResource
, then you're already halfway there. LockResource
gives you a pointer to the first byte of the resource data. Call SizeofResource
to find out how many bytes are there, and you can do whatever you want with that block of memory, such as copy it to another block of memory or write it to a file.
resinfo := FindResource(module, MakeIntResource(resid), type);
hres := LoadResource(module, resinfo);
pres := LockResource(module, hres);
// The following is the only new line in your code. You should
// already have code like the above.
size := SizeofResource(module, resinfo);
Copy to another memory block:
var
buffer: TBytes;
SetLength(buffer, size);
Move(pres^, buffer[0], size);
Write to a file:
var
fs: TStream;
fs := TFileStream.Create('foo.wav', fmCreate);
try
fs.Write(pres^, size);
finally
fs.Free;
end;
This gives us several ways to play that wave data:
PlaySound(MakeIntResource(resid), module, snd_Resource);
PlaySound(PChar(pres), 0, snd_Memory);
PlaySound(PChar(@buffer[0]), 0, snd_Memory);
PlaySound('foo.wav', 0, snd_FileName);