Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Address Book (WAB)

Status
Not open for further replies.

indrekm

Programmer
Nov 21, 2005
1
EE
How can use WAB in MS Visual C++?
How can acces "mobile number"?
I have found accessing "e-mail".

Code:
// Load email addresses into the vector 
int CWinAddrBook::LoadEmails(void) 
{ 
    HRESULT hr = E_FAIL; 

    if (ssWABOpen==NULL) return 1; //ssWABOpen cannot be NULL 
    { 
        ULONG lpcbEntryID; 
        ENTRYID* lpEntryID; 

        hr = lpAddrBook->GetPAB(&lpcbEntryID, &lpEntryID); 
        if (hr!=S_OK) return 10; //error opening the darn PAB 
        
        //Declare variables for MAPI and specific access to the PAB 
        ULONG ulFlags = MAPI_BEST_ACCESS, 
              ulObjType = NULL; 
        LPUNKNOWN lpIUnknown = NULL; 
        hr = lpAddrBook->OpenEntry(lpcbEntryID, 
                                   lpEntryID, 
                                   NULL, 
                                   ulFlags, 
                                   &ulObjType, 
                                   &lpIUnknown); 

        ulFlags = NULL; //We are using it again :) 

        if (ulObjType==MAPI_ABCONT) //See if an address book container was passed which we are looking for 
        { 
            IABContainer* lpABContainer = static_cast<IABContainer*>(lpIUnknown); //cast the IUnknown pointer returned from previous function to what we need 
            LPMAPITABLE lpMAPItbl = NULL; 
            hr = lpABContainer->GetContentsTable(ulFlags, &lpMAPItbl); 
            ASSERT(lpMAPItbl); 
            
            ULONG ulRows; //Number of rows in the MAPI table (Addresses) 
            hr = lpMAPItbl->GetRowCount(0, &ulRows); 
                if (hr!=S_OK) return 11; //Return 11 to tell them we where unable to get the row count 
            
            SRowSet* lpRowSet; 
            hr = lpMAPItbl->QueryRows(        //Return all the rows found in the address book 
                                    ulRows,                                    
                                    0, 
                                    &lpRowSet); 
            
            //Grow variable 
            AddrMemBook.resize(lpRowSet->cRows); 
            //char Match[200]; strset(Match, 0); 

            for (ULONG x = 0; x < lpRowSet->cRows; x++) 
            { 
                //Loop through all the rows and add it to our address book 
                //vector variable 
                EMAILS thisAddr;                                            

                SRow* lpRow = &lpRowSet->aRow[x]; //Get this specific row 
                for (ULONG y = 0; y < lpRow->lpProps; y++) 
                { 
                    
                } 
                for (ULONG y = 0; y < lpRow->cValues; y++) 
                { 
                    //Loop through the fields in the address book and assign 
                    //to our variable and put it in the address book variable                    
                        SPropValue* lPropVal = &lpRow->lpProps[y]; 
                    switch (lPropVal->ulPropTag) 
                    { 
                    case PR_DISPLAY_NAME_A:        
                        thisAddr.DisplayName = lPropVal->Value.lpszA;                        
                        //strcpy(thisAddr->DisplayName, lPropVal->Value.lpszA); 
                        break; 

                    case PR_EMAIL_ADDRESS_A:                        
                        thisAddr.EmailAddr = lPropVal->Value.lpszA; 
                        if (strchr(thisAddr.EmailAddr.c_str(), '@')==NULL) //replace with empty string 
                            thisAddr.EmailAddr='\0'; 
                        //strcpy(thisAddr->EmailAddr, lPropVal->Value.lpszA);                        
                        break; 

                    case PR_NICKNAME_A:                        
                        thisAddr.NickName = lPropVal->Value.lpszA; 
                        //strcpy(thisAddr->NickName, lPropVal->Value.lpszA); 
                        break; 

                    default: 
                        break; 
                    } 

                }//End of cycling through fields 
                //Add the information to the vector variable                
                if (!thisAddr.EmailAddr.empty()) 
                    AddrMemBook.push_back(thisAddr);                

                lpWABObject->FreeBuffer(lpRow); 

            }//End of cycling through rows 
            lpWABObject->FreeBuffer(lpRowSet); 
        } 
    } 

    return 0; 
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top