You can read and write Address Book records by calling abRead and abWrite. Both functions take the CEOID of the record you want to read or write as their first parameter, and return a HRESULT that indicates success or failure.
This parameter is also used to return the number of properties actually read.
The following code example shows how to call abDialog to have the user find a record, and how to call abRead to read two properties from the selected record.
HRESULT hr;
ABDIALOGINFO abDI;
static char sCaption[80] = “Where do you want to go today?”;
// Set the caption to use at the top of the screen.
abDI.bstrMainFormCaption = &sCaption;
abDI.ceoid = NULL; // Do not use a default record.
// Set the initial view to be the Address Book List dialog box
// and put an Auto PC into locate mode.
abDI.wInitView = ABV_LOCATE;
// Make an Auto PC behave as if it were put
// into locate mode by voice commands.
abDI.dwEnabled = ABE_TTS ;
hr = abDialog(&abDI); // Enable the user to pick a contact.
if (SUCCEEDED(hr))
{
// The user has picked a contact. Read the record’s properties.
// The list of properties to read
CEPROPID rgidProps[] = { HHPR_GIVEN_NAME, HHPR_SURNAME };
// The pointer in which abRead returns a pointer to the list of
// properties that were read
PCEPROPVAL prgProps = NULL;
// The number of properties to read
WORD cProps = sizeof(rgidProps)/sizeof(CEPROPID);
hr = abRead(abDI.ceoid, &cProps, rgidProps, &prgProps);
if(SUCCEEDED(hr))
{
// Copy the first name to m_bstrName.
wcscpy(m_bstrName, prgProps->val.lpwstr);
prgProps++; // Go to the next property.
// Copy the last name to m_bstrlastname.
wcscpy(m_bstrLastName, prgProps->val.lpwstr);
}
else hr = E_FAIL;
}
return;