Share via


How to: Add PIM Items to the Pocket Outlook Database

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

The Pocket Outlook 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 Pocket Outlook application object and then use it to establish a POOM session. For more information, see How to: Establish a POOM Session.

  2. Create a PIM item. For more information, see How to: Create 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 demonstrates how to add a new IContact interface object to the Contacts folder.

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

    hr = polApp->GetDefaultFolder(olFolderContacts, &pFolder);
    if (hr != S_OK) {
        // GetDefaultFolder failed.
        MessageBox(NULL, 
                   _T("GetDefaultFolder failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = pFolder->get_Items(&pItems)
    if (hr != S_OK) {
        // get_Items failed.
        MessageBox(NULL, 
                   _T("get_Items failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = pItems->Add(&pContact)
    if (hr != S_OK) {
        // Add failed.
        MessageBox(NULL, 
                   _T("Add failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = pContact->put_FirstName(TEXT("Michael"));
    if (hr != S_OK) {
        // put_FirstName failed.
        MessageBox(NULL, 
                   _T("put_FirstName failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = pContact->put_LastName(TEXT("Angelo"));
    if (hr != S_OK) {
        // put_LastName failed.
        MessageBox(NULL, 
                   _T("put_LastName failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = pContact->put_Company(TEXT("Microsoft"));
    if (hr != S_OK) {
        // put_Company failed.
        MessageBox(NULL, 
                   _T("put_Company failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = pContact->put_FileAs(TEXT("Angelo"));
    if (hr != S_OK) {
        // put_FileAs failed.
        MessageBox(NULL, 
                   _T("put_FileAs failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    hr = pContact->Save();
    if (hr != S_OK) {
        // Save failed.
        MessageBox(NULL, 
                   _T("Save failed."),
                   _T("Warning"), 
                   MB_OK);
        exit(0);  // Replace with specific error handling.;
    }

    pContact->Release();
    pFolder->Release();
    pItems->Release();
}

See Also

OlDefaultFolders

Pocket Outlook Object Model

Send feedback on this topic to the authors.

© 2005 Microsoft Corporation. All rights reserved.