📄 poom.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 "Poom.hpp"
#include <auto_xxx.hxx>
const WCHAR* Poom_t::sc_SearchTemplates[] =
{
L"[BusinessTelephoneNumber] = \"%s\"",
L"[MobileTelephoneNumber] = \"%s\"",
L"[HomeTelephoneNumber] = \"%s\"",
};
const WCHAR Poom_t::sc_NameTemplate[] = L"%s, %s";
Poom_t::Poom_t(
void
)
{
;
}
Poom_t::Poom_t(
IPOutlookApp* cpOutlookApp
)
{
m_cpOutlookApp = cpOutlookApp;
}
Poom_t::~Poom_t(
void
)
{
;
}
HRESULT
Poom_t::Initialize(
void
)
{
if (m_cpOutlookApp)
{
return S_FALSE;
}
//co create the object...
HRESULT hr = m_cpOutlookApp.CoCreateInstance(CLSID_Application);
if (FAILED(hr))
{
return hr;
}
hr = m_cpOutlookApp->Logon(NULL);
if (FAILED(hr))
{
m_cpOutlookApp = NULL;
return hr;
}
return S_OK;
}
void
Poom_t::Uninitialize(
void
)
{
if (m_cpOutlookApp != NULL)
{
m_cpOutlookApp->Logoff();
m_cpOutlookApp = NULL;
}
}
HRESULT
Poom_t::GetContactInformation(
BSTR FriendlyNumber,
IContact** ppContactInfo
)
{
if (m_cpOutlookApp == NULL)
{
return E_UNEXPECTED;
}
if (FriendlyNumber == NULL || ppContactInfo == NULL)
{
return E_INVALIDARG;
}
*ppContactInfo = NULL;
CComPtr<IFolder> cpFolder;
HRESULT hr = m_cpOutlookApp->GetDefaultFolder(
olFolderContacts,
&cpFolder
);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
CComPtr<IPOutlookItemCollection> cpItems;
hr = cpFolder->get_Items(&cpItems);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
WCHAR SearchCreteria[MAX_PATH] = L"";
for (unsigned int Index = 0; Index < _countof(sc_SearchTemplates); Index ++)
{
hr = StringCchPrintf(
SearchCreteria,
_countof(SearchCreteria),
sc_SearchTemplates[Index],
FriendlyNumber
);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
hr = cpItems->Find(
SearchCreteria,
reinterpret_cast<IDispatch**>(ppContactInfo)
);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
if (*ppContactInfo != NULL)
{
break;
}
}
if (*ppContactInfo == NULL)
{
return S_FALSE;
}
return S_OK;
}
HRESULT
Poom_t::GetCallerName(
BSTR FriendlyNumber,
BSTR* pFriendlyName
)
{
if (m_cpOutlookApp == NULL)
{
return E_UNEXPECTED;
}
if (FriendlyNumber == NULL || pFriendlyName == NULL)
{
return E_INVALIDARG;
}
*pFriendlyName = NULL;
CComPtr<IContact> cpContact;
HRESULT hr = GetContactInformation(
FriendlyNumber,
&cpContact
);
if (FAILED(hr))
{
return hr;
}
if (cpContact == NULL)
{
return S_FALSE;
}
ce::auto_bstr FirstName;
cpContact->get_FirstName(&FirstName);
ce::auto_bstr LastName;
cpContact->get_LastName(&LastName);
WCHAR Name[MAX_PATH] = L"";
hr = StringCchPrintf(
Name,
_countof(Name),
sc_NameTemplate,
LastName,
FirstName
);
if (FAILED(hr))
{
return hr;
}
*pFriendlyName = SysAllocString(Name);
if (*pFriendlyName == NULL)
{
return E_OUTOFMEMORY;
}
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -