🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2948

Re: OnDeviceChange Problem

#2948
From: Michel Leunen
Date: Wed, 18 Oct 2006 17:46
47 lines
2510 bytes
Uri wrote:

> Hi, I did not understand how to use it.

Ok, I tried with my usb key and it works.

RegisterDeviceNotification() tells the OS to send to your app the 
notification messages you want. Without this as you've noted, you don't 
receive the arrival or removal of your device.

First add this to your form constructor:

DEV_BROADCAST_DEVICEINTERFACE NotificationFilter = {0};
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = GUID_DEVCLASS_USB;
RegisterDeviceNotification(Handle,
                            &NotificationFilter,
                            DEVICE_NOTIFY_WINDOW_HANDLE);

And then in your message handler (WndProc or whatever):

if(Message.Msg == WM_DEVICECHANGE)
   {
     switch(Message.WParam)
     {
       case DBT_DEVICEARRIVAL:
         Application->MessageBox("Arrival","USB",MB_OK);
         break;
       case DBT_DEVICEREMOVECOMPLETE:
         Application->MessageBox("Removal","USB",MB_OK);
         break;
     }
   }

Don't know if it works for any USB devices but at least it works for my 
usb key.

HTH
Michel
-- 
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
Technical Details
Message-ID: <45366845@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4534d31d$1@newsgroups.borland.com> <45350f17@newsgroups.borland.com> <453620dd$1@newsgroups.borland.com> <4536288b@newsgroups.borland.com> <45362fb9$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a72a1c41eec7e70f
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 18 Oct 2006 19:46:26 +0200
From: Michel Leunen <nospam@noreply.be>
Organization: www.leunen.com
User-Agent: Thunderbird 1.5.0.7 (Windows/20060909)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: OnDeviceChange Problem
References: <4534d31d$1@newsgroups.borland.com> <45350f17@newsgroups.borland.com> <453620dd$1@newsgroups.borland.com> <4536288b@newsgroups.borland.com> <45362fb9$1@newsgroups.borland.com>
In-Reply-To: <45362fb9$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.247.66.248
Message-ID: <45366845@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1161193541 81.247.66.248 (18 Oct 2006 10:45:41 -0700)
Lines: 47
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail