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
CSIDL_DESKTOP,
0,    // no flags
NULL, // no tokens
path);

if (SUCCEEDED(hr)) {
#ifdef _UNICODE
wcout << L"Desktop path = " << path << endl;
#else
cout << "Desktop path = " << path << endl;
#endif
}
}

1 comment:

  1. How can I turn this path into a variable like a string?

    ReplyDelete

"Don't let anyone ever make you feel like you don't deserve what you want."