Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
// along with this program. If not, see https://www.gnu.org/licenses/.

#include <windows.h>
#include <shellapi.h>
#include <stdio.h>
#include <wchar.h>

#include "../include/gui.h"
#include "../include/version.h"

/* Force NVIDIA Optimus and AMD switchable-graphics systems to use the
* high-performance discrete GPU for this process.
Expand All @@ -25,11 +29,51 @@
__declspec(dllexport) unsigned long NvOptimusEnablement = 1;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;

static void attach_output_console(void)
{
FILE *stream;

if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
AllocConsole();
}

freopen_s(&stream, "CONOUT$", "w", stdout);
freopen_s(&stream, "CONOUT$", "w", stderr);
}

static int handle_command_line_flags(void)
{
int argc = 0;
int handled = 0;
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);

if (argv == NULL) {
return 0;
}

if (argc == 2 && wcscmp(argv[1], L"--version") == 0) {
attach_output_console();
printf("FSP.DMRCrack %s\n", DMRCRACK_VERSION);
handled = 1;
} else if (argc == 2 && wcscmp(argv[1], L"--help") == 0) {
attach_output_console();
printf("Usage: dmrcrack.exe [--help] [--version]\n");
handled = 1;
}

LocalFree(argv);
return handled;
}

int WINAPI WinMain(HINSTANCE h_instance, HINSTANCE h_prev, LPSTR lp_cmd_line, int n_cmd_show)
{
(void)h_prev;
(void)lp_cmd_line;

if (handle_command_line_flags()) {
return 0;
}

/* Enable per-monitor DPI awareness for crisp rendering on high-DPI displays */
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);

Expand Down