Creating a PIM Item

Send Feedback

The three PIM item types — Appointment, Task, and Contact — are the main object types in the Pocket Outlook Object Model, and the procedure for creating them is identical for all three.

To create an Appointment

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

  2. Declare and initialize a pointer to a new IAppointment interface object, as follows:

    IAppointment *pAppt = NULL;
  3. Call IPOutlookApp::CreateItem on the Outlook Mobile application object:

    polApp->CreateItem(olAppointmentItem, (IDispatch **)&pAppt);
  4. Create a SYSTEMTIME object, and initialize it with a start date, as follows:

    hDayMonthCtrl = GetDlgItem(hDlg, IDC_DAYMONTHPICKER);
    MonthCal_GetCurSel(hDayMonthCtrl, &st);
    st.wYear = nYear;
    st.wMonth = nMonth;
    st.wDay = nDay;
    hTimeCtrl = GetDlgItem(hDlg, IDC_TIMEPICKER);
    MonthCal_GetCurSel(hTimeCtrl, &st);
    st.wHour = nHour;
    st.wMinute = nMinute;
    st.wSecond = nSecond;
  5. Convert the system time object to a Variant date/time object:

    polApp->SystemTimeToVariantTime(&st, &date);
  6. Set the Appointment Start property:

  7. Set the Appointment Subject property:

    pAppt->put_Subject(TEXT("Recurring Appointment"));
  8. Add the new Appointment to the Appointment collection:


    The Appointment item is added to the Outlook Mobile database.

Code Example

The following code example demonstrates how to create an IAppointment interface object.

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 AddNewAppointment(IPOutlookApp *polApp)
    IAppointment *pAppt = NULL;
    DATE date = NULL;

    // Create an appointment item.
    hr = polApp->CreateItem(olAppointmentItem, (IDispatch **)&pAppt);
    if (hr != S_OK) {
        // CreateItem failed.
                   _T("CreateItem failed."),
        exit(0);  // Replace with specific error handling.;

    // Set the appointment start date.
    hDayMonthCtrl = GetDlgItem(hDlg, IDC_DAYMONTHPICKER);
    MonthCal_GetCurSel(hDayMonthCtrl, &st);
    nDay = &st.wDay;
    nMonth = &st.wMonth;
    nYear = &st.wYear;

    // Set the appointment start time.
    hTimeCtrl = GetDlgItem(hDlg, IDC_TIMEPICKER);
    MonthCal_GetCurSel(hTimeCtrl, &st);
    nHour = &st.wHour;
    nMinute = &st.wMinute;
    nSecond = &st.wSecond;

    polApp->SystemTimeToVariantTime(&st, &date);

    GetCtrlBstr(hDlg, IDC_DESC, &bstrSubject);

    // Set the appointment subject.
    if (SysStringLen(bstrSubject) <= 1) {
                   _T("Please enter a description"), 
        return TRUE;

    // Add the new appointment to the appointment collection.
    hr = pAppt->Save();
    if (hr != S_OK) {
        // Save failed.
                   _T("Save failed."),
        EndDialog(hDlg, IDCANCEL);

    // Free resources.

See Also

How to Create a PIM Application with POOM | Pocket Outlook Object Model Application Development for Windows Mobile-based Devices | IPOutlookApp::CreateItem | IPOutlookApp::SystemTimeToVariantTime | OlItemType

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.