Share via


Método IDirectoryObject::GetObjectAttributes (iads.h)

El método IDirectoryObject::GetObjectAttributes recupera uno o varios atributos especificados del objeto de servicio de directorio.

Sintaxis

HRESULT GetObjectAttributes(
  [in]  LPWSTR         *pAttributeNames,
  [in]  DWORD          dwNumberAttributes,
  [out] PADS_ATTR_INFO *ppAttributeEntries,
  [out] DWORD          *pdwNumAttributesReturned
);

Parámetros

[in] pAttributeNames

Especifica una matriz de nombres de los atributos solicitados.

Para solicitar todos los atributos del objeto, establezca pAttributeNames en NULL y establezca el parámetro dwNumberAttributes en (DWORD)-1.

[in] dwNumberAttributes

Especifica el tamaño de la matriz pAttributeNames . Si es -1, se solicitan todos los atributos del objeto.

[out] ppAttributeEntries

Puntero a una variable que recibe un puntero a una matriz de estructuras de ADS_ATTR_INFO que contienen los valores de atributo solicitados. Si no se puede obtener ningún atributo del objeto de servicio de directorio, el puntero devuelto es NULL.

[out] pdwNumAttributesReturned

Puntero a una variable DWORD que recibe el número de atributos recuperados en la matriz ppAttributeEntries .

Valor devuelto

Este método devuelve los valores estándar, así como los siguientes:

Para obtener más información y otros valores devueltos, consulta Códigos de error ADSI.

Comentarios

ADSI asigna la memoria de la matriz de estructuras de ADS_ATTR_INFO devueltas en el parámetro ppAttributeEntries . El llamador debe llamar a FreeADsMem para liberar la matriz.

El orden de los atributos devueltos en ppAttributeEntries no es necesariamente el mismo que se solicitó en pAttributeNames.

El método IDirectoryObject::GetObjectAttributes intenta leer la definición de esquema de los atributos solicitados para que pueda devolver los valores de atributo en el formato adecuado en las estructuras ADSVALUE contenidas en las estructuras ADS_ATTR_INFO . Sin embargo, GetObjectAttributes puede realizarse correctamente incluso cuando la definición de esquema no está disponible, en cuyo caso el miembro dwADsType de la estructura ADS_ATTR_INFO devuelve ADSTYPE_PROV_SPECIFIC y el valor se devuelve en una estructura ADS_PROV_SPECIFIC . Al procesar los resultados de una llamada GetObjectAttributes , compruebe dwADsType para asegurarse de que los datos se devolvieron en el formato esperado.

Ejemplos

En el ejemplo de código siguiente se muestra cómo se puede usar el método IDirectoryObject::GetObjectAttributes .

HRESULT hr;
IDirectoryObject *pDirObject = NULL;
 
hr = ADsGetObject(L"LDAP://CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=com",
                     IID_IDirectoryObject, 
                     (void**) &pDirObject );
 
if ( SUCCEEDED(hr) )
{
    ADS_ATTR_INFO *pAttrInfo=NULL;
    DWORD dwReturn;
    LPWSTR pAttrNames[]={L"givenName",L"sn", L"otherTelephone" };
    DWORD dwNumAttr=sizeof(pAttrNames)/sizeof(LPWSTR);

    //////////////////////////////////////////////////////
    // Get attribute values requested.
    // Be aware that the order is not necessarily the 
    // same as requested using pAttrNames.
    //////////////////////////////////////////////////////
    hr = pDirObject->GetObjectAttributes( pAttrNames, 
                                        dwNumAttr, 
                                        &pAttrInfo, 
                                        &dwReturn );
     
    if ( SUCCEEDED(hr) )
    {
        for(DWORD idx = 0; idx < dwReturn; idx++ )
        {
            if ( _wcsicmp(pAttrInfo[idx].pszAttrName,L"givenName") == 0 )
            {
                switch (pAttrInfo[idx].dwADsType)
                {
                    case ADSTYPE_CASE_IGNORE_STRING:
                        printf("First Name: %S\n", pAttrInfo[idx].pADsValues->CaseIgnoreString);
                        break;
         
                    case ADSTYPE_PROV_SPECIFIC:
                        printf("First Name: %S\n", pAttrInfo[idx].pADsValues->ProviderSpecific.lpValue);
                        break;
         
                    default:
                        printf("Invalid ADsType: %d\n", pAttrInfo[idx].dwADsType);
                        break;
                }
            }
            else if ( _wcsicmp(pAttrInfo[idx].pszAttrName, L"sn") == 0 )
            {
                switch (pAttrInfo[idx].dwADsType)
                {
                    case ADSTYPE_CASE_IGNORE_STRING:
                        printf("Last Name: %S\n", pAttrInfo[idx].pADsValues->CaseIgnoreString);
                        break;
         
                    case ADSTYPE_PROV_SPECIFIC:
                        printf("Last Name: %S\n", pAttrInfo[idx].pADsValues->ProviderSpecific.lpValue);
                        break;
         
                    default:
                        printf("Invalid ADsType: %d\n", pAttrInfo[idx].dwADsType);
                        break;
                }
            }
            else if ( _wcsicmp(pAttrInfo[idx].pszAttrName, L"otherTelephone") == 0  )
            {   // Print the multi-valued property, "Other Telephones".
                switch (pAttrInfo[idx].dwADsType)
                {
                    case ADSTYPE_CASE_IGNORE_STRING:
                        printf("Other Telephones:");
                        for (DWORD val=0; val < pAttrInfo[idx].dwNumValues; val++) 
                        printf("  %S\n", pAttrInfo[idx].pADsValues[val].CaseIgnoreString);
                        break;
         
                    case ADSTYPE_PROV_SPECIFIC:
                        printf("Other Telephones:");
                        for (DWORD val=0; val < pAttrInfo[idx].dwNumValues; val++) 
                        printf("  %S\n", pAttrInfo[idx].pADsValues[val].CaseIgnoreString);
                        break;
         
                    default:
                        printf("Other Telephones:");
                        for (DWORD val=0; val < pAttrInfo[idx].dwNumValues; val++) 
                        printf("  %S\n", pAttrInfo[idx].pADsValues[val].CaseIgnoreString);
                        break;
                }
            }
        }

        /////////////////////////////////////////////////////////////
        // Use FreeADsMem for all memory obtained from the ADSI call. 
        /////////////////////////////////////////////////////////////
        FreeADsMem( pAttrInfo );
    
    }
 
    pDirObject->Release();
}

Requisitos

Requisito Value
Cliente mínimo compatible Windows Vista
Servidor mínimo compatible Windows Server 2008
Plataforma de destino Windows
Encabezado iads.h
Archivo DLL Activeds.dll

Consulte también

Códigos de error adsi

ADS_ATTR_INFO

FreeADsMem

IDirectoryObject