Article View: borland.public.cppbuilder.nativeapi
Article #4449Question about WM_DEVICECHANGE
From: Kris
Date: Wed, 25 Jan 2006 17:09
Date: Wed, 25 Jan 2006 17:09
49 lines
2460 bytes
2460 bytes
I would like to detect when USB devices are added or removed. Such operations are accompanied by following message : WM_DEVICECHANGE : DBT_DEVNODES_CHANGED However, the DBT_DEVNODES_CHANGED is sent multiple times whenever a device change occurs (e.g. when I removed a device I got 2 DBT_DEVNODES_CHANGED, when I re-attached the device I got 4 DBT_DEVNODES_CHANGED). Obviously, I only want to perform one device scan instead of scanning x times depending on the number of DBT_DEVNODES_CHANGED messages received). Any ideas on how to accomplish this ? Should I just wait a little bit longer, e.g. treat all DBT_DEVNODES_CHANGED in a 2 second time-span as one DBT_DEVNODES_CHANGED message that will then trigger a new device scan ? I was also looking at using DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE. Unfortunately, these events are also sent when I remove or insert a CD in the drive. So, solely relying on these events would again result in performing a new device scan too frequently. These are the messages I see appearing : Connect device : DBT_DEVNODES_CHANGED DBT_DEVNODES_CHANGED DBT_DEVICEREMOVECOMPLETE Remove device : DBT_DEVNODES_CHANGED DBT_DEVNODES_CHANGED DBT_DEVNODES_CHANGED DBT_DEVICEARRIVAL DBT_DEVNODES_CHANGED Insert CD : DBT_DEVICEARRIVAL Remove CD : DBT_DEVICEREMOVECOMPLETE Any ideas on what is the most efficient way of detecting the adding/removing of devices without ending up doing too many calls to the function that will (re)enumerate the device list. Thanks.
Technical Details
Message-ID:
<3qbft19f0602l0f1m44t2uhiuio593trh1@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!news2.volia.net!news.musoftware.de!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,72e517fafc72a733,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Kris <x.y@xyz.xx> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Question about WM_DEVICECHANGE Date: Wed, 25 Jan 2006 18:09:22 +0100 Message-ID: <3qbft19f0602l0f1m44t2uhiuio593trh1@4ax.com> X-Newsreader: Forte Free Agent 3.1/32.783 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 81.11.242.208 X-Trace: newsgroups.borland.com 1138208779 81.11.242.208 (25 Jan 2006 09:06:19 -0700) Lines: 50 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!news2.volia.net!news.musoftware.de!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail