Unfortunately, HTML help files are no longer offered when creating a Visual Studio project. Especially with MFC, this option was previously offered and the required files were also created. In order to use your own chm file, an absolute path must be specified and it makes sense to check whether the file actually exists there.
In a Win32 program the display of the help with the system call HtmlHelp() was successful if HH_INITIALIZE was NOT called before. It worked after InitInstance(), whereby you can then specify the main window or also before if you specify NULL.
HWND wrtn = HtmlHelp(NULL, helpFilePath, HH_DISPLAY_TOPIC, 0);
if (wrtn == NULL) {
DWORD error = GetLastError();
WCHAR errorMessage[255];
_stprintf(errorMessage, _T("Error displaying HTML help. Error code: %lu"), error);
MessageBox(NULL, errorMessage, _T("Error"), MB_OK | MB_ICONERROR);
}
With an MFC program it is much easier, as you can overwrite the member function OnHelp().
void Chtmlhelp3App::OnHelp()
{
if (!PathFileExists(m_helpFilePath)) {
MessageBox(NULL, _T("No Help found!"), _T("Error"), MB_OK | MB_ICONERROR);
return;
}
HWND result = ::HtmlHelp(m_pMainWnd->GetSafeHwnd(), m_helpFilePath, HH_DISPLAY_TOPIC, 0);
if (result == NULL) {
DWORD error = GetLastError();
...
}
}
Apparently not every old chm file can be opened, I have created a completely new chm file for testing. HelpNDoc may also be helpful here.