Platform SDK: Active Directory, ADSI, and Directory Services

IADsPropertyValue2::GetObjectProperty

The IADsPropertyValue2::GetObjectProperty method retrieves the property values of an ADSI object.

HRESULT IADsPropertyValue2::GetObjectProperty(
  long *lnADsType,
  VARIANT *pvProp
);

Parameters

lnADsType
[out, in] A pointer to the ADsType of the data referred to by pvProp. ADSI-defined data types can be found in the ADSTYPEENUM enumeration.
pvProp
[retval, out] Pointer to property values of the VARIANT type, including VT_BSTR for strings, VT_UI1 for bytes, VT_DATE for time, and VT_DISPATCH for objects representing the property values.

Return Values

The method supports the standard HRESULT return values, including S_OK. For other return values, see ADSI Error Codes.

Remarks

If you are not sure of the return data type, you should pass in the ADSTYPE_UNKNOWN constant as pointed to by the lnADsType pointer. In this case, ADSI will try to resolve the data types of the property value using the default data types as defined in the IADsPropertyValue interface. When you specify any other constant through lnADsType, ADSI will return the data only if the data type matches.

Example Code [Visual Basic]

The following Visual Basic code snippet shows how to use IADsPropertyValue2::GetObjectProperty to retrieve the value of the property entry from a property list.

Dim propList As IADsPropertyList
Dim propEnty As IADsPropertyEntry
Dim propVal As IADsPropertyValue2
Dim descString as String
 
Set propList = GetObject("LDAP://dc01/DC=Microsoft,DC=com")
propList.GetInfo
 
Set propEntry = propList.GetPropertyItem("description", ADSTYPE_CASE_IGNORE_STRING)
 
For Each v In propEntry.Values
    Set propVal = v
    descString = propVal.GetObjectProperty ADSTYPE_CASE_IGNORE_STRING
    MsgBox "Description: " descString
Next

Example Code [C++]

The following C++ code snippet shows how to use IADsPropertyValue2::GetObjectProperty to retrieve the value of the property entry from a property list.

#include <activeds.h>
#include <stdio.h>
IADsPropertyList *pList;
IADsPropertyEntry *pEntry;
IADsPropertyValue2 *pVal2;
IADs *pObj;
VARIANT var, varProp, varItem;
long valType = ADSTYPE_CASE_IGNORE_STRING;
IEnumVARIANT *pEnum = NULL;
LONG lstart, lend;
 
VariantInit(&var);
VariantInit(&varItem);
VariantInit(&varProp);
 
// bind to directory object
HRESULT hr = ADsGetObject(L"LDAP://dc01/DC=Microsoft,DC=com",
                          IID_IADsPropertyList,
                          (void**)&pList);
 
// initialize the property cache
hr = pList->QueryInterface(IID_IADs,(void**)&pObj);
pObj->GetInfo();
pObj->Release();
 
// get a property entry
hr = pList->GetPropertyItem(L"description", valType, &var);
pList->Release();
hr = V_DISPATCH(&var)->QueryInterface(IID_IADsPropertyEntry,
                                      (void**)&pEntry);
VariantClear(&var);
 
// get the value array of the property entry
hr = pEntry->get_Values(&var);
SAFEARRAY *sa = V_ARRAY( &var );
 
// Get the lower and upper bound and iterate and print the values
hr = SafeArrayGetLBound( sa, 1, &lstart );
hr = SafeArrayGetUBound( sa, 1, &lend );
printf(" Property value(s) = ");
for ( long idx=lstart; idx < lend+1; idx++ )    {
    hr = SafeArrayGetElement( sa, &idx, &varItem );
    hr = V_DISPATCH(&varItem)->QueryInterface(IID_IADsPropertyValue2,
                                              (void**)&pVal2);
    hr = pVal2->GetObjectProperty(&valType,&varProp);
    printf(" %S ", V_BSTR(&varProp));
    VariantClear(&varItem);
    VariantClear(&varProp);
}
printf("\n");
VariantClear(&var);

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

ADSI Error Codes, ADSTYPEENUM, IADsPropertyValue, IADsPropertyValue2