Preventing the CD-ROM From Ejecting

Hi,

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);
[1496 byte] By [ramey] at [2007-11-19 2:43:35]
# 1 Re: Preventing the CD-ROM From Ejecting
Because you are the locker -> hVolume so it is valid to Send an eject via DeviceIoControl(...) via the returned handle.

The FSCTL_LOCK_VOLUME control code locks a volume. A locked volume can be accessed only through handles to the file object (*hDevice) that locks the volume.
Mick at 2007-11-11 0:46:18 >
# 2 Re: Preventing the CD-ROM From Ejecting
Or did you want to prevent an ejection from elsewhere?

DWORD dwBytesReturned;
PREVENT_MEDIA_REMOVAL PMRBuffer;

PMRBuffer.PreventMediaRemoval = TRUE;

DeviceIoControl(hVolume,
IOCTL_STORAGE_MEDIA_REMOVAL,
&PMRBuffer, sizeof(PREVENT_MEDIA_REMOVAL),
NULL, 0,
&dwBytesReturned
NULL);
Mick at 2007-11-11 0:47:13 >