万恶的win编程
计算机模型里,应用编程面向系统。在win编程的时候就有系统资源这么个东西,具体是win核心编程之类书里的。
资源的申请,释放,同步,权限,安全,很麻烦。
问题:文件删除失败,被程序占用。问题很简单,属于人sb了
代码:
void FileMonitor::FileSearch(const TCHAR *szRootPath)
{
using std::wstring;
WIN32_FIND_DATA FindFileData;
WIN32_FIND_DATA FileData;
HANDLE hFind;
wstring NodePath;
wstring rootPath;
bool Ret = true;
TCHAR tmp[1024] = { 0 };
m_pNotifyObj->debugLog(szRootPath);
NodePath.assign(szRootPath);
rootPath = szRootPath;
rootPath += _T("\\*.*");
//FindFileData.dwFileAttributes
hFind = FindFirstFile(rootPath.c_str(), &FindFileData);
while ((hFind != INVALID_HANDLE_VALUE) && (Ret))
{
m_pNotifyObj->debugLog(_T("FileSearch"));
if (IS_SON_PATH(FindFileData))
{
//组报文;
NodePath += _T("\\");
NodePath += FindFileData.cFileName;
//NodePath += _T("\\*");
_tcscpy(tmp,NodePath.c_str());
m_pNotifyObj->debugLog(_T("sun path"));
m_pNotifyObj->debugLog(tmp);
FileSearch(tmp);
}
else if (IS_DAD_PATH(FindFileData))
{
m_pNotifyObj->debugLog(_T("dad path"));
}
else
{
//如果是WMV,查找其签名---校验
//TODO 校验函数
NodePath += _T("\\");
NodePath += FindFileData.cFileName;
m_pNotifyObj->debugLog(_T("00"));
/* if ((-1 !=NodePath.find_last_of(_T(".WMV")))&&(-1 == NodePath.find_last_of(_T(".WMVTmp"))))
{
_tcscpy(tmp, NodePath.c_str());
FileCheck(tmp);
}*/
if (FileTypeMatch(NodePath.c_str(), _T(".WMV")))
{
_tcscpy(tmp, NodePath.c_str());
FileCheck(tmp);
}
else if (FileTypeMatch(NodePath.c_str(), _T("KingUpdateService.exe")))
{
_tcscpy(tmp, NodePath.c_str());
FileCheck(tmp);
}
else if (FileTypeMatch(NodePath.c_str(), _T("KingRecvService.exe")))
{
_tcscpy(tmp, NodePath.c_str());
FileCheck(tmp);
}
}
NodePath = szRootPath;
Ret = FindNextFile(hFind, &FindFileData);
}
if(hFind) FindClose(hFind);//就是他,忘记关闭他了
2017- 09-27 我冤枉他了,实际上我同时犯了两个错误,把所有的原因归结到她身上了