The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ecube on November 01, 2006, 11:08:20 PM

Title: InString problem
Post by: ecube on November 01, 2006, 11:08:20 PM
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
Title: Re: InString problem
Post by: MichaelW on November 02, 2006, 03:02:26 AM
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.
Title: Re: InString problem
Post by: ecube on November 02, 2006, 05:48:48 AM
Thankyou sir, your helps much appreciated