Chinaunix首页 | 论坛 | 博客
  • 博客访问: 570552
  • 博文数量: 97
  • 博客积分: 5090
  • 博客等级: 大校
  • 技术积分: 969
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-01 14:56
文章分类

全部博文(97)

文章存档

2011年(1)

2009年(1)

2008年(14)

2007年(37)

2006年(44)

我的朋友

分类: C/C++

2006-09-22 11:08:11

  一、包含头文件及一个指针函数声明

// Outlook Express中通讯薄部分
#include                 // 通讯薄头文件
// 内部涵数声明
typedef HRESULT (WINAPI *fWABOpen)(LPADRBOOK*,LPWABOBJECT*,LPWAB_PARAM,DWORD);

 

二、下面的代码写在一个函数里面就可以了

// TODO: Add your control notification handler code here
 HRESULT hRes;
 LPADRBOOK lpAdrBook;
 LPWABOBJECT lpWABObject;
 LPWAB_PARAM lpWABParam = NULL;
 DWORD Reserved2 = NULL;

 HINSTANCE hinstLib;
 hinstLib = LoadLibrary("c:\\Program Files\\Common Files\\System\\wab32");
 fWABOpen procWABOpen;

 if (hinstLib != NULL)
 {
  // 获取"Wab32.dll"内部涵数WABOpen的进程地址
  procWABOpen = (fWABOpen) GetProcAddress(hinstLib, "WABOpen");

  if (procWABOpen != NULL)
  {
   hRes = (procWABOpen)(&lpAdrBook,&lpWABObject,NULL,Reserved2);
   _ASSERTE(hRes == S_OK);
   if (hRes != S_OK) exit(1);

   ULONG lpcbEntryID;
   ENTRYID *lpEntryID;
   hRes = lpAdrBook->GetPAB(
    &lpcbEntryID,
    &lpEntryID
   );
   _ASSERTE(hRes == S_OK);
   if (hRes != S_OK) exit(2);

   ULONG ulFlags = MAPI_BEST_ACCESS;
   ULONG ulObjType = NULL;
   LPUNKNOWN lpUnk = NULL;
   hRes = lpAdrBook->OpenEntry(
    lpcbEntryID,
    lpEntryID,
    NULL,
    ulFlags,
    &ulObjType,
    &lpUnk
   );

   ulFlags = NULL;
   
   if (ulObjType == MAPI_ABCONT)
   {
    IABContainer *lpContainer = static_cast (lpUnk);
    LPMAPITABLE lpTable = NULL;
    hRes = lpContainer->GetContentsTable(
     ulFlags,
     &lpTable
    );
    _ASSERT(lpTable);
    ULONG ulRows;
    hRes = lpTable->GetRowCount(0,&ulRows);
    _ASSERTE(hRes == S_OK);
    SRowSet *lpRows;

    hRes = lpTable->QueryRows(
     ulRows,  // 获取所有行
     0,
     &lpRows
    );
//    m_ListEmail.ResetContent();
    for(ULONG i=0;icRows;i++)
    {
     SRow *lpRow = &lpRows->aRow[i];
     CString strTemp;
     
     for(ULONG j=0;jcValues;j++)
     {
      SPropValue *lpProp = &lpRow->lpProps[j];
      
      if (lpProp->ulPropTag == PR_DISPLAY_NAME_A)
       strTemp = strTemp + " 名字: " + (char *)lpProp->Value.lpszA;
      if (lpProp->ulPropTag == PR_EMAIL_ADDRESS_A)
       strTemp = strTemp + " Email: " + (char *)lpProp->Value.lpszA;
      if (lpProp->ulPropTag == PR_NICKNAME_A)
       strTemp = strTemp + " 呢称: " + (char *)lpProp->Value.lpszA;
      if (lpProp->ulPropTag == PR_ADDRTYPE_A)
       strTemp = strTemp + " 类型: " + (char *)lpProp->Value.lpszA;
      if (lpProp->ulPropTag == PR_CALLBACK_TELEPHONE_NUMBER_A)
       strTemp = strTemp + "电话:" + (char *)lpProp->Value.lpszA;
     
     }
//     m_ListEmail.AddString(strTemp);
     ::AfxMessageBox(strTemp);
     lpWABObject->FreeBuffer(lpRow);
    }
    lpWABObject->FreeBuffer(lpRows);
   }
  }
  //FreeLibrary(hinstLib);
 }

阅读(3721) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~