本文整理汇总了C++中CError::bad_alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ CError::bad_alloc方法的具体用法?C++ CError::bad_alloc怎么用?C++ CError::bad_alloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CError
的用法示例。
在下文中一共展示了CError::bad_alloc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DecodeThread
UINT WINAPI CExtractData::DecodeThread(LPVOID lpParam)
{
CExtractData* pObj = (CExtractData*)lpParam;
CArcFile* pclArc = NULL;
try
{
SOption* pOption = pObj->m_pOption;
LPCTSTR pSaveDir = pObj->m_pSaveDir;
BOOL bConvert = pObj->m_bConvert;
// Determine entire filesize
std::vector<int> nSelects;
QWORD AllFileSize = 0;
std::vector<CArcFile*>& rArcList = pObj->m_ArcList;
if (pObj->m_dwExtractMode == EXTRACT_SELECT)
{
int nItem = -1;
while ((nItem = pObj->m_pListView->GetNextItem(nItem)) != -1)
{
nSelects.push_back(nItem);
AllFileSize += rArcList[0]->GetFileInfo(nItem)->sizeOrg;
}
}
else
{
size_t nItemCount = rArcList[0]->GetFileInfo().size();
for (int nItem = 0; nItem < (int)nItemCount; nItem++)
{
nSelects.push_back(nItem);
AllFileSize += rArcList[0]->GetFileInfo(nItem)->sizeOrg;
}
}
// Initialize progressbar
CProgBar prog;
prog.Init(pObj->m_hWnd, AllFileSize);
for (size_t i = 0; i < nSelects.size(); i++)
{
SFileInfo* pInfFile = rArcList[0]->GetFileInfo(nSelects[i]);
pclArc = rArcList[pInfFile->arcID];
pclArc->SetProg(prog);
// Create destination folder name from the destination filename input
if (pSaveDir == NULL && pOption->bSaveSrc == TRUE)
{
TCHAR SaveDir[MAX_PATH];
// Get input
lstrcpy(SaveDir, pclArc->GetArcPath());
// Delete the filename
PathRemoveFileSpec(SaveDir);
if (pclArc->GetCtEnt() == 1)
{
// Archive folder creation stores files one by one
TCHAR ArcDirName[_MAX_DIR];
lstrcpy(ArcDirName, PathFindFileName(SaveDir));
PathAppend(SaveDir, _T("_"));
lstrcat(SaveDir, ArcDirName);
}
else
{
// Create a folder with the name of the archive files if there are more than two files present
PathAppend(SaveDir, _T("_"));
lstrcat(SaveDir, pclArc->GetArcName());
}
pclArc->SetSaveDir(SaveDir);
}
else
{
pclArc->SetSaveDir(pSaveDir);
}
pclArc->SetFileInfo(nSelects[i]);
// View filename
prog.SetFileName(pInfFile->name);
// Extraction
CExtract::Decode(pclArc, bConvert);
// Close the file (For when I forget to close it)
pclArc->CloseFile();
}
//MessageBox(pObj->m_hWnd, "", "", MB_OK);
}
catch (std::bad_alloc)
{
// Out of memory error
CError error;
error.bad_alloc(pObj->m_hWnd);
}
catch (...)
{
// Or if we cancel the operation
//CError error;
//error.Message(pObj->m_hWnd, "");
//.........这里部分代码省略.........
示例2: MountThread
UINT WINAPI CExtractData::MountThread(LPVOID lpParam)
{
CExtractData* pObj = (CExtractData*)lpParam;
try
{
SOption* pOption = pObj->m_pOption;
LPCTSTR pclArcNames = pObj->m_pclArcNames;
std::vector<SFileInfo>& rEnt = pObj->m_pListView->GetFileInfo();
std::vector<YCString> sArcNameList;
YCString sArcNames(pclArcNames);
sArcNameList.push_back(sArcNames);
pclArcNames += lstrlen(pclArcNames) + 1; // Because of ZeroMemory, we have to add one for the null terminator char.
// If you select more than one
if (lstrcmp(pclArcNames, _T("")) != 0)
{
// Get directory name
TCHAR tmpDir[_MAX_DIR];
lstrcpy(tmpDir, sArcNameList[0]);
PathAddBackslash(tmpDir);
YCString Dir(tmpDir);
sArcNameList.clear();
// Directory Name + Filename in the list.
while (lstrcmp(pclArcNames, _T("")) != 0)
{
YCString sArcName(pclArcNames);
sArcNameList.push_back(Dir + sArcName);
pclArcNames += lstrlen(pclArcNames) + 1;
}
sort(sArcNameList.begin(), sArcNameList.end());
}
// Entire file size
QWORD AllArcSize = 0;
std::vector<CArcFile*>& rArcList = pObj->m_ArcList;
for (std::vector<YCString>::iterator itr = sArcNameList.begin(); itr != sArcNameList.end(); )
{
// Open the archive file
CArcFile* pclArc = new CArcFile();
if (!pclArc->Open(*itr))
{
itr = sArcNameList.erase(itr); // Remove archive files that could not be opened from the list
delete pclArc;
}
else
{
// Add archive filesize
AllArcSize += pclArc->GetArcSize();
rArcList.push_back(pclArc);
itr++;
}
}
// Initialize the progress bar
CProgBar prog;
prog.Init(pObj->m_hWnd, AllArcSize);
// Reading
DWORD dwArcID = 0;
//for (std::vector<CArcFile*>::iterator itrArc = rArcList.begin(); itrArc != rArcList.end(); ) {
for (size_t i = 0; i < rArcList.size(); i++)
{
CArcFile* pclArc = rArcList[i];
pclArc->SetArcID(dwArcID);
pclArc->SetEnt(rEnt);
pclArc->SetProg(prog);
pclArc->SetOpt(pOption);
// View the archive filename
prog.SetArcName(pclArc->GetArcName());
// Corresponding file
if (CExtract::Mount(pclArc) == TRUE)
{
dwArcID++;
pclArc->SetState(TRUE);
}
}
//MessageBox(pObj->m_hWnd, "", "", MB_OK);
// Progress towards 100%
prog.UpdatePercent();
}
catch (std::bad_alloc)
{
// Out of memory
CError error;
error.bad_alloc(pObj->m_hWnd);
}
catch (...)
{
// or if canceled
}
//.........这里部分代码省略.........