获取程序运行路径的几种方法

 

.GetModuleFileName()

 char path[255];
 GetModuleFileName(AfxGetInstanceHandle(),   path,   MAX_PATH-1);

 

. _getcwd

#include <direct.h>

char path[255];
 _getcwd(path,255);

.GetCommandLine

#include "Shlwapi.h"
 LPSTR path = ::GetCommandLine(); 

PathRemoveArgs(path);   //Path.RemoveArgs();
 PathUnquoteSpaces(path);  //Path.UnquoteSpaces();
 PathRemoveFileSpec(path);  //Path.RemoveFileSpec();
 PathAppend(path,"test.ini");

你可能感兴趣的:(Path)