IADsPropertyList ::P utPropertyItem, méthode (iads.h)
La méthode IADsPropertyList ::P utPropertyItem met à jour les valeurs d’un élément dans la liste de propriétés.
Syntaxe
HRESULT PutPropertyItem(
[in] VARIANT varData
);
Paramètres
[in] varData
Nouvelles valeurs de propriété à placer dans le cache de propriétés. Celui-ci doit contenir le pointeur IDispatch vers l’objet qui implémente l’IADsPropertyEntry qui contient les valeurs de propriété modifiées.
Valeur retournée
Cette méthode prend en charge les valeurs de retour HRESULT standard, y compris S_OK. Pour plus d’informations et d’autres valeurs de retour, consultez Codes d’erreur ADSI.
Remarques
L’IADsPropertyEntry ::p ut_ControlCode doit être défini sur l’opération de modification/ajout/suppression souhaitée à l’aide de la valeur de ADS_PROPERTY_OPERATION_ENUM appropriée. Une fois PutPropertyItem appelé, vous devez appeler IADs ::SetInfo pour conserver toutes les modifications apportées au magasin d’annuaires. Les valeurs de propriété ne sont pas validées tant que la méthode IADs ::SetInfo n’est pas appelée.
Exemples
L’exemple de code suivant montre comment ajouter une nouvelle entrée à une liste de propriétés à l’aide de PutPropertyItem.
Dim propList As IADsPropertyList
Dim propVal As IADsPropertyValue
Dim propEntry As IADsPropertyEntry
On Error GoTo Cleanup
Set propList = GetObject("LDAP://DC=Fabrikam,DC=com")
Set propVal = New PropertyValue
'--- Property Value-----
propVal.CaseIgnoreString = "Fabrikam, Inc - Seattle, WA"
propVal.ADsType = ADSTYPE_CASE_IGNORE_STRING
'--- Property Entry ----
Set propEntry = New PropertyEntry
propEntry.Name = "adminDescription"
propEntry.Values = Array(propVal)
propEntry.ControlCode = ADS_PROPERTY_UPDATE
propEntry.ADsType = ADSTYPE_CASE_IGNORE_STRING
' --- Property List----
propList.PutPropertyItem (propEntry)
' query the IADs interface on the propList object
Dim IADsObj As IADs
Set IADsObj=propList
' Commit changes of the property list to the directory store.
IADsObj.SetInfo
Cleanup:
If(Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set propList = Nothing
Set propVal = Nothing
Set propEntry = Nothing
Set IADsObj = Nothing
L’exemple de code suivant ajoute une nouvelle entrée à une liste de propriétés à l’aide de IADsPropertyList ::P utPropertyItem.
// forward declaration of a helper function
HRESULT ADsBuildVarArrayDisp(IDispatch ** ppObjs,
DWORD dwObjs,
VARIANT * pVar
)
int main()
{
HRESULT hr = CoInitialize(NULL);
IADsPropertyList *pList;
hr = ADsOpenObject(L"LDAP://dc=Fabrikam,dc=com",
L"Administrator",
L"",
ADS_SECURE_AUTHENTICATION,
IID_IADsPropertyList,
(void**)&pList);
if(hr!=S_OK)
{
_tprintf(TEXT("An error has occurred."));
return;
}
// create a property value object
IADsPropertyValue *pVal;
hr = CoCreateInstance(CLSID_PropertyValue,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsPropertyValue,
(void**)&pVal);
if(hr!=S_OK)
{
_tprintf(TEXT("An error has occurred."));
pList->Release();
return;
}
hr = pVal->put_CaseIgnoreString(CComBSTR("Fabrikam, Inc - Seattle, WA"));
hr = pVal->put_ADsType(ADSTYPE_CASE_IGNORE_STRING);
// put the propertyValue object into a variant array for
// assignment to a propertyEntry object
IDispatch *pDisp;
hr = pVal->QueryInterface(IID_IDispatch,(void**)&pDisp);
hr = pVal->Release();
VARIANT vVals;
VariantInit(&vVals);
hr = ADsBuildVarArrayDisp(&pDisp,1,&vVals); //code given below.
pDisp->Release();
if(hr!=S_OK)
{
_tprintf(TEXT("An error has occurred."));
pList->Release();
return;
}
// Create a propertyEntry object
IADsPropertyEntry *pEntry;
hr = CoCreateInstance(CLSID_PropertyEntry,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsPropertyEntry,
(void**)&pEntry);
hr = pEntry->put_Name(CComBSTR("adminDescription"));
hr = pEntry->put_ControlCode(ADS_PROPERTY_UPDATE);
hr = pEntry->put_ADsType(ADSTYPE_CASE_IGNORE_STRING);
hr = pEntry->put_Values(vVals);
VariantClear(&vVals);
// Convert pEntry to pDisp for use in pList.PutPropertyItem
hr = pEntry->QueryInterface(IID_IDispatch,(void**)&pDisp);
pEntry->Release();
VARIANT vEntry;
VariantInit(&vEntry);
V_DISPATCH(&vEntry)=pDisp;
V_VT(&vEntry)= VT_DISPATCH;
hr = pList->PutPropertyItem(vEntry);
VariantClear(&vEntry);
IADs *pObj;
hr = pList->QueryInterface(IID_IADs,(void**)&pObj);
pObj->SetInfo();
pObj->Release();
pList->Release();
CoUninitialize();
return 0;
}
////////////////
// Helper function to build a variant array of IDispatch objects.
///////////////
HRESULT ADsBuildVarArrayDisp(
IDispatch ** ppObjs,
DWORD dwObjs,
VARIANT * pVar
)
{
VARIANT v;
SAFEARRAYBOUND sabNewArray;
DWORD i;
SAFEARRAY *psa = NULL;
HRESULT hr = E_FAIL;
if((!IDispatch) || (dwObjs<=0))
{
return E_INVALIDARG;
}
sabNewArray.cElements = dwObjs;
sabNewArray.lLbound = 0;
psa = SafeArrayCreate(VT_VARIANT, 1, &sabNewArray);
if (!pVar) {
hr = E_ADS_BAD_PARAMETER;
goto Fail;
}
VariantInit(pVar);
if (!psa) {
goto Fail;
}
for (i = 0; i < dwObjs; i++) {
VariantInit(&v);
V_VT(&v) = VT_DISPATCH;
V_DISPATCH(&v) = *(ppObjs + i);
hr = SafeArrayPutElement(psa,
(long FAR *)&i,
&v
);
if (FAILED(hr)) {
goto Fail;
}
}
V_VT(pVar) = VT_VARIANT | VT_ARRAY;
V_ARRAY(pVar) = psa;
return(ResultFromScode(S_OK));
Fail:
if (psa) {
SafeArrayDestroy(psa);
}
return(E_FAIL);
}
Configuration requise
Condition requise | Valeur |
---|---|
Client minimal pris en charge | Windows Vista |
Serveur minimal pris en charge | Windows Server 2008 |
Plateforme cible | Windows |
En-tête | iads.h |
DLL | Activeds.dll |
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour