SHGetFolderPath
Posted
by
user530589
on Stack Overflow
See other posts from Stack Overflow
or by user530589
Published on 2012-04-08T10:30:17Z
Indexed on
2012/04/08
11:29 UTC
Read the original article
Hit count: 166
winapi
|visual-c++
This code works for windows 7 but doesn't work for windows XP (outputs only part of startup folder path)
#include <iostream>
#include <shlobj.h>
using namespace std;
int main()
{
wchar_t startupFolder[1024];
HRESULT hr = SHGetFolderPath(0, CSIDL_STARTUP, 0, 0, startupFolder);
if (SUCCEEDED(hr))
wcout << L"Startup folder = " << startupFolder << endl;
else
cout << "Error when getting startup folder\n";
getchar();
return 0;
}
output is: Startup folder = C:\Documents and Settings\Admin\ <- cursor is here. Newline is not provided. Also I have russian window xp. I think this is unicode issue.
when I use wprintf I got: C:\Documents and Settings\Admin\???????? .....
Thanks.
As a temporary solution: After SHGetFolderPath I call GetShortPathName then I get path in msdos style: C:\DOCUME~1\Admin\5D29~1\4A66~1\60C2~1 Not really beautiful solution, but at least that is a valid path.
© Stack Overflow or respective owner