1.程序設置成開機啓動,通過註冊表啓動,導致程序崩潰;
分析是日誌這塊出問題了:
分析:是log4cppLIB庫中,FileAppender 打開相對路徑的日誌文件,失敗導致的。寫文件的時候程序崩潰的問題;
原因:
std::string strConfigFile;
std::string strLogPath;
TCHAR szModuleFileName[BUFSIZE] = { 0 };
TCHAR szCurrentDir[BUFSIZE] = { 0 };
::GetModuleFileName(NULL, szModuleFileName, 1024);
::PathRemoveExtension(szModuleFileName); //
::SetCurrentDirectory(szModuleFileName);
::GetCurrentDirectory(BUFSIZE, szCurrentDir);
獲取的GetCurrentDirectory路徑是:C:\Windows\System32 路徑,不是程序的路徑導致的;
本質原因是::SetCurrentDirectory的路徑是有問題的;
採用如下的方法:分解路徑,在設置當前路徑,纔可以;
strConfigFile.assign(szModuleFileName);
strConfigFile = strConfigFile.substr(0, strConfigFile.find_last_of('\\'));