• Sign In
 
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...

  • Advanced search options...
  • Blog Home
  • About
  • Email Blog Author
  • Share this
  • RSS for posts
  • Atom
  • RSS for comments
  • CDO (20)
  • Code Snippet (42)
  • Custom Providers (15)
  • Debugging (7)
  • DevMsgTeam (268)
  • Documentation (96)
  • DST (8)
  • EWS (7)
  • Exchange (98)
  • Gotchas (89)
  • Hotfix (26)
  • MAPI (212)
  • MAPI Download (47)
  • MFCMAPI (87)
  • MSDN (49)
  • Non Dev (11)
  • OOM (17)
  • Outlook (154)
  • Outlook 2007 Auxiliary Reference (44)
  • Outlook Integration API (11)
  • Protocol Docs (20)
  • PST/OST (21)
  • Public Folders (3)
  • Vista (12)
  • WrapPST (14)
Links:
  • Download MFCMAPI
  • MFCMAPI on Facebook
  • Troubleshooting Outlook Crashes
  • Office Update Center
  • Developer Messaging Team Blog
This site is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.
Archives
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (1)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (4)
  • June 2011 (3)
  • May 2011 (3)
  • April 2011 (3)
  • March 2011 (5)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (4)
  • October 2010 (1)
  • September 2010 (3)
  • August 2010 (5)
  • July 2010 (3)
  • June 2010 (3)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (4)
  • September 2009 (5)
  • August 2009 (5)
  • July 2009 (11)
  • June 2009 (6)
  • May 2009 (5)
  • April 2009 (3)
  • March 2009 (18)
  • February 2009 (10)
  • January 2009 (3)
  • December 2008 (2)
  • November 2008 (2)
  • October 2008 (5)
  • September 2008 (4)
  • August 2008 (10)
  • July 2008 (6)
  • June 2008 (8)
  • May 2008 (2)
  • April 2008 (4)
  • March 2008 (2)
  • February 2008 (2)
  • January 2008 (5)
  • December 2007 (3)
  • November 2007 (2)
  • October 2007 (3)
  • September 2007 (1)
  • August 2007 (4)
  • July 2007 (5)
  • June 2007 (3)
  • May 2007 (4)
  • April 2007 (1)
  • March 2007 (6)
  • February 2007 (3)
  • January 2007 (2)
  • December 2006 (4)
  • November 2006 (3)
  • October 2006 (1)
  • August 2006 (1)
  • June 2006 (5)
  • May 2006 (5)
  • December 2005 (1)
  • November 2005 (4)
  • October 2005 (2)
  • September 2005 (1)
  • April 2005 (3)
  • December 2004 (2)
  • September 2004 (2)
  • August 2004 (3)
  • July 2004 (3)

You Mean You Want the OOM To Actually Work?

MSDN Blogs > SGriffin's MAPI Internals > You Mean You Want the OOM To Actually Work?

You Mean You Want the OOM To Actually Work?

Stephen Griffin - MSFT
3 Jul 2007 1:13 PM
  • Comments 2

We had a customer report recently that when he tried to fetch certain properties using the Outlook Object Model, all he got was garbage. This turned in to an interesting foray into the world of dual dispatch interfaces and VB.

The properties in question were these:

ContactItem: 
    Email1EntryID 
    Email2EntryID 
    Email3EntryID
MailItem: 
    ReceivedByEntryID 
    ReceivedOnBehalfOfEntryID

Note that all of them are entry IDs, but they're not the commonly used entry ID properties like EntryID or StoreID.

If you ask for one of these properties using VB/VBA, all you get is garbage:

    strEntryID = objContactItem.Email1EntryID
    Debug.Print strEntryID
    On Error Resume Next
    Set objRec = Application.Session.GetRecipientFromID(strEntryID)
    If objRec Is Nothing Then
        Debug.Print "GetRecipientFromID failed"
    Else
        Debug.Print objRec.name
        Debug.Print objRec.entryID
    End If

I'll spare you the C++ code, but suffice it to say that requesting this property via the IDispatch interface works.

What's going on? The key detail here is how Outlook builds the VARIANT property to return it. It doesn't use something like SAFEARRAY. It doesn't covert the entry ID from a binary format to a hex encoded string. Instead, it uses VT_BSTR, setting the number of bytes as the length prefix and the binary blob as the string.

This actually works, as long as you never copy the BSTR. And when you're fetching the property with C++, you can just pass the pointer around and treat it however you like. But not in VB. Any manipulation of the variant in VB, even assigning it to a variable, results in an implicit copy of the data. And the routines doing the copy think they're dealing with a NULL terminated string, so they truncate the binary blob at the first NULL.

Of course, I filed a bug on all this, but ultimately we had to reject it. The only way to fix this is to change the form of the data returned by the property, which would break all existing C++ code that uses the property. Maybe for a future version of Outlook we'll look at adding new properties to expose these entry IDs as hex encoded strings.

However, if you're using Outlook 2007, you have a workaround - the PropertyAccessor handles binary properties correctly. You just need to know what properties to fetch. The MailItem properties, ReceivedByEntryID and ReceivedOnBehalfOfEntryID are already documented as PR_RECEIVED_BY_ENTRYID and PR_RCVD_REPRESENTING_ENTRYID. The contact properties, like the other contact linking props I documented before, are named properties in the PSETID_Address namespace. Here they are (in C++ form):

#define dispidEmail1OriginalEntryID 0x8085
#define dispidEmail2OriginalEntryID 0x8095
#define dispidEmail3OriginalEntryID 0x80A5

And here's how you can use them from VB:

    Const dispidEmail1OriginalEntryID As String =
        "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/80850102"
    Set oPA = objContactItem.PropertyAccessor
    strEntryID = oPA.BinaryToString(oPA.GetProperty(dispidEmail1OriginalEntryID))
    Debug.Print strEntryID
    Set objRec = Application.Session.GetRecipientFromID(strEntryID)
    If objRec Is Nothing Then
        Debug.Print "GetRecipientFromID failed"
    Else
        Debug.Print objRec.name
        Debug.Print objRec.entryID
    End If
  • 2 Comments
Outlook, MAPI, Code Snippet, Gotchas, OOM, DevMsgTeam
Comments
  • Dmitry Streblechenko
    3 Jul 2007 2:25 PM

    Well, you fixed the same problem with the ConversationIndex property back in Outlook 2002 (?). These properties are not really different....

  • Stephen Griffin - MSFT
    14 Aug 2008 11:32 PM

    Jean-Yves points out that this practice of storing a binary in a BSTR is actually documented in the MSDN: http://thefiles.macadamian.com/2008/07/outlook-entry-ids-made-easy.html

    Nice catch!

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 7 and 8 and type the answer here:
  • Post
  • © 2012 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy Statement
  • Report Abuse
  • 5.6.131.143