diff options
Diffstat (limited to 'c/common.cpp')
-rw-r--r-- | c/common.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/c/common.cpp b/c/common.cpp index 1fcff31..c7ea873 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -6,26 +6,20 @@ #include "common.h" /* Convert normal string to TSTR using given codepage. */ -TCHAR *TszFromSz(const char *sz, int iCp) +std::basic_string<TCHAR> TsmFromSz(const char *sz, int iCp) { - TCHAR *tsz; - #ifdef UNICODE int cbMultiByte, cchWideChar; cbMultiByte = strlen(sz)+1; cchWideChar = MultiByteToWideChar(iCp, 0, sz, cbMultiByte, NULL, 0); - tsz = (TCHAR *)malloc(cchWideChar*sizeof(WCHAR)); - if (!tsz) return NULL; - if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, tsz, cchWideChar)) - return NULL; + std::wstring wsm(cchWideChar, 0); + if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, wsm.data(), cchWideChar)) + throw Win32Error(GetLastError()); + return wsm; #else - tsz = malloc(strlen(sz)+1); - if (!tsz) return NULL; - strcpy(tsz, sz); + return std::string(sz); #endif - - return tsz; } Win32Error::Win32Error(DWORD dwErr) |