VirtualBox

Changeset 50183 in vbox for trunk


Ignore:
Timestamp:
Jan 23, 2014 3:58:21 PM (11 years ago)
Author:
vboxsync
Message:

Main/cbinding: bring the C binding to a new functionality level, making them handle both COM and XPCOM based platforms, plus some xsl cleanup to eliminate the $dispatch case which was unused for many years (and will not be used again)

Location:
trunk/src/VBox
Files:
8 edited
6 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/win/VirtualBox.wxs

    r49537 r50183  
    660660<?endif?>
    661661
     662                    <!-- C API (glue) binding -->
     663                    <Component Id="cp_VBoxCAPI" Guid="097F7F53-7111-467F-8E0C-257D9926FDA0">
     664                        <File Id="file_VBoxCAPI.dll" Name="VBoxCAPI.dll"
     665                              Source="$(env.PATH_OUT)\bin\VBoxCAPI.dll" />
     666                    </Component>
     667
    662668<?if $(env.VBOX_WITH_PYTHON) = "yes" ?>
    663669                    <Component Id="cp_VBoxPythonBinding" Guid="293D7E11-78DA-4C31-AEED-AE2FE42F6881">
  • trunk/src/VBox/Main/cbinding/Makefile.kmk

    r49539 r50183  
    55
    66#
    7 # Copyright (C) 2009-2013 Oracle Corporation
     7# Copyright (C) 2009-2014 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020
    2121
    22 if defined(VBOX_WITH_XPCOM) || defined(VBOX_ONLY_SDK)
    2322#
    2423# The samples
    2524#
    26 INSTALLS += XpComCSamples
    27 XpComCSamples_MODE = a+r,u+rw
    28 XpComCSamples_INST = \
    29         $(INST_SDK)bindings/xpcom/cbinding/samples/
    30 XpComCSamples_SOURCES = \
    31         tstXPCOMCGlue.c \
    32         makefile.tstXPCOMCGlue=>Makefile
     25INSTALLS += CAPISamples
     26CAPISamples_MODE = a+r,u+rw
     27CAPISamples_INST = \
     28        $(INST_SDK)bindings/c/samples/
     29CAPISamples_SOURCES = \
     30        tstCAPIGlue.c \
     31        makefile.tstCAPIGlue=>Makefile
    3332
    34 INSTALLS += XpComCGlue
    35 XpComCGlue_MODE = a+r,u+rw
    36 XpComCGlue_INST = \
    37         $(INST_SDK)bindings/xpcom/cbinding/
    38 XpComCGlue_SOURCES = \
    39         VBoxXPCOMCGlue.c \
    40         $(XpComCHeaders_0_OUTDIR)/VBoxXPCOMCGlue.h
     33INSTALLS += CAPIGlue
     34CAPIGlue_MODE = a+r,u+rw
     35CAPIGlue_INST = \
     36        $(INST_SDK)bindings/c/glue/
     37CAPIGlue_SOURCES = \
     38        VBoxCAPIGlue.c \
     39        $(CAPIHeaders_0_OUTDIR)/VBoxCAPIGlue.h
    4140
    42 INSTALLS += XpComCHeaders
    43 XpComCHeaders_MODE = a+r,u+rw
    44 XpComCHeaders_INST = $(INST_SDK)bindings/xpcom/include/
    45 XpComCHeaders_SOURCES = \
     41INSTALLS += CAPIHeaders
     42CAPIHeaders_MODE = a+r,u+rw
     43CAPIHeaders_INST = $(INST_SDK)bindings/c/include/
     44CAPIHeaders_SOURCES = \
    4645        VBoxCAPI_v2_2.h \
    4746        VBoxCAPI_v3_0.h \
     
    5150        VBoxCAPI_v4_1.h \
    5251        VBoxCAPI_v4_2.h \
    53         $(XpComCHeaders_0_OUTDIR)/VBoxCAPI.h=>VBoxCAPI_v$(VBOX_API_VERSION).h
     52        $(CAPIHeaders_0_OUTDIR)/VBoxCAPI.h=>VBoxCAPI_v$(VBOX_API_VERSION).h
    5453
    55 $$(XpComCHeaders_0_OUTDIR)/VBoxXPCOMCGlue.h: \
    56                 $(PATH_SUB_CURRENT)/VBoxXPCOMCGlue.h.in \
     54$$(CAPIHeaders_0_OUTDIR)/VBoxCAPIGlue.h: \
     55                $(PATH_SUB_CURRENT)/VBoxCAPIGlue.h.in \
    5756                $(MAKEFILE_CURRENT) \
    5857                | $$(dir $$@)
     
    6261                <  $< >  $@
    6362
    64 $$(XpComCHeaders_0_OUTDIR)/VBoxCAPI.h: \
    65                 $(PATH_SUB_CURRENT)/xpcidl.xsl \
     63$$(CAPIHeaders_0_OUTDIR)/VBoxCAPI.h: \
     64                $(PATH_SUB_CURRENT)/capiidl.xsl \
    6665                $(VBOX_XIDL_FILE) \
    6766                | $$(dir $$@)
    68         $(call MSG_TOOL,xsltproc,XpComCHeaders,$<,$@)
     67        $(call MSG_TOOL,xsltproc,CAPIHeaders,$<,$@)
    6968        $(QUIET)$(VBOX_XSLTPROC) -o $@ $^
    7069
    71 endif # VBOX_WITH_XPCOM || SDK
    72 if !defined(VBOX_ONLY_SDK) && defined(VBOX_WITH_XPCOM)
     70if !defined(VBOX_ONLY_SDK)
    7371
    7472 #
    75  # The C utility DLL
     73 # The C API binding utility DLL
    7674 #
     75 DLLS += VBoxCAPI
     76 VBoxCAPI_TEMPLATE = VBOXMAINCLIENTDLL
    7777 ifdef VBOX_WITH_XPCOM
    78  DLLS += VBoxXPCOMC
    79  VBoxXPCOMC_TEMPLATE = VBOXMAINDLL
    80  VBoxXPCOMC_DEFS = IN_VBOXXPCOMC
    81  VBoxXPCOMC_SOURCES = \
    82         VBoxXPCOMC.cpp
    83  VBoxXPCOMC_INCS = \
    84         $(XpComCHeaders_0_OUTDIR)
    85  VBoxXPCOMC_INTERMEDIATES = \
    86         $(XpComCHeaders_0_OUTDIR)/VBoxCAPI.h
     78  # Keep old name on XPCOM so that legacy code is happy.
     79  VBoxCAPI_INST = $(INST_BIN)VBoxXPCOMC$(VBOX_SUFF_DLL)
    8780 endif
     81 VBoxCAPI_DEFS = IN_VBOXCAPI
     82 VBoxCAPI_SOURCES = \
     83        VBoxCAPI.cpp
     84 VBoxCAPI_INCS = \
     85        $(CAPIHeaders_0_OUTDIR)
     86 VBoxCAPI_INTERMEDIATES = \
     87        $(CAPIHeaders_0_OUTDIR)/VBoxCAPI.h
    8888
    8989 #
    9090 # The C glue library.
    9191 #
    92  LIBRARIES += VBoxXPCOMCGlue
    93  VBoxXPCOMCGlue_TEMPLATE = VBOXMAINEXE
    94  VBoxXPCOMCGlue_DEFS = IN_VBOXXPCOMC
    95  VBoxXPCOMCGlue_SOURCES = \
    96         VBoxXPCOMCGlue.c
    97  VBoxXPCOMCGlue_INCS = \
    98         $(VBOX_PATH_SDK)/bindings/xpcom/cbinding
    99  VBoxXPCOMCGlue_INTERMEDIATES = \
    100         $(VBOX_PATH_SDK)/bindings/xpcom/cbinding/VBoxXPCOMCGlue.h \
    101         $(VBOX_PATH_SDK)/bindings/xpcom/include/VBoxCAPI_v$(VBOX_API_VERSION).h
     92 LIBRARIES += VBoxCAPIGlue
     93 VBoxCAPIGlue_TEMPLATE = VBOXMAINEXE
     94 VBoxCAPIGlue_DEFS = IN_VBOXCAPI
     95 VBoxCAPIGlue_SOURCES = \
     96        VBoxCAPIGlue.c
     97 ifdef VBOX_WITH_XPCOM
     98  VBoxCAPIGlue_SOURCES += \
     99        $(VBOX_PATH_SDK)/bindings/xpcom/lib/VirtualBox_i.c
     100 else
     101  VBoxCAPIGlue_SOURCES += \
     102        $(VBOX_PATH_SDK)/bindings/mscom/lib/VirtualBox_i.c
     103 endif
     104 VBoxCAPIGlue_INCS = \
     105        $(VBOX_PATH_SDK)/bindings/c/include \
     106        $(VBOX_PATH_SDK)/bindings/c/glue
     107 VBoxCAPIGlue_INTERMEDIATES = \
     108        $(VBOX_PATH_SDK)/bindings/c/glue/VBoxCAPIGlue.h \
     109        $(VBOX_PATH_SDK)/bindings/c/include/VBoxCAPI_v$(VBOX_API_VERSION).h
    102110
    103111 if defined(VBOX_WITH_TESTCASES) && "$(KBUILD_TARGET)" != "darwin"
     
    106114  # C testcase using the dynamic glue.
    107115  #
    108   PROGRAMS += tstXPCOMCGlue
    109   tstXPCOMCGlue_TEMPLATE = VBOXR3TSTEXE
    110   tstXPCOMCGlue_INCS = \
    111         $(VBOX_PATH_SDK)/bindings/xpcom/include \
    112         $(VBOX_PATH_SDK)/bindings/xpcom/cbinding
    113   tstXPCOMCGlue_INTERMEDIATES = \
    114         $(VBOX_PATH_SDK)/bindings/xpcom/cbinding/VBoxXPCOMCGlue.h \
    115         $(VBOX_PATH_SDK)/bindings/xpcom/include/VBoxCAPI_v$(VBOX_API_VERSION).h
    116   tstXPCOMCGlue_SOURCES = \
    117         tstXPCOMCGlue.c
    118   tstXPCOMCGlue_LIBS = \
    119         $(VBoxXPCOMCGlue_1_TARGET)
     116  PROGRAMS += tstCAPIGlue
     117  tstCAPIGlue_TEMPLATE = VBOXR3TSTEXE
     118  tstCAPIGlue_INCS = \
     119        $(VBOX_PATH_SDK)/bindings/c/include \
     120        $(VBOX_PATH_SDK)/bindings/c/glue
     121  ifdef VBOX_WITH_XPCOM
     122   tstCAPIGlue_INCS += \
     123        $(VBOX_PATH_SDK)/bindings/xpcom/include
     124  else
     125   tstCAPIGlue_INCS += \
     126        $(VBOX_PATH_SDK)/bindings/mscom/include
     127  endif
     128  tstCAPIGlue_INTERMEDIATES = \
     129        $(VBOX_PATH_SDK)/bindings/c/glue/VBoxCAPIGlue.h \
     130        $(VBOX_PATH_SDK)/bindings/c/include/VBoxCAPI_v$(VBOX_API_VERSION).h
     131  tstCAPIGlue_SOURCES = \
     132        tstCAPIGlue.c
     133  tstCAPIGlue_LIBS = \
     134        $(VBoxCAPIGlue_1_TARGET)
    120135 endif
    121136
  • trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp

    r49984 r50183  
    11/* $Id$ */
    2 /** @file VBoxXPCOMC.cpp
    3  * Utility functions to use with the C binding for XPCOM.
     2/** @file VBoxCAPI.cpp
     3 * Utility functions to use with the C API binding.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2013 Oracle Corporation
     7 * Copyright (C) 2009-2014 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717
    1818#define LOG_GROUP LOG_GROUP_MAIN
    19 #include <nsMemory.h>
    20 #include <nsIServiceManager.h>
    21 #include <nsEventQueueUtils.h>
    22 #include <nsIExceptionService.h>
    23 
     19
     20#include "VBoxCAPI.h"
     21
     22#ifdef VBOX_WITH_XPCOM
     23# include <nsMemory.h>
     24# include <nsIServiceManager.h>
     25# include <nsEventQueueUtils.h>
     26# include <nsIExceptionService.h>
     27# include <stdlib.h>
     28#endif /* VBOX_WITH_XPCOM */
     29
     30#include <iprt/initterm.h>
    2431#include <iprt/string.h>
     32#include <iprt/uuid.h>
    2533#include <iprt/env.h>
     34#include <iprt/mem.h>
    2635#include <VBox/log.h>
    27 
    28 #include "VBoxCAPI.h"
     36#include <VBox/version.h>
     37
    2938#include "VBox/com/com.h"
    30 #include "VBox/version.h"
     39#include "VBox/com/NativeEventQueue.h"
    3140
    3241using namespace std;
    3342
    34 /* The following 3 object references should be eliminated once the legacy
    35  * way to initialize the XPCOM C bindings is removed. */
     43/* The following 2 object references should be eliminated once the legacy
     44 * way to initialize the COM/XPCOM C bindings is removed. */
    3645static ISession            *g_Session           = NULL;
    3746static IVirtualBox         *g_VirtualBox        = NULL;
    38 static nsIComponentManager *g_Manager           = NULL;
    39 
     47
     48#ifdef VBOX_WITH_XPCOM
     49/* This object reference should be eliminated once the legacy way of handling
     50 * the event queue (XPCOM specific) is removed. */
    4051static nsIEventQueue       *g_EventQueue        = NULL;
     52#endif /* VBOX_WITH_XPCOM */
    4153
    4254static void VBoxComUninitialize(void);
     
    4456
    4557static int
    46 VBoxUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString)
    47 {
     58VBoxUtf16ToUtf8(CBSTR pwszString, char **ppszString)
     59{
     60    if (!pwszString)
     61    {
     62        *ppszString = NULL;
     63        return VINF_SUCCESS;
     64    }
    4865    return RTUtf16ToUtf8(pwszString, ppszString);
    4966}
    5067
    5168static int
    52 VBoxUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString)
    53 {
     69VBoxUtf8ToUtf16(const char *pszString, BSTR *ppwszString)
     70{
     71    if (!pszString)
     72    {
     73        *ppwszString = NULL;
     74        return VINF_SUCCESS;
     75    }
     76#ifdef VBOX_WITH_XPCOM
    5477    return RTStrToUtf16(pszString, ppwszString);
     78#else /* !VBOX_WITH_XPCOM */
     79    PRTUTF16 pwsz;
     80    int vrc = RTStrToUtf16(pszString, &pwsz);
     81    *ppwszString = ::SysAllocString(pwsz);
     82    RTUtf16Free(pwsz);
     83    return vrc;
     84#endif /* !VBOX_WITH_XPCOM */
    5585}
    5686
    5787static void
    58 VBoxUtf16Free(PRUnichar *pwszString)
    59 {
     88VBoxUtf16Free(BSTR pwszString)
     89{
     90#ifdef VBOX_WITH_XPCOM
    6091    RTUtf16Free(pwszString);
     92#else /* !VBOX_WITH_XPCOM */
     93    ::SysFreeString(pwszString);
     94#endif /* !VBOX_WITH_XPCOM */
    6195}
    6296
     
    68102
    69103static void
    70 VBoxComUnallocMem(void *ptr)
    71 {
    72     if (ptr)
    73         nsMemory::Free(ptr);
     104VBoxComUnallocString(BSTR pwsz)
     105{
     106    if (pwsz)
     107    {
     108#ifdef VBOX_WITH_XPCOM
     109        nsMemory::Free(pwsz);
     110#else /* !VBOX_WITH_XPCOM */
     111        ::SysFreeString(pwsz);
     112#endif /* !VBOX_WITH_XPCOM */
     113    }
     114}
     115
     116static void
     117VBoxComUnallocMem(void *pv)
     118{
     119    VBoxComUnallocString((BSTR)pv);
     120}
     121
     122static ULONG
     123VBoxVTElemSize(VARTYPE vt)
     124{
     125    switch (vt)
     126    {
     127        case VT_BOOL:
     128        case VT_I1:
     129        case VT_UI1:
     130            return 1;
     131        case VT_I2:
     132        case VT_UI2:
     133            return 2;
     134        case VT_I4:
     135        case VT_UI4:
     136        case VT_HRESULT:
     137            return 4;
     138        case VT_I8:
     139        case VT_UI8:
     140            return 8;
     141        case VT_BSTR:
     142        case VT_DISPATCH:
     143        case VT_UNKNOWN:
     144            return sizeof(void *);
     145        default:
     146            return 0;
     147    }
     148}
     149
     150static SAFEARRAY *
     151VBoxSafeArrayCreateVector(VARTYPE vt, LONG lLbound, ULONG cElements)
     152{
     153#ifdef VBOX_WITH_XPCOM
     154    NOREF(lLbound);
     155    ULONG cbElement = VBoxVTElemSize(vt);
     156    if (!cbElement)
     157        return NULL;
     158    SAFEARRAY *psa = (SAFEARRAY *)RTMemAllocZ(sizeof(SAFEARRAY));
     159    if (!psa)
     160        return psa;
     161    if (cElements)
     162    {
     163        void *pv = nsMemory::Alloc(cElements * cbElement);
     164        if (!pv)
     165        {
     166            RTMemFree(psa);
     167            return NULL;
     168        }
     169        psa->pv = pv;
     170        psa->c = cElements;
     171    }
     172    return psa;
     173#else /* !VBOX_WITH_XPCOM */
     174    return SafeArrayCreateVector(vt, lLbound, cElements);
     175#endif /* !VBOX_WITH_XPCOM */
     176}
     177
     178static SAFEARRAY *
     179VBoxSafeArrayOutParamAlloc(void)
     180{
     181#ifdef VBOX_WITH_XPCOM
     182    return (SAFEARRAY *)RTMemAllocZ(sizeof(SAFEARRAY));
     183#else /* !VBOX_WITH_XPCOM */
     184    return NULL;
     185#endif /* !VBOX_WITH_XPCOM */
     186}
     187
     188static HRESULT
     189VBoxSafeArrayDestroy(SAFEARRAY *psa)
     190{
     191#ifdef VBOX_WITH_XPCOM
     192    if (psa)
     193    {
     194        if (psa->pv)
     195            nsMemory::Free(psa->pv);
     196        RTMemFree(psa);
     197    }
     198    return S_OK;
     199#else /* !VBOX_WITH_XPCOM */
     200    return SafeArrayDestroy(psa);
     201#endif /* !VBOX_WITH_XPCOM */
     202}
     203
     204static HRESULT
     205VBoxSafeArrayCopyInParamHelper(SAFEARRAY *psa, const void *pv, ULONG cb)
     206{
     207    if (!pv || !psa)
     208        return E_POINTER;
     209    if (!cb)
     210        return S_OK;
     211
     212    void *pData;
     213#ifdef VBOX_WITH_XPCOM
     214    pData = psa->pv;
     215#else /* !VBOX_WITH_XPCOM */
     216    HRESULT rc = SafeArrayAccessData(psa, &pData);
     217    if (FAILED(rc))
     218        return rc;
     219#endif /* !VBOX_WITH_XPCOM */
     220    memcpy(pData, pv, cb);
     221#ifndef VBOX_WITH_XPCOM
     222    SafeArrayUnaccessData(psa);
     223#endif /* !VBOX_WITH_XPCOM */
     224    return S_OK;
     225}
     226
     227static HRESULT
     228VBoxSafeArrayCopyOutParamHelper(void **ppv, ULONG *pcb, VARTYPE vt, SAFEARRAY *psa)
     229{
     230    if (!ppv)
     231        return E_POINTER;
     232    ULONG cbElement = VBoxVTElemSize(vt);
     233    if (!cbElement)
     234        return E_INVALIDARG;
     235#ifndef VBOX_WITH_XPCOM
     236    if (psa->cDims != 1)
     237        return E_INVALIDARG;
     238    Assert(cbElement = psa->cbElements);
     239#endif /* !VBOX_WITH_XPCOM */
     240    void *pData;
     241    ULONG cElements;
     242#ifdef VBOX_WITH_XPCOM
     243    pData = psa->pv;
     244    cElements = psa->c;
     245#else /* !VBOX_WITH_XPCOM */
     246    HRESULT rc = SafeArrayAccessData(psa, &pData);
     247    if (FAILED(rc))
     248        return rc;
     249    cElements = psa->rgsabound[0].cElements;
     250#endif /* !VBOX_WITH_XPCOM */
     251    size_t cbTotal = cbElement * cElements;
     252    void *pv = malloc(cbTotal);
     253    if (pv)
     254    {
     255        memcpy(pv, pData, cbTotal);
     256        *ppv = pv;
     257        if (pcb)
     258            *pcb = (ULONG)cbTotal;
     259    }
     260#ifndef VBOX_WITH_XPCOM
     261    SafeArrayUnaccessData(psa);
     262#endif /* !VBOX_WITH_XPCOM */
     263    return S_OK;
     264}
     265
     266static HRESULT
     267VBoxSafeArrayCopyOutIfaceParamHelper(IUnknown ***ppaObj, ULONG *pcObj, SAFEARRAY *psa)
     268{
     269    ULONG mypcb;
     270    HRESULT rc = VBoxSafeArrayCopyOutParamHelper((void **)ppaObj, &mypcb, VT_UNKNOWN, psa);
     271    if (FAILED(rc))
     272        return rc;
     273    ULONG cElements = mypcb / sizeof(void *);
     274    if (pcObj)
     275        *pcObj = cElements;
     276#ifndef VBOX_WITH_XPCOM
     277    /* Do this only for COM, as there the SAFEARRAY destruction will release
     278     * the contained references automatically. XPCOM doesn't do that, which
     279     * means that copying implicitly transfers ownership. */
     280    IUnknown **paObj = *ppaObj;
     281    for (ULONG i = 0; i < cElements; i++)
     282    {
     283        IUnknown *pObj = paObj[i];
     284        if (pObj)
     285            pObj->AddRef();
     286    }
     287#endif /* VBOX_WITH_XPCOM */
     288    return S_OK;
    74289}
    75290
     
    78293                  const char *pszSessionIID, ISession **ppSession)
    79294{
    80     nsresult rc;
    81     nsID virtualBoxIID;
    82     nsID sessionIID;
     295    int vrc;
     296    IID virtualBoxIID;
     297    IID sessionIID;
    83298
    84299    *ppSession    = NULL;
    85300    *ppVirtualBox = NULL;
    86301
    87     /* convert the string representation of UUID to nsIID type */
    88     if (!(virtualBoxIID.Parse(pszVirtualBoxIID) && sessionIID.Parse(pszSessionIID)))
    89         return;
    90 
    91     rc = com::Initialize();
    92     if (NS_FAILED(rc))
    93     {
    94         Log(("Cbinding: XPCOM could not be initialized! rc=%Rhrc\n", rc));
     302    /* convert the string representation of the UUIDs (if provided) to IID */
     303    if (pszVirtualBoxIID && *pszVirtualBoxIID)
     304    {
     305        vrc = ::RTUuidFromStr((RTUUID *)&virtualBoxIID, pszVirtualBoxIID);
     306        if (RT_FAILURE(vrc))
     307            return;
     308    }
     309    else
     310        virtualBoxIID = IID_IVirtualBox;
     311    if (pszSessionIID && *pszSessionIID)
     312    {
     313        vrc = ::RTUuidFromStr((RTUUID *)&sessionIID, pszSessionIID);
     314        if (RT_FAILURE(vrc))
     315            return;
     316    }
     317    else
     318        sessionIID = IID_ISession;
     319
     320    HRESULT rc = com::Initialize();
     321    if (FAILED(rc))
     322    {
     323        Log(("Cbinding: COM/XPCOM could not be initialized! rc=%Rhrc\n", rc));
    95324        VBoxComUninitialize();
    96325        return;
    97326    }
    98327
    99     rc = NS_GetComponentManager(&g_Manager);
    100     if (NS_FAILED(rc))
     328#ifdef VBOX_WITH_XPCOM
     329    rc = NS_GetMainEventQ(&g_EventQueue);
     330    if (FAILED(rc))
     331    {
     332        Log(("Cbinding: Could not get XPCOM event queue! rc=%Rhrc\n", rc));
     333        VBoxComUninitialize();
     334        return;
     335    }
     336#endif /* VBOX_WITH_XPCOM */
     337
     338#ifdef VBOX_WITH_XPCOM
     339    nsIComponentManager *pManager;
     340    rc = NS_GetComponentManager(&pManager);
     341    if (FAILED(rc))
    101342    {
    102343        Log(("Cbinding: Could not get component manager! rc=%Rhrc\n", rc));
     
    105346    }
    106347
     348    rc = pManager->CreateInstanceByContractID(NS_VIRTUALBOX_CONTRACTID,
     349                                              nsnull,
     350                                              virtualBoxIID,
     351                                              (void **)&g_VirtualBox);
     352#else /* !VBOX_WITH_XPCOM */
     353    rc = CoCreateInstance(CLSID_VirtualBox, NULL, CLSCTX_LOCAL_SERVER, virtualBoxIID, (void **)&g_VirtualBox);
     354#endif /* !VBOX_WITH_XPCOM */
     355    if (FAILED(rc))
     356    {
     357        Log(("Cbinding: Could not instantiate VirtualBox object! rc=%Rhrc\n",rc));
     358#ifdef VBOX_WITH_XPCOM
     359        pManager->Release();
     360        pManager = NULL;
     361#endif /* VBOX_WITH_XPCOM */
     362        VBoxComUninitialize();
     363        return;
     364    }
     365
     366    Log(("Cbinding: IVirtualBox object created.\n"));
     367
     368#ifdef VBOX_WITH_XPCOM
     369    rc = pManager->CreateInstanceByContractID(NS_SESSION_CONTRACTID,
     370                                              nsnull,
     371                                              sessionIID,
     372                                              (void **)&g_Session);
     373#else /* !VBOX_WITH_XPCOM */
     374    rc = CoCreateInstance(CLSID_Session, NULL, CLSCTX_INPROC_SERVER, sessionIID, (void **)&g_Session);
     375#endif /* !VBOX_WITH_XPCOM */
     376    if (FAILED(rc))
     377    {
     378        Log(("Cbinding: Could not instantiate Session object! rc=%Rhrc\n",rc));
     379#ifdef VBOX_WITH_XPCOM
     380        pManager->Release();
     381        pManager = NULL;
     382#endif /* VBOX_WITH_XPCOM */
     383        VBoxComUninitialize();
     384        return;
     385    }
     386
     387    Log(("Cbinding: ISession object created.\n"));
     388
     389#ifdef VBOX_WITH_XPCOM
     390    pManager->Release();
     391    pManager = NULL;
     392#endif /* VBOX_WITH_XPCOM */
     393
     394    *ppSession = g_Session;
     395    *ppVirtualBox = g_VirtualBox;
     396}
     397
     398static void
     399VBoxComInitializeV1(IVirtualBox **ppVirtualBox, ISession **ppSession)
     400{
     401    VBoxComInitialize(NULL, ppVirtualBox, NULL, ppSession);
     402}
     403
     404static void
     405VBoxComUninitialize(void)
     406{
     407    if (g_Session)
     408    {
     409        g_Session->Release();
     410        g_Session = NULL;
     411    }
     412    if (g_VirtualBox)
     413    {
     414        g_VirtualBox->Release();
     415        g_VirtualBox = NULL;
     416    }
     417#ifdef VBOX_WITH_XPCOM
     418    if (g_EventQueue)
     419    {
     420        g_EventQueue->Release();
     421        g_EventQueue = NULL;
     422    }
     423#endif /* VBOX_WITH_XPCOM */
     424    com::Shutdown();
     425    Log(("Cbinding: Cleaned up the created objects.\n"));
     426}
     427
     428#ifdef VBOX_WITH_XPCOM
     429static void
     430VBoxGetEventQueue(nsIEventQueue **ppEventQueue)
     431{
     432    *ppEventQueue = g_EventQueue;
     433}
     434#endif /* VBOX_WITH_XPCOM */
     435
     436static int
     437VBoxProcessEventQueue(LONG64 iTimeoutMS)
     438{
     439    RTMSINTERVAL iTimeout;
     440    if (iTimeoutMS < 0 || iTimeoutMS > UINT32_MAX)
     441        iTimeout = RT_INDEFINITE_WAIT;
     442    else
     443        iTimeout = (RTMSINTERVAL)iTimeoutMS;
     444    int vrc = com::NativeEventQueue::getMainEventQueue()->processEventQueue(iTimeout);
     445    switch (vrc)
     446    {
     447        case VINF_SUCCESS:
     448            return 0;
     449        case VINF_INTERRUPTED:
     450            return 1;
     451        case VERR_INTERRUPTED:
     452            return 2;
     453        case VERR_TIMEOUT:
     454            return 3;
     455        case VERR_INVALID_CONTEXT:
     456            return 4;
     457        default:
     458            return 5;
     459    }
     460}
     461
     462static int
     463VBoxInterruptEventQueueProcessing(void)
     464{
     465    com::NativeEventQueue::getMainEventQueue()->interruptEventQueueProcessing();
     466    return 0;
     467}
     468
     469static HRESULT
     470VBoxGetException(IErrorInfo **ppException)
     471{
     472    HRESULT rc;
     473
     474    *ppException = NULL;
     475
     476#ifdef VBOX_WITH_XPCOM
     477    nsIServiceManager *mgr = NULL;
     478    rc = NS_GetServiceManager(&mgr);
     479    if (FAILED(rc) || !mgr)
     480        return rc;
     481
     482    IID esid = NS_IEXCEPTIONSERVICE_IID;
     483    nsIExceptionService *es = NULL;
     484    rc = mgr->GetServiceByContractID(NS_EXCEPTIONSERVICE_CONTRACTID, esid, (void **)&es);
     485    if (FAILED(rc) || !es)
     486    {
     487        mgr->Release();
     488        return rc;
     489    }
     490
     491    nsIExceptionManager *em;
     492    rc = es->GetCurrentExceptionManager(&em);
     493    if (FAILED(rc) || !em)
     494    {
     495        es->Release();
     496        mgr->Release();
     497        return rc;
     498    }
     499
     500    nsIException *ex;
     501    rc = em->GetCurrentException(&ex);
     502    if (FAILED(rc))
     503    {
     504        em->Release();
     505        es->Release();
     506        mgr->Release();
     507        return rc;
     508    }
     509
     510    *ppException = ex;
     511    em->Release();
     512    es->Release();
     513    mgr->Release();
     514#else /* !VBOX_WITH_XPCOM */
     515    IErrorInfo *ex;
     516    rc = ::GetErrorInfo(0, &ex);
     517    if (FAILED(rc))
     518        return rc;
     519
     520    *ppException = ex;
     521#endif /* !VBOX_WITH_XPCOM */
     522
     523    return rc;
     524}
     525
     526static HRESULT
     527VBoxClearException(void)
     528{
     529    HRESULT rc;
     530
     531#ifdef VBOX_WITH_XPCOM
     532    nsIServiceManager *mgr = NULL;
     533    rc = NS_GetServiceManager(&mgr);
     534    if (FAILED(rc) || !mgr)
     535        return rc;
     536
     537    IID esid = NS_IEXCEPTIONSERVICE_IID;
     538    nsIExceptionService *es = NULL;
     539    rc = mgr->GetServiceByContractID(NS_EXCEPTIONSERVICE_CONTRACTID, esid, (void **)&es);
     540    if (FAILED(rc) || !es)
     541    {
     542        mgr->Release();
     543        return rc;
     544    }
     545
     546    nsIExceptionManager *em;
     547    rc = es->GetCurrentExceptionManager(&em);
     548    if (FAILED(rc) || !em)
     549    {
     550        es->Release();
     551        mgr->Release();
     552        return rc;
     553    }
     554
     555    rc = em->SetCurrentException(NULL);
     556    em->Release();
     557    es->Release();
     558    mgr->Release();
     559#else /* !VBOX_WITH_XPCOM */
     560    rc = ::SetErrorInfo(0, NULL);
     561#endif /* !VBOX_WITH_XPCOM */
     562
     563    return rc;
     564}
     565
     566static HRESULT
     567VBoxClientInitialize(const char *pszVirtualBoxClientIID, IVirtualBoxClient **ppVirtualBoxClient)
     568{
     569    IID virtualBoxClientIID;
     570
     571    *ppVirtualBoxClient = NULL;
     572
     573    /* convert the string representation of UUID to IID type */
     574    if (pszVirtualBoxClientIID && *pszVirtualBoxClientIID)
     575    {
     576        int vrc = ::RTUuidFromStr((RTUUID *)&virtualBoxClientIID, pszVirtualBoxClientIID);
     577        if (RT_FAILURE(vrc))
     578            return E_INVALIDARG;
     579    }
     580    else
     581        virtualBoxClientIID = IID_IVirtualBoxClient;
     582
     583    HRESULT rc = com::Initialize();
     584    if (FAILED(rc))
     585    {
     586        Log(("Cbinding: COM/XPCOM could not be initialized! rc=%Rhrc\n", rc));
     587        VBoxClientUninitialize();
     588        return rc;
     589    }
     590
     591#ifdef VBOX_WITH_XPCOM
    107592    rc = NS_GetMainEventQ(&g_EventQueue);
    108593    if (NS_FAILED(rc))
    109594    {
    110         Log(("Cbinding: Could not get xpcom event queue! rc=%Rhrc\n", rc));
    111         VBoxComUninitialize();
    112         return;
    113     }
    114 
    115     rc = g_Manager->CreateInstanceByContractID(NS_VIRTUALBOX_CONTRACTID,
    116                                                nsnull,
    117                                                virtualBoxIID,
    118                                                (void **)&g_VirtualBox);
    119     if (NS_FAILED(rc))
    120     {
    121         Log(("Cbinding: Could not instantiate VirtualBox object! rc=%Rhrc\n",rc));
    122         VBoxComUninitialize();
    123         return;
    124     }
    125 
    126     Log(("Cbinding: IVirtualBox object created.\n"));
    127 
    128     rc = g_Manager->CreateInstanceByContractID(NS_SESSION_CONTRACTID,
    129                                                nsnull,
    130                                                sessionIID,
    131                                                (void **)&g_Session);
    132     if (NS_FAILED(rc))
    133     {
    134         Log(("Cbinding: Could not instantiate Session object! rc=%Rhrc\n",rc));
    135         VBoxComUninitialize();
    136         return;
    137     }
    138 
    139     Log(("Cbinding: ISession object created.\n"));
    140 
    141     *ppSession = g_Session;
    142     *ppVirtualBox = g_VirtualBox;
    143 }
    144 
    145 static void
    146 VBoxComInitializeV1(IVirtualBox **ppVirtualBox, ISession **ppSession)
    147 {
    148     VBoxComInitialize(IVIRTUALBOX_IID_STR, ppVirtualBox,
    149                       ISESSION_IID_STR, ppSession);
    150 }
    151 
    152 static void
    153 VBoxComUninitialize(void)
    154 {
    155     if (g_Session)
    156     {
    157         NS_RELEASE(g_Session);
    158         g_Session = NULL;
    159     }
    160     if (g_VirtualBox)
    161     {
    162         NS_RELEASE(g_VirtualBox);
    163         g_VirtualBox = NULL;
    164     }
    165     if (g_EventQueue)
    166     {
    167         NS_RELEASE(g_EventQueue);
    168         g_EventQueue = NULL;
    169     }
    170     if (g_Manager)
    171     {
    172         NS_RELEASE(g_Manager);
    173         g_Manager = NULL;
    174     }
    175     com::Shutdown();
    176     Log(("Cbinding: Cleaned up the created objects.\n"));
    177 }
    178 
    179 static void
    180 VBoxGetEventQueue(nsIEventQueue **ppEventQueue)
    181 {
    182     *ppEventQueue = g_EventQueue;
    183 }
    184 
    185 static nsresult
    186 VBoxGetException(nsIException **ppException)
    187 {
    188     nsresult rc;
    189 
    190     *ppException = NULL;
    191     nsIServiceManager *mgr = NULL;
    192     rc = NS_GetServiceManager(&mgr);
    193     if (NS_FAILED(rc) || !mgr)
    194         return rc;
    195 
    196     nsIID esid = NS_IEXCEPTIONSERVICE_IID;
    197     nsIExceptionService *es = NULL;
    198     rc = mgr->GetServiceByContractID(NS_EXCEPTIONSERVICE_CONTRACTID, esid, (void **)&es);
    199     if (NS_FAILED(rc) || !es)
    200     {
    201         NS_RELEASE(mgr);
    202         return rc;
    203     }
    204 
    205     nsIExceptionManager *em;
    206     rc = es->GetCurrentExceptionManager(&em);
    207     if (NS_FAILED(rc) || !em)
    208     {
    209         NS_RELEASE(es);
    210         NS_RELEASE(mgr);
    211         return rc;
    212     }
    213 
    214     nsIException *ex;
    215     rc = em->GetCurrentException(&ex);
    216     if (NS_FAILED(rc))
    217     {
    218         NS_RELEASE(em);
    219         NS_RELEASE(es);
    220         NS_RELEASE(mgr);
    221         return rc;
    222     }
    223 
    224     *ppException = ex;
    225     NS_RELEASE(em);
    226     NS_RELEASE(es);
    227     NS_RELEASE(mgr);
    228     return rc;
    229 }
    230 
    231 static nsresult
    232 VBoxClearException(void)
    233 {
    234     nsresult rc;
    235 
    236     nsIServiceManager *mgr = NULL;
    237     rc = NS_GetServiceManager(&mgr);
    238     if (NS_FAILED(rc) || !mgr)
    239         return rc;
    240 
    241     nsIID esid = NS_IEXCEPTIONSERVICE_IID;
    242     nsIExceptionService *es = NULL;
    243     rc = mgr->GetServiceByContractID(NS_EXCEPTIONSERVICE_CONTRACTID, esid, (void **)&es);
    244     if (NS_FAILED(rc) || !es)
    245     {
    246         NS_RELEASE(mgr);
    247         return rc;
    248     }
    249 
    250     nsIExceptionManager *em;
    251     rc = es->GetCurrentExceptionManager(&em);
    252     if (NS_FAILED(rc) || !em)
    253     {
    254         NS_RELEASE(es);
    255         NS_RELEASE(mgr);
    256         return rc;
    257     }
    258 
    259     rc = em->SetCurrentException(NULL);
    260     NS_RELEASE(em);
    261     NS_RELEASE(es);
    262     NS_RELEASE(mgr);
    263     return rc;
    264 }
    265 
    266 static nsresult
    267 VBoxClientInitialize(const char *pszVirtualBoxClientIID, IVirtualBoxClient **ppVirtualBoxClient)
    268 {
    269     nsresult rc;
    270     nsID virtualBoxClientIID;
    271     nsID sessionIID;
    272 
    273     *ppVirtualBoxClient = NULL;
    274 
    275     /* convert the string representation of UUID to nsIID type */
    276     if (!virtualBoxClientIID.Parse(pszVirtualBoxClientIID))
    277         return NS_ERROR_INVALID_ARG;
    278 
    279     rc = com::Initialize();
    280     if (NS_FAILED(rc))
    281     {
    282         Log(("Cbinding: XPCOM could not be initialized! rc=%Rhrc\n", rc));
     595        Log(("Cbinding: Could not get XPCOM event queue! rc=%Rhrc\n", rc));
    283596        VBoxClientUninitialize();
    284597        return rc;
    285598    }
    286 
     599#endif /* VBOX_WITH_XPCOM */
     600
     601#ifdef VBOX_WITH_XPCOM
    287602    nsIComponentManager *pManager;
    288603    rc = NS_GetComponentManager(&pManager);
    289     if (NS_FAILED(rc))
     604    if (FAILED(rc))
    290605    {
    291606        Log(("Cbinding: Could not get component manager! rc=%Rhrc\n", rc));
    292         VBoxClientUninitialize();
    293         return rc;
    294     }
    295 
    296     rc = NS_GetMainEventQ(&g_EventQueue);
    297     if (NS_FAILED(rc))
    298     {
    299         Log(("Cbinding: Could not get xpcom event queue! rc=%Rhrc\n", rc));
    300607        VBoxClientUninitialize();
    301608        return rc;
     
    306613                                              virtualBoxClientIID,
    307614                                              (void **)ppVirtualBoxClient);
    308     if (NS_FAILED(rc))
     615#else /* !VBOX_WITH_XPCOM */
     616    rc = CoCreateInstance(CLSID_VirtualBoxClient, NULL, CLSCTX_INPROC_SERVER, virtualBoxClientIID, (void **)ppVirtualBoxClient);
     617#endif /* !VBOX_WITH_XPCOM */
     618    if (FAILED(rc))
    309619    {
    310620        Log(("Cbinding: Could not instantiate VirtualBoxClient object! rc=%Rhrc\n",rc));
     621#ifdef VBOX_WITH_XPCOM
     622        pManager->Release();
     623        pManager = NULL;
     624#endif /* VBOX_WITH_XPCOM */
    311625        VBoxClientUninitialize();
    312626        return rc;
    313627    }
    314628
    315     NS_RELEASE(pManager);
     629#ifdef VBOX_WITH_XPCOM
     630    pManager->Release();
    316631    pManager = NULL;
     632#endif /* VBOX_WITH_XPCOM */
    317633
    318634    Log(("Cbinding: IVirtualBoxClient object created.\n"));
    319635
    320     return NS_OK;
     636    return S_OK;
     637}
     638
     639static HRESULT
     640VBoxClientThreadInitialize(void)
     641{
     642    return com::Initialize();
     643}
     644
     645static HRESULT
     646VBoxClientThreadUninitialize(void)
     647{
     648    return com::Shutdown();
    321649}
    322650
     
    324652VBoxClientUninitialize(void)
    325653{
     654#ifdef VBOX_WITH_XPCOM
    326655    if (g_EventQueue)
    327656    {
     
    329658        g_EventQueue = NULL;
    330659    }
     660#endif /* VBOX_WITH_XPCOM */
    331661    com::Shutdown();
    332662    Log(("Cbinding: Cleaned up the created objects.\n"));
     
    345675}
    346676
    347 VBOXXPCOMC_DECL(PCVBOXXPCOM)
    348 VBoxGetXPCOMCFunctions(unsigned uVersion)
    349 {
     677VBOXCAPI_DECL(PCVBOXCAPI)
     678VBoxGetCAPIFunctions(unsigned uVersion)
     679{
     680    /* This is the first piece of code which knows that IPRT exists, so
     681     * initialize it properly. The limited initialization in VBoxC is not
     682     * sufficient, and causes trouble with com::Initialize() misbehaving. */
     683    RTR3InitDll(0);
     684
    350685    /*
    351686     * The current interface version.
    352687     */
    353     static const VBOXXPCOMC s_Functions =
    354     {
    355         sizeof(VBOXXPCOMC),
    356         VBOX_XPCOMC_VERSION,
     688    static const VBOXCAPI s_Functions =
     689    {
     690        sizeof(VBOXCAPI),
     691        VBOX_CAPI_VERSION,
    357692
    358693        VBoxVersion,
     
    360695
    361696        VBoxClientInitialize,
     697        VBoxClientThreadInitialize,
     698        VBoxClientThreadUninitialize,
    362699        VBoxClientUninitialize,
    363700
     
    365702        VBoxComUninitialize,
    366703
    367         VBoxComUnallocMem,
     704        VBoxComUnallocString,
    368705
    369706        VBoxUtf16ToUtf8,
     
    372709        VBoxUtf16Free,
    373710
     711        VBoxSafeArrayCreateVector,
     712        VBoxSafeArrayOutParamAlloc,
     713        VBoxSafeArrayCopyInParamHelper,
     714        VBoxSafeArrayCopyOutParamHelper,
     715        VBoxSafeArrayCopyOutIfaceParamHelper,
     716        VBoxSafeArrayDestroy,
     717
     718#ifdef VBOX_WITH_XPCOM
    374719        VBoxGetEventQueue,
     720#endif /* VBOX_WITH_XPCOM */
    375721        VBoxGetException,
    376722        VBoxClearException,
    377 
    378         VBOX_XPCOMC_VERSION
     723        VBoxProcessEventQueue,
     724        VBoxInterruptEventQueueProcessing,
     725
     726        VBOX_CAPI_VERSION
    379727    };
    380728
    381     if ((uVersion & 0xffff0000U) == (VBOX_XPCOMC_VERSION & 0xffff0000U))
     729    if ((uVersion & 0xffff0000U) == (VBOX_CAPI_VERSION & 0xffff0000U))
    382730        return &s_Functions;
    383731
    384732    /*
    385      * Legacy interface version 2.0.
     733     * Legacy interface version 3.0.
    386734     */
    387     static const struct VBOXXPCOMCV2
     735    static const struct VBOXCAPIV3
    388736    {
    389737        /** The size of the structure. */
     
    394742        unsigned int (*pfnGetVersion)(void);
    395743
     744        unsigned int (*pfnGetAPIVersion)(void);
     745
     746        HRESULT (*pfnClientInitialize)(const char *pszVirtualBoxClientIID,
     747                                       IVirtualBoxClient **ppVirtualBoxClient);
     748        void (*pfnClientUninitialize)(void);
     749
    396750        void  (*pfnComInitialize)(const char *pszVirtualBoxIID,
    397751                                  IVirtualBox **ppVirtualBox,
     
    402756
    403757        void  (*pfnComUnallocMem)(void *pv);
    404         void  (*pfnUtf16Free)(PRUnichar *pwszString);
     758
     759        int   (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString);
     760        int   (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString);
    405761        void  (*pfnUtf8Free)(char *pszString);
    406 
    407         int   (*pfnUtf16ToUtf8)(const PRUnichar *pwszString, char **ppszString);
    408         int   (*pfnUtf8ToUtf16)(const char *pszString, PRUnichar **ppwszString);
    409 
     762        void  (*pfnUtf16Free)(BSTR pwszString);
     763
     764#ifdef VBOX_WITH_XPCOM
    410765        void  (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue);
     766#endif /* VBOX_WITH_XPCOM */
     767        HRESULT (*pfnGetException)(IErrorInfo **ppException);
     768        HRESULT (*pfnClearException)(void);
    411769
    412770        /** Tail version, same as uVersion. */
    413771        unsigned uEndVersion;
    414     } s_Functions_v2_0 =
    415     {
    416         sizeof(s_Functions_v2_0),
    417         0x00020000U,
     772    } s_Functions_v3_0 =
     773    {
     774        sizeof(s_Functions_v3_0),
     775        0x00030000U,
    418776
    419777        VBoxVersion,
     778        VBoxAPIVersion,
     779
     780        VBoxClientInitialize,
     781        VBoxClientUninitialize,
    420782
    421783        VBoxComInitialize,
     
    423785
    424786        VBoxComUnallocMem,
    425         VBoxUtf16Free,
    426         VBoxUtf8Free,
    427787
    428788        VBoxUtf16ToUtf8,
    429789        VBoxUtf8ToUtf16,
    430 
     790        VBoxUtf8Free,
     791        VBoxUtf16Free,
     792
     793#ifdef VBOX_WITH_XPCOM
    431794        VBoxGetEventQueue,
    432 
    433         0x00020000U
     795#endif /* VBOX_WITH_XPCOM */
     796        VBoxGetException,
     797        VBoxClearException,
     798
     799        0x00030000U
    434800    };
    435801
    436     if ((uVersion & 0xffff0000U) == 0x00020000U)
    437         return (PCVBOXXPCOM)&s_Functions_v2_0;
     802    if ((uVersion & 0xffff0000U) == 0x00030000U)
     803        return (PCVBOXCAPI)&s_Functions_v3_0;
    438804
    439805    /*
    440      * Legacy interface version 1.0.
     806     * Legacy interface version 2.0.
    441807     */
    442     static const struct VBOXXPCOMCV1
     808    static const struct VBOXCAPIV2
    443809    {
    444810        /** The size of the structure. */
     
    449815        unsigned int (*pfnGetVersion)(void);
    450816
     817        void  (*pfnComInitialize)(const char *pszVirtualBoxIID,
     818                                  IVirtualBox **ppVirtualBox,
     819                                  const char *pszSessionIID,
     820                                  ISession **ppSession);
     821
     822        void  (*pfnComUninitialize)(void);
     823
     824        void  (*pfnComUnallocMem)(void *pv);
     825        void  (*pfnUtf16Free)(BSTR pwszString);
     826        void  (*pfnUtf8Free)(char *pszString);
     827
     828        int   (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString);
     829        int   (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString);
     830
     831#ifdef VBOX_WITH_XPCOM
     832        void  (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue);
     833#endif /* VBOX_WITH_XPCOM */
     834
     835        /** Tail version, same as uVersion. */
     836        unsigned uEndVersion;
     837    } s_Functions_v2_0 =
     838    {
     839        sizeof(s_Functions_v2_0),
     840        0x00020000U,
     841
     842        VBoxVersion,
     843
     844        VBoxComInitialize,
     845        VBoxComUninitialize,
     846
     847        VBoxComUnallocMem,
     848        VBoxUtf16Free,
     849        VBoxUtf8Free,
     850
     851        VBoxUtf16ToUtf8,
     852        VBoxUtf8ToUtf16,
     853
     854#ifdef VBOX_WITH_XPCOM
     855        VBoxGetEventQueue,
     856#endif /* VBOX_WITH_XPCOM */
     857
     858        0x00020000U
     859    };
     860
     861    if ((uVersion & 0xffff0000U) == 0x00020000U)
     862        return (PCVBOXCAPI)&s_Functions_v2_0;
     863
     864    /*
     865     * Legacy interface version 1.0.
     866     */
     867    static const struct VBOXCAPIV1
     868    {
     869        /** The size of the structure. */
     870        unsigned cb;
     871        /** The structure version. */
     872        unsigned uVersion;
     873
     874        unsigned int (*pfnGetVersion)(void);
     875
    451876        void  (*pfnComInitialize)(IVirtualBox **virtualBox, ISession **session);
    452877        void  (*pfnComUninitialize)(void);
    453878
    454879        void  (*pfnComUnallocMem)(void *pv);
    455         void  (*pfnUtf16Free)(PRUnichar *pwszString);
     880        void  (*pfnUtf16Free)(BSTR pwszString);
    456881        void  (*pfnUtf8Free)(char *pszString);
    457882
    458         int   (*pfnUtf16ToUtf8)(const PRUnichar *pwszString, char **ppszString);
    459         int   (*pfnUtf8ToUtf16)(const char *pszString, PRUnichar **ppwszString);
     883        int   (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString);
     884        int   (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString);
    460885
    461886        /** Tail version, same as uVersion. */
     
    482907
    483908    if ((uVersion & 0xffff0000U) == 0x00010000U)
    484         return (PCVBOXXPCOM)&s_Functions_v1_0;
     909        return (PCVBOXCAPI)&s_Functions_v1_0;
    485910
    486911    /*
     
    490915}
    491916
     917#ifdef VBOX_WITH_XPCOM
     918VBOXCAPI_DECL(PCVBOXCAPI)
     919VBoxGetXPCOMCFunctions(unsigned uVersion)
     920{
     921    return VBoxGetCAPIFunctions(uVersion);
     922}
     923#endif /* VBOX_WITH_XPCOM */
    492924/* vim: set ts=4 sw=4 et: */
  • trunk/src/VBox/Main/cbinding/VBoxCAPIGlue.c

    r49984 r50183  
    11/* $Revision$ */
    22/** @file
    3  * Glue code for dynamically linking to VBoxXPCOMC.
     3 * Glue code for dynamically linking to VBoxCAPI.
    44 */
    55
    66/*
    7  * Copyright (C) 2008-2013 Oracle Corporation
     7 * Copyright (C) 2008-2014 Oracle Corporation
    88 *
    99 * Permission is hereby granted, free of charge, to any person
     
    3232*   Header Files                                                               *
    3333*******************************************************************************/
     34#include "VBoxCAPIGlue.h"
     35
    3436#include <stdio.h>
    3537#include <string.h>
     
    3739#include <stdarg.h>
    3840#include <stdint.h>
    39 #include <dlfcn.h>
    40 #include <pthread.h>
    41 
    42 #include "VBoxXPCOMCGlue.h"
     41#ifndef WIN32
     42# include <dlfcn.h>
     43# include <pthread.h>
     44#else /* WIN32 */
     45# include <Windows.h>
     46#endif /* WIN32 */
    4347
    4448
     
    4751*******************************************************************************/
    4852#if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || defined(__FreeBSD__)
    49 # define DYNLIB_NAME    "VBoxXPCOMC.so"
     53# define DYNLIB_NAME        "VBoxXPCOMC.so"
    5054#elif defined(__APPLE__)
    51 # define DYNLIB_NAME    "VBoxXPCOMC.dylib"
    52 #elif defined(_MSC_VER) || defined(__OS2__)
    53 # define DYNLIB_NAME    "VBoxXPCOMC.dll"
     55# define DYNLIB_NAME        "VBoxXPCOMC.dylib"
     56#elif defined(__OS2__)
     57# define DYNLIB_NAME        "VBoxXPCOMC.dll"
     58#elif defined(WIN32)
     59# define DYNLIB_NAME        "VBoxCAPI.dll"
     60# undef DYNLIB_LEGACY_NAME
    5461#else
    5562# error "Port me"
     
    6067*   Global Variables                                                           *
    6168*******************************************************************************/
    62 /** The dlopen handle for VBoxXPCOMC. */
    63 void *g_hVBoxXPCOMC = NULL;
     69/** The so/dynsym/dll handle for VBoxCAPI. */
     70#ifndef WIN32
     71void *g_hVBoxCAPI = NULL;
     72#else /* WIN32 */
     73HMODULE g_hVBoxCAPI = NULL;
     74#endif /* WIN32 */
    6475/** The last load error. */
    65 char g_szVBoxErrMsg[256];
    66 /** Pointer to the VBoxXPCOMC function table. */
    67 PCVBOXXPCOM g_pVBoxFuncs = NULL;
    68 /** Pointer to VBoxGetXPCOMCFunctions for the loaded VBoxXPCOMC so/dylib/dll. */
    69 PFNVBOXGETXPCOMCFUNCTIONS g_pfnGetFunctions = NULL;
     76char g_szVBoxErrMsg[256] = "";
     77/** Pointer to the VBOXCAPI function table. */
     78PCVBOXCAPI g_pVBoxFuncs = NULL;
     79/** Pointer to VBoxGetCAPIFunctions for the loaded VBoxCAPI so/dylib/dll. */
     80PFNVBOXGETCAPIFUNCTIONS g_pfnGetFunctions = NULL;
    7081
    7182typedef void FNDUMMY(void);
    7283typedef FNDUMMY *PFNDUMMY;
    7384/** Just a dummy global structure containing a bunch of
    74  * function pointers to code which is wanted in the link.
    75  * In this case this is for helping gdb as it gets hideously
    76  * confused if the application doesn't drag in pthreads.
    77  */
    78 PFNDUMMY g_apfnVBoxXPCOMCGlue[] =
    79 {
    80     (PFNDUMMY)pthread_create
     85 * function pointers to code which is wanted in the link. */
     86PFNDUMMY g_apfnVBoxCAPIGlue[] =
     87{
     88#ifndef WIN32
     89    /* The following link dependency is for helping gdb as it gets hideously
     90     * confused if the application doesn't drag in pthreads, but uses it. */
     91    (PFNDUMMY)pthread_create,
     92#endif /* !WIN32 */
     93    NULL
    8194};
    8295
     
    103116
    104117/**
    105  * Try load VBoxXPCOMC.so/dylib/dll from the specified location and resolve all
    106  * the symbols we need.
     118 * Try load C API .so/dylib/dll from the specified location and resolve all
     119 * the symbols we need. Tries both the new style and legacy name.
    107120 *
    108121 * @returns 0 on success, -1 on failure.
    109  * @param   pszHome         The director where to try load VBoxXPCOMC from. Can
    110  *                          be NULL.
     122 * @param   pszHome         The directory where to try load VBoxCAPI/VBoxXPCOMC
     123 *                          from. Can be NULL.
    111124 * @param   fSetAppHome     Whether to set the VBOX_APP_HOME env.var. or not
    112125 *                          (boolean).
    113126 */
    114 static int tryLoadOne(const char *pszHome, int fSetAppHome)
     127static int tryLoadLibrary(const char *pszHome, int fSetAppHome)
    115128{
    116129    size_t      cchHome = pszHome ? strlen(pszHome) : 0;
    117130    size_t      cbBufNeeded;
    118131    char        szName[4096];
    119     int         rc = -1;
    120132
    121133    /*
     
    143155    if (fSetAppHome)
    144156    {
     157#ifndef WIN32
    145158        if (pszHome)
    146159            setenv("VBOX_APP_HOME", pszHome, 1 /* always override */);
    147160        else
    148161            unsetenv("VBOX_APP_HOME");
    149     }
    150     g_hVBoxXPCOMC = dlopen(szName, RTLD_NOW | RTLD_LOCAL);
    151     if (g_hVBoxXPCOMC)
    152     {
    153         PFNVBOXGETXPCOMCFUNCTIONS pfnGetFunctions;
    154         pfnGetFunctions = (PFNVBOXGETXPCOMCFUNCTIONS)(uintptr_t)
    155             dlsym(g_hVBoxXPCOMC, VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME);
     162#endif /* !WIN32 */
     163    }
     164
     165#ifndef WIN32
     166    g_hVBoxCAPI = dlopen(szName, RTLD_NOW | RTLD_LOCAL);
     167    if (g_hVBoxCAPI)
     168    {
     169        PFNVBOXGETCAPIFUNCTIONS pfnGetFunctions;
     170        pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS)(uintptr_t)
     171            dlsym(g_hVBoxCAPI, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME);
     172#ifdef VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME
     173        if (!pfnGetFunctions)
     174            pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS)(uintptr_t)
     175                dlsym(g_hVBoxCAPI, VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME);
     176#endif /* VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME */
    156177        if (pfnGetFunctions)
    157178        {
    158             g_pVBoxFuncs = pfnGetFunctions(VBOX_XPCOMC_VERSION);
     179            g_pVBoxFuncs = pfnGetFunctions(VBOX_CAPI_VERSION);
    159180            if (g_pVBoxFuncs)
    160181            {
     
    165186            /* bail out */
    166187            setErrMsg(1, "%.80s: pfnGetFunctions(%#x) failed",
    167                       szName, VBOX_XPCOMC_VERSION);
     188                      szName, VBOX_CAPI_VERSION);
    168189        }
    169190        else
    170191            setErrMsg(1, "dlsym(%.80s/%.32s): %.128s",
    171                       szName, VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME, dlerror());
    172         dlclose(g_hVBoxXPCOMC);
    173         g_hVBoxXPCOMC = NULL;
     192                      szName, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME, dlerror());
     193        dlclose(g_hVBoxCAPI);
     194        g_hVBoxCAPI = NULL;
    174195    }
    175196    else
    176197        setErrMsg(0, "dlopen(%.80s): %.160s", szName, dlerror());
    177     return rc;
     198#else /* !WIN32 */
     199    g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */);
     200    if (g_hVBoxCAPI)
     201    {
     202        PFNVBOXGETCAPIFUNCTIONS pfnGetFunctions;
     203        pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS)
     204            GetProcAddress(g_hVBoxCAPI, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME);
     205        if (pfnGetFunctions)
     206        {
     207            g_pVBoxFuncs = pfnGetFunctions(VBOX_CAPI_VERSION);
     208            if (g_pVBoxFuncs)
     209            {
     210                g_pfnGetFunctions = pfnGetFunctions;
     211                return 0;
     212            }
     213
     214            /* bail out */
     215            setErrMsg(1, "%.80s: pfnGetFunctions(%#x) failed",
     216                      szName, VBOX_CAPI_VERSION);
     217        }
     218        else
     219            setErrMsg(1, "GetProcAddress(%.80s/%.32s): %d",
     220                      szName, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME, GetLastError());
     221        FreeLibrary(g_hVBoxCAPI);
     222        g_hVBoxCAPI = NULL;
     223    }
     224    else
     225        setErrMsg(0, "LoadLibraryEx(%.80s): %d", szName, GetLastError());
     226#endif /* !WIN32 */
     227
     228    return -1;
    178229}
    179230
    180231
    181232/**
    182  * Tries to locate and load VBoxXPCOMC.so/dylib/dll, resolving all the related
     233 * Tries to locate and load VBoxCAPI.so/dylib/dll, resolving all the related
    183234 * function pointers.
    184235 *
     
    186237 *
    187238 * @remark  This should be considered moved into a separate glue library since
    188  *          its its going to be pretty much the same for any user of VBoxXPCOMC
     239 *          its its going to be pretty much the same for any user of VBoxCAPI
    189240 *          and it will just cause trouble to have duplicate versions of this
    190241 *          source code all around the place.
     
    192243int VBoxCGlueInit(void)
    193244{
     245    const char *pszHome;
     246
     247    memset(g_szVBoxErrMsg, 0, sizeof(g_szVBoxErrMsg));
     248
    194249    /*
    195250     * If the user specifies the location, try only that.
    196251     */
    197     const char *pszHome = getenv("VBOX_APP_HOME");
     252    pszHome = getenv("VBOX_APP_HOME");
    198253    if (pszHome)
    199         return tryLoadOne(pszHome, 0);
     254        return tryLoadLibrary(pszHome, 0);
    200255
    201256    /*
    202257     * Try the known standard locations.
    203258     */
    204     g_szVBoxErrMsg[0] = '\0';
    205259#if defined(__gnu__linux__) || defined(__linux__)
    206     if (tryLoadOne("/opt/VirtualBox", 1) == 0)
    207         return 0;
    208     if (tryLoadOne("/usr/lib/virtualbox", 1) == 0)
     260    if (tryLoadLibrary("/opt/VirtualBox", 1) == 0)
     261        return 0;
     262    if (tryLoadLibrary("/usr/lib/virtualbox", 1) == 0)
    209263        return 0;
    210264#elif defined(__sun__)
    211     if (tryLoadOne("/opt/VirtualBox/amd64", 1) == 0)
    212         return 0;
    213     if (tryLoadOne("/opt/VirtualBox/i386", 1) == 0)
     265    if (tryLoadLibrary("/opt/VirtualBox/amd64", 1) == 0)
     266        return 0;
     267    if (tryLoadLibrary("/opt/VirtualBox/i386", 1) == 0)
    214268        return 0;
    215269#elif defined(__APPLE__)
    216     if (tryLoadOne("/Application/VirtualBox.app/Contents/MacOS", 1) == 0)
     270    if (tryLoadLibrary("/Application/VirtualBox.app/Contents/MacOS", 1) == 0)
    217271        return 0;
    218272#elif defined(__FreeBSD__)
    219     if (tryLoadOne("/usr/local/lib/virtualbox", 1) == 0)
     273    if (tryLoadLibrary("/usr/local/lib/virtualbox", 1) == 0)
    220274        return 0;
    221275#elif defined(__OS2__)
    222     if (tryLoadOne("C:/Apps/VirtualBox", 1) == 0)
     276    if (tryLoadLibrary("C:/Apps/VirtualBox", 1) == 0)
     277        return 0;
     278#elif defined(WIN32)
     279    pszHome = getenv("ProgramFiles");
     280    if (pszHome)
     281    {
     282        char szPath[4096];
     283        size_t cb = sizeof(szPath);
     284        char *tmp = szPath;
     285        strncpy(tmp, pszHome, cb);
     286        tmp[cb - 1] = '\0';
     287        cb -= strlen(tmp);
     288        tmp += strlen(tmp);
     289        strncpy(tmp, "/Oracle/VirtualBox", cb);
     290        tmp[cb - 1] = '\0';
     291        if (tryLoadLibrary(szPath, 1) == 0)
     292            return 0;
     293    }
     294    if (tryLoadLibrary("C:/Program Files/Oracle/VirtualBox", 1) == 0)
    223295        return 0;
    224296#else
     
    229301     * Finally try the dynamic linker search path.
    230302     */
    231     if (tryLoadOne(NULL, 1) == 0)
     303    if (tryLoadLibrary(NULL, 1) == 0)
    232304        return 0;
    233305
     
    242314void VBoxCGlueTerm(void)
    243315{
    244     if (g_hVBoxXPCOMC)
     316    if (g_hVBoxCAPI)
    245317    {
    246318#if 0 /* VBoxRT.so doesn't like being reloaded. See @bugref{3725}. */
    247         dlclose(g_hVBoxXPCOMC);
     319#ifndef WIN32
     320        dlclose(g_hVBoxCAPI);
     321#else
     322        FreeLibrary(g_hVBoxCAPI);
    248323#endif
    249         g_hVBoxXPCOMC = NULL;
     324#endif
     325        g_hVBoxCAPI = NULL;
    250326    }
    251327    g_pVBoxFuncs = NULL;
  • trunk/src/VBox/Main/cbinding/VBoxCAPIGlue.h.in

    r49984 r50183  
    11/* $Revision$ */
    2 /** @file VBoxXPCOMCGlue.h
    3  * Glue for dynamically linking with VBoxXPCOMC.
     2/** @file VBoxCAPIGlue.h
     3 * Glue for dynamically linking with VBoxCAPI.
    44 */
    55
    66/*
    7  * Copyright (C) 2008-2012 Oracle Corporation
     7 * Copyright (C) 2008-2014 Oracle Corporation
    88 *
    99 * Permission is hereby granted, free of charge, to any person
     
    2929 */
    3030
    31 #ifndef ___VBoxXPCOMC_cglue_h
    32 #define ___VBoxXPCOMC_cglue_h
     31#ifndef ___VBoxCAPIGlue_h
     32#define ___VBoxCAPIGlue_h
    3333
     34#undef VBOX_WITH_GLUE
     35#define VBOX_WITH_GLUE
    3436#include "VBoxCAPI_v@[email protected]"
    3537
     
    3840#endif
    3941
    40 /** The dlopen handle for VBoxXPCOMC. */
    41 extern void *g_hVBoxXPCOMC;
     42/** The so/dynsym/dll handle for VBoxCAPI. */
     43#ifndef WIN32
     44extern void *g_hVBoxCAPI;
     45#else
     46extern HMODULE g_hVBoxCAPI;
     47#endif
    4248/** The last load error. */
    4349extern char g_szVBoxErrMsg[256];
    44 /** Pointer to the VBoxXPCOMC function table. */
    45 extern PCVBOXXPCOM g_pVBoxFuncs;
    46 /** Pointer to VBoxGetXPCOMCFunctions for the loaded VBoxXPCOMC so/dylib/dll. */
    47 extern PFNVBOXGETXPCOMCFUNCTIONS g_pfnGetFunctions;
     50/** Pointer to the VBOXCAPI function table. */
     51extern PCVBOXCAPI g_pVBoxFuncs;
     52/** Pointer to VBoxGetCAPIFunctions for the loaded VBoxCAPI so/dylib/dll. */
     53extern PFNVBOXGETCAPIFUNCTIONS g_pfnGetFunctions;
    4854
    4955
  • trunk/src/VBox/Main/cbinding/capiidl.xsl

    r49984 r50183  
    33
    44<!--
    5  *  A template to generate a XPCOM IDL compatible interface definition file
    6  *  from the generic interface definition expressed in XML.
    7 
    8     Copyright (C) 2008-2013 Oracle Corporation
     5 *  A template to generate a C header file for all relevant XPCOM interfaces
     6 *  provided or needed for calling the VirtualBox API. The header file also
     7 *  works on Windows, by using the C bindings header created by the MS COM IDL
     8 *  compiler (which simultaneously supports C and C++, unlike XPCOM).
     9
     10    Copyright (C) 2008-2014 Oracle Corporation
    911
    1012    This file is part of VirtualBox Open Source Edition (OSE), as
     
    100102-->
    101103<xsl:template match="/idl">
    102   <xsl:text>
    103 /*
     104  <xsl:text>/*
    104105 *  DO NOT EDIT! This is a generated file.
    105106 *
    106  *  XPCOM IDL (XPIDL) definition for VirtualBox Main API (COM interfaces)
    107  *  generated from XIDL (XML interface definition).
     107 *  Header file which provides C declarations for VirtualBox Main API
     108 *  (COM interfaces), generated from XIDL (XML interface definition).
     109 *  On Windows (which uses COM instead of XPCOM) the native C support
     110 *  is used, and most of this file is not used.
    108111 *
    109112 *  Source    : src/VBox/Main/idl/VirtualBox.xidl
    110  *  Generator : src/VBox/Main/idl/xpcidl.xsl
     113 *  Generator : src/VBox/Main/cbinding/capiidl.xsl
    111114 *
    112115 *  This file contains portions from the following Mozilla XPCOM files:
     
    121124
    122125/*
    123  * Copyright (C) 2008-2012 Oracle Corporation
     126 * Copyright (C) 2008-2014 Oracle Corporation
    124127 *
    125128 * This file is part of a free software library; you can redistribute
     
    140143 */
    141144
    142 #ifndef ___VirtualBox_CXPCOM_h
    143 #define ___VirtualBox_CXPCOM_h
     145#ifndef ___VirtualBox_CAPI_h
     146#define ___VirtualBox_CAPI_h
     147
     148#ifdef _WIN32
     149# undef COBJMACROS
     150# define COBJMACROS
     151# include "Windows.h"
     152#endif /* _WIN32 */
     153
     154#ifdef WIN32
     155# ifdef IN_VBOXCAPI
     156#  define VBOXCAPI_DECL(type) extern __declspec(dllexport) type
     157# else /* !IN_VBOXCAPI */
     158#  define VBOXCAPI_DECL(type) __declspec(dllimport) type
     159# endif /* !IN_VBOXCAPI */
     160#endif /* WIN32 */
    144161
    145162#ifdef __cplusplus
    146 # include "VirtualBox_XPCOM.h"
    147 #else /* !__cplusplus */
     163/* The C++ treatment in this file is not meant for SDK users, it only exists
     164 * so that this file can be used to produce the VBoxCAPI shared library which
     165 * has to use C++ as it does all the conversion magic. */
     166# ifdef IN_VBOXCAPI
     167#  include "VBox/com/VirtualBox.h"
     168#  ifndef WIN32
     169#   include "nsIEventQueue.h"
     170#  endif /* !WIN32 */
     171# else /* !IN_VBOXCAPI */
     172#  error Do not include this header file from C++ code
     173# endif /* !IN_VBOXCAPI */
     174#endif /* __cplusplus */
     175
     176#ifdef __GNUC__
     177# define VBOX_EXTERN_CONST(type, name) extern const type name __attribute__((nocommon))
     178#else /* !__GNUC__ */
     179# define VBOX_EXTERN_CONST(type, name) extern const type name
     180#endif /* !__GNUC__ */
     181
     182/* Treat WIN32 completely separately, as on Windows VirtualBox uses COM, not
     183 * XPCOM like on all other platforms. While the code below would also compile
     184 * on Windows, we need to switch to the native C support provided by the header
     185 * files produced by the COM IDL compiler. */
     186#ifdef WIN32
     187# include "ObjBase.h"
     188# include "oaidl.h"
     189# include "VirtualBox.h"
     190
     191typedef const BSTR CBSTR;
     192
     193#define ComSafeArrayAsInParam(f) (f)
     194#define ComSafeArrayAsOutParam(f) (&amp;(f))
     195#define ComSafeArrayAsOutIfaceParam(f) (&amp;(f))
     196
     197#else /* !WIN32 */
    148198
    149199#include &lt;stddef.h&gt;
    150200#include "wchar.h"
     201
     202#ifdef IN_VBOXCAPI
     203# define VBOXCAPI_DECL(type) PR_EXPORT(type)
     204#else /* !IN_VBOXCAPI */
     205# define VBOXCAPI_DECL(type) PR_IMPORT(type)
     206#endif /* !IN_VBOXCAPI */
     207
     208#ifndef __cplusplus
    151209
    152210#if defined(WIN32)
     
    361419typedef PRUint16 PRUnichar;
    362420#endif
     421typedef PRUnichar *BSTR;
     422typedef const PRUnichar *CBSTR;
    363423#endif
    364424
     
    721781#define NS_ERROR_FACTORY_EXISTS            (NS_ERROR_BASE + 0x100)
    722782
    723 
    724783/**
    725784 * An "interface id" which can be used to uniquely identify a given
     
    729788
    730789struct nsID {
    731   PRUint32 m0;
    732   PRUint16 m1;
    733   PRUint16 m2;
    734   PRUint8 m3[8];
     790    PRUint32 m0;
     791    PRUint16 m1;
     792    PRUint16 m2;
     793    PRUint8 m3[8];
    735794};
    736795
    737796typedef struct nsID nsID;
    738797typedef nsID nsIID;
     798typedef nsID nsCID;
     799
     800#endif /* __cplusplus */
     801
     802
     803/* Various COM types defined by their XPCOM equivalent */
     804typedef PRInt64 LONG64;
     805typedef PRInt32 LONG;
     806typedef PRInt32 DWORD;
     807typedef PRInt16 SHORT;
     808typedef PRUint64 ULONG64;
     809typedef PRUint32 ULONG;
     810typedef PRUint16 USHORT;
     811
     812typedef PRBool BOOL;
     813
     814#ifndef FALSE
     815#define FALSE 0
     816#define TRUE 1
     817#endif
     818
     819#define HRESULT nsresult
     820#define SUCCEEDED NS_SUCCEEDED
     821#define FAILED NS_FAILED
     822
     823/* OLE error codes */
     824#define S_OK                ((nsresult)NS_OK)
     825#define E_UNEXPECTED        NS_ERROR_UNEXPECTED
     826#define E_NOTIMPL           NS_ERROR_NOT_IMPLEMENTED
     827#define E_OUTOFMEMORY       NS_ERROR_OUT_OF_MEMORY
     828#define E_INVALIDARG        NS_ERROR_INVALID_ARG
     829#define E_NOINTERFACE       NS_ERROR_NO_INTERFACE
     830#define E_POINTER           NS_ERROR_NULL_POINTER
     831#define E_ABORT             NS_ERROR_ABORT
     832#define E_FAIL              NS_ERROR_FAILURE
     833/* Note: a better analog for E_ACCESSDENIED would probably be
     834 * NS_ERROR_NOT_AVAILABLE, but we want binary compatibility for now. */
     835#define E_ACCESSDENIED      ((nsresult)0x80070005L)
     836
     837/* Basic vartype for COM compatibility. */
     838typedef enum VARTYPE
     839{
     840    VT_I2 = 2,
     841    VT_I4 = 3,
     842    VT_BSTR = 8,
     843    VT_DISPATCH = 9,
     844    VT_BOOL = 11,
     845    VT_UNKNOWN = 13,
     846    VT_I1 = 16,
     847    VT_UI1 = 17,
     848    VT_UI2 = 18,
     849    VT_UI4 = 19,
     850    VT_I8 = 20,
     851    VT_UI8 = 21,
     852    VT_HRESULT = 25
     853} VARTYPE;
     854
     855/* Basic safearray type for COM compatibility. */
     856typedef struct SAFEARRAY
     857{
     858    void *pv;
     859    ULONG c;
     860} SAFEARRAY;
     861
     862#define ComSafeArrayAsInParam(f) ((f)->c), ((f)->pv)
     863#define ComSafeArrayAsOutParam(f) (&amp;((f)->c)), (&amp;((f)->pv))
     864#define ComSafeArrayAsOutIfaceParam(f,t) (&amp;((f)->c)), (t**)(&amp;((f)->pv))
     865
     866/* Glossing over differences between COM and XPCOM */
     867#define IErrorInfo nsIException
     868#define IUnknown nsISupports
     869#define IDispatch nsISupports
     870
     871#ifndef __cplusplus
    739872
    740873struct nsISupports;   /* forward declaration */
     
    745878typedef struct nsIException nsIException;   /* forward declaration */
    746879
    747 /**
    748  * IID for the nsISupports interface
    749  * {00000000-0000-0000-c000-000000000046}
    750  *
    751  * To maintain binary compatibility with COM's IUnknown, we define the IID
    752  * of nsISupports to be the same as that of COM's IUnknown.
    753  */
    754 #define NS_ISUPPORTS_IID                                                      \
    755   { 0x00000000, 0x0000, 0x0000,                                               \
    756     {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }
     880/* starting interface:    nsISupports */
     881#define NS_ISUPPORTS_IID_STR "00000000-0000-0000-c000-000000000046"
     882
     883#define NS_ISUPPORTS_IID \
     884    { 0x00000000, 0x0000, 0x0000, \
     885      {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }
    757886
    758887/**
     
    764893 * IUnknown.
    765894 */
     895#if defined(XP_WIN) &amp;&amp; PR_BYTES_PER_LONG == 4
     896typedef unsigned long nsrefcnt;
     897#else
     898typedef PRUint32 nsrefcnt;
     899#endif
    766900
    767901/**
     
    771905 * modelled after the win32 IUnknown API.
    772906 */
    773 struct nsISupports_vtbl {
    774 
    775   /**
    776    * @name Methods
    777    */
    778 
    779   /**
    780    * A run time mechanism for interface discovery.
    781    * @param aIID         [in]  A requested interface IID
    782    * @param aInstancePtr [out] A pointer to an interface pointer to
    783    *                           receive the result.
    784    * @return            NS_OK if the interface is supported by the associated
    785    *                          instance, NS_NOINTERFACE if it is not.
    786    * NS_ERROR_INVALID_POINTER if aInstancePtr is NULL.
    787    */
    788   nsresult (*QueryInterface)(nsISupports *pThis, const nsID *iid, void **resultp);
    789   /**
    790    * Increases the reference count for this interface.
    791    * The associated instance will not be deleted unless
    792    * the reference count is returned to zero.
    793    *
    794    * @return The resulting reference count.
    795    */
    796   nsresult (*AddRef)(nsISupports *pThis);
    797 
    798   /**
    799    * Decreases the reference count for this interface.
    800    * Generally, if the reference count returns to zero,
    801    * the associated instance is deleted.
    802    *
    803    * @return The resulting reference count.
    804    */
    805   nsresult (*Release)(nsISupports *pThis);
    806 
     907#ifndef VBOX_WITH_GLUE
     908struct nsISupports_vtbl
     909{
     910    nsresult (*QueryInterface)(nsISupports *pThis, const nsID *iid, void **resultp);
     911    nsrefcnt (*AddRef)(nsISupports *pThis);
     912    nsrefcnt (*Release)(nsISupports *pThis);
    807913};
    808 
    809 struct nsISupports {
     914#else /* !VBOX_WITH_GLUE */
     915struct nsISupportsVtbl
     916{
     917    nsresult (*QueryInterface)(nsISupports *pThis, const nsID *iid, void **resultp);
     918    nsrefcnt (*AddRef)(nsISupports *pThis);
     919    nsrefcnt (*Release)(nsISupports *pThis);
     920};
     921#define nsISupports_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     922#define nsISupports_AddRef(p) ((p)->lpVtbl->AddRef(p))
     923#define nsISupports_Release(p) ((p)->lpVtbl->Release(p))
     924#define IUnknown_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     925#define IUnknown_AddRef(p) ((p)->lpVtbl->AddRef(p))
     926#define IUnknown_Release(p) ((p)->lpVtbl->Release(p))
     927#define IDispatch_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     928#define IDispatch_AddRef(p) ((p)->lpVtbl->AddRef(p))
     929#define IDispatch_Release(p) ((p)->lpVtbl->Release(p))
     930#endif /* !VBOX_WITH_GLUE */
     931
     932struct nsISupports
     933{
     934#ifndef VBOX_WITH_GLUE
    810935    struct nsISupports_vtbl *vtbl;
     936#else /* !VBOX_WITH_GLUE */
     937    struct nsISupportsVtbl *lpVtbl;
     938#endif /* !VBOX_WITH_GLUE */
    811939};
    812940
     
    815943
    816944#define NS_IEXCEPTION_IID \
    817   {0xf3a8d3b4, 0xc424, 0x4edc, \
    818     { 0x8b, 0xf6, 0x89, 0x74, 0xc9, 0x83, 0xba, 0x78 }}
    819 
    820 struct nsIException_vtbl {
    821 
    822   /* Methods from the Class nsISupports */
    823   struct nsISupports_vtbl nsisupports;
    824 
    825   /* readonly attribute string message; */
    826   nsresult (*GetMessage)(nsIException *pThis, PRUnichar * *aMessage);
    827 
    828   /* readonly attribute nsresult (*result; */
    829   nsresult (*GetResult)(nsIException *pThis, nsresult *aResult);
    830 
    831   /* readonly attribute string name; */
    832   nsresult (*GetName)(nsIException *pThis, PRUnichar * *aName);
    833 
    834   /* readonly attribute string filename; */
    835   nsresult (*GetFilename)(nsIException *pThis, PRUnichar * *aFilename);
    836 
    837   /* readonly attribute PRUint32 lineNumber; */
    838   nsresult (*GetLineNumber)(nsIException *pThis, PRUint32 *aLineNumber);
    839 
    840   /* readonly attribute PRUint32 columnNumber; */
    841   nsresult (*GetColumnNumber)(nsIException *pThis, PRUint32 *aColumnNumber);
    842 
    843   /* readonly attribute nsIStackFrame location; */
    844   nsresult (*GetLocation)(nsIException *pThis, nsIStackFrame * *aLocation);
    845 
    846   /* readonly attribute nsIException inner; */
    847   nsresult (*GetInner)(nsIException *pThis, nsIException * *aInner);
    848 
    849   /* readonly attribute nsISupports data; */
    850   nsresult (*GetData)(nsIException *pThis, nsISupports * *aData);
    851 
    852   /* string toString (); */
    853   nsresult (*ToString)(nsIException *pThis, PRUnichar **_retval);
     945    {0xf3a8d3b4, 0xc424, 0x4edc, \
     946      { 0x8b, 0xf6, 0x89, 0x74, 0xc9, 0x83, 0xba, 0x78 }}
     947
     948#ifndef VBOX_WITH_GLUE
     949struct nsIException_vtbl
     950{
     951    /* Methods from the interface nsISupports */
     952    struct nsISupports_vtbl nsisupports;
     953
     954    nsresult (*GetMessage)(nsIException *pThis, PRUnichar * *aMessage);
     955    nsresult (*GetResult)(nsIException *pThis, nsresult *aResult);
     956    nsresult (*GetName)(nsIException *pThis, PRUnichar * *aName);
     957    nsresult (*GetFilename)(nsIException *pThis, PRUnichar * *aFilename);
     958    nsresult (*GetLineNumber)(nsIException *pThis, PRUint32 *aLineNumber);
     959    nsresult (*GetColumnNumber)(nsIException *pThis, PRUint32 *aColumnNumber);
     960    nsresult (*GetLocation)(nsIException *pThis, nsIStackFrame * *aLocation);
     961    nsresult (*GetInner)(nsIException *pThis, nsIException * *aInner);
     962    nsresult (*GetData)(nsIException *pThis, nsISupports * *aData);
     963    nsresult (*ToString)(nsIException *pThis, PRUnichar **_retval);
    854964};
    855 
    856 struct nsIException {
     965#else /* !VBOX_WITH_GLUE */
     966struct nsIExceptionVtbl
     967{
     968    nsresult (*QueryInterface)(nsIException *pThis, const nsID *iid, void **resultp);
     969    nsrefcnt (*AddRef)(nsIException *pThis);
     970    nsrefcnt (*Release)(nsIException *pThis);
     971
     972    nsresult (*GetMessage)(nsIException *pThis, PRUnichar * *aMessage);
     973    nsresult (*GetResult)(nsIException *pThis, nsresult *aResult);
     974    nsresult (*GetName)(nsIException *pThis, PRUnichar * *aName);
     975    nsresult (*GetFilename)(nsIException *pThis, PRUnichar * *aFilename);
     976    nsresult (*GetLineNumber)(nsIException *pThis, PRUint32 *aLineNumber);
     977    nsresult (*GetColumnNumber)(nsIException *pThis, PRUint32 *aColumnNumber);
     978    nsresult (*GetLocation)(nsIException *pThis, nsIStackFrame * *aLocation);
     979    nsresult (*GetInner)(nsIException *pThis, nsIException * *aInner);
     980    nsresult (*GetData)(nsIException *pThis, nsISupports * *aData);
     981    nsresult (*ToString)(nsIException *pThis, PRUnichar **_retval);
     982};
     983#define nsIException_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     984#define nsIException_AddRef(p) ((p)->lpVtbl->AddRef(p))
     985#define nsIException_Release(p) ((p)->lpVtbl->Release(p))
     986#define nsIException_get_Message(p, aMessage) ((p)->lpVtbl->GetMessage(p, aMessage))
     987#define nsIException_GetMessage(p, aMessage) ((p)->lpVtbl->GetMessage(p, aMessage))
     988#define nsIException_get_Result(p, aResult) ((p)->lpVtbl->GetResult(p, aResult))
     989#define nsIException_GetResult(p, aResult) ((p)->lpVtbl->GetResult(p, aResult))
     990#define nsIException_get_Name(p, aName) ((p)->lpVtbl->GetName(p, aName))
     991#define nsIException_GetName(p, aName) ((p)->lpVtbl->GetName(p, aName))
     992#define nsIException_get_Filename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))
     993#define nsIException_GetFilename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))
     994#define nsIException_get_LineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))
     995#define nsIException_GetLineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))
     996#define nsIException_get_ColumnNumber(p, aColumnNumber) ((p)->lpVtbl->GetColumnNumber(p, aColumnNumber))
     997#define nsIException_GetColumnNumber(p, aColumnNumber) ((p)->lpVtbl->GetColumnNumber(p, aColumnNumber))
     998#define nsIException_get_Inner(p, aInner) ((p)->lpVtbl->GetInner(p, aInner))
     999#define nsIException_GetInner(p, aInner) ((p)->lpVtbl->GetInner(p, aInner))
     1000#define nsIException_get_Data(p, aData) ((p)->lpVtbl->GetData(p, aData))
     1001#define nsIException_GetData(p, aData) ((p)->lpVtbl->GetData(p, aData))
     1002#define nsIException_ToString(p, retval) ((p)->lpVtbl->ToString(p, retval))
     1003#define IErrorInfo_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     1004#define IErrorInfo_AddRef(p) ((p)->lpVtbl->AddRef(p))
     1005#define IErrorInfo_Release(p) ((p)->lpVtbl->Release(p))
     1006#define IErrorInfo_get_Message(p, aMessage) ((p)->lpVtbl->GetMessage(p, aMessage))
     1007#define IErrorInfo_GetMessage(p, aMessage) ((p)->lpVtbl->GetMessage(p, aMessage))
     1008#define IErrorInfo_get_Result(p, aResult) ((p)->lpVtbl->GetResult(p, aResult))
     1009#define IErrorInfo_GetResult(p, aResult) ((p)->lpVtbl->GetResult(p, aResult))
     1010#define IErrorInfo_get_Name(p, aName) ((p)->lpVtbl->GetName(p, aName))
     1011#define IErrorInfo_GetName(p, aName) ((p)->lpVtbl->GetName(p, aName))
     1012#define IErrorInfo_get_Filename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))
     1013#define IErrorInfo_GetFilename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))
     1014#define IErrorInfo_get_LineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))
     1015#define IErrorInfo_GetLineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))
     1016#define IErrorInfo_get_ColumnNumber(p, aColumnNumber) ((p)->lpVtbl->GetColumnNumber(p, aColumnNumber))
     1017#define IErrorInfo_GetColumnNumber(p, aColumnNumber) ((p)->lpVtbl->GetColumnNumber(p, aColumnNumber))
     1018#define IErrorInfo_get_Inner(p, aInner) ((p)->lpVtbl->GetInner(p, aInner))
     1019#define IErrorInfo_GetInner(p, aInner) ((p)->lpVtbl->GetInner(p, aInner))
     1020#define IErrorInfo_get_Data(p, aData) ((p)->lpVtbl->GetData(p, aData))
     1021#define IErrorInfo_GetData(p, aData) ((p)->lpVtbl->GetData(p, aData))
     1022#define IErrorInfo_ToString(p, retval) ((p)->lpVtbl->ToString(p, retval))
     1023#endif /* !VBOX_WITH_GLUE */
     1024
     1025struct nsIException
     1026{
     1027#ifndef VBOX_WITH_GLUE
    8571028    struct nsIException_vtbl *vtbl;
     1029#else /* !VBOX_WITH_GLUE */
     1030    struct nsIExceptionVtbl *lpVtbl;
     1031#endif /* !VBOX_WITH_GLUE */
    8581032};
    8591033
     
    8621036
    8631037#define NS_ISTACKFRAME_IID \
    864   {0x91d82105, 0x7c62, 0x4f8b, \
    865     { 0x97, 0x79, 0x15, 0x42, 0x77, 0xc0, 0xee, 0x90 }}
    866 
    867 struct nsIStackFrame_vtbl {
    868 
    869   /* Methods from the Class nsISupports */
    870   struct nsISupports_vtbl nsisupports;
    871 
    872   /* readonly attribute PRUint32 language; */
    873   nsresult (*GetLanguage)(nsIStackFrame *pThis, PRUint32 *aLanguage);
    874 
    875   /* readonly attribute string languageName; */
    876   nsresult (*GetLanguageName)(nsIStackFrame *pThis, PRUnichar * *aLanguageName);
    877 
    878   /* readonly attribute string filename; */
    879   nsresult (*GetFilename)(nsIStackFrame *pThis, PRUnichar * *aFilename);
    880 
    881   /* readonly attribute string name; */
    882   nsresult (*GetName)(nsIStackFrame *pThis, PRUnichar * *aName);
    883 
    884   /* readonly attribute PRInt32 lineNumber; */
    885   nsresult (*GetLineNumber)(nsIStackFrame *pThis, PRInt32 *aLineNumber);
    886 
    887   /* readonly attribute string sourceLine; */
    888   nsresult (*GetSourceLine)(nsIStackFrame *pThis, PRUnichar * *aSourceLine);
    889 
    890   /* readonly attribute nsIStackFrame caller; */
    891   nsresult (*GetCaller)(nsIStackFrame *pThis, nsIStackFrame * *aCaller);
    892 
    893   /* string toString (); */
    894   nsresult (*ToString)(nsIStackFrame *pThis, PRUnichar **_retval);
     1038    {0x91d82105, 0x7c62, 0x4f8b, \
     1039      { 0x97, 0x79, 0x15, 0x42, 0x77, 0xc0, 0xee, 0x90 }}
     1040
     1041#ifndef VBOX_WITH_GLUE
     1042struct nsIStackFrame_vtbl
     1043{
     1044    /* Methods from the interface nsISupports */
     1045    struct nsISupports_vtbl nsisupports;
     1046
     1047    nsresult (*GetLanguage)(nsIStackFrame *pThis, PRUint32 *aLanguage);
     1048    nsresult (*GetLanguageName)(nsIStackFrame *pThis, PRUnichar * *aLanguageName);
     1049    nsresult (*GetFilename)(nsIStackFrame *pThis, PRUnichar * *aFilename);
     1050    nsresult (*GetName)(nsIStackFrame *pThis, PRUnichar * *aName);
     1051    nsresult (*GetLineNumber)(nsIStackFrame *pThis, PRInt32 *aLineNumber);
     1052    nsresult (*GetSourceLine)(nsIStackFrame *pThis, PRUnichar * *aSourceLine);
     1053    nsresult (*GetCaller)(nsIStackFrame *pThis, nsIStackFrame * *aCaller);
     1054    nsresult (*ToString)(nsIStackFrame *pThis, PRUnichar **_retval);
    8951055};
    896 
    897 struct nsIStackFrame {
     1056#else /* !VBOX_WITH_GLUE */
     1057struct nsIStackFrameVtbl
     1058{
     1059    nsresult (*QueryInterface)(nsIStackFrame *pThis, const nsID *iid, void **resultp);
     1060    nsrefcnt (*AddRef)(nsIStackFrame *pThis);
     1061    nsrefcnt (*Release)(nsIStackFrame *pThis);
     1062
     1063    nsresult (*GetLanguage)(nsIStackFrame *pThis, PRUint32 *aLanguage);
     1064    nsresult (*GetLanguageName)(nsIStackFrame *pThis, PRUnichar * *aLanguageName);
     1065    nsresult (*GetFilename)(nsIStackFrame *pThis, PRUnichar * *aFilename);
     1066    nsresult (*GetName)(nsIStackFrame *pThis, PRUnichar * *aName);
     1067    nsresult (*GetLineNumber)(nsIStackFrame *pThis, PRInt32 *aLineNumber);
     1068    nsresult (*GetSourceLine)(nsIStackFrame *pThis, PRUnichar * *aSourceLine);
     1069    nsresult (*GetCaller)(nsIStackFrame *pThis, nsIStackFrame * *aCaller);
     1070    nsresult (*ToString)(nsIStackFrame *pThis, PRUnichar **_retval);
     1071};
     1072#define nsIStackFrame_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     1073#define nsIStackFrame_AddRef(p) ((p)->lpVtbl->AddRef(p))
     1074#define nsIStackFrame_Release(p) ((p)->lpVtbl->Release(p))
     1075#define nsIStackFrame_get_Language(p, aLanguage) ((p)->lpVtbl->GetLanguge(p, aLanguage))
     1076#define nsIStackFrame_GetLanguage(p, aLanguage) ((p)->lpVtbl->GetLanguge(p, aLanguage))
     1077#define nsIStackFrame_get_LanguageName(p, aLanguageName) ((p)->lpVtbl->GetLanguageName(p, aLanguageName))
     1078#define nsIStackFrame_GetLanguageName(p, aLanguageName) ((p)->lpVtbl->GetLanguageName(p, aLanguageName))
     1079#define nsIStackFrame_get_Filename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))
     1080#define nsIStackFrame_GetFilename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))
     1081#define nsIStackFrame_get_Name(p, aName) ((p)->lpVtbl->GetName(p, aName))
     1082#define nsIStackFrame_GetName(p, aName) ((p)->lpVtbl->GetName(p, aName))
     1083#define nsIStackFrame_get_LineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))
     1084#define nsIStackFrame_GetLineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))
     1085#define nsIStackFrame_get_SourceLine(p, aSourceLine) ((p)->lpVtbl->GetSourceLine(p, aSourceLine))
     1086#define nsIStackFrame_GetSourceLine(p, aSourceLine) ((p)->lpVtbl->GetSourceLine(p, aSourceLine))
     1087#define nsIStackFrame_get_Caller(p, aCaller) ((p)->lpVtbl->GetCaller(p, aCaller))
     1088#define nsIStackFrame_GetCaller(p, aCaller) ((p)->lpVtbl->GetCaller(p, aCaller))
     1089#define nsIStackFrame_ToString(p, retval) ((p)->lpVtbl->ToString(p, retval))
     1090#endif /* !VBOX_WITH_GLUE */
     1091
     1092struct nsIStackFrame
     1093{
     1094#ifndef VBOX_WITH_GLUE
    8981095    struct nsIStackFrame_vtbl *vtbl;
     1096#else /* !VBOX_WITH_GLUE */
     1097    struct nsIStackFrameVtbl *lpVtbl;
     1098#endif /* !VBOX_WITH_GLUE */
    8991099};
    9001100
     
    9031103
    9041104#define NS_IEVENTTARGET_IID \
    905   {0xea99ad5b, 0xcc67, 0x4efb, \
    906     { 0x97, 0xc9, 0x2e, 0xf6, 0x20, 0xa5, 0x9f, 0x2a }}
     1105    {0xea99ad5b, 0xcc67, 0x4efb, \
     1106      { 0x97, 0xc9, 0x2e, 0xf6, 0x20, 0xa5, 0x9f, 0x2a }}
    9071107
    9081108struct nsIEventTarget;
    9091109typedef struct nsIEventTarget nsIEventTarget;
    9101110
    911 struct nsIEventTarget_vtbl {
    912 
     1111#ifndef VBOX_WITH_GLUE
     1112struct nsIEventTarget_vtbl
     1113{
    9131114    struct nsISupports_vtbl nsisupports;
    9141115
    9151116    nsresult (*PostEvent)(nsIEventTarget *pThis, PLEvent * aEvent);
    916 
    9171117    nsresult (*IsOnCurrentThread)(nsIEventTarget *pThis, PRBool *_retval);
    918 
    9191118};
    920 
    921 struct nsIEventTarget {
     1119#else /* !VBOX_WITH_GLUE */
     1120struct nsIEventTargetVtbl
     1121{
     1122    nsresult (*QueryInterface)(nsIEventTarget *pThis, const nsID *iid, void **resultp);
     1123    nsrefcnt (*AddRef)(nsIEventTarget *pThis);
     1124    nsrefcnt (*Release)(nsIEventTarget *pThis);
     1125
     1126    nsresult (*PostEvent)(nsIEventTarget *pThis, PLEvent * aEvent);
     1127    nsresult (*IsOnCurrentThread)(nsIEventTarget *pThis, PRBool *_retval);
     1128};
     1129#define nsIEventTarget_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     1130#define nsIEventTarget_AddRef(p) ((p)->lpVtbl->AddRef(p))
     1131#define nsIEventTarget_Release(p) ((p)->lpVtbl->Release(p))
     1132#define nsIEventTarget_PostEvent(p, aEvent) ((p)->lpVtbl->PostEvent(p, aEvent))
     1133#define nsIEventTarget_IsOnCurrentThread(p, retval) ((p)->lpVtbl->IsOnCurrentThread(p, retval))
     1134#endif /* !VBOX_WITH_GLUE */
     1135
     1136struct nsIEventTarget
     1137{
     1138#ifndef VBOX_WITH_GLUE
    9221139    struct nsIEventTarget_vtbl *vtbl;
     1140#else /* !VBOX_WITH_GLUE */
     1141    struct nsIEventTargetVtbl *lpVtbl;
     1142#endif /* !VBOX_WITH_GLUE */
    9231143};
    9241144
     
    9331153typedef struct nsIEventQueue nsIEventQueue;
    9341154
    935 struct nsIEventQueue_vtbl {
    936 
     1155#ifndef VBOX_WITH_GLUE
     1156struct nsIEventQueue_vtbl
     1157{
    9371158    struct nsIEventTarget_vtbl nsieventtarget;
    9381159
    9391160    nsresult (*InitEvent)(nsIEventQueue *pThis, PLEvent * aEvent, void * owner, PLHandleEventProc handler, PLDestroyEventProc destructor);
    940 
    9411161    nsresult (*PostSynchronousEvent)(nsIEventQueue *pThis, PLEvent * aEvent, void * *aResult);
    942 
    9431162    nsresult (*PendingEvents)(nsIEventQueue *pThis, PRBool *_retval);
    944 
    9451163    nsresult (*ProcessPendingEvents)(nsIEventQueue *pThis);
    946 
    9471164    nsresult (*EventLoop)(nsIEventQueue *pThis);
    948 
    9491165    nsresult (*EventAvailable)(nsIEventQueue *pThis, PRBool *aResult);
    950 
    9511166    nsresult (*GetEvent)(nsIEventQueue *pThis, PLEvent * *_retval);
    952 
    9531167    nsresult (*HandleEvent)(nsIEventQueue *pThis, PLEvent * aEvent);
    954 
    9551168    nsresult (*WaitForEvent)(nsIEventQueue *pThis, PLEvent * *_retval);
    956 
    9571169    PRInt32 (*GetEventQueueSelectFD)(nsIEventQueue *pThis);
    958 
    9591170    nsresult (*Init)(nsIEventQueue *pThis, PRBool aNative);
    960 
    9611171    nsresult (*InitFromPRThread)(nsIEventQueue *pThis, PRThread * thread, PRBool aNative);
    962 
    9631172    nsresult (*InitFromPLQueue)(nsIEventQueue *pThis, PLEventQueue * aQueue);
    964 
    9651173    nsresult (*EnterMonitor)(nsIEventQueue *pThis);
    966 
    9671174    nsresult (*ExitMonitor)(nsIEventQueue *pThis);
    968 
    9691175    nsresult (*RevokeEvents)(nsIEventQueue *pThis, void * owner);
    970 
    9711176    nsresult (*GetPLEventQueue)(nsIEventQueue *pThis, PLEventQueue * *_retval);
    972 
    9731177    nsresult (*IsQueueNative)(nsIEventQueue *pThis, PRBool *_retval);
    974 
    9751178    nsresult (*StopAcceptingEvents)(nsIEventQueue *pThis);
    976 
    9771179};
    978 
    979 struct nsIEventQueue {
     1180#else /* !VBOX_WITH_GLUE */
     1181struct nsIEventQueueVtbl
     1182{
     1183    nsresult (*QueryInterface)(nsIEventQueue *pThis, const nsID *iid, void **resultp);
     1184    nsrefcnt (*AddRef)(nsIEventQueue *pThis);
     1185    nsrefcnt (*Release)(nsIEventQueue *pThis);
     1186
     1187    nsresult (*PostEvent)(nsIEventQueue *pThis, PLEvent * aEvent);
     1188    nsresult (*IsOnCurrentThread)(nsIEventQueue *pThis, PRBool *_retval);
     1189
     1190    nsresult (*InitEvent)(nsIEventQueue *pThis, PLEvent * aEvent, void * owner, PLHandleEventProc handler, PLDestroyEventProc destructor);
     1191    nsresult (*PostSynchronousEvent)(nsIEventQueue *pThis, PLEvent * aEvent, void * *aResult);
     1192    nsresult (*PendingEvents)(nsIEventQueue *pThis, PRBool *_retval);
     1193    nsresult (*ProcessPendingEvents)(nsIEventQueue *pThis);
     1194    nsresult (*EventLoop)(nsIEventQueue *pThis);
     1195    nsresult (*EventAvailable)(nsIEventQueue *pThis, PRBool *aResult);
     1196    nsresult (*GetEvent)(nsIEventQueue *pThis, PLEvent * *_retval);
     1197    nsresult (*HandleEvent)(nsIEventQueue *pThis, PLEvent * aEvent);
     1198    nsresult (*WaitForEvent)(nsIEventQueue *pThis, PLEvent * *_retval);
     1199    PRInt32 (*GetEventQueueSelectFD)(nsIEventQueue *pThis);
     1200    nsresult (*Init)(nsIEventQueue *pThis, PRBool aNative);
     1201    nsresult (*InitFromPRThread)(nsIEventQueue *pThis, PRThread * thread, PRBool aNative);
     1202    nsresult (*InitFromPLQueue)(nsIEventQueue *pThis, PLEventQueue * aQueue);
     1203    nsresult (*EnterMonitor)(nsIEventQueue *pThis);
     1204    nsresult (*ExitMonitor)(nsIEventQueue *pThis);
     1205    nsresult (*RevokeEvents)(nsIEventQueue *pThis, void * owner);
     1206    nsresult (*GetPLEventQueue)(nsIEventQueue *pThis, PLEventQueue * *_retval);
     1207    nsresult (*IsQueueNative)(nsIEventQueue *pThis, PRBool *_retval);
     1208    nsresult (*StopAcceptingEvents)(nsIEventQueue *pThis);
     1209};
     1210#define nsIEventQueue_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))
     1211#define nsIEventQueue_AddRef(p) ((p)->lpVtbl->AddRef(p))
     1212#define nsIEventQueue_Release(p) ((p)->lpVtbl->Release(p))
     1213#define nsIEventQueue_PostEvent(p, aEvent) ((p)->lpVtbl->PostEvent(p, aEvent))
     1214#define nsIEventQueue_IsOnCurrentThread(p, retval) ((p)->lpVtbl->IsOnCurrentThread(p, retval))
     1215#define nsIEventQueue_InitEvent(p, aEvent, owner, handler, destructor) ((p)->lpVtbl->InitEvent(p, aEvent, owner, handler, destructor))
     1216#define nsIEventQueue_PostSynchronousEvent(p, aEvent, aResult) ((p)->lpVtbl->PostSynchronousEvent(p, aEvent, aResult))
     1217#define nsIEventQueue_ProcessPendingEvents(p) ((p)->lpVtbl->ProcessPendingEvents(p))
     1218#define nsIEventQueue_EventLoop(p) ((p)->lpVtbl->EventLoop(p))
     1219#define nsIEventQueue_EventAvailable(p, aResult) ((p)->lpVtbl->EventAvailable(p, aResult))
     1220#define nsIEventQueue_get_Event(p, aEvent) ((p)->lpVtbl->GetEvent(p, aEvent))
     1221#define nsIEventQueue_GetEvent(p, aEvent) ((p)->lpVtbl->GetEvent(p, aEvent))
     1222#define nsIEventQueue_HandleEvent(p, aEvent) ((p)->lpVtbl->HandleEvent(p, aEvent))
     1223#define nsIEventQueue_WaitForEvent(p, aEvent) ((p)->lpVtbl->WaitForEvent(p, aEvent))
     1224#define nsIEventQueue_GetEventQueueSelectFD(p) ((p)->lpVtbl->GetEventQueueSelectFD(p))
     1225#define nsIEventQueue_Init(p, aNative) ((p)->lpVtbl->Init(p, aNative))
     1226#define nsIEventQueue_InitFromPLQueue(p, aQueue) ((p)->lpVtbl->InitFromPLQueue(p, aQueue))
     1227#define nsIEventQueue_EnterMonitor(p) ((p)->lpVtbl->EnterMonitor(p))
     1228#define nsIEventQueue_ExitMonitor(p) ((p)->lpVtbl->ExitMonitor(p))
     1229#define nsIEventQueue_RevokeEvents(p, owner) ((p)->lpVtbl->RevokeEvents(p, owner))
     1230#define nsIEventQueue_GetPLEventQueue(p, retval) ((p)->lpVtbl->GetPLEventQueue(p, retval))
     1231#define nsIEventQueue_IsQueueNative(p, retval) ((p)->lpVtbl->IsQueueNative(p, retval))
     1232#define nsIEventQueue_StopAcceptingEvents(p) ((p)->lpVtbl->StopAcceptingEvents(p))
     1233#endif /* !VBOX_WITH_GLUE */
     1234
     1235struct nsIEventQueue
     1236{
     1237#ifndef VBOX_WITH_GLUE
    9801238    struct nsIEventQueue_vtbl *vtbl;
     1239#else /* !VBOX_WITH_GLUE */
     1240    struct nsIEventQueueVtbl *lpVtbl;
     1241#endif /* !VBOX_WITH_GLUE */
    9811242};
    9821243
    9831244</xsl:text>
    9841245 <xsl:apply-templates/>
    985 <xsl:text>
    986 #endif /* !__cplusplus */
    987 
    988 #ifdef IN_VBOXXPCOMC
    989 # define VBOXXPCOMC_DECL(type)  PR_EXPORT(type)
    990 #else
    991 # define VBOXXPCOMC_DECL(type)  PR_IMPORT(type)
    992 #endif
     1246 <xsl:text>
     1247
     1248#endif /* __cplusplus */
     1249
     1250#endif /* !WIN32 */
    9931251
    9941252#ifdef __cplusplus
    995 extern "C" {
    996 #endif
     1253extern "C"
     1254{
     1255#endif /* __cplusplus */
    9971256
    9981257
    9991258/**
    10001259 * Function table for dynamic linking.
    1001  * Use VBoxGetFunctions() to obtain the pointer to it.
     1260 * Use VBoxGetCAPIFunctions() to obtain the pointer to it.
    10021261 */
    1003 typedef struct VBOXXPCOMC
     1262typedef struct VBOXCAPI
    10041263{
    10051264    /** The size of the structure. */
     
    10321291     * @param pszVirtualBoxClientIID    pass IVIRTUALBOXCLIENT_IID_STR
    10331292     * @param ppVirtualBoxClient        output parameter for VirtualBoxClient
    1034      *              reference, handled as usual with XPCOM.
    1035      * @returns XPCOM error code
     1293     *              reference, handled as usual with COM/XPCOM.
     1294     * @returns COM/XPCOM error code
    10361295     */
    1037     nsresult (*pfnClientInitialize)(const char *pszVirtualBoxClientIID,
    1038                                     IVirtualBoxClient **ppVirtualBoxClient);
     1296    HRESULT (*pfnClientInitialize)(const char *pszVirtualBoxClientIID,
     1297                                   IVirtualBoxClient **ppVirtualBoxClient);
     1298    /**
     1299     * Initialize the use of the C bindings in a non-primary thread.
     1300     *
     1301     * Must be called on any newly created thread which wants to use the
     1302     * VirtualBox API.
     1303     *
     1304     * @returns COM/XPCOM error code
     1305     */
     1306    HRESULT (*pfnClientThreadInitialize)(void);
     1307    /**
     1308     * Uninitialize the use of the C bindings in a non-primary thread.
     1309     *
     1310     * Should be called before terminating the thread which initialized the
     1311     * C bindings using pfnClientThreadInitialize.
     1312     *
     1313     * @returns COM/XPCOM error code
     1314     */
     1315    HRESULT (*pfnClientThreadUninitialize)(void);
    10391316    /**
    10401317     * Uninitialize the C bindings for an API client.
     
    10771354
    10781355    /**
    1079      * Free memory managed by XPCOM.
    1080      *
    1081      * @param pv        pointer to memory block to be freed
     1356     * Free string managed by COM/XPCOM.
     1357     *
     1358     * @param pwsz          pointer to string to be freed
    10821359     */
    1083     void  (*pfnComUnallocMem)(void *pv);
     1360    void  (*pfnComUnallocString)(BSTR pwsz);
     1361#ifndef WIN32
     1362    /** Legacy function, was always for freeing strings only. */
     1363#define pfnComUnallocMem(pv) pfnComUnallocString((BSTR)(pv))
     1364#endif /* !WIN32 */
    10841365
    10851366    /**
     
    10901371     * @returns IPRT status code
    10911372     */
    1092     int   (*pfnUtf16ToUtf8)(const PRUnichar *pwszString, char **ppszString);
     1373    int   (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString);
    10931374    /**
    10941375     * Convert string from UTF-8 encoding to UTF-16 encoding.
     
    10981379     * @returns IPRT status code
    10991380     */
    1100     int   (*pfnUtf8ToUtf16)(const char *pszString, PRUnichar **ppwszString);
     1381    int   (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString);
    11011382    /**
    11021383     * Free memory returned by pfnUtf16ToUtf8. Do not use for anything else.
     
    11101391     * @param pwszString    string to be freed.
    11111392     */
    1112     void  (*pfnUtf16Free)(PRUnichar *pwszString);
     1393    void  (*pfnUtf16Free)(BSTR pwszString);
    11131394
    11141395    /**
    1115      * Get main XPCOM event queue.
     1396     * Create a safearray (used for passing arrays to COM/XPCOM)
     1397     *
     1398     * Must be freed by pfnSafeArrayDestroy.
     1399     *
     1400     * @param vt            variant type, defines the size of the elements
     1401     * @param lLbound       lower bound of the index, should be 0
     1402     * @param cElements     number of elements
     1403     * @returns pointer to safearray
     1404     */
     1405    SAFEARRAY *(*pfnSafeArrayCreateVector)(VARTYPE vt, LONG lLbound, ULONG cElements);
     1406    /**
     1407     * Pre-allocate a safearray to be used by an out safearray parameter
     1408     *
     1409     * Must be freed by pfnSafeArrayDestroy.
     1410     *
     1411     * @returns pointer to safearray (system dependent, may be NULL if
     1412     *    there is no need to pre-allocate a safearray)
     1413     */
     1414    SAFEARRAY *(*pfnSafeArrayOutParamAlloc)(void);
     1415    /**
     1416     * Copy a C array into a safearray (for passing as an input parameter)
     1417     *
     1418     * @param psa           pointer to already created safearray.
     1419     * @param pv            pointer to memory block to copy into safearray.
     1420     * @param cb            number of bytes to copy.
     1421     * @returns COM/XPCOM error code
     1422     */
     1423    HRESULT (*pfnSafeArrayCopyInParamHelper)(SAFEARRAY *psa, const void *pv, ULONG cb);
     1424    /**
     1425     * Copy a safearray into a C array (for getting an output parameter)
     1426     *
     1427     * @param ppv           output pointer to newly created array, which has to
     1428     *          be freed with free().
     1429     * @param pcb           number of bytes in the output buffer.
     1430     * @param vt            variant type, defines the size of the elements
     1431     * @param psa           pointer to safearray for getting the data
     1432     * @returns COM/XPCOM error code
     1433     */
     1434    HRESULT (*pfnSafeArrayCopyOutParamHelper)(void **ppv, ULONG *pcb, VARTYPE vt, SAFEARRAY *psa);
     1435    /**
     1436     * Copy a safearray into a C array (special variant for interface pointers)
     1437     *
     1438     * @param ppaObj        output pointer to newly created array, which has
     1439     *          to be freed with free(). Note that it's the caller's
     1440     *          responsibility to call Release() on each non-NULL interface
     1441     *          pointer before freeing.
     1442     * @param pcObj         number of pointers in the output buffer.
     1443     * @param psa           pointer to safearray for getting the data
     1444     * @returns COM/XPCOM error code
     1445     */
     1446    HRESULT (*pfnSafeArrayCopyOutIfaceParamHelper)(IUnknown ***ppaObj, ULONG *pcObj, SAFEARRAY *psa);
     1447    /**
     1448     * Free a safearray
     1449     *
     1450     * @param psa           pointer to safearray for getting the data
     1451     * @returns COM/XPCOM error code
     1452     */
     1453    HRESULT (*pfnSafeArrayDestroy)(SAFEARRAY *psa);
     1454
     1455#ifndef WIN32
     1456    /**
     1457     * Get XPCOM event queue. Deprecated!
    11161458     *
    11171459     * @param ppEventQueue      output parameter for nsIEventQueue reference,
     
    11191461     */
    11201462    void  (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue);
     1463#endif /* !WIN32 */
    11211464
    11221465    /**
    1123      * Get current XPCOM exception.
    1124      *
    1125      * @param ppException       output parameter for nsIException reference,
     1466     * Get current COM/XPCOM exception.
     1467     *
     1468     * @param ppException       output parameter for exception info reference,
    11261469     *              may be @c NULL if no exception object has been created by
    1127      *              a previous XPCOM call.
    1128      * @returns XPCOM error code
     1470     *              a previous COM/XPCOM call.
     1471     * @returns COM/XPCOM error code
    11291472     */
    1130     nsresult (*pfnGetException)(nsIException **ppException);
     1473    HRESULT (*pfnGetException)(IErrorInfo **ppException);
    11311474    /**
    1132      * Clears current XPCOM exception.
    1133      *
    1134      * @returns XPCOM error code
     1475     * Clears current COM/XPCOM exception.
     1476     *
     1477     * @returns COM/XPCOM error code
    11351478     */
    1136     nsresult (*pfnClearException)(void);
     1479    HRESULT (*pfnClearException)(void);
     1480
     1481    /**
     1482     * Process the event queue for a given amount of time.
     1483     *
     1484     * Must be called on the primary thread. Typical timeouts are from 200 to
     1485     * 5000 msecs, to allow for checking a volatile variable if the event queue
     1486     * processing should be terminated (,
     1487     * or 0 if only the pending events should be processed, without waiting.
     1488     *
     1489     * @param iTimeoutMS        how long to process the event queue, -1 means
     1490     *              infinitely long
     1491     * @returns status code
     1492     * @retval 0 if at least one event has been processed
     1493     * @retval 1 if any signal interrupted the native system call (or returned
     1494     *      otherwise)
     1495     * @retval 2 if the event queue was explicitly interrupted
     1496     * @retval 3 if the timeout expired
     1497     * @retval 4 if the function was called from the wrong thread
     1498     * @retval 5 for all other (unexpected) errors
     1499     */
     1500    int (*pfnProcessEventQueue)(LONG64 iTimeoutMS);
     1501    /**
     1502     * Interrupt event queue processing.
     1503     *
     1504     * Can be called on any thread. Note that this function is not async-signal
     1505     * safe, so never use it in such a context, instead use a volatile global
     1506     * variable and a sensible timeout.
     1507     * @returns 0 if successful, 1 otherwise.
     1508     */
     1509    int (*pfnInterruptEventQueueProcessing)(void);
    11371510
    11381511    /** Tail version, same as uVersion. */
    11391512    unsigned uEndVersion;
    1140 } VBOXXPCOMC;
    1141 /** Pointer to a const VBoxXPCOMC function table. */
    1142 typedef VBOXXPCOMC const *PCVBOXXPCOM;
     1513} VBOXCAPI;
     1514/** Pointer to a const VBOXCAPI function table. */
     1515typedef VBOXCAPI const *PCVBOXCAPI;
     1516#ifndef WIN32
     1517/** Backwards compatibility: Pointer to a const VBOXCAPI function table.
     1518 * Use PCVBOXCAPI instead. */
     1519typedef VBOXCAPI const *PCVBOXXPCOM;
     1520#endif /* !WIN32 */
     1521
     1522#ifndef WIN32
     1523/** Backwards compatibility: make sure old code using VBOXXPCOMC still compiles.
     1524 * Use VBOXCAPI instead. */
     1525#define VBOXXPCOMC VBOXCAPI
     1526#endif /* !WIN32 */
    11431527
    11441528/** The current interface version.
    1145  * For use with VBoxGetXPCOMCFunctions and to be found in
    1146  * VBOXXPCOMC::uVersion. */
    1147 #define VBOX_XPCOMC_VERSION     0x00030000U
    1148 
    1149 VBOXXPCOMC_DECL(PCVBOXXPCOM) VBoxGetXPCOMCFunctions(unsigned uVersion);
    1150 /** Typedef for VBoxGetXPCOMCFunctions. */
    1151 typedef PCVBOXXPCOM (*PFNVBOXGETXPCOMCFUNCTIONS)(unsigned uVersion);
    1152 
    1153 /** The symbol name of VBoxGetXPCOMCFunctions. */
    1154 #if defined(__OS2__)
    1155 # define VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME   "_VBoxGetXPCOMCFunctions"
    1156 #else
    1157 # define VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME   "VBoxGetXPCOMCFunctions"
    1158 #endif
     1529 * For use with VBoxGetCAPIFunctions and to be found in VBOXCAPI::uVersion. */
     1530#define VBOX_CAPI_VERSION 0x00040000U
     1531
     1532#ifndef WIN32
     1533/** Backwards compatibility: The current interface version.
     1534 * Use VBOX_CAPI_VERSION instead. */
     1535#define VBOX_XPCOMC_VERSION VBOX_CAPI_VERSION
     1536#endif /* !WIN32 */
     1537
     1538/** VBoxGetCAPIFunctions. */
     1539VBOXCAPI_DECL(PCVBOXCAPI) VBoxGetCAPIFunctions(unsigned uVersion);
     1540#ifndef WIN32
     1541/** Backwards compatibility: VBoxGetXPCOMCFunctions.
     1542 * Use VBoxGetCAPIFunctions instead. */
     1543VBOXCAPI_DECL(PCVBOXCAPI) VBoxGetXPCOMCFunctions(unsigned uVersion);
     1544#endif /* !WIN32 */
     1545
     1546/** Typedef for VBoxGetCAPIFunctions. */
     1547typedef PCVBOXCAPI (*PFNVBOXGETCAPIFUNCTIONS)(unsigned uVersion);
     1548#ifndef WIN32
     1549/** Backwards compatibility: Typedef for VBoxGetXPCOMCFunctions.
     1550 * Use PFNVBOXGETCAPIFUNCTIONS instead. */
     1551typedef PCVBOXCAPI (*PFNVBOXGETXPCOMCFUNCTIONS)(unsigned uVersion);
     1552#endif /* !WIN32 */
     1553
     1554/** The symbol name of VBoxGetCAPIFunctions. */
     1555#ifdef __OS2__
     1556# define VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME "_VBoxGetCAPIFunctions"
     1557#else /* !__OS2__ */
     1558# define VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME "VBoxGetCAPIFunctions"
     1559#endif /* !__OS2__ */
     1560#ifndef WIN32
     1561/** Backwards compatibility: The symbol name of VBoxGetXPCOMCFunctions.
     1562 * Use VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME instead. */
     1563# ifdef __OS2__
     1564#  define VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME "_VBoxGetXPCOMCFunctions"
     1565# else /* !__OS2__ */
     1566#  define VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME "VBoxGetXPCOMCFunctions"
     1567# endif /* !__OS2__ */
     1568#endif /* !WIN32 */
    11591569
    11601570
    11611571#ifdef __cplusplus
    11621572}
    1163 #endif
    1164 
    1165 #endif /* !___VirtualBox_CXPCOM_h */
     1573#endif /* __cplusplus */
     1574
     1575#endif /* !___VirtualBox_CAPI_h */
    11661576</xsl:text>
    11671577</xsl:template>
     
    11691579<!--
    11701580 *  ignore all |if|s except those for XPIDL target
     1581-->
    11711582<xsl:template match="if">
    11721583  <xsl:if test="@target='xpidl'">
     
    11851596</xsl:template>
    11861597
    1187 -->
    1188 
    1189 <!--
    1190  *  cpp_quote
    1191 <xsl:template match="cpp">
    1192   <xsl:if test="text()">
    1193     <xsl:text>%{C++</xsl:text>
    1194     <xsl:value-of select="text()"/>
    1195     <xsl:text>&#x0A;%}&#x0A;&#x0A;</xsl:text>
    1196   </xsl:if>
    1197   <xsl:if test="not(text()) and @line">
    1198     <xsl:text>%{C++&#x0A;</xsl:text>
    1199     <xsl:value-of select="@line"/>
    1200     <xsl:text>&#x0A;%}&#x0A;&#x0A;</xsl:text>
    1201   </xsl:if>
    1202 </xsl:template>
    1203 -->
    1204 
    1205 
    1206 <!--
    1207  *  #if statement (@if attribute)
    1208  *  @note
    1209  *      xpidl doesn't support any preprocessor defines other than #include
    1210  *      (it just ignores them), so the generated IDL will most likely be
    1211  *      invalid. So for now we forbid using @if attributes
    1212 -->
    1213 <xsl:template match="@if" mode="begin">
    1214   <xsl:message terminate="yes">
    1215     @if attributes are not currently allowed because xpidl lacks
    1216     support for #ifdef and stuff.
    1217   </xsl:message>
    1218   <xsl:text>#if </xsl:text>
    1219   <xsl:value-of select="."/>
    1220   <xsl:text>&#x0A;</xsl:text>
    1221 </xsl:template>
    1222 <xsl:template match="@if" mode="end">
    1223   <xsl:text>#endif&#x0A;</xsl:text>
    1224 </xsl:template>
    1225 
    12261598
    12271599<!--
     
    12361608  <xsl:text>&#x0A;&#x0A;</xsl:text>
    12371609  <!-- forward declarations -->
    1238   <xsl:apply-templates select="if | interface" mode="forward"/>
     1610  <xsl:apply-templates select="interface | if/interface" mode="forward"/>
    12391611  <xsl:text>&#x0A;</xsl:text>
    12401612  <!-- typedef'ing the struct declarations -->
    1241   <xsl:apply-templates select="if | interface" mode="typedef"/>
     1613  <xsl:apply-templates select="interface | if/interface" mode="typedef"/>
    12421614  <xsl:text>&#x0A;</xsl:text>
    12431615  <!-- all enums go first -->
     
    12631635-->
    12641636<xsl:template match="interface" mode="forward">
    1265   <xsl:text>struct </xsl:text>
    1266   <xsl:value-of select="@name"/>
    1267   <xsl:text>;&#x0A;</xsl:text>
     1637  <xsl:if test="not(@internal='yes')">
     1638    <xsl:text>struct </xsl:text>
     1639    <xsl:value-of select="@name"/>
     1640    <xsl:text>;&#x0A;</xsl:text>
     1641  </xsl:if>
    12681642</xsl:template>
    12691643
     
    12731647-->
    12741648<xsl:template match="interface" mode="typedef">
    1275   <xsl:text>typedef struct </xsl:text>
    1276   <xsl:value-of select="@name"/>
    1277   <xsl:text> </xsl:text>
    1278   <xsl:value-of select="@name"/>
    1279   <xsl:text>;&#x0A;</xsl:text>
     1649  <xsl:if test="not(@internal='yes')">
     1650    <xsl:text>typedef struct </xsl:text>
     1651    <xsl:value-of select="@name"/>
     1652    <xsl:text> </xsl:text>
     1653    <xsl:value-of select="@name"/>
     1654    <xsl:text>;&#x0A;</xsl:text>
     1655  </xsl:if>
     1656</xsl:template>
     1657
     1658
     1659<!--
     1660 *  COBJMACRO style convenience macros for calling methods
     1661-->
     1662<xsl:template match="interface" mode="cobjmacro">
     1663  <xsl:param name="iface"/>
     1664
     1665  <xsl:variable name="extends" select="@extends"/>
     1666  <xsl:choose>
     1667    <xsl:when test="$extends='$unknown'">
     1668      <xsl:text>#define </xsl:text>
     1669      <xsl:value-of select="$iface"/>
     1670      <xsl:text>_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))&#x0A;</xsl:text>
     1671      <xsl:text>#define </xsl:text>
     1672      <xsl:value-of select="$iface"/>
     1673      <xsl:text>_AddRef(p) ((p)->lpVtbl->AddRef(p))&#x0A;</xsl:text>
     1674      <xsl:text>#define </xsl:text>
     1675      <xsl:value-of select="$iface"/>
     1676      <xsl:text>_Release(p) ((p)->lpVtbl->Release(p))&#x0A;</xsl:text>
     1677    </xsl:when>
     1678    <xsl:when test="$extends='$errorinfo'">
     1679      <xsl:text>#define </xsl:text>
     1680      <xsl:value-of select="$iface"/>
     1681      <xsl:text>_QueryInterface(p, iid, resultp) ((p)->lpVtbl->QueryInterface(p, iid, resultp))&#x0A;</xsl:text>
     1682      <xsl:text>#define </xsl:text>
     1683      <xsl:value-of select="$iface"/>
     1684      <xsl:text>_AddRef(p) ((p)->lpVtbl->AddRef(p))&#x0A;</xsl:text>
     1685      <xsl:text>#define </xsl:text>
     1686      <xsl:value-of select="$iface"/>
     1687      <xsl:text>_Release(p) ((p)->lpVtbl->Release(p))&#x0A;</xsl:text>
     1688      <xsl:text>#define </xsl:text>
     1689      <xsl:value-of select="$iface"/>
     1690      <xsl:text>_get_Message(p, aMessage) ((p)->lpVtbl->GetMessage(p, aMessage))&#x0A;</xsl:text>
     1691      <xsl:text>#define </xsl:text>
     1692      <xsl:value-of select="$iface"/>
     1693      <xsl:text>_GetMessage(p, aMessage) ((p)->lpVtbl->GetMessage(p, aMessage))&#x0A;</xsl:text>
     1694      <xsl:text>#define </xsl:text>
     1695      <xsl:value-of select="$iface"/>
     1696      <xsl:text>_get_Result(p, aResult) ((p)->lpVtbl->GetResult(p, aResult))&#x0A;</xsl:text>
     1697      <xsl:text>#define </xsl:text>
     1698      <xsl:value-of select="$iface"/>
     1699      <xsl:text>_GetResult(p, aResult) ((p)->lpVtbl->GetResult(p, aResult))&#x0A;</xsl:text>
     1700      <xsl:text>#define </xsl:text>
     1701      <xsl:value-of select="$iface"/>
     1702      <xsl:text>_get_Name(p, aName) ((p)->lpVtbl->GetName(p, aName))&#x0A;</xsl:text>
     1703      <xsl:text>#define </xsl:text>
     1704      <xsl:value-of select="$iface"/>
     1705      <xsl:text>_GetName(p, aName) ((p)->lpVtbl->GetName(p, aName))&#x0A;</xsl:text>
     1706      <xsl:text>#define </xsl:text>
     1707      <xsl:value-of select="$iface"/>
     1708      <xsl:text>_get_Filename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))&#x0A;</xsl:text>
     1709      <xsl:text>#define </xsl:text>
     1710      <xsl:value-of select="$iface"/>
     1711      <xsl:text>_GetFilename(p, aFilename) ((p)->lpVtbl->GetFilename(p, aFilename))&#x0A;</xsl:text>
     1712      <xsl:text>#define </xsl:text>
     1713      <xsl:value-of select="$iface"/>
     1714      <xsl:text>_get_LineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))&#x0A;</xsl:text>
     1715      <xsl:text>#define </xsl:text>
     1716      <xsl:value-of select="$iface"/>
     1717      <xsl:text>_GetLineNumber(p, aLineNumber) ((p)->lpVtbl->GetLineNumber(p, aLineNumber))&#x0A;</xsl:text>
     1718      <xsl:text>#define </xsl:text>
     1719      <xsl:value-of select="$iface"/>
     1720      <xsl:text>_get_ColumnNumber(p, aColumnNumber) ((p)->lpVtbl->GetColumnNumber(p, aColumnNumber))&#x0A;</xsl:text>
     1721      <xsl:text>#define </xsl:text>
     1722      <xsl:value-of select="$iface"/>
     1723      <xsl:text>_GetColumnNumber(p, aColumnNumber) ((p)->lpVtbl->GetColumnNumber(p, aColumnNumber))&#x0A;</xsl:text>
     1724      <xsl:text>#define </xsl:text>
     1725      <xsl:value-of select="$iface"/>
     1726      <xsl:text>_get_Location(p, aLocation) ((p)->lpVtbl->GetLocation(p, aLocation))&#x0A;</xsl:text>
     1727      <xsl:text>#define </xsl:text>
     1728      <xsl:value-of select="$iface"/>
     1729      <xsl:text>_GetLocation(p, aLocation) ((p)->lpVtbl->GetLocation(p, aLocation))&#x0A;</xsl:text>
     1730      <xsl:text>#define </xsl:text>
     1731      <xsl:value-of select="$iface"/>
     1732      <xsl:text>_get_Inner(p, aInner) ((p)->lpVtbl->GetInner(p, aInner))&#x0A;</xsl:text>
     1733      <xsl:text>#define </xsl:text>
     1734      <xsl:value-of select="$iface"/>
     1735      <xsl:text>_GetInner(p, aInner) ((p)->lpVtbl->GetInner(p, aInner))&#x0A;</xsl:text>
     1736      <xsl:text>#define </xsl:text>
     1737      <xsl:value-of select="$iface"/>
     1738      <xsl:text>_get_Data(p, aData) ((p)->lpVtbl->GetData(p, aData))&#x0A;</xsl:text>
     1739      <xsl:text>#define </xsl:text>
     1740      <xsl:value-of select="$iface"/>
     1741      <xsl:text>_GetData(p, aData) ((p)->lpVtbl->GetData(p, aData))&#x0A;</xsl:text>
     1742      <xsl:text>#define </xsl:text>
     1743      <xsl:value-of select="$iface"/>
     1744      <xsl:text>_ToString(p, retval) ((p)->lpVtbl->ToString(p, retval))&#x0A;</xsl:text>
     1745    </xsl:when>
     1746    <xsl:otherwise>
     1747      <xsl:apply-templates select="//interface[@name=$extends]" mode="cobjmacro">
     1748        <xsl:with-param name="iface" select="$iface"/>
     1749      </xsl:apply-templates>
     1750    </xsl:otherwise>
     1751  </xsl:choose>
     1752  <!-- attributes (properties) -->
     1753  <xsl:apply-templates select="attribute | if/attribute" mode="cobjmacro">
     1754    <xsl:with-param name="iface" select="$iface"/>
     1755  </xsl:apply-templates>
     1756  <!-- methods -->
     1757  <xsl:apply-templates select="method | if/method" mode="cobjmacro">
     1758    <xsl:with-param name="iface" select="$iface"/>
     1759  </xsl:apply-templates>
     1760</xsl:template>
     1761
     1762
     1763<!--
     1764 *  emit flat vtable, compatible with COM
     1765-->
     1766<xsl:template match="interface" mode="vtab_flat">
     1767  <xsl:param name="iface"/>
     1768
     1769  <xsl:variable name="extends" select="@extends"/>
     1770  <xsl:choose>
     1771    <xsl:when test="$extends='$unknown'">
     1772      <xsl:text>    nsresult (*QueryInterface)(</xsl:text>
     1773      <xsl:value-of select="$iface"/>
     1774      <xsl:text> *pThis, const nsID *iid, void **resultp);&#x0A;</xsl:text>
     1775      <xsl:text>    nsrefcnt (*AddRef)(</xsl:text>
     1776      <xsl:value-of select="$iface"/>
     1777      <xsl:text> *pThis);&#x0A;</xsl:text>
     1778      <xsl:text>    nsrefcnt (*Release)(</xsl:text>
     1779      <xsl:value-of select="$iface"/>
     1780      <xsl:text> *pThis);&#x0A;</xsl:text>
     1781    </xsl:when>
     1782    <xsl:when test="$extends='$errorinfo'">
     1783      <xsl:text>    nsresult (*QueryInterface)(</xsl:text>
     1784      <xsl:value-of select="$iface"/>
     1785      <xsl:text> *pThis, const nsID *iid, void **resultp);&#x0A;</xsl:text>
     1786      <xsl:text>    nsrefcnt (*AddRef)(</xsl:text>
     1787      <xsl:value-of select="$iface"/>
     1788      <xsl:text> *pThis);&#x0A;</xsl:text>
     1789      <xsl:text>    nsrefcnt (*Release)(</xsl:text>
     1790      <xsl:value-of select="$iface"/>
     1791      <xsl:text> *pThis);&#x0A;</xsl:text>
     1792      <xsl:text>    nsresult (*GetMessage)(</xsl:text>
     1793      <xsl:value-of select="$iface"/>
     1794      <xsl:text> *pThis, PRUnichar * *aMessage);&#x0A;</xsl:text>
     1795      <xsl:text>    nsresult (*GetResult)(</xsl:text>
     1796      <xsl:value-of select="$iface"/>
     1797      <xsl:text> *pThis, nsresult *aResult);&#x0A;</xsl:text>
     1798      <xsl:text>    nsresult (*GetName)(</xsl:text>
     1799      <xsl:value-of select="$iface"/>
     1800      <xsl:text>*pThis, PRUnichar * *aName);&#x0A;</xsl:text>
     1801      <xsl:text>    nsresult (*GetFilename)(</xsl:text>
     1802      <xsl:value-of select="$iface"/>
     1803      <xsl:text> *pThis, PRUnichar * *aFilename);&#x0A;</xsl:text>
     1804      <xsl:text>    nsresult (*GetLineNumber)(</xsl:text>
     1805      <xsl:value-of select="$iface"/>
     1806      <xsl:text> *pThis, PRUint32 *aLineNumber);&#x0A;</xsl:text>
     1807      <xsl:text>    nsresult (*GetColumnNumber)(</xsl:text>
     1808      <xsl:value-of select="$iface"/>
     1809      <xsl:text> *pThis, PRUint32 *aColumnNumber);&#x0A;</xsl:text>
     1810      <xsl:text>    nsresult (*GetLocation)(</xsl:text>
     1811      <xsl:value-of select="$iface"/>
     1812      <xsl:text> *pThis, nsIStackFrame * *aLocation);&#x0A;</xsl:text>
     1813      <xsl:text>    nsresult (*GetInner)(</xsl:text>
     1814      <xsl:value-of select="$iface"/>
     1815      <xsl:text> *pThis, nsIException * *aInner);&#x0A;</xsl:text>
     1816      <xsl:text>    nsresult (*GetData)(</xsl:text>
     1817      <xsl:value-of select="$iface"/>
     1818      <xsl:text> *pThis, nsISupports * *aData);&#x0A;</xsl:text>
     1819      <xsl:text>    nsresult (*ToString)(</xsl:text>
     1820      <xsl:value-of select="$iface"/>
     1821      <xsl:text> *pThis, PRUnichar **_retval);&#x0A;</xsl:text>
     1822    </xsl:when>
     1823    <xsl:otherwise>
     1824      <xsl:apply-templates select="//interface[@name=$extends]" mode="vtab_flat">
     1825        <xsl:with-param name="iface" select="$iface"/>
     1826      </xsl:apply-templates>
     1827    </xsl:otherwise>
     1828  </xsl:choose>
     1829  <!-- attributes (properties) -->
     1830  <xsl:apply-templates select="attribute | if/attribute">
     1831    <xsl:with-param name="iface" select="$iface"/>
     1832  </xsl:apply-templates>
     1833  <!-- methods -->
     1834  <xsl:apply-templates select="method | if/method">
     1835    <xsl:with-param name="iface" select="$iface"/>
     1836  </xsl:apply-templates>
    12801837</xsl:template>
    12811838
     
    12851842-->
    12861843<xsl:template match="interface">
    1287   <xsl:text>/* Start of struct </xsl:text>
    1288   <xsl:value-of select="@name"/>
    1289   <xsl:text> Declaration */&#x0A;</xsl:text>
    1290   <xsl:text>#define </xsl:text>
    1291   <xsl:call-template name="uppercase">
    1292     <xsl:with-param name="str" select="@name"/>
    1293   </xsl:call-template>
    1294   <xsl:value-of select="concat('_IID_STR &quot;',@uuid,'&quot;')"/>
    1295   <xsl:text>&#x0A;</xsl:text>
    1296   <xsl:text>#define </xsl:text>
    1297   <xsl:call-template name="uppercase">
    1298     <xsl:with-param name="str" select="@name"/>
    1299   </xsl:call-template>
    1300   <xsl:text>_IID { \&#x0A;</xsl:text>
    1301   <xsl:text>    0x</xsl:text><xsl:value-of select="substring(@uuid,1,8)"/>
    1302   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,10,4)"/>
    1303   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,15,4)"/>
    1304   <xsl:text>, \&#x0A;    </xsl:text>
    1305   <xsl:text>{ 0x</xsl:text><xsl:value-of select="substring(@uuid,20,2)"/>
    1306   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,22,2)"/>
    1307   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,25,2)"/>
    1308   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,27,2)"/>
    1309   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,29,2)"/>
    1310   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,31,2)"/>
    1311   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,33,2)"/>
    1312   <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,35,2)"/>
    1313   <xsl:text> } \&#x0A;}&#x0A;</xsl:text>
    1314   <xsl:text>struct </xsl:text>
    1315   <xsl:value-of select="@name"/>
    1316   <xsl:text>_vtbl&#x0A;{&#x0A;</xsl:text>
    1317   <xsl:text>    </xsl:text>
    1318   <xsl:choose>
    1319     <xsl:when test="@extends='$unknown'">struct nsISupports_vtbl nsisupports;</xsl:when>
    1320     <xsl:when test="@extends='$dispatched'">struct nsISupports_vtbl nsisupports;</xsl:when>
    1321     <xsl:when test="@extends='$errorinfo'">struct nsIException_vtbl nsiexception;</xsl:when>
    1322     <xsl:otherwise>
    1323       <xsl:text>struct </xsl:text>
    1324       <xsl:value-of select="@extends"/>
    1325       <xsl:text>_vtbl </xsl:text>
    1326       <xsl:call-template name="lowercase">
    1327         <xsl:with-param name="str" select="@extends"/>
    1328       </xsl:call-template>
    1329       <xsl:text>;</xsl:text>
    1330     </xsl:otherwise>
    1331   </xsl:choose>
    1332   <xsl:text>&#x0A;&#x0A;</xsl:text>
    1333   <!-- attributes (properties) -->
    1334   <xsl:apply-templates select="attribute"/>
    1335   <!-- methods -->
    1336   <xsl:apply-templates select="method"/>
    1337   <!-- 'if' enclosed elements, unsorted -->
    1338   <xsl:apply-templates select="if"/>
    1339   <!-- -->
    1340   <xsl:text>};</xsl:text>
    1341   <xsl:text>&#x0A;&#x0A;</xsl:text>
    1342   <xsl:text>struct </xsl:text>
    1343   <xsl:value-of select="@name"/>
    1344   <xsl:text>&#x0A;{&#x0A;    struct </xsl:text>
    1345   <xsl:value-of select="@name"/>
    1346   <xsl:text>_vtbl *vtbl;&#x0A;};&#x0A;</xsl:text>
    1347   <xsl:text>/* End of struct </xsl:text>
    1348   <xsl:value-of select="@name"/>
    1349   <xsl:text> Declaration */&#x0A;&#x0A;&#x0A;</xsl:text>
     1844  <xsl:if test="not(@internal='yes')">
     1845    <xsl:text>/* Start of struct </xsl:text>
     1846    <xsl:value-of select="@name"/>
     1847    <xsl:text> declaration */&#x0A;</xsl:text>
     1848    <xsl:text>#define </xsl:text>
     1849    <xsl:call-template name="uppercase">
     1850      <xsl:with-param name="str" select="@name"/>
     1851    </xsl:call-template>
     1852    <xsl:value-of select="concat('_IID_STR &quot;',@uuid,'&quot;')"/>
     1853    <xsl:text>&#x0A;</xsl:text>
     1854    <xsl:text>#define </xsl:text>
     1855    <xsl:call-template name="uppercase">
     1856      <xsl:with-param name="str" select="@name"/>
     1857    </xsl:call-template>
     1858    <xsl:text>_IID { \&#x0A;</xsl:text>
     1859    <xsl:text>    0x</xsl:text><xsl:value-of select="substring(@uuid,1,8)"/>
     1860    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,10,4)"/>
     1861    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,15,4)"/>
     1862    <xsl:text>, \&#x0A;    </xsl:text>
     1863    <xsl:text>{ 0x</xsl:text><xsl:value-of select="substring(@uuid,20,2)"/>
     1864    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,22,2)"/>
     1865    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,25,2)"/>
     1866    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,27,2)"/>
     1867    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,29,2)"/>
     1868    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,31,2)"/>
     1869    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,33,2)"/>
     1870    <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,35,2)"/>
     1871    <xsl:text> } \&#x0A;}&#x0A;</xsl:text>
     1872    <xsl:text>/* COM compatibility */&#x0A;</xsl:text>
     1873    <xsl:text>VBOX_EXTERN_CONST(nsIID, IID_</xsl:text>
     1874    <xsl:value-of select="@name"/>
     1875    <xsl:text>);&#x0A;</xsl:text>
     1876    <xsl:text>#ifndef VBOX_WITH_GLUE&#x0A;</xsl:text>
     1877    <xsl:text>struct </xsl:text>
     1878    <xsl:value-of select="@name"/>
     1879    <xsl:text>_vtbl&#x0A;{&#x0A;</xsl:text>
     1880    <xsl:text>    </xsl:text>
     1881    <xsl:choose>
     1882      <xsl:when test="@extends='$unknown'">struct nsISupports_vtbl nsisupports;</xsl:when>
     1883      <xsl:when test="@extends='$errorinfo'">struct nsIException_vtbl nsiexception;</xsl:when>
     1884      <xsl:otherwise>
     1885        <xsl:text>struct </xsl:text>
     1886        <xsl:value-of select="@extends"/>
     1887        <xsl:text>_vtbl </xsl:text>
     1888        <xsl:call-template name="lowercase">
     1889          <xsl:with-param name="str" select="@extends"/>
     1890        </xsl:call-template>
     1891        <xsl:text>;</xsl:text>
     1892      </xsl:otherwise>
     1893    </xsl:choose>
     1894    <xsl:text>&#x0A;&#x0A;</xsl:text>
     1895    <!-- attributes (properties) -->
     1896    <xsl:apply-templates select="attribute | if/attribute"/>
     1897    <!-- methods -->
     1898    <xsl:apply-templates select="method | if/method"/>
     1899    <!-- -->
     1900    <xsl:text>};&#x0A;</xsl:text>
     1901    <xsl:text>#else /* VBOX_WITH_GLUE */&#x0A;</xsl:text>
     1902    <xsl:text>struct </xsl:text>
     1903    <xsl:value-of select="@name"/>
     1904    <xsl:text>Vtbl&#x0A;{&#x0A;</xsl:text>
     1905    <xsl:apply-templates select="." mode="vtab_flat">
     1906      <xsl:with-param name="iface" select="@name"/>
     1907    </xsl:apply-templates>
     1908    <xsl:text>};&#x0A;</xsl:text>
     1909    <xsl:apply-templates select="." mode="cobjmacro">
     1910      <xsl:with-param name="iface" select="@name"/>
     1911    </xsl:apply-templates>
     1912    <!-- -->
     1913    <xsl:text>#endif /* VBOX_WITH_GLUE */&#x0A;</xsl:text>
     1914    <xsl:text>&#x0A;</xsl:text>
     1915    <xsl:text>struct </xsl:text>
     1916    <xsl:value-of select="@name"/>
     1917    <xsl:text>&#x0A;{&#x0A;</xsl:text>
     1918    <xsl:text>#ifndef VBOX_WITH_GLUE&#x0A;</xsl:text>
     1919    <xsl:text>    struct </xsl:text>
     1920    <xsl:value-of select="@name"/>
     1921    <xsl:text>_vtbl *vtbl;&#x0A;</xsl:text>
     1922    <xsl:text>#else /* VBOX_WITH_GLUE */&#x0A;</xsl:text>
     1923    <xsl:text>    struct </xsl:text>
     1924    <xsl:value-of select="@name"/>
     1925    <xsl:text>Vtbl *lpVtbl;&#x0A;</xsl:text>
     1926    <xsl:text>#endif /* VBOX_WITH_GLUE */&#x0A;</xsl:text>
     1927    <xsl:text>};&#x0A;</xsl:text>
     1928    <xsl:text>/* End of struct </xsl:text>
     1929    <xsl:value-of select="@name"/>
     1930    <xsl:text> declaration */&#x0A;&#x0A;&#x0A;</xsl:text>
     1931  </xsl:if>
    13501932</xsl:template>
    13511933
     
    13541936 *  attributes
    13551937-->
    1356 <xsl:template match="interface//attribute">
    1357   <xsl:apply-templates select="@if" mode="begin"/>
    1358   <xsl:if test="@mod='ptr'">
    1359     <!-- attributes using native types must be non-scriptable
    1360     <xsl:text>    [noscript]&#x0A;</xsl:text>-->
    1361   </xsl:if>
     1938<xsl:template match="attribute">
     1939  <xsl:param name="iface" select="ancestor::interface/@name"/>
     1940
    13621941  <xsl:choose>
    13631942    <!-- safearray pseudo attribute -->
     
    13691948      </xsl:call-template>
    13701949      <xsl:text>)(</xsl:text>
    1371       <xsl:value-of select="../@name" />
     1950      <xsl:value-of select="$iface" />
    13721951      <xsl:text> *pThis, </xsl:text>
    13731952      <!-- array size -->
     
    13871966        </xsl:call-template>
    13881967        <xsl:text>)(</xsl:text>
    1389         <xsl:value-of select="../@name" />
     1968        <xsl:value-of select="$iface" />
    13901969        <xsl:text> *pThis, </xsl:text>
    13911970        <!-- array size -->
     
    14091988        </xsl:call-template>
    14101989        <xsl:text>)(</xsl:text>
    1411         <xsl:value-of select="../@name" />
     1990        <xsl:value-of select="$iface" />
    14121991        <xsl:text> *pThis, </xsl:text>
    14131992        <xsl:apply-templates select="@type" mode="forwarder"/>
     
    14252004          </xsl:call-template>
    14262005          <xsl:text>)(</xsl:text>
    1427           <xsl:value-of select="../@name" />
     2006          <xsl:value-of select="$iface" />
    14282007          <xsl:text> *pThis, </xsl:text>
    14292008          <xsl:apply-templates select="@type" mode="forwarder"/>
     
    14362015          </xsl:call-template>
    14372016          <xsl:text>)(</xsl:text>
    1438           <xsl:value-of select="../@name" />
     2017          <xsl:value-of select="$iface" />
    14392018          <xsl:text> *pThis, </xsl:text>
    14402019          <xsl:apply-templates select="@type" mode="forwarder"/>
     
    14462025    </xsl:otherwise>
    14472026  </xsl:choose>
    1448   <xsl:apply-templates select="@if" mode="end"/>
    14492027  <xsl:text>&#x0A;</xsl:text>
    14502028</xsl:template>
    14512029
    1452 <xsl:template match="interface//attribute" mode="forwarder">
    1453 
    1454   <xsl:variable name="parent" select="ancestor::interface"/>
    1455 
    1456   <xsl:apply-templates select="@if" mode="begin"/>
    1457 
    1458   <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO(smth) -->
    1459   <xsl:text>#define COM_FORWARD_</xsl:text>
    1460   <xsl:value-of select="$parent/@name"/>
    1461   <xsl:text>_GETTER_</xsl:text>
     2030<xsl:template match="attribute" mode="cobjmacro">
     2031  <xsl:param name="iface"/>
     2032
     2033  <!-- getter (COM compatible) -->
     2034  <xsl:text>#define </xsl:text>
     2035  <xsl:value-of select="concat($iface, '_get_')"/>
    14622036  <xsl:call-template name="capitalize">
    14632037    <xsl:with-param name="str" select="@name"/>
    14642038  </xsl:call-template>
    1465   <xsl:text>_TO(smth) NS_IMETHOD Get</xsl:text>
     2039  <xsl:text>(p, a</xsl:text>
    14662040  <xsl:call-template name="capitalize">
    14672041    <xsl:with-param name="str" select="@name"/>
    14682042  </xsl:call-template>
    1469   <xsl:text> (</xsl:text>
    1470   <xsl:if test="@safearray='yes'">
    1471     <xsl:text>PRUint32 * a</xsl:text>
     2043  <xsl:text>) ((p)->lpVtbl->Get</xsl:text>
     2044  <xsl:call-template name="capitalize">
     2045    <xsl:with-param name="str" select="@name"/>
     2046  </xsl:call-template>
     2047  <xsl:text>(p, a</xsl:text>
     2048  <xsl:call-template name="capitalize">
     2049    <xsl:with-param name="str" select="@name"/>
     2050  </xsl:call-template>
     2051  <xsl:text>))&#x0A;</xsl:text>
     2052
     2053  <!-- getter (XPCOM compatible) -->
     2054  <xsl:text>#define </xsl:text>
     2055  <xsl:value-of select="concat($iface, '_Get')"/>
     2056  <xsl:call-template name="capitalize">
     2057    <xsl:with-param name="str" select="@name"/>
     2058  </xsl:call-template>
     2059  <xsl:text>(p, a</xsl:text>
     2060  <xsl:call-template name="capitalize">
     2061    <xsl:with-param name="str" select="@name"/>
     2062  </xsl:call-template>
     2063  <xsl:text>) ((p)->lpVtbl->Get</xsl:text>
     2064  <xsl:call-template name="capitalize">
     2065    <xsl:with-param name="str" select="@name"/>
     2066  </xsl:call-template>
     2067  <xsl:text>(p, a</xsl:text>
     2068  <xsl:call-template name="capitalize">
     2069    <xsl:with-param name="str" select="@name"/>
     2070  </xsl:call-template>
     2071  <xsl:text>))&#x0A;</xsl:text>
     2072
     2073  <xsl:if test="not(@readonly='yes')">
     2074    <!-- setter (COM compatible) -->
     2075    <xsl:text>#define </xsl:text>
     2076    <xsl:value-of select="concat($iface, '_set_')"/>
    14722077    <xsl:call-template name="capitalize">
    14732078      <xsl:with-param name="str" select="@name"/>
    14742079    </xsl:call-template>
    1475     <xsl:text>Size, </xsl:text>
    1476   </xsl:if>
    1477   <xsl:apply-templates select="@type" mode="forwarder"/>
    1478   <xsl:if test="@safearray='yes'">
    1479     <xsl:text> *</xsl:text>
    1480   </xsl:if>
    1481   <xsl:text> * a</xsl:text>
    1482   <xsl:call-template name="capitalize">
    1483     <xsl:with-param name="str" select="@name"/>
    1484   </xsl:call-template>
    1485   <xsl:text>) { return smth Get</xsl:text>
    1486   <xsl:call-template name="capitalize">
    1487     <xsl:with-param name="str" select="@name"/>
    1488   </xsl:call-template>
    1489   <xsl:text> (</xsl:text>
    1490   <xsl:if test="@safearray='yes'">
    1491     <xsl:text>a</xsl:text>
     2080    <xsl:text>(p, a</xsl:text>
    14922081    <xsl:call-template name="capitalize">
    14932082      <xsl:with-param name="str" select="@name"/>
    14942083    </xsl:call-template>
    1495     <xsl:text>Size, </xsl:text>
    1496   </xsl:if>
    1497   <xsl:text>a</xsl:text>
    1498   <xsl:call-template name="capitalize">
    1499     <xsl:with-param name="str" select="@name"/>
    1500   </xsl:call-template>
    1501   <xsl:text>); }&#x0A;</xsl:text>
    1502   <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO_OBJ(obj) -->
    1503   <xsl:text>#define COM_FORWARD_</xsl:text>
    1504   <xsl:value-of select="$parent/@name"/>
    1505   <xsl:text>_GETTER_</xsl:text>
    1506   <xsl:call-template name="capitalize">
    1507     <xsl:with-param name="str" select="@name"/>
    1508   </xsl:call-template>
    1509   <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
    1510   <xsl:value-of select="$parent/@name"/>
    1511   <xsl:text>_GETTER_</xsl:text>
    1512   <xsl:call-template name="capitalize">
    1513     <xsl:with-param name="str" select="@name"/>
    1514   </xsl:call-template>
    1515   <xsl:text>_TO ((obj)->)&#x0A;</xsl:text>
    1516   <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO_BASE(base) -->
    1517   <xsl:text>#define COM_FORWARD_</xsl:text>
    1518   <xsl:value-of select="$parent/@name"/>
    1519   <xsl:text>_GETTER_</xsl:text>
    1520   <xsl:call-template name="capitalize">
    1521     <xsl:with-param name="str" select="@name"/>
    1522   </xsl:call-template>
    1523   <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
    1524   <xsl:value-of select="$parent/@name"/>
    1525   <xsl:text>_GETTER_</xsl:text>
    1526   <xsl:call-template name="capitalize">
    1527     <xsl:with-param name="str" select="@name"/>
    1528   </xsl:call-template>
    1529   <xsl:text>_TO (base::)&#x0A;</xsl:text>
    1530   <!-- -->
    1531   <xsl:if test="not(@readonly='yes')">
    1532     <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO(smth) -->
    1533     <xsl:text>#define COM_FORWARD_</xsl:text>
    1534     <xsl:value-of select="$parent/@name"/>
    1535     <xsl:text>_SETTER_</xsl:text>
     2084    <xsl:text>) ((p)->lpVtbl->Set</xsl:text>
    15362085    <xsl:call-template name="capitalize">
    15372086      <xsl:with-param name="str" select="@name"/>
    15382087    </xsl:call-template>
    1539     <xsl:text>_TO(smth) NS_IMETHOD Set</xsl:text>
     2088    <xsl:text>(p, a</xsl:text>
    15402089    <xsl:call-template name="capitalize">
    15412090      <xsl:with-param name="str" select="@name"/>
    15422091    </xsl:call-template>
    1543     <xsl:text> (</xsl:text>
    1544     <xsl:if test="@safearray='yes'">
    1545       <xsl:text>PRUint32 a</xsl:text>
    1546       <xsl:call-template name="capitalize">
    1547         <xsl:with-param name="str" select="@name"/>
    1548       </xsl:call-template>
    1549       <xsl:text>Size, </xsl:text>
    1550     </xsl:if>
    1551     <xsl:if test="not(@safearray='yes') and (@type='string' or @type='wstring')">
    1552       <xsl:text>const </xsl:text>
    1553     </xsl:if>
    1554     <xsl:apply-templates select="@type" mode="forwarder"/>
    1555     <xsl:if test="@safearray='yes'">
    1556       <xsl:text> *</xsl:text>
    1557     </xsl:if>
    1558     <xsl:text> a</xsl:text>
     2092    <xsl:text>))&#x0A;</xsl:text>
     2093
     2094    <!-- setter (XPCOM compatible) -->
     2095    <xsl:text>#define </xsl:text>
     2096    <xsl:value-of select="concat($iface, '_Set')"/>
    15592097    <xsl:call-template name="capitalize">
    15602098      <xsl:with-param name="str" select="@name"/>
    15612099    </xsl:call-template>
    1562     <xsl:text>) { return smth Set</xsl:text>
     2100    <xsl:text>(p, a</xsl:text>
    15632101    <xsl:call-template name="capitalize">
    15642102      <xsl:with-param name="str" select="@name"/>
    15652103    </xsl:call-template>
    1566     <xsl:text> (a</xsl:text>
     2104    <xsl:text>) ((p)->lpVtbl->Set</xsl:text>
    15672105    <xsl:call-template name="capitalize">
    15682106      <xsl:with-param name="str" select="@name"/>
    15692107    </xsl:call-template>
    1570     <xsl:text>); }&#x0A;</xsl:text>
    1571     <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO_OBJ(obj) -->
    1572     <xsl:text>#define COM_FORWARD_</xsl:text>
    1573     <xsl:value-of select="$parent/@name"/>
    1574     <xsl:text>_SETTER_</xsl:text>
     2108    <xsl:text>(p, a</xsl:text>
    15752109    <xsl:call-template name="capitalize">
    15762110      <xsl:with-param name="str" select="@name"/>
    15772111    </xsl:call-template>
    1578     <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
    1579     <xsl:value-of select="$parent/@name"/>
    1580     <xsl:text>_SETTER_</xsl:text>
    1581     <xsl:call-template name="capitalize">
    1582       <xsl:with-param name="str" select="@name"/>
    1583     </xsl:call-template>
    1584     <xsl:text>_TO ((obj)->)&#x0A;</xsl:text>
    1585     <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO_BASE(base) -->
    1586     <xsl:text>#define COM_FORWARD_</xsl:text>
    1587     <xsl:value-of select="$parent/@name"/>
    1588     <xsl:text>_SETTER_</xsl:text>
    1589     <xsl:call-template name="capitalize">
    1590       <xsl:with-param name="str" select="@name"/>
    1591     </xsl:call-template>
    1592     <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
    1593     <xsl:value-of select="$parent/@name"/>
    1594     <xsl:text>_SETTER_</xsl:text>
    1595     <xsl:call-template name="capitalize">
    1596       <xsl:with-param name="str" select="@name"/>
    1597     </xsl:call-template>
    1598     <xsl:text>_TO (base::)&#x0A;</xsl:text>
     2112    <xsl:text>))&#x0A;</xsl:text>
     2113
    15992114  </xsl:if>
    1600 
    1601   <xsl:apply-templates select="@if" mode="end"/>
    1602 
    16032115</xsl:template>
    1604 
    16052116
    16062117<!--
    16072118 *  methods
    16082119-->
    1609 <xsl:template match="interface//method">
    1610   <xsl:apply-templates select="@if" mode="begin"/>
     2120<xsl:template match="method">
     2121  <xsl:param name="iface" select="ancestor::interface/@name"/>
     2122
    16112123  <xsl:if test="param/@mod='ptr'">
    16122124    <!-- methods using native types must be non-scriptable
     
    16202132    <xsl:text>)(&#x0A;</xsl:text>
    16212133    <xsl:text>        </xsl:text>
    1622     <xsl:value-of select="../@name" />
     2134    <xsl:value-of select="$iface" />
    16232135    <xsl:text> *pThis,&#x0A;</xsl:text>
    16242136    <xsl:for-each select="param [position() != last()]">
     
    16332145  <xsl:if test="not(param)">
    16342146    <xsl:text>)(</xsl:text>
    1635     <xsl:value-of select="../@name" />
     2147    <xsl:value-of select="$iface" />
    16362148    <xsl:text> *pThis );&#x0A;</xsl:text>
    16372149  </xsl:if>
    1638   <xsl:apply-templates select="@if" mode="end"/>
    16392150  <xsl:text>&#x0A;</xsl:text>
    16402151</xsl:template>
    16412152
    1642 <xsl:template match="interface//method" mode="forwarder">
    1643 
    1644   <xsl:variable name="parent" select="ancestor::interface"/>
    1645 
    1646   <xsl:apply-templates select="@if" mode="begin"/>
    1647 
    1648   <xsl:text>#define COM_FORWARD_</xsl:text>
    1649   <xsl:value-of select="$parent/@name"/>
    1650   <xsl:text>_</xsl:text>
     2153<xsl:template match="method" mode="cobjmacro">
     2154  <xsl:param name="iface"/>
     2155
     2156  <xsl:text>#define </xsl:text>
     2157  <xsl:value-of select="concat($iface, '_')"/>
    16512158  <xsl:call-template name="capitalize">
    16522159    <xsl:with-param name="str" select="@name"/>
    16532160  </xsl:call-template>
    1654   <xsl:text>_TO(smth) NS_IMETHOD </xsl:text>
     2161  <xsl:text>(p</xsl:text>
     2162  <xsl:for-each select="param">
     2163    <xsl:text>, a</xsl:text>
     2164    <xsl:call-template name="capitalize">
     2165      <xsl:with-param name="str" select="@name"/>
     2166    </xsl:call-template>
     2167  </xsl:for-each>
     2168  <xsl:text>) ((p)->lpVtbl-></xsl:text>
    16552169  <xsl:call-template name="capitalize">
    16562170    <xsl:with-param name="str" select="@name"/>
    16572171  </xsl:call-template>
    1658   <xsl:choose>
    1659     <xsl:when test="param">
    1660       <xsl:text> (</xsl:text>
    1661       <xsl:for-each select="param [position() != last()]">
    1662         <xsl:apply-templates select="." mode="forwarder"/>
    1663         <xsl:text>, </xsl:text>
    1664       </xsl:for-each>
    1665       <xsl:apply-templates select="param [last()]" mode="forwarder"/>
    1666       <xsl:text>) { return smth </xsl:text>
    1667       <xsl:call-template name="capitalize">
    1668         <xsl:with-param name="str" select="@name"/>
    1669       </xsl:call-template>
    1670       <xsl:text> (</xsl:text>
    1671       <xsl:for-each select="param [position() != last()]">
    1672         <xsl:if test="@safearray='yes'">
    1673           <xsl:text>a</xsl:text>
    1674           <xsl:call-template name="capitalize">
    1675             <xsl:with-param name="str" select="@name"/>
    1676           </xsl:call-template>
    1677           <xsl:text>Size+++, </xsl:text>
    1678         </xsl:if>
    1679         <xsl:text>a</xsl:text>
    1680         <xsl:call-template name="capitalize">
    1681           <xsl:with-param name="str" select="@name"/>
    1682         </xsl:call-template>
    1683         <xsl:text>, </xsl:text>
    1684       </xsl:for-each>
    1685       <xsl:if test="param [last()]/@safearray='yes'">
    1686         <xsl:text>a</xsl:text>
    1687         <xsl:call-template name="capitalize">
    1688           <xsl:with-param name="str" select="param [last()]/@name"/>
    1689         </xsl:call-template>
    1690         <xsl:text>Size, </xsl:text>
    1691       </xsl:if>
    1692       <xsl:text>a</xsl:text>
    1693       <xsl:call-template name="capitalize">
    1694         <xsl:with-param name="str" select="param [last()]/@name"/>
    1695       </xsl:call-template>
    1696       <xsl:text>); }</xsl:text>
    1697     </xsl:when>
    1698     <xsl:otherwise test="not(param)">
    1699       <xsl:text>() { return smth </xsl:text>
    1700       <xsl:call-template name="capitalize">
    1701         <xsl:with-param name="str" select="@name"/>
    1702       </xsl:call-template>
    1703       <xsl:text>(); }</xsl:text>
    1704     </xsl:otherwise>
    1705   </xsl:choose>
    1706   <xsl:text>&#x0A;</xsl:text>
    1707   <!-- COM_FORWARD_Interface_Method_TO_OBJ(obj) -->
    1708   <xsl:text>#define COM_FORWARD_</xsl:text>
    1709   <xsl:value-of select="$parent/@name"/>
    1710   <xsl:text>_</xsl:text>
    1711   <xsl:call-template name="capitalize">
    1712     <xsl:with-param name="str" select="@name"/>
    1713   </xsl:call-template>
    1714   <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
    1715   <xsl:value-of select="$parent/@name"/>
    1716   <xsl:text>_</xsl:text>
    1717   <xsl:call-template name="capitalize">
    1718     <xsl:with-param name="str" select="@name"/>
    1719   </xsl:call-template>
    1720   <xsl:text>_TO ((obj)->)&#x0A;</xsl:text>
    1721   <!-- COM_FORWARD_Interface_Method_TO_BASE(base) -->
    1722   <xsl:text>#define COM_FORWARD_</xsl:text>
    1723   <xsl:value-of select="$parent/@name"/>
    1724   <xsl:text>_</xsl:text>
    1725   <xsl:call-template name="capitalize">
    1726     <xsl:with-param name="str" select="@name"/>
    1727   </xsl:call-template>
    1728   <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
    1729   <xsl:value-of select="$parent/@name"/>
    1730   <xsl:text>_</xsl:text>
    1731   <xsl:call-template name="capitalize">
    1732     <xsl:with-param name="str" select="@name"/>
    1733   </xsl:call-template>
    1734   <xsl:text>_TO (base::)&#x0A;</xsl:text>
    1735 
    1736   <xsl:apply-templates select="@if" mode="end"/>
    1737 
     2172  <xsl:text>(p</xsl:text>
     2173  <xsl:for-each select="param">
     2174    <xsl:text>, a</xsl:text>
     2175    <xsl:call-template name="capitalize">
     2176      <xsl:with-param name="str" select="@name"/>
     2177    </xsl:call-template>
     2178  </xsl:for-each>
     2179  <xsl:text>))&#x0A;</xsl:text>
    17382180</xsl:template>
    17392181
     
    17822224  <xsl:text>;1&quot;&#x0A;</xsl:text>
    17832225  <!-- CLSID_xxx declarations for XPCOM, for compatibility with Win32 -->
    1784   <xsl:text>/* for compatibility with Win32 */&#x0A;</xsl:text>
    1785   <xsl:text>#define CLSID_</xsl:text>
     2226  <xsl:text>/* COM compatibility */&#x0A;</xsl:text>
     2227  <xsl:text>VBOX_EXTERN_CONST(nsCID, CLSID_</xsl:text>
    17862228  <xsl:value-of select="@name"/>
    1787   <xsl:text> (nsCID) NS_</xsl:text>
    1788   <xsl:call-template name="uppercase">
    1789     <xsl:with-param name="str" select="@name"/>
    1790   </xsl:call-template>
    1791   <xsl:text>_CID&#x0A;</xsl:text>
     2229  <xsl:text>);&#x0A;</xsl:text>
    17922230  <xsl:text>&#x0A;&#x0A;</xsl:text>
    17932231</xsl:template>
     
    18002238  <xsl:text>/* Start of enum </xsl:text>
    18012239  <xsl:value-of select="@name"/>
    1802   <xsl:text> Declaration */&#x0A;</xsl:text>
     2240  <xsl:text> declaration */&#x0A;</xsl:text>
    18032241  <xsl:text>#define </xsl:text>
    18042242  <xsl:call-template name="uppercase">
     
    18422280  <xsl:text>/* End of enum </xsl:text>
    18432281  <xsl:value-of select="@name"/>
    1844   <xsl:text> Declaration */&#x0A;&#x0A;&#x0A;</xsl:text>
     2282  <xsl:text> declaration */
     2283#define </xsl:text>
     2284  <xsl:value-of select="concat(@name, '_T PRUint32&#x0A;&#x0A;&#x0A;')"/>
    18452285</xsl:template>
    18462286
  • trunk/src/VBox/Main/cbinding/makefile.tstCAPIGlue

    r49984 r50183  
    11# $Revision$
    2 ## @file makefile.tstXPCOMCGlue
    3 # Makefile for sample program illustrating use of C binding for XPCOM.
     2## @file makefile.tstCAPIGlue
     3# Makefile for sample program illustrating use of C binding for COM/XPCOM.
    44#
    55
    66#
    7 # Copyright (C) 2009-2013 Oracle Corporation
     7# Copyright (C) 2009-2014 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616#
    1717
    18 INCS_XPCOM    = -I../../include
    19 GLUE_DIR      = ..
    20 GLUE_INC      = -I..
     18PATH_SDK      = ../../..
     19CAPI_INC      = -I$(PATH_SDK)/bindings/c/include
     20ifeq ($(BUILD_PLATFORM),win)
     21PLATFORM_INC  = -I$(PATH_SDK)/bindings/mscom/include
     22PLATFORM_LIB  = $(PATH_SDK)/bindings/mscom/lib
     23else
     24PLATFORM_INC  = -I$(PATH_SDK)/bindings/xpcom/include
     25PLATFORM_LIB  = $(PATH_SDK)/bindings/xpcom/lib
     26endif
     27GLUE_DIR      = $(PATH_SDK)/bindings/c/glue
     28GLUE_INC      = -I$(GLUE_DIR)
    2129
    2230CC            = gcc
     
    2432
    2533.PHONY: all
    26 all: tstXPCOMCGlue
     34all: tstCAPIGlue
    2735
    2836.PHONY: clean
    2937clean:
    30         rm -f tstXPCOMCGlue.o tstXPCOMCGlue VBoxXPCOMCGlue.o
     38        rm -f tstCAPIGlue.o VBoxCAPIGlue.o VirtualBox_i.o tstCAPIGlue
    3139
    32 tstXPCOMCGlue: tstXPCOMCGlue.o VBoxXPCOMCGlue.o
     40tstCAPIGlue: tstCAPIGlue.o VBoxCAPIGlue.o VirtualBox_i.o
    3341        $(CC) -o $@ $^ -ldl -lpthread
    3442
    35 tstXPCOMCGlue.o: tstXPCOMCGlue.c
    36         $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $<
     43tstCAPIGlue.o: tstCAPIGlue.c
     44        $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $<
    3745
    38 VBoxXPCOMCGlue.o: $(GLUE_DIR)/VBoxXPCOMCGlue.c
    39         $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $<
     46VBoxCAPIGlue.o: $(GLUE_DIR)/VBoxCAPIGlue.c
     47        $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $<
     48
     49VirtualBox_i.o: $(PLATFORM_LIB)/VirtualBox_i.c
     50        $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $<
  • trunk/src/VBox/Main/cbinding/tstCAPIGlue.c

    r49984 r50183  
    11/* $Revision$ */
    2 /** @file tstXPCOMCGlue.c
    3  * Demonstrator program to illustrate use of C bindings of Main API, including
    4  * how to retrieve all available error information.
     2/** @file tstCAPIGlue.c
     3 * Demonstrator program to illustrate use of C bindings of Main API.
    54 *
    6  * This includes code which shows how to handle active event listeners
    7  * (event delivery through callbacks), which is not so frequently seen in
    8  * other samples which mostly use passive event listeners.
    9  *
    10  * Linux only at the moment due to shared library magic in the Makefile.
     5 * It has sample code showing how to retrieve all available error information,
     6 * and how to handle active (event delivery through callbacks) or passive
     7 * (event delivery through a polling mechanism) event listeners.
    118 */
    129
    1310/*
    14  * Copyright (C) 2009-2013 Oracle Corporation
     11 * Copyright (C) 2009-2014 Oracle Corporation
    1512 *
    1613 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2623*   Header Files                                                               *
    2724*******************************************************************************/
    28 #include "VBoxXPCOMCGlue.h"
     25#include "VBoxCAPIGlue.h"
    2926#include <stdio.h>
    3027#include <string.h>
    3128#include <stdlib.h>
    32 #include <unistd.h>
    33 #include <signal.h>
    34 #include <sys/poll.h>
     29#ifndef WIN32
     30# include <signal.h>
     31# include <unistd.h>
     32# include <sys/poll.h>
     33#endif
     34
     35/**
     36 * Select between active event listener (defined) and passive event listener
     37 * (undefined). The active event listener case needs much more code, and
     38 * additionally requires a lot more platform dependent code.
     39 */
     40#undef USE_ACTIVE_EVENT_LISTENER
     41
    3542
    3643/*******************************************************************************
    3744*   Global Variables                                                           *
    3845*******************************************************************************/
    39 /** Set by signal handler. */
     46/** Set by Ctrl+C handler. */
    4047static volatile int g_fStop = 0;
    4148
    42 static const char *GetStateName(PRUint32 machineState)
     49#ifdef USE_ACTIVE_EVENT_LISTENER
     50# ifdef WIN32
     51/** The COM type information for IEventListener, for implementing IDispatch. */
     52static ITypeInfo *g_pTInfoIEventListener = NULL;
     53# endif /* WIN32 */
     54#endif /* USE_ACTIVE_EVENT_LISTENER */
     55
     56static const char *GetStateName(MachineState_T machineState)
    4357{
    4458    switch (machineState)
     
    7084}
    7185
    72 struct IEventListenerDemo_vtbl
    73 {
    74     struct IEventListener_vtbl ieventlistener;
    75 };
    76 
    77 typedef struct IEventListenerDemo
    78 {
    79     struct IEventListenerDemo_vtbl *vtbl;
    80 
    81     int refcount;
    82 } IEventListenerDemo;
    83 
    8486/**
    85  * Event handler function
     87 * Ctrl+C handler, terminate event listener.
     88 *
     89 * Remember that most function calls are not allowed in this context (including
     90 * printf!), so make sure that this does as little as possible.
     91 *
     92 * @param  iInfo    Platform dependent detail info (ignored).
    8693 */
    87 static nsresult IEventListenerDemo_HandleEvent(IEventListener *pThis, IEvent *event)
    88 {
    89     enum VBoxEventType evType;
    90     nsresult rc;
     94static BOOL ctrlCHandler(DWORD iInfo)
     95{
     96    (void)iInfo;
     97    g_fStop = 1;
     98    return TRUE;
     99}
     100
     101/**
     102 * Sample event processing function, dumping some event information.
     103 * Shared between active and passive event demo, to highlight that this part
     104 * is identical between the two.
     105 */
     106static HRESULT EventListenerDemoProcessEvent(IEvent *event)
     107{
     108    VBoxEventType_T evType;
     109    HRESULT rc;
    91110
    92111    if (!event)
    93112    {
    94113        printf("event null\n");
    95         return NS_OK;
     114        return S_OK;
    96115    }
    97116
    98117    evType = VBoxEventType_Invalid;
    99     rc = event->vtbl->GetType(event, &evType);
    100     if (NS_FAILED(rc))
     118    rc = IEvent_get_Type(event, &evType);
     119    if (FAILED(rc))
    101120    {
    102121        printf("cannot get event type, rc=%#x\n", rc);
    103         return NS_OK;
     122        return S_OK;
    104123    }
    105124
     
    120139        case VBoxEventType_OnStateChanged:
    121140        {
    122             static const nsID istateChangedEventUUID = ISTATECHANGEDEVENT_IID;
    123141            IStateChangedEvent *ev = NULL;
    124142            enum MachineState state;
    125             rc = event->vtbl->nsisupports.QueryInterface((nsISupports *)event, &istateChangedEventUUID, (void **)&ev);
    126             if (NS_FAILED(rc))
     143            rc = IEvent_QueryInterface(event, &IID_IStateChangedEvent, (void **)&ev);
     144            if (FAILED(rc))
    127145            {
    128146                printf("cannot get StateChangedEvent interface, rc=%#x\n", rc);
    129                 return NS_OK;
     147                return S_OK;
    130148            }
    131149            if (!ev)
    132150            {
    133151                printf("StateChangedEvent reference null\n");
    134                 return NS_OK;
     152                return S_OK;
    135153            }
    136             rc = ev->vtbl->GetState(ev, &state);
    137             if (NS_FAILED(rc))
     154            rc = IStateChangedEvent_get_State(ev, &state);
     155            if (FAILED(rc))
    138156                printf("warning: cannot get state, rc=%#x\n", rc);
    139             ev->vtbl->ievent.nsisupports.Release((nsISupports *)ev);
     157            IStateChangedEvent_Release(ev);
    140158            printf("OnStateChanged: %s\n", GetStateName(state));
    141159
     
    205223    }
    206224
    207     return NS_OK;
    208 }
    209 
    210 static nsresult IEventListenerDemo_QueryInterface(nsISupports *pThis, const nsID *iid, void **resultp)
    211 {
    212     static const nsID ieventListenerUUID = IEVENTLISTENER_IID;
    213     static const nsID isupportIID = NS_ISUPPORTS_IID;
    214 
     225    return S_OK;
     226}
     227
     228#ifdef USE_ACTIVE_EVENT_LISTENER
     229
     230struct IEventListenerDemo;
     231typedef struct IEventListenerDemo IEventListenerDemo;
     232
     233typedef struct IEventListenerDemoVtbl
     234{
     235    HRESULT (*QueryInterface)(IEventListenerDemo *pThis, REFIID riid, void **ppvObject);
     236    ULONG (*AddRef)(IEventListenerDemo *pThis);
     237    ULONG (*Release)(IEventListenerDemo *pThis);
     238#ifdef WIN32
     239    HRESULT (*GetTypeInfoCount)(IEventListenerDemo *pThis, UINT *pctinfo);
     240    HRESULT (*GetTypeInfo)(IEventListenerDemo *pThis, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo);
     241    HRESULT (*GetIDsOfNames)(IEventListenerDemo *pThis, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId);
     242    HRESULT (*Invoke)(IEventListenerDemo *pThis, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
     243#endif
     244    HRESULT (*HandleEvent)(IEventListenerDemo *pThis, IEvent *aEvent);
     245} IEventListenerDemoVtbl;
     246
     247typedef struct IEventListenerDemo
     248{
     249    struct IEventListenerDemoVtbl *lpVtbl;
     250
     251    int cRef;
     252
     253#ifdef WIN32
     254    /* Active event delivery needs a free threaded marshaler, as the default
     255     * proxy marshaling cannot deal correctly with this case. */
     256    IUnknown *pUnkMarshaler;
     257#endif
     258} IEventListenerDemo;
     259
     260/* Defines for easily calling IEventListenerDemo functions. */
     261
     262/* IUnknown functions. */
     263#define IEventListenerDemo_QueryInterface(This,riid,ppvObject) \
     264    ( (This)->lpVtbl->QueryInterface(This,riid,ppvObject) )
     265
     266#define IEventListenerDemo_AddRef(This) \
     267    ( (This)->lpVtbl->AddRef(This) )
     268
     269#define IEventListenerDemo_Release(This) \
     270    ( (This)->lpVtbl->Release(This) )
     271
     272#ifdef WIN32
     273/* IDispatch functions. */
     274#define IEventListenerDemo_GetTypeInfoCount(This,pctinfo) \
     275    ( (This)->lpVtbl->GetTypeInfoCount(This,pctinfo) )
     276
     277#define IEventListenerDemo_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
     278    ( (This)->lpVtbl->GetTypeInfo(This,iTInfo,lcid,ppTInfo) )
     279
     280#define IEventListenerDemo_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
     281    ( (This)->lpVtbl->GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) )
     282
     283#define IEventListenerDemo_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
     284    ( (This)->lpVtbl->Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) )
     285#endif
     286
     287/* IEventListener functions. */
     288#define IEventListenerDemo_HandleEvent(This,aEvent) \
     289    ( (This)->lpVtbl->HandleEvent(This,aEvent) )
     290
     291
     292/**
     293 * Event handler function, for active event processing.
     294 */
     295static HRESULT IEventListenerDemoImpl_HandleEvent(IEventListenerDemo *pThis, IEvent *event)
     296{
     297    return EventListenerDemoProcessEvent(event);
     298}
     299
     300static HRESULT IEventListenerDemoImpl_QueryInterface(IEventListenerDemo *pThis, const IID *iid, void **resultp)
     301{
    215302    /* match iid */
    216     if (    memcmp(iid, &ieventListenerUUID, sizeof(nsID)) == 0
    217         ||  memcmp(iid, &isupportIID, sizeof(nsID)) == 0)
    218     {
    219         pThis->vtbl->AddRef(pThis);
     303    if (    !memcmp(iid, &IID_IEventListener, sizeof(IID))
     304        ||  !memcmp(iid, &IID_IDispatch, sizeof(IID))
     305        ||  !memcmp(iid, &IID_IUnknown, sizeof(IID)))
     306    {
     307        IEventListenerDemo_AddRef(pThis);
    220308        *resultp = pThis;
    221         return NS_OK;
    222     }
    223 
    224     return NS_NOINTERFACE;
    225 }
    226 
    227 static nsresult IEventListenerDemo_AddRef(nsISupports *pThis)
    228 {
    229     return ++(((IEventListenerDemo *)pThis)->refcount);
    230 }
    231 
    232 static nsresult IEventListenerDemo_Release(nsISupports *pThis)
    233 {
    234     nsresult c;
    235 
    236     c = --(((IEventListenerDemo *)pThis)->refcount);
    237     if (c == 0)
     309        return S_OK;
     310    }
     311#ifdef WIN32
     312    if (!memcmp(iid, &IID_IMarshal, sizeof(IID)))
     313        return IUnknown_QueryInterface(pThis->pUnkMarshaler, iid, resultp);
     314#endif
     315
     316    return E_NOINTERFACE;
     317}
     318
     319static HRESULT IEventListenerDemoImpl_AddRef(IEventListenerDemo *pThis)
     320{
     321    return ++(pThis->cRef);
     322}
     323
     324static HRESULT IEventListenerDemoImpl_Release(IEventListenerDemo *pThis)
     325{
     326    HRESULT c;
     327
     328    c = --(pThis->cRef);
     329    if (!c)
    238330        free(pThis);
    239331    return c;
    240332}
    241333
    242 struct IEventListenerDemo_vtbl_int_gcc
     334#ifdef WIN32
     335static HRESULT IEventListenerDemoImpl_GetTypeInfoCount(IEventListenerDemo *pThis, UINT *pctinfo)
     336{
     337    if (!pctinfo)
     338        return E_POINTER;
     339    *pctinfo = 1;
     340    return S_OK;
     341}
     342
     343static HRESULT IEventListenerDemoImpl_GetTypeInfo(IEventListenerDemo *pThis, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
     344{
     345    if (!ppTInfo)
     346        return E_POINTER;
     347    ITypeInfo_AddRef(g_pTInfoIEventListener);
     348    *ppTInfo = g_pTInfoIEventListener;
     349    return S_OK;
     350}
     351
     352static HRESULT IEventListenerDemoImpl_GetIDsOfNames(IEventListenerDemo *pThis, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
     353{
     354    return ITypeInfo_GetIDsOfNames(g_pTInfoIEventListener, rgszNames, cNames, rgDispId);
     355}
     356
     357static HRESULT IEventListenerDemoImpl_Invoke(IEventListenerDemo *pThis, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
     358{
     359    return ITypeInfo_Invoke(g_pTInfoIEventListener, (IDispatch *)pThis, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
     360}
     361
     362static HRESULT LoadTypeInfo(REFIID riid, ITypeInfo **pTInfo)
     363{
     364    HRESULT rc;
     365    ITypeLib *pTypeLib;
     366    rc = LoadRegTypeLib(&LIBID_VirtualBox, 1 /* major */, 0 /* minor */, 0 /* lcid */, &pTypeLib);
     367    if (FAILED(rc))
     368        return rc;
     369    rc = ITypeLib_GetTypeInfoOfGuid(pTypeLib, riid, pTInfo);
     370
     371    /* No longer need access to the type lib, release it. */
     372    ITypeLib_Release(pTypeLib);
     373
     374    return rc;
     375}
     376#endif
     377
     378#ifdef __GNUC__
     379typedef struct IEventListenerDemoVtblInt
    243380{
    244381    ptrdiff_t offset_to_top;
    245382    void *typeinfo;
    246     struct IEventListenerDemo_vtbl vtbl;
    247 };
    248 
    249 static struct IEventListenerDemo_vtbl_int_gcc g_IEventListenerDemo_vtbl_int_gcc =
     383    IEventListenerDemoVtbl lpVtbl;
     384} IEventListenerDemoVtblInt;
     385
     386static IEventListenerDemoVtblInt g_IEventListenerDemoVtblInt =
    250387{
    251388    0,      /* offset_to_top */
    252389    NULL,   /* typeinfo, not vital */
    253390    {
    254         {
    255             {
    256                 IEventListenerDemo_QueryInterface,
    257                 IEventListenerDemo_AddRef,
    258                 IEventListenerDemo_Release
    259             },
    260             IEventListenerDemo_HandleEvent
    261         }
     391        IEventListenerDemoImpl_QueryInterface,
     392        IEventListenerDemoImpl_AddRef,
     393        IEventListenerDemoImpl_Release,
     394#ifdef WIN32
     395        IEventListenerDemoImpl_GetTypeInfoCount,
     396        IEventListenerDemoImpl_GetTypeInfo,
     397        IEventListenerDemoImpl_GetIDsOfNames,
     398        IEventListenerDemoImpl_Invoke,
     399#endif
     400        IEventListenerDemoImpl_HandleEvent
    262401    }
    263402};
     403#elif defined(_MSC_VER)
     404typedef struct IEventListenerDemoVtblInt
     405{
     406    IEventListenerDemoVtbl lpVtbl;
     407} IEventListenerDemoVtblInt;
     408
     409static IEventListenerDemoVtblInt g_IEventListenerDemoVtblInt =
     410{
     411    {
     412        IEventListenerDemoImpl_QueryInterface,
     413        IEventListenerDemoImpl_AddRef,
     414        IEventListenerDemoImpl_Release,
     415#ifdef WIN32
     416        IEventListenerDemoImpl_GetTypeInfoCount,
     417        IEventListenerDemoImpl_GetTypeInfo,
     418        IEventListenerDemoImpl_GetIDsOfNames,
     419        IEventListenerDemoImpl_Invoke,
     420#endif
     421        IEventListenerDemoImpl_HandleEvent
     422    }
     423};
     424#else
     425# error Port me!
     426#endif
    264427
    265428/**
    266  * Signal handler, terminate event listener.
    267  *
    268  * @param  iSig     The signal number (ignored).
    269  */
    270 static void sigIntHandler(int iSig)
    271 {
    272     (void)iSig;
    273     g_fStop = 1;
    274 }
    275 
    276 /**
    277  * Register event listener for the selected VM.
     429 * Register active event listener for the selected VM.
    278430 *
    279431 * @param   virtualBox ptr to IVirtualBox object
    280432 * @param   session    ptr to ISession object
    281433 * @param   id         identifies the machine to start
    282  * @param   queue      handle to the event queue
    283434 */
    284 static void registerEventListener(IVirtualBox *virtualBox, ISession *session, PRUnichar *machineId, nsIEventQueue *queue)
     435static void registerActiveEventListener(IVirtualBox *virtualBox, ISession *session, BSTR machineId)
    285436{
    286437    IConsole *console = NULL;
    287     nsresult rc;
    288 
    289     rc = session->vtbl->GetConsole(session, &console);
    290     if ((NS_SUCCEEDED(rc)) && console)
     438    HRESULT rc;
     439
     440    rc = ISession_get_Console(session, &console);
     441    if ((SUCCEEDED(rc)) && console)
    291442    {
    292443        IEventSource *es = NULL;
    293         rc = console->vtbl->GetEventSource(console, &es);
    294         if (NS_SUCCEEDED(rc) && es)
    295         {
    296             PRUint32 interestingEvents[] =
     444        rc = IConsole_get_EventSource(console, &es);
     445        if (SUCCEEDED(rc) && es)
     446        {
     447            static const ULONG interestingEvents[] =
    297448                {
    298449                    VBoxEventType_OnMousePointerShapeChanged,
     
    314465                    VBoxEventType_OnShowWindow
    315466                };
     467            SAFEARRAY *interestingEventsSA = NULL;
    316468            IEventListenerDemo *consoleListener = NULL;
     469
     470            /* The VirtualBox API expects enum values as VT_I4, which in the
     471             * future can be hopefully relaxed. */
     472            interestingEventsSA = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0, sizeof(interestingEvents) / sizeof(interestingEvents[0]));
     473            g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(interestingEventsSA, &interestingEvents, sizeof(interestingEvents));
     474
    317475            consoleListener = calloc(1, sizeof(IEventListenerDemo));
    318476            if (consoleListener)
    319477            {
    320                 consoleListener->vtbl = &(g_IEventListenerDemo_vtbl_int_gcc.vtbl);
    321                 consoleListener->vtbl->ieventlistener.nsisupports.AddRef((nsISupports *)consoleListener);
    322 
    323                 rc = es->vtbl->RegisterListener(es, (IEventListener *)consoleListener,
    324                                                 sizeof(interestingEvents) / sizeof(interestingEvents[0]),
    325                                                 interestingEvents, 1 /* active */);
    326                 if (NS_SUCCEEDED(rc))
     478                consoleListener->lpVtbl = &(g_IEventListenerDemoVtblInt.lpVtbl);
     479#ifdef WIN32
     480                CoCreateFreeThreadedMarshaler((IUnknown *)consoleListener, &consoleListener->pUnkMarshaler);
     481#endif
     482                IEventListenerDemo_AddRef(consoleListener);
     483
     484                rc = IEventSource_RegisterListener(es, (IEventListener *)consoleListener,
     485                                                   ComSafeArrayAsInParam(interestingEventsSA),
     486                                                   1 /* active */);
     487                if (SUCCEEDED(rc))
    327488                {
    328489                    /* Just wait here for events, no easy way to do this better
    329490                     * as there's not much to do after this completes. */
    330                     PRInt32 fd;
    331                     int ret;
    332491                    printf("Entering event loop, PowerOff the machine to exit or press Ctrl-C to terminate\n");
    333492                    fflush(stdout);
    334                     signal(SIGINT, sigIntHandler);
    335 
    336                     fd = queue->vtbl->GetEventQueueSelectFD(queue);
    337                     if (fd >= 0)
     493#ifdef WIN32
     494                    SetConsoleCtrlHandler(ctrlCHandler, TRUE);
     495#else
     496                    signal(SIGINT, (void (*)(int))ctrlCHandler);
     497#endif
     498
     499                    while (!g_fStop)
    338500                    {
    339                         while (!g_fStop)
    340                         {
    341                             struct pollfd pfd;
    342 
    343                             pfd.fd = fd;
    344                             pfd.events = POLLIN | POLLERR | POLLHUP;
    345                             pfd.revents = 0;
    346 
    347                             ret = poll(&pfd, 1, 250);
    348 
    349                             if (ret <= 0)
    350                                 continue;
    351 
    352                             if (pfd.revents & POLLHUP)
    353                                 g_fStop = 1;
    354 
    355                             queue->vtbl->ProcessPendingEvents(queue);
    356                         }
     501                        g_pVBoxFuncs->pfnProcessEventQueue(250);
    357502                    }
    358                     else
    359                     {
    360                         while (!g_fStop)
    361                         {
    362                             PLEvent *pEvent = NULL;
    363                             rc = queue->vtbl->WaitForEvent(queue, &pEvent);
    364                             if (NS_SUCCEEDED(rc))
    365                                 queue->vtbl->HandleEvent(queue, pEvent);
    366                         }
    367                     }
     503
     504#ifdef WIN32
     505                    SetConsoleCtrlHandler(ctrlCHandler, FALSE);
     506#else
    368507                    signal(SIGINT, SIG_DFL);
     508#endif
    369509                }
    370                 es->vtbl->UnregisterListener(es, (IEventListener *)consoleListener);
    371                 consoleListener->vtbl->ieventlistener.nsisupports.Release((nsISupports *)consoleListener);
     510                else
     511                {
     512                    printf("Failed to register event listener.\n");
     513                }
     514                IEventSource_UnregisterListener(es, (IEventListener *)consoleListener);
     515#ifdef WIN32
     516                if (consoleListener->pUnkMarshaler)
     517                    IUnknown_Release(consoleListener->pUnkMarshaler);
     518#endif
     519                IEventListenerDemo_Release(consoleListener);
    372520            }
    373521            else
     
    375523                printf("Failed while allocating memory for console event listener.\n");
    376524            }
    377             es->vtbl->nsisupports.Release((nsISupports *)es);
    378         }
    379         console->vtbl->nsisupports.Release((nsISupports *)console);
    380     }
    381 }
     525            g_pVBoxFuncs->pfnSafeArrayDestroy(interestingEventsSA);
     526            IEventSource_Release(es);
     527        }
     528        else
     529        {
     530            printf("Failed to get the event source instance.\n");
     531        }
     532        IConsole_Release(console);
     533    }
     534}
     535
     536#else /* !USE_ACTIVE_EVENT_LISTENER */
     537
     538/**
     539 * Register passive event listener for the selected VM.
     540 *
     541 * @param   virtualBox ptr to IVirtualBox object
     542 * @param   session    ptr to ISession object
     543 * @param   id         identifies the machine to start
     544 */
     545static void registerPassiveEventListener(IVirtualBox *virtualBox, ISession *session, BSTR machineId)
     546{
     547    IConsole *console = NULL;
     548    HRESULT rc;
     549
     550    rc = ISession_get_Console(session, &console);
     551    if ((SUCCEEDED(rc)) && console)
     552    {
     553        IEventSource *es = NULL;
     554        rc = IConsole_get_EventSource(console, &es);
     555        if (SUCCEEDED(rc) && es)
     556        {
     557            static const ULONG interestingEvents[] =
     558                {
     559                    VBoxEventType_OnMousePointerShapeChanged,
     560                    VBoxEventType_OnMouseCapabilityChanged,
     561                    VBoxEventType_OnKeyboardLedsChanged,
     562                    VBoxEventType_OnStateChanged,
     563                    VBoxEventType_OnAdditionsStateChanged,
     564                    VBoxEventType_OnNetworkAdapterChanged,
     565                    VBoxEventType_OnSerialPortChanged,
     566                    VBoxEventType_OnParallelPortChanged,
     567                    VBoxEventType_OnStorageControllerChanged,
     568                    VBoxEventType_OnMediumChanged,
     569                    VBoxEventType_OnVRDEServerChanged,
     570                    VBoxEventType_OnUSBControllerChanged,
     571                    VBoxEventType_OnUSBDeviceStateChanged,
     572                    VBoxEventType_OnSharedFolderChanged,
     573                    VBoxEventType_OnRuntimeError,
     574                    VBoxEventType_OnCanShowWindow,
     575                    VBoxEventType_OnShowWindow
     576                };
     577            SAFEARRAY *interestingEventsSA = NULL;
     578            IEventListener *consoleListener = NULL;
     579
     580            /* The VirtualBox API expects enum values as VT_I4, which in the
     581             * future can be hopefully relaxed. */
     582            interestingEventsSA = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0, sizeof(interestingEvents) / sizeof(interestingEvents[0]));
     583            g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(interestingEventsSA, &interestingEvents, sizeof(interestingEvents));
     584
     585            rc = IEventSource_CreateListener(es, &consoleListener);
     586            if (SUCCEEDED(rc) && consoleListener)
     587            {
     588                rc = IEventSource_RegisterListener(es, consoleListener,
     589                                                   ComSafeArrayAsInParam(interestingEventsSA),
     590                                                   0 /* passive */);
     591                if (SUCCEEDED(rc))
     592                {
     593                    /* Just wait here for events, no easy way to do this better
     594                     * as there's not much to do after this completes. */
     595                    printf("Entering event loop, PowerOff the machine to exit or press Ctrl-C to terminate\n");
     596                    fflush(stdout);
     597#ifdef WIN32
     598                    SetConsoleCtrlHandler(ctrlCHandler, TRUE);
     599#else
     600                    signal(SIGINT, (void (*)(int))ctrlCHandler);
     601#endif
     602
     603                    while (!g_fStop)
     604                    {
     605                        IEvent *ev = NULL;
     606                        rc = IEventSource_GetEvent(es, consoleListener, 250, &ev);
     607                        if (FAILED(rc))
     608                        {
     609                            printf("Failed getting event: %#x\n", rc);
     610                            g_fStop = 1;
     611                            continue;
     612                        }
     613                        /* handle timeouts, resulting in NULL events */
     614                        if (!ev)
     615                            continue;
     616                        rc = EventListenerDemoProcessEvent(ev);
     617                        if (FAILED(rc))
     618                        {
     619                            printf("Failed processing event: %#x\n", rc);
     620                            g_fStop = 1;
     621                            /* finish processing the event */
     622                        }
     623                        rc = IEventSource_EventProcessed(es, consoleListener, ev);
     624                        if (FAILED(rc))
     625                        {
     626                            printf("Failed to mark event as processed: %#x\n", rc);
     627                            g_fStop = 1;
     628                            /* continue with event release */
     629                        }
     630                        if (ev)
     631                        {
     632                            IEvent_Release(ev);
     633                            ev = NULL;
     634                        }
     635                    }
     636
     637#ifdef WIN32
     638                    SetConsoleCtrlHandler(ctrlCHandler, FALSE);
     639#else
     640                    signal(SIGINT, SIG_DFL);
     641#endif
     642                }
     643                else
     644                {
     645                    printf("Failed to register event listener.\n");
     646                }
     647                IEventSource_UnregisterListener(es, (IEventListener *)consoleListener);
     648                IEventListener_Release(consoleListener);
     649            }
     650            else
     651            {
     652                printf("Failed to create an event listener instance.\n");
     653            }
     654            g_pVBoxFuncs->pfnSafeArrayDestroy(interestingEventsSA);
     655            IEventSource_Release(es);
     656        }
     657        else
     658        {
     659            printf("Failed to get the event source instance.\n");
     660        }
     661        IConsole_Release(console);
     662    }
     663}
     664
     665#endif /* !USE_ACTIVE_EVENT_LISTENER */
    382666
    383667/**
     
    385669 * @param   pszExecutable   string with the executable name
    386670 * @param   pszErrorMsg     string containing the code location specific error message
    387  * @param   rc              XPCOM result code
     671 * @param   rc              COM/XPCOM result code
    388672 */
    389 static void PrintErrorInfo(const char *pszExecutable, const char *pszErrorMsg, nsresult rc)
    390 {
    391     nsIException *ex;
    392     nsresult rc2 = NS_OK;
     673static void PrintErrorInfo(const char *pszExecutable, const char *pszErrorMsg, HRESULT rc)
     674{
     675    IErrorInfo *ex;
     676    HRESULT rc2 = S_OK;
    393677    fprintf(stderr, "%s: %s (rc=%#010x)\n", pszExecutable, pszErrorMsg, (unsigned)rc);
    394678    rc2 = g_pVBoxFuncs->pfnGetException(&ex);
    395     if (NS_SUCCEEDED(rc2))
    396     {
    397         static const nsID vbei = IVIRTUALBOXERRORINFO_IID;
     679    if (SUCCEEDED(rc2))
     680    {
    398681        IVirtualBoxErrorInfo *ei;
    399         rc2 = ex->vtbl->nsisupports.QueryInterface((nsISupports *)ex, &vbei, (void **)&ei);
    400         if (NS_FAILED(rc2))
     682        rc2 = IErrorInfo_QueryInterface(ex, &IID_IVirtualBoxErrorInfo, (void **)&ei);
     683        if (FAILED(rc2))
    401684            ei = NULL;
    402685        if (ei)
     
    405688            do
    406689            {
    407                 PRInt32 resultCode = NS_OK;
    408                 PRUnichar *componentUtf16 = NULL;
     690                LONG resultCode = S_OK;
     691                BSTR componentUtf16 = NULL;
    409692                char *component = NULL;
    410                 PRUnichar *textUtf16 = NULL;
     693                BSTR textUtf16 = NULL;
    411694                char *text = NULL;
    412695                IVirtualBoxErrorInfo *ei_next = NULL;
    413696                fprintf(stderr, "Extended error info (IVirtualBoxErrorInfo):\n");
    414697
    415                 ei->vtbl->GetResultCode(ei, &resultCode);
     698                IVirtualBoxErrorInfo_get_ResultCode(ei, &resultCode);
    416699                fprintf(stderr, "  resultCode=%#010x\n", (unsigned)resultCode);
    417700
    418                 ei->vtbl->GetComponent(ei, &componentUtf16);
     701                IVirtualBoxErrorInfo_get_Component(ei, &componentUtf16);
    419702                g_pVBoxFuncs->pfnUtf16ToUtf8(componentUtf16, &component);
    420                 g_pVBoxFuncs->pfnComUnallocMem(componentUtf16);
     703                g_pVBoxFuncs->pfnComUnallocString(componentUtf16);
    421704                fprintf(stderr, "  component=%s\n", component);
    422705                g_pVBoxFuncs->pfnUtf8Free(component);
    423706
    424                 ei->vtbl->GetText(ei, &textUtf16);
     707                IVirtualBoxErrorInfo_get_Text(ei, &textUtf16);
    425708                g_pVBoxFuncs->pfnUtf16ToUtf8(textUtf16, &text);
    426                 g_pVBoxFuncs->pfnComUnallocMem(textUtf16);
     709                g_pVBoxFuncs->pfnComUnallocString(textUtf16);
    427710                fprintf(stderr, "  text=%s\n", text);
    428711                g_pVBoxFuncs->pfnUtf8Free(text);
    429712
    430                 rc2 = ei->vtbl->GetNext(ei, &ei_next);
    431                 if (NS_FAILED(rc2))
     713                rc2 = IVirtualBoxErrorInfo_get_Next(ei, &ei_next);
     714                if (FAILED(rc2))
    432715                    ei_next = NULL;
    433                 ei->vtbl->nsiexception.nsisupports.Release((nsISupports *)ei);
     716                IVirtualBoxErrorInfo_Release(ei);
    434717                ei = ei_next;
    435718            }
    436719            while (ei);
    437720        }
    438         else
    439         {
    440             /* got basic error info */
    441             nsresult resultCode = NS_OK;
    442             PRUnichar *messageUtf16 = NULL;
    443             char *message = NULL;
    444             fprintf(stderr, "Basic error info (nsIException):\n");
    445 
    446             ex->vtbl->GetResult(ex, &resultCode);
    447             fprintf(stderr, "  resultCode=%#010x\n", resultCode);
    448 
    449             ex->vtbl->GetMessage(ex, &messageUtf16);
    450             g_pVBoxFuncs->pfnUtf16ToUtf8(messageUtf16, &message);
    451             g_pVBoxFuncs->pfnComUnallocMem(messageUtf16);
    452             fprintf(stderr, "  message=%s\n", message);
    453             g_pVBoxFuncs->pfnUtf8Free(message);
    454         }
    455 
    456         ex->vtbl->nsisupports.Release((nsISupports *)ex);
     721
     722        IErrorInfo_Release(ex);
    457723        g_pVBoxFuncs->pfnClearException();
    458724    }
     
    466732 * @param   session     ptr to ISession object
    467733 * @param   id          identifies the machine to start
    468  * @param   queue       ptr to event queue
    469734 */
    470 static void startVM(const char *argv0, IVirtualBox *virtualBox, ISession *session, PRUnichar *id, nsIEventQueue *queue)
    471 {
    472     nsresult rc;
     735static void startVM(const char *argv0, IVirtualBox *virtualBox, ISession *session, BSTR id)
     736{
     737    HRESULT rc;
    473738    IMachine  *machine    = NULL;
    474739    IProgress *progress   = NULL;
    475     PRUnichar *env        = NULL;
    476     PRUnichar *sessionType;
    477 
    478     rc = virtualBox->vtbl->FindMachine(virtualBox, id, &machine);
    479     if (NS_FAILED(rc) || !machine)
     740    BSTR env              = NULL;
     741    BSTR sessionType;
     742
     743    rc = IVirtualBox_FindMachine(virtualBox, id, &machine);
     744    if (FAILED(rc) || !machine)
    480745    {
    481746        PrintErrorInfo(argv0, "Error: Couldn't get the Machine reference", rc);
     
    484749
    485750    g_pVBoxFuncs->pfnUtf8ToUtf16("gui", &sessionType);
    486     rc = machine->vtbl->LaunchVMProcess(machine,
    487         session,
    488         sessionType,
    489         env,
    490         &progress
    491     );
     751    rc = IMachine_LaunchVMProcess(machine, session, sessionType, env, &progress);
    492752    g_pVBoxFuncs->pfnUtf16Free(sessionType);
    493     if (NS_SUCCEEDED(rc))
    494     {
    495         PRBool completed;
    496         PRInt32 resultCode;
     753    if (SUCCEEDED(rc))
     754    {
     755        BOOL completed;
     756        LONG resultCode;
    497757
    498758        printf("Waiting for the remote session to open...\n");
    499         progress->vtbl->WaitForCompletion(progress, -1);
    500 
    501         rc = progress->vtbl->GetCompleted(progress, &completed);
    502         if (NS_FAILED(rc))
     759        IProgress_WaitForCompletion(progress, -1);
     760
     761        rc = IProgress_get_Completed(progress, &completed);
     762        if (FAILED(rc))
    503763            fprintf(stderr, "Error: GetCompleted status failed\n");
    504764
    505         progress->vtbl->GetResultCode(progress, &resultCode);
    506         if (NS_FAILED(resultCode))
     765        IProgress_get_ResultCode(progress, &resultCode);
     766        if (FAILED(resultCode))
    507767        {
    508768            IVirtualBoxErrorInfo *errorInfo;
    509             PRUnichar *textUtf16;
     769            BSTR textUtf16;
    510770            char *text;
    511771
    512             progress->vtbl->GetErrorInfo(progress, &errorInfo);
    513             errorInfo->vtbl->GetText(errorInfo, &textUtf16);
     772            IProgress_get_ErrorInfo(progress, &errorInfo);
     773            IVirtualBoxErrorInfo_get_Text(errorInfo, &textUtf16);
    514774            g_pVBoxFuncs->pfnUtf16ToUtf8(textUtf16, &text);
    515775            printf("Error: %s\n", text);
    516776
    517             g_pVBoxFuncs->pfnComUnallocMem(textUtf16);
     777            g_pVBoxFuncs->pfnComUnallocString(textUtf16);
    518778            g_pVBoxFuncs->pfnUtf8Free(text);
     779            IVirtualBoxErrorInfo_Release(errorInfo);
    519780        }
    520781        else
     
    524785            /* Kick off the event listener demo part, which is quite separate.
    525786             * Ignore it if you need a more basic sample. */
    526             registerEventListener(virtualBox, session, id, queue);
    527         }
    528         progress->vtbl->nsisupports.Release((nsISupports *)progress);
     787#ifdef USE_ACTIVE_EVENT_LISTENER
     788            registerActiveEventListener(virtualBox, session, id);
     789#else /* !USE_ACTIVE_EVENT_LISTENER */
     790            registerPassiveEventListener(virtualBox, session, id);
     791#endif /* !USE_ACTIVE_EVENT_LISTENER */
     792        }
     793        IProgress_Release(progress);
    529794    }
    530795    else
     
    532797
    533798    /* It's important to always release resources. */
    534     machine->vtbl->nsisupports.Release((nsISupports *)machine);
     799    IMachine_Release(machine);
    535800}
    536801
     
    541806 * @param   virtualBox  ptr to IVirtualBox object
    542807 * @param   session     ptr to ISession object
    543  * @param   queue       ptr to event queue
    544808 */
    545 static void listVMs(const char *argv0, IVirtualBox *virtualBox, ISession *session, nsIEventQueue *queue)
    546 {
    547     nsresult rc;
     809static void listVMs(const char *argv0, IVirtualBox *virtualBox, ISession *session)
     810{
     811    HRESULT rc;
     812    SAFEARRAY *machinesSA = g_pVBoxFuncs->pfnSafeArrayOutParamAlloc();
    548813    IMachine **machines = NULL;
    549     PRUint32 machineCnt = 0;
    550     PRUint32 i;
     814    ULONG machineCnt = 0;
     815    ULONG i;
    551816    unsigned start_id;
    552817
     
    554819     * Get the list of all registered VMs.
    555820     */
    556 
    557     rc = virtualBox->vtbl->GetMachines(virtualBox, &machineCnt, &machines);
    558     if (NS_FAILED(rc))
     821    rc = IVirtualBox_get_Machines(virtualBox, ComSafeArrayAsOutIfaceParam(machinesSA, IMachine *));
     822    if (FAILED(rc))
    559823    {
    560824        PrintErrorInfo(argv0, "could not get list of machines", rc);
     
    562826    }
    563827
    564     if (machineCnt == 0)
     828    /*
     829     * Extract interface pointers from machinesSA, and update the reference
     830     * counter of each object, as destroying machinesSA would call Release.
     831     */
     832    g_pVBoxFuncs->pfnSafeArrayCopyOutIfaceParamHelper((IUnknown ***)&machines, &machineCnt, machinesSA);
     833    g_pVBoxFuncs->pfnSafeArrayDestroy(machinesSA);
     834
     835    if (!machineCnt)
    565836    {
    566837        printf("\tNo VMs\n");
     
    577848    {
    578849        IMachine *machine      = machines[i];
    579         PRBool    isAccessible = PR_FALSE;
     850        BOOL      isAccessible = FALSE;
    580851
    581852        printf("\tMachine #%u\n", (unsigned)i);
     
    587858        }
    588859
    589         machine->vtbl->GetAccessible(machine, &isAccessible);
     860        IMachine_get_Accessible(machine, &isAccessible);
    590861
    591862        if (isAccessible)
    592863        {
    593             PRUnichar *machineNameUtf16;
     864            BSTR machineNameUtf16;
    594865            char *machineName;
    595866
    596             machine->vtbl->GetName(machine, &machineNameUtf16);
     867            IMachine_get_Name(machine, &machineNameUtf16);
    597868            g_pVBoxFuncs->pfnUtf16ToUtf8(machineNameUtf16,&machineName);
    598             g_pVBoxFuncs->pfnComUnallocMem(machineNameUtf16);
     869            g_pVBoxFuncs->pfnComUnallocString(machineNameUtf16);
    599870            printf("\tName:        %s\n", machineName);
    600871            g_pVBoxFuncs->pfnUtf8Free(machineName);
     
    606877
    607878        {
    608             PRUnichar *uuidUtf16;
     879            BSTR uuidUtf16;
    609880            char      *uuidUtf8;
    610881
    611             machine->vtbl->GetId(machine, &uuidUtf16);
     882            IMachine_get_Id(machine, &uuidUtf16);
    612883            g_pVBoxFuncs->pfnUtf16ToUtf8(uuidUtf16, &uuidUtf8);
    613             g_pVBoxFuncs->pfnComUnallocMem(uuidUtf16);
     884            g_pVBoxFuncs->pfnComUnallocString(uuidUtf16);
    614885            printf("\tUUID:        %s\n", uuidUtf8);
    615886            g_pVBoxFuncs->pfnUtf8Free(uuidUtf8);
     
    619890        {
    620891            {
    621                 PRUnichar *configFileUtf16;
     892                BSTR      configFileUtf16;
    622893                char      *configFileUtf8;
    623894
    624                 machine->vtbl->GetSettingsFilePath(machine, &configFileUtf16);
     895                IMachine_get_SettingsFilePath(machine, &configFileUtf16);
    625896                g_pVBoxFuncs->pfnUtf16ToUtf8(configFileUtf16, &configFileUtf8);
    626                 g_pVBoxFuncs->pfnComUnallocMem(configFileUtf16);
     897                g_pVBoxFuncs->pfnComUnallocString(configFileUtf16);
    627898                printf("\tConfig file: %s\n", configFileUtf8);
    628899                g_pVBoxFuncs->pfnUtf8Free(configFileUtf8);
     
    630901
    631902            {
    632                 PRUint32 memorySize;
    633 
    634                 machine->vtbl->GetMemorySize(machine, &memorySize);
     903                ULONG memorySize;
     904
     905                IMachine_get_MemorySize(machine, &memorySize);
    635906                printf("\tMemory size: %uMB\n", memorySize);
    636907            }
    637908
    638909            {
    639                 PRUnichar *typeId;
    640                 PRUnichar *osNameUtf16;
     910                BSTR typeId;
     911                BSTR osNameUtf16;
    641912                char *osName;
    642913                IGuestOSType *osType = NULL;
    643914
    644                 machine->vtbl->GetOSTypeId(machine, &typeId);
    645                 virtualBox->vtbl->GetGuestOSType(virtualBox, typeId, &osType);
    646                 g_pVBoxFuncs->pfnComUnallocMem(typeId);
    647                 osType->vtbl->GetDescription(osType, &osNameUtf16);
     915                IMachine_get_OSTypeId(machine, &typeId);
     916                IVirtualBox_GetGuestOSType(virtualBox, typeId, &osType);
     917                g_pVBoxFuncs->pfnComUnallocString(typeId);
     918                IGuestOSType_get_Description(osType, &osNameUtf16);
    648919                g_pVBoxFuncs->pfnUtf16ToUtf8(osNameUtf16,&osName);
    649                 g_pVBoxFuncs->pfnComUnallocMem(osNameUtf16);
     920                g_pVBoxFuncs->pfnComUnallocString(osNameUtf16);
    650921                printf("\tGuest OS:    %s\n\n", osName);
    651922                g_pVBoxFuncs->pfnUtf8Free(osName);
    652923
    653                 osType->vtbl->nsisupports.Release((nsISupports *)osType);
     924                IGuestOSType_Release(osType);
    654925            }
    655926        }
     
    670941        if (machine)
    671942        {
    672             PRUnichar *uuidUtf16 = NULL;
    673 
    674             machine->vtbl->GetId(machine, &uuidUtf16);
    675             startVM(argv0, virtualBox, session, uuidUtf16, queue);
    676             g_pVBoxFuncs->pfnComUnallocMem(uuidUtf16);
     943            BSTR uuidUtf16 = NULL;
     944
     945            IMachine_get_Id(machine, &uuidUtf16);
     946            startVM(argv0, virtualBox, session, uuidUtf16);
     947            g_pVBoxFuncs->pfnComUnallocString(uuidUtf16);
    677948        }
    678949    }
     
    688959        if (machine)
    689960        {
    690             machine->vtbl->nsisupports.Release((nsISupports *)machine);
     961            IMachine_Release(machine);
    691962        }
    692963    }
    693964    if (machines)
    694         g_pVBoxFuncs->pfnComUnallocMem(machines);
     965        free(machines);
    695966}
    696967
     
    702973    IVirtualBox *vbox            = NULL;
    703974    ISession   *session          = NULL;
    704     nsIEventQueue *queue         = NULL;
    705     PRUint32    revision         = 0;
    706     PRUnichar  *versionUtf16     = NULL;
    707     PRUnichar  *homefolderUtf16  = NULL;
    708     nsresult    rc;     /* Result code of various function (method) calls. */
     975    ULONG       revision         = 0;
     976    BSTR        versionUtf16     = NULL;
     977    BSTR        homefolderUtf16  = NULL;
     978    HRESULT    rc;     /* Result code of various function (method) calls. */
    709979
    710980    printf("Starting main()\n");
     
    724994    }
    725995
    726     g_pVBoxFuncs->pfnClientInitialize(IVIRTUALBOXCLIENT_IID_STR, &vboxclient);
    727     if (vboxclient == NULL)
     996    g_pVBoxFuncs->pfnClientInitialize(NULL, &vboxclient);
     997    if (!vboxclient)
    728998    {
    729999        fprintf(stderr, "%s: FATAL: could not get VirtualBoxClient reference\n", argv[0]);
     
    7331003    printf("----------------------------------------------------\n");
    7341004
    735     rc = vboxclient->vtbl->GetVirtualBox(vboxclient, &vbox);
    736     if (NS_FAILED(rc) || !vbox)
     1005    rc = IVirtualBoxClient_get_VirtualBox(vboxclient, &vbox);
     1006    if (FAILED(rc) || !vbox)
    7371007    {
    7381008        PrintErrorInfo(argv[0], "FATAL: could not get VirtualBox reference", rc);
    7391009        return EXIT_FAILURE;
    7401010    }
    741     rc = vboxclient->vtbl->GetSession(vboxclient, &session);
    742     if (NS_FAILED(rc) || !session)
     1011    rc = IVirtualBoxClient_get_Session(vboxclient, &session);
     1012    if (FAILED(rc) || !session)
    7431013    {
    7441014        PrintErrorInfo(argv[0], "FATAL: could not get Session reference", rc);
     
    7461016    }
    7471017
    748     g_pVBoxFuncs->pfnGetEventQueue(&queue);
     1018#ifdef USE_ACTIVE_EVENT_LISTENER
     1019# ifdef WIN32
     1020    rc = LoadTypeInfo(&IID_IEventListener, &g_pTInfoIEventListener);
     1021    if (FAILED(rc) || !g_pTInfoIEventListener)
     1022    {
     1023        PrintErrorInfo(argv[0], "FATAL: could not get type information for IEventListener", rc);
     1024        return EXIT_FAILURE;
     1025    }
     1026# endif /* WIN32 */
     1027#endif /* USE_ACTIVE_EVENT_LISTENER */
    7491028
    7501029    /*
     
    7561035    /* 1. Revision */
    7571036
    758     rc = vbox->vtbl->GetRevision(vbox, &revision);
    759     if (NS_SUCCEEDED(rc))
     1037    rc = IVirtualBox_get_Revision(vbox, &revision);
     1038    if (SUCCEEDED(rc))
    7601039        printf("\tRevision: %u\n", revision);
    7611040    else
     
    7641043    /* 2. Version */
    7651044
    766     rc = vbox->vtbl->GetVersion(vbox, &versionUtf16);
    767     if (NS_SUCCEEDED(rc))
     1045    rc = IVirtualBox_get_Version(vbox, &versionUtf16);
     1046    if (SUCCEEDED(rc))
    7681047    {
    7691048        char *version = NULL;
     
    7711050        printf("\tVersion: %s\n", version);
    7721051        g_pVBoxFuncs->pfnUtf8Free(version);
    773         g_pVBoxFuncs->pfnComUnallocMem(versionUtf16);
     1052        g_pVBoxFuncs->pfnComUnallocString(versionUtf16);
    7741053    }
    7751054    else
     
    7781057    /* 3. Home Folder */
    7791058
    780     rc = vbox->vtbl->GetHomeFolder(vbox, &homefolderUtf16);
    781     if (NS_SUCCEEDED(rc))
     1059    rc = IVirtualBox_get_HomeFolder(vbox, &homefolderUtf16);
     1060    if (SUCCEEDED(rc))
    7821061    {
    7831062        char *homefolder = NULL;
     
    7851064        printf("\tHomeFolder: %s\n", homefolder);
    7861065        g_pVBoxFuncs->pfnUtf8Free(homefolder);
    787         g_pVBoxFuncs->pfnComUnallocMem(homefolderUtf16);
     1066        g_pVBoxFuncs->pfnComUnallocString(homefolderUtf16);
    7881067    }
    7891068    else
    7901069        PrintErrorInfo(argv[0], "GetHomeFolder() failed", rc);
    7911070
    792     listVMs(argv[0], vbox, session, queue);
    793     session->vtbl->UnlockMachine(session);
     1071    listVMs(argv[0], vbox, session);
     1072    ISession_UnlockMachine(session);
    7941073
    7951074    printf("----------------------------------------------------\n");
     
    7991078     */
    8001079
     1080#ifdef USE_ACTIVE_EVENT_LISTENER
     1081# ifdef WIN32
     1082    if (g_pTInfoIEventListener)
     1083    {
     1084        ITypeInfo_Release(g_pTInfoIEventListener);
     1085        g_pTInfoIEventListener = NULL;
     1086    }
     1087# endif /* WIN32 */
     1088#endif /* USE_ACTIVE_EVENT_LISTENER */
     1089
    8011090    if (session)
    8021091    {
    803         session->vtbl->nsisupports.Release((nsISupports *)session);
     1092        ISession_Release(session);
    8041093        session = NULL;
    8051094    }
    8061095    if (vbox)
    8071096    {
    808         vbox->vtbl->nsisupports.Release((nsISupports *)vbox);
     1097        IVirtualBox_Release(vbox);
    8091098        vbox = NULL;
    8101099    }
    8111100    if (vboxclient)
    8121101    {
    813         vboxclient->vtbl->nsisupports.Release((nsISupports *)vboxclient);
     1102        IVirtualBoxClient_Release(vboxclient);
    8141103        vboxclient = NULL;
    8151104    }
     1105
    8161106    g_pVBoxFuncs->pfnClientUninitialize();
    8171107    VBoxCGlueTerm();
  • trunk/src/VBox/Main/glue/glue-java.xsl

    r48005 r50183  
    1111        VirtualBox.xidl.
    1212
    13     Copyright (C) 2010-2013 Oracle Corporation
     13    Copyright (C) 2010-2014 Oracle Corporation
    1414
    1515    This file is part of VirtualBox Open Source Edition (OSE), as
     
    4747  <xsl:param name="name" />
    4848  <xsl:text>/*
    49  * Copyright (C) 2010-2013 Oracle Corporation
     49 * Copyright (C) 2010-2014 Oracle Corporation
    5050 *
    5151 * This file is part of the VirtualBox SDK, as available from
     
    24872487        <xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
    24882488        <xsl:choose>
    2489           <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
     2489          <xsl:when test="($extends = '$unknown') or ($extends = '$errorinfo')">
    24902490            <xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown&#10;')" />
    24912491            <xsl:text>{&#10;&#10;</xsl:text>
  • trunk/src/VBox/Main/idl/apiwrap-server.xsl

    r49994 r50183  
    66        VirtualBox.xidl.
    77
    8      Copyright (C) 2010-2013 Oracle Corporation
     8     Copyright (C) 2010-2014 Oracle Corporation
    99
    1010     This file is part of VirtualBox Open Source Edition (OSE), as
     
    7878
    7979/**
    80  * Copyright (C) 2011-2013 Oracle Corporation
     80 * Copyright (C) 2010-2014 Oracle Corporation
    8181 *
    8282 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    9898    <!-- now recurse to emit all base interfaces -->
    9999    <xsl:variable name="extends" select="$iface/@extends"/>
    100     <xsl:if test="$extends and not($extends='$unknown') and not($extends='$dispatched') and not($extends='$errorinfo')">
     100    <xsl:if test="$extends and not($extends='$unknown') and not($extends='$errorinfo')">
    101101        <xsl:call-template name="emitCOMInterfaces">
    102102            <xsl:with-param name="iface" select="//interface[@name=$extends]"/>
     
    165165
    166166    <xsl:choose>
    167         <xsl:when test="$extends and not($extends='$unknown') and not($extends='$dispatched') and not($extends='$errorinfo')">
     167        <xsl:when test="$extends and not($extends='$unknown') and not($extends='$errorinfo')">
    168168            <xsl:variable name="newextends" select="//interface[@name=$extends]/@extends"/>
    169169            <xsl:variable name="newiflist" select="concat($interfacelist, ', ', $extends)"/>
     
    876876    <!-- first recurse to emit all base interfaces -->
    877877    <xsl:variable name="extends" select="$iface/@extends"/>
    878     <xsl:if test="$extends and not($extends='$unknown') and not($extends='$dispatched') and not($extends='$errorinfo')">
     878    <xsl:if test="$extends and not($extends='$unknown') and not($extends='$errorinfo')">
    879879        <xsl:call-template name="emitAttributes">
    880880            <xsl:with-param name="iface" select="//interface[@name=$extends]"/>
     
    11311131    <!-- first recurse to emit all base interfaces -->
    11321132    <xsl:variable name="extends" select="$iface/@extends"/>
    1133     <xsl:if test="$extends and not($extends='$unknown') and not($extends='$dispatched') and not($extends='$errorinfo')">
     1133    <xsl:if test="$extends and not($extends='$unknown') and not($extends='$errorinfo')">
    11341134        <xsl:call-template name="emitMethods">
    11351135            <xsl:with-param name="iface" select="//interface[@name=$extends]"/>
  • trunk/src/VBox/Main/idl/midl.xsl

    r49908 r50183  
    66 *  from the generic interface definition expressed in XML.
    77
    8     Copyright (C) 2006-2012 Oracle Corporation
     8    Copyright (C) 2006-2014 Oracle Corporation
    99
    1010    This file is part of VirtualBox Open Source Edition (OSE), as
     
    243243  <xsl:choose>
    244244    <xsl:when test="@extends='$unknown'">IDispatch</xsl:when>
    245     <xsl:when test="@extends='$dispatched'">IDispatch</xsl:when>
    246245    <xsl:when test="@extends='$errorinfo'">IErrorInfo</xsl:when>
    247246    <xsl:otherwise><xsl:value-of select="@extends"/></xsl:otherwise>
  • trunk/src/VBox/Main/idl/xpidl.xsl

    r50121 r50183  
    244244  <xsl:choose>
    245245      <xsl:when test="@extends='$unknown'">nsISupports</xsl:when>
    246       <xsl:when test="@extends='$dispatched'">nsISupports</xsl:when>
    247246      <xsl:when test="@extends='$errorinfo'">nsIException</xsl:when>
    248247      <xsl:otherwise><xsl:value-of select="@extends"/></xsl:otherwise>
  • trunk/src/VBox/Main/webservice/websrv-php.xsl

    r45483 r50183  
    1212     Contributed by James Lucas (mjlucas at eng.uts.edu.au).
    1313
    14     Copyright (C) 2008-2013 Oracle Corporation
     14    Copyright (C) 2008-2014 Oracle Corporation
    1515
    1616    This file is part of VirtualBox Open Source Edition (OSE), as
     
    169169</xsl:text>
    170170   <xsl:choose>
    171       <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
     171      <xsl:when test="($extends = '$unknown') or ($extends = '$errorinfo')">
    172172         <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject&#10;{&#10;')" />
    173173      </xsl:when>
     
    361361
    362362/*
    363  * Copyright (C) 2008-2013 Oracle Corporation
     363 * Copyright (C) 2008-2014 Oracle Corporation
    364364 *
    365365 * This file is part of a free software library; you can redistribute
  • trunk/src/VBox/Main/webservice/websrv-python.xsl

    r45483 r50183  
    1010        web service API. Depends on WSDL file for actual SOAP bindings.
    1111
    12     Copyright (C) 2008-2013 Oracle Corporation
     12    Copyright (C) 2008-2014 Oracle Corporation
    1313
    1414    This file is part of VirtualBox Open Source Edition (OSE), as
     
    5252    <xsl:when test="$type='octet'">Octet</xsl:when>
    5353    <xsl:when test="$type='$unknown'">IUnknown</xsl:when>
    54     <xsl:when test="$type='$dispatched'">IUnknown</xsl:when>
    5554    <xsl:otherwise><xsl:value-of select="$type" /></xsl:otherwise>
    5655  </xsl:choose>
     
    149148
    150149  <xsl:choose>
    151     <xsl:when test="($base = '$unknown') or ($base = '$dispatched')">
     150    <xsl:when test="($base = '$unknown')">
    152151      <xsl:value-of select="'IUnknown'"/>
    153152    </xsl:when>
     
    469468
    470469<xsl:template match="/">
    471 <xsl:text># Copyright (C) 2008-2011 Oracle Corporation
     470<xsl:text># Copyright (C) 2008-2014 Oracle Corporation
    472471#
    473472# This file is part of a free software library; you can redistribute
Note: See TracChangeset for help on using the changeset viewer.

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