ReadFile函数返回错误23

时间:2016-11-22 07:48:04

标签: c++ windows

我试图从USB设备(Windows 7)读取数据,但是我收到错误23(ERROR_CRC)。这是我的代码:

int main( int argc, char*argv[]) { HANDLE file; file = CreateFile(L"\\\\.\\PhysicalDrive1", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); if (file == INVALID_HANDLE_VALUE){ std::cout << "ERROR opening\n"; } DWORD byte_count; GET_LENGTH_INFORMATION source_disklength; if(!DeviceIoControl(file, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &source_disklength, sizeof(source_disklength), &byte_count, NULL ) ){ std::cout << "Error "<< GetLastError() << " getting device length \n"; } std::cout << "DISK Length has " << source_disklength.Length.QuadPart << " bytes\n"; int count = 0; DWORD cbRead; uint8_t buffer[50 * 1024]; while (ReadFile(file, buffer, sizeof(buffer), &cbRead, NULL)) { ++count; } std::cout << "Read Error " << GetLastError() <<std::endl; return 0; }

结果是:

DISK长度为16013942784字节

阅读错误23

有人知道为什么GetLastError()会返回错误,错误的含义究竟是什么?

0 个答案:

没有答案