Article View: borland.public.cppbuilder.nativeapi
Article #2302Re: My app closes, but cancels Windows shutdown?
From: A Nonymous
Date: Sat, 10 Mar 2007 19:40
Date: Sat, 10 Mar 2007 19:40
45 lines
2606 bytes
2606 bytes
>> Now the bad news... It doesn't seem to work. I get nothing.
>> In fact I tried setting a breakpoint on the if( nCode == HC_ACTION )
>> line and then using my fake shutdown utility to send a
>> WM_QUERYENDSESSION. The app closed, but the break
>> point was never reached.
>
> Then SetWindowsHookEx() is failing to install the hook. Try passing
> the value of WinMain's hInstance parameter to SetWindowsHookEx's hMod
> parameter.
>
I did some reading and a null return is a failure, so I added a call to
GetLastError() and found that the error is 1428 "Cannot set non-local
hook without a module handle". This agrees with your above statement. So
I changed the:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
to:
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
as in your example. I changed the line:
hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC)
&CallWndRetProc, NULL, 0);
to:
hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC)
&CallWndRetProc, hInstance, 0);
and now when I run, the entire IDE dissapears! WOW!
The MSDN docs say:
HHOOK SetWindowsHookEx( int idHook,
HOOKPROC lpfn,
HINSTANCE hMod,
DWORD dwThreadId
);
What am I missing?
Sorry to seem so dumb.
Technical Details
Message-ID:
<Xns98EF8B2886544anonymoushotmailcom@207.105.83.66>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<Xns98ED90968E734anonymoushotmailcom@207.105.83.66> <45f07307@newsgroups.borland.com> <Xns98ED988E421A8anonymoushotmailcom@207.105.83.66> <45f08f8f$1@newsgroups.borland.com> <Xns98EDAC20DAA4Eanonymoushotmailcom@207.105.83.66> <45f095bf$1@newsgroups.borland.com> <45f0a594@newsgroups.borland.com> <45f0a77f$1@newsgroups.borland.com> <45f0d6c1@newsgroups.borland.com> <Xns98EE722D896C6anonymoushotmailcom@207.105.83.66> <45f1a96b$1@newsgroups.borland.com> <Xns98EE9F12960D1anonymoushotmailcom@207.105.83.66> <45f1d8a5$1@newsgroups.borland.com> <Xns98EEAB7C7DA52anonymoushotmailcom@207.105.83.66> <45f1ffc0$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,346f60f70c29a156 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: My app closes, but cancels Windows shutdown? From: A Nonymous <anonymous@hotmail.com> References: <Xns98ED90968E734anonymoushotmailcom@207.105.83.66> <45f07307@newsgroups.borland.com> <Xns98ED988E421A8anonymoushotmailcom@207.105.83.66> <45f08f8f$1@newsgroups.borland.com> <Xns98EDAC20DAA4Eanonymoushotmailcom@207.105.83.66> <45f095bf$1@newsgroups.borland.com> <45f0a594@newsgroups.borland.com> <45f0a77f$1@newsgroups.borland.com> <45f0d6c1@newsgroups.borland.com> <Xns98EE722D896C6anonymoushotmailcom@207.105.83.66> <45f1a96b$1@newsgroups.borland.com> <Xns98EE9F12960D1anonymoushotmailcom@207.105.83.66> <45f1d8a5$1@newsgroups.borland.com> <Xns98EEAB7C7DA52anonymoushotmailcom@207.105.83.66> <45f1ffc0$1@newsgroups.borland.com> Message-ID: <Xns98EF8B2886544anonymoushotmailcom@207.105.83.66> User-Agent: Xnews/5.04.25 NNTP-Posting-Host: 68.0.56.152 Date: 10 Mar 2007 11:40:12 -0800 X-Trace: newsgroups.borland.com 1173555612 68.0.56.152 (10 Mar 2007 11:40:12 -0800) Lines: 46 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail