Windows Develop Bookmark and Share   
 index > Windows Forms General > CBT Hook not working in Windows Vista
 

CBT Hook not working in Windows Vista

I am trying to use a CBT hook to receive HCBT_MOVESIZE notifications. It works fine for all applications when I run my program from a folder on my desktop. When I install the application to the "Program Files" or "Program Files (x86" folder I only receive notifications for my own application. I am having this problem in Windows Vista x86 and x64. The .exe file is signed and works perfectly in Windows XP. Can anyone offer any suggestions on how to troubleshoot this? Thanks!
Jon Tackabury  Monday, June 01, 2009 9:16 PM

In order to install a global hook, the program code that contains your hook procedure has to be injected by the operating system into the process of every running application. Since it's impossible to inject 32-bit code into a 64-bit process and visa versa, you have to create two DLLs, one 32-bit and one 64-bit, than you have to have a 32-bit process set the CBT hook to the 32-bit DLL and a 64-bit process set the CBT hook to the 64-bit DLL. Then you need a way for each of these DLLs to report back to your application (memory mapped files work very well).

Tergiver  Monday, June 01, 2009 9:44 PM
You can't write global hooks in a .NET language, neither on XP nor on Vista.

Hans Passant.
nobugz  Monday, June 01, 2009 10:32 PM

Show me your SetWindowsHookEx declaration and call. I'm beginning to wonder if CBT hook can even be global.

Tergiver  Monday, June 01, 2009 11:38 PM
@Tergiver: I have an x86 and x64 DLL, which are loaded depending on the OS version. The CBT hook can be global. Like I said in my post, it works perfectly fine until I run my application from the Program Files folder. I have no problems getting the CBT hook to work, it just doesn't work when launched from certain folders.

@nobugz: I know you can't write this in a .NET language, I wrote the DLL in unmanaged C++ and I'm using it in my .NET winforms application.

My problem boils down to this: Why can't I use a CBT hook in an application launched from the "Program Files" folder?
Jon Tackabury  Tuesday, June 02, 2009 1:02 AM
Remember that on 64-bit Vista, there are both 32 and 64-bit processes running. That's why you need both injection DLLs at the ready.

Is this UAC issue? Have you tried running from an administrator account with UAC turned off (just to eliminate both)?
Tergiver  Tuesday, June 02, 2009 2:17 AM

You can use google to search for other answers

Custom Search

More Threads

• "not statement" error - VS prob or what?
• RichTextBox truncates lines after about 5800 chars in VSTO (Excel)
• How to implement a multi threaded user interface ?
• The windows controls suck!
• Hepl : Image in Label
• How to add a Single alphabet as hotkey
• Disable window
• How to add non-selectable items into a combobox
• Desktop app with database
• Subclassed ToolStrip + Overriding OnPaint Event