Directory Services |
The IADsPropertyValue2::GetObjectProperty method retrieves the property values of an ADSI object.
HRESULT GetObjectProperty( long* lnADsType, VARIANT* pvProp );
The method supports the standard HRESULT return values, including S_OK. For more information and other return values, see ADSI Error Codes.
If the data type is unknown, pass in the ADSTYPE_UNKNOWN constant as pointed to by the lnADsType pointer. In this case, ADSI attempts 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 code example shows how to use IADsPropertyValue2::GetObjectProperty to retrieve the value of the property entry from a property list.
Dim propList As IADsPropertyList Dim propEntry As IADsPropertyEntry Dim propVal As IADsPropertyValue2 Dim descString As String On Error GoTo Cleanup Set propList = GetObject("LDAP://dc01/DC=Fabrikam,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 Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set propList = Nothing Set propEntry = Nothing Set propVal = Nothing
The following code example 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 = NULL; IADsPropertyEntry *pEntry = NULL; IADsPropertyValue2 *pVal2 = NULL; IADs *pObj = NULL; 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=Fabrikam,DC=com", IID_IADsPropertyList, (void**)&pList); if(FAILED(hr)){goto Cleanup;} // Initialize the property cache. hr = pList->QueryInterface(IID_IADs,(void**)&pObj); if(FAILED(hr)){goto Cleanup;} pObj->GetInfo(); pObj->Release(); // Get a property entry. hr = pList->GetPropertyItem(CComBSTR("description"), valType, &var); if(FAILED(hr)){goto Cleanup;} 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); if(FAILED(hr)){goto Cleanup;} 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); if(FAILED(hr)){goto Cleanup;} hr = pVal2->GetObjectProperty(&valType,&varProp); if(FAILED(hr)){goto Cleanup;} printf(" %S ", V_BSTR(&varProp)); VariantClear(&varItem); VariantClear(&varProp); } printf("\n"); Cleanup: if(pList) pList->Release(); if(pEntry) pEntry->Release(); if(pVal2) pVal2->Release(); if(pEnum) pEnum->Release(); VariantClear(&varItem); VariantClear(&varProp); VariantClear(&var);
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.
ADSI Error Codes, ADSTYPEENUM, IADsPropertyValue, IADsPropertyValue2