[1] | 1 | /** @file
|
---|
[58110] | 2 | * MS COM / XPCOM Abstraction Layer - Common Definitions.
|
---|
[1] | 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[106061] | 6 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
[1] | 7 | *
|
---|
[96407] | 8 | * This file is part of VirtualBox base platform packages, as
|
---|
| 9 | * available from https://www.virtualbox.org.
|
---|
[5999] | 10 | *
|
---|
[96407] | 11 | * This program is free software; you can redistribute it and/or
|
---|
| 12 | * modify it under the terms of the GNU General Public License
|
---|
| 13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 14 | * License.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful, but
|
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 19 | * General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 23 | *
|
---|
[5999] | 24 | * The contents of this file may alternatively be used under the terms
|
---|
| 25 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[5999] | 28 | * CDDL are applicable instead of those of the GPL.
|
---|
| 29 | *
|
---|
| 30 | * You may elect to license modified versions of this file under the
|
---|
| 31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 32 | *
|
---|
| 33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[1] | 34 | */
|
---|
| 35 |
|
---|
[76558] | 36 | #ifndef VBOX_INCLUDED_com_defs_h
|
---|
| 37 | #define VBOX_INCLUDED_com_defs_h
|
---|
[76507] | 38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 39 | # pragma once
|
---|
| 40 | #endif
|
---|
[1] | 41 |
|
---|
[9332] | 42 | /* Make sure all the stdint.h macros are included - must come first! */
|
---|
| 43 | #ifndef __STDC_LIMIT_MACROS
|
---|
| 44 | # define __STDC_LIMIT_MACROS
|
---|
| 45 | #endif
|
---|
| 46 | #ifndef __STDC_CONSTANT_MACROS
|
---|
| 47 | # define __STDC_CONSTANT_MACROS
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
[8194] | 50 | #if defined (RT_OS_OS2)
|
---|
| 51 |
|
---|
[33385] | 52 | # if defined(RT_MAX) && RT_MAX != 22
|
---|
| 53 | # undef RT_MAX
|
---|
| 54 | # define REDEFINE_RT_MAX
|
---|
[33676] | 55 | # endif
|
---|
[33385] | 56 | # undef RT_MAX
|
---|
[13908] | 57 |
|
---|
[8194] | 58 | /* Make sure OS/2 Toolkit headers are pulled in to have BOOL/ULONG/etc. typedefs
|
---|
[33385] | 59 | * already defined in order to be able to redefine them using #define. */
|
---|
| 60 | # define INCL_BASE
|
---|
| 61 | # define INCL_PM
|
---|
| 62 | # include <os2.h>
|
---|
[8194] | 63 |
|
---|
| 64 | /* OS/2 Toolkit defines TRUE and FALSE */
|
---|
[33385] | 65 | # undef FALSE
|
---|
| 66 | # undef TRUE
|
---|
[8194] | 67 |
|
---|
[33385] | 68 | /* */
|
---|
[33676] | 69 | # undef RT_MAX
|
---|
[33385] | 70 | # ifdef REDEFINE_RT_MAX
|
---|
| 71 | # define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
|
---|
| 72 | # endif
|
---|
| 73 |
|
---|
[45058] | 74 | #endif /* defined(RT_OS_OS2) */
|
---|
[8194] | 75 |
|
---|
| 76 | /* Include iprt/types.h (which also includes iprt/types.h) now to make sure iprt
|
---|
[18050] | 77 | * gets to stdint.h first, otherwise a system/xpcom header might beat us and
|
---|
[8194] | 78 | * we'll be without the macros that are optional in C++. */
|
---|
[612] | 79 | #include <iprt/types.h>
|
---|
| 80 |
|
---|
[58110] | 81 |
|
---|
| 82 |
|
---|
| 83 | /** @defgroup grp_com_defs Common Definitions
|
---|
| 84 | * @ingroup grp_com
|
---|
| 85 | * @{
|
---|
| 86 | */
|
---|
| 87 |
|
---|
[45058] | 88 | #if !defined(VBOX_WITH_XPCOM)
|
---|
[3191] | 89 |
|
---|
[62780] | 90 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 91 |
|
---|
| 92 | // Windows COM
|
---|
| 93 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 94 |
|
---|
[62780] | 95 | # include <iprt/win/objbase.h>
|
---|
| 96 | # ifndef VBOX_COM_NO_ATL
|
---|
[35638] | 97 |
|
---|
[60765] | 98 | /* Do not use actual ATL, just provide a superficial lookalike ourselves. */
|
---|
[62780] | 99 | # include <VBox/com/microatl.h>
|
---|
| 100 | # endif /* VBOX_COM_NO_ATL */
|
---|
[1] | 101 |
|
---|
[62780] | 102 | # define NS_DECL_ISUPPORTS
|
---|
| 103 | # define NS_IMPL_ISUPPORTS1_CI(a, b)
|
---|
[1] | 104 |
|
---|
[3191] | 105 | /* these are XPCOM only, one for every interface implemented */
|
---|
[62780] | 106 | # define NS_DECL_ISUPPORTS
|
---|
[1] | 107 |
|
---|
[6976] | 108 | /** Returns @c true if @a rc represents a warning result code */
|
---|
[62780] | 109 | # define SUCCEEDED_WARNING(rc) (SUCCEEDED(rc) && (rc) != S_OK)
|
---|
[6976] | 110 |
|
---|
[28944] | 111 | /** Tests is a COM result code indicates that the process implementing the
|
---|
[28950] | 112 | * interface is dead.
|
---|
| 113 | *
|
---|
| 114 | * COM status codes:
|
---|
| 115 | * 0x800706ba - RPC_S_SERVER_UNAVAILABLE. Killed before call was made.
|
---|
| 116 | * 0x800706be - RPC_S_CALL_FAILED. Killed after call was made.
|
---|
[48063] | 117 | * 0x800706bf - RPC_S_CALL_FAILED_DNE. Not observed, but should be
|
---|
| 118 | * matter of timing.
|
---|
[47988] | 119 | * 0x80010108 - RPC_E_DISCONNECTED. Observed deregistering
|
---|
| 120 | * python event listener.
|
---|
[48063] | 121 | * 0x800706b5 - RPC_S_UNKNOWN_IF. Observed deregistering python
|
---|
| 122 | * event listener
|
---|
[28950] | 123 | */
|
---|
| 124 | #define FAILED_DEAD_INTERFACE(rc) \
|
---|
| 125 | ( (rc) == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) \
|
---|
| 126 | || (rc) == HRESULT_FROM_WIN32(RPC_S_CALL_FAILED) \
|
---|
| 127 | || (rc) == HRESULT_FROM_WIN32(RPC_S_CALL_FAILED_DNE) \
|
---|
[47988] | 128 | || (rc) == RPC_E_DISCONNECTED \
|
---|
[28950] | 129 | )
|
---|
[28944] | 130 |
|
---|
[15051] | 131 | /** Immutable BSTR string */
|
---|
| 132 | typedef const OLECHAR *CBSTR;
|
---|
[1] | 133 |
|
---|
[18050] | 134 | /** Input BSTR argument of interface method declaration. */
|
---|
[15051] | 135 | #define IN_BSTR BSTR
|
---|
| 136 |
|
---|
[18050] | 137 | /** Input GUID argument of interface method declaration. */
|
---|
[15051] | 138 | #define IN_GUID GUID
|
---|
[18050] | 139 | /** Output GUID argument of interface method declaration. */
|
---|
[60765] | 140 | #define OUT_GUID GUID *
|
---|
[15051] | 141 |
|
---|
[13580] | 142 | /** Makes the name of the getter interface function (n must be capitalized). */
|
---|
[1] | 143 | #define COMGETTER(n) get_##n
|
---|
[13580] | 144 | /** Makes the name of the setter interface function (n must be capitalized). */
|
---|
[1] | 145 | #define COMSETTER(n) put_##n
|
---|
| 146 |
|
---|
| 147 | /**
|
---|
[6935] | 148 | * Declares an input safearray parameter in the COM method implementation. Also
|
---|
| 149 | * used to declare the COM attribute setter parameter. Corresponds to either of
|
---|
| 150 | * the following XIDL definitions:
|
---|
[6851] | 151 | * <pre>
|
---|
[99739] | 152 | * <param name="arg" ... dir="in" safearray="yes"/>
|
---|
[6851] | 153 | * ...
|
---|
[99739] | 154 | * <attribute name="arg" ... safearray="yes"/>
|
---|
[6935] | 155 | * </pre>
|
---|
| 156 | *
|
---|
| 157 | * The method implementation should use the com::SafeArray helper class to work
|
---|
| 158 | * with parameters declared using this define.
|
---|
| 159 | *
|
---|
[6851] | 160 | * @param aType Array element type.
|
---|
| 161 | * @param aArg Parameter/attribute name.
|
---|
| 162 | */
|
---|
[35913] | 163 | #define ComSafeArrayIn(aType, aArg) SAFEARRAY *aArg
|
---|
[6851] | 164 |
|
---|
[6935] | 165 | /**
|
---|
[58106] | 166 | * Expands to @c true if the given input safearray parameter is a "null pointer"
|
---|
[6935] | 167 | * which makes it impossible to use it for reading safearray data.
|
---|
| 168 | */
|
---|
[35913] | 169 | #define ComSafeArrayInIsNull(aArg) ((aArg) == NULL)
|
---|
[6851] | 170 |
|
---|
[6935] | 171 | /**
|
---|
[6851] | 172 | * Wraps the given parameter name to generate an expression that is suitable for
|
---|
[6935] | 173 | * passing the parameter to functions that take input safearray parameters
|
---|
[45058] | 174 | * declared using the ComSafeArrayIn macro.
|
---|
[6935] | 175 | *
|
---|
| 176 | * @param aArg Parameter name to wrap. The given parameter must be declared
|
---|
[6851] | 177 | * within the calling function using the ComSafeArrayIn macro.
|
---|
| 178 | */
|
---|
| 179 | #define ComSafeArrayInArg(aArg) aArg
|
---|
| 180 |
|
---|
| 181 | /**
|
---|
[6935] | 182 | * Declares an output safearray parameter in the COM method implementation. Also
|
---|
| 183 | * used to declare the COM attribute getter parameter. Corresponds to either of
|
---|
[6851] | 184 | * the following XIDL definitions:
|
---|
| 185 | * <pre>
|
---|
[99739] | 186 | * <param name="arg" ... dir="out" safearray="yes"/>
|
---|
| 187 | * <param name="arg" ... dir="return" safearray="yes"/>
|
---|
[6851] | 188 | * ...
|
---|
[99739] | 189 | * <attribute name="arg" ... safearray="yes"/>
|
---|
[6935] | 190 | * </pre>
|
---|
| 191 | *
|
---|
| 192 | * The method implementation should use the com::SafeArray helper class to work
|
---|
| 193 | * with parameters declared using this define.
|
---|
| 194 | *
|
---|
[6851] | 195 | * @param aType Array element type.
|
---|
| 196 | * @param aArg Parameter/attribute name.
|
---|
| 197 | */
|
---|
| 198 | #define ComSafeArrayOut(aType, aArg) SAFEARRAY **aArg
|
---|
| 199 |
|
---|
[6935] | 200 | /**
|
---|
[58106] | 201 | * Expands to @c true if the given output safearray parameter is a "null
|
---|
| 202 | * pointer" which makes it impossible to use it for returning a safearray.
|
---|
[6935] | 203 | */
|
---|
[13580] | 204 | #define ComSafeArrayOutIsNull(aArg) ((aArg) == NULL)
|
---|
[6851] | 205 |
|
---|
[6935] | 206 | /**
|
---|
[6851] | 207 | * Wraps the given parameter name to generate an expression that is suitable for
|
---|
[6935] | 208 | * passing the parameter to functions that take output safearray parameters
|
---|
| 209 | * declared using the ComSafeArrayOut marco.
|
---|
| 210 | *
|
---|
| 211 | * @param aArg Parameter name to wrap. The given parameter must be declared
|
---|
[6851] | 212 | * within the calling function using the ComSafeArrayOut macro.
|
---|
| 213 | */
|
---|
| 214 | #define ComSafeArrayOutArg(aArg) aArg
|
---|
| 215 |
|
---|
| 216 | /**
|
---|
[13580] | 217 | * Version of ComSafeArrayIn for GUID.
|
---|
| 218 | * @param aArg Parameter name to wrap.
|
---|
| 219 | */
|
---|
[35913] | 220 | #define ComSafeGUIDArrayIn(aArg) SAFEARRAY *aArg
|
---|
[13580] | 221 |
|
---|
| 222 | /**
|
---|
| 223 | * Version of ComSafeArrayInIsNull for GUID.
|
---|
| 224 | * @param aArg Parameter name to wrap.
|
---|
| 225 | */
|
---|
[45058] | 226 | #define ComSafeGUIDArrayInIsNull(aArg) ComSafeArrayInIsNull(aArg)
|
---|
[13580] | 227 |
|
---|
| 228 | /**
|
---|
| 229 | * Version of ComSafeArrayInArg for GUID.
|
---|
| 230 | * @param aArg Parameter name to wrap.
|
---|
| 231 | */
|
---|
[45058] | 232 | #define ComSafeGUIDArrayInArg(aArg) ComSafeArrayInArg(aArg)
|
---|
[13580] | 233 |
|
---|
| 234 | /**
|
---|
| 235 | * Version of ComSafeArrayOut for GUID.
|
---|
| 236 | * @param aArg Parameter name to wrap.
|
---|
| 237 | */
|
---|
| 238 | #define ComSafeGUIDArrayOut(aArg) SAFEARRAY **aArg
|
---|
| 239 |
|
---|
| 240 | /**
|
---|
| 241 | * Version of ComSafeArrayOutIsNull for GUID.
|
---|
| 242 | * @param aArg Parameter name to wrap.
|
---|
| 243 | */
|
---|
[45058] | 244 | #define ComSafeGUIDArrayOutIsNull(aArg) ComSafeArrayOutIsNull(aArg)
|
---|
[13580] | 245 |
|
---|
| 246 | /**
|
---|
| 247 | * Version of ComSafeArrayOutArg for GUID.
|
---|
| 248 | * @param aArg Parameter name to wrap.
|
---|
| 249 | */
|
---|
[45058] | 250 | #define ComSafeGUIDArrayOutArg(aArg) ComSafeArrayOutArg(aArg)
|
---|
[13580] | 251 |
|
---|
| 252 | /**
|
---|
[45058] | 253 | * Gets size of safearray parameter.
|
---|
| 254 | * @param aArg Parameter name.
|
---|
| 255 | */
|
---|
[63385] | 256 | #define ComSafeArraySize(aArg) ((aArg) == NULL ? 0 : (aArg)->rgsabound[0].cElements)
|
---|
[45058] | 257 |
|
---|
| 258 | /**
|
---|
[63385] | 259 | * Apply RT_NOREF_PV to a safearray parameter.
|
---|
| 260 | * @param aArg Parameter name.
|
---|
| 261 | */
|
---|
| 262 | #define ComSafeArrayNoRef(aArg) RT_NOREF_PV(aArg)
|
---|
| 263 |
|
---|
| 264 | /**
|
---|
[1] | 265 | * Returns the const reference to the IID (i.e., |const GUID &|) of the given
|
---|
| 266 | * interface.
|
---|
| 267 | *
|
---|
[58106] | 268 | * @param I interface class
|
---|
[1] | 269 | */
|
---|
[60765] | 270 | #define COM_IIDOF(I) __uuidof(I)
|
---|
[1] | 271 |
|
---|
[34075] | 272 | /**
|
---|
| 273 | * For using interfaces before including the interface definitions. This will
|
---|
| 274 | * deal with XPCOM using 'class' and COM using 'struct' when defining
|
---|
| 275 | * interfaces.
|
---|
| 276 | *
|
---|
| 277 | * @param I interface name.
|
---|
| 278 | */
|
---|
| 279 | #define COM_STRUCT_OR_CLASS(I) struct I
|
---|
| 280 |
|
---|
[45058] | 281 | #else /* defined(RT_OS_WINDOWS) */
|
---|
[1] | 282 |
|
---|
[6851] | 283 | #error "VBOX_WITH_XPCOM must be defined on a platform other than Windows!"
|
---|
[3191] | 284 |
|
---|
[45058] | 285 | #endif /* defined(RT_OS_WINDOWS) */
|
---|
[3191] | 286 |
|
---|
[45058] | 287 | #else /* !defined(VBOX_WITH_XPCOM) */
|
---|
[3191] | 288 |
|
---|
[1] | 289 | // XPCOM
|
---|
| 290 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 291 |
|
---|
[45058] | 292 | #if defined(RT_OS_DARWIN) || (defined(QT_VERSION) && (QT_VERSION >= 0x040000))
|
---|
[9332] | 293 | /* CFBase.h defines these &
|
---|
[8266] | 294 | * qglobal.h from Qt4 defines these */
|
---|
[3601] | 295 | # undef FALSE
|
---|
| 296 | # undef TRUE
|
---|
[8266] | 297 | #endif /* RT_OS_DARWIN || QT_VERSION */
|
---|
[3601] | 298 |
|
---|
[1] | 299 | #include <nsID.h>
|
---|
| 300 |
|
---|
[6976] | 301 | #define HRESULT nsresult
|
---|
| 302 | #define SUCCEEDED NS_SUCCEEDED
|
---|
| 303 | #define FAILED NS_FAILED
|
---|
[1] | 304 |
|
---|
[45058] | 305 | #define SUCCEEDED_WARNING(rc) (NS_SUCCEEDED(rc) && (rc) != NS_OK)
|
---|
[6976] | 306 |
|
---|
[34655] | 307 | #define FAILED_DEAD_INTERFACE(rc) ( (rc) == NS_ERROR_ABORT \
|
---|
| 308 | || (rc) == NS_ERROR_CALL_FAILED \
|
---|
| 309 | )
|
---|
[28944] | 310 |
|
---|
[1] | 311 | #define IUnknown nsISupports
|
---|
| 312 |
|
---|
[469] | 313 | #define BOOL PRBool
|
---|
| 314 | #define BYTE PRUint8
|
---|
| 315 | #define SHORT PRInt16
|
---|
| 316 | #define USHORT PRUint16
|
---|
| 317 | #define LONG PRInt32
|
---|
| 318 | #define ULONG PRUint32
|
---|
| 319 | #define LONG64 PRInt64
|
---|
| 320 | #define ULONG64 PRUint64
|
---|
[27780] | 321 | /* XPCOM has only 64bit floats */
|
---|
| 322 | #define FLOAT PRFloat64
|
---|
| 323 | #define DOUBLE PRFloat64
|
---|
[469] | 324 |
|
---|
[15051] | 325 | #define FALSE PR_FALSE
|
---|
| 326 | #define TRUE PR_TRUE
|
---|
| 327 |
|
---|
[469] | 328 | #define OLECHAR wchar_t
|
---|
| 329 |
|
---|
[15051] | 330 | /* note: typedef to semantically match BSTR on Win32 */
|
---|
| 331 | typedef PRUnichar *BSTR;
|
---|
| 332 | typedef const PRUnichar *CBSTR;
|
---|
| 333 | typedef BSTR *LPBSTR;
|
---|
[1] | 334 |
|
---|
[15051] | 335 | /** Input BSTR argument the interface method declaration. */
|
---|
| 336 | #define IN_BSTR CBSTR
|
---|
[13580] | 337 |
|
---|
[15051] | 338 | /**
|
---|
| 339 | * Type to define a raw GUID variable (for members use the com::Guid class
|
---|
| 340 | * instead).
|
---|
| 341 | */
|
---|
| 342 | #define GUID nsID
|
---|
| 343 | /** Input GUID argument the interface method declaration. */
|
---|
| 344 | #define IN_GUID const nsID &
|
---|
| 345 | /** Output GUID argument the interface method declaration. */
|
---|
| 346 | #define OUT_GUID nsID **
|
---|
| 347 |
|
---|
[13580] | 348 | /** Makes the name of the getter interface function (n must be capitalized). */
|
---|
[1] | 349 | #define COMGETTER(n) Get##n
|
---|
[13580] | 350 | /** Makes the name of the setter interface function (n must be capitalized). */
|
---|
[1] | 351 | #define COMSETTER(n) Set##n
|
---|
| 352 |
|
---|
[6851] | 353 | /* safearray input parameter macros */
|
---|
| 354 | #define ComSafeArrayIn(aType, aArg) PRUint32 aArg##Size, aType *aArg
|
---|
[13580] | 355 | #define ComSafeArrayInIsNull(aArg) ((aArg) == NULL)
|
---|
[6851] | 356 | #define ComSafeArrayInArg(aArg) aArg##Size, aArg
|
---|
| 357 |
|
---|
| 358 | /* safearray output parameter macros */
|
---|
| 359 | #define ComSafeArrayOut(aType, aArg) PRUint32 *aArg##Size, aType **aArg
|
---|
[13580] | 360 | #define ComSafeArrayOutIsNull(aArg) ((aArg) == NULL)
|
---|
[6851] | 361 | #define ComSafeArrayOutArg(aArg) aArg##Size, aArg
|
---|
| 362 |
|
---|
[13580] | 363 | /* safearray input parameter macros for GUID */
|
---|
| 364 | #define ComSafeGUIDArrayIn(aArg) PRUint32 aArg##Size, const nsID **aArg
|
---|
[45058] | 365 | #define ComSafeGUIDArrayInIsNull(aArg) ComSafeArrayInIsNull(aArg)
|
---|
| 366 | #define ComSafeGUIDArrayInArg(aArg) ComSafeArrayInArg(aArg)
|
---|
[13580] | 367 |
|
---|
| 368 | /* safearray output parameter macros for GUID */
|
---|
| 369 | #define ComSafeGUIDArrayOut(aArg) PRUint32 *aArg##Size, nsID ***aArg
|
---|
[45058] | 370 | #define ComSafeGUIDArrayOutIsNull(aArg) ComSafeArrayOutIsNull(aArg)
|
---|
| 371 | #define ComSafeGUIDArrayOutArg(aArg) ComSafeArrayOutArg(aArg)
|
---|
[13580] | 372 |
|
---|
[63385] | 373 | /** safearray size */
|
---|
| 374 | #define ComSafeArraySize(aArg) ((aArg) == NULL ? 0 : (aArg##Size))
|
---|
[45058] | 375 |
|
---|
[63385] | 376 | /** NOREF a COM safe array argument. */
|
---|
| 377 | #define ComSafeArrayNoRef(aArg) RT_NOREF2(aArg, aArg##Size)
|
---|
| 378 |
|
---|
[3191] | 379 | /* CLSID and IID for compatibility with Win32 */
|
---|
[1] | 380 | typedef nsCID CLSID;
|
---|
| 381 | typedef nsIID IID;
|
---|
| 382 |
|
---|
[3191] | 383 | /* OLE error codes */
|
---|
[45058] | 384 | #define S_OK ((nsresult)NS_OK)
|
---|
[78966] | 385 | #define S_FALSE ((nsresult)1)
|
---|
[1] | 386 | #define E_UNEXPECTED NS_ERROR_UNEXPECTED
|
---|
| 387 | #define E_NOTIMPL NS_ERROR_NOT_IMPLEMENTED
|
---|
| 388 | #define E_OUTOFMEMORY NS_ERROR_OUT_OF_MEMORY
|
---|
| 389 | #define E_INVALIDARG NS_ERROR_INVALID_ARG
|
---|
| 390 | #define E_NOINTERFACE NS_ERROR_NO_INTERFACE
|
---|
| 391 | #define E_POINTER NS_ERROR_NULL_POINTER
|
---|
| 392 | #define E_ABORT NS_ERROR_ABORT
|
---|
| 393 | #define E_FAIL NS_ERROR_FAILURE
|
---|
[2976] | 394 | /* Note: a better analog for E_ACCESSDENIED would probably be
|
---|
| 395 | * NS_ERROR_NOT_AVAILABLE, but we want binary compatibility for now. */
|
---|
[45058] | 396 | #define E_ACCESSDENIED ((nsresult)0x80070005L)
|
---|
[1] | 397 |
|
---|
| 398 | #define STDMETHOD(a) NS_IMETHOD a
|
---|
| 399 | #define STDMETHODIMP NS_IMETHODIMP
|
---|
[50120] | 400 | #define STDMETHOD_(ret, meth) NS_IMETHOD_(ret) meth
|
---|
[1] | 401 |
|
---|
[30714] | 402 | #define COM_IIDOF(I) NS_GET_IID(I)
|
---|
[1] | 403 |
|
---|
[34075] | 404 | #define COM_STRUCT_OR_CLASS(I) class I
|
---|
| 405 |
|
---|
[3191] | 406 | /* helper functions */
|
---|
[1] | 407 | extern "C"
|
---|
| 408 | {
|
---|
[60765] | 409 | BSTR SysAllocString(const OLECHAR *sz);
|
---|
[80790] | 410 | BSTR SysAllocStringByteLen(char const *psz, unsigned int len);
|
---|
[45058] | 411 | BSTR SysAllocStringLen(const OLECHAR *pch, unsigned int cch);
|
---|
| 412 | void SysFreeString(BSTR bstr);
|
---|
| 413 | int SysReAllocString(BSTR *pbstr, const OLECHAR *psz);
|
---|
| 414 | int SysReAllocStringLen(BSTR *pbstr, const OLECHAR *psz, unsigned int cch);
|
---|
| 415 | unsigned int SysStringByteLen(BSTR bstr);
|
---|
| 416 | unsigned int SysStringLen(BSTR bstr);
|
---|
[1] | 417 | }
|
---|
| 418 |
|
---|
[60765] | 419 | #ifndef VBOX_COM_NO_ATL
|
---|
| 420 |
|
---|
[60766] | 421 | namespace ATL
|
---|
| 422 | {
|
---|
| 423 |
|
---|
| 424 | #define ATL_NO_VTABLE
|
---|
| 425 | #define DECLARE_CLASSFACTORY(a)
|
---|
| 426 | #define DECLARE_CLASSFACTORY_SINGLETON(a)
|
---|
| 427 | #define DECLARE_REGISTRY_RESOURCEID(a)
|
---|
| 428 | #define DECLARE_NOT_AGGREGATABLE(a)
|
---|
| 429 | #define DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
| 430 | #define BEGIN_COM_MAP(a)
|
---|
| 431 | #define COM_INTERFACE_ENTRY(a)
|
---|
| 432 | #define COM_INTERFACE_ENTRY2(a,b)
|
---|
| 433 | #define END_COM_MAP() NS_DECL_ISUPPORTS
|
---|
| 434 | #define COM_INTERFACE_ENTRY_AGGREGATE(a,b)
|
---|
| 435 |
|
---|
| 436 | /* A few very simple ATL emulator classes to provide
|
---|
| 437 | * FinalConstruct()/FinalRelease() functionality with XPCOM. */
|
---|
| 438 |
|
---|
| 439 | class CComMultiThreadModel
|
---|
| 440 | {
|
---|
| 441 | };
|
---|
| 442 |
|
---|
| 443 | template <class DummyThreadModel> class CComObjectRootEx
|
---|
| 444 | {
|
---|
| 445 | public:
|
---|
| 446 | HRESULT FinalConstruct()
|
---|
| 447 | {
|
---|
| 448 | return S_OK;
|
---|
| 449 | }
|
---|
| 450 | void FinalRelease()
|
---|
| 451 | {
|
---|
| 452 | }
|
---|
| 453 | };
|
---|
| 454 |
|
---|
| 455 | template <class Base> class CComObject : public Base
|
---|
| 456 | {
|
---|
| 457 | public:
|
---|
| 458 | virtual ~CComObject() { this->FinalRelease(); }
|
---|
| 459 | };
|
---|
| 460 |
|
---|
| 461 | } /* namespace ATL */
|
---|
| 462 |
|
---|
| 463 |
|
---|
[1] | 464 | /**
|
---|
| 465 | * 'Constructor' for the component class.
|
---|
| 466 | * This constructor, as opposed to NS_GENERIC_FACTORY_CONSTRUCTOR,
|
---|
| 467 | * assumes that the component class is derived from the CComObjectRootEx<>
|
---|
| 468 | * template, so it calls FinalConstruct() right after object creation
|
---|
| 469 | * and ensures that FinalRelease() will be called right before destruction.
|
---|
| 470 | * The result from FinalConstruct() is returned to the caller.
|
---|
| 471 | */
|
---|
| 472 | #define NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC(_InstanceClass) \
|
---|
| 473 | static NS_IMETHODIMP \
|
---|
| 474 | _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
|
---|
| 475 | void **aResult) \
|
---|
| 476 | { \
|
---|
| 477 | nsresult rv; \
|
---|
| 478 | \
|
---|
| 479 | *aResult = NULL; \
|
---|
| 480 | if (NULL != aOuter) { \
|
---|
| 481 | rv = NS_ERROR_NO_AGGREGATION; \
|
---|
| 482 | return rv; \
|
---|
| 483 | } \
|
---|
| 484 | \
|
---|
[60766] | 485 | ATL::CComObject<_InstanceClass> *inst = new ATL::CComObject<_InstanceClass>(); \
|
---|
[1] | 486 | if (NULL == inst) { \
|
---|
| 487 | rv = NS_ERROR_OUT_OF_MEMORY; \
|
---|
| 488 | return rv; \
|
---|
| 489 | } \
|
---|
| 490 | \
|
---|
| 491 | NS_ADDREF(inst); /* protect FinalConstruct() */ \
|
---|
| 492 | rv = inst->FinalConstruct(); \
|
---|
| 493 | if (NS_SUCCEEDED(rv)) \
|
---|
| 494 | rv = inst->QueryInterface(aIID, aResult); \
|
---|
| 495 | NS_RELEASE(inst); \
|
---|
| 496 | \
|
---|
| 497 | return rv; \
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | /**
|
---|
| 501 | * 'Constructor' that uses an existing getter function that gets a singleton.
|
---|
| 502 | * The getter function must have the following prototype:
|
---|
[45058] | 503 | * nsresult _GetterProc(_InstanceClass **inst)
|
---|
[1] | 504 | * This constructor, as opposed to NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR,
|
---|
| 505 | * lets the getter function return a result code that is passed back to the
|
---|
| 506 | * caller that tries to instantiate the object.
|
---|
| 507 | * NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
|
---|
| 508 | */
|
---|
| 509 | #define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC(_InstanceClass, _GetterProc) \
|
---|
| 510 | static NS_IMETHODIMP \
|
---|
| 511 | _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
|
---|
| 512 | void **aResult) \
|
---|
| 513 | { \
|
---|
| 514 | nsresult rv; \
|
---|
| 515 | \
|
---|
[60765] | 516 | _InstanceClass *inst = NULL; /* initialized to shut up gcc */ \
|
---|
[1] | 517 | \
|
---|
| 518 | *aResult = NULL; \
|
---|
| 519 | if (NULL != aOuter) { \
|
---|
| 520 | rv = NS_ERROR_NO_AGGREGATION; \
|
---|
| 521 | return rv; \
|
---|
| 522 | } \
|
---|
| 523 | \
|
---|
| 524 | rv = _GetterProc(&inst); \
|
---|
| 525 | if (NS_FAILED(rv)) \
|
---|
| 526 | return rv; \
|
---|
| 527 | \
|
---|
| 528 | /* sanity check */ \
|
---|
| 529 | if (NULL == inst) \
|
---|
| 530 | return NS_ERROR_OUT_OF_MEMORY; \
|
---|
| 531 | \
|
---|
| 532 | /* NS_ADDREF(inst); */ \
|
---|
| 533 | if (NS_SUCCEEDED(rv)) { \
|
---|
| 534 | rv = inst->QueryInterface(aIID, aResult); \
|
---|
| 535 | } \
|
---|
| 536 | NS_RELEASE(inst); \
|
---|
| 537 | \
|
---|
| 538 | return rv; \
|
---|
| 539 | }
|
---|
| 540 |
|
---|
[60765] | 541 | #endif /* !VBOX_COM_NO_ATL */
|
---|
| 542 |
|
---|
[45058] | 543 | #endif /* !defined(VBOX_WITH_XPCOM) */
|
---|
[1] | 544 |
|
---|
| 545 | /**
|
---|
[18050] | 546 | * Declares a wchar_t string literal from the argument.
|
---|
[1] | 547 | * Necessary to overcome MSC / GCC differences.
|
---|
| 548 | * @param s expression to stringify
|
---|
| 549 | */
|
---|
[45058] | 550 | #if defined(_MSC_VER)
|
---|
[1] | 551 | # define WSTR_LITERAL(s) L#s
|
---|
[45058] | 552 | #elif defined(__GNUC__)
|
---|
[1] | 553 | # define WSTR_LITERAL(s) L""#s
|
---|
| 554 | #else
|
---|
| 555 | # error "Unsupported compiler!"
|
---|
| 556 | #endif
|
---|
| 557 |
|
---|
[6963] | 558 | namespace com
|
---|
| 559 | {
|
---|
| 560 |
|
---|
[60765] | 561 | #ifndef VBOX_COM_NO_ATL
|
---|
| 562 |
|
---|
[19134] | 563 | // use this macro to implement scriptable interfaces
|
---|
| 564 | #ifdef RT_OS_WINDOWS
|
---|
| 565 | #define VBOX_SCRIPTABLE_IMPL(iface) \
|
---|
[60765] | 566 | public ATL::IDispatchImpl<iface, &IID_##iface, &LIBID_VirtualBox, \
|
---|
| 567 | kTypeLibraryMajorVersion, kTypeLibraryMinorVersion>
|
---|
[21521] | 568 |
|
---|
[41216] | 569 | #define VBOX_SCRIPTABLE_DISPATCH_IMPL(iface) \
|
---|
[60765] | 570 | STDMETHOD(QueryInterface)(REFIID riid, void **ppObj) \
|
---|
[41216] | 571 | { \
|
---|
| 572 | if (riid == IID_##iface) \
|
---|
| 573 | { \
|
---|
[60765] | 574 | *ppObj = (iface *)this; \
|
---|
[41216] | 575 | AddRef(); \
|
---|
| 576 | return S_OK; \
|
---|
| 577 | } \
|
---|
| 578 | if (riid == IID_IUnknown) \
|
---|
| 579 | { \
|
---|
[60765] | 580 | *ppObj = (IUnknown *)this; \
|
---|
[41216] | 581 | AddRef(); \
|
---|
| 582 | return S_OK; \
|
---|
| 583 | } \
|
---|
| 584 | if (riid == IID_IDispatch) \
|
---|
| 585 | { \
|
---|
[60765] | 586 | *ppObj = (IDispatch *)this; \
|
---|
[41216] | 587 | AddRef(); \
|
---|
| 588 | return S_OK; \
|
---|
| 589 | } \
|
---|
| 590 | *ppObj = NULL; \
|
---|
| 591 | return E_NOINTERFACE; \
|
---|
| 592 | }
|
---|
[19134] | 593 | #else
|
---|
[21521] | 594 | #define VBOX_SCRIPTABLE_IMPL(iface) \
|
---|
[19134] | 595 | public iface
|
---|
[41216] | 596 | #define VBOX_SCRIPTABLE_DISPATCH_IMPL(iface)
|
---|
[19134] | 597 | #endif
|
---|
| 598 |
|
---|
[60765] | 599 | #endif /* !VBOX_COM_NO_ATL */
|
---|
[19134] | 600 |
|
---|
[6963] | 601 | } /* namespace com */
|
---|
| 602 |
|
---|
[58110] | 603 | /** @} */
|
---|
| 604 |
|
---|
[76585] | 605 | #endif /* !VBOX_INCLUDED_com_defs_h */
|
---|
[45125] | 606 |
|
---|