Preventing the CD-ROM From Ejecting
With Linux, if there is a CD-ROM in the drive and you try ejecting the CD-ROM, the CD-ROM light will glow amber until you unmount the drive. Currently, I have the following code, but even though it's running, the drive ejects. What's wrong?? Thanks
HANDLE hVolume;
LPTSTR szRootName = TEXT("D:\\");
LPTSTR szVolumeFormat = TEXT("\\\\.\\D:");
UINT uDriveType = GetDriveType(szRootName);
DWORD dwAccessFlags;
DWORD dwBytesReturned;
char temp[10];
sprintf(temp,"%d",uDriveType);
if (uDriveType == DRIVE_CDROM)
dwAccessFlags = GENERIC_READ;
hVolume = CreateFile( szVolumeFormat,
dwAccessFlags,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL );
for (int i=0; i< 50; ++i)
{
if (DeviceIoControl(hVolume,
FSCTL_LOCK_VOLUME,
NULL, 0,
NULL, 0,
&dwBytesReturned,
NULL))
{
}
}
DeviceIoControl( hVolume,
IOCTL_STORAGE_EJECT_MEDIA,
NULL, 0,
NULL, 0,
&dwBytesReturned,
NULL);

