From 9a20d35cc8952a120ae146fbe35c23d0bc0580eb Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 22 Feb 2007 22:47:21 +0100 Subject: [PATCH] hhctrl.ocx: Declare strdupAtoW in hhctrl.h and use it instead of duplicated *ANSIToUnicode. --- dlls/hhctrl.ocx/chm.c | 14 +------------- dlls/hhctrl.ocx/help.c | 14 +------------- dlls/hhctrl.ocx/hhctrl.h | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c index c59fd71f9e7..3e105b04e31 100644 --- a/dlls/hhctrl.ocx/chm.c +++ b/dlls/hhctrl.ocx/chm.c @@ -20,18 +20,6 @@ #include "hhctrl.h" -static LPWSTR CHM_ANSIToUnicode(LPCSTR ansi) -{ - LPWSTR unicode; - int count; - - count = MultiByteToWideChar(CP_ACP, 0, ansi, -1, NULL, 0); - unicode = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, ansi, -1, unicode, count); - - return unicode; -} - /* Reads a string from the #STRINGS section in the CHM file */ static LPWSTR CHM_ReadString(CHMInfo *pChmInfo, DWORD dwOffset) { @@ -70,7 +58,7 @@ static LPWSTR CHM_ReadString(CHMInfo *pChmInfo, DWORD dwOffset) { if (!szString[iPos]) { - stringW = CHM_ANSIToUnicode(szString); + stringW = strdupAtoW(szString); HeapFree(GetProcessHeap(), 0, szString); return stringW; } diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c index beb62856083..39d750bddd2 100644 --- a/dlls/hhctrl.ocx/help.c +++ b/dlls/hhctrl.ocx/help.c @@ -57,18 +57,6 @@ typedef struct tagHHInfo extern HINSTANCE hhctrl_hinstance; -static LPWSTR HH_ANSIToUnicode(LPCSTR ansi) -{ - LPWSTR unicode; - int count; - - count = MultiByteToWideChar(CP_ACP, 0, ansi, -1, NULL, 0); - unicode = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, ansi, -1, unicode, count); - - return unicode; -} - /* Loads a string from the resource file */ static LPWSTR HH_LoadString(DWORD dwID) { @@ -861,7 +849,7 @@ int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine) if (FAILED(OleInitialize(NULL))) return -1; - pHHInfo = HH_OpenHH(hInstance, HH_ANSIToUnicode(szCmdLine)); + pHHInfo = HH_OpenHH(hInstance, strdupAtoW(szCmdLine)); if (!pHHInfo || !HH_OpenCHM(pHHInfo) || !HH_CreateViewer(pHHInfo)) { OleUninitialize(); diff --git a/dlls/hhctrl.ocx/hhctrl.h b/dlls/hhctrl.ocx/hhctrl.h index 17e5ac8ce5d..367564b0ed6 100644 --- a/dlls/hhctrl.ocx/hhctrl.h +++ b/dlls/hhctrl.ocx/hhctrl.h @@ -70,4 +70,19 @@ BOOL CHM_OpenCHM(CHMInfo *pCHMInfo, LPCWSTR szFile); BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType); void CHM_CloseCHM(CHMInfo *pCHMInfo); +static inline LPWSTR strdupAtoW(LPCSTR str) +{ + LPWSTR ret; + DWORD len; + + if(!str) + return NULL; + + len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len); + + return ret; +} + #endif