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
Mild critique:
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:
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.I dun mind critique. But thanks anyway BitRake. btw I added mov ecx,eax just for fun.. :p
hi, roticv try!
Try:
you dont need do write "ErrorMessage ENDM", please try without the macroname before ENDM
Greets !
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 !
Why did you write a macro for this? That is the question you should be asking yourself.