Page 1 of 1
[Solved] Disabled audio and InitSound()
Posted: Sat May 10, 2025 5:49 am
by BarryG
[Edit] SOLVED. See here ->
viewtopic.php?p=640610#p640610
I've got all audio disabled on my PC but InitSound() doesn't return 0. I was hoping to use InitSound() so my app knows NOT to use audio APIs if it returns 0 for no audio, but I can't.

Re: 6.21 B9: Disabled audio and InitSound()
Posted: Sat May 10, 2025 8:09 am
by jacdelad
Doesn't InitSound() just build a bridge between you program and the Windows sound system (which itself looks for devices) and just returns that it "successfully connected to the Windows component"?
Re: 6.21 B9: Disabled audio and InitSound()
Posted: Sat May 10, 2025 2:15 pm
by Fred
Nowaday the sound system will be almost always successful, because you can plugin USB headset etc. which can enable sound on the go. So you can't rely to InitSound() to detect a sound card
Re: Disabled audio and InitSound()
Posted: Sat May 10, 2025 3:10 pm
by Quin
BarryG wrote: Sat May 10, 2025 5:49 am
I've got all audio disabled on my PC but InitSound() doesn't return 0. I was hoping to use InitSound() so my app knows NOT to use audio APIs if it returns 0 for no audio, but I can't.
What do you mean, all audio disabled? You have all soundcards disconnected/disabled?
Re: Disabled audio and InitSound()
Posted: Sun May 11, 2025 1:21 am
by BarryG
Hi Quin. Yes, what I mean is I went into Device Manager and disabled all audio components, because it turns out some users don't have sound cards, and my app was crashing for them due to it. So I need a way to detect if a sound card is present/enabled or not, and I thought InitSound() would do the job; but as Fred said, you can't use it like that.

Re: Disabled audio and InitSound()
Posted: Sun May 11, 2025 6:42 pm
by AZJIO
RunProgram() + "devcon status" ?
Code: Select all
EnableExplicit
If Not IsUserAnAdmin_()
Debug "Admin?"
End
EndIf
Define Compiler, Output$
Compiler = RunProgram("devcon", "status =media", "", #PB_Program_Open | #PB_Program_Read)
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Output$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
Output$ + Chr(13) + Chr(13)
Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))
CloseProgram(Compiler)
EndIf
MessageRequester("Output", "|" + Output$ + "|")
Re: [Solved] Disabled audio and InitSound()
Posted: Sun May 11, 2025 9:57 pm
by BarryG
Sorry, forgot to say this was solved by mk-soft in another post (edited my first post here), without needing admin rights. Thanks for your post, too.
