======== Path: news.idiom.com!nntp2.ba.best.com!news1.best.com!nntprelay.mathworks.com!howland.erols.net!cpk-news-hub1.bbnplanet.com!su-news-hub1.bbnplanet.com!news.bbnplanet.com!news.Stanford.EDU!nntp.Stanford.EDU!not-for-mail From: "Sylvan W. Clebsch" Newsgroups: comp.os.ms-windows.programmer.win32 Subject: Re: Subclassing WndProc in another process Date: Wed, 6 Aug 1997 13:46:07 -0700 Organization: Stanford University Lines: 48 Message-ID: <5sano7$eqr$1@nntp.Stanford.EDU> References: <33E80031.D777E152@deltanet.com> NNTP-Posting-Host: xevious.stanford.edu Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft Outlook Express 4.71.1008.3 X-MimeOle: Produced By Microsoft MimeOLE Engine V4.71.1008.3 Xref: news.idiom.com comp.os.ms-windows.programmer.win32:30851 >I create a systemwide hook with SetWindowsHookEx, but the hook function >is never called (at least not in NT). a couple of things about system wide hooks: 1) they have to be in a DLL in order to work 2) remember you have to supply the library handle OR the module handle, and a thread ID of 0 my personal approach to hooks is to place them in a DLL along with their "startup" functions. that why i can link directly to the DLL in my app and not LoadLibrary on it. i call the "startup" function from my app, which internally calls something like: HHOOK hHook = SetWindowsHookEx( WH_CBT, // the type of hook (HOOKPROC)HookProc, // the filter function (HMODULE)GetModuleHandle( "DLLNAME.DLL" ), // DLL module handle NULL // zero to install it system wide ); note that if you put a breakpoint on it, you will only break when it is called from your app, not when its called from the rest of the system. also, for system wide hooks don't forget to make sure any global data you need to be shared system wide is placed in a shard data segment. you will need to do the following: #pragma data_seg( ".SHARDATA" ) int someSharedInt #pragme data_seq() that goes right in your source module. in addition, you will need a .def file (normally not needed for a 32bit DLL since you can just use __declspec(dllexport), but now you need one, heheh). add this to your module definition file: SECTIONS .SHARDATA Read Write Shared that should do it. i hope this helps. -s