Need a project done?

C++ Programming Developer

Search This Blog

Get Desktop Path Dynamically in C++

This program automatically finds the path of desktop in C++.
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <tchar.h>
#include <shlobj.h> // for SHGetFolderPath

using namespace std;

int main(int argc, _TCHAR* argv[])
TCHAR path[_MAX_PATH] = _T(""); // must be _MAX_PATH in size

HRESULT hr = SHGetFolderPath(NULL, // no parent window
0,    // no flags
NULL, // no tokens

if (SUCCEEDED(hr)) {
#ifdef _UNICODE
wcout << L"Desktop path = " << path << endl;
cout << "Desktop path = " << path << endl;
"Don't let anyone ever make you feel like you don't deserve what you want."