3 out of 5 rated this helpful - Rate this topic

StringFromGUID2 function

Applies to: desktop apps | Metro style apps

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

Syntax

int StringFromGUID2(
  __in   REFGUID rguid,
  __out  LPOLESTR lpsz,
  __in   int cchMax
);

Parameters

rguid [in]

The GUID to be converted.

lpsz [out]

A pointer to a caller-allocated string variable to receive the resulting string. The string that represents rguid includes enclosing braces.

cchMax [in]

The number of characters available in the lpsz buffer.

Return value

If the function succeeds, the return value is the number of characters in the returned string, including the null terminator. If the buffer is too small to contain the string, the return value is 0.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Objbase.h

Library

Ole32.lib

DLL

Ole32.dll

See also

StringFromCLSID

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
REFGUID is defined differently between C++ and C!
If you are calling this function from C++, REFGUID is defined as "const GUID &", so you can just pass the GUID struct directly.  However, if you are calling this function from C, REFGUID is defined as "const GUID *"! So make sure you pass the address of the GUID struct.  This is particularly important if you are handed a VOID* as a pointer to a GUID.
Example use
OLECHAR szGuid[40]={0}; int nCount = ::StringFromGUID2(guid, szGuid, 40); CString str(szGuid);
Endianness
The Data1, Data2, and Data3 fields of the GUID structure are printed to the buffer in Big Endian hexadecimal format.
Minimum buffer size
The buffer pointed to by lpsz needs to have space for 39 wide characters;  cchMax needs to be at least 39.
Returns the number of characters including the NUL terminator
The return value is either 39 or 0, indicating that the wide string pointed to by lpsz does not have space for 39 characters.