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

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




->
        // getOutlookStyleContactList
        int getOutlookStyleContactList(BOOL fetchGlobal)
        {
            IMAPISession-> OpenAddressBook(0,NULL,AB_NO_DIALOG,&pAddressBook);
            pAddressBook-> GetSearchPath(NULL,&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); 
            }
        }
    }




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

最佳答案

这就是它的工作方式-OAB仅向联系人公开电子邮件地址。如果需要所有联系人,则需要打开“联系人”文件夹而不是使用“通讯簿”对象。

从Inbox文件夹中读取PR_IPM_CONTACT_ENTRYID(由IMsgStore :: GetReceiveFolder(“ IPM.Note”)返回),打开该文件夹,读取其内容表,等等。使用OutlookSpy来查看Contacts文件夹及其项目(单击IMAPIFolder和IMessage)。

关于c++ - 尝试使用MAPI检索Outlook联系人。但是,仅返回具有电子邮件地址的联系人。有人知道我在做什么错吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36658436/

相关文章:

c++ - 如何使用 gtest 测试具有多个模板参数的 C++ 模板类?

c - Rockbox 音频格式

c# - 使用 C# 按日期列出 Outlook 中的约会

outlook - 如何使用 EWS 从 Outlook 联系人读取扩展属性

c++ - 如何使用 boost::fs 只加载 30 个最新文件而不是整个目录?

c++ - 作为模板参数的成员函数和 c++17 等价物

c++ - gcc 4.8 中静态 constexpr 成员数组的初始化

c - 赋值运算符的实现

c - 在 unix 架构中,与 c 相关的 POSIX 的用途是什么

vba - 如何获取当前登录用户的电子邮件地址?