Windows Mobile 6.5

The RemoveCategory method removes a category from a PIM item's PIMPR_CATEGORIES property.

HRESULT RemoveCategory(
  LPCWSTR pszwCategory


[in] The category string value.

This method returns the standard values HRESULT_FROM_WIN32(GetLastError()), E_INVALIDARG, and S_FAIL, as well as the following:


The method completed successfully.

For PIM items, PIMPR_CATEGORIES represents the categories assigned to that item. For a root folders, PIMPR_CATEGORIES represents the set of categories available for that folder.

When the user deletes the last PIM item associated with a particular category, Outlook Mobile automatically removes that category from the list of available categories, and it no longer shows up in the category picker in the user interface.

The following code example demonstrates how to use RemoveCategory.

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.
HRESULT RemoveCategoryExample(IItem *pItem)
    HRESULT hr                = E_FAIL;

    CEPROPID propidCategories = PIMPR_CATEGORIES;
    CEPROPVAL *pValCategories = NULL;

    ULONG   cbBuffer          = 0;
    HANDLE hHeap              = GetProcessHeap();

    // Assume that the original categories set for this are Category1, Category11, and Category111. Check the HRESULT returned from 
    // each of these calls to make sure that the new category was actually added.
    hr = pItem->RemoveCategory(L"Category111");

    hr = pItem->Save();

    hr = pItem->GetProps(&propidCategories, CEDB_ALLOWREALLOC, 1, &pValCategories, &cbBuffer, hHeap);

    // At this point, the list is L"Category1, Category11".
    HeapFree(hHeap, 0, pValCategories);

    return hr;

Windows MobilePocket PC for Windows Mobile Version 5.0 and later, Smartphone for Windows Mobile Version 5.0 and later



Other Resources

Community Additions