From bba85010a3d174d43c82c1450b72d744baefafd6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 4 Feb 2008 08:04:39 +0000 Subject: [PATCH] use WideCharToMultiByte() instead of wcstombs() to deal with BSTRs containing NULs (modified patch 1886062) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/ole/oleutils.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/msw/ole/oleutils.cpp b/src/msw/ole/oleutils.cpp index 8fbcf99885..c596c2bc1c 100644 --- a/src/msw/ole/oleutils.cpp +++ b/src/msw/ole/oleutils.cpp @@ -83,11 +83,15 @@ WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr) #if wxUSE_UNICODE wxString str(bStr); #else - int len = SysStringLen(bStr) + 1; - char *buf = new char[len]; - (void)wcstombs( buf, bStr, len); - wxString str(buf); - delete[] buf; + 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 */) ) + { + str.clear(); + } #endif return str; } -- 2.45.2