什么是
Pocket Outlook
对象模型
(POOM)
?
应用程序通过
Pocket Outlook
对象模型来访问
Pocket Outlook
数据,即通常所称的
POOM
。
.
该库基于
COM
,它提供了一个对象层次结构,从而简化了创建、修改和显示约会、任务和联系人的过程。
int allItemsCount = 0;
hr = pItems->get_Count(&allItemsCount);
IAppointment *pIAppointment = NULL;
IContact *Contact = NULL;
ITask *task = NULL;
for (int index= 1;index<= allItemsCount;index++)
{
if(FAILED(pItems->Item(1,reinterpret_cast<IDispatch **>(&Contact))))
{
return FALSE;
}
else
{
Contact->Delete();
}
}
if (NULL != pFolder)
{
pFolder->Release();
pFolder = NULL;
}
if (NULL != pItems)
{
pItems->Release();
pItems = NULL;
}
return TRUE;
}
return TRUE;
}
if (NULL != pFolder)
{
pFolder->Release();
pFolder = NULL;
}
if (NULL != pItems)
{
pItems->Release();
pItems = NULL;
}
return TRUE;
}
以上是对联系人的处理,任务,约会,处理方法类似,只是HRESULT hr =g_polApp->GetDefaultFolder(olFolderContacts, &pFolder);中的olFolderContacts应改为其他的,在头文件 pimstore.h中
首先对
POOM
进行初始化:
BOOL InitPoom(void)
{
// Initialize COM for Pocket Outlook.
if (FAILED(CoInitializeEx(NULL, 0))) //初始化com
{
return FALSE;
}
// Get the application object.
HRESULT hr = CoCreateInstance(CLSID_Application,
NULL,
CLSCTX_INPROC_SERVER,
IID_IPOutlookApp2,
(LPVOID*)&g_polApp);
if (FAILED(hr))
{
return FALSE;
}
// Log on to POOM.
hr = g_polApp->Logon(NULL);//登陆
if (FAILED(hr))
{
return FALSE;
}
return TRUE;
}
{
// Initialize COM for Pocket Outlook.
if (FAILED(CoInitializeEx(NULL, 0))) //初始化com
{
return FALSE;
}
// Get the application object.
HRESULT hr = CoCreateInstance(CLSID_Application,
NULL,
CLSCTX_INPROC_SERVER,
IID_IPOutlookApp2,
(LPVOID*)&g_polApp);
if (FAILED(hr))
{
return FALSE;
}
// Log on to POOM.
hr = g_polApp->Logon(NULL);//登陆
if (FAILED(hr))
{
return FALSE;
}
return TRUE;
}
获得电话中的联系人:
BOOL ReadPhoneContact()
{
IFolder * pFolder;
IPOutlookItemCollection * pItems; //*m_pSimOnly;
{
IFolder * pFolder;
IPOutlookItemCollection * pItems; //*m_pSimOnly;
//Get the default contact folder.
HRESULT hr =g_polApp->GetDefaultFolder(olFolderContacts, &pFolder);
if (FAILED(hr))
{
return FALSE;
}
//Get the contact items collection.
hr = pFolder->get_Items(&pItems);
if (FAILED(hr))
{
return FALSE;
}
HRESULT hr =g_polApp->GetDefaultFolder(olFolderContacts, &pFolder);
if (FAILED(hr))
{
return FALSE;
}
//Get the contact items collection.
hr = pFolder->get_Items(&pItems);
if (FAILED(hr))
{
return FALSE;
}
int phonContactCount;
pItems->get_Count(&phonContactCount);
for (int index= 1;index<= phonContactCount;index++)
{
IContact *pContact = NULL;
//BSTR bsMobileNum = NULL;
if(FAILED(pItems->Item(index,reinterpret_cast<IDispatch **>(&pContact))))
{
return FALSE;
}
else
{
pContact->get_MobileTelephoneNumber(&contactText.mobileNum);
pContact->get_FirstName(&contactText.firstName);
pContact->get_LastName(&contactText.lastName);
//pContact->put_Birthday(DATE st);
}
}
pItems->get_Count(&phonContactCount);
for (int index= 1;index<= phonContactCount;index++)
{
IContact *pContact = NULL;
//BSTR bsMobileNum = NULL;
if(FAILED(pItems->Item(index,reinterpret_cast<IDispatch **>(&pContact))))
{
return FALSE;
}
else
{
pContact->get_MobileTelephoneNumber(&contactText.mobileNum);
pContact->get_FirstName(&contactText.firstName);
pContact->get_LastName(&contactText.lastName);
//pContact->put_Birthday(DATE st);
}
}
如何写入联系人信息:
BOOL PutPhoneContact( CONTACTDATE contact)
{
if (g_polApp == NULL)
{
return FALSE;
}
g_polApp->AddRef();
{
if (g_polApp == NULL)
{
return FALSE;
}
g_polApp->AddRef();
IContact * pNewContact = NULL;
if (SUCCEEDED(g_polApp->CreateItem(olContactItem, reinterpret_cast<IDispatch **>(&pNewContact))))
{
// set the new contact properties
pNewContact->put_FirstName(contact.firstName);
pNewContact->put_LastName(contact.lastName);
pNewContact->put_HomeTelephoneNumber(contact.mobileNum);
if (SUCCEEDED(g_polApp->CreateItem(olContactItem, reinterpret_cast<IDispatch **>(&pNewContact))))
{
// set the new contact properties
pNewContact->put_FirstName(contact.firstName);
pNewContact->put_LastName(contact.lastName);
pNewContact->put_HomeTelephoneNumber(contact.mobileNum);
// save and clean up
pNewContact->Save();
pNewContact->Release();
SysFreeString(contact.firstName);
SysFreeString(contact.lastName);
SysFreeString(contact.mobileNum);
}
pNewContact->Save();
pNewContact->Release();
SysFreeString(contact.firstName);
SysFreeString(contact.lastName);
SysFreeString(contact.mobileNum);
}
如何删除联系人信息:
BOOL DeleteContact()
{
IFolder * pFolder = NULL;
IPOutlookItemCollection * pItems = NULL;
HRESULT hr =g_polApp->GetDefaultFolder(olFolderContacts, &pFolder);
if (FAILED(hr))
{
return FALSE;
}
//Get the contact items collection.
hr = pFolder->get_Items(&pItems);
if (FAILED(hr))
{
return FALSE;
}
{
IFolder * pFolder = NULL;
IPOutlookItemCollection * pItems = NULL;
HRESULT hr =g_polApp->GetDefaultFolder(olFolderContacts, &pFolder);
if (FAILED(hr))
{
return FALSE;
}
//Get the contact items collection.
hr = pFolder->get_Items(&pItems);
if (FAILED(hr))
{
return FALSE;
}
int allItemsCount = 0;
hr = pItems->get_Count(&allItemsCount);
IAppointment *pIAppointment = NULL;
IContact *Contact = NULL;
ITask *task = NULL;
for (int index= 1;index<= allItemsCount;index++)
{
if(FAILED(pItems->Item(1,reinterpret_cast<IDispatch **>(&Contact))))
{
return FALSE;
}
else
{
Contact->Delete();
}
}
if (NULL != pFolder)
{
pFolder->Release();
pFolder = NULL;
}
if (NULL != pItems)
{
pItems->Release();
pItems = NULL;
}
return TRUE;
}
return TRUE;
}
if (NULL != pFolder)
{
pFolder->Release();
pFolder = NULL;
}
if (NULL != pItems)
{
pItems->Release();
pItems = NULL;
}
return TRUE;
}
enum
OlDefaultFolders
{ olFolderCalendar = 9,//日程 olFolderContacts = 10,//联系人 olFolderTasks = 13,//任务
olFolderCities = 101,//
城市 时区
olFolderInfrared = 102,//红外线
} OlDefaultFolders;
后两个没有用过