473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.
Jan 15 '06 #1
9 12951
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

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
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
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
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
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gabriel Lozano-Morán | last post by:
First of all sorry for the cross-posting but I am not sure wether this belongs under internationalization or just general. Environment: Visual Studio .NET 2003 Problem: Newly added and...
3
by: Bern | last post by:
This message is probably out of topic but I get no response from the less popular microsoft.public.dotnet.general newsgroup. Is there a resource manager of some sort in VS C# .NET which you can...
0
by: Josef Meile | last post by:
Hi, I'm working with .resx files for a multilanguage application and so far it has worked perfectly. However, now I want to add more attributes to the xml schema and read them at running time....
7
by: Wysiwyg | last post by:
Is there any way to add an embedded resource to a project without copying it to the project's directory? I have shared resources and don't want each project using the images, xml files, etc. to...
4
by: TCook | last post by:
Hey All, I am building a solution which will have many strings that will need to be localized (i.e. strings for toolbars, strings for different WinForms, strings for messages and error messages,...
7
by: Rich | last post by:
I am resurrecting this question (since it got bumped down by more recent posts). This is probably very simple - I need to add a version resource to a DLL project in MSVC++ 2005 Express in order...
5
by: DBC User | last post by:
I have a situation, where I need to add 4 or 5 data files (they change every time I build) in my project during build time and somehow I need a way to access these files during runtime. So I have...
1
by: John | last post by:
Is there such a thing as storing icons or bitmaps into a resource file, and adding more icons or bitmaps into the resource file at runtime? I want to store a bunch of icons into a resource file,...
0
by: CSharper | last post by:
Just curious, When you are in IDE, you are able to add a resource to the project through resource tab. Later this resource can be accessed using the resource manager. One good thing about this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.