April 2nd, 2004, 10:45 PM
Detecting DVD drive
How can I detect DVD drive with Delphi. The GetDriveType function is not capable of returning this information. Also I would like to know if the CD drive is writeable or readonly.
April 10th, 2004, 01:53 PM
You had the right idea there. Here's how to do it:
1. Call GetDriveType and see if this media is a DVD/CD or some other device (i.e.) Of return value is 5, this is either a DVD or a CD. If not, this is some other device.
2. Call DeviceIoControl and pass it IOCTL_STORAGE_GET_MEDIA_TYPES_EX for the second argument. Then check the value of the fifth parameter that you passed to the function (this is a pointer to a GET_MEDIA_TYPES structure). The GET_MEDIA_TYPES structure has a member called DeviceType which will tell you whether this is a CD or DVD. These two links should give you all the information that you need to get started with DeviceIoControl.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
April 19th, 2004, 02:16 PM
I've been trying this, but with no luck
I get 'Undeclared Identifier: IOCTL_STORAGE_GET_MEDIA_TYPES_EX', and am also stumped on the rest of the parameters.
Hnd := CreateFile('\\.\D:', 0, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, null);
DeviceIoControl(Hnd, IOCTL_STORAGE_GET_MEDIA_TYPES_EX, nil, 0, ???
How can I do it??
September 16th, 2004, 09:34 AM
I just found this post, and never actually solved my problem, here's another link I found (C++), but am unable to translate to Delphi, specifically some of the structs which I guess must be in some Delphi header file I'm unaware of.
September 16th, 2004, 04:37 PM
Go to this page and download win32api.zip. This file contains Delphi translations of many windows header files including winioctl.h.
Extract the contents of the zip file to the folder containing your project. Then add "Windows" and "JwaWinIoctl" to your uses list. JwaWinIoctl.pas provides definitions for IOCTL_STORAGE_GET_MEDIA_TYPES_EX and the GET_MEDIA_TYPES struct.
Attached is a sample console program (that you can improve) that uses the GetDriveType, CreateFile and DeviceIoControl functions.