1. 程式人生 > >GetModuleFileNameA函數與GetCurrentDirectoryA函數

GetModuleFileNameA函數與GetCurrentDirectoryA函數

debug log tools string last tor cts 代碼 ast

cited from: http://cooker.iteye.com/blog/657706

頭文件#include <windows.h>

C++代碼 技術分享
  1. char moduleFileName[MAX_PATH];
  2. GetModuleFileNameA(0, moduleFileName, MAX_PATH);

取得的路徑為:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects
\Test\debug\Test.exe

C++代碼 技術分享
  1. char moduleFileName[MAX_PATH];
  2. GetModuleFileNameA(NULL, moduleFileName, MAX_PATH);
  3. std::string workingFolder(moduleFileName);
  4. size_t pos = workingFolder.find_last_of("\\");
  5. workingFolder = workingFolder.substr(0, pos+1);
  6. std::cout<<workingFolder<<std::endl;

取得的路徑為:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects
\Test\debug\

C++代碼 技術分享
  1. char result[MAX_PATH];
  2. GetCurrentDirectoryA(MAX_PATH, result);

取得的路徑為:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects
\Test\Test

GetModuleFileNameA函數與GetCurrentDirectoryA函數