diff --git a/setup/installer/windows/file_dialogs.cpp b/setup/installer/windows/file_dialogs.cpp index f79cc21602..ee10aef947 100644 --- a/setup/installer/windows/file_dialogs.cpp +++ b/setup/installer/windows/file_dialogs.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #define PRINTERR(x) fprintf(stderr, x); fflush(stderr); #define REPORTERR(x) { PRINTERR(x); ret = 1; goto error; } @@ -76,6 +78,7 @@ bool read_string(unsigned short sz, LPWSTR* ans) { #define READ(x, y) if (!read_bytes((x), (y))) return 1; #define CHECK_KEY(x) (key_size == sizeof(x) - 1 && memcmp(buf, x, sizeof(x) - 1) == 0) #define READSTR(x) READ(sizeof(unsigned short), buf); if(!read_string(*((unsigned short*)buf), &x)) return 1; +#define SETBINARY(x) if(_setmode(_fileno(x), _O_BINARY) == -1) { PRINTERR("Failed to set binary mode"); return 1; } int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { char buf[257]; @@ -85,6 +88,11 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine unsigned short len = 0; LPWSTR title = NULL; + SETBINARY(stdout); SETBINARY(stdin); SETBINARY(stderr); + // The calibre executables call SetDllDirectory, we unset it here just in + // case it interferes with some idiotic shell extension or the other + SetDllDirectory(NULL); + while(!feof(stdin)) { memset(buf, 0, sizeof(buf)); if(!read_bytes(1, buf, true)) { if (feof(stdin)) break; return 1;}