News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Why SetDlgItemText doesn't work?

Started by xiahan, April 11, 2012, 05:35:48 PM

Previous topic - Next topic

xiahan



.if HookFlag==FALSE
invoke InstallHook,hDlg
.if eax!=NULL
   mov HookFlag,TRUE
   invoke SetDlgItemText,hDlg,IDC_HOOK,addr UnhookText
.endif
.else
invoke UninstallHook
invoke SetDlgItemText,hDlg,IDC_HOOK,addr HookText
mov HookFlag,FALSE
invoke SetDlgItemText,hDlg,IDC_HANDLE,NULL
invoke SetDlgItemText,hDlg,IDC_WNDPROC,NULL
.endif


when the user click "UnHook" the edit control doesn't been clear

dedndave

invoke SetDlgItemText,hDlg,IDC_HOOK,addr HookText

you can't set the text of a hook   :P
where you have IDC_HOOK, you put in the dialog control ID of the control or window that you want to set text for
SetDlgItemText is handy when you do not have the control handle stored someplace, because you can reference it by ID

if you have the handle of the window or control, use SetWindowText
        INVOKE  SetWindowText,hWnd,offset szText
for windows that have a caption bar, it sets the caption text
for windows or controls that do not have a caption bar (like a button or static control), it sets text inside the window

xiahan

IDC_HOOK is a ID of a button

in the souce code, the edit control carries ES_READONLY style, but the forwards set/getDlgItemText been execute successfully, just these calls can not do their work

i don't know this happening,but it did happen.

the return value of the SetDlgItemText isn't zero,it means it didn't fail

but just didn't clear the edit control

dedndave

ok - that might work   :P

invoke SetDlgItemText,hDlg,IDC_HANDLE,NULL
invoke SetDlgItemText,hDlg,IDC_WNDPROC,NULL

i think these will crash - you need to point to some text, even if it's a null string

szNull db 0
        INVOKE  SetDlgItemText,hDlg,IDC_HANDLE,offset szNull
        INVOKE  SetDlgItemText,hDlg,IDC_WNDPROC,offset szNull

i could be wrong on that one   :bg

shortcut method...
        push    0
        INVOKE  SetDlgItemText,hDlg,IDC_HANDLE,esp
        INVOKE  SetDlgItemText,hDlg,IDC_WNDPROC,esp
        pop     ecx

xiahan

i have test use this


szText db " ",0

  .....

   invoke SetDlgItemText,hDlg,IDC_WNDPROC,addr szText



but the result just persists,the edit control didn't been clear

xiahan



shortcut method...
        push    0
        INVOKE  SetDlgItemText,hDlg,IDC_HANDLE,esp
        INVOKE  SetDlgItemText,hDlg,IDC_WNDPROC,esp
        pop     ecx

Quote

nice trick! :U

dedndave

ok - you're going to have to show us more code

here is my guess....
that code is never being executed
i.e., you are not properly intercepting the pushed button message
if it did execute, i think the program would crash with 0xc0000005 error

xiahan

i have uploaded the source code , see the zip

xiahan

Quote from: dedndave on April 11, 2012, 06:31:15 PM
ok - you're going to have to show us more code

here is my guess....
that code is never being executed
i.e., you are not properly intercepting the pushed button message
if it did execute, i think the program would crash with 0xc0000005 error

i manually add some code like this


.else
invoke UninstallHook
invoke SetDlgItemText,hDlg,IDC_HOOK,addr HookText
mov HookFlag,FALSE
invoke SetDlgItemText,hDlg,IDC_HANDLE,NULL

invoke MessageBox,hDlg,0,0,MB_OK  ;ADD CODE
invoke SetDlgItemText,hDlg,IDC_WNDPROC,NULL
.endif

the MSGBOX executed,but the edit control always display the last class name

xiahan

It has already 3:00 am in China, I got to sleep now, wait for your good analysis :toothy

dedndave

#10
ok
let me start by saying...
Iczelion's tutorials are kind of old   :P
they have not been kept up to date, as the masm32 package has been updated
so, some things need a little clean-up just to make it compatible
that includes adding the resource.h file to the resource file

another thing - the name of the DLL, LIB, and INC are "MouseHook"
it is best to name the project files something different - i chose "MHook"
i also made a little batch file to build it - just click on the BAT file and it does everything - much faster for testing code

and - it appears as though the SetDlgItemText function can have a NULL pointer - it is not documented that way
let me tell you - many functions will crash if you do that   :bg

once i got the thing to assemble, the Hook/Unhook button text worked ok
but - the edit text boxes were not being cleared out

well - what was really happening - they were being cleared out, then set back to the buffer value
it seems as though you have a WM_MOUSEHOOK message still in the message queue   :P
i fixed that by adding a test on HookFlag...
    .elseif uMsg==WM_MOUSEHOOK
        .if HookFlag==TRUE
            ;do stuff
        .endif
    .elseif.........


it seems to work fine, now
interesting little project   :P
set the hook, then move the mouse around over different windows and controls

we need to update the Iczelion package
it is for newcomers - who really can't be expected to work through these kinds of issues

xiahan

i download the MHook.zip

it works fine, :U

one more question,when is the mousehook.dll  loaded into the calling process,

and when is it  mapped into other process's 2GB address?




dedndave

when you run the program, the operating system loads it
if it is not registered, it will look for the DLL in the current folder, then in the system folder (C:\Windows\System32)
you may register the file, then the OS looks in a specific location

xiahan




.data
hInstance dd 0

  ....

InstallHook proc hwnd:DWORD
push hwnd
pop hWnd
invoke SetWindowsHookEx,WH_MOUSE,addr MouseProc,hInstance,NULL
mov hHook,eax
ret
InstallHook endp



for this function in the mousehook.dll, when it is called, who is the hInstance's owner?

dedndave

the process module is the "instance handle"
if you call GetModuleHandle with a parameter of 0, it returns the handle for the current process

when the DLL is loaded, the OS calls the entry point function - this is the simple form of a DLL
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD
        push    hInst
        pop     hInstance
        mov     eax,TRUE
        ret
DllEntry Endp

it is refering to the module handle for the DLL

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583%28v=vs.85%29.aspx