我应该将应用程序安装文件夹存储在哪里以供应用程序引用?
最佳答案
我相信您正在寻找的是 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/