.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");
本文介绍了几种在Windows环境下获取路径的方法,包括获取当前模块文件名(GetModuleFileName)、获取当前工作目录(_getcwd)以及从命令行参数中提取路径(GetCommandLine)等。通过这些方法可以方便地在应用程序中使用文件和目录。
2876

被折叠的 条评论
为什么被折叠?



