VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/nocrt-startup-common-win.cpp@ 96388

Last change on this file since 96388 was 96388, checked in by vboxsync, 3 years ago

IPRT/nocrt: Introduced an internal rtNoCrtFatalMsg/Write API to be used instead of RTMsgError and RTAssertMsg2 to report no-CRT init and runtime issues. The other two drags in hundreds of KBs of unnecessary code. bugref:10261

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: nocrt-startup-common-win.cpp 96388 2022-08-20 23:08:15Z vboxsync $ */
2/** @file
3 * IPRT - No-CRT - Common Windows startup code.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/nocrt.h"
32#include "internal/process.h"
33
34#include <iprt/nt/nt-and-windows.h>
35#ifndef IPRT_NOCRT_WITHOUT_FATAL_WRITE
36# include <iprt/assert.h>
37#endif
38#include <iprt/getopt.h>
39#include <iprt/message.h>
40#include <iprt/path.h>
41#include <iprt/string.h>
42#include <iprt/utf16.h>
43
44#include "internal/compiler-vcc.h"
45
46
47/*********************************************************************************************************************************
48* Global Variables *
49*********************************************************************************************************************************/
50RT_C_DECLS_BEGIN
51DECL_HIDDEN_DATA(char) g_szrtProcExePath[RTPATH_MAX] = "Unknown.exe";
52DECL_HIDDEN_DATA(size_t) g_cchrtProcExePath = 11;
53DECL_HIDDEN_DATA(size_t) g_cchrtProcExeDir = 0;
54DECL_HIDDEN_DATA(size_t) g_offrtProcName = 0;
55RT_C_DECLS_END
56
57
58
59void rtVccWinInitProcExecPath(void)
60{
61 WCHAR wszPath[RTPATH_MAX];
62 UINT cwcPath = GetModuleFileNameW(NULL, wszPath, RT_ELEMENTS(wszPath));
63 if (cwcPath)
64 {
65 char *pszDst = g_szrtProcExePath;
66 int rc = RTUtf16ToUtf8Ex(wszPath, cwcPath, &pszDst, sizeof(g_szrtProcExePath), &g_cchrtProcExePath);
67 if (RT_SUCCESS(rc))
68 {
69 g_cchrtProcExeDir = g_offrtProcName = RTPathFilename(pszDst) - g_szrtProcExePath;
70 while ( g_cchrtProcExeDir >= 2
71 && RTPATH_IS_SLASH(g_szrtProcExePath[g_cchrtProcExeDir - 1])
72 && g_szrtProcExePath[g_cchrtProcExeDir - 2] != ':')
73 g_cchrtProcExeDir--;
74 }
75 else
76 {
77#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
78 RTMsgError("initProcExecPath: RTUtf16ToUtf8Ex failed: %Rrc\n", rc);
79#else
80 rtNoCrtFatalMsgWithRc(RT_STR_TUPLE("initProcExecPath: RTUtf16ToUtf8Ex failed: "), rc);
81#endif
82 }
83 }
84 else
85 {
86#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
87 RTMsgError("initProcExecPath: GetModuleFileNameW failed: %Rhrc\n", GetLastError());
88#else
89 rtNoCrtFatalWriteBegin(RT_STR_TUPLE("initProcExecPath: GetModuleFileNameW failed: "));
90 rtNoCrtFatalWriteWinRc(GetLastError());
91 rtNoCrtFatalWrite(RT_STR_TUPLE("\r\n"));
92#endif
93 }
94}
95
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette