Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Das folgende Codebeispiel kann verwendet werden, um eine Zeichenfolgendarstellung einer GUID zurückzugeben, die zum Binden an das Objekt verwendet werden kann.
//*******************************************************************
//
// GUIDtoBindableString()
//
// Converts a GUID into a string that can be used for binding with
// the <GUID= or <WKGUID= syntax. The caller must free the allocated
// string with the FreeADsStr when it is no longer required.
//
//*******************************************************************
HRESULT GUIDtoBindableString(LPGUID pGUID, LPWSTR *ppGUIDString)
{
if((!pGUID) || (ppGUIDString==NULL))
{
return E_INVALIDARG;
}
// Build bindable GUID string.
DWORD dwBytes = sizeof(GUID);
WCHAR szByte[3];
LPWSTR pwszGUID = new WCHAR[(dwBytes * 2) + 1];
if(NULL == pwszGUID)
{
return E_OUTOFMEMORY;
}
*pwszGUID = NULL;
HRESULT hr = S_OK;
LPBYTE lpByte;
DWORD dwItem;
// Loop through to add each byte to the string.
for(dwItem = 0,
lpByte = (LPBYTE)pGUID; dwItem < dwBytes;
dwItem++)
{
// Append to pwszGUID, double-byte, byte at dwItem index.
swprintf_s(szByte, L"%02x", lpByte[dwItem]);
wcscat_s(pwszGuid, szByte);
}
// Allocate memory for the string.
*ppGUIDString = AllocADsStr(pwszGUID);
delete [] pwszGUID;
if(NULL != *ppGUIDString)
{
hr = S_OK;
}
else
{
hr = E_OUTOFMEMORY;
}
// Caller must free ppGUIDString using FreeADsStr.
return hr;
}