As mentioned in the http://support.microsoft.com/kb/266353, programmatically reading MAPI properties by using APIs such as Extended MAPI the PropertyAccessor object in the Microsoft Office Outlook 2007 object model is supported.Here's how we do it in C++.#pragma warning(disable:4146)
#import "C:\Windows\System32\stdole2.tlb" rename_namespace("Outlook")#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll" rename_namespace("Outlook")#import "C:\Program Files\Microsoft Office\OFFICE12\msoutl.olb" rename_namespace("Outlook")
#pragma warning(default:4146)
#include <stdio.h>#include <tchar.h>
using namespace Outlook;
struct StartOle{ StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }}_inst_StartOle;
void dump_com_error(_com_error &e){ _tprintf(_T("Oops - hit an error!\n")); _tprintf(_T("\a\tCode = %08lx\n"), e.Error()); _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage()); _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource); _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);}
void main(int argc, char* argv[]){ try { _ApplicationPtr pApp("Outlook.Application"); _NameSpacePtr pNameSpace; pNameSpace = pApp->GetNamespace(L"MAPI");
MAPIFolderPtr pAppointmentMAPIFolder; pAppointmentMAPIFolder = pNameSpace->GetDefaultFolder(olFolderCalendar);
_ItemsPtr pItems; _AppointmentItemPtr pAppointmentItem;
pItems = pAppointmentMAPIFolder->GetItems();
printf("No of items : %d\n", pItems->Count);
pAppointmentItem = pItems->GetFirst();
/* The following code uses GetPropertyAccessor: gets the user property WORKS */
_PropertyAccessorPtr pPropAccPtr; pPropAccPtr = pAppointmentItem->GetPropertyAccessor(); _variant_t var; var = pPropAccPtr->GetProperty(L"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-c000-000000000046}/SomeID");
/* The following code uses GetUserProperties: does not get the user property DOES NOT WORK */
//UserPropertiesPtr pUP; //pUP = pAppointmentItem->GetUserProperties(); //UserPropertyPtr uPP = pUP->Item(L"SomeID"); //_variant_t var; //var = pPropAccPtr->GetProperty(L"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-c000-000000000046}/SomeID"); //var = uPP->GetValue(); } catch(_com_error &e) { dump_com_error(e); }}