CD ROM open close problem
-
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
-
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
//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; }
-
//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; }
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
-
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
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 ); }
-
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 ); }