Article View: borland.public.cppbuilder.nativeapi
Article #7264Re: Global window hook
From: Remy Lebeau (TeamB)
Date: Thu, 24 Feb 2005 18:23
Date: Thu, 24 Feb 2005 18:23
33 lines
2263 bytes
2263 bytes
"roger" <rogersmail@ntlworld.com> wrote in message
news:421dc13d$1@newsgroups.borland.com...
> extern "C" {
> bool __stdcall __declspec(dllexport) InstallHook(void);
> bool __stdcall __declspec(dllexport) RemoveHook(void);
> }
The form should be importing the functions, not exporting them.
> char *buffer = new char[cds->cbData];
> memcpy(buffer, cds->lpData, cds->cbData);
> Memo1->Lines->Add(buffer);
You are leaking the memory you allocated as you are never freeing it. You
don't need to allocate a new buffer anyway, just use the existing buffer in
the message:
Memo1->Lines->Add(AnsiString(cds->lpData, cds->cbData));
> void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
> {
> RemoveHook();
> }
I would suggest moving the call to RemoveHook() into the form's destructor
instead. You used the constructor to install the hook, so the destructor is
logical to remove it. Also, OnClose is not guaranteed to always be called
in all situations, but the destructor is.
Gambit
Technical Details
Message-ID:
<421e1b91$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!83.128.0.12.MISMATCH!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<421d76a8@newsgroups.borland.com> <421d81d6@newsgroups.borland.com> <421d891c@newsgroups.borland.com> <421dc13d$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9b9eac270d6034d6 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: <421d76a8@newsgroups.borland.com> <421d81d6@newsgroups.borland.com> <421d891c@newsgroups.borland.com> <421dc13d$1@newsgroups.borland.com> Subject: Re: Global window hook Date: Thu, 24 Feb 2005 10:23:16 -0800 Lines: 35 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: 68.69.17.41 Message-ID: <421e1b91$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1109269393 68.69.17.41 (24 Feb 2005 10:23:13 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!83.128.0.12.MISMATCH!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail