hhctrl.ocx: Declare strdupAtoW in hhctrl.h and use it instead of duplicated *ANSIToUnicode.
This commit is contained in:
parent
6e72b2614a
commit
9a20d35cc8
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue