Board index » cppbuilder » CD / Floppy ?

CD / Floppy ?


2005-08-08 12:48:06 PM
cppbuilder47
Hello,
How can detect CD / Floppy is in Drive ?
Thanks,
Best Regards,
M.T
 
 

Re:CD / Floppy ?

Hello,
One way is to attempt to get file-system information for the drive in
question. If the attempt fails, you can assume that drive empty ortherwise
not available. This can be done by calling the WIN32 API function
GetVolumeInformation().
Below is a bit of code which seems to work I used some WIN32 API functions,
so you may need "#include <windows.h>" in your source code.
Drive letters are hard-coded in this example "A:\"= floppy; "G:\"=CD-ROM.
I'm assuming you already have a way of know what drives are floppy and
CD-ROM.
Hope this helps,
James O'Brien
void __fastcall TMainForm::Test1Click(TObject *Sender)
{
char Volume[MAX_PATH+1];
char SysName[MAX_PATH+1];
DWORD SerialNo,
MaxFileNameLen,
FSysFlags;
AnsiString A;
if(! GetVolumeInformation("a:\\", Volume, MAX_PATH, &SerialNo,
&MaxFileNameLen, &FSysFlags, SysName, MAX_PATH) ){
::MessageBox(Handle, "Floppy not in drive\n", "Error",
MB_OK|MB_ICONSTOP);
}
else{
A.sprintf("Volume Label: %s\n"
"Serial No: %u\n"
"Max Filename Length: %u\n"
"File System %s", Volume, SerialNo, MaxFileNameLen,
SysName);
::MessageBox(Handle, A.c_str(), "Volume Info",
MB_OK|MB_ICONINFORMATION);
}
if(! GetVolumeInformation("g:\\", Volume, MAX_PATH, &SerialNo,
&MaxFileNameLen, &FSysFlags, SysName, MAX_PATH) ){
::MessageBox(Handle, "CD-ROM not in drive\n", "Error",
MB_OK|MB_ICONSTOP);
}
else{
A.sprintf("Volume Label: %s\n"
"Serial No: %u\n"
"Max Filename Length: %u\n"
"File System %s", Volume, SerialNo, MaxFileNameLen,
SysName);
::MessageBox(Handle, A.c_str(), "Volume Info",
MB_OK|MB_ICONINFORMATION);
}
}
 

Re:CD / Floppy ?

Quote
I'm assuming you already have a way of know what drives
are floppy and CD-ROM.
This is what I use to get the first CD ROM drive
(probably can be optimized a little):
AnsiString GetFirstCdRomDrive()
{
unsigned long r;
char Drives[129];
char* pDrive;
AnsiString Result = "";
r = GetLogicalDriveStrings( sizeof( Drives ), Drives );
if ( r == 0 )
return ( Result );
if ( r>sizeof( Drives ) )
return( Result );
pDrive = &Drives[0]; // Point to the first drive
while ( *pDrive != NULL )
{
if ( GetDriveType( pDrive ) == DRIVE_CDROM )
return ( UpperCase ( (char)*pDrive ) + ":\\" );
pDrive += 4; // Point to the next drive
}
return( "" );
}
--
Best regards,
Vladimir Stefanovic
 

{smallsort}