News:

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

Why does my computer hang with this code?

Started by port513, May 26, 2006, 01:43:28 PM

Previous topic - Next topic

port513

I tried an example from Iczelion about hooking the mouse, this is the code that hangs my computer

MouseProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD
   invoke CallNextHookEx,hHook,nCode,wParam,lParam
   mov edx,lParam
   assume edx:PTR MOUSEHOOKSTRUCT
   invoke WindowFromPoint,[edx].pt.x,[edx].pt.y
   invoke PostMessage,hWnd,WM_MOUSEHOOK,eax,0
   assume edx:nothing
   xor eax,eax
   ret
MouseProc endp

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

UninstallHook proc
   invoke UnhookWindowsHookEx,hHook
   ret
UninstallHook endp

it's not the complete code check TUTE24 to see the complete code.

My computer gets really slow when this hook is installed and after a few seconds it stops responding to everything. Why?


/Henrik

Ossa

I can't recreate the problem here... so just to check that we're working from the same code, I've attached the tutorial again, complete with binaries and more batch files for building them.

1) Try running the executable (without rebuilding the binaries)... if you still encounter the same problem, then it is some sort of difference between my system and yours that means it works for me and not you. If so, what system are you running (windows version, etc)?

2) Rebuild the binaries by first running the build.bat file in the DLL subfolder and then the build.bat file in the main folder. If (1) worked, but this doesn't then it must be something to do with different MASM versions. If so, what version of MASM/MASM32 are you using?

If it all works, then you are either building them wrong (so explain how you are doing it currently), or the code has been altered in some way that we can't fix without you posting the whole lot (preferably in a zip file).

Hope this helps a bit,
Ossa

Argh... the forum is saying that "The attachments upload directory is not writable. Your attachment or avatar cannot be saved."

will put it on my webspace shortly...

[edit] OK, it's up: http://web.mit.edu/rcassels/www/TUTE24.zip [/edit]
Website (very old): ossa.the-wot.co.uk

P1

port513,

Welcome a Board !!!        :U 

Forum 'Search' is your friend, along with Google.        :dance:

Please read the forum rules.    :eek

This code is to run from a dll.  And unless you know how to re-code to an .exe file properly, it will not run.

I suggest you use the dll approach for now, it's easier and works without doing much special with it.

Regards,  P1  :8)

port513

I know it's a DLL ;)

I tried to use that DLL in my own software and it's there my problem is.

The funny thing is that everything else seems right but as soon as I call InstallHook everything is slowed down.

If I run the compiled file ecerything works as it should.


/Henke

Ossa

Quote from: port513 on May 26, 2006, 03:15:02 PM
If I run the compiled file ecerything works as it should.

How about if you rebuild them?

If that still runs fine, then tell us all of the build options (command lines) that you are using and post the code that you have written to call it (strip out all of the other stuff if you want)... just give us some code that we can build that causes this problem - I doubt it is possible to help you if you don't do this.

Ossa
Website (very old): ossa.the-wot.co.uk

P1

port513,

Port Number: 513
TCP / UDP: TCP
Delivery: Yes
Protocol / Name: login,who

Grlogin
Port Description: who.'remote who, maintains data bases showing who's, bsd rwhod(8)'


Who are you?  Who, Who, I really want to know.   :green2

How did you come by your handle?

The support dll should be with the .exe as a pair.  So if you have built the dll in another directory, you will need to move it to where the .exe file is.

Regards,  P1  :8)

port513

By mistake I used SendMessage intstead of PostMessage ;)

But now another weird thing.

If I use this working DLL with a new program that should get every ClassName that the mouse is hovering over it only get classnames from the window that installed the hook. Why?

The TUTE24 get every classname.


/Henke

Ossa

This is to do with the comment I made on the temporary forum: You must share the data section using the /SECTION:sec_name,S linker switch.

I forget the name of the section you need to share (it might be the same as Iczelion, but I believe that doesn't work for all things now). Iczelion shares the .bss section, so his switch is /SECTION:.bss,S

Ossa

[edit] Fairly sure the .bss section is correct... but if it doesn't work, I'll have another look [/edit]
Website (very old): ossa.the-wot.co.uk

port513

Quote from: Ossa on May 26, 2006, 05:44:39 PM
This is to do with the comment I made on the temporary forum: You must share the data section using the /SECTION:sec_name,S linker switch.

I forget the name of the section you need to share (it might be the same as Iczelion, but I believe that doesn't work for all things now). Iczelion shares the .bss section, so his switch is /SECTION:.bss,S

Ossa

[edit] Fairly sure the .bss section is correct... but if it doesn't work, I'll have another look [/edit]

It's .bss ;)

By using SendMessage I crashed my poor XP ;)

I'm a C++, C# programmer so I'm not used to MASM right now ;)


/Henke

PBrennick

Port513,
So with your new assembly program you crashed your machine?  It is a rite of passage.  You are now, officially, an assembly language programmer.  Welcome to the club.  If I had a nickel for every time I crashed a PC, I would be able to afford to buy gasoline!

Paul
The GeneSys Project is available from:
The Repository or My crappy website

port513

Quote from: PBrennick on May 26, 2006, 07:27:34 PM
Port513,
So with your new assembly program you crashed your machine?  It is a rite of passage.  You are now, officially, an assembly language programmer.  Welcome to the club.  If I had a nickel for every time I crashed a PC, I would be able to afford to buy gasoline!

Paul


I know it's very easy to take a computer down with low level programming ;)

But that's what we have to pay to have 100% controll over what the computer is doing ;)


/Henke

PBrennick

Henke,
That is correct, I just wanted to make sure that it does not discourage you.  Also, even the best low level programmer has to debug for errors.  They are just too easy to make so don't feel that your problems are unusual and don't be afraid to bring them here.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

port513

Quote from: PBrennick on May 26, 2006, 08:25:59 PM
Henke,
That is correct, I just wanted to make sure that it does not discourage you.  Also, even the best low level programmer has to debug for errors.  They are just too easy to make so don't feel that your problems are unusual and don't be afraid to bring them here.

Paul


You will see some silly questions from me, that's for sure ;)


/Henke