本文整理汇总了C++中CAtlFile::Attach方法的典型用法代码示例。如果您正苦于以下问题:C++ CAtlFile::Attach方法的具体用法?C++ CAtlFile::Attach怎么用?C++ CAtlFile::Attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAtlFile
的用法示例。
在下文中一共展示了CAtlFile::Attach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
std::vector<unsigned char> DumpUploaderWebServiceEx::ReadFile(const std::wstring& path)
{
std::vector<unsigned char> data;
CAtlFile file;
for (int i = 0; ; ++i)
{
file.Attach(CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
if (file != INVALID_HANDLE_VALUE)
break;
DWORD err = GetLastError();
// File indexing services like to open just closed files (our doctor_dump_mini.zip file), so lets make few tries.
if (err == ERROR_SHARING_VIOLATION && i < 10)
{
Sleep(1000);
continue;
}
CStringA text;
text.Format("failed (err %d) to open file %ls", err, path.c_str());
throw std::runtime_error(text);
}
ULONGLONG fileSize;
if (FAILED(file.GetSize(fileSize)))
throw std::runtime_error(std::string("failed to get file size ") + (const char*)CW2A(path.c_str()));
if (fileSize != 0)
{
data.resize((size_t)fileSize);
if (FAILED(file.Read(&data[0], static_cast<DWORD>(fileSize))))
throw std::runtime_error(std::string("failed to read file ") + (const char*)CW2A(path.c_str()));
}
return data;
}