Adding a WAV file as a resource in VB - basic.visual

This is a discussion on Adding a WAV file as a resource in VB - basic.visual ; A while back I was playing with C++ and made a simple program with a WAV file as a resource. It worked well and was easy to make. I then went on to try this with VB . I had ...

+ Reply to Thread
Results 1 to 10 of 10

Adding a WAV file as a resource in VB

  1. Default Adding a WAV file as a resource in VB

    A while back I was playing with C++ and made a simple program
    with a WAV file as a resource. It worked well and was easy to make.
    I then went on to try this with VB. I had problems.
    Can this be done in VB? I have VB6 (Visual Studio 6 Enterprise edition)..
    Any pointers to get me going in the right direction would help.
    I like to learn on my own. Making a mistake and figuring out where the
    error was made enhances the learning experience.
    It would be nice to embed the WAV file in the VB EXE just
    like I did in C++.

    Tom the Canuck.



  2. Default Re: Adding a WAV file as a resource in VB

    The code below should do it for you. To do this, open up the resource file
    editor; if you don't see it, go to "Addins...Add-in Manager" on the menu.
    Check that the "VB 6 Resource Editor" has the words Startup (and maybe
    Loaded too) under the column labeled "Load Behavior". After exiting out of
    this window, you can access the resource editor either by the green icon on
    the toolbar, or "Tools...Resource Editor".

    After this, I just drag/dropped a .WAV file into the resource file window
    (if you don't see the resource file window in VB 6. Then I ran the code
    below:

    Option Explicit

    'API Declarations
    Private Declare Function sndPlaySound Lib "winmm.dll" Alias
    "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As
    Long

    'Module Level Constant Declarations
    Private Const SND_ASYNC As Long = &H1
    Private Const SND_MEMORY As Long = &H4
    Private Const SND_NODEFAULT = &H2
    Private Const Flags& = SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY

    'Control-related Events
    Private Sub Command1_Click()
    Dim b As String

    b = StrConv(LoadResData(101, "WAVE"), vbUnicode)

    sndPlaySound b, Flags&
    End Sub

    This code was copied and very minimally changed (to document) from code I
    found at http://www.vbforums.com/showthread.p...hreadid=297909

    Jay Taplin, MCP



  3. Default Re: Adding a WAV file as a resource in VB


    Jay Taplin wrote
    > The code below should do it for you. To do this, open up the resource

    file
    > editor; if you don't see it, go to "Addins...Add-in Manager" on the menu.
    > Check that the "VB 6 Resource Editor" has the words Startup (and maybe
    > Loaded too) under the column labeled "Load Behavior". After exiting out

    of
    > this window, you can access the resource editor either by the green icon

    on
    > the toolbar, or "Tools...Resource Editor".
    >
    > After this, I just drag/dropped a .WAV file into the resource file window
    > (if you don't see the resource file window in VB 6. Then I ran the code
    > below:
    >
    > Option Explicit
    >
    > 'API Declarations
    > Private Declare Function sndPlaySound Lib "winmm.dll" Alias
    > "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As
    > Long
    >
    > 'Module Level Constant Declarations
    > Private Const SND_ASYNC As Long = &H1
    > Private Const SND_MEMORY As Long = &H4
    > Private Const SND_NODEFAULT = &H2
    > Private Const Flags& = SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY
    >
    > 'Control-related Events
    > Private Sub Command1_Click()
    > Dim b As String
    >
    > b = StrConv(LoadResData(101, "WAVE"), vbUnicode)
    >
    > sndPlaySound b, Flags&
    > End Sub
    >
    > This code was copied and very minimally changed (to document) from code I
    > found at http://www.vbforums.com/showthread.p...hreadid=297909
    >
    > Jay Taplin, MCP
    >
    >

    Thanks. I will try it soon.

    Tom the Canuck.



  4. Default Re: Adding a WAV file as a resource in VB

    Tom the Canuck wrote:
    > A while back I was playing with C++ and made a simple program
    > with a WAV file as a resource. It worked well and was easy to make.
    > I then went on to try this with VB. I had problems.
    > Can this be done in VB? I have VB6 (Visual Studio 6 Enterprise edition)..
    > Any pointers to get me going in the right direction would help.
    > I like to learn on my own. Making a mistake and figuring out where the
    > error was made enhances the learning experience.
    > It would be nice to embed the WAV file in the VB EXE just
    > like I did in C++.


    It should be able to work the same as in C++.
    I would use the PlaySound API as it can load a WAV data direct from the
    resources of your application

    --
    Dean Earley (dean.earley@icode.co.uk)
    i-Catcher Development Team

    iCode Systems

  5. Default Re: Adding a WAV file as a resource in VB - limitation

    Yup the code works, but . . .
    "The data that LoadResData loads from the resource file can be up to 64K."

    Any way to bypass this limit? I guess that I have to shell another app that
    can
    play larger files. Bummer. The obvious immediate solution is to put the WAV
    file I want to play in the directory the EXE is in and use the media player
    in VB.

    What would be the best way to pass the VB resource to another app?

    Tom the Canuck.



  6. Default Re: Adding a WAV file as a resource in VB - limitation

    Tom

    Since a WAV file is a bitstream (?) you could just split up your WAV into
    64k chunks, and then grab the chunks from the resource file, binary writing them
    one after the other into a temporary file, and use sndPlaySound to play that file.

    For splitting WAVs, have a look at http://www.009soft.com/products/wav-splitter.htm
    as an example.


    > "The data that LoadResData loads from the resource file can be up to 64K."
    >
    > Any way to bypass this limit?


    > The obvious immediate solution is to put the WAV
    > file I want to play in the directory the EXE is in and use the media player
    > in VB.


    Yes, you could do that too. May be easier.

    Cheers

    Brad

  7. Default Re: Adding a WAV file as a resource in VB - limitation

    "Brad Thomas" <bradzo0647@bigpond.com> wrote in message
    news:sHwDf.231625$V7.127822@news-server.bigpond.net.au...
    > Tom
    >
    > Since a WAV file is a bitstream (?) you could just split up your WAV into
    > 64k chunks, and then grab the chunks from the resource file, binary

    writing them
    > one after the other into a temporary file, and use sndPlaySound to play

    that file.
    >
    > For splitting WAVs, have a look at

    http://www.009soft.com/products/wav-splitter.htm
    > as an example.
    >
    >
    > > "The data that LoadResData loads from the resource file can be up to

    64K."
    > >
    > > Any way to bypass this limit?

    >
    > > The obvious immediate solution is to put the WAV
    > > file I want to play in the directory the EXE is in and use the media

    player
    > > in VB.

    >
    > Yes, you could do that too. May be easier.
    >
    > Cheers
    >
    > Brad


    Thanks Brad,
    What you posted is what I was thinking.
    In the end, I made smaller WAV files that
    fit in the 64K limit. Yup, resource file stuff.
    Nothing fancy, just two basic small sound files.
    One for the EXE when it loaded, one for the
    'About' window. It does what I wanted, simple
    audio stuff for the target populace for the app to
    enjoy (or turn off -- menu option).
    I thank all those who replied to my question.
    Mission accomplished. My youngest daughter
    even liked the app in progress. Kind of makes
    you feel good when what you did appeals to
    others, no matter what the age.
    [She just turned 17, I am almost 48]
    Tom the Canuck.

    From that wonderful word 'cheers' I take it that
    you are from England. Loved my stay there (8 days).
    Nottingham, Robin Hood, the castle, the pub
    under the castle. A very fine place to visit. I enjoyed
    every minute I was there.




  8. Default Re: Adding a WAV file as a resource in VB - limitation

    Tom the Canuck wrote:
    > "Brad Thomas" <bradzo0647@bigpond.com> wrote in message
    > news:sHwDf.231625$V7.127822@news-server.bigpond.net.au...
    >
    >>Tom
    >>
    >>Since a WAV file is a bitstream (?) you could just split up your WAV into
    >>64k chunks, and then grab the chunks from the resource file, binary

    >

    [snip]
    >
    > Thanks Brad,
    > What you posted is what I was thinking.
    >


    Excellent - glad you got it working.

    >
    > From that wonderful word 'cheers' I take it that
    > you are from England. Loved my stay there (8 days).
    > Nottingham, Robin Hood, the castle, the pub
    > under the castle. A very fine place to visit. I enjoyed
    > every minute I was there.


    Um, no - Australia actually....
    My sister lives in England though, but I've never been there.

    And you're from wonderful Canada? If you ever go to the Toronto
    Public Library or branches, the main web interface on the public PC's for
    accessing all sorts of different resources is *my* program! Woohoo!
    Shameless self-promotion I know

    Cheers

    Brad

  9. Default Re: Adding a WAV file as a resource in VB - limitation

    "Brad Thomas" <bradzo0647@bigpond.com> wrote in message
    news:m_aEf.233252$V7.131876@news-server.bigpond.net.au...
    > Tom the Canuck wrote:
    > > "Brad Thomas" <bradzo0647@bigpond.com> wrote in message
    > > news:sHwDf.231625$V7.127822@news-server.bigpond.net.au...
    > >
    > >>Tom
    > >>
    > >>Since a WAV file is a bitstream (?) you could just split up your WAV

    into
    > >>64k chunks, and then grab the chunks from the resource file, binary

    > >

    > [snip]
    > >
    > > Thanks Brad,
    > > What you posted is what I was thinking.
    > >

    >
    > Excellent - glad you got it working.
    >
    > >
    > > From that wonderful word 'cheers' I take it that
    > > you are from England. Loved my stay there (8 days).
    > > Nottingham, Robin Hood, the castle, the pub
    > > under the castle. A very fine place to visit. I enjoyed
    > > every minute I was there.

    >
    > Um, no - Australia actually....
    > My sister lives in England though, but I've never been there.
    >
    > And you're from wonderful Canada? If you ever go to the Toronto
    > Public Library or branches, the main web interface on the public PC's for
    > accessing all sorts of different resources is *my* program! Woohoo!
    > Shameless self-promotion I know
    >
    > Cheers
    >
    > Brad


    I guess to correct my error, I think that I should say G'day mate instead.
    Perhaps the British origins to Australia confused me with the 'cheers' from
    you.
    I will not discuss the actual origins of the first European inhabitants
    there.
    I think in my case in Montreal, Quebec that we had similar origins in
    terms of the arrivals. I think that they were from just across the English
    Channel and liked to eat the legs of amphibians and snails as well.

    Bloody hell, I like me fish and chips and after a bag of crisps. When I
    am done eating, smoking a good fag just tops it off for me. Then it's off
    to the pub for a few pints of bitters. Packston's Old Peculiar took some
    time to get used to (first two swigs) but it is a fine brew indeed.
    I heard that Foster's ale was crap and just exported to other countries.
    What fine ale do you like where you are? I just would like to know.

    It is bloody winter here now. Enjoy your summer down under.
    [yup, Canada, gotta love it, -30 in winter, +30 in summer]
    {for the Americans reading this, that was in Celsius.
    That would be -22 in winter, +86 in summer in Fahrenheit}

    Cheers mate,
    Tom the Canuck.




  10. Default Re: Adding a WAV file as a resource in VB - limitation

    Tom the Canuck wrote:
    > "Brad Thomas" <bradzo0647@bigpond.com> wrote in message
    > news:m_aEf.233252$V7.131876@news-server.bigpond.net.au...
    >
    >>Tom the Canuck wrote:
    >>
    >>>"Brad Thomas" <bradzo0647@bigpond.com> wrote in message
    >>>news:sHwDf.231625$V7.127822@news-server.bigpond.net.au...
    >>>
    >>>
    >>>>Tom
    >>>>
    >>>>Since a WAV file is a bitstream (?) you could just split up your WAV

    >
    > into
    >
    >>>>64k chunks, and then grab the chunks from the resource file, binary
    >>>

    >>[snip]
    >>
    >>>Thanks Brad,
    >>> What you posted is what I was thinking.
    >>>

    >>
    >>Excellent - glad you got it working.
    >>
    >>
    >>>From that wonderful word 'cheers' I take it that
    >>>you are from England. Loved my stay there (8 days).
    >>>Nottingham, Robin Hood, the castle, the pub
    >>>under the castle. A very fine place to visit. I enjoyed
    >>>every minute I was there.

    >>
    >>Um, no - Australia actually....
    >>My sister lives in England though, but I've never been there.
    >>
    >>And you're from wonderful Canada? If you ever go to the Toronto
    >>Public Library or branches, the main web interface on the public PC's for
    >>accessing all sorts of different resources is *my* program! Woohoo!
    >>Shameless self-promotion I know
    >>

    e>>Cheers
    >>
    >>Brad

    >
    > Bloody hell, I like me fish and chips and after a bag of crisps. When I
    > am done eating, smoking a good fag just tops it off for me. Then it's off
    > to the pub for a few pints of bitters. Packston's Old Peculiar took some
    > time to get used to (first two swigs) but it is a fine brew indeed.
    > I heard that Foster's ale was crap and just exported to other countries.
    > What fine ale do you like where you are? I just would like to know.
    >
    > It is bloody winter here now. Enjoy your summer down under.
    > [yup, Canada, gotta love it, -30 in winter, +30 in summer]
    > {for the Americans reading this, that was in Celsius.
    > That would be -22 in winter, +86 in summer in Fahrenheit}
    >
    > Cheers mate,
    > Tom the Canuck.
    >
    >
    >


    G'day Tom!

    Haha! I agree - Except for me its meat and two veg, then a smoke, and
    a glass of red wine (Cabernet Merlot, or just Merlot, or Shiraz are my
    favourites.)

    Foster's *is* pretty crap. If I have a beer (rare) I prefer a thing
    called XXXX Bitter - a fine Queensland brew.

    Its been quite fine weather here - but hardly any rainfall which is a
    bad thing - our dams are below 50% so govts have implemented water restrictions.
    Other than that, I am looking forward to it cooling down a bit, but with
    the air-conditioner in the house and the car, its quite bearable.

    Onya!
    Brad

    PS "Onya" means "Good on you" not some weird sexual thing....

+ Reply to Thread

Similar Threads

  1. Resource file vs. regular Xml file
    By Application Development in forum CSharp
    Replies: 12
    Last Post: 11-21-2007, 08:19 AM
  2. Get a file from my resource file and write it to disk
    By Application Development in forum CSharp
    Replies: 9
    Last Post: 11-13-2007, 12:41 AM
  3. VS.NET keeps losing toolbar items after adding images to resource?
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 10-24-2007, 04:25 PM
  4. Disposing strings created from a resource file using resource mana
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 06-25-2007, 09:30 AM
  5. Adding resource files to a form or user controle
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 09-18-2005, 06:52 AM