diff --git a/reactos/dll/win32/user32/windows/class.c b/reactos/dll/win32/user32/windows/class.c index f3b9004c659..93d3f26c5d0 100644 --- a/reactos/dll/win32/user32/windows/class.c +++ b/reactos/dll/win32/user32/windows/class.c @@ -421,15 +421,22 @@ GetClassNameA( LPSTR lpClassName, int nMaxCount) { - ANSI_STRING ClassName; - int Result; + UNICODE_STRING ClassName; + INT Result; - ClassName.MaximumLength = nMaxCount; - ClassName.Buffer = lpClassName; + ClassName.MaximumLength = nMaxCount * sizeof(WCHAR); + ClassName.Buffer = LocalAlloc(LMEM_FIXED, ClassName.MaximumLength); + if (ClassName.Buffer == NULL) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } - Result = NtUserGetClassName(hWnd, - (PUNICODE_STRING)&ClassName, - TRUE); + Result = NtUserGetClassName(hWnd, FALSE, &ClassName); + + WideCharToMultiByte(CP_ACP, 0, ClassName.Buffer, Result, lpClassName, nMaxCount - 1, NULL, NULL); + lpClassName[nMaxCount - 1] = '\0'; + LocalFree(ClassName.Buffer); TRACE("%p class/atom: %s/%04x %x\n", hWnd, IS_ATOM(lpClassName) ? NULL : lpClassName, @@ -456,9 +463,7 @@ GetClassNameW( ClassName.MaximumLength = nMaxCount * sizeof(WCHAR); ClassName.Buffer = lpClassName; - Result = NtUserGetClassName(hWnd, - &ClassName, - FALSE); + Result = NtUserGetClassName(hWnd, FALSE, &ClassName); TRACE("%p class/atom: %S/%04x %x\n", hWnd, IS_ATOM(lpClassName) ? NULL : lpClassName, @@ -629,12 +634,24 @@ SetWindowWord ( HWND hWnd,int nIndex,WORD wNewWord ) UINT STDCALL RealGetWindowClassW( - HWND hwnd, + HWND hWnd, LPWSTR pszType, UINT cchType) { - /* FIXME: Implement correct functionality of RealGetWindowClass */ - return GetClassNameW(hwnd,pszType,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; } @@ -644,12 +661,33 @@ RealGetWindowClassW( UINT STDCALL RealGetWindowClassA( - HWND hwnd, + HWND hWnd, LPSTR pszType, UINT cchType) { - /* FIXME: Implement correct functionality of RealGetWindowClass */ - return GetClassNameA(hwnd,pszType,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; } /* diff --git a/reactos/include/reactos/win32k/ntuser.h b/reactos/include/reactos/win32k/ntuser.h index 6fea2eec45e..e1e4b430ecc 100644 --- a/reactos/include/reactos/win32k/ntuser.h +++ b/reactos/include/reactos/win32k/ntuser.h @@ -1160,18 +1160,11 @@ NtUserGetClassInfo(HINSTANCE hInstance, LPWSTR *ppszMenuName, BOOL Ansi); -INT +UINT NTAPI NtUserGetClassName(HWND hWnd, - PUNICODE_STRING ClassName, - BOOL Ansi); -#if 0 // Real NtUserGetClassName -INT -NTAPI -NtUserGetClassName(HWND hWnd, - BOOL Unknown, // 0 GetClassNameW, 1 RealGetWindowClassA/W + BOOL bGetRealClass, // 0 GetClassNameA/W, 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 3b399a7a388..be3394b548e 100644 --- a/reactos/subsystems/win32/win32k/ntuser/class.c +++ b/reactos/subsystems/win32/win32k/ntuser/class.c @@ -1255,107 +1255,33 @@ UserUnregisterClass(IN PUNICODE_STRING ClassName, INT UserGetClassName(IN PWINDOWCLASS Class, - IN OUT PUNICODE_STRING ClassName, - IN BOOL Ansi) + IN OUT PUNICODE_STRING ClassName) { NTSTATUS Status = STATUS_SUCCESS; - WCHAR szStaticTemp[32]; - PWSTR szTemp = NULL; - ULONG BufLen = sizeof(szStaticTemp); + ULONG BufLen; INT Ret = 0; /* Note: Accessing the buffer in ClassName may raise an exception! */ _SEH_TRY { - if (Ansi) + BufLen = ClassName->MaximumLength; + + /* query the atom name */ + Status = RtlQueryAtomInAtomTable(gAtomTable, + Class->Atom, + NULL, + NULL, + ClassName->Buffer, + &BufLen); + + if (!NT_SUCCESS(Status)) { - PANSI_STRING AnsiClassName = (PANSI_STRING)ClassName; - UNICODE_STRING UnicodeClassName; - - /* 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); + SetLastNtError(Status); + _SEH_LEAVE; } - 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); - } + Ret = BufLen / sizeof(WCHAR); } _SEH_HANDLE { @@ -1363,11 +1289,6 @@ UserGetClassName(IN PWINDOWCLASS Class, } _SEH_END; - if (Ansi && szTemp != NULL && szTemp != szStaticTemp) - { - ExFreePool(szTemp); - } - return Ret; } @@ -2265,10 +2186,10 @@ Cleanup: -INT NTAPI -NtUserGetClassName (IN HWND hWnd, - OUT PUNICODE_STRING ClassName, - IN BOOL Ansi) +UINT NTAPI +NtUserGetClassName(IN HWND hWnd, + IN BOOL bGetRealClass, // 0 GetClassNameA/W, 1 RealGetWindowClassA/W + OUT PUNICODE_STRING ClassName) { PWINDOW_OBJECT Window; UNICODE_STRING CapturedClassName; @@ -2284,10 +2205,11 @@ 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, - Ansi); + &CapturedClassName); if (Ret != 0) {