| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | } SDL_LogLevel; |
| | | |
| | | /* The default log output function */ |
| | | static void SDL_LogOutput(void *userdata, |
| | | int category, SDL_LogPriority priority, |
| | | const char *message); |
| | | static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message); |
| | | |
| | | static SDL_LogLevel *SDL_loglevels; |
| | | static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY; |
| | |
| | | SDL_stack_free(message); |
| | | } |
| | | |
| | | #if defined(__WIN32__) |
| | | /* Flag tracking the attachment of the console: 0=unattached, 1=attached, -1=error */ |
| | | #if defined(__WIN32__) && !defined(HAVE_STDIO_H) && !defined(__WINRT__) |
| | | /* Flag tracking the attachment of the console: 0=unattached, 1=attached to a console, 2=attached to a file, -1=error */ |
| | | static int consoleAttached = 0; |
| | | |
| | | /* Handle to stderr output of console. */ |
| | | static HANDLE stderrHandle = NULL; |
| | | #endif |
| | | |
| | | static void |
| | | static void SDLCALL |
| | | SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, |
| | | const char *message) |
| | | { |
| | |
| | | BOOL attachResult; |
| | | DWORD attachError; |
| | | unsigned long charsWritten; |
| | | DWORD consoleMode; |
| | | |
| | | /* Maybe attach console and get stderr handle */ |
| | | if (consoleAttached == 0) { |
| | |
| | | if (!attachResult) { |
| | | attachError = GetLastError(); |
| | | if (attachError == ERROR_INVALID_HANDLE) { |
| | | OutputDebugString(TEXT("Parent process has no console\r\n")); |
| | | /* This is expected when running from Visual Studio */ |
| | | /*OutputDebugString(TEXT("Parent process has no console\r\n"));*/ |
| | | consoleAttached = -1; |
| | | } else if (attachError == ERROR_GEN_FAILURE) { |
| | | OutputDebugString(TEXT("Could not attach to console of parent process\r\n")); |
| | |
| | | /* Newly attached */ |
| | | consoleAttached = 1; |
| | | } |
| | | |
| | | |
| | | if (consoleAttached == 1) { |
| | | stderrHandle = GetStdHandle(STD_ERROR_HANDLE); |
| | | |
| | | if (GetConsoleMode(stderrHandle, &consoleMode) == 0) { |
| | | /* WriteConsole fails if the output is redirected to a file. Must use WriteFile instead. */ |
| | | consoleAttached = 2; |
| | | } |
| | | } |
| | | } |
| | | #endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */ |
| | |
| | | OutputDebugString(TEXT("Insufficient heap memory to write message\r\n")); |
| | | } |
| | | } |
| | | |
| | | } else if (consoleAttached == 2) { |
| | | if (!WriteFile(stderrHandle, output, lstrlenA(output), &charsWritten, NULL)) { |
| | | OutputDebugString(TEXT("Error calling WriteFile\r\n")); |
| | | } |
| | | } |
| | | #endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */ |
| | | |