* Changed to correct signature of NtUserGetClassName()

* Implemented correct behaviour in GetRealWindowClass(), but in reality just shifted the todo parts to NtUserGetClassName() instead.

svn path=/trunk/; revision=33689
This commit is contained in:
Gregor Brunmar 2008-05-25 08:36:30 +00:00
parent 61350d2a48
commit 21f3bde4eb
3 changed files with 79 additions and 126 deletions

View file

@ -421,15 +421,22 @@ GetClassNameA(
LPSTR lpClassName, LPSTR lpClassName,
int nMaxCount) int nMaxCount)
{ {
ANSI_STRING ClassName; UNICODE_STRING ClassName;
int Result; INT Result;
ClassName.MaximumLength = nMaxCount; ClassName.MaximumLength = nMaxCount * sizeof(WCHAR);
ClassName.Buffer = lpClassName; ClassName.Buffer = LocalAlloc(LMEM_FIXED, ClassName.MaximumLength);
if (ClassName.Buffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
Result = NtUserGetClassName(hWnd, Result = NtUserGetClassName(hWnd, FALSE, &ClassName);
(PUNICODE_STRING)&ClassName,
TRUE); 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, TRACE("%p class/atom: %s/%04x %x\n", hWnd,
IS_ATOM(lpClassName) ? NULL : lpClassName, IS_ATOM(lpClassName) ? NULL : lpClassName,
@ -456,9 +463,7 @@ GetClassNameW(
ClassName.MaximumLength = nMaxCount * sizeof(WCHAR); ClassName.MaximumLength = nMaxCount * sizeof(WCHAR);
ClassName.Buffer = lpClassName; ClassName.Buffer = lpClassName;
Result = NtUserGetClassName(hWnd, Result = NtUserGetClassName(hWnd, FALSE, &ClassName);
&ClassName,
FALSE);
TRACE("%p class/atom: %S/%04x %x\n", hWnd, TRACE("%p class/atom: %S/%04x %x\n", hWnd,
IS_ATOM(lpClassName) ? NULL : lpClassName, IS_ATOM(lpClassName) ? NULL : lpClassName,
@ -629,12 +634,24 @@ SetWindowWord ( HWND hWnd,int nIndex,WORD wNewWord )
UINT UINT
STDCALL STDCALL
RealGetWindowClassW( RealGetWindowClassW(
HWND hwnd, HWND hWnd,
LPWSTR pszType, LPWSTR pszType,
UINT cchType) UINT cchType)
{ {
/* FIXME: Implement correct functionality of RealGetWindowClass */ UNICODE_STRING ClassName;
return GetClassNameW(hwnd,pszType,cchType); 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 UINT
STDCALL STDCALL
RealGetWindowClassA( RealGetWindowClassA(
HWND hwnd, HWND hWnd,
LPSTR pszType, LPSTR pszType,
UINT cchType) UINT cchType)
{ {
/* FIXME: Implement correct functionality of RealGetWindowClass */ UNICODE_STRING ClassName;
return GetClassNameA(hwnd,pszType,cchType); 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;
} }
/* /*

View file

@ -1160,18 +1160,11 @@ NtUserGetClassInfo(HINSTANCE hInstance,
LPWSTR *ppszMenuName, LPWSTR *ppszMenuName,
BOOL Ansi); BOOL Ansi);
INT UINT
NTAPI NTAPI
NtUserGetClassName(HWND hWnd, NtUserGetClassName(HWND hWnd,
PUNICODE_STRING ClassName, BOOL bGetRealClass, // 0 GetClassNameA/W, 1 RealGetWindowClassA/W
BOOL Ansi);
#if 0 // Real NtUserGetClassName
INT
NTAPI
NtUserGetClassName(HWND hWnd,
BOOL Unknown, // 0 GetClassNameW, 1 RealGetWindowClassA/W
PUNICODE_STRING ClassName); PUNICODE_STRING ClassName);
#endif
HANDLE HANDLE
NTAPI NTAPI

View file

@ -1255,88 +1255,15 @@ UserUnregisterClass(IN PUNICODE_STRING ClassName,
INT INT
UserGetClassName(IN PWINDOWCLASS Class, UserGetClassName(IN PWINDOWCLASS Class,
IN OUT PUNICODE_STRING ClassName, IN OUT PUNICODE_STRING ClassName)
IN BOOL Ansi)
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
WCHAR szStaticTemp[32]; ULONG BufLen;
PWSTR szTemp = NULL;
ULONG BufLen = sizeof(szStaticTemp);
INT Ret = 0; INT Ret = 0;
/* Note: Accessing the buffer in ClassName may raise an exception! */ /* Note: Accessing the buffer in ClassName may raise an exception! */
_SEH_TRY _SEH_TRY
{
if (Ansi)
{
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);
}
else /* !Ansi */
{ {
BufLen = ClassName->MaximumLength; BufLen = ClassName->MaximumLength;
@ -1356,18 +1283,12 @@ UserGetClassName(IN PWINDOWCLASS Class,
Ret = BufLen / sizeof(WCHAR); Ret = BufLen / sizeof(WCHAR);
} }
}
_SEH_HANDLE _SEH_HANDLE
{ {
SetLastNtError(_SEH_GetExceptionCode()); SetLastNtError(_SEH_GetExceptionCode());
} }
_SEH_END; _SEH_END;
if (Ansi && szTemp != NULL && szTemp != szStaticTemp)
{
ExFreePool(szTemp);
}
return Ret; return Ret;
} }
@ -2265,10 +2186,10 @@ Cleanup:
INT NTAPI UINT NTAPI
NtUserGetClassName (IN HWND hWnd, NtUserGetClassName(IN HWND hWnd,
OUT PUNICODE_STRING ClassName, IN BOOL bGetRealClass, // 0 GetClassNameA/W, 1 RealGetWindowClassA/W
IN BOOL Ansi) OUT PUNICODE_STRING ClassName)
{ {
PWINDOW_OBJECT Window; PWINDOW_OBJECT Window;
UNICODE_STRING CapturedClassName; UNICODE_STRING CapturedClassName;
@ -2284,10 +2205,11 @@ NtUserGetClassName (IN HWND hWnd,
ProbeForWriteUnicodeString(ClassName); ProbeForWriteUnicodeString(ClassName);
CapturedClassName = *ClassName; CapturedClassName = *ClassName;
/* TODO: Get real class name here if bGetRealClass == TRUE */
/* get the class name */ /* get the class name */
Ret = UserGetClassName(Window->Wnd->Class, Ret = UserGetClassName(Window->Wnd->Class,
&CapturedClassName, &CapturedClassName);
Ansi);
if (Ret != 0) if (Ret != 0)
{ {