Index: trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp	(revision 38791)
+++ trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp	(revision 38797)
@@ -560,14 +560,14 @@
 static VOID DoLogging(LPCSTR szString, ...)
 {
-    LOG_ROUTINE pRoutine = (LOG_ROUTINE)(*((void * volatile *)&g_Logger));
-    if (pRoutine)
+    LOG_ROUTINE pfnRoutine = (LOG_ROUTINE)(*((void * volatile *)&g_Logger));
+    if (pfnRoutine)
     {
         char szBuffer[4096] = {0};
-        va_list pArgList;
-        va_start(pArgList, szString);
-        _vsnprintf(szBuffer, RT_ELEMENTS(szBuffer), szString, pArgList);
-        va_end(pArgList);
-
-        pRoutine(szBuffer);
+        va_list va;
+        va_start(va, szString);
+        _vsnprintf(szBuffer, RT_ELEMENTS(szBuffer), szString, va);
+        va_end(va);
+
+        pfnRoutine(szBuffer);
     }
 }
@@ -789,38 +789,42 @@
 {
     HRESULT hr;
-    WCHAR aQueryString[256];
-    WCHAR GuidString[50];
-
-    int length = StringFromGUID2(*pGuid, GuidString, sizeof(GuidString)/sizeof(GuidString[0]));
+    WCHAR wszQuery[256];
+    WCHAR wszGuid[50];
+
+    int length = StringFromGUID2(*pGuid, wszGuid, RT_ELEMENTS(wszGuid));
     if (length)
     {
-        swprintf(aQueryString, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"%s\"", GuidString);
+        swprintf(wszQuery, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"%s\"", wszGuid);
         IEnumWbemClassObject* pEnumerator = NULL;
-        hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(aQueryString), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
+        hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(wszQuery), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
+                             NULL, &pEnumerator);
         if (SUCCEEDED(hr))
         {
-            IWbemClassObject *pclsObj;
-            ULONG uReturn = 0;
-
             if (pEnumerator)
             {
-                HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
-
+                IWbemClassObject *pclsObj;
+                ULONG uReturn = 0;
+                hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
+                NonStandardLogFlow(("netIfWinFindAdapterClassById: IEnumWbemClassObject::Next -> hr=0x%x pclsObj=%p uReturn=%u 42=%u\n", 
+                                    hr, (void *)pclsObj, uReturn, 42));
                 if (SUCCEEDED(hr))
                 {
-                    if (uReturn)
+                    if (uReturn && pclsObj != NULL)
                     {
+                        *pAdapterConfig = pclsObj;
                         pEnumerator->Release();
-                        *pAdapterConfig = pclsObj;
-                        hr = S_OK;
-                        return hr;
+                        NonStandardLogFlow(("netIfWinFindAdapterClassById: S_OK and %p\n", *pAdapterConfig));
+                        return S_OK;
                     }
-                    else
-                    {
-                        hr = S_FALSE;
-                    }
+
+                    hr = E_FAIL;
                 }
 
                 pEnumerator->Release();
+            }
+            else
+            {
+                NonStandardLogFlow(("ExecQuery returned no enumerator\n"));
+                hr = E_FAIL;
             }
         }
@@ -831,8 +835,11 @@
     {
         DWORD winEr = GetLastError();
-        NonStandardLogFlow(("StringFromGUID2 failed winEr (%d)\n", winEr));
         hr = HRESULT_FROM_WIN32( winEr );
-    }
-
+        if (SUCCEEDED(hr))
+            hr = E_FAIL;
+        NonStandardLogFlow(("StringFromGUID2 failed winEr=%u, hr=0x%x\n", winEr, hr));
+    }
+
+    NonStandardLogFlow(("netIfWinFindAdapterClassById: 0x%x and %p\n", hr, *pAdapterConfig));
     return hr;
 }
@@ -844,8 +851,8 @@
     VariantInit(&vtServiceName);
 
