Approach 1:
 #include <Shlobj.h> std::string desktop_directory(bool path_w) { if (path_w == true) { WCHAR path[MAX_PATH + 1]; if (SHGetSpecialFolderPathW(HWND_DESKTOP, path, CSIDL_DESKTOPDIRECTORY, FALSE)) { std::wstring ws(path); std::string str(ws.begin(), ws.end()); return str; } else return NULL; } } 
Approach 2:
 #include <Shlobj.h> LPSTR desktop_directory() { static char path[MAX_PATH + 1]; if (SHGetSpecialFolderPathA(HWND_DESKTOP, path, CSIDL_DESKTOPDIRECTORY, FALSE)) return path; else return NULL; }