CnPack Forum » CnWizards IDE Wizards » "Small" issue to report


2008-1-6 02:42 cata
"Small" issue to report

Last days an annoying error was shown every time I close BDS 2006 (with CnWizards_0.8.2.356:
Exception error at ..... in module hhctrl.ocx.

After I played a little I found that error appears only if cnwizard is loaded. My problem was to find the error point (pretty hard).

Stepping over my digging researches, the problem is in this function:

function UnLoadHtmlHelp: Boolean;
begin
  Result := True;
  if HtmlHelpLoaded then
  begin
    if Assigned(HtmlHelp) then HtmlHelp(0, nil, HH_CLOSE_ALL, 0);
    Result := FreeLibrary(HtmlHelpLib);
    HtmlHelpLib := 0;
    @HtmlHelpA := nil;
    @HtmlHelpW := nil;
    @HtmlHelp := nil;
  end;
end;

and, more specific, in HtmlHelp(0, nil, HH_CLOSE_ALL, 0).

Seems is an known issue which is not solved by Microsoft.

see this link: http://www.helpware.net/FAR/far_faq.htmin section: HH_CLOSE_ALL Bug and HH_INITIALIZE

copy/paste the text:


[indent]  [b]Problem:[/b]
    Marcel van Brakel has uncovered a real problem with HH_CLOSE_ALL. When you   call HH_CLOSE_ALL on shut down, the HH API creates another thread   and sometimes does not return until after you have performed UnLoadLibrary(hhctrl.ocx).   In this case the HH_CLOSE_ALL thread returns to nothing and causes an access   violation.
  [b]Discussion:[/b]
  Ralph Walden (x-Microsoft) describes the problem:
    The switch to a background thread was done after I left (the MS help team)    in order to solve a problem with Visual Studio. I knew they should have fixed   Visual Studio instead of "fixing" HTML Help (which wasn't broken). I've never   actually tried it, but along with that change was a hack that allowed you to   call the API in a way that it would create an interface, and then you'd call   the API again to release that interface. You start off with HH_INITIALIZE and   end with HH_UNINITIALIZE. Another alternative would be to set the   HH_GPROPID_SINGLETHREAD property to TRUE -- that might get HTML Help back onto   the parent's thread.
  [b]Fix:[/b]
    [list][*]As described by Ralph above, you can try using the     HH_INITIALIZE, HH_UNINITIALIZE commands. These are documented in the HH     Workshop online help.[*]Call HH_CLOSE_ALL earlier. Get more space between the HH_CLOSE_ALL and     your call to UnloadLibrary. In VB and Delphi you would perform the call on     the Form QueryUnload _not_ on the Form Close or Destroy.[*]Marcel van Brakel seemed to fix it by calling     Sleep(0); immediately after the call to HH_CLOSE_ALL. Again providing more     time for the rogue thread to return.[/list]  [b]More Tips:[/b]
  Here is an alternative to using HH_CLOSE_ALL. What I do with my   applications is keep the handle of the HH Windows when making a help call:  _HHwinHwnd := htmlhelp(...) and on shutdown call:[table=98%]    [tr]      [td=1,1,560]if IsWindow(_HHwinHwnd) then
   SendMessage( _HHwinHwnd, wm_close, 0, 0 );[/td]    [/tr]  [/table]This is 10 times faster code, and eliminates the   need for HH_CLOSE_ALL completely.
  Also, as programming wizard Roland Mechling points   out, don't blindly call HH_CLOSE_ALL on shutdown. If a user does not have HTML   Help installed then this call will crash your application.   Here is safer code. Notice we are checking if HH is installed before calling   HtmlHelp();[table]    [tr]      [td]procedure HHCloseAll;
begin
     If @HH.HtmlHelp <> Nil then  //HH API is available
     begin
           HH.HtmlHelp(0, nil, HH_CLOSE_ALL, 0);
           Sleep(0);
     end;
end;[/td]    [/tr]  [/table][/indent]


Also a Borland bug report: http://qc.borland.com/wc/qcmain.aspx?d=48983


I know that is not a cnWizard bug but maybe someone knows a better workaround and can change UnLoadHtmlHelp function.
I tried Sleep(0) but seems doesn't help.

I'll come back with more info.

[[i] Last edited by  cata at 2008-1-6 04:01 [/i]]

2008-1-6 03:55 cata
Ripped from group discussion:


I have moved the LoadLibrary() from DllMain() to separate initialization
function and that solved the problem.

M.?.

"Miroslav ?ulc" <miroslav.s...@startnet.cz> pí?e v diskusním p?íspìvku
news:3ae99c78@news.cvut.cz...

> Hi Rob,

> I have went through DLLs code and I have realized that I use LoadLibrary()
> in DllMain(). MSDN documentation for DllMain() says that it could be
source
> of strange errors. Now I am moving the LoadLibrary() functions to a
separate
> initialization functions. Then I will see if this is the cause.


This could be the problem because LoadLibrary(PChar(HHOCXPath)) is done in unit initialization of HtmlHlp.pas which is in uses clause of CnMsdnWizard-> uses of CnWizards_D10.dpr, means DllEntryPoint of CnWizards_D10.dll.
So, in fact, is the problem described above.

I'll try to move it to see the effect.

What is strange is that I can't associate the appearance of this problem with an install of specific software/components.

[[i] Last edited by  cata at 2008-1-6 04:02 [/i]]

2008-1-6 04:57 cata
The fastest solution was to disable MSDN wizard. I didn't used, anyway.

2008-1-7 10:05 Passion
For a user, if he does not need MSDN Wizard, he can disable it.
But if he need it, what's the simple way to resolve it? Add a Sleep(0); after the call to HH_CLOSE_ALL seems simplest.:)

2008-1-8 19:28 cata
[quote]Originally posted by [i]Passion[/i] at 2008-1-7 10:05
For a user, if he does not need MSDN Wizard, he can disable it.
But if he need it, what's the simple way to resolve it? Add a Sleep(0); after the call to HH_CLOSE_ALL seems simplest.:) [/quote]


Agree, but maybe is better to include it in next release.

2008-1-8 20:37 Passion
Yes. we've add this line into our 0.8.2.361 nighly build verison.

If you can, please download and test it for us?:)

[url]http://www.cnpack.org/downbuilds.php[/url]

2008-1-10 14:15 cata
[quote]Originally posted by [i]Passion[/i] at 2008-1-8 20:37
Yes. we've add this line into our 0.8.2.361 nighly build verison.

If you can, please download and test it for us?:)

[url=http://www.cnpack.org/downbuilds.php]http://www.cnpack.org/downbuilds.php[/url] [/quote]


Ok. I'll try it.

Are available the sources for nigthly builds somewhere?

2008-1-10 16:09 Passion
Yes. It's in our CVS.

You can get CnPack and CnWizards latest source code from this CVS repository:

CVSROOT:
:pserver:anoncvs@[url]www.cnpack.org:/var/cvshome/cnpack[/url]

Password:
anoncvs

Module Name:

cnpack
cnwizards

页: [1]
查看完整版本: "Small" issue to report


Powered by Discuz! Archiver 5.0.0  © 2001-2006 Comsenz Inc.