Partager via


Liaison au parent d’un objet

Dans ADSI, chaque objet d’annuaire est représenté par un objet COM ADSI qui expose l’interface IADs . Pour obtenir le conteneur parent d’un objet, utilisez la méthode IADs::get_Parent pour obtenir l’ADsPath de l’objet parent, puis liez à l’ADsPath du parent.

L’exemple de code C++ suivant montre comment obtenir le parent d’un objet .

HRESULT GetParentObject(IADs *pObject,   // Pointer to the object whose parent to bind to.
                        IADs **ppParent) // Return a pointer to the parent object.
{
    if(NULL == ppParent)
    {
        return E_INVALIDARG;
    }
 
    *ppParent = NULL;

    if(NULL == pObject)
    {
        return E_INVALIDARG;
    }
 
    HRESULT hr;
    BSTR bstr;

    // Get the ADsPath of the parent.
    hr = pObject->get_Parent(&bstr);
    if(SUCCEEDED(hr))
    {
        // Bind to the parent.
        hr = ADsOpenObject(bstr,
             NULL,
             NULL,
             ADS_SECURE_AUTHENTICATION,
             IID_IADs,
             (void**)ppParent);

        SysFreeString(bstr);
    }

    return hr;
}