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
}
}
#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
}
}
How can I turn this path into a variable like a string?
ReplyDelete