Thng tin: Lu tin nh?n vo MSG Compound File

D?ch tiu ? D?ch tiu ?
ID c?a bi: 171907 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?


Bi vi?t ny ch?a m? ch?ng t? lm th? no ? lu m?t th ?n m?t ti li?u h?p ch?t--?c bi?t .msg t?p-- l c th? ?c ?c b?ng b?t k? khch hng c h? tr? cc ?nh d?ng t?p tin .msg.


Ch?c nng d?i y s? a m?t ?i t?ng h?p l? th nh m?t tham s? trong v s? d?ng thu?c tnh c?a n ? t?o m?t b?n sao c?a tin nh?n v lu n vo m?t h?p ch?t t?p tin b?ng cch s? d?ng ?nh d?ng .msg. D?ng tiu ? c?a bi vi?t l ?c s? d?ng nh l tn t?p tin c?a cc t?p tin m?i.

Lu ?: K? t? ?c bi?t trong d?ng ch? ? c?a cc tham s? trong ny ch?c nng c th? gy ra k?t qu? b?t ng?. Trong khi m? c th? ?c vi?t ? trnh k? t? ?c bi?t trong d?ng ch? ?, n khng ph?i l Gecman c?a ? ti v M? nh v?y c? ? tri ra ngoi.
#define INITGUID
#include <objbase.h>

#define USES_IID_IMessage

#include <mapix.h>
#include <mapitags.h>
#include <mapidefs.h>
#include <mapiutil.h>
#include <mapiguid.h>
#include <imessage.h>

// {00020D0B-0000-0000-C000-000000000046}
0x0000, 0x0000, 0xC0, 0x00, 0x0, 0x00, 0x0, 0x00, 0x00, 0x46);

    HRESULT hRes = S_OK;
    LPSPropValue pSubject = NULL;
    LPSTORAGE pStorage = NULL;
    LPMSGSESS pMsgSession =  NULL;
    SizedSPropTagArray ( 7, excludeTags );
    char szPath[_MAX_PATH];
    char strAttachmentFile[_MAX_PATH];
    LPWSTR lpWideCharStr = NULL;
    ULONG cbStrSize = 0L;

    // create the file name in the directory where "TMP" is defined
    // with subject as the filename and ".msg" extension.

    // get temp file directory
    GetTempPath(_MAX_PATH, szPath);

    // get subject line of message to copy. This will be used as the
    // new file name.
    HrGetOneProp( pMessage, PR_SUBJECT, &pSubject );

    // fuse path, subject, and suffix into one string
    strcpy ( strAttachmentFile, szPath );
    strcat ( strAttachmentFile, pSubject->Value.lpszA  );
    strcat ( strAttachmentFile, ".msg");

    // get memory allocation function
    LPMALLOC pMalloc = MAPIGetDefaultMalloc();

    // Convert new file name to WideChar
    cbStrSize = MultiByteToWideChar (CP_ACP,
                                     -1, lpWideCharStr, 0);

    MAPIAllocateBuffer ( cbStrSize * sizeof(WCHAR),
                            (LPVOID *)&lpWideCharStr );

    MultiByteToWideChar (CP_ACP,
                         -1, lpWideCharStr, cbStrSize );

    // create compound file
    hRes = ::StgCreateDocfile(lpWideCharStr,
                              STGM_READWRITE |
                              STGM_TRANSACTED |
                              STGM_CREATE, 0, &pStorage);

    // Open an IMessage session.
    hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession);

    // Open an IMessage interface on an IStorage object
    hRes = ::OpenIMsgOnIStg(pMsgSession,
                            NULL, 0, 0, &pIMsg);

    // write the CLSID to the IStorage instance - pStorage. This will
    // only work with clients that support this compound document type
    // as the storage medium. If the client does not support
    // CLSID_MailMessage as the compound document, you will have to use
    // the CLSID that it does support.
    hRes = WriteClassStg(pStorage, CLSID_MailMessage );

    // Specify properties to exclude in the copy operation. These are
    // the properties that Exchange excludes to save bits and time.
    // Should not be necessary to exclude these, but speeds the process
    // when a lot of messages are being copied.
    excludeTags.cValues = 7;
    excludeTags.aulPropTag[0] = PR_ACCESS;
    excludeTags.aulPropTag[1] = PR_BODY;
    excludeTags.aulPropTag[2] = PR_RTF_SYNC_BODY_COUNT;
    excludeTags.aulPropTag[3] = PR_RTF_SYNC_BODY_CRC;
    excludeTags.aulPropTag[4] = PR_RTF_SYNC_BODY_TAG;
    excludeTags.aulPropTag[5] = PR_RTF_SYNC_PREFIX_COUNT;
    excludeTags.aulPropTag[6] = PR_RTF_SYNC_TRAILING_COUNT;

    // copy message properties to IMessage object opened on top of
    // IStorage.
    hRes = pMessage->CopyTo(0, NULL,
                            NULL, NULL,
                            pIMsg, 0, NULL );

    // save changes to IMessage object.
    pIMsg -> SaveChanges ( KEEP_OPEN_READWRITE );

    // save changes in storage of new doc file
    hRes = pStorage -> Commit(STGC_DEFAULT);

    // free objects and clean up memory
    MAPIFreeBuffer ( lpWideCharStr );
    CloseIMsgSession ( pMsgSession );

    pStorage = NULL;
    pIMsg = NULL;
    pMsgSession = NULL;
    lpWideCharStr = NULL;

    return hRes;
T?t c? cc phin b?n c?a Outlook v Exchange khch hng h? tr? CLSID_MailMessage nh cc ti li?u h?p ch?t. L? do duy nh?t ? s? d?ng m?t CLSID khc nhau l ? h? tr? khch hng khc m s? d?ng m?t CLISD khc nhau khi b?n vi?t th ? lu tr? c c?u trc.

Khi lu thng i?p c m?t s? l?n cc ni nh?n ny ho?c t?p tin nh km, c th? thao tc CopyTo s? khng thnh cng v?i MAPI_E_NOT_ENOUGH_MEMORY. Nguyn nhn l do m?t v?n ? ?c bi?t ?n v?i lu tr? c c?u trc v su?i. M?i khi m?t t?p tin nh km m?i ho?c nh?n thm vo tin nh?n ?c lu trong lu tr? c c?u trc, m?t t?p g?c lu tr? m?i ?c m? ra. Nh?ng t?p tin ny khng ?c ng c?a cho ?n khi giao d?ch ?c hon t?t. B?i v? h? i?u hnh p ?t m?t gi?i h?n v? s? l?ng ?ng th?i m? g?c lu tr? t?p, khng c khng c workaround ?c bi?t ?n. ? bi?t thm chi ti?t, b?m vo s? bi vi?t d?i y ? xem bi vi?t trong c s? ki?n th?c Microsoft:
163202 Gi?i h?n s? l?ng Simultaeously m? g?c lu tr? t?p
T?t c? cc phin b?n c?a Outlook s? b? ?nh h?ng b?i s? h?n ch? ny l t?t.

Thu?c tnh

ID c?a bi: 171907 - L?n xem xt sau cng: 19 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Office Outlook 2007
  • Microsoft Messaging Application Programming Interface
T? kha:
kbinfo kbmsg kbmt KB171907 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:171907

Cung cp Phan hi


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from