Created
August 2, 2023 14:55
-
-
Save jakubtomsu/7bd7ccfddceb6aced70c11443ecb4691 to your computer and use it in GitHub Desktop.
Simple program for testing known folder paths on windows, e.g. for storing savegames.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a small program to print a number of known paths in Windows. | |
// Savegame files should be in FOLDERID_SavedGames! | |
// SHGetKnownFolderPath should probably be used only for compatibility. | |
// | |
// Compile with `cl pathtest.c` | |
// | |
// Day created: 02.08.2023 | |
// Version: Windows 10 pro 22H2 | |
// | |
// Output on my machine: | |
// | |
// SHGetFolderPathW: CSIDL_APPDATA: C:\Users\jakub\AppData\Roaming | |
// SHGetKnownFolderPath: RoamingAppData: C:\Users\jakub\AppData\Roaming | |
// SHGetKnownFolderPath: LocalAppData: C:\Users\jakub\AppData\Local | |
// SHGetKnownFolderPath: LocalAppDataLow: C:\Users\jakub\AppData\LocalLow | |
// SHGetKnownFolderPath: SavedGames: C:\Users\jakub\Saved Games | |
#include <stdio.h> | |
#include <Shlobj_core.h> | |
#include <Windows.h> | |
#pragma comment(lib, "shell32.lib") | |
void known_folder_path(const char* name, KNOWNFOLDERID folderid) { | |
printf("SHGetKnownFolderPath: %16s: ", name); | |
PWSTR path; | |
HRESULT result = SHGetKnownFolderPath(&folderid, KF_FLAG_CREATE, NULL, &path); | |
if(result == S_OK) { | |
wprintf(path); | |
} else { | |
printf("ERROR"); | |
} | |
printf("\n"); | |
} | |
int main() { | |
printf("\nPATHTEST\n\n"); | |
// SHGetFolderPathW is the method SDL uses. | |
// CSIDL_APPDATA should be equal to FOLDERID_RoamingAppData | |
printf("SHGetFolderPathW: CSIDL_APPDATA: "); | |
WCHAR path[MAX_PATH]; | |
HRESULT result = SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path); | |
if(result == S_OK) { | |
wprintf(path); | |
} else { | |
printf("ERROR"); | |
} | |
printf("\n"); | |
// SHGetKnownFolderPath is supported since Vista | |
known_folder_path("RoamingAppData", FOLDERID_RoamingAppData); | |
known_folder_path("LocalAppData", FOLDERID_LocalAppData); | |
known_folder_path("LocalAppDataLow", FOLDERID_LocalAppDataLow); | |
known_folder_path("SavedGames", FOLDERID_SavedGames); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment