defs.h revision 7c4556925685d859915f5517c9ce1c55c7399c6f
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @file
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * MS COM / XPCOM Abstraction Layer - Common definitions.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Copyright (C) 2006-2014 Oracle Corporation
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * available from http://www.virtualbox.org. This file is free software;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * General Public License (GPL) as published by the Free Software
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * The contents of this file may alternatively be used under the terms
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * of the Common Development and Distribution License Version 1.0
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * CDDL are applicable instead of those of the GPL.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * You may elect to license modified versions of this file under the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * terms and conditions of either the GPL or the CDDL or both.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#ifndef ___VBox_com_defs_h
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#define ___VBox_com_defs_h
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/* Make sure all the stdint.h macros are included - must come first! */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#ifndef __STDC_LIMIT_MACROS
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync# define __STDC_LIMIT_MACROS
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#endif
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#ifndef __STDC_CONSTANT_MACROS
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync# define __STDC_CONSTANT_MACROS
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync#endif
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync#if defined (RT_OS_OS2)
e4bf6817370e1a71833a02285515694afcda7599vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync# if defined(RT_MAX) && RT_MAX != 22
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync# undef RT_MAX
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync# define REDEFINE_RT_MAX
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync# endif
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync# undef RT_MAX
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/* Make sure OS/2 Toolkit headers are pulled in to have BOOL/ULONG/etc. typedefs
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * already defined in order to be able to redefine them using #define. */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync# define INCL_BASE
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync# define INCL_PM
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync# include <os2.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/* OS/2 Toolkit defines TRUE and FALSE */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync# undef FALSE
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync# undef TRUE
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/* */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync# undef RT_MAX
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync# ifdef REDEFINE_RT_MAX
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync# define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync# endif
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#endif /* defined(RT_OS_OS2) */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/* Include iprt/types.h (which also includes iprt/types.h) now to make sure iprt
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * gets to stdint.h first, otherwise a system/xpcom header might beat us and
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * we'll be without the macros that are optional in C++. */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#include <iprt/types.h>
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#if !defined(VBOX_WITH_XPCOM)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#if defined(RT_OS_WINDOWS)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync// Windows COM
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/////////////////////////////////////////////////////////////////////////////
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#include <objbase.h>
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#ifndef VBOX_COM_NO_ATL
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync# define _ATL_FREE_THREADED
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync# include <atlbase.h>
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#include <atlcom.h>
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#endif
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define NS_DECL_ISUPPORTS
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define NS_IMPL_ISUPPORTS1_CI(a, b)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/* these are XPCOM only, one for every interface implemented */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define NS_DECL_ISUPPORTS
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Returns @c true if @a rc represents a warning result code */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define SUCCEEDED_WARNING(rc) (SUCCEEDED(rc) && (rc) != S_OK)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Tests is a COM result code indicates that the process implementing the
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * interface is dead.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * COM status codes:
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * 0x800706ba - RPC_S_SERVER_UNAVAILABLE. Killed before call was made.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * 0x800706be - RPC_S_CALL_FAILED. Killed after call was made.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * 0x800706bf - RPC_S_CALL_FAILED_DNE. Not observed, but should be
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * matter of timing.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * 0x80010108 - RPC_E_DISCONNECTED. Observed deregistering
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * python event listener.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * 0x800706b5 - RPC_S_UNKNOWN_IF. Observed deregistering python
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * event listener
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define FAILED_DEAD_INTERFACE(rc) \
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync ( (rc) == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) \
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync || (rc) == HRESULT_FROM_WIN32(RPC_S_CALL_FAILED) \
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync || (rc) == HRESULT_FROM_WIN32(RPC_S_CALL_FAILED_DNE) \
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync || (rc) == RPC_E_DISCONNECTED \
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync )
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Immutable BSTR string */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef const OLECHAR *CBSTR;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Input BSTR argument of interface method declaration. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define IN_BSTR BSTR
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Input GUID argument of interface method declaration. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define IN_GUID GUID
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Output GUID argument of interface method declaration. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define OUT_GUID GUID*
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Makes the name of the getter interface function (n must be capitalized). */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define COMGETTER(n) get_##n
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Makes the name of the setter interface function (n must be capitalized). */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define COMSETTER(n) put_##n
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Declares an input safearray parameter in the COM method implementation. Also
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * used to declare the COM attribute setter parameter. Corresponds to either of
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * the following XIDL definitions:
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * <pre>
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * <param name="arg" ... dir="in" safearray="yes"/>
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * ...
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * <attribute name="arg" ... safearray="yes"/>
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * </pre>
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * The method implementation should use the com::SafeArray helper class to work
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * with parameters declared using this define.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param aType Array element type.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param aArg Parameter/attribute name.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
5902b558ec0657b3ee3cdba4deaa190f6fe182f1vboxsync#define ComSafeArrayIn(aType, aArg) SAFEARRAY *aArg
5902b558ec0657b3ee3cdba4deaa190f6fe182f1vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Expands to @true if the given input safearray parameter is a "null pointer"
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * which makes it impossible to use it for reading safearray data.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeArrayInIsNull(aArg) ((aArg) == NULL)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Wraps the given parameter name to generate an expression that is suitable for
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * passing the parameter to functions that take input safearray parameters
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * declared using the ComSafeArrayIn macro.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap. The given parameter must be declared
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * within the calling function using the ComSafeArrayIn macro.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeArrayInArg(aArg) aArg
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Declares an output safearray parameter in the COM method implementation. Also
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * used to declare the COM attribute getter parameter. Corresponds to either of
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * the following XIDL definitions:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * <pre>
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * <param name="arg" ... dir="out" safearray="yes"/>
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * <param name="arg" ... dir="return" safearray="yes"/>
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * ...
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * <attribute name="arg" ... safearray="yes"/>
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * </pre>
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * The method implementation should use the com::SafeArray helper class to work
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * with parameters declared using this define.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aType Array element type.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter/attribute name.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeArrayOut(aType, aArg) SAFEARRAY **aArg
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Expands to @true if the given output safearray parameter is a "null pointer"
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * which makes it impossible to use it for returning a safearray.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeArrayOutIsNull(aArg) ((aArg) == NULL)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Wraps the given parameter name to generate an expression that is suitable for
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * passing the parameter to functions that take output safearray parameters
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * declared using the ComSafeArrayOut marco.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap. The given parameter must be declared
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * within the calling function using the ComSafeArrayOut macro.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeArrayOutArg(aArg) aArg
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Version of ComSafeArrayIn for GUID.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeGUIDArrayIn(aArg) SAFEARRAY *aArg
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Version of ComSafeArrayInIsNull for GUID.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeGUIDArrayInIsNull(aArg) ComSafeArrayInIsNull(aArg)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Version of ComSafeArrayInArg for GUID.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeGUIDArrayInArg(aArg) ComSafeArrayInArg(aArg)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Version of ComSafeArrayOut for GUID.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeGUIDArrayOut(aArg) SAFEARRAY **aArg
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Version of ComSafeArrayOutIsNull for GUID.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeGUIDArrayOutIsNull(aArg) ComSafeArrayOutIsNull(aArg)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Version of ComSafeArrayOutArg for GUID.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name to wrap.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeGUIDArrayOutArg(aArg) ComSafeArrayOutArg(aArg)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Gets size of safearray parameter.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param aArg Parameter name.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ComSafeArraySize(aArg) ((aArg) == NULL ? 0 : (aArg)->rgsabound[0].cElements)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Returns the const reference to the IID (i.e., |const GUID &|) of the given
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * interface.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param i interface class
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
7468341cace5f5d2287abd9b8c3543033c7bf049vboxsync#define COM_IIDOF(I) _ATL_IIDOF(I)
7468341cace5f5d2287abd9b8c3543033c7bf049vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * For using interfaces before including the interface definitions. This will
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * deal with XPCOM using 'class' and COM using 'struct' when defining
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * interfaces.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param I interface name.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define COM_STRUCT_OR_CLASS(I) struct I
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#else /* defined(RT_OS_WINDOWS) */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#error "VBOX_WITH_XPCOM must be defined on a platform other than Windows!"
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#endif /* defined(RT_OS_WINDOWS) */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#else /* !defined(VBOX_WITH_XPCOM) */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync// XPCOM
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/////////////////////////////////////////////////////////////////////////////
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#if defined(RT_OS_DARWIN) || (defined(QT_VERSION) && (QT_VERSION >= 0x040000))
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync /* CFBase.h defines these &
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * qglobal.h from Qt4 defines these */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync# undef FALSE
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync# undef TRUE
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#endif /* RT_OS_DARWIN || QT_VERSION */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#include <nsID.h>
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define ATL_NO_VTABLE
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DECLARE_CLASSFACTORY(a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DECLARE_CLASSFACTORY_SINGLETON(a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DECLARE_REGISTRY_RESOURCEID(a)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DECLARE_NOT_AGGREGATABLE(a)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DECLARE_PROTECT_FINAL_CONSTRUCT()
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define BEGIN_COM_MAP(a)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define COM_INTERFACE_ENTRY(a)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define COM_INTERFACE_ENTRY2(a,b)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define END_COM_MAP() NS_DECL_ISUPPORTS
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define COM_INTERFACE_ENTRY_AGGREGATE(a,b)
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define HRESULT nsresult
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define SUCCEEDED NS_SUCCEEDED
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define FAILED NS_FAILED
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define SUCCEEDED_WARNING(rc) (NS_SUCCEEDED(rc) && (rc) != NS_OK)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define FAILED_DEAD_INTERFACE(rc) ( (rc) == NS_ERROR_ABORT \
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync || (rc) == NS_ERROR_CALL_FAILED \
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync )
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define IUnknown nsISupports
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define BOOL PRBool
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define BYTE PRUint8
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define SHORT PRInt16
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define USHORT PRUint16
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define LONG PRInt32
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ULONG PRUint32
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define LONG64 PRInt64
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ULONG64 PRUint64
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/* XPCOM has only 64bit floats */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define FLOAT PRFloat64
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DOUBLE PRFloat64
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define FALSE PR_FALSE
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define TRUE PR_TRUE
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define OLECHAR wchar_t
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/* note: typedef to semantically match BSTR on Win32 */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsynctypedef PRUnichar *BSTR;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsynctypedef const PRUnichar *CBSTR;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsynctypedef BSTR *LPBSTR;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** Input BSTR argument the interface method declaration. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define IN_BSTR CBSTR
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Type to define a raw GUID variable (for members use the com::Guid class
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * instead).
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define GUID nsID
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** Input GUID argument the interface method declaration. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define IN_GUID const nsID &
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** Output GUID argument the interface method declaration. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define OUT_GUID nsID **
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** Makes the name of the getter interface function (n must be capitalized). */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define COMGETTER(n) Get##n
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** Makes the name of the setter interface function (n must be capitalized). */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define COMSETTER(n) Set##n
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/* safearray input parameter macros */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeArrayIn(aType, aArg) PRUint32 aArg##Size, aType *aArg
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeArrayInIsNull(aArg) ((aArg) == NULL)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeArrayInArg(aArg) aArg##Size, aArg
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/* safearray output parameter macros */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeArrayOut(aType, aArg) PRUint32 *aArg##Size, aType **aArg
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeArrayOutIsNull(aArg) ((aArg) == NULL)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeArrayOutArg(aArg) aArg##Size, aArg
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/* safearray input parameter macros for GUID */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeGUIDArrayIn(aArg) PRUint32 aArg##Size, const nsID **aArg
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define ComSafeGUIDArrayInIsNull(aArg) ComSafeArrayInIsNull(aArg)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#define ComSafeGUIDArrayInArg(aArg) ComSafeArrayInArg(aArg)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/* safearray output parameter macros for GUID */
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ComSafeGUIDArrayOut(aArg) PRUint32 *aArg##Size, nsID ***aArg
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ComSafeGUIDArrayOutIsNull(aArg) ComSafeArrayOutIsNull(aArg)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ComSafeGUIDArrayOutArg(aArg) ComSafeArrayOutArg(aArg)
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/* safearray size */
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ComSafeArraySize(aArg) ((aArg) == NULL ? 0 : (aArg##Size))
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/* CLSID and IID for compatibility with Win32 */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef nsCID CLSID;
5b0a093ca572a855886faa6747ad46df859dd041vboxsynctypedef nsIID IID;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync/* OLE error codes */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define S_OK ((nsresult)NS_OK)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_UNEXPECTED NS_ERROR_UNEXPECTED
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_NOTIMPL NS_ERROR_NOT_IMPLEMENTED
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_OUTOFMEMORY NS_ERROR_OUT_OF_MEMORY
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_INVALIDARG NS_ERROR_INVALID_ARG
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_NOINTERFACE NS_ERROR_NO_INTERFACE
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_POINTER NS_ERROR_NULL_POINTER
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_ABORT NS_ERROR_ABORT
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_FAIL NS_ERROR_FAILURE
5b0a093ca572a855886faa6747ad46df859dd041vboxsync/* Note: a better analog for E_ACCESSDENIED would probably be
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * NS_ERROR_NOT_AVAILABLE, but we want binary compatibility for now. */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define E_ACCESSDENIED ((nsresult)0x80070005L)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define STDMETHOD(a) NS_IMETHOD a
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define STDMETHODIMP NS_IMETHODIMP
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define STDMETHOD_(ret, meth) NS_IMETHOD_(ret) meth
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define COM_IIDOF(I) NS_GET_IID(I)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync#define COM_STRUCT_OR_CLASS(I) class I
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/* A few very simple ATL emulator classes to provide
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * FinalConstruct()/FinalRelease() functionality on Linux. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncclass CComMultiThreadModel
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync};
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsynctemplate <class Base> class CComObjectRootEx : public Base
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
6ade813a528d8d2de918522b445e04010f09f021vboxsyncpublic:
6ade813a528d8d2de918522b445e04010f09f021vboxsync HRESULT FinalConstruct() { return S_OK; }
6ade813a528d8d2de918522b445e04010f09f021vboxsync void FinalRelease() {}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync};
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctemplate <class Base> class CComObject : public Base
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncpublic:
ad66a27959d7085aa31760f63ce082943be60e89vboxsync virtual ~CComObject() { this->FinalRelease(); }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync};
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/* helper functions */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncextern "C"
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncBSTR SysAllocString(const OLECHAR* sz);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncBSTR SysAllocStringByteLen(char *psz, unsigned int len);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncBSTR SysAllocStringLen(const OLECHAR *pch, unsigned int cch);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncvoid SysFreeString(BSTR bstr);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncint SysReAllocString(BSTR *pbstr, const OLECHAR *psz);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncint SysReAllocStringLen(BSTR *pbstr, const OLECHAR *psz, unsigned int cch);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncunsigned int SysStringByteLen(BSTR bstr);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncunsigned int SysStringLen(BSTR bstr);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync}
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/**
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * 'Constructor' for the component class.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * This constructor, as opposed to NS_GENERIC_FACTORY_CONSTRUCTOR,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * assumes that the component class is derived from the CComObjectRootEx<>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * template, so it calls FinalConstruct() right after object creation
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * and ensures that FinalRelease() will be called right before destruction.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * The result from FinalConstruct() is returned to the caller.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC(_InstanceClass) \
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic NS_IMETHODIMP \
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync void **aResult) \
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync{ \
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync nsresult rv; \
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync \
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync *aResult = NULL; \
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync if (NULL != aOuter) { \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync rv = NS_ERROR_NO_AGGREGATION; \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return rv; \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync } \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync CComObject <_InstanceClass> *inst = new CComObject <_InstanceClass>(); \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (NULL == inst) { \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync rv = NS_ERROR_OUT_OF_MEMORY; \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return rv; \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync } \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync NS_ADDREF(inst); /* protect FinalConstruct() */ \
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync rv = inst->FinalConstruct(); \
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync if (NS_SUCCEEDED(rv)) \
5b0a093ca572a855886faa6747ad46df859dd041vboxsync rv = inst->QueryInterface(aIID, aResult); \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync NS_RELEASE(inst); \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return rv; \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync}
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * 'Constructor' that uses an existing getter function that gets a singleton.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * The getter function must have the following prototype:
e4bf6817370e1a71833a02285515694afcda7599vboxsync * nsresult _GetterProc(_InstanceClass **inst)
e4bf6817370e1a71833a02285515694afcda7599vboxsync * This constructor, as opposed to NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR,
e4bf6817370e1a71833a02285515694afcda7599vboxsync * lets the getter function return a result code that is passed back to the
e961f5bfe1727c6816d3dad3805ebe21b6ba1c64vboxsync * caller that tries to instantiate the object.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
da44a59925a62ca7330a244c71b93794016f29f0vboxsync */
da44a59925a62ca7330a244c71b93794016f29f0vboxsync#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC(_InstanceClass, _GetterProc) \
da44a59925a62ca7330a244c71b93794016f29f0vboxsyncstatic NS_IMETHODIMP \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync void **aResult) \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{ \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync nsresult rv; \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync _InstanceClass * inst = NULL; /* initialized to shut up gcc */ \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync *aResult = NULL; \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (NULL != aOuter) { \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rv = NS_ERROR_NO_AGGREGATION; \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return rv; \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync } \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rv = _GetterProc(&inst); \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (NS_FAILED(rv)) \
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return rv; \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync /* sanity check */ \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync if (NULL == inst) \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync return NS_ERROR_OUT_OF_MEMORY; \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync /* NS_ADDREF(inst); */ \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync if (NS_SUCCEEDED(rv)) { \
7c4a90169768dcfac3c355a4c1f98b3ef0193641vboxsync rv = inst->QueryInterface(aIID, aResult); \
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync } \
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync NS_RELEASE(inst); \
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync \
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return rv; \
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync#endif /* !defined(VBOX_WITH_XPCOM) */
e4bf6817370e1a71833a02285515694afcda7599vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/**
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * Declares a wchar_t string literal from the argument.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * Necessary to overcome MSC / GCC differences.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * @param s expression to stringify
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#if defined(_MSC_VER)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync# define WSTR_LITERAL(s) L#s
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#elif defined(__GNUC__)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync# define WSTR_LITERAL(s) L""#s
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync#else
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync# error "Unsupported compiler!"
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync#endif
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsyncnamespace com
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync// use this macro to implement scriptable interfaces
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#ifdef RT_OS_WINDOWS
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define VBOX_SCRIPTABLE_IMPL(iface) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync public IDispatchImpl<iface, &IID_##iface, &LIBID_VirtualBox, \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync kTypeLibraryMajorVersion, kTypeLibraryMinorVersion>
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync#define VBOX_SCRIPTABLE_DISPATCH_IMPL(iface) \
ad66a27959d7085aa31760f63ce082943be60e89vboxsync STDMETHOD(QueryInterface)(REFIID riid , void **ppObj) \
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync { \
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (riid == IID_##iface) \
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync { \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *ppObj = (iface*)this; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync AddRef(); \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return S_OK; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync } \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if (riid == IID_IUnknown) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync { \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *ppObj = (IUnknown*)this; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync AddRef(); \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return S_OK; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync } \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if (riid == IID_IDispatch) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync { \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *ppObj = (IDispatch*)this; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync AddRef(); \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return S_OK; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync } \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *ppObj = NULL; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return E_NOINTERFACE; \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync }
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#define VBOX_DEFAULT_INTERFACE_ENTRIES(iface) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync COM_INTERFACE_ENTRY(ISupportErrorInfo) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync COM_INTERFACE_ENTRY(iface) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync COM_INTERFACE_ENTRY2(IDispatch,iface) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#else
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#define VBOX_SCRIPTABLE_IMPL(iface) \
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync public iface
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#define VBOX_SCRIPTABLE_DISPATCH_IMPL(iface)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#define VBOX_DEFAULT_INTERFACE_ENTRIES(iface)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#endif
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync} /* namespace com */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#endif /* !___VBox_com_defs_h */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync