VirtualBox

Ignore:
Timestamp:
Apr 18, 2020 11:08:25 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137331
Message:

VBoxNetFlt: VC++ 14.1 warnings and some cleanups. bugref:8489

Location:
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp

    r82968 r83805  
    7171    {
    7272        WCHAR wsz[512];
    73         DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
     73        DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], RT_ELEMENTS(wsz));
    7474        if (cch > 0)
    7575        {
     
    107107
    108108        WCHAR wszInfFile[MAX_PATH];
    109         DWORD cwcInfFile = MyGetfullPathNameW(VBOX_NETADP_INF, sizeof(wszInfFile) / sizeof(wszInfFile[0]), wszInfFile);
     109        DWORD cwcInfFile = MyGetfullPathNameW(VBOX_NETADP_INF, RT_ELEMENTS(wszInfFile), wszInfFile);
    110110        if (cwcInfFile > 0)
    111111        {
     
    119119
    120120                if (hr == S_OK)
    121                 {
    122121                    wprintf(L"installed successfully\n");
    123                 }
    124122                else
    125                 {
    126                     wprintf(L"error installing VBoxNetAdp (0x%x)\n", hr);
    127                 }
     123                    wprintf(L"error installing VBoxNetAdp (%#lx)\n", hr);
    128124
    129125                VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
    130126            }
    131127            else
    132                 wprintf(L"VBoxNetCfgWinQueryINetCfg failed: hr = 0x%x\n", hr);
     128                wprintf(L"VBoxNetCfgWinQueryINetCfg failed: hr=%#lx\n", hr);
    133129            /*
    134130            hr = VBoxDrvCfgInfInstall(MpInf);
     
    151147                    hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
    152148                    if (SUCCEEDED(hr))
    153                     {
    154149                        printf("installation successful\n");
    155                     }
    156150                    else
    157                         printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr);
     151                        printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr=%#lx\n", hr);
    158152                }
    159153                else
    160                     printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr = 0x%x\n", hr);
     154                    printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr=%#lx\n", hr);
    161155            }
    162156            else
    163                 printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr);
     157                printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr=%#lx\n", hr);
    164158            */
    165159        }
     
    167161        {
    168162            DWORD dwErr = GetLastError();
    169             wprintf(L"GetFullPathNameW failed: winEr = %d\n", dwErr);
     163            wprintf(L"GetFullPathNameW failed: winEr = %lu\n", dwErr);
    170164            hr = HRESULT_FROM_WIN32(dwErr);
    171165        }
     
    173167    }
    174168    else
    175         wprintf(L"Error initializing COM (0x%x)\n", hr);
    176 
    177     VBoxNetCfgWinSetLogging(NULL);
    178 
    179     return SUCCEEDED(hr) ? 0 : 1;
     169        wprintf(L"Error initializing COM (%#lx)\n", hr);
     170
     171    VBoxNetCfgWinSetLogging(NULL);
     172
     173    return SUCCEEDED(hr) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    180174}
    181175
     
    194188            hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", VBOX_NETADP_HWID, 0/* could be SUOI_FORCEDELETE */);
    195189            if (SUCCEEDED(hr))
    196             {
    197190                printf("uninstallation successful\n");
    198             }
    199191            else
    200192                printf("uninstalled successfully, but failed to remove infs\n");
    201193        }
    202194        else
    203             printf("uninstall failed, hr = 0x%x\n", hr);
    204         CoUninitialize();
    205     }
    206     else
    207         printf("Error initializing COM (0x%x)\n", hr);
    208 
    209     VBoxNetCfgWinSetLogging(NULL);
    210 
    211     return SUCCEEDED(hr) ? 0 : 1;
     195            printf("uninstall failed, hr=%#lx\n", hr);
     196        CoUninitialize();
     197    }
     198    else
     199        printf("Error initializing COM (%#lx)\n", hr);
     200
     201    VBoxNetCfgWinSetLogging(NULL);
     202
     203    return SUCCEEDED(hr) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    212204}
    213205
     
    237229        }
    238230        else
    239             printf("update failed, hr = 0x%x\n", hr);
    240 
    241         CoUninitialize();
    242     }
    243     else
    244         printf("Error initializing COM (0x%x)\n", hr);
    245 
    246     VBoxNetCfgWinSetLogging(NULL);
    247 
    248     return SUCCEEDED(hr) ? 0 : 1;
     231            printf("update failed, hr=%#lx\n", hr);
     232
     233        CoUninitialize();
     234    }
     235    else
     236        printf("Error initializing COM (%#lx)\n", hr);
     237
     238    VBoxNetCfgWinSetLogging(NULL);
     239
     240    return SUCCEEDED(hr) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    249241}
    250242
     
    260252        hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(VBOX_NETADP_HWID, VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE);
    261253        if (SUCCEEDED(hr))
    262         {
    263254            printf("disabling successful\n");
    264         }
    265         else
    266             printf("disable failed, hr = 0x%x\n", hr);
    267 
    268         CoUninitialize();
    269     }
    270     else
    271         printf("Error initializing COM (0x%x)\n", hr);
    272 
    273     VBoxNetCfgWinSetLogging(NULL);
    274 
    275     return SUCCEEDED(hr) ? 0 : 1;
     255        else
     256            printf("disable failed, hr=%#lx\n", hr);
     257
     258        CoUninitialize();
     259    }
     260    else
     261        printf("Error initializing COM (%#lx)\n", hr);
     262
     263    VBoxNetCfgWinSetLogging(NULL);
     264
     265    return SUCCEEDED(hr) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    276266}
    277267
     
    287277        hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(VBOX_NETADP_HWID, VBOXNECTFGWINPROPCHANGE_TYPE_ENABLE);
    288278        if (SUCCEEDED(hr))
    289         {
    290279            printf("enabling successful\n");
    291         }
    292         else
    293             printf("enabling failed, hr = 0x%x\n", hr);
    294 
    295         CoUninitialize();
    296     }
    297     else
    298         printf("Error initializing COM (0x%x)\n", hr);
    299 
    300     VBoxNetCfgWinSetLogging(NULL);
    301 
    302     return SUCCEEDED(hr) ? 0 : 1;
     280        else
     281            printf("enabling failed, hr=%#lx\n", hr);
     282
     283        CoUninitialize();
     284    }
     285    else
     286        printf("Error initializing COM (%#lx)\n", hr);
     287
     288    VBoxNetCfgWinSetLogging(NULL);
     289
     290    return SUCCEEDED(hr) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    303291}
    304292
     
    323311    {
    324312        printUsage();
    325         return 1;
     313        return RTEXITCODE_SYNTAX;
    326314    }
    327315
     
    338326
    339327    printUsage();
    340     return !strcmp(argv[1], "h");
    341 }
     328    return !strcmp(argv[1], "h") ? RTEXITCODE_SUCCESS : RTEXITCODE_SYNTAX;
     329}
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp

    r82968 r83805  
    3232
    3333#ifdef NDIS60
    34 #define VBOX_NETADP_HWID L"sun_VBoxNetAdp6"
    35 #else /* !NDIS60 */
    36 #define VBOX_NETADP_HWID L"sun_VBoxNetAdp"
    37 #endif /* !NDIS60 */
     34# define VBOX_NETADP_HWID L"sun_VBoxNetAdp6"
     35#else
     36# define VBOX_NETADP_HWID L"sun_VBoxNetAdp"
     37#endif
    3838
    39 static VOID winNetCfgLogger (LPCSTR szString)
     39static VOID winNetCfgLogger(LPCSTR szString)
    4040{
    4141    printf("%s", szString);
    4242}
    4343
    44 static int VBoxNetAdpUninstall()
     44static int VBoxNetAdpUninstall(void)
    4545{
    46     int r = 1;
     46    int rcExit = RTEXITCODE_FAILURE;
    4747    VBoxNetCfgWinSetLogging(winNetCfgLogger);
    4848
     
    5757            hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", VBOX_NETADP_HWID, 0/* could be SUOI_FORCEDELETE */);
    5858            if (hr == S_OK)
    59             {
    6059                printf("uninstalled successfully\n");
    61             }
    6260            else
    63             {
    6461                printf("uninstalled successfully, but failed to remove infs\n");
    65             }
    66             r = 0;
     62            rcExit = RTEXITCODE_SUCCESS;
    6763        }
    6864        else
    69         {
    70             printf("uninstall failed, hr = 0x%x\n", hr);
    71         }
     65            printf("uninstall failed, hr=%#lx\n", hr);
    7266
    7367        CoUninitialize();
    7468    }
    7569    else
    76     {
    77         wprintf(L"Error initializing COM (0x%x)\n", hr);
    78     }
     70        wprintf(L"Error initializing COM (%#lx)\n", hr);
    7971
    8072    VBoxNetCfgWinSetLogging(NULL);
    8173
    82     return r;
     74    return rcExit;
    8375}
    8476
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp

    r82968 r83805  
    3636
    3737
    38 static VOID winNetCfgLogger (LPCSTR szString)
     38static VOID winNetCfgLogger(LPCSTR szString)
    3939{
    4040    printf("%s", szString);
     
    5858    {
    5959        WCHAR wsz[512];
    60         DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
     60        DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], RT_ELEMENTS(wsz));
    6161        if (cch > 0)
    6262        {
     
    6464                cch--;
    6565            unsigned i = 0;
    66             while (cch < sizeof(wsz) / sizeof(wsz[0]))
     66            while (cch < RT_ELEMENTS(wsz))
    6767            {
    6868                wsz[cch] = pwszFilePart[i++];
     
    8585static int VBoxNetFltInstall()
    8686{
    87     WCHAR PtInf[MAX_PATH];
    88     WCHAR MpInf[MAX_PATH];
     87    WCHAR wszPtInf[MAX_PATH];
     88    WCHAR wszMpInf[MAX_PATH];
    8989    INetCfg *pnc;
    90     LPWSTR lpszLockedBy = NULL;
    91     int r = 1;
     90    int rcExit = RTEXITCODE_FAILURE;
    9291
    9392    VBoxNetCfgWinSetLogging(winNetCfgLogger);
     
    9695    if (hr == S_OK)
    9796    {
    98         int i = 0;
    99         do
     97        for (int i = 0;; i++)
    10098        {
    101             hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
     99            LPWSTR pwszLockedBy = NULL;
     100            hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &pwszLockedBy);
    102101            if (hr == S_OK)
    103102            {
    104103                DWORD dwSize;
    105                 dwSize = MyGetfullPathNameW(VBOX_NETFLT_PT_INF, sizeof(PtInf)/sizeof(PtInf[0]), PtInf);
     104                dwSize = MyGetfullPathNameW(VBOX_NETFLT_PT_INF, RT_ELEMENTS(wszPtInf), wszPtInf);
    106105                if (dwSize > 0)
    107106                {
    108                     /** @todo add size check for (sizeof(PtInf)/sizeof(PtInf[0])) == dwSize (string length in sizeof(PtInf[0])) */
     107                    /** @todo add size check for (RT_ELEMENTS(wszPtInf) == dwSize (string length in WCHARs) */
    109108
    110                     dwSize = MyGetfullPathNameW(VBOX_NETFLT_MP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf);
     109                    dwSize = MyGetfullPathNameW(VBOX_NETFLT_MP_INF, RT_ELEMENTS(wszMpInf), wszMpInf);
    111110                    if (dwSize > 0)
    112111                    {
    113                         /** @todo add size check for (sizeof(MpInf)/sizeof(MpInf[0])) == dwSize (string length in sizeof(MpInf[0])) */
     112                        /** @todo add size check for (RT_ELEMENTS(wszMpInf) == dwSize (string length in WHCARs) */
    114113
    115                         LPCWSTR aInfs[] = {PtInf, MpInf};
    116                         hr = VBoxNetCfgWinNetFltInstall(pnc, aInfs, 2);
     114                        LPCWSTR apwszInfs[] = { wszPtInf, wszMpInf };
     115                        hr = VBoxNetCfgWinNetFltInstall(pnc, apwszInfs, 2);
    117116                        if (hr == S_OK)
    118117                        {
    119118                            wprintf(L"installed successfully\n");
    120                             r = 0;
     119                            rcExit = RTEXITCODE_SUCCESS;
    121120                        }
    122121                        else
    123                         {
    124                             wprintf(L"error installing VBoxNetFlt (0x%x)\n", hr);
    125                         }
     122                            wprintf(L"error installing VBoxNetFlt (%#lx)\n", hr);
    126123                    }
    127124                    else
    128125                    {
    129126                        hr = HRESULT_FROM_WIN32(GetLastError());
    130                         wprintf(L"error getting full inf path for VBoxNetFltM.inf (0x%x)\n", hr);
     127                        wprintf(L"error getting full inf path for VBoxNetFltM.inf (%#lx)\n", hr);
    131128                    }
    132129                }
     
    134131                {
    135132                    hr = HRESULT_FROM_WIN32(GetLastError());
    136                     wprintf(L"error getting full inf path for VBoxNetFlt.inf (0x%x)\n", hr);
     133                    wprintf(L"error getting full inf path for VBoxNetFlt.inf (%#lx)\n", hr);
    137134                }
    138 
    139135
    140136                VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
    141137                break;
    142138            }
    143             else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
     139
     140            if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
    144141            {
    145                 if (i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
     142                if (i < VBOX_NETFLT_RETRIES && !wcscmp(pwszLockedBy, L"6to4svc.dll"))
    146143                {
    147                     wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
    148                     CoTaskMemFree(lpszLockedBy);
     144                    wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", i + 1, VBOX_NETFLT_RETRIES);
     145                    CoTaskMemFree(pwszLockedBy);
    149146                }
    150147                else
    151148                {
    152                     wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n", lpszLockedBy);
    153                     r = 1;
    154                     CoTaskMemFree(lpszLockedBy);
     149                    wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n", pwszLockedBy);
     150                    CoTaskMemFree(pwszLockedBy);
    155151                    break;
    156152                }
     
    158154            else
    159155            {
    160                 wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
    161                 r = 1;
     156                wprintf(L"Error getting the INetCfg interface (%#lx)\n", hr);
    162157                break;
    163158            }
    164         } while (true);
     159        }
    165160
    166161        CoUninitialize();
    167162    }
    168163    else
    169     {
    170         wprintf(L"Error initializing COM (0x%x)\n", hr);
    171         r = 1;
    172     }
     164        wprintf(L"Error initializing COM (%#lx)\n", hr);
    173165
    174166    VBoxNetCfgWinSetLogging(NULL);
    175167
    176     return r;
     168    return rcExit;
    177169}
    178170
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp

    r82968 r83805  
    3434#define VBOX_NETFLT_RETRIES 10
    3535
    36 static VOID winNetCfgLogger (LPCSTR szString)
     36static VOID winNetCfgLogger(LPCSTR szString)
    3737{
    3838    printf("%s", szString);
     
    4242{
    4343    INetCfg *pnc;
    44     LPWSTR lpszLockedBy = NULL;
    45     int r;
     44    int rcExit = RTEXITCODE_FAILURE;
    4645
    4746    VBoxNetCfgWinSetLogging(winNetCfgLogger);
     
    5049    if (hr == S_OK)
    5150    {
    52         int i = 0;
    53         do
     51        for (int i = 0;; i++)
    5452        {
    55             hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
     53            LPWSTR pwszLockedBy = NULL;
     54            hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &pwszLockedBy);
    5655            if (hr == S_OK)
    5756            {
    5857                hr = VBoxNetCfgWinNetFltUninstall(pnc);
    5958                if (hr != S_OK && hr != S_FALSE)
    60                 {
    61                     wprintf(L"error uninstalling VBoxNetFlt (0x%x)\n", hr);
    62                     r = 1;
    63                 }
     59                    wprintf(L"error uninstalling VBoxNetFlt (%#lx)\n", hr);
    6460                else
    6561                {
    6662                    wprintf(L"uninstalled successfully\n");
    67                     r = 0;
     63                    rcExit = RTEXITCODE_SUCCESS;
    6864                }
    6965
     
    7167                break;
    7268            }
    73             else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
     69
     70            if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
    7471            {
    75                 if (i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
     72                if (i < VBOX_NETFLT_RETRIES && !wcscmp(pwszLockedBy, L"6to4svc.dll"))
    7673                {
    77                     wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
    78                     CoTaskMemFree(lpszLockedBy);
     74                    wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", i + 1, VBOX_NETFLT_RETRIES);
     75                    CoTaskMemFree(pwszLockedBy);
    7976                }
    8077                else
    8178                {
    82                     wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy);
    83                     r = 1;
    84                     CoTaskMemFree(lpszLockedBy);
     79                    wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n",
     80                            pwszLockedBy);
     81                    CoTaskMemFree(pwszLockedBy);
    8582                    break;
    8683                }
     
    8885            else
    8986            {
    90                 wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
    91                 r = 1;
     87                wprintf(L"Error getting the INetCfg interface (%#lx)\n", hr);
    9288                break;
    9389            }
    94         } while (true);
     90        }
    9591
    9692        CoUninitialize();
    9793    }
    9894    else
    99     {
    100         wprintf(L"Error initializing COM (0x%x)\n", hr);
    101         r = 1;
    102     }
     95        wprintf(L"Error initializing COM (%#lx)\n", hr);
    10396
    10497    VBoxNetCfgWinSetLogging(NULL);
    10598
    106     return r;
     99    return rcExit;
    107100}
    108101
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfInstall.cpp

    r82968 r83805  
    3434
    3535
    36 static VOID winNetCfgLogger (LPCSTR szString)
     36static VOID winNetCfgLogger(LPCSTR pszString)
    3737{
    38     printf("%s", szString);
     38    printf("%s", pszString);
    3939}
    4040
     
    5656    {
    5757        WCHAR wsz[512];
    58         DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
     58        DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], RT_ELEMENTS(wsz));
    5959        if (cch > 0)
    6060        {
     
    6262                cch--;
    6363            unsigned i = 0;
    64             while (cch < sizeof(wsz) / sizeof(wsz[0]))
     64            while (cch < RT_ELEMENTS(wsz))
    6565            {
    6666                wsz[cch] = pwszFilePart[i++];
     
    8383static int VBoxNetLwfInstall()
    8484{
    85     WCHAR Inf[MAX_PATH];
     85    WCHAR wszInf[MAX_PATH];
    8686    INetCfg *pnc;
    87     LPWSTR lpszLockedBy = NULL;
    88     int r = 1;
     87    int rcExit = RTEXITCODE_FAILURE;
    8988
    9089    VBoxNetCfgWinSetLogging(winNetCfgLogger);
     
    9392    if (hr == S_OK)
    9493    {
    95         int i = 0;
    96         do
     94        for (int i = 0;; i++)
    9795        {
    98             hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
     96            LPWSTR pwszLockedBy = NULL;
     97            hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &pwszLockedBy);
    9998            if (hr == S_OK)
    10099            {
    101100                DWORD dwSize;
    102                 dwSize = MyGetfullPathNameW(VBOX_NETLWF_INF, sizeof(Inf)/sizeof(Inf[0]), Inf);
     101                dwSize = MyGetfullPathNameW(VBOX_NETLWF_INF, RT_ELEMENTS(wszInf), wszInf);
    103102                if (dwSize > 0)
    104103                {
    105                     /** @todo add size check for (sizeof(Inf)/sizeof(Inf[0])) == dwSize (string length in sizeof(Inf[0])) */
    106                     hr = VBoxNetCfgWinNetLwfInstall(pnc, Inf);
     104                    /** @todo add size check for (RT_ELEMENTS(wszInf) == dwSize (string length in WCHARs) */
     105                    hr = VBoxNetCfgWinNetLwfInstall(pnc, wszInf);
    107106                    if (hr == S_OK)
    108107                    {
    109108                        wprintf(L"installed successfully\n");
    110                         r = 0;
     109                        rcExit = RTEXITCODE_SUCCESS;
    111110                    }
    112111                    else
    113                     {
    114                         wprintf(L"error installing VBoxNetLwf (0x%x)\n", hr);
    115                     }
     112                        wprintf(L"error installing VBoxNetLwf (%#lx)\n", hr);
    116113                }
    117114                else
    118115                {
    119116                    hr = HRESULT_FROM_WIN32(GetLastError());
    120                     wprintf(L"error getting full inf path for VBoxNetLwf.inf (0x%x)\n", hr);
     117                    wprintf(L"error getting full inf path for VBoxNetLwf.inf (%#lx)\n", hr);
    121118                }
    122 
    123119
    124120                VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
    125121                break;
    126122            }
    127             else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
     123
     124            if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
    128125            {
    129                 if (i < VBOX_NETLWF_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
     126                if (i < VBOX_NETLWF_RETRIES && !wcscmp(pwszLockedBy, L"6to4svc.dll"))
    130127                {
    131                     wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETLWF_RETRIES);
    132                     CoTaskMemFree(lpszLockedBy);
     128                    wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", i + 1, VBOX_NETLWF_RETRIES);
     129                    CoTaskMemFree(pwszLockedBy);
    133130                }
    134131                else
    135132                {
    136                     wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n", lpszLockedBy);
    137                     r = 1;
    138                     CoTaskMemFree(lpszLockedBy);
     133                    wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n",
     134                            pwszLockedBy);
     135                    CoTaskMemFree(pwszLockedBy);
    139136                    break;
    140137                }
     
    142139            else
    143140            {
    144                 wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
    145                 r = 1;
     141                wprintf(L"Error getting the INetCfg interface (%#lx)\n", hr);
    146142                break;
    147143            }
    148         } while (true);
     144        }
    149145
    150146        CoUninitialize();
    151147    }
    152148    else
    153     {
    154         wprintf(L"Error initializing COM (0x%x)\n", hr);
    155         r = 1;
    156     }
     149        wprintf(L"Error initializing COM (%#lx)\n", hr);
    157150
    158151    VBoxNetCfgWinSetLogging(NULL);
    159152
    160     return r;
     153    return rcExit;
    161154}
    162155
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfUninstall.cpp

    r82968 r83805  
    3131#define VBOX_NETLWF_RETRIES 10
    3232
    33 static VOID winNetCfgLogger (LPCSTR szString)
     33static VOID winNetCfgLogger(LPCSTR szString)
    3434{
    3535    printf("%s", szString);
     
    3939{
    4040    INetCfg *pnc;
    41     LPWSTR lpszLockedBy = NULL;
    42     int r;
     41    int rcExit = RTEXITCODE_FAILURE;
    4342
    4443    VBoxNetCfgWinSetLogging(winNetCfgLogger);
     
    4746    if (hr == S_OK)
    4847    {
    49         int i = 0;
    50         do
     48        for (int i = 0;; i++)
    5149        {
    52             hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
     50            LPWSTR pwszLockedBy = NULL;
     51            hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &pwszLockedBy);
    5352            if (hr == S_OK)
    5453            {
    5554                hr = VBoxNetCfgWinNetLwfUninstall(pnc);
    56                 if (hr != S_OK)
     55                if (hr == S_OK)
    5756                {
    58                     wprintf(L"error uninstalling VBoxNetLwf (0x%x)\n", hr);
    59                     r = 1;
     57                    wprintf(L"uninstalled successfully\n");
     58                    rcExit = RTEXITCODE_SUCCESS;
    6059                }
    6160                else
    62                 {
    63                     wprintf(L"uninstalled successfully\n");
    64                     r = 0;
    65                 }
     61                    wprintf(L"error uninstalling VBoxNetLwf (%#lx)\n", hr);
    6662
    6763                VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
    6864                break;
    6965            }
    70             else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
     66
     67            if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
    7168            {
    72                 if (i < VBOX_NETLWF_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
     69                if (i < VBOX_NETLWF_RETRIES && !wcscmp(pwszLockedBy, L"6to4svc.dll"))
    7370                {
    74                     wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETLWF_RETRIES);
    75                     CoTaskMemFree(lpszLockedBy);
     71                    wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", i + 1, VBOX_NETLWF_RETRIES);
     72                    CoTaskMemFree(pwszLockedBy);
    7673                }
    7774                else
    7875                {
    79                     wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy);
    80                     r = 1;
    81                     CoTaskMemFree(lpszLockedBy);
     76                    wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n",
     77                             pwszLockedBy);
     78                    CoTaskMemFree(pwszLockedBy);
    8279                    break;
    8380                }
     
    8582            else
    8683            {
    87                 wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
    88                 r = 1;
     84                wprintf(L"Error getting the INetCfg interface (%#lx)\n", hr);
    8985                break;
    9086            }
    91         } while (true);
     87        }
    9288
    9389        CoUninitialize();
    9490    }
    9591    else
    96     {
    97         wprintf(L"Error initializing COM (0x%x)\n", hr);
    98         r = 1;
    99     }
     92        wprintf(L"Error initializing COM (%#lx)\n", hr);
    10093
    10194    VBoxNetCfgWinSetLogging(NULL);
    10295
    103     return r;
     96    return rcExit;
    10497}
    10598
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