<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
}
}
}
http://stackoverflow.com/editing-help –
無論如何都要插入代碼。在這個問題出現之前,沒有人能夠解決這個問題。 – user4581301
我已經嘗試了一切插入C基礎代碼,我不斷收到代碼格式/縮進錯誤 – jlandje