Index: /trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp
===================================================================
--- /trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp	(revision 62769)
+++ /trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp	(revision 62770)
@@ -69,9 +69,7 @@
 VBoxUtf8ToUtf16(const char *pszString, BSTR *ppwszString)
 {
+    *ppwszString = NULL;
     if (!pszString)
-    {
-        *ppwszString = NULL;
         return VINF_SUCCESS;
-    }
 #ifdef VBOX_WITH_XPCOM
     return RTStrToUtf16(pszString, ppwszString);
@@ -79,6 +77,11 @@
     PRTUTF16 pwsz;
     int vrc = RTStrToUtf16(pszString, &pwsz);
-    *ppwszString = ::SysAllocString(pwsz);
-    RTUtf16Free(pwsz);
+    if (RT_SUCCESS(vrc))
+    {
+        *ppwszString = ::SysAllocString(pwsz);
+        if (!*ppwszString)
+            vrc = VERR_NO_STR_MEMORY;
+        RTUtf16Free(pwsz);
+    }
     return vrc;
 #endif /* !VBOX_WITH_XPCOM */
@@ -102,7 +105,7 @@
 #ifdef VBOX_WITH_XPCOM
     RTUtf16Free(pwszString);
-#else /* !VBOX_WITH_XPCOM */
+#else
     ::SysFreeString(pwszString);
-#endif /* !VBOX_WITH_XPCOM */
+#endif
 }
 
@@ -120,7 +123,7 @@
 #ifdef VBOX_WITH_XPCOM
         nsMemory::Free(pwsz);
-#else /* !VBOX_WITH_XPCOM */
+#else
         ::SysFreeString(pwsz);
-#endif /* !VBOX_WITH_XPCOM */
+#endif
     }
 }
@@ -254,5 +257,5 @@
 #ifndef VBOX_WITH_XPCOM
     SafeArrayUnaccessData(psa);
-#endif /* !VBOX_WITH_XPCOM */
+#endif
     return S_OK;
 }
@@ -317,5 +320,5 @@
 #ifndef VBOX_WITH_XPCOM
     SafeArrayUnaccessData(psa);
-#endif /* !VBOX_WITH_XPCOM */
+#endif
     return S_OK;
 }
Index: /trunk/src/VBox/Main/cbinding/capiidl.xsl
===================================================================
--- /trunk/src/VBox/Main/cbinding/capiidl.xsl	(revision 62769)
+++ /trunk/src/VBox/Main/cbinding/capiidl.xsl	(revision 62770)
@@ -96,7 +96,10 @@
 
 #ifdef _WIN32
+# pragma warning(push)
+# pragma warning(disable:4668 4255) /* -Wall and windows.h */
 # undef COBJMACROS
 # define COBJMACROS
 # include "Windows.h"
+# pragma warning(pop)
 #endif /* _WIN32 */
 
Index: /trunk/src/VBox/Main/cbinding/tstCAPIGlue.c
===================================================================
--- /trunk/src/VBox/Main/cbinding/tstCAPIGlue.c	(revision 62769)
+++ /trunk/src/VBox/Main/cbinding/tstCAPIGlue.c	(revision 62770)
@@ -32,4 +32,7 @@
 # include <unistd.h>
 # include <sys/poll.h>
+#endif
+#ifdef ___iprt_cdefs_h
+# error "not supposed to involve any IPRT or VBox headers here."
 #endif
 
@@ -432,7 +435,6 @@
  * @param   virtualBox ptr to IVirtualBox object
  * @param   session    ptr to ISession object
- * @param   id         identifies the machine to start
  */
