mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / programs / wineconsole / wineconsole.c
blobd398e6eb1a8af97a3f5747e7a81b28e7367d3ede
1 /*
2 * an application for displaying Win32 console
4 * Copyright 2001, 2002 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <stdlib.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wincon.h"
29 #include "wineconsole_res.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(console);
35 int WINAPI wWinMain( HINSTANCE inst, HINSTANCE prev, WCHAR *cmdline, INT show )
37 STARTUPINFOW startup = { sizeof(startup) };
38 PROCESS_INFORMATION info;
39 WCHAR *cmd = cmdline;
40 DWORD exit_code;
42 static WCHAR default_cmd[] = L"cmd";
44 FreeConsole(); /* make sure we're not connected to inherited console */
45 if (!AllocConsole())
47 ERR( "failed to allocate console: %u\n", GetLastError() );
48 return 1;
51 if (!*cmd) cmd = default_cmd;
53 startup.dwFlags = STARTF_USESTDHANDLES;
54 startup.hStdInput = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE, 0, NULL,
55 OPEN_EXISTING, 0, 0 );
56 startup.hStdOutput = CreateFileW( L"CONOUT$", GENERIC_READ | GENERIC_WRITE, 0, NULL,
57 OPEN_EXISTING, 0, 0 );
58 startup.hStdError = startup.hStdOutput;
60 if (!CreateProcessW( NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info ))
62 WCHAR format[256], *buf;
63 INPUT_RECORD ir;
64 DWORD len;
65 exit_code = GetLastError();
66 WARN( "CreateProcess failed: %u\n", exit_code );
67 LoadStringW( GetModuleHandleW( NULL ), IDS_CMD_LAUNCH_FAILED, format, ARRAY_SIZE(format) );
68 len = wcslen( format ) + wcslen( cmd );
69 if ((buf = malloc( len * sizeof(WCHAR) )))
71 swprintf( buf, len, format, cmd );
72 WriteConsoleW( startup.hStdOutput, buf, wcslen(buf), &len, NULL);
73 while (ReadConsoleInputW( startup.hStdInput, &ir, 1, &len ) && ir.EventType == MOUSE_EVENT);
75 return exit_code;
78 CloseHandle( info.hThread );
79 WaitForSingleObject( info.hProcess, INFINITE );
80 return GetExitCodeProcess( info.hProcess, &exit_code ) ? exit_code : GetLastError();