I have a question, may be some one can help me, please!
I am writing a window hook that hook WH_GETMESSAGE.
My hook's job is display only 1 character 00E1h (Unicode).

It's working very good with all most Win32 Apps but in Microsoft Word or Excel when I type "a" and after that type "1".
It process 6 characters, what is going on here? Who can help me please!
Microsoft Word and Excel and Access can not hook by WM_CHAR and WM_KEYDOWN?

;My source code here:

.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
includelib \masm32\lib.net\user32.lib
includelib \masm32\lib.net\kernel32.lib

include \masm32\include-unicode.net\user32.inc
include \masm32\include-unicode.net\kernel32.inc


hInstance dd 0
edit1 word 0

hHook dd ?
hWnd dd ?
VNF dw 1 DUP (?)


DllEntry proc hInst:HINSTANCE,reason:DWORD,reserved1:DWORD

mov [VNF],00E1h;a1

push hInst
pop hInstance
mov eax,TRUE
DllEntry endp
KeyProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD

mov ebx,lParam
assume ebx:PTR MSG
.IF nCode>=0

.IF [ebx].message==WM_CHAR
push [ebx].wParam
pop eax
mov edit1,ax
.ELSEIF [ebx].message==WM_KEYDOWN

.IF [ebx].wParam==VK_1
.IF edit1=="a"
push VNF
pop ax
invoke PostMessage,[ebx].hwnd,WM_CHAR,ax,1
mov [ebx].wParam,0
mov edit1,0

invoke CallNextHookEx,hHook,nCode,wParam,lParam
KeyProc endp

InstallHook proc hwnd:DWORD
push hwnd
pop hWnd
invoke SetWindowsHookEx,WH_GETMESSAGE,ADDR KeyProc,hInstance,0
mov hHook,eax
InstallHook endp


UninstallHook proc
invoke UnhookWindowsHookEx,hHook
UninstallHook endp


End DllEntry
Posted on 2002-09-19 23:57:26 by nhnpresario
Since you're dealing with global hook, the hook procudure should reside in a dll.
Posted on 2002-09-20 03:53:48 by C.Z.
^_^ :)

as you can see, this is my DLL entry.
I installed it in DLL - > Global DLL that effect all the system.

ml /c /Cp /coff abc.asm
link /SECTION:.bss,S /DLL /DEF:asm.def /SUBSYSTEM:WINDOWS abc.obj

My caller to this DLL is another EXE program.
I said it run but had no effect to WORD and EXCEL of Microsoft.
...exactly It had wrong EFFECT with MS WORD and EXCEL.
This dll is good with notepad, wordpad...
Posted on 2002-09-20 04:28:30 by nhnpresario
Didn't see that :grin:

I suppose Word and Access don't process WM_CHAR at all, they only deal with WM_KEYDOWN(UP). In fact this happens to IE as well, that you can't simply post a WM_CHAR message and expect it to be processed.

You have to post a WM_KEYDOWN and a WM_KEYUP. Please also notice the flags in lParam - I saw you passed 1 for this parameter, which may likely cause problems.
Posted on 2002-09-20 04:49:01 by C.Z.
.ELSEIF [ebx].message == WM_KEYDOWN

.IF [ebx].wParam == VK_1
.IF edit1 == "a"
[COLOR=red] .if wParam == PM_REMOVE[/COLOR]
push VNF
pop ax
invoke PostMessage, [ebx].hwnd, WM_CHAR, ax, 0
mov [ebx].wParam, 0
[COLOR=red] .endif[/COLOR]
Posted on 2002-09-20 07:30:49 by Four-F
Thanks a lot!
It's working perfectly.

I want to say thank you again.
Posted on 2002-09-21 05:26:57 by nhnpresario