VirtualBox

Changeset 38791 in vbox


Ignore:
Timestamp:
Sep 19, 2011 1:21:31 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
74086
Message:

VBoxInstallHelper.cpp,++: Clean up TCHAR/WCHAR mess - just use WCHAR, forget TCHAR.

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp

    r38732 r38791  
    274274}
    275275
     276/** @todo r=bird: This function is not in the header file, why is it
     277 *        exported? */
    276278VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinInstallInfAndComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass,
    277                                                                 IN LPCWSTR * apInfPaths, IN UINT cInfPaths,
     279                                                                IN LPCWSTR const *apInfPaths, IN UINT cInfPaths,
    278280                                                                OUT INetCfgComponent **ppComponent)
    279281{
     
    18581860
    18591861VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltInstall(IN INetCfg *pNc,
    1860                                                        IN LPCWSTR * apInfFullPaths, IN UINT cInfFullPaths)
     1862                                                       IN LPCWSTR const *apInfFullPaths, IN UINT cInfFullPaths)
    18611863{
    18621864    HRESULT hr = vboxNetCfgWinNetFltUninstall(pNc, SUOI_FORCEDELETE);
     
    20562058
    20572059    /* Build the display name in the form "::{GUID}". */
    2058     if (wcslen (wGuid) >= MAX_PATH)
     2060    if (wcslen(wGuid) >= MAX_PATH)
    20592061        return E_INVALIDARG;
    20602062    WCHAR szAdapterGuid[MAX_PATH + 2] = {0};
    2061     swprintf (szAdapterGuid, L"::%ls", wGuid);
     2063    swprintf(szAdapterGuid, L"::%ls", wGuid);
    20622064
    20632065    /* Create an instance of the network connections folder. */
    2064     hr = CoCreateInstance (CLSID_NetworkConnections, NULL,
    2065                            CLSCTX_INPROC_SERVER, IID_IShellFolder,
    2066                            reinterpret_cast <LPVOID *> (&pShellFolder));
     2066    hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
     2067                          CLSCTX_INPROC_SERVER, IID_IShellFolder,
     2068                          reinterpret_cast<LPVOID *>(&pShellFolder));
    20672069    /* Parse the display name. */
    20682070    if (SUCCEEDED (hr))
     
    27092711        if (lppszName)
    27102712        {
    2711             *lppszName = ::SysAllocString((const OLECHAR *) DevName);
     2713            *lppszName = SysAllocString((const OLECHAR *) DevName);
    27122714            if (!*lppszName)
    27132715            {
  • trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp

    r37289 r38791  
    55
    66/*
    7  * Copyright (C) 2008-2010 Oracle Corporation
     7 * Copyright (C) 2008-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
     18
     19/*******************************************************************************
     20*   Header Files                                                               *
     21*******************************************************************************/
    1822#include <windows.h>
    1923#include <tchar.h>
     
    2428
    2529
    26 #if (_MSC_VER < 1400) /* Provide _stprintf_s to VC < 8.0. */
    27 int _stprintf_s(TCHAR *buffer, size_t cbBuffer, const TCHAR *format, ...)
     30#if (_MSC_VER < 1400) /* Provide swprintf_s to VC < 8.0. */
     31int swprintf_s(WCHAR *buffer, size_t cbBuffer, const WCHAR *format, ...)
    2832{
    2933    int ret;
    30     va_list args;
    31     va_start(args, format);
    32     ret = _vsntprintf(buffer, cbBuffer, format, args);
    33     va_end(args);
     34    va_list va;
     35    va_start(va, format);
     36    ret = _vsnwprintf(buffer, cbBuffer, format, va);
     37    va_end(va);
    3438    return ret;
    3539}
    3640#endif
    3741
    38 UINT VBoxGetProperty(MSIHANDLE a_hModule, TCHAR* a_pszName, TCHAR* a_pValue, DWORD a_dwSize)
     42UINT VBoxGetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue, DWORD a_dwSize)
    3943{
    40     UINT uiRet = ERROR_SUCCESS;
    4144    DWORD dwBuffer = 0;
    42 
    43     uiRet = MsiGetProperty(a_hModule, a_pszName, TEXT(""), &dwBuffer);
    44     if (ERROR_MORE_DATA == uiRet)
     45    UINT uiRet = MsiGetPropertyW(a_hModule, a_pwszName, L"", &dwBuffer);
     46    if (uiRet == ERROR_MORE_DATA)
    4547    {
    4648        ++dwBuffer;     /* On output does not include terminating null, so add 1. */
     
    4951            return ERROR_MORE_DATA;
    5052
    51         ZeroMemory(a_pValue, a_dwSize);
    52         uiRet = MsiGetProperty(a_hModule, a_pszName, a_pValue, &dwBuffer);
     53        ZeroMemory(a_pwszValue, a_dwSize);
     54        uiRet = MsiGetPropertyW(a_hModule, a_pwszName, a_pwszValue, &dwBuffer);
    5355    }
    5456    return uiRet;
    5557}
    5658
    57 UINT VBoxSetProperty(MSIHANDLE a_hModule, TCHAR* a_pszName, TCHAR* a_pValue)
     59UINT VBoxSetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue)
    5860{
    59     return MsiSetProperty(a_hModule, a_pszName, a_pValue);
     61    return MsiSetPropertyW(a_hModule, a_pwszName, a_pwszValue);
    6062}
    6163
  • trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.h

    r32112 r38791  
    55
    66/*
    7  * Copyright (C) 2008-2010 Oracle Corporation
     7 * Copyright (C) 2008-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020
    2121#if (_MSC_VER < 1400) /* Provide _stprintf_s to VC < 8.0. */
    22 int _stprintf_s(TCHAR *buffer, size_t cbBuffer, const TCHAR *format, ...);
     22int swprintf_s(WCHAR *buffer, size_t cbBuffer, const WCHAR *format, ...);
    2323#endif
    2424
    25 UINT VBoxGetProperty(MSIHANDLE a_hModule, TCHAR *a_pszName, TCHAR *a_pValue, DWORD a_dwSize);
    26 UINT VBoxSetProperty(MSIHANDLE a_hModule, TCHAR *a_pszName, TCHAR *a_pValue);
     25UINT VBoxGetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue, DWORD a_dwSize);
     26UINT VBoxSetProperty(MSIHANDLE a_hModule, WCHAR *a_pwszName, WCHAR *a_pwszValue);
    2727
    2828#endif /* !___VBoxInstallHelper_Common_h */
  • trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp

    r38740 r38791  
    1616 */
    1717
     18
     19/*******************************************************************************
     20*   Header Files                                                               *
     21*******************************************************************************/
    1822#ifdef VBOX_WITH_NETFLT
    1923# include "VBox/VBoxNetCfg-win.h"
     
    2428
    2529#include <windows.h>
    26 #include <tchar.h>
     30#include <wchar.h>
    2731#include <stdio.h>
    2832
     
    4852#endif
    4953
     54
     55/*******************************************************************************
     56*   Header Files                                                               *
     57*******************************************************************************/
    5058#ifdef DEBUG
    5159# define NonStandardAssert(_expr) assert(_expr)
     
    5462#endif
    5563
     64#define MY_WTEXT_HLP(a_str) L##a_str
     65#define MY_WTEXT(a_str)     MY_WTEXT_HLP(a_str)
     66
     67
    5668BOOL APIENTRY DllMain(HANDLE hModule,
    5769                      DWORD  ul_reason_for_call,
     
    6173}
    6274
    63 static void LogString(MSIHANDLE hInstall, LPCSTR szString, ...)
     75static void logString(MSIHANDLE hInstall, LPCSTR szString, ...)
    6476{
    6577    PMSIHANDLE newHandle = MsiCreateRecord(2);
    6678
    67     char szBuffer[1024] = {0};
    68     va_list pArgList;
    69     va_start(pArgList, szString);
    70     _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(char), szString, pArgList);
    71     va_end(pArgList);
     79    char szBuffer[1024];
     80    va_list va;
     81    va_start(va, szString);
     82    _vsnprintf(szBuffer, sizeof(szBuffer), szString, va);
     83    va_end(va);
    7284
    7385    MsiRecordSetStringA(newHandle, 0, szBuffer);
     
    7587    MsiCloseHandle(newHandle);
    7688
    77 #ifdef DEBUG
     89#if 0/*def DEBUG - wrong? What does '%s' expect, wchar or char? */
    7890    _tprintf(_T("Debug: %s\n"), szBuffer);
    7991#endif
    8092}
    8193
    82 static void LogStringW(MSIHANDLE hInstall, LPCWSTR szString, ...)
     94static void logStringW(MSIHANDLE hInstall, LPCWSTR pwszString, ...)
    8395{
    8496    PMSIHANDLE newHandle = MsiCreateRecord(2);
    8597
    86     TCHAR szBuffer[1024] = {0};
    87     va_list pArgList;
    88     va_start(pArgList, szString);
    89     _vsnwprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), szString, pArgList);
    90     va_end(pArgList);
     98    WCHAR szBuffer[1024];
     99    va_list va;
     100    va_start(va, pwszString);
     101    _vsnwprintf(szBuffer, RT_ELEMENTS(szBuffer), pwszString, va);
     102    va_end(va);
    91103
    92104    MsiRecordSetStringW(newHandle, 0, szBuffer);
     
    112124
    113125DWORD Exec(MSIHANDLE hModule,
    114            const TCHAR *pszAppName, TCHAR *pszCmdLine, const TCHAR *pszWorkDir,
     126           const WCHAR *pwszAppName, WCHAR *pwszCmdLine, const WCHAR *pwszWorkDir,
    115127           DWORD *pdwExitCode)
    116128{
     
    128140    ZeroMemory(&pi, sizeof(pi));
    129141
    130     LogStringW(hModule, TEXT("Executing command line: %s %s (Working Dir: %s)"),
    131                pszAppName, pszCmdLine, pszWorkDir == NULL ? L"Current" : pszWorkDir);
     142    logStringW(hModule, L"Executing command line: %s %s (Working Dir: %s)",
     143               pwszAppName, pwszCmdLine, pwszWorkDir == NULL ? L"Current" : pwszWorkDir);
    132144
    133145    SetLastError(0);
    134     if (!CreateProcess(pszAppName,    /* Module name. */
    135                        pszCmdLine,    /* Command line. */
     146    if (!CreateProcess(pwszAppName,  /* Module name. */
     147                       pwszCmdLine,  /* Command line. */
    136148                       NULL,         /* Process handle not inheritable. */
    137149                       NULL,         /* Thread handle not inheritable. */
     
    139151                       0,            /* No creation flags. */
    140152                       NULL,         /* Use parent's environment block. */
    141                        pszWorkDir,    /* Use parent's starting directory. */
     153                       pwszWorkDir,  /* Use parent's starting directory. */
    142154                       &si,          /* Pointer to STARTUPINFO structure. */
    143155                       &pi))         /* Pointer to PROCESS_INFORMATION structure. */
    144156    {
    145157        rc = GetLastError();
    146         LogStringW(hModule, TEXT("Executing command line: CreateProcess() failed! Error: %ld"), rc);
     158        logStringW(hModule, L"Executing command line: CreateProcess() failed! Error: %ld", rc);
    147159        return rc;
    148160    }
     
    152164    {
    153165        rc = GetLastError();
    154         LogStringW(hModule, TEXT("Executing command line: WaitForSingleObject() failed! Error: %ld"), rc);
     166        logStringW(hModule, L"Executing command line: WaitForSingleObject() failed! Error: %u", rc);
    155167    }
    156168    else
     
    159171        {
    160172            rc = GetLastError();
    161             LogStringW(hModule, TEXT("Executing command line: GetExitCodeProcess() failed! Error: %ld"), rc);
     173            logStringW(hModule, L"Executing command line: GetExitCodeProcess() failed! Error: %u", rc);
    162174        }
    163175    }
     
    167179    CloseHandle(pi.hThread);
    168180
    169     LogStringW(hModule, TEXT("Executing command returned: %ld (exit code %ld)"), rc, *pdwExitCode);
     181    logStringW(hModule, L"Executing command returned: %u (exit code %u)", rc, *pdwExitCode);
    170182    return rc;
    171183}
     
    173185UINT __stdcall InstallPythonAPI(MSIHANDLE hModule)
    174186{
    175     LogStringW(hModule, TEXT("InstallPythonAPI: Checking for installed Python environment ..."));
     187    logStringW(hModule, L"InstallPythonAPI: Checking for installed Python environment ...");
    176188
    177189    HKEY hkPythonCore = NULL;
     
    180192    if (rc != ERROR_SUCCESS)
    181193    {
    182         LogStringW(hModule, TEXT("InstallPythonAPI: Python seems not to be installed."));
     194        logStringW(hModule, L"InstallPythonAPI: Python seems not to be installed.");
    183195        return ERROR_SUCCESS;
    184196    }
    185197
    186     TCHAR szPath[MAX_PATH] = { 0 };
    187     TCHAR szVal[MAX_PATH] = { 0 };
     198    WCHAR wszPath[MAX_PATH] = { 0 };
     199    WCHAR wszVal[MAX_PATH] = { 0 };
    188200
    189201    for (int i = 0;; ++i)
    190202    {
    191         TCHAR szRoot[MAX_PATH] = { 0 };
    192         DWORD dwLen = sizeof (szPath);
     203        WCHAR wszRoot[MAX_PATH] = { 0 };
     204        DWORD dwLen = sizeof(wszPath);
    193205        DWORD dwKeyType = REG_SZ;
    194206
    195         rc = RegEnumKeyEx(hkPythonCore, i, szRoot, &dwLen, NULL, NULL, NULL, NULL);
     207        rc = RegEnumKeyEx(hkPythonCore, i, wszRoot, &dwLen, NULL, NULL, NULL, NULL);
    196208        if (rc != ERROR_SUCCESS || dwLen <= 0)
    197209            break;
    198210
    199         _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\InstallPath", szRoot);
    200         dwLen = sizeof(szVal);
     211        swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\InstallPath", wszRoot);
     212        dwLen = sizeof(wszVal);
    201213
    202214        HKEY hkPythonInstPath = NULL;
    203         rc = RegOpenKeyEx(hkPythonCore, szPath, 0, KEY_READ,  &hkPythonInstPath);
     215        rc = RegOpenKeyEx(hkPythonCore, wszPath, 0, KEY_READ,  &hkPythonInstPath);
    204216        if (rc != ERROR_SUCCESS)
    205217            continue;
    206218
    207         rc = RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)szVal, &dwLen);
     219        rc = RegQueryValueEx(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)wszVal, &dwLen);
    208220        if (rc == ERROR_SUCCESS)
    209             LogStringW(hModule, TEXT("InstallPythonAPI: Path \"%s\" detected."), szVal);
     221            logStringW(hModule, L"InstallPythonAPI: Path \"%s\" detected.", wszVal);
    210222
    211223        RegCloseKey(hkPythonInstPath);
     
    214226
    215227    /* Python path found? */
    216     TCHAR szExec[MAX_PATH] = { 0 };
    217     TCHAR szCmdLine[MAX_PATH] = { 0 };
     228    WCHAR wszExec[MAX_PATH] = { 0 };
     229    WCHAR wszCmdLine[MAX_PATH] = { 0 };
    218230    DWORD dwExitCode = 0;
    219     if (_tcslen(szVal) > 0)
     231    if (wcslen(wszVal) > 0)
    220232    {
    221233        /* Cool, check for installed Win32 extensions. */
    222         LogStringW(hModule, TEXT("InstallPythonAPI: Python installed. Checking for Win32 extensions ..."));
    223         _stprintf_s(szExec, sizeof(szExec) / sizeof(TCHAR), L"%s\\python.exe", szVal);
    224         _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe -c \"import win32api\"", szVal);
    225 
    226         DWORD dwRetExec = Exec(hModule, szExec, szCmdLine, NULL, &dwExitCode);
     234        logStringW(hModule, L"InstallPythonAPI: Python installed. Checking for Win32 extensions ...");
     235        swprintf_s(wszExec, RT_ELEMENTS(wszExec), L"%s\\python.exe", wszVal);
     236        swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe -c \"import win32api\"", wszVal);
     237
     238        DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, NULL, &dwExitCode);
    227239        if (   (ERROR_SUCCESS == dwRetExec)
    228240            && (            0 == dwExitCode))
    229241        {
    230242            /* Did we get the correct error level (=0)? */
    231             LogStringW(hModule, TEXT("InstallPythonAPI: Win32 extensions installed."));
     243            logStringW(hModule, L"InstallPythonAPI: Win32 extensions installed.");
    232244            bFound = TRUE;
    233245        }
    234246        else
    235             LogStringW(hModule, TEXT("InstallPythonAPI: Win32 extensions not found."));
     247            logStringW(hModule, L"InstallPythonAPI: Win32 extensions not found.");
    236248    }
    237249
     
    240252    {
    241253        /* Get the VBoxAPI setup string. */
    242         TCHAR szPathTargetDir[MAX_PATH] = {0};
    243         VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));
    244         if (_tcslen(szPathTargetDir))
     254        WCHAR wszPathTargetDir[MAX_PATH] = {0};
     255        VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
     256        if (wcslen(wszPathTargetDir))
    245257        {
    246258
    247259            /* Set final path. */
    248             _stprintf_s(szPath, sizeof(szPath) / sizeof(TCHAR), L"%s\\sdk\\install", szPathTargetDir);
     260            swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\sdk\\install", wszPathTargetDir);
    249261
    250262            /* Install our API module. */
    251             _stprintf_s(szCmdLine, sizeof(szCmdLine) / sizeof(TCHAR), L"%s\\python.exe vboxapisetup.py install", szVal);
     263            swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe vboxapisetup.py install", wszVal);
    252264
    253265            /* Set required environment variables. */
    254             if (!SetEnvironmentVariable(L"VBOX_INSTALL_PATH", szPathTargetDir))
    255             {
    256                 LogStringW(hModule, TEXT("InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!"));
    257             }
     266            if (!SetEnvironmentVariableW(L"VBOX_INSTALL_PATH", wszPathTargetDir))
     267                logStringW(hModule, L"InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!");
    258268            else
    259269            {
    260                 DWORD dwRetExec = Exec(hModule, szExec, szCmdLine, szPath, &dwExitCode);
     270                DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, wszPath, &dwExitCode);
    261271                if (   (ERROR_SUCCESS == dwRetExec)
    262272                    && (            0 == dwExitCode))
    263273                {
    264274                    /* All done! */
    265                     LogStringW(hModule, TEXT("InstallPythonAPI: VBoxAPI for Python successfully installed."));
     275                    logStringW(hModule, L"InstallPythonAPI: VBoxAPI for Python successfully installed.");
    266276                    bInstalled = TRUE;
    267277                }
     
    269279                {
    270280                    if (dwRetExec)
    271                         LogStringW(hModule, TEXT("InstallPythonAPI: Error while executing installation of VBox API: %ld"), dwRetExec);
     281                        logStringW(hModule, L"InstallPythonAPI: Error while executing installation of VBox API: %ld", dwRetExec);
    272282                    else
    273                         LogStringW(hModule, TEXT("InstallPythonAPI: Python reported an error while installing VBox API: %ld"), dwExitCode);
     283                        logStringW(hModule, L"InstallPythonAPI: Python reported an error while installing VBox API: %ld", dwExitCode);
    274284                }
    275285            }
    276286        }
    277287        else
    278             LogStringW(hModule, TEXT("InstallPythonAPI: Unable to retrieve VBox installation path!"));
     288            logStringW(hModule, L"InstallPythonAPI: Unable to retrieve VBox installation path!");
    279289    }
    280290
     
    282292
    283293    if (!bInstalled)
    284         LogStringW(hModule, TEXT("InstallPythonAPI: VBox API not installed."));
     294        logStringW(hModule, L"InstallPythonAPI: VBox API not installed.");
    285295    return ERROR_SUCCESS; /* Do not fail here. */
    286296}
    287297
    288 static LONG InstallBrandingValue(MSIHANDLE hModule,
    289                                  const TCHAR* pszFileName,
    290                                  const TCHAR* pszSection,
    291                                  const TCHAR* pszValue)
     298static LONG installBrandingValue(MSIHANDLE hModule,
     299                                 const WCHAR *pwszFileName,
     300                                 const WCHAR *pwszSection,
     301                                 const WCHAR *pwszValue)
    292302{
    293303    LONG rc;
    294     TCHAR szValue[_MAX_PATH];
    295     if (GetPrivateProfileString(pszSection, pszValue, NULL,
    296                                 szValue, sizeof(szValue), pszFileName) > 0)
     304    WCHAR wszValue[_MAX_PATH];
     305    if (GetPrivateProfileString(pwszSection, pwszValue, NULL,
     306                                wszValue, sizeof(wszValue), pwszFileName) > 0)
    297307    {
    298308        HKEY hkBranding;
    299         TCHAR szKey[_MAX_PATH];
    300 
    301         if (wcsicmp(L"General", pszSection) != 0)
    302             _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pszSection);
     309        WCHAR wszKey[_MAX_PATH];
     310
     311        if (wcsicmp(L"General", pwszSection) != 0)
     312            swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pwszSection);
    303313        else
    304             _stprintf_s(szKey, sizeof(szKey) / sizeof(TCHAR), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
    305 
    306         rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey,
    307                           0, KEY_WRITE, &hkBranding);
     314            swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
     315
     316        rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wszKey, 0, KEY_WRITE, &hkBranding);
    308317        if (rc == ERROR_SUCCESS)
    309318        {
    310             rc = RegSetValueEx(hkBranding,
    311                                pszValue,
    312                                NULL,
    313                                REG_SZ,
    314                                (BYTE*)szValue,
    315                                (DWORD)wcslen(szValue));
     319            rc = RegSetValueExW(hkBranding,
     320                                pwszValue,
     321                                NULL,
     322                                REG_SZ,
     323                                (BYTE *)wszValue,
     324                                (DWORD)wcslen(wszValue));
    316325            if (rc != ERROR_SUCCESS)
    317                 LogStringW(hModule, TEXT("InstallBranding: Could not write value %s! Error %ld"), pszValue, rc);
     326                logStringW(hModule, L"InstallBranding: Could not write value %s! Error %ld", pwszValue, rc);
    318327            RegCloseKey (hkBranding);
    319328        }
     
    324333}
    325334
    326 UINT CopyDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)
     335UINT CopyDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir)
    327336{
    328337    UINT rc;
    329     TCHAR szDest[_MAX_PATH + 1];
    330     TCHAR szSource[_MAX_PATH + 1];
    331 
    332     _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');
    333     _stprintf_s(szSource, sizeof(szSource) / sizeof(TCHAR), L"%s%c", pszSourceDir, '\0');
     338    WCHAR wszDest[_MAX_PATH + 1];
     339    WCHAR wszSource[_MAX_PATH + 1];
     340
     341    swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0');
     342    swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, '\0');
    334343
    335344    SHFILEOPSTRUCT s = {0};
    336345    s.hwnd = NULL;
    337346    s.wFunc = FO_COPY;
    338     s.pTo = szDest;
    339     s.pFrom = szSource;
     347    s.pTo = wszDest;
     348    s.pFrom = wszSource;
    340349    s.fFlags = FOF_SILENT |
    341350               FOF_NOCONFIRMATION |
     
    343352               FOF_NOERRORUI;
    344353
    345     LogStringW(hModule, TEXT("CopyDir: DestDir=%s, SourceDir=%s"),
    346               szDest, szSource);
     354    logStringW(hModule, L"CopyDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);
    347355    int r = SHFileOperation(&s);
    348356    if (r != 0)
    349357    {
    350         LogStringW(hModule, TEXT("CopyDir: Copy operation returned status 0x%x"), r);
     358        logStringW(hModule, L"CopyDir: Copy operation returned status 0x%x", r);
    351359        rc = ERROR_GEN_FAILURE;
    352360    }
     
    356364}
    357365
    358 UINT RemoveDir(MSIHANDLE hModule, const TCHAR *pszDestDir)
     366UINT RemoveDir(MSIHANDLE hModule, const WCHAR *pwszDestDir)
    359367{
    360368    UINT rc;
    361     TCHAR szDest[_MAX_PATH + 1];
    362 
    363     _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');
    364 
    365     SHFILEOPSTRUCT s = {0};
     369    WCHAR wszDest[_MAX_PATH + 1];
     370
     371    swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0');
     372
     373    SHFILEOPSTRUCTW s = {0};
    366374    s.hwnd = NULL;
    367375    s.wFunc = FO_DELETE;
    368     s.pFrom = szDest;
    369     s.fFlags = FOF_SILENT |
    370                FOF_NOCONFIRMATION |
    371                FOF_NOCONFIRMMKDIR |
    372                FOF_NOERRORUI;
    373 
    374     LogStringW(hModule, TEXT("RemoveDir: DestDir=%s"), szDest);
    375     int r = SHFileOperation(&s);
     376    s.pFrom = wszDest;
     377    s.fFlags = FOF_SILENT
     378             | FOF_NOCONFIRMATION
     379             | FOF_NOCONFIRMMKDIR
     380             | FOF_NOERRORUI;
     381
     382    logStringW(hModule, L"RemoveDir: DestDir=%s", wszDest);
     383    int r = SHFileOperationW(&s);
    376384    if (r != 0)
    377385    {
    378         LogStringW(hModule, TEXT("RemoveDir: Remove operation returned status 0x%x"), r);
     386        logStringW(hModule, L"RemoveDir: Remove operation returned status 0x%x", r);
    379387        rc = ERROR_GEN_FAILURE;
    380388    }
     
    384392}
    385393
    386 UINT RenameDir(MSIHANDLE hModule, const TCHAR *pszDestDir, const TCHAR *pszSourceDir)
     394UINT RenameDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir)
    387395{
    388396    UINT rc;
    389     TCHAR szDest[_MAX_PATH + 1];
    390     TCHAR szSource[_MAX_PATH + 1];
    391 
    392     _stprintf_s(szDest, sizeof(szDest) / sizeof(TCHAR), L"%s%c", pszDestDir, '\0');
    393     _stprintf_s(szSource, sizeof(szSource) / sizeof(TCHAR), L"%s%c", pszSourceDir, '\0');
    394 
    395     SHFILEOPSTRUCT s = {0};
     397    WCHAR wszDest[_MAX_PATH + 1];
     398    WCHAR wszSource[_MAX_PATH + 1];
     399
     400    swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, '\0');
     401    swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, '\0');
     402
     403    SHFILEOPSTRUCTW s = {0};
    396404    s.hwnd = NULL;
    397405    s.wFunc = FO_RENAME;
    398     s.pTo = szDest;
    399     s.pFrom = szSource;
    400     s.fFlags = FOF_SILENT |
    401                FOF_NOCONFIRMATION |
    402                FOF_NOCONFIRMMKDIR |
    403                FOF_NOERRORUI;
    404 
    405     LogStringW(hModule, TEXT("RenameDir: DestDir=%s, SourceDir=%s"),
    406               szDest, szSource);
    407     int r = SHFileOperation(&s);
     406    s.pTo = wszDest;
     407    s.pFrom = wszSource;
     408    s.fFlags = FOF_SILENT
     409             | FOF_NOCONFIRMATION
     410             | FOF_NOCONFIRMMKDIR
     411             | FOF_NOERRORUI;
     412
     413    logStringW(hModule, L"RenameDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);
     414    int r = SHFileOperationW(&s);
    408415    if (r != 0)
    409416    {
    410         LogStringW(hModule, TEXT("RenameDir: Rename operation returned status 0x%x"), r);
     417        logStringW(hModule, L"RenameDir: Rename operation returned status 0x%x", r);
    411418        rc = ERROR_GEN_FAILURE;
    412419    }
     
    419426{
    420427    UINT rc;
    421     LogStringW(hModule, TEXT("UninstallBranding: Handling branding file ..."));
    422 
    423     TCHAR szPathTargetDir[_MAX_PATH];
    424     TCHAR szPathDest[_MAX_PATH];
    425 
    426     rc = VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));
     428    logStringW(hModule, L"UninstallBranding: Handling branding file ...");
     429
     430    WCHAR wszPathTargetDir[_MAX_PATH];
     431    WCHAR wszPathDest[_MAX_PATH];
     432
     433    rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
    427434    if (rc == ERROR_SUCCESS)
    428435    {
    429436        /** @todo Check trailing slash after %s. */
    430         _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom", szPathTargetDir);
    431         rc = RemoveDir(hModule, szPathDest);
     437/** @todo r=bird: using swprintf_s for formatting paths without checking for
     438 * overflow not good.  You're dodging the buffer overflow issue only to end up
     439 * with incorrect behavior!  (Truncated file/dir names)
     440 *
     441 * This applies almost to all swprintf_s calls in this file!!
     442 */
     443        swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir);
     444        rc = RemoveDir(hModule, wszPathDest);
    432445        if (rc != ERROR_SUCCESS)
    433446        {
    434447            /* Check for hidden .custom directory and remove it. */
    435             _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%s.custom", szPathTargetDir);
    436             rc = RemoveDir(hModule, szPathDest);
    437         }
    438     }
    439 
    440     LogStringW(hModule, TEXT("UninstallBranding: Handling done."));
     448            swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s.custom", wszPathTargetDir);
     449            rc = RemoveDir(hModule, wszPathDest);
     450        }
     451    }
     452
     453    logStringW(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc);
    441454    return ERROR_SUCCESS; /* Do not fail here. */
    442455}
     
    445458{
    446459    UINT rc;
    447     LogStringW(hModule, TEXT("InstallBranding: Handling branding file ..."));
    448 
    449     TCHAR szPathMSI[_MAX_PATH];
    450     TCHAR szPathTargetDir[_MAX_PATH];
    451 
    452     TCHAR szPathSource[_MAX_PATH];
    453     TCHAR szPathDest[_MAX_PATH];
    454 
    455     rc = VBoxGetProperty(hModule, L"SOURCEDIR", szPathMSI, sizeof(szPathMSI));
     460    logStringW(hModule, L"InstallBranding: Handling branding file ...");
     461
     462    WCHAR wszPathMSI[_MAX_PATH];
     463    rc = VBoxGetProperty(hModule, L"SOURCEDIR", wszPathMSI, sizeof(wszPathMSI));
    456464    if (rc == ERROR_SUCCESS)
    457465    {
    458         rc = VBoxGetProperty(hModule, L"CustomActionData", szPathTargetDir, sizeof(szPathTargetDir));
     466        WCHAR wszPathTargetDir[_MAX_PATH];
     467        rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
    459468        if (rc == ERROR_SUCCESS)
    460469        {
    461470            /** @todo Check for trailing slash after %s. */
    462             _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%s", szPathTargetDir);
    463             _stprintf_s(szPathSource, sizeof(szPathSource) / sizeof(TCHAR), L"%s.custom", szPathMSI);
    464             rc = CopyDir(hModule, szPathDest, szPathSource);
     471            WCHAR wszPathDest[_MAX_PATH];
     472            swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s", wszPathTargetDir);
     473
     474            WCHAR wszPathSource[_MAX_PATH];
     475            swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathMSI);
     476            rc = CopyDir(hModule, wszPathDest, wszPathSource);
    465477            if (rc == ERROR_SUCCESS)
    466478            {
    467                 _stprintf_s(szPathDest, sizeof(szPathDest) / sizeof(TCHAR), L"%scustom", szPathTargetDir);
    468                 _stprintf_s(szPathSource, sizeof(szPathSource) / sizeof(TCHAR), L"%s.custom", szPathTargetDir);
    469                 rc = RenameDir(hModule, szPathDest, szPathSource);
     479                swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir);
     480                swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathTargetDir);
     481                rc = RenameDir(hModule, wszPathDest, wszPathSource);
    470482            }
    471483        }
    472484    }
    473485
    474     LogStringW(hModule, TEXT("InstallBranding: Handling done."));
     486    logStringW(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc);
    475487    return ERROR_SUCCESS; /* Do not fail here. */
    476488}
     
    491503{
    492504    if (g_hCurrentModule)
    493         LogString(g_hCurrentModule, szString);
     505        logString(g_hCurrentModule, szString);
    494506}
    495507
     
    515527}
    516528
    517 static UINT ErrorConvertFromHResult(MSIHANDLE hModule, HRESULT hr)
     529static UINT errorConvertFromHResult(MSIHANDLE hModule, HRESULT hr)
    518530{
    519531    UINT uRet;
     
    526538        case NETCFG_S_REBOOT:
    527539        {
    528             LogStringW(hModule, TEXT("Reboot required, setting REBOOT property to Force"));
    529             HRESULT hr2 = MsiSetProperty(hModule, TEXT("REBOOT"), TEXT("Force"));
     540            logStringW(hModule, L"Reboot required, setting REBOOT property to Force");
     541            HRESULT hr2 = MsiSetProperty(hModule, L"REBOOT", L"Force");
    530542            if (hr2 != ERROR_SUCCESS)
    531                 LogStringW(hModule, TEXT("Failed to set REBOOT property, error = 0x%x"), hr2);
     543                logStringW(hModule, L"Failed to set REBOOT property, error = 0x%x", hr2);
    532544            uRet = ERROR_SUCCESS; /* Never fail here. */
    533545            break;
     
    535547
    536548        default:
    537             LogStringW(hModule, TEXT("Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE"), hr);
     549            logStringW(hModule, L"Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE", hr);
    538550            uRet = ERROR_GEN_FAILURE;
    539551    }
     
    549561        if (uErr != ERROR_SUCCESS)
    550562        {
    551             LogStringW(hModule, TEXT("createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x"), uErr);
     563            logStringW(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x", uErr);
    552564            MsiCloseHandle(hRecord);
    553565            hRecord = NULL;
     
    555567    }
    556568    else
    557         LogStringW(hModule, TEXT("createNetCfgLockedMsgRecord: Failed to create a record"));
     569        logStringW(hModule, L"createNetCfgLockedMsgRecord: Failed to create a record");
    558570
    559571    return hRecord;
     
    574586        {
    575587            if (FAILED(hr))
    576                 LogStringW(hModule, TEXT("doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x"), hr);
    577             uErr = ErrorConvertFromHResult(hModule, hr);
     588                logStringW(hModule, L"doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x", hr);
     589            uErr = errorConvertFromHResult(hModule, hr);
    578590            break;
    579591        }
     
    583595        if (!lpszLockedBy)
    584596        {
    585             LogStringW(hModule, TEXT("doNetCfgInit: lpszLockedBy == NULL, breaking"));
     597            logStringW(hModule, L"doNetCfgInit: lpszLockedBy == NULL, breaking");
    586598            break;
    587599        }
     
    597609        {
    598610            cRetries++;
    599             LogStringW(hModule, TEXT("doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d"), cRetries, VBOX_NETCFG_MAX_RETRIES);
     611            logStringW(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);
    600612            MsgResult = IDRETRY;
    601613        }
     
    607619                if (!hMsg)
    608620                {
    609                     LogStringW(hModule, TEXT("doNetCfgInit: Failed to create a message record, breaking"));
     621                    logStringW(hModule, L"doNetCfgInit: Failed to create a message record, breaking");
    610622                    CoTaskMemFree(lpszLockedBy);
    611623                    break;
     
    617629            if (rTmp != ERROR_SUCCESS)
    618630            {
    619                 LogStringW(hModule, TEXT("doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x"), rTmp);
     631                logStringW(hModule, L"doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x", rTmp);
    620632                CoTaskMemFree(lpszLockedBy);
    621633                break;
     
    624636            MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg);
    625637            NonStandardAssert(MsgResult == IDRETRY || MsgResult == IDCANCEL);
    626             LogStringW(hModule, TEXT("doNetCfgInit: MsiProcessMessage returned (0x%x)"), MsgResult);
     638            logStringW(hModule, L"doNetCfgInit: MsiProcessMessage returned (0x%x)", MsgResult);
    627639        }
    628640        CoTaskMemFree(lpszLockedBy);
     
    635647}
    636648
    637 static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR *apInfFullPaths, PUINT pcInfs, DWORD dwSize)
    638 {
    639     UINT uErr;
    640     if (*pcInfs >= 2)
    641     {
    642         *pcInfs = 2;
    643 
    644         DWORD dwBuf = dwSize;
    645         uErr = MsiGetPropertyW(hModule, L"CustomActionData", apInfFullPaths[0], &dwBuf);
    646         if (   uErr == ERROR_SUCCESS
    647             && dwBuf)
    648         {
    649             /** @todo r=andy Avoid wcscpy and wcsncat, can cause buffer overruns! */
    650             wcscpy(apInfFullPaths[1], apInfFullPaths[0]);
    651 
    652             wcsncat(apInfFullPaths[0], NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH));
    653             LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: INF 1: %s"), apInfFullPaths[0]);
    654 
    655             wcsncat(apInfFullPaths[1], NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH));
    656             LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: INF 2: %s"), apInfFullPaths[1]);
    657         }
    658         else
    659         {
    660             if (uErr != ERROR_SUCCESS)
    661                 LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x"), uErr);
    662             else
    663                 LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: Empty installation directory"));
    664         }
    665     }
     649static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize)
     650{
     651    DWORD dwBuf = dwSize - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH));
     652    UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &dwBuf);
     653    if (   uErr == ERROR_SUCCESS
     654        && dwBuf)
     655    {
     656        wcscpy(pwszMpInf, pwszPtInf);
     657
     658        wcsncat(pwszPtInf, NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH));
     659        logStringW(hModule, L"vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf);
     660
     661        wcsncat(pwszMpInf, NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH));
     662        logStringW(hModule, L"vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf);
     663    }
     664    else if (uErr != ERROR_SUCCESS)
     665        logStringW(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr);
    666666    else
    667667    {
    668         uErr = ERROR_BUFFER_OVERFLOW;
    669         LogStringW(hModule, TEXT("vboxNetFltQueryInfArray: Buffer array size is < 2 (%u)"), *pcInfs);
     668        logStringW(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");
     669        uErr = ERROR_GEN_FAILURE;
    670670    }
    671671
     
    687687    __try
    688688    {
    689         LogStringW(hModule, TEXT("Uninstalling NetFlt"));
     689        logStringW(hModule, L"Uninstalling NetFlt");
    690690
    691691        uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
     
    694694            HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg);
    695695            if (hr != S_OK)
    696                 LogStringW(hModule, TEXT("UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x"), hr);
    697 
    698             uErr = ErrorConvertFromHResult(hModule, hr);
     696                logStringW(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);
     697
     698            uErr = errorConvertFromHResult(hModule, hr);
    699699
    700700            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
    701701
    702             LogStringW(hModule, TEXT("Uninstalling NetFlt done, error = 0x%x"), uErr);
     702            logStringW(hModule, L"Uninstalling NetFlt done, error = 0x%x", uErr);
    703703
    704704            /* Never fail on uninstall. */
     
    706706        }
    707707        else
    708             LogStringW(hModule, TEXT("UninstallNetFlt: doNetCfgInit failed, error = 0x%x"), uErr);
     708            logStringW(hModule, L"UninstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);
    709709    }
    710710    __finally
     
    736736    {
    737737
    738         LogStringW(hModule, TEXT("Installing NetFlt"));
     738        logStringW(hModule, L"Installing NetFlt");
    739739
    740740        uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
    741741        if (uErr == ERROR_SUCCESS)
    742742        {
    743             WCHAR PtInf[MAX_PATH];
    744             WCHAR MpInf[MAX_PATH];
    745             DWORD sz = sizeof(PtInf);
    746             LPWSTR aInfs[] = {PtInf, MpInf};
    747             UINT cInfs = 2;
    748             uErr = vboxNetFltQueryInfArray(hModule, aInfs, &cInfs, sz);
     743            WCHAR wszPtInf[MAX_PATH];
     744            WCHAR wszMpInf[MAX_PATH];
     745            uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, wszMpInf, sizeof(wszMpInf));
    749746            if (uErr == ERROR_SUCCESS)
    750747            {
    751                 HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, (LPCWSTR*)aInfs, cInfs);
     748                LPCWSTR const apwszInfs[] = { wszPtInf, wszMpInf };
     749                HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, &apwszInfs[0], RT_ELEMENTS(apwszInfs));
    752750                if (FAILED(hr))
    753                     LogStringW(hModule, TEXT("InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x"), hr);
    754 
    755                 uErr = ErrorConvertFromHResult(hModule, hr);
     751                    logStringW(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x", hr);
     752
     753                uErr = errorConvertFromHResult(hModule, hr);
    756754            }
    757755            else
    758                 LogStringW(hModule, TEXT("InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x"), uErr);
     756                logStringW(hModule, L"InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x", uErr);
    759757
    760758            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
    761759
    762             LogStringW(hModule, TEXT("Installing NetFlt done"));
     760            logStringW(hModule, L"Installing NetFlt done");
    763761        }
    764762        else
    765             LogStringW(hModule, TEXT("InstallNetFlt: doNetCfgInit failed, error = 0x%x"), uErr);
     763            logStringW(hModule, L"InstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);
    766764    }
    767765    __finally
     
    822820                if (SUCCEEDED(hr))
    823821                {
    824                     hr = VBoxNetCfgWinRenameConnection (guid, ConnectoinName);
     822                    hr = VBoxNetCfgWinRenameConnection(guid, ConnectoinName);
    825823                    NonStandardAssert(hr == S_OK);
    826824                }
     
    846844    bool bSetStaticIp = true;
    847845
    848     LogStringW(hModule, TEXT("Creating host-only interface"));
     846    logStringW(hModule, L"Creating host-only interface");
    849847
    850848    HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(NETADP_ID);
    851849    if (FAILED(hr))
    852850    {
    853         LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, error = 0x%x"), hr);
     851        logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, error = 0x%x", hr);
    854852        bSetStaticIp = false;
    855853    }
     
    865863        if (cSize)
    866864        {
    867             LogStringW(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property = %s"), MpInf);
     865            logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", MpInf);
    868866            if (MpInf[cSize-1] != L'\\')
    869867            {
     
    878876            bIsFile = true;
    879877
    880             LogStringW(hModule, TEXT("CreateHostOnlyInterface: Resulting INF path = %s"), pInfPath);
     878            logStringW(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pInfPath);
    881879        }
    882880        else
    883             LogStringW(hModule, TEXT("CreateHostOnlyInterface: NetAdpDir property value is empty"));
     881            logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property value is empty");
    884882    }
    885883    else
    886         LogStringW(hModule, TEXT("CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x"), uErr);
     884        logStringW(hModule, L"CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x", uErr);
    887885
    888886    /* Make sure the inf file is installed. */
     
    891889        hr = VBoxDrvCfgInfInstall(pInfPath);
    892890        if (FAILED(hr))
    893             LogStringW(hModule, TEXT("CreateHostOnlyInterface: Failed to install INF file, error = 0x%x"), hr);
     891            logStringW(hModule, L"CreateHostOnlyInterface: Failed to install INF file, error = 0x%x", hr);
    894892    }
    895893
     
    903901            hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
    904902            if (FAILED(hr))
    905                 LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x"), hr);
     903                logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr);
    906904        }
    907905        else
    908             LogStringW(hModule, TEXT("CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x"), hr);
     906            logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr);
    909907    }
    910908
    911909    if (SUCCEEDED(hr))
    912         LogStringW(hModule, TEXT("Creating host-only interface done"));
     910        logStringW(hModule, L"Creating host-only interface done");
    913911
    914912    /* Restore original setup mode. */
     
    929927    netCfgLoggerEnable(hModule);
    930928
    931     LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: Removing All Host-Only Interface"));
     929    logStringW(hModule, L"RemoveHostOnlyInterfaces: Removing All Host-Only Interface");
    932930
    933931    BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
     
    939937        if (FAILED(hr))
    940938        {
    941             LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs\n"));
     939            logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs\n");
    942940        }
    943941    }
    944942    else
    945         LogStringW(hModule, TEXT("RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x\n"), hr);
     943        logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x\n", hr);
    946944
    947945    /* Restore original setup mode. */
     
    956954}
    957955
    958 static bool IsTAPDevice(const TCHAR *pcGUID)
     956static bool isTAPDevice(const WCHAR *pwszGUID)
    959957{
    960958    HKEY hNetcard;
    961959    bool bIsTapDevice = false;
    962     LONG lStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    963                                 TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"),
    964                                 0, KEY_READ, &hNetcard);
     960    LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
     961                                 L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",
     962                                 0, KEY_READ, &hNetcard);
    965963    if (lStatus != ERROR_SUCCESS)
    966964        return false;
    967965
    968966    int i = 0;
    969     while (true)
    970     {
    971         TCHAR szEnumName[256];
    972         TCHAR szNetCfgInstanceId[256];
     967    for (;;)
     968    {
     969        WCHAR wszEnumName[256];
     970        WCHAR wszNetCfgInstanceId[256];
    973971        DWORD dwKeyType;
    974972        HKEY  hNetCardGUID;
    975973
    976         DWORD dwLen = sizeof(szEnumName);
    977         lStatus = RegEnumKeyEx(hNetcard, i, szEnumName, &dwLen, NULL, NULL, NULL, NULL);
     974        DWORD dwLen = sizeof(wszEnumName);
     975        lStatus = RegEnumKeyEx(hNetcard, i, wszEnumName, &dwLen, NULL, NULL, NULL, NULL);
    978976        if (lStatus != ERROR_SUCCESS)
    979977            break;
    980978
    981         lStatus = RegOpenKeyEx(hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);
     979        lStatus = RegOpenKeyEx(hNetcard, wszEnumName, 0, KEY_READ, &hNetCardGUID);
    982980        if (lStatus == ERROR_SUCCESS)
    983981        {
    984             dwLen = sizeof(szNetCfgInstanceId);
    985             lStatus = RegQueryValueEx(hNetCardGUID, TEXT("NetCfgInstanceId"), NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &dwLen);
     982            dwLen = sizeof(wszNetCfgInstanceId);
     983            lStatus = RegQueryValueExW(hNetCardGUID, L"NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)wszNetCfgInstanceId, &dwLen);
    986984            if (   lStatus == ERROR_SUCCESS
    987985                && dwKeyType == REG_SZ)
    988986            {
    989                 TCHAR szNetProductName[256];
    990                 TCHAR szNetProviderName[256];
    991 
    992                 szNetProductName[0] = 0;
    993                 dwLen = sizeof(szNetProductName);
    994                 lStatus = RegQueryValueEx(hNetCardGUID, TEXT("ProductName"), NULL, &dwKeyType, (LPBYTE)szNetProductName, &dwLen);
    995 
    996                 szNetProviderName[0] = 0;
    997                 dwLen = sizeof(szNetProviderName);
    998                 lStatus = RegQueryValueEx(hNetCardGUID, TEXT("ProviderName"), NULL, &dwKeyType, (LPBYTE)szNetProviderName, &dwLen);
    999 
    1000                 if (   !wcscmp(szNetCfgInstanceId, pcGUID)
    1001                     && !wcscmp(szNetProductName, TEXT("VirtualBox TAP Adapter"))
    1002                     && (   (!wcscmp(szNetProviderName, TEXT("innotek GmbH"))) /* Legacy stuff. */
    1003                         || (!wcscmp(szNetProviderName, TEXT("Sun Microsystems, Inc."))) /* Legacy stuff. */
    1004                         || (!wcscmp(szNetProviderName, TEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
     987                WCHAR wszNetProductName[256];
     988                WCHAR wszNetProviderName[256];
     989
     990                wszNetProductName[0] = 0;
     991                dwLen = sizeof(wszNetProductName);
     992                lStatus = RegQueryValueExW(hNetCardGUID, L"ProductName", NULL, &dwKeyType, (LPBYTE)wszNetProductName, &dwLen);
     993
     994                wszNetProviderName[0] = 0;
     995                dwLen = sizeof(wszNetProviderName);
     996                lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen);
     997
     998                if (   !wcscmp(wszNetCfgInstanceId, pwszGUID)
     999                    && !wcscmp(wszNetProductName, L"VirtualBox TAP Adapter")
     1000                    && (   (!wcscmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */
     1001                        || (!wcscmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */
     1002                        || (!wcscmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
    10051003                       )
    10061004                   )
     
    10161014    }
    10171015
    1018     RegCloseKey (hNetcard);
     1016    RegCloseKey(hNetcard);
    10191017    return bIsTapDevice;
    10201018}
    1021 
    1022 #define VBOX_TAP_HWID _T("vboxtap")
    10231019
    10241020#define SetErrBreak(strAndArgs) \
    10251021    if (1) { \
    10261022        rc = 0; \
    1027         LogStringW(hModule, strAndArgs); \
     1023        logStringW(hModule, strAndArgs); \
    10281024        break; \
    10291025    } else do {} while (0)
    10301026
    1031 int removeNetworkInterface(MSIHANDLE hModule, const TCHAR* pcGUID)
     1027int removeNetworkInterface(MSIHANDLE hModule, const WCHAR *pwszGUID)
    10321028{
    10331029    int rc = 1;
    10341030    do
    10351031    {
    1036         TCHAR lszPnPInstanceId [512] = {0};
     1032        WCHAR wszPnPInstanceId[512] = {0};
    10371033
    10381034        /* We have to find the device instance ID through a registry search */
     
    10411037        HKEY hkeyConnection = 0;
    10421038
    1043         do
    1044         {
    1045             TCHAR strRegLocation [256];
    1046             swprintf (strRegLocation,
    1047                       TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")
    1048                       TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s"),
    1049                       pcGUID);
    1050             LONG lStatus;
    1051             lStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strRegLocation, 0,
    1052                                    KEY_READ, &hkeyNetwork);
     1039        do /* break-loop */
     1040        {
     1041            WCHAR wszRegLocation[256];
     1042            swprintf(wszRegLocation,
     1043                     L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
     1044                     pwszGUID);
     1045            LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork);
    10531046            if ((lStatus != ERROR_SUCCESS) || !hkeyNetwork)
    1054                 SetErrBreak((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]"), strRegLocation));
    1055 
    1056             lStatus = RegOpenKeyExA(hkeyNetwork, "Connection", 0,
    1057                                     KEY_READ, &hkeyConnection);
     1047                SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]", wszRegLocation));
     1048
     1049            lStatus = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection);
    10581050            if ((lStatus != ERROR_SUCCESS) || !hkeyConnection)
    1059                 SetErrBreak((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]"), strRegLocation));
    1060 
    1061             DWORD len = sizeof (lszPnPInstanceId);
     1051                SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]", wszRegLocation));
     1052
     1053            DWORD len = sizeof(wszPnPInstanceId);
    10621054            DWORD dwKeyType;
    10631055            lStatus = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL,
    1064                                        &dwKeyType, (LPBYTE) lszPnPInstanceId, &len);
     1056                                       &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len);
    10651057            if ((lStatus != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
    1066                 SetErrBreak((TEXT("VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]"), strRegLocation));
     1058                SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]", wszRegLocation));
    10671059        }
    10681060        while (0);
     
    10991091            if (hDeviceInfo == INVALID_HANDLE_VALUE)
    11001092            {
    1101                 LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!"), GetLastError());
    1102                 SetErrBreak(TEXT("VBox HostInterfaces: Uninstallation failed!"));
     1093                logStringW(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError());
     1094                SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
    11031095            }
    11041096
     
    11081100            while (TRUE)
    11091101            {
    1110                 TCHAR *pszDeviceHwid;
     1102                WCHAR *pwszDeviceHwid;
    11111103
    11121104                fResult = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData);
     
    11381130                    }
    11391131
    1140                     pszDeviceHwid = (TCHAR *)malloc(size);
    1141                     if (pszDeviceHwid)
     1132                    pwszDeviceHwid = (WCHAR *)malloc(size);
     1133                    if (pwszDeviceHwid)
    11421134                    {
    11431135                        fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
     
    11451137                                                                   SPDRP_HARDWAREID,
    11461138                                                                   NULL,
    1147                                                                    (PBYTE)pszDeviceHwid,
     1139                                                                   (PBYTE)pwszDeviceHwid,
    11481140                                                                   size,
    11491141                                                                   NULL);
    11501142                        if (!fResult)
    11511143                        {
    1152                             free(pszDeviceHwid);
    1153                             pszDeviceHwid = NULL;
     1144                            free(pwszDeviceHwid);
     1145                            pwszDeviceHwid = NULL;
    11541146                            index++;
    11551147                            continue;
     
    11641156                }
    11651157
    1166                 for (TCHAR *t = pszDeviceHwid;
    1167                      t && *t && t < &pszDeviceHwid[size / sizeof(TCHAR)];
    1168                      t += _tcslen (t) + 1)
     1158                for (WCHAR *t = pwszDeviceHwid;
     1159                     t && *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)];
     1160                     t += wcslen(t) + 1)
    11691161                {
    1170                     if (!_tcsicmp(VBOX_TAP_HWID, t))
     1162                    if (!_wcsicmp(L"vboxtap", t))
    11711163                    {
    11721164                          /* get the device instance ID */
    1173                           TCHAR devID [MAX_DEVICE_ID_LEN];
     1165                          WCHAR wszDevID[MAX_DEVICE_ID_LEN];
    11741166                          if (CM_Get_Device_ID(DeviceInfoData.DevInst,
    1175                                                devID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
     1167                                               wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
    11761168                          {
    11771169                              /* compare to what we determined before */
    1178                               if (!wcscmp(devID, lszPnPInstanceId))
     1170                              if (!wcscmp(wszDevID, wszPnPInstanceId))
    11791171                              {
    11801172                                  fFoundDevice = TRUE;
     
    11851177                }
    11861178
    1187                 if (pszDeviceHwid)
     1179                if (pwszDeviceHwid)
    11881180                {
    1189                     free(pszDeviceHwid);
    1190                     pszDeviceHwid = NULL;
     1181                    free(pwszDeviceHwid);
     1182                    pwszDeviceHwid = NULL;
    11911183                }
    11921184
     
    12021194                if (!fResult)
    12031195                {
    1204                     LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!"), GetLastError());
    1205                     SetErrBreak(TEXT("VBox HostInterfaces: Uninstallation failed!"));
     1196                    logStringW(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());
     1197                    SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
    12061198                }
    12071199
     
    12091201                if (!fResult)
    12101202                {
    1211                     LogStringW(hModule, TEXT("VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!"), GetLastError());
    1212                     SetErrBreak(TEXT("VBox HostInterfaces: Uninstallation failed!"));
     1203                    logStringW(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());
     1204                    SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
    12131205                }
    12141206            }
    12151207            else
    1216                 SetErrBreak(TEXT("VBox HostInterfaces: Host interface network device not found!"));
     1208                SetErrBreak(L"VBox HostInterfaces: Host interface network device not found!");
    12171209        }
    12181210        while (0);
     
    12281220UINT __stdcall UninstallTAPInstances(MSIHANDLE hModule)
    12291221{
    1230     static const TCHAR *NetworkKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")
    1231                                      TEXT("{4D36E972-E325-11CE-BFC1-08002BE10318}");
     1222    static const WCHAR *s_wszNetworkKey = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
    12321223    HKEY hCtrlNet;
    12331224
    1234     LONG lStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NetworkKey, 0, KEY_READ, &hCtrlNet);
     1225    LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet);
    12351226    if (lStatus == ERROR_SUCCESS)
    12361227    {
    1237         LogStringW(hModule, TEXT("VBox HostInterfaces: Enumerating interfaces ..."));
    1238         for (int i = 0;; ++ i)
    1239         {
    1240             TCHAR szNetworkGUID [256] = { 0 };
    1241             TCHAR szNetworkConnection [256] = { 0 };
    1242 
    1243             DWORD dwLen = (DWORD)sizeof(szNetworkGUID);
    1244             lStatus = RegEnumKeyEx(hCtrlNet, i, szNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);
     1228        logStringW(hModule, L"VBox HostInterfaces: Enumerating interfaces ...");
     1229        for (int i = 0; ; ++i)
     1230        {
     1231            WCHAR wszNetworkGUID[256] = { 0 };
     1232            DWORD dwLen = (DWORD)sizeof(wszNetworkGUID);
     1233            lStatus = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);
    12451234            if (lStatus != ERROR_SUCCESS)
    12461235            {
    12471236                switch (lStatus)
    12481237                {
    1249                 case ERROR_NO_MORE_ITEMS:
    1250                     LogStringW(hModule, TEXT("VBox HostInterfaces: No interfaces found."));
    1251                     break;
    1252                 default:
    1253                     LogStringW(hModule, TEXT("VBox HostInterfaces: Enumeration failed: %ld"), lStatus);
    1254                     break;
    1255                 };
     1238                    case ERROR_NO_MORE_ITEMS:
     1239                        logStringW(hModule, L"VBox HostInterfaces: No interfaces found.");
     1240                        break;
     1241                    default:
     1242                        logStringW(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus);
     1243                        break;
     1244                }
    12561245                break;
    12571246            }
    12581247
    1259             if (IsTAPDevice(szNetworkGUID))
     1248            if (isTAPDevice(wszNetworkGUID))
    12601249            {
    1261                 LogStringW(hModule, TEXT("VBox HostInterfaces: Removing interface \"%s\" ..."), szNetworkGUID);
    1262                 removeNetworkInterface (hModule, szNetworkGUID);
    1263                 lStatus = RegDeleteKey (hCtrlNet, szNetworkGUID);
     1250                logStringW(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID);
     1251                removeNetworkInterface(hModule, wszNetworkGUID);
     1252                lStatus = RegDeleteKeyW(hCtrlNet, wszNetworkGUID);
    12641253            }
    12651254        }
    1266         RegCloseKey (hCtrlNet);
    1267         LogStringW(hModule, TEXT("VBox HostInterfaces: Removing interfaces done."));
     1255        RegCloseKey(hCtrlNet);
     1256        logStringW(hModule, L"VBox HostInterfaces: Removing interfaces done.");
    12681257    }
    12691258    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