I was wondering what is wrong with my macro... the assembler keep giving me an error. hope there is someone out there that would help me on it. Thanks
ErrorMessage macro

DWORD lpmsg;string pointer
call GetLastError
mov ecx,eax
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax, LANG_NEUTRAL,ADDR lpmsg,0,NULL
invoke MessageBox, NULL, lpmsg, 0, MB_OK
ErrorMessage endm
Posted on 2002-07-14 04:26:14 by roticv
Mild critique:
ErrorMessage macro

DWORD lpmsg;string pointer

It is not good to place DWORDs in the middle of the instruction stream. We have to tell MASM that the DWORD goes in the un-initialized data section, and we only need one DWORD for all the times this macros will be put in the code. Replace with the following:
	IFNDEF ErrorMessage_lpmsg

.data?
; handy and unique name because it is global
ErrorMessage_lpmsg dd ?
.code
ENDIF
we continue...
	call	GetLastError

mov ecx,eax
This last line seems to have no purpose. ;)
	invoke	FormatMessage, \

FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, \
NULL, eax, LANG_NEUTRAL, \
ADDR ErrorMessage_lpmsg, 0, NULL
invoke MessageBox, NULL, ErrorMessage_lpmsg, 0, MB_OK
ErrorMessage endm
You almost had it. :) IIRC, you have to free the memory that FormatMessage allocated for the message.
Posted on 2002-07-14 06:12:55 by bitRAKE
I dun mind critique. But thanks anyway BitRake. btw I added mov ecx,eax just for fun.. :p
Posted on 2002-07-14 10:15:36 by roticv
hi, roticv try!

Try:



ErrorMessage macro
[...]
endm ;shitty god, please help to to do the error never again.:rolleyes:

you dont need do write "ErrorMessage ENDM", please try without the macroname before ENDM

Greets !
Posted on 2003-10-11 03:07:57 by Bubu-Boy
Why did you write a macro for this? That is the question you should be asking yourself.

Posted on 2003-10-11 10:43:52 by Sephiroth3