Example Code for Using IADsProperty Interfaces to Access the Property Cache
The following code example shows how to use the IADsPropertyList, IADsPropertyEntry, and IADsPropertyValue interfaces with C++ and ADSI.
HRESULT hr;
BSTR bstr;
VARIANT var;
IDispatch *pDispatch;
IADsPropertyList *pPropList;
IADsPropertyEntry *pEntry;
IADsPropertyValue *pValue;
LONG lADsType;
IADs *pADs=NULL;
//////////////////////////////////////////////////////////
// Be aware that, for brevity, error handling is omitted.
//////////////////////////////////////////////////////////
hr = ADsGetObject(L"LDAP://DC=Sales,DC=Fabrikam,DC=Com", IID_IADs, (void**) &pADs);
///////////////////////////////////////////////////////////////////
// Retrieve objects prior to calling IADsProperty* methods.
///////////////////////////////////////////////////////////////////
hr = pADs->GetInfo();
hr = pADs->QueryInterface(IID_IADsPropertyList, (void**) &pPropList);
pADs->Release();
//////////////////////////////////////////////////
// Get the DC property.
//////////////////////////////////////////////////
hr = pPropList->GetPropertyItem(CComBSTR("dc"), ADSTYPE_CASE_IGNORE_STRING, &var);
if (SUCCEEDED(hr))
{
//////////////////////////////////////////
// Get the IADsPropertyEntry interface.
//////////////////////////////////////////
pDispatch = V_DISPATCH( &var );
hr = pDispatch->QueryInterface(IID_IADsPropertyEntry, (void**)&pEntry);
VariantClear(&var);
if (SUCCEEDED(hr))
{
VARIANT varValueArray;
VARIANT varValue;
long idx=0;
///////////////////////////////////////////////
// get_Values return array of VT_DISPATCH.
///////////////////////////////////////////////
hr = pEntry->get_Values(&varValueArray);
hr = pEntry->get_ADsType(&lADsType);
hr = SafeArrayGetElement(V_ARRAY(&varValueArray), &idx, &varValue);
pEntry->Release(); // Release entry.
/////////////////////////////////////
// IADsPropertyValue
/////////////////////////////////////
pDispatch = (IDispatch*) V_DISPATCH(&varValue);
hr = pDispatch->QueryInterface(IID_IADsPropertyValue,
(void**) &pValue);
pDispatch->Release();
/////////////////////////////
// Display the value.
/////////////////////////////
hr = pValue->get_CaseIgnoreString(&bstr);
printf("%S\n", bstr);
SysFreeString(bstr);
pValue->Release();
}
}
The following code example shows how to use the IADsPropertyList, IADsPropertyEntry, and IADsPropertyValue interfaces using Visual Basic and ADSI.
Dim propList As IADsPropertyList
Dim propEntry As IADsPropertyEntry
Dim propVal As IADsPropertyValue
Dim count As Long
Set propList = GetObject("LDAP://dc01/DC=Fabrikam,DC=com")
propList.GetInfo
count = propList.PropertyCount
Debug.Print "No of Property Found: " & count
For i = 0 To count - 1
' Each item in the property list has a property entry.
Set propEntry = propList.Item(i)
Debug.Print propEntry.Name
Debug.Print propEntry.ADsType
' Each value in property entry has property values.
For Each v In propEntry.Values
Set propVal = v
Debug.Print propVal.ADsType
Next
Next