Fixed up Get/SetConsoleTitleAW().

svn path=/trunk/; revision=4225
This commit is contained in:
Marty Dill 2003-03-02 01:23:19 +00:00
parent cb819643dd
commit 20a78cdf13

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.52 2003/02/24 23:24:55 hbirr Exp $ /* $Id: console.c,v 1.53 2003/03/02 01:23:19 mdill 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
@ -2144,7 +2144,6 @@ GenerateConsoleCtrlEvent(
/*-------------------------------------------------------------- /*--------------------------------------------------------------
* GetConsoleTitleW * GetConsoleTitleW
*/ */
#define MAX_CONSOLE_TITLE_LENGTH 80
WINBASEAPI WINBASEAPI
DWORD DWORD
@ -2154,60 +2153,43 @@ GetConsoleTitleW(
DWORD nSize DWORD nSize
) )
{ {
union { CSRSS_API_REQUEST Request;
CSRSS_API_REQUEST quest; PCSRSS_API_REPLY Reply;
CSRSS_API_REPLY ply; NTSTATUS Status;
} Re;
NTSTATUS Status; Reply = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
/* Marshall data */ if(Reply == NULL)
Re.quest.Type = CSRSS_GET_TITLE; {
Re.quest.Data.GetTitleRequest.ConsoleHandle = SetLastError(ERROR_OUTOFMEMORY);
GetStdHandle (STD_INPUT_HANDLE); return 0;
}
/* Call CSRSS */
Status = CsrClientCallServer ( Request.Type = CSRSS_GET_TITLE;
& Re.quest, Request.Data.GetTitleRequest.ConsoleHandle = GetStdHandle(STD_INPUT_HANDLE);
& Re.ply,
(sizeof (CSRSS_GET_TITLE_REQUEST) + Status = CsrClientCallServer(&Request, Reply, sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REPLY) + CSRSS_MAX_TITLE_LENGTH * sizeof(WCHAR));
sizeof (LPC_MESSAGE) + if(!NT_SUCCESS(Status) || !(NT_SUCCESS(Status = Reply->Status)))
sizeof (ULONG)), {
sizeof (CSRSS_API_REPLY) SetLastErrorByStatus(Status);
); RtlFreeHeap(GetProcessHeap(), 0, Reply);
if ( !NT_SUCCESS(Status) return 0;
|| !NT_SUCCESS (Status = Re.ply.Status) }
)
{ if(nSize * sizeof(WCHAR) < Reply->Data.GetTitleReply.Length)
SetLastErrorByStatus (Status); {
return (0); wcsncpy(lpConsoleTitle, Reply->Data.GetTitleReply.Title, nSize - 1);
} lpConsoleTitle[nSize--] = L'\0';
}
/* Convert size in characters to size in bytes */ else
nSize = sizeof (WCHAR) * nSize; {
nSize = Reply->Data.GetTitleReply.Length / sizeof (WCHAR);
/* Unmarshall data */ wcscpy(lpConsoleTitle, Reply->Data.GetTitleReply.Title);
if (nSize < Re.ply.Data.GetTitleReply.Length) lpConsoleTitle[nSize] = L'\0';
{ }
DbgPrint ("%s: ret=%d\n", __FUNCTION__, Re.ply.Data.GetTitleReply.Length);
nSize /= sizeof (WCHAR); RtlFreeHeap(GetProcessHeap(), 0, Reply);
if (nSize > 1) return nSize;
{
wcsncpy (
lpConsoleTitle,
Re.ply.Data.GetTitleReply.Title,
(nSize - 1)
);
/* Add null */
lpConsoleTitle [nSize --] = L'\0';
}
}
else
{
nSize = Re.ply.Data.GetTitleReply.Length / sizeof (WCHAR);
wcscpy (lpConsoleTitle, Re.ply.Data.GetTitleReply.Title);
}
return nSize;
} }
@ -2224,14 +2206,14 @@ GetConsoleTitleA(
DWORD nSize DWORD nSize
) )
{ {
wchar_t WideTitle [MAX_CONSOLE_TITLE_LENGTH]; wchar_t WideTitle [CSRSS_MAX_TITLE_LENGTH];
DWORD nWideTitle = sizeof WideTitle; DWORD nWideTitle = sizeof WideTitle;
// DWORD nWritten; DWORD nWritten;
if (!lpConsoleTitle || !nSize) return 0; if (!lpConsoleTitle || !nSize) return 0;
nWideTitle = GetConsoleTitleW( (LPWSTR) WideTitle, nWideTitle ); nWideTitle = GetConsoleTitleW( (LPWSTR) WideTitle, nWideTitle );
if (!nWideTitle) return 0; if (!nWideTitle) return 0;
#if 0
if ( (nWritten = WideCharToMultiByte( if ( (nWritten = WideCharToMultiByte(
CP_ACP, // ANSI code page CP_ACP, // ANSI code page
0, // performance and mapping flags 0, // performance and mapping flags
@ -2246,7 +2228,7 @@ GetConsoleTitleA(
lpConsoleTitle[nWritten] = '\0'; lpConsoleTitle[nWritten] = '\0';
return nWritten; return nWritten;
} }
#endif
return 0; return 0;
} }
@ -2285,10 +2267,8 @@ SetConsoleTitleW(
Request->Data.SetTitleRequest.Length = c; Request->Data.SetTitleRequest.Length = c;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(Request,
&Reply, &Reply,
sizeof(CSRSS_SET_TITLE_REQUEST) + sizeof(CSRSS_API_REQUEST) +
c + c * sizeof(WCHAR),
sizeof( LPC_MESSAGE ) +
sizeof( ULONG ),
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )
@ -2338,10 +2318,8 @@ SetConsoleTitleA(
Request->Data.SetTitleRequest.Length = c; Request->Data.SetTitleRequest.Length = c;
Status = CsrClientCallServer(Request, Status = CsrClientCallServer(Request,
&Reply, &Reply,
sizeof(CSRSS_SET_TITLE_REQUEST) + sizeof(CSRSS_API_REQUEST) +
c + c * sizeof(WCHAR),
sizeof( LPC_MESSAGE ) +
sizeof( ULONG ),
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) ) if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )