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

Alexandre Julliard julliard at winehq.org
Thu Dec 13 08:23:15 CST 2007


Module: wine
Branch: master
Commit: 7293f00d9dccf1411ed84817755c6378377bbc33
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7293f00d9dccf1411ed84817755c6378377bbc33

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Dec 13 13:48:00 2007 +0100

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

---

 dlls/hhctrl.ocx/chm.c    |   30 +++++++++++++++---------------
 dlls/hhctrl.ocx/help.c   |   22 +++++++++++-----------
 dlls/hhctrl.ocx/hhctrl.h |   15 ++++++++++++++-
 3 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c
index 1c18240..013cb7d 100644
--- a/dlls/hhctrl.ocx/chm.c
+++ b/dlls/hhctrl.ocx/chm.c
@@ -200,10 +200,10 @@ LPWSTR FindContextAlias(CHMInfo *chm, DWORD index)
  * FIXME: There may be more than one window type in the file, so
  *        add the ability to choose a certain window type
  */
-BOOL LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType)
+BOOL LoadWinTypeFromCHM(HHInfo *info)
 {
     LARGE_INTEGER liOffset;
-    IStorage *pStorage = pChmInfo->pStorage;
+    IStorage *pStorage = info->pCHMInfo->pStorage;
     IStream *pStream;
     HRESULT hr;
     DWORD cbRead;
@@ -221,26 +221,26 @@ BOOL LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType)
     if (FAILED(hr)) goto done;
 
     /* 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;
 
     /* convert the #STRINGS offsets to actual strings */
-    pHHWinType->pszType = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszType));
-    pHHWinType->pszCaption = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszCaption));
-    pHHWinType->pszToc = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszToc));
-    pHHWinType->pszIndex = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszIndex));
-    pHHWinType->pszFile = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszFile));
-    pHHWinType->pszHome = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszHome));
-    pHHWinType->pszJump1 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszJump1));
-    pHHWinType->pszJump2 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszJump2));
-    pHHWinType->pszUrlJump1 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszUrlJump1));
-    pHHWinType->pszUrlJump2 = strdupAtoW(GetChmString(pChmInfo, (DWORD)pHHWinType->pszUrlJump2));
-    
+    info->WinType.pszType     = info->pszType     = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszType));
+    info->WinType.pszCaption  = info->pszCaption  = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszCaption));
+    info->WinType.pszToc      = info->pszToc      = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszToc));
+    info->WinType.pszIndex    = info->pszIndex    = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszIndex));
+    info->WinType.pszFile     = info->pszFile     = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszFile));
+    info->WinType.pszHome     = info->pszHome     = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszHome));
+    info->WinType.pszJump1    = info->pszJump1    = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszJump1));
+    info->WinType.pszJump2    = info->pszJump2    = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszJump2));
+    info->WinType.pszUrlJump1 = info->pszUrlJump1 = strdupAtoW(GetChmString(info->pCHMInfo, (DWORD_PTR)info->WinType.pszUrlJump1));
+    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
      * work in this case
      */
 #if 0
-    pHHWinType->pszCustomTabs = CHM_ReadString(pChmInfo, (DWORD)pHHWinType->pszCustomTabs);
+    info->WinType.pszCustomTabs = info->pszCustomTabs = CHM_ReadString(pChmInfo, (DWORD_PTR)info->WinType.pszCustomTabs);
 #endif
 
 done:
diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c
index 85c076d..c49d3cf 100644
--- a/dlls/hhctrl.ocx/help.c
+++ b/dlls/hhctrl.ocx/help.c
@@ -922,16 +922,16 @@ void ReleaseHelpViewer(HHInfo *info)
         return;
 
     /* Free allocated strings */
-    heap_free((LPWSTR)info->WinType.pszType);
-    heap_free((LPWSTR)info->WinType.pszCaption);
-    heap_free((LPWSTR)info->WinType.pszToc);
-    heap_free((LPWSTR)info->WinType.pszIndex);
-    heap_free((LPWSTR)info->WinType.pszFile);
-    heap_free((LPWSTR)info->WinType.pszHome);
-    heap_free((LPWSTR)info->WinType.pszJump1);
-    heap_free((LPWSTR)info->WinType.pszJump2);
-    heap_free((LPWSTR)info->WinType.pszUrlJump1);
-    heap_free((LPWSTR)info->WinType.pszUrlJump2);
+    heap_free(info->pszType);
+    heap_free(info->pszCaption);
+    heap_free(info->pszToc);
+    heap_free(info->pszIndex);
+    heap_free(info->pszFile);
+    heap_free(info->pszHome);
+    heap_free(info->pszJump1);
+    heap_free(info->pszJump2);
+    heap_free(info->pszUrlJump1);
+    heap_free(info->pszUrlJump2);
 
     if (info->pCHMInfo)
         CloseCHM(info->pCHMInfo);
@@ -958,7 +958,7 @@ HHInfo *CreateHelpViewer(LPCWSTR filename)
         return NULL;
     }
 
-    if (!LoadWinTypeFromCHM(info->pCHMInfo, &info->WinType)) {
+    if (!LoadWinTypeFromCHM(info)) {
         ReleaseHelpViewer(info);
         return NULL;
     }
diff --git a/dlls/hhctrl.ocx/hhctrl.h b/dlls/hhctrl.ocx/hhctrl.h
index 73ec569..26c9d4d 100644
--- a/dlls/hhctrl.ocx/hhctrl.h
+++ b/dlls/hhctrl.ocx/hhctrl.h
@@ -92,6 +92,19 @@ typedef struct {
     IOleObject *wb_object;
 
     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;
     ContentItem *content;
     HWND hwndTabCtrl;
@@ -111,7 +124,7 @@ void InitContent(HHInfo*);
 void ReleaseContent(HHInfo*);
 
 CHMInfo *OpenCHM(LPCWSTR szFile);
-BOOL LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
+BOOL LoadWinTypeFromCHM(HHInfo *info);
 CHMInfo *CloseCHM(CHMInfo *pCHMInfo);
 void SetChmPath(ChmPath*,LPCWSTR,LPCWSTR);
 IStream *GetChmStream(CHMInfo*,LPCWSTR,ChmPath*);




More information about the wine-cvs mailing list