Platform SDK: CDO for Windows 2000 |
To save a serialized message from a Message object into a Microsoft® ActiveX® Data Objects (ADO) Stream object, perform the following steps:
' Reference to Microsoft ActiveX Data Objects 2.5 Library ' Reference to Microsoft CDO for Windows 2000 Library Sub SaveMessageToFile(iMsg As CDO.Message, Filepath As String) Dim Stm As New Stream Stm.Open Stm.Type = adTypeText Stm.Charset = "US-ASCII" Dim iDsrc As IDataSource Set iDsrc = iMsg iDsrc.SaveToObject Stm, "_Stream" Stm.SaveToFile Filepath, adSaveCreateOverWrite End Sub
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace #import <cdosys.dll> no_namespace // ... void Save_Message_to_File(IMessagePtr iMsg, bstr_t filename) { /* ** This example shows a common use of the ADO Stream ** object with CDO, namely, saving a serialized ** message to disk using an ADO Stream object. **/ _StreamPtr pStm(__uuidof(Stream)); IDataSourcePtr iDsrc; iDsrc = iMsg; _variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR); pStm->raw_Open(varOptional, adModeUnknown, adOpenStreamUnspecified,NULL,NULL); pStm->Type = adTypeText; pStm->Charset = "US-ASCII"; // apparently, we need this! try { iDsrc->SaveToObject(pStm,_bstr_t("_Stream")); } catch(_com_error error) { throw error; } try { pStm->SaveToFile(filename,adSaveCreateOverWrite); } catch(_com_error e) { throw e; } }
Sub SaveMessageToFile(iMsg, Filepath) Dim Stm Set Stm = CreateObject("ADODB.Stream") Stm.Type = adTypeText ' 2 Stm.Charset = "US-ASCII" Stm.Open Dim iDsrc Set iDsrc = iMsg.DataSource iDsrc.SaveToObject Stm, "_Stream" Stm.SaveToFile Filepath, adSaveCreateOverWrite End Sub