Platform SDK: Active Directory, ADSI, and Directory Services

IDirectorySearch::CloseSearchHandle

The IDirectory::CloseSearchHandle method closes the handle to a search result and frees the associated memory.

HRESULT CloseSearchHandle(
  ADS_SEARCH_HANDLE hSearchHandle
);

Parameters

[in] hSearchHandle
Provides a handle to the search result to be closed.

Return Values

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

S_OK
The search result was closed.
E_ADS_BAD_PARAMETER
The search handle is invalid.

For other return values, see ADSI Error Codes.

Remarks

The process that implements the IDirectorySearch::CloseSearchHandle method must also be responsible for freeing all memory allocated by the IDirectorySearch::ExecuteSearch method, including the search result and the search result handle.

The caller may call this method only once for each opened search handle and must use the IDirectorySearch::ExecuteSearch method to obtain a new search handle after issuing IDirectorySearch::CloseSearchHandle.

Example Code [C++]

ADS_SEARCH_HANDLE hSearch;
HRESULT hr;
hr = m_pSearch->ExecuteSearch(L"(&(objectCategory=user)(l=Redmond))", pszAttr, dwCount, &hSearch );
if ( SUCCEEDED(hr) )
{
   // Omit getting the data
   m_pSearch->CloseSearchHandle(hSearch);
}

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 Iads.h.

See Also

IDirectorySearch, IDirectorySearch::ExecuteSearch, ADSI Error Codes