Platform SDK: Exchange 2000 Server

SaveToObject Method

[This is preliminary documentation and subject to change.]

Binds to and saves data into the specified object.

[Visual Basic,VBScript]
Sub SaveToObject(Source as Object, InterfaceName as String)
[C++]
HRESULT SaveToObject(IUnknown* Source , BSTR InterfaceName);
[IDL]
HRESULT SaveToObject(IUnknown* Source , BSTR InterfaceName);
Source
A reference to the object in which to save.
InterfaceName
A string indicating the type of interface passed in the first argument.

Remarks

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

One example use of SaveToObject is for 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 wished to save changes you make to the message data into the embedded location, call IDataSource.Save, and the modified message contents would be 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 IDataSource.Source is the object reference passed to the method. Avoid passing interfaces that are not OLE Automation compatible such as IStream if languages such as Visual Basic, Microsoft J++, and VBScript will attempt to access the bound source object through the Source property. In such cases, the object reference returned by the Source property would 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.

Example

[Visual Basic]
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 embeddes the message in the MIME
  ' hierarchy with content-type="message/rfc822"

  iDsrc.SaveToObject iBp, "IBodyPart"

End Sub
[C++,IDL]
HRESULT EmbedMessage(IBodyPart* pBp, IMessage* pMsg) {

  if(pBp == NULL || pMsg == NULL)
    return E_POINTER;

  HRESULT hr = S_OK;
  IDataSource* pDsrc = NULL;
  
  hr = pMsg->QueryInterface(__uuidof(IDataSource),(void**)&pDsrc);

  return pDsrc->SaveToObject(pBp, _bstr_t("IBodyPart"));
  
}
[VBScript]
Sub EmbedMessageIntoBodyPart(iBp, iMsg)

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

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

  iDsrc.SaveToObject iBp, "IBodyPart"

End Sub