6#include <Foundation/Basics/Platform/Win/MinWindows.h>
7#include <Foundation/Logging/Log.h>
8#include <Foundation/Memory/MemoryTracker.h>
9#include <Foundation/Threading/Lock.h>
10#include <Foundation/Threading/Mutex.h>
12namespace plApplicationDetails
14 PL_FOUNDATION_DLL
void SetConsoleCtrlHandler(plMinWindows::BOOL(PL_WINDOWS_WINAPI* consoleHandler)(plMinWindows::DWORD dwCtrlType));
15 PL_FOUNDATION_DLL
plMutex& GetShutdownMutex();
17 template <
typename AppClass,
typename... Args>
18 int ConsoleEntry(
int iArgc,
const char** pArgv, Args&&... arguments)
20#if PL_ENABLED(PL_COMPILER_MSVC)
21 static char appBuffer[
sizeof(AppClass)];
23 alignas(PL_ALIGNMENT_OF(AppClass))
static char appBuffer[
sizeof(AppClass)];
29 PL_LOCK(GetShutdownMutex());
31 static AppClass* pApp =
new (appBuffer) AppClass(std::forward<Args>(arguments)...);
32 pApp->SetCommandLineArguments((plUInt32)iArgc, pArgv);
36 const auto consoleHandler = [](plMinWindows::DWORD ctrlType) -> plMinWindows::BOOL
40 pApp->SetReturnCode(ctrlType);
42 PL_LOCK(GetShutdownMutex());
45 SetConsoleCtrlHandler(consoleHandler);
49 const int iReturnCode = pApp->GetReturnCode();
52 std::string text = pApp->TranslateReturnCode();
54 plLog::Printf(
"Return Code: %i = '%s'\n", iReturnCode, text.c_str());
56 plLog::Printf(
"Return Code: %i\n", iReturnCode, text.c_str());
59 const bool memLeaks = pApp->IsMemoryLeakReportingEnabled();
61 memset((
void*)pApp, 0,
sizeof(AppClass));
68 template <
typename AppClass,
typename... Args>
69 int ApplicationEntry(Args&&... arguments)
71#if PL_ENABLED(PL_COMPILER_MSVC)
72 static char appBuffer[
sizeof(AppClass)];
74 alignas(PL_ALIGNMENT_OF(AppClass))
static char appBuffer[
sizeof(AppClass)];
77 AppClass* pApp =
new (appBuffer) AppClass(std::forward<Args>(arguments)...);
78 pApp->SetCommandLineArguments((plUInt32)__argc,
const_cast<const char**
>(__argv));
81 const int iReturnCode = pApp->GetReturnCode();
84 std::string text = pApp->TranslateReturnCode();
89 const bool memLeaks = pApp->IsMemoryLeakReportingEnabled();
91 memset((
void*)pApp, 0,
sizeof(AppClass));
100#define PL_CONSOLEAPP_ENTRY_POINT(AppClass, ...) \
104 _declspec(dllexport) plMinWindows::DWORD NvOptimusEnablement = 0x00000001; \
105 _declspec(dllexport) plMinWindows::DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; \
107 PL_APPLICATION_ENTRY_POINT_CODE_INJECTION \
108 int main(int argc, const char** argv) \
110 return plApplicationDetails::ConsoleEntry<AppClass>(argc, argv, __VA_ARGS__); \
119#define _PL_APPLICATION_ENTRY_POINT_HINSTANCE HINSTANCE
120#define _PL_APPLICATION_ENTRY_POINT_LPSTR LPSTR
121#define _PL_APPLICATION_ENTRY_POINT_HINSTANCE_WINDOWS_ plMinWindows::HINSTANCE
122#define _PL_APPLICATION_ENTRY_POINT_LPSTR_WINDOWS_ plMinWindows::LPSTR
134#define PL_APPLICATION_ENTRY_POINT(AppClass, ...) \
138 _declspec(dllexport) plMinWindows::DWORD NvOptimusEnablement = 0x00000001; \
139 _declspec(dllexport) plMinWindows::DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; \
141 PL_APPLICATION_ENTRY_POINT_CODE_INJECTION \
142 int PL_WINDOWS_CALLBACK WinMain(_In_ PL_PP_CONCAT(_PL_, PL_PP_CONCAT(APPLICATION_ENTRY_POINT_HINSTANCE, _WINDOWS_)) hInstance, \
143 _In_opt_ PL_PP_CONCAT(_PL_, PL_PP_CONCAT(APPLICATION_ENTRY_POINT_HINSTANCE, _WINDOWS_)) hPrevInstance, \
144 _In_ PL_PP_CONCAT(_PL_, PL_PP_CONCAT(APPLICATION_ENTRY_POINT_LPSTR, _WINDOWS_)) lpCmdLine, _In_ int nCmdShow) \
146 return plApplicationDetails::ApplicationEntry<AppClass>(__VA_ARGS__); \
static void Printf(const char *szFormat,...)
Calls low-level OS functionality to print a string to the typical outputs. Forwards to Print.
Definition Log.cpp:271
static void DumpMemoryLeaks()
Prints the known memory leaks to plLog and triggers an assert if there are any.
Definition MemoryTracker.cpp:470
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13