Article View: borland.public.cppbuilder.nativeapi
Article #8613Re: Registering Help Viewer
From: 3 Wishes
Date: Fri, 08 Oct 2004 06:41
Date: Fri, 08 Oct 2004 06:41
158 lines
6943 bytes
6943 bytes
Hi Remy,
Thanks to your input I was able to do something that seems to be working
now.... I will need you however to answer to the question below, but first
here is the code:
<<HEADER>>
namespace _HTMLHelp
{
typedef HWND WINAPI (*HTML_HELP_PROC)(HWND, LPCSTR, UINT, DWORD_PTR);
//---------------------------------------------------------------------------
class THtmlHelpViewer : public TInterfacedObject, IExtendedHelpViewer,
IHelpSelector
{
private:
int fViewerID;
AnsiString fViewerName;
HTML_HELP_PROC fHtmlHelpFunction;
char* _GetModuleName();
protected:
HMODULE fHHCtrlHandle;
AnsiString fHtmlExt;
IHelpManager* fHelpManager;
HRESULT __stdcall QueryInterface(const GUID& IID, void **Obj);
ULONG __stdcall AddRef();
ULONG __stdcall Release();
AnsiString __fastcall GetHelpFileName();
bool __fastcall IsChmFile(const AnsiString FileName);
void __fastcall CallHtmlHelp(const AnsiString HelpFile, unsigned uCommand,
unsigned dwData);
/***ICustomHelpViewer***/
// {** Communication with the help manager }
virtual AnsiString __fastcall GetViewerName();
virtual void __fastcall NotifyID(const int ViewerID);
virtual void __fastcall ShutDown();
virtual void __fastcall SoftShutDown();
// { Communication with the help manager **}
// {** Keyword based help }
virtual TStringList* __fastcall GetHelpStrings(const AnsiString
HelpString);
virtual void __fastcall ShowHelp(const AnsiString HelpString);
// {Keyword based help **}
// {** Table of content }
virtual bool __fastcall CanShowTableOfContents();
virtual void __fastcall ShowTableOfContents();
// { Table of content **}
/***IExtendedHelpViewer***/
// {** F1 Key }
virtual bool __fastcall UnderstandsContext(const int ContextID, const
AnsiString HelpFileName);
// { F1 Key **}
// {** Topic based help ...}
virtual bool __fastcall UnderstandsTopic(const AnsiString Topic);
virtual void __fastcall DisplayTopic(const AnsiString Topic);
// { Topic based help **}
// {** Help manager call }
virtual void __fastcall DisplayHelpByContext(const int ContextID, const
AnsiString HelpFileName);
// { Help manager call **}
/***IHelpSelector** */
virtual int __fastcall TableOfContents(TStrings* Contents);
virtual int __fastcall UnderstandsKeyword(const AnsiString HelpString);
virtual int __fastcall SelectKeyword(TStrings* Keywords);
public:
virtual __fastcall THtmlHelpViewer();
virtual __fastcall ~THtmlHelpViewer();
void __fastcall InternalShutdown();
__property AnsiString HtmlExt = {read = fHtmlExt, write = fHtmlExt};
__property IHelpManager* HelpManager = {read = fHelpManager, write =
fHelpManager};
};
//---------------------------------------------------------------------------
class THtmlWinHelpTester : public TInterfacedObject, IWinHelpTester
{
protected:
virtual bool __fastcall CanShowALink(const AnsiString ALink, const
AnsiString FileName);
virtual bool __fastcall CanShowTopic(const AnsiString Topic, const
AnsiString FileName);
virtual bool __fastcall CanShowContext(const int Context, const AnsiString
FileName);
virtual TStringList* __fastcall GetHelpStrings(const AnsiString ALink);
virtual AnsiString __fastcall GetHelpPath();
virtual AnsiString __fastcall GetDefaultHelpFile();
HRESULT __stdcall QueryInterface(const GUID& IID, void **Obj);
ULONG __stdcall AddRef();
ULONG __stdcall Release();
};
//---------------------------------------------------------------------------
} //namespace _HTMLHelp
using namespace _HTMLHelp;
//---------------------------------------------------------------------------
<<SOURCE>>
#include <vcl.h>
#pragma hdrstop
#include "UnitHTMLHelp.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
_di_ICustomHelpViewer iHtmlHelpViewer;
_di_IHelpManager* iHelpManager = NULL;
THtmlHelpViewer* HtmlHelpViewer = NULL;
//---------------------------------------------------------------------------
void Initialization()
{
HtmlHelpViewer = new THtmlHelpViewer;
iHtmlHelpViewer = (ICustomHelpViewer*) HtmlHelpViewer;
iHelpManager = (_di_IHelpManager*) malloc(sizeof(_di_IHelpManager));
_di_IHelpManager& iHelpManagerRef = *iHelpManager;
RegisterViewer(iHtmlHelpViewer, iHelpManagerRef);
HtmlHelpViewer->HelpManager = (IHelpManager*) iHelpManagerRef;
Application->HelpSystem->AssignHelpSelector((IHelpSelector*)
HtmlHelpViewer);
WinHelpTester = (IWinHelpTester*) new THtmlWinHelpTester;
}
#pragma startup Initialization
//---------------------------------------------------------------------------
void Finalization()
{
if (HtmlHelpViewer)
HtmlHelpViewer->InternalShutdown();
if (iHelpManager)
free(iHelpManager);
}
#pragma exit Finalization
(...)
==============================================
So as I was saying before this works perfectly calling the help from the
menu of the application, or answering to a F1 key press with a context ID
(the reason why I made a IExtendedHelpViewer instead of a ICustomHelpViewer.
There is no memory leak, exceptions or anything bad happening. But I am not
really sure that what I did was elegant... I mean, because I could not have
a _di_IHelpManager define on the stack, I decided to get one on the heap
(hence the malloc in the initialization), while making sure that this block
of memory would then be released during the finalization (hence the
free).... I do not know however if there is a better academic method to do
this, and I think that I am just very lucky right now to have it working. Do
you have any better way to avoid the problem that we notice before
(inability for the compiler to make the difference between the two versions
of Release)?
Thanks for your answer.
Technical Details
Message-ID:
<4166370b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4165b82e$2@newsgroups.borland.com> <4165c3bb$1@newsgroups.borland.com> <4165d4c5@newsgroups.borland.com> <4165d89f$1@newsgroups.borland.com> <4165da2a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fa848f661129ced4 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "3 Wishes" <3@wishes.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4165b82e$2@newsgroups.borland.com> <4165c3bb$1@newsgroups.borland.com> <4165d4c5@newsgroups.borland.com> <4165d89f$1@newsgroups.borland.com> <4165da2a$1@newsgroups.borland.com> Subject: Re: Registering Help Viewer Date: Fri, 8 Oct 2004 02:41:14 -0400 Lines: 160 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 64.223.183.32 Message-ID: <4166370b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1097217803 64.223.183.32 (7 Oct 2004 23:43:23 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail