Cramming into 1 EXE file
My Second Win32 program....
This one uses .wav files, When i compile and get the exe and run it in a different directory on my PC it doesn't play the sounds cause their not in the directory.
My question is how can I Embed the sound files into the .exe to make it more easily portable ?
Thanks in Advance
Store the sound files as data resources so that they are automatically compiled into the final .exe. When you want a file, read a specific resource back, using a combination of LoadResource() and LockResource() to secure the data.
That's Exactly what i want to do but i'm still having trouble doing it, I'm still learning win prog from my C++ experience.
This is what i have (screenshot link)
are the files loaded where they should be ?
are the funcation calls (highlited) proper ?
..The .exe file didn't get any larger..
I'm having some real trouble as you can see...
Workspace screenshot :
You need to specify the SND_RESOURCE flag in your PlaySound() function call.
It's now changed to :
...And the .exe still doesn't embed the .wav file
PlaySound("GF_Pauly.wav",NULL,SND_FILENAME | SND_ASYNC | SND_RESOURCE);
Alright, according to the MSDN documentation on PlaySound(), if you enter SND_RESOURCE as a flag, the first parameter just has to be the resource identifier. LoadResource() and LockResource() aren't needed. So, just pass the identifier to the function and all should be well.
But, you must provide a non-NULL value for the second parameter, which is a handle to the executable file. You can get this with GetModuleHandle(NULL).
PlaySound("GF_Pauly.wav", NULL, SND_FILENAME | SND_ASYNC | SND_RESOURCE);
You must have 3 parameters, i think that SND_RESOURCE means that you don't have to specify the second parameter to be NULL, instead a handle.
hmod (second parameter)
Handle to the executable file that contains
the resource to be loaded.
ok, how do i get a handle to a .wav ?
(NB: newbie here)
Alright Guys Thanks for all the help, I found out how to do it and thought I'd post the answer for all to see..
... !! Behold !! ...
PlaySound((char *)IDR_WAVE2, GetModuleHandle(0), SND_RESOURCE | SND_ASYNC);
p.s. Couldn't have done it without the C BOARD !