📄 datasource.cpp
字号:
}
CLEANUP:
//Only NULL the handle if the RefCount is 0
if(ulRefCount == 0)
*phAccessor = NULL;
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::SetCommandText
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::SetCommandText(WCHAR* pwszText)
{
HRESULT hr = S_OK;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
COptionsDlg* pCOptionsDlg = GetOptionsObj();
HWND hWnd = m_pCMDIChild->m_hWnd;
//Set CommandText
if(m_pICommandText)
{
TESTC(pCListBox->OutputPreMethod("ICommandText::SetCommandText(%S, \"%S\")", pCOptionsDlg->m_wszDialect, pwszText));
XTEST(hWnd, hr = m_pICommandText->SetCommandText(pCOptionsDlg->m_guidDialect, pwszText));
TESTC(pCListBox->OutputPostMethod(hr, "ICommandText::SetCommandText(%S, \"%S\")", pCOptionsDlg->m_wszDialect, pwszText));
}
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// CTransaction::CTransaction
//
/////////////////////////////////////////////////////////////////
CTransaction::CTransaction(CMDIChild* pCMDIChild) : CBase(pCMDIChild)
{
//OLEDB Interfaces
m_pITransaction = NULL; //Transaction interface
m_pIConnectionPointContainer= NULL; //Transaction interface
m_pISupportErrorInfo = NULL; //Transaction interface
//Extra interfaces
m_pITransactionOptions = NULL; //TransactionOptions interface
}
/////////////////////////////////////////////////////////////////
// CTransaction::~CTransaction
//
/////////////////////////////////////////////////////////////////
CTransaction::~CTransaction()
{
ReleaseObject();
}
/////////////////////////////////////////////////////////////////
// HRESULT CTransaction::SetInterface
//
/////////////////////////////////////////////////////////////////
HRESULT CTransaction::SetInterface(REFIID riid, IUnknown* pIUnknown)
{
HRESULT hr = S_OK;
//no-op
if(pIUnknown == NULL)
return E_INVALIDARG;
//If the requested interface is a DataSource interface, place it in the
//Appropiate member variable, otherwise we have to release it, since we
//have no place to store it...
if(riid == IID_IUnknown)
m_pIUnknown = pIUnknown;
else if(riid == IID_ITransaction)
m_pITransaction = (ITransaction*)pIUnknown;
else if(riid == IID_IConnectionPointContainer)
m_pIConnectionPointContainer = (IConnectionPointContainer*)pIUnknown;
else if(riid == IID_ISupportErrorInfo)
m_pISupportErrorInfo = (ISupportErrorInfo*)pIUnknown;
else
hr = E_NOINTERFACE;
return hr;
}
/////////////////////////////////////////////////////////////////
// BOOL CTransaction::ReleaseObject
//
/////////////////////////////////////////////////////////////////
HRESULT CTransaction::ReleaseObject()
{
//DataSource interfaces
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
pCListBox->OutputRelease((IUnknown**)&m_pITransaction, "ITransaction");
pCListBox->OutputRelease((IUnknown**)&m_pIConnectionPointContainer, "IConnectionPointContainer");
pCListBox->OutputRelease((IUnknown**)&m_pISupportErrorInfo, "ISupportErrorInfo");
//Extra interfaces
pCListBox->OutputRelease((IUnknown**)&m_pITransactionOptions, "ITransactionOptions");
//Base
ReleaseBase("Transaction");
return S_OK;
}
/////////////////////////////////////////////////////////////////
// HRESULT CTransaction::CreateObject
//
/////////////////////////////////////////////////////////////////
HRESULT CTransaction::CreateObject(IUnknown* pIUnknown)
{
HRESULT hr = E_FAIL;
HRESULT hrOptional = E_FAIL;
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
COptionsDlg* pCOptionsDlg = GetOptionsObj();
//Some don't return a rowset
if(pIUnknown==NULL)
goto CLEANUP;
//Release any previous object
ReleaseObject();
//Now use the new object
//[MANDATORY]
XTESTC(hWnd, hr = pCListBox->OutputQI(pIUnknown, IID_IUnknown, (IUnknown**)&m_pIUnknown));
XTESTC(hWnd, hr = pCListBox->OutputQI(pIUnknown, IID_ITransaction, (IUnknown**)&m_pITransaction));
hrOptional = pCListBox->OutputQI(pIUnknown, IID_IConnectionPointContainer, (IUnknown**)&m_pIConnectionPointContainer);
//Auto QI
if(pCOptionsDlg->m_dwRowsetOpts & ROWSET_AUTOQI)
{
//Obtain [optional] interfaces
hrOptional = pCListBox->OutputQI(pIUnknown, IID_ISupportErrorInfo, (IUnknown**)&m_pISupportErrorInfo);
}
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// CError::CError
//
/////////////////////////////////////////////////////////////////
CError::CError(CMDIChild* pCMDIChild) : CBase(pCMDIChild)
{
//OLEDB Interfaces
m_pIErrorInfo = NULL; //Error interface
m_pIErrorRecords = NULL; //Error interface
m_pISQLErrorInfo = NULL; //Error interface
}
/////////////////////////////////////////////////////////////////
// CError::~CError
//
/////////////////////////////////////////////////////////////////
CError::~CError()
{
ReleaseError();
}
/////////////////////////////////////////////////////////////////
// HRESULT CError::SetInterface
//
/////////////////////////////////////////////////////////////////
HRESULT CError::SetInterface(REFIID riid, IUnknown* pIUnknown)
{
HRESULT hr = S_OK;
//no-op
if(pIUnknown == NULL)
return E_INVALIDARG;
//If the requested interface is a Command interface, place it in the
//Appropiate member variable, otherwise we have to release it, since we
//have no place to store it...
if(riid == IID_IUnknown)
m_pIUnknown = (IUnknown*)pIUnknown;
else if(riid == IID_IErrorInfo)
m_pIErrorInfo = (IErrorInfo*)pIUnknown;
else if(riid == IID_IErrorRecords)
m_pIErrorRecords = (IErrorRecords*)pIUnknown;
else if(riid == IID_ISQLErrorInfo)
m_pISQLErrorInfo = (ISQLErrorInfo*)pIUnknown;
else
hr = E_NOINTERFACE;
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CError::ReleaseError
//
/////////////////////////////////////////////////////////////////
HRESULT CError::ReleaseError()
{
//Error
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
pCListBox->OutputRelease((IUnknown**)&m_pIErrorInfo, "IErrorInfo");
pCListBox->OutputRelease((IUnknown**)&m_pIErrorRecords, "IErrorRecords");
pCListBox->OutputRelease((IUnknown**)&m_pISQLErrorInfo, "ISQLErrorInfo");
ReleaseBase("Error");
return S_OK;
}
/////////////////////////////////////////////////////////////////
// HRESULT CError::GetErrorInfo
//
/////////////////////////////////////////////////////////////////
HRESULT CError::GetErrorInfo()
{
HRESULT hr = S_OK;
HRESULT hrOptional = S_OK;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
HWND hWnd = pCListBox->m_hWnd;
//Release all current interfaces
ReleaseError();
//GetErrorInfo
TESTC(pCListBox->OutputPreMethod("GetErrorInfo(0, &0x%08x)", m_pIUnknown));
XTEST(hWnd, hr = ::GetErrorInfo(0, (IErrorInfo**)&m_pIUnknown));
TESTC(pCListBox->OutputPostMethod(hr, "GetErrorInfo(0, &0x%08x)", m_pIUnknown));
//AutoQI
if(m_pIUnknown && GetOptionsObj()->m_dwRowsetOpts & ROWSET_AUTOQI)
{
//[MANDATORY]
XTESTC(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_IErrorInfo, (IUnknown**)&m_pIErrorInfo));
XTESTC(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_IErrorRecords, (IUnknown**)&m_pIErrorRecords));
//[OPTIONAL]
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ISQLErrorInfo, (IUnknown**)&m_pISQLErrorInfo);
}
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CError::SetErrorInfo
//
/////////////////////////////////////////////////////////////////
HRESULT CError::SetErrorInfo()
{
HRESULT hr = S_OK;
HRESULT hrOptional = S_OK;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
HWND hWnd = pCListBox->m_hWnd;
//SetErrorInfo
TESTC(pCListBox->OutputPreMethod("SetErrorInfo(0, NULL)"));
XTEST(hWnd, hr = ::SetErrorInfo(0, NULL));
TESTC(pCListBox->OutputPostMethod(hr, "SetErrorInfo(0, NULL)"));
CLEANUP:
return hr;
}
// {CB21F4D6-878D-11d1-9528-00C04FB66A50}
static const GUID IID_IAggregate =
{ 0xcb21f4d6, 0x878d, 0x11d1, { 0x95, 0x28, 0x0, 0xc0, 0x4f, 0xb6, 0x6a, 0x50 } };
///////////////////////////////////////////////////////////////////////////////
// class CAggregate
//
///////////////////////////////////////////////////////////////////////////////
CAggregate::CAggregate()
{
m_cRef = 1;
m_pIUnkInner = NULL;
}
CAggregate::~CAggregate()
{
//COM Aggregation rule #6
//To free an inner pointer (other than IUnknown), the outer object calls its
//own outer unknown's AddRef followed by Release on the inner object's pointer
//Currently we don't have this case, since we only have IUnknown
//AddRef()
//SAFE_RELEASE(m_pNonIUnknownInner);
//Inner object free
SAFE_RELEASE(m_pIUnkInner);
}
ULONG CAggregate::GetRefCount()
{
return m_cRef;
}
ULONG CAggregate::AddRef(void)
{
return ++m_cRef;
}
ULONG CAggregate::Release(void)
{
ASSERT(m_cRef);
if(--m_cRef)
return m_cRef;
//COM Aggregation rule #5
//The outer object must protect its implementation of Release from
//reentrantcy with an artifical reference count arround its destruction code
m_cRef++;
//Delete this object
delete this;
return 0;
}
HRESULT CAggregate::QueryInterface(REFIID riid, LPVOID *ppv)
{
HRESULT hr = S_OK;
//TEST_ NULL
if(ppv == NULL)
return E_INVALIDARG;
//Null output params
*ppv = NULL;
//Support IID_IUnknown
if(riid == IID_IUnknown)
{
*ppv = (IUnknown*)this;
SAFE_ADDREF((IUnknown*)*ppv);
}
else if(riid == IID_IAggregate)
{
*ppv = (IUnknown*)this;
SAFE_ADDREF((IUnknown*)*ppv);
}
else if(m_pIUnkInner)
{
//Delegate the the Inner Object
//This is not "circular" since this interface is the IID_IUnknown
//interface only, which has its own non-delegating QI...
hr = m_pIUnkInner->QueryInterface(riid, ppv);
}
else
{
return E_NOINTERFACE;
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -