WaveIn crashes when cable is unplugged

Hey guys,

I am working on a recording program using win32 API and waveIn. Everything works fine so far, BUT the waveIn part crashes when I unplug the microphone cable. Seems that my laptop automatically switches from the jack input to the built in microphone, disabling the jack input. Plugging in the jack again doesn't help.

The only solution I found was to restart the program, the functions waveInStop() and/or waveInClose() don't work after plugging/unplugging the cable.

Does anybody have an idea how to solve this problem?

Thanks a lot!

Kevin
It "crashes", as in it brings down your entire program? That seems unlikely.

All waveIn functions return error codes. It's more likely that your wavein object is getting in a bad state when the plug is removed -- and then the following calls with your handle are failing.

Are you checking the return values to make sure the calls succeed?
Disch is right, removing the device invalidates any handles\streams you had open to it. This is why "RegisterDeviceNotification()" exists: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363431(v=vs.85).aspx
The first message I get from WM_DEVICECHANGE is DBT_DEVNODES_CHANGED and that's already too late to close the waveIn handle, it's already invalid...
Last edited on
Topic archived. No new replies allowed.