MCI-Problem (Laufwerk)



  • Hallo,
    ich versuche das CD-Laufwerk zu öffnen und zu schließen mit diesem Code:

    #include "stdafx.h"
    
    #include <windows.h>
    
    #include <winuser.h>
    #include <mmsystem.h>
    #include <iostream.h>
    
    bool DoOpenCdRom(void)
    {  
       char chrRc[256];  
    
       return mciSendString("Set CDAudio Door Open\0", chrRc, sizeof(chrRc), NULL);
    }
    
    bool DoCloseCdRom(void)
    {  
       char chrRc[256];  
    
       return mciSendString("Set CDAudio Door Closed\0", chrRc, sizeof(chrRc), NULL);
    }
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
       DoOpenCdRom();  
    
       DoCloseCdRom();
    
       return 0;
    }
    

    Danke
    MfG Daniel



  • Ich würde es eher so machen:

    #include <windows.h> 
    #include <tchar.h> 
    #include <stdio.h> 
    
    int _tmain() 
    { 
      DWORD dwBytes; 
      HANDLE hCdRom = CreateFile(_T("\\\\.\\M:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 
      if (hCdRom == INVALID_HANDLE_VALUE) 
      { 
        _tprintf(_T("Error: %x"), GetLastError()); 
        return 1; 
      } 
    
      // Open the door: 
      DeviceIoControl(hCdRom, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &dwBytes, NULL); 
    
      Sleep(1000);
    
      // Close the door: 
      DeviceIoControl(hCdRom, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &dwBytes, NULL); 
    
      CloseHandle(hCdRom); 
    }
    


  • Danke, jetzt bekomme ich, aber diesen Fehler:
    error C2065: 'IOCTL_STORAGE_EJECT_MEDIA' : undeclared identifier
    error C2065: 'IOCTL_STORAGE_LOAD_MEDIA' : undeclared identifier

    Gruß Daniel



  • Füge mal folgende Header-Datei ein, dann müsste es klappen:

    #include "winioctl.h"
    


  • Dank euch allen es funzt! 🙂

    MfG Daniel


Anmelden zum Antworten