Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtentrypoint_win.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <qt_windows.h>
5#include <shellapi.h>
6
7/*
8 This file contains the code in the QtEntryPoint library for Windows.
9 QtEntryPoint contains the Windows startup code and is required for
10 linking to the Qt DLL.
11
12 When a Windows application starts, the WinMain function is
13 invoked.
14*/
15
16#if defined(QT_NEEDS_QMAIN)
17int qMain(int, char **);
18#define main qMain
19#else
20extern "C" int main(int, char **);
21#endif
22
23/*
24 WinMain() - Initializes Windows and calls user's startup function main().
25 NOTE: WinMain() won't be called if the application was linked as a "console"
26 application.
27*/
28
29// Convert a wchar_t to char string, equivalent to QString::toLocal8Bit()
30// when passed CP_ACP.
31static inline char *wideToMulti(unsigned int codePage, const wchar_t *aw)
32{
33 const int required = WideCharToMultiByte(codePage, 0, aw, -1, nullptr, 0, nullptr, nullptr);
34 char *result = new char[required];
35 WideCharToMultiByte(codePage, 0, aw, -1, result, required, nullptr, nullptr);
36 return result;
37}
38
39static inline int qtEntryPoint()
40{
41 int argc = 0;
42 wchar_t **argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
43 if (argvW == nullptr)
44 return -1;
45 char **argv = new char *[argc + 1];
46 for (int i = 0; i != argc; ++i)
47 argv[i] = wideToMulti(CP_ACP, argvW[i]);
48 argv[argc] = nullptr;
49 LocalFree(argvW);
50 const int exitCode = main(argc, argv);
51 for (int i = 0; (i != argc) && (argv[i] != nullptr); ++i)
52 delete [] argv[i];
53 delete [] argv;
54 return exitCode;
55}
56
57extern "C" int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
58{
59 return qtEntryPoint();
60}
61
62extern "C" int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
63{
64 return qtEntryPoint();
65}
int main()
[0]
GLuint64EXT * result
[6]
static int qtEntryPoint()
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
static char * wideToMulti(unsigned int codePage, const wchar_t *aw)
int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)