|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 200152 - Last Review: August 24, 2005 - Revision: 1.5 How To Use Address Type as a Restriction with MAPIThis article was previously published under Q200152
Sometimes your application may need to process only a particular type of mailbox (for example, only Custom Recipients or only Exchange Users). This can be done by looking at the PR_DISPLAY_TYPE in the restriction.
This article contains a code sample that demonstrates how to use the PR_DISPLAY_TYPE and the PR_DISPLAY_NAME to retrieve a restricted list of mailboxes.
- Place the following code in a Win32 application project.
- On the Link tab, select the Ignore All Default Libraries option.
- Use the following libraries to compile the code:
- Msvcrt.lib
- Version.lib
- Mapi32.lib
- Edkmapi.lib
- Edkutils.lib
- Addrlkup.lib
- Edkdebug.lib
#include <edk.h>
HRESULT GetGALContents (LPMAPISESSION);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pszCmd, int nCmdShow)
{
// Load strings, and register window classes.
LPMAPISESSION psess = NULL;
HRESULT hr = MAPIInitialize(NULL);
if (FAILED(hr))
{
MessageBox(0L,"Initialize Failed","Error",MB_OK);
return 1;
}
hr = MAPILogonEx(0L,
NULL,
NULL,
MAPI_NEW_SESSION | MAPI_LOGON_UI,
&psess);
if (FAILED(hr))
{
MessageBox(0L,"Logon Failed","Error",MB_OK);
MAPIUninitialize();
return 1;
}
hr = GetGALContents(psess);
if (FAILED(hr))
{
MessageBox(0L,"Restriction Failed","Error",MB_OK);
MAPIUninitialize();
return 1;
}
MAPIUninitialize();
return 0;
};
HRESULT GetGALContents (LPMAPISESSION psess)
{
ULONG cbeid = 0L;
LPENTRYID lpeid = NULL;
HRESULT hr = S_OK;
LPSRowSet pRow;
ULONG ulObjType;
SRestriction sres,
srlevel1[2];
LPMAPITABLE lpContentsTable = NULL;
LPABCONT lpGAL = NULL;
SPropValue spvDisplay, spvAddrType;
LPADRBOOK m_pAddrBook = NULL;
LPFlagList lpFlagList = NULL;
LPADRLIST pAdrList = NULL;
spvDisplay.ulPropTag = PR_DISPLAY_NAME;
spvDisplay.Value.lpszA = "Enter Display Name";
spvAddrType.ulPropTag = PR_DISPLAY_TYPE;
spvAddrType.Value.l = DT_MAILUSER;
SizedSPropTagArray ( 2, sptCols ) = { 2,
PR_ENTRYID,
PR_DISPLAY_NAME };
psess->OpenAddressBook(NULL,NULL,AB_NO_DIALOG,&m_pAddrBook);
if ( FAILED ( hr = HrFindExchangeGlobalAddressList ( m_pAddrBook,
&cbeid,
&lpeid ) ) )
goto Quit;
if(FAILED(hr = m_pAddrBook->OpenEntry((ULONG) cbeid,
(LPENTRYID) lpeid,
NULL,
MAPI_BEST_ACCESS,
&ulObjType,
(LPUNKNOWN *)&lpGAL)))
goto Quit;
if ( ulObjType != MAPI_ABCONT )
goto Quit;
if(FAILED(hr = lpGAL->GetContentsTable(0L, &lpContentsTable)))
goto Quit;
//Create Restriction
sres.rt = RES_AND;
sres.res.resAnd.cRes = 2;
sres.res.resAnd.lpRes =srlevel1;
srlevel1[0].rt = RES_CONTENT;
srlevel1[0].res.resContent.ulFuzzyLevel = FL_PREFIX|FL_IGNORECASE;
srlevel1[0].res.resContent.ulPropTag = PR_DISPLAY_NAME;
srlevel1[0].res.resContent.lpProp = &spvDisplay;
srlevel1[1].rt = RES_PROPERTY;
srlevel1[1].res.resProperty.relop = RELOP_EQ;
srlevel1[1].res.resProperty.ulPropTag = PR_DISPLAY_TYPE;
srlevel1[1].res.resProperty.lpProp = &spvAddrType;
if ( FAILED ( hr = HrQueryAllRows (lpContentsTable,(SPropTagArray*) &sptCols, &sres, NULL, 0,&pRow)))
goto Quit;
if (pRow->cRows > 0)
MessageBox(0L,"Names Returned","Information",MB_OK);<BR/>
Quit:
if ( NULL != lpGAL)
{
lpGAL -> Release ( );
lpGAL = NULL;
}
if ( lpContentsTable )
{
lpContentsTable -> Release ( );
lpContentsTable = NULL;
}
return hr;
}
APPLIES TO- Microsoft Office Outlook 2007
- Microsoft Messaging Application Programming Interface
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
 |
 |
 |
 |
 |
 |
 |
| |