VirtualBox

Changeset 96449 in vbox


Ignore:
Timestamp:
Aug 23, 2022 11:55:38 PM (2 years ago)
Author:
vboxsync
Message:

Add/NT/Inst: Factored out the no-CRT output and error messaging routines and used them in VBoxWindowsAdditions.cpp as well. bugref:10261

Location:
trunk/src/VBox/Additions/WINNT
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Installer/Loader/Makefile.kmk

    r96407 r96449  
    2929include $(KBUILD_PATH)/subheader.kmk
    3030
    31 ifeq ($(KBUILD_TARGET_ARCH),x86)
    32 
    33 # This has to be 32-bit, so don't include it in the 64-bit build.
    34 PROGRAMS.x86 += VBoxWindowsAdditions
     31# This has to be 32-bit.
     32PROGRAMS += VBoxWindowsAdditions
    3533VBoxWindowsAdditions_TEMPLATE= VBoxGuestR3Exe
    36 VBoxWindowsAdditions_DEFS    = _WIN32_WINNT=0x0400 _UNICODE UNICODE
     34VBoxWindowsAdditions_BLD_TRG_ARCH = x86
     35VBoxWindowsAdditions_DEFS    = _WIN32_WINNT=0x0400
     36VBoxWindowsAdditions_INCS    = ../../include
    3737VBoxWindowsAdditions_SOURCES = \
    3838        VBoxWindowsAdditions.cpp \
    3939        VBoxWindowsAdditions.rc
    40 
     40ifdef VBOX_WITH_NOCRT_STATIC
     41VBoxWindowsAdditions_LDFLAGS  = /SubSystem:Windows
     42else
    4143VBoxWindowsAdditions_LDFLAGS  = \
    4244        /DISALLOWLIB:msvcrt.lib \
    4345        /DISALLOWLIB:msvcprt.lib \
    4446        /DISALLOWLIB:libcmt.lib
    45 
    4647VBoxWindowsAdditions_LIBS     = \
    4748        $(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.$(KBUILD_TARGET_ARCH))_LIB)/oldnames.lib \
    4849        $(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.$(KBUILD_TARGET_ARCH))_LIB)/libcmt.lib \
    4950        $(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.$(KBUILD_TARGET_ARCH))_LIB)/libcpmt.lib
     51endif
    5052
    5153# Version stuff.
     
    6567        $(APPEND) $@ 'IDI_VIRTUALBOX ICON DISCARDABLE "$(subst /,\\,$(VBOX_WINDOWS_ADDITIONS_ICON_FILE))"'
    6668
    67 endif # (x86 only because of the above rule)
    68 
    6969
    7070include $(FILE_KBUILD_SUB_FOOTER)
  • trunk/src/VBox/Additions/WINNT/Installer/Loader/VBoxWindowsAdditions.cpp

    r96407 r96449  
    3838#endif
    3939
    40 #include <stdio.h>
    41 #include <string.h>
     40#include <iprt/string.h>
     41#include <iprt/utf16.h>
     42
     43#include "NoCrtOutput.h"
    4244
    4345
     
    4648    BOOL fIsWow64 = FALSE;
    4749    typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
    48     LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(L"kernel32"), "IsWow64Process");
     50    LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandleW(L"kernel32"), "IsWow64Process");
    4951    if (fnIsWow64Process != NULL)
    5052    {
    5153        if (!fnIsWow64Process(GetCurrentProcess(), &fIsWow64))
    5254        {
    53             fwprintf(stderr, L"ERROR: Could not determine process type!\n");
     55            ErrorMsgLastErr("Unable to determine the process type!");
    5456
    5557            /* Error in retrieving process type - assume that we're running on 32bit. */
     
    6062}
    6163
    62 static void WaitForProcess2(HANDLE hProcess, int *piExitCode)
     64static int WaitForProcess2(HANDLE hProcess)
    6365{
    6466    /*
     
    8183            && dwRc != WAIT_OBJECT_0 + 1)
    8284        {
    83             fwprintf(stderr, L"ERROR: MsgWaitForMultipleObjects failed: %lu (%lu)\n", dwRc, GetLastError());
     85            ErrorMsgLastErrSUR("MsgWaitForMultipleObjects failed: ", dwRc);
    8486            break;
    8587        }
     
    9193    DWORD dwExitCode;
    9294    if (GetExitCodeProcess(hProcess, &dwExitCode))
    93         *piExitCode = (int)dwExitCode;
    94     else
    95     {
    96         fwprintf(stderr, L"ERROR: GetExitCodeProcess failed: %lu\n", GetLastError());
    97         *piExitCode = 16;
    98     }
    99 }
    100 
    101 static void WaitForProcess(HANDLE hProcess, int *piExitCode)
     95        return (int)dwExitCode;
     96    return ErrorMsgRcLastErr(16, "GetExitCodeProcess failed");
     97}
     98
     99static int WaitForProcess(HANDLE hProcess)
    102100{
    103101    DWORD WaitRc = WaitForSingleObjectEx(hProcess, INFINITE, TRUE);
     
    109107        DWORD dwExitCode;
    110108        if (GetExitCodeProcess(hProcess, &dwExitCode))
    111             *piExitCode = (int)dwExitCode;
    112         else
    113         {
    114             fwprintf(stderr, L"ERROR: GetExitCodeProcess failed: %lu\n", GetLastError());
    115             *piExitCode = 16;
    116         }
    117     }
    118     else
    119     {
    120         fwprintf(stderr, L"ERROR: WaitForSingleObjectEx failed: %lu (%lu)\n", WaitRc, GetLastError());
    121         *piExitCode = 16;
    122     }
    123 }
    124 
     109            return (int)dwExitCode;
     110        return ErrorMsgRcLastErr(16, "GetExitCodeProcess failed");
     111    }
     112    return ErrorMsgRcLastErrSUR(16, "MsgWaitForMultipleObjects failed: ", WaitRc);
     113}
     114
     115#ifndef IPRT_NO_CRT
    125116int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    126 {
     117#else
     118int main()
     119#endif
     120{
     121#ifndef IPRT_NO_CRT
    127122    RT_NOREF(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
     123#endif
    128124
    129125    /*
    130126     * Gather the parameters of the real installer program.
    131127     */
    132 
    133128    SetLastError(NO_ERROR);
    134     WCHAR wszCurDir[_MAX_PATH] = { 0 };
    135     DWORD cchCurDir = GetCurrentDirectoryW(sizeof(wszCurDir), wszCurDir);
    136     if (cchCurDir == 0 || cchCurDir >= sizeof(wszCurDir))
    137     {
    138         fwprintf(stderr, L"ERROR: GetCurrentDirectoryW failed: %lu (ret %lu)\n", GetLastError(), cchCurDir);
    139         return 12;
    140     }
     129    WCHAR wszCurDir[MAX_PATH] = { 0 };
     130    DWORD cwcCurDir = GetCurrentDirectoryW(sizeof(wszCurDir), wszCurDir);
     131    if (cwcCurDir == 0 || cwcCurDir >= sizeof(wszCurDir))
     132        return ErrorMsgRcLastErrSUR(12, "GetCurrentDirectoryW failed: ", cwcCurDir);
    141133
    142134    SetLastError(NO_ERROR);
    143     WCHAR wszModule[_MAX_PATH] = { 0 };
    144     DWORD cchModule = GetModuleFileNameW(NULL, wszModule, sizeof(wszModule));
    145     if (cchModule == 0 || cchModule >= sizeof(wszModule))
    146     {
    147         fwprintf(stderr, L"ERROR: GetModuleFileNameW failed: %lu (ret %lu)\n", GetLastError(), cchModule);
    148         return 13;
    149     }
    150 
    151     /* Strip the extension off the module name and construct the arch specific
    152        one of the real installer program. */
    153     DWORD off = cchModule - 1;
     135    WCHAR wszExePath[MAX_PATH] = { 0 };
     136    DWORD cwcExePath = GetModuleFileNameW(NULL, wszExePath, sizeof(wszExePath));
     137    if (cwcExePath == 0 || cwcExePath >= sizeof(wszExePath))
     138        return ErrorMsgRcLastErrSUR(13, "GetModuleFileNameW failed: ", cwcExePath);
     139
     140    /*
     141    * Strip the extension off the module name and construct the arch specific
     142    * one of the real installer program.
     143    */
     144    DWORD off = cwcExePath - 1;
    154145    while (   off > 0
    155            && (   wszModule[off] != '/'
    156                && wszModule[off] != '\\'
    157                && wszModule[off] != ':'))
    158     {
    159         if (wszModule[off] == '.')
    160         {
    161             wszModule[off] = '\0';
    162             cchModule = off;
     146           && (   wszExePath[off] != '/'
     147               && wszExePath[off] != '\\'
     148               && wszExePath[off] != ':'))
     149    {
     150        if (wszExePath[off] == '.')
     151        {
     152            wszExePath[off] = '\0';
     153            cwcExePath = off;
    163154            break;
    164155        }
     
    167158
    168159    WCHAR const  *pwszSuff = IsWow64() ? L"-amd64.exe" : L"-x86.exe";
    169     size_t        cchSuff  = wcslen(pwszSuff);
    170     if (cchSuff + cchModule >= sizeof(wszModule))
    171     {
    172         fwprintf(stderr, L"ERROR: Real installer name is too long (%u chars)\n", (unsigned)(cchSuff + cchModule));
    173         return 14;
    174     }
    175     wcscpy(&wszModule[cchModule], pwszSuff);
    176     cchModule += cchSuff;
    177 
    178     /* Replace the first argument of the argument list. */
     160    int rc = RTUtf16Copy(&wszExePath[cwcExePath], RT_ELEMENTS(wszExePath) - cwcExePath, pwszSuff);
     161    if (RT_FAILURE(rc))
     162        return ErrorMsgRc(14, "Real installer name is too long!");
     163    cwcExePath += RTUtf16Len(&wszExePath[cwcExePath]);
     164
     165    /*
     166     * Replace the first argument of the argument list.
     167     */
    179168    PWCHAR  pwszNewCmdLine = NULL;
    180169    LPCWSTR pwszOrgCmdLine = GetCommandLineW();
     
    209198            pwszOrgCmdLine++;
    210199
    211         /* Join up "szModule" with the remainder of the original command line. */
    212         size_t cchOrgCmdLine = wcslen(pwszOrgCmdLine);
    213         size_t cchNewCmdLine = 1 + cchModule + 1 + 1 + cchOrgCmdLine + 1;
    214         PWCHAR pwsz = pwszNewCmdLine = (PWCHAR)LocalAlloc(LPTR, cchNewCmdLine * sizeof(WCHAR));
     200        /* Join up "wszExePath" with the remainder of the original command line. */
     201        size_t cwcOrgCmdLine = RTUtf16Len(pwszOrgCmdLine);
     202        size_t cwcNewCmdLine = 1 + cwcExePath + 1 + 1 + cwcOrgCmdLine + 1;
     203        PWCHAR pwsz = pwszNewCmdLine = (PWCHAR)LocalAlloc(LPTR, cwcNewCmdLine * sizeof(WCHAR));
    215204        if (!pwsz)
    216         {
    217             fwprintf(stderr, L"ERROR: Out of memory (%u bytes)\n", (unsigned)cchNewCmdLine);
    218             return 15;
    219         }
     205            return ErrorMsgRcSUS(15, "Out of memory (", cwcNewCmdLine * sizeof(WCHAR), " bytes)");
    220206        *pwsz++ = L'"';
    221         wcscpy(pwsz, wszModule);
    222         pwsz += cchModule;
     207        memcpy(pwsz, wszExePath, cwcExePath * sizeof(pwsz[0]));
     208        pwsz += cwcExePath;
    223209        *pwsz++ = L'"';
    224         if (cchOrgCmdLine)
     210        if (cwcOrgCmdLine)
    225211        {
    226212            *pwsz++ = L' ';
    227             wcscpy(pwsz, pwszOrgCmdLine);
     213            memcpy(pwsz, pwszOrgCmdLine, cwcOrgCmdLine * sizeof(pwsz[0]));
    228214        }
    229215        else
     
    237223     * Start the process.
    238224     */
    239     int iRet = 0;
     225    int                 rcExit      = 0;
    240226    STARTUPINFOW        StartupInfo = { sizeof(StartupInfo), 0 };
    241     PROCESS_INFORMATION ProcInfo = { 0 };
     227    PROCESS_INFORMATION ProcInfo    = { 0 };
    242228    SetLastError(740);
    243     BOOL fOk = CreateProcessW(wszModule,
     229    BOOL fOk = CreateProcessW(wszExePath,
    244230                              pwszNewCmdLine,
    245231                              NULL /*pProcessAttributes*/,
     
    255241        /* Wait for the process to finish. */
    256242        CloseHandle(ProcInfo.hThread);
    257         WaitForProcess(ProcInfo.hProcess, &iRet);
     243        rcExit = WaitForProcess(ProcInfo.hProcess);
    258244        CloseHandle(ProcInfo.hProcess);
    259245    }
     
    273259        ShExecInfo.hwnd         = NULL;
    274260        ShExecInfo.lpVerb       = L"runas" ;
    275         ShExecInfo.lpFile       = wszModule;
     261        ShExecInfo.lpFile       = wszExePath;
    276262        ShExecInfo.lpParameters = pwszOrgCmdLine; /* pass only args here!!! */
    277263        ShExecInfo.lpDirectory  = wszCurDir;
     
    282268            if (ShExecInfo.hProcess != INVALID_HANDLE_VALUE)
    283269            {
    284                 WaitForProcess2(ShExecInfo.hProcess, &iRet);
     270                rcExit = WaitForProcess2(ShExecInfo.hProcess);
    285271                CloseHandle(ShExecInfo.hProcess);
    286272            }
    287273            else
    288             {
    289                 fwprintf(stderr, L"ERROR: ShellExecuteExW did not return a valid process handle!\n");
    290                 iRet = 1;
    291             }
     274                rcExit = ErrorMsgRc(1, "ShellExecuteExW did not return a valid process handle!");
    292275        }
    293276        else
    294         {
    295             fwprintf(stderr, L"ERROR: Failed to execute '%ws' via ShellExecuteExW: %lu\n", wszModule, GetLastError());
    296             iRet = 9;
    297         }
     277            rcExit = ErrorMsgRcLastErrSWSR(9, "Failed to execute '", wszExePath, "' via ShellExecuteExW!");
    298278    }
    299279    else
    300     {
    301         fwprintf(stderr, L"ERROR: Failed to execute '%ws' via CreateProcessW: %lu\n", wszModule, GetLastError());
    302         iRet = 8;
    303     }
     280        rcExit = ErrorMsgRcLastErrSWSR(8, "Failed to execute '", wszExePath, "' via CreateProcessW!");
    304281
    305282    if (pwszNewCmdLine)
    306283        LocalFree(pwszNewCmdLine);
    307284
    308 #if 0
    309     fwprintf(stderr, L"DEBUG: iRet=%d\n", iRet);
    310     fflush(stderr);
    311 #endif
    312     return iRet;
    313 }
    314 
     285    return rcExit;
     286}
     287
  • trunk/src/VBox/Additions/WINNT/Installer/Makefile.kmk

    r96443 r96449  
    5050VBoxDrvInst_DEPS    = $(VBOX_SVN_REV_KMK)
    5151VBoxDrvInst_SDKS    = ReorderCompilerIncs $(VBOX_WINPSDK_GST) $(VBOX_WINDDK_GST) VBOX_WIN_NEWDEV
     52VBoxDrvInst_INCS    = ../include
    5253VBoxDrvInst_LIBS    = \
    5354        $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/setupapi.lib
     
    380381PROGRAMS.win.x86 += VBoxAddInstallNt3x
    381382ifdef VBOX_WITH_NOCRT_STATIC
     383## @todo noCRT: the result is much too big. Got rid of log.cpp, but still pretty big. Work on reducing it.
    382384VBoxAddInstallNt3x_TEMPLATE := VBoxGuestR3Exe
    383385else
    384386VBoxAddInstallNt3x_TEMPLATE := VBoxGuestR3NoCrtExe
    385387endif
     388VBoxAddInstallNt3x_LDFLAGS  := /VERBOSE
    386389VBoxAddInstallNt3x_SOURCES  := \
    387390        VBoxAddInstallNt3x.cpp \
  • trunk/src/VBox/Additions/WINNT/Installer/VBoxDrvInst.cpp

    r96437 r96449  
    4646#include <iprt/utf16.h>
    4747
    48 
    49 /*********************************************************************************************************************************
    50 *   Defines                                                                                                                      *
    51 *********************************************************************************************************************************/
    5248/* Exit codes */
    5349#define EXIT_OK      (0)
     
    5652#define EXIT_USAGE   (3)
    5753
     54/* Must include after EXIT_FAIL was defined! Sorry for the mixing up of thing. */
     55#include "NoCrtOutput.h"
     56
     57
     58/*********************************************************************************************************************************
     59*   Defines                                                                                                                      *
     60*********************************************************************************************************************************/
    5861/* Defines */
    5962#define DRIVER_PACKAGE_REPAIR                   0x00000001
     
    113116
    114117
    115 /** @name Output helpers
    116  *
    117  * The general ASSUMPTION here is that all strings are restricted to 7-bit
    118  * ASCII, with the exception of wchar_t ones.
    119  *
    120  * @note We don't use printf, RTPrintf or similar not for masochistic reasons
    121  *       but to keep the binary small and make it easier to switch between CRT
    122  *       and IPRT w/ no-CRT.
    123  *
    124  * @{
    125  */
    126 
    127 static void OutputWStr(HANDLE hDst, const wchar_t *pwszStr)
    128 {
    129     DWORD cbIgn;
    130     if (GetConsoleMode(hDst, &cbIgn))
    131         WriteConsoleW(hDst, pwszStr, (DWORD)RTUtf16Len(pwszStr), &cbIgn, NULL);
    132     else
    133     {
    134         char *pszTmp;
    135         int rc = RTUtf16ToUtf8(pwszStr, &pszTmp);
    136         if (RT_SUCCESS(rc))
    137         {
    138             char *pszInCodepage;
    139             rc = RTStrUtf8ToCurrentCP(&pszInCodepage, pszTmp);
    140             if (RT_SUCCESS(rc))
    141             {
    142                 WriteFile(hDst, pszInCodepage, (DWORD)strlen(pszInCodepage), &cbIgn, NULL);
    143                 RTStrFree(pszInCodepage);
    144             }
    145             else
    146                 WriteFile(hDst, RT_STR_TUPLE("<RTStrUtf8ToCurrentCP error>"), &cbIgn, NULL);
    147             RTStrFree(pszTmp);
    148         }
    149         else
    150             WriteFile(hDst, RT_STR_TUPLE("<RTUtf16ToUtf8 error>"), &cbIgn, NULL);
    151     }
    152 }
    153 
    154 
    155 static void ErrorMsgBegin(const char *pszMsg)
    156 {
    157     HANDLE const hStdErr = GetStdHandle(STD_ERROR_HANDLE);
    158     DWORD        cbIgn;
    159     WriteFile(hStdErr, RT_STR_TUPLE("error: "), &cbIgn, NULL);
    160     WriteFile(hStdErr, pszMsg, (DWORD)strlen(pszMsg), &cbIgn, NULL);
    161 }
    162 
    163 
    164 static void ErrorMsgStr(const char *pszMsg)
    165 {
    166     HANDLE const hStdErr = GetStdHandle(STD_ERROR_HANDLE);
    167     DWORD cbIgn;
    168     WriteFile(hStdErr, pszMsg, (DWORD)strlen(pszMsg), &cbIgn, NULL);
    169 }
    170 
    171 
    172 static void ErrorMsgWStr(const wchar_t *pwszStr)
    173 {
    174     OutputWStr(GetStdHandle(STD_ERROR_HANDLE), pwszStr);
    175 }
    176 
    177 
    178 static int ErrorMsgEnd(const char *pszMsg)
    179 {
    180     HANDLE const hStdErr = GetStdHandle(STD_ERROR_HANDLE);
    181     DWORD        cbIgn;
    182     if (pszMsg)
    183         WriteFile(hStdErr, pszMsg, (DWORD)strlen(pszMsg), &cbIgn, NULL);
    184     WriteFile(hStdErr, RT_STR_TUPLE("\r\n"), &cbIgn, NULL);
    185     return EXIT_FAIL;
    186 }
    187 
    188 
    189 static void ErrorMsgU64(uint64_t uValue, bool fSigned = false)
    190 {
    191     char szVal[128];
    192     RTStrFormatU64(szVal, sizeof(szVal), uValue, 10, 0, 0, fSigned ? RTSTR_F_VALSIGNED : 0);
    193     ErrorMsgStr(szVal);
    194 }
    195 
    196 
    197 static int ErrorMsg(const char *pszMsg)
    198 {
    199     ErrorMsgBegin(pszMsg);
    200     return ErrorMsgEnd(NULL);
    201 }
    202 
    203 
    204 static int ErrorMsgSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3)
    205 {
    206     ErrorMsgBegin(pszMsg1);
    207     ErrorMsgWStr(pwszMsg2);
    208     return ErrorMsgEnd(pszMsg3);
    209 }
    210 
    211 
    212 static int ErrorMsgSWSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3,
    213                          const wchar_t *pwszMsg4, const char *pszMsg5)
    214 {
    215     ErrorMsgBegin(pszMsg1);
    216     ErrorMsgWStr(pwszMsg2);
    217     ErrorMsgStr(pszMsg3);
    218     ErrorMsgWStr(pwszMsg4);
    219     return ErrorMsgEnd(pszMsg5);
    220 }
    221 
    222 
    223 static void ErrorMsgErrVal(uint32_t uErrVal, bool fSigned)
    224 {
    225     char    szVal[128];
    226     ssize_t cchVal = RTStrFormatU32(szVal, sizeof(szVal) - 1, uErrVal, 10, 0, 0, fSigned ? RTSTR_F_VALSIGNED : 0);
    227     szVal[cchVal++] = '/';
    228     szVal[cchVal]   = '\0';
    229     ErrorMsgStr(szVal);
    230 
    231     RTStrFormatU32(szVal, sizeof(szVal) - 1, uErrVal, 16, 0, 0, RTSTR_F_SPECIAL);
    232     ErrorMsgStr(szVal);
    233 }
    234 
    235 
    236 static int ErrorMsgErr(const char *pszMsg, uint32_t uErrVal, const char *pszErrIntro, bool fSigned)
    237 {
    238     ErrorMsgBegin(pszMsg);
    239     ErrorMsgStr(pszErrIntro);
    240     ErrorMsgErrVal(uErrVal, fSigned);
    241     return ErrorMsgEnd(")");
    242 }
    243 
    244 
    245 static int ErrorMsgVBoxErr(const char *pszMsg, int rc)
    246 {
    247     return ErrorMsgErr(pszMsg, rc, " (", true);
    248 }
    249 
    250 
    251 static int ErrorMsgLastErr(const char *pszMsg)
    252 {
    253     return ErrorMsgErr(pszMsg, GetLastError(), " (last error ", false);
    254 }
    255 
    256 
    257 static int ErrorMsgLastErrSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3)
    258 {
    259     DWORD dwErr = GetLastError();
    260     ErrorMsgBegin(pszMsg1);
    261     ErrorMsgWStr(pwszMsg2);
    262     ErrorMsgStr(pszMsg3);
    263     ErrorMsgStr(" (last error ");
    264     ErrorMsgErrVal(dwErr, false);
    265     return ErrorMsgEnd(")");
    266 }
    267 
    268 static int ErrorMsgLastErrSWSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3,
    269                                 const wchar_t *pwszMsg4, const char *pszMsg5)
    270 {
    271     DWORD dwErr = GetLastError();
    272     ErrorMsgBegin(pszMsg1);
    273     ErrorMsgWStr(pwszMsg2);
    274     ErrorMsgStr(pszMsg3);
    275     ErrorMsgWStr(pwszMsg4);
    276     ErrorMsgStr(pszMsg5);
    277     ErrorMsgStr(" (last error ");
    278     ErrorMsgErrVal(dwErr, false);
    279     return ErrorMsgEnd(")");
    280 }
    281 
    282 
    283 static int ErrorMsgLastErrSWSRSUS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3, const char *pszMsg4,
    284                                   uint64_t uValue, const char *pszMsg5)
    285 {
    286     DWORD dwErr = GetLastError();
    287     ErrorMsgBegin(pszMsg1);
    288     ErrorMsgWStr(pwszMsg2);
    289     ErrorMsgStr(pszMsg3);
    290     ErrorMsgStr(" (last error ");
    291     ErrorMsgErrVal(dwErr, false);
    292     ErrorMsgStr(")");
    293     ErrorMsgStr(pszMsg4);
    294     ErrorMsgU64(uValue);
    295     return ErrorMsgEnd(pszMsg5);
    296 }
    297 
    298 
    299 static int ErrorMsgLastErrSSS(const char *pszMsg1, const char *pszMsg2, const char *pszMsg3)
    300 {
    301     DWORD dwErr = GetLastError();
    302     ErrorMsgBegin(pszMsg1);
    303     ErrorMsgStr(pszMsg2);
    304     ErrorMsgStr(pszMsg3);
    305     ErrorMsgStr(" (last error ");
    306     ErrorMsgErrVal(dwErr, false);
    307     return ErrorMsgEnd(")");
    308 }
    309 
    310 
    311 static int ErrorMsgLStatus(const char *pszMsg, LSTATUS lrc)
    312 {
    313     return ErrorMsgErr(pszMsg, (DWORD)lrc, " (", true);
    314 }
    315 
    316 
    317 static int ErrorMsgLStatusSWSRS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3,
    318                                 LSTATUS lrc, const char *pszMsg4)
    319 {
    320     ErrorMsgBegin(pszMsg1);
    321     ErrorMsgWStr(pwszMsg2);
    322     ErrorMsgStr(pszMsg3);
    323     ErrorMsgErrVal((DWORD)lrc, true);
    324     return ErrorMsgEnd(pszMsg4);
    325 }
    326 
    327 
    328 static int ErrorMsgLStatusSWSWSRS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3, const wchar_t *pwszMsg4,
    329                                   const char *pszMsg5, LSTATUS lrc, const char *pszMsg6)
    330 {
    331     ErrorMsgBegin(pszMsg1);
    332     ErrorMsgWStr(pwszMsg2);
    333     ErrorMsgStr(pszMsg3);
    334     ErrorMsgWStr(pwszMsg4);
    335     ErrorMsgStr(pszMsg5);
    336     ErrorMsgErrVal((DWORD)lrc, true);
    337     return ErrorMsgEnd(pszMsg6);
    338 }
    339 
    340 
    341 static int ErrorMsgLStatusSWSWSWSRS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3, const wchar_t *pwszMsg4,
    342                                     const char *pszMsg5, const wchar_t *pwszMsg6, const char *pszMsg7,
    343                                     LSTATUS lrc, const char *pszMsg8)
    344 {
    345     ErrorMsgBegin(pszMsg1);
    346     ErrorMsgWStr(pwszMsg2);
    347     ErrorMsgStr(pszMsg3);
    348     ErrorMsgWStr(pwszMsg4);
    349     ErrorMsgStr(pszMsg5);
    350     ErrorMsgWStr(pwszMsg6);
    351     ErrorMsgStr(pszMsg7);
    352     ErrorMsgErrVal((DWORD)lrc, true);
    353     return ErrorMsgEnd(pszMsg8);
    354 }
    355 
    356 
    357 static int ErrorMsgLStatusSWSWSWSWSRS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3, const wchar_t *pwszMsg4,
    358                                       const char *pszMsg5, const wchar_t *pwszMsg6, const char *pszMsg7, const wchar_t *pwszMsg8,
    359                                       const char *pszMsg9, LSTATUS lrc, const char *pszMsg10)
    360 {
    361     ErrorMsgBegin(pszMsg1);
    362     ErrorMsgWStr(pwszMsg2);
    363     ErrorMsgStr(pszMsg3);
    364     ErrorMsgWStr(pwszMsg4);
    365     ErrorMsgStr(pszMsg5);
    366     ErrorMsgWStr(pwszMsg6);
    367     ErrorMsgStr(pszMsg7);
    368     ErrorMsgWStr(pwszMsg8);
    369     ErrorMsgStr(pszMsg9);
    370     ErrorMsgErrVal((DWORD)lrc, true);
    371     return ErrorMsgEnd(pszMsg10);
    372 }
    373 
    374 
    375 static int ErrorBadArg(const char *pszName, wchar_t const *pwszArg, const char *pszValues = NULL)
    376 {
    377     ErrorMsgBegin("Bad argument '");
    378     ErrorMsgStr(pszName);
    379     ErrorMsgStr("': ");
    380     ErrorMsgWStr(pwszArg);
    381     if (pszValues)
    382         ErrorMsgStr(", expected: ");
    383     return ErrorMsgEnd(pszValues);
    384 }
    385 
    386 
    387 /** Simple fputs(stdout) replacement. */
    388 static void PrintStr(const char *pszMsg)
    389 {
    390     HANDLE const hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    391     DWORD        cbIgn;
    392     WriteFile(hStdOut, pszMsg, (DWORD)strlen(pszMsg), &cbIgn, NULL);
    393 }
    394 
    395 
    396 /** Simple fputs(stdout) replacement. */
    397 static void PrintWStr(const wchar_t *pwszStr)
    398 {
    399     OutputWStr(GetStdHandle(STD_OUTPUT_HANDLE), pwszStr);
    400 }
    401 
    402 
    403 static void PrintX64(uint64_t uValue)
    404 {
    405     char szVal[128];
    406     RTStrFormatU64(szVal, sizeof(szVal), uValue, 16, 0, 0, RTSTR_F_64BIT | RTSTR_F_SPECIAL);
    407     PrintStr(szVal);
    408 }
    409 
    410 
    411 static void PrintSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3)
    412 {
    413     PrintStr(pszMsg1);
    414     PrintWStr(pwszMsg2);
    415     PrintStr(pszMsg3);
    416 }
    417 
    418 
    419 static void PrintSWSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3,
    420                        const wchar_t *pwszMsg4, const char *pszMsg5)
    421 {
    422     PrintStr(pszMsg1);
    423     PrintWStr(pwszMsg2);
    424     PrintStr(pszMsg3);
    425     PrintWStr(pwszMsg4);
    426     PrintStr(pszMsg5);
    427 }
    428 
    429 
    430 static void PrintSWSWSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3, const wchar_t *pwszMsg4,
    431                          const char *pszMsg5, const wchar_t *pwszMsg6, const char *pszMsg7)
    432 {
    433     PrintStr(pszMsg1);
    434     PrintWStr(pwszMsg2);
    435     PrintStr(pszMsg3);
    436     PrintWStr(pwszMsg4);
    437     PrintStr(pszMsg5);
    438     PrintWStr(pwszMsg6);
    439     PrintStr(pszMsg7);
    440 }
    441 
    442 
    443 static void PrintSWSWSWSWS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3, const wchar_t *pwszMsg4,
    444                            const char *pszMsg5, const wchar_t *pwszMsg6, const char *pszMsg7, const wchar_t *pwszMsg8,
    445                            const char *pszMsg9)
    446 {
    447     PrintStr(pszMsg1);
    448     PrintWStr(pwszMsg2);
    449     PrintStr(pszMsg3);
    450     PrintWStr(pwszMsg4);
    451     PrintStr(pszMsg5);
    452     PrintWStr(pwszMsg6);
    453     PrintStr(pszMsg7);
    454     PrintWStr(pwszMsg8);
    455     PrintStr(pszMsg9);
    456 }
    457 
    458 
    459 static void PrintSXS(const char *pszMsg1, uint64_t uValue, const char *pszMsg2)
    460 {
    461     PrintStr(pszMsg1);
    462     PrintX64(uValue);
    463     PrintStr(pszMsg2);
    464 }
    465 
    466 
    467 static void PrintSWSWSWSXS(const char *pszMsg1, const wchar_t *pwszMsg2, const char *pszMsg3, const wchar_t *pwszMsg4,
    468                            const char *pszMsg5, const wchar_t *pwszMsg6, const char *pszMsg7, uint64_t uValue, const char *pszMsg8)
    469 {
    470     PrintStr(pszMsg1);
    471     PrintWStr(pwszMsg2);
    472     PrintStr(pszMsg3);
    473     PrintWStr(pwszMsg4);
    474     PrintStr(pszMsg5);
    475     PrintWStr(pwszMsg6);
    476     PrintStr(pszMsg7);
    477     PrintX64(uValue);
    478     PrintStr(pszMsg8);
    479 }
    480 
    481 /** @} */
    482118
    483119static char *ArgToUtf8(wchar_t const *pwszString, const char *pszArgName)
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp

    r96407 r96449  
    6666
    6767
    68 static void VBoxGrapicsSetSupported(BOOL fSupported);
    69 
    70 
    7168/*********************************************************************************************************************************
    7269*   Internal Functions                                                                                                           *
    7370*********************************************************************************************************************************/
     71static void VBoxGrapicsSetSupported(BOOL fSupported);
    7472static int vboxTrayCreateTrayIcon(void);
    7573static LRESULT CALLBACK vboxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
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