梁某人

发展才是硬道理

导航

读取地址本内容

// main.h

#include <windows.h>
#include <crtdbg.h>
#include <iostream.h>

#include <wab.h>

typedef HRESULT (WINAPI *fWABOpen)(LPADRBOOK*,LPWABOBJECT*,LPWAB_PARAM,DWORD);

int main()
{
 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)
 {
  procWABOpen = (fWABOpen) GetProcAddress(hinstLib, "WABOpen");

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

   //lpWABObject->Find(lpAdrBook,NULL);
   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;
   //IABTable *lpTable;
   
   if (ulObjType == MAPI_ABCONT)
   {
    IABContainer *lpContainer = static_cast <IABContainer *>(lpUnk);
    LPMAPITABLE lpTable = NULL;
    hRes = lpContainer->GetContentsTable(
     ulFlags,
     &lpTable
    );
    _ASSERT(lpTable);
    ULONG ulRows;
    hRes = lpTable->GetRowCount(0,&ulRows);
    _ASSERTE(hRes == S_OK);
    cout << "Rows " << ulRows << endl;
    SRowSet *lpRows;

    hRes = lpTable->QueryRows(
     ulRows,  // Get all Rows
     0,
     &lpRows
    );
    for(ULONG i=0;i<lpRows->cRows;i++)
    {
     SRow *lpRow = &lpRows->aRow[i];
     cout << i << " : " << lpRow->cValues << endl;
     for(ULONG j=0;j<lpRow->cValues;j++)
     {
      SPropValue *lpProp = &lpRow->lpProps[j];
      cout << "\t" << j << " : " << (void*)lpProp->ulPropTag << " : ";
      
      if (lpProp->ulPropTag == PR_DISPLAY_NAME_A)
       cout << "Display Name: " << lpProp->Value.lpszA;
      if (lpProp->ulPropTag == PR_EMAIL_ADDRESS_A)
       cout << "Email Address: " << lpProp->Value.lpszA;
      if (lpProp->ulPropTag == PR_NICKNAME_A)
       cout << "Nickname: " << lpProp->Value.lpszA;
      if (lpProp->ulPropTag == PR_ADDRTYPE_A)
       cout << "Addrtype: " << lpProp->Value.lpszA;
      cout << endl;
     }
     lpWABObject->FreeBuffer(lpRow);
    }
    lpWABObject->FreeBuffer(lpRows);
   }
  }
  FreeLibrary(hinstLib);
 }
 return 0;
}

posted on 2005-07-16 01:41  涛仔28  阅读(526)  评论(1编辑  收藏  举报