resource file

I learned how to add source files to the excutable file (sound files in my project)
The question is: can I make that resources in a single seperated file so I can reach my resources from a files outside the exeutable?

Comments

  • Do you mean to call a sound file in code, but have the sound file separate, (like in another directory)? Just call the sndPlaySound API if it's a wav file and specify the filename:

    [code]
    Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

    Public Const SND_APPLICATION = &H80 ' look for application specific association
    Public Const SND_ASYNC = &H1 ' play asynchronously
    Public Const SND_FILENAME = &H20000 ' name is a file name
    Public Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
    Public Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
    Public Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
    Public Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
    Public Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy
    Public Const SND_PURGE = &H40 ' purge non-static events for task
    Public Const SND_RESERVED = &HFF000000 ' In particular these flags are reserved
    Public Const SND_RESOURCE = &H40004 ' name is a resource name or atom
    Public Const SND_SYNC = &H0 ' play synchronously (default)
    Public Const SND_TYPE_MASK = &H170007
    Public Const SND_VALID = &H1F ' valid flags / ;Internal /
    Public Const SND_VALIDFLAGS = &H17201F ' Set of valid flag bits. Anything outside
    Public Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry
    Public Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier
    Public Const SND_ALIAS_START = 0 ' must be > 4096 to keep strings in same section of resource file


    Private Function PlaySound(sLocation as String)
    sndPlaySound sLocation, SND_ASYNC OR SND_FILENAME
    End Function
    [/code]


  • : Do you mean to call a sound file in code, but have the sound file separate, (like in another directory)?

    Not that.
    I have multiple wave sounds contained in one resource file created by VB6 resource editor.
    Usually this resource file engaged in the .exe file when compile.
    I want to creat this file and remove it from my project then when I compile to exe I have a separated resource file.
    my question is: can I reach wave files in that 9separated) resource file by code?
  • : : Do you mean to call a sound file in code, but have the sound file separate, (like in another directory)?
    :
    : Not that.
    : I have multiple wave sounds contained in one resource file created by VB6 resource editor.
    : Usually this resource file engaged in the .exe file when compile.
    : I want to creat this file and remove it from my project then when I compile to exe I have a separated resource file.
    : my question is: can I reach wave files in that 9separated) resource file by code?
    :
    According to the MSDN Library, you can't do that. Although you can compile your resource file externally, it has to be included in the project when it's compiled. This is what the library says:

    "One of the ways to distribute these required files is to include them in a resource file. The resource file is compiled into the EXE. This makes the included files available to the program, but keeps the user from being able to modify them. "



  • : "One of the ways to distribute these required files is to include them in a resource file. The resource file is compiled into the EXE. This makes the included files available to the program, but keeps the user from being able to modify them. "
    :
    :
    :
    Is there a way to gother wave files in one file and run the one I need from VB?

    Thanks again.
  • : : "One of the ways to distribute these required files is to include them in a resource file. The resource file is compiled into the EXE. This makes the included files available to the program, but keeps the user from being able to modify them. "
    : :
    : :
    : :
    : Is there a way to gother wave files in one file and run the one I need from VB?
    :
    : Thanks again.
    :

    There are only three ways that come to mind.
    1) Place all the wavs into one big one.
    This is what some of the older games did (like Buried in Time, Myst, etc. They encoded all the scenes into a quicktime movie file, then just played the selection that corresponded with the movement you wanted.)

    2) Place the WAV files in an INI file
    You can either use the Windows INI API's (getProfileString, etc.) or you can write your own Setting text file. The way I did it once was to have headings and lines. Then I could read one line at a time and know if it was a heading (if it was, I knew what section I was in), or a line of code (which I could parse - left side was the command, right side was the filename). For example:

    [Default Sounds] ' Heading
    Startup="soundsstartup.wav"
    End="soundsend.wav"
    [System Sounds] ' New Heading
    Startup="c:winntsoundswindows start.wav"
    End="c:winntsoundswindows end.wav"

    Then you could also encode/decode it with a custom algorithm.

    3) Or you could rename your wav files to say, .tmp and encode the name (like if you want John singing Country at 120 beats per minute, the filename could be jnct128.tmp)

    Other than that, I don't know of any other ways, unless you could create a custom resource file (maybe a way to read WinZip files). Then you could compress your sound files into one WinZip file and read them.
  • : : : "One of the ways to distribute these required files is to include them in a resource file. The resource file is compiled into the EXE. This makes the included files available to the program, but keeps the user from being able to modify them. "
    : : :
    : : :
    : : :
    : : Is there a way to gother wave files in one file and run the one I need from VB?
    : :
    : : Thanks again.
    : :
    :
    : There are only three ways that come to mind.
    : 1) Place all the wavs into one big one.
    : This is what some of the older games did (like Buried in Time, Myst, etc. They encoded all the scenes into a quicktime movie file, then just played the selection that corresponded with the movement you wanted.)
    :
    : 2) Place the WAV files in an INI file
    : You can either use the Windows INI API's (getProfileString, etc.) or you can write your own Setting text file. The way I did it once was to have headings and lines. Then I could read one line at a time and know if it was a heading (if it was, I knew what section I was in), or a line of code (which I could parse - left side was the command, right side was the filename). For example:
    :
    : [Default Sounds] ' Heading
    : Startup="soundsstartup.wav"
    : End="soundsend.wav"
    : [System Sounds] ' New Heading
    : Startup="c:winntsoundswindows start.wav"
    : End="c:winntsoundswindows end.wav"
    :
    : Then you could also encode/decode it with a custom algorithm.
    :
    : 3) Or you could rename your wav files to say, .tmp and encode the name (like if you want John singing Country at 120 beats per minute, the filename could be jnct128.tmp)
    :
    : Other than that, I don't know of any other ways, unless you could create a custom resource file (maybe a way to read WinZip files). Then you could compress your sound files into one WinZip file and read them.
    :

    Thanks for the replay, that is the idea I asked for.
    But I just get a new way to do that:
    I can creat a new formless program and add my resource file to it and with a few lines of code in the Sub Main I can play the file I want reffered by a parameter passed when lunch this sub program.
    Is it a good idea? can it do the purpose?
    please tell me, and help me.

    Thanks alot.
  • That should work, but you can still only have one resoure file per project. If that works, then do it. BTW, what are these sound files used for? Are they just for default program sounds, or for a game, or what?

    : : : : "One of the ways to distribute these required files is to include them in a resource file. The resource file is compiled into the EXE. This makes the included files available to the program, but keeps the user from being able to modify them. "
    : : : :
    : : : :
    : : : :
    : : : Is there a way to gother wave files in one file and run the one I need from VB?
    : : :
    : : : Thanks again.
    : : :
    : :
    : : There are only three ways that come to mind.
    : : 1) Place all the wavs into one big one.
    : : This is what some of the older games did (like Buried in Time, Myst, etc. They encoded all the scenes into a quicktime movie file, then just played the selection that corresponded with the movement you wanted.)
    : :
    : : 2) Place the WAV files in an INI file
    : : You can either use the Windows INI API's (getProfileString, etc.) or you can write your own Setting text file. The way I did it once was to have headings and lines. Then I could read one line at a time and know if it was a heading (if it was, I knew what section I was in), or a line of code (which I could parse - left side was the command, right side was the filename). For example:
    : :
    : : [Default Sounds] ' Heading
    : : Startup="soundsstartup.wav"
    : : End="soundsend.wav"
    : : [System Sounds] ' New Heading
    : : Startup="c:winntsoundswindows start.wav"
    : : End="c:winntsoundswindows end.wav"
    : :
    : : Then you could also encode/decode it with a custom algorithm.
    : :
    : : 3) Or you could rename your wav files to say, .tmp and encode the name (like if you want John singing Country at 120 beats per minute, the filename could be jnct128.tmp)
    : :
    : : Other than that, I don't know of any other ways, unless you could create a custom resource file (maybe a way to read WinZip files). Then you could compress your sound files into one WinZip file and read them.
    : :
    :
    : Thanks for the replay, that is the idea I asked for.
    : But I just get a new way to do that:
    : I can creat a new formless program and add my resource file to it and with a few lines of code in the Sub Main I can play the file I want reffered by a parameter passed when lunch this sub program.
    : Is it a good idea? can it do the purpose?
    : please tell me, and help me.
    :
    : Thanks alot.
    :

  • : That should work, but you can still only have one resoure file per project. If that works, then do it. BTW, what are these sound files used for? Are they just for default program sounds, or for a game, or what?
    :
    :

    They are sound effects for my program, for example key click sound when writting, welcome message when starting ... and so on, all of it are short.

    The problem with my last idea is that to lunch other program could take long time for an effect to play.
    Thanks for help maybe I'll try one of your methods.

  • : They are sound effects for my program, for example key click sound when writting, welcome message when starting ... and so on, all of it are short.
    :
    : The problem with my last idea is that to lunch other program could take long time for an effect to play.
    : Thanks for help maybe I'll try one of your methods.

    Could be another option. Why do you want the resource file seperate?

  • : Could be another option. Why do you want the resource file seperate?
    :
    Because the .exe file will becomes fairly big in size and that is not good, and to enable updating my program by replacing the exe using one Floppy Disk

    Also because I'm angry of other programs that makes that.

    Do you have any other option htat could help me?

    thanks
  • : Because the .exe file will becomes fairly big in size and that is not good, and to enable updating my program by replacing the exe using one Floppy Disk
    :
    : Also because I'm angry of other programs that makes that.
    :
    : Do you have any other option htat could help me?
    :
    : thanks

    Yep, this would be what you want:

    1. Open VB and create a new project of type ActiveX dll.
    2. Add your resource file to it.
    3. Add access functions to the class such as:
    [code]
    Public Function LoadSound(ByVal Index As Long) As Boolean

    Select Case Index
    Case 0
    'Load sound number [italic]Index[/italic]
    Case Else
    'No sound with this number!
    LoadSound = False
    End Select

    End Sub
    [/code]
    It could easily use string IDs instead of longs, it's all in how you wish to access the resource file.

    4. Name the project ResourceAccess.
    5. Name the class Init.
    6. Save and compile.
    7. Open your project that will use this.
    8. In General Declarations (in .bas if multiple forms will need access or in form (change Public to Private) if only one will need access), add the following:
    [code]
    Public Res As Object
    [/code]
    9. In Sub Main or Form_Load (wherever your program starts), add this:
    [code]
    Set Res = CreateObject("ResourceAccess.Init")
    [/code]
    10. And finally, add the code!
    [code]
    Res.LoadSound 157
    [/code]
    Hope this helps!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories