🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2254

Re: Still struggling with a DLL for keyboard hooking

#2254
From: Remy Lebeau (TeamB)
Date: Fri, 16 Mar 2007 17:58
46 lines
2946 bytes
"antivari" <antivari@sbb.co.yu> wrote in message
news:45fa8441$1@newsgroups.borland.com...

> * What is the main reason for using CreateWnd() and DestroyWnd()

Using CreateWnd() an Destroy(), you are able to set the hook at the
absolute earliest time that the HWND is available, and release it at
the absolute last moment just before the HWND is destroyed.
Previously

> and not FormActivate() and Destructor, for handling hook
> activation?

You were not using those in the code you showed.  You were using the
CM_RECREATEWND message, but not correctly.  You were not removing the
hook before the HWND was destroyed, and you were re-setting the hook
to use the original HWND again before then allowing the TForm to
recreate the HWND, leaving your hook pointing to an invalid HWND
value.  Also, the OnClose event is not always guaranteed to be
triggered in all situations, so you could miss releasing your hook at
times.

Since your hook is directly dependant on the existance of the HWND, it
is best to map the activation/deactivation to that HWND's
creation/destruction as closely as possible.  That is what CreateWnd()
and DestroyWnd() allow you to do.

> * Also, what is the main reason for testing HandleAllocated()?

In case CreateWnd() failed.  Accessing the Handle property when it is
NULL will cause CreateWnd() to be called again, so you don't want to
cause a recursive loop.  But looking at CreateWnd()'s source code, it
will throw an exception if the HWND fails to be created, so you could
take out the check.

> I ask this because I experienced that my original program (that
> used my old DLL) sometimes left the DLL in a state in which
> DLL could not be deteted by uninstall procedure, and I'm
> sure that I had the RemoveHook() on every possible place that
> app could exit.

No, you didn't.


Gambit
Technical Details
Message-ID: <45facce0$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!news2.euro.net!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail
References: <45f9a429$1@newsgroups.borland.com> <45f9c0a3@newsgroups.borland.com> <45fa8441$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2dee6d400474aadb
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <45f9a429$1@newsgroups.borland.com> <45f9c0a3@newsgroups.borland.com> <45fa8441$1@newsgroups.borland.com>
Subject: Re: Still struggling with a DLL for keyboard hooking
Date: Fri, 16 Mar 2007 09:58:19 -0800
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.34.171
Message-ID: <45facce0$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1174064352 75.83.34.171 (16 Mar 2007 09:59:12 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!news2.euro.net!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail