/******************************************************************************* * * (C) COPYRIGHT MICROSOFT CORPORATION, 1998 * * TITLE: PROPARRY.CPP * * VERSION: 1.0 * * AUTHOR: ShaunIv * * DATE: 5/4/1999 * * DESCRIPTION: IWiaPropertyStorage cache definitions * *******************************************************************************/ #include "precomp.h" #pragma hdrstop CPropertyStorageArray::CPropertyStorageArray( const CPropertyStorageArray &other ) : m_nCount(0), m_ppvPropVariants(NULL), m_ppsPropSpecs(NULL), m_pstrPropNames(NULL) { Copy(other); } CPropertyStorageArray::CPropertyStorageArray(IUnknown *pIUnknown) : m_nCount(0), m_ppvPropVariants(NULL), m_ppsPropSpecs(NULL), m_pstrPropNames(NULL) { Initialize(pIUnknown); } CPropertyStorageArray::~CPropertyStorageArray(void) { Destroy(); } bool CPropertyStorageArray::IsValid(void) const { // It's OK to have an empty list, but it isn't considered valid return (m_nCount && m_ppvPropVariants && m_ppsPropSpecs && m_pstrPropNames); } HRESULT CPropertyStorageArray::Copy( const CPropertyStorageArray &other ) { Destroy(); HRESULT hr = S_OK; if (this != &other) { if (other.IsValid()) { m_nCount = other.Count(); if (m_nCount) { if (AllocateData()) { for (int i=0;iEnum(&pIEnum); if (SUCCEEDED(hr)) { STATPROPSTG StatPropStg; ZeroMemory(&StatPropStg,sizeof(StatPropStg)); while ((hr = pIEnum->Next(1,&StatPropStg, NULL)) == S_OK) { nCount++; if (StatPropStg.lpwstrName) { CoTaskMemFree(StatPropStg.lpwstrName); } ZeroMemory(&StatPropStg,sizeof(StatPropStg)); } } return(nCount); } HRESULT CPropertyStorageArray::GetPropertyNames( IWiaPropertyStorage *pIWiaPropertyStorage ) { IEnumSTATPROPSTG *pIEnum = NULL; HRESULT hr; int nCurrentIndex=0; hr = pIWiaPropertyStorage->Enum(&pIEnum); if (SUCCEEDED(hr)) { STATPROPSTG StatPropStg; ZeroMemory(&StatPropStg,sizeof(StatPropStg)); while ((hr = pIEnum->Next(1,&StatPropStg, NULL)) == S_OK) { m_ppsPropSpecs[nCurrentIndex].propid = StatPropStg.propid; m_ppsPropSpecs[nCurrentIndex].ulKind = PRSPEC_PROPID; if (StatPropStg.lpwstrName) { m_pstrPropNames[nCurrentIndex] = new WCHAR[lstrlenW(StatPropStg.lpwstrName)+1]; if (m_pstrPropNames[nCurrentIndex]) { lstrcpyW( m_pstrPropNames[nCurrentIndex], StatPropStg.lpwstrName ); CoTaskMemFree(StatPropStg.lpwstrName); } else { hr = E_OUTOFMEMORY; CoTaskMemFree(StatPropStg.lpwstrName); break; } } nCurrentIndex++; } } return(hr); } HRESULT CPropertyStorageArray::Initialize( IUnknown *pIUnknown ) { Destroy(); HRESULT hr = E_INVALIDARG; if (pIUnknown) { CComPtr pIWiaPropertyStorage; hr = pIUnknown->QueryInterface(IID_IWiaPropertyStorage, (void**)&pIWiaPropertyStorage); if (SUCCEEDED(hr)) { m_nCount = GetPropertyCount( pIWiaPropertyStorage ); if (m_nCount) { if (AllocateData()) { hr = GetPropertyNames( pIWiaPropertyStorage ); if (SUCCEEDED(hr)) { hr = pIWiaPropertyStorage->ReadMultiple( m_nCount, m_ppsPropSpecs, m_ppvPropVariants ); } } } } } if (!SUCCEEDED(hr)) { Destroy(); } return(hr); } HRESULT CPropertyStorageArray::Read( IUnknown *pIUnknown ) { HRESULT hr = E_FAIL; if (IsValid()) { ClearPropVariantArray(); CComPtr pIWiaPropertyStorage; hr = pIUnknown->QueryInterface(IID_IWiaPropertyStorage, (void**)&pIWiaPropertyStorage); if (SUCCEEDED(hr)) { hr = pIWiaPropertyStorage->ReadMultiple( m_nCount, m_ppsPropSpecs, m_ppvPropVariants ); } } return(hr); } HRESULT CPropertyStorageArray::Write( IUnknown *pIUnknown ) { HRESULT hr = E_FAIL; if (IsValid()) { CComPtr pIWiaPropertyStorage; hr = pIUnknown->QueryInterface(IID_IWiaPropertyStorage, (void**)&pIWiaPropertyStorage); if (SUCCEEDED(hr)) { hr = pIWiaPropertyStorage->WriteMultiple( m_nCount, m_ppsPropSpecs, m_ppvPropVariants, WIA_IPA_FIRST); } } return(hr); } HRESULT CPropertyStorageArray::Write( IUnknown *pIUnknown, PROPID propId ) { HRESULT hr = E_FAIL; if (IsValid()) { int nIndex = GetIndexFromPropId( propId ); if (nIndex >= 0) { CComPtr pIWiaPropertyStorage; hr = pIUnknown->QueryInterface(IID_IWiaPropertyStorage, (void**)&pIWiaPropertyStorage); if (SUCCEEDED(hr)) { hr = pIWiaPropertyStorage->WriteMultiple( 1, m_ppsPropSpecs+nIndex, m_ppvPropVariants+nIndex, WIA_IPA_FIRST ); } } } return(hr); } int CPropertyStorageArray::GetIndexFromPropId( PROPID propId ) { if (!IsValid()) return -1; for (int i=0;ivt) return(false); nProp = ppvPropValue->lVal; return(TRUE); } bool CPropertyStorageArray::GetProperty( PROPID propId, CSimpleStringWide &strProp ) { PROPVARIANT *ppvPropValue = GetProperty( propId ); if (!ppvPropValue) return(false); if (VT_LPWSTR != ppvPropValue->vt && VT_BSTR != ppvPropValue->vt) return(false); strProp = ppvPropValue->pwszVal; return(true); } bool CPropertyStorageArray::SetProperty( PROPID propId, PROPVARIANT *pPropVar ) { PROPVARIANT *ppvPropValue = GetProperty( propId ); if (ppvPropValue) { PropVariantClear(ppvPropValue); return(SUCCEEDED(PropVariantCopy(ppvPropValue,pPropVar))); } return(false); } bool CPropertyStorageArray::SetProperty( PROPID propId, LONG nProp ) { PROPVARIANT *ppvPropValue = GetProperty( propId ); if (ppvPropValue) { ppvPropValue->vt = VT_I4; ppvPropValue->lVal = nProp; return(true); } return(false); } int CPropertyStorageArray::Count(void) const { return(m_nCount); } PROPVARIANT *CPropertyStorageArray::PropVariants(void) const { return(m_ppvPropVariants); } PROPSPEC *CPropertyStorageArray::PropSpecs(void) const { return(m_ppsPropSpecs); } LPWSTR *CPropertyStorageArray::PropNames(void) const { return(m_pstrPropNames); } void CPropertyStorageArray::Dump( int nIndex ) { #if defined(WIA_DEBUG) WIA_TRACE((TEXT("Dumping IWiaPropertyStorage:"))); int nStart = nIndex < 0 ? 0 : nIndex; int nCount = nIndex < 0 ? Count() : 1; for (int i=nStart;i