VirtualBox

source: vbox/trunk/src/VBox/Main/include/VirtualBoxErrorInfoImpl.h@ 55319

Last change on this file since 55319 was 55189, checked in by vboxsync, 10 years ago

Main/VirtualBoxErrorInfo: Fix long-standing issue on Windows host when using this interface in the GUI process (which has to use a rather unusual apartment style, leading to marshaling issues between threads). The symptom was e.g. no detailed error information when a VM powerup failed due to inaccessible disks.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/** @file
2 * VirtualBoxErrorInfo COM class definition.
3 */
4
5/*
6 * Copyright (C) 2006-2015 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ____H_VIRTUALBOXERRORINFOIMPL
18#define ____H_VIRTUALBOXERRORINFOIMPL
19
20#include "VirtualBoxBase.h"
21
22using namespace com;
23
24class ATL_NO_VTABLE VirtualBoxErrorInfo
25 : public CComObjectRootEx<CComMultiThreadModel>
26 , VBOX_SCRIPTABLE_IMPL(IVirtualBoxErrorInfo)
27#ifndef VBOX_WITH_XPCOM /* IErrorInfo doesn't inherit from IDispatch, ugly 3am hack: */
28 , public IDispatch
29#endif
30{
31public:
32
33 DECLARE_NOT_AGGREGATABLE(VirtualBoxErrorInfo)
34
35 DECLARE_PROTECT_FINAL_CONSTRUCT()
36
37 BEGIN_COM_MAP(VirtualBoxErrorInfo)
38 COM_INTERFACE_ENTRY(IErrorInfo)
39 COM_INTERFACE_ENTRY(IVirtualBoxErrorInfo)
40 COM_INTERFACE_ENTRY(IDispatch)
41 COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler)
42 END_COM_MAP()
43
44 HRESULT FinalConstruct()
45 {
46#ifndef VBOX_WITH_XPCOM
47 return CoCreateFreeThreadedMarshaler((IUnknown *)(void *)this, &m_pUnkMarshaler);
48#else
49 return S_OK;
50#endif
51 }
52
53 void FinalRelease()
54 {
55#ifndef VBOX_WITH_XPCOM
56 if (m_pUnkMarshaler)
57 {
58 m_pUnkMarshaler->Release();
59 m_pUnkMarshaler = NULL;
60 }
61#endif
62 }
63
64#ifndef VBOX_WITH_XPCOM
65
66 HRESULT init(IErrorInfo *aInfo);
67
68 STDMETHOD(GetGUID)(GUID *guid);
69 STDMETHOD(GetSource)(BSTR *source);
70 STDMETHOD(GetDescription)(BSTR *description);
71 STDMETHOD(GetHelpFile)(BSTR *pBstrHelpFile);
72 STDMETHOD(GetHelpContext)(DWORD *pdwHelpContext);
73
74 // IDispatch forwarding - 3am hack.
75 typedef IDispatchImpl<IVirtualBoxErrorInfo, &IID_IVirtualBoxErrorInfo, &LIBID_VirtualBox, kTypeLibraryMajorVersion, kTypeLibraryMinorVersion> idi;
76
77 STDMETHOD(GetTypeInfoCount)(UINT *pcInfo)
78 {
79 return idi::GetTypeInfoCount(pcInfo);
80 }
81
82 STDMETHOD(GetTypeInfo)(UINT iInfo, LCID Lcid, ITypeInfo **ppTypeInfo)
83 {
84 return idi::GetTypeInfo(iInfo, Lcid, ppTypeInfo);
85 }
86
87 STDMETHOD(GetIDsOfNames)(REFIID rIID, LPOLESTR *papwszNames, UINT cNames, LCID Lcid, DISPID *paDispIDs)
88 {
89 return idi::GetIDsOfNames(rIID, papwszNames, cNames, Lcid, paDispIDs);
90 }
91
92 STDMETHOD(Invoke)(DISPID idDispMember, REFIID rIID, LCID Lcid, WORD fw, DISPPARAMS *pDispParams,
93 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *piErrArg)
94 {
95 return idi::Invoke(idDispMember, rIID, Lcid, fw, pDispParams, pVarResult, pExcepInfo, piErrArg);
96 }
97
98#else // defined(VBOX_WITH_XPCOM)
99
100 HRESULT init(nsIException *aInfo);
101
102 NS_DECL_NSIEXCEPTION
103
104#endif
105
106 VirtualBoxErrorInfo()
107 : m_resultCode(S_OK),
108 m_resultDetail(0)
109 {}
110
111 // public initializer/uninitializer for internal purposes only
112 HRESULT init(HRESULT aResultCode,
113 const GUID &aIID,
114 const char *pcszComponent,
115 const Utf8Str &strText,
116 IVirtualBoxErrorInfo *aNext = NULL);
117
118 HRESULT initEx(HRESULT aResultCode,
119 LONG aResultDetail,
120 const GUID &aIID,
121 const char *pcszComponent,
122 const Utf8Str &strText,
123 IVirtualBoxErrorInfo *aNext = NULL);
124
125 HRESULT init(const com::ErrorInfo &ei,
126 IVirtualBoxErrorInfo *aNext = NULL);
127
128 // IVirtualBoxErrorInfo properties
129 STDMETHOD(COMGETTER(ResultCode))(LONG *aResultCode);
130 STDMETHOD(COMGETTER(ResultDetail))(LONG *aResultDetail);
131 STDMETHOD(COMGETTER(InterfaceID))(BSTR *aIID);
132 STDMETHOD(COMGETTER(Component))(BSTR *aComponent);
133 STDMETHOD(COMGETTER(Text))(BSTR *aText);
134 STDMETHOD(COMGETTER(Next))(IVirtualBoxErrorInfo **aNext);
135
136private:
137 // FIXME: declare these here until VBoxSupportsTranslation base
138 // is available in this class.
139 static const char *tr(const char *a) { return a; }
140 static HRESULT setError(HRESULT rc,
141 const char * /* a */,
142 const char * /* b */,
143 void * /* c */) { return rc; }
144
145 HRESULT m_resultCode;
146 LONG m_resultDetail;
147 Utf8Str m_strText;
148 Guid m_IID;
149 Utf8Str m_strComponent;
150 ComPtr<IVirtualBoxErrorInfo> mNext;
151
152#ifndef VBOX_WITH_XPCOM
153 IUnknown *m_pUnkMarshaler;
154#endif
155};
156
157#endif // !____H_VIRTUALBOXERRORINFOIMPL
158
159/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette