Results 1 to 12 of 12

Thread: Q: Sound files inside the exe

  1. #1

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post


    How do some programs have sound files inside the exe? I just played a game that was nothing but an exe and there were no sound files.

    How can I make an exe and have the sound files inside the exe instead of having to access them?

    Thank for reading this and any help you can provide.

    ------------------
    Steve Stunning

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    You can create a resource file that will be compiled with your EXE. Resource file can hold a lot of different file formats. If you have VB6, then you have a Resource Editor.
    To put the file in the resource: From the Add-Ins menu select Add-In Manager.... From the list select (put a check mark) a VB6 Resource Editor. Then, from the Project menu select Add New Resource File. A common dialog will be shown to give a name to your new resource file, do so (don't worry, this file will not be needed after you compile your program). Now, you will notice that in project explorer you would have a resource file added. Now, double click on that file. You will get the Resource Editor. From the toolbar select secon icon from the right (the icon called Add Custom Resource... Select the appropriate sounds (Wavs). Notice that editor will create an ID for each item you add. You can keep the default or change them to different ID by double click on each item. Close the Resource Editor. Let's say you keep the default IDs. Now, the programming part.

    Here is the generic routine that you can use:
    Code:
    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Const SND_ASYNC = &H1
    Private Const SND_NODEFAULT = &H2
    Private Const FLAGS = SND_ASYNC And SND_NODEFAULT
    Public Sub PlayWavResource(pintResourceID As Integer)
        Dim bytArr() As Byte
        Dim intFFN As Integer
        Dim strPath As String
    
        bytArr = LoadResData(pintResourceID, "CUSTOM")
        strPath = App.Path & IIf(Right(App.Path, 1) = "\", "~tempwav.wav", "\~tempwav.wav")
        intFFN = FreeFile
        Open strPath For Binary As intFFN
        Put #intFFN, , bytArr
        Close #intFFN
        Call sndPlaySound(strPath, FLAGS)
        Kill strPath
    End Sub
    Usage: PlayWavResource ResourceID
    Example: Call PlayWavResource(101)


    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819



    [This message has been edited by Serge (edited 12-02-1999).]

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Serge - or anyone - how could I modify the above to include an AVI in my EXE that plays using the Windows Media Player? I have the AVI as resource id 101 in the CUSTOM bit.

    Thank you

    Regards,

    ------------------
    - Chris
    [email protected]
    If it ain't broke - don't fix it

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure!

    Code:
    Public Sub PlayAVIResource(pintResourceID As Integer, pMediaPlayer As MediaPlayer)
        Dim bytArr() As Byte
        Dim intFFN As Integer
        Dim strPath As String
    
        bytArr = LoadResData(pintResourceID, "CUSTOM")
        strPath = App.Path & IIf(Right(App.Path, 1) = "\", "~tempavi.avi", "\~tempavi.avi")
        intFFN = FreeFile
        Open strPath For Binary As intFFN
        Put #intFFN, , bytArr
        Close #intFFN
        pMediaPlayer.FileName = strPath
        pMediaPlayer.Play
    End Sub
    Example: Call PlayAVIResource(101, MediaPlayer1)

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  5. #5

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post

    Thank you Serge... I will give it a try.

  6. #6
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    so is there any way to compile the EXE and write ActiveX files inside of it so that the user does not have to have them located on his/her hard drive? ...and so i don't have to package them with the software? because we all know that ActiveX references can be a ***** if the user does not have them in their Windows\System directory. ok. bye.

    --michael

  7. #7

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post

    Serge,

    It worked great. Thanks for you help!!

  8. #8
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    There is no need to write the wav file to disk before playing it.

    Code:
    Option Explicit
    Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Const SND_ASYNC = &H1     ' Play asynchronously
    Private Const SND_NODEFAULT = &H2 ' Don't use default sound
    Private Const SND_MEMORY = &H4    ' lpszSoundName points to a memory file
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim retVal As Long
    Dim SoundBuffer As String
        SoundBuffer = StrConv(LoadResData(101, "CUSTOM"), vbUnicode)  'replace 101 with your resource ID
        retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
    End Sub

  9. #9

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post


    Frans C,

    Even better.... I like not having to save it to disk prior to play!!

    Many thanks to you...

  10. #10
    Junior Member
    Join Date
    Jan 1999
    Location
    Fridley, MN, USA
    Posts
    19

    Post

    since im kinda confused by this, does anyone know how to run an exe. file from a resource file? They are default ( "Custom",101) settings.

  11. #11
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Use the method I posted earlier (which is to save the file to disk first), then use Shell statement:
    Code:
    Public Sub RunResourceExe(pintResourceID As Integer)
        Dim bytArr() As Byte
        Dim intFFN As Integer
        Dim strPath As String
    
        bytArr = LoadResData(pintResourceID, "CUSTOM")
        strPath = App.Path & IIf(Right(App.Path, 1) = "\", "~tempexe.exe", "\~tempexe.exe")
        intFFN = FreeFile
        Open strPath For Binary As intFFN
        Put #intFFN, , bytArr
        Close #intFFN
        Shell strPath, vbNormalFocus
    End Sub
    Example: RunResourceExe 101

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819



    [This message has been edited by Serge (edited 12-10-1999).]

  12. #12
    New Member
    Join Date
    Feb 2000
    Location
    Calgary, Alberta, Canada
    Posts
    2

    Post Need help with RES files

    1. Is there any way to write into a RES file from my app? My game uses RES files for levels and graphics, and I want to make an editor for it.

    2. Is there any way to (probably with the API) read from a RES file other than the one that is associated with my app? I want to have a separate RES file for each chapter of my game, so I can easily create add-ons.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width