|
-
Dec 1st, 1999, 10:40 AM
#1
Thread Starter
Hyperactive Member
How do some programs have sound files inside the exe? I just played a game that was nothing but an exe and there were no sound files.
How can I make an exe and have the sound files inside the exe instead of having to access them?
Thank for reading this and any help you can provide.
------------------
Steve Stunning
-
Dec 1st, 1999, 07:06 PM
#2
You can create a resource file that will be compiled with your EXE. Resource file can hold a lot of different file formats. If you have VB6, then you have a Resource Editor.
To put the file in the resource: From the Add-Ins menu select Add-In Manager.... From the list select (put a check mark) a VB6 Resource Editor. Then, from the Project menu select Add New Resource File. A common dialog will be shown to give a name to your new resource file, do so (don't worry, this file will not be needed after you compile your program). Now, you will notice that in project explorer you would have a resource file added. Now, double click on that file. You will get the Resource Editor. From the toolbar select secon icon from the right (the icon called Add Custom Resource... Select the appropriate sounds (Wavs). Notice that editor will create an ID for each item you add. You can keep the default or change them to different ID by double click on each item. Close the Resource Editor. Let's say you keep the default IDs. Now, the programming part.
Here is the generic routine that you can use:
Code:
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const FLAGS = SND_ASYNC And SND_NODEFAULT
Public Sub PlayWavResource(pintResourceID As Integer)
Dim bytArr() As Byte
Dim intFFN As Integer
Dim strPath As String
bytArr = LoadResData(pintResourceID, "CUSTOM")
strPath = App.Path & IIf(Right(App.Path, 1) = "\", "~tempwav.wav", "\~tempwav.wav")
intFFN = FreeFile
Open strPath For Binary As intFFN
Put #intFFN, , bytArr
Close #intFFN
Call sndPlaySound(strPath, FLAGS)
Kill strPath
End Sub
Usage: PlayWavResource ResourceID
Example: Call PlayWavResource(101)
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 12-02-1999).]
-
Dec 1st, 1999, 08:25 PM
#3
PowerPoster
Serge - or anyone - how could I modify the above to include an AVI in my EXE that plays using the Windows Media Player? I have the AVI as resource id 101 in the CUSTOM bit.
Thank you
Regards,
------------------
- Chris
[email protected]
If it ain't broke - don't fix it 
-
Dec 1st, 1999, 08:52 PM
#4
Sure!
Code:
Public Sub PlayAVIResource(pintResourceID As Integer, pMediaPlayer As MediaPlayer)
Dim bytArr() As Byte
Dim intFFN As Integer
Dim strPath As String
bytArr = LoadResData(pintResourceID, "CUSTOM")
strPath = App.Path & IIf(Right(App.Path, 1) = "\", "~tempavi.avi", "\~tempavi.avi")
intFFN = FreeFile
Open strPath For Binary As intFFN
Put #intFFN, , bytArr
Close #intFFN
pMediaPlayer.FileName = strPath
pMediaPlayer.Play
End Sub
Example: Call PlayAVIResource(101, MediaPlayer1)
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
-
Dec 3rd, 1999, 09:20 PM
#5
Thread Starter
Hyperactive Member
Thank you Serge... I will give it a try.
-
Dec 4th, 1999, 04:02 PM
#6
Lively Member
so is there any way to compile the EXE and write ActiveX files inside of it so that the user does not have to have them located on his/her hard drive? ...and so i don't have to package them with the software? because we all know that ActiveX references can be a ***** if the user does not have them in their Windows\System directory. ok. bye.
--michael
-
Dec 4th, 1999, 10:42 PM
#7
Thread Starter
Hyperactive Member
Serge,
It worked great. Thanks for you help!!
-
Dec 4th, 1999, 11:30 PM
#8
There is no need to write the wav file to disk before playing it.
Code:
Option Explicit
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1 ' Play asynchronously
Private Const SND_NODEFAULT = &H2 ' Don't use default sound
Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim retVal As Long
Dim SoundBuffer As String
SoundBuffer = StrConv(LoadResData(101, "CUSTOM"), vbUnicode) 'replace 101 with your resource ID
retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
End Sub
-
Dec 5th, 1999, 09:30 AM
#9
Thread Starter
Hyperactive Member
Frans C,
Even better.... I like not having to save it to disk prior to play!!
Many thanks to you...
-
Dec 9th, 1999, 07:09 AM
#10
Junior Member
since im kinda confused by this, does anyone know how to run an exe. file from a resource file? They are default ( "Custom",101) settings.
-
Dec 9th, 1999, 06:53 PM
#11
Use the method I posted earlier (which is to save the file to disk first), then use Shell statement:
Code:
Public Sub RunResourceExe(pintResourceID As Integer)
Dim bytArr() As Byte
Dim intFFN As Integer
Dim strPath As String
bytArr = LoadResData(pintResourceID, "CUSTOM")
strPath = App.Path & IIf(Right(App.Path, 1) = "\", "~tempexe.exe", "\~tempexe.exe")
intFFN = FreeFile
Open strPath For Binary As intFFN
Put #intFFN, , bytArr
Close #intFFN
Shell strPath, vbNormalFocus
End Sub
Example: RunResourceExe 101
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 12-10-1999).]
-
Mar 7th, 2000, 01:53 AM
#12
New Member
Need help with RES files
1. Is there any way to write into a RES file from my app? My game uses RES files for levels and graphics, and I want to make an editor for it.
2. Is there any way to (probably with the API) read from a RES file other than the one that is associated with my app? I want to have a separate RES file for each chapter of my game, so I can easily create add-ons.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|