• win32


    #include <tchar.h>
    #include <windows.h>
    #include <mmsystem.h> // for MCI functions
    
    // Link to winmm.lib (usually included in project settings)
    #pragma comment(lib, "winmm")
    
    void ControlCdTray(TCHAR drive, DWORD command)
    {
        // Not used here, only for debug
        MCIERROR mciError = 0;
    
        // Flags for MCI command
        DWORD mciFlags = MCI_WAIT | MCI_OPEN_SHAREABLE | 
            MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT;
    
        // Open drive device and get device ID
        TCHAR elementName[] = { drive };
        MCI_OPEN_PARMS mciOpenParms = { 0 };
        mciOpenParms.lpstrDeviceType = (LPCTSTR)MCI_DEVTYPE_CD_AUDIO;
        mciOpenParms.lpstrElementName = elementName;    
        mciError = mciSendCommand(0, 
            MCI_OPEN, mciFlags, (DWORD_PTR)&mciOpenParms);
    
        // Eject or close tray using device ID
        MCI_SET_PARMS mciSetParms = { 0 };
        mciFlags = MCI_WAIT | command; // command is sent by caller
        mciError = mciSendCommand(mciOpenParms.wDeviceID, 
            MCI_SET, mciFlags, (DWORD_PTR)&mciSetParms);
        
        // Close device ID
        mciFlags = MCI_WAIT;
        MCI_GENERIC_PARMS mciGenericParms = { 0 };
        mciError = mciSendCommand(mciOpenParms.wDeviceID, 
            MCI_CLOSE, mciFlags, (DWORD_PTR)&mciGenericParms);
    }
    
    // Eject drive tray
    void EjectCdTray(TCHAR drive)
    {
        ControlCdTray(drive, MCI_SET_DOOR_OPEN);
    }
    
    // Retract drive tray
    void CloseCdTray(TCHAR drive)
    {
        ControlCdTray(drive, MCI_SET_DOOR_CLOSED);
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        EjectCdTray(TEXT('E')); // drive letter hardcoded
        CloseCdTray(TEXT('E'));
    
        return 0;
    }
    #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); 
    } 
  • 相关阅读:
    rbd-mirror新功能
    ceph查询rbd的使用容量(快速)
    Ceph Bluestore首测
    让磁盘硬盘灯常闪定位盘
    aa
    地理围栏
    Can't connect to MySQL server on localhost (10061)解决方法
    经典智力题
    MEF程序设计指南
    ESRI.ArcGIS.AnalysisTools.Erase 结果是空?
  • 原文地址:https://www.cnblogs.com/strive-sun/p/14242598.html
Copyright © 2020-2023  润新知