diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2013-05-27 03:55:14 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2013-05-27 03:55:14 (GMT) |
commit | 6742ad55f4cf335fc767ab65784aab81e06b61d0 (patch) | |
tree | 53bf1b3661a8d0d894487d20906b26e498158649 /src/PlatformUtils-win.cc | |
parent | 53e778af703e40e91c2021d4ab12f8d30e14bd60 (diff) |
fix buggy string init. remove debug string
Diffstat (limited to 'src/PlatformUtils-win.cc')
-rw-r--r-- | src/PlatformUtils-win.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/PlatformUtils-win.cc b/src/PlatformUtils-win.cc index a314ebe..a58a346 100644 --- a/src/PlatformUtils-win.cc +++ b/src/PlatformUtils-win.cc @@ -9,8 +9,6 @@ // convert from windows api w_char strings (usually utf16) to utf8 std::string std::string winapi_wstr_to_utf8( std::wstring wstr ) { - std::string utf8_str(""); - UINT CodePage = CP_UTF8; DWORD dwFlags = 0; LPCWSTR lpWideCharStr = &wstr[0]; @@ -23,6 +21,9 @@ std::string winapi_wstr_to_utf8( std::wstring wstr ) int numbytes = WideCharToMultiByte( CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar ); + //PRINTB("utf16 to utf8 conversion: numbytes %i",numbytes); + + std::string utf8_str(numbytes,0); lpMultiByteStr = &utf8_str[0]; cbMultiByte = numbytes; @@ -48,12 +49,19 @@ std::string PlatformUtils::documentsPath() std::string retval; std::wstring path(MAX_PATH,0); - HRESULT result = SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, - SHGFP_TYPE_CURRENT, &path[0]); + HWND hwndOwner = 0; + int nFolder = CSIDL_PERSONAL; + HANDLE hToken = NULL; + DWORD dwFlags = SHGFP_TYPE_CURRENT; + LPTSTR pszPath = &path[0]; + + int result = SHGetFolderPathW( hwndOwner, nFolder, hToken, dwFlags, pszPath ); if (result == S_OK) { path = std::wstring( path.c_str() ); // stip extra NULLs + //std::wcerr << "wchar path:" << "\n"; retval = winapi_wstr_to_utf8( path ); + //PRINTB("Path found: %s",retval); } else { PRINT("ERROR: Could not find My Documents location"); retval = ""; |