Writing to a C ++ user document folder

I am trying to write some information to a user documents folder (for example, C: \ Documents and Settings \ [username]), but I cannot figure out how to get the program path. Is there any way to do this? C ++ without using .NET.

Thanks!

+6
c ++ windows winapi
source share
2 answers

SHGetFolderPath with CSIDL_PERSONAL can be used to get the User Documents folder.

WCHAR path[MAX_PATH]; HRESULT hr = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path); 
+16
source share

You can do it:

 wchar_t *pUSERPROFILE; size_t len; _wdupenv_s( &pUSERPROFILE, &len, L"USERPROFILE" ); wstring userprofile = pUSERPROFILE; free (pUSERPROFILE); 

_ wdupenv_s MSDN

-2
source share

All Articles