-static void registerActiveEventListener(IVirtualBox *virtualBox, ISession *session, BSTR machineId)
+static void registerActiveEventListener(IVirtualBox *virtualBox, ISession *session)
 {
     IConsole *console = NULL;
@@ -446,24 +448,24 @@
         if (SUCCEEDED(rc) && es)
         {
-            static const ULONG interestingEvents[] =
-                {
-                    VBoxEventType_OnMousePointerShapeChanged,
-                    VBoxEventType_OnMouseCapabilityChanged,
-                    VBoxEventType_OnKeyboardLedsChanged,
-                    VBoxEventType_OnStateChanged,
-                    VBoxEventType_OnAdditionsStateChanged,
-                    VBoxEventType_OnNetworkAdapterChanged,
-                    VBoxEventType_OnSerialPortChanged,
-                    VBoxEventType_OnParallelPortChanged,
-                    VBoxEventType_OnStorageControllerChanged,
-                    VBoxEventType_OnMediumChanged,
-                    VBoxEventType_OnVRDEServerChanged,
-                    VBoxEventType_OnUSBControllerChanged,
-                    VBoxEventType_OnUSBDeviceStateChanged,
-                    VBoxEventType_OnSharedFolderChanged,
-                    VBoxEventType_OnRuntimeError,
-                    VBoxEventType_OnCanShowWindow,
-                    VBoxEventType_OnShowWindow
-                };
+            static const ULONG s_auInterestingEvents[] =
+            {
+                VBoxEventType_OnMousePointerShapeChanged,
+                VBoxEventType_OnMouseCapabilityChanged,
+                VBoxEventType_OnKeyboardLedsChanged,
+                VBoxEventType_OnStateChanged,
+                VBoxEventType_OnAdditionsStateChanged,
+                VBoxEventType_OnNetworkAdapterChanged,
+                VBoxEventType_OnSerialPortChanged,
+                VBoxEventType_OnParallelPortChanged,
+                VBoxEventType_OnStorageControllerChanged,
+                VBoxEventType_OnMediumChanged,
+                VBoxEventType_OnVRDEServerChanged,
+                VBoxEventType_OnUSBControllerChanged,
+                VBoxEventType_OnUSBDeviceStateChanged,
+                VBoxEventType_OnSharedFolderChanged,
+                VBoxEventType_OnRuntimeError,
+                VBoxEventType_OnCanShowWindow,
+                VBoxEventType_OnShowWindow
+            };
             SAFEARRAY *interestingEventsSA = NULL;
             IEventListenerDemo *consoleListener = NULL;
@@ -471,6 +473,9 @@
             /* The VirtualBox API expects enum values as VT_I4, which in the
              * future can be hopefully relaxed. */
-            interestingEventsSA = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0, sizeof(interestingEvents) / sizeof(interestingEvents[0]));
-            g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(interestingEventsSA, &interestingEvents, sizeof(interestingEvents));
+            interestingEventsSA = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0,
+                                                                           sizeof(s_auInterestingEvents)
+                                                                         / sizeof(s_auInterestingEvents[0]));
+            g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(interestingEventsSA, &s_auInterestingEvents,
+                                                        sizeof(s_auInterestingEvents));
 
             consoleListener = calloc(1, sizeof(IEventListenerDemo));
@@ -499,7 +504,5 @@
 
                     while (!g_fStop)
-                    {
                         g_pVBoxFuncs->pfnProcessEventQueue(250);
-                    }
 
 #ifdef WIN32
@@ -510,7 +513,5 @@
                 }
                 else
-                {
                     printf("Failed to register event listener.\n");
-                }
                 IEventSource_UnregisterListener(es, (IEventListener *)consoleListener);
 #ifdef WIN32
@@ -521,14 +522,10 @@
             }
             else
-            {
                 printf("Failed while allocating memory for console event listener.\n");
-            }
             g_pVBoxFuncs->pfnSafeArrayDestroy(interestingEventsSA);
             IEventSource_Release(es);
         }
         else
-        {
             printf("Failed to get the event source instance.\n");
-        }
         IConsole_Release(console);
     }
@@ -542,7 +539,6 @@
  * @param   virtualBox ptr to IVirtualBox object
  * @param   session    ptr to ISession object
- * @param   id         identifies the machine to start
  */
-static void registerPassiveEventListener(IVirtualBox *virtualBox, ISession *session, BSTR machineId)
+static void registerPassiveEventListener(ISession *session)
 {
     IConsole *console = NULL;
@@ -550,5 +546,5 @@
 
     rc = ISession_get_Console(session, &console);
-    if ((SUCCEEDED(rc)) && console)
+    if (SUCCEEDED(rc) && console)
     {
         IEventSource *es = NULL;
@@ -556,24 +552,24 @@
         if (SUCCEEDED(rc) && es)
         {
-            static const ULONG interestingEvents[] =
-                {
-                    VBoxEventType_OnMousePointerShapeChanged,
-                    VBoxEventType_OnMouseCapabilityChanged,
-                    VBoxEventType_OnKeyboardLedsChanged,
-                    VBoxEventType_OnStateChanged,
-                    VBoxEventType_OnAdditionsStateChanged,
-                    VBoxEventType_OnNetworkAdapterChanged,
-                    VBoxEventType_OnSerialPortChanged,
-                    VBoxEventType_OnParallelPortChanged,
-                    VBoxEventType_OnStorageControllerChanged,
-                    VBoxEventType_OnMediumChanged,
-                    VBoxEventType_OnVRDEServerChanged,
-                    VBoxEventType_OnUSBControllerChanged,
-                    VBoxEventType_OnUSBDeviceStateChanged,
-                    VBoxEventType_OnSharedFolderChanged,
-                    VBoxEventType_OnRuntimeError,
-                    VBoxEventType_OnCanShowWindow,
-                    VBoxEventType_OnShowWindow
-                };
+            static const ULONG s_auInterestingEvents[] =
+            {
+                VBoxEventType_OnMousePointerShapeChanged,
+                VBoxEventType_OnMouseCapabilityChanged,
+                VBoxEventType_OnKeyboardLedsChanged,
+                VBoxEventType_OnStateChanged,
+                VBoxEventType_OnAdditionsStateChanged,
+                VBoxEventType_OnNetworkAdapterChanged,
+                VBoxEventType_OnSerialPortChanged,
+                VBoxEventType_OnParallelPortChanged,
+                VBoxEventType_OnStorageControllerChanged,
+                VBoxEventType_OnMediumChanged,
+                VBoxEventType_OnVRDEServerChanged,
+                VBoxEventType_OnUSBControllerChanged,
+                VBoxEventType_OnUSBDeviceStateChanged,
+                VBoxEventType_OnSharedFolderChanged,
+                VBoxEventType_OnRuntimeError,
+                VBoxEventType_OnCanShowWindow,
+                VBoxEventType_OnShowWindow
+            };
             SAFEARRAY *interestingEventsSA = NULL;
             IEventListener *consoleListener = NULL;
@@ -581,6 +577,9 @@
             /* The VirtualBox API expects enum values as VT_I4, which in the
              * future can be hopefully relaxed. */
-            interestingEventsSA = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0, sizeof(interestingEvents) / sizeof(interestingEvents[0]));
-            g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(interestingEventsSA, &interestingEvents, sizeof(interestingEvents));
+            interestingEventsSA = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0,
+                                                                           sizeof(s_auInterestingEvents)
+                                                                         / sizeof(s_auInterestingEvents[0]));
+            g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(interestingEventsSA, &s_auInterestingEvents,
+                                                        sizeof(s_auInterestingEvents));
 
             rc = IEventSource_CreateListener(es, &consoleListener);
@@ -643,21 +642,15 @@
                 }
                 else
-                {
                     printf("Failed to register event listener.\n");
-                }
                 IEventSource_UnregisterListener(es, (IEventListener *)consoleListener);
                 IEventListener_Release(consoleListener);
             }
             else
