Created
November 23, 2020 19:09
-
-
Save abel0b/0b740648d6370e3e77fd70a816a34523 to your computer and use it in GitHub Desktop.
Get AppData Roaming folder in C C++
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
// how to locate application data %AppData% directory path on Windows 10 MSVC | |
// see on documentation https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath?redirectedfrom=MSDN | |
// compiled with cl .\appdata.c Shell32.lib | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <shlobj_core.h> | |
#include <direct.h> | |
int main() { | |
// KF_FLAG_CREATE force folder creation if not exists | |
PWSTR appdata = NULL; | |
if (SHGetKnownFolderPath(&FOLDERID_RoamingAppData, KF_FLAG_CREATE, NULL, &appdata) == S_OK) { | |
char dest[MAX_PATH]; | |
wcstombs(dest, appdata, MAX_PATH); | |
printf("appdata path is %s\n", dest); | |
} | |
else { | |
fprintf(stderr, "error getting appdata path\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment