2016-04-15 32 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)嗎? –

相關問題