Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CD drive open and close

CD drive open and close

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    p_
    wrote on last edited by
    #1

    hi to all vc++ masters and happy teachers day :rose: i am building an application in which there is button and i want that when i clich on that button the CD:Drive open and when i click on another button CD:Drive closed please help me in this regard and i have no idea about that thanks :rose:

    N D 2 Replies Last reply
    0
    • P p_

      hi to all vc++ masters and happy teachers day :rose: i am building an application in which there is button and i want that when i clich on that button the CD:Drive open and when i click on another button CD:Drive closed please help me in this regard and i have no idea about that thanks :rose:

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      see How To Ejecting Removable Media in Windows NT/Windows 2000/Windows XP[^]

      nave [OpenedFileFinder]

      P 1 Reply Last reply
      0
      • N Naveen

        see How To Ejecting Removable Media in Windows NT/Windows 2000/Windows XP[^]

        nave [OpenedFileFinder]

        P Offline
        P Offline
        p_
        wrote on last edited by
        #3

        thanks sir but actually i have no idea about this so can u give me some other example for help thanks

        N 1 Reply Last reply
        0
        • P p_

          thanks sir but actually i have no idea about this so can u give me some other example for help thanks

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          p_ wrote:

          so can u give me some other example for help

          But the sample is already there in the link I provide. The cd drive can be ejected and inserted using the DeviceIoControl() function. For eg if you want to eject the drive the below code will do DeviceIoControl( (HANDLE) hDevice, // handle to device IOCTL_STORAGE_EJECT_MEDIA, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); And for inserting change the flag to IOCTL_STORAGE_LOAD_MEDIA

          nave [OpenedFileFinder]

          P 1 Reply Last reply
          0
          • N Naveen

            p_ wrote:

            so can u give me some other example for help

            But the sample is already there in the link I provide. The cd drive can be ejected and inserted using the DeviceIoControl() function. For eg if you want to eject the drive the below code will do DeviceIoControl( (HANDLE) hDevice, // handle to device IOCTL_STORAGE_EJECT_MEDIA, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); And for inserting change the flag to IOCTL_STORAGE_LOAD_MEDIA

            nave [OpenedFileFinder]

            P Offline
            P Offline
            p_
            wrote on last edited by
            #5

            sir i use this code on button but it does not work DWORD bytesreturned; DWORD IOCTL_STORAGE_EJECT_MEDIA; void * hDevice; DeviceIoControl( hDevice, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); thanks

            N 1 Reply Last reply
            0
            • P p_

              sir i use this code on button but it does not work DWORD bytesreturned; DWORD IOCTL_STORAGE_EJECT_MEDIA; void * hDevice; DeviceIoControl( hDevice, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); thanks

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              p_ wrote:

              void * hDevice;

              Now you are passing an invalid value as hDevice. see the below code in the above link. HANDLE OpenVolume(TCHAR cDriveLetter) { HANDLE hVolume; UINT uDriveType; TCHAR szVolumeName[8]; TCHAR szRootName[5]; DWORD dwAccessFlags; wsprintf(szRootName, szRootFormat, cDriveLetter); uDriveType = GetDriveType(szRootName); switch(uDriveType) { case DRIVE_REMOVABLE: dwAccessFlags = GENERIC_READ | GENERIC_WRITE; break; case DRIVE_CDROM: dwAccessFlags = GENERIC_READ; break; default: _tprintf(TEXT("Cannot eject. Drive type is incorrect.\n")); return INVALID_HANDLE_VALUE; } wsprintf(szVolumeName, szVolumeFormat, cDriveLetter); hVolume = CreateFile( szVolumeName, dwAccessFlags, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); if (hVolume == INVALID_HANDLE_VALUE) ReportError(TEXT("CreateFile")); return hVolume; } If you specify the drive letter of the drive, te above function will return a handle pass that handle to the DeviceIoControl() function. like HANDLE hVolume = OpenVolume( "E:" ); OpenVolume( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL );

              nave [OpenedFileFinder]

              1 Reply Last reply
              0
              • P p_

                hi to all vc++ masters and happy teachers day :rose: i am building an application in which there is button and i want that when i clich on that button the CD:Drive open and when i click on another button CD:Drive closed please help me in this regard and i have no idea about that thanks :rose:

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Try mciSendCommand(), like: mciSendCommand(..., MCI_SET, MCI_SET_DOOR_OPEN, ...);


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups