#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    14
    Rep Power
    0

    Detecting DVD drive


    Hi Friends,

    How can I detect DVD drive with Delphi. The GetDriveType function is not capable of returning this information. Also I would like to know if the CD drive is writeable or readonly.

    regards,
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    You had the right idea there. Here's how to do it:

    1. Call GetDriveType and see if this media is a DVD/CD or some other device (i.e.) Of return value is 5, this is either a DVD or a CD. If not, this is some other device.
    2. Call DeviceIoControl and pass it IOCTL_STORAGE_GET_MEDIA_TYPES_EX for the second argument. Then check the value of the fifth parameter that you passed to the function (this is a pointer to a GET_MEDIA_TYPES structure). The GET_MEDIA_TYPES structure has a member called DeviceType which will tell you whether this is a CD or DVD. These two links should give you all the information that you need to get started with DeviceIoControl.
    http://msdn.microsoft.com/library/de...eiocontrol.asp
    http://msdn.microsoft.com/library/de...a_types_ex.asp
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Hamburg, DE
    Posts
    71
    Rep Power
    14
    I've been trying this, but with no luck

    Code:
    var
     Hnd: THandle;
    begin
     Hnd := CreateFile('\\.\D:', 0, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, null);
     DeviceIoControl(Hnd, IOCTL_STORAGE_GET_MEDIA_TYPES_EX, nil, 0, ???
     CloseHandle(Hnd);
    end;
    I get 'Undeclared Identifier: IOCTL_STORAGE_GET_MEDIA_TYPES_EX', and am also stumped on the rest of the parameters.

    How can I do it??

    Cheers
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Hamburg, DE
    Posts
    71
    Rep Power
    14
    I just found this post, and never actually solved my problem, here's another link I found (C++), but am unable to translate to Delphi, specifically some of the structs which I guess must be in some Delphi header file I'm unaware of.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    Go to this page and download win32api.zip. This file contains Delphi translations of many windows header files including winioctl.h.
    Extract the contents of the zip file to the folder containing your project. Then add "Windows" and "JwaWinIoctl" to your uses list. JwaWinIoctl.pas provides definitions for IOCTL_STORAGE_GET_MEDIA_TYPES_EX and the GET_MEDIA_TYPES struct.

    Attached is a sample console program (that you can improve) that uses the GetDriveType, CreateFile and DeviceIoControl functions.
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo