Microsoft KB Archive/255621: Difference between revisions
From BetaArchive Wiki
(importing KB archive) |
m (Text replacement - """ to """) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 45: | Line 45: | ||
== SUMMARY == | == SUMMARY == | ||
A Microsoft Foundation Classes (MFC) '''CRichEditCtrl''' class can be used as a source of data for the '''PR_RTF_COMPRESSED''' property of an Extended MAPI message. The sample code in the | A Microsoft Foundation Classes (MFC) '''CRichEditCtrl''' class can be used as a source of data for the '''PR_RTF_COMPRESSED''' property of an Extended MAPI message. The sample code in the "More Information" section of this article demonstrates one way to write the RTF stream out from the control into the property. | ||
</div> | </div> | ||
Line 74: | Line 74: | ||
ASSERT(pCookie); | ASSERT(pCookie); | ||
LPSTREAM stmData = pCookie- | LPSTREAM stmData = pCookie->m_pData; | ||
DWORD dw = 0; | DWORD dw = 0; | ||
ULONG cbWritten; | ULONG cbWritten; | ||
hRes = stmData- | hRes = stmData->Write(pbBuff,cb,&cbWritten); | ||
//TODO: Check hRes and complain appropriately if not S_OK | //TODO: Check hRes and complain appropriately if not S_OK | ||
Line 94: | Line 94: | ||
LPSTREAM lpStmUncompressed = NULL; | LPSTREAM lpStmUncompressed = NULL; | ||
hRes = m_lpMessage- | hRes = m_lpMessage->OpenProperty( PR_RTF_COMPRESSED, | ||
& | &IID_IStream, | ||
STGM_WRITE | STGM_DIRECT, | STGM_WRITE | STGM_DIRECT, | ||
MAPI_CREATE | MAPI_MODIFY, | MAPI_CREATE | MAPI_MODIFY, | ||
(LPUNKNOWN *)& | (LPUNKNOWN *)&lpStm); | ||
if (SUCCEEDED(hRes)) | if (SUCCEEDED(hRes)) | ||
{ | { | ||
hRes = WrapCompressedRTFStream(lpStm, MAPI_MODIFY, | hRes = WrapCompressedRTFStream(lpStm, MAPI_MODIFY, | ||
& | &lpStmUncompressed); | ||
} | } | ||
Line 111: | Line 111: | ||
EDITSTREAM es = {0, 0, EditStreamCallBack}; | EDITSTREAM es = {0, 0, EditStreamCallBack}; | ||
MyRichEditCookie cookie(lpStmUncompressed); | MyRichEditCookie cookie(lpStmUncompressed); | ||
es.dwCookie = (DWORD)& | es.dwCookie = (DWORD)&cookie; | ||
UINT uFormat = SF_RTFNOOBJS; | UINT uFormat = SF_RTFNOOBJS; | ||
cb = m_RichEditCtrl.StreamOut(uFormat,es); | cb = m_RichEditCtrl.StreamOut(uFormat,es); | ||
hRes = lpStmUncompressed- | hRes = lpStmUncompressed->Commit(STGC_DEFAULT); | ||
} | } | ||
if (SUCCEEDED(hRes)) | if (SUCCEEDED(hRes)) | ||
{ | { | ||
hRes = m_lpMessage- | hRes = m_lpMessage->SaveChanges(KEEP_OPEN_READWRITE); | ||
} | } | ||
//TODO: Check hRes and complain appropriately if not S_OK | //TODO: Check hRes and complain appropriately if not S_OK | ||
if (lpStm) lpStm- | if (lpStm) lpStm->Release(); | ||
if (lpStmUncompressed) lpStmUncompressed- | if (lpStmUncompressed) lpStmUncompressed->Release(); | ||
} | } |
Latest revision as of 13:53, 21 July 2020
Article ID: 255621
Article Last Modified on 8/25/2005
APPLIES TO
- Microsoft Messaging Application Programming Interface
- Microsoft Visual C++ 6.0 Service Pack 5
This article was previously published under Q255621
SUMMARY
A Microsoft Foundation Classes (MFC) CRichEditCtrl class can be used as a source of data for the PR_RTF_COMPRESSED property of an Extended MAPI message. The sample code in the "More Information" section of this article demonstrates one way to write the RTF stream out from the control into the property.
MORE INFORMATION
//This code assumes that m_lpMessage is a class level variable //pointing to an existing MAPI message. class MyRichEditCookie { public: LPSTREAM m_pData; MyRichEditCookie(LPSTREAM pData ) { m_pData=pData; } }; static DWORD CALLBACK EditStreamCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { HRESULT hRes = S_OK; ASSERT(pbBuff); ASSERT(pcb); MyRichEditCookie * pCookie = (MyRichEditCookie *)dwCookie; ASSERT(pCookie); LPSTREAM stmData = pCookie->m_pData; DWORD dw = 0; ULONG cbWritten; hRes = stmData->Write(pbBuff,cb,&cbWritten); //TODO: Check hRes and complain appropriately if not S_OK *pcb = cbWritten; return dw; } void CRichEdDlg::OnCommit() { HRESULT hRes = S_OK; LPSTREAM lpStm = NULL; LPSTREAM lpStmUncompressed = NULL; hRes = m_lpMessage->OpenProperty( PR_RTF_COMPRESSED, &IID_IStream, STGM_WRITE | STGM_DIRECT, MAPI_CREATE | MAPI_MODIFY, (LPUNKNOWN *)&lpStm); if (SUCCEEDED(hRes)) { hRes = WrapCompressedRTFStream(lpStm, MAPI_MODIFY, &lpStmUncompressed); } if (SUCCEEDED(hRes)) { LONG cb; EDITSTREAM es = {0, 0, EditStreamCallBack}; MyRichEditCookie cookie(lpStmUncompressed); es.dwCookie = (DWORD)&cookie; UINT uFormat = SF_RTFNOOBJS; cb = m_RichEditCtrl.StreamOut(uFormat,es); hRes = lpStmUncompressed->Commit(STGC_DEFAULT); } if (SUCCEEDED(hRes)) { hRes = m_lpMessage->SaveChanges(KEEP_OPEN_READWRITE); } //TODO: Check hRes and complain appropriately if not S_OK if (lpStm) lpStm->Release(); if (lpStmUncompressed) lpStmUncompressed->Release(); }
Keywords: kbhowto kbmsg KB255621