Article ID: 166106
Article Last Modified on 8/18/2005
HRESULT GetGALContents ( LPSRowSet * ppRow )
{
ULONG cbeid = 0L;
LPENTRYID lpeid = NULL;
HRESULT hRes = S_OK;
LPSRowSet pRow;
ULONG ulObjType;
ULONG cRows = 0L;
LPMAPITABLE lpContentsTable = NULL;
LPMAPICONTAINER lpGAL = NULL;
SizedSPropTagArray ( 2, sptCols ) = { 2,
PR_ENTRYID,
PR_DISPLAY_NAME };
if ( FAILED ( hRes = HrFindExchangeGlobalAddressList ( m_pAddrBook,
&cbeid,
&lpeid ) ) )
goto Quit;
if(FAILED(hRes = m_pAddrBook->OpenEntry((ULONG) cbeid,
(LPENTRYID) lpeid,
NULL,
MAPI_BEST_ACCESS,
&ulObjType,
(LPUNKNOWN *)&lpGAL)))
goto Quit;
if ( ulObjType != MAPI_ABCONT )
goto Quit;
if(FAILED(hRes = lpGAL->GetContentsTable(0L, &lpContentsTable)))
goto Quit;
if(FAILED(hRes = lpContentsTable->SetColumns((LPSPropTagArray)&sptCols,
TBL_BATCH)))
goto Quit;
if ( FAILED ( hRes = lpContentsTable -> GetRowCount ( 0, &cRows ) ) )
goto Quit;
if ( FAILED ( hRes = lpContentsTable -> QueryRows ( cRows, 0L, &pRow )
goto Quit;
else
*ppRow = pRow;
Quit:
if ( NULL != lpGAL)
{
lpGAL -> Release ( );
lpGAL = NULL;
}
if ( lpContentsTable )
{
lpContentsTable -> Release ( );
lpContentsTable = NULL;
}
return hRes;
}
// End code
NOTE: In order to compile and run this code, you must have the Win32 SDK
and the Platform SDK. The latest versions of these SDK's are January 1997
and March 1997, respectively. The following libraries must be included for
linking: Mapi32.lib, Edkmapi.lib, Edkutils.lib, and Addrlkup.lib. If you
are building in debug mode, Edkdebug.lib is also necessary. Also, the debug
or release MultiThreaded DLL option must be selected in the code generation
options of the C/C++ tab in the build settings dialog box in order to link
properly.
Keywords: kbhowto kbapi kbmsg KB166106