🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages Started by JH Mon, 14 May 2007 05:24
FlashDrive: An example to detect if plugged + drive letter
#2046
Author: JH
Date: Mon, 14 May 2007 05:24
8 lines
1016 bytes
Hi,
Can someone post an example that shows if a 
FlashDrive/ThumbDrive is plugged. One of the 
problems is that we have several laptops and 
the drive's letter changes from F to H 
depending on the laptop. An example on how 
to deal with this would help. Thanks.
Re: FlashDrive: An example to detect if plugged + drive letter
#1947
Author: 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...
>
Re: FlashDrive: An example to detect if plugged + drive letter
#1949
Author: JH
Date: Mon, 14 May 2007 12:52
8 lines
992 bytes
Yes, an example to detect when the flash
drive is inserted/removed would help. The
other example is good but it also reports
a floppy drive a DRIVE_REMOVABLE too.
Thanks.

JH
Re: FlashDrive: An example to detect if plugged + drive letter
#1953
Author: Chris
Date: Mon, 14 May 2007 19:43
13 lines
1305 bytes
"JH" <jhs2375@nospam.com> wrote in message 
news:46485bab$1@newsgroups.borland.com...
> The
> other example is good but it also reports
> a floppy drive a DRIVE_REMOVABLE too.

But aren't floppies only ever assigned to A & B?

I don't have a floppy drive on my PC and the drive start at C with removable 
drives always being higher up the chain.

CHris 
Re: FlashDrive: An example to detect if plugged + drive letter
#1956
Author: JH
Date: Mon, 14 May 2007 21:39
5 lines
1026 bytes
"Chris" <nospam@nospam.com> wrote:
>But aren't floppies only ever assigned to A & B?

Yep, that part was taking care of with DriveLetter != A.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads