Jacek Caban : hhctrl.ocx: Move more code from doWinMain.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Feb 28 08:19:09 CST 2007


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Feb 28 03:48:45 2007 +0100

hhctrl.ocx: Move more code from doWinMain.

---

 dlls/hhctrl.ocx/chm.c    |    4 +-
 dlls/hhctrl.ocx/help.c   |   51 ++++++++++++++++++++++++---------------------
 dlls/hhctrl.ocx/hhctrl.h |   19 ++++++++++++++++-
 3 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c
index d0498ff..8e9fcf8 100644
--- a/dlls/hhctrl.ocx/chm.c
+++ b/dlls/hhctrl.ocx/chm.c
@@ -151,7 +151,7 @@ static BOOL ReadChmSystem(CHMInfo *chm)
  * FIXME: There may be more than one window type in the file, so
  *        add the ability to choose a certain window type
  */
-BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType)
+BOOL LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType)
 {
     LARGE_INTEGER liOffset;
     IStorage *pStorage = pChmInfo->pStorage;
@@ -209,7 +209,7 @@ CHMInfo *OpenCHM(LPCWSTR szFile)
 
     CHMInfo *ret = hhctrl_alloc_zero(sizeof(CHMInfo));
 
-    ret->szFile = szFile;
+    ret->szFile = strdupW(szFile);
 
     hres = CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER,
             &IID_IITStorage, (void **) &ret->pITStorage) ;
diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c
index 8196e4e..770b69a 100644
--- a/dlls/hhctrl.ocx/help.c
+++ b/dlls/hhctrl.ocx/help.c
@@ -24,7 +24,6 @@
 #include "commctrl.h"
 #include "wininet.h"
 
-#include "wine/unicode.h"
 #include "wine/debug.h"
 
 #include "resource.h"
@@ -737,7 +736,7 @@ static void HH_InitRequiredControls(DWORD dwControls)
 }
 
 /* Creates the whole package */
-static BOOL HH_CreateViewer(HHInfo *pHHInfo)
+static BOOL CreateViewer(HHInfo *pHHInfo)
 {
     HH_CreateFont(pHHInfo);
 
@@ -765,7 +764,7 @@ static BOOL HH_CreateViewer(HHInfo *pHHInfo)
     return TRUE;
 }
 
-static void HH_Close(HHInfo *info)
+static void ReleaseHelpViewer(HHInfo *info)
 {
     if (!info)
         return;
@@ -786,43 +785,49 @@ static void HH_Close(HHInfo *info)
         CloseCHM(info->pCHMInfo);
 
     ReleaseWebBrowser(info);
+
+    hhctrl_free(info);
+    OleUninitialize();
 }
 
-static HHInfo *HH_OpenHH(LPWSTR filename)
+static HHInfo *CreateHelpViewer(LPCWSTR filename)
 {
-    HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
+    HHInfo *info = hhctrl_alloc_zero(sizeof(HHInfo));
+
+    OleInitialize(NULL);
+
+    info->pCHMInfo = OpenCHM(filename);
+    if(!info->pCHMInfo) {
+        ReleaseHelpViewer(info);
+        return NULL;
+    }
 
-    pHHInfo->pCHMInfo = OpenCHM(filename);
-    if(!pHHInfo->pCHMInfo) {
-        HH_Close(pHHInfo);
+    if (!LoadWinTypeFromCHM(info->pCHMInfo, &info->WinType)) {
+        ReleaseHelpViewer(info);
         return NULL;
     }
 
-    if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, &pHHInfo->WinType)) {
-        HH_Close(pHHInfo);
+    if(!CreateViewer(info)) {
+        ReleaseHelpViewer(info);
         return NULL;
     }
 
-    return pHHInfo;
+    return info;
 }
 
 /* FIXME: Check szCmdLine for bad arguments */
 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
 {
     MSG msg;
-    HHInfo *pHHInfo;
+    HHInfo *info;
+    LPWSTR filename = strdupAtoW(szCmdLine);
 
-    if (FAILED(OleInitialize(NULL)))
+    info = CreateHelpViewer(filename);
+    hhctrl_free(filename);
+    if(!info)
         return -1;
 
-    pHHInfo = HH_OpenHH(strdupAtoW(szCmdLine));
-    if (!pHHInfo || !HH_CreateViewer(pHHInfo))
-    {
-        OleUninitialize();
-        return -1;
-    }
-
-    NavigateToChm(pHHInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->WinType.pszFile);
+    NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszFile);
     
     while (GetMessageW(&msg, 0, 0, 0))
     {
@@ -830,9 +835,7 @@ int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
         DispatchMessageW(&msg);
     }
 
-    HH_Close(pHHInfo);
-    hhctrl_free(pHHInfo);
-    OleUninitialize();
+    ReleaseHelpViewer(info);
 
     return 0;
 }
diff --git a/dlls/hhctrl.ocx/hhctrl.h b/dlls/hhctrl.ocx/hhctrl.h
index 2c0b71d..5d2bb0f 100644
--- a/dlls/hhctrl.ocx/hhctrl.h
+++ b/dlls/hhctrl.ocx/hhctrl.h
@@ -1,5 +1,6 @@
 /*
  * Copyright 2005 James Hawkins
+ * Copyright 2007 Jacek Caban for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -37,6 +38,7 @@
 #endif
 
 #include "wine/itss.h"
+#include "wine/unicode.h"
 
 #define WB_GOBACK     0
 #define WB_GOFORWARD  1
@@ -75,7 +77,7 @@ void ResizeWebBrowser(HHInfo*,DWORD,DWORD);
 void DoPageAction(HHInfo*,DWORD);
 
 CHMInfo *OpenCHM(LPCWSTR szFile);
-BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
+BOOL LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
 CHMInfo *CloseCHM(CHMInfo *pCHMInfo);
 
 /* memory allocation functions */
@@ -105,6 +107,21 @@ static inline BOOL hhctrl_free(void *mem)
     return HeapFree(GetProcessHeap(), 0, mem);
 }
 
+static inline LPWSTR strdupW(LPCWSTR str)
+{
+    LPWSTR ret;
+    int size;
+
+    if(!str)
+        return NULL;
+
+    size = (strlenW(str)+1)*sizeof(WCHAR);
+    ret = hhctrl_alloc(size);
+    memcpy(ret, str, size);
+
+    return ret;
+}
+
 static inline LPWSTR strdupAtoW(LPCSTR str)
 {
     LPWSTR ret;




More information about the wine-cvs mailing list