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

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 on other sites
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 on other sites
Ohm Sorry.
I need not to read always. I need to check some files when application starts.
Just once.

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 on other sites
Quote:
 Original post by joanusdmentiaYou 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 on other sites
Ops. It works for floppies, CD-s, and Hard disks, but not for card readers.

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 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".

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 86
• 11
• 10
• Forum Statistics

• Total Topics
632972
• Total Posts
3009611
• Who's Online (See full list)

There are no registered users currently online

×