Solved

How to detect USB device arrival and removal.

Posted on 2004-04-29
11
3,242 Views
Last Modified: 2013-12-03
Hi,

Could you please let me know how to detect USB device arrival. Am writing a windows 32 application using SDK which would detect arrival of any device at USB port. After detecting the device it would get device handle and then later to get details of the device using it's handle.

MSDN describes all top windows will recieve WM_DEVICECHANGE message with DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE; upon inserting and removing the device respetively into the PC. Unfortunately I do not recieve these messages/events whenever I insert a device or remove it. However, I could receive these messages whenever I inserted a CD_ROM. Does this mean that windows deliver these messages only when CD_ROM device is inserted into the disk?

Then I thought; I should be using RegisterDeviceNotification but the remarks on this API indicates that I need not register in order to recieve above events and more over no registration is required for volume type devices either.

I will be greatful to you if you could help me in resolving this most nagging problem.
0
Comment
Question by:vtatikonda
  • 5
  • 4
11 Comments
 
LVL 12

Accepted Solution

by:
andrewjb earned 200 total points
ID: 10949958
_I_ received them OK - it's only the top level window that gets them, though.


See http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_20970771.html as I've just asked a similar Q yesterday!
0
 

Author Comment

by:vtatikonda
ID: 10956302
andrewjb

Thank you for a very quick response. I need some time to write this code and test. Will be able to get back to you in couple of days time.

vtatikonda
0
 

Author Comment

by:vtatikonda
ID: 10960700
andrewjb

Your suggestion worked. Thanks a lot for guiding me. It has resolved first part of my problem. However I am accepting it as a solution as you have at least guided me to some point before I continue to struggle. If possible could you please tell me how to use PDEV_BROADCAST_DEVICEINTERFACE
{
DWORD dbcc_size;  DWORD dbcc_devicetype;  DWORD dbcc_reserved;  GUID dbcc_classguid;  TCHAR dbcc_name[1];
}

As I could only get the name of the device from the above structure. I know there should be something else through which I could get more details of device. Like to which drive the usb storage device is mapped etc...

In my application I am suppose to trap USB device arrival and get the details like, name of the device, drive to which it has been mapped, number of bytes copied from and to.

I could get these details if the device type is of volume; that is by using FirstDriveFromMask I am getting drive letter subsequentely device handle from the drive. Finally using device handle I am calling DeviceIOcontrol calls to get above details. Similarly is there any way to get while the device is of type PDEV_BROADCAST_DEVICEINTERFACE.

vtatikonda
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:vtatikonda
ID: 10960789
andrewjb

I am sorry; How to accept this one as solution without closing this question. I wanted to accept this but I saw I have to close this question by accepting. Which I do not want.

Anyway please let me know if know how to accept this without closing this question.

vtatikonda.
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 10960807
Ah... the WM_DEVICECHANGE is only automatic for (COM) ports, not all devices, methinks.

And I've not progressed any further than this - I only wanted to know about COM port arrival. Sorry - I'd just have to trawl through the documentation, too.

Perhaps you should re-ask this question?
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 10960919
You can't accept but keep open. You can split points later on, and give points to multiple people once you're happy with the overall answer.

You might get more support by closing this one (reduce points if necssary - ask in Community support) then asking a new question with a more specific title and description now you've progressed a little further.
0
 

Author Comment

by:vtatikonda
ID: 10984437
andrewjb

I requested community expert to allocate 200 points to you and leave this question open. Thank you for your suggessions.

An update for you. May be it could be useful to you.

I am using SetupDI*** calls to retrieve device related information after recieving device arrival notification. However I am still unsuccessful in retriving complete data. Currently I am succeful in creating device handle but program is failing when I am using this handle to retrive device related information with API DeviceIOcontrol.

I continuing my work in this area. Please do let me know if you figure out something on USB related stuff.

Thanks,
vtatikonda.
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 11222897
Venabili - see comment above yours. He was going to split...
0
 

Author Comment

by:vtatikonda
ID: 11229721
Venabili

Please alocate 200 points to andrewjb before you remove this question. Thank you.

vtatikonda.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
link access with Quickbooks 9 49
Insert filename column as column a 18 76
Asp.net Form view Pager Template First Record 2 77
SignTool Error with Windows 10 5 148
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question