Re: cheking whether a media is in a slot.
From: EMonk (emonk_at_slingshot.no.uce)
Date: 09/15/04
- Next message: EMonk: "Re: [EGN] Numerical Accuracy"
- Previous message: Paul Lutus: "Re: Importance of Computer Science degree?"
- In reply to: Doublehp: "cheking whether a media is in a slot."
- Next in thread: Doublehp: "Re: cheking whether a media is in a slot."
- Reply: Doublehp: "Re: cheking whether a media is in a slot."
- Reply: Doublehp: "Re: cheking whether a media is in a slot."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 15 Sep 2004 11:43:20 +1200
Doublehp wrote:
> I am still working on CD drives under windows; I d need a trick to
> check whether a media is still present in a drive. I can not try to
> open file in the disk nor try to list the drive, because other apps
> are expected to do so at the same time; in fact I d need a trck which
> gives the response at once ( within 0.1 s ), even if the lense is
> blocked on a reading acces.
>
> What about using some DeviceIoControl ? is it fast ? does need to
> perform a read acces ? ( if yes, then I dont want to use it )
> what about other solutions ?
>
> for example it would be enough if my app was notified of any 'eject
> event' ... but I dont know how to do that.
>
> I am doing C, but accept multitasking and multithreading. I can NOT
> use mciSendCommand or any command of that familly.
One possibility is to use the GetVolumeInformation() API. If there's a
disk mounted it will return volume name and so on, otherwise it will
fail and GetLastError() will return 21 - drive not ready.
Here's a quick-n-nasty way to test whether a CD-ROM drive has a disk
inserted (assuming your 'D' drive is a CD-ROM):
if (GetDriveInformation("D:\\", NULL, 0, NULL, NULL, NULL, NULL, 0))
{
// non-zero result means success
}
else
{
// failure
}
You needn't actually ask for information about the drive to discover
whether there's a disk in or not... the call will fail if there isn't,
and should succeed if there is.
One exception though... if the inserted disk doesn't have a recognized
file system (corrupted disk or similar) the call will fail and
GetLastError() returns 1005 (0x3ED) to tell you about it. If you don't
care about whether or not the disk is readable you might want to do a
further check after failure to make sure that it failed because the
drive isn't ready.
int IsCDPresent(char const* path)
{
if (!GetDriveInformation(path, NULL, 0, NULL, NULL, NULL, NULL, 0))
{
if (21 == GetLastError())
return FALSE;
}
return TRUE;
}
Neither bulletproof nor tested... but it's a starting point. There are
a slew of other errors that you might want to check for as well.
-- Corey Murtagh The Electric Monk "Quidquid latine dictum sit, altum viditur!"
- Next message: EMonk: "Re: [EGN] Numerical Accuracy"
- Previous message: Paul Lutus: "Re: Importance of Computer Science degree?"
- In reply to: Doublehp: "cheking whether a media is in a slot."
- Next in thread: Doublehp: "Re: cheking whether a media is in a slot."
- Reply: Doublehp: "Re: cheking whether a media is in a slot."
- Reply: Doublehp: "Re: cheking whether a media is in a slot."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|