VirtualBox

Ignore:
Timestamp:
Sep 1, 2022 8:36:22 PM (2 years ago)
Author:
vboxsync
Message:

HostDrives,Installer/win: Reworked the windows installer related code for no-CRT mode, where applicable, and changed the XxxxInstall.exe/XxxxUninstall.exe utilities to link against VBoxRT.dll instead of being statically linked. Lot's of cleanup. The change is uncomfortably large, but difficult to detangle these things. bugref:10261

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp

    r96428 r96572  
    3535#endif
    3636
    37 #include <VBox/version.h>
    38 
    39 #include <wchar.h>
    40 #include <stdio.h>
    41 
    4237#include <msi.h>
    4338#include <msiquery.h>
     
    4641#include <iprt/win/windows.h>
    4742
    48 #include <assert.h>
    4943#include <shellapi.h>
    5044#define INITGUID
     
    5347#include <devguid.h>
    5448
    55 #include <iprt/alloca.h>
    56 #include <iprt/string.h> /* RT_ZERO */
    57 #include <iprt/path.h>   /* RTPATH_MAX, RTPATH_IS_SLASH */
    58 
    5949#include <iprt/win/objbase.h>
    6050#include <iprt/win/setupapi.h>
    6151#include <iprt/win/shlobj.h>
    6252
     53#include <VBox/version.h>
     54
     55#include <iprt/assert.h>
     56#include <iprt/alloca.h>
     57#include <iprt/mem.h>
     58#include <iprt/path.h>   /* RTPATH_MAX, RTPATH_IS_SLASH */
     59#include <iprt/string.h> /* RT_ZERO */
     60#include <iprt/utf16.h>
     61
    6362#include "VBoxCommon.h"
    64 
    6563#ifndef VBOX_OSE
    6664# include "internal/VBoxSerial.h"
     
    7270*********************************************************************************************************************************/
    7371#ifdef DEBUG
    74 # define NonStandardAssert(_expr) assert(_expr)
     72# define NonStandardAssert(_expr) Assert(_expr)
    7573#else
    7674# define NonStandardAssert(_expr) do{ }while(0)
     
    8886{
    8987    RT_NOREF(hInst, uReason, pReserved);
     88
     89#if 0
     90    /*
     91     * This is a trick for allowing the debugger to be attached, don't know if
     92     * there is an official way to do that, but this is a pretty efficient.
     93     *
     94     * Monitor the debug output in DbgView and be ready to start windbg when
     95     * the message below appear.  This will happen 3-4 times during install,
     96     * and 2-3 times during uninstall.
     97     *
     98     * Note! The DIFxApp.DLL will automatically trigger breakpoints when a
     99     *       debugger is attached.  Just continue on these.
     100     */
     101    if (uReason == DLL_PROCESS_ATTACH)
     102    {
     103        WCHAR wszMsg[128];
     104        RTUtf16Printf(wszMsg, RT_ELEMENTS(wszMsg), "Waiting for debugger to attach: windbg -g -G -p %u\n", GetCurrentProcessId());
     105        for (unsigned i = 0; i < 128 && !IsDebuggerPresent(); i++)
     106        {
     107            OutputDebugStringW(wszMsg);
     108            Sleep(1001);
     109        }
     110        Sleep(1002);
     111        __debugbreak();
     112    }
     113#endif
     114
    90115    return TRUE;
    91116}
     
    94119 * Format and add message to the MSI log.
    95120 *
    96  * UTF-16 strings are formatted using '%s' (lowercase).
    97  * ANSI strings are formatted using '%S' (uppercase).
     121 * UTF-16 strings are formatted using '%ls' (lowercase).
     122 * ANSI strings are formatted using '%s' (uppercase).
    98123 */
    99 static UINT logStringF(MSIHANDLE hInstall, const wchar_t *pwszFmt, ...)
     124static UINT logStringF(MSIHANDLE hInstall, const char *pszFmt, ...)
    100125{
    101126    PMSIHANDLE hMSI = MsiCreateRecord(2 /* cParms */);
     
    104129        wchar_t wszBuf[RTPATH_MAX + 256];
    105130        va_list va;
    106         va_start(va, pwszFmt);
    107         ssize_t cwc = _vsnwprintf(wszBuf, RT_ELEMENTS(wszBuf), pwszFmt, va);
     131        va_start(va, pszFmt);
     132        ssize_t cwc = RTUtf16PrintfV(wszBuf, RT_ELEMENTS(wszBuf), pszFmt, va);
    108133        va_end(va);
    109         wszBuf[RT_ELEMENTS(wszBuf) - 1] = '\0';
    110134
    111135        MsiRecordSetStringW(hMSI, 0, wszBuf);
     
    151175     * Construct a full command line.
    152176     */
    153     size_t const cwcImage = wcslen(pwszImage);
    154     size_t const cwcArgs  = wcslen(pwszArgs);
     177    size_t const cwcImage = RTUtf16Len(pwszImage);
     178    size_t const cwcArgs  = RTUtf16Len(pwszArgs);
    155179
    156180    wchar_t *pwszCmdLine = (wchar_t *)alloca((1 + cwcImage + 1 + 1 + cwcArgs + 1) * sizeof(wchar_t));
     
    184208                       0 /*fFlags*/, NULL /*pwszEnv*/, NULL /*pwszCwd*/, &StartupInfo, &ChildInfo))
    185209    {
    186         logStringF(hModule, L"procRun: Info: Started process %u: %s", ChildInfo.dwProcessId, pwszCmdLine);
     210        logStringF(hModule, "procRun: Info: Started process %u: %ls", ChildInfo.dwProcessId, pwszCmdLine);
    187211        CloseHandle(ChildInfo.hThread);
    188212        DWORD const dwWait = WaitForSingleObject(ChildInfo.hProcess, RT_MS_30SEC);
     
    192216            if (dwExitCode == 0)
    193217            {
    194                 logStringF(hModule, L"procRun: Info: Process '%s' terminated exit code zero", pwszCmdLine);
     218                logStringF(hModule, "procRun: Info: Process '%ls' terminated exit code zero", pwszCmdLine);
    195219                rcWin = ERROR_SUCCESS;
    196220            }
    197221            else
    198222            {
    199                 logStringF(hModule, L"procRun: Process '%s' terminated with non-zero exit code: %u (%#x)",
     223                logStringF(hModule, "procRun: Process '%ls' terminated with non-zero exit code: %u (%#x)",
    200224                           pwszCmdLine, dwExitCode, dwExitCode);
    201225                rcWin = ERROR_GEN_FAILURE;
     
    205229        {
    206230            rcWin = GetLastError();
    207             logStringF(hModule, L"procRun: Process '%s' is probably still running: rcWin=%u dwWait=%u (%#x)",
     231            logStringF(hModule, "procRun: Process '%ls' is probably still running: rcWin=%u dwWait=%u (%#x)",
    208232                       pwszCmdLine, rcWin, dwWait, dwWait);
    209233        }
     
    212236    {
    213237        rcWin = GetLastError();
    214         logStringF(hModule, L"procRun: Creating process '%s' failed: rcWin=%u\n", pwszCmdLine, rcWin);
     238        logStringF(hModule, "procRun: Creating process '%ls' failed: rcWin=%u\n", pwszCmdLine, rcWin);
    215239    }
    216240    return rcWin;
     
    308332                            cwc += RT_ELEMENTS(s_wszPythonExe) - 1;
    309333                        wszBuf[cwc] = '\0';
    310                         logStringF(hModule, L"getPythonPath: Found: \"%s\"", wszBuf);
     334                        logStringF(hModule, "getPythonPath: Found: \"%ls\"", wszBuf);
    311335
    312336                        NonStandardAssert(cwcPythonPath > cwc);
     
    316340                    }
    317341                    else
    318                         logStringF(hModule, L"getPythonPath: Warning: Skipping \"%s\": is a directory (%#x)", wszBuf, fAttribs);
     342                        logStringF(hModule, "getPythonPath: Warning: Skipping \"%ls\": is a directory (%#x)", wszBuf, fAttribs);
    319343                }
    320344                else
    321                     logStringF(hModule, L"getPythonPath: Warning: Skipping \"%s\": Does not exist (%u)", wszBuf, GetLastError());
     345                    logStringF(hModule, "getPythonPath: Warning: Skipping \"%ls\": Does not exist (%u)", wszBuf, GetLastError());
    322346            }
    323347        }
     
    326350    RegCloseKey(hKeyPythonCore);
    327351    if (rcWinRet != ERROR_SUCCESS)
    328         logStringF(hModule, L"getPythonPath: Unable to find python");
     352        logStringF(hModule, "getPythonPath: Unable to find python");
    329353    return rcWinRet;
    330354}
     
    374398     * This is a prerequisite for setting up the VBox API.
    375399     */
    376     logStringF(hModule, L"checkPythonDependencies: Checking for win32api extensions ...");
     400    logStringF(hModule, "checkPythonDependencies: Checking for win32api extensions ...");
    377401
    378402    UINT rcWin = procRun(hModule, pwszPythonExe, L"-c \"import win32api\"");
    379403    if (rcWin == ERROR_SUCCESS)
    380         logStringF(hModule, L"checkPythonDependencies: win32api found\n");
     404        logStringF(hModule, "checkPythonDependencies: win32api found\n");
    381405    else
    382         logStringF(hModule, L"checkPythonDependencies: Importing win32api failed with %u (%#x)\n", rcWin, rcWin);
     406        logStringF(hModule, "checkPythonDependencies: Importing win32api failed with %u (%#x)\n", rcWin, rcWin);
    383407
    384408    return rcWin;
     
    402426    if (rcWin == ERROR_SUCCESS)
    403427    {
    404         logStringF(hModule, L"IsPythonInstalled: Python installation found at \"%s\"", wszPythonPath);
     428        logStringF(hModule, "IsPythonInstalled: Python installation found at \"%ls\"", wszPythonPath);
    405429        VBoxSetMsiProp(hModule, L"VBOX_PYTHON_PATH", wszPythonPath);
    406430        VBoxSetMsiProp(hModule, L"VBOX_PYTHON_INSTALLED", L"1");
     
    408432    else
    409433    {
    410         logStringF(hModule, L"IsPythonInstalled: Error: No suitable Python installation found (%u), skipping installation.", rcWin);
    411         logStringF(hModule, L"IsPythonInstalled: Python seems not to be installed; please download + install the Python Core package.");
     434        logStringF(hModule, "IsPythonInstalled: Error: No suitable Python installation found (%u), skipping installation.", rcWin);
     435        logStringF(hModule, "IsPythonInstalled: Python seems not to be installed; please download + install the Python Core package.");
    412436        VBoxSetMsiProp(hModule, L"VBOX_PYTHON_INSTALLED", L"0");
    413437    }
     
    434458        dwErr = checkPythonDependencies(hModule, wszPythonExe);
    435459        if (dwErr == ERROR_SUCCESS)
    436             logStringF(hModule, L"ArePythonAPIDepsInstalled: Dependencies look good.");
     460            logStringF(hModule, "ArePythonAPIDepsInstalled: Dependencies look good.");
    437461    }
    438462
    439463    if (dwErr != ERROR_SUCCESS)
    440         logStringF(hModule, L"ArePythonAPIDepsInstalled: Failed with dwErr=%u", dwErr);
     464        logStringF(hModule, "ArePythonAPIDepsInstalled: Failed with dwErr=%u", dwErr);
    441465
    442466    VBoxSetMsiProp(hModule, L"VBOX_PYTHON_DEPS_INSTALLED", dwErr == ERROR_SUCCESS ? L"1" : L"0");
     
    462486{
    463487    HKEY hKeyVS = NULL;
    464     LSTATUS dwErr = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
    465                                   L"SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X64",
    466                                   0, KEY_READ, &hKeyVS);
    467     if (dwErr == ERROR_SUCCESS)
     488    LSTATUS lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
     489                                L"SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X64",
     490                                0, KEY_READ, &hKeyVS);
     491    if (lrc == ERROR_SUCCESS)
    468492    {
    469493        DWORD dwVal = 0;
    470494        DWORD cbVal = sizeof(dwVal);
    471         DWORD dwValueType = REG_DWORD;
    472 
    473         dwErr = RegQueryValueExW(hKeyVS, L"Installed", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal);
    474         if (dwErr == ERROR_SUCCESS)
     495        DWORD dwValueType = REG_DWORD; /** @todo r=bird: output only parameter, optional, so pointless. */
     496        lrc = RegQueryValueExW(hKeyVS, L"Installed", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal);
     497        if (lrc == ERROR_SUCCESS)
    475498        {
    476499            if (dwVal >= 1)
    477500            {
    478                 DWORD dwMin, dwMaj;
    479                 dwErr = RegQueryValueExW(hKeyVS, L"Major", NULL, &dwValueType, (LPBYTE)&dwMaj, &cbVal);
    480                 if (dwErr == ERROR_SUCCESS)
     501                DWORD dwMaj = 0; /** @todo r=bird: It's purdent to initialize values if you don't bother to check the type and size! */
     502                lrc = RegQueryValueExW(hKeyVS, L"Major", NULL, &dwValueType, (LPBYTE)&dwMaj, &cbVal);
     503                if (lrc == ERROR_SUCCESS)
    481504                {
    482505                    VBoxSetMsiPropDWORD(hModule, L"VBOX_MSCRT_VER_MAJ", dwMaj);
    483506
    484                     dwErr = RegQueryValueExW(hKeyVS, L"Minor", NULL, &dwValueType, (LPBYTE)&dwMin, &cbVal);
    485                     if (dwErr == ERROR_SUCCESS)
     507                    DWORD dwMin = 0;
     508                    lrc = RegQueryValueExW(hKeyVS, L"Minor", NULL, &dwValueType, (LPBYTE)&dwMin, &cbVal);
     509                    if (lrc == ERROR_SUCCESS)
    486510                    {
    487511                        VBoxSetMsiPropDWORD(hModule, L"VBOX_MSCRT_VER_MIN", dwMin);
    488512
    489                         logStringF(hModule, L"IsMSCRTInstalled: Found v%ld.%ld\n", dwMaj, dwMin);
     513                        logStringF(hModule, "IsMSCRTInstalled: Found v%u.%u\n", dwMaj, dwMin);
    490514
    491515                        /* Check for at least 2019. */
     
    494518                    }
    495519                    else
    496                         logStringF(hModule, L"IsMSCRTInstalled: Found, but 'Minor' key not present");
     520                        logStringF(hModule, "IsMSCRTInstalled: Found, but 'Minor' key not present (lrc=%d)", lrc);
    497521                }
    498522                else
    499                     logStringF(hModule, L"IsMSCRTInstalled: Found, but 'Major' key not present");
     523                    logStringF(hModule, "IsMSCRTInstalled: Found, but 'Major' key not present (lrc=%d)", lrc);
    500524            }
    501525            else
    502526            {
    503                 logStringF(hModule, L"IsMSCRTInstalled: Found, but not marked as installed");
    504                 dwErr = ERROR_NOT_INSTALLED;
     527                logStringF(hModule, "IsMSCRTInstalled: Found, but not marked as installed");
     528                lrc = ERROR_NOT_INSTALLED;
    505529            }
    506530        }
    507531        else
    508             logStringF(hModule, L"IsMSCRTInstalled: Found, but 'Installed' key not present");
    509     }
    510 
    511     if (dwErr != ERROR_SUCCESS)
    512         logStringF(hModule, L"IsMSCRTInstalled: Failed with dwErr=%ld", dwErr);
     532            logStringF(hModule, "IsMSCRTInstalled: Found, but 'Installed' key not present (lrc=%d)", lrc);
     533    }
     534
     535    if (lrc != ERROR_SUCCESS)
     536        logStringF(hModule, "IsMSCRTInstalled: Failed with lrc=%ld", lrc);
    513537
    514538    return ERROR_SUCCESS; /* Never return failure. */
     
    533557     */
    534558    HKEY hKeyCurVer = NULL;
    535     LSTATUS dwErr = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKeyCurVer);
    536     if (dwErr == ERROR_SUCCESS)
     559    LSTATUS lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKeyCurVer);
     560    if (lrc == ERROR_SUCCESS)
    537561    {
    538562        DWORD dwVal = 0;
    539563        DWORD cbVal = sizeof(dwVal);
    540         DWORD dwValueType = REG_DWORD;
    541         dwErr = RegQueryValueExW(hKeyCurVer, L"CurrentMajorVersionNumber", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal);
    542         if (dwErr == ERROR_SUCCESS)
    543         {
    544             logStringF(hModule, L"IsWindows10/CurrentMajorVersionNumber: %ld", dwVal);
     564        DWORD dwValueType = REG_DWORD; /** @todo r=bird: Again, the type is an optional output parameter. pointless to init or pass it unless you check.  */
     565        lrc = RegQueryValueExW(hKeyCurVer, L"CurrentMajorVersionNumber", NULL, &dwValueType, (LPBYTE)&dwVal, &cbVal);
     566        if (lrc == ERROR_SUCCESS)
     567        {
     568            logStringF(hModule, "IsWindows10/CurrentMajorVersionNumber: %u", dwVal);
    545569
    546570            VBoxSetMsiProp(hModule, L"VBOX_IS_WINDOWS_10", dwVal >= 10 ? L"1" : L"");
    547571        }
    548572        else
    549             logStringF(hModule, L"IsWindows10/RegOpenKeyExW: Error reading CurrentMajorVersionNumber (%ld)", dwErr);
     573            logStringF(hModule, "IsWindows10/RegOpenKeyExW: Error reading CurrentMajorVersionNumber (%ld)", lrc);
    550574
    551575        RegCloseKey(hKeyCurVer);
    552576    }
    553577    else
    554         logStringF(hModule, L"IsWindows10/RegOpenKeyExW: Error opening CurrentVersion key (%ld)", dwErr);
     578        logStringF(hModule, "IsWindows10/RegOpenKeyExW: Error opening CurrentVersion key (%ld)", lrc);
    555579
    556580    return ERROR_SUCCESS; /* Never return failure. */
     
    569593UINT __stdcall InstallPythonAPI(MSIHANDLE hModule)
    570594{
    571     logStringF(hModule, L"InstallPythonAPI: Checking for installed Python environment(s) ...");
     595    logStringF(hModule, "InstallPythonAPI: Checking for installed Python environment(s) ...");
    572596
    573597    /** @todo r=bird: Can't we get the VBOX_PYTHON_PATH property here? */
     
    585609    /* Get the VBox API setup string. */
    586610    WCHAR wszVBoxSDKPath[RTPATH_MAX];
    587     rcWin = VBoxGetMsiProp(hModule, L"CustomActionData", wszVBoxSDKPath, sizeof(wszVBoxSDKPath));
     611    rcWin = VBoxGetMsiProp(hModule, L"CustomActionData", wszVBoxSDKPath, RT_ELEMENTS(wszVBoxSDKPath));
    588612    if (rcWin == ERROR_SUCCESS)
    589613    {
     
    594618            if (SetEnvironmentVariableW(L"VBOX_INSTALL_PATH", wszVBoxSDKPath))
    595619            {
    596                 logStringF(hModule, L"InstallPythonAPI: Invoking vboxapisetup.py in \"%s\" ...", wszVBoxSDKPath);
     620                logStringF(hModule, "InstallPythonAPI: Invoking vboxapisetup.py in \"%ls\" ...", wszVBoxSDKPath);
    597621
    598622                rcWin = procRun(hModule, wszPythonExe, L"vboxapisetup.py install");
    599623                if (rcWin == ERROR_SUCCESS)
    600624                {
    601                     logStringF(hModule, L"InstallPythonAPI: Installation of vboxapisetup.py successful");
     625                    logStringF(hModule, "InstallPythonAPI: Installation of vboxapisetup.py successful");
    602626
    603627                    /*
    604628                     * Do some sanity checking if the VBox API works.
    605629                     */
    606                     logStringF(hModule, L"InstallPythonAPI: Validating VBox API ...");
     630                    logStringF(hModule, "InstallPythonAPI: Validating VBox API ...");
    607631
    608632                    rcWin = procRun(hModule, wszPythonExe, L"-c \"from vboxapi import VirtualBoxManager\"");
    609633                    if (rcWin == ERROR_SUCCESS)
    610634                    {
    611                         logStringF(hModule, L"InstallPythonAPI: VBox API looks good.");
     635                        logStringF(hModule, "InstallPythonAPI: VBox API looks good.");
    612636                        VBoxSetMsiProp(hModule, L"VBOX_API_INSTALLED", L"1");
    613637                        return ERROR_SUCCESS;
     
    615639
    616640                    /* failed */
    617                     logStringF(hModule, L"InstallPythonAPI: Validating VBox API failed with %u (%#x)", rcWin, rcWin);
     641                    logStringF(hModule, "InstallPythonAPI: Validating VBox API failed with %u (%#x)", rcWin, rcWin);
    618642                }
    619643                else
    620                     logStringF(hModule, L"InstallPythonAPI: Calling vboxapisetup.py failed with %u (%#x)", rcWin, rcWin);
     644                    logStringF(hModule, "InstallPythonAPI: Calling vboxapisetup.py failed with %u (%#x)", rcWin, rcWin);
    621645            }
    622646            else
    623                 logStringF(hModule, L"InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH: LastError=%u",
     647                logStringF(hModule, "InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH: LastError=%u",
    624648                           GetLastError());
    625649        }
    626650        else
    627             logStringF(hModule, L"InstallPythonAPI: Could set working directory to \"%s\": LastError=%u",
     651            logStringF(hModule, "InstallPythonAPI: Could set working directory to \"%ls\": LastError=%u",
    628652                       wszVBoxSDKPath, GetLastError());
    629653    }
    630654    else
    631         logStringF(hModule, L"InstallPythonAPI: Unable to retrieve VBox installation directory: rcWin=%u (%#x)", rcWin, rcWin);
     655        logStringF(hModule, "InstallPythonAPI: Unable to retrieve VBox installation directory: rcWin=%u (%#x)", rcWin, rcWin);
    632656
    633657    VBoxSetMsiProp(hModule, L"VBOX_API_INSTALLED", L"0");
    634     logStringF(hModule, L"InstallPythonAPI: Installation failed");
     658    logStringF(hModule, "InstallPythonAPI: Installation failed");
    635659    return ERROR_SUCCESS; /* Do not fail here. */
    636660}
     
    642666{
    643667    LONG rc;
    644     WCHAR wszValue[_MAX_PATH];
     668    WCHAR wszValue[MAX_PATH];
    645669    if (GetPrivateProfileStringW(pwszSection, pwszValue, NULL, wszValue, sizeof(wszValue), pwszFileName) > 0)
    646670    {
    647         WCHAR wszKey[_MAX_PATH + 64];
    648         if (wcsicmp(L"General", pwszSection) != 0)
    649             swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%S\\VirtualBox\\Branding\\%s", VBOX_VENDOR_SHORT, pwszSection);
     671        WCHAR wszKey[MAX_PATH + 64];
     672        if (RTUtf16ICmpAscii(pwszSection, "General") != 0)
     673            RTUtf16Printf(wszKey, RT_ELEMENTS(wszKey), "SOFTWARE\\%s\\VirtualBox\\Branding\\%ls", VBOX_VENDOR_SHORT, pwszSection);
    650674        else
    651             swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%S\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
     675            RTUtf16Printf(wszKey, RT_ELEMENTS(wszKey), "SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
    652676
    653677        HKEY hkBranding = NULL;
     
    660684                                REG_SZ,
    661685                                (BYTE *)wszValue,
    662                                 (DWORD)wcslen(wszValue));
     686                                (DWORD)RTUtf16Len(wszValue));
    663687            if (rc != ERROR_SUCCESS)
    664                 logStringF(hModule, L"InstallBranding: Could not write value %s! Error %d", pwszValue, rc);
     688                logStringF(hModule, "InstallBranding: Could not write value %s! Error %d", pwszValue, rc);
    665689            RegCloseKey(hkBranding);
    666690        }
     
    676700static UINT CopyDir(MSIHANDLE hModule, const WCHAR *pwszzDstDir, const WCHAR *pwszzSrcDir)
    677701{
    678     NonStandardAssert(pwszzDstDir[wcslen(pwszzDstDir) + 1] == '\0');
    679     NonStandardAssert(pwszzSrcDir[wcslen(pwszzSrcDir) + 1] == '\0');
     702    NonStandardAssert(pwszzDstDir[RTUtf16Len(pwszzDstDir) + 1] == '\0');
     703    NonStandardAssert(pwszzSrcDir[RTUtf16Len(pwszzSrcDir) + 1] == '\0');
    680704
    681705    SHFILEOPSTRUCTW s = {0};
     
    689713             | FOF_NOERRORUI;
    690714
    691     logStringF(hModule, L"CopyDir: pwszzDstDir=%s, pwszzSrcDir=%s", pwszzDstDir, pwszzSrcDir);
     715    logStringF(hModule, "CopyDir: pwszzDstDir=%ls, pwszzSrcDir=%ls", pwszzDstDir, pwszzSrcDir);
    692716    int r = SHFileOperationW(&s);
    693717    if (r == 0)
    694718        return ERROR_SUCCESS;
    695     logStringF(hModule, L"CopyDir: Copy operation returned status %#x", r);
     719    logStringF(hModule, "CopyDir: Copy operation returned status %#x", r);
    696720    return ERROR_GEN_FAILURE;
    697721}
     
    702726static UINT RemoveDir(MSIHANDLE hModule, const WCHAR *pwszzDstDir)
    703727{
    704     NonStandardAssert(pwszzDstDir[wcslen(pwszzDstDir) + 1] == '\0');
     728    NonStandardAssert(pwszzDstDir[RTUtf16Len(pwszzDstDir) + 1] == '\0');
    705729
    706730    SHFILEOPSTRUCTW s = {0};
     
    713737             | FOF_NOERRORUI;
    714738
    715     logStringF(hModule, L"RemoveDir: pwszzDstDir=%s", pwszzDstDir);
     739    logStringF(hModule, "RemoveDir: pwszzDstDir=%ls", pwszzDstDir);
    716740    int r = SHFileOperationW(&s);
    717741    if (r == 0)
    718742        return ERROR_SUCCESS;
    719     logStringF(hModule, L"RemoveDir: Remove operation returned status %#x", r);
     743    logStringF(hModule, "RemoveDir: Remove operation returned status %#x", r);
    720744    return ERROR_GEN_FAILURE;
    721745}
     
    726750static UINT RenameDir(MSIHANDLE hModule, const WCHAR *pwszzDstDir, const WCHAR *pwszzSrcDir)
    727751{
    728     NonStandardAssert(pwszzDstDir[wcslen(pwszzDstDir) + 1] == '\0');
    729     NonStandardAssert(pwszzSrcDir[wcslen(pwszzSrcDir) + 1] == '\0');
     752    NonStandardAssert(pwszzDstDir[RTUtf16Len(pwszzDstDir) + 1] == '\0');
     753    NonStandardAssert(pwszzSrcDir[RTUtf16Len(pwszzSrcDir) + 1] == '\0');
    730754
    731755    SHFILEOPSTRUCTW s = {0};
     
    739763             | FOF_NOERRORUI;
    740764
    741     logStringF(hModule, L"RenameDir: pwszzDstDir=%s, pwszzSrcDir=%s", pwszzDstDir, pwszzSrcDir);
     765    logStringF(hModule, "RenameDir: pwszzDstDir=%ls, pwszzSrcDir=%ls", pwszzDstDir, pwszzSrcDir);
    742766    int r = SHFileOperationW(&s);
    743767    if (r == 0)
    744768        return ERROR_SUCCESS;
    745     logStringF(hModule, L"RenameDir: Rename operation returned status %#x", r);
     769    logStringF(hModule, "RenameDir: Rename operation returned status %#x", r);
    746770    return ERROR_GEN_FAILURE;
    747771}
     
    750774static UINT AppendToPath(wchar_t *pwszPath, size_t cwcPath, wchar_t *pwszAppend, bool fDoubleTerm = false)
    751775{
    752     size_t cwcCurPath = wcslen(pwszPath);
     776    size_t cwcCurPath = RTUtf16Len(pwszPath);
    753777    size_t cwcSlash   = cwcCurPath > 1 && RTPATH_IS_SLASH(pwszPath[cwcCurPath - 1]) ? 0 : 1;
    754778    while (RTPATH_IS_SLASH(*pwszAppend))
    755779        pwszAppend++;
    756     size_t cwcAppend  = wcslen(pwszAppend);
     780    size_t cwcAppend  = RTUtf16Len(pwszAppend);
    757781    if (cwcCurPath + cwcCurPath + cwcAppend + fDoubleTerm < cwcPath)
    758782    {
     
    770794static UINT JoinPaths(wchar_t *pwszPath, size_t cwcPath, wchar_t *pwszPath1, wchar_t *pwszAppend, bool fDoubleTerm = false)
    771795{
    772     size_t cwcCurPath = wcslen(pwszPath1);
     796    size_t cwcCurPath = RTUtf16Len(pwszPath1);
    773797    if (cwcCurPath < cwcPath)
    774798    {
     
    781805UINT __stdcall UninstallBranding(MSIHANDLE hModule)
    782806{
    783     logStringF(hModule, L"UninstallBranding: Handling branding file ...");
     807    logStringF(hModule, "UninstallBranding: Handling branding file ...");
    784808
    785809    WCHAR wszPath[RTPATH_MAX];
    786     UINT rc = VBoxGetMsiProp(hModule, L"CustomActionData", wszPath, sizeof(wszPath));
     810    UINT rc = VBoxGetMsiProp(hModule, L"CustomActionData", wszPath, RT_ELEMENTS(wszPath));
    787811    if (rc == ERROR_SUCCESS)
    788812    {
    789         size_t const cwcPath = wcslen(wszPath);
     813        size_t const cwcPath = RTUtf16Len(wszPath);
    790814        rc = AppendToPath(wszPath, RTPATH_MAX, L"custom", true /*fDoubleTerm*/);
    791815        if (rc == ERROR_SUCCESS)
     
    799823    }
    800824
    801     logStringF(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc);
     825    logStringF(hModule, "UninstallBranding: Handling done. (rc=%u (ignored))", rc);
    802826    return ERROR_SUCCESS; /* Do not fail here. */
    803827}
     
    805829UINT __stdcall InstallBranding(MSIHANDLE hModule)
    806830{
    807     logStringF(hModule, L"InstallBranding: Handling branding file ...");
     831    logStringF(hModule, "InstallBranding: Handling branding file ...");
    808832
    809833    /*
     
    842866    }
    843867
    844     logStringF(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc);
     868    logStringF(hModule, "InstallBranding: Handling done. (rc=%u (ignored))", rc);
    845869    return ERROR_SUCCESS; /* Do not fail here. */
    846870}
     
    863887static UINT _uninstallNetLwf(MSIHANDLE hModule);
    864888
    865 static VOID vboxDrvLoggerCallback(VBOXDRVCFG_LOG_SEVERITY enmSeverity, char *pszMsg, void *pvContext)
     889static VOID vboxDrvLoggerCallback(VBOXDRVCFG_LOG_SEVERITY_T enmSeverity, char *pszMsg, void *pvContext)
    866890{
    867891    RT_NOREF1(pvContext);
     
    873897        case VBOXDRVCFG_LOG_SEVERITY_REL:
    874898            if (g_hCurrentModule)
    875                 logStringF(g_hCurrentModule, L"%S", pszMsg);
     899                logStringF(g_hCurrentModule, "%s", pszMsg);
    876900            break;
    877901        default:
     
    883907{
    884908    if (g_hCurrentModule)
    885         logStringF(g_hCurrentModule, L"%S", pszString);
     909        logStringF(g_hCurrentModule, "%s", pszString);
    886910}
    887911
     
    920944        case NETCFG_S_REBOOT:
    921945        {
    922             logStringF(hModule, L"Reboot required, setting REBOOT property to \"force\"");
     946            logStringF(hModule, "Reboot required, setting REBOOT property to \"force\"");
    923947            HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
    924948            if (hr2 != ERROR_SUCCESS)
    925                 logStringF(hModule, L"Failed to set REBOOT property, error = %#x", hr2);
     949                logStringF(hModule, "Failed to set REBOOT property, error = %#x", hr2);
    926950            uRet = ERROR_SUCCESS; /* Never fail here. */
    927951            break;
     
    929953
    930954        default:
    931             logStringF(hModule, L"Converting unhandled HRESULT (%#x) to ERROR_GEN_FAILURE", hr);
     955            logStringF(hModule, "Converting unhandled HRESULT (%#x) to ERROR_GEN_FAILURE", hr);
    932956            uRet = ERROR_GEN_FAILURE;
    933957    }
     
    943967        if (uErr != ERROR_SUCCESS)
    944968        {
    945             logStringF(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = %#x", uErr);
     969            logStringF(hModule, "createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = %#x", uErr);
    946970            MsiCloseHandle(hRecord);
    947971            hRecord = NULL;
     
    949973    }
    950974    else
    951         logStringF(hModule, L"createNetCfgLockedMsgRecord: Failed to create a record");
     975        logStringF(hModule, "createNetCfgLockedMsgRecord: Failed to create a record");
    952976
    953977    return hRecord;
     
    968992        {
    969993            if (FAILED(hr))
    970                 logStringF(hModule, L"doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = %#x", hr);
     994                logStringF(hModule, "doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = %#x", hr);
    971995            uErr = errorConvertFromHResult(hModule, hr);
    972996            break;
     
    9771001        if (!lpszLockedBy)
    9781002        {
    979             logStringF(hModule, L"doNetCfgInit: lpszLockedBy == NULL, breaking");
     1003            logStringF(hModule, "doNetCfgInit: lpszLockedBy == NULL, breaking");
    9801004            break;
    9811005        }
     
    9881012         * rather than waiting for a longer period of time before displaying it */
    9891013        if (   cRetries < VBOX_NETCFG_MAX_RETRIES
    990             && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
     1014            && RTUtf16ICmpAscii(lpszLockedBy, "6to4svc.dll") == 0)
    9911015        {
    9921016            cRetries++;
    993             logStringF(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);
     1017            logStringF(hModule, "doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);
    9941018            MsgResult = IDRETRY;
    9951019        }
     
    10011025                if (!hMsg)
    10021026                {
    1003                     logStringF(hModule, L"doNetCfgInit: Failed to create a message record, breaking");
     1027                    logStringF(hModule, "doNetCfgInit: Failed to create a message record, breaking");
    10041028                    CoTaskMemFree(lpszLockedBy);
    10051029                    break;
     
    10111035            if (rTmp != ERROR_SUCCESS)
    10121036            {
    1013                 logStringF(hModule, L"doNetCfgInit: MsiRecordSetStringW failed, error = #%x", rTmp);
     1037                logStringF(hModule, "doNetCfgInit: MsiRecordSetStringW failed, error = #%x", rTmp);
    10141038                CoTaskMemFree(lpszLockedBy);
    10151039                break;
     
    10181042            MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg);
    10191043            NonStandardAssert(MsgResult == IDRETRY || MsgResult == IDCANCEL);
    1020             logStringF(hModule, L"doNetCfgInit: MsiProcessMessage returned (%#x)", MsgResult);
     1044            logStringF(hModule, "doNetCfgInit: MsiProcessMessage returned (%#x)", MsgResult);
    10211045        }
    10221046        CoTaskMemFree(lpszLockedBy);
     
    10291053}
    10301054
    1031 static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize)
    1032 {
    1033     DWORD dwBuf = dwSize - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH));
    1034     UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &dwBuf);
     1055static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, DWORD cwcPtInf,
     1056                                    OUT LPWSTR pwszMpInf, DWORD cwcMpInf)
     1057{
     1058    DWORD cwcEffBuf = cwcPtInf - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH)) / sizeof(WCHAR);
     1059    UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &cwcEffBuf);
    10351060    if (   uErr == ERROR_SUCCESS
    1036         && dwBuf)
    1037     {
    1038         wcscpy(pwszMpInf, pwszPtInf);
    1039 
    1040         wcsncat(pwszPtInf, NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH));
    1041         logStringF(hModule, L"vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf);
    1042 
    1043         wcsncat(pwszMpInf, NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH));
    1044         logStringF(hModule, L"vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf);
     1061        && cwcEffBuf > 0)
     1062    {
     1063        int vrc = RTUtf16Copy(pwszMpInf, cwcMpInf, pwszPtInf);
     1064        AssertRCReturn(vrc, ERROR_BUFFER_OVERFLOW);
     1065
     1066        vrc = RTUtf16Cat(pwszPtInf, cwcPtInf, NETFLT_PT_INF_REL_PATH);
     1067        AssertRCReturn(vrc, ERROR_BUFFER_OVERFLOW);
     1068        logStringF(hModule, "vboxNetFltQueryInfArray: INF 1: %ls", pwszPtInf);
     1069
     1070        vrc = RTUtf16Cat(pwszMpInf, cwcMpInf, NETFLT_MP_INF_REL_PATH);
     1071        AssertRCReturn(vrc, ERROR_BUFFER_OVERFLOW);
     1072        logStringF(hModule, "vboxNetFltQueryInfArray: INF 2: %ls", pwszMpInf);
    10451073    }
    10461074    else if (uErr != ERROR_SUCCESS)
    1047         logStringF(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr);
     1075        logStringF(hModule, "vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr);
    10481076    else
    10491077    {
    1050         logStringF(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");
     1078        logStringF(hModule, "vboxNetFltQueryInfArray: Empty installation directory");
    10511079        uErr = ERROR_GEN_FAILURE;
    10521080    }
     
    10691097    __try
    10701098    {
    1071         logStringF(hModule, L"Uninstalling NetFlt");
     1099        logStringF(hModule, "Uninstalling NetFlt");
    10721100
    10731101        uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
     
    10761104            HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg);
    10771105            if (hr != S_OK)
    1078                 logStringF(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);
     1106                logStringF(hModule, "UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);
    10791107
    10801108            uErr = errorConvertFromHResult(hModule, hr);
     
    10821110            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
    10831111
    1084             logStringF(hModule, L"Uninstalling NetFlt done, error = %#x", uErr);
     1112            logStringF(hModule, "Uninstalling NetFlt done, error = %#x", uErr);
    10851113        }
    10861114        else
    1087             logStringF(hModule, L"UninstallNetFlt: doNetCfgInit failed, error = %#x", uErr);
     1115            logStringF(hModule, "UninstallNetFlt: doNetCfgInit failed, error = %#x", uErr);
    10881116    }
    10891117    __finally
     
    11211149    {
    11221150
    1123         logStringF(hModule, L"InstallNetFlt: Installing NetFlt");
     1151        logStringF(hModule, "InstallNetFlt: Installing NetFlt");
    11241152
    11251153        uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
     
    11281156            WCHAR wszPtInf[MAX_PATH];
    11291157            WCHAR wszMpInf[MAX_PATH];
    1130             uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, wszMpInf, sizeof(wszMpInf));
     1158            uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, RT_ELEMENTS(wszPtInf), wszMpInf, RT_ELEMENTS(wszMpInf));
    11311159            if (uErr == ERROR_SUCCESS)
    11321160            {
     
    11341162                HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, &apwszInfs[0], RT_ELEMENTS(apwszInfs));
    11351163                if (FAILED(hr))
    1136                     logStringF(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = %#x", hr);
     1164                    logStringF(hModule, "InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = %#x", hr);
    11371165
    11381166                uErr = errorConvertFromHResult(hModule, hr);
    11391167            }
    11401168            else
    1141                 logStringF(hModule, L"InstallNetFlt: vboxNetFltQueryInfArray failed, error = %#x", uErr);
     1169                logStringF(hModule, "InstallNetFlt: vboxNetFltQueryInfArray failed, error = %#x", uErr);
    11421170
    11431171            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
    11441172
    1145             logStringF(hModule, L"InstallNetFlt: Done");
     1173            logStringF(hModule, "InstallNetFlt: Done");
    11461174        }
    11471175        else
    1148             logStringF(hModule, L"InstallNetFlt: doNetCfgInit failed, error = %#x", uErr);
     1176            logStringF(hModule, "InstallNetFlt: doNetCfgInit failed, error = %#x", uErr);
    11491177    }
    11501178    __finally
     
    11821210    __try
    11831211    {
    1184         logStringF(hModule, L"Uninstalling NetLwf");
     1212        logStringF(hModule, "Uninstalling NetLwf");
    11851213
    11861214        uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
     
    11891217            HRESULT hr = VBoxNetCfgWinNetLwfUninstall(pNetCfg);
    11901218            if (hr != S_OK)
    1191                 logStringF(hModule, L"UninstallNetLwf: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);
     1219                logStringF(hModule, "UninstallNetLwf: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);
    11921220
    11931221            uErr = errorConvertFromHResult(hModule, hr);
     
    11951223            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
    11961224
    1197             logStringF(hModule, L"Uninstalling NetLwf done, error = %#x", uErr);
     1225            logStringF(hModule, "Uninstalling NetLwf done, error = %#x", uErr);
    11981226        }
    11991227        else
    1200             logStringF(hModule, L"UninstallNetLwf: doNetCfgInit failed, error = %#x", uErr);
     1228            logStringF(hModule, "UninstallNetLwf: doNetCfgInit failed, error = %#x", uErr);
    12011229    }
    12021230    __finally
     
    12341262    {
    12351263
    1236         logStringF(hModule, L"InstallNetLwf: Installing NetLwf");
     1264        logStringF(hModule, "InstallNetLwf: Installing NetLwf");
    12371265
    12381266        uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
     
    12521280                    }
    12531281
    1254                     wcscat(wszInf, NETLWF_INF_NAME);
     1282                    int vrc = RTUtf16Cat(wszInf, RT_ELEMENTS(wszInf), NETLWF_INF_NAME);
     1283                    AssertRC(vrc);
    12551284
    12561285                    HRESULT hr = VBoxNetCfgWinNetLwfInstall(pNetCfg, wszInf);
    12571286                    if (FAILED(hr))
    1258                         logStringF(hModule, L"InstallNetLwf: VBoxNetCfgWinNetLwfInstall failed, error = %#x", hr);
     1287                        logStringF(hModule, "InstallNetLwf: VBoxNetCfgWinNetLwfInstall failed, error = %#x", hr);
    12591288
    12601289                    uErr = errorConvertFromHResult(hModule, hr);
     
    12621291                else
    12631292                {
    1264                     logStringF(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");
     1293                    logStringF(hModule, "vboxNetFltQueryInfArray: Empty installation directory");
    12651294                    uErr = ERROR_GEN_FAILURE;
    12661295                }
    12671296            }
    12681297            else
    1269                 logStringF(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr);
     1298                logStringF(hModule, "vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = %#x", uErr);
    12701299
    12711300            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
    12721301
    1273             logStringF(hModule, L"InstallNetLwf: Done");
     1302            logStringF(hModule, "InstallNetLwf: Done");
    12741303        }
    12751304        else
    1276             logStringF(hModule, L"InstallNetLwf: doNetCfgInit failed, error = %#x", uErr);
     1305            logStringF(hModule, "InstallNetLwf: doNetCfgInit failed, error = %#x", uErr);
    12771306    }
    12781307    __finally
     
    13361365                ULONG cbName = sizeof(ConnectoinName);
    13371366
    1338                 HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName (DevName, ConnectoinName, &cbName);
     1367                HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName(DevName, ConnectoinName, &cbName);
    13391368                NonStandardAssert(hr == S_OK);
    13401369                if (SUCCEEDED(hr))
     
    13631392    BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
    13641393
    1365     logStringF(hModule, L"CreateHostOnlyInterface: Creating host-only interface");
     1394    logStringF(hModule, "CreateHostOnlyInterface: Creating host-only interface");
    13661395
    13671396    HRESULT hr = E_FAIL;
    13681397    GUID guid;
    13691398    WCHAR wszMpInf[MAX_PATH];
    1370     DWORD cchMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)wcslen(pwszInfName) - 1 - 1;
     1399    DWORD cwcMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)RTUtf16Len(pwszInfName) - 1 - 1;
    13711400    LPCWSTR pwszInfPath = NULL;
    13721401    bool fIsFile = false;
    1373     UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cchMpInf);
     1402    UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cwcMpInf);
    13741403    if (uErr == ERROR_SUCCESS)
    13751404    {
    1376         if (cchMpInf)
    1377         {
    1378             logStringF(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", wszMpInf);
    1379             if (wszMpInf[cchMpInf - 1] != L'\\')
    1380             {
    1381                 wszMpInf[cchMpInf++] = L'\\';
    1382                 wszMpInf[cchMpInf]   = L'\0';
    1383             }
    1384 
    1385             wcscat(wszMpInf, pwszInfName);
     1405        if (cwcMpInf)
     1406        {
     1407            logStringF(hModule, "CreateHostOnlyInterface: NetAdpDir property = %ls", wszMpInf);
     1408            if (wszMpInf[cwcMpInf - 1] != L'\\')
     1409            {
     1410                wszMpInf[cwcMpInf++] = L'\\';
     1411                wszMpInf[cwcMpInf]   = L'\0';
     1412            }
     1413
     1414            int vrc = RTUtf16Cat(wszMpInf, RT_ELEMENTS(wszMpInf), pwszInfName);
     1415            AssertRC(vrc);
     1416
    13861417            pwszInfPath = wszMpInf;
    13871418            fIsFile = true;
    13881419
    1389             logStringF(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pwszInfPath);
     1420            logStringF(hModule, "CreateHostOnlyInterface: Resulting INF path = %ls", pwszInfPath);
    13901421        }
    13911422        else
    1392             logStringF(hModule, L"CreateHostOnlyInterface: VBox installation path is empty");
     1423            logStringF(hModule, "CreateHostOnlyInterface: VBox installation path is empty");
    13931424    }
    13941425    else
    1395         logStringF(hModule, L"CreateHostOnlyInterface: Unable to retrieve VBox installation path, error = %#x", uErr);
     1426        logStringF(hModule, "CreateHostOnlyInterface: Unable to retrieve VBox installation path, error = %#x", uErr);
    13961427
    13971428    /* Make sure the inf file is installed. */
    13981429    if (pwszInfPath != NULL && fIsFile)
    13991430    {
    1400         logStringF(hModule, L"CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%s)", pwszInfPath);
     1431        logStringF(hModule, "CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%ls)", pwszInfPath);
    14011432        hr = VBoxDrvCfgInfInstall(pwszInfPath);
    1402         logStringF(hModule, L"CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns %#x", hr);
     1433        logStringF(hModule, "CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns %#x", hr);
    14031434        if (FAILED(hr))
    1404             logStringF(hModule, L"CreateHostOnlyInterface: Failed to install INF file, error = %#x", hr);
     1435            logStringF(hModule, "CreateHostOnlyInterface: Failed to install INF file, error = %#x", hr);
    14051436    }
    14061437
     
    14141445            if (fRebootRequired)
    14151446            {
    1416                 logStringF(hModule, L"CreateHostOnlyInterface: Reboot required for update, setting REBOOT property to force");
     1447                logStringF(hModule, "CreateHostOnlyInterface: Reboot required for update, setting REBOOT property to force");
    14171448                HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
    14181449                if (hr2 != ERROR_SUCCESS)
    1419                     logStringF(hModule, L"CreateHostOnlyInterface: Failed to set REBOOT property for update, error = %#x", hr2);
     1450                    logStringF(hModule, "CreateHostOnlyInterface: Failed to set REBOOT property for update, error = %#x", hr2);
    14201451            }
    14211452        }
     
    14231454        {
    14241455            //in fail case call CreateHostOnlyInterface
    1425             logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr);
    1426             logStringF(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");
     1456            logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr);
     1457            logStringF(hModule, "CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");
    14271458#ifdef VBOXNETCFG_DELAYEDRENAME
    14281459            BSTR devId;
     
    14311462            hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, NULL, &guid, NULL, NULL);
    14321463#endif /* !VBOXNETCFG_DELAYEDRENAME */
    1433             logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns %#x", hr);
     1464            logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns %#x", hr);
    14341465            if (SUCCEEDED(hr))
    14351466            {
    14361467                ULONG ip = inet_addr("192.168.56.1");
    14371468                ULONG mask = inet_addr("255.255.255.0");
    1438                 logStringF(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig");
     1469                logStringF(hModule, "CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig");
    14391470                hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
    1440                 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns %#x", hr);
     1471                logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns %#x", hr);
    14411472                if (FAILED(hr))
    1442                     logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = %#x", hr);
     1473                    logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = %#x", hr);
    14431474#ifdef VBOXNETCFG_DELAYEDRENAME
    14441475                hr = VBoxNetCfgWinRenameHostOnlyConnection(&guid, devId, NULL);
    14451476                if (FAILED(hr))
    1446                     logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinRenameHostOnlyConnection failed, error = %#x", hr);
     1477                    logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinRenameHostOnlyConnection failed, error = %#x", hr);
    14471478                SysFreeString(devId);
    14481479#endif /* VBOXNETCFG_DELAYEDRENAME */
    14491480            }
    14501481            else
    1451                 logStringF(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = %#x", hr);
     1482                logStringF(hModule, "CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = %#x", hr);
    14521483        }
    14531484    }
    14541485
    14551486    if (SUCCEEDED(hr))
    1456         logStringF(hModule, L"CreateHostOnlyInterface: Creating host-only interface done");
     1487        logStringF(hModule, "CreateHostOnlyInterface: Creating host-only interface done");
    14571488
    14581489    /* Restore original setup mode. */
    1459     logStringF(hModule, L"CreateHostOnlyInterface: Almost done...");
     1490    logStringF(hModule, "CreateHostOnlyInterface: Almost done...");
    14601491    if (fSetupModeInteractive)
    14611492        SetupSetNonInteractiveMode(fSetupModeInteractive);
     
    14651496#endif /* VBOX_WITH_NETFLT */
    14661497
    1467     logStringF(hModule, L"CreateHostOnlyInterface: Returns success (ignoring all failures)");
     1498    logStringF(hModule, "CreateHostOnlyInterface: Returns success (ignoring all failures)");
    14681499    /* Never fail the install even if we did not succeed. */
    14691500    return ERROR_SUCCESS;
     
    14771508UINT __stdcall Ndis6CreateHostOnlyInterface(MSIHANDLE hModule)
    14781509{
     1510#if 0 /* Trick for allowing the debugger to be attached. */
     1511    for (unsigned i = 0; i < 128 && !IsDebuggerPresent(); i++)
     1512    {
     1513        logStringF(hModule, "Waiting for debugger to attach: windbg -p %u", GetCurrentProcessId());
     1514        Sleep(1001);
     1515    }
     1516    Sleep(1002);
     1517    __debugbreak();
     1518#endif
    14791519    return _createHostOnlyInterface(hModule, NETADP_ID, L"VBoxNetAdp6.inf");
    14801520}
     
    14851525    netCfgLoggerEnable(hModule);
    14861526
    1487     logStringF(hModule, L"RemoveHostOnlyInterfaces: Removing all host-only interfaces");
     1527    logStringF(hModule, "RemoveHostOnlyInterfaces: Removing all host-only interfaces");
    14881528
    14891529    BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
     
    14941534        hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", pwszId, SUOI_FORCEDELETE/* could be SUOI_FORCEDELETE */);
    14951535        if (FAILED(hr))
    1496             logStringF(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove INF files");
     1536            logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove INF files");
    14971537        else
    1498             logStringF(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully");
     1538            logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstalled successfully");
    14991539    }
    15001540    else
    1501         logStringF(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = %#x", hr);
     1541        logStringF(hModule, "RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = %#x", hr);
    15021542
    15031543    /* Restore original setup mode. */
     
    15221562    netCfgLoggerEnable(hModule);
    15231563
    1524     logStringF(hModule, L"StopHostOnlyInterfaces: Stopping all host-only interfaces");
     1564    logStringF(hModule, "StopHostOnlyInterfaces: Stopping all host-only interfaces");
    15251565
    15261566    BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
     
    15281568    HRESULT hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(pwszId, VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE);
    15291569    if (SUCCEEDED(hr))
    1530         logStringF(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces was successful, hr = %#x", hr);
     1570        logStringF(hModule, "StopHostOnlyInterfaces: Disabling host interfaces was successful, hr = %#x", hr);
    15311571    else
    1532         logStringF(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces failed, hr = %#x", hr);
     1572        logStringF(hModule, "StopHostOnlyInterfaces: Disabling host interfaces failed, hr = %#x", hr);
    15331573
    15341574    /* Restore original setup mode. */
     
    15531593    netCfgLoggerEnable(hModule);
    15541594
    1555     logStringF(hModule, L"UpdateHostOnlyInterfaces: Updating all host-only interfaces");
     1595    logStringF(hModule, "UpdateHostOnlyInterfaces: Updating all host-only interfaces");
    15561596
    15571597    BOOL fSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
    15581598
    15591599    WCHAR wszMpInf[MAX_PATH];
    1560     DWORD cchMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)wcslen(pwszInfName) - 1 - 1;
     1600    DWORD cwcMpInf = RT_ELEMENTS(wszMpInf) - (DWORD)RTUtf16Len(pwszInfName) - 1 - 1;
    15611601    LPCWSTR pwszInfPath = NULL;
    15621602    bool fIsFile = false;
    1563     UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cchMpInf);
     1603    UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cwcMpInf);
    15641604    if (uErr == ERROR_SUCCESS)
    15651605    {
    1566         if (cchMpInf)
    1567         {
    1568             logStringF(hModule, L"UpdateHostOnlyInterfaces: NetAdpDir property = %s", wszMpInf);
    1569             if (wszMpInf[cchMpInf - 1] != L'\\')
    1570             {
    1571                 wszMpInf[cchMpInf++] = L'\\';
    1572                 wszMpInf[cchMpInf]   = L'\0';
    1573             }
    1574 
    1575             wcscat(wszMpInf, pwszInfName);
     1606        if (cwcMpInf)
     1607        {
     1608            logStringF(hModule, "UpdateHostOnlyInterfaces: NetAdpDir property = %ls", wszMpInf);
     1609            if (wszMpInf[cwcMpInf - 1] != L'\\')
     1610            {
     1611                wszMpInf[cwcMpInf++] = L'\\';
     1612                wszMpInf[cwcMpInf]   = L'\0';
     1613            }
     1614
     1615            int vrc = RTUtf16Cat(wszMpInf, RT_ELEMENTS(wszMpInf), pwszInfName);
     1616             AssertRC(vrc);
    15761617            pwszInfPath = wszMpInf;
    15771618            fIsFile = true;
    15781619
    1579             logStringF(hModule, L"UpdateHostOnlyInterfaces: Resulting INF path = %s", pwszInfPath);
     1620            logStringF(hModule, "UpdateHostOnlyInterfaces: Resulting INF path = %ls", pwszInfPath);
    15801621
    15811622            DWORD attrFile = GetFileAttributesW(pwszInfPath);
     
    15831624            {
    15841625                DWORD dwErr = GetLastError();
    1585                 logStringF(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" not found, dwErr=%ld", pwszInfPath, dwErr);
     1626                logStringF(hModule, "UpdateHostOnlyInterfaces: File \"%ls\" not found, dwErr=%ld", pwszInfPath, dwErr);
    15861627            }
    15871628            else
    15881629            {
    1589                 logStringF(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" exists", pwszInfPath);
     1630                logStringF(hModule, "UpdateHostOnlyInterfaces: File \"%ls\" exists", pwszInfPath);
    15901631
    15911632                BOOL fRebootRequired = FALSE;
     
    15951636                    if (fRebootRequired)
    15961637                    {
    1597                         logStringF(hModule, L"UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force");
     1638                        logStringF(hModule, "UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force");
    15981639                        HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
    15991640                        if (hr2 != ERROR_SUCCESS)
    1600                             logStringF(hModule, L"UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = %#x", hr2);
     1641                            logStringF(hModule, "UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = %#x", hr2);
    16011642                    }
    16021643                }
    16031644                else
    1604                     logStringF(hModule, L"UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr);
     1645                    logStringF(hModule, "UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = %#x", hr);
    16051646            }
    16061647        }
    16071648        else
    1608             logStringF(hModule, L"UpdateHostOnlyInterfaces: VBox installation path is empty");
     1649            logStringF(hModule, "UpdateHostOnlyInterfaces: VBox installation path is empty");
    16091650    }
    16101651    else
    1611         logStringF(hModule, L"UpdateHostOnlyInterfaces: Unable to retrieve VBox installation path, error = %#x", uErr);
     1652        logStringF(hModule, "UpdateHostOnlyInterfaces: Unable to retrieve VBox installation path, error = %#x", uErr);
    16121653
    16131654    /* Restore original setup mode. */
     
    16441685    __try
    16451686    {
    1646         logStringF(hModule, L"Uninstalling NetAdp");
     1687        logStringF(hModule, "Uninstalling NetAdp");
    16471688
    16481689        uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
     
    16511692            HRESULT hr = VBoxNetCfgWinNetAdpUninstall(pNetCfg, pwszId);
    16521693            if (hr != S_OK)
    1653                 logStringF(hModule, L"UninstallNetAdp: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);
     1694                logStringF(hModule, "UninstallNetAdp: VBoxNetCfgWinUninstallComponent failed, error = %#x", hr);
    16541695
    16551696            uErr = errorConvertFromHResult(hModule, hr);
     
    16571698            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
    16581699
    1659             logStringF(hModule, L"Uninstalling NetAdp done, error = %#x", uErr);
     1700            logStringF(hModule, "Uninstalling NetAdp done, error = %#x", uErr);
    16601701        }
    16611702        else
    1662             logStringF(hModule, L"UninstallNetAdp: doNetCfgInit failed, error = %#x", uErr);
     1703            logStringF(hModule, "UninstallNetAdp: doNetCfgInit failed, error = %#x", uErr);
    16631704    }
    16641705    __finally
     
    17241765                lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen);
    17251766
    1726                 if (   !wcscmp(wszNetCfgInstanceId, pwszGUID)
    1727                     && !wcscmp(wszNetProductName, L"VirtualBox TAP Adapter")
    1728                     && (   (!wcscmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */
    1729                         || (!wcscmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */
    1730                         || (!wcscmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
     1767                if (   !RTUtf16Cmp(wszNetCfgInstanceId, pwszGUID)
     1768                    && !RTUtf16Cmp(wszNetProductName, L"VirtualBox TAP Adapter")
     1769                    && (   (!RTUtf16Cmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */
     1770                        || (!RTUtf16Cmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */
     1771                        || (!RTUtf16Cmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
    17311772                       )
    17321773                   )
     
    17461787}
    17471788
    1748 /** @todo r=andy BUGBUG WTF! Why do we a) set the rc to 0 (success), and b) need this macro at all!? */
     1789/** @todo r=andy BUGBUG WTF! Why do we a) set the rc to 0 (success), and b) need this macro at all!?
     1790 *
     1791 * @todo r=bird: Because it's returning a bool, not int? The return code is
     1792 * ignored anyway, both internally in removeNetworkInterface and in it's caller.
     1793 * There is similar code in VBoxNetCfg.cpp, which is probably where it was copied from. */
    17491794#define SetErrBreak(args) \
    17501795    if (1) { \
     
    17691814        {
    17701815            WCHAR wszRegLocation[256];
    1771             swprintf_s(wszRegLocation, RT_ELEMENTS(wszRegLocation),
    1772                        L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", pwszGUID);
    1773             LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork);
    1774             if (lStatus != ERROR_SUCCESS || !hkeyNetwork)
    1775                 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]",
    1776                              wszRegLocation));
    1777 
    1778             lStatus = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection);
    1779             if (lStatus != ERROR_SUCCESS || !hkeyConnection)
    1780                 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]",
    1781                              wszRegLocation));
     1816            RTUtf16Printf(wszRegLocation, RT_ELEMENTS(wszRegLocation),
     1817                          "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%ls", pwszGUID);
     1818            LONG lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork);
     1819            if (lrc != ERROR_SUCCESS || !hkeyNetwork)
     1820                SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%ls)! (lrc=%d) [1]",
     1821                             wszRegLocation, lrc));
     1822
     1823            lrc = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection);
     1824            if (lrc != ERROR_SUCCESS || !hkeyConnection)
     1825                SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%ls)! (lrc=%d) [2]",
     1826                             wszRegLocation, lrc));
    17821827
    17831828            DWORD len = sizeof(wszPnPInstanceId);
    17841829            DWORD dwKeyType;
    1785             lStatus = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL, &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len);
    1786             if (lStatus != ERROR_SUCCESS || (dwKeyType != REG_SZ))
    1787                 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]",
    1788                              wszRegLocation));
     1830            lrc = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL, &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len);
     1831            if (lrc != ERROR_SUCCESS || dwKeyType != REG_SZ)
     1832                SetErrBreak((hModule, "VBox HostInterfaces: Host interface network was not found in registry (%ls)! (lrc=%d) [3]",
     1833                             wszRegLocation, lrc));
    17891834        }
    17901835        while (0);
     
    18051850        do /* break-loop */
    18061851        {
     1852            /* initialize the structure size */
     1853            SP_DEVINFO_DATA DeviceInfoData = { sizeof(DeviceInfoData) };
     1854
     1855            /* copy the net class GUID */
    18071856            GUID netGuid;
    1808             SP_DEVINFO_DATA DeviceInfoData;
    1809             DWORD index = 0;
    1810             DWORD size = 0;
    1811 
    1812             /* initialize the structure size */
    1813             DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
    1814 
    1815             /* copy the net class GUID */
    18161857            memcpy(&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
    18171858
     
    18201861            if (hDeviceInfo == INVALID_HANDLE_VALUE)
    18211862            {
    1822                 logStringF(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError());
    1823                 SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));
    1824             }
    1825 
     1863                logStringF(hModule, "VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError());
     1864                SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!"));
     1865            }
     1866
     1867            /* enumerate the driver info list */
    18261868            BOOL fFoundDevice = FALSE;
    1827 
    1828             /* enumerate the driver info list */
    1829             while (TRUE)
    1830             {
    1831                 WCHAR *pwszDeviceHwid;
    1832 
     1869            for (DWORD index = 0;; index++)
     1870            {
    18331871                fResult = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData);
    18341872                if (!fResult)
     
    18361874                    if (GetLastError() == ERROR_NO_MORE_ITEMS)
    18371875                        break;
    1838                     else
    1839                     {
    1840                         index++;
    1841                         continue;
    1842                     }
     1876                    continue;
    18431877                }
    18441878
    18451879                /* try to get the hardware ID registry property */
     1880                WCHAR *pwszDeviceHwid;
     1881                DWORD size = 0;
    18461882                fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
    18471883                                                           &DeviceInfoData,
     
    18541890                {
    18551891                    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
     1892                        continue;
     1893
     1894                    pwszDeviceHwid = (WCHAR *)RTMemAllocZ(size);
     1895                    if (!pwszDeviceHwid)
     1896                        continue;
     1897
     1898                    fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
     1899                                                               &DeviceInfoData,
     1900                                                               SPDRP_HARDWAREID,
     1901                                                               NULL,
     1902                                                               (PBYTE)pwszDeviceHwid,
     1903                                                               size,
     1904                                                               &size);
     1905                    if (!fResult)
    18561906                    {
    1857                         index++;
     1907                        RTMemFree(pwszDeviceHwid);
    18581908                        continue;
    1859                     }
    1860 
    1861                     pwszDeviceHwid = (WCHAR *)malloc(size);
    1862                     if (pwszDeviceHwid)
    1863                     {
    1864                         fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
    1865                                                                    &DeviceInfoData,
    1866                                                                    SPDRP_HARDWAREID,
    1867                                                                    NULL,
    1868                                                                    (PBYTE)pwszDeviceHwid,
    1869                                                                    size,
    1870                                                                    NULL);
    1871                         if (!fResult)
    1872                         {
    1873                             free(pwszDeviceHwid);
    1874                             pwszDeviceHwid = NULL;
    1875                             index++;
    1876                             continue;
    1877                         }
    18781909                    }
    18791910                }
     
    18811912                {
    18821913                    /* something is wrong.  This shouldn't have worked with a NULL buffer */
    1883                     index++;
    18841914                    continue;
    18851915                }
    18861916
    18871917                for (WCHAR *t = pwszDeviceHwid;
    1888                      t && *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)];
    1889                      t += wcslen(t) + 1)
     1918                     *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)];
     1919                     t += RTUtf16Len(t) + 1)
    18901920                {
    1891                     if (!_wcsicmp(L"vboxtap", t))
     1921                    if (RTUtf16ICmpAscii(t, "vboxtap") == 0)
    18921922                    {
    1893                           /* get the device instance ID */
    1894                           WCHAR wszDevID[MAX_DEVICE_ID_LEN];
    1895                           if (CM_Get_Device_IDW(DeviceInfoData.DevInst,
    1896                                                 wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
    1897                           {
    1898                               /* compare to what we determined before */
    1899                               if (!wcscmp(wszDevID, wszPnPInstanceId))
    1900                               {
    1901                                   fFoundDevice = TRUE;
    1902                                   break;
    1903                               }
    1904                           }
     1923                        /* get the device instance ID */
     1924                        WCHAR wszDevID[MAX_DEVICE_ID_LEN];
     1925                        if (CM_Get_Device_IDW(DeviceInfoData.DevInst, wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
     1926                        {
     1927                            /* compare to what we determined before */
     1928                            if (RTUtf16Cmp(wszDevID, wszPnPInstanceId) == 0)
     1929                            {
     1930                                fFoundDevice = TRUE;
     1931                                break;
     1932                            }
     1933                        }
    19051934                    }
    19061935                }
    19071936
    1908                 if (pwszDeviceHwid)
    1909                 {
    1910                     free(pwszDeviceHwid);
    1911                     pwszDeviceHwid = NULL;
    1912                 }
     1937                RTMemFree(pwszDeviceHwid);
    19131938
    19141939                if (fFoundDevice)
    19151940                    break;
    1916 
    1917                 index++;
    19181941            }
    19191942
     
    19231946                if (!fResult)
    19241947                {
    1925                     logStringF(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());
    1926                     SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));
     1948                    logStringF(hModule, "VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());
     1949                    SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!"));
    19271950                }
    19281951
     
    19301953                if (!fResult)
    19311954                {
    1932                     logStringF(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());
    1933                     SetErrBreak((hModule, L"VBox HostInterfaces: Uninstallation failed!"));
     1955                    logStringF(hModule, "VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());
     1956                    SetErrBreak((hModule, "VBox HostInterfaces: Uninstallation failed!"));
    19341957                }
    19351958            }
    19361959            else
    1937                 SetErrBreak((hModule, L"VBox HostInterfaces: Host interface network device not found!"));
     1960                SetErrBreak((hModule, "VBox HostInterfaces: Host interface network device not found!"));
    19381961        } while (0);
    19391962
     
    19501973    HKEY hCtrlNet;
    19511974
    1952     LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet);
    1953     if (lStatus == ERROR_SUCCESS)
    1954     {
    1955         logStringF(hModule, L"VBox HostInterfaces: Enumerating interfaces ...");
     1975    LSTATUS lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet);
     1976    if (lrc == ERROR_SUCCESS)
     1977    {
     1978        logStringF(hModule, "VBox HostInterfaces: Enumerating interfaces ...");
    19561979        for (int i = 0; ; ++i)
    19571980        {
    19581981            WCHAR wszNetworkGUID[256] = { 0 };
    19591982            DWORD dwLen = (DWORD)sizeof(wszNetworkGUID);
    1960             lStatus = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);
    1961             if (lStatus != ERROR_SUCCESS)
    1962             {
    1963                 switch (lStatus)
     1983            lrc = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);
     1984            if (lrc != ERROR_SUCCESS)
     1985            {
     1986                switch (lrc)
    19641987                {
    19651988                    case ERROR_NO_MORE_ITEMS:
    1966                         logStringF(hModule, L"VBox HostInterfaces: No interfaces found.");
     1989                        logStringF(hModule, "VBox HostInterfaces: No interfaces found.");
    19671990                        break;
    19681991                    default:
    1969                         logStringF(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus);
     1992                        logStringF(hModule, "VBox HostInterfaces: Enumeration failed: %ld", lrc);
    19701993                        break;
    19711994                }
     
    19751998            if (isTAPDevice(wszNetworkGUID))
    19761999            {
    1977                 logStringF(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID);
     2000                logStringF(hModule, "VBox HostInterfaces: Removing interface \"%ls\" ...", wszNetworkGUID);
    19782001                removeNetworkInterface(hModule, wszNetworkGUID);
    1979                 lStatus = RegDeleteKeyW(hCtrlNet, wszNetworkGUID);
     2002                lrc = RegDeleteKeyW(hCtrlNet, wszNetworkGUID);
    19802003            }
    19812004        }
    19822005        RegCloseKey(hCtrlNet);
    1983         logStringF(hModule, L"VBox HostInterfaces: Removing interfaces done.");
     2006        logStringF(hModule, "VBox HostInterfaces: Removing interfaces done.");
    19842007    }
    19852008    return ERROR_SUCCESS;
     
    20162039            QueryServiceStatus(hService, &Status);
    20172040            if (Status.dwCurrentState == SERVICE_STOPPED)
    2018                 logStringF(hModule, L"VBoxDrv: The service old service was already stopped");
     2041                logStringF(hModule, "VBoxDrv: The service old service was already stopped");
    20192042            else
    20202043            {
    2021                 logStringF(hModule, L"VBoxDrv: Stopping the service (state %u)", Status.dwCurrentState);
     2044                logStringF(hModule, "VBoxDrv: Stopping the service (state %u)", Status.dwCurrentState);
    20222045                if (ControlService(hService, SERVICE_CONTROL_STOP, &Status))
    20232046                {
     
    20312054
    20322055                    if (Status.dwCurrentState == SERVICE_STOPPED)
    2033                         logStringF(hModule, L"VBoxDrv: Stopped service");
     2056                        logStringF(hModule, "VBoxDrv: Stopped service");
    20342057                    else
    2035                         logStringF(hModule, L"VBoxDrv: Failed to stop the service, status: %u", Status.dwCurrentState);
     2058                        logStringF(hModule, "VBoxDrv: Failed to stop the service, status: %u", Status.dwCurrentState);
    20362059                }
    20372060                else
     
    20402063                    if (   Status.dwCurrentState == SERVICE_STOP_PENDING
    20412064                        && dwErr == ERROR_SERVICE_CANNOT_ACCEPT_CTRL)
    2042                         logStringF(hModule, L"VBoxDrv: Failed to stop the service: stop pending, not accepting control messages");
     2065                        logStringF(hModule, "VBoxDrv: Failed to stop the service: stop pending, not accepting control messages");
    20432066                    else
    2044                         logStringF(hModule, L"VBoxDrv: Failed to stop the service: dwErr=%u status=%u", dwErr, Status.dwCurrentState);
     2067                        logStringF(hModule, "VBoxDrv: Failed to stop the service: dwErr=%u status=%u", dwErr, Status.dwCurrentState);
    20452068                }
    20462069            }
     
    20502073             */
    20512074            if (DeleteService(hService))
    2052                 logStringF(hModule, L"VBoxDrv: Successfully delete service");
     2075                logStringF(hModule, "VBoxDrv: Successfully delete service");
    20532076            else
    2054                 logStringF(hModule, L"VBoxDrv: Failed to delete the service: %u", GetLastError());
     2077                logStringF(hModule, "VBoxDrv: Failed to delete the service: %u", GetLastError());
    20552078
    20562079            CloseServiceHandle(hService);
     
    20602083            DWORD const dwErr = GetLastError();
    20612084            if (dwErr == ERROR_SERVICE_DOES_NOT_EXIST)
    2062                 logStringF(hModule, L"VBoxDrv: Nothing to do, the old service does not exist");
     2085                logStringF(hModule, "VBoxDrv: Nothing to do, the old service does not exist");
    20632086            else
    2064                 logStringF(hModule, L"VBoxDrv: Failed to open the service: %u", dwErr);
     2087                logStringF(hModule, "VBoxDrv: Failed to open the service: %u", dwErr);
    20652088        }
    20662089
     
    20682091    }
    20692092    else
    2070         logStringF(hModule, L"VBoxDrv: Failed to open service manager (%u).", GetLastError());
     2093        logStringF(hModule, "VBoxDrv: Failed to open service manager (%u).", GetLastError());
    20712094
    20722095    return ERROR_SUCCESS;
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