Freigeben über


IPOutlookItemCollection::Sort

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The Sort method sorts items within an item collection, based on an item property.

Syntax

HRESULT Sort(
   BSTR pwszProperty,
   VARIANT_BOOL fDescending
);

Parameters

  • pwszProperty
    [in] Reference to the item property to sort on. This is a NULL-terminated Unicode string. For information on the BSTR type, see BSTR.
  • fDescending
    [in] VARIANT_TRUE to sort in descending order; VARIANT_FALSE to sort in ascending order. For information about the VARIANT_BOOL type, see the union member of the PROPVARIANT structure.

Return Value

This method returns the standard values E_INVALIDARG, E_OUTOFMEMORY, E_UNEXPECTED, and E_FAIL, as well as the following:

  • S_OK
    The method completed successfully.

Remarks

If you want a particular sort order, specify it in IPOutlookItemCollection::Sort; do not rely on the default sort order.

You cannot sort on the following properties: Categories, BodyInk, ReminderTime, and Recipients.

The VARIANT_BOOL data type (also known as VT_BOOL) uses the value -1 to represent TRUE and 0 to represent FALSE. It is defined in the wtypes.h header file in the following manner:

typedef short VARIANT_BOOL;

A common programming error occurs when, for readability purposes, you want to set a VARIANT_BOOL value to TRUE or FALSE. You can achieve the same effect by using the aliases VARIANT_TRUE and VARIANT_FALSE, which are also defined in the wtypes.h header file.

#define VARIANT_TRUE  ((VARIANT_BOOL)0xffff)
#define VARIANT_FALSE ((VARIANT_BOOL)0)

The default property used to order an item collection depends on the data type, and on the Windows Mobile platform version.

Example

The following code shows how to sort items in ascending order.

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 SortItems(IPOutlookApp * polApp)
{
    IPOutlookItemCollection * pItems;
    IFolder * pFolder;

    // Get the Contacts collection.
    polApp->GetDefaultFolder(olFolderContacts, &pFolder);
    pFolder->get_Items(&pItems);

    // Sort the Contact items by timezone.
    pItems->Sort(TEXT "[TimezoneIndex]", FALSE);

    // Release objects.
    pItems->Release();
    pFolder->Release();
}

Requirements

Header pimstore.h
Library Pimstore.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

IPOutlookItemCollection
Pocket Outlook Object Model Interfaces