Compartir a través de


OpenObject Method

Topic Last Modified: 2006-06-13

Binds to and opens data from the specified object.

Applies To

IDataSource Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

Function OpenObject(    Source As Object,
        InterfaceName As String)
HRESULT OpenObject
(
        Object* Source,
        BSTR InterfaceName
);

Parameters

  • Source
    A reference (interface) to the object to open.
  • 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 bind to and extract data from another object at run time, rather than from a particular store or database.

For example, you can use OpenObject for manipulation of encapsulated messages. A message can contain a body part for which the ContentMediaType Property is "message/rfc822". To extract the embedded message, you create a new Message object and call IDataSource.OpenObject, passing the IBodyPart reference on the BodyPart object containing the encapsulated message. This opens the contents of the encapsulated message into the new Message object. If you want to save changes to this message, back into the embedded location from where it was extracted, call Save Method and the modified message contents are saved back to the source body part.

Note

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

Set iDsrc = iSomeInterface
iDsrc.OpenObject 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


Function GetEmbeddedMessage(iBp As CDO.IBodyPart) As CDO.message

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

  ' open the body part object containing an embedded message
  iDsrc.OpenObject iBp, "IBodyPart"
  Set GetEmbeddedMessage = iMsg

End Function



/*
 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

IMessagePtr GetEmbeddedMessage(IBodyPartPtr pBp) {

   IDataSourcePtr pDsrc;
   if(pBp == NULL)
      throw _com_error(E_POINTER);
   pDsrc.CreateInstance(__uuidof(Message));

   /*
   * Open body part that contains message/rfc822 content
   */

   pDsrc->OpenObject(pBp, _bstr_t("IBodyPart"));
   IMessagePtr pMsg = pDsrc;

   return pMsg;
}


Function GetEmbeddedMessage(iBp)

  Dim iMsg
  Set iMsg = CreateObject("CDO.Message")
  Dim iDsrc
  Set iDsrc = iMsg.DataSource ' get IDataSource interface

  ' open the body part object containing an embedded message
  iDsrc.OpenObject iBp, "IBodyPart"
  Set GetEmbeddedMessage = iMsg

End Function