Processing the Search Results
If the return value is S_ADS_NOMORE_ROWS, no more objects matching the filter were found. If an error result is returned, the query failed. In both cases, you are not required to process the rows in the result because nothing was returned.
If S_OK is returned, a row has been retrieved. You can parse the columns by name using IDirectorySearch::GetColumn. The name is the lDAPDisplayName of the attribute in the column. The set of all columns was defined by the pAttributeNames parameter of the IDirectorySearch::ExecuteSearch method. If NULL was specified, the set of all columns is the union of all properties found for all the objects returned. To read the entire set of columns returned for an object, use the IDirectorySearch::GetNextColumnName to iterate each column, and use the column name returned to call IDirectorySearch::GetColumn.
The IDirectorySearch::GetColumn method returns an ADS_SEARCH_COLUMN structure that contains the attribute name, the type of the attribute, count of values, and a pointer to an array of ADSVALUE structures that contain the values. You can loop through the ADSVALUE structures to read the values for the property returned by the column. You must read the appropriate member of the ADSVALUE structure based on the ADSTYPE specified by the dwADsType member of the ADS_SEARCH_COLUMN structure (or the dwType member of the ADSVALUE structure). For example, if dwADsType was ADSTYPE_INTEGER, you would read the Integer member of each ADSVALUE structure.
For more information and a code example, see Example Code for Searching for Users.