TCHAR buffer[256];
unsigned long dwDrive = 1, dwDrives = GetLogicalDrives();
char cLetter;
bool bFileFound = false;
for(cLetter = 'A'; cLetter <= 'Z'; cLetter++){
if(dwDrives & dwDrive)
{
sprintf(buffer,"%c:/getthisfile.log", cLetter);
if( (stream = fopen( buffer, "r" )) != NULL )
{
bFileFound = true;
fclose(stream);
break;
}
}
dwDrive <<= 1;
}
Card Reader Detection in C++
Hello.
How can I retrieve information about if card is inserted into card reader (same as floppy), and not to get the message box "Please insert disk in drive F:"?
I'm using this:
Thank you.
[Edited by - streamer on June 4, 2007 9:22:24 AM]
You can't using C++ alone.
You'll need to use OS calls, if it is possible at all.
For floppy disks, applications uses a way that forced the drive read continously, even if no disk was inserted. This isn't the best method, since it forces the driver to do what it shouldn't, and could even damage it, so only a few very specific applications did that.
If card reader uses floppy disk interface via BIOS, this probably won't work, since the hardware is somewhat different.
You'll need to use OS calls, if it is possible at all.
For floppy disks, applications uses a way that forced the drive read continously, even if no disk was inserted. This isn't the best method, since it forces the driver to do what it shouldn't, and could even damage it, so only a few very specific applications did that.
If card reader uses floppy disk interface via BIOS, this probably won't work, since the hardware is somewhat different.
Ohm Sorry.
I need not to read always. I need to check some files when application starts.
Just once.
I need not to read always. I need to check some files when application starts.
Just once.
You may be able to check for the file's existance using the stat() function before trying to open the file for reading. I don't know for sure if this will stop the OS from asking you to insert a floppy/card, but it might. The only other option will be using the Win32 API, perhaps a call to CreateFile() with some special flags.
Quote:Original post by joanusdmentia
You may be able to check for the file's existance using the stat() function before trying to open the file for reading. I don't know for sure if this will stop the OS from asking you to insert a floppy/card, but it might. The only other option will be using the Win32 API, perhaps a call to CreateFile() with some special flags.
Working! File writing if fails it means that there is no drive (or drive is write protected but that doesn't count [smile]).
Thank you.
int iRating;iRating++;
I don't think it's possible to do without using platform specific code.
Here's one way of doing it in windows:
My 2c
Here's one way of doing it in windows:
// Get a bitmask for all valid drives. DWORD d = GetLogicalDrives(); char rootPath[] = "@:\\";// Loop through all drives while (d > 0){ // Test if drive is valid (bit set) bool isValid = ((d & 1) != 0); // Adjust root path and get the next bit ++ rootPath[0]; d >>= 1; // If the drive isn't valid, continue with the next if (!isValid) continue; // We've got a valid drive, reject all non removable drives if (GetDriveType(rootPath) != DRIVE_REMOVABLE) continue; // Get the volume name of the inserted media, this will fail if no media is present char volumeName[MAX_PATH + 1] = ""; if (GetVolumeInformation(rootPath, volumeName, sizeof(volumeName), NULL, NULL, NULL, NULL, 0) == FALSE) continue; // Reject volumes without a name, maybe not needed if (volumeName[0] == 0) continue; // Found a valid removeable media, do something with it printf("Found valid removable volume at %s named %s", rootPath, volumeName); }
My 2c
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement