Loading Messages from Within ADO Stream Objects

Loading Messages from Within ADO Stream Objects

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.To load a serialized message into a Collaboration Data Objects (CDO) Message object from an ADO Stream object

  1. Retrieve the IDataSource interface on the Message object.
  2. Create or otherwise obtain a _Stream object reference on a Microsoft® ActiveX® Data Objects (ADO) Stream object.
  3. Use the IDataSource interface on the Message object to call OpenObject. Pass the _Stream object reference as the first argument, and the string "_Stream" as the second.

Visual Basic

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Server Library

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
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

C++, IDL

#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace

// Note: It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
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;
}

VBScript

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Function LoadMessageFromFile(Path) As Message
    Dim Stm
    Set Stm = CreateObject("ADODB.Stream")
    Stm.Open
    Stm.LoadFromFile Path
    Dim iMsg
    Set iMsg = CreateObject("CDO.Message")
    Dim iDsrc
    Set iDsrc = iMsg
    iDsrc.OpenObject Stm, "_Stream"
    Set LoadMessageFromFile = iMsg
End Function

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.