1 | /* $Id: VirtualBoxErrorInfoImpl.h 106809 2024-10-31 14:37:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBoxErrorInfo COM class definition.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_VirtualBoxErrorInfoImpl_h
|
---|
29 | #define MAIN_INCLUDED_VirtualBoxErrorInfoImpl_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "VirtualBoxBase.h"
|
---|
35 |
|
---|
36 | using namespace com;
|
---|
37 |
|
---|
38 | class ATL_NO_VTABLE VirtualBoxErrorInfo
|
---|
39 | : public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>
|
---|
40 | , VBOX_SCRIPTABLE_IMPL(IVirtualBoxErrorInfo)
|
---|
41 | #ifndef VBOX_WITH_XPCOM /* IErrorInfo doesn't inherit from IDispatch, ugly 3am hack: */
|
---|
42 | , public IDispatch
|
---|
43 | #endif
|
---|
44 | {
|
---|
45 | public:
|
---|
46 |
|
---|
47 | DECLARE_NOT_AGGREGATABLE(VirtualBoxErrorInfo)
|
---|
48 |
|
---|
49 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
50 |
|
---|
51 | BEGIN_COM_MAP(VirtualBoxErrorInfo)
|
---|
52 | COM_INTERFACE_ENTRY(IErrorInfo)
|
---|
53 | COM_INTERFACE_ENTRY(IVirtualBoxErrorInfo)
|
---|
54 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
55 | COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler)
|
---|
56 | END_COM_MAP()
|
---|
57 |
|
---|
58 | DECLARE_TRANSLATE_METHODS(VirtualBoxErrorInfo)
|
---|
59 |
|
---|
60 | HRESULT FinalConstruct()
|
---|
61 | {
|
---|
62 | #ifndef VBOX_WITH_XPCOM
|
---|
63 | return CoCreateFreeThreadedMarshaler((IUnknown *)(void *)this, &m_pUnkMarshaler);
|
---|
64 | #else
|
---|
65 | return S_OK;
|
---|
66 | #endif
|
---|
67 | }
|
---|
68 |
|
---|
69 | void FinalRelease()
|
---|
70 | {
|
---|
71 | #ifndef VBOX_WITH_XPCOM
|
---|
72 | if (m_pUnkMarshaler)
|
---|
73 | {
|
---|
74 | m_pUnkMarshaler->Release();
|
---|
75 | m_pUnkMarshaler = NULL;
|
---|
76 | }
|
---|
77 | #endif
|
---|
78 | }
|
---|
79 |
|
---|
80 | #ifndef VBOX_WITH_XPCOM
|
---|
81 |
|
---|
82 | HRESULT init(IErrorInfo *aInfo);
|
---|
83 |
|
---|
84 | STDMETHOD(GetGUID)(GUID *guid);
|
---|
85 | STDMETHOD(GetSource)(BSTR *pBstrSource);
|
---|
86 | STDMETHOD(GetDescription)(BSTR *description);
|
---|
87 | STDMETHOD(GetHelpFile)(BSTR *pBstrHelpFile);
|
---|
88 | STDMETHOD(GetHelpContext)(DWORD *pdwHelpContext);
|
---|
89 |
|
---|
90 | // IDispatch forwarding - 3am hack.
|
---|
91 | // 2024-10-31 bird: Match com/defs.h __uuidof() workaround for IID_IEventSource conflict with Uuid.lib.
|
---|
92 | typedef IDispatchImpl<IVirtualBoxErrorInfo, /*&IID_IVirtualBoxErrorInfo*/ &__uuidof(IVirtualBoxErrorInfo),
|
---|
93 | &LIBID_VirtualBox, kTypeLibraryMajorVersion, kTypeLibraryMinorVersion> idi;
|
---|
94 |
|
---|
95 | STDMETHOD(GetTypeInfoCount)(UINT *pcInfo)
|
---|
96 | {
|
---|
97 | return idi::GetTypeInfoCount(pcInfo);
|
---|
98 | }
|
---|
99 |
|
---|
100 | STDMETHOD(GetTypeInfo)(UINT iInfo, LCID Lcid, ITypeInfo **ppTypeInfo)
|
---|
101 | {
|
---|
102 | return idi::GetTypeInfo(iInfo, Lcid, ppTypeInfo);
|
---|
103 | }
|
---|
104 |
|
---|
105 | STDMETHOD(GetIDsOfNames)(REFIID rIID, LPOLESTR *papwszNames, UINT cNames, LCID Lcid, DISPID *paDispIDs)
|
---|
106 | {
|
---|
107 | return idi::GetIDsOfNames(rIID, papwszNames, cNames, Lcid, paDispIDs);
|
---|
108 | }
|
---|
109 |
|
---|
110 | STDMETHOD(Invoke)(DISPID idDispMember, REFIID rIID, LCID Lcid, WORD fw, DISPPARAMS *pDispParams,
|
---|
111 | VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *piErrArg)
|
---|
112 | {
|
---|
113 | return idi::Invoke(idDispMember, rIID, Lcid, fw, pDispParams, pVarResult, pExcepInfo, piErrArg);
|
---|
114 | }
|
---|
115 |
|
---|
116 | #else // defined(VBOX_WITH_XPCOM)
|
---|
117 |
|
---|
118 | HRESULT init(nsIException *aInfo);
|
---|
119 |
|
---|
120 | NS_DECL_NSIEXCEPTION
|
---|
121 |
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | VirtualBoxErrorInfo()
|
---|
125 | : m_resultCode(S_OK),
|
---|
126 | m_resultDetail(0)
|
---|
127 | {}
|
---|
128 | virtual ~VirtualBoxErrorInfo() {}
|
---|
129 |
|
---|
130 | // public initializer/uninitializer for internal purposes only
|
---|
131 | HRESULT init(HRESULT aResultCode,
|
---|
132 | const GUID &aIID,
|
---|
133 | const char *pcszComponent,
|
---|
134 | const Utf8Str &strText,
|
---|
135 | IVirtualBoxErrorInfo *aNext = NULL);
|
---|
136 |
|
---|
137 | HRESULT initEx(HRESULT aResultCode,
|
---|
138 | LONG aResultDetail,
|
---|
139 | const GUID &aIID,
|
---|
140 | const char *pcszComponent,
|
---|
141 | const Utf8Str &strText,
|
---|
142 | IVirtualBoxErrorInfo *aNext = NULL);
|
---|
143 |
|
---|
144 | HRESULT init(const com::ErrorInfo &ei,
|
---|
145 | IVirtualBoxErrorInfo *aNext = NULL);
|
---|
146 |
|
---|
147 | // IVirtualBoxErrorInfo properties
|
---|
148 | STDMETHOD(COMGETTER(ResultCode))(LONG *aResultCode) RT_OVERRIDE;
|
---|
149 | STDMETHOD(COMGETTER(ResultDetail))(LONG *aResultDetail) RT_OVERRIDE;
|
---|
150 | STDMETHOD(COMGETTER(InterfaceID))(BSTR *aIID) RT_OVERRIDE;
|
---|
151 | STDMETHOD(COMGETTER(Component))(BSTR *aComponent) RT_OVERRIDE;
|
---|
152 | STDMETHOD(COMGETTER(Text))(BSTR *aText) RT_OVERRIDE;
|
---|
153 | STDMETHOD(COMGETTER(Next))(IVirtualBoxErrorInfo **aNext) RT_OVERRIDE;
|
---|
154 |
|
---|
155 | const char* getComponentName() const { return "VirtualBoxErrorInfo"; }
|
---|
156 |
|
---|
157 | private:
|
---|
158 | static HRESULT setError(HRESULT rc,
|
---|
159 | const char * /* a */,
|
---|
160 | const char * /* b */,
|
---|
161 | void * /* c */) { return rc; }
|
---|
162 |
|
---|
163 | HRESULT m_resultCode;
|
---|
164 | LONG m_resultDetail;
|
---|
165 | Utf8Str m_strText;
|
---|
166 | Guid m_IID;
|
---|
167 | Utf8Str m_strComponent;
|
---|
168 | ComPtr<IVirtualBoxErrorInfo> mNext;
|
---|
169 |
|
---|
170 | #ifndef VBOX_WITH_XPCOM
|
---|
171 | IUnknown *m_pUnkMarshaler;
|
---|
172 | #endif
|
---|
173 | };
|
---|
174 |
|
---|
175 | #endif /* !MAIN_INCLUDED_VirtualBoxErrorInfoImpl_h */
|
---|
176 |
|
---|
177 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|