WAB
- From
- Alexander Cherednichenko ()
- To
- Ilya Fromsky
- Date
- 2002-02-22T06:06:44Z
- Area
- SU.WINDOWS.NT.PROG
From: "Alexander Cherednichenko" <alcher@att.net>
Thu Feb 21 2002 10:47, Ilya Fromsky wrote to All:
IF> Кто-нибудь юзал сабж?
IF> Как, имея указатель на IAddrBook, получить список всех адресов (из wab
IF> файла)?
IF> fromsky@nm.ru
читается из WAB и заносится в лист контрол - см. ниже. не помню какие из
мемберов нужны в этом методе, на всякий случай то же даны. взято все из
работающего примера, так что пробуй
LPADRBOOK lpAdrBook;
LPSPropValue m_lpPropArray;
ULONG m_ulcValues;
// Cache entry id of currently selected item in the listview
SBinary m_SB;
HRESULT CWAB::LoadWABContents( HWND hList, BOOL bAll )
{
ULONG ulObjType = 0;
LPMAPITABLE lpAB = NULL;
LPTSTR * lppszArray=NULL;
ULONG cRows = 0;
LPSRowSet lpRow = NULL;
LPSRowSet lpRowAB = NULL;
LPABCONT lpContainer = NULL;
int cNumRows = 0;
int nRows = 0;
HRESULT hr = E_FAIL;
ULONG lpcbEID;
LPENTRYID lpEID = NULL;
// Get the entryid of the root PAB container
//
hr = m_lpAdrBook->GetPAB (&lpcbEID, &lpEID);
ulObjType = 0;
// Open the root PAB container
// This is where all the WAB contents reside
//
hr = m_lpAdrBook->OpenEntry (lpcbEID,
(LPENTRYID)lpEID,
NULL,
0,
&ulObjType,
(LPUNKNOWN *)&lpContainer);
m_lpWABObject->FreeBuffer (lpEID);
lpEID = NULL;
if( HR_FAILED (hr) ) goto exit;
// getting th ename of the address book
{
ULONG ulc;
LPSPropValue lpProps;
static const SizedSPropTagArray( 1, ptaProp ) =
{ 1, { PR_DISPLAY_NAME } };
lpContainer->GetProps ((SPropTagArray*) &ptaProp, 0, &ulc, &lpProps);
lpProps->Value.lpszA;
}
// Get a contents table of all the contents in the
// WABs root container
//
hr = lpContainer->GetContentsTable (0, &lpAB);
if( HR_FAILED (hr) ) goto exit;
// Order the columns in the ContentsTable to conform to the
// ones we want - which are mainly DisplayName, EntryID and
// ObjectType
// The table is guaranteed to set the columns in the order
// requested
//
hr = lpAB->SetColumns ((LPSPropTagArray) &ptaEid, 0);
if( HR_FAILED (hr) ) goto exit;
// Reset to the beginning of the table
//
hr = lpAB->SeekRow (BOOKMARK_BEGINNING, 0, NULL);
if( HR_FAILED (hr) ) goto exit;
// Read all the rows of the table one by one
//
do
{
hr = lpAB->QueryRows (1, 0, &lpRowAB);
if( HR_FAILED (hr) ) break;
if(lpRowAB)
{
cNumRows = lpRowAB->cRows;
if( cNumRows )
{
BOOL bOkay = TRUE;
LPTSTR lpsz = lpRowAB->aRow [0].lpProps
[ieidPR_GIVEN_NAME].Value.lpszA;
LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow [0].lpProps
[ieidPR_ENTRYID].Value.bin.lpb;
ULONG cbEID = lpRowAB->aRow [0].lpProps
[ieidPR_ENTRYID].Value.bin.cb;
if( bAll == FALSE )
{
UINT uiType = PROP_TYPE (lpRowAB->aRow [0].lpProps
[ieidPR_BUSINESS_FAX_NUMBER].ulPropTag);
LPSTR lp = lpRowAB->aRow [0].lpProps
[ieidPR_BUSINESS_FAX_NUMBER].Value.lpszA;
if( uiType != PT_STRING8 || strlen (lp) == 0 ) bOkay = FALSE;
}
// There are 2 kinds of objects - the MAPI_MAILUSER contact object
// and the MAPI_DISTLIST contact object
// For the purposes of this sample, we will only consider MAILUSER
// objects
//
if( bOkay && lpRowAB->aRow [0].lpProps [ieidPR_OBJECT_TYPE].Value.l ==
MAPI_MAILUSER )
{
// the number of the newly added item (row)
int iRow = 0;
// We will now take the entry-id of each object and cache it
// on the listview item representing that object. This enables
// us to uniquely identify the object later if we need to
//
LPSBinary lpSB = NULL;
m_lpWABObject->AllocateBuffer (sizeof (SBinary), (LPVOID *) &lpSB);
if( lpSB )
{
m_lpWABObject->AllocateMore (cbEID, lpSB, (LPVOID *)
&(lpSB->lpb));
if( !lpSB->lpb )
{
m_lpWABObject->FreeBuffer (lpSB);
continue;
}
CopyMemory (lpSB->lpb, lpEID, cbEID);
lpSB->cb = cbEID;
LV_ITEM lvi = {0};
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iItem = ListView_GetItemCount (hList);
lvi.iSubItem = 0;
lvi.pszText = lpsz;
lvi.lParam = (LPARAM) lpSB;
// Now add this item to the list view
iRow = ListView_InsertItem (hList, &lvi);
// Now add sub-items to the list view
// it should start from 1. 0 is the first column
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_SURNAME);
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_BUSINESS_FAX_NUMBER);
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_EMAIL_ADDRESS);
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_ADDRTYPE);
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_STREET_ADDRESS);
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_LOCALITY);
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_STATE_OR_PROVINCE);
SetItemText (hList, iRow, lpRowAB->aRow [0].lpProps,
ieidPR_POSTAL_CODE);
}
}
}
this->FreeProws (lpRowAB );
}
}
while( SUCCEEDED(hr) && cNumRows && lpRowAB );
exit:
if ( lpContainer ) lpContainer->Release ();
if ( lpAB ) lpAB->Release ();
return hr;
}
Alex Cherednichenko
--- ifmail v.2.15dev5
* Origin: FidoNet Online - http://www.fido-online.com (2:5020/400)