[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to detect USB device arrival and removal.

Posted on 2004-04-29
11
Medium Priority
?
3,279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
11 Comments
 
LVL 12

Accepted Solution

by:
andrewjb earned 800 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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