I suspect that this has already done by someone somewhere, but in my quick search I didn’t find anything similar, so…
This macro allows you to paste a C statement, that uses the DEFINE_GUID macro (see Guiddef.h) to define a GUID, directly in your code or data section without modification. There is no need to translate the hex notation, replace the parentheses with angle brackets/curly braces or place angle brackets/curly braces around the last 8 fields, or even remove the statement separator at the end.
This macro ensures that the statement uses C hex notation for every field, but does not test for any other problems. And note that it has NOT been thoroughly tested.
;========================================================================================================
include \masm32\include\masm32rt.inc
;========================================================================================================
DEFINE_GUID MACRO _name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8
guiddef equ <_name GUID {>
val equ <>
n = 0
FOR arg,<l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8>
pre SUBSTR <arg>,1,2
IFDIFI pre,<0x>
ECHO -----------------------------------------
ECHO ERROR 0x PREFIX ON INITIALIZERS REQUIRED
ECHO -----------------------------------------
.ERR
ENDIF
val SUBSTR <arg>,3
IF n LT 10
val CATSTR <0>,val,<h>,<,>
ELSE
val CATSTR <0>,val,<h>
ENDIF
guiddef CATSTR guiddef,val
IF n EQ 2
guiddef CATSTR guiddef,<{>
ENDIF
n = n + 1
ENDM
guiddef CATSTR guiddef,<}}>
curseg TEXTEQU @CurSeg
;% echo curseg
.data
align 16
guiddef
@CurSeg ENDS
curseg SEGMENT
EXITM <>
ENDM
;========================================================================================================
.data?
buffer db 100 dup(?)
.data
IID_IDebugControl0 GUID <5182E668h,105Eh,416Eh,<0ADh,92h,24h,0EFh,80h,4,24h,0BAh>>
DEFINE_GUID(IID_IDebugControl1,0x5182e668,0x105e,0x416e,0xad,0x92,0x24,0xef,0x80,0x04,0x24,0xba);
IID_IDebugControl3 GUID <5182E668h,105Eh,416Eh,<0ADh,92h,24h,0EFh,80h,4,24h,0BAh>>
.code
;========================================================================================================
start:
;========================================================================================================
;-----------------------------------------------------------------------
; With the original coding the macro switched back to the code section,
; instead of preserving and then restoring the current section, and the
; following statements displayed:
; 403000h
; 401000h
; So obviously IID_IDebugControl3 was not where I intended it to be :)
;-----------------------------------------------------------------------
printf("%Xh\n", ADDR IID_IDebugControl0)
printf("%Xh\n\n", ADDR IID_IDebugControl3)
DEFINE_GUID(IID_IDebugControl2,0x5182e668,0x105e,0x416e,0xad,0x92,0x24,0xef,0x80,0x04,0x24,0xba);
invoke StringFromGUID2, ADDR IID_IDebugControl0, ADDR buffer, 50
printf("%d\t%S\n", eax, ADDR buffer)
invoke StringFromGUID2, ADDR IID_IDebugControl1, ADDR buffer, 50
printf("%d\t%S\n", eax, ADDR buffer)
invoke StringFromGUID2, ADDR IID_IDebugControl2, ADDR buffer, 50
printf("%d\t%S\n", eax, ADDR buffer)
invoke StringFromGUID2, ADDR IID_IDebugControl3, ADDR buffer, 50
printf("%d\t%S\n\n", eax, ADDR buffer)
inkey
exit
;========================================================================================================
end start
The curly braces on the returned string are added by StringFromGUID2.
403000h
403020h
39 {5182E668-105E-416E-AD92-24EF800424BA}
39 {5182E668-105E-416E-AD92-24EF800424BA}
39 {5182E668-105E-416E-AD92-24EF800424BA}
39 {5182E668-105E-416E-AD92-24EF800424BA}