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:

    pAppt->put_Start(date);
    
  7. Set the Appointment Subject property:

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

    pAppt->Save();
    

    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;
    SYSTEMTIME st = NULL;
    DATE date = NULL;

    // Create an appointment item.
    hr = polApp->CreateItem(olAppointmentItem, (IDispatch **)&pAppt);
    if (hr != S_OK) {
        // CreateItem failed.
        MessageBox(NULL, 
                   _T("CreateItem failed."),
                   _T("Warning"), 
                   MB_OK);
        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);
    pAppt->put_Start(date);

    GetCtrlBstr(hDlg, IDC_DESC, &bstrSubject);

    // Set the appointment subject.
    if (SysStringLen(bstrSubject) <= 1) {
        MessageBox(hDlg, 
                   _T("Please enter a description"), 
                   _T("Error"), 
                   MB_OK);
        return TRUE;
    }
    pAppt->put_Subject(bstrSubject);

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

    // Free resources.
    pAppt->Release();
}

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.