Hi
I am writing a native mode application that can eject the CD ROM drive.
Below is my code
BOOL bRet = FALSE;
UNICODE_STRING strVolumeName;
OBJECT_ATTRIBUTES objAttrsVolume;
PWCHAR pBufVolume;
WCHAR wVolumePath[MAX_PATH];
IO_STATUS_BLOCK ioStatusVolume;
NTSTATUS ntStatVolume;
pBufVolume = RtlAllocateHeap(g_hHeap, 0, MAX_PATH);
swprintf(wVolumePath, L"\??\E:");
RtlInitUnicodeString(&strVolumeName, wVolumePath);
objAttrsVolume.Length = sizeof(OBJECT_ATTRIBUTES);
objAttrsVolume.RootDirectory = NULL;
objAttrsVolume.ObjectName = &strVolumeName;
objAttrsVolume.Attributes = OBJ_CASE_INSENSITIVE;
objAttrsVolume.SecurityDescriptor = NULL;
objAttrsVolume.SecurityQualityOfService = NULL;
ntStatVolume = NtCreateFile(&g_hVolume,
GENERIC_READ,
&objAttrsVolume,
&ioStatusVolume,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
NULL,
0);
if(NT_SUCCESS(ntStatVolume))
{
ntStatus = NtDeviceIoControlFile( g_hVolume,
NULL,
NULL,
NULL,
NULL,
IOCTL_STORAGE_EJECT_MEDIA,
NULL,
0,
NULL,
0);
if(NT_SUCCESS(ntStatus))
{
//Display open success
}
}
Though I get the “Open Success” message, the drive is not opening. Could
anyone help me with this.
Thanks
Ramananda