Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6 KiB

  1. // Copyright (C) Microsoft Corporation 1996-1997, All Rights reserved.
  2. #include "windows.h"
  3. #include "htmlhelp.h"
  4. #pragma data_seg(".text", "CODE")
  5. static const char txtHHCtrl[] = "hhctrl.ocx";
  6. static const char txtInProc[] = "CLSID\\{ADB880A6-D8FF-11CF-9377-00AA003B7A11}\\InprocServer32";
  7. #pragma data_seg()
  8. HWND (WINAPI *pHtmlHelpA)(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData);
  9. HWND (WINAPI *pHtmlHelpW)(HWND hwndCaller, PCWSTR pszFile, UINT uCommand, DWORD_PTR dwData);
  10. static BOOL GetRegisteredLocation(LPTSTR pszPathname)
  11. {
  12. BOOL bReturn = FALSE;
  13. HKEY hKey;
  14. if (RegOpenKeyEx(HKEY_CLASSES_ROOT, txtInProc, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
  15. DWORD dwSize = MAX_PATH;
  16. if (RegQueryValueEx(hKey, "", 0, 0, (PBYTE) pszPathname, &dwSize) == ERROR_SUCCESS) {
  17. bReturn = TRUE;
  18. }
  19. }
  20. else
  21. return FALSE;
  22. RegCloseKey(hKey);
  23. return bReturn;
  24. }
  25. extern "C"
  26. HWND WINAPI HtmlHelpA(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData)
  27. {
  28. static HMODULE g_hmodHHCtrl;
  29. static BOOL g_fTriedAndFailed;
  30. if (!g_hmodHHCtrl && !g_fTriedAndFailed) {
  31. char szHHCtrl[MAX_PATH];
  32. if (GetRegisteredLocation(szHHCtrl))
  33. g_hmodHHCtrl = LoadLibrary(szHHCtrl); // try registered location
  34. if (!g_hmodHHCtrl)
  35. g_hmodHHCtrl = LoadLibrary(txtHHCtrl); // try normal location
  36. if (g_hmodHHCtrl == NULL) {
  37. g_fTriedAndFailed = TRUE;
  38. return NULL;
  39. }
  40. }
  41. if (!pHtmlHelpA) {
  42. (FARPROC&) pHtmlHelpA = GetProcAddress(g_hmodHHCtrl, ATOM_HTMLHELP_API_ANSI);
  43. if (pHtmlHelpA == NULL) {
  44. g_fTriedAndFailed = TRUE;
  45. return NULL;
  46. }
  47. }
  48. return pHtmlHelpA(hwndCaller, pszFile, uCommand, dwData);
  49. }
  50. extern "C"
  51. HWND WINAPI HtmlHelpW(HWND hwndCaller, PCWSTR pszFile, UINT uCommand, DWORD_PTR dwData)
  52. {
  53. static HMODULE g_hmodHHCtrl;
  54. static BOOL g_fTriedAndFailed;
  55. if (!g_hmodHHCtrl && !g_fTriedAndFailed) {
  56. char szHHCtrl[MAX_PATH];
  57. if (GetRegisteredLocation(szHHCtrl))
  58. g_hmodHHCtrl = LoadLibrary(szHHCtrl); // try registered location
  59. if (!g_hmodHHCtrl)
  60. g_hmodHHCtrl = LoadLibrary(txtHHCtrl);
  61. if (g_hmodHHCtrl == NULL) {
  62. g_fTriedAndFailed = TRUE;
  63. return NULL;
  64. }
  65. }
  66. if (!pHtmlHelpW) {
  67. (FARPROC&) pHtmlHelpW = GetProcAddress(g_hmodHHCtrl, ATOM_HTMLHELP_API_UNICODE);
  68. if (pHtmlHelpW == NULL) {
  69. g_fTriedAndFailed = TRUE;
  70. return NULL;
  71. }
  72. }
  73. return pHtmlHelpW(hwndCaller, pszFile, uCommand, dwData);
  74. }