public Form1() { try { InitializeComponent(); // Create an instance of the PocketOutlook application object and log on outlookApp = new PocketOutlook.ApplicationClass(); outlookApp.Logon(0); // Get the contacts, tasks, and calendar folders. contactsFolder = outlookApp.GetDefaultFolder(OlDefaultFolders.olFolderContacts); tasksFolder = outlookApp.GetDefaultFolder(OlDefaultFolders.olFolderTasks); calendarFolder = outlookApp.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); // Add event handlers used to parse phone numbers after they // are entered. homePhoneTextBox.LostFocus += new EventHandler(phone_LostFocus); workPhoneTextBox.LostFocus += new EventHandler(phone_LostFocus); cellPhoneTextBox.LostFocus += new EventHandler(phone_LostFocus); // Clear the fields in the UI. ClearContact(); ClearTask(); ClearAppointment(); } // Failure HRESULTS returned from COM objects result in COMExceptions in managed code. // Catching COMExceptions allows you to examine the HRESULT returned from the Com object catch (COMException cex) { MessageBox.Show("A Com error occurred while initializing PocketOutlook: " + cex.ToString()); } }