📄 dataitemarray.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "DataItemArray.h"
#include "..\contacts\ContactsInformation.h"
#include "..\galsearch\GALSearchInformation.h"
#include "..\freebusy\FreeBusyInformation.h"
//Macro that creates an object, sets its datarecord and qi's for the
//correct interface -
//NOTE: Not a function because I want to use different type specifiers
#define CreateItem(hr, Type, pDataRecord, ppiUnk) \
{ \
CComObject<Type> *pClassObj = NULL; \
hr = CComObject<Type>::CreateInstance(&pClassObj); \
if (SUCCEEDED(hr)) \
{ \
hr = pClassObj->SetDataRecord(pDataRecord); \
} \
if (SUCCEEDED(hr)) \
{ \
hr = pClassObj->QueryInterface( \
IID_IUnknown, \
reinterpret_cast<void**>(ppiUnk) \
); \
} \
}
/*------------------------------------------------------------------------------
CExchangeClientDataItemArray::CExchangeClientDataItemArray
Constructor
------------------------------------------------------------------------------*/
CExchangeClientDataItemArray::CExchangeClientDataItemArray()
{
TRACE();
MemTrackAdd();
m_pDataRecordList = NULL;
m_Type = e_ecrtInvalid;
}
/*------------------------------------------------------------------------------
CExchangeClientDataItemArray::~CExchangeClientDataItemArray
Destructor
------------------------------------------------------------------------------*/
CExchangeClientDataItemArray::~CExchangeClientDataItemArray()
{
TRACE();
MemTrackRemove();
if (m_pDataRecordList)
{
m_pDataRecordList->Release();
m_pDataRecordList = NULL;
}
}
/*------------------------------------------------------------------------------
CExchangeClientDataItemArray::SetDataRecordList
Initialize the internal datarecord list pointer
------------------------------------------------------------------------------*/
HRESULT CExchangeClientDataItemArray::SetDataRecordList(RefCountedDataRecordList * pDataRecordList)
{
if (pDataRecordList == NULL)
{
return E_POINTER;
}
m_pDataRecordList = pDataRecordList;
m_pDataRecordList->AddRef();
return S_OK;
}
/*------------------------------------------------------------------------------
CExchangeClientDataItemArray::SetType
Initialize the internal type
Parameters:
type:
Returns (HRESULT):
------------------------------------------------------------------------------*/
HRESULT CExchangeClientDataItemArray::SetType(ExchangeClientRequestType type)
{
if (type == e_ecrtInvalid)
{
return E_INVALIDARG;
}
m_Type = type;
return S_OK;
}
/*------------------------------------------------------------------------------
CExchangeClientDataItemArray::GetItemCount
Get the size of the interal vector
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CExchangeClientDataItemArray::GetItemCount(
UINT *pcElts
)
{
if (pcElts == NULL)
{
return E_POINTER;
}
*pcElts = m_pDataRecordList->size();
return S_OK;
}
/*------------------------------------------------------------------------------
CExchangeClientDataItemArray::GetItemAt
Get the datarecord (wrapped in a CExchangeClientInfomationObject derivative) and return it
to the user
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE CExchangeClientDataItemArray::GetItemAt(
UINT idxItem,
IUnknown **ppiItem
)
{
//check params
if (ppiItem == NULL)
{
return E_POINTER;
}
//check params
if (idxItem >= m_pDataRecordList->size())
{
return E_INVALIDARG;
}
*ppiItem = NULL;
HRESULT hr = S_OK;
switch (m_Type)
{
case e_ecrtContacts:
CreateItem(hr, CExchangeClientContactInformation, (*m_pDataRecordList)[idxItem], ppiItem);
break;
case e_ecrtGALSearch:
CreateItem(hr, CExchangeClientGALSearchInformation, (*m_pDataRecordList)[idxItem], ppiItem);
break;
case e_ecrtFreeBusy:
CreateItem(hr, CExchangeClientFreeBusyInformation, (*m_pDataRecordList)[idxItem], ppiItem);
break;
default:
ASSERT(FALSE);
hr = E_UNEXPECTED;
break;
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -