🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: FlashDrive: An example to detect if plugged + drive letter

#1947
From: Mike Collins
Date: Mon, 14 May 2007 09:18
42 lines
2626 bytes
If I remember rightly, you  can use RegisterDeviceNotification to allow your 
application to be informed of the devices insertion and removal.

If you simply want to determine what the drive letter is, then you can 
iterate through all the available drive letters and test there drive type. 
I have a similar system, I have some information that can only be save or 
loaded from a removable drive.

To get a list of all available or active drive letters, use the api 
GetLogicalDriveStrings().  The example code below will firstly get a listing 
of all valid and available drive letters - this is not the same as potential 
drive letters which is obviously A...Z.  It then process this string and 
tests each drive letter to determine it's drive type, using GetDriveType() 
api.  If the drive is a removable one, it shows you a message/

   UINT uDriveType;
   AnsiString szDrvLtr;
   LPTSTR sBuffer[MAXPATH];
   int iRst = GetLogicalDriveStrings(MAXPATH,(LPTSTR)sBuffer);
   for (int I=0; I<iRst; I+=4)
   {
       szDrvLtr = "";
       szDrvLtr = (LPTSTR)&sBuffer + I;
       uDriveType = GetDriveType(szDrvLtr.c_str());
       if (uDriveType == DRIVE_REMOVABLE)
           ShowMessage("Removable Flash Drive found, drive letter - " + 
szDrvLtr);
   }

You haven't explained the full extent of your problem though.  Do you need 
notification of when a flash drive is inserted / removed or do you just need 
some facility to locate the flash drive at a give point in time (as in the 
example above).  Also, have you considered what will happen if there are two 
removable drives inserted?

HTH

Mike C

"JH" <jhs2375@nospam.com> wrote in message 
news:4647f275$1@newsgroups.borland.com...
>
Technical Details
Message-ID: <46481944@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4647f275$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2d3ccfc2a3b2ecb3
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mike Collins" <its@TheBottomOfThePost>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4647f275$1@newsgroups.borland.com>
Subject: Re: FlashDrive: An example to detect if plugged + drive letter
Date: Mon, 14 May 2007 09:18:39 -0000
Lines: 44
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.3959
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3959
NNTP-Posting-Host: 82.35.254.37
Message-ID: <46481944@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1179130180 82.35.254.37 (14 May 2007 01:09:40 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail