comparison src/helper.cpp @ 17:78baaad4a001

Further check in char conversion
author Chris Cannam
date Fri, 28 Oct 2016 14:32:30 +0100
parents 51229bd6c24b
children 7eff522b23ae
comparison
equal deleted inserted replaced
16:51229bd6c24b 17:78baaad4a001
83 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 83 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
84 (LPTSTR) &buffer, 84 (LPTSTR) &buffer,
85 0, NULL ); 85 0, NULL );
86 int wn = wcslen(buffer); 86 int wn = wcslen(buffer);
87 int n = WideCharToMultiByte(CP_UTF8, 0, buffer, wn, 0, 0, 0, 0); 87 int n = WideCharToMultiByte(CP_UTF8, 0, buffer, wn, 0, 0, 0, 0);
88 if (n < 0) {
89 LocalFree(&buffer);
90 return "Unable to convert error string (internal error)";
91 }
88 char *text = new char[n+1]; 92 char *text = new char[n+1];
89 n = WideCharToMultiByte(CP_UTF8, 0, buffer, wn, text, n, 0, 0); 93 (void)WideCharToMultiByte(CP_UTF8, 0, buffer, wn, text, n, 0, 0);
90 text[n] = '\0'; 94 text[n] = '\0';
91 std::string s(text); 95 std::string s(text);
92 LocalFree(&buffer); 96 LocalFree(&buffer);
93 delete[] text; 97 delete[] text;
94 for (int i = s.size(); i > 0; ) { 98 for (int i = s.size(); i > 0; ) {