I want to make a debug macro with a variable list of arguments, like this :
DEBUG "eax = %d, value = %d", eax, value
or
DEBUG "Debug message"
I've tried this code :
It doesn't work and I'm not comfortable with macro. Any help appreciated. Thanks !
DEBUG "eax = %d, value = %d", eax, value
or
DEBUG "Debug message"
I've tried this code :
DEBUG MACRO fmt:REQ, vars:VARARG
; from huh's macro
LOCAL TxtName
IFDEF __DEBUG
; avoid multiple definitions
IFNDEF __DEBUG_MACRO__
.DATA
__DEBUG_MACRO_BUFFER BYTE 512 DUP (?)
__DEBUG_MACRO_TITLE BYTE "Debug", 0
__DEBUG_MACRO__ = 1
.CODE
ENDIF
; huh's macro
.DATA
TxtName BYTE fmt,0
.CODE
pushad
; clear buffer
push eax
push ecx
push edi
xor eax, eax
mov ecx, 512/4
mov edi, offset __DEBUG_MACRO_BUFFER
rep stosd
pop edi
pop ecx
pop eax
IFB vars
; write message directly
INVOKE MessageBox, NULL, OFFSET fmt, OFFSET __DEBUG_MACRO_TITLE, MB_OK
ELSE
; use wsprintf and write message
INVOKE wsprintf, OFFSET TxtName, vars
INVOKE MessageBox, NULL, OFFSET TxtName, OFFSET __DEBUG_MACRO_TITLE, MB_OK
ENDIF
popad
ENDIF
ENDM
It doesn't work and I'm not comfortable with macro. Any help appreciated. Thanks !
This works here:
DEBUG MACRO fmt:REQ, vars:VARARG
; from huh's macro
LOCAL TxtName
IFDEF __DEBUG
; avoid multiple definitions
IFNDEF __DEBUG_MACRO__
.DATA
__DEBUG_MACRO_BUFFER BYTE 512 DUP (?)
__DEBUG_MACRO_TITLE BYTE "Debug", 0
__DEBUG_MACRO__ = 1
.CODE
ENDIF
; huh's macro
.DATA
TxtName BYTE fmt,0
.CODE
pushad
; clear buffer
push eax
push ecx
push edi
xor eax, eax
mov ecx, 512/4
mov edi, offset __DEBUG_MACRO_BUFFER
rep stosd
pop edi
pop ecx
pop eax
IFB <&vars>
; write message directly
INVOKE MessageBox, NULL, ADDR TxtName, ADDR __DEBUG_MACRO_TITLE, MB_OK
ELSE
; use wsprintf and write message
INVOKE wsprintf, ADDR __DEBUG_MACRO_BUFFER, ADDR TxtName, &vars
INVOKE MessageBox, NULL, ADDR __DEBUG_MACRO_BUFFER, ADDR __DEBUG_MACRO_TITLE, MB_OK
ENDIF
popad
ENDIF
ENDM
:alright: Thanks !