Loading Message from within ADO Stream Objects
To load a serialized message into a Microsoft Collaboration Data Objects (CDO) Message object from within a Microsoft® ActiveX® Data Object (ADO) Stream object, perform the following steps:
- Retrieve the IDataSource interface on the Message object.
- Create or otherwise obtain a _Stream object reference on an ADO Stream object.
- Using the IDataSource interface on the Message object, call the OpenObject method, passing the _Stream object reference as the first argument, and the string "_Stream" as the second.
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Function LoadMessageFromFile(Path As String) As Message
Dim Stm As New Stream
Stm.Open
Stm.LoadFromFile Path
Dim iMsg As New CDO.Message
Dim iDsrc As IDataSource
Set iDsrc = iMsg
iDsrc.OpenObject Stm, "_Stream"
Set LoadMessageFromFile = iMsg
End Function
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
// ...
IMessagePtr Load_Message_from_File(_bstr_t path)
{
/*
** This example shows a common use of the ADO Stream
** object with CDO, namely, opening a serialized
** message from a file on disk and loading it into
** a CDO Message object.
**/
_StreamPtr pStm(__uuidof(Stream));
_variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
try {
pStm->raw_Open(varOptional, adModeUnknown, adOpenStreamUnspecified,NULL,NULL);
pStm->LoadFromFile(path);
}
catch(_com_error e)
{
throw e;
}
IMessagePtr iMsg(__uuidof(Message));
IDataSourcePtr iDsrc;
iDsrc = iMsg;
try {
iDsrc->OpenObject(pStm,_bstr_t("_Stream"));
}
catch(_com_error e)
{
throw e;
}
// ....
return iMsg;
}
Function LoadMessageFromFile(Path)
Dim Stm
Set Stm = CreateObject("ADODB.Stream")
Stm.Open
Stm.LoadFromFile Path
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iDsrc
Set iDsrc = iMsg.DataSource
iDsrc.OpenObject Stm, "_Stream"
Set LoadMessageFromFile = iMsg
End Function