expando.cxx
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 5k
Category:

Windows Develop

Development Platform:

Visual C++

  1. /*
  2. * Copyright (c) 1998,1999 Microsoft Corporation. All rights reserved.
  3. * EXEMPT: copyright change only, no build required
  4. */
  5. #include "core.hxx"
  6. #pragma hdrstop
  7. #include <dispex.h>
  8. #include "utils.hxx"
  9. #include "expando.hxx"
  10. HRESULT 
  11. AddDOCExpandoProperty(
  12.     BSTR bstrAttribName,
  13.     IHTMLDocument2 *pDoc,
  14.     IDispatch *pDispToAdd)
  15. {
  16.     HRESULT hr;
  17.     VARIANT_BOOL vbExpando;
  18.     VARIANT var;     
  19.     DISPID dispid, putid;
  20.     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
  21.     IDispatchEx *pIEx = NULL;
  22.     hr = pDoc->get_expando(&vbExpando);
  23.     CHECKHR(hr);
  24.     // On change the state of the expando property if necessary
  25.     if (VARIANT_TRUE != vbExpando)
  26.     {
  27.         hr = pDoc->put_expando(VARIANT_TRUE);
  28.         CHECKHR(hr);
  29.     }
  30.     hr = pDoc->QueryInterface(IID_IDispatchEx, (void **)&pIEx);
  31.     CHECKHR(hr);
  32.     // Create new dispid in object
  33.     hr = pIEx->GetDispID(bstrAttribName, fdexNameEnsure, &dispid);
  34.     CHECKHR(hr);
  35.       
  36.     // now mark it as a dispatch and put the value
  37.     // trident wants PUT, not PUTREF or it craps out (??)
  38.     putid = DISPID_PROPERTYPUT;
  39.     var.vt = VT_DISPATCH;
  40.     var.pdispVal = pDispToAdd;
  41.     dispparams.rgvarg = &var;
  42.     dispparams.rgdispidNamedArgs = &putid;
  43.     dispparams.cArgs = 1;
  44.     dispparams.cNamedArgs = 1;
  45.     hr = pIEx->InvokeEx(dispid, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
  46.     CHECKHR(hr);
  47.     // Reset the state of the expando property
  48.     if (VARIANT_TRUE != vbExpando)
  49.     {
  50.         hr = pDoc->put_expando(VARIANT_FALSE);
  51.         CHECKHR(hr);
  52.     }
  53. CleanUp:
  54.     SafeRelease(pIEx);
  55.     return hr;
  56. }  // AddExpandoProperty
  57. /////////////////////////////////////////////////////////////////////////////////////////
  58. DISPATCHINFO ExpandoDocument::s_dispatchinfoEXP = 
  59. {
  60.     NULL, &IID_IXMLDOMDocument, &LIBID_MSXML, ORD_MSXML, NULL, 0, NULL, 0, NULL
  61. };
  62. ExpandoDocument::ExpandoDocument(BSTR bURL)
  63. {
  64.     _bURL = ::SysAllocString(bURL);
  65.     _refcount = 1;
  66.     ::IncrementComponents();
  67. }
  68. ExpandoDocument::~ExpandoDocument()
  69. {
  70.     ::SysFreeString(_bURL);
  71.     ::DecrementComponents();
  72. }
  73. //////////////////////////////////////////////
  74. ////  IUnknown methods
  75. HRESULT STDMETHODCALLTYPE 
  76. ExpandoDocument::QueryInterface(REFIID riid, void **ppv)
  77. {
  78.     *ppv = NULL;
  79.     if (riid == IID_IUnknown || riid == IID_IDispatch || riid == IID_IXMLDOMDocument || riid == IID_IXMLDOMDocument)
  80.     {
  81.         *ppv = this; // assumes vtable layout is definition order
  82.     }
  83.     else if (riid == IID_ISupportErrorInfo)
  84.     {
  85.         *ppv = static_cast<ISupportErrorInfo *>(this);
  86.     }
  87.     else
  88.     {
  89.         return E_NOINTERFACE;
  90.     }
  91.     AddRef();
  92.     return S_OK;
  93. }
  94. ULONG STDMETHODCALLTYPE 
  95. ExpandoDocument::AddRef()
  96. {
  97.     return InterlockedIncrement(&_refcount);
  98. }
  99. ULONG STDMETHODCALLTYPE 
  100. ExpandoDocument::Release()
  101. {
  102.     if (InterlockedDecrement(&_refcount) == 0)
  103.     {
  104.         delete this;
  105.         return 0;
  106.     }
  107.     return _refcount;
  108. }
  109. //////////////////////////////////////////////
  110. //// IDispatch methods
  111. HRESULT STDMETHODCALLTYPE 
  112. ExpandoDocument::GetTypeInfoCount( 
  113.     /* [out] */ UINT __RPC_FAR *pctinfo)
  114. {
  115.     return _dispatchImpl::GetTypeInfoCount(&s_dispatchinfoEXP, pctinfo);
  116. }
  117.     
  118. HRESULT STDMETHODCALLTYPE 
  119. ExpandoDocument::GetTypeInfo( 
  120.     /* [in] */ UINT iTInfo,
  121.     /* [in] */ LCID lcid,
  122.     /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
  123. {
  124.     return _dispatchImpl::GetTypeInfo(&s_dispatchinfoEXP, iTInfo, lcid, ppTInfo); 
  125. }
  126.     
  127. HRESULT STDMETHODCALLTYPE 
  128. ExpandoDocument::GetIDsOfNames( 
  129.     /* [in] */ REFIID riid,
  130.     /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
  131.     /* [in] */ UINT cNames,
  132.     /* [in] */ LCID lcid,
  133.     /* [size_is][out] */ DISPID __RPC_FAR *rgDispId)
  134. {
  135.     return _dispatchImpl::GetIDsOfNames(&s_dispatchinfoEXP, riid, rgszNames, cNames, lcid, rgDispId);
  136. }
  137.     
  138. HRESULT STDMETHODCALLTYPE 
  139. ExpandoDocument::Invoke( 
  140.     /* [in] */ DISPID dispIdMember,
  141.     /* [in] */ REFIID riid,
  142.     /* [in] */ LCID lcid,
  143.     /* [in] */ WORD wFlags,
  144.     /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
  145.     /* [out] */ VARIANT __RPC_FAR *pVarResult,
  146.     /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
  147.     /* [out] */ UINT __RPC_FAR *puArgErr)
  148. {
  149.     return _dispatchImpl::Invoke(&s_dispatchinfoEXP, this,
  150.                                       dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
  151. }
  152. //////////////////////////////////////////////
  153. //// ISupportErrorInfo
  154. HRESULT STDMETHODCALLTYPE 
  155. ExpandoDocument::InterfaceSupportsErrorInfo(REFIID riid)
  156. {
  157.     if (riid == IID_IXMLDOMDocument)
  158.         return S_OK;
  159.     return S_FALSE;    
  160. }       
  161. void 
  162. ExpandoDocument::setErrorInfo(WCHAR * szDescription)
  163. {
  164.     _dispatchImpl::setErrorInfo(szDescription);
  165. }
  166.     
  167. HRESULT STDMETHODCALLTYPE 
  168. ExpandoDocument::get_url( 
  169.     /* [out][retval] */ BSTR __RPC_FAR *urlString)
  170. {
  171.     Assert(_bURL);
  172.     *urlString = ::SysAllocString(_bURL);
  173.     return (*urlString ? S_OK : E_OUTOFMEMORY);
  174. }
  175.                 
  176.