SetCurrentDirectory 导致的崩溃问题

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 导致的崩溃问题