第一步:
// 导入读取Outlook2000中通讯薄内容所需库
#import "c:\Program Files\Microsoft Office\Office\mso9.dll" named_guids
#import "c:\Program Files\Microsoft Office\Office\MSOUTL9.olb" \
no_namespace exclude("_IRecipientControl", "_DRecipientControl")
第二步:
_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;
HRESULT hr;
try
{
hr=pApp.CreateInstance(__uuidof(Application));
if (FAILED(hr))
{
MessageBox("Outlook实例创建失败","错误",MB_OK);
return;
}
// 获取默认Outlook中联系人文件夹
pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->GetDefaultFolder(olFolderContacts);
if (pFolder==NULL)
{
MessageBox("没有发现默认的Outlook联系人文件夹","错误!");
return;
}/*
else // 否则自行选择Outlook中一指定文件夹
{
pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->PickFolder();
if (pFolder==NULL)
return;
if (pFolder->GetDefaultItemType()!=olContactItem) // 不是联系人
{
MessageBox("选择不是联系人文件夹","错误");
return;
}
}
*/
pItems=pFolder->GetItems();
if (pItems==NULL)
{
MessageBox("不能得到联系人条目","错误");
return;
}
pContact=pItems->GetFirst();
long n = pItems->GetCount();
BSTR bstrCity;
BSTR bstrJobTitle;
int nImportCount = 0;
while(1)
{
if (pContact==NULL)
break;
pContact->get_HomeAddressCity(&bstrCity);
::AfxMessageBox(CString(bstrCity));
pContact->get_JobTitle(&bstrJobTitle);
::AfxMessageBox(CString(bstrJobTitle));
pContact->GetFullName();
pContact->GetFirstName();
pContact->GetMobileTelephoneNumber();
pContact->GetDepartment();
pContact->GetCompanyName();
pContact->GetBusinessAddress();
pContact->GetHomeAddress();
pContact->GetHomeTelephoneNumber();
}
pContact=pItems->GetNext();
}
}
catch(_com_error &e)
{
MessageBox((char *)e.Description());
}
输入指针符号->就可以出来很多函数了,可以获取更多联系人信息,麻烦兄弟们自己看去吧,一看就能理解的.
阅读(1126) | 评论(0) | 转发(0) |