42 static BOOL AlreadyDisplayingProps =
FALSE;
52 if (lpThreadParameter)
58 AlreadyDisplayingProps =
TRUE;
62 wcscat(szBuffer,
L"\\console.dll");
64 if (hConsoleApplet ==
NULL)
66 DPRINT1(
"Failed to load console.dll\n");
75 DPRINT1(
"Error: console.dll misses CPlApplet export\n");
83 DPRINT1(
"Error: failed to initialize console.dll\n");
91 DPRINT1(
"Error: console.dll returned unexpected CPL count\n");
108 AlreadyDisplayingProps =
FALSE;
117 DPRINT(
"ParseShellInfo is UNIMPLEMENTED\n");
147 ConsoleStartInfo->IconIndex = 0;
148 ConsoleStartInfo->hIcon =
NULL;
149 ConsoleStartInfo->hIconSm =
NULL;
150 ConsoleStartInfo->dwStartupFlags =
Parameters->WindowFlags;
151 ConsoleStartInfo->nFont = 0;
152 ConsoleStartInfo->nInputBufferSize = 0;
153 ConsoleStartInfo->uCodePage =
GetOEMCP();
210 if (lpDesktop) *lpDesktop =
NULL;
215 ConsoleStartInfo->wFillAttribute = (
WORD)
Parameters->FillAttribute;
219 ConsoleStartInfo->dwScreenBufferSize.X = (
SHORT)
Parameters->CountCharsX;
220 ConsoleStartInfo->dwScreenBufferSize.Y = (
SHORT)
Parameters->CountCharsY;
224 ConsoleStartInfo->wShowWindow = (
WORD)
Parameters->ShowWindowFlags;
259 if (ConsoleStartInfo->dwStartupFlags & STARTF_SHELLPRIVATE)
261 Parameters->WindowFlags &= ~STARTF_SHELLPRIVATE;
265 Parameters->ConsoleHandle = ConsoleStartInfo->ConsoleHandle;
269 Parameters->StandardInput = ConsoleStartInfo->InputHandle;
270 Parameters->StandardOutput = ConsoleStartInfo->OutputHandle;
271 Parameters->StandardError = ConsoleStartInfo->ErrorHandle;
291 ULONG ConnectInfoSize =
sizeof(*ConnectInfo);
296 DPRINT(
"Connecting to the Console Server...\n");
304 DPRINT1(
"Failed to connect to the Console Server (Status %lx)\n",
Status);
309 if (*InServerProcess)
return TRUE;
312 if (!ConnectInfo->IsConsoleApp)
return TRUE;
317 ConnectInfo->ConsoleStartInfo.InitEvents,
345 ULONG cbInfo, cbResult;
359 pInfo, cbInfo, &cbResult);
385 cchLen =
wcslen(pszPath) + 1;
386 if (cchLen + 2 > cchPathMax)
391 pszPath[cchLen] =
L'"';
401 for (ich = 0; pszPath[ich]; ++ich)
403 if (pszPath[ich] ==
L'/')
404 pszPath[ich] =
L'\\';
423 static const PCWSTR ConsoleKey =
424 L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console";
427 if (cchSysDir > 0 && cchSysDir <
cchBuffer - 1)
460 DPRINT(
"ConsoleIME: '%S'\n", pszBuffer);
496 DWORD dwCreationFlags;
508 hStartUpEvent =
NULL;
518 si.lpDesktop =
NtCurrentPeb()->ProcessParameters->DesktopInfo.Buffer;
539 DPRINT1(
"'%S' startup failed: 0x%08X\n", szCommandLine, dwError);
578 DPRINT(
"ConDllInitialize for: %wZ\n"
579 "Our current console handles are: 0x%p, 0x%p, 0x%p 0x%p\n",
599 DPRINT(
"Image is not a console application\n");
608 DPRINT(
"No console to create\n");
620 DPRINT(
"Creating a new separate console\n");
630 DPRINT(
"Creating a new invisible console\n");
678 DPRINT(
"ConsoleTitle = '%S' - Desktop = '%S'\n",
679 ConsoleTitle, ConnectInfo.
Desktop);
703 DPRINT(
"CurDir = '%S' - AppName = '%S'\n",
740 DPRINT(
"Console setup: 0x%p, 0x%p, 0x%p, 0x%p\n",
#define InterlockedExchange
#define CONSRV_SERVERDLL_INDEX
LONG(APIENTRY * APPLET_PROC)(HWND, UINT, LPARAM, LPARAM)
PIMAGE_NT_HEADERS WINAPI ImageNtHeader(_In_ PVOID)
static CHAR AppName[MAX_PATH]
#define NT_SUCCESS(StatCode)
static const WCHAR Title[]
#define DLL_PROCESS_ATTACH
#define DLL_PROCESS_DETACH
#define GetProcAddress(x, y)
#define HeapFree(x, y, z)
#define DLL_THREAD_ATTACH
DWORD WINAPI ConsoleControlDispatcher(IN LPVOID lpThreadParameter)
VOID SetTEBLangID(VOID)
Internal helper function used to synchronize the current thread's language ID with the one from the c...
VOID InitializeCtrlHandling(VOID)
VOID SetUpAppName(IN BOOLEAN CaptureStrings, IN OUT LPDWORD CurDirLength, IN OUT LPWSTR *CurDir, IN OUT LPDWORD AppNameLength, IN OUT LPWSTR *AppName)
static INT ParseShellInfo(LPCWSTR lpszShellInfo, LPCWSTR lpszKeyword)
static const PWSTR DefaultConsoleTitle
DWORD WINAPI PropDialogHandler(IN LPVOID lpThreadParameter)
VOID SetUpConsoleInfo(IN BOOLEAN CaptureTitle, IN OUT LPDWORD pTitleLength, IN OUT LPWSTR *lpTitle OPTIONAL, IN OUT LPDWORD pDesktopLength, IN OUT LPWSTR *lpDesktop OPTIONAL, IN OUT PCONSOLE_START_INFO ConsoleStartInfo)
static NTSTATUS IntPathQuoteSpacesW(_Inout_updates_z_(cchPathMax) PWSTR pszPath, _In_ UINT cchPathMax)
RTL_CRITICAL_SECTION ConsoleLock
static NTSTATUS IntRegQueryValue(_In_ HANDLE hKey, _In_ PCWSTR pszValueName, _Out_ PVOID pvValue, _In_ ULONG cbValue)
static BOOL IntIsSafeRelativePath(_Inout_z_ PWSTR pszPath)
static BOOLEAN ConnectConsole(IN PWSTR SessionDir, IN PCONSRV_API_CONNECTINFO ConnectInfo, OUT PBOOLEAN InServerProcess)
DWORD WINAPI ConsoleIMERoutine(_In_ PVOID unused)
This function is called from winsrv.dll, in the context of the console application,...
BOOLEAN WINAPI ConDllInitialize(IN ULONG Reason, IN PWSTR SessionDir)
static volatile LONG g_bConsoleIMEStartingUp
VOID SetUpHandles(IN PCONSOLE_START_INFO ConsoleStartInfo)
static VOID GetConsoleIMECommandLine(_Out_ PWSTR pszBuffer, _In_ UINT cchBuffer)
static BOOLEAN IsConsoleApp(VOID)
BOOLEAN ConsoleInitialized
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
#define HANDLE_CREATE_NEW_CONSOLE
#define HANDLE_CREATE_NO_WINDOW
#define HANDLE_DETACHED_PROCESS
UINT WINAPI GetOEMCP(void)
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
_ACRTIMP wchar_t *__cdecl wcsstr(const wchar_t *, const wchar_t *)
#define InterlockedCompareExchange
#define ERROR_ALREADY_EXISTS
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
static PROCESS_INFORMATION pi
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define _Inout_updates_z_(s)
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
@ KeyValuePartialInformation
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
#define UNREFERENCED_PARAMETER(P)
_In_ ULONG _In_ ULONG _In_ ULONG Length
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
NTSTRSAFEAPI RtlStringCchCopyW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
NTSTRSAFEAPI RtlStringCchCatW(_Inout_updates_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
NTSTATUS NTAPI NtWaitForMultipleObjects(IN ULONG ObjectCount, IN PHANDLE HandleArray, IN WAIT_TYPE WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER TimeOut OPTIONAL)
#define OBJ_CASE_INSENSITIVE
DWORD BaseSetLastNTError(IN NTSTATUS Status)
NTSTATUS NTAPI CsrClientConnectToServer(_In_ PCWSTR ObjectDirectory, _In_ ULONG ServerId, _In_ PVOID ConnectionInfo, _Inout_ PULONG ConnectionInfoSize, _Out_ PBOOLEAN ServerToServerCall)
#define STATUS_BUFFER_TOO_SMALL
PULONG MinorVersion OPTIONAL
WCHAR ConsoleTitle[MAX_PATH+1]
LPTHREAD_START_ROUTINE PropRoutine
LPTHREAD_START_ROUTINE ImeRoutine
CONSOLE_START_INFO ConsoleStartInfo
LPTHREAD_START_ROUTINE CtrlRoutine
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
#define FIELD_OFFSET(t, f)
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define RtlMoveMemory(Destination, Source, Length)
#define STATUS_UNSUCCESSFUL
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
#define NORMAL_PRIORITY_CLASS
#define STARTF_USEPOSITION
#define CREATE_BREAKAWAY_FROM_JOB
DWORD WINAPI GetLastError(void)
#define STARTF_USESHOWWINDOW
#define STARTF_USECOUNTCHARS
#define STARTF_USEFILLATTRIBUTE
#define CREATE_DEFAULT_ERROR_MODE
#define CREATE_NEW_PROCESS_GROUP
#define STARTF_USESTDHANDLES
#define STARTF_FORCEONFEEDBACK