Windows Mobile: Programmatically Making Contact


I’ve recently been working on a Windows Mobile Starter Kit (I’ll be uploading it shortly) that interacts with the internal Contact’s database on the Windows Mobile device. Last time I wrote an application that tried to read the Contacts, I used C++ to play around with POOM (the Pocket Outlook Object Model) and let’s just say it wasn’t the most fun I've ever had. This time, however, I’ve been using C# to do all the dirty work, and it’s absolutely wonderful.


If there is one thing that C# makes easy, it’s accessing a hierarchical list of data. Here’s how easy it is to list all the names stored in the Contacts directory:


1.    Create a “session”, like this:


private OutlookSession mySession = new OutlookSession();


2.    Set up a loop to go through all the Contacts


 


int index = 0;


while (index < mySession.Contacts.Items.Count)


{


// Do stuff


}


3.    Access the data, like this:


MessageBox.Show( mySession.Contacts.Items[index].FirstName + " " + mySession.Contacts.Items[index].LastName);


Nice, huh?


Now I did meet a snag. I wanted my program to react if the user added or deleted a Contact from the list manually, using the standard Contact dialog. I was hoping that I could simply use a callback with the


mySession.Contacts.Items.ListChanged


event. Alas, it was not to be. After some research, it turns out that this event is only triggered when changes to the Contact’s list occurs programmatically within the same session. It makes sense, I suppose, but its less helpful than I hoped.


I asked a few code gurus, including Peter Foot, who recommended registering for PIM notifications  via native code. Peter has created a PocketOutlook namespace that exposes this – you can check it out here: http://inthehand.com/content/Mobile.aspx

Skip to main content