### Author Topic: DEFINE_GUID macro  (Read 8667 times)

#### MichaelW

• Global Moderator
• Member
• Posts: 1204
##### DEFINE_GUID macro
« on: March 06, 2013, 07:10:32 PM »
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.
Code: [Select]
`;========================================================================================================    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.
Code: [Select]
`403000h403020h39      {5182E668-105E-416E-AD92-24EF800424BA}39      {5182E668-105E-416E-AD92-24EF800424BA}39      {5182E668-105E-416E-AD92-24EF800424BA}39      {5182E668-105E-416E-AD92-24EF800424BA}`
« Last Edit: March 06, 2013, 11:30:25 PM by MichaelW »
Well Microsoft, here’s another nice mess you’ve gotten us into.

#### dedndave

• Member
• Posts: 8829
• Still using Abacus 2.0
##### Re: DEFINE_GUID macro
« Reply #1 on: March 06, 2013, 08:29:35 PM »
hi Michael
the best one i found in the old forum....
http://www.masmforum.com/board/index.php?topic=2077.msg16530#msg16530

Jeff tries to emulate the C definition of DEFINE_GUID, including INITGUID
that seems like a clumsy step in "asm world"

to my way of thinking, why not...
Code: [Select]
`DEFINE_GUID MACRO name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8    name GUID <l,w1,w2,<b1,b2,b3,b4,b5,b6,b7,b8>>ENDM` :P

of course, you could add FourF's little section preservation trick...
http://masm32.com/board/index.php?topic=1546.msg15842#msg15842
it should be simple to test for no current open segment and upgrade the section preservation technique

#### MichaelW

• Global Moderator
• Member
• Posts: 1204
##### Re: DEFINE_GUID macro
« Reply #2 on: March 06, 2013, 09:10:55 PM »
Dave,

Thanks. Jeff went further with the declarations, but I don’t know enough about it to judge the value of that. He did not do any translations. The DbgEng.h from my Server 2003 SP1 PSDK defines 22 GUIDs, all in a format that my macro can handle, for example:
Code: [Select]
`/* f2df5f53-071f-47bd-9de6-5734c3fed689 */DEFINE_GUID(IID_IDebugAdvanced, 0xf2df5f53, 0x071f, 0x47bd,            0x9d, 0xe6, 0x57, 0x34, 0xc3, 0xfe, 0xd6, 0x89);/* 5bd9d474-5975-423a-b88b-65a8e7110e65 */DEFINE_GUID(IID_IDebugBreakpoint, 0x5bd9d474, 0x5975, 0x423a,            0xb8, 0x8b, 0x65, 0xa8, 0xe7, 0x11, 0x0e, 0x65);/* 27fe5639-8407-4f47-8364-ee118fb08ac8 */DEFINE_GUID(IID_IDebugClient, 0x27fe5639, 0x8407, 0x4f47,            0x83, 0x64, 0xee, 0x11, 0x8f, 0xb0, 0x8a, 0xc8);`
And my quick survey of the 95 header files that my search for DEFINE_GUID found showed anywhere from 1 to more than 100 per file, all apparently in the same format, and I suspect that with the later versions of Windows the number has increased, and possibly “exploded”.

Regarding the segment preservation, I can’t see the value of it for anything resembling normal code.

Edit:

Scratch that, the value of it should have been obvious. I changed the code above to preserve and restore the current section.

Strange, even with /W3 MASM sill assumed that I knew what I was doing
« Last Edit: March 06, 2013, 11:10:31 PM by MichaelW »
Well Microsoft, here’s another nice mess you’ve gotten us into.

#### dedndave

• Member
• Posts: 8829
• Still using Abacus 2.0
##### Re: DEFINE_GUID macro
« Reply #3 on: March 06, 2013, 09:32:55 PM »
Quote
Regarding the section preservation, I can’t see the value of it for anything resembling normal code.

well - not for "us"
for "them"

by "them", i mean those who came from the world of C to ASM - lol
my preference is to just use the GUID struct in the .DATA section
Code: [Select]
`GUID_DEVCLASS_1394 GUID <6BDD1FC1h,810Fh,11D0h,<0BEh,0C7h,8,0,2Bh,0E2h,9,2Fh>>`what's so hard about that ?

#### jj2007

• Member
• Posts: 11550
• Assembler is fun ;-)
##### Re: DEFINE_GUID macro
« Reply #4 on: March 06, 2013, 10:19:23 PM »
> what's so hard about that?
Not so hard, actually, although copy & paste can be convenient:

.data
CLSID_WebBrowser        GuidFromString(8856F961-340A-11D0-A96B-00C04FD705A2)      ; ExDisp.h syntax
IID_IWebBrowser           GuidFromString("EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B")   ; quoted
IID_IWebBrowser2         GuidFromString({D30C1661-CDAF-11D0-8A3E-00C04FC9E26E})   ; registry syntax

Init
.if GuidsEqual(offset IID_IWebBrowser, offset IID_IWebBrowser2)
Inkey "The GUIDs are equal"
.else
Inkey "The GUIDs are NOT equal"
.endif
Exit
end start

(from OLE support in MasmBasic, Sept 2012)

#### MichaelW

• Global Moderator
• Member
• Posts: 1204
##### Re: DEFINE_GUID macro
« Reply #5 on: March 06, 2013, 10:25:26 PM »
If you need a sizable number of GUIDs, and for some purposes you do, and your source for the GUIDs is C code or a C header file, doing it via copy paste and an automated translation could save a significant amount of time and prevent errors.

Well Microsoft, here’s another nice mess you’ve gotten us into.