NtUserBuildHwndList() returns NTSTATUS, not ULONG. More correct fix than 33483 to...
authorGregor Brunmar <gbrunmar.ros@gmail.com>
Tue, 13 May 2008 18:09:08 +0000 (18:09 +0000)
committerGregor Brunmar <gbrunmar.ros@gmail.com>
Tue, 13 May 2008 18:09:08 +0000 (18:09 +0000)
svn path=/trunk/; revision=33500

reactos/dll/win32/user32/windows/mdi.c
reactos/dll/win32/user32/windows/window.c
reactos/include/reactos/win32k/ntuser.h
reactos/subsystems/win32/win32k/ntuser/window.c

index 4d8e8d1..26c38f1 100644 (file)
@@ -133,12 +133,11 @@ HWND* WIN_ListChildren (HWND hWndparent)
   DWORD dwCount = 0;
   HWND* pHwnd = NULL;
   HANDLE hHeap;
+  NTSTATUS Status;
 
-  SetLastError(0);
+  Status = NtUserBuildHwndList ( NULL, hWndparent, FALSE, 0, 0, NULL, &dwCount );
 
-  dwCount = NtUserBuildHwndList ( NULL, hWndparent, FALSE, 0, 0, NULL, 0 );
-
-  if ( !dwCount || GetLastError() )
+  if ( !NT_SUCCESS( Status ) )
     return 0;
 
   /* allocate buffer to receive HWND handles */
@@ -152,12 +151,12 @@ HWND* WIN_ListChildren (HWND hWndparent)
     }
 
   /* now call kernel again to fill the buffer this time */
-  dwCount = NtUserBuildHwndList (NULL, hWndparent, FALSE, 0, 0, pHwnd, dwCount );
+  Status = NtUserBuildHwndList (NULL, hWndparent, FALSE, 0, 0, pHwnd, &dwCount );
 
-  if ( !dwCount || GetLastError() )
+  if ( !NT_SUCCESS( Status ) )
     {
       if ( pHwnd )
-       HeapFree ( hHeap, 0, pHwnd );
+        HeapFree ( hHeap, 0, pHwnd );
       return 0;
     }
 
index 774197c..723c3a2 100644 (file)
@@ -558,6 +558,7 @@ User32EnumWindows (
   DWORD i, dwCount = 0;
   HWND* pHwnd = NULL;
   HANDLE hHeap;
+  NTSTATUS Status;
 
   if ( !lpfn )
     {
@@ -569,9 +570,9 @@ User32EnumWindows (
      sort of persistent buffer and only grow it ( requiring a 2nd
      call ) when the buffer wasn't already big enough? */
   /* first get how many window entries there are */
-  dwCount = NtUserBuildHwndList (
-    hDesktop, hWndparent, bChildren, dwThreadId, lParam, NULL, 0 );
-  if ( !dwCount )
+  Status = NtUserBuildHwndList (
+    hDesktop, hWndparent, bChildren, dwThreadId, lParam, NULL, &dwCount );
+  if ( !NT_SUCCESS( Status ) )
     return FALSE;
 
   /* allocate buffer to receive HWND handles */
@@ -584,9 +585,9 @@ User32EnumWindows (
     }
 
   /* now call kernel again to fill the buffer this time */
-  dwCount = NtUserBuildHwndList (
-    hDesktop, hWndparent, bChildren, dwThreadId, lParam, pHwnd, dwCount );
-  if ( !dwCount )
+  Status = NtUserBuildHwndList (
+    hDesktop, hWndparent, bChildren, dwThreadId, lParam, pHwnd, &dwCount );
+  if ( !NT_SUCCESS( Status ) )
     {
       if ( pHwnd )
         HeapFree ( hHeap, 0, pHwnd );
index ed48367..c76deca 100644 (file)
@@ -481,7 +481,7 @@ NTAPI
 NtUserBlockInput(
   BOOL BlockIt);
 
-ULONG
+NTSTATUS
 NTAPI
 NtUserBuildHwndList(
   HDESK hDesktop,
@@ -490,7 +490,7 @@ NtUserBuildHwndList(
   ULONG dwThreadId,
   ULONG lParam,
   HWND* pWnd,
-  ULONG nBufSize);
+  ULONG* nBufSize);
 
 NTSTATUS NTAPI
 NtUserBuildNameList(
index 3c925a4..4b6d1df 100644 (file)
@@ -1212,7 +1212,7 @@ NtUserAlterWindowStyle(DWORD Unknown0,
 /*
  * @implemented
  */
-ULONG
+NTSTATUS
 STDCALL
 NtUserBuildHwndList(
    HDESK hDesktop,
@@ -1221,11 +1221,14 @@ NtUserBuildHwndList(
    ULONG dwThreadId,
    ULONG lParam,
    HWND* pWnd,
-   ULONG nBufSize)
+   ULONG* pBufSize)
 {
    NTSTATUS Status;
    ULONG dwCount = 0;
 
+   if (pBufSize == 0)
+       return ERROR_INVALID_PARAMETER;
+
    if (hwndParent || !dwThreadId)
    {
       PDESKTOP_OBJECT Desktop;
@@ -1235,8 +1238,7 @@ NtUserBuildHwndList(
       {
          if(hDesktop == NULL && !(Desktop = IntGetActiveDesktop()))
          {
-            SetLastWin32Error(ERROR_INVALID_HANDLE);
-            return 0;
+            return ERROR_INVALID_HANDLE;
          }
 
          if(hDesktop)
@@ -1247,8 +1249,7 @@ NtUserBuildHwndList(
                                               &Desktop);
             if(!NT_SUCCESS(Status))
             {
-               SetLastWin32Error(ERROR_INVALID_HANDLE);
-               return 0;
+               return ERROR_INVALID_HANDLE;
             }
          }
          hwndParent = Desktop->DesktopWindow;
@@ -1268,7 +1269,7 @@ NtUserBuildHwndList(
          {
             if (bGoDown)
             {
-               if(dwCount++ < nBufSize && pWnd)
+               if(dwCount++ < *pBufSize && pWnd)
                {
                   _SEH_TRY
                   {
@@ -1323,15 +1324,13 @@ NtUserBuildHwndList(
       Status = PsLookupThreadByThreadId((HANDLE)dwThreadId, &Thread);
       if(!NT_SUCCESS(Status))
       {
-         SetLastWin32Error(ERROR_INVALID_PARAMETER);
-         return 0;
+         return ERROR_INVALID_PARAMETER;
       }
       if(!(W32Thread = (PW32THREAD)Thread->Tcb.Win32Thread))
       {
          ObDereferenceObject(Thread);
          DPRINT("Thread is not a GUI Thread!\n");
-         SetLastWin32Error(ERROR_INVALID_PARAMETER);
-         return 0;
+         return ERROR_INVALID_PARAMETER;
       }
 
       Current = W32Thread->WindowListHead.Flink;
@@ -1342,7 +1341,7 @@ NtUserBuildHwndList(
 
          if(bChildren || Window->hOwner != NULL)
          {
-             if(dwCount < nBufSize && pWnd)
+             if(dwCount < *pBufSize && pWnd)
              {
                 Status = MmCopyToCaller(pWnd++, &Window->hSelf, sizeof(HWND));
                 if(!NT_SUCCESS(Status))
@@ -1359,7 +1358,8 @@ NtUserBuildHwndList(
       ObDereferenceObject(Thread);
    }
 
-   return dwCount;
+   *pBufSize = dwCount;
+   return STATUS_SUCCESS;
 }