2016-04-15 14 views
-3
<b>Here's a high level logic used, to retrieve Personal Contacts. -- Note for simplicity, we've removed error handling and Object releases.</b> 

<!-- getOutlookStyleContactList() -- Try fetching contact entries for Global or Personal conatcs --> 

- > // getOutlookStyleContactList INT getOutlookStyleContactList(BOOL fetchGlobal) { IMAPISession-> OpenAddressBook(0,NULL,AB_NO_DIALOG,& pAddressBook); pAddressBook-> GetSearchPath(NULL,& pRows);尝试使用MAPI检索Outlook联系人。但是,仅返回具有电子邮件地址的联系人。任何人都知道我做错了什么?

 // Loop through the rows and find the one for the GAL 
     // and the one for the PAB. 
     for (i = 0; i < pRows->cRows; i++) 
     { 
      SRow* folder_row = &pRows->aRow[i]; 
      LPSPropValue lpDN_cont = PpropFindProp(folder_row->lpProps,folder_row->cValues,PR_ENTRYID); 
      _PV* ContainerEntryId = NULL; 
      ContainerEntryId = &lpDN_cont->Value; 

      //Tries seraching for Global and Personal Conacts 
      BOOL bFound = false; 
      for (j = 0; j < pRows->aRow[i].cValues; j++) 
      { 
       if (pRows->aRow[i].lpProps[j].ulPropTag == PR_DISPLAY_TYPE) 
       { 
        if (pRows->aRow[i].lpProps[j].Value.ul == DT_GLOBAL) 
        { 
         if (fetchGlobal) 
         { 
          bFound = true; 
         } 
        } 
       } 

       if (pRows->aRow[i].lpProps[j].ulPropTag == PR_DISPLAY_NAME) 
       { 
        if (checkForGlobal(pRows->aRow[i].lpProps[j].Value.lpszA)) 
        { 
         if (fetchGlobal) 
         { 
          bFound = true; 
         } 
        } 
        else 
        { 
         if (!fetchGlobal) 
         { 
          bFound = true; 
         } 
        } 
       } 
      } 
      //A folder was found. Now read all ontact contents from folder 
      if (bFound) 
      { 
       readContainerContents(pAddressBook, ContainerEntryId->bin.cb, (LPENTRYID)ContainerEntryId->bin.lpb); 
      } 
     } 
    } 

- > // readContainerContents()。从提供的文件夹中读取联系人 int readContainerContents(LPADRBOOK pAddressBook,ULONG cbEntryID,LPENTRYID lpEntryID) ULONG ulFlags = 0; ULONG ulObjType = NULL; LPUNKNOWN lpUnk = NULL; HRESULT hRes; int retArrayObj = 0; ULONG j; ULONG i;

 hRes = pAddressBook->OpenEntry(cbEntryID, lpEntryID, NULL, ulFlags, &ulObjType, &lpUnk); 

     ulFlags = NULL; 
     IABContainer *lpContainer = static_cast <IABContainer *>(lpUnk); 

     if (ulObjType != MAPI_ABCONT) 
     { 
      RELEASE(lpUnk); 
      return -1; 
     } 

     LPMAPITABLE lpTable = NULL; 

     ULONG ulContentFlag = 0; 
     hRes = lpContainer->GetContentsTable(ulContentFlag, &lpTable); 

     uint32_t total_entries = 0; 
     uint32_t cur_entry = 0; 

     //Loop through retrieved contact entries 
     while (1) 
     { 
      SRowSet *lpRows = NULL; 
      hRes = lpTable->QueryRows(50, 0, &lpRows); 

      if ((hRes != S_OK) || (lpRows == NULL) || (lpRows->cRows == 0)) 
      { 
       break; 
      } 
      //Run through all contact entries 
      total_entries += lpRows->cRows; 
      for(i=0;i<lpRows->cRows;i++) 
      { 
       SRow *lpRow = &lpRows->aRow[i]; 
       LPSPropValue lpDN_cont = PpropFindProp(lpRow->lpProps, lpRow->cValues, PR_ENTRYID); 
       CMAPIContact contact; 
       contact.Open(pMAPIEx, lpDN_cont->Value.bin); 
       //ADD CONTACT TO LIST 
      } 
     } 
    } 
+0

http://stackoverflow.com/editing-help –

+0

无论如何都要插入代码。在这个问题出现之前,没有人能够解决这个问题。 – user4581301

+0

我已经尝试了一切插入C基础代码,我不断收到代码格式/缩进错误 – jlandje

回答

0

也就是说它是如何工作 - OAB只公开与电子邮件地址的通讯录。如果您想要所有联系人,则需要打开联系人文件夹,而不是使用通讯簿对象。

从收件箱文件夹(IMsgStore :: GetReceiveFolder(“IPM.Note的”)返回),打开文件夹阅读PR_IPM_CONTACT_ENTRYID,阅读其内容表,等等看看联系人文件夹及其与OutlookSpy项目(点击IMAPIFolder和IMessage)。

+0

德米特里,感谢您的答案。使用您建议的方法时,只会显示主要联系人条目。无法从联系人子文件夹读取联系人条目。谢谢 – jlandje

+0

为什么你不能?您可以在“联系人”文件夹或任何其他文件夹中获取相同的IMessage对象。你只需要检索联系人特定的属性。你看过OutlookSpy的联系人(点击IMessage)吗? –

相关问题