void FreeWAB(HINSTANCE hWAB, LPADRBOOK pAdrBook, LPWABOBJECT pWABObject, AdrBookTable *pTable, UINT nNumEntries) { if (pTable && nNumEntries) { for (UINT i=0; i<nNumEntries; i++) { if (pTable[i].szName) free(pTable[i].szName); if (pTable[i].szEmail) free(pTable[i].szEmail); } free(pTable); } if(pAdrBook) pAdrBook->Release(); if(pWABObject) pWABObject->Release(); if(hWAB) FreeLibrary(hWAB); return; }
void CProcessor::ImportWAB() { HINSTANCE hinstLib; HRESULT hRes; LPADRBOOK lpAdrBook; LPWABOBJECT lpWABObject; DWORD Reserved2 = NULL; fWABOpen procWABOpen; { 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, "", 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 // hinstLib = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME ); } if (hinstLib != NULL) { procWABOpen = (fWABOpen) GetProcAddress(hinstLib, "WABOpen"); if (procWABOpen != NULL) { hRes = (procWABOpen)(&lpAdrBook,&lpWABObject,NULL,Reserved2); // WABOpen _ASSERTE(hRes == S_OK); if (hRes != S_OK) return; ULONG lpcbEntryID; ENTRYID *lpEntryID; hRes = lpAdrBook->GetPAB( &lpcbEntryID, &lpEntryID ); _ASSERTE(hRes == S_OK); if (hRes != S_OK) return; ULONG ulFlags = MAPI_BEST_ACCESS; ULONG ulObjType = NULL; LPUNKNOWN lpUnk = NULL; hRes = lpAdrBook->OpenEntry( lpcbEntryID, lpEntryID, NULL, ulFlags, &ulObjType, &lpUnk ); ulFlags = NULL; //IABTable *lpTable; if (ulObjType == MAPI_ABCONT) { IABContainer *lpContainer = static_cast <IABContainer *>(lpUnk); LPMAPITABLE lpTable = NULL; hRes = lpContainer->GetContentsTable( ulFlags, &lpTable ); _ASSERT(lpTable); ULONG ulRows, ulFound = 0, ulExisted = 0; hRes = lpTable->GetRowCount(0,&ulRows); _ASSERTE(hRes == S_OK); SRowSet *lpRows; hRes = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0 ); hRes = lpTable->QueryRows( ulRows, // Get all Rows 0, &lpRows ); for(ULONG i=0;i<lpRows->cRows;i++) { bool bBirthdayProcessed = false; CBirthday* pbd = new CBirthday; SRow *lpRow = &lpRows->aRow[i]; for(ULONG j=0;j<lpRow->cValues;j++) { SPropValue *lpProp = &lpRow->lpProps[j]; if(lpProp->ulPropTag == PR_BIRTHDAY) { SYSTEMTIME st; FileTimeToSystemTime(&lpProp->Value.ft,&st); pbd->m_date = CDate((BYTE)st.wDay, (BYTE)st.wMonth, (UINT)st.wYear); bBirthdayProcessed = true; } if(lpProp->ulPropTag == PR_DISPLAY_NAME_A) { pbd->m_name = lpProp->Value.lpszA; } } if( bBirthdayProcessed && pbd->m_date.ValidDate() ) { ulFound++; if( !WABExists(pbd) ) { pbd->m_medium = MEDIUM_WAB; Add( pbd ); } else { delete pbd; ulExisted++; } } else delete pbd; lpWABObject->FreeBuffer(lpRow); } CString c; c.Format( "Processed %d contacts\r\n\r\nFound %d birthdays of which\r\n%d already existed", ulRows, ulFound, ulExisted ); AfxMessageBox( c, MB_OK|MB_SYSTEMMODAL, 0 ); lpWABObject->FreeBuffer(lpRows); } if(lpAdrBook) lpAdrBook->Release(); if(lpWABObject) lpWABObject->Release(); } // This would be nice but leads to crashing Trillian // FreeLibrary(hinstLib); } }