X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bba85010a3d174d43c82c1450b72d744baefafd6..763163a80ae0d5a0684633e72f928302578c1214:/src/msw/ole/oleutils.cpp diff --git a/src/msw/ole/oleutils.cpp b/src/msw/ole/oleutils.cpp index c596c2bc1c..94f134a097 100644 --- a/src/msw/ole/oleutils.cpp +++ b/src/msw/ole/oleutils.cpp @@ -80,19 +80,22 @@ WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr) 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; }