if ( !bStr )
return wxString();
+ const int len = SysStringLen(bStr);
+
#if wxUSE_UNICODE
- wxString str(bStr);
+ wxString str(bStr, len);
#else
wxString str;
- const int len = SysStringLen(bStr) + 1;
- if ( !::WideCharToMultiByte(CP_ACP, 0 /* no flags */,
- bStr, len,
- wxStringBuffer(str, len), len,
- NULL, NULL /* no default char */) )
+ if (len)
{
- str.clear();
+ wxStringBufferLength buf(str, len); // asserts if len == 0
+ buf.SetLength(WideCharToMultiByte(CP_ACP, 0 /* no flags */,
+ bStr, len /* not necessarily NUL-terminated */,
+ buf, len,
+ NULL, NULL /* no default char */));
}
#endif
+
return str;
}