Article View: borland.public.cppbuilder.nativeapi
Article #68Re: Setting (and losing) a keyboard hook
From: salamander1965
Date: Thu, 19 Jun 2008 13:15
Date: Thu, 19 Jun 2008 13:15
39 lines
3208 bytes
3208 bytes
Here's some additional information that might be useful if you're looking at the code in the original post. I put in some MessageBox() calls in the DllEntryPoint() function of the DLL -- one to report when the DLL_PROCESS_ATTACH case block executed, one in the DLL_PROCESS_DETACH block, and one in the if() block that detects when the nRefCount variable is 0 and calls DetachKeyboardHook(). Each message box reports the section of the code being executed as well as the ID of the process attaching to/detaching from the DLL and the value of the shared nRefCount variable. When several instances of the main application are started, the message boxes appear as would be expected with appropriate process ID and nRefCount values, so that part of the code seems to be working as expected. The message box for detaching the hook itself only appears at the very end, as expected. I mentioned in the original post that there seems to be something 'special' about the first instance of the application to load the DLL. With the message boxes in place, it seems that after the first instance of the application attaches to the DLL, Explorer then attaches also. This occurs under Windows 2000 and Windows XP, so I'm assuming it's normal, although I don't understand why this is happening. Subsequent instances of the application attach to the DLL normally, but Explorer does not attach again -- only attaching the first time the DLL is loaded. When the application instances are terminated, again everything seems to occur as expected, but when the instance that was started first terminates (regardless of when it's terminated compared to the other instances), Explorer immediately detaches from the DLL, too. After this is when the hook apparently stops working. Maybe the association of Explorer with the first loading of the DLL is what is special about the first instance of the application, although I do not have enough experience with DLL's or hooks in general to even guess what might be going on. Hopefully this might make sense to someone with more experience. -- Steve
Technical Details
Message-ID:
<485a5bc6$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed.freenet.de!ecngs!feeder2.ecngs.de!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4859926a@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,21bdbb7b8038a591 X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 19 Jun 2008 09:15:01 -0400 From: salamander1965 <salamander1@verizon.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Setting (and losing) a keyboard hook References: <4859926a@newsgroups.borland.com> In-Reply-To: <4859926a@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 205.149.71.160 Message-ID: <485a5bc6$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1213881286 205.149.71.160 (19 Jun 2008 06:14:46 -0700) Lines: 39 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed.freenet.de!ecngs!feeder2.ecngs.de!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail