Adding PIM Items to the Outlook Mobile Database (Windows Embedded CE 6.0)

1/6/2010

Adding a PIM item to the Outlook Mobile database involves calling the item's Save method.

The Outlook Mobile database consists of three separate PIM item lists contained in the three Default Folders: the Appointments folder, the Tasks folder, and the Contacts folder.

To add a Contact to the Contacts folder

  1. Create an instance of the Outlook Mobile application object and then use it to establish a POOM session. For more information, see Establishing a POOM Session.

  2. Create a PIM item. For more information, see Creating a PIM Item.

  3. Declare a reference to a generic PIM item collection, as follows:

    IPOutlookItemCollection *pItems;
    
  4. Declare a reference to a generic PIM item folder:

    IFolder *pFolder;
    
  5. Use the generic PIM item folder to get the Contacts folder:

    polApp->GetDefaultFolder(olFolderContacts, &pFolder);
    
  6. Use the Contacts folder to get the collection of Contact items:

    pFolder->get_Items(&pItems)
    
  7. Create a new Contact item:

    pItems->Add(&pContact)
    
  8. Initialize the new Contact item's data members:

    pContact->put_FirstName(TEXT("Michael"));
    pContact->put_LastName(TEXT("Angelo"));
    pContact->put_Company(TEXT("Microsoft"));
    pContact->put_FileAs(TEXT("Angelo"));
    
  9. Save the new Contact item to the database:

    pContact->Save();
    

Example

The following code example demonstrates how to add a new Contact object to the Contacts folder.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

void AddNewContact(IPOutlookApp *polApp)
{
    IPOutlookItemCollection * pItems;
    IFolder                 * pFolder;
    IContact                * pContact;

    hr = polApp->GetDefaultFolder(olFolderContacts, &pFolder);
    hr = pFolder->get_Items(&pItems)
    hr = pItems->Add(&pContact)

    hr = pContact->put_FirstName(TEXT("Michael"));
    hr = pContact->put_LastName(TEXT("Angelo"));
    hr = pContact->put_Company(TEXT("Microsoft"));
    hr = pContact->put_FileAs(TEXT("Angelo"));

    hr = pContact->Save();
}

To make the code example easier to read, security checking and error handling are not included.

This code example should not be used in a release configuration unless it has been modified to include them.

Compiling the Code

  • Include Header File: PimStore.h
  • Linker Dependency: PimStore.lib

See Also

Reference

OlDefaultFolders

Other Resources

Pocket Outlook Object Model Common Tasks
Pocket Outlook Object Model Application Development