[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

how to EMBED wav file in exe?

Posted on 1999-11-29
9
Medium Priority
?
872 Views
Last Modified: 2008-02-26
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?
0
Comment
Question by:greg1
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Expert Comment

by:mflam
ID: 2241364
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2241412
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
 

Author Comment

by:greg1
ID: 2260973
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:greg1
ID: 2260974
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
 
LVL 2

Expert Comment

by:mflam
ID: 2262487
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
 

Author Comment

by:greg1
ID: 2263859
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
 
LVL 32

Accepted Solution

by:
Erick37 earned 100 total points
ID: 2263874
Please grade my comment as answer.
Good luck on the exams!
0
 

Author Comment

by:greg1
ID: 2264015
Erik37, does your method leave only ONE exe file as the finished product or 2 files, an exe and a separate resource file?
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2264114
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question