Jump to content
  • Advertisement
Sign in to follow this  
ninjai

USB device error handling

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I am a newbie at programming in DX and am making a program that will use directsound for source/sink (mic/speaker). Given this scenario: -User runs the program -User uses USB headphones mic combo -When running the program, user unplugs this device (I want to know how to get to next step) -Program automatically detects this and switches to soundblaster wavein/out microphone and speaker config -Program detects if user has again switched usb headphones mic combo and switches to that source while running the program. Thank you very much in advance for help. Andrej

Share this post


Link to post
Share on other sites
Advertisement
Most applciations/games I've seen that do this have to quit before they refind/change the device.

For example:

If I start Day of Defeat, then plug my USB headset in it won't use it. But when I restart the game it finds it. Or if I pull it out and plug it back in while playing it lsoes it.

Share this post


Link to post
Share on other sites
WM_DEVICECHANGE might do what you want. I've heard it only works for mass storage devices, but test it and see if you recieve the message with your speakers or headset or whatever.

When you get the message check for DBT_DEVICEARRIVAL, enumerate your DirectX devices and see what's available, and switch if necessary. Device removal is a little harder, I don't know what happens to the DX interface when a device is removed, somehow I'm guessing you can't wait until the device is gone to clean up...

Try running Spy++ and plugging in and removing various devices, see what messages are generated.

Share this post


Link to post
Share on other sites
It works. Spy++ detects this message, but the question is, how to differentiate this headset from any other usb device.

Any suggestions?

Share this post


Link to post
Share on other sites
I'm sure WM_DEVICECHANGE will give you some means to determine what device has been inserted. Check out the LPARAM documentation for the message, I'm guessing you should look into the DBT_DEVTYP_DEVICEINTERFACE type and it's associated DEV_BROADCAST_DEVICEINTERFACE struct.

Share this post


Link to post
Share on other sites
Thanks.

Interesting, my device posts only 8 WM_DEVICECHANGE messages with wparam 00000007 and lparam 00000000 when i plug it in. And 4 of same messages when i plug it out.

And when i plug in usb device i get 4 of this messages and 1 with DBT_DEVICEARRIVAL event. Analog is with unplug.

Doesnt directInput have any mechanism to detect this changes? Or any windows sdk functions for handling usb devices? Or must I always make message loop.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!