News:

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

InString problem

Started by ecube, November 01, 2006, 11:08:20 PM

Previous topic - Next topic

ecube

i'm having trouble with InString in the masm32lib, it keeps returning true when it's not suppose to. The code below enums all top level windows looking for one that contains the word "Notepad" in it and if it finds it do a  messagebox. But since instring returns true regardless it's not working correctly, any help would be much appreciated


.486
.model flat, stdcall
option casemap:none


include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib


     CTEXT MACRO text:VARARG
            local TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
     ENDM

     EnumWindowsProc proto :DWORD, :DWORD

.code
start:
invoke EnumWindows,addr EnumWindowsProc,0
invoke ExitProcess,0

EnumWindowsProc proc hwnd:DWORD,lParam:DWORD
LOCAL szWinBuf[100]:BYTE
invoke GetWindowText,hwnd,addr szWinBuf,100
invoke InString,1,addr szWinBuf,CTEXT("Notepad")
.if eax>0 ;to bypass errors and a non-match
invoke MessageBox,0,addr szWinBuf,CTEXT("Notepad"),MB_ICONINFORMATION 
mov ecx,hwnd
mov eax,FALSE
ret
.endif

mov eax,TRUE
ret
EnumWindowsProc endp
end start

MichaelW

If notepad is not running, then InString is returning 0 or -1. The .IF statement is doing an unsigned comparison, so -1 is > 0. You can force a signed comparison by preceding eax with SDWORD PTR.
eschew obfuscation

ecube

Thankyou sir, your helps much appreciated