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('\\'));

 


SetCurrentDirectory 导致的崩溃问题

相关文章:

  • 2021-09-10
  • 2021-05-12
  • 2021-08-28
  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-04-16
  • 2021-10-18
相关资源
相似解决方案