Link to home
Start Free TrialLog in
Avatar of l_d_allan
l_d_allan

asked on

Mfc Dialog-App activating HtmlHelp: ok from Explorer, fails in VisStudio

Mfc Dialog-App activating HtmHelp: ok from Explorer, fails in VisStudio

I've got an Mfc generated Dialog App with a menu and various controls.  I want to use HtmlHelp, and am having a strange problem with "Help + Topics" and "Help + Index"

I compile/link with Debug configuration to create files
.\Debug\InVerse.exe
.\Debug\InVerse.chm

The code below works fine when I dbl-click on InVerse.exe from the Explorer.  It displays the 'Contents' and 'Index' correctly.  It seems to be able to 'find' InVerse.chm.  

But it fails (ret = 0) when I run it from VisStudio 6.0 sp5's IDE.  It fails both when I step through the code with the debugger, or run via Ctrl+F5.  The same behavior happens with a Release configuration and Ctrl-F5.  Runs ok from the Explorer, but not in the IDE.

void CInVerseDlg::OnHelp()
{
  HWND ret = HtmlHelp(NULL, "InVerse.chm", HH_DISPLAY_TOC, NULL);
  if (ret == 0) {
    AfxMessageBox("Unable to display HH_DISPLAY_TOC");
  }
}

void CInVerseDlg::OnHelpIndex()
{
  HWND ret = HtmlHelp(NULL,"InVerse.chm", HH_DISPLAY_INDEX, 0);
  if (ret == 0) {
    AfxMessageBox("Unable to display HH_DISPLAY_INDEX");
  }
}

What am I doing wrong or leaving out?  I'm aware that Dialogs work differently than Sdi/Mdi apps, but I'm baffled that it works ok 'outside' the IDE and not 'inside'.

TIA
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of l_d_allan
l_d_allan

ASKER

Hi Dan,

Ahhh, Mr. Mfc ... out in front and pulling away ...

Works great ... I'd seen a reference in other places that sometimes you needed to specify the full path ... and didn't think to do that here.  Gettin' groggy here in Blissful Colorado.

Thought I'd check ... is it ok to change the
AfxGetApp()->m_pszHelpFilePath() directly?  It is declared as a publicly visible const char*.  The MSDN documentation for m_pszHelpFilePath discusses using _strdup and free.  Since I'm only changing the last 3 characters, am I ok to ignore the malloc/free/_strdup info?  In my CInVerseApp::InitInstance, I strcat "chm" to &m_pszHelpFilePath[len - 3], as shown below

BOOL CInVerseApp::InitInstance()
{
...
  char* pszHFP=(char*)AfxGetApp()->m_pszHelpFilePath;
  int len = strlen(pszHFP);
  pszHFP[len - 3] = '\0';
  strcat(pszHFP,"chm");

  int nResponse = dlg.DoModal();
  if (nResponse == IDOK)
  ...
}

void CInVerseDlg::OnHelp()
{
  const char* pszHFP=AfxGetApp()->m_pszHelpFilePath;
  HWND ret = HtmlHelp(NULL, pszHFP, HH_DISPLAY_TOC, NULL);
  if (ret == 0) {
    MessageBox("Can't display HH_DISPLAY_TOC",pszHFP);
  }
}

void CInVerseDlg::OnHelpIndex()
{
  const char* pszHFP = AfxGetApp()->m_pszHelpFilePath;
  HWND ret = HtmlHelp(NULL, pszHFP, HH_DISPLAY_INDEX, 0);
  if (ret == 0) {
    MessageBox("Can't display HH_DISPLAY_INDEX", pszHFP);
  }
}

Thx again,
Lynn Allan
Don't CHANGE m_pszHelpFilePath.  Just USE it.

m_sMyHelpFile.Format("%s\\"InVerse.chm",  m_pszHelpFilePath );

...
HtmlHelp(NULL, m_sMyHelpFile, HH_DISPLAY_INDEX, 0);

-- Dan
>> Remember, when running from the IDE, your
>> program is in the .\debug or .\release
>> directory. I'm not sure what the 'current default'
>> will be in that case.  When you double-click
>> in the explorer, the default directory will be the
>> program directory.

Actually, I think both InVerse.exe and InVerse.chm are in the same directory.  I have Custom Build steps to compile the .hhp so that both are in $(OutDir).
Even so, I think the the 'current active directory' at the time that you run will be the direct parent of $(OutDir) -- that is, your project directory.  

It is easy to test.  Just copy the chm to there and see if the problem disappears.  Then add the code I gave (sans the typo) to your CMyApp::InitInstance() fn.

-- Dan
Hello Dan,

Good suggestion ...

I suppose "a poor craftsman blames his tools", but this exercise to wire a MFC dialog-app to WinHelp/HtmlHelp has been really frustrating.  Nice feeling when it works, but does it have to be so obscure?  I was trying to explain to my wife all the 'machinery' behind getting a simple popup window up.  

And at least so far, HtmlHelp popups look lousy compared with what you can do with WinHelp.  But WinHelp is a hassle for an end-user to navigate once in the 'Books'.  Almost unusable.

Oh, well, if this stuff was easy, I suppose it wouldn't pay particulary well.  And MFC is difficult enough that it certainly presents "barriers to entry" for people crowding the field.

An aside or two:  is it proper etiquette (sp?) for an 'Asker' to accept the answer once an excellent answer has been provided?  Or leave it open for a while?  

When tracking down previous PAQ's about HthmHelp, I came across a comment by you to another Expert to not prematurely post a reply as an answer, but rather as a comment.  So as to not discourage other experts from adding comments.  On the other hand, should the Asker accept the answer expeditiously so as to not waste time of experts?  "Inquiring minds want to know :-)"  I'd like to be a good citizen on this site.

And another question ... would you be the person to ask about tracking down "Unique Software"?  Do you suppose the $40 diskette for "IBM PC 8088 Macro Assembler Programming" is still available?  I thought maybe it might be a collector's item on E-Bay, but no luck :-)

Have a great weekend!

Lynn Allan
>>would you be the person to ask about tracking down "Unique Software"?  Do

wow, blast from the past.  I dug up a copy of the Listing Diskette, but I no longer have a computer that can read 5-1/4" diskettes!

-- Dan