GetModuleFileNameA函數與GetCurrentDirectoryA函數
阿新 • • 發佈:2017-10-13
debug log tools string last tor cts 代碼 ast
C++代碼
cited from: http://cooker.iteye.com/blog/657706
頭文件#include <windows.h>
C++代碼
- char moduleFileName[MAX_PATH];
- GetModuleFileNameA(0, moduleFileName, MAX_PATH);
取得的路徑為:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects
\Test\debug\Test.exe
- char moduleFileName[MAX_PATH];
- GetModuleFileNameA(NULL, moduleFileName, MAX_PATH);
- std::string workingFolder(moduleFileName);
- size_t pos = workingFolder.find_last_of("\\");
- workingFolder = workingFolder.substr(0, pos+1);
- std::cout<<workingFolder<<std::endl;
取得的路徑為:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects
\Test\debug\
- char result[MAX_PATH];
- GetCurrentDirectoryA(MAX_PATH, result);
取得的路徑為:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects
\Test\Test
GetModuleFileNameA函數與GetCurrentDirectoryA函數