slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Wed Aug 29, 2007 8:07 pm Post subject: Embedding .XM and player Delphi |
|
|
Well today, i wanted to embed a .XM into my Delphi app, and play it, i googled, and searched, ect. i could never get it to work tho in the end. This is as close as i got:
| Quote: |
Create a Resource file.
First fire up Notepad, and type in:
Then save it as Resources.rc.
I ran SDK and compiled it using:
That shouldve compiled the Rc file into a Resource File.
Now in my App, i had to make sure it was implemented in :
Now that the resource for the Xm file is done i had to now find a way to put the Xm into memory and call it from the App.
| Code: |
var
Music_XM: pointer;
function GetResourceAsPointer(ResName: pchar; ResType: pchar;
out Size: longword): pointer;
var
InfoBlock: HRSRC;
GlobalMemoryBlock: HGLOBAL;
begin
InfoBlock := FindResource(hInstance, resname, restype);
if InfoBlock = 0 then
raise Exception.Create(SysErrorMessage(GetLastError));
size := SizeofResource(hInstance, InfoBlock);
if size = 0 then
raise Exception.Create(SysErrorMessage(GetLastError));
GlobalMemoryBlock := LoadResource(hInstance, InfoBlock);
if GlobalMemoryBlock = 0 the
raise Exception.Create(SysErrorMessage(GetLastError));
Result := LockResource(GlobalMemoryBlock);
if Result = nil then
raise Exception.Create(SysErrorMessage(GetLastError));
end;
function GetResourceAsString(ResName: pchar; ResType: pchar): string;
var
ResData: PChar;
ResSize: Longword;
begin
ResData := GetResourceAsPointer(resname, restype, ResSize);
SetString(Result, ResData, ResSize);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
size: longword;
begin
Music_MX := GetResourceAsPointer('Music_XM', 'XM', size);
end;
|
Now to call it to play:
| Code: |
sndPlaySound(sample_wav, SND_MEMORY or SND_NODEFAULT or SND_ASYNC);
|
|
After all this, i still wasnt able to successfully embed the XM file in and play it. Can anyone take a look and give a review, that could help?
[/quote]
|
|