Discussion:
How to convert a GUID to CString and display it?
(too old to reply)
Jeff R.
2004-05-19 00:58:19 UTC
Permalink
Hello,
I am using the Create GUID tool to generate a GUID in either of the
following formats:

// {AB7F780B-D27B-4c8f-A19A-005D8AB7874E}

DEFINE_GUID(myGUID,
0xab7f780b, 0xd27b, 0x4c8f, 0xa1, 0x9a, 0x0, 0x5d, 0x8a, 0xb7, 0x87, 0x4e);

static const GUID myGUID =
{ 0xab7f780b, 0xd27b, 0x4c8f, { 0xa1, 0x9a, 0x0, 0x5d, 0x8a, 0xb7, 0x87,
0x4e } };


I do it this way so that I don't have to store the GUID as a string in my
code (I don't want the actual GUID to be visible as a string if someone
opens my .EXE in Notepad). But I need to convert the GUID to a string so I
can use it with registry functions. Can someone show me how to convert a
GUID in either of the formats above to a CString or TCHAR[] ? thanks!
Jianwei Sun
2004-05-19 02:51:55 UTC
Permalink
From MSDN

StringFromGUID2
Converts a globally unique identifier (GUID) into a string of printable
characters.

int StringFromGUID2(
REFGUID rguid,
LPOLESTR lpsz,
int cchMax
);
Parameters
rguid
[in] GUID to be converted.
lpsz
[out] Pointer to a caller-allocated string variable to contain the resulting
string on return.
cchMax
[in] Number of characters available in the buffer indicated by lpsz.
Return Values
0 (zero)
Array at lpsz is too small to contain a string representation of a GUID.
Non-zero value
The number of characters in the returned string, including the null
terminator.
Remarks
The string that the lpsz parameter receives has a format like that of the
following sample:

{c200e360-38c5-11ce-ae62-08002b2b79ef}
where the successive fields break the GUID into the form
DWORD-WORD-WORD-WORD-WORD.DWORD covering the 128-bit GUID. The string
includes enclosing braces, which are an OLE convention.
Post by Jeff R.
Hello,
I am using the Create GUID tool to generate a GUID in either of the
// {AB7F780B-D27B-4c8f-A19A-005D8AB7874E}
DEFINE_GUID(myGUID,
0xab7f780b, 0xd27b, 0x4c8f, 0xa1, 0x9a, 0x0, 0x5d, 0x8a, 0xb7, 0x87, 0x4e);
static const GUID myGUID =
{ 0xab7f780b, 0xd27b, 0x4c8f, { 0xa1, 0x9a, 0x0, 0x5d, 0x8a, 0xb7, 0x87,
0x4e } };
I do it this way so that I don't have to store the GUID as a string in my
code (I don't want the actual GUID to be visible as a string if someone
opens my .EXE in Notepad). But I need to convert the GUID to a string so I
can use it with registry functions. Can someone show me how to convert a
GUID in either of the formats above to a CString or TCHAR[] ? thanks!
Loading...