IADsPropertyValue2::PutObjectProperty method

The IADsPropertyValue2::PutObjectProperty method sets an attribute value.

Syntax


HRESULT PutObjectProperty(
  [inlong    lnADsType,
  [in] VARIANT pvProp
);

Parameters

lnADsType [in]

Contains one of the ADSTYPEENUM values that specifies the data format of the value set. This value must correspond to the pvProp variant type. For more information and a list of the lnADsType values and corresponding pvProp variant types, see IADsPropertyValue2.

pvProp [in]

Pointer to a VARIANT that contains the new attribute value. The variant type of this data must correspond to the value in lnADsType. For more information and a list of the lnADsType values and corresponding pvProp variant types, see IADsPropertyValue2.

Return value

Returns S_OK if successful or an error code otherwise. The following are the most common error codes.

E_ADS_BAD_PARAMETER

lnADsType is invalid.

E_ADS_CANT_CONVERT_DATATYPE

The attribute value cannot be converted to the requested data type.

Examples

The following code example shows how to use IADsPropertyValue2::PutObjectProperty to change a property value, descString, of the property entry in a property list.


Const ADSTYPE_CASE_IGNORE_STRING = 3
Dim propList As IADsPropertyList
Dim propEntry As IADsPropertyEntry
Dim propVal As IADsPropertyValue2
Dim descString As String

Set propList = GetObject("LDAP://dc01/DC=Fabrikam,DC=com")
propList.GetInfo
 
Set propEntry = propList.GetPropertyItem("description", ADSTYPE_CASE_IGNORE_STRING)
 
descString = "This is Fabrikam.com"
For Each v In propEntry.Values
    Set propVal = v
    propVal.PutObjectProperty ADSTYPE_CASE_IGNORE_STRING, descString
Next
propList.Setinfo

Set propList = Nothing
Set propEntry = Nothing
Set propVal = Nothing

The following code example shows how to use IADsPropertyValue2::PutObjectProperty to change a property value, descString, of the property entry in 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);
 
// Bind to the directory object.
HRESULT hr = ADsGetObject(L"LDAP://dc01/DC=Fabrikam,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(CComBSTR("description"), valType, &var);
hr = V_DISPATCH(&var)->QueryInterface(IID_IADsPropertyEntry,
                                      (void**)&pEntry);
VariantClear(&var);
 
// Get the property value object.
hr = pEntry->get_Values(&var);
SAFEARRAY *sa = V_ARRAY( &var );
long item = 0;
hr = SafeArrayGetElement( sa, &item, &varItem );
hr = V_DISPATCH(&varItem)->QueryInterface(IID_IADsPropertyValue2,
                                          (void**)&pVal2);
V_BSTR(&varProp) = "This is Fabrikam.com";
hr = pVal2->PutObjectProperty(&valType,&varProp);
 
// Commit the change to the directory store.
hr = pList->SetInfo();

Cleanup:
    if(pList)
        pList->Release();

    if(pEntry)
        pEntry->Release();

    if(pVal2)
        pVal2->Release();

    if(pEnum)
        pEnum->Release();

    VariantClear(&varItem);
    VariantClear(&varProp);
    VariantClear(&var);

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

Iads.h

DLL

Activeds.dll

IID

IID_IADsPropertyValue2 is defined as 306E831C-5BC7-11D1-A3B8-00C04FB950DC

See also

ADSI Error Codes
ADSTYPEENUM
IADsPropertyValue
IADsPropertyValue2

 

 

Show: