1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_mscom_DispatchForwarder_h
8 #define mozilla_mscom_DispatchForwarder_h
9 
10 #include <oaidl.h>
11 
12 #include "mozilla/mscom/Interceptor.h"
13 #include "mozilla/mscom/Ptr.h"
14 
15 namespace mozilla {
16 namespace mscom {
17 
18 class DispatchForwarder final : public IDispatch {
19  public:
20   static HRESULT Create(IInterceptor* aInterceptor,
21                         STAUniquePtr<IDispatch>& aTarget, IUnknown** aOutput);
22 
23   // IUnknown
24   STDMETHODIMP QueryInterface(REFIID riid, void** ppv) override;
25   STDMETHODIMP_(ULONG) AddRef() override;
26   STDMETHODIMP_(ULONG) Release() override;
27 
28   // IDispatch
29   STDMETHODIMP GetTypeInfoCount(
30       /* [out] */ __RPC__out UINT* pctinfo) override;
31 
32   STDMETHODIMP GetTypeInfo(
33       /* [in] */ UINT iTInfo,
34       /* [in] */ LCID lcid,
35       /* [out] */ __RPC__deref_out_opt ITypeInfo** ppTInfo) override;
36 
37   STDMETHODIMP GetIDsOfNames(
38       /* [in] */ __RPC__in REFIID riid,
39       /* [size_is][in] */ __RPC__in_ecount_full(cNames) LPOLESTR* rgszNames,
40       /* [range][in] */ __RPC__in_range(0, 16384) UINT cNames,
41       /* [in] */ LCID lcid,
42       /* [size_is][out] */ __RPC__out_ecount_full(cNames) DISPID* rgDispId)
43       override;
44 
45   STDMETHODIMP Invoke(
46       /* [annotation][in] */
47       _In_ DISPID dispIdMember,
48       /* [annotation][in] */
49       _In_ REFIID riid,
50       /* [annotation][in] */
51       _In_ LCID lcid,
52       /* [annotation][in] */
53       _In_ WORD wFlags,
54       /* [annotation][out][in] */
55       _In_ DISPPARAMS* pDispParams,
56       /* [annotation][out] */
57       _Out_opt_ VARIANT* pVarResult,
58       /* [annotation][out] */
59       _Out_opt_ EXCEPINFO* pExcepInfo,
60       /* [annotation][out] */
61       _Out_opt_ UINT* puArgErr) override;
62 
63  private:
64   DispatchForwarder(IInterceptor* aInterceptor,
65                     STAUniquePtr<IDispatch>& aTarget);
66   ~DispatchForwarder();
67 
68  private:
69   ULONG mRefCnt;
70   RefPtr<IInterceptor> mInterceptor;
71   STAUniquePtr<IDispatch> mTarget;
72   RefPtr<ITypeInfo> mTypeInfo;
73   RefPtr<IUnknown> mInterface;
74 };
75 
76 }  // namespace mscom
77 }  // namespace mozilla
78 
79 #endif  // mozilla_mscom_DispatchForwarder_h
80