-            {
                 printf("Failed to create an event listener instance.\n");
-            }
             g_pVBoxFuncs->pfnSafeArrayDestroy(interestingEventsSA);
             IEventSource_Release(es);
         }
         else
-        {
             printf("Failed to get the event source instance.\n");
-        }
         IConsole_Release(console);
     }
@@ -675,5 +668,5 @@
 {
     IErrorInfo *ex;
-    HRESULT rc2 = S_OK;
+    HRESULT rc2;
     fprintf(stderr, "%s: %s (rc=%#010x)\n", pszExecutable, pszErrorMsg, (unsigned)rc);
     rc2 = g_pVBoxFuncs->pfnGetException(&ex);
@@ -682,7 +675,5 @@
         IVirtualBoxErrorInfo *ei;
         rc2 = IErrorInfo_QueryInterface(ex, &IID_IVirtualBoxErrorInfo, (void **)&ei);
-        if (FAILED(rc2))
-            ei = NULL;
-        if (ei)
+        if (SUCCEEDED(rc2) && ei != NULL)
         {
             /* got extended error info, maybe multiple infos */
@@ -717,6 +708,5 @@
                 IVirtualBoxErrorInfo_Release(ei);
                 ei = ei_next;
-            }
-            while (ei);
+            } while (ei);
         }
 
@@ -813,8 +803,8 @@
              * Ignore it if you need a more basic sample. */
 #ifdef USE_ACTIVE_EVENT_LISTENER
-            registerActiveEventListener(virtualBox, session, id);
-#else /* !USE_ACTIVE_EVENT_LISTENER */
-            registerPassiveEventListener(virtualBox, session, id);
-#endif /* !USE_ACTIVE_EVENT_LISTENER */
+            registerActiveEventListener(virtualBox, session);
+#else
+            registerPassiveEventListener(session);
+#endif
         }
         IProgress_Release(progress);
@@ -872,5 +862,4 @@
      * Iterate through the collection.
      */
-
     for (i = 0; i < machineCnt; ++i)
     {
@@ -900,7 +889,5 @@
         }
         else
-        {
             printf("\tName:        <inaccessible>\n");
-        }
 
         {
@@ -958,7 +945,6 @@
      * Let the user chose a machine to start.
      */
-
     printf("Type Machine# to start (0 - %u) or 'quit' to do nothing: ",
-        (unsigned)(machineCnt - 1));
+           (unsigned)(machineCnt - 1));
     fflush(stdout);
 
@@ -980,5 +966,4 @@
      * Don't forget to release the objects in the array.
      */
-
     for (i = 0; i < machineCnt; ++i)
     {
@@ -986,7 +971,5 @@
 
         if (machine)
-        {
             IMachine_Release(machine);
-        }
     }
     g_pVBoxFuncs->pfnArrayOutFree(machines);
@@ -1003,5 +986,6 @@
     BSTR        versionUtf16     = NULL;
     BSTR        homefolderUtf16  = NULL;
-    HRESULT    rc;     /* Result code of various function (method) calls. */
+    HRESULT     rc;     /* Result code of various function (method) calls. */
+    (void)argc;
 
     printf("Starting main()\n");
@@ -1061,5 +1045,4 @@
 
     /* 1. Revision */
-
     rc = IVirtualBox_get_Revision(vbox, &revision);
     if (SUCCEEDED(rc))
@@ -1069,5 +1052,4 @@
 
     /* 2. Version */
-
     rc = IVirtualBox_get_Version(vbox, &versionUtf16);
     if (SUCCEEDED(rc))
@@ -1083,5 +1065,4 @@
 
     /* 3. Home Folder */
-
     rc = IVirtualBox_get_HomeFolder(vbox, &homefolderUtf16);
     if (SUCCEEDED(rc))
@@ -1104,5 +1085,4 @@
      * Do as mom told us: always clean up after yourself.
      */
-
 #ifdef USE_ACTIVE_EVENT_LISTENER
 # ifdef WIN32
