尝试使用MAPI检索Outlook联系人。但是,仅返回具有电子邮件地址的联系人。谁知道我做错了什么?

时间:2016-04-15 23:35:35

标签: c++ c outlook mapi

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

- &GT;         // getOutlookStyleContactList         int getOutlookStyleContactList(BOOL fetchGlobal)         {             IMAPISession-&gt; OpenAddressBook(0,NULL,AB_NO_DIALOG,&amp; pAddressBook);             pAddressBook-&gt; GetSearchPath(NULL,&amp; pRows);

        // 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); 
            }
        }
    }

- &GT;         // 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
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

这就是它的工作原理 - OAB只使用电子邮件地址公开联系人。如果您想要所有联系人,则需要打开“联系人”文件夹,而不是使用“地址簿”对象。

从收件箱文件夹中读取PR_IPM_CONTACT_ENTRYID(由IMsgStore :: GetReceiveFolder(&#34; IPM.Note&#34;)返回),打开文件夹,阅读其内容表等。查看“联系人”文件夹和其项目为OutlookSpy(单击IMAPIFolder和IMessage)。