本文整理汇总了C++中LPADRBOOK::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ LPADRBOOK::Release方法的具体用法?C++ LPADRBOOK::Release怎么用?C++ LPADRBOOK::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPADRBOOK
的用法示例。
在下文中一共展示了LPADRBOOK::Release方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddRecipientW
HRESULT AddRecipientW(LPMESSAGE lpMessage,
ULONG ulRecipientType,
LPWSTR szRecipientName){
HRESULT hRes = S_OK;
LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST
LPADRBOOK lpAddrBook = NULL;
hRes = HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList);
if (SUCCEEDED(hRes) && lpAdrList)
{
// Set up the recipient by indicating how many recipients
// and how many properties will be set on each recipient.
lpAdrList->cEntries = 1; // How many recipients.
lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient
lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].ulPropTag = PR_DISPLAY_NAME_W;
lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].ulPropTag = PR_RECIPIENT_TYPE;
lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].Value.lpszW = szRecipientName;
lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].Value.l = ulRecipientType;
// If everything goes right, add the new recipient to the message
// object passed into us.
hRes = lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList);
}
if (lpAdrList) FreePadrlist(lpAdrList);
if (lpAddrBook) lpAddrBook->Release();
return hRes;
}
示例2: FreeWAB
void FreeWAB(HINSTANCE hWAB,
LPADRBOOK pAdrBook,
LPWABOBJECT pWABObject,
AdrBookTable *pTable,
UINT nNumEntries)
{
if (pTable && nNumEntries)
{
for (UINT i=0; i<nNumEntries; i++)
{
if (pTable[i].szName)
free(pTable[i].szName);
if (pTable[i].szEmail)
free(pTable[i].szEmail);
}
free(pTable);
}
if(pAdrBook)
pAdrBook->Release();
if(pWABObject)
pWABObject->Release();
if(hWAB)
FreeLibrary(hWAB);
return;
}
示例3: AddRecipient
_Check_return_ HRESULT AddRecipient(
_In_ LPMAPISESSION lpMAPISession,
_In_ LPMESSAGE lpMessage,
_In_z_ LPCTSTR szName,
ULONG ulRecipientType)
{
HRESULT hRes = S_OK;
LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST
LPADRBOOK lpAddrBook = NULL;
enum
{
NAME,
RECIP,
NUM_RECIP_PROPS
};
if (!lpMessage || !lpMAPISession) return MAPI_E_INVALID_PARAMETER;
EC_MAPI(lpMAPISession->OpenAddressBook(
NULL,
NULL,
NULL,
&lpAddrBook));
EC_MAPI(HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList));
if (lpAdrList)
{
// Setup the One Time recipient by indicating how many recipients
// and how many properties will be set on each recipient.
lpAdrList->cEntries = 1; // How many recipients.
lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient
// Set the SPropValue members == the desired values.
lpAdrList->aEntries[0].rgPropVals[NAME].ulPropTag = PR_DISPLAY_NAME;
lpAdrList->aEntries[0].rgPropVals[NAME].Value.LPSZ = (LPTSTR)szName;
lpAdrList->aEntries[0].rgPropVals[RECIP].ulPropTag = PR_RECIPIENT_TYPE;
lpAdrList->aEntries[0].rgPropVals[RECIP].Value.l = ulRecipientType;
EC_MAPI(lpAddrBook->ResolveName(
0L,
fMapiUnicode,
NULL,
lpAdrList));
// If everything goes right, add the new recipient to the message
// object passed into us.
EC_MAPI(lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList));
EC_MAPI(lpMessage->SaveChanges(KEEP_OPEN_READWRITE));
}
if (lpAdrList) FreePadrlist(lpAdrList);
if (lpAddrBook) lpAddrBook->Release();
return hRes;
} // AddRecipient
示例4: AddRecipientA
HRESULT AddRecipientA(LPMAPISESSION lpMAPISession,
LPMESSAGE lpMessage,
ULONG ulRecipientType,
LPSTR szRecipientName)
{
HRESULT hRes = S_OK;
LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST
LPADRBOOK lpAddrBook = NULL;
if (!lpMessage || !lpMAPISession) return MAPI_E_INVALID_PARAMETER;
hRes = lpMAPISession->OpenAddressBook(
NULL,
NULL,
NULL,
&lpAddrBook);
if (SUCCEEDED(hRes) && lpAddrBook)
{
hRes = HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList);
if (SUCCEEDED(hRes) && lpAdrList)
{
// Set up the recipient by indicating how many recipients
// and how many properties will be set on each recipient.
lpAdrList->cEntries = 1; // How many recipients.
lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient
lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].ulPropTag = PR_DISPLAY_NAME_A;
lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].ulPropTag = PR_RECIPIENT_TYPE;
lpAdrList->aEntries[0].rgPropVals[p_PR_DISPLAY_NAME_W].Value.lpszA = szRecipientName;
lpAdrList->aEntries[0].rgPropVals[p_PR_RECIPIENT_TYPE].Value.l = ulRecipientType;
hRes = lpAddrBook->ResolveName(
0L,
MAPI_UNICODE,
NULL,
lpAdrList);
if (SUCCEEDED(hRes))
{
// If everything goes right, add the new recipient to the message
// object passed into us.
hRes = lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList);
}
}
}
if (lpAdrList) FreePadrlist(lpAdrList);
if (lpAddrBook) lpAddrBook->Release();
return hRes;
}
示例5: SessionLogOn
bool COLAddrBook::SessionLogOn(ULONG hWnd, LPCTSTR profile, LPCTSTR pswd, ULONG flags)
{
bool bResult = false;
LPMAPISESSION pSession = NULL;
HRESULT hr = g_pMAPIEDK->pMAPILogonEx(hWnd, (LPTSTR)profile, (LPTSTR)pswd, flags, &pSession);
if (pSession)
{
LPADRBOOK pAddrBook = NULL;
if (SUCCEEDED(pSession->OpenAddressBook(NULL, NULL, AB_NO_DIALOG, &pAddrBook)))
{
m_initRef->SetAddrBook(pAddrBook);
// открываем корневой каталог
ULONG ulObjType = 0;
LPUNKNOWN pUnk = NULL;
if (SUCCEEDED(pAddrBook->OpenEntry(0, NULL, NULL, MAPI_BEST_ACCESS, &ulObjType, &pUnk)))
{
if (MAPI_ABCONT == ulObjType)
{
LPABCONT pContainer = NULL;
m_pABCont = (LPABCONT)pUnk;
m_pABCont->AddRef();
bResult = true;
}
}
if (pUnk)
pUnk->Release();
}
if (pAddrBook)
pAddrBook->Release();
}
if (pSession)
pSession->Release();
return bResult;
}
示例6: ImportWAB
//.........这里部分代码省略.........
_ASSERTE(hRes == S_OK);
if (hRes != S_OK) return;
ULONG ulFlags = MAPI_BEST_ACCESS;
ULONG ulObjType = NULL;
LPUNKNOWN lpUnk = NULL;
hRes = lpAdrBook->OpenEntry(
lpcbEntryID,
lpEntryID,
NULL,
ulFlags,
&ulObjType,
&lpUnk
);
ulFlags = NULL;
//IABTable *lpTable;
if (ulObjType == MAPI_ABCONT)
{
IABContainer *lpContainer = static_cast <IABContainer *>(lpUnk);
LPMAPITABLE lpTable = NULL;
hRes = lpContainer->GetContentsTable(
ulFlags,
&lpTable
);
_ASSERT(lpTable);
ULONG ulRows, ulFound = 0, ulExisted = 0;
hRes = lpTable->GetRowCount(0,&ulRows);
_ASSERTE(hRes == S_OK);
SRowSet *lpRows;
hRes = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0 );
hRes = lpTable->QueryRows(
ulRows, // Get all Rows
0,
&lpRows
);
for(ULONG i=0;i<lpRows->cRows;i++)
{
bool bBirthdayProcessed = false;
CBirthday* pbd = new CBirthday;
SRow *lpRow = &lpRows->aRow[i];
for(ULONG j=0;j<lpRow->cValues;j++)
{
SPropValue *lpProp = &lpRow->lpProps[j];
if(lpProp->ulPropTag == PR_BIRTHDAY)
{
SYSTEMTIME st;
FileTimeToSystemTime(&lpProp->Value.ft,&st);
pbd->m_date = CDate((BYTE)st.wDay, (BYTE)st.wMonth, (UINT)st.wYear);
bBirthdayProcessed = true;
}
if(lpProp->ulPropTag == PR_DISPLAY_NAME_A)
{
pbd->m_name = lpProp->Value.lpszA;
}
}
if( bBirthdayProcessed && pbd->m_date.ValidDate() )
{
ulFound++;
if( !WABExists(pbd) )
{
pbd->m_medium = MEDIUM_WAB;
Add( pbd );
}
else
{
delete pbd;
ulExisted++;
}
}
else
delete pbd;
lpWABObject->FreeBuffer(lpRow);
}
CString c;
c.Format( "Processed %d contacts\r\n\r\nFound %d birthdays of which\r\n%d already existed",
ulRows, ulFound, ulExisted );
AfxMessageBox( c, MB_OK|MB_SYSTEMMODAL, 0 );
lpWABObject->FreeBuffer(lpRows);
}
if(lpAdrBook)
lpAdrBook->Release();
if(lpWABObject)
lpWABObject->Release();
}
// This would be nice but leads to crashing Trillian
// FreeLibrary(hinstLib);
}
}
示例7: SetAddressListSearchOrder
//.........这里部分代码省略.........
abNUM_COLS, // Num fields to get (2)
PR_ENTRYID, // Get ENTRYID struct
PR_DISPLAY_NAME_A // Get display name
};
// Open address book
hr = Session.OpenAddressBook(NULL, NULL, NULL, &lpAddrBook);
if (FAILED(hr)) {
cerr << "Error getting MAPI Address book." << endl;
goto Exit;
}
TraceSearchPath(*lpAddrBook);
ULONG ulObjType;
LPMAPICONTAINER pIABRoot = NULL;
hr = lpAddrBook->OpenEntry(0, NULL, NULL, 0, &ulObjType, (LPUNKNOWN *)&pIABRoot);
if (FAILED(hr) || ulObjType != MAPI_ABCONT) {
cerr << "Error opening MAPI Address book root entry." << endl;
if (SUCCEEDED(hr)) hr = E_UNEXPECTED;
goto Cleanup;
}
// Setup MAPI memory allocation link
MAPIAllocateBuffer(0, &tempLink);
// Query MAPI for all address lists
LPMAPITABLE pHTable = NULL;
hr = pIABRoot->GetHierarchyTable(CONVENIENT_DEPTH, &pHTable);
if (FAILED(hr)) {
cerr << "Error obtaining MAPI address list hierarchy." << endl;
goto Cleanup;
}
LPSRowSet pQueryRows = NULL;
hr = HrQueryAllRows(pHTable, (LPSPropTagArray)&abCols, NULL, NULL, 0, &pQueryRows);
if (FAILED(hr)) {
cerr << "Error getting MAPI address lists." << endl;
goto Cleanup;
}
// Cross reference pQueryRows with SearchList for matches
for (list<string>::const_iterator SearchListIter = SearchList.begin(); SearchListIter != SearchList.end(); SearchListIter++) {
const string &SearchName = *SearchListIter;
// Is SearchName in the pQueryRows list?
for (ULONG i = 0; i < pQueryRows->cRows && pQueryRows->aRow[i].lpProps[abPR_DISPLAY_NAME_A].ulPropTag == PR_DISPLAY_NAME_A; i++) {
SRow &QueryRow = pQueryRows->aRow[i];
string ContainerName = QueryRow.lpProps[abPR_DISPLAY_NAME_A].Value.lpszA;
if (ContainerName == SearchName) {
// Found a match!
cout << "Adding address list search path: " << SearchName << endl;
// Build SRow/SPropValue structs
// Assumptions: SRow contains 1 SPropValue of type SBinary
SPropValue TmpSPropValue = { QueryRow.lpProps[0].ulPropTag, QueryRow.lpProps[0].dwAlignPad };
NewSPropList.push_back(TmpSPropValue);
SPropValue &NewSPropValue = NewSPropList.back();
SRow TmpSRow = { QueryRow.ulAdrEntryPad, 1, &NewSPropValue };
NewSRowList.push_back(TmpSRow);
SRow &NewSRow = NewSRowList.back();
// Safely copy binary portion of SPropValue
hr = CopySBinary(
NewSRow.lpProps[0].Value.bin,
QueryRow.lpProps[0].Value.bin,
tempLink);
if (FAILED(hr)) {
cerr << "Error while building MAPI data." << endl;
goto Cleanup;
}
// break out of inner pQueryRows loop and continue to next in SearchList
break;
}
} // for (i in pQueryRows)
} // for (SearchList)
// Convert NewSRowList to SRowSet
NewSRowSet = AllocSRowSet(NewSRowList, tempLink);
if (NewSRowSet == NULL) goto Cleanup;
hr = lpAddrBook->SetSearchPath(0, NewSRowSet);
if (FAILED(hr)) {
cerr << "Error while saving address list search path" << endl;
goto Cleanup;
}
TraceSearchPath(*lpAddrBook);
Cleanup:
if (NewSRowSet) delete[] NewSRowSet;
MAPIFreeBuffer(tempLink);
if (lpAddrBook) lpAddrBook->Release();
Exit:
if (FAILED(hr)) cerr << "HRESULT = 0x" << hex << hr << endl;
return hr;
}
示例8: TSTRING
//.........这里部分代码省略.........
&lpAdrList)))
{
// Even though we succeeded, do a check to make sure we have
// an address list
if (lpAdrList)
{
lpAdrList->cEntries = 1; // only looking for 1 entry
lpAdrList->aEntries[0].cValues = NUM_PROPS; // Number of props
// Set the SPropValue to whom we're looking for
lpAdrList->aEntries[0].rgPropVals[prDISPLAY_NAME].ulPropTag =
PR_DISPLAY_NAME;
lpAdrList->aEntries[0].rgPropVals[prDISPLAY_NAME].Value.LPSZ =
(LPTSTR)szName.c_str();
// Let's try to resolve the name now
if (SUCCEEDED(hr = lpAdrBook->ResolveName(
0L,
MAPI_UNICODE,
NULL,
lpAdrList)))
{
m_log << output::both << level::Informational <<
"Resolve name yielded " <<
lpAdrList->aEntries[0].cValues <<
" properties." << endl;
for (UINT i = 0; i < lpAdrList->aEntries[0].cValues; i++)
{
// Store the property so I don't have to type so much...
SPropValue spvCurrent = lpAdrList->aEntries[0].rgPropVals[i];
m_log << output::both << level::Informational <<
"Found Property '0x" <<
setfill(_T('0')) << setw(8) << setbase(16) <<
spvCurrent.ulPropTag << "'";
switch (spvCurrent.ulPropTag)
{
case PR_ADDRTYPE:
if (szEX.compare(spvCurrent.Value.LPSZ) == 0)
isExchange = true;
break;
case PR_DISPLAY_NAME:
m_log << ": " << spvCurrent.Value.LPSZ;
break;
case PR_EMAIL_ADDRESS:
m_log << ": " << spvCurrent.Value.LPSZ;
szEmailAddress = TSTRING(spvCurrent.Value.LPSZ);
break;
default:
if (((spvCurrent.ulPropTag & 0x1f) == 0x1f) ||
((spvCurrent.ulPropTag & 0x1e) == 0x1e))
m_log << ": " << spvCurrent.Value.LPSZ;
break;
}
m_log << endl;
}
if (!isExchange || (szEmailAddress.empty()))
{
hr = MAPI_E_NOT_FOUND;
goto CLEANUP;
}
}
else
{
FATAL(_T("lpAdrBook->ResolveName()"), hr);
goto CLEANUP;
}
}
}
else
{
FATAL(_T("AllocAdrList()"), hr);
goto CLEANUP;
}
}
else
{
FATAL(_T("OpenAddressBook()"), hr);
}
CLEANUP:
if (lpAdrList)
{
FreePadrlist(lpAdrList);
lpAdrList = NULL;
}
if (lpAdrBook)
{
lpAdrBook->Release();
lpAdrBook = NULL;
}
EXIT:
return hr;
}
示例9: AddOneOffAddress
_Check_return_ HRESULT AddOneOffAddress(
_In_ LPMAPISESSION lpMAPISession,
_In_ LPMESSAGE lpMessage,
_In_z_ LPCTSTR szDisplayName,
_In_z_ LPCTSTR szAddrType,
_In_z_ LPCTSTR szEmailAddress,
ULONG ulRecipientType)
{
HRESULT hRes = S_OK;
LPADRLIST lpAdrList = NULL; // ModifyRecips takes LPADRLIST
LPADRBOOK lpAddrBook = NULL;
LPENTRYID lpEID = NULL;
enum
{
NAME,
ADDR,
EMAIL,
RECIP,
EID,
NUM_RECIP_PROPS
};
if (!lpMessage || !lpMAPISession) return MAPI_E_INVALID_PARAMETER;
EC_MAPI(lpMAPISession->OpenAddressBook(
NULL,
NULL,
NULL,
&lpAddrBook));
EC_MAPI(HrAllocAdrList(NUM_RECIP_PROPS, &lpAdrList));
// Setup the One Time recipient by indicating how many recipients
// and how many properties will be set on each recipient.
if (SUCCEEDED(hRes) && lpAdrList)
{
lpAdrList->cEntries = 1; // How many recipients.
lpAdrList->aEntries[0].cValues = NUM_RECIP_PROPS; // How many properties per recipient
// Set the SPropValue members == the desired values.
lpAdrList->aEntries[0].rgPropVals[NAME].ulPropTag = PR_DISPLAY_NAME;
lpAdrList->aEntries[0].rgPropVals[NAME].Value.LPSZ = (LPTSTR)szDisplayName;
lpAdrList->aEntries[0].rgPropVals[ADDR].ulPropTag = PR_ADDRTYPE;
lpAdrList->aEntries[0].rgPropVals[ADDR].Value.LPSZ = (LPTSTR)szAddrType;
lpAdrList->aEntries[0].rgPropVals[EMAIL].ulPropTag = PR_EMAIL_ADDRESS;
lpAdrList->aEntries[0].rgPropVals[EMAIL].Value.LPSZ = (LPTSTR)szEmailAddress;
lpAdrList->aEntries[0].rgPropVals[RECIP].ulPropTag = PR_RECIPIENT_TYPE;
lpAdrList->aEntries[0].rgPropVals[RECIP].Value.l = ulRecipientType;
lpAdrList->aEntries[0].rgPropVals[EID].ulPropTag = PR_ENTRYID;
// Create the One-off address and get an EID for it.
EC_MAPI(lpAddrBook->CreateOneOff(
lpAdrList->aEntries[0].rgPropVals[NAME].Value.LPSZ,
lpAdrList->aEntries[0].rgPropVals[ADDR].Value.LPSZ,
lpAdrList->aEntries[0].rgPropVals[EMAIL].Value.LPSZ,
fMapiUnicode,
&lpAdrList->aEntries[0].rgPropVals[EID].Value.bin.cb,
&lpEID));
lpAdrList->aEntries[0].rgPropVals[EID].Value.bin.lpb = (LPBYTE)lpEID;
EC_MAPI(lpAddrBook->ResolveName(
0L,
fMapiUnicode,
NULL,
lpAdrList));
// If everything goes right, add the new recipient to the message
// object passed into us.
EC_MAPI(lpMessage->ModifyRecipients(MODRECIP_ADD, lpAdrList));
EC_MAPI(lpMessage->SaveChanges(KEEP_OPEN_READWRITE));
}
MAPIFreeBuffer(lpEID);
if (lpAdrList) FreePadrlist(lpAdrList);
if (lpAddrBook) lpAddrBook->Release();
return hRes;
} // AddOneOffAddress
示例10: SizedSPropTagArray
// Manually resolve a name in the address book and add it to the message
_Check_return_ HRESULT ManualResolve(
_In_ LPMAPISESSION lpMAPISession,
_In_ LPMESSAGE lpMessage,
_In_z_ LPCTSTR szName,
ULONG PropTagToCompare)
{
HRESULT hRes = S_OK;
ULONG ulObjType = 0;
LPADRBOOK lpAdrBook = NULL;
LPSRowSet lpABRow = NULL;
LPMAPITABLE lpABContainerTable = NULL;
LPADRLIST lpAdrList = NULL;
LPABCONT lpABContainer = NULL;
LPMAPITABLE pTable = NULL;
LPSPropValue lpFoundRow = NULL;
enum
{
abcPR_ENTRYID,
abcPR_DISPLAY_NAME,
abcNUM_COLS
};
static const SizedSPropTagArray(abcNUM_COLS, abcCols) =
{
abcNUM_COLS,
PR_ENTRYID,
PR_DISPLAY_NAME,
};
enum
{
abPR_ENTRYID,
abPR_DISPLAY_NAME,
abPR_RECIPIENT_TYPE,
abPR_ADDRTYPE,
abPR_DISPLAY_TYPE,
abPropTagToCompare,
abNUM_COLS
};
if (!lpMAPISession) return MAPI_E_INVALID_PARAMETER;
DebugPrint(DBGGeneric, _T("ManualResolve: Asked to resolve \"%s\"\n"), szName);
EC_MAPI(lpMAPISession->OpenAddressBook(
NULL,
NULL,
NULL,
&lpAdrBook));
EC_H(GetABContainerTable(lpAdrBook, &lpABContainerTable));
if (lpABContainerTable)
{
// Restrict the table to the properties that we are interested in.
EC_MAPI(lpABContainerTable->SetColumns((LPSPropTagArray)&abcCols, TBL_BATCH));
if (!FAILED(hRes)) for (;;)
{
hRes = S_OK;
FreeProws(lpABRow);
lpABRow = NULL;
EC_MAPI(lpABContainerTable->QueryRows(
1,
NULL,
&lpABRow));
if (FAILED(hRes) || !lpABRow || (lpABRow && !lpABRow->cRows)) break;
// From this point forward, consider any error an error with the current address book container, so just continue and try the next one.
if (PR_ENTRYID == lpABRow->aRow->lpProps[abcPR_ENTRYID].ulPropTag)
{
DebugPrint(DBGGeneric, _T("ManualResolve: Searching this container\n"));
DebugPrintBinary(DBGGeneric, &lpABRow->aRow->lpProps[abcPR_ENTRYID].Value.bin);
if (lpABContainer) lpABContainer->Release();
lpABContainer = NULL;
EC_H(CallOpenEntry(
NULL,
lpAdrBook,
NULL,
NULL,
lpABRow->aRow->lpProps[abcPR_ENTRYID].Value.bin.cb,
(ENTRYID*)lpABRow->aRow->lpProps[abcPR_ENTRYID].Value.bin.lpb,
NULL,
NULL,
&ulObjType,
(LPUNKNOWN*)&lpABContainer));
if (!lpABContainer) continue;
DebugPrint(DBGGeneric, _T("ManualResolve: Object opened as 0x%X\n"), ulObjType);
if (lpABContainer && ulObjType == MAPI_ABCONT)
{
if (pTable) pTable->Release();
pTable = NULL;
WC_MAPI(lpABContainer->GetContentsTable(fMapiUnicode, &pTable));
if (!pTable)
//.........这里部分代码省略.........
示例11: ResolveAddressList
// Resolve address list name to ENTRYID
// Memory is allocated through MAPIAllocateBuffer using pAllocLink
STDMETHODIMP ResolveAddressList(IMAPISession &Session, const string &AddressList, LPVOID pAllocLink, ULONG *cbEntry, LPENTRYID *Entry) {
HRESULT hr = S_OK;
// Setup struct specifying MAPI fields to query
enum {
abPR_ENTRYID, // Field index for ENTRYID
abPR_DISPLAY_NAME_A, // Field index for display name
abNUM_COLS // Automatically set to number of fields
};
static SizedSPropTagArray(abNUM_COLS, abCols) = {
abNUM_COLS, // Num fields to get (2)
PR_ENTRYID, // Get ENTRYID struct
PR_DISPLAY_NAME_A // Get display name
};
// Open address book
LPADRBOOK lpAddrBook;
hr = Session.OpenAddressBook(NULL, NULL, NULL, &lpAddrBook);
if (FAILED(hr)) {
cerr << "Error getting MAPI Address book." << endl;
goto Exit;
}
ULONG ulObjType;
LPMAPICONTAINER pIABRoot = NULL;
hr = lpAddrBook->OpenEntry(0, NULL, NULL, 0, &ulObjType, (LPUNKNOWN *)&pIABRoot);
if (FAILED(hr) || ulObjType != MAPI_ABCONT) {
cerr << "Error opening MAPI Address book root entry." << endl;
if (SUCCEEDED(hr)) hr = E_UNEXPECTED;
goto Cleanup;
}
// Query MAPI for all address lists
LPMAPITABLE pHTable = NULL;
hr = pIABRoot->GetHierarchyTable(CONVENIENT_DEPTH, &pHTable);
if (FAILED(hr)) {
cerr << "Error obtaining MAPI address list hierarchy." << endl;
goto Cleanup;
}
LPSRowSet pQueryRows = NULL;
hr = HrQueryAllRows(pHTable, (LPSPropTagArray)&abCols, NULL, NULL, 0, &pQueryRows);
if (FAILED(hr)) {
cerr << "Error getting MAPI address lists." << endl;
goto Cleanup;
}
// Is AddressList in the pQueryRows list?
for (ULONG i = 0; i < pQueryRows->cRows && pQueryRows->aRow[i].lpProps[abPR_DISPLAY_NAME_A].ulPropTag == PR_DISPLAY_NAME_A; i++) {
SRow &QueryRow = pQueryRows->aRow[i];
string ContainerName = QueryRow.lpProps[abPR_DISPLAY_NAME_A].Value.lpszA;
if (ContainerName == AddressList) {
// Found a match!
// Build ENTRYID struct
ULONG cbNewEntryID = QueryRow.lpProps[abPR_ENTRYID].Value.bin.cb;
LPENTRYID lpNewEntryID;
MAPIAllocateMore(cbNewEntryID, pAllocLink, (LPVOID *)&lpNewEntryID);
memcpy(lpNewEntryID, QueryRow.lpProps[abPR_ENTRYID].Value.bin.lpb, cbNewEntryID);
// Set return values
*cbEntry = cbNewEntryID;
*Entry = lpNewEntryID;
// Break out
break;
}
}
Cleanup:
if (lpAddrBook) lpAddrBook->Release();
Exit:
return hr;
}