how to EMBED wav file in exe?

I don't know if this question is easy or hard or whatever so I'll start with 50 pts.

I'm taking an intro VB6 course.  

I know how to play a wav file, but I would like to EMBED the wav file in the finished EXE file. For the finished product, I want only ONE file NOT an exe and a wav file.

When I run the following code the wave file in the same folder as the saved project file plays correctly, but....(see problem after code)

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

Public Sub PlaySnd()
   Dim tmp%
   'tmp% = sndPlaySound("D:\My Documents\FUNNIES\dotcom.wav", 1)
   tmp% = sndPlaySound(App.Path & "\dotcom.wav", 1)
End Sub

Private Sub Command1_Click()
Call PlaySnd
End Sub


Problem:

When I choose "make project1 exe" and save it to another dir, the wav doesn't play.  How do I fix this?
greg1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mflamCommented:
As far as I know, you cannot embed the wav file in your VB code.
(You could do that in C or C++ having your wav file as a resource.
If you have Visual Studio 6, post here and I'll tell you how to do that, although it won't solve your problem - 2 files).

To fix the problem with your code, so it plays after you make the project1.exe:
The best thing would be to use the MMControl (Microsoft Multimedia Control).

To do this, you right mouse button on the toolbox and choose COMPONENTS.
Find the MM Control, and check it.
After you OK, your toolbox will have an MMControl added. Drag it onto your form, and use it. It's easy and intuitive, and it works (also after you make the project1.exe).

If you still want to know what went wrong with your old code:
The App.Path is the path from which you double clicked the file.
Your wav file must be in the correct location for this.
You saved the proj to another dir!
So of course your app.path is there.
Either copy the wav file there, or give it the full or at least the relative path: "..\..\wavs\dotcom.wav"
Or: "wavs\dotcom.wav" and put your wavs one dir under the "current app dir".
Or: "d:\my documents\Funny\dotcom.wav"
as you did originally.

Moshe

0
Erick37Commented:
You can add a resource file to your VB project (Use the Resource Editor Add-In).
Then save the sound file into a custom (binary) resource type named "WAVE."

More Info:

http://support.microsoft.com/support/kb/articles/Q141/5/05.asp
0
greg1Author Commented:
Thanks for trying to solve my problem.  
After re-reading my question, I can see how you might think I don't know that the wav file has to be in the same dir as the exe.  But I do know, and my little program runs fine, with its original code.

The reason I stated the problem to be solved the way I did is this:  The bmp,jpg and ico files that are a part of my program aren't required in the same dir (after making the project exe)so they must embeded.  But the wav won't play unless in the same dir, so obviously something is wrong, I just didn't know it was a limitation of VB.

If there is no way VB can create this type of program to run from a single file, then there is no solution to this problem.

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

greg1Author Commented:
Thanks for trying to solve my problem.  
After re-reading my question, I can see how you might think I don't know that the wav file has to be in the same dir as the exe.  But I do know, and my little program runs fine, with its original code.

The reason I stated the problem to be solved the way I did is this:  The bmp,jpg and ico files that are a part of my program aren't required in the same dir (after making the project exe)so they must embeded.  But the wav won't play unless in the same dir, so obviously something is wrong, I just didn't know it was a limitation of VB.

If there is no way VB can create this type of program to run from a single file, then there is no solution to this problem.

0
mflamCommented:
Dear greg1,

Not only did I 'not help' I was bluntly wrong!
You may have not noticed eric37's answer just above your comment.
Accordingly, you simply add the wave file as a resource!
He deserves the full points!

Thanks, Moshe
0
greg1Author Commented:
I have already submitted the project, and I have to cram for final exams so I don't have any time for this right now.

Thanks for your concern.

greg1
0
Erick37Commented:
Please grade my comment as answer.
Good luck on the exams!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
greg1Author Commented:
Erik37, does your method leave only ONE exe file as the finished product or 2 files, an exe and a separate resource file?
0
Erick37Commented:
Resource files are embedded in the EXE file.  They can hold Strings, Bitmaps, Icons, custom data, etc.  The exe can have only one resource file, but it can contain lots of resources.

 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.