在我的 c++ 应用程序中,我很想通过createfile
- 使用重叠标志并在它之后 -异步读取 iso 文件readfile
。但是,当我在一个简单的文件(例如 txt 文件)上尝试此代码时,它可以工作。但是当我在 iso 文件上运行此代码时 - 它失败了。我在 MSDN 中看到压缩文件只能通过 readfile 同步调用读取。iso文件属于这个类别吗?如果是 - 你有其他建议如何异步读取iso文件吗?
这是我的代码:
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile;
DWORD NumberOfBytesRead = 0, dw;
BYTE *buf = (BYTE*)malloc(BUF_SIZE*sizeof(BYTE));
OVERLAPPED overlapped;
overlapped.Offset = overlapped.OffsetHigh = 0;
memset(buf, 0, 1024);
overlapped.hEvent = CreateEvent(NULL, true, false, NULL);
if(NULL == overlapped.hEvent)
printf("error");
hFile = CreateFile("xxx.iso",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING ,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
printf("invalid hfile\n");
int i;
i= ReadFile(hFile,
buf,
BUF_SIZE,
&NumberOfBytesRead,
&overlapped);
if( GetLastError() == ERROR_IO_PENDING)
{
dw = WaitForSingleObject(overlapped.hEvent, INFINITE);
if(dw == WAIT_OBJECT_0)
if (GetOverlappedResult(hFile,&overlapped,&NumberOfBytesRead, TRUE) != 0)
{
if (NumberOfBytesRead != 0)
{
printf("!!!\n");
}
}
}
谢谢