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 ROM open close problem

CD ROM open close problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
5 Posts 2 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 all vc++ masters \ i use this code for cd rom open and close but this gives 'OpenVolume' : local function definitions are illegal 'OpenVolume' : cannot convert parameter 1 from 'char [3]' to 'char' This conversion requires a reinterpret_cast, a C-style cast or function-style cast NOTE:the line contain stars shows errors; DWORD IOCTL_STORAGE_EJECT_MEDIA; DWORD bytesreturned; 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; } *******HANDLE hVolume = OpenVolume("D:");**DeviceIoControl( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); thanks special thanks to MR Naveen

    N 1 Reply Last reply
    0
    • P p_

      hi all vc++ masters \ i use this code for cd rom open and close but this gives 'OpenVolume' : local function definitions are illegal 'OpenVolume' : cannot convert parameter 1 from 'char [3]' to 'char' This conversion requires a reinterpret_cast, a C-style cast or function-style cast NOTE:the line contain stars shows errors; DWORD IOCTL_STORAGE_EJECT_MEDIA; DWORD bytesreturned; 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; } *******HANDLE hVolume = OpenVolume("D:");**DeviceIoControl( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); thanks special thanks to MR Naveen

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

      //the first error may be caused by placing function OpenVolume inside of another funtion. //the second is, TCHAR cDriveLetter means just pass a single charecter (Driveletter ie, 'D' ) //DWORD IOCTL_STORAGE_EJECT_MEDIA allready defined in winioctl.h DWORD bytesreturned ; TCHAR szRootFormat[5] = {"%c:\\" } ; TCHAR szVolumeFormat[9] = {"\\\\.\\%c:" } ; 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 ) { _tprintf(TEXT("Error Creatfile ") ) ; } return hVolume ; } int _tmain(int argc, _TCHAR* argv[]) { HANDLE hVolume = OpenVolume( 'D' ) ; //TCHAR Stands for a single charecter DeviceIoControl( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); return 0; }

      P 1 Reply Last reply
      0
      • N nitin3

        //the first error may be caused by placing function OpenVolume inside of another funtion. //the second is, TCHAR cDriveLetter means just pass a single charecter (Driveletter ie, 'D' ) //DWORD IOCTL_STORAGE_EJECT_MEDIA allready defined in winioctl.h DWORD bytesreturned ; TCHAR szRootFormat[5] = {"%c:\\" } ; TCHAR szVolumeFormat[9] = {"\\\\.\\%c:" } ; 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 ) { _tprintf(TEXT("Error Creatfile ") ) ; } return hVolume ; } int _tmain(int argc, _TCHAR* argv[]) { HANDLE hVolume = OpenVolume( 'D' ) ; //TCHAR Stands for a single charecter DeviceIoControl( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); return 0; }

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

        thanks sir i us this code as u specify but problem is now as: errors: 'OpenVolume' : local function definitions are illegal main' : local function definitions are illegal i use whole code inside this : void CInoutDlg::OnButton3() now please tell me where am i wrong thanks

        N 1 Reply Last reply
        0
        • P p_

          thanks sir i us this code as u specify but problem is now as: errors: 'OpenVolume' : local function definitions are illegal main' : local function definitions are illegal i use whole code inside this : void CInoutDlg::OnButton3() now please tell me where am i wrong thanks

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

          u should not place the HANDLE OpenVolume( TCHAR cDriveLetter ) definsion insde of "void CInoutDlg::OnButton3()" because this is another function, one function definition cant be place inside of another one. //so put the code here HANDLE OpenVolume( TCHAR cDriveLetter ) { ... } void CInoutDlg::OnButton3() { //call OpevVolume HANDLE hVolume = OpenVolume( 'D' ) ; //TCHAR Stands for a single charecter DeviceIoControl( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); }

          P 1 Reply Last reply
          0
          • N nitin3

            u should not place the HANDLE OpenVolume( TCHAR cDriveLetter ) definsion insde of "void CInoutDlg::OnButton3()" because this is another function, one function definition cant be place inside of another one. //so put the code here HANDLE OpenVolume( TCHAR cDriveLetter ) { ... } void CInoutDlg::OnButton3() { //call OpevVolume HANDLE hVolume = OpenVolume( 'D' ) ; //TCHAR Stands for a single charecter DeviceIoControl( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); }

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

            thanks alot sir

            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