[PATCH] Add undocumented function to unify MultiByteToWideChar conversation

Alexey Fisher bug-track at fisher-privat.net
Thu Apr 28 01:45:21 CDT 2011


MultiByteToWideChar are called directly only from one function. All other
colls in comctl32 go thrue this function.
It was recovered with from dissassambled code.

Signed-off-by: Alexey Fisher <bug-track at fisher-privat.net>
---
 dlls/comctl32/comctl32undoc.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c
index ff94051..6eb6c0f 100644
--- a/dlls/comctl32/comctl32undoc.c
+++ b/dlls/comctl32/comctl32undoc.c
@@ -560,6 +560,47 @@ INT WINAPI AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
 }
 
 /**************************************************************************
+ *            comctl_MultiByteToWideChar (internal)
+ * Convert Multibyte string to WideChar string.
+ *
+ * PARAMS
+ *    CodePage [I] COdepage of lpMultiByteStr
+ *    lpMultiByteStr [I] multibyte string
+ *
+ * RETURNS
+ *    Pointer to lpWideCharStr [O] or NULL if failed. Do not forget to
+ *    Free the lpWideCharStr after use!
+ */
+LPWSTR comctl_MultiByteToWideChar(UINT CodePage, LPCSTR lpMultiByteStr)
+{
+    LPWSTR lpWideCharStr;
+    int len;
+
+    if (lpMultiByteStr == NULL || lpMultiByteStr == -1)
+        return NULL;
+
+    if (IsBadReadPtr(lpMultiByteStr, 1))
+        return NULL;
+
+    len = MultiByteToWideChar(CodePage, NULL, lpMultiByteStr, -1, NULL, NULL);
+    if (!len)
+        len = 1;
+
+    lpWideCharStr = LocalAlloc(len * sizeof(WCHAR), 0);
+    if (!lpWideCharStr)
+         return NULL;
+
+    if (!MultiByteToWideChar(CodePage, 1, lpMultiByteStr, -1,
+                             lpWideCharStr, len)) {
+        LocalFree(lpWideCharStr);
+        lpWideCharStr = NULL;
+        return NULL;
+    }
+
+    return lpWideCharStr;
+}
+
+/**************************************************************************
  *              AddMRUStringA [COMCTL32.153]
  *
  * See AddMRUStringW.
-- 
1.7.4.1




More information about the wine-devel mailing list