Share via


Outlook 2010 MAPI Samples

I’ve updated the Outlook MAPI Samples and posted a new project up on Codeplex: Outlook 2010 MAPI Samples. We’ll get the MSDN updated to point at these samples soon. The goal of this update, of course, was to get these samples working with Outlook 2010, especially in 64 bit mode. Most of the changes were minor, swapping ULONG for ULONG_PTR, etc., but  I did have to make a couple big changes:

  • None of the samples link to mapi32.lib anymore. I talked about this already. This was actually easier to do than I expected. I just copied my ImportProc files from MFCMAPI and tweaked them a bit.
  • The other major change was removing the Exchange Client Extension from Wrapped PST. The extension never had anything to do with the sample. It was just used as a convenient way to drive a test function to illustrate the replication API. I replaced the whole thing with an exported function and a simple VBA macro used to call the function. You’ll find the macro in the file TestMacro.txt

I’m sure there are bugs in these samples. I didn’t get to test every possible scenario. So feedback is welcome – see the Help/Feedback section of the main page.

Comments

  • Anonymous
    August 20, 2009
    Not sure where to ask this, so bare with me if this is the wrong place. We have a solution that is using MAPI to extract data from Exchange 2003/2007 and works well with the ExchangeCdo.EXE download from MS. But testing with this against Exchange 2010 give me a "The information store could not be opened" exception. Installing Outlook 2003 or 2007 helps, but is not a doable solution. Any advice on this ? Regards, Thomas

  • Anonymous
    August 20, 2009
    The problem is with how your profile is configured. Exchange 2010 is gonna need some special tweaks in the profile to connect from the MAPI download. Dave Vespa is the guy you wanna talk to: http://blogs.msdn.com/dvespa/archive/2009/08/18/exchange-2010-rc-has-been-released.aspx

  • Anonymous
    October 05, 2009
    Hi. Thanks for the help on the earlier request. Dave Vespa does not allow comments/questions, so I will try here once again. To summarize: I use the ExchangeCdo.EXE download from MS to connect to Exchange 2010 RC and get the following error I got the profile to work easily, but get following error after a while. Mapi session "/o=First Organization/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=DEV-EXCH2K10/cn=Microsoft System Attendant" exceeded the maximum of 250 objects of type "objtMessage". No issues with Exchange 2003/2007. Looked at the code a LONG time, but it seems to release ok, this occurs when looping through a collection of messages. Any advice? Regards, Thomas

  • Anonymous
    October 05, 2009
    If any help I just noticed that an error just prior to other one is: /o=First Organization/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=DEV-EXCH2K10/cn=Microsoft System Attendant   250   objtStream The streams ARE released in the code. I think these streams could be the one that keeps the messages open as well. Regards, Thomas

  • Anonymous
    October 06, 2009
    Hi. To summarize: I use the ExchangeCdo.EXE download from MS to connect to Exchange 2010 RC. I think I have isolated the code that will make the prior issue to fail. Looping through a large collection of messages and referencing the attachment table on each message, will make the code fail with 0x80004005, even with a proper release of IMAPITable. My code: #include "stdafx.h" #include <afxwin.h> #include <edk.h> int _tmain(int argc, _TCHAR* argv[]) {    LPMAPISESSION pSession = NULL; HRESULT hr = S_OK;         //Initialize MAPI libraries. First step on MAPI Programming         hr = MAPIInitialize (NULL); char lpProfileName[] = "DEVTG"; //LPTSTR lpProfileName = "DEVTG";         // logon to MAPI for enumerating emails from inbox. This can also be used to open the public folders, if one has access.         hr = MAPILogonEx (NULL, (LPTSTR)lpProfileName, NULL, MAPI_EXTENDED| MAPI_NEW_SESSION| MAPI_LOGON_UI| MAPI_EXPLICIT_PROFILE,&pSession);         if (FAILED (hr))           return E_FAIL;        // Find default message store using HRMAPI function        ULONG cbDefStoreEntryid = 0;        LPENTRYID pDefStoreEntryid = NULL;        hr = HrMAPIFindDefaultMsgStore(pSession, &cbDefStoreEntryid, &pDefStoreEntryid);        if (FAILED (hr))            return E_FAIL;       // open the MAPI Public Folder tree       LPMDB pDefaultMsgStore = NULL;       hr = pSession->OpenMsgStore(0, cbDefStoreEntryid, pDefStoreEntryid, NULL,                     MDB_WRITE | MAPI_DEFERRED_ERRORS, &pDefaultMsgStore );       if (FAILED (hr))             return E_FAIL;       DWORD cbeid = 0;       LPENTRYID lpeid = NULL;       LPMAPIFOLDER pFolder = NULL;       ULONG ulObjType = 0;       //Path to the inbox       CString l_strFullPath = "@PR_IPM_SUBTREE_ENTRYID\Inbox&quot;;       //Used to filter the columns for enumerating emails using MAPI       SizedSPropTagArray ( 2, rgPropTag ) =       {            2,            {                  PR_ENTRYID, // its unique across directory                  PR_SUBJECT            }        };        // Open the Inbox folder        hr = HrMAPIOpenFolderEx(pDefaultMsgStore,  '', (LPCTSTR)l_strFullPath, &pFolder);        if (FAILED (hr))            return E_FAIL;        LPMAPITABLE lpMapiTbl = NULL;        //Enumerate emails using MAPI in C++        hr = pFolder->GetContentsTable(0, &lpMapiTbl);        if (FAILED (hr))           return E_FAIL;        // Get count rows        ULONG ulRows = 0;        hr = lpMapiTbl->GetRowCount(0, &ulRows);        if (FAILED (hr))            return E_FAIL;        hr = lpMapiTbl->SetColumns((LPSPropTagArray)&rgPropTag, 0 );        if (FAILED (hr)) return E_FAIL;        // Get all rows        SRowSet * pRows = NULL;        hr = HrQueryAllRows(lpMapiTbl,NULL, NULL, NULL, ulRows,&pRows);        if (FAILED (hr)) return E_FAIL;       printf("Total Number of messages : %dn",pRows->cRows);       for(int i=0;i<pRows->cRows;i++)       {          if(PR_ENTRYID == pRows -> aRow[i].lpProps[0].ulPropTag)          { printf("Opening message : %dn",i);               LPUNKNOWN pMessage; ULONG ulObjType = 0; // Open the target message                hr = pFolder->OpenEntry(pRows -> aRow[i].lpProps[0].Value.bin.cb,                    (LPENTRYID) pRows -> aRow[i].lpProps[0].Value.bin.lpb,                    NULL,                    MAPI_BEST_ACCESS,                    &ulObjType,                    &pMessage); if (FAILED (hr)) { DWORD iLastError = GetLastError(); printf("Opening message failed : %xn",hr); return E_FAIL; } LPMAPITABLE pAttachTbl = NULL; /* UNCOMMENT THE NEXT 2 LINE TO MAKE THE LOOP FAIL*/ hr = ((LPMESSAGE) pMessage)->GetAttachmentTable(0, &pAttachTbl); if (FAILED(hr)) throw -1; if (pAttachTbl) pAttachTbl->Release(); if (pMessage)   pMessage->Release();  }   }       //Release all the resources used       if (lpMapiTbl)          lpMapiTbl->Release();       if (pRows)          FreeProws(pRows);       if(pFolder)          pFolder->Release();       if(pDefaultMsgStore)          pDefaultMsgStore->Release();       MAPIFreeBuffer (lpeid);       pFolder = NULL;       //Free all MAPI libraries       MAPIUninitialize(); return 0; }

  • Anonymous
    December 02, 2009
    The comment has been removed

  • Anonymous
    December 02, 2009
    I tested them with a build of 2010, but it may have been an early build. I'll check it out and update them as needed. Thanks!

  • Anonymous
    December 03, 2009
    I fixed it. Thanks for the report.