Skip to content

Instantly share code, notes, and snippets.

@DreamVB
Created August 21, 2016 20:12
Show Gist options
  • Select an option

  • Save DreamVB/a67a75e001d33a836264d02360910f5b to your computer and use it in GitHub Desktop.

Select an option

Save DreamVB/a67a75e001d33a836264d02360910f5b to your computer and use it in GitHub Desktop.
Get special folder locations
#include <iostream>
#include <ShlObj.h>
//Get Special Folders ~By DreammVB~
//Example of returning special folder locations.
using namespace std;
using std::cout;
using std::endl;
string GetSpecialFolder(int ID){
static wchar_t path[MAX_PATH+1];
HRESULT hr = 0;
hr = SHGetFolderPath(HWND_DESKTOP,ID,NULL,0,path);
if(hr != 0){return "";}
//Convert wide string to string
wstring ws(path);
//Retuurn string
return string(ws.begin(),ws.end());
}
int main(int argc, char **anvg){
cout << "AppData : " << GetSpecialFolder(CSIDL_APPDATA).c_str() << endl;
cout << "Cookies : " << GetSpecialFolder(CSIDL_COOKIES).c_str() << endl;
cout << "Windows : " << GetSpecialFolder(CSIDL_WINDOWS).c_str() << endl;
cout << "Desktop : " << GetSpecialFolder(CSIDL_DESKTOP).c_str() << endl;
//Keep console open
system("pause");
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment