Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
C++
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
Updated 22-Jan-13 3: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.

Possibly you may use IMAPI, namely IDiscRecorder::QueryMediaType[^] method. See also CD Burning and Device Discovery with IMAPI[^]
 
Share this answer
 
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.
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.
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900