VBCE.com - The Premier Website For Visual Basic/CE Developers

 

*Dev Corner

Sample Code
Controls
Workarounds
Tips & Tricks
Q & A
Forums

*Goodies
Downloads
Software
Bookstore


*General
Home
What's New
General Info
Misc. Info


*News Worthy
News
Articles
Editorials
KB Articles
Reviews
Awards

*Miscellaneous
Web Links
Partners
Search
Feedback
Advertising

Sponsors


More...


Pocket Outlook Object Model (POOM)

Special thanks to John Bonin for providing this sample codeJohn is a Sr. Software Engineer, working at EG&G Services.   He has over 20 years programming experience, dating back when input was done with Punch cards and you waited hours to days to see that you had a syntax error in your program!  Currently, he is involved with developing internet database solutions, desktop database solutions, and applications on handheld devices to aid in the accurate and timely collection of data.


Download Code!

A frequent question appearing in the Windows CE newsgroups, was how to access the Pocket Outlook databases. Well, Microsoft just recently answered that question when they released the Pocket Outlook Object Model SDK (msdn.microsoft.com/cetools/platform/poomsdk.asp). The object model allows the developer to programmatically manipulate the Calendar, Contacts and Tasks database on the H/PC 2.0, H/PC 3.0 or P/PC 1.0 devices.

For complete information about the Pocket Outlook Object Model, visit the Microsoft site listed above and download a copy today. Included with the SDK is a version of the file, pimstore.dll for the Intel 486, Strong Arm, MIPS 3000 , MIPS 4000, SH3 and SH4 processors. You will need to download and register the version matching your processor before you can work with the sample included here.

Although there are many different actions available to the developer using this SDK, I am going to briefly show how to get started by adding an appointment to the Calendar. Get the SDK, read the documentation and experiment. You will be surprised with what you can do with it. Download the sample for the complete code and a Flight Scheduler application.

You should have already downloaded and installed the file pimstore.dll on your device. Next open up Visual Basic and create a new H/PC application. You should add the following line of code to the General Declaration section of Form1:

Dim pol as PocketOutlook.Application

This will bind the pimstore.dll to application during run-time. This is the only object that needs to be declared. Next, we need to create an instance of the Pocket Outlook session by creating the Pocket Outlook Application object:

Set pol = CreateObject("PocketOutlook.Application")

The application object supports the following methods:

  1. Logon
  2. Logoff
  3. GetDefaultFolder
  4. CreateItem
  5. ReceiveFromInfrared
  6. GetTimeZoneFromIndex
  7. GetTimeZoneInformationFromIndex
  8. GetItemFromOidSysFreeString

I am only going to go over the first 4 items in this sample. After creating the Pocket Outlook session, we need to log the user into the session. Unlike, the PC version of Outlook, there is no namespace object and we do not need a username and password to logon to the session. So the first call to Pocket Outlook, must be:

pol.Logon

As expected, our last call to Pocket Outlook application object, should be:

pol.Logout

This logs the user off of a Pocket Outlook session.

Pocket Outlook is made up of 5 folders, Contacts, Cities, Tasks, Appointments and Infrared. Only the first 4 folders can be used to access or create individual Pocket Outlook items. These folders are provided as a means of containing the Items collection. You can not create, delete or manipulate these folders. To access a folders Items collection you call the GetDefaultFolder method.

Set pFolder = pol.GetDefaultFolder(101)

The parameter that is passed is the identifier for the folder that is to be retrieved.

Folder Type Value
Calendar 9
Contacts 10
Tasks 13
Cities 101
Infrared 102

As an example, you would access the Cities collection in the World Clock by:

Set pFolder = pol.GetDefaultFolder(101)
Set pCity = pFolder.Items
For i = 1 To pCity.Count
     Set cityItem = pCity.Item(i)
     dCity.AddItem cityItem.Name
Next i

The last method that I am going to look at today, is the CreateItem method. This function is called to create a task, an appointment or contact. This function allows the developer to create an item without first having to work their way down to the appropriate folder. When you create an item this way, it is only in memory and will not be added to the folder until it is saved. The following will create a new appointment:

Set appointment = pol.CreateItem(1)

The parameter passed is the type of item to be created.

Item Type Value
Appointment 1
Contact 2
Tasks 3
City 101

This Appointment item supports the following properties:

Property Type

Subject String
Location String
Categories String
Start Date
Duration Long
End Date
AllDayEvent Boolean
IsRecurring Boolean ReadOnly
MeetingStatus Long ReadOnly
Sensitivity Long Normal=0 Private=2
BusyStatus Long

Free=0, Tentative=1, Busy=2, Out of Office=3

ReminderSet Boolean
ReminderSoundFile String
ReminderOptions Long
ReminderMinutesbeforeStart Long
Recipients Irecipients ReadOnly
Body String
BodyInk CEBLOB

MeetingStatus is read-only. An appointment that has recipients is automatically a meeting. The Start, Duration and End properties are all related. If you set all three, the Duration is ignored. If you set either Start or End with Duration, then the other one will be calculated. There are some rules that you must follow when creating an appointment. The Subject can only be 4096 characters in length. The Location property can only be 1024 characters. The Body is limited to 20K. Dates must be within the range of 1/1/1900 to 12/32/2999. The Start property must be equal to or less than the End property. Duration must be less than 31 days and the ReminderMinutesBeforeStart must be less than 45 days.

Below is a code example of creating an appointment: 

appointment.Subject = "Flight - " & dCity.Text & " to " & aCity.Text
appointment.Location = Airline.Text & " Flight:" & FlightNumber.Text
appointment.Categories = "Travel"
appointment.BusyStatus = 3
sTime = dDate.Text & " " & dTime.Text
eTime = aDate.Text & " " & aTime.Text
appointment.Start = CDate(sTime)
appointment.Duration = 1
appointment.End = CDate(eTime)
appointment.Body = sComment.Text

We now have created our new appointment, but as stated earlier, it is in memory only. In order to commit it to the calendar, we need to call the Save method:

pol.Save

Now to finish off our sample, we want to look at the appointment just created. A call to Display (pol.Display) will display an item. This will display the new item just created. You may add or modify any information to this display.

poom.gif (8821 bytes)

This has been a quick introduction to the Pocket Outlook Object Model. It is fairly simple to access in Visual Basic and in my opinion opens up many new areas for application developers. Enjoy!

 

VBCE.com is DevX Winner!

Unless otherwise noted, all information on VBCE.com is Copyright 1998 - 2002
Windows, Windows CE, and Visual Basic are trademarks of the Microsoft Corporation.
VBCE.com is not responsible for content on external sites.
Send all feedback to webmaster@vbce.com
Webmasters - feel free to link to
VBCE.com - Premier Website for Visual Basic/CE Development

Buy Books!