我正在写一个游戏。我计划将保存存储在“保存的游戏”目录中。
如何以编程方式查找“已保存游戏”文件夹的位置?
它需要在非英语 Windows 上运行。黑客喜欢%USERPROFILE%\Saved Games
不是一个选择。
保存的游戏目录可以通过SHGetKnownFolderPath() https://learn.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath功能,自 Windows Vista 和 Windows Server 2008 起可用。
请注意,FOLDERID_SavedGames
argument 是一个 C++ 参考。用。。。来代替&FOLDERID_SavedGames
从 C 代码调用。
在我能找到的第一个在线 MSVC 编译器上测试成功:
https://rextester.com/l/cpp_online_compiler_visual https://rextester.com/l/cpp_online_compiler_visual
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <stdio.h>
#include <shlobj.h>
#include <objbase.h>
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "ole32.lib")
int main(void)
{
PWSTR path = NULL;
HRESULT r;
r = SHGetKnownFolderPath(FOLDERID_SavedGames, KF_FLAG_CREATE, NULL, &path);
if (path != NULL)
{
printf("%ls", path);
CoTaskMemFree(path);
}
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)