X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a518e5080d824422b592e95fb4a9f958b1cd0724..bd84061db32633592490da273570b8d78215c6c3:/src/msw/ole/oleutils.cpp diff --git a/src/msw/ole/oleutils.cpp b/src/msw/ole/oleutils.cpp index 1c37542f38..59f387426c 100644 --- a/src/msw/ole/oleutils.cpp +++ b/src/msw/ole/oleutils.cpp @@ -75,15 +75,26 @@ WXDLLEXPORT BSTR wxConvertStringToOle(const wxString& str) WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr) { + // NULL BSTR is equivalent to an empty string (this is the convention used + // by VB and hence we must follow it) + if ( !bStr ) + return wxString(); + + const int len = SysStringLen(bStr); + #if wxUSE_UNICODE - wxString str(bStr); + wxString str(bStr, len); #else - int len = SysStringLen(bStr) + 1; - char *buf = new char[len]; - (void)wcstombs( buf, bStr, len); - wxString str(buf); - delete[] buf; + wxString str; + if ( !::WideCharToMultiByte(CP_ACP, 0 /* no flags */, + bStr, len /* not necessary NUL-terminated */, + wxStringBuffer(str, len + 1), len + 1, + NULL, NULL /* no default char */) ) + { + str.clear(); + } #endif + return str; }