📄 wiapropertymanager.cpp
字号:
/**************************************************************************
*
* Copyright (c) 2003 Microsoft Corporation
*
* Title: wiapropertymanager.cpp
*
* Date:
*
* Description: This file contains the class implementation of the
* CWIAPropertyManager class that encapsulates simple WIA
* property creation.
*
***************************************************************************/
#include "stdafx.h"
CWIAPropertyManager::CWIAPropertyManager()
{
;
}
CWIAPropertyManager::~CWIAPropertyManager()
{
//
// cleanup any items contained in the property list
// before exiting
//
for(INT i = 0; i < m_List.Size(); i++)
{
PWIA_PROPERTY_INFO_DATA pPropertyData = m_List[i];
if(pPropertyData)
{
//
// delete contents
//
DeletePropertyData(pPropertyData);
//
// delete container
//
delete pPropertyData;
}
}
}
/*****************************************************************************
Function Name: FindProperty
Arguments:
LONG lPropertyID - Property ID of the property to find
Description:
This function finds the specified property, and removes it from the list
of properties
*****************************************************************************/
PWIA_PROPERTY_INFO_DATA CWIAPropertyManager::FindProperty(LONG lPropertyID)
{
PWIA_PROPERTY_INFO_DATA pInfo = NULL;
for(INT i = 0; i< m_List.Size(); i++)
{
PWIA_PROPERTY_INFO_DATA pPropertyData = m_List[i];
if(pPropertyData->pid == (LONG)lPropertyID)
{
pInfo = pPropertyData;
break;
}
}
return pInfo;
}
/*****************************************************************************
Function Name: DeletePropertyData
Arguments:
PWIA_PROPERTY_INFO_DATA pInfo - pointer containing the property data
Description:
This function deletes the contents of a WIA_PROPERTY_DATA structure.
*****************************************************************************/
HRESULT CWIAPropertyManager::DeletePropertyData(__inout PWIA_PROPERTY_INFO_DATA pInfo)
{
HRESULT hr = E_INVALIDARG;
if (pInfo)
{
//
// delete any allocated LISTS
//
if (pInfo->wpi.lAccessFlags & WIA_PROP_LIST)
{
if(pInfo->pv.vt & VT_I4)
{
WIAS_TRACE((g_hInst,"Freeing LONG List for %d",pInfo->pid));
if (pInfo->wpi.ValidVal.List.pList)
{
LocalFree(pInfo->wpi.ValidVal.List.pList);
pInfo->wpi.ValidVal.List.pList = NULL;
}
}
if(pInfo->pv.vt & VT_CLSID)
{
WIAS_TRACE((g_hInst,"Freeing GUID List for %d",pInfo->pid));
if (pInfo->wpi.ValidVal.ListGuid.pList)
{
LocalFree(pInfo->wpi.ValidVal.ListGuid.pList);
pInfo->wpi.ValidVal.ListGuid.pList = NULL;
}
}
}
//
// free any allocated BSTRS
//
if (pInfo->pv.vt == VT_BSTR)
{
SysFreeString(pInfo->pv.bstrVal);
pInfo->pv.bstrVal = NULL;
}
//
// delete any allocated GUIDS
//
if (pInfo->pv.vt == VT_CLSID)
{
delete pInfo->pv.puuid;
pInfo->pv.puuid = NULL;
}
hr = S_OK;
}
return hr;
}
/*****************************************************************************
Function Name: AllocatePropertyData
Arguments:
NONE
Description:
This function allocates a WIA_PROPERTY_INFO_DATA strucuture, and initializes
the members.
*****************************************************************************/
PWIA_PROPERTY_INFO_DATA CWIAPropertyManager::AllocatePropertyData()
{
PWIA_PROPERTY_INFO_DATA pInfo = NULL;
pInfo = new WIA_PROPERTY_INFO_DATA;
if (pInfo)
{
//
// erase all values in newly allocated property data structure
//
memset(pInfo,0,sizeof(WIA_PROPERTY_INFO_DATA));
//
// properly initialize the property variant
//
PropVariantInit(&pInfo->pv);
}
return pInfo;
}
/*****************************************************************************
Function Name: RemovePropertyAndDeleteData
Arguments:
LONG lPropertyID - Property ID of the property to remove and delete
Description:
This function finds the property specified by lPropertyID and deletes the
contents of the WIA_PROPERTY_INFO_DATA.
*****************************************************************************/
HRESULT CWIAPropertyManager::RemovePropertyAndDeleteData(LONG lPropertyID)
{
//
// find any existing property with the same ID, and remove it from the list
//
PWIA_PROPERTY_INFO_DATA pInfo = FindProperty(lPropertyID);
if (pInfo)
{
//
// find and remove the property info from the list and delete the
// contents
//
m_List.Delete(m_List.Find(pInfo));
delete pInfo;
pInfo = NULL;
}
return S_OK;
}
/*****************************************************************************
Function Name: AddProperty
Arguments:
LONG lPropertyID - Property ID
LPOLESTR szName - Property NAME
LONG lAccessFlags - Property Access Flags
LONG lCurrValue - Current Property Value
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, LONG lCurrValue)
{
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
//
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;
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
BYTE *pbCurrValue - Current Property Value (BYTE vector)
ULONG ulNumItems - Number of items in the current propery value vector
Description:
This function adds a new VT_UI1 | VT_VECTOR 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,
__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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -