Share via


How to: Create a PIM Item

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 Pocket Outlook 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 POOM 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();
    

Example

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

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);
    st.wDay = nDay;
    st.wMonth = nMonth;
    st.wYear = nYear;

    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

IPOutlookApp::CreateItem

IPOutlookApp::SystemTimeToVariantTime

OlItemType

Pocket Outlook Object Model

Send feedback on this topic to the authors.

© 2005 Microsoft Corporation. All rights reserved.