Reinstate a piece of code accidentally removed in r9214, where Windows
[u/mdw/putty] / windows / winhelp.c
index 29e7aa0..8b652c7 100644 (file)
 
 #include "putty.h"
 
+#ifndef NO_HTMLHELP
 #include <htmlhelp.h>
+#endif /* NO_HTMLHELP */
 
-typedef HWND (CALLBACK *htmlhelp_t)(HWND, LPCSTR, UINT, DWORD);
-
-static char *help_path, *chm_path;
-static int help_has_contents;
 static int requested_help;
-static DWORD html_help_cookie;
-static htmlhelp_t htmlhelp;
+static char *help_path;
+static int help_has_contents;
+#ifndef NO_HTMLHELP
+DECL_WINDOWS_FUNCTION(static, HWND, HtmlHelpA, (HWND, LPCSTR, UINT, DWORD));
+static char *chm_path;
+#endif /* NO_HTMLHELP */
 
 void init_help(void)
 {
@@ -45,6 +47,7 @@ void init_help(void)
     } else
        help_has_contents = FALSE;
 
+#ifndef NO_HTMLHELP
     strcpy(r, PUTTY_CHM_FILE);
     if ( (fp = fopen(b, "r")) != NULL) {
        chm_path = dupstr(b);
@@ -52,23 +55,22 @@ void init_help(void)
     } else
        chm_path = NULL;
     if (chm_path) {
-       HINSTANCE dllHH = LoadLibrary("hhctrl.ocx");
-       if (dllHH) {
-           htmlhelp = (htmlhelp_t)GetProcAddress(dllHH, "HtmlHelpA");
-           if (!htmlhelp)
+       HINSTANCE dllHH = load_system32_dll("hhctrl.ocx");
+       GET_WINDOWS_FUNCTION(dllHH, HtmlHelpA);
+       if (!p_HtmlHelpA) {
+           chm_path = NULL;
+           if (dllHH)
                FreeLibrary(dllHH);
        }
-       if (htmlhelp)
-           htmlhelp(NULL, NULL, HH_INITIALIZE, (DWORD)&html_help_cookie);
-       else
-           chm_path = NULL;
     }
+#endif /* NO_HTMLHELP */
 }
 
 void shutdown_help(void)
 {
-    if (chm_path)
-       htmlhelp(NULL, NULL, HH_UNINITIALIZE, html_help_cookie);
+    /* Nothing to do currently.
+     * (If we were running HTML Help single-threaded, this is where we'd
+     * call HH_UNINITIALIZE.) */
 }
 
 int has_help(void)
@@ -79,7 +81,11 @@ int has_help(void)
      * unrealistic, since even Vista will have it if the user
      * specifically downloads it.
      */
-    return (help_path || chm_path);
+    return (help_path != NULL
+#ifndef NO_HTMLHELP
+           || chm_path
+#endif /* NO_HTMLHELP */
+          );
 }
 
 void launch_help(HWND hwnd, const char *topic)
@@ -87,22 +93,28 @@ void launch_help(HWND hwnd, const char *topic)
     if (topic) {
        int colonpos = strcspn(topic, ":");
 
+#ifndef NO_HTMLHELP
        if (chm_path) {
            char *fname;
            assert(topic[colonpos] != '\0');
            fname = dupprintf("%s::/%s.html>main", chm_path,
                              topic + colonpos + 1);
-           htmlhelp(hwnd, fname, HH_DISPLAY_TOPIC, 0);
+           p_HtmlHelpA(hwnd, fname, HH_DISPLAY_TOPIC, 0);
            sfree(fname);
-       } else if (help_path) {
+       } else
+#endif /* NO_HTMLHELP */
+       if (help_path) {
            char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic);
            WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
            sfree(cmd);
        }
     } else {
+#ifndef NO_HTMLHELP
        if (chm_path) {
-           htmlhelp(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);
-       } else if (help_path) {
+           p_HtmlHelpA(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);
+       } else
+#endif /* NO_HTMLHELP */
+       if (help_path) {
            WinHelp(hwnd, help_path,
                    help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0);
        }
@@ -113,9 +125,12 @@ void launch_help(HWND hwnd, const char *topic)
 void quit_help(HWND hwnd)
 {
     if (requested_help) {
+#ifndef NO_HTMLHELP
        if (chm_path) {
-           htmlhelp(NULL, NULL, HH_CLOSE_ALL, 0);
-       } else if (help_path) {
+           p_HtmlHelpA(NULL, NULL, HH_CLOSE_ALL, 0);
+       } else
+#endif /* NO_HTMLHELP */
+       if (help_path) {
            WinHelp(hwnd, help_path, HELP_QUIT, 0);
        }
        requested_help = FALSE;