Microsoft KB Archive/252649: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
(2 intermediate revisions by the same user not shown)
Line 46: Line 46:
== SUMMARY ==
== SUMMARY ==


When you work with CDO using Microsoft Visual C++, it may sometimes be necessary to switch over to MAPI. The code in the "More Information" section shows how to take a message in CDO and open that same message in MAPI.
When you work with CDO using Microsoft Visual C++, it may sometimes be necessary to switch over to MAPI. The code in the "More Information" section shows how to take a message in CDO and open that same message in MAPI.


</div>
</div>
Line 54: Line 54:


<pre class="codesample">//This code assumes that CDO has been imported with the following statement
<pre class="codesample">//This code assumes that CDO has been imported with the following statement
//#import &quot;cdo.dll&quot; no_namespace
//#import "cdo.dll" no_namespace
//and that we have a MAPI session opened with the same profile as the CDO session.
//and that we have a MAPI session opened with the same profile as the CDO session.
HRESULT OpenMAPIMessageFromCDOMessage(
HRESULT OpenMAPIMessageFromCDOMessage(
Line 68: Line 68:


     //Find CDO's StoreID
     //Find CDO's StoreID
     bstr_t szStoreEID = pCDOMessage-&gt;StoreID;
     bstr_t szStoreEID = pCDOMessage->StoreID;


     //Convert the StoreID to a byte array for OpenMsgStore
     //Convert the StoreID to a byte array for OpenMsgStore
     cbSEID = strlen(szStoreEID)/2;
     cbSEID = strlen(szStoreEID)/2;
     hRes = MAPIAllocateBuffer(cbSEID, (void **)&amp;pbSEID);
     hRes = MAPIAllocateBuffer(cbSEID, (void **)&pbSEID);
     FBinFromHex(szStoreEID, (LPBYTE)pbSEID);
     FBinFromHex(szStoreEID, (LPBYTE)pbSEID);


     hRes = lpMAPISession-&gt;OpenMsgStore(
     hRes = lpMAPISession->OpenMsgStore(
         0,
         0,
         cbSEID,
         cbSEID,
Line 81: Line 81:
         0,
         0,
         MAPI_BEST_ACCESS,
         MAPI_BEST_ACCESS,
         &amp;lpMDB);
         &lpMDB);
     MAPIFreeBuffer(pbSEID);
     MAPIFreeBuffer(pbSEID);
     if (FAILED(hRes)) return hRes;
     if (FAILED(hRes)) return hRes;


     _variant_t lClass = pMessage-&gt;Class;
     _variant_t lClass = pMessage->Class;


     //Find the CDO message's Entry ID
     //Find the CDO message's Entry ID
Line 92: Line 92:
     {
     {
         //CDO tacks on 80 extra bytes to appointment item IDs. Skip them.
         //CDO tacks on 80 extra bytes to appointment item IDs. Skip them.
         szEID = ((char *)(bstr_t)pMessage-&gt;ID)+80;
         szEID = ((char *)(bstr_t)pMessage->ID)+80;
     }
     }
     else  
     else  
     {
     {
         szEID = pCDOMessage-&gt;ID;
         szEID = pCDOMessage->ID;
     }
     }


     //Convert the ID to a byte array for OpenMsgStore
     //Convert the ID to a byte array for OpenMsgStore
     cbEID = strlen(szEID)/2;
     cbEID = strlen(szEID)/2;
     hRes = MAPIAllocateBuffer(cbEID, (void **)&amp;pbEID);
     hRes = MAPIAllocateBuffer(cbEID, (void **)&pbEID);
     FBinFromHex(szEID, (LPBYTE) pbEID);
     FBinFromHex(szEID, (LPBYTE) pbEID);


     hRes = lpMDB-&gt;OpenEntry(
     hRes = lpMDB->OpenEntry(
         cbEID,
         cbEID,
         pbEID,
         pbEID,
         0,
         0,
         MAPI_BEST_ACCESS,
         MAPI_BEST_ACCESS,
         &amp;lpObjType,
         &lpObjType,
         (LPUNKNOWN *) lppMessage);
         (LPUNKNOWN *) lppMessage);
     MAPIFreeBuffer(pbEID);
     MAPIFreeBuffer(pbEID);
     if (FAILED(hRes)) return hRes;
     if (FAILED(hRes)) return hRes;


     if (lpMDB) lpMDB-&gt;Release();
     if (lpMDB) lpMDB->Release();
     return hRes;
     return hRes;
}
}

Latest revision as of 13:51, 21 July 2020

Knowledge Base


How To Open a MAPI IMessage Interface with CDO Entry ID

Article ID: 252649

Article Last Modified on 8/25/2005



APPLIES TO

  • Microsoft Messaging Application Programming Interface
  • Microsoft Collaboration Data Objects 1.2
  • Microsoft Collaboration Data Objects 1.21



This article was previously published under Q252649

SUMMARY

When you work with CDO using Microsoft Visual C++, it may sometimes be necessary to switch over to MAPI. The code in the "More Information" section shows how to take a message in CDO and open that same message in MAPI.

MORE INFORMATION

//This code assumes that CDO has been imported with the following statement
//#import "cdo.dll" no_namespace
//and that we have a MAPI session opened with the same profile as the CDO session.
HRESULT OpenMAPIMessageFromCDOMessage(
    LPMAPISESSION lpMAPISession,
    MessagePtr pCDOMessage,
    LPMESSAGE* lppMessage)
{
    HRESULT hRes = S_OK;
    int cbSEID;
    LPENTRYID pbSEID;
    int cbEID;
    LPENTRYID pbEID;

    //Find CDO's StoreID
    bstr_t szStoreEID = pCDOMessage->StoreID;

    //Convert the StoreID to a byte array for OpenMsgStore
    cbSEID = strlen(szStoreEID)/2;
    hRes = MAPIAllocateBuffer(cbSEID, (void **)&pbSEID);
    FBinFromHex(szStoreEID, (LPBYTE)pbSEID);

    hRes = lpMAPISession->OpenMsgStore(
        0,
        cbSEID,
        pbSEID,
        0,
        MAPI_BEST_ACCESS,
        &lpMDB);
    MAPIFreeBuffer(pbSEID);
    if (FAILED(hRes)) return hRes;

    _variant_t lClass = pMessage->Class;

    //Find the CDO message's Entry ID
    bstr_t szEID
    if ((LONG) lClass == 26)//that is, we have an appointment item
    {
        //CDO tacks on 80 extra bytes to appointment item IDs. Skip them.
        szEID = ((char *)(bstr_t)pMessage->ID)+80;
    }
    else 
    {
        szEID = pCDOMessage->ID;
    }

    //Convert the ID to a byte array for OpenMsgStore
    cbEID = strlen(szEID)/2;
    hRes = MAPIAllocateBuffer(cbEID, (void **)&pbEID);
    FBinFromHex(szEID, (LPBYTE) pbEID);

    hRes = lpMDB->OpenEntry(
        cbEID,
        pbEID,
        0,
        MAPI_BEST_ACCESS,
        &lpObjType,
        (LPUNKNOWN *) lppMessage);
    MAPIFreeBuffer(pbEID);
    if (FAILED(hRes)) return hRes;

    if (lpMDB) lpMDB->Release();
    return hRes;
}
                

Keywords: kbhowto kbmsg KB252649