使用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

你可能感兴趣的:(null,application,Class,email,include,button)