Advertisement

09.14.2007 at 04:47AM PDT, ID: 22828574
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

SetWindowsHookEx failing
Tags: setwindowshookex
Following on from my question at: http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_22828041.html

The call to SetWindowsHookEx function seems to be failing. I've checked the dllMain method doesn't seem to get called at any time either:

      BOOL WINAPI dllMain(HINSTANCE aHInstance, DWORD aReason, LPVOID aVoid){      
            MessageBox(0, "Start", "", 0);
            if(aReason==DLL_PROCESS_ATTACH){
                  hInstance=aHInstance;            
                  MessageBox(0, "On", "", 0);
            }
            if(aReason==DLL_PROCESS_DETACH){
                  removeKeyHook();
                  MessageBox(0, "Off", "", 0);
            }
            return true;
      }

Thanks,
Uni
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Unimatrix_001
Solution Provided By: jkr
Participating Experts: 2
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
09.14.2007 at 09:06AM PDT, ID: 19892775

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 09:10AM PDT, ID: 19892808

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 09:24AM PDT, ID: 19892921

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 09:27AM PDT, ID: 19892939

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 09:36AM PDT, ID: 19893027

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:05AM PDT, ID: 19893267

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:18AM PDT, ID: 19893377

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:19AM PDT, ID: 19893383

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:26AM PDT, ID: 19893459

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:47AM PDT, ID: 19893638

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:49AM PDT, ID: 19893661

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:50AM PDT, ID: 19893674

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 12:44PM PDT, ID: 19894600

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 07:27PM PDT, ID: 19896238

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
09.14.2007 at 09:06AM PDT, ID: 19892775

Rank: Guru

Looking at your code, I guess it fails because you pass incorrect HINSTANCE parameter to the SetWindowsEx function. This should be result of LoadLibrary function and not HINSTANCE passed to DllMain.
Try to get the same library handle using LoadLibrary. If this doesn't help, place hook callback function to separate Dll. Dll which is called by VB client belongs to this client process. For global hook, Windows needs to inject Dll to another processes, this is why LoadLibrary is used.

For most Windows API you can get additional error information by using GetLastError, this helps to find the reason of the fault.
 
09.14.2007 at 09:10AM PDT, ID: 19892808
Does that mean from the VB application I need to specifically call the dllMain method? If so, what do I put as the DWORD aReason and LPVOID aVoid parameters?
 
09.14.2007 at 09:24AM PDT, ID: 19892921

Rank: Guru

No, your VB code is OK. Dll hook code must be changed. WinMain is called by Windows when it loads Dll to a process address space.
Just change Dll code. First try to replace HINSTANCE parameter with result of LoadLibrary. In Dll you know Dll name, this should not be problem. If this doesn't help, move hook callback function to another Dll, load it using LoadLibrary and use handle returned by LoadLibrary in SetWindowsHookEx call.
 
09.14.2007 at 09:27AM PDT, ID: 19892939
>>Just change Dll code. First try to replace HINSTANCE parameter with result of LoadLibrary.
I don't call LoadLibrary inside the DLL?

>>If this doesn't help, move hook callback function to another Dll, load it using LoadLibrary and use handle returned by LoadLibrary in SetWindowsHookEx call.
This would mean I'd have a VB application and two DLL's???
 
09.14.2007 at 09:36AM PDT, ID: 19893027

Rank: Guru

I don't see any LoadLibrary call in your code.
Try this:

__declspec(dllexport) bool setKeyHook(){
      if(messageHook==NULL){
            HMODULE h = LoadLibrary("Hook.dll");
            HOOKPROC hProc = (HOOKPROC)GetProcAddress(h, "messageProc");
            messageHook=SetWindowsHookEx(WH_GETMESSAGE, hProc, h, 0);
            if(messageHook==NULL){
                  return false;
            }
      }
      return true;
}

If this still doesn't work, try to use second library.
Agan, please check return code and call GetLastError after every function.
 
09.14.2007 at 10:05AM PDT, ID: 19893267
This is getting quite confusing now...

>>I don't see any LoadLibrary call in your code.
That's because there isn't one...

My VB calls LoadLibrary on hook.dll to load the dll, why do I need to call:
    HMODULE h = LoadLibrary("Hook.dll");
from within the Hook.dll (which would load itself?) when it has already been loaded by the VB application.
 
09.14.2007 at 10:18AM PDT, ID: 19893377

Rank: Genius

Just store the HINSTANCE that is passed in the hook DLL's 'HINSTANCE' parameter and use that for 'SetWindowsHookEx()'.
 
09.14.2007 at 10:19AM PDT, ID: 19893383

Rank: Genius

... or use

HINSTANCE hInst = GetModuleHandle("hook.dll");

which will return the same information.
 
09.14.2007 at 10:26AM PDT, ID: 19893459
Hi jkr,

Thanks, that works wonderful. :) Do I need the dllMain method then, as the "start" message doesn't even fire (see code at the top of this page)?

Uni.
 
09.14.2007 at 10:47AM PDT, ID: 19893638

Rank: Genius

Actually, you should make that a 'DllMain()', the 1st 'D' has to be capital..
 
09.14.2007 at 10:49AM PDT, ID: 19893661
>>Actually, you should make that a 'DllMain()', the 1st 'D' has to be capital..
:S I thought the method name was irrelevant and it matched the method by the paramters and return type???

Although even so, do I require it?

Thanks,
Uni
 
09.14.2007 at 10:50AM PDT, ID: 19893674
Also, do I need to add 'extern "C" __declspec(dllexport)' to it and do I need to specifically call it from the VB app?
 
09.14.2007 at 12:44PM PDT, ID: 19894600

Rank: Genius

No, the case must match. Let me put it like that: A DLL entry point has some advantaged, so it won't hurt to have one. However there are some limitations about what you are allowed to do there. I have the habit to add one, even if only for debugging purposes. And no, no need to export it nor to call it directly, the system loader will do that for you.
Accepted Solution
 
09.14.2007 at 07:27PM PDT, ID: 19896238
Thank you. :)
 
 
20080236-EE-VQP-29 / EE_QW_1_20070628