Article View: borland.public.cppbuilder.nativeapi
Article #17290Re: Hooking another application
From: nicolasr
Date: Fri, 28 Mar 2003 00:14
Date: Fri, 28 Mar 2003 00:14
78 lines
3082 bytes
3082 bytes
Hi,
thanks for your help!
> Just be careful with PostMessage(). Keep in mind that it returns
> immediately...
Thanks for the hint. I guess that is why I would prefer SendMessage(). On
the other hand with PostMessage() I maybe could implement a timeout
mechanism. I think it depends on the individual message. So it would be nice
to have both options.
> > The hook callback is called for other messages (redraw
> > etc.)
>
> Those are posted to the message queue, thus the WH_GETMESSAGE hook would
> pick them up.
>
> > but never for my SendMessage().
>
> Did you call SetWindowsHookEx() a second time to register the
WH_CALLWNDPROC
> hook as well?
>
Actually I have tried both ways separately yet. But I should do both in the
end. As I wrote the client calls SetHook(threadId) on the DLL which
currently looks like this:
bool SetHook(DWORD threadId)
{
hHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc,
HInstance, threadId);
if(hHook == NULL)
return false;
else
return true;
}
I'm a little unsure about the parameters passed to SetWindowsHookEx? Must
the third parameter be NULL or not in my special case?
The callback in the DLL looks like this:
LRESULT CALLBACK CallWndProc(int code, WPARAM wParam, LPARAM lParam)
{
if(code == HC_ACTION)
{
CWPSTRUCT* msg = (CWPSTRUCT*)lParam;
switch(msg->message)
{
case HOOK_WM_TEST:
MessageBeep(-1); //never called ##########
break;
case WM_NCHITTEST:
MessageBeep(-1); //this is always called when I move the mouse
over the server window########
break;
}
}
return CallNextHookEx(hHook, code, wParam, lParam);
}
the call in the client looks like this:
void __fastcall TForm2::Button2Click(TObject *Sender)
{
if(hwnd) //hwnd returned from FindWindow for the servers main window
{
SendMessage(hwnd, HOOK_WM_TEST, 0, 0);
}
}
I really don't have any idea what could be wrong?
thanks,
Nick
Technical Details
Message-ID:
<3e83949f@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e824b00@newsgroups.borland.com> <3e824e7e$1@newsgroups.borland.com> <3e834e27$1@newsgroups.borland.com> <3e835e66$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,c5183b6fe95bcc6 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-03-27 16:40:20 PST From: "nicolasr" <nicolasrATSIGNgmx.net> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e824b00@newsgroups.borland.com> <3e824e7e$1@newsgroups.borland.com> <3e834e27$1@newsgroups.borland.com> <3e835e66$1@newsgroups.borland.com> Subject: Re: Hooking another application Date: Fri, 28 Mar 2003 01:14:31 +0100 Lines: 80 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 80.133.173.93 Message-ID: <3e83949f@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1048810655 80.133.173.93 (27 Mar 2003 16:17:35 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail