Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Eject a CD from CDROM drive

0 views
Skip to first unread message

whitemous

unread,
Jun 1, 2000, 3:00:00 AM6/1/00
to
I am tring to write a small app that will eject a cd from the drive. I try
first to CreateFile on the drive,

hDevice = CreateFile("\\\\.\\s:", // drive to open

GENERIC_READ, // | GENERIC_WRITE, // don't need any access to the drive

FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode

NULL, // default security attributes

OPEN_EXISTING, // disposition

0, // file attributes

NULL); // don't copy any file's attributes

file://I then try to Lock the drive with,

// for (int abcd=0; abcd < 20; abcd++)

bResult = DeviceIoControl(

hDevice, // handle to a volume

FSCTL_LOCK_VOLUME, // dwIoControlCode operation

NULL, // lpInBuffer; must be NULL

0, // nInBufferSize; must be zero

NULL, // lpOutBuffer; must be NULL

0, // nOutBufferSize; must be zero

lpBytesReturned, // number of bytes returned

lpOverlapped // OVERLAPPED structure

);

junk = GetLastError();

if (junk)

ShowGetLastError(junk);

if (!bResult)

{ // if IOCTL failed...

CloseHandle(hDevice); // we're done with the handle

return (FALSE);

}

But I get Unhandled exception in LockDrive.exe (Kernal32.dll) 0xC0000005:
Access Violation. I was then going to FSCTL_DISMOUNT_VOLUME then
IOCTL_STORAGE_MEDIA_REMOVAL then IOCTL_STORAGE_EJECT_MEDIA. What am I doing
wrong?

If anyone want to email me code that would be great.

My CDROM drive is a SCSI unit. I am running Windows 2000 with Administrative
rights. There is a CD in the drive.

Thanks,

Allan

David Wendt

unread,
Jun 2, 2000, 3:00:00 AM6/2/00
to
Just out curiosity, how is lpBytesReturned defined? Did you allocate
storage for it?

"whitemous" <whit...@nospam.org> wrote in message
news:kQhZ4.56712$nl3.1...@typhoon.ne.mediaone.net...

whitemous

unread,
Jun 4, 2000, 3:00:00 AM6/4/00
to
It was only,

LPDWORD lpBytesReturned;

silly me,

it's now

LPDWORD lpBytesReturned;
DWORD BytesReturned;
lpBytesReturned = &BytesReturned;

Thanks

"David Wendt" <we...@us.ibm.com> wrote in message
news:8h87aa$sq8$1...@news2atm.raleigh.ibm.com...

Jerry Coffin

unread,
Jun 4, 2000, 3:00:00 AM6/4/00
to
In article <kQhZ4.56712$nl3.1...@typhoon.ne.mediaone.net>,
whit...@nospam.org says...

> I am tring to write a small app that will eject a cd from the drive. I try
> first to CreateFile on the drive,

[ ... ]

There's a much easier way. Try:
mciSendString("set cdaudio door open");

--
Later,
Jerry.

The universe is a figment of its own imagination.

0 new messages