diff options
author | Stef Walter <stef@thewalter.net> | 2003-09-17 19:07:23 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2003-09-17 19:07:23 +0000 |
commit | 3f95d417d9e623ac0c74df8ef11d7a01846392dd (patch) | |
tree | 45ec73f2dc07eafd7f41a6f62a8cdfbaa279469f /Common/CmptData.cpp |
Diffstat (limited to 'Common/CmptData.cpp')
-rw-r--r-- | Common/CmptData.cpp | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/Common/CmptData.cpp b/Common/CmptData.cpp new file mode 100644 index 0000000..2fd8878 --- /dev/null +++ b/Common/CmptData.cpp @@ -0,0 +1,200 @@ +// ShutdownData.cpp: implementation of the CPropertyBagImpl class. +// +////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "CmptData.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CPropertyBag::CPropertyBag() +{ + m_pBag = NULL; +} + +CPropertyBag::~CPropertyBag() +{ + m_pBag = NULL; +} + +HRESULT CPropertyBag::Initialize(IUnknown * pUnk) +{ + if(pUnk == NULL) + { + if(m_pBag != NULL) + { + m_pBag->Release(); + m_pBag = NULL; + return S_OK; + } + else + return E_UNEXPECTED; + } + + HRESULT hr; + + hr = pUnk->QueryInterface(IID_IPropertyBag, (void**) &m_pBag); + + if(FAILED(hr)) + m_pBag = NULL; + + return hr; + +} + +HRESULT CPropertyBag::Initialize(int cUnks, IUnknown** ppUnks) +{ + HRESULT hr = S_FALSE; + + for (UINT i = 0; i < cUnks; i++) + { + hr = Initialize(ppUnks[i]); + + if(SUCCEEDED(hr)) + return hr; + } + + return hr; +} + +int CPropertyBag::GetInt(const string& sKeyName, int nDefault) const +{ + if(m_pBag == NULL) + return nDefault; + + CComVariant var; + + if(SUCCEEDED(m_pBag->Read(CComBSTR(sKeyName), &var, NULL))) + { + if(var.vt == VT_I4) + { + return var.lVal; + } + else + return nDefault; + } + else + { + return nDefault; + } +} + +string CPropertyBag::GetString(const string& sKeyName, const string& sDefault) const +{ + USES_CONVERSION; + + if(m_pBag == NULL) + return sDefault; + + CComVariant var; + string sRet; + + if(SUCCEEDED(m_pBag->Read(CComBSTR(sKeyName), &var, NULL))) + { + if(var.vt == VT_BSTR) + { + sRet = OLE2T(var.bstrVal); + return sRet; + } + else + return sDefault; + } + else { + return sDefault; + } + + +} + +HRESULT CPropertyBag::WriteInt(const string& sKeyName, int nValue) +{ + if(m_pBag == NULL) + return E_POINTER; + + CComVariant var; + + var.vt = VT_I4; + var.lVal = nValue; + + return m_pBag->Write(CComBSTR(sKeyName), &var); + +} + +HRESULT CPropertyBag::WriteString(const string& sKeyName, const string& sValue) +{ + if(m_pBag == NULL) + return E_POINTER; + + CComVariant var; + CComBSTR bsVal(sValue); + + var.vt = VT_BSTR; + var.bstrVal = bsVal; + + return m_pBag->Write(CComBSTR(sKeyName), &var); +} + + +HRESULT CPropertyBag::DeleteProperty(const string& sKeyName) +{ + if(m_pBag == NULL) + return E_POINTER; + + CComVariant var; + + var.Clear(); + + return m_pBag->Write(CComBSTR(sKeyName), &var); +} + +UINT CPropertyBag::GetStringSet(const string& sFormat, string_array& asData) const +{ + UINT nCnt = 0; + string sVal; + string sKeyName; + + // Format Key Name + sKeyName.format(sFormat, nCnt++); + + // Add URLs to List Box + while((sVal = GetString(sKeyName, NS_NO_KEY)) != NS_NO_KEY) + { + asData.push_back(sVal); + + // Format Key Name + sKeyName.format(sFormat, nCnt++); + } + + return --nCnt; +} + +UINT CPropertyBag::WriteStringSet(const string& sFormat, const string_array& asData) +{ + UINT nCnt = 0; // Number of URLs from Registry + string sKeyName; + + string_array::const_iterator iter = asData.begin(); + for(; iter != asData.end(); iter++) + { + sKeyName.format(sFormat, nCnt++); + WriteString(sKeyName, *iter); + } + + UINT nRet = nCnt - 1; + sKeyName.format(sFormat, nCnt++); + CComVariant var; + + while(SUCCEEDED(m_pBag->Read(CComBSTR(sKeyName), &var, NULL)) && + var.vt != VT_EMPTY && var.vt != VT_NULL) + { + // Format Registry Key + DeleteProperty(sKeyName); + sKeyName.format(sFormat, nCnt++); + var.Clear(); + } + + return nRet; + +} |