Partager via


How to: Read Time Zone Properties from an Appointment

How to: Read Time Zone Properties from an Appointment

This topic shows a function, ReadTimeZones, that calls the two functions, BinToTZDEFINITION and BinToTZREG, to read the time zone properties, dispidApptTZDefStartDisplay and dispidTimeZoneStruct, from an appointment.

dispidApptTZDefStartDisplay contains a stream that maps to the persisted format of a TZDEFINITION structure, and dispidTimeZoneStruct contains a stream that maps to the persisted format of a TZREG structure. To obtain the exact TZDEFINITION and TZREG structures, BinToTZDEFINITION and BinToTZREG are used to parse the stream values of these properties appropriately. These two functions are defined in How to: Parse a Stream from a Binary Property to Read the TZDEFINITION Structure and How to: Parse a Stream from a Binary Property to Read the TZREG Structure respectively.

  void ReadTimeZones(LPMAPIPROP lpAppointment)
{
    HRESULT hRes = S_OK;
    LPSPropTagArray lpNamedPropTags = NULL;
    MAPINAMEID NamedID[2] = {0};
    LPMAPINAMEID lpNamedID[2];
    lpNamedID[0] = &NamedID[0];
    lpNamedID[1] = &NamedID[1];
    NamedID[0].lpguid = (LPGUID)&PSETID_Appointment;
    NamedID[0].ulKind = MNID_ID;
    NamedID[0].Kind.lID = dispidTimeZoneStruct;
    NamedID[1].lpguid = (LPGUID)&PSETID_Appointment;
    NamedID[1].ulKind = MNID_ID;
    NamedID[1].Kind.lID = dispidApptTZDefStartDisplay;
    hRes = lpAppointment->GetIDsFromNames(
        2,
        lpNamedID,
        NULL,
        &lpNamedPropTags);
    if (SUCCEEDED(hRes) && lpNamedPropTags)
    {
        SizedSPropTagArray(2,sptaTzProps) = {2,
            CHANGE_PROP_TYPE(lpNamedPropTags->aulPropTag[0],PT_BINARY),
            CHANGE_PROP_TYPE(lpNamedPropTags->aulPropTag[1],PT_BINARY),
        };
        LPSPropValue lpProps = NULL;
        ULONG cProps = 0;
        hRes = lpAppointment->GetProps(
            (LPSPropTagArray)&sptaTzProps,
            NULL,
            &cProps,
            &lpProps);
        if (SUCCEEDED(hRes) && 2 == cProps && lpProps)
        {
            if (PT_BINARY == PROP_TYPE(lpProps[0].ulPropTag))
            {
                TZREG* ptzReg = BinToTZREG(lpProps[0].Value.bin.cb,lpProps[0].Value.bin.lpb);
                // TODO: Do whatever necessary with ptzReg
                delete ptzReg;
            }
            if (PT_BINARY == PROP_TYPE(lpProps[1].ulPropTag))
            {
                TZDEFINITION* ptzDef = BinToTZDEFINITION(lpProps[1].Value.bin.cb,lpProps[1].Value.bin.lpb);
                // TODO: Do whatever is necessary with ptzDef
                delete[] ptzDef;
            }
           }
        MAPIFreeBuffer(lpProps);
    }
    MAPIFreeBuffer(lpNamedPropTags);
}

See Also

About Rebasing Calendars Programmatically for Daylight Saving Time