Platform SDK: Active Directory, ADSI, and Directory Services

ADsEncodeBinaryData

The ADsEncodeBinaryData function converts a binary blob of data to the Unicode format suitable to be embedded in a search filter.

HRESULT ADsEncodeBinaryData(
  PBYTE pbSrcData, 
  DWORD dwSrcLen, 
  LPWSTR *ppszDestData 
);

Parameters

pbSrcData
A binary blob of data to be converted.
dwSrcLen
Size of the blob in bytes.
ppszDestData
Converted data as a Unicode string.

Return Values

This method supports the standard return values, as well as the following:

E_ADS_BAD_PARAMETER
Parameters are not valid. For example, the length of the source data is zero.
E_OUTOFMEMORY
Memory allocation has failed.
S_OK
Operation is successful.
For other return values, see ADSI Error Codes.

Remarks

In ADSI, search filters must be Unicode strings. Sometimes, a filter contains information that is normally represented by an opaque blob of data. For example, you may want to include an object's security identifier in a search filter, which is of binary data. In this case, you must first call the ADsEncodeBinaryData function to convert the binary data to the Unicode string format. When the data is no longer needed, you should call the FreeADsMem function to free the converted Unicode string (that is, ppszDestData). The following code snippet gives an example of how to use this function.

//Test binary values in filters and use
//a binary filter instead of a string filter in ExecuteSearch.
 
WCHAR pszBinaryFilter[256] = L"objectSid=";
LPWSTR pszDest = NULL;
 
BYTE column[100] = {
  0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00,
  0x00, 0x00, 0x59, 0x51, 0xb8, 0x17, 0x66, 0x72, 0x5d, 0x25,
  0x64, 0x63, 0x3b, 0x0b, 0x29, 0x99, 0x21, 0x00 };
 
hr = ADsEncodeBinaryData (
    column,
    28,
    &pszDest
    );
 
wcscat( pszBinaryFilter, pszDest );
 
//Do the search with the pszDest as the filter string. Code omitted.
. . . 
//Done with the search and free the converted string.
FreeADsMem( pszDest );
 

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Adshlp.h.
  Library: Included as a resource in ActiveDs.dll.

See Also

ADSI Error Codes, ADSI Functions, FreeADsMem