Click here to Skip to main content
11,578,739 members (62,567 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C Windows API
Hello, guys
I use GetDriveType function to determine CD-ROM drives in a computer, but I want to detect the writable ones, using windows API, I searched DeviceIoControl function but the documentation was very comprehensive and I was unable to get my answer. Can anyone help me?
Thanks in advance

EDIT: I found that the DEVICE_MEDIA_INFO structure contains a
DWORD  MediaCharacteristics;
member that clearly specifies if the media is Writable, by I can not find which function returns it.

EDIT: I got the DEVICE_MEDIA_INFO structure for both CD-ROM and CD-RW and examined the MediaCharacteristics member, showing no difference, so DEVICE_MEDIA_INFO may not contain writable characteristic of a cd-rom drive.
Posted 22-Jan-13 0:34am
Edited 22-Jan-13 3:19am
Richard MacCutchan at 22-Jan-13 9:33am
Did you have a CD mounted in the drive at the time you ran the test?
mr.abzadeh at 22-Jan-13 10:19am
Yes, there was a CD in the drive for both CD-ROM and CD-RW.
Richard MacCutchan at 22-Jan-13 10:22am
See my Solution comments below.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Possibly you may use IMAPI, namely IDiscRecorder::QueryMediaType[^] method. See also CD Burning and Device Discovery with IMAPI[^]
mr.abzadeh at 22-Jan-13 10:43am
I tested ICDBurn Interface, and It worked correctly, Thanks for your help.
If one day you found a way to detect recordable cd drives directly, without ICDBurn or IMAPI, please send it to me. Thanks again
CPallini at 22-Jan-13 12:44pm
You are welcome.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I just tested this on my system and it shows the correct characteristics for the drive when a Writable CD/DVD is mounted. Note that the GET_MEDIA_TYPES[^] structure contains an array of DEVICE_MEDIA_INFO[^] entries, so you need to iterate the list for the correct entry.
mr.abzadeh at 22-Jan-13 10:31am
I examined it for both CD-ROW and CD-RW, with CD mounted, and the value of MediaCharacteristics in the second item of array was MEDIA_READ_WRITE,
i.e. pMediaType->MediaInfo[1].DeviceSpecific.DiskInfo.MediaCharacteristics was 8. my code is as this:
static int uIsMediaWritable( const GET_MEDIA_TYPES * pMediaType )
unsigned uCount = pMediaType->MediaInfoCount;
for ( unsigned uIndex = 0 ; uIndex < uCount ; uIndex ++ )
DWORD dwMediaCharacteristics = pMediaType->MediaInfo[uIndex].DeviceSpecific.DiskInfo.MediaCharacteristics;
if ( dwMediaCharacteristics & MEDIA_READ_WRITE ) return TRUE;
if ( dwMediaCharacteristics & MEDIA_WRITE_ONCE ) return TRUE;
//if ( dwMediaCharacteristics & MEDIA_WRITE_PROTECTED ) return TRUE;
return FALSE;
Richard MacCutchan at 22-Jan-13 10:42am
So that is good then?
mr.abzadeh at 22-Jan-13 14:16pm
No, It reported that CD DRIVE is recordable for both CD-ROW and CD-RW drives, which is not correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Peter Leow 135
1 Frankie-C 115
2 OriginalGriff 113
3 Richard MacCutchan 85
4 Afzaal Ahmad Zeeshan 75
0 OriginalGriff 933
1 Sergey Alexandrovich Kryukov 740
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 403

Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100