Cramming into 1 EXE file

This is a discussion on Cramming into 1 EXE file within the Windows Programming forums, part of the Platform Specific Boards category; My Second Win32 program.... This one uses .wav files, When i compile and get the exe and run it in ...

  1. #1
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187

    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

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    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.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    Unregistered
    Guest
    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 :
    http://www.corrado.italy.com/help.gif

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You need to specify the SND_RESOURCE flag in your PlaySound() function call.

  5. #5
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    It's now changed to :
    ...And the .exe still doesn't embed the .wav file

    LoadResource(NULL, (HRSRC)"GF_Pauly.wav");

    LockResource((HRSRC)"GF_Pauly.wav");

    PlaySound("GF_Pauly.wav",NULL,SND_FILENAME | SND_ASYNC | SND_RESOURCE);

  6. #6
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    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).
    Last edited by johnnie2; 01-04-2002 at 09:34 PM.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  7. #7
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    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.

    MSDN :
    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)

  8. #8
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187

    The Answer

    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 !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21