Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Keyboard hook... Posted by illuminator on 15 Jan 2003 at 12:42 AM
Hi,

this function is called:

void SetKBHook(void)
{
KH1 = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KHookProc,hInst,0L);
}

KH1 is 0, why? :(
-hInst is my app instance
-KHookProc is the correct HookProc

hhheelllppp...

cu,

illuminator
(Novus ordo seclorum)
Report
Re: Keyboard hook... Posted by pingpong on 15 Jan 2003 at 6:14 AM
What OS? WH_KEYBOARD_LL does not work in 9x.

Also, is this in an EXE or DLL? Because passing an hInstance should be done only with system-wide hooks that reside in a DLL. For a local hook in an EXE use:
KH1 = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KHookProc, NULL, GetCurrentThreadId());

Which hooks the keyboard for the current process only.

: Hi,
:
: this function is called:
:
: void SetKBHook(void)
: {
: KH1 = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KHookProc,hInst,0L);
: }
:
: KH1 is 0, why? :(
: -hInst is my app instance
: -KHookProc is the correct HookProc
:
: hhheelllppp...
:
: cu,
:
: illuminator
: (Novus ordo seclorum)
:

Report
Thx !! :) Posted by illuminator on 17 Jan 2003 at 9:02 AM
Thx !! :)

cu,

illuminator
(Novus ordo seclorum)

Report
Additional question... Posted by illuminator on 20 Jan 2003 at 8:31 AM
Hi

1. Thx. Your code works. :)

2. Hm, i tried to convert it to VB.NET, works also, but this structure causes huge problems:

C:
typedef struct tagKBDLLHOOKSTRUCT {
DWORD vkCode;
DWORD scanCode;
DWORD flags;
DWORD time;
DWORD dwExtraInfo;
} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;

VB.Net:
Public Structure KBDLLHOOKSTRUCT
Public vkCode As Integer
Public scanCode As Integer
Public flags As Integer
Public time As Integer
Public dwExtraInfo As Integer
End Structure
- Wrong :( Why?

PS: you guys are great! ;)



cu,

illuminator
(Novus ordo seclorum)

Report
Re: Additional question... Posted by pingpong on 20 Jan 2003 at 11:41 AM
This message was edited by pingpong at 2003-1-20 11:43:29

/edit Yikes, got my VB mixed up with C#. Why dont you use C# by the way?

You need the StructLayout attribute thingy..
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack = 1)> _
Public Structure KBDLLHOOKSTRUCT
   Public vkCode As Integer
   Public scanCode As Integer
   Public flags As Integer
   Public time As Integer
   Public dwExtraInfo As Integer
End Structure

So .NET wont mess around with it and tries to optimize it. The pack=1 is standard Win32 API stuff.

Dont know how are you going to make the LowLevelKeyboardProc work though, this might work:
<DllImport("kernel32.dll")> _
Public Shared Function LowLevelKeyboardProc(nCode As Integer, wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer

If it doesnt, it means that Windows is trying to send a NULL in the lParam, dont know how you fix that in VB.NET, in C# you can declare it as int lParam then do the appropriate cast in a fixed block.

Good luck.

: Hi
:
: 1. Thx. Your code works. :)
:
: 2. Hm, i tried to convert it to VB.NET, works also, but this structure causes huge problems:
:
: C:
: typedef struct tagKBDLLHOOKSTRUCT {
: DWORD vkCode;
: DWORD scanCode;
: DWORD flags;
: DWORD time;
: DWORD dwExtraInfo;
: } KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
:
: VB.Net:
: Public Structure KBDLLHOOKSTRUCT
: Public vkCode As Integer
: Public scanCode As Integer
: Public flags As Integer
: Public time As Integer
: Public dwExtraInfo As Integer
: End Structure
: - Wrong :( Why?
:
: PS: you guys are great! ;)
:
:
:
: cu,
:
: illuminator
: (Novus ordo seclorum)
:
:



Report
Re: Additional question... Posted by illuminator on 21 Jan 2003 at 12:39 AM
Hi

thx again! :)

<StructLayout(LayoutKind.Sequential)> _
Public Structure KBDLLHOOKSTRUCT
Public vkCode As Integer
Public scanCode As Integer
Public flags As Integer
Public time As Integer
Public dwExtraInfo As Integer
End Structure

"Pack = 1" was not accepted, because "StructLayout" only expects one parameter.

cu,

illuminator
(Novus ordo seclorum)




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.