Article ID: 171637
Article Last Modified on 8/18/2005
HRESULT GetDetails ( LPSTR lpszFriendlyName )
{
HRESULT hRes = S_OK;
ULONG ulUIParam = 0;
LPADRLIST lpAdrList = NULL;
ULONG cbEID = 0L;
LPBYTE lpEID = NULL;
hRes = ResolveName ( lpszFriendlyName, &lpAdrList );
if ( SUCCEEDED ( hRes ) )
{
// Step through the rows of properties in lpAdrList. When we
// find the PR_ENTRYID, stop and call the IAddrBook::Details
// method to show the information stored in the address book
// about the requested recipient.
for ( ULONG i = 0; i < lpAdrList -> aEntries -> cValues; i++ )
{
if ( PR_ENTRYID ==
lpAdrList -> aEntries -> rgPropVals[i].ulPropTag )
{
// These next two assignments are unnecessary but make
// the code more readable below.
cbEID=lpAdrList->aEntries->rgPropVals[i].Value.bin.cb;
lpEID=lpAdrList->aEntries->rgPropVals[i].Value.bin.lpb;
hRes = m_pAddrBook -> Details ( &ulUIParam,
NULL, NULL,
cbEID,
(LPENTRYID) lpEID,
NULL, NULL, NULL,
DIALOG_MODAL );
break;
}
}
}
MAPIFreeBuffer ( lpAdrList );
return hRes;
}
HRESULT ResolveName ( LPSTR lpszName, LPADRLIST *lpAdrList )
{
// NOTE: Callers of this function MUST release lpAdrList when done
// with it using MAPIFreeBuffer.
HRESULT hRes = S_OK;
LPADRLIST pAdrList = NULL;
// Allocate memory for new SRowSet structure.
hRes = MAPIAllocateBuffer(CbNewSRowSet(1),(LPVOID*) &pAdrList);
// If memory allocation fails, quit.
if ( FAILED ( hRes ) )
return hRes;
// Zero out allocated memory.
ZeroMemory ( pAdrList, CbNewSRowSet(1));
// Allocate memory for SPropValue structure that indicates what
// recipient properties will be set. NUM_RECIP_PROPS == 5.
hRes = MAPIAllocateBuffer( 1 * sizeof(SPropValue),
(LPVOID*) &(pAdrList->aEntries[0].rgPropVals));
// If memory allocation fails, quit.
if ( FAILED ( hRes ) )
hRes;
// Zero out allocated memory.
ZeroMemory ( pAdrList -> aEntries[0].rgPropVals,
sizeof(SPropValue) );
// How many recipients.
pAdrList->cEntries = 1;
// How many properties per recipient.
pAdrList->aEntries[0].cValues = 1;
// Set the SPropValue members == the desired values.
pAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
pAdrList->aEntries[0].rgPropVals[0].Value.lpszA = lpszName;
// ResolveName is kind enough to redimension the ADRLIST that we
// pass to it and give us back a fully qualified ADRLIST structure
// that contains all the recipient information the address book
// decided to give us back.
if ( SUCCEEDED (
hRes = m_pAddrBook -> ResolveName ( (ULONG) m_hWnd,
0L, NULL, pAdrList ) ) )
*lpAdrList = pAdrList;
return hRes;
}
Important Note: The documentation for the IAddrBook::Details method fails
to mention the DIALOG_MODAL flag. This flag is not optional for this call
at the present time and must be included in order to display the details
page.
Keywords: kbhowto kbmsg KB171637