class CWAB
{
public:
CWAB(string fileName);
~CWAB();
bool LoadWABContents(list<string> &contactsList);
void ClearWABLVContents();
private:
BOOL m_bInitialized;
HINSTANCE m_hinstWAB;
LPWABOPEN m_lpfnWABOpen;
LPADRBOOK m_lpAdrBook;
LPWABOBJECT m_lpWABObject;
// Cache Proparray of currently selected item in the list view
LPSPropValue m_lpPropArray;
ULONG m_ulcValues;
// Cache entry id of currently selected item in the listview
SBinary m_SB;
map<int,void *> contactsMap;
void FreeProws(LPSRowSet prows);
//HRESULT HrGetWABTemplateID(ULONG ulObjectType, ULONG *lpcbEID, LPENTRYID * lppEID);
};
class CWAB
{
public:
CWAB(string fileName);
~CWAB();
bool LoadWABContents(list<string> &contactsList);
void ClearWABLVContents();
private:
BOOL m_bInitialized;
HINSTANCE m_hinstWAB;
LPWABOPEN m_lpfnWABOpen;
LPADRBOOK m_lpAdrBook;
LPWABOBJECT m_lpWABObject;
// Cache Proparray of currently selected item in the list view
LPSPropValue m_lpPropArray;
ULONG m_ulcValues;
// Cache entry id of currently selected item in the listview
SBinary m_SB;
map<int,void *> contactsMap;
void FreeProws(LPSRowSet prows);
//HRESULT HrGetWABTemplateID(ULONG ulObjectType, ULONG *lpcbEID, LPENTRYID * lppEID);
};
To copy to clipboard, switch view to plain text mode
CWAB::CWAB(string fileName)
{
// Here we load the WAB Object and initialize it
m_bInitialized = FALSE;
m_lpPropArray = NULL;
m_ulcValues = 0;
m_SB.cb = 0;
m_SB.lpb = NULL;
{
TCHAR szWABDllPath[MAX_PATH];
DWORD dwType = 0;
ULONG cbData = sizeof(szWABDllPath);
HKEY hKey = NULL;
*szWABDllPath = '\0';
// First we look under the default WAB DLL path location in the
// Registry.
// WAB_DLL_PATH_KEY is defined in wabapi.h
//
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
RegQueryValueEx( hKey, L"", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
if(hKey) RegCloseKey(hKey);
// if the Registry came up blank, we do a loadlibrary on the wab32.dll
// WAB_DLL_NAME is defined in wabapi.h
//
m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
}
if(m_hinstWAB)
{
// if we loaded the dll, get the entry point
//
m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
if(m_lpfnWABOpen)
{
HRESULT hr = E_FAIL;
WAB_PARAM wp = {0};
wp.cbSize = sizeof(WAB_PARAM);
wp.szFileName = (LPSTR) (LPCTSTR) fileName.c_str();
// if we choose not to pass in a WAB_PARAM object,
// the default WAB file will be opened up
//
hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0);
if(!hr)
m_bInitialized = TRUE;
}
}
}
// Destructor
CWAB::~CWAB()
{
if(m_SB.lpb)
LocalFree(m_SB.lpb);
if(m_bInitialized)
{
if(m_lpPropArray)
m_lpWABObject->FreeBuffer(m_lpPropArray);
if(m_lpAdrBook)
m_lpAdrBook->Release();
if(m_lpWABObject)
m_lpWABObject->Release();
if(m_hinstWAB)
FreeLibrary(m_hinstWAB);
}
}
bool CWAB::LoadWABContents(list<string> &contactsList)
{
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)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// Get a contents table of all the contents in the
// WABs root container
//
hr = lpContainer->GetContentsTable( 0,&lpAB);
if(HR_FAILED(hr)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// 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)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// Reset to the beginning of the table
//
hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
if(HR_FAILED(hr)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// Read all the rows of the table one by one
//
int i = 1;
do {
hr = lpAB->QueryRows(1, 0, &lpRowAB);
if(HR_FAILED(hr)){
break;
}
if(lpRowAB) {
cNumRows = lpRowAB->cRows;
if (cNumRows) {
LPSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_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;
// There are 2 kinds of objects - the MAPI_MAILUSER contact object
// and the MAPI_DISTLIST contact object
// We will only consider MAILUSER objects
//
if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER) {
// 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;
contactsList.push_back(lpsz);
contactsMap.insert(make_pair(i,lpSB));
//LV_ITEM lvi = {0};
//lvi.mask = LVIF_TEXT | LVIF_PARAM;
//lvi.iItem = pListView->GetItemCount();
//lvi.iSubItem = 0;
//lvi.pszText = lpsz;
//lvi.lParam = (LPARAM) lpSB;
// Now add this item to the list view
//pListView->InsertItem(&lvi);
}
}
}
FreeProws(lpRowAB );
}
++i;
}while ( SUCCEEDED(hr) && cNumRows && lpRowAB) ;
return true;
}
void CWAB::FreeProws(LPSRowSet prows)
{
ULONG irow;
if (!prows)
return;
for (irow = 0; irow < prows->cRows; ++irow)
m_lpWABObject->FreeBuffer(prows->aRow[irow].lpProps);
m_lpWABObject->FreeBuffer(prows);
}
void CWAB::ClearWABLVContents()
{
map<int,void *>::iterator mapIterator;
for(mapIterator = contactsMap.begin(); mapIterator != contactsMap.end(); ++ mapIterator){
if((*mapIterator).second){
LPSBinary lpSB = (LPSBinary) (*mapIterator).second;
m_lpWABObject->FreeBuffer(lpSB);
}
}
}
CWAB::CWAB(string fileName)
{
// Here we load the WAB Object and initialize it
m_bInitialized = FALSE;
m_lpPropArray = NULL;
m_ulcValues = 0;
m_SB.cb = 0;
m_SB.lpb = NULL;
{
TCHAR szWABDllPath[MAX_PATH];
DWORD dwType = 0;
ULONG cbData = sizeof(szWABDllPath);
HKEY hKey = NULL;
*szWABDllPath = '\0';
// First we look under the default WAB DLL path location in the
// Registry.
// WAB_DLL_PATH_KEY is defined in wabapi.h
//
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
RegQueryValueEx( hKey, L"", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
if(hKey) RegCloseKey(hKey);
// if the Registry came up blank, we do a loadlibrary on the wab32.dll
// WAB_DLL_NAME is defined in wabapi.h
//
m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
}
if(m_hinstWAB)
{
// if we loaded the dll, get the entry point
//
m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
if(m_lpfnWABOpen)
{
HRESULT hr = E_FAIL;
WAB_PARAM wp = {0};
wp.cbSize = sizeof(WAB_PARAM);
wp.szFileName = (LPSTR) (LPCTSTR) fileName.c_str();
// if we choose not to pass in a WAB_PARAM object,
// the default WAB file will be opened up
//
hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0);
if(!hr)
m_bInitialized = TRUE;
}
}
}
// Destructor
CWAB::~CWAB()
{
if(m_SB.lpb)
LocalFree(m_SB.lpb);
if(m_bInitialized)
{
if(m_lpPropArray)
m_lpWABObject->FreeBuffer(m_lpPropArray);
if(m_lpAdrBook)
m_lpAdrBook->Release();
if(m_lpWABObject)
m_lpWABObject->Release();
if(m_hinstWAB)
FreeLibrary(m_hinstWAB);
}
}
bool CWAB::LoadWABContents(list<string> &contactsList)
{
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)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// Get a contents table of all the contents in the
// WABs root container
//
hr = lpContainer->GetContentsTable( 0,&lpAB);
if(HR_FAILED(hr)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// 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)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// Reset to the beginning of the table
//
hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
if(HR_FAILED(hr)){
if ( lpContainer )
lpContainer->Release();
if ( lpAB )
lpAB->Release();
return false;
}
// Read all the rows of the table one by one
//
int i = 1;
do {
hr = lpAB->QueryRows(1, 0, &lpRowAB);
if(HR_FAILED(hr)){
break;
}
if(lpRowAB) {
cNumRows = lpRowAB->cRows;
if (cNumRows) {
LPSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_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;
// There are 2 kinds of objects - the MAPI_MAILUSER contact object
// and the MAPI_DISTLIST contact object
// We will only consider MAILUSER objects
//
if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER) {
// 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;
contactsList.push_back(lpsz);
contactsMap.insert(make_pair(i,lpSB));
//LV_ITEM lvi = {0};
//lvi.mask = LVIF_TEXT | LVIF_PARAM;
//lvi.iItem = pListView->GetItemCount();
//lvi.iSubItem = 0;
//lvi.pszText = lpsz;
//lvi.lParam = (LPARAM) lpSB;
// Now add this item to the list view
//pListView->InsertItem(&lvi);
}
}
}
FreeProws(lpRowAB );
}
++i;
}while ( SUCCEEDED(hr) && cNumRows && lpRowAB) ;
return true;
}
void CWAB::FreeProws(LPSRowSet prows)
{
ULONG irow;
if (!prows)
return;
for (irow = 0; irow < prows->cRows; ++irow)
m_lpWABObject->FreeBuffer(prows->aRow[irow].lpProps);
m_lpWABObject->FreeBuffer(prows);
}
void CWAB::ClearWABLVContents()
{
map<int,void *>::iterator mapIterator;
for(mapIterator = contactsMap.begin(); mapIterator != contactsMap.end(); ++ mapIterator){
if((*mapIterator).second){
LPSBinary lpSB = (LPSBinary) (*mapIterator).second;
m_lpWABObject->FreeBuffer(lpSB);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks