Skip to content

Commit 169ca33

Browse files
WinMain: do not attach console as it does not work anyway
Also, don't use auto where unnecessary
1 parent 66b9a6e commit 169ca33

File tree

1 file changed

+15
-44
lines changed

1 file changed

+15
-44
lines changed

NativeApp/src/Win32/WinMain.cpp

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -55,39 +55,28 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance,
5555
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
5656
#endif
5757

58-
BOOL ConsoleAttached = AttachConsole(ATTACH_PARENT_PROCESS);
59-
60-
FILE* pConOut = nullptr;
61-
FILE* pConErr = nullptr;
62-
FILE* pConIn = nullptr;
63-
if (ConsoleAttached)
64-
{
65-
freopen_s(&pConOut, "CONOUT$", "w", stdout);
66-
freopen_s(&pConErr, "CONOUT$", "w", stderr);
67-
freopen_s(&pConIn, "CONIN$", "r", stdin);
68-
}
69-
7058
g_pTheApp.reset(CreateApplication());
7159

72-
const auto* CmdLine = GetCommandLineA();
73-
const auto Args = SplitString(CmdLine, CmdLine + strlen(CmdLine));
60+
LPCSTR CmdLine = GetCommandLineA();
61+
62+
const std::vector<std::string> Args = SplitString(CmdLine, CmdLine + strlen(CmdLine));
7463

7564
std::vector<const char*> ArgsV(Args.size());
7665
for (size_t i = 0; i < Args.size(); ++i)
7766
ArgsV[i] = Args[i].c_str();
7867

79-
auto CmdLineStatus = g_pTheApp->ProcessCommandLine(static_cast<int>(ArgsV.size()), ArgsV.data());
68+
AppBase::CommandLineStatus CmdLineStatus = g_pTheApp->ProcessCommandLine(static_cast<int>(ArgsV.size()), ArgsV.data());
8069
if (CmdLineStatus == AppBase::CommandLineStatus::Help)
8170
return 0;
8271
else if (CmdLineStatus == AppBase::CommandLineStatus::Error)
8372
return -1;
8473

85-
const auto* AppTitle = g_pTheApp->GetAppTitle();
74+
const char* AppTitle = g_pTheApp->GetAppTitle();
8675

8776
#ifdef UNICODE
88-
const auto* const WindowClassName = L"SampleApp";
77+
LPCWSTR WindowClassName = L"SampleApp";
8978
#else
90-
const auto* const WindowClassName = "SampleApp";
79+
LPCSTR WindowClassName = "SampleApp";
9180
#endif
9281

9382
// Register our window class
@@ -118,7 +107,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance,
118107
return -1;
119108
}
120109

121-
auto GoldenImgMode = g_pTheApp->GetGoldenImageMode();
110+
NativeAppBase::GoldenImageMode GoldenImgMode = g_pTheApp->GetGoldenImageMode();
122111
if (GoldenImgMode != NativeAppBase::GoldenImageMode::None)
123112
{
124113
g_pTheApp->Update(0, 0);
@@ -128,7 +117,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance,
128117
g_pTheApp->Update(0, 0);
129118
g_pTheApp->Render();
130119
g_pTheApp->Present();
131-
auto ExitCode = g_pTheApp->GetExitCode();
120+
int ExitCode = g_pTheApp->GetExitCode();
132121
g_pTheApp.reset();
133122
return ExitCode;
134123
}
@@ -140,7 +129,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance,
140129

141130
Diligent::Timer Timer;
142131

143-
auto PrevTime = Timer.GetElapsedTime();
132+
double PrevTime = Timer.GetElapsedTime();
144133
double filteredFrameTime = 0.0;
145134

146135
// Main message loop
@@ -154,9 +143,9 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance,
154143
}
155144
else
156145
{
157-
auto CurrTime = Timer.GetElapsedTime();
158-
auto ElapsedTime = CurrTime - PrevTime;
159-
PrevTime = CurrTime;
146+
double CurrTime = Timer.GetElapsedTime();
147+
double ElapsedTime = CurrTime - PrevTime;
148+
PrevTime = CurrTime;
160149

161150
if (g_pTheApp->IsReady())
162151
{
@@ -178,24 +167,6 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance,
178167

179168
g_pTheApp.reset();
180169

181-
if (ConsoleAttached)
182-
{
183-
if (pConOut)
184-
{
185-
fflush(stdout);
186-
fclose(pConOut);
187-
}
188-
if (pConErr)
189-
{
190-
fflush(stderr);
191-
fclose(pConErr);
192-
}
193-
if (pConIn)
194-
fclose(pConIn);
195-
196-
FreeConsole();
197-
}
198-
199170
return (int)msg.wParam;
200171
}
201172

@@ -204,7 +175,7 @@ LRESULT CALLBACK MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lPara
204175
{
205176
if (g_pTheApp)
206177
{
207-
auto res = g_pTheApp->HandleWin32Message(wnd, message, wParam, lParam);
178+
LRESULT res = g_pTheApp->HandleWin32Message(wnd, message, wParam, lParam);
208179
if (res != 0)
209180
return res;
210181
}

0 commit comments

Comments
 (0)