Platform SDK: Exchange 2000 Server |
[This is preliminary documentation and subject to change.]
Binds to and opens data from the specified object.
[Visual Basic,VBScript] Sub OpenObject(ByVal Source as Object, ByVal InterfaceName as String) [C++] HRESULT OpenObject(IUnknown* Source, BSTR InterfaceName); [IDL] HRESULT OpenObject([in] IUnknown* Source, [in] BSTR InterfaceName);
Implementations of this method are intended to allow you to easily bind to and extract data from another object at runtime, rather that from a particular store or database.
One example use of OpenObject is 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 wished to save changes you make to this message back into the embedded location from whence it was extracted, call IDataSource.Save, and the modified message contents would be 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 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 Microsoft® Visual Basic®, Microsoft® Visual J++®, and Microsoft® Visual Basic® Scripting Edition (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.
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
HRESULT GetEmbeddedMessage(IBodyPart* pBp, IMessage** ppMsg) { HRESULT hr = S_OK; IDataSource* pDsrc = NULL; if(pBp == NULL) return hr = E_POINTER; hr = CoCreateInstance( __uuidof(Message), NULL, CLSCTX_INPROC_SERVER, __uuidof(IDataSource), reinterpret_cast<void**>(&pDsrc)); /* * Open body part that contains message/rfc822 content */ hr=pDsrc->OpenObject(pBp, _bstr_t("IBodyPart")); if(SUCCEEDED(hr)){ hr=pDsrc->QueryInterface(__uuidof(IMessage), reinterpret_cast<void**>(ppMsg)); if(FAILED(hr)) hr=E_UNEXPECTED; else hr=S_OK; } else hr=E_FAIL; pDsrc->Release(); return hr; }
Function GetEmbeddedMessage(iBp) Dim iMsg Set iMsg = CreateObject("CDO.Message") Dim iDsrc Set iDsrc = iMsg ' get IDataSource interface ' open the body part object containing an embedded message iDsrc.OpenObject iBp, "IBodyPart" Set GetEmbeddedMessage = iMsg End Function