Hi All

I am attempting to install a low level keyboard hook using the following calls:

HANDLE hDll = LoadLibrary(DLL_NAME);
LPVOID procAddress = GetProcAddress(hDll, "HookProc");
HHOOK wHook;

wHook = SetWindowsHookEx(WH_KEYBOARD_LL, procAddress, hDll, 0);

I have built a DLL containing HookProc define below:

__declspec (dllexport) LRESULT CALLBACK HookProc (int nCode, WPARAM wParam, LPARAM lParam)
{
     if(nCode < 0) 
	 { 
		 return CallNextHookEx(0, nCode, wParam, lParam); 
	 }
     
     if(nCode == HC_ACTION)
     {
          if(wParam == WM_KEYDOWN)
          {
			   printf("Keyboard Event Detected\n");
               return 1;
          }
          
     }
     return CallNextHookEx(0, nCode, wParam, lParam);
}

When I run my code; I get no run time errors and the values for Dll, procAddress and wHook returned seem reasonable (I don't get any NULLS) but my keyboard hook (HookProc) is never called.

Any thoughts on this matter would be greatly appreciated.

Regards

Steve

Normally code is wrapped between code tags, learn how to use them and increase your chances of being helped by the forum members :)

Normally code is wrapped between code tags, learn how to use them and increase your chances of being helped by the forum members :)

I have to ask myself; am I really interested in the posts of members who can't tell the difference between code and text.

commented: No, go away and puke on some other forum -7

I have to ask myself; am I really interested in the posts of members who can't tell the difference between code and text.

What are you trying to achieve with that?
I know: You don't want to be helped.
(Even if you 'formatted' your code in italic, it's very annoying to read, just wrap it in between code tags)

Hi All

I am attempting to install a low level keyboard hook using the following calls:

HANDLE hDll = LoadLibrary(DLL_NAME);
LPVOID procAddress = GetProcAddress(hDll, "HookProc");
HHOOK wHook;

wHook = SetWindowsHookEx(WH_KEYBOARD_LL, procAddress, hDll, 0);

I have built a DLL containing HookProc define below:

__declspec (dllexport) LRESULT CALLBACK HookProc (int nCode, WPARAM wParam, LPARAM lParam)
{
     if(nCode < 0) 
	 { 
		 return CallNextHookEx(0, nCode, wParam, lParam); 
	 }
     
     if(nCode == HC_ACTION)
     {
          if(wParam == WM_KEYDOWN)
          {
			   printf("Keyboard Event Detected\n");
               return 1;
          }
          
     }
     return CallNextHookEx(0, nCode, wParam, lParam);
}

When I run my code; I get no run time errors and the values for Dll, procAddress and wHook returned seem reasonable (I don't get any NULLS) but my keyboard hook (HookProc) is never called.

Any thoughts on this matter would be greatly appreciated.

Regards

Steve

What are you trying to achieve with that?
I know: You don't want to be helped.
(Even if you 'formatted' your code in italic, it's very annoying to read, just wrap it in between code tags)

I am trying to point out that your post was obnoxious. My default position to someone being obnoxious is to fire it straight back.

Next time maybe you could try: "Hi <enter a name>. I can see it is your first post. On this forum we highlight our code with code snippets, it makes it much easier for us to understand what you have posted. You can edit your post like this......"

Manners don't cost much, and you'll get a better response from people almost every time.

Cheesey,
You sure need to have a reading on this page. It is written by one of the most profound hacker, Eric S Raymond : How to ask question the smart way.
Please go and read it first before attempting to seek any help.
I specially like to quote a paragraph :

Never assume you are entitled to an answer. You are not; you aren't, after all, paying for the service. You will earn an answer, if you earn it, by asking a substantial, interesting, and thought-provoking question — one that implicitly contributes to the experience of the community rather than merely passively demanding knowledge from others.

You do not have any excuse that you didn't knew about code-tags. Information about code-tag is posted all over the website :
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in

commented: Agreed! +9
commented: Well said! +36
commented: hi chicken, I think u need ta work on yer grammer, or if u r having problems get someone ta read over your work, especially if ur gonna post it on the internet! tnx +21

Wow. I am amazed by your arogance. If you don't like the way I have posted just ignore it and move on. What's going on in your head that makes you feel you need to butt in on someone elses conversation and start quoting other peoples work. Seek help dude.

commented: Thats it. You crossed limits. Here are my "tomatoes and eggs" -2
commented: Strange: all your posts apply to yourself !! -2
commented: So, When Everyone does the same thing, Your Post is Un-Answered, There is something known as Internet Etiquette. +4
commented: I agree with the last sentence. +21

Cheesey, how about this. I know the exact problem you're facing, but I don't think I want to help you anymore.

Seems your attitude here isn't getting you anywhere.

commented: Works for me +36

Cheesey, how about this. I know the exact problem you're facing, but I don't think I want to help you anymore.

Seems your attitude here isn't getting you anywhere.

Problem Fixed. Thanks to all posters.

commented: You're welcome. +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.