patch from w3seek : optimize FindWindowEx and fix passing a NULL window class

svn path=/trunk/; revision=21960
This commit is contained in:
Magnus Olsen
2006-05-21 09:21:38 +00:00
parent 2d54ed6453
commit 0e3e95794f
2 changed files with 100 additions and 73 deletions
+51 -27
View File
@@ -516,33 +516,51 @@ FindWindowExA(HWND hwndParent,
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);
if (lpszWindow != NULL)
{
if (!RtlCreateUnicodeStringFromAsciiz(&ucWindowName,
(LPSTR)lpszWindow))
{
if (!IS_ATOM(lpszClass) && lpszClass != NULL)
RtlFreeUnicodeString(&ucWindowName);
Result = NtUserFindWindowEx(hwndParent, hwndChildAfter, &ucClassName,
&ucWindowName);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
if (!IS_ATOM(lpszClass))
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 @@ FindWindowExW(HWND hwndParent,
LPCWSTR lpszClass,
LPCWSTR lpszWindow)
{
UNICODE_STRING ucClassName;
UNICODE_STRING ucWindowName;
UNICODE_STRING ucClassName, *pucClassName = NULL;
UNICODE_STRING ucWindowName, *pucWindowName = NULL;
if (lpszClass == NULL)
if (IS_ATOM(lpszClass))
{
ucClassName.Buffer = NULL;
ucClassName.Length = 0;
}
else if (IS_ATOM(lpszClass))
{
RtlInitUnicodeString(&ucClassName, NULL);
ucClassName.Buffer = (LPWSTR)lpszClass;
pucClassName = &ucClassName;
}
else
else if (lpszClass != NULL)
{
RtlInitUnicodeString(&ucClassName, lpszClass);
RtlInitUnicodeString(&ucClassName,
lpszClass);
pucClassName = &ucClassName;
}
RtlInitUnicodeString(&ucWindowName, lpszWindow);
if (lpszWindow != NULL)
{
RtlInitUnicodeString(&ucWindowName,
lpszWindow);
pucWindowName = &ucWindowName;
}
return NtUserFindWindowEx(hwndParent, hwndChildAfter, &ucClassName, &ucWindowName);
return NtUserFindWindowEx(hwndParent,
hwndChildAfter,
pucClassName,
pucWindowName);
}
+49 -46
View File
@@ -2433,61 +2433,64 @@ NtUserFindWindowEx(HWND hwndParent,
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);
}
}
Desktop = IntGetCurrentThreadDesktopWindow();