-    HRESULT hr = pAdapterConfig->Get(L"ServiceName", 0, &vtServiceName, 0, 0);
+    HRESULT hr = pAdapterConfig->Get(L"ServiceName", 0 /*lFlags*/, &vtServiceName, NULL /*pvtType*/, NULL /*plFlavor*/);
     if (SUCCEEDED(hr))
     {
-        *pbIsHostOnly = (bstr_t(vtServiceName.bstrVal) == bstr_t("VBoxNetAdp"));
+        *pbIsHostOnly = bstr_t(vtServiceName.bstrVal) == bstr_t("VBoxNetAdp");
 
         VariantClear(&vtServiceName);
@@ -985,8 +992,8 @@
     for (i = 0;
             (hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam())) == S_OK
-            && (hr = netIfWinHasIpSettings(pAdapterConfig, pCheckIp, pCheckMask, pFound)) == S_OK
-            && !(*pFound)
-            && i < sec2Wait/6;
-            i++)
+         && (hr = netIfWinHasIpSettings(pAdapterConfig, pCheckIp, pCheckMask, pFound)) == S_OK
+         && !(*pFound)
+         && i < sec2Wait/6;
+         i++)
     {
         Sleep(6000);
@@ -1457,5 +1464,5 @@
     if (SUCCEEDED(hr))
     {
-        ComPtr <IWbemClassObject> pAdapterConfig;
+        ComPtr<IWbemClassObject> pAdapterConfig;
         hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
         if (SUCCEEDED(hr))
@@ -1471,4 +1478,79 @@
 
 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinIsDhcpEnabled(const GUID * pGuid, BOOL *pEnabled)
+{
+    HRESULT hr;
+    ComPtr <IWbemServices> pSvc;
+    hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
+    if (SUCCEEDED(hr))
+    {
+        ComPtr<IWbemClassObject> pAdapterConfig;
+        hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
+        if (SUCCEEDED(hr))
+        {
+            VARIANT vtEnabled;
+            hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0);
+            if (SUCCEEDED(hr))
+                *pEnabled = vtEnabled.boolVal;
+        }
+    }
+
+    return hr;
+}
+
+VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableStaticIpConfig(IN const GUID *pGuid, IN ULONG ip, IN ULONG mask)
+{
+    NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: ip=0x%x mask=0x%x", ip, mask));
+    ComPtr<IWbemServices> pSvc;
+    HRESULT hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
+    if (SUCCEEDED(hr))
+    {
+        ComPtr<IWbemClassObject> pAdapterConfig;
+        hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
+        if (SUCCEEDED(hr))
+        {
+            BOOL bIsHostOnly;
+            hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
+            if (SUCCEEDED(hr))
+            {
+                if (bIsHostOnly)
+                {
+                    in_addr aIp[1];
+                    in_addr aMask[1];
+                    aIp[0].S_un.S_addr = ip;
+                    aMask[0].S_un.S_addr = mask;
+
+                    BSTR ObjPath;
+                    hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
+                    if (SUCCEEDED(hr))
+                    {
+                        hr = netIfWinEnableStaticV4(pSvc, pGuid, ObjPath, aIp, aMask, ip != 0 ? 1 : 0);
+                        if (SUCCEEDED(hr))
+                        {
+#if 0
+                            in_addr aGw[1];
+                            aGw[0].S_un.S_addr = gw;
+                            hr = netIfWinSetGatewaysV4(pSvc, ObjPath, aGw, 1);
+                            if (SUCCEEDED(hr))
+#endif
+                            {
+                            }
+                        }
+                        SysFreeString(ObjPath);
+                    }
+                }
+                else
+                {
+                    hr = E_FAIL;
+                }
+            }
+        }
+    }
+
+    NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: returns 0x%x", hr));
+    return hr;
+}
+
+#if 0
+static HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway)
 {
     HRESULT hr;
@@ -1477,79 +1559,5 @@
         if (SUCCEEDED(hr))
         {
-            ComPtr <IWbemClassObject> pAdapterConfig;
-            hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
-            if (SUCCEEDED(hr))
-            {
-                VARIANT vtEnabled;
-                hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0);
-                if (SUCCEEDED(hr))
-                    *pEnabled = vtEnabled.boolVal;
-            }
-        }
-
-    return hr;
-}
-
-VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableStaticIpConfig(IN const GUID *pGuid, IN ULONG ip, IN ULONG mask)
-{
-    HRESULT hr;
-        ComPtr <IWbemServices> pSvc;
-        hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
-        if (SUCCEEDED(hr))
-        {
-            ComPtr <IWbemClassObject> pAdapterConfig;
-            hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
-            if (SUCCEEDED(hr))
-            {
-                BOOL bIsHostOnly;
-                hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
-                if (SUCCEEDED(hr))
-                {
-                    if (bIsHostOnly)
-                    {
-                        in_addr aIp[1];
-                        in_addr aMask[1];
-                        aIp[0].S_un.S_addr = ip;
-                        aMask[0].S_un.S_addr = mask;
-
-                        BSTR ObjPath;
-                        hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
-                        if (SUCCEEDED(hr))
-                        {
-                            hr = netIfWinEnableStaticV4(pSvc, pGuid, ObjPath, aIp, aMask, ip != 0 ? 1 : 0);
-                            if (SUCCEEDED(hr))
-                            {
-#if 0
-                                in_addr aGw[1];
-                                aGw[0].S_un.S_addr = gw;
-                                hr = netIfWinSetGatewaysV4(pSvc, ObjPath, aGw, 1);
-                                if (SUCCEEDED(hr))
-#endif
-                                {
-                                }
-                            }
-                            SysFreeString(ObjPath);
-                        }
-                    }
-                    else
-                    {
-                        hr = E_FAIL;
-                    }
-                }
-            }
-        }
-
-    return hr;
-}
-
-#if 0
-static HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway)
-{
-    HRESULT hr;
-        ComPtr <IWbemServices> pSvc;
-        hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
-        if (SUCCEEDED(hr))
-        {
-            ComPtr <IWbemClassObject> pAdapterConfig;
+            ComPtr<IWbemClassObject> pAdapterConfig;
             hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
             if (SUCCEEDED(hr))
@@ -1599,5 +1607,5 @@
         if (SUCCEEDED(hr))
         {
-            ComPtr <IWbemClassObject> pAdapterConfig;
+            ComPtr<IWbemClassObject> pAdapterConfig;
             hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
             if (SUCCEEDED(hr))
@@ -1636,37 +1644,37 @@
 {
     HRESULT hr;
-        ComPtr <IWbemServices> pSvc;
-        hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
+    ComPtr <IWbemServices> pSvc;
+    hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
+    if (SUCCEEDED(hr))
+    {
+        ComPtr<IWbemClassObject> pAdapterConfig;
+        hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
         if (SUCCEEDED(hr))
         {
-            ComPtr <IWbemClassObject> pAdapterConfig;
-            hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
+            BOOL bIsHostOnly;
+            hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
             if (SUCCEEDED(hr))
             {
-                BOOL bIsHostOnly;
-                hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
-                if (SUCCEEDED(hr))
-                {
-                    if (bIsHostOnly)
+                if (bIsHostOnly)
+                {
+                    BSTR ObjPath;
+                    hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
+                    if (SUCCEEDED(hr))
                     {
-                        BSTR ObjPath;
-                        hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
+                        hr = netIfWinDhcpRediscover(pSvc, ObjPath);
                         if (SUCCEEDED(hr))
                         {
-                            hr = netIfWinDhcpRediscover(pSvc, ObjPath);
-                            if (SUCCEEDED(hr))
-                            {
-//                        hr = netIfWinUpdateConfig(pIf);
-                            }
-                            SysFreeString(ObjPath);
+                            //hr = netIfWinUpdateConfig(pIf);
                         }
+                        SysFreeString(ObjPath);
                     }
-                    else
-                    {
-                        hr = E_FAIL;
-                    }
-                }
-            }
-        }
+                }
+                else
+                {
+                    hr = E_FAIL;
+                }
+            }
+        }
+    }
 
 
@@ -2152,7 +2160,7 @@
         {
             WCHAR strRegLocation [256];
-            WCHAR GuidString[50];
-
-            int length = StringFromGUID2(*pGUID, GuidString, sizeof(GuidString)/sizeof(GuidString[0]));
+            WCHAR wszGuid[50];
+
+            int length = StringFromGUID2(*pGUID, wszGuid, RT_ELEMENTS(wszGuid));
             if (!length)
                 SetErrBreak(("Failed to create a Guid string"));
@@ -2161,5 +2169,5 @@
                      L"SYSTEM\\CurrentControlSet\\Control\\Network\\"
                      L"{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
-                     GuidString);
+                     wszGuid);
 
             LONG status;
@@ -2637,8 +2645,7 @@
                                     KEY_READ);
         if (hkey == INVALID_HANDLE_VALUE)
-            SetErrBreak (("SetupDiOpenDevRegKey failed (0x%08X)",
-                          GetLastError()));
-
-        cbSize = sizeof (pWCfgGuidString);
+            SetErrBreak(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError()));
+
+        cbSize = sizeof(pWCfgGuidString);
         DWORD ret;
         ret = RegQueryValueExW (hkey, L"NetCfgInstanceId", NULL,
