Writing to user documents folder C++

前端 未结 2 1767
时光说笑
时光说笑 2021-01-13 00:57

I\'m trying to write some info to the user\'s documents folder (eg. C:\\Documents and Settings\\[userName]), but I can\'t seem to find out how to grab the path programmatica

相关标签:
2条回答
  • 2021-01-13 01:31

    SHGetFolderPath with CSIDL_PERSONAL can be used to get the user's Documents folder.

    WCHAR path[MAX_PATH];
    HRESULT hr = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL,
                                 SHGFP_TYPE_CURRENT, path);
    
    0 讨论(0)
  • 2021-01-13 01:49

    You could do this :

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

    _wdupenv_s MSDN

    0 讨论(0)
提交回复
热议问题