Skip to content

Commit 15d8172

Browse files
committed
need to hack stderr for non-console build
1 parent 417f09e commit 15d8172

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

bnk-extract/defs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ typedef struct {
4949
#else
5050
#define dprintf(...)
5151
#endif
52-
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
52+
extern FILE* consoleless_stderr;
53+
#define eprintf(...) fprintf(consoleless_stderr ? consoleless_stderr : stderr, __VA_ARGS__)
5354
#define v_printf(level, ...) if (VERBOSE >= level) printf(__VA_ARGS__)
5455

5556
#ifdef __cplusplus

gui.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "treeview_extension.h"
1515
#include "bnk-extract/api.h"
1616

17+
FILE* consoleless_stderr;
18+
1719
// global window variables
1820
static HINSTANCE me;
1921
static HWND mainWindow;
@@ -250,6 +252,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
250252
// redirect stderr to a temporary file, in order to be able to read it back and display later
251253
FILE* temp_file = tmpfile();
252254
dup2(fileno(temp_file), STDERR_FILENO);
255+
if (fileno(stderr) == -2) { // no console, but we still want to capture stderr
256+
consoleless_stderr = temp_file;
257+
}
253258
WemInformation* wemInformation = bnk_extract(onlyAudioGiven ? 3 : 7, bnk_extract_args);
254259
free(binPath); free(audioPath); free(eventsPath);
255260
if (wemInformation) {
@@ -268,6 +273,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
268273
MessageBox(mainWindow, stderr_buffer, "Failed to read audio files", MB_ICONERROR);
269274
}
270275
fclose(temp_file);
276+
consoleless_stderr = NULL;
271277
// restore stderr
272278
dup2(duped_stderr, STDERR_FILENO);
273279
} else if ((HWND) lParam == XButton) {

0 commit comments

Comments
 (0)