Author Topic: USB Device Connect/Disconnect in Windows C  (Read 6135 times)

cgopalg

  • Member
  • ***
  • Posts: 9
USB Device Connect/Disconnect in Windows C
« on: February 12, 2014, 01:07:21 pm »
Hi,

I want my application in Windows to detect USB connect/disconnect of *my* USB mass storage device.

I could able to get the USB connect/disconnect event in my application of *any* USB mass storage device.

How can I find the connect/disconnect event correspond to *my* USB mass storage device.

Thanks,
Gopal
 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Device Connect/Disconnect in Windows C
« Reply #1 on: February 12, 2014, 02:06:09 pm »
Take a look at my WinUSB application, esp. the FindDeviceUsingWmi and AddDeviceArrivedHandler routines.

http://www.lvr.com/winusb.htm

cgopalg

  • Member
  • ***
  • Posts: 9
Re: USB Device Connect/Disconnect in Windows C
« Reply #2 on: February 13, 2014, 01:05:28 am »
Thanks, I could check  FindDeviceUsingWmi and AddDeviceArrivedHandler routines from your cs project.

I understand that I need to again search whether my device is connected or not.

Do you have examples based on vc++?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Device Connect/Disconnect in Windows C
« Reply #3 on: February 13, 2014, 09:09:42 am »
When you add a handler, the handler routine will run on attachment.

I don't have a c++ example. My older examples use WM_DEVICECHANGE messages instead of WMI/System.Management.

cgopalg

  • Member
  • ***
  • Posts: 9
Re: USB Device Connect/Disconnect in Windows C
« Reply #4 on: February 13, 2014, 09:14:20 am »
Thanks, I could find my device when it is connected or disconnected by using lParam of the callback API.