none
读取SD卡信息不支持请求 RRS feed

  • 问题

  • 请问,我下面这段代码读取SD卡信息的错在哪里了???要怎样修改?

    void GetSDInfofmation()
    {
      HANDLE sd = CreateFile(_T("\\\\.\\G:"), GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
      if (sd == INVALID_HANDLE_VALUE) {
        //can't open G:
        // int result = GetLastError();
        return ;
      }
      int size = sizeof(SFFDISK_DEVICE_COMMAND_DATA) + sizeof(SDCMD_DESCRIPTOR) + 12;
      //SFFDISK_DEVICE_COMMAND_DATA *data = (SFFDISK_DEVICE_COMMAND_DATA)malloc(size);
      SFFDISK_DEVICE_COMMAND_DATA *data = (SFFDISK_DEVICE_COMMAND_DATA*) new BYTE[size];
      if (!data) {
        //malloc failed
      }
      memset(data, 0, size);
      data->HeaderSize = sizeof(SFFDISK_DEVICE_COMMAND_DATA);
      data->Command = SFFDISK_DC_DEVICE_COMMAND;
      data->ProtocolArgumentSize = sizeof(SDCMD_DESCRIPTOR);
      data->DeviceDataBufferSize = 12;
      data->Information = 0; /* param: stuff bits */
    
      SDCMD_DESCRIPTOR desc;
      desc.Cmd = 44; /* read single block */
      desc.CmdClass = SDCC_APP_CMD; 
      desc.TransferDirection = SDTD_READ;
      desc.TransferType = SDTT_SINGLE_BLOCK;
      desc.ResponseType = SDRT_1; 
      memcpy(data->Data, &desc, sizeof(SDCMD_DESCRIPTOR));
    
      DWORD returned = 0;
      int result = 0;
      bool ret = DeviceIoControl(sd, IOCTL_SFFDISK_DEVICE_COMMAND, data, size, data, size, &returned, NULL);
    
      //返回的ret 为false了。错在哪里了???
    
      if (!ret) {
        TCHAR Str[64] = {0};
        wsprintf(Str,L"ioctl failed: %d\n", GetLastError());
        result = GetLastError();   //这里返回的是:50
      }
    }
    请问上面代码中,
    DeviceIoControl发送请求为什么失败了????获取不了SD卡信息啊

    • 已移动 Elegentin Xie 2013年7月15日 10:14 from Visual C++, to a more appropriate forum
    2013年7月12日 6:29