我正在尝试使用winhttp
将文件上传到云服务,但是在运行以下代码后,我无法再访问同一个文件了。似乎程序没有正确关闭其文件句柄:
HANDLE hFile = CreateFileW(MultiByteToWideChar(filePath), GENERIC_READ, FILE_SHARE_READ+FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwFileSize = GetFileSize(hFile, NULL);
HANDLE hFileMappingObject = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, dwFileSize, NULL);
HANDLE file = MapViewOfFile(hFileMappingObject, FILE_MAP_READ, 0, 0, 0);
bool result = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0, WINHTTP_NO_REQUEST_DATA, 0,
dwFileSize, 0);
result = WinHttpWriteData( hRequest, file, dwFileSize, &dwBytesWritten);
FlushViewOfFile(file, dwFileSize);
FlushFileBuffers(hFile);
UnmapViewOfFile(file);
CloseHandle(hFileMappingObject);
CloseHandle(hFile);