How to determine whether the optical drive is a CD or a DVD?

Source: Internet
Author: User

// 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.