写程序的时候遇到一点困难,怎样得知驱动器中有没有插入盘?譬如插入SD卡的移动存储器?

解决方案 »

  1.   

    FindFirstFile
    看GetLastError
    自己试验一下不同情况下的ERROR是什么值
      

  2.   

    我知道,我用CreateDirectory也可以知道啊,但是系统会报告一个“没有插入软盘”的对话框,我不希望那个对话框出现,怎么办呢?
      

  3.   

    我想如果不进行读写超作是测不出来的,你用这个函数试试DeviceIoControl:IOCTL_STORAGE_CHECK_VERIFY
    The IOCTL_STORAGE_CHECK_VERIFY DeviceIoControl operation determines whether a device's media is accessible; for example, whether the media is in the device. BOOL DeviceIoControl(
      (HANDLE) hDevice,        // handle to device of interest
      IOCTL_STORAGE_CHECK_VERIFY,  // dwIoControlCode, control code of
                               // operation to perform
      NULL,                    // lpInBuffer is not used; must be NULL
      0,                       // nInBufferSize is not used; must be zero
      NULL,                    // lpOutBuffer is not used; must be NULL
      0,                       // nOutBufferSize is not used;
                               // must be zero
      (LPDWORD) lpBytesReturned,   // pointer to variable to receive
                               // output byte count
      (LPOVERLAPPED) lpOverlapped  // pointer to OVERLAPPED structure
                               // for asynchronous operation
    );
      

  4.   

    bool IsMediaExist(char *Drive)
    {
    char DeviceName[MAX_PATH];
    HANDLE hDevice;
    DWORD cbBytesAct = 0;
    bool fMediaExist = false; sprintf(DeviceName, "\\\\.\\%s", Drive); hDevice = CreateFile(
    DeviceName,
    GENERIC_READ | GENERIC_WRITE,
    FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,
    NULL,
    NULL); if (hDevice != INVALID_HANDLE_VALUE) {
    if (DeviceIoControl(
    hDevice,
    IOCTL_DISK_CHECK_VERIFY,
    NULL,
    0,
    NULL,
    0,
    &cbBytesAct,
    NULL)) {
    fMediaExist = true;
    } CloseHandle(hDevice);
    } return( fMediaExist );
    }