123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /////////////////////////////////////////////////////////////////////////////
- // AGCDBParams.cpp : Implementation of the CAGCDBParams class.
- //
- #include "pch.h"
- #include "AGCDBParams.h"
- /////////////////////////////////////////////////////////////////////////////
- // CAGCDBParams
- TC_OBJECT_EXTERN_IMPL(CAGCDBParams)
- /////////////////////////////////////////////////////////////////////////////
- // IAGCDBParams Interface Methods
- STDMETHODIMP CAGCDBParams::put_ConnectionString(BSTR bstr)
- {
- XLock lock(this);
- m_bstrConnectionString = bstr;
- m_bDirty = true;
- return S_OK;
- }
- STDMETHODIMP CAGCDBParams::get_ConnectionString(BSTR* pbstr)
- {
- CLEAROUT(pbstr, (BSTR)NULL);
- XLock lock(this);
- *pbstr = m_bstrConnectionString.Copy();
- return S_OK;
- }
- STDMETHODIMP CAGCDBParams::put_TableName(BSTR bstr)
- {
- XLock lock(this);
- m_bstrTableName = bstr;
- m_bDirty = true;
- return S_OK;
- }
- STDMETHODIMP CAGCDBParams::get_TableName(BSTR* pbstr)
- {
- CLEAROUT(pbstr, (BSTR)NULL);
- XLock lock(this);
- *pbstr = m_bstrTableName.Copy();
- return S_OK;
- }
- /////////////////////////////////////////////////////////////////////////////
- // IPersist Interface Methods
- STDMETHODIMP CAGCDBParams::GetClassID(CLSID* pClassID)
- {
- __try
- {
- *pClassID = GetObjectCLSID();
- }
- __except(1)
- {
- return E_POINTER;
- }
- return S_OK;
- }
- /////////////////////////////////////////////////////////////////////////////
- // IPersistStreamInit Interface Methods
- STDMETHODIMP CAGCDBParams::IsDirty()
- {
- // Return dirty flag
- XLock lock(this);
- return m_bDirty ? S_OK : S_FALSE;
- }
- STDMETHODIMP CAGCDBParams::Load(LPSTREAM pStm)
- {
- XLock lock(this);
- // Read each string from the stream
- m_bstrConnectionString.Empty();
- m_bstrTableName.Empty();
- RETURN_FAILED(m_bstrConnectionString.ReadFromStream(pStm));
- RETURN_FAILED(m_bstrTableName.ReadFromStream(pStm));
- // Set the dirty flag
- m_bDirty = true;
- // Indicate success
- return S_OK;
- }
- STDMETHODIMP CAGCDBParams::Save(LPSTREAM pStm, BOOL fClearDirty)
- {
- XLock lock(this);
- // Write each string to the stream
- RETURN_FAILED(m_bstrConnectionString.WriteToStream(pStm));
- RETURN_FAILED(m_bstrTableName.WriteToStream(pStm));
- // Clear the dirty flag, if specified
- if (fClearDirty)
- m_bDirty = false;
- // Indicate success
- return S_OK;
- }
- STDMETHODIMP CAGCDBParams::GetSizeMax(ULARGE_INTEGER* pCbSize)
- {
- XLock lock(this);
- return TCGetPersistStreamSize(GetUnknown(), pCbSize);
- }
- STDMETHODIMP CAGCDBParams::InitNew( void)
- {
- XLock lock(this);
- // Initialize the strings
- m_bstrConnectionString.Empty();
- m_bstrTableName.Empty();
- // Indicate success
- return S_OK;
- }
- /////////////////////////////////////////////////////////////////////////////
- // IPersistPropertyBag Interface Methods
- STDMETHODIMP CAGCDBParams::Load(IPropertyBag* pPropBag, IErrorLog* pErrorLog)
- {
- // Load each string
- VARIANT varConnectionString, varTableName;
- RETURN_FAILED(pPropBag->Read(L"ConnectionString", &varConnectionString, pErrorLog));
- RETURN_FAILED(pPropBag->Read(L"TableName" , &varTableName , pErrorLog));
- // Attach the variants to the strings
- // Note: Do NOT call VariantClear since ownership is given to the strings
- XLock lock(this);
- m_bstrConnectionString.Empty();
- m_bstrConnectionString.Attach(V_BSTR(&varConnectionString));
- m_bstrTableName.Empty();
- m_bstrTableName.Attach(V_BSTR(&varTableName));
- // Set the dirty flag
- m_bDirty = true;
- // Indicate success
- return S_OK;
- }
- STDMETHODIMP CAGCDBParams::Save(IPropertyBag* pPropBag, BOOL fClearDirty, BOOL)
- {
- XLock lock(this);
- // Save each string
- RETURN_FAILED(pPropBag->Write(L"ConnectionString", &CComVariant(m_bstrConnectionString)));
- RETURN_FAILED(pPropBag->Write(L"TableName" , &CComVariant(m_bstrTableName )));
- // Clear the dirty flag, if specified
- if (fClearDirty)
- m_bDirty = false;
- // Indicate success
- return S_OK;
- }
|