Directory Services

IADsPathname::GetElement

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

HRESULT GetElement( 
  long lnElementIndex,
  BSTR* pbstrElement
);

Parameters

lnElementIndex
[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:

For more information and other return values, see ADSI Error Codes.

Return Code Description
S_OK The operation succeeded.
E_FAIL The operation failed.
ERROR_INVALID_INDEX The supplied index does not exist.
E_INVALIDARG The supplied index is invalid.

Example Code [Visual Basic]

The following Visual Basic code example shows how to extract the first element of a path.

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 example shows how to extract the first element of a path.

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 example prints all the elements of a path. For more information and a code example of the GetPathnameObject function, see IADsPathname.

LPWSTR adsPath=L"LDAP://server/cn=jeffsmith,dc=Fabrikam,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

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

See Also

IADsPathname, ADSI Error Codes