Platform SDK: Active Directory, ADSI, and Directory Services

IADsContainer::GetObject

The IADsContainer::GetObject method obtains an IADs interface pointer to a directory object in the container. The object is identified by its schema class and the relative name.

HRESULT IADsContainer::GetObject(
  BSTR bstrClass,        
  BSTR bstrRelativeName, 
  IDispatch ** ppNamedObject  
);

If the schema class name is not provided, retrieve an interface pointer on the first object found in the container with the specified name.

Parameters

bstrClass
[in] Name of the object as known in the underlying directory and identical to the one retrieved through the IADs::get_Class property method. If the class name is NULL, the provider returns the first item found in the container.
bstrRelativeName
[in] Name of the object as known in the underlying directory and identical to the one retrieved through the IADs::get_Name property method.
ppNamedObject
[out] Indirect pointer to the IDispatch interface on the specified object.

Return Values

This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.

Remarks

The GetObject method is the most common way of retrieving an IADs interface pointer on an ADSI object.

Example Code [Visual Basic]

The following Visual Basic code snippet gets a user object from a container object.

Dim cont As IADsContainer
Dim usr As IADsUser
Set cont = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com")
Set usr = cont.GetObject("user", "jsmith")

This is equivalent to the more succinct and more efficient code:

Dim usr As IADsUser
Set usr=GetObject("LDAP://CN=jsmith, OU=Sales,DC=Fabrikam,DC=com")

Example Code [C++]

The following C++ code snippet gets a user object from a container object.

HRESULT hr;
CoInitialize(NULL);
 
IADsContainer *pCont=NULL;
 
hr = ADsGetObject(L"LDAP://DC=windows2000,DC=nttest,DC=microsoft,DC=com",
            IID_IADsContainer, 
            (void**) &pCont );
 
//////////////////////////////////////////////////////////////////////
// Get the child from the container.
// Note in the LDAP provider you can go down more than one level.
//////////////////////////////////////////////////////////////////////
IDispatch *pDisp = NULL;
IADs *pADs = NULL;
hr = pCont->GetObject(L"user", L"CN=Mike Smith, OU=DSys", &pDisp );
pCont->Release();
 
hr = pDisp->QueryInterface( IID_IADs, (void**) &pADs );
pDisp->Release(); 
 
// Do something with pADs here.
pADs->Release();
 
CoUninitialize();

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

ADsGetObject, IADs, IADs::get_Class, IADs::get_Name, IADsContainer, IDispatch