Platform SDK: Active Directory, ADSI, and Directory Services

IADsPathname::GetElement

The IADsPathname::GetElement method retrieves an element of a directory path.

HRESULT IADsPathname::GetElement(
  DWORD dwElementIndex,
  BSTR *pbstrElement
);

Parameters

dwElementIndex
[in] The index of the element.
pbstrElement
[out] The returned element.

Return Values

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

S_OK
The operation is successful.
E_FAIL
The operation has failed.
ERROR_INVALID_INDEX
The supplied index does not exist.
E_INVALIDARG
The supplied index is not valid.

For other return values, see ADSI Error Codes.

Example Code [Visual Basic]

The following Visual Basic® code snippet shows how to extract the first element of a pathname.

Dim x As New Pathname
x.Set "LDAP://srv1/dc=dom,dc=company,dc=com", ADS_SETTYPE_FULL
y = x.GetElement(0)            ' y becomes "dc=dom".

Example Code [VBScript]

The following VBScript code snippet shows how to extract the first element of a pathname.

Dim x
Const ADS_SETTYPE_FULL = 1
Set x =  CreateObject("Pathname")
x.Set "LDAP://srv1/dc=dom,dc=company,dc=com", ADS_SETTYPE_FULL
y = x.GetElement(0)            ' y becomes "dc=dom".

Example Code [C++]

The following C++ code snippet prints out all the elements of a path. See the code snippet in IADsPathname for the GetPathnameObject function.

LPWSTR adsPath=L"LDAP://server/cn=jsmith,dc=Microsoft,dc=com";
 
IADsPathname *pPath = GetPathnameObject(adsPath);
long count=0;
HRESULT hr = pPath->GetNumElements(&count);
BSTR bstr;
for (int I = 0; I<count; I++) {
    hr = pPath->GetElement(I,&bstr);
    printf("Element(%d): %S\n",bstr);
    SysFreeString(bstr);
}

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

IADsPathname, ADSI Error Codes