Anupam07

Hi All,

I am trying to get an exclusive lock to the optical drive on my system and for that I am trying to use the IOCTL_CDROM_EXCLUSIVE_ACCESS device IO control call. I am having trouble issuing it using Windows Server 2003 SP1 DDK. I tried using it as described in here: http://msdn2.microsoft.com/en-us/library/aa509211.aspx

According to the documentation IOCTL_CDROM_EXCLUSIVE_ACCESS,
CDROM_EXCLUSIVE_ACCESS and
CDROM_EXCLUSIVE_LOCK_STATE are defined in "ntddcdrm.h".

I included ntddcdrm.h and tried issuing IOCTL_CDROM_EXCLUSIVE_ACCESS but I couldn't even compile my code as I was getting IOCTL_CDROM_EXCLUSIVE_ACCESS,
CDROM_EXCLUSIVE_ACCESS and CDROM_EXCLUSIVE_LOCK_STATE : undeclared identifier error.

Here is how I am trying to use it in the code:

#include <windows.h>
#include <winioctl.h>
#include "ntddcdrm.h"

CDROM_EXCLUSIVE_ACCESS cdromExclusiveAccess;
cdromExclusiveAccess.RequestType = ExclusiveAccessQueryState;

CDROM_EXCLUSIVE_LOCK_STATE cdromExclusiveLockState;

Uint32 bytesReturned;

if ( DeviceIoControl(deviceHandle,
IOCTL_CDROM_EXCLUSIVE_ACCESS,
&cdromExclusiveAccess,
sizeof(CDROM_EXCLUSIVE_ACCESS),
&cdromExclusiveLockState,
sizeof(CDROM_EXCLUSIVE_LOCK_STATE),
&bytesReturned,
NULL
) == 0 )
{
cout << "Exclusive Access to the CD-ROM device Failed. Error Code : " <<
GetLastError();
}

cout << "Device Locked : " << cdromExclusiveLockState.LockState "YES" : "NO" << endl;

Please let me know if there is any bug in here or any other ways of getting an exclusive access to the Optical Drive.

Thanks,

Anupam.


Re: Optical Platform Discussion Problem with IOCTL_CDROM_EXCLUSIVE_ACCESS

Michael Xing - MSFT

Hi,

IOCTL_CDROM_EXCLUSIVE_ACCESS is an IOCTL added in Vista (note that this IOCTL does not work on Windows XP/Server2003/Windows 2000 now) and you need WDK for using it.

Thanks,

Michael