Can't get Outlook calendar info

D

D-Code-99

Hi,

I have a strange problem with Outlook automation of the calendar. I have
mail, tasks etc working perfectly. This is a VC6 app with the MFC wrappers
around the Outlook 2k automation interface.

I'm trying to retrieve a list of all calendar items in the next X days,
including recurrences. I have 2 problems.

Problem 1: Without recurrences, I can't get the details (eg: subject) of any
calendar items. Code sample:

MAPIFolder olCalendar = olNs.GetDefaultFolder(FolderType_olFolderCalendar);
olItems = olCalendar.GetItems();
_Items ol7DayItems = olItems.Restrict(_T("[Start] > '04/12/2005' and
[Start] < '11/12/2005'"));
_AppointmentItem olCalendarItem = ol7DayItems.GetFirst();

for(int iCalendarItemCount = 0; iCalendarItemCount <=
ol7DayItems.GetCount(); iCalendarItemCount++)
{
olCalendarItem = ol7DayItems.GetNext();

CString cstrSubj = olCalendarItem.GetSubject();
}

In this code, ol7DayItems.GetCount() is correct but cstrSubj is always blank.

Problem 2: With recurrence enabled, GetCount() returns a crazy number.
Sample code:

olItems = olCalendar.GetItems();
iCount = olItems.GetCount();
olItems.SetIncludeRecurrences(TRUE);
olItems.Sort(_T("[Start]"), g_covFalse);
iCount = olItems.GetCount();

The first call to GetCount() correctly returns the number of items. The
second call returns 2147483647. When retrieving the items, the first
recurring item is retrieved correctly (I can actually get the subject), but
the rest return blank as above. I also admit I don't understand why the
collection must be sorted by Start in ascending order, but that's the only
time recurrence appears to work.

All help appreciated, thanks!
 
D

D-Code-99

Never mind, I got it. Why the hell MS insists on providing a million VB
samples and about 2 C++ samples I have no idea.

For anyone that cares in the future, there's a technet article that states
recurring appointments return the invalid count. So to avoid it, loop based
on the return val of GetNext() != NULL. Still have no idea why sorting
ascending by start is required though.

Bah.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top