SaveToObject Method

Topic Last Modified: 2006-06-13

Binds to and saves data into the specified object.

Applies To

IDataSource Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

Sub SaveToObject(    Source As Object,
        InterfaceName As String)
HRESULT SaveToObject
(
        Object* Source,
        BSTR InterfaceName
);

Parameters

  • Source
    A reference to the object in which to save.
  • InterfaceName
    A string indicating the type of interface passed in the first argument.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

Implementations of this method are intended to allow you to easily save data into another object at run time, rather that from a particular store or database.

A sample use for SaveToObject is embedding messages into other messages. To embed a message, call IDataSource.SaveToObject passing the IBodyPart interface on a BodyPart object that is to contain the embedded message. If you subsequently want to save changes you make to the message data into the embedded location, call Save Method, and the modified message contents are saved back to the bound BodyPart object.

Note

Circular binding is not supported. You cannot use SaveToObject to bind the same object, such as:

Set iDsrc = iSomeInterface
iDsrc.SaveToObject iSomeInterface, "ISomeInterface"

If circular binding is attempted, the CDO_E_SELF_BINDING exception is raised.

After a successful binding, the Source Property is the object reference passed to the method. Avoid passing interfaces that are not OLE Automation compatible, such as Istream, if languages such as Microsoft® Visual Basic®, Microsoft Visual J++®, and Visual Basic Scripting Edition (VBScript) will attempt to access the bound source object through the Source property. If you pass interfaces that are not OLE Automation compatible, the object reference returned by the Source property will be unusable by these languages.

If the string passed as the interface type name (the InterfaceName parameter) is not recognized, the method must raise an exception.

Examples


Sub EmbedMessageIntoBodyPart(iBp As CDO.IBodyPart, iMsg As CDO.message)

  Dim iDsrc As CDO.IDataSource
  Set iDsrc = iMsg ' get IDataSource interface

  ' Save the message to the BodyPart object.
  ' This embeds the message in the MIME
  ' hierarchy with content-type="message/rfc822"

  iDsrc.SaveToObject iBp, "IBodyPart"

End Sub



/*
 You must have the following paths in your
 INCLUDE path.
 %CommonProgramFiles%\system\ado
 %CommonProgramFiles%\microsoft shared\cdo

*/
#ifndef _CORE_EXAMPLE_HEADERS_INCLUDED
#define _CORE_EXAMPLE_HEADERS_INCLUDED
#import <msado15.dll> no_namespace
#import <cdoex.dll> no_namespace
#include <iostream.h>
#endif

void EmbedMessage(IBodyPartPtr pBp, IMessagePtr pMsg) {

  if(pBp == NULL || pMsg == NULL)
    throw _com_error(E_POINTER);

  IDataSourcePtr pDsrc;
  try {
     pDsrc = pMsg;
     pDsrc->SaveToObject(pBp,_bstr_t("IBodyPart"));
  }
  catch(_com_error e) {
   cerr << "Error embedding message!" << endl;
   throw e;
  }
}


Sub EmbedMessageIntoBodyPart(iBp, iMsg)

  Dim iDsrc
  Set iDsrc = iMsg.DataSource ' get IDataSource interface

  ' Save the message to the BodyPart object.
  ' This embeds the message in the MIME
  ' hierarchy with content-type="message/rfc822"

  iDsrc.SaveToObject iBp, "IBodyPart"

End Sub