hhctrl.ocx: Store a copy of the string pointers to enable freeing them without casting away const.

This commit is contained in:
Alexandre Julliard 2007-12-13 13:48:00 +01:00
parent 9642714d06
commit 7293f00d9d
3 changed files with 40 additions and 27 deletions

View file

@ -200,10 +200,10 @@ LPWSTR FindContextAlias(CHMInfo *chm, DWORD index)
* FIXME: There may be more than one window type in the file, so * FIXME: There may be more than one window type in the file, so
* add the ability to choose a certain window type * add the ability to choose a certain window type
*/ */
BOOL LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType) BOOL LoadWinTypeFromCHM(HHInfo *info)
{ {
LARGE_INTEGER liOffset; LARGE_INTEGER liOffset;
IStorage *pStorage = pChmInfo->pStorage; IStorage *pStorage = info->pCHMInfo->pStorage;
IStream *pStream; IStream *pStream;
HRESULT hr; HRESULT hr;
DWORD cbRead; DWORD cbRead;
@ -221,26 +221,26 @@ BOOL LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType)
if (FAILED(hr)) goto done; if (FAILED(hr)) goto done;
/* read the HH_WINTYPE struct data */ /* read the HH_WINTYPE struct data */
hr = IStream_Read(pStream, pHHWinType, sizeof(*pHHWinType), &cbRead); hr = IStream_Read(pStream, &info->WinType, sizeof(info->WinType), &cbRead);
if (FAILED(hr)) goto done; if (FAILED(hr)) goto done;
/* convert the #STRINGS offsets to actual strings */ /* convert the #STRINGS offsets to actual strings */
pHHWinType->pszType = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszType)); info->WinType.pszType = info->pszType = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszType));
pHHWinType->pszCaption = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszCaption)); info->WinType.pszCaption = info->pszCaption = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszCaption));
pHHWinType->pszToc = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszToc)); info->WinType.pszToc = info->pszToc = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszToc));
pHHWinType->pszIndex = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszIndex)); info->WinType.pszIndex = info->pszIndex = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszIndex));
pHHWinType->pszFile = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszFile)); info->WinType.pszFile = info->pszFile = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszFile));
pHHWinType->pszHome = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszHome)); info->WinType.pszHome = info->pszHome = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszHome));
pHHWinType->pszJump1 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszJump1)); info->WinType.pszJump1 = info->pszJump1 = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszJump1));
pHHWinType->pszJump2 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszJump2)); info->WinType.pszJump2 = info->pszJump2 = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszJump2));
pHHWinType->pszUrlJump1 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszUrlJump1)); info->WinType.pszUrlJump1 = info->pszUrlJump1 = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszUrlJump1));
pHHWinType->pszUrlJump2 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszUrlJump2)); info->WinType.pszUrlJump2 = info->pszUrlJump2 = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszUrlJump2));
/* FIXME: pszCustomTabs is a list of multiple zero-terminated strings so ReadString won't /* FIXME: pszCustomTabs is a list of multiple zero-terminated strings so ReadString won't
* work in this case * work in this case
*/ */
#if 0 #if 0
pHHWinType->pszCustomTabs = CHM_ReadString(pChmInfo, (DWORD)pHHWinType->pszCustomTabs); info->WinType.pszCustomTabs = info->pszCustomTabs = CHM_ReadString(pChmInfo, (DWORD_PTR)info->WinType.pszCustomTabs);
#endif #endif
done: done:

View file

@ -922,16 +922,16 @@ void ReleaseHelpViewer(HHInfo *info)
return; return;
/* Free allocated strings */ /* Free allocated strings */
heap_free((LPWSTR)info->WinType.pszType); heap_free(info->pszType);
heap_free((LPWSTR)info->WinType.pszCaption); heap_free(info->pszCaption);
heap_free((LPWSTR)info->WinType.pszToc); heap_free(info->pszToc);
heap_free((LPWSTR)info->WinType.pszIndex); heap_free(info->pszIndex);
heap_free((LPWSTR)info->WinType.pszFile); heap_free(info->pszFile);
heap_free((LPWSTR)info->WinType.pszHome); heap_free(info->pszHome);
heap_free((LPWSTR)info->WinType.pszJump1); heap_free(info->pszJump1);
heap_free((LPWSTR)info->WinType.pszJump2); heap_free(info->pszJump2);
heap_free((LPWSTR)info->WinType.pszUrlJump1); heap_free(info->pszUrlJump1);
heap_free((LPWSTR)info->WinType.pszUrlJump2); heap_free(info->pszUrlJump2);
if (info->pCHMInfo) if (info->pCHMInfo)
CloseCHM(info->pCHMInfo); CloseCHM(info->pCHMInfo);
@ -958,7 +958,7 @@ HHInfo *CreateHelpViewer(LPCWSTR filename)
return NULL; return NULL;
} }
if (!LoadWinTypeFromCHM(info->pCHMInfo, &info->WinType)) { if (!LoadWinTypeFromCHM(info)) {
ReleaseHelpViewer(info); ReleaseHelpViewer(info);
return NULL; return NULL;
} }

View file

@ -92,6 +92,19 @@ typedef struct {
IOleObject *wb_object; IOleObject *wb_object;
HH_WINTYPEW WinType; HH_WINTYPEW WinType;
LPWSTR pszType;
LPWSTR pszCaption;
LPWSTR pszToc;
LPWSTR pszIndex;
LPWSTR pszFile;
LPWSTR pszHome;
LPWSTR pszJump1;
LPWSTR pszJump2;
LPWSTR pszUrlJump1;
LPWSTR pszUrlJump2;
LPWSTR pszCustomTabs;
CHMInfo *pCHMInfo; CHMInfo *pCHMInfo;
ContentItem *content; ContentItem *content;
HWND hwndTabCtrl; HWND hwndTabCtrl;
@ -111,7 +124,7 @@ void InitContent(HHInfo*);
void ReleaseContent(HHInfo*); void ReleaseContent(HHInfo*);
CHMInfo *OpenCHM(LPCWSTR szFile); CHMInfo *OpenCHM(LPCWSTR szFile);
BOOL LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType); BOOL LoadWinTypeFromCHM(HHInfo *info);
CHMInfo *CloseCHM(CHMInfo *pCHMInfo); CHMInfo *CloseCHM(CHMInfo *pCHMInfo);
void SetChmPath(ChmPath*,LPCWSTR,LPCWSTR); void SetChmPath(ChmPath*,LPCWSTR,LPCWSTR);
IStream *GetChmStream(CHMInfo*,LPCWSTR,ChmPath*); IStream *GetChmStream(CHMInfo*,LPCWSTR,ChmPath*);