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++
Most things are possible in C++ with the right libraries, whatever they might be.
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
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.
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
If you are just checking a known location in the registry, that is trivial:
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 :)
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
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:
USB HID tools, may or may not be helpful
And a guy that made an XBOX 360 controller driver, source and all:
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!
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.