hey, i'm trying to make a simple program that closes all of aim instant messages really quick

i'm having trouble comparing (i'm not that great @ c++ or asm, i'm coming from starting out & using vb for a long time) or getting the classname of the window and checking it with the "iMClass"

i'm not sure if i got the buffer size right, etc.

like, the string has to end in a null character ",0", so is that part of the size of the string?

and am i making the write jump (in italics) to skip closing the window

.386

.model flat, stdcall

includelib \masm32\lib\kernel32.lib
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
include \masm32\include\user32.inc

EWP PROTO :DWORD,:DWORD

.data
iMClass db "AIM_IMessage",0

.data?
CBuffer db 13 dup(?)

.const
WM_CLOSE equ 10h

.code
start:

invoke EnumWindows,addr EWP,0

EWP PROC hWnd:DWORD,lParam:DWORD
[b] invoke GetClassName,hWnd,addr CBuffer,13
invoke lstrcmp,addr CBuffer,addr iMClass
[i]jne notit[/i][/b]
invoke SendMessage,hWnd,WM_CLOSE,0,0
notit:
mov eax,1
ret
EWP ENDP

end start
Posted on 2002-03-19 19:08:17 by Xeek
everything looks good to me except this line:

CBuffer db 13 dup(?)

try changing it to:

CBuffer dd 13 dup(?)
Posted on 2002-03-19 20:02:05 by smurf
smurf, it ought to be "db". 13 is a fine size as well, large enough
to hold his wanted string + 0... doesn't need to be larger, at least
not if GetClassName fails on too small buffer (dunno if it does -
if not you could accidentally get AIM_IMessageLalaHat and do a
false ID (though it's pretty unlikely in this case I guess ;)).

Now... problems with the code. First, I suggest you add a
"invoke ExitProcess, 0" after the EnumWindows invoke. Otherwise
you'll fall through and end up executing your enumeration proc
(with garbage instead of correct parms). Also, as it is now, it
should eventually crash somewhere after the routine returns, if
not within the routine :).

If you read the API guide, you would see that lstrcmp returns:

If the string pointed to by lpString1 is less than the string pointed to by lpString2, the return value is negative. If the string pointed to by lpString1 is greater than the string pointed to by lpString2, the return value is positive. If the strings are equal, the return value is zero.

So, after the invoke to lstrcmp, do a "cmp eax, 0" or "test eax, eax"
followed by "a jnz notit". Or, if you prefer very easy to read code,


.IF EAX == 0
invoke SendMessage,hWnd,WM_CLOSE,0,0
.ENDIF
Posted on 2002-03-19 20:32:36 by f0dder
omg, thank you people :alright:
it worked

db is the shortcut for DWORD, i forget what dd is short for

nah, GetClassName won't error out if the buffer size is too small

here's the final source... compile it and stick it on your quick launch, that's where i have it. i get alot of instant messages all the time and this is as useful as the "Show Desktop" button
.386

.model flat, stdcall

includelib \masm32\lib\kernel32.lib
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
include \masm32\include\user32.inc

EWP PROTO :DWORD,:DWORD

.data
iMClass db "AIM_IMessage",0

.data?
CBuffer db 13 dup(?)

.const
WM_CLOSE equ 10h

.code
start:

invoke EnumWindows,addr EWP,0
invoke ExitProcess,0

EWP PROC hWnd:DWORD,lParam:DWORD
invoke GetClassName,hWnd,addr CBuffer,13
invoke lstrcmp,addr CBuffer,addr iMClass
cmp eax, 0
jnz notit
invoke SendMessage,hWnd,WM_CLOSE,0,0
notit:
mov eax,1
ret
EWP ENDP

end start
Posted on 2002-03-20 01:02:30 by Xeek

db is the shortcut for DWORD, i forget what dd is short for

Nah. db is short for declare/define/data (whatever) byte(s). dd is
dword(s).
Posted on 2002-03-20 01:12:50 by f0dder
Don't confuse dd with dw either: DW is *not* DWORD. DB = Define Byte, DW = Define Word, DD = Define Dword. You can use 'byte', 'word' and 'dword' as well instead of db, dw and dd.

Thomas
Posted on 2002-03-20 03:42:54 by Thomas