A Pocket Outlook folder defined by the IFolder interface contains a collection of objects that are specific to the folder type. For example, the Tasks folder contains only ITask items. To get the pointer for an IFolder interface, you use the IPOutlookApp::GetDefaultFolder() function. Once you have the pointer to a particular IFolder interface, you can then access, modify, and delete Pocket Outlook items. Table 10.4 describes the method supported by each IFolder interface (for Contacts, Calendar, and Tasks).
Table 10.5 describes the properties supported by the IFolder interface.
The most common use for a folder is to get access to the collection object for the items that it is storing. To do so, use the following function: HRESULT IFolder::get_Items(IPOutlookItemCollection **ppolItems); The only parameter that the function takes is a pointer to an IPOutlookItemCollection interface pointer. Once this pointer has been returned, you can begin to sort and access individual Outlook data items. You can get the collection of Outlook items in the following manner: // Get the calendar items IPOutlookItemCollection *pICalItems = NULL; hr = pIFolder->get_Items(&pICalItems); if(FAILED(hr)) { pIFolder->Release(); return FALSE; } // Do something with the items TCHAR tchMsg[1024] = TEXT("\0"); int nCount = 0; pICalItems->get_Count(&nCount); wsprintf(tchMsg, TEXT("There are %d items"), nCount); MessageBox(NULL, tchMsg, TEXT("Calendar"), MB_OK); // Clean up if(pICalItems) pICalItems->Release(); Sending and Receiving Items over InfraredIn addition to the three standard folders Contacts, Tasks, and Calendar there is a special fourth folder that doesn't contain any actual Outlook items. The Infrared folder is used for sending items over the IR port to another Pocket PC device. You can get a pointer to the Infrared folder just as you do for other folders, by using the IPOutlookApp::GetDefaultFolder() function, as shown in the following example: // Infrared IFolder *pIRFolder = NULL; hr = pOlApp->GetDefaultFolder(olFolderInfrared, &pIRFolder); if(FAILED(hr)) { OutputDebugString(TEXT("Could not get the infrared folder")); return FALSE; } if(pIRFolder) pIRFolder->Release(); Table 10.6 describes the additional methods supported by the IFolder interface, which are used when working with the Infrared folder.
You can add any type of item that is supported by Pocket Outlook to the folder by calling into the IFolder::AddItemToInfraredFolder() method, which is defined as follows: HRESULT IFolder::AddItemToInfraredFolder(int olItem, IDispatch *polItem); The first parameter should specify the type of item that is being added, and can be set to olAppointmentItem, olContactItem or olTaskItem. The polItem parameter should point to the actual item that is being added. After you have added all of the contacts, appointments, and tasks that you want to send, you can simply instruct the folder to transmit them by calling the following function: HRESULT IFolder::SendToInfrared(); The following example shows how to use these functions to send a Pocket Outlook appointment item over infrared: // Get the calendar items IPOutlookItemCollection *pICalItems = NULL; hr = pIFolder->get_Items(&pICalItems); if(FAILED(hr)) { pIFolder->Release(); return FALSE; } // Get an item IAppointment *pICalEntry = NULL; hr = pICalItems->Item(1, (IDispatch **)&pICalEntry); // Send it to IR if(SUCCEEDED(hr)) { pIRFolder->AddItemToInfraredFolder(olAppointmentItem, pICalEntry); pIRFolder->SendToInfrared(); } When you want to receive Outlook data over the infrared port, there are two different methods that you can use:
To set up your application to receive data over the infrared port, you can do the following: // Infrared IFolder *pIRFolder = NULL; hr = pOlApp->GetDefaultFolder(olFolderInfrared, &pIRFolder); if(FAILED(hr)) { OutputDebugString(TEXT("Could not get the infrared folder")); return FALSE; } // Receive pIRFolder->ReceiveFromInfrared(); if(pIRFolder) pIRFolder->Release(); |