diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c index dbf174d8839..c3a7499266b 100644 --- a/dlls/hhctrl.ocx/chm.c +++ b/dlls/hhctrl.ocx/chm.c @@ -362,15 +362,16 @@ IStream *GetChmStream(CHMInfo *info, LPCWSTR parent_chm, ChmPath *chm_file) /* Opens the CHM file for reading */ CHMInfo *OpenCHM(LPCWSTR szFile) { - WCHAR file[MAX_PATH] = {0}; HRESULT hres; + CHMInfo *ret; static const WCHAR wszSTRINGS[] = {'#','S','T','R','I','N','G','S',0}; - CHMInfo *ret = heap_alloc_zero(sizeof(CHMInfo)); + if (!(ret = heap_alloc_zero(sizeof(CHMInfo)))) + return NULL; - GetFullPathNameW(szFile, sizeof(file)/sizeof(file[0]), file, NULL); - ret->szFile = strdupW(file); + if (!(ret->szFile = strdupW(szFile))) + return NULL; hres = CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER, &IID_IITStorage, (void **) &ret->pITStorage) ; diff --git a/dlls/hhctrl.ocx/hhctrl.c b/dlls/hhctrl.ocx/hhctrl.c index 10e04bc3217..8268a21f34b 100644 --- a/dlls/hhctrl.ocx/hhctrl.c +++ b/dlls/hhctrl.ocx/hhctrl.c @@ -86,11 +86,27 @@ static const char *command_to_string(UINT command) #undef X } +static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen) +{ + static const WCHAR helpW[] = {'\\','h','e','l','p','\\',0}; + + GetFullPathNameW(filename, buflen, fullname, NULL); + if (GetFileAttributesW(fullname) == INVALID_FILE_ATTRIBUTES) + { + GetWindowsDirectoryW(fullname, buflen); + strcatW(fullname, helpW); + strcatW(fullname, filename); + } + return (GetFileAttributesW(fullname) != INVALID_FILE_ATTRIBUTES); +} + /****************************************************************** * HtmlHelpW (HHCTRL.OCX.15) */ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data) { + WCHAR fullname[MAX_PATH]; + TRACE("(%p, %s, command=%s, data=%lx)\n", caller, debugstr_w( filename ), command_to_string( command ), data); @@ -120,7 +136,13 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR dat index += 2; /* advance beyond "::" for calling NavigateToChm() later */ } - info = CreateHelpViewer(filename); + if (!resolve_filename(filename, fullname, MAX_PATH)) + { + WARN("can't find %s\n", debugstr_w(filename)); + return 0; + } + + info = CreateHelpViewer(fullname); if(!info) return NULL; @@ -142,7 +164,13 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR dat if (!filename) return NULL; - info = CreateHelpViewer(filename); + if (!resolve_filename(filename, fullname, MAX_PATH)) + { + WARN("can't find %s\n", debugstr_w(filename)); + return 0; + } + + info = CreateHelpViewer(fullname); if(!info) return NULL;