Changeset 95877 in vbox for trunk/src/VBox
- Timestamp:
- Jul 27, 2022 8:37:32 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
r95864 r95877 139 139 HANDLE g_hSeamlessWtNotifyEvent = 0; 140 140 HANDLE g_hSeamlessKmNotifyEvent = 0; 141 HINSTANCE g_hInstance ;141 HINSTANCE g_hInstance = NULL; 142 142 HWND g_hwndToolWindow; 143 143 NOTIFYICONDATA g_NotifyIconData; … … 999 999 * Main function 1000 1000 */ 1001 #ifdef IPRT_NO_CRT1002 1001 int main(int cArgs, char **papszArgs) 1003 #else 1004 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 1005 #endif 1006 { 1007 char szLogFile[RTPATH_MAX] = {0}; 1008 1009 #ifdef IPRT_NO_CRT 1002 { 1010 1003 int rc = RTR3InitExe(cArgs, &papszArgs, RTR3INIT_FLAGS_STANDALONE_APP); 1011 1004 if (RT_FAILURE(rc)) 1012 1005 return RTMsgInitFailure(rc); 1013 #else 1014 RT_NOREF(hPrevInstance, lpCmdLine, nCmdShow); 1015 /** @todo r=bird: WTF do you use __argc & __argv here only to parse the 1016 * command line furthe down?!? Makes no effing sense, espcially given 1017 * that RTR3InitExe will return valid UTF-8, doing exactly the 1018 * same stuff as you do here. 1019 * aaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAARG! */ 1020 int rc = RTR3InitExe(__argc, &__argv, RTR3INIT_FLAGS_STANDALONE_APP); 1006 1007 /* 1008 * Parse the top level arguments until we find a command. 1009 */ 1010 static const RTGETOPTDEF s_aOptions[] = 1011 { 1012 { "--help", 'h', RTGETOPT_REQ_NOTHING }, 1013 { "-help", 'h', RTGETOPT_REQ_NOTHING }, 1014 { "/help", 'h', RTGETOPT_REQ_NOTHING }, 1015 { "/?", 'h', RTGETOPT_REQ_NOTHING }, 1016 { "--logfile", 'l', RTGETOPT_REQ_STRING }, 1017 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 1018 { "--version", 'V', RTGETOPT_REQ_NOTHING }, 1019 }; 1020 1021 char szLogFile[RTPATH_MAX] = {0}; 1022 1023 RTGETOPTSTATE GetState; 1024 rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/); 1021 1025 if (RT_FAILURE(rc)) 1022 return RTMsgInitFailure(rc); 1023 1024 LPWSTR pwszCmdLine = GetCommandLineW(); 1025 if (!pwszCmdLine) 1026 return RTMsgErrorExit(RTEXITCODE_FAILURE, "GetCommandLineW failed"); 1027 1028 char *pszCmdLine; 1029 rc = RTUtf16ToUtf8(pwszCmdLine, &pszCmdLine); /* leaked */ 1030 if (RT_FAILURE(rc)) 1031 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to convert the command line: %Rrc", rc); 1032 1033 int cArgs; 1034 char **papszArgs; 1035 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, RTGETOPTARGV_CNV_QUOTE_MS_CRT, NULL); 1036 if (RT_SUCCESS(rc)) 1037 #endif 1038 { 1039 /* 1040 * Parse the top level arguments until we find a command. 1041 */ 1042 static const RTGETOPTDEF s_aOptions[] = 1043 { 1044 { "--help", 'h', RTGETOPT_REQ_NOTHING }, 1045 { "-help", 'h', RTGETOPT_REQ_NOTHING }, 1046 { "/help", 'h', RTGETOPT_REQ_NOTHING }, 1047 { "/?", 'h', RTGETOPT_REQ_NOTHING }, 1048 { "--logfile", 'l', RTGETOPT_REQ_STRING }, 1049 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 1050 { "--version", 'V', RTGETOPT_REQ_NOTHING }, 1051 }; 1052 1053 RTGETOPTSTATE GetState; 1054 rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/); 1055 if (RT_FAILURE(rc)) 1056 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptInit failed: %Rrc\n", rc); 1057 1058 int ch; 1059 RTGETOPTUNION ValueUnion; 1060 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0) 1061 { 1062 switch (ch) 1063 { 1064 case 'h': 1065 hlpShowMessageBox(VBOX_VBOXTRAY_TITLE, MB_ICONINFORMATION, "-- %s v%u.%u.%ur%u --\n" 1066 "\n" 1067 "Command Line Parameters:\n\n" 1068 "-l, --logfile <file>\n" 1069 " Enables logging to a file\n" 1070 "-v, --verbose\n" 1071 " Increases verbosity\n" 1072 "-V, --version\n" 1073 " Displays version number and exit\n" 1074 "-?, -h, --help\n" 1075 " Displays this help text and exit\n" 1076 "\n" 1077 "Examples:\n" 1078 " %s -vvv\n", 1079 VBOX_VBOXTRAY_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV, 1080 papszArgs[0], papszArgs[0]); 1081 return RTEXITCODE_SUCCESS; 1082 1083 case 'l': 1084 if (*ValueUnion.psz == '\0') 1085 szLogFile[0] = '\0'; 1086 else 1087 { 1088 rc = RTPathAbs(ValueUnion.psz, szLogFile, sizeof(szLogFile)); 1089 if (RT_FAILURE(rc)) 1090 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on log file path: %Rrc (%s)", 1091 rc, ValueUnion.psz); 1092 } 1093 break; 1094 1095 case 'v': 1096 g_cVerbosity++; 1097 break; 1098 1099 case 'V': 1100 hlpShowMessageBox(VBOX_VBOXTRAY_TITLE, MB_ICONINFORMATION, 1101 "Version: %u.%u.%ur%u", 1102 VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV); 1103 return RTEXITCODE_SUCCESS; 1104 1105 default: 1106 rc = RTGetOptPrintError(ch, &ValueUnion); 1107 break; 1108 } 1109 } 1110 1111 RTGetOptArgvFree(papszArgs); 1112 } 1113 #ifndef IPRT_NO_CRT 1114 else 1115 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptArgvFromString failed: %Rrc", rc); 1116 #endif 1026 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptInit failed: %Rrc\n", rc); 1027 1028 int ch; 1029 RTGETOPTUNION ValueUnion; 1030 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0) 1031 { 1032 switch (ch) 1033 { 1034 case 'h': 1035 hlpShowMessageBox(VBOX_PRODUCT " - " VBOX_VBOXTRAY_TITLE, 1036 MB_ICONINFORMATION, 1037 "-- " VBOX_PRODUCT " %s v%u.%u.%ur%u --\n\n" 1038 "Copyright (C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n" 1039 "All rights reserved.\n\n" 1040 "Command Line Parameters:\n\n" 1041 "-l, --logfile <file>\n" 1042 " Enables logging to a file\n" 1043 "-v, --verbose\n" 1044 " Increases verbosity\n" 1045 "-V, --version\n" 1046 " Displays version number and exit\n" 1047 "-?, -h, --help\n" 1048 " Displays this help text and exit\n" 1049 "\n" 1050 "Examples:\n" 1051 " %s -vvv\n", 1052 VBOX_VBOXTRAY_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV, 1053 papszArgs[0], papszArgs[0]); 1054 return RTEXITCODE_SUCCESS; 1055 1056 case 'l': 1057 if (*ValueUnion.psz == '\0') 1058 szLogFile[0] = '\0'; 1059 else 1060 { 1061 rc = RTPathAbs(ValueUnion.psz, szLogFile, sizeof(szLogFile)); 1062 if (RT_FAILURE(rc)) 1063 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on log file path: %Rrc (%s)", 1064 rc, ValueUnion.psz); 1065 } 1066 break; 1067 1068 case 'v': 1069 g_cVerbosity++; 1070 break; 1071 1072 case 'V': 1073 hlpShowMessageBox(VBOX_VBOXTRAY_TITLE, MB_ICONINFORMATION, 1074 "Version: %u.%u.%ur%u", 1075 VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV); 1076 return RTEXITCODE_SUCCESS; 1077 1078 default: 1079 rc = RTGetOptPrintError(ch, &ValueUnion); 1080 break; 1081 } 1082 } 1117 1083 1118 1084 /* Note: Do not use a global namespace ("Global\\") for mutex name here, … … 1143 1109 /* Set the instance handle. */ 1144 1110 #ifdef IPRT_NO_CRT 1111 Assert(g_hInstance == NULL); /* Make sure this isn't set before by WinMain(). */ 1145 1112 g_hInstance = GetModuleHandleW(NULL); 1146 #else1147 g_hInstance = hInstance;1148 1113 #endif 1149 1150 1114 hlpReportStatus(VBoxGuestFacilityStatus_Init); 1151 1115 rc = vboxTrayCreateToolWindow(); … … 1221 1185 vboxTrayLogDestroy(); 1222 1186 1223 return RT_SUCCESS(rc) ? 0 : 1; 1224 } 1187 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1188 } 1189 1190 #ifndef IPRT_NO_CRT 1191 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 1192 { 1193 RT_NOREF(hPrevInstance, lpCmdLine, nCmdShow); 1194 1195 g_hInstance = hInstance; 1196 1197 return main(__argc, __argv); 1198 } 1199 #endif /* IPRT_NO_CRT */ 1225 1200 1226 1201 /**
Note:
See TracChangeset
for help on using the changeset viewer.