Index: /trunk/src/VBox/Main/testcase/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Main/testcase/Makefile.kmk	(revision 50338)
+++ /trunk/src/VBox/Main/testcase/Makefile.kmk	(revision 50339)
@@ -5,5 +5,5 @@
 
 #
-# Copyright (C) 2004-2013 Oracle Corporation
+# Copyright (C) 2004-2014 Oracle Corporation
 #
 # This file is part of VirtualBox Open Source Edition (OSE), as
@@ -102,6 +102,29 @@
 # It comes with a custom makefile which should be tested as well!
 #
-tstVBoxAPIXPCOM_TEMPLATE = VBOXMAINCLIENTTSTEXE
+# Use very generic template to make the build environment similar
+# to the standalone case, to detect if IPRT or glue use sneaks in.
+#
+tstVBoxAPIXPCOM_TEMPLATE = VBoxBldProg
+tstVBoxAPIXPCOM_INST = $(INST_TESTCASE)
 tstVBoxAPIXPCOM_SOURCES  = tstVBoxAPIXPCOM.cpp
+tstVBoxAPIXPCOM_INCS = \
+	$(VBOX_PATH_SDK)/bindings/xpcom/include \
+	$(VBOX_PATH_SDK)/bindings/xpcom/include/nsprpub \
+	$(VBOX_PATH_SDK)/bindings/xpcom/include/string \
+	$(VBOX_PATH_SDK)/bindings/xpcom/include/xpcom \
+	$(VBOX_PATH_SDK)/bindings/xpcom/include/ipcd
+tstVBoxAPIXPCOM_LIBS = \
+	$(LIB_XPCOM)
+tstVBoxAPIXPCOM_CXXFLAGS = -fshort-wchar
+ifdef VBOX_WITH_RUNPATH
+ tstVBoxAPIXPCOM_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' $(TEMPLATE_VBoxBldProg_LDFLAGS)
+else ifdef VBOX_WITH_RELATIVE_RUNPATH
+ tstVBoxAPIXPCOM_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..' $(TEMPLATE_VBoxBldProg_LDFLAGS)
+endif
+tstVBoxAPIXPCOM_INTERMEDIATES = \
+	$(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h
+ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
+ tstVBoxAPIXPCOM_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
+endif
 
 
@@ -109,8 +132,16 @@
 # tstVBoxAPIWin
 #
-tstVBoxAPIWin_TEMPLATE = VBOXMAINCLIENTTSTEXE
+# Use very generic template to make the build environment similar
+# to the standalone case, to detect if IPRT or glue use sneaks in.
+#
+tstVBoxAPIWin_TEMPLATE = VBoxBldProg
+tstVBoxAPIWin_INST = $(INST_TESTCASE)
 tstVBoxAPIWin_SOURCES  = \
 	tstVBoxAPIWin.cpp \
 	$(VBOX_PATH_SDK)/bindings/mscom/lib/VirtualBox_i.c
+tstVBoxAPIWin_INCS = \
+	$(VBOX_PATH_SDK)/bindings/mscom/include
+tstVBoxAPIWin_INTERMEDIATES = \
+	$(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h
 
 
Index: /trunk/src/VBox/Main/testcase/makefile.tstVBoxAPIXPCOM
===================================================================
--- /trunk/src/VBox/Main/testcase/makefile.tstVBoxAPIXPCOM	(revision 50338)
+++ /trunk/src/VBox/Main/testcase/makefile.tstVBoxAPIXPCOM	(revision 50339)
@@ -3,5 +3,5 @@
 #
 #
-# Copyright (C) 2006-2013 Oracle Corporation
+# Copyright (C) 2006-2014 Oracle Corporation
 #
 # This file is part of VirtualBox Open Source Edition (OSE), as
@@ -32,4 +32,8 @@
 endif
 
+# Adjust this to match your platform, pick from RT_OS_LINUX, RT_OS_WINDOWS,
+# RT_OS_DARWIN, RT_OS_SOLARIS...
+DEFS_XPCOM += RT_OS_LINUX
+
 
 #
Index: /trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp
===================================================================
--- /trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp	(revision 50338)
+++ /trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp	(revision 50339)
@@ -13,5 +13,5 @@
 
 /*
- * Copyright (C) 2006-2010 Oracle Corporation
+ * Copyright (C) 2006-2014 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -74,5 +74,5 @@
     {
         IMachine **machines;
-        rc = SafeArrayAccessData (machinesArray, (void **) &machines);
+        rc = SafeArrayAccessData(machinesArray, (void **) &machines);
         if (SUCCEEDED(rc))
         {
@@ -89,8 +89,8 @@
             }
 
-            SafeArrayUnaccessData (machinesArray);
-        }
-
-        SafeArrayDestroy (machinesArray);
+            SafeArrayUnaccessData(machinesArray);
+        }
+
+        SafeArrayDestroy(machinesArray);
     }
 
@@ -218,6 +218,6 @@
 
             /* Wait until VM is running. */
-            printf ("Starting VM, please wait ...\n");
-            rc = progress->WaitForCompletion (-1);
+            printf("Starting VM, please wait ...\n");
+            rc = progress->WaitForCompletion(-1);
 
             /* Get console object. */
@@ -227,5 +227,5 @@
             machine->ShowConsoleWindow(0);
 
-            printf ("Press enter to power off VM and close the session...\n");
+            printf("Press enter to power off VM and close the session...\n");
             getchar();
 
@@ -234,6 +234,6 @@
 
             /* Wait until VM is powered down. */
-            printf ("Powering off VM, please wait ...\n");
-            rc = progress->WaitForCompletion (-1);
+            printf("Powering off VM, please wait ...\n");
+            rc = progress->WaitForCompletion(-1);
 
             /* Close the session. */
Index: /trunk/src/VBox/Main/testcase/tstVBoxAPIXPCOM.cpp
===================================================================
--- /trunk/src/VBox/Main/testcase/tstVBoxAPIXPCOM.cpp	(revision 50338)
+++ /trunk/src/VBox/Main/testcase/tstVBoxAPIXPCOM.cpp	(revision 50339)
@@ -1,6 +1,6 @@
 /** @file
  *
- * tstVBoxAPILinux - sample program to illustrate the VirtualBox
- *                   XPCOM API for machine management on Linux.
+ * tstVBoxAPIXPCOM - sample program to illustrate the VirtualBox
+ *                   XPCOM API for machine management.
  *                   It only uses standard C/C++ and XPCOM semantics,
  *                   no additional VBox classes/macros/helpers.
@@ -53,5 +53,5 @@
  * use the following (or similar) command to execute it:
  *
- *   $ env VBOX_XPCOM_HOME=../../.. LD_LIBRARY_PATH=../../.. ./tstVBoxAPILinux
+ *   $ env VBOX_XPCOM_HOME=../../.. LD_LIBRARY_PATH=../../.. ./tstVBoxAPIXPCOM
  *
  * The above command assumes that VBoxRT.so, VBoxXPCOM.so and others reside in
@@ -74,16 +74,4 @@
 #include <nsIExceptionService.h>
 
-#include <VBox/com/com.h>
-#include <VBox/com/string.h>
-#include <VBox/com/array.h>
-#include <VBox/com/Guid.h>
-#include <VBox/com/ErrorInfo.h>
-#include <VBox/com/errorprint.h>
-
-#include <VBox/com/VirtualBox.h>
-
-#include <iprt/stream.h>
-
-
 /*
  * VirtualBox XPCOM interface. This header is generated
@@ -109,6 +97,6 @@
     nsresult rc;
 
-    RTPrintf("----------------------------------------------------\n");
-    RTPrintf("VM List:\n\n");
+    printf("----------------------------------------------------\n");
+    printf("VM List:\n\n");
 
     /*
@@ -137,10 +125,10 @@
                     machine->GetName(getter_Copies(machineName));
                     char *machineNameAscii = ToNewCString(machineName);
-                    RTPrintf("\tName:        %s\n", machineNameAscii);
+                    printf("\tName:        %s\n", machineNameAscii);
                     free(machineNameAscii);
                 }
                 else
                 {
-                    RTPrintf("\tName:        <inaccessible>\n");
+                    printf("\tName:        <inaccessible>\n");
                 }
 
@@ -148,5 +136,5 @@
                 machine->GetId(getter_Copies(iid));
                 const char *uuidString = ToNewCString(iid);
-                RTPrintf("\tUUID:        %s\n", uuidString);
+                printf("\tUUID:        %s\n", uuidString);
                 free((void*)uuidString);
 
@@ -156,10 +144,10 @@
                     machine->GetSettingsFilePath(getter_Copies(configFile));
                     char *configFileAscii = ToNewCString(configFile);
-                    RTPrintf("\tConfig file: %s\n", configFileAscii);
+                    printf("\tConfig file: %s\n", configFileAscii);
                     free(configFileAscii);
 
                     PRUint32 memorySize;
                     machine->GetMemorySize(&memorySize);
-                    RTPrintf("\tMemory size: %uMB\n", memorySize);
+                    printf("\tMemory size: %uMB\n", memorySize);
 
                     nsXPIDLString typeId;
@@ -170,5 +158,5 @@
                     osType->GetDescription(getter_Copies(osName));
                     char *osNameAscii = ToNewCString(osName);
-                    RTPrintf("\tGuest OS:    %s\n\n", osNameAscii);
+                    printf("\tGuest OS:    %s\n\n", osNameAscii);
                     free(osNameAscii);
                     osType->Release();
@@ -180,5 +168,5 @@
         }
     }
-    RTPrintf("----------------------------------------------------\n\n");
+    printf("----------------------------------------------------\n\n");
 }
 
@@ -204,5 +192,5 @@
     if (NS_FAILED(rc))
     {
-        RTPrintf("Error: could not create machine! rc=%Rhrc\n", rc);
+        printf("Error: could not create machine! rc=%#x\n", rc);
         return;
     }
@@ -230,5 +218,5 @@
     if (NS_FAILED(rc))
     {
-        RTPrintf("Error: could not find guest OS type! rc=%Rhrc\n", rc);
+        printf("Error: could not find guest OS type! rc=%#x\n", rc);
     }
     else
@@ -248,5 +236,5 @@
     if (NS_FAILED(rc))
     {
-        RTPrintf("Error: could not register machine! rc=%Rhrc\n", rc);
+        printf("Error: could not register machine! rc=%#x\n", rc);
         printErrorInfo();
         return;
@@ -266,5 +254,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc);
+            printf("Error: could not get component manager! rc=%#x\n", rc);
             return;
         }
@@ -275,5 +263,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error, could not instantiate session object! rc=%Rhrc\n", rc);
+            printf("Error, could not instantiate session object! rc=%#x\n", rc);
             return;
         }
@@ -282,5 +270,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error, could not lock the machine for the session! rc=%Rhrc\n", rc);
+            printf("Error, could not lock the machine for the session! rc=%#x\n", rc);
             return;
         }
@@ -294,5 +282,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error, could not get machine session! rc=%Rhrc\n", rc);
+            printf("Error, could not get machine session! rc=%#x\n", rc);
             return;
         }
@@ -304,9 +292,9 @@
     nsCOMPtr<IMedium> hardDisk = 0;
     rc = virtualBox->CreateHardDisk(NS_LITERAL_STRING("VDI").get(),
-                                    NS_LITERAL_STRING("TestHardDisk.vdi").get(),
+                                    NS_LITERAL_STRING("/tmp/TestHardDisk.vdi").get(),
                                     getter_AddRefs(hardDisk));
     if (NS_FAILED(rc))
     {
-        RTPrintf("Failed creating a hard disk object! rc=%Rhrc\n", rc);
+        printf("Failed creating a hard disk object! rc=%#x\n", rc);
     }
     else
@@ -318,12 +306,12 @@
          */
         nsCOMPtr<IProgress> progress;
-        com::SafeArray<MediumVariant_T> mediumVariant;
-        mediumVariant.push_back(MediumVariant_Standard);
-        rc = hardDisk->CreateBaseStorage(100,                                // size in megabytes
-                                         ComSafeArrayAsInParam(mediumVariant),
+        MediumVariant_T mediumVariants[] =
+            { MediumVariant_Standard };
+        rc = hardDisk->CreateBaseStorage(100 * 1024 * 1024,                  // size in bytes
+                                         sizeof(mediumVariants) / sizeof(mediumVariants[0]), mediumVariants,
                                          getter_AddRefs(progress));          // optional progress object
         if (NS_FAILED(rc))
         {
-            RTPrintf("Failed creating hard disk image! rc=%Rhrc\n", rc);
+            printf("Failed creating hard disk image! rc=%#x\n", rc);
         }
         else
@@ -339,5 +327,5 @@
             if (NS_FAILED(rc) || NS_FAILED(resultCode))
             {
-                RTPrintf("Error: could not create hard disk! rc=%Rhrc\n",
+                printf("Error: could not create hard disk! rc=%#x\n",
                        NS_FAILED(rc) ? rc : resultCode);
             }
@@ -355,5 +343,5 @@
                 if (NS_FAILED(rc))
                 {
-                    RTPrintf("Error: could not attach hard disk! rc=%Rhrc\n", rc);
+                    printf("Error: could not attach hard disk! rc=%#x\n", rc);
                 }
             }
@@ -374,5 +362,5 @@
                                 getter_AddRefs(dvdImage));
     if (NS_FAILED(rc))
-        RTPrintf("Error: could not open CD image! rc=%Rhrc\n", rc);
+        printf("Error: could not open CD image! rc=%#x\n", rc);
     else
     {
@@ -388,5 +376,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error: could not mount ISO image! rc=%Rhrc\n", rc);
+            printf("Error: could not mount ISO image! rc=%#x\n", rc);
         }
         else
@@ -398,5 +386,5 @@
             if (NS_FAILED(rc))
             {
-                RTPrintf("Could not set boot device! rc=%Rhrc\n", rc);
+                printf("Could not set boot device! rc=%#x\n", rc);
             }
         }
@@ -408,5 +396,5 @@
     rc = sessionMachine->SaveSettings();
     if (NS_FAILED(rc))
-        RTPrintf("Could not save machine settings! rc=%Rhrc\n", rc);
+        printf("Could not save machine settings! rc=%#x\n", rc);
 
     /*
@@ -416,15 +404,16 @@
     session->UnlockMachine();
 
-    com::SafeIfaceArray<IMedium> aMedia;
+    IMedium **aMedia;
+    PRUint32 cMedia;
     rc = machine->Unregister((CleanupMode_T)CleanupMode_DetachAllReturnHardDisksOnly,
-                             ComSafeArrayAsOutParam(aMedia));
+                             &cMedia, &aMedia);
     if (NS_FAILED(rc))
-        RTPrintf("Unregistering the machine failed! rc=%Rhrc\n", rc);
+        printf("Unregistering the machine failed! rc=%#x\n", rc);
     else
     {
-        ComPtr<IProgress> pProgress;
-        rc = machine->DeleteConfig(ComSafeArrayAsInParam(aMedia), pProgress.asOutParam());
-        if (NS_FAILED(rc))
-            RTPrintf("Deleting of machine failed! rc=%Rhrc\n", rc);
+        nsCOMPtr<IProgress> pProgress;
+        rc = machine->DeleteConfig(cMedia, aMedia, getter_AddRefs(pProgress));
+        if (NS_FAILED(rc))
+            printf("Deleting of machine failed! rc=%#x\n", rc);
         else
         {
@@ -433,6 +422,6 @@
             pProgress->GetResultCode(&resultCode);
             if (NS_FAILED(rc) || NS_FAILED(resultCode))
-                RTPrintf("Failed to delete the machine! rc=%Rhrc\n",
-                         NS_FAILED(rc) ? rc : resultCode);
+                printf("Failed to delete the machine! rc=%#x\n",
+                       NS_FAILED(rc) ? rc : resultCode);
         }
     }
@@ -453,5 +442,5 @@
     if (sizeof(PRUnichar) != sizeof(wchar_t))
     {
-        RTPrintf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n"
+        printf("Error: sizeof(PRUnichar) {%lu} != sizeof(wchar_t) {%lu}!\n"
                "Probably, you forgot the -fshort-wchar compiler option.\n",
                (unsigned long) sizeof(PRUnichar),
@@ -476,5 +465,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error: XPCOM could not be initialized! rc=%Rhrc\n", rc);
+            printf("Error: XPCOM could not be initialized! rc=%#x\n", rc);
             return -1;
         }
@@ -489,5 +478,5 @@
         if (!registrar)
         {
-            RTPrintf("Error: could not query nsIComponentRegistrar interface!\n");
+            printf("Error: could not query nsIComponentRegistrar interface!\n");
             return -1;
         }
@@ -507,5 +496,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error: could not get main event queue! rc=%Rhrc\n", rc);
+            printf("Error: could not get main event queue! rc=%#x\n", rc);
             return -1;
         }
@@ -523,5 +512,5 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error: could not get component manager! rc=%Rhrc\n", rc);
+            printf("Error: could not get component manager! rc=%#x\n", rc);
             return -1;
         }
@@ -534,8 +523,8 @@
         if (NS_FAILED(rc))
         {
-            RTPrintf("Error, could not instantiate VirtualBox object! rc=%Rhrc\n", rc);
+            printf("Error, could not instantiate VirtualBox object! rc=%#x\n", rc);
             return -1;
         }
-        RTPrintf("VirtualBox object created\n");
+        printf("VirtualBox object created\n");
 
         ////////////////////////////////////////////////////////////////////////////////
@@ -567,5 +556,5 @@
      */
     NS_ShutdownXPCOM(nsnull);
-    RTPrintf("Done!\n");
+    printf("Done!\n");
     return 0;
 }
@@ -588,5 +577,5 @@
     if (res != NULL)
     {
-        RTStrPrintf(res, 39, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
+        snprintf(res, 39, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
                  guid->m0, (PRUint32)guid->m1, (PRUint32)guid->m2,
                  (PRUint32)guid->m3[0], (PRUint32)guid->m3[1], (PRUint32)guid->m3[2],
@@ -623,25 +612,25 @@
                 {
                     /* got extended error info */
-                    RTPrintf("Extended error info (IVirtualBoxErrorInfo):\n");
+                    printf("Extended error info (IVirtualBoxErrorInfo):\n");
                     PRInt32 resultCode = NS_OK;
                     info->GetResultCode(&resultCode);
-                    RTPrintf("  resultCode=%08X\n", resultCode);
+                    printf("  resultCode=%08X\n", resultCode);
                     nsXPIDLString component;
                     info->GetComponent(getter_Copies(component));
-                    RTPrintf("  component=%s\n", NS_ConvertUTF16toUTF8(component).get());
+                    printf("  component=%s\n", NS_ConvertUTF16toUTF8(component).get());
                     nsXPIDLString text;
                     info->GetText(getter_Copies(text));
-                    RTPrintf("  text=%s\n", NS_ConvertUTF16toUTF8(text).get());
+                    printf("  text=%s\n", NS_ConvertUTF16toUTF8(text).get());
                 }
                 else
                 {
                     /* got basic error info */
-                    RTPrintf("Basic error info (nsIException):\n");
+                    printf("Basic error info (nsIException):\n");
                     nsresult resultCode = NS_OK;
                     ex->GetResult(&resultCode);
-                    RTPrintf("  resultCode=%08X\n", resultCode);
+                    printf("  resultCode=%08X\n", resultCode);
                     nsXPIDLCString message;
                     ex->GetMessage(getter_Copies(message));
-                    RTPrintf("  message=%s\n", message.get());
+                    printf("  message=%s\n", message.get());
                 }
 
