HRESULT CWIAPropertyManager::AddProperty( LONG lPropertyID, _In_ LPOLESTR pszName, LONG lAccessFlags, LONG lCurrValue) { HRESULT hr = E_INVALIDARG; if (pszName) { PWIA_PROPERTY_INFO_DATA pInfo = NULL; // // When a property is being added, always remove any existing property that has the same // property ID. Any call to AddProperty() means that the property being added should be // treated as the latest. // RemovePropertyAndDeleteData(lPropertyID); // // Allocate a property info structure: // pInfo = AllocatePropertyData(); if (pInfo) { // // Populate the data in the structure, and add it to the property list: // pInfo->pszName = pszName; pInfo->pid = lPropertyID; pInfo->pv.lVal = lCurrValue; pInfo->pv.vt = VT_I4; pInfo->ps.ulKind = PRSPEC_PROPID; pInfo->ps.propid = pInfo->pid; pInfo->wpi.lAccessFlags = lAccessFlags; pInfo->wpi.vt = pInfo->pv.vt; m_List.Append(pInfo); hr = S_OK; } else { hr = E_OUTOFMEMORY; } } return hr; }
HRESULT CWIAPropertyManager::AddProperty(LONG lPropertyID, __in LPOLESTR szName, LONG lAccessFlags, GUID guidCurrValue, GUID guidNomValue, __in CBasicDynamicArray<GUID> *pValueList) { HRESULT hr = E_INVALIDARG; if((szName)&&(pValueList)) { PWIA_PROPERTY_INFO_DATA pInfo = NULL; GUID *pguid = NULL; GUID *pguidList = NULL; // // when a property is being added, always remove any existing property that has the same // property ID. Any call to AddProperty() means that the property being added should be // treated as the lastest. // RemovePropertyAndDeleteData(lPropertyID); if(pValueList) { LONG lNumValues = (LONG)pValueList->Size(); if(lNumValues) { pguidList = (GUID*)LocalAlloc(LPTR,(sizeof(GUID)*lNumValues)); if(pguidList) { for(INT iIndex = 0; iIndex < pValueList->Size(); iIndex++) { pguidList[iIndex] = ((*pValueList)[iIndex]); } hr = S_OK; if(SUCCEEDED(hr)) { #pragma prefast(suppress:__WARNING_ALIASED_MEMORY_LEAK, "pguid is freed by DeletePropertyData() when m_List is destroyed.") pguid = new GUID; if(pguid) { *pguid = guidCurrValue; hr = S_OK; } else { hr = E_OUTOFMEMORY; } } } if(SUCCEEDED(hr)) { // // allocate a property info structure // pInfo = AllocatePropertyData(); if(pInfo) { // // populate the data in the structure, and add it to the property list // pInfo->szName = szName; pInfo->pid = lPropertyID; pInfo->pv.puuid = pguid; pInfo->pv.vt = VT_CLSID; pInfo->ps.ulKind = PRSPEC_PROPID; pInfo->ps.propid = pInfo->pid; pInfo->wpi.lAccessFlags = lAccessFlags; pInfo->wpi.vt = pInfo->pv.vt; pInfo->wpi.ValidVal.ListGuid.pList = pguidList; pInfo->wpi.ValidVal.ListGuid.Nom = guidNomValue; pInfo->wpi.ValidVal.ListGuid.cNumList = lNumValues; m_List.Append(pInfo); hr = S_OK; } else { hr = E_OUTOFMEMORY; } } else { hr = E_OUTOFMEMORY; } } else { hr = E_INVALIDARG; } } else { hr = E_INVALIDARG; } if(FAILED(hr)) { // free memory any allocated memory if failure occurs if(pguidList) { LocalFree(pguidList); pguidList = NULL; } if(pguid) { delete pguid; pguid = NULL; } } } return hr; }
HRESULT CWIAPropertyManager::AddProperty(LONG lPropertyID, __in LPOLESTR szName, LONG lAccessFlags, GUID guidCurrValue) { HRESULT hr = E_INVALIDARG; if(szName) { PWIA_PROPERTY_INFO_DATA pInfo = NULL; // // when a property is being added, always remove any existing property that has the same // property ID. Any call to AddProperty() means that the property being added should be // treated as the lastest. // RemovePropertyAndDeleteData(lPropertyID); #pragma prefast(suppress:__WARNING_ALIASED_MEMORY_LEAK, "pguid is freed by DeletePropertyData() when m_List is destroyed.") GUID *pguid = new GUID; if(pguid) { *pguid = guidCurrValue; hr = S_OK; } else { hr = E_OUTOFMEMORY; } if(SUCCEEDED(hr)) { // // allocate a property info structure // pInfo = AllocatePropertyData(); if(pInfo) { // // populate the data in the structure, and add it to the property list // pInfo->szName = szName; pInfo->pid = lPropertyID; pInfo->pv.puuid = pguid; pInfo->pv.vt = VT_CLSID; pInfo->ps.ulKind = PRSPEC_PROPID; pInfo->ps.propid = pInfo->pid; pInfo->wpi.lAccessFlags = lAccessFlags; pInfo->wpi.vt = pInfo->pv.vt; m_List.Append(pInfo); hr = S_OK; } else { // // Cleanup locally allocated memory // delete pguid; pguid = NULL; hr = E_OUTOFMEMORY; } } } return hr; }
HRESULT CWIAPropertyManager::AddProperty(LONG lPropertyID, __in LPOLESTR szName, LONG lAccessFlags, LONG lCurrValue, LONG lNomValue, __in CBasicDynamicArray<LONG> *pValueList) { HRESULT hr = E_INVALIDARG; if((szName)&&(pValueList)&&(pValueList->Size())) { PWIA_PROPERTY_INFO_DATA pInfo = NULL; LONG *pLongList = NULL; // // when a property is being added, always remove any existing property that has the same // property ID. Any call to AddProperty() means that the property being added should be // treated as the lastest. // RemovePropertyAndDeleteData(lPropertyID); if(pValueList) { LONG lNumValues = (LONG)pValueList->Size(); if(lNumValues) { pLongList = (LONG*)LocalAlloc(LPTR,(sizeof(LONG)*lNumValues)); if(pLongList) { for(INT iIndex = 0; iIndex < pValueList->Size(); iIndex++) { pLongList[iIndex] = ((*pValueList)[iIndex]); } hr = S_OK; } else { hr = E_OUTOFMEMORY; } if(SUCCEEDED(hr)) { // // allocate a property info structure // pInfo = AllocatePropertyData(); if(pInfo) { // // populate the data in the structure, and add it to the property list // pInfo->szName = szName; pInfo->pid = lPropertyID; pInfo->pv.lVal = lCurrValue; pInfo->pv.vt = VT_I4; pInfo->ps.ulKind = PRSPEC_PROPID; pInfo->ps.propid = pInfo->pid; pInfo->wpi.lAccessFlags = lAccessFlags; pInfo->wpi.vt = pInfo->pv.vt; pInfo->wpi.ValidVal.List.pList = (BYTE*)pLongList; pInfo->wpi.ValidVal.List.Nom = lNomValue; pInfo->wpi.ValidVal.List.cNumList = lNumValues; m_List.Append(pInfo); hr = S_OK; } else { hr = E_OUTOFMEMORY; } } } else { hr = E_INVALIDARG; } } else { hr = E_INVALIDARG; } if(FAILED(hr)) { if(pLongList) { LocalFree(pLongList); pLongList = NULL; } } } return hr; }
HRESULT CWIAPropertyManager::AddProperty(LONG lPropertyID, __in LPOLESTR szName, LONG lAccessFlags, LONG lCurrValue, LONG lNomValue, LONG lMinValue, LONG lMaxValue, LONG lInc) { HRESULT hr = E_INVALIDARG; if((szName)&& (lMinValue <= lMaxValue) && (lNomValue >= lMinValue) && (lNomValue <= lMaxValue) && (lCurrValue >= lMinValue) && (lCurrValue <= lMaxValue)) // TODO: validate lInc value??? { PWIA_PROPERTY_INFO_DATA pInfo = NULL; // // when a property is being added, always remove any existing property that has the same // property ID. Any call to AddProperty() means that the property being added should be // treated as the lastest. // RemovePropertyAndDeleteData(lPropertyID); // // allocate a property info structure // pInfo = AllocatePropertyData(); if(pInfo) { // // populate the data in the structure, and add it to the property list // pInfo->szName = szName; pInfo->pid = lPropertyID; pInfo->pv.lVal = lCurrValue; pInfo->pv.vt = VT_I4; pInfo->ps.ulKind = PRSPEC_PROPID; pInfo->ps.propid = pInfo->pid; pInfo->wpi.lAccessFlags = lAccessFlags; pInfo->wpi.vt = pInfo->pv.vt; pInfo->wpi.ValidVal.Range.Inc = lInc; pInfo->wpi.ValidVal.Range.Min = lMinValue; pInfo->wpi.ValidVal.Range.Max = lMaxValue; pInfo->wpi.ValidVal.Range.Nom = lNomValue; m_List.Append(pInfo); hr = S_OK; } else { hr = E_OUTOFMEMORY; } } return hr; }
HRESULT CWIAPropertyManager::AddProperty(LONG lPropertyID, __in LPOLESTR szName, LONG lAccessFlags, __in BYTE *pbCurrValue, ULONG ulNumItems) { HRESULT hr = E_INVALIDARG; if(szName) { PWIA_PROPERTY_INFO_DATA pInfo = NULL; // // when a property is being added, always remove any existing property that has the same // property ID. Any call to AddProperty() means that the property being added should be // treated as the lastest. // RemovePropertyAndDeleteData(lPropertyID); // // allocate a property info structure // pInfo = AllocatePropertyData(); if(pInfo) { // // populate the data in the structure, and add it to the property list // // Note: for a VT_VECTOR | VT_UI1 the correct PROPVARIANT member is: caub (type: CAUB) // // From MSDN: // // "If the type indicator is combined with VT_VECTOR by using an OR operator, the value is one of the counted array values. // This creates a DWORD count of elements, followed by a pointer to the specified repetitions of the value. // For example, a type indicator of VT_LPSTR|VT_VECTOR has a DWORD element count, followed by a pointer to an array of LPSTR elements. // VT_VECTOR can be combined by an OR operator with the following types: VT_I1, VT_UI1, VT_I2, VT_UI2, VT_BOOL, VT_I4, VT_UI4, VT_R4, // VT_R8, VT_ERROR, VT_I8, VT_UI8, VT_CY, VT_DATE, VT_FILETIME, VT_CLSID, VT_CF, VT_BSTR, VT_LPSTR, VT_LPWSTR, and VT_VARIANT". // pInfo->szName = szName; pInfo->pid = lPropertyID; pInfo->pv.caub.cElems = ulNumItems; pInfo->pv.caub.pElems = pbCurrValue; pInfo->pv.vt = VT_UI1 | VT_VECTOR; pInfo->ps.ulKind = PRSPEC_PROPID; pInfo->ps.propid = pInfo->pid; pInfo->wpi.lAccessFlags = lAccessFlags; pInfo->wpi.vt = pInfo->pv.vt; m_List.Append(pInfo); hr = S_OK; } else { hr = E_OUTOFMEMORY; } } return hr; }