The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: baltoro on December 31, 2008, 10:06:10 PM

Title: GUID Routines
Post by: baltoro on December 31, 2008, 10:06:10 PM
I recently wrote a program in C++, to query and override functionality in USB hardware devices, and found that I was dealing with instance and device class GUIDs (which Windows stores in the registry). There are few GUID routines in the Win32 system DLLs, and I ended up writing these ridiculously long functions to compare GUIDs and convert to readable strings (GUIDs are a portion of the Device Identifier). Speed is NOT an issue, but, I wanted reliable function performance.
So, it occurred to me that exported assembly routines would be the way to go with this type of function.

This is the syntax in C++, from the MSDN site:   

typedef struct _GUID
{  DWORD Data1; 
WORD Data2; 
WORD Data3; 
BYTE Data4[8];
} GUID;


Members
Data1
Specifies the first 8 hexadecimal digits of the GUID.
Data2
Specifies the first group of 4 hexadecimal digits.
Data3
Specifies the second group of 4 hexadecimal digits.
Data4
Array of 8 bytes. The first 2 bytes contain the third group of 4 hexadecimal digits. The remaining 6 bytes contain the final 12 hexadecimal digits.

A GUID is a 128-bit value consisting of one group of 8 hexadecimal digits, followed by three groups of 4 hexadecimal digits each, followed by one group of 12 hexadecimal digits. GUIDs are the Microsoft implementation of the distributed computing environment (DCE) universally unique identifier ( UUID).   

So, I'm wondering, if there already existing GUID conversion assembly routines. I did a preliminary search and came up with nothing.
Thanks.
Title: Re: GUID Routines
Post by: donkey on December 31, 2008, 10:12:10 PM
If speed isn't an issue, why not just use the API for this ? StringFromGUID2 (http://msdn.microsoft.com/en-us/library/ms683893(VS.85).aspx) and  IsEqualGUID (http://msdn.microsoft.com/en-us/library/ms680575(VS.85).aspx)  do a fine job and are very reliable. GUID is generally defined as follows in assembly (MASM syntax)

GUID STRUCT
  Data1 dd ?
  Data2 dw ?
  Data3 dw ?
  Data4 db 8 DUP (?)
GUID ENDSS
Title: Re: GUID Routines
Post by: baltoro on December 31, 2008, 10:35:22 PM
Thanks Donkey,
Yeah, you're right about the COM APIs IsEqualGUID and related.
Title: Re: GUID Routines
Post by: jdoe on December 31, 2008, 11:10:42 PM
Quote from: baltoro on December 31, 2008, 10:35:22 PM
Yeah, you're right about the COM APIs IsEqualGUID and related.

Speed does not matter in that case but for an assembly replacement of IsEqualGUID...

http://www.masm32.com/board/index.php?topic=8312.0

Title: Re: GUID Routines
Post by: Tedd on January 01, 2009, 02:04:55 PM
Quote from: baltoro on December 31, 2008, 10:06:10 PM
There are few GUID routines in the Win32 system DLLs, and I ended up writing these ridiculously long functions to compare GUIDs and convert to readable strings (GUIDs are a portion of the Device Identifier). Speed is NOT an issue, but, I wanted reliable function performance.
They're still just binary values, so a straight compare is perfectly fine (i.e. memcmp)
And printf for converting to string ("{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}") :wink
Title: Re: GUID Routines
Post by: baltoro on January 03, 2009, 06:41:26 PM
Thanks for excellent replies,...
I know it's kind of a simple question. I'm just incredibly lazy.
...and, my brain has been reduced to complete dysfunction by Influenza,...