devices

This is a discussion on devices within the C++ Programming forums, part of the General Programming Boards category; hi, I would like to detect if a usb device is actually plugged into my system. My aim is to ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    99

    devices

    hi, I would like to detect if a usb device is actually plugged into my system. My aim is to get the registry keys of the USB device that is currently plugged into my system at the time my program is run. I have no idea how to start but I have experiance searching and reading registry keys and so on so its just the detecting if the device is plugged in that is causing me some trouble. Is this even possible with c++

    cheers

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Most things are possible in C++ with the right libraries, whatever they might be.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    Ive been having a bit more of a look around and I've come across 'getdrivetype()' which will give me the type of device ie removalable and so on, but I dont think it allows me to determine if the device is connected and allow me to link the device to its registry keys stored by the OS

  4. #4
    Registered User
    Join Date
    Jul 2008
    Location
    California
    Posts
    5
    Not that I know how to do this, but you could probably learn a lot from reading through driver code. I'm sure there are some 3rd party, open-source drivers for many USB devices out there and some of them are destined to be in C++. From one of these you could see how they detect/connect to the device and probably find a solution if nothing comes up here.

    Sorry I can't point you to anything specific--this is all just speculation.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    ahh right, to be honest my programming skills arnt advanced enough in my eyes to be playing with drivers I thought that there maybe something along the links of a function that checks the 'mounted devices' registry key to see which key is currently active whilst the device is plugged in. I guess im just guessing on how i thought this may be done

  6. #6
    Registered User
    Join Date
    Jul 2008
    Location
    California
    Posts
    5
    If you are just checking a known location in the registry, that is trivial:

    RegOpenKeyEx
    http://msdn.microsoft.com/en-us/libr...97(VS.85).aspx

    RegQueryValueEx
    http://msdn.microsoft.com/en-us/libr...11(VS.85).aspx

    RegCloseKey
    http://msdn.microsoft.com/en-us/libr...37(VS.85).aspx

    Its been a while since I've used those guys so I can't give you a tutorial, but Google will hopefully provide you with more than enough examples. Cheers

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    Although I know the registry key will exist i need to be able to link the key to the plugged in device. Its the registry key containing the unique serial number for the usb device. If its a new device when I plug it in the key will be generated in the registry. In order to get the correct one I would need to correlate the key to see if it comes from the device that is plugged in. It is a bit of a trivial program to do but for what im planning on using it for it would be useful

  8. #8
    Registered User
    Join Date
    Jul 2008
    Location
    California
    Posts
    5
    Ah, well I guess it isn't a simple registry lookup then! Don't be afraid to search for some driver code...

    Here's a chapter out of a book about driver programming in Windows that might shed light on the usb detection mess:
    http://www.microsoft.com/mspress/boo...chap/6262.aspx

    USB HID tools, may or may not be helpful
    http://www.usb.org/developers/hidpage/

    And a guy that made an XBOX 360 controller driver, source and all:
    http://www.redcl0ud.com/xbcd.htm

    Thats one Google search for " 'C++' open source driver." I'm sure there are better examples out there heh. Thats pretty much all I can contribute, for I have no experience in what you'd like to do. Looking through code will help a ton, but you can easily get lost. Don't spend too much time on poorly documented code if you can help it--move on to the next example you can find. Good luck!

  9. #9
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    it sounds like you need to determine if there is a handle assigned to the device.

    i do a fair amount of this kind of thing, though the devices i'm communicating with were intended for programmatic use and i use manufacturer-supplied driver libraries.

    if you can obtain the drivers, they're usually pretty straightforward and all the ones i've used have example code to go with them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a List of the USB devices listed on the system
    By WDT in forum Windows Programming
    Replies: 11
    Last Post: 11-22-2009, 08:05 PM
  2. Lost devices in Direct3D
    By VirtualAce in forum Game Programming
    Replies: 10
    Last Post: 12-09-2006, 06:41 AM
  3. Palm Pilot devices
    By ventolin in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-11-2004, 09:51 AM
  4. Replies: 2
    Last Post: 03-25-2002, 04:49 AM
  5. About those devices..
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 03-14-2002, 03:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21