The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: jj2007 on June 17, 2008, 01:24:09 PM

Title: Masm bug? Macro not working when called as first instruction after Start:
Post by: jj2007 on June 17, 2008, 01:24:09 PM
Just made a strange discovery. The code below works perfectly. However, try...

start: .if EXIST(addr FindMe)

... instead of ...

start:
.if EXIST(addr FindMe)


Is this a known bug?

.nolist
include \masm32\include\masm32rt.inc

EXIST MACRO fname:REQ, DiscardHandle:=<1>
invoke FindFirstFile, reparg(<fname>), addr wfd
.if eax==INVALID_HANDLE_VALUE
xor eax, eax
.elseif DiscardHandle
invoke FindClose, eax
.endif
EXITM <eax>
ENDM

.data?
wfd WIN32_FIND_DATA <?>

.data
FindMe db "\masm32\OllyDbg\OLLYDBG.EXE", 0
FileEx db "The file exists:", 0
NoFile db "The file does NOT exist:", 0

.code
start:
.if EXIST(addr FindMe)
invoke MessageBox, 0, addr FindMe, addr FileEx, MB_OK
.else
invoke MessageBox, 0, addr FindMe, addr NoFile, MB_OK
.endif
invoke ExitProcess, 0
end start

[attachment deleted by admin]
Title: Re: Masm bug? Macro not working when called as first instruction after Start:
Post by: qWord on June 17, 2008, 02:38:29 PM
hi,

i don't think this is a bug. The code in EXIST()-macro will be created before the entrypoint. The reason for this is that masm expand macros before the current line.

regards qword

Title: Re: Masm bug? Macro not working when called as first instruction after Start:
Post by: jj2007 on June 17, 2008, 02:50:04 PM
Good to know, thanks a lot!