c++ - MS Windows 中的应用程序路径位置

标签 c++ windows path

我应该将应用程序安装文件夹存储在哪里以供应用程序引用?

最佳答案

我相信您正在寻找的是 GetModuleFileName函数,您可以像这样使用它:

// get the full path to the current executable
wchar_t fullPath[MAX_PATH];
GetModuleFileName(NULL, fullPath, MAX_PATH);

// cut the string at the last slash, because we just want the directory
// not the actual executeable file name. 
TCHAR *lastSlash = wcsrchr(fullPath, L'\\');
lastSlash = 0;

// directory where the executable is location is fullPath

无论当前工作目录如何,这都有效,一般来说,这就是我做所有“相对路径”事情的方式(也就是说,我从来没有真正使用相对路径,它们总是绝对的路径,基于从上述函数返回的值)。

关于c++ - MS Windows 中的应用程序路径位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3200651/

相关文章:

c++ - C++中 "resizing"数组访问冲突

java - 在Java中,如何实现像文件资源管理器这样的东西?

Windows Server 2008 r2 - 无法让 apache 在端口 80 上运行

c# - 用于将数据与文件系统路径相关联的高效数据结构?

c++ - 如何找到 BFS 找到的实际路径?

c++ - 实现线程间同步屏障的最佳方法是什么

c++ - C++ 中的作用域指针是什么?

c++ - 在 A 类中引用 A 类的其他实例

windows - 如何从 WSL(Linux 的 Windows 子系统)访问 aws 配置文件?

c# - 如何避免包含文件的完整路径