Sorry to mislead you.... ;)

I'm trying to hook the keyboard which is working fine, but I want to use the low-level hook, and I don't think it's working out too well. I'll show you what I mean:

KeyProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD
.IF nCode==HC_ACTION
.IF wParam == WM_KEYUP
.IF lParam.vkCode == VK_B ; this is the error line
invoke PostMessage,hWnd,WM_KEYHOOK,eax,wParam
.ENDIF
.ENDIF
.ENDIF
invoke CallNextHookEx,hHook,nCode,wParam,lParam
xor eax,eax
ret
KeyProc endp

InstallHook proc hwnd:DWORD
push hwnd
pop hWnd
invoke SetWindowsHookEx,WH_KEYBOARD_LL,addr KeyProc,hInstance,NULL
.IF eax==NULL
invoke MessageBox, NULL, addr fail, addr fail, MB_OK
.ENDIF
mov hHook,eax
ret
InstallHook endp

The error says "khook.asm(35) : error A2006: undefined symbol : vkCode"

But on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hooks_6fc3.asp

It says that lParam is a Pointer to a KBDLLHOOKSTRUCT structure. But it dosen't act that way! Or is it me? As a newbie, it is EXTREMELY possible I have done something to offend the program.

Your help is as always much appreciated.

-lackluster
Posted on 2001-10-13 00:04:03 by lackluster
Hi, lackluster!
You have to write like this:


mov edx, lParam
assume edx: ptr KBDLLHOOKSTRUCT
.if [edx].vkCode == VK_B
;do something
.endif
assume edx: nothing

Standard windows.inc doesn't contain the structure KBDLLHOOKSTRUCT.
Posted on 2001-10-13 00:37:40 by vkim
what exactly does "assume" do? In that code it looks like you could just "mov edx, ADDR KBDLLHOOKSTRUCT"

I don't get it.
Posted on 2001-10-13 02:01:53 by Kenny
ASSUME tells MASM to treat the indicated register as the base address for a given structure. From then on, that register can be used together with a dot ('.') to access the structure's members and so on and so forth :)

Latigo
Posted on 2001-10-13 04:45:05 by latigo
Thanks alot. The code worked like a charm, and I had added the STRUCT previous to my orginal post (that's what I thought the problem was). I suppose I should back and read my AOAL Book a little more. Does it ever frustrate you guys that the chapters are not labeled? It goes CHAPTER1, CHAPTER2, CHAPTER3 ....... Instead of INTRODUCTION, COMPUTER ORGANIZATION, BINARY ALGEBRA......? Anyways, thanks.
Posted on 2001-10-13 13:24:51 by lackluster
hmm okie thanks latigo! I guess I'd been doing it the hard way the whole time :)
Posted on 2001-10-13 16:14:01 by Kenny
does the following code



mov edx, lParam
assume edx: ptr KBDLLHOOKSTRUCT
.if [edx].vkCode == VK_B
;do something
.endif
assume edx: nothing


equivalent to



mov ebx,lParam
.if KBDLLHOOKSTRUCT.vkCode[ebx] == VK_B
;do something
.endif


or not?
Posted on 2001-10-14 05:45:53 by doby
Doby: No it's not :)

The first one is the syntax you need here, the second one would be used if you had a variable called KBDLLHOOKSTRUCT of type X, where X is declared as

X STRUCT
vkCode WORD 200 dup (?)
X ENDS
Posted on 2001-10-14 10:52:09 by Qweerdy
Qweerdy: may be i misunderstand but why my following code work?



ChildData STRUCT
hWndREdit DWORD ?
ChildData ENDS
.
.
.
.
invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, sizeof ChildData
mov pChildData, eax
mov ebx, eax
invoke SetWindowLong, hChild, 0, eax
invoke LoadLibrary,ADDR REditLibName
invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
ADDR REditClass,NULL,\
WS_MAXIMIZE or WS_CHILDWINDOW or ES_MULTILINE or\
ES_SAVESEL or WS_VSCROLL or WS_HSCROLL or ES_AUTOHSCROLL or\
ES_AUTOVSCROLL or ES_NOHIDESEL,\
0,0,100,100,hChild,NULL,hInstance,NULL
mov ChildData.hWndREdit[ebx],eax
invoke SetFocus,ChildData.hWndREdit[ebx]
invoke ShowWindow,ChildData.hWndREdit[ebx],SW_SHOWMAXIMIZED
Posted on 2001-10-14 12:48:05 by doby
doby,
the code


mov edx, lParam
assume edx: ptr KBDLLHOOKSTRUCT
.if [edx].vkCode == VK_B
;do something
.endif
assume edx: nothing

is equivalent to


.if (KBDLLHOOKSTRUCT ptr [edx]).vkCode == VK_B
;do something
.endif
Posted on 2001-10-14 21:24:17 by vkim
And I think your code is cleaner, vkim :).
Posted on 2001-10-14 23:01:03 by f0dder
ahh, that's good way vkim :)
Posted on 2001-10-15 05:16:31 by doby
doby,
the second way is not always good, because You have to write too much sometimes. For instance,


.if ((KBDLLHOOKSTRUCT ptr [edx]).vkCode == VK_B) || (KBDLLHOOKSTRUCT ptr [edx].vkCode == VB_C)
mov ecx, (KBDLLHOOKSTRUCT ptr [edx]).flags
;and so on
.endif

Compare this with assume directive


assume edx: ptr KBDLLHOOKSTRUCT
.if ([edx].vkCode == VK_B) || ([edx].vkCode == VK_C)
mov ecx, [edx].flags
;and so on
.endif
assume edx: nothing
Posted on 2001-10-15 06:56:14 by vkim
I was really expecting more from this thread.
hehehe.... :)
Posted on 2001-10-15 17:26:40 by bitRAKE
Okay, now i will throw my question in....

how is this:

assume edx: ptr KBDLLHOOKSTRUCT

any different from using:

lea edx, KBDLLHOOKSTRUCT

i have been using the "lea..." method so that i can use the dot operator, does either of the methods have an advantage over the other?

sluggy
Posted on 2001-10-15 21:59:48 by sluggy


assume edx: ptr KBDLLHOOKSTRUCT

Means masm will assume edx holds the address of *a* KBDLLHOOKSTRUCT,
ie, a variable of the time KBDLLHOOKSTRUCT.



lea edx, KBDLLHOOKSTRUCT

Is wrong. It's correct for a variable, but KBDLLHOOKSTRUCT is a
type (as far as I can see ;)). Also, it doesn't tell masm that edx
will be pointing to a KBDLLHOOKSTRUCT type, so you can't do the
thingy. Also, "lea edx, "
is (imho) the cleaner way to write it.
Posted on 2001-10-15 22:17:30 by f0dder
Sorry, i should have been more precise..... I should have written something like this:

LOCAL blah : KBDLLHOOKSTRUCT
lea edx, blah


there is a negative to using this method, in order to use the dot operator to access the struct i still have to qualify the statement somewhat:

lea edx, blah
mov .KBDLLHOOKSTRUCT.member, 0

this is more typing, so i think i will be using the "assume" method from now on...


sluggy
Posted on 2001-10-15 22:26:48 by sluggy
Just remember to "unsassume" later on... not really necessary,
but it helps you avoiding bugs.
Posted on 2001-10-15 22:38:49 by f0dder