// 0: Unknown
// file_device_cd_rom: CD-ROM
// file_device_dvd: DVD-ROM
function getcdtype (drive: Char): device_type;
const size = 2048;
var
hdrive: thandle;
dwbytesreturned: DWORD;
bmediatypes: array [0 .. size-1] of byte;
rmediatypes: tgetmediatypes absolute bmediatypes;
begin
result: = 0;
hdrive: = createfile (pchar ('\\. \ '+ drive +': '), generic_read,
file_cmd_read, nil, open_existing, 0, 0);
If hdrive = invalid_handle_value then exit;
If deviceiocontrol (hdrive, ioctl_storage_get_media_types_ex, nil, 0,
@ Bmediatypes, size, dwbytesreturned, nil) then
With rmediatypes do
If mediainfocount> 0 then result: = devicetype;
Closehandle (hdrive );
End;
Device_type/tgetmediatypes are defined in IOCTL. Pas.
In fact, there is a method getmediatype in IOCTL. Pas, which returns storage_media_type with N values, such
Removablemedia = 11; // removable media other than floppy
Fixedmedia = 12; // Fixed hard disk media
...
Cd_rom = 51; // opt_disk-CD
Cd_r = 52; // opt_disk-Cd-recordable (write once)
Cd_rw = 53; // opt_disk-Cd-rewriteable
Dvd_rom = 54; // opt_disk-DVD-ROM
Dvd_r = 55; // opt_disk-DVD-recordable (write once)
Dvd_rw = 56; // opt_disk-DVD-rewriteable
The drive type should be more detailed, but I tested it and found that the DVD-RW on my machine was recognized as cd_rom
I don't know what the problem is. I have time to study it again.