# GUID (Microsoft COM UUID Mixed-Endian) constants in Clarion

**URL:** <https://clarionhub.com/t/guid-microsoft-com-uuid-mixed-endian-constants-in-clarion/8093>\
**Category:** code\
**Tags:** com, language\
**Created:** [April 14, 2025, 5:29am UTC](https://clarionhub.com/t/guid-microsoft-com-uuid-mixed-endian-constants-in-clarion/8093 "2025-04-14T05:29:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarlosGtrz](https://clarionhub.com/user_avatar/clarionhub.com/carlosgtrz/32/5870_2.png) [@CarlosGtrz](https://clarionhub.com/u/CarlosGtrz)\
**Post date:** [April 14, 2025, 5:29am UTC](https://clarionhub.com/t/guid-microsoft-com-uuid-mixed-endian-constants-in-clarion/8093/1 "2025-04-14T05:29:34Z")

</div>

Some times I wondered why SV's definition for GUIDs is structured as a group like this:

```clarion
GUID group, type
Data1 long
Data2 short
Data3 short
Data4 byte, dim(8)
                       end

```

instead of something more straightforward, like `guid STRING('<011h,022h,033h....>')`.

While troubleshooting a problem with an API call that expects a GUID constant, I found the answer in [Wikipedia's article on _Universally unique identifier_](https://en.wikipedia.org/wiki/Universally_unique_identifier#Endianness):

> An exception to this are Microsoft's variant 2 UUIDs ("GUID"): historically used in [COM/OLE libraries](https://en.wikipedia.org/wiki/Component_Object_Model), they use a [little-endian](https://en.wikipedia.org/wiki/Little-endian) format, but appear [mixed-endian](https://en.wikipedia.org/wiki/Mixed-endian) with the first three components of the UUID as [little-endian](https://en.wikipedia.org/wiki/Little-endian) and last two [big-endian](https://en.wikipedia.org/wiki/Big-endian). Microsoft's GUID structure defines the last eight bytes as an 8-byte array, which are serialized in ascending order, which makes the byte representation appear mixed-endian.[[23]](https://en.wikipedia.org/wiki/Universally_unique_identifier#cite_note-23) For example, `00112233-4455-6677-8899-aabbccddeeff` is encoded as the bytes `33 22 11 00` `55 44` `77 66` `88 99` `aa bb cc dd ee ff` .

Understanding this, a GUID constant can declared in the data section like this:

```clarion
  PROGRAM

!00112233-4455-6677-8899-aabbccddeeff
GuidA GROUP
Data1 LONG(000112233h)
Data2 SHORT(04455h)
Data3 SHORT(06677h)
Data4Str STRING('<088h,099h,0AAh,0BBh,0CCh,0DDh,0EEh,0FFh>') !There is no need for a byte array
                    END

!33 22 11 00 55 44 77 66 88 99 aa bb cc dd ee ff
Expected STRING('<033h,022h,011h,000h,055h,044h,077h,066h,088h,099h,0AAh,0BBh,0CCh,0DDh,0EEh,0FFh>')

  CODE
  PRAGMA('define(asserts=>on)')  
  
  ASSERT(GuidA = Expected)

```

---

<div class="post-metadata">

**Author:** ![PaulAttryde](https://clarionhub.com/user_avatar/clarionhub.com/paulattryde/32/3519_2.png) [@PaulAttryde](https://clarionhub.com/u/PaulAttryde)\
**Post date:** [April 14, 2025, 12:17pm UTC](https://clarionhub.com/t/guid-microsoft-com-uuid-mixed-endian-constants-in-clarion/8093/2 "2025-04-14T12:17:55Z")

</div>

fyi, if you want to convert a GUID into a string, or vice versa, you can use UuidFromStringA & UuidToStringA from RPCRT4.DLL or CLSIDFromString & StringFromGUID2 from OLE32.DLL
