使用VC6编写程序导出Outlook联系人信息

一、导入MSOUTL.OLB
#import "C://Program Files//Microsoft Office//OFFICE11//MSOUTL.OLB" /
no_namespace exclude("_IRecipientControl", "_DRecipientControl")  
 
二、include头文件
#include "msoutl.h" 
 
三、在Button1的OnClicked事件中添加下面的代码
// OutLook Automatic
void COutlookExport_1Dlg::OnButton1()
{
   // TODO: Add your control notification handler code here
   _Application olApp;
   COleException e;
   if(!olApp.CreateDispatch("Outlook.Application", &e)) {
      CString str;
      str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc);
      AfxMessageBox(str, MB_SETFOREGROUND);
      return;
   }
   // Logon. Doesn't hurt if you are already running and logged on...
   _NameSpace olNs(olApp.GetNamespace("MAPI"));
   COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
   olNs.Logon(covOptional, covOptional, covOptional, covOptional);
  
 
  
   // Get Contact Folder
   MAPIFolder outbox = olNs.GetDefaultFolder(10);
 
   // Get All Contact Items
   _Items outboxItems = outbox.GetItems();   
   if (outboxItems == NULL) {
      MessageBox("不能得到联系人条目","错误");
      return;
   }

   // Get First Item
   _ContactItem contact = outboxItems.GetFirst(); 
   m_mailList.ResetContent();
 
   while(1)
   {
     if (contact==NULL)
       break;
     CString strD2CS;
     COleDateTime bdDate;
     CString strTemp;

     // Get Full Name
     strTemp=contact.GetFullName(); 
   
     // Get Birthday
     strTemp=strTemp + "<";      
     bdDate = contact.GetBirthday();
     strD2CS.Format("%i", bdDate.GetYear());
     strTemp=strTemp + strD2CS + "-";
     strD2CS.Format("%i", bdDate.GetMonth());
     strTemp=strTemp + strD2CS + "-";
     strD2CS.Format("%i", bdDate.GetDay());
     strTemp=strTemp + strD2CS;
     strTemp=strTemp + ">";
 
     // Get Company Name
     strTemp=strTemp + "<";      
     strTemp=strTemp + contact.GetCompanyName();
     strTemp=strTemp + ">";
 
     // Get Home Telephone Number
     strTemp=strTemp + "<";
     strTemp=strTemp + contact.GetHomeTelephoneNumber();
     strTemp=strTemp + ">";
 
     // Add Contact Information to First Line
     //m_mailList.AddString(strTemp);
     m_mailList.InsertString(m_mailList.GetCount(), strTemp);
 
     // Clear the whole strTemp
     strTemp.Empty();
 
     // Get Email 1 Address
     strTemp=strTemp + "<";
     strTemp=strTemp + contact.GetEmail1Address();
     strTemp=strTemp + ">";
 
     // Get Job Title
     strTemp=strTemp + "<";
     strTemp=strTemp + contact.GetJobTitle();
     strTemp=strTemp + ">";
     m_mailList.InsertString(m_mailList.GetCount(), strTemp);
     strTemp.Empty();
 
     // Get Home Address
     strTemp=strTemp + "<";
     strTemp=strTemp + contact.GetHomeAddress();
     strTemp=strTemp + ">";
     m_mailList.InsertString(m_mailList.GetCount(), strTemp);
  
     contact = outboxItems.GetNext();
   }
  
}
 
四、在.cpp文件中添加一个Ole-initialization class,并生成一个实例
// Ole-initialization class.
class OleInitClass {
  public:
    OleInitClass() {
      OleInitialize(NULL);
    }
    ~OleInitClass() {
         OleUninitialize();
    }
};
// This global class calls OleInitialize() at
// application startup, and calls OleUninitialize()
// at application exit...
 OleInitClass g_OleInitClass;
转自:http://blog.chinaunix.net/u/11315/showart_405134.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值