You can add the SND_MEMORY flag, and pass a TResourceStream.Memory
pointer as the first parameter.
First, use XE2's Project->Resources and Images
menu item to add a new resource. Give it the path and filename of your .wav file, a resource type of RC_DATA
(it's not in the drop down list, but you can manually type it in), and a resource name you can use at runtime to refer to it. (In my example, I'm using C:\Microsoft Office\Office12\MEDIA\APPLAUSE.WAV
, and giving it a resource name of APPLAUSE
.)
procedure TForm2.Button1Click(Sender: TObject);
var
Res: TResourceStream;
begin
Res := TResourceStream.Create(HInstance, 'APPLAUSE', 'RC_DATA');
try
Res.Position := 0;
SndPlaySound(Res.Memory, SND_MEMORY or SND_ASYNC or SND_LOOP);
finally
Res.Free;
end;
end;