mirror of
https://github.com/lammertb/libhttp.git
synced 2025-09-07 11:07:23 +03:00
Move windows console creation to a function
This commit is contained in:
32
src/main.c
32
src/main.c
@@ -134,18 +134,17 @@ static void die(const char *fmt, ...)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
static int MakeConsole();
|
||||||
|
#endif
|
||||||
|
|
||||||
static void show_usage_and_exit(void)
|
static void show_usage_and_exit(void)
|
||||||
{
|
{
|
||||||
const struct mg_option *options;
|
const struct mg_option *options;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
|
MakeConsole();
|
||||||
AllocConsole();
|
|
||||||
AttachConsole(GetCurrentProcessId());
|
|
||||||
}
|
|
||||||
freopen("CON", "a", stdout);
|
|
||||||
freopen("CON", "a", stderr);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fprintf(stderr, "Civetweb v%s, built on %s\n",
|
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);
|
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)
|
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
|
||||||
{
|
{
|
||||||
WNDCLASS cls;
|
WNDCLASS cls;
|
||||||
|
Reference in New Issue
Block a user