By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,574 Members | 1,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,574 IT Pros & Developers. It's quick & easy.

Adding a WAV file as a resource in VB

P: n/a
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.
Jan 15 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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
Jan 16 '06 #2

P: n/a

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.
Jan 16 '06 #3

P: n/a
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 (de*********@icode.co.uk)
i-Catcher Development Team

iCode Systems
Jan 16 '06 #4

P: n/a
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.
Jan 17 '06 #5

P: n/a
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
Jan 30 '06 #6

P: n/a
"Brad Thomas" <br********@bigpond.com> wrote in message
news:sH********************@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.

Jan 31 '06 #7

P: n/a
Tom the Canuck wrote:
"Brad Thomas" <br********@bigpond.com> wrote in message
news:sH********************@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
Feb 1 '06 #8

P: n/a
"Brad Thomas" <br********@bigpond.com> wrote in message
news:m_********************@news-server.bigpond.net.au...
Tom the Canuck wrote:
"Brad Thomas" <br********@bigpond.com> wrote in message
news:sH********************@news-server.bigpond.net.au...
Tom

Since a WAV file is a bitstream (?) you could just split up your WAV into64k 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.

Feb 3 '06 #9

P: n/a
Tom the Canuck wrote:
"Brad Thomas" <br********@bigpond.com> wrote in message
news:m_********************@news-server.bigpond.net.au...
Tom the Canuck wrote:
"Brad Thomas" <br********@bigpond.com> wrote in message
news:sH********************@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.... :)
Feb 13 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.