Click here to Skip to main content
12,622,652 members (27,266 online)
Rate this:
 
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
mr.abzadeh

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 1:34am
Updated 22-Jan-13 4:19am
v5
Comments
Richard MacCutchan 22-Jan-13 9:33am
   
Did you have a CD mounted in the drive at the time you ran the test?
mr.abzadeh 22-Jan-13 10:19am
   
Yes, there was a CD in the drive for both CD-ROM and CD-RW.
Richard MacCutchan 22-Jan-13 10:22am
   
See my Solution comments below.
Rate this: bad
 
good
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[^]
  Permalink  
Comments
mr.abzadeh 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
mr.abzadeh
CPallini 22-Jan-13 12:44pm
   
You are welcome.
Rate this: bad
 
good
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.
  Permalink  
Comments
mr.abzadeh 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 22-Jan-13 10:42am
   
So that is good then?
mr.abzadeh 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2016
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