| Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsPropertyValue2::GetObjectProperty method retrieves the property values of an ADSI object.
HRESULT IADsPropertyValue2::GetObjectProperty( long *lnADsType, VARIANT *pvProp );
The method supports the standard HRESULT return values, including S_OK. For other return values, see ADSI Error Codes.
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.
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
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);
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.
ADSI Error Codes, ADSTYPEENUM, IADsPropertyValue, IADsPropertyValue2