How do I convert PWSTR to string in C++?

前端 未结 5 853
南笙
南笙 2020-12-11 04:41

I have the following code:

// Fetch Local App Data folder path.
PWSTR localAppData = (PWSTR) malloc(128);
SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 05:19

    If you don't like widechar and want ansi string badly, try wcstombs or WideCharToMultiByte.

    To call SHGetKnownFolderPath, you don't need to allocate memory by yourself, it will cause memory leak.

提交回复
热议问题