Jump to content
  • Advertisement
Sign in to follow this  
streamer

Card Reader Detection in C++

This topic is 4156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
   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;
	}




Thank you. [Edited by - streamer on June 4, 2007 9:22:24 AM]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Ohm Sorry.
I need not to read always. I need to check some files when application starts.
Just once.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++;

Share this post


Link to post
Share on other sites
I don't think it's possible to do without using platform specific code.

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

Share this post


Link to post
Share on other sites
There is strange thing happening. When I startup the windows my detection of card works perfectly. Then I insert one usb stick and when I remove it, whole code goes mad. Then every try to access card reader results in "please insert a disk int drive G or F".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!