AttachConsole over AllocConsole
Opened this issue · 0 comments
JustArion commented
Hi, in ModLoader.cpp#L135 BOOL
AllocConsole is called.
An alternate proposal is to call BOOL
AttachConsole first, then if that fails call AllocConsole.
The reasoning behind this is that you can launch the game from the CLI and the Console Data will be sent to the Console who started the game (if any) instead of making a new console on launch.
You can attach to the parent process by calling AttachConsole(ATTACH_PARENT_PROCESS);
The function returns true
on success, and false
if there's no parent console (eg. the user double-clicked the program and launched it)
The proposed change can be made like this:
void ModLoader::OpenTerminal()
{
if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())
{
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
SetWindowText(GetConsoleWindow(), "Elden Mod Loader");
}
}