-
[RESOLVED] Please help : How to embed sound file into a project..
Hi everyone,
can anyone help me how to embed a sound file without requiring any additional RES file??
I mean something like a standalone application that has a playable sound file in it. Please help.. Thank you
-
Re: Please help : How to embed sound file into a project..
But a RES file is compiled into the exe file.
-
Re: Please help : How to embed sound file into a project..
That's why i'd like to do it without using res file. How should i?
-
Re: Please help : How to embed sound file into a project..
I don't understand. You say that you want the sound file in your EXE but you don't want to use a RES file that does exactly that? If you put the sound file into the project RES file it is compiled into the EXE. Meaning that you don't have to distribute the sound file nor the RES file.
-
Re: Please help : How to embed sound file into a project..
The only way ou are going to do it is with a resource file.
Without a resource file, you sound file can not be embedded in your EXE
The only other option that I'm aware of is to physically store the file in a database field.
-
Re: Please help : How to embed sound file into a project..
Is that really so? So, you mean there's no such possibility to embed sound file into an EXE? Well, ok but i've ever seen a program built that way (something like a keygen), it does standalone with no RES file included..
Sorry for my lack of knowledge is Vb..
Thanks for the reply anyway. I wish someday i'd find one like i described, so that i can show you. :D
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by vibiEn
Thanks for the reply anyway. I wish someday i'd find one like i described, so that i can show you. :D
If you do find it, it will either have an embedded resource file that you don't know about or it won't be written in VB.
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by Hack
...The only other option that I'm aware of is to physically store the file in a database field.
Could you show me how to do it?
Thanks again..
-
Re: Please help : How to embed sound file into a project..
One little thing that come to my mind is that to open the file by accessing it through binary and save it into a textbox field, then reopen it using binary access as the original sound file (i.e. *.Wav)
this sounds a bit odd but i dunno whether or not it can be done..
-
Re: Please help : How to embed sound file into a project..
you can put a sound file into your EXE (not a res file) but it's not practical to do so and is a bit akward to build the binary byte codes and have them in your source code as such. I didn't use a sound file but I did put the binary of a Java class file in my VB source but the principal is the same for any binary file.
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by jmsrickland
you can put a sound file into your EXE (not a res file) but it's not practical to do so and is a bit akward to build the binary byte codes and have them in your source code as such. I didn't use a sound file but I did put the binary of a Java class file in my VB source but the principal is the same for any binary file.
could you please show me some simple code to clearly explain to me? I dunno how
much appreciate. Thanks..
-
Re: Please help : How to embed sound file into a project..
I really need help on this. Please help me out
-
Re: Please help : How to embed sound file into a project..
Why can't you use a Resource File? Why has it 'got' to be embeded? You'll have to build a Setup file if you're going to distribute your program and that will take care of dependencies - what's the problem ?
-
Re: Please help : How to embed sound file into a project..
Just like VB embeds Icon and bitmap files i want it to be done. I wonder if i can use a byte array to store the data somehow..
-
Re: Please help : How to embed sound file into a project..
Our database FAQs cover how to store a file in a database table.
-
Re: Please help : How to embed sound file into a project..
Well, however i thank you all for the assistance :)
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by vibiEn
Just like VB embeds Icon and bitmap files i want it to be done. I wonder if i can use a byte array to store the data somehow..
These files are stored in the resource section of your exe file. I think you have misunderstood what a resource file is.
-
Re: Please help : How to embed sound file into a project..
These files are stored in the resource section of your exe file. I think you have misunderstood what a resource file is.
Ummm, I don't think so. When you put a bitmap on your Form or in a Picturebox Control the bitmap data is stored in the Form1.frx file which is not the same as the .RES file. I think what he wants is the same thing for a sound file where it is stored either directly in the source code (which when I get the time I will show him how I did it) or he wants the sound file stored in the same manner as a bitmap in the .FRX file.
-
Re: Please help : How to embed sound file into a project..
The Form.frx file is a sort of resource file, the frx file is only used by the VB IDE, the content is compiled into the exe just like any other resource. A resource file will be embedded into the exe. If you want something embedded into your exe use a resource file. I just don't get the question at all. "I want the sound embedded in my exe that is why I don't want to use a resource file"????
-
Re: Please help : How to embed sound file into a project..
I too don't understand what his problem is using a resource file. Doesn't make any sense. Even when I was able to figure out how to put the Java class file into the source code it was still a hassle to do but that was before I knew about the resource file and now I won't bother doing it the old way I now use the resource file to embed Java class files or any binary file for that matter.
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by jmsrickland
Ummm, I don't think so. When you put a bitmap on your Form or in a Picturebox Control the bitmap data is stored in the Form1.frx file which is not the same as the .RES file. I think what he wants is the same thing for a sound file where it is stored either directly in the source code (which when I get the time I will show him how I did it) or he wants the sound file stored in the same manner as a bitmap in the .FRX file.
You did get what i really mean, Great! I'm looking forward to hearing good news from you soon.. Thanks alot :D
-
Re: Please help : How to embed sound file into a project..
vibiEn, can you please explain why you don't want to use a resource file? Understanding your requirements makes it easier to come up with a solution. The icon is indeed a resource and is put inside the resource section of your exe file. The frx file is beside the point.
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by SilverDog
vibiEn, can you please explain why you don't want to use a resource file? Understanding your requirements makes it easier to come up with a solution. The icon is indeed a resource and is put inside the resource section of your exe file. The frx file is beside the point.
Thanks for asking.
I got a pretty simple answer that is, i'm about to build a simple learning program that will require no additional file. The reason's so that i can easily move the exe anywhere without caring other related files. Just to make it stand-alone. Is that really impossible to do without resource??
If it really is, then is there any other way to make a program with built-in custom files that require no files? Just an exe, that's all
thanks alot
-
Re: Please help : How to embed sound file into a project..
Thanks for trying to answer the question, but you actually never said *why* you wouldn't use a resource file. All you say is that you just want a standalone exe file that doesn't need any additional files (which BTW isn't possible using VB since all VB programs needs the run-time files) and a resource file actually does exactly that! So can you please try to answer this question: If a resource file meets your requirements to 100% then why don't you want to use it? You do not need to copy the resource file with your EXE, since the resource is embedded into the EXE. I do like to help you if I can I just don't understand your requirements, and without that understanding I don't really think anyone can answer your question. Embedding the file into a database, as suggested above, doesn't meet your requirements since you then need to distribute the database (and possibly the database engine) with your EXE.
-
Re: Please help : How to embed sound file into a project..
Haha, sorry for the mess i started..
Ok. From the beginning what i've got is just RES and RES again.. Umm, i'm working on this silly mistery of my own and i wish to be able to get the solution somehow, and show it to you.. Sorry for this confusion.
If the only way to do it is just by using Resource file, then perhaps i'll start to think about using it..
Thanks to you all :)
-
Re: Please help : How to embed sound file into a project..
Well, there are probably other ways of doing it. I just wondered what your requirements are that force you to use a non-standard approach?
-
Re: Please help : How to embed sound file into a project..
Well, no other requirements. Just a stand-alone EXE (without any RES or DLLs) with a sound file (i.e. Wav) in it. That's all. So..
-
Re: Please help : How to embed sound file into a project..
You will still need DLLs since VB needs its run-time. The RES is just a developer file, just like your frm, cls, bas files which is not distributed but all compiled into the EXE. So unlike DLLs the RES file does not need to be distributed with your EXE.
-
Re: Please help : How to embed sound file into a project..
Aha, i'm aware of that. I mean i knew that vb needs frm or dll or other files while it is not compiled. But will the EXE be an independent app when it is compiled into an exe ?
I myself even get confused due to my own question.. :blush:
-
Re: Please help : How to embed sound file into a project..
Any idea where I could get a tut or code examples on using a RES?
Thanks :)
-
Re: Please help : How to embed sound file into a project..
Notwithstanding Joacim's comments and your desire not to use a RES file, you could just append the contents of the sound file to the end of your .exe, and in your Program read the contents back into an array and use, whatever API it is, to play a sound from an array. You'll need to understand how to use Binary files, Get, Put, Seek and. probably, Seek().
Also, with this method you may run the risk of Virus Scanners deciding that your program is a virus, because of the additional bytes in the .exe file.
All in all, a RES file seems to be the correct method for you to adopt as it gets 'imbedded' into the .exe in a standard fashion.
If you've not used them before there's a Tutorial here: http://www.vbforums.com/showthread.php?t=345097
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by vibiEn
Aha, i'm aware of that. I mean i knew that vb needs frm or dll or other files while it is not compiled. But will the EXE be an independent app when it is compiled into an exe ?
I myself even get confused due to my own question.. :blush:
When your .exe is compiled it will have Dependencies, for instance, any controls you use on the form (ie .OCX files, DLL files). All these dependencies must exist on the target machine for your program to run successfully. Some will be in the VB Runtimes so at a minimum, the target machine will have to have those, other files will have to be installed and registered.
The Package and Deployment Wizard will do all that for you. It works out all the dependencies and will create a Setup.exe and associated cabinets, so all you have to do is run the setup program on the target machine to install the program and its dependencies.
-
Re: Please help : How to embed sound file into a project..
If you don't mind, Please show me a simple code on this, i long for codes :D
-
Re: Please help : How to embed sound file into a project..
-
Re: Please help : How to embed sound file into a project..
I am working on the method I stated earlier on how to put your sound file inside your VB source code.
If you still want to use this method then OK but I told you earlier that it is quite akward and kind of silly to do so when a resource file will solve your problem without any hassle.
-
Re: Please help : How to embed sound file into a project..
Quote:
Originally Posted by jmsrickland
I am working on the method I stated earlier on how to put your sound file inside your VB source code.
If you still want to use this method then OK but I told you earlier that it is quite akward and kind of silly to do so when a resource file will solve your problem without any hassle.
Thanks for the assistance. No matter what the result will be, I just like to see it is done that way :)
-
Re: Please help : How to embed sound file into a project..
I don't know how JM is getting on, but I've created an example of the 'append it to the .exe file' method.
You need a Form with the following controls:
Timer - Named: Timer1
CommandButtons - Names: cmdPut, cmdRead, and cmdPlay. Then Copy and Paste the code below into the Declarations Section of the Form
Code:
Option Explicit
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As Long, _
ByVal hModule As Long, _
ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
Private Const SIGNATURE As String = "SOUND_FILE_IMBEDDED"
Private bytSound() As Byte
Private Function GetEmbeddedSound() As Boolean
Dim bytName() As Byte
Dim intFile As Integer
Dim intLen As Integer
Dim lngPos As Long
Dim lngEOF As Long
Dim lngSLen As Long
Dim strName As String
Dim intI As Integer
intFile = FreeFile
'
' Open the .exe and position to eof
'
Open App.Path & "\" & App.EXEName & ".exe" For Binary Access Read As intFile
Seek intFile, LOF(intFile)
'
' Size the array to hold the signature
' Position the .exe to the start of the signature
' and read it
'
intLen = Len(SIGNATURE)
ReDim bytName(intLen - 1)
lngEOF = Seek(intFile)
lngPos = lngEOF - intLen + 1
Seek intFile, lngPos
Get #intFile, , bytName
For intI = 0 To UBound(bytName)
strName = strName & Chr(bytName(intI))
Next intI
'
' If the signature is valid
' Position the .exe at the start of the length of the data
' read it, and use it to size an array to receive the data.
' Position to the start of the data, read it, and then close the .exe file
'
If strName = SIGNATURE Then
lngPos = lngPos - 4
Seek intFile, lngPos
Get #intFile, , lngSLen
ReDim bytSound(lngSLen - 1)
lngPos = lngPos - UBound(bytSound)
Seek intFile, lngPos - 1
Get #intFile, , bytSound
Close intFile
GetEmbeddedSound = True
Else
GetEmbeddedSound = False
End If
End Function
Private Function PutEmbeddedSound(strFile As String, strSound As String) As Long
'
' Function appends the contents of the file defined in strSound
' to the Program (.exe) file specified in strFile
'
' Format is:
' Sound file contents
' 4 byte Length of Sound Contents
' Signature
'
Dim bytName() As Byte
Dim intFile As Integer
Dim intSound As Integer
Dim intI As Integer
Dim lngEOF As Long
Dim lngSLen As Long
intFile = FreeFile
If Dir$(strFile) <> "" Then
If Dir$(strSound) <> "" Then
'
' Open the .exe and position it at EOF
'
Open strFile For Binary Access Write As intFile
Seek intFile, LOF(intFile)
'
' Read the Sound File into an array
'
intSound = FreeFile
Open strSound For Binary Access Read As intSound
ReDim bytSound(LOF(intSound) - 1)
Get #intSound, , bytSound
Close #intSound
'
' Get our current position in
' the exe file and append the sound data to it
'
lngEOF = Seek(intFile)
Seek intFile, lngEOF + 1
Put #intFile, , bytSound
lngSLen = UBound(bytSound) + 1
lngEOF = Seek(intFile)
'
' Now write the length of the sound data
'
Put #intFile, lngEOF, lngSLen
'
' Now write the signature
' and close the .exe
'
ReDim bytName(Len(SIGNATURE) - 1)
For intI = 0 To Len(SIGNATURE) - 1
bytName(intI) = Asc(Mid$(SIGNATURE, intI + 1, 1))
Next intI
lngEOF = Seek(intFile)
Put #intFile, lngEOF, bytName
Close #1
PutEmbeddedSound = 1
Else
PutEmbeddedSound = -1
End If
Else
PutEmbeddedSound = 0
End If
End Function
Private Sub cmdPlay_Click()
Dim lngReturn As Long
'
' Play the sound from the byte Array
' Start the duration timer
'
lngReturn = PlaySound(VarPtr(bytSound(0)), 0, SND_ASYNC Or SND_LOOP Or SND_MEMORY)
Timer1.Enabled = True
End Sub
Private Sub cmdPut_Click()
Dim lngResult As Long
Dim strExe As String
Dim strSound As String
strExe = App.Path & "\" & App.EXEName & ".exe"
strSound = App.Path & "\buzzer3_x.wav"
lngResult = PutEmbeddedSound(strExe, strSound)
Select Case lngResult
Case 0
MsgBox "File: " & strExe & " Not Found"
Case -1
MsgBox "File: " & strSound & " Not Found"
End Select
End Sub
Private Sub cmdRead_Click()
Dim boResult As Boolean
boResult = GetEmbeddedSound
If boResult = False Then
MsgBox "This program does not have a valid Sound Embedded"
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 5000
End Sub
Private Sub Timer1_Timer()
Dim lngReturn As Long
'
' Stop playing the sound
' Disable the timer
'
lngReturn = PlaySound(0, 0, 0)
Timer1.Enabled = False
End Sub
Put the name of the .wav file in this statement to replace buzzer3_x.wav (making sure that the file you choose is in the App.Path Directory)
Code:
strSound = App.Path & "\buzzer3_x.wav"
Make the .exe. Then, run the program and press the cmdPut button. This will append the contents of the sound file to the .exe file. Then, either from the IDE or by running the .exe, click the cmdRead button, this will read the sound data embedded within the .exe into memory, then click on cmdPlay and the sound will be played continuously for 5 seconds.
The duration can be adjusted by modifying the Timer Interval and whether it runs synschonously or asychronously and repeats or not can be adjusted by changing the appropriate SND_ flags. (but don't remove SND_MEMORY).
Obviously you could make a separate program that, given a sound file and an exe file will append the contents of the sound file to the .exe, using the PutEmbeddedSound and supporting code, and just run that against the files you want, making sure that the necessary GetEmbeededSound and supporting code is already in the target program. With a few modifications you could embedd more than one sound file and other types of files if you wished to.
EDIT: Then, just out of interest, copy the .exe file to a machine that hasn't got VB6 installed run it, click on cmdRead, and then on cmdPlay and see what happens.
-
Re: Please help : How to embed sound file into a project..
Wow, the code almost did it. But still the exe file has a dependence to the wav file. When i compiled it into exe and move it to another directory, it says "Run time error 70" Permission denied..
But the thing that make me suprised is that when i clicked "put" and then followed by "Read" then i deleted the Wav file before clicking on the play button.. It did it! The exe played with an embedded sound file (Wav)!
Maybe i should figure it out on how to do this without put and read first..
I mean the Play button will be the only executor of the sound playing in the exe.. Wow.. Thanks alot you're great!
-
Re: Please help : How to embed sound file into a project..
Please note that adding a file to the end of the exe file may result in that some antivirus programs will report it as a virus.
-
Re: Please help : How to embed sound file into a project..
Yes, as I mentoned in Post #31 by adding into a .exe, some anti virus programs will report a suspect file.
One of the reasons I put a 'signature' in there, was to enable the user to check, if SOUND_FILE_EMBEDDED appeared as the last characters of the .exe (opening the file with Notepad, for example). Another idea might be to actually put the old and new file sizes of the file as a signature, again, giving the user an opportunity to check.
I don't think there's any 'sure fire' method to persuade the end user that it's not a virus, if their virus scanner reports it as suspicious - I wouldn't be persuaded, unless I'd been pre-warned.
But, if it's for your own use then it doesn't really matter.
I don't understand the error 70, what did you do, exactly? Remember, you have to add the sound file before moving the .exe anywhere. Once it is added it is completely independent of the .wav file.