Reading and Writing Records

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.

    To read a record using abRead

  1. Specify the CEOID of the record to read, or specify NULL to read the current record.
  2. Specify the number of properties to read from this record.

    This parameter is also used to return the number of properties actually read.

  3. Specify an array of HPR_* identifiers that indicates the properties to retrieve.
  4. Specify a pointer to an array of CEPROPVAL structures that will receive the properties read.
  5. Call abRead.
  6. Check the return value to verify if the call succeeded.

    To create or update a record using abWrite

  1. Specify the CEOID of the record to update, or specify NULL to create a new record.
  2. Specify the number of properties to write.
  3. Specify a pointer to the array of CEPROPVAL structures that contain the properties to write.
  4. Call abWrite.
  5. Check the return value to verify if the call succeeded.

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;