use BSTR length to also deal with NULs inside BSTRs correctly in Unicode build

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-02-04 08:08:57 +00:00
parent bba85010a3
commit 59af032ab6

View File

@@ -80,19 +80,21 @@ WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr)
if ( !bStr ) if ( !bStr )
return wxString(); return wxString();
const int len = SysStringLen(bStr);
#if wxUSE_UNICODE #if wxUSE_UNICODE
wxString str(bStr); wxString str(bStr, len);
#else #else
wxString str; wxString str;
const int len = SysStringLen(bStr) + 1;
if ( !::WideCharToMultiByte(CP_ACP, 0 /* no flags */, if ( !::WideCharToMultiByte(CP_ACP, 0 /* no flags */,
bStr, len, bStr, len + 1 /* include last NUL */,
wxStringBuffer(str, len), len, wxStringBuffer(str, len), len,
NULL, NULL /* no default char */) ) NULL, NULL /* no default char */) )
{ {
str.clear(); str.clear();
} }
#endif #endif
return str; return str;
} }