diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2013-08-06 16:35:28 +0100 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2013-08-06 18:01:06 +0100 |
commit | c253121aabd940107fac2ce85668993cc7e94237 (patch) | |
tree | 0390e58c550821617ae3dd7cd3c6eeda7c29cc40 /lib | |
parent | 6e6df220c717862a3ca1c2094aa37c7c4bc911b3 (diff) |
Provide our own htmlhelp library codexlaunch-20130806-1
- libhtmlhelp.a we now provide ourself
- htmlhelp.h comes from MinGW-w64 w32api
- hhc.exe comes from the HTML Help Workshop
We need to do this because:
- w32api doesn't provde a libhtmlhelp.a, and we don't know where to get one for
x86_64 that is actually useful
- maybe there are some license issue with linking with htlphelp.lib from a
Microsoft PSDK and the cygwin DLL?
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 4 | ||||
-rw-r--r-- | lib/init.c | 83 | ||||
-rw-r--r-- | lib/sub.c | 24 |
3 files changed, 111 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..b74f086 --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,4 @@ + +noinst_LIBRARIES = libhtmlhelp.a + +libhtmlhelp_a_SOURCES = init.c diff --git a/lib/init.c b/lib/init.c new file mode 100644 index 0000000..6343e91 --- /dev/null +++ b/lib/init.c @@ -0,0 +1,83 @@ +/* + Copied from https://github.com/yumeyao/7zip + "building 7zip using vc8(x86) and vc11(x64) while still linking to msvcrt.dll" + + To the best of my knowledge this file is licensed under the LGPL. + + PSDK versions of htmlhelp.lib for x86_64 depend on bufferoverflowU.lib for __security_cookie, + since they are compiled with VC using the /GS flag + + This also improves on the x86 library in previous SDK, since it adds functionality to expand + REG_EXPAND_SZ to a full path. +*/ + +#include <windows.h> + +static HMODULE g_hmodHHCtrl = NULL; +static BOOL g_fTriedAndFailed = FALSE; +typedef HWND (WINAPI *pHtmlHelpA_t)(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData); +typedef HWND (WINAPI *pHtmlHelpW_t)(HWND hwndCaller, LPCWSTR pszFile, UINT uCommand, DWORD_PTR dwData); +pHtmlHelpA_t pHtmlHelpA = NULL; +pHtmlHelpW_t pHtmlHelpW = NULL; +#define HtmlHelpAHint 14 +#define HtmlHelpWHint 15 + +__attribute__((always_inline)) static LPSTR GetRegisteredLocation(LPSTR pszPath, LPSTR pszExpandedPath) +{ + LPSTR ret = NULL; + HKEY hKey; + DWORD cbData; + DWORD dwType; + if (ERROR_SUCCESS != RegOpenKeyExA( + HKEY_CLASSES_ROOT, + "CLSID\\{ADB880A6-D8FF-11CF-9377-00AA003B7A11}\\InprocServer32", + 0, KEY_READ, &hKey)) + return ret; + cbData = MAX_PATH; + if (ERROR_SUCCESS == RegQueryValueExA(hKey, NULL, NULL, &dwType, (LPBYTE)pszPath, &cbData)) { + if (REG_EXPAND_SZ==dwType) { + if (MAX_PATH == ExpandEnvironmentStringsA(pszPath, pszExpandedPath, MAX_PATH)) { + ret = pszExpandedPath; + } + } else { + ret = pszPath; + } + } + RegCloseKey(hKey); + return ret; +} + +__declspec(noinline) static HMODULE WINAPI TryLoadingModule() +{ + CHAR szPath[MAX_PATH]; + CHAR szExpandedPath[MAX_PATH]; + HMODULE hMod; + CHAR *pszPath; + + if (pszPath = GetRegisteredLocation(szPath, szExpandedPath)) { + hMod = LoadLibraryA(pszPath); + if (!hMod) + goto LoadDefaultPath; + } else { +LoadDefaultPath: + hMod = LoadLibraryA("hhctrl.ocx"); + } + return hMod; +} + +#define _mkFuncPtr(FuncName) p##FuncName +#define _mkFuncPtrType(FuncName) p##FuncName##_t +#define _mkFuncHint(FuncName) FuncName##Hint +#define mkFuncPtr(FuncName) _mkFuncPtr(FuncName) +#define mkFuncPtrType(FuncName) _mkFuncPtrType(FuncName) +#define mkFuncHint(FuncName) _mkFuncHint(FuncName) + +#define FuncName HtmlHelpA +#define StrType LPCSTR +#include "sub.c" + +#undef FuncName +#undef StrType +#define FuncName HtmlHelpW +#define StrType LPCWSTR +#include "sub.c" diff --git a/lib/sub.c b/lib/sub.c new file mode 100644 index 0000000..352da94 --- /dev/null +++ b/lib/sub.c @@ -0,0 +1,24 @@ + +HWND WINAPI FuncName(HWND hwndCaller, StrType pszFile, UINT uCommand, DWORD_PTR dwData) +{ + HMODULE hMod = g_hmodHHCtrl; + mkFuncPtrType(FuncName) pFunc; + if (!hMod && g_fTriedAndFailed == FALSE) { + if (hMod = TryLoadingModule()) + g_hmodHHCtrl = hMod; + else + goto Fail; + } + + pFunc = mkFuncPtr(FuncName); + if (pFunc) goto CallFunc; + if (pFunc = (mkFuncPtrType(FuncName))GetProcAddress(g_hmodHHCtrl, (LPCSTR)mkFuncHint(FuncName))) { + mkFuncPtr(FuncName) = pFunc; +CallFunc: + return pFunc((HWND)hwndCaller, pszFile, uCommand, dwData); + } + +Fail: + g_fTriedAndFailed = ~FALSE; + return NULL; +} |