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

来源:互联网 发布:小超市销售软件 编辑:程序博客网 时间:2024/06/08 15:28

 

.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");

原创粉丝点击