- Implemented DuplicateConsoleHandle.

- Duplicate the error handle in AllocConsole.
- Opening 'CONIN$' for console access in GetConsoleTitleW, SetConsoleTitleW, SetConsoleTitleA.

svn path=/trunk/; revision=4271
This commit is contained in:
Hartmut Birr 2003-03-09 21:37:18 +00:00
parent 95bceebe67
commit bb63ba9048

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.54 2003/03/05 22:51:48 ekohl Exp $ /* $Id: console.c,v 1.55 2003/03/09 21:37:18 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -56,17 +56,35 @@ ConsoleMenuControl (HANDLE hConsole,
return FALSE; return FALSE;
} }
BOOL STDCALL HANDLE STDCALL
DuplicateConsoleHandle (HANDLE hConsole, DuplicateConsoleHandle (HANDLE hConsole,
DWORD Unknown1, DWORD dwDesiredAccess,
DWORD Unknown2, BOOL bInheritHandle,
DWORD Unknown3) DWORD dwOptions)
/*
* Undocumented
*/
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); CSRSS_API_REQUEST Request;
return FALSE; CSRSS_API_REPLY Reply;
NTSTATUS Status;
if (IsConsoleHandle (hConsole) == FALSE)
{
SetLastError (ERROR_INVALID_PARAMETER);
return INVALID_HANDLE_VALUE;
}
Request.Type = CSRSS_DUPLICATE_HANDLE;
Request.Data.DuplicateHandleRequest.Handle = hConsole;
Request.Data.DuplicateHandleRequest.ProcessId = GetCurrentProcessId();
Status = CsrClientCallServer(&Request,
&Reply,
sizeof(CSRSS_API_REQUEST),
sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status=Reply.Status))
{
SetLastErrorByStatus(Status);
return INVALID_HANDLE_VALUE;
}
return Reply.Data.DuplicateHandleReply.Handle;
} }
DWORD STDCALL DWORD STDCALL
@ -838,6 +856,7 @@ WINBOOL STDCALL AllocConsole(VOID)
CSRSS_API_REQUEST Request; CSRSS_API_REQUEST Request;
CSRSS_API_REPLY Reply; CSRSS_API_REPLY Reply;
NTSTATUS Status; NTSTATUS Status;
HANDLE hStdError;
Request.Type = CSRSS_ALLOC_CONSOLE; Request.Type = CSRSS_ALLOC_CONSOLE;
Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) ); Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
@ -848,7 +867,11 @@ WINBOOL STDCALL AllocConsole(VOID)
} }
SetStdHandle( STD_INPUT_HANDLE, Reply.Data.AllocConsoleReply.InputHandle ); SetStdHandle( STD_INPUT_HANDLE, Reply.Data.AllocConsoleReply.InputHandle );
SetStdHandle( STD_OUTPUT_HANDLE, Reply.Data.AllocConsoleReply.OutputHandle ); SetStdHandle( STD_OUTPUT_HANDLE, Reply.Data.AllocConsoleReply.OutputHandle );
SetStdHandle( STD_ERROR_HANDLE, Reply.Data.AllocConsoleReply.OutputHandle ); hStdError = DuplicateConsoleHandle(Reply.Data.AllocConsoleReply.OutputHandle,
0,
TRUE,
DUPLICATE_SAME_ACCESS);
SetStdHandle( STD_ERROR_HANDLE, hStdError );
return TRUE; return TRUE;
} }
@ -2189,19 +2212,27 @@ GetConsoleTitleW(
CSRSS_API_REQUEST Request; CSRSS_API_REQUEST Request;
PCSRSS_API_REPLY Reply; PCSRSS_API_REPLY Reply;
NTSTATUS Status; NTSTATUS Status;
HANDLE hConsole;
hConsole = CreateFileW(L"CONIN$", GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hConsole == INVALID_HANDLE_VALUE)
{
return 0;
}
Reply = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR)); Reply = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
if(Reply == NULL) if(Reply == NULL)
{ {
CloseHandle(hConsole);
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return 0; return 0;
} }
Request.Type = CSRSS_GET_TITLE; Request.Type = CSRSS_GET_TITLE;
Request.Data.GetTitleRequest.ConsoleHandle = GetStdHandle(STD_INPUT_HANDLE); Request.Data.GetTitleRequest.ConsoleHandle = hConsole;
Status = CsrClientCallServer(&Request, Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR)); Status = CsrClientCallServer(&Request, Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
CloseHandle(hConsole);
if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Reply->Status))) if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Reply->Status)))
{ {
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
@ -2280,18 +2311,26 @@ SetConsoleTitleW(
CSRSS_API_REPLY Reply; CSRSS_API_REPLY Reply;
NTSTATUS Status; NTSTATUS Status;
unsigned int c; unsigned int c;
HANDLE hConsole;
hConsole = CreateFileW(L"CONIN$", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hConsole == INVALID_HANDLE_VALUE)
{
return FALSE;
}
Request = RtlAllocateHeap(GetProcessHeap(), Request = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_SET_TITLE_REQUEST); sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_SET_TITLE_REQUEST);
if (Request == NULL) if (Request == NULL)
{ {
CloseHandle(hConsole);
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return(FALSE); return(FALSE);
} }
Request->Type = CSRSS_SET_TITLE; Request->Type = CSRSS_SET_TITLE;
Request->Data.SetTitleRequest.Console = GetStdHandle( STD_INPUT_HANDLE ); Request->Data.SetTitleRequest.Console = hConsole;
for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ ) for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ )
Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c]; Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c];
@ -2303,7 +2342,7 @@ SetConsoleTitleW(
sizeof(CSRSS_API_REQUEST) + sizeof(CSRSS_API_REQUEST) +
c * sizeof(WCHAR), c * sizeof(WCHAR),
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
CloseHandle(hConsole);
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )
{ {
RtlFreeHeap( GetProcessHeap(), 0, Request ); RtlFreeHeap( GetProcessHeap(), 0, Request );
@ -2331,18 +2370,26 @@ SetConsoleTitleA(
CSRSS_API_REPLY Reply; CSRSS_API_REPLY Reply;
NTSTATUS Status; NTSTATUS Status;
unsigned int c; unsigned int c;
HANDLE hConsole;
hConsole = CreateFileW(L"CONIN$", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hConsole == INVALID_HANDLE_VALUE)
{
return FALSE;
}
Request = RtlAllocateHeap(GetProcessHeap(), Request = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_SET_TITLE_REQUEST); sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_SET_TITLE_REQUEST);
if (Request == NULL) if (Request == NULL)
{ {
CloseHandle(hConsole);
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return(FALSE); return(FALSE);
} }
Request->Type = CSRSS_SET_TITLE; Request->Type = CSRSS_SET_TITLE;
Request->Data.SetTitleRequest.Console = GetStdHandle( STD_INPUT_HANDLE ); Request->Data.SetTitleRequest.Console = hConsole;
for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ ) for( c = 0; lpConsoleTitle[c] && c < CSRSS_MAX_TITLE_LENGTH; c++ )
Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c]; Request->Data.SetTitleRequest.Title[c] = lpConsoleTitle[c];
@ -2354,7 +2401,7 @@ SetConsoleTitleA(
sizeof(CSRSS_API_REQUEST) + sizeof(CSRSS_API_REQUEST) +
c * sizeof(WCHAR), c * sizeof(WCHAR),
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
CloseHandle(hConsole);
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )
{ {
RtlFreeHeap( GetProcessHeap(), 0, Request ); RtlFreeHeap( GetProcessHeap(), 0, Request );