From 8a2b9285a74e7fe19f8f06feb4bf014f145e7267 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Wed, 11 Jun 2008 09:05:39 +0000 Subject: [PATCH] - Revert 33689 as breaking mIRC installation. See issue #3328 for more details. svn path=/trunk/; revision=33928 --- reactos/dll/win32/user32/windows/class.c | 70 +++------- reactos/include/reactos/win32k/ntuser.h | 11 +- .../subsystems/win32/win32k/ntuser/class.c | 126 ++++++++++++++---- 3 files changed, 127 insertions(+), 80 deletions(-) diff --git a/reactos/dll/win32/user32/windows/class.c b/reactos/dll/win32/user32/windows/class.c index 93d3f26c5d0..f3b9004c659 100644 --- a/reactos/dll/win32/user32/windows/class.c +++ b/reactos/dll/win32/user32/windows/class.c @@ -421,22 +421,15 @@ GetClassNameA( LPSTR lpClassName, int nMaxCount) { - UNICODE_STRING ClassName; - INT Result; + ANSI_STRING ClassName; + int Result; - ClassName.MaximumLength = nMaxCount * sizeof(WCHAR); - ClassName.Buffer = LocalAlloc(LMEM_FIXED, ClassName.MaximumLength); - if (ClassName.Buffer == NULL) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return 0; - } + ClassName.MaximumLength = nMaxCount; + ClassName.Buffer = lpClassName; - Result = NtUserGetClassName(hWnd, FALSE, &ClassName); - - WideCharToMultiByte(CP_ACP, 0, ClassName.Buffer, Result, lpClassName, nMaxCount - 1, NULL, NULL); - lpClassName[nMaxCount - 1] = '\0'; - LocalFree(ClassName.Buffer); + Result = NtUserGetClassName(hWnd, + (PUNICODE_STRING)&ClassName, + TRUE); TRACE("%p class/atom: %s/%04x %x\n", hWnd, IS_ATOM(lpClassName) ? NULL : lpClassName, @@ -463,7 +456,9 @@ GetClassNameW( ClassName.MaximumLength = nMaxCount * sizeof(WCHAR); ClassName.Buffer = lpClassName; - Result = NtUserGetClassName(hWnd, FALSE, &ClassName); + Result = NtUserGetClassName(hWnd, + &ClassName, + FALSE); TRACE("%p class/atom: %S/%04x %x\n", hWnd, IS_ATOM(lpClassName) ? NULL : lpClassName, @@ -634,24 +629,12 @@ SetWindowWord ( HWND hWnd,int nIndex,WORD wNewWord ) UINT STDCALL RealGetWindowClassW( - HWND hWnd, + HWND hwnd, LPWSTR pszType, UINT cchType) { - UNICODE_STRING ClassName; - UINT Length; - - ClassName.MaximumLength = cchType * sizeof(WCHAR); - ClassName.Buffer = pszType; - - Length = NtUserGetClassName(hWnd, TRUE, &ClassName); - - TRACE("%p class/atom: %S/%04x %x\n", hWnd, - IS_ATOM(pszType) ? NULL : pszType, - IS_ATOM(pszType) ? pszType : 0, - cchType); - - return Length; + /* FIXME: Implement correct functionality of RealGetWindowClass */ + return GetClassNameW(hwnd,pszType,cchType); } @@ -661,33 +644,12 @@ RealGetWindowClassW( UINT STDCALL RealGetWindowClassA( - HWND hWnd, + HWND hwnd, LPSTR pszType, UINT cchType) { - UNICODE_STRING ClassName; - UINT Length; - - ClassName.MaximumLength = cchType * sizeof(WCHAR); - ClassName.Buffer = LocalAlloc(LMEM_FIXED, ClassName.MaximumLength); - if (ClassName.Buffer == NULL) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return 0; - } - - Length = NtUserGetClassName(hWnd, TRUE, &ClassName); - - WideCharToMultiByte(CP_ACP, 0, ClassName.Buffer, Length, pszType, cchType - 1, NULL, NULL); - pszType[cchType - 1] = '\0'; - LocalFree(ClassName.Buffer); - - TRACE("%p class/atom: %s/%04x %x\n", hWnd, - IS_ATOM(pszType) ? NULL : pszType, - IS_ATOM(pszType) ? pszType : 0, - cchType); - - return Length; + /* FIXME: Implement correct functionality of RealGetWindowClass */ + return GetClassNameA(hwnd,pszType,cchType); } /* diff --git a/reactos/include/reactos/win32k/ntuser.h b/reactos/include/reactos/win32k/ntuser.h index c4c7ffa08c5..cd4e2977478 100644 --- a/reactos/include/reactos/win32k/ntuser.h +++ b/reactos/include/reactos/win32k/ntuser.h @@ -1255,11 +1255,18 @@ NtUserGetClassInfo(HINSTANCE hInstance, LPWSTR *ppszMenuName, BOOL Ansi); -UINT +INT NTAPI NtUserGetClassName(HWND hWnd, - BOOL bGetRealClass, // 0 GetClassNameA/W, 1 RealGetWindowClassA/W + PUNICODE_STRING ClassName, + BOOL Ansi); +#if 0 // Real NtUserGetClassName +INT +NTAPI +NtUserGetClassName(HWND hWnd, + BOOL Unknown, // 0 GetClassNameW, 1 RealGetWindowClassA/W PUNICODE_STRING ClassName); +#endif HANDLE NTAPI diff --git a/reactos/subsystems/win32/win32k/ntuser/class.c b/reactos/subsystems/win32/win32k/ntuser/class.c index ca77a300bab..953cfc81e05 100644 --- a/reactos/subsystems/win32/win32k/ntuser/class.c +++ b/reactos/subsystems/win32/win32k/ntuser/class.c @@ -1264,33 +1264,107 @@ UserUnregisterClass(IN PUNICODE_STRING ClassName, INT UserGetClassName(IN PWINDOWCLASS Class, - IN OUT PUNICODE_STRING ClassName) + IN OUT PUNICODE_STRING ClassName, + IN BOOL Ansi) { NTSTATUS Status = STATUS_SUCCESS; - ULONG BufLen; + WCHAR szStaticTemp[32]; + PWSTR szTemp = NULL; + ULONG BufLen = sizeof(szStaticTemp); INT Ret = 0; /* Note: Accessing the buffer in ClassName may raise an exception! */ _SEH_TRY { - BufLen = ClassName->MaximumLength; - - /* query the atom name */ - Status = RtlQueryAtomInAtomTable(gAtomTable, - Class->Atom, - NULL, - NULL, - ClassName->Buffer, - &BufLen); - - if (!NT_SUCCESS(Status)) + if (Ansi) { - SetLastNtError(Status); - _SEH_LEAVE; - } + PANSI_STRING AnsiClassName = (PANSI_STRING)ClassName; + UNICODE_STRING UnicodeClassName; - Ret = BufLen / sizeof(WCHAR); + /* limit the size of the static buffer on the stack to the + size of the buffer provided by the caller */ + if (BufLen / sizeof(WCHAR) > AnsiClassName->MaximumLength) + { + BufLen = AnsiClassName->MaximumLength * sizeof(WCHAR); + } + + /* find out how big the buffer needs to be */ + Status = RtlQueryAtomInAtomTable(gAtomTable, + Class->Atom, + NULL, + NULL, + szStaticTemp, + &BufLen); + if (Status == STATUS_BUFFER_TOO_SMALL) + { + if (BufLen / sizeof(WCHAR) > AnsiClassName->MaximumLength) + { + /* the buffer required exceeds the ansi buffer provided, + pretend like we're using the ansi buffer and limit the + size to the buffer size provided */ + BufLen = AnsiClassName->MaximumLength * sizeof(WCHAR); + } + + /* allocate a temporary buffer that can hold the unicode class name */ + szTemp = ExAllocatePool(PagedPool, + BufLen); + if (szTemp == NULL) + { + SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY); + _SEH_LEAVE; + } + + /* query the class name */ + Status = RtlQueryAtomInAtomTable(gAtomTable, + Class->Atom, + NULL, + NULL, + szTemp, + &BufLen); + } + else + szTemp = szStaticTemp; + + if (NT_SUCCESS(Status)) + { + /* convert the atom name to ansi */ + + RtlInitUnicodeString(&UnicodeClassName, + szTemp); + + Status = RtlUnicodeStringToAnsiString(AnsiClassName, + &UnicodeClassName, + FALSE); + if (!NT_SUCCESS(Status)) + { + SetLastNtError(Status); + _SEH_LEAVE; + } + } + + Ret = BufLen / sizeof(WCHAR); + } + else /* !Ansi */ + { + BufLen = ClassName->MaximumLength; + + /* query the atom name */ + Status = RtlQueryAtomInAtomTable(gAtomTable, + Class->Atom, + NULL, + NULL, + ClassName->Buffer, + &BufLen); + + if (!NT_SUCCESS(Status)) + { + SetLastNtError(Status); + _SEH_LEAVE; + } + + Ret = BufLen / sizeof(WCHAR); + } } _SEH_HANDLE { @@ -1298,6 +1372,11 @@ UserGetClassName(IN PWINDOWCLASS Class, } _SEH_END; + if (Ansi && szTemp != NULL && szTemp != szStaticTemp) + { + ExFreePool(szTemp); + } + return Ret; } @@ -2195,10 +2274,10 @@ Cleanup: -UINT NTAPI -NtUserGetClassName(IN HWND hWnd, - IN BOOL bGetRealClass, // 0 GetClassNameA/W, 1 RealGetWindowClassA/W - OUT PUNICODE_STRING ClassName) +INT NTAPI +NtUserGetClassName (IN HWND hWnd, + OUT PUNICODE_STRING ClassName, + IN BOOL Ansi) { PWINDOW_OBJECT Window; UNICODE_STRING CapturedClassName; @@ -2214,11 +2293,10 @@ NtUserGetClassName(IN HWND hWnd, ProbeForWriteUnicodeString(ClassName); CapturedClassName = *ClassName; - /* TODO: Get real class name here if bGetRealClass == TRUE */ - /* get the class name */ Ret = UserGetClassName(Window->Wnd->Class, - &CapturedClassName); + &CapturedClassName, + Ansi); if (Ret != 0) {