]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/ole/oleutils.cpp
added (wxMSW-only) wxToolTip::SetMaxWidth() and improve its default behaviour (#2817)
[wxWidgets.git] / src / msw / ole / oleutils.cpp
index 8fbcf998855b1d38a7e678c6fb72290a24187300..94f134a097af38981513e4182471ff32c946d50f 100644 (file)
@@ -80,15 +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
-    int len = SysStringLen(bStr) + 1;
-    char    *buf = new char[len];
-    (void)wcstombs( buf, bStr, len);
-    wxString str(buf);
-    delete[] buf;
+    wxString str;
+    if (len)
+    {
+        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;
 }