1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-09-03 01:21:16 +03:00

Move windows console creation to a function

This commit is contained in:
bel
2014-04-18 23:09:02 +02:00
parent de735c5544
commit ca564eab93

View File

@@ -134,18 +134,17 @@ static void die(const char *fmt, ...)
exit(EXIT_FAILURE);
}
#ifdef WIN32
static int MakeConsole();
#endif
static void show_usage_and_exit(void)
{
const struct mg_option *options;
int i;
#ifdef WIN32
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
AllocConsole();
AttachConsole(GetCurrentProcessId());
}
freopen("CON", "a", stdout);
freopen("CON", "a", stderr);
MakeConsole();
#endif
fprintf(stderr, "Civetweb v%s, built on %s\n",
@@ -1428,6 +1427,27 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
return DefWindowProc(hWnd, msg, wParam, lParam);
}
static int MakeConsole() {
DWORD err;
int ok = (GetConsoleWindow() != NULL);
if (!ok) {
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
FreeConsole();
if (!AllocConsole()) {
err = GetLastError();
if (err==ERROR_ACCESS_DENIED) {
MessageBox(NULL, "Insufficient rights to create a console window", "Error", MB_ICONERROR);
}
}
AttachConsole(GetCurrentProcessId());
}
freopen("CON", "a", stdout);
freopen("CON", "a", stderr);
ok = (GetConsoleWindow() != NULL);
}
return ok;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
{
WNDCLASS cls;