Created
August 21, 2016 20:12
-
-
Save DreamVB/a67a75e001d33a836264d02360910f5b to your computer and use it in GitHub Desktop.
Get special folder locations
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
| #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