I have a problem with the opencallbacks with MP3’s in VB6, In the IDE it all works fine, i can open a stream with the nonblocking flag and set the nonblocking call back it runs fine.. But once its compiled as an exe it crashes everytime when the stream is opened. I have removed the lines to play the stream from the callback and the set endcallback and it then it works.. But if i debug the code line by line in the IDE it all works perfectly.
However opening a CD stream and setting the substreams in a callback is fine!! I just cant seem to see where the problem lies.
Also is it possible to open a CD with the nonblocking flag. If i set the streamopen callback on the cd stream it crashes as soon as the callback gets called, or so i assume.
Any help would be appreciated…
- Drinkyfish asked 13 years ago
I tried but the msgboxes dont get called whilst in the EXE, the application failes the moment the callback is executed it seems. If i remove the code to play the stream once opened and the setting of the end callback the program runs. However if i leave either line in the opencallback the applcation crashes, (But the file opens and plays, so it does reach the callback) but no Message boxes are displayed form within the callback.
Using the same method for setting up a opencallback to open a CD then setting the subsounds in the callback is fine and runs without issues. I simply call the playsound function and then the SetendCallback. Thats all, and these work in the IDE with no problem!!
I’ll post some code later as not in the right place to do it at the minute!!!
PS what about opening a CD as a NonBlocking stream?? Possible??
Ok i started fresh and wrote a new set of function and once again it works fine in the IDE but when compiled as an EXE it crashes. The following code is all i have currently written yet it crashes as soon as i get to the nonblockingcallback.
I initialise with
RetVal = FMOD_System_Init(SoundSys, 2, FMOD_INIT_NORMAL, 0)
RetVal = FMOD_System_SetStreamBufferSize(SoundSys, 65536, FMOD_TIMEUNIT_RAWBYTES)
Then on a button Press i call
Public Function OpenCD() As Boolean
Dim RetVal As FMOD_RESULT
Dim exinfo As FMOD_CREATESOUNDEXINFO
exinfo.cbsize = 72
exinfo.nonblockcallback = GetFunctionPointer(AddressOf CDOpened)
RetVal = fmodex.FMOD_System_CreateSound(SoundSys, CDDrive, (FMOD_HARDWARE Or FMOD_2D Or FMOD_CREATESTREAM Or FMOD_OPENONLY Or FMOD_NONBLOCKING), exinfo, CDSound)
If DebugErr(RetVal) Then
OpenCD = True
Then in the CDOpened function i have
Private Function CDOpened(sound As Long, ByVal Result As FMOD_RESULT) As Long
If DebugErr(Result) Then
Form1.ArtTit.Text = "Opened"
If DebugErr(FMOD_Sound_GetSubSound(CDSound, 0, CDSubSound)) Then
If DebugErr(FMOD_System_PlaySound(SoundSys, FMOD_CHANNEL_FREE, CDSubSound, 0, CDChan)) Then
Form1.ArtTit.Text = "No Disc"
CDOpened = FMOD_OK
If i remove the lines to get the sub sound and play it, all works fine in the EXE. If i run from the IDE with the lines it works?? The Variables are globals, soundsys as long, cdchan as long, cdsubsound as long, cdsound as long, CDDrive as string const.
I also call fmod_system_update in a timer every 10ms.
Why does it not work when compiled?? What am i doing wrong?? Its driving me mad as it all works in the IDE!!
It seems that there are problems with VB callbacks when the thread calling the callback function wasn’t created by VB.
When the error occurs, the callback function is called by a thread that was not created by Visual Basic.
For instance, certain API calls such as CreateThread() and RegisterServiceCtrlHandler() create an additional thread before invoking the callback function that was previously setup by using the AddressOf operator. Although the same code may have worked in previous versions of Visual Basic, calling API’s of this nature are currently unsupported in Visual Basic.
These API functions use a Free threading model, but Visual Basic only supports Apartment-model threading. Furthermore, additional care must be taken with regards to what code can be executed within the callback function. Any use of the following within the callback function may cause undesirable results:
• File I/O.
• Error handling.
• Fixed size arrays.
• Set statements.
• COM method calls that return HRESULTs (such as any Visual Basic ActiveX object).
• Declare calls.
• Global objects such as the Application object.
• Most of the Visual Basic run-time files.
So basically, doing anything (usefull) in the callback will cause a crash. What you can do to get it working is just have your callback function set a global variable. You can then check that global variable in your main loop and if it is set, execute what you wanted to do in the callback.
Have a look at the ripnetstream example for an example of this.
Thanks changed the code to use global booleans for new and ended and yeah all works fine….
Would it work if the timer was called by the winapi rather than from within VB?? Or will VB still cry and crash?? I am still confused to where the crash is happening, is the Crash caused by VB calling Fmod twice or something more!!!
I have some code for a real time interrupt handler driven from the winapi timers would that solve the crashing issue???
Please login first to submit.