GetModuleFileNameA()与GetCurrentDirectoryA()

头文件: #include <windows.h>

GetModuleFileNameA()
char moduleFileName[MAX_PATH];     
GetModuleFileNameA(0, moduleFileName, MAX_PATH);

取得的路径为:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\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 2010\Projects 
\Test\debug\

 

GetCurrentDirectoryA()
char result[MAX_PATH];     
GetCurrentDirectoryA(MAX_PATH, result);

取得的路径为:c:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects 
\Test\Test 

posted @ 2014-07-23 16:18  紫清婷  阅读(1909)  评论(0编辑  收藏  举报