PocketOutlook and COM Interop

New to the .NET Compact Framework in Whidbey Beta 1 is a feature known as COM Interop.  Among other things, this feature allows simple managed access to a number of Native APIs, including the Pocket Outlook Object Model (POOM).  Steven has posted a great article on getting POOM into your Whidbey project (I highly recommend reading it here.)

I thought I'd take some time to focus on Step 4 of Steven's article, "Write your POOM application".  After all, once you've gotten the PocketOutlook Interop Assembly references, it's time to do something with it.

Two resources I've found to be invaluable are the Pocket Outlook Object Model Documentation at MSDN, and the Object Browser within Whidbey itself. 

If you're not familiar with the Object Browser, take some time to get acquainted with it once you've referenced the Pocket Outlook Interop Assembly.  All assemblies and their namespaces are listed in the browser.

By expanding the namespace, you can look at individual classes and interfaces, and see not only their methods, by also the signatures as they have been imported by TLBIMP.  And, of course, through the magic that is intellisense, you get full intellisense for the POOM classes and methods.

For my application, I chose to write a simple managed Task Viewer.  One drawback of the task viewer that ships with Windows Mobile is that there's no way to both view and edit tasks at the same time. 

With approximately 2 hours of coding, I was able to produce the application pictured to the left.  The ListView shows all the tasks on the system (the same tasks that will show in the task viewer that ships with Windows Mobile). The fields at the bottom will allow the user to add new tasks, or edit existing tasks after selecting them in the ListView.  Using the context menu on the ListView, the user can mark tasks as complete (which highlights them with a dark grey), or delete them.

Changes made to the tasks via this application are reflected in the task viewer integrated into Windows Mobile.  The app stores no information internally, but rather makes all updates, and retrieves all displayed items, directly with POOM.

The code for this program (not counting that code automatically generated by the Windows Designer) is well under 300 lines (including white space for readability), and as you can well imagine, the majority of the code I wrote manipulates the UI.  Less than 40 lines of C# code were required to manipulate POOM in the ways I've described. 

The code required to activate the POOM Application object, logon, and retrieve the the Task Folder is as simple as:

// Get the application class and the tasksFolder
ApplicationClass outlookApp = new ApplicationClass();
outlookApp.Logon(0);
IFolder tasksFolder = outlookApp.GetDefaultFolder(OlDefaultFolders.olFolderTasks);

You can find TaskViewer.cs here.  Please feel free to send me any questions regarding this application, or using COM Interop with POOM.