Platform SDK: Active Directory, ADSI, and Directory Services

AllocADsMem

The AllocADsMem function allocates a block of memory of the specified size (in bytes).

LPVOID AllocADsMem(
  DWORD cb 
);

Parameters

cb
The amount of memory (in bytes) to be allocated

Return Values

When successful, the function returns a non-NULL pointer to the allocated memory. Otherwise, it returns NULL. Call ADsGetLastError to obtain extended error status. For error code values, see ADSI Error Codes.

Remarks

The following code snippet builds an ADsPath string by concatenating the relative name of an object and the path of its parent. To do so, it first calls AllocADsMem to create a buffer of sufficient length. Error checking is omitted in the example.

HRESULT buildADsPath(BSTR parent, BSTR child, BSTR *pADsPath)
{
    LPWSTR lpADsPath=NULL;
    HRESULT hr = S_OK;
    DWORD dwLen = 0;
    dwLen = wcslen(parent) + wcslen(Name) + 2 + MAX_PATH;
 
    // create a buffer for the string
    lpADsPath = (LPWSTR)AllocADsMem(dwlen*sizeof(WCHAR));
    if(!lpADspath) return (E_OUTOFMEMORY);
 
    wcscpy(lpADsPath,parent);
    wcscat(lpADsPath,L"/");
    wcscat(lpADsPath, child);
    hr = ADsAllocString(lpADsPath, pADsPath);
 
    // release the buffer
    if(lpADsPath) FreeADsMem(lpADsPath);
    return (hr);
}

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, ADsGetLastError, FreeADsMem