Directory Services

FreeADsMem

The FreeADsMem function frees the memory allocated by AllocADsMem.

BOOL FreeADsMem(
  LPVOID pMem
);

Parameters

pMem
[in] Pointer to the local memory to be freed.

Return Values

The function returns TRUE if successful, otherwise it returns FALSE.

Remarks

In ADSI, all method-allocated memory must be freed using FreeADsMem. The following is a code example.

// m_pSearch is a valid pointer to an IDirectorySearch interface.
LPWSTR pszColumn;
ADS_SEARCH_HANDLE hSearch;
HRESULT hr = S_OK;

hr = m_pSearch->GetFirstRow(hSearch);
if(hr == S_OK)
{
	printf("Column names are: ");
	while(m_pSearch->GetNextColumnName(hSearch, &pszColumn) !=
									 S_ADS_NOMORE_COLUMNS) {
		printf("%S ", pszColumn);
		// Method-allocated memory, pszColumn, must be freed before
		// the pointer variable is used in the next GetnextColumnName call.
		FreeADsMem(pszColumn);
}
}
m_pSearch->CloseSearchHandle(hSearch);

Requirements

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Adshlp.h.
Library: Use ActiveDS.lib.

See Also

ADSI Functions, AllocADsMem