Author: greatlrd Date: Sun May 21 13:21:38 2006 New Revision: 21960
URL: http://svn.reactos.ru/svn/reactos?rev=21960&view=rev Log: patch from w3seek : optimize FindWindowEx and fix passing a NULL window class
Modified: trunk/reactos/dll/win32/user32/windows/window.c trunk/reactos/subsystems/win32/win32k/ntuser/window.c
Modified: trunk/reactos/dll/win32/user32/windows/window.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/dll/win32/user32/windows/win... ============================================================================== --- trunk/reactos/dll/win32/user32/windows/window.c (original) +++ trunk/reactos/dll/win32/user32/windows/window.c Sun May 21 13:21:38 2006 @@ -516,33 +516,51 @@ LPCSTR lpszClass, LPCSTR lpszWindow) { - UNICODE_STRING ucClassName; - UNICODE_STRING ucWindowName; + UNICODE_STRING ucClassName, *pucClassName = NULL; + UNICODE_STRING ucWindowName, *pucWindowName = NULL; HWND Result;
- if (lpszClass == NULL) - { - ucClassName.Buffer = NULL; - ucClassName.Length = 0; - } - else if (IS_ATOM(lpszClass)) + if (IS_ATOM(lpszClass)) { ucClassName.Buffer = (LPWSTR)lpszClass; ucClassName.Length = 0; + pucClassName = &ucClassName; } - else + else if (lpszClass != NULL) { - RtlCreateUnicodeStringFromAsciiz(&ucClassName, (LPSTR)lpszClass); + if (!RtlCreateUnicodeStringFromAsciiz(&ucClassName, + (LPSTR)lpszClass)) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return NULL; + } + pucClassName = &ucClassName; }
- RtlCreateUnicodeStringFromAsciiz(&ucWindowName, (LPSTR)lpszWindow); - - Result = NtUserFindWindowEx(hwndParent, hwndChildAfter, &ucClassName, - &ucWindowName); - - if (!IS_ATOM(lpszClass)) + if (lpszWindow != NULL) + { + if (!RtlCreateUnicodeStringFromAsciiz(&ucWindowName, + (LPSTR)lpszWindow)) + { + if (!IS_ATOM(lpszClass) && lpszClass != NULL) + RtlFreeUnicodeString(&ucWindowName); + + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return NULL; + } + + pucWindowName = &ucWindowName; + } + + Result = NtUserFindWindowEx(hwndParent, + hwndChildAfter, + pucClassName, + pucWindowName); + + if (!IS_ATOM(lpszClass) && lpszClass != NULL) RtlFreeUnicodeString(&ucClassName); - RtlFreeUnicodeString(&ucWindowName); + if (lpszWindow != NULL) + RtlFreeUnicodeString(&ucWindowName);
return Result; } @@ -557,27 +575,33 @@ LPCWSTR lpszClass, LPCWSTR lpszWindow) { - UNICODE_STRING ucClassName; - UNICODE_STRING ucWindowName; - - if (lpszClass == NULL) + UNICODE_STRING ucClassName, *pucClassName = NULL; + UNICODE_STRING ucWindowName, *pucWindowName = NULL; + + if (IS_ATOM(lpszClass)) { - ucClassName.Buffer = NULL; ucClassName.Length = 0; + ucClassName.Buffer = (LPWSTR)lpszClass; + pucClassName = &ucClassName; } - else if (IS_ATOM(lpszClass)) + else if (lpszClass != NULL) { - RtlInitUnicodeString(&ucClassName, NULL); - ucClassName.Buffer = (LPWSTR)lpszClass; + RtlInitUnicodeString(&ucClassName, + lpszClass); + pucClassName = &ucClassName; } - else + + if (lpszWindow != NULL) { - RtlInitUnicodeString(&ucClassName, lpszClass); + RtlInitUnicodeString(&ucWindowName, + lpszWindow); + pucWindowName = &ucWindowName; }
- RtlInitUnicodeString(&ucWindowName, lpszWindow); - - return NtUserFindWindowEx(hwndParent, hwndChildAfter, &ucClassName, &ucWindowName); + return NtUserFindWindowEx(hwndParent, + hwndChildAfter, + pucClassName, + pucWindowName); }
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/window.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/subsystems/win32/win32k/ntus... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/ntuser/window.c (original) +++ trunk/reactos/subsystems/win32/win32k/ntuser/window.c Sun May 21 13:21:38 2006 @@ -2433,60 +2433,63 @@ DPRINT("Enter NtUserFindWindowEx\n"); UserEnterShared();
- _SEH_TRY - { + if (ucClassName != NULL || ucWindowName != NULL) + { + _SEH_TRY + { + if (ucClassName != NULL) + { + ClassName = ProbeForReadUnicodeString(ucClassName); + if (ClassName.Length != 0) + { + ProbeForRead(ClassName.Buffer, + ClassName.Length, + sizeof(WCHAR)); + } + else if (!IS_ATOM(ClassName.Buffer)) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER); + _SEH_LEAVE; + } + + if (!IntGetAtomFromStringOrAtom(&ClassName, + &ClassAtom)) + { + _SEH_LEAVE; + } + } + + if (ucWindowName != NULL) + { + WindowName = ProbeForReadUnicodeString(ucWindowName); + if (WindowName.Length != 0) + { + ProbeForRead(WindowName.Buffer, + WindowName.Length, + sizeof(WCHAR)); + } + } + } + _SEH_HANDLE + { + SetLastNtError(_SEH_GetExceptionCode()); + RETURN(NULL); + } + _SEH_END; + if (ucClassName != NULL) { - ClassName = ProbeForReadUnicodeString(ucClassName); - if (ClassName.Length != 0) - { - ProbeForRead(ClassName.Buffer, - ClassName.Length, - sizeof(WCHAR)); - } - else if (ClassName.Buffer != NULL && !IS_ATOM(ClassName.Buffer)) + if (ClassName.Length == 0 && ClassName.Buffer != NULL && + !IS_ATOM(ClassName.Buffer)) { SetLastWin32Error(ERROR_INVALID_PARAMETER); - _SEH_LEAVE; + RETURN(NULL); } - - if (!IntGetAtomFromStringOrAtom(&ClassName, - &ClassAtom)) + else if (ClassAtom == (RTL_ATOM)0) { - _SEH_LEAVE; + /* LastError code was set by IntGetAtomFromStringOrAtom */ + RETURN(NULL); } - } - - if (ucWindowName != NULL) - { - WindowName = ProbeForReadUnicodeString(ucWindowName); - if (WindowName.Length != 0) - { - ProbeForRead(WindowName.Buffer, - WindowName.Length, - sizeof(WCHAR)); - } - } - } - _SEH_HANDLE - { - SetLastNtError(_SEH_GetExceptionCode()); - RETURN(NULL); - } - _SEH_END; - - if (ucClassName != NULL) - { - if (ClassName.Length == 0 && ClassName.Buffer != NULL && - !IS_ATOM(ClassName.Buffer)) - { - SetLastWin32Error(ERROR_INVALID_PARAMETER); - RETURN(NULL); - } - else if (ClassAtom == (RTL_ATOM)0) - { - /* LastError code was set by IntGetAtomFromStringOrAtom */ - RETURN(NULL); } }