📄 wiapropertymanager.cpp
字号:
*****************************************************************************/
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);
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
{
hr = E_OUTOFMEMORY;
}
}
}
return hr;
}
/*****************************************************************************
Function Name: AddProperty
Arguments:
LONG lPropertyID - Property ID
LPOLESTR szName - Property NAME
LONG lAccessFlags - Property Access Flags
GUID guidCurrValue - Current Property Value
GUID guidNomValue - Property Nominal Value
CBasicDynamicArray<GUID> - GUID List
Description:
This function adds a new property to the property list.
Remarks:
If a property exists with the same property ID:
1. The old property is removed from the list, and the contents
destroyed
2. The new property is added to the list.
*****************************************************************************/
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))
{
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;
}
/*****************************************************************************
Function Name: RemoveProperty
Arguments:
LONG lPropertyID - Property ID
Description:
This function removes a property from the property list.
*****************************************************************************/
HRESULT CWIAPropertyManager::RemoveProperty(LONG lPropertyID)
{
return RemovePropertyAndDeleteData(lPropertyID);
}
/*****************************************************************************
Function Name: SetItemProperties
Arguments:
BYTE *pWiasContext - WIA Context provided by the WIA service
Description:
This function uses WIA helper functions to upload the properties to the
WIA service.
*****************************************************************************/
HRESULT CWIAPropertyManager::SetItemProperties(__inout BYTE *pWiasContext)
{
HRESULT hr = E_INVALIDARG;
if(pWiasContext)
{
hr = S_OK;
//
// get current number of properties in the list
//
LONG lNumProps = m_List.Size();
if(lNumProps)
{
PWIA_PROPERTY_INFO_DATA pInfo = NULL;
LONG lIndex = 0;
LPOLESTR *pszName = NULL;
PROPID *ppid = NULL;
PROPVARIANT *ppv = NULL;
PROPSPEC *pps = NULL;
WIA_PROPERTY_INFO *pwpi = NULL;
//
// allocate arrays of structures needed to contain the property data
//
pszName = new LPOLESTR[lNumProps];
ppid = new PROPID[lNumProps];
ppv = new PROPVARIANT[lNumProps];
pps = new PROPSPEC[lNumProps];
pwpi = new WIA_PROPERTY_INFO[lNumProps];
if((pszName)&&(ppid)&&(ppv)&&(pps)&&(pwpi))
{
//
// copy the property data into the proper structures
//
for(INT i = 0; i < m_List.Size(); i++)
{
PWIA_PROPERTY_INFO_DATA pPropertyData = m_List[i];
if(pPropertyData)
{
pszName[lIndex] = pPropertyData->szName;
ppid[lIndex] = pPropertyData->pid;
memcpy(&ppv[lIndex],&pPropertyData->pv,sizeof(PROPVARIANT));
memcpy(&pps[lIndex],&pPropertyData->ps, sizeof(PROPSPEC));
memcpy(&pwpi[lIndex],&pPropertyData->wpi,sizeof(WIA_PROPERTY_INFO));
lIndex++;
}
}
//
// send the property names to the WIA service
//
hr = wiasSetItemPropNames(pWiasContext,lNumProps,ppid,pszName);
if(SUCCEEDED(hr))
{
//
// send the property values to the WIA service
//
hr = wiasWriteMultiple(pWiasContext,lNumProps,pps,ppv);
if(SUCCEEDED(hr))
{
//
// send the property valid values to the WIA service
//
hr = wiasSetItemPropAttribs(pWiasContext,lNumProps,pps,pwpi);
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "CWIAPropertyManager_SetItemProperties - wiasSetItemPropAttribs failed"));
}
}
else
{
WIAS_ERROR((g_hInst, "CWIAPropertyManager_SetItemProperties - wiasWriteMultiple failed"));
}
}
else
{
WIAS_ERROR((g_hInst, "CWIAPropertyManager_SetItemProperties - wiasSetItemPropNames failed"));
}
}
else
{
WIAS_ERROR((g_hInst, "CWIAPropertyManager_SetItemProperties - failed to allocate memory for property arrays"));
hr = E_OUTOFMEMORY;
}
//
// always delete any temporary memory allocated before exiting the function. The WIA
// service makes a copy of the information during the "wias" helper calls.
//
if(pszName)
{
delete [] pszName;
pszName = NULL;
}
if(ppid)
{
delete [] ppid;
ppid = NULL;
}
if(ppv)
{
delete [] ppv;
ppid = NULL;
}
if(pps)
{
delete [] pps;
ppid = NULL;
}
if(pwpi)
{
delete [] pwpi;
ppid = NULL;
}
}
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -