Discussion Locked

Accessing outlook through C or Java

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How can I read the outlook.pst file from a C or Java programs to extract the contacts, tasks etc information.

1 reply

by australian fun

Hello,

Honestly, I do not know how you can access contacts or tasks directly from outlook.pst. Likely, you can not. Though, as far as I know, there is documented way to access all those items from C. Actually, it is not about C, but about COM. The following is the code snippet to do it using MFC.

_Application oApp;
_NameSpace mapi;
MAPIFolder folder;
_Items contacts;
_ContactItem contact;
CString name;

oApp.CreateDispatch (_T ("Outlook.Application"));
mapi = oApp.GetNamespace (_T("MAPI"));
folder = mapi.GetDefaultFolder (10); // olFolderContacts
contacts = folder.GetItems ();
for (long i = 1;
i < contacts.GetCount (); i++) {
contact = contacts.Item (COleVariant (i));
m_List.AddString (contact.GetFirstName ());
}

Perhaps, some comments are required.
I. Unfortunately, I could not find the constant olFolderContacts in header files, but (1) assume it is possible; (2) it is possible to find values through Visual Basic Editor's Object Browser.
II. Personally, I found it easier to write even C code from Visual Basic examples (that's essentially what I did).
III. In the MS KB Article "FILE: OFFAUTMN.EXE Discusses Office 97 and 2000 Automation and Provides Sample Code (Q253235)" you can find examples, written in pure C++. And of course, you can write the same in C. And definitely, my m_List.AddString () is not the only way of handling a contact, and GetFirstName() is not the only method of a contact :-)

As a conclusion, I can not provide a Javaexample, but as far as I know, there is a method of access COM from Java.

Good luck!

This discussion is closed to new replies.