Metodo IADs::GetEx (iads.h)

Il metodo IADs::GetEx recupera, dalla cache delle proprietà, i valori delle proprietà di un attributo specificato. I valori delle proprietà restituiti possono essere a valore singolo o multivalore. A differenza del metodo IADs::Get , i valori delle proprietà vengono restituiti come matrice variante di VARIANT o una matrice variant di byte per i dati binari. Una proprietà con valore singolo viene quindi rappresentata come matrice di un singolo elemento.

Sintassi

HRESULT GetEx(
  [in]  BSTR    bstrName,
  [out] VARIANT *pvProp
);

Parametri

[in] bstrName

Contiene un BSTR che specifica il nome della proprietà.

[out] pvProp

Puntatore a un valore VARIANT che riceve il valore o i valori della proprietà.

Valore restituito

Questo metodo supporta i valori restituiti standard e i valori restituiti elencati nell'elenco seguente.

Per altre informazioni, vedere Codici di errore ADSI.

Commenti

I metodi IADs::Get e IADs::GetEx restituiscono una struttura variante diversa per un valore di proprietà con valore singolo. Se la proprietà è una stringa, IADs::Get restituisce una variante di stringa (VT_BSTR), mentre IADs::GetEx restituisce una matrice variant di una stringa di tipo VARIANT con un singolo elemento. Pertanto, se non si è certi che un attributo multivalore restituirà un singolo valore o più valori, usare IADs::GetEx. Poiché non è necessario convalidare le strutture dei dati del risultato, è possibile usare IADs::GetEx per recuperare una proprietà quando non si è certi che abbia un singolo o più valori. L'elenco seguente confronta i due metodi.

ID::Get versione ID::GetEx versione
Dim x as IADs

otherNumbers = x.Get("otherHomePhone")
If VarType(otherNumbers) = vbString Then
  Debug.Print otherNumbers
Else
  For Each homeNum In otherNumbers
    Debug.Print homeNum
  Next
End If
Dim x as IADs

otherNumbers = x.GetEx("otherHomePhone")
For Each homeNum In otherNumbers
  Debug.Print homeNum
Next
 

Come il metodo IADs::Get, IADs::GetEx chiama in modo implicito IADs::GetInfo su una cache delle proprietà non inizializzata. Per altre informazioni sulle chiamate implicite ed esplicite a IADs::GetInfo, vedere IADs::GetInfo.

Esempio

Nell'esempio di codice seguente viene illustrato come usare IADs::GetEx per recuperare le proprietà dell'oggetto.

Dim x As IADs
On Error GoTo ErrTest:
 
Set x = GetObject("LDAP://CN=Administrator,CN=Users,DC=Fabrikam,DC=com")
 
' Single value property.
Debug.Print "Home Phone Number is: " 
phoneNumber = x.GetEx(""homePhone")
For Each homeNum in phoneNumber
    Debug.Print homeNum
Next
 
' Multiple value property.
Debug.Print "Other Phone Numbers are: "
otherNumbers = x.GetEx("otherHomePhone")
For Each homeNum In otherNumbers
    Debug.Print homeNum
Next
Exit Sub
 
ErrTest:
    Debug.Print Hex(Err.Number)
    Set x = Nothing

Nell'esempio di codice seguente viene illustrato come recuperare i valori delle proprietà facoltative di un oggetto usando il metodo IADs::Get .

<HTML>
<head><title></title></head>

<body>
<%
Dim x 

On Error Resume Next
Set x = GetObject("WinNT://Fabrikam/Administrator")
Response.Write "Object Name: " & x.Name & "<br>"
Response.Write "Object Class: " & x.Class & "<br>"
 
' Get the optional property values for this object.
Set cls = GetObject(x.Schema)
For Each op In cls.OptionalProperties
   vals = obj.GetEx(op)
   if err.Number = 0 then
       Response.Write "Optional Property: & op & "=" 
       for each v in vals 
          Response.Write v & " "
       next
       Response.Write "<br>"
   end if
Next
%>

</body>
</html>

Nell'esempio di codice seguente vengono recuperati i valori delle proprietà "homePhone" usando IADs::GetEx.

IADs *pADs = NULL;
 
hr = ADsGetObject(L"LDAP://CN=Administrator,CN=Users,DC=Fabrikam,DC=Com", IID_IADs, (void**) &pADs );
if ( !SUCCEEDED(hr) ) { return hr;}
 
hr = pADs->GetEx(CComBSTR("homePhone"), &var);
if ( SUCCEEDED(hr) )
{
    LONG lstart, lend;
    SAFEARRAY *sa = V_ARRAY( &var );
    VARIANT varItem;
 
    // Get the lower and upper bound.
    hr = SafeArrayGetLBound( sa, 1, &lstart );
    hr = SafeArrayGetUBound( sa, 1, &lend );
 
    // Iterate and print the content.
    VariantInit(&varItem);
    printf("Getting Home Phone using IADs::Get.\n");
    for ( long idx=lstart; idx <= lend; idx++ )
    {
        hr = SafeArrayGetElement( sa, &idx, &varItem );
        printf("%S ", V_BSTR(&varItem));
        VariantClear(&varItem);
    }
    printf("\n");
 
    VariantClear(&var);
}
 
// Cleanup.
if ( pADs )
{
    pADs->Release();
}

Requisiti

   
Client minimo supportato Windows Vista
Server minimo supportato Windows Server 2008
Piattaforma di destinazione Windows
Intestazione iads.h
DLL Activeds.dll

Vedi anche

ID

ID::Get

ID::GetInfo

ID::P ut

ID::P utEx

Interfacce cache delle proprietà