make handle table session global
Modified: trunk/reactos/subsys/win32k/include/userfuncs.h
Modified: trunk/reactos/subsys/win32k/include/winsta.h
Modified: trunk/reactos/subsys/win32k/ntuser/accelerator.c
Modified: trunk/reactos/subsys/win32k/ntuser/cursoricon.c
Modified: trunk/reactos/subsys/win32k/ntuser/hook.c
Modified: trunk/reactos/subsys/win32k/ntuser/input.c
Modified: trunk/reactos/subsys/win32k/ntuser/menu.c
Modified: trunk/reactos/subsys/win32k/ntuser/monitor.c
Modified: trunk/reactos/subsys/win32k/ntuser/msgqueue.c
Modified: trunk/reactos/subsys/win32k/ntuser/ntuser.c
Modified: trunk/reactos/subsys/win32k/ntuser/object.c
Modified: trunk/reactos/subsys/win32k/ntuser/window.c
Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c
Modified: trunk/reactos/subsys/win32k/ntuser/winsta.c

Modified: trunk/reactos/subsys/win32k/include/userfuncs.h
--- trunk/reactos/subsys/win32k/include/userfuncs.h	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/include/userfuncs.h	2005-09-06 10:05:31 UTC (rev 17694)
@@ -1,6 +1,10 @@
 #ifndef _WIN32K_USERFUNCS_H
 #define _WIN32K_USERFUNCS_H
 
+
+extern PUSER_HANDLE_TABLE gHandleTable;
+
+
 /*************** WINSTA.C ***************/
 
 HWINSTA FASTCALL UserGetProcessWindowStation(VOID);

Modified: trunk/reactos/subsys/win32k/include/winsta.h
--- trunk/reactos/subsys/win32k/include/winsta.h	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/include/winsta.h	2005-09-06 10:05:31 UTC (rev 17694)
@@ -27,7 +27,6 @@
     UNICODE_STRING Name;
     LIST_ENTRY DesktopListHead;
     PRTL_ATOM_TABLE AtomTable;
-    PVOID HandleTable;
     HANDLE SystemMenuTemplate;
     PVOID SystemCursor;
     UINT CaretBlinkRate;

Modified: trunk/reactos/subsys/win32k/ntuser/accelerator.c
--- trunk/reactos/subsys/win32k/ntuser/accelerator.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/accelerator.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -94,10 +94,11 @@
     RETURN(0);
   }
 
-  Status = ObmReferenceObjectByHandle(WindowStation->HandleTable,
+  Status = ObmReferenceObjectByHandle(gHandleTable,
     Table,
     otAcceleratorTable,
     (PVOID*)&AcceleratorTable);
+  
   if (!NT_SUCCESS(Status))
   {
     SetLastWin32Error(ERROR_INVALID_ACCEL_HANDLE);
@@ -161,7 +162,7 @@
   }
 
   AcceleratorTable = ObmCreateObject(
-    WindowStation->HandleTable,
+    gHandleTable,
     (PHANDLE)&Handle,
     otAcceleratorTable,
 	sizeof(ACCELERATOR_TABLE));
@@ -179,7 +180,7 @@
 	AcceleratorTable->Table = ExAllocatePoolWithTag(PagedPool, EntriesCount * sizeof(ACCEL), TAG_ACCEL);
 	if (AcceleratorTable->Table == NULL)
 	{
-		ObmCloseHandle(WindowStation->HandleTable, Handle);
+		ObmCloseHandle(gHandleTable, Handle);
 		ObDereferenceObject(WindowStation);
 		SetLastNtError(Status);
 		DPRINT1("E3\n");
@@ -190,7 +191,7 @@
     if (!NT_SUCCESS(Status))
     {
 	  ExFreePool(AcceleratorTable->Table);
-	  ObmCloseHandle(WindowStation->HandleTable, Handle);
+	  ObmCloseHandle(gHandleTable, Handle);
       ObDereferenceObject(WindowStation);
       SetLastNtError(Status);
       DPRINT1("E4\n");
@@ -240,7 +241,7 @@
     RETURN( FALSE);
   }
 
-  Status = ObmReferenceObjectByHandle(WindowStation->HandleTable,
+  Status = ObmReferenceObjectByHandle(gHandleTable,
     Table,
     otAcceleratorTable,
     (PVOID*)&AcceleratorTable);
@@ -252,7 +253,7 @@
     RETURN( FALSE);
   }
 
-  ObmCloseHandle(WindowStation->HandleTable, Table);
+  ObmCloseHandle(gHandleTable, Table);
 
   if (AcceleratorTable->Table != NULL)
   {
@@ -503,7 +504,7 @@
     RETURN( 0);
   }
 
-  Status = ObmReferenceObjectByHandle(WindowStation->HandleTable,
+  Status = ObmReferenceObjectByHandle(gHandleTable,
     Table,
     otAcceleratorTable,
     (PVOID*)&AcceleratorTable);

Modified: trunk/reactos/subsys/win32k/ntuser/cursoricon.c
--- trunk/reactos/subsys/win32k/ntuser/cursoricon.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/cursoricon.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -77,7 +77,7 @@
    PCURICON_OBJECT Object;
    NTSTATUS Status;
 
-   Status = ObmReferenceObjectByHandle(WinStaObject->HandleTable,
+   Status = ObmReferenceObjectByHandle(gHandleTable,
       Handle, otCursorIcon, (PVOID*)&Object);
    if (!NT_SUCCESS(Status))
    {
@@ -391,7 +391,7 @@
   PCURICON_OBJECT Object;
   HANDLE Handle;
 
-  Object = ObmCreateObject(WinStaObject->HandleTable, &Handle, otCursorIcon, sizeof(CURICON_OBJECT));
+  Object = ObmCreateObject(gHandleTable, &Handle, otCursorIcon, sizeof(CURICON_OBJECT));
 
   if(!Object)
   {
@@ -405,7 +405,7 @@
   if (! ReferenceCurIconByProcess(Object))
   {
     DPRINT1("Failed to add process\n");
-    ObmCloseHandle(WinStaObject->HandleTable, Handle);
+    ObmCloseHandle(gHandleTable, Handle);
     ObmDereferenceObject(Object);
     return NULL;
   }
@@ -483,7 +483,7 @@
   bmpMask = Object->IconInfo.hbmMask;
   bmpColor = Object->IconInfo.hbmColor;
 
-  Ret = NT_SUCCESS(ObmCloseHandle(WinStaObject->HandleTable, Object->Self));
+  Ret = NT_SUCCESS(ObmCloseHandle(gHandleTable, Object->Self));
 
   /* delete bitmaps */
   if(bmpMask)
@@ -941,7 +941,7 @@
     RETURN( FALSE);
   }
 
-  Status = ObmReferenceObjectByHandle(WinStaObject->HandleTable, Handle, otCursorIcon, (PVOID*)&Object);
+  Status = ObmReferenceObjectByHandle(gHandleTable, Handle, otCursorIcon, (PVOID*)&Object);
   if(!NT_SUCCESS(Status))
   {
     ObDereferenceObject(WinStaObject);

Modified: trunk/reactos/subsys/win32k/ntuser/hook.c
--- trunk/reactos/subsys/win32k/ntuser/hook.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/hook.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -83,7 +83,7 @@
         }
     }
 
-  Hook = ObmCreateObject(WinStaObj->HandleTable, &Handle,
+  Hook = ObmCreateObject(gHandleTable, &Handle,
                          otHookProc, sizeof(HOOK));
   if (NULL == Hook)
     {
@@ -180,7 +180,7 @@
     }
 
   /* Close handle */
-  ObmCloseHandle(WinStaObj->HandleTable, Hook->Self);
+  ObmCloseHandle(gHandleTable, Hook->Self);
 }
 
 /* remove a hook, freeing it if the chain is not in use */
@@ -399,7 +399,7 @@
       RETURN( FALSE);
     }
 
-  Status = ObmReferenceObjectByHandle(WinStaObj->HandleTable, Hook,
+  Status = ObmReferenceObjectByHandle(gHandleTable, Hook,
                                       otHookProc, (PVOID *) &HookObj);
   ObDereferenceObject(WinStaObj);
   if (! NT_SUCCESS(Status))
@@ -687,7 +687,7 @@
       RETURN( FALSE);
     }
 
-  Status = ObmReferenceObjectByHandle(WinStaObj->HandleTable, Hook,
+  Status = ObmReferenceObjectByHandle(gHandleTable, Hook,
                                       otHookProc, (PVOID *) &HookObj);
   if (! NT_SUCCESS(Status))
     {

Modified: trunk/reactos/subsys/win32k/ntuser/input.c
--- trunk/reactos/subsys/win32k/ntuser/input.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/input.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -378,7 +378,7 @@
   MSG Mesg;
   NTSTATUS Status;
 
-  Status = ObmReferenceObjectByHandle(InputWindowStation->HandleTable,
+  Status = ObmReferenceObjectByHandle(gHandleTable,
                                       InputWindowStation->ShellWindow,
 				      otWindow,
 				      (PVOID *)&Window);
@@ -947,7 +947,7 @@
       MousePos.y += mi->dy;
     }
 
-    Status = ObmReferenceObjectByHandle(WinSta->HandleTable,
+    Status = ObmReferenceObjectByHandle(gHandleTable,
       WinSta->ActiveDesktop->DesktopWindow, otWindow, (PVOID*)&DesktopWindow);
     if (NT_SUCCESS(Status))
     {

Modified: trunk/reactos/subsys/win32k/ntuser/menu.c
--- trunk/reactos/subsys/win32k/ntuser/menu.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/menu.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -142,7 +142,7 @@
     return NULL;
   }
 
-  NTSTATUS Status = ObmReferenceObjectByHandle(W32Thread->Desktop->WindowStation->HandleTable,
+  NTSTATUS Status = ObmReferenceObjectByHandle(gHandleTable,
                                                hMenu, otMenu, (PVOID*)&MenuObject);
   if (!NT_SUCCESS(Status))
   {
@@ -243,7 +243,7 @@
                                        NULL);
     if(NT_SUCCESS(Status))
     {
-      ObmCloseHandle(WindowStation->HandleTable, MenuObject->MenuInfo.Self);
+      ObmCloseHandle(gHandleTable, MenuObject->MenuInfo.Self);
       ObDereferenceObject(WindowStation);
       return TRUE;
     }
@@ -255,10 +255,9 @@
 IntCreateMenu(PHANDLE Handle, BOOL IsMenuBar)
 {
   PMENU_OBJECT MenuObject;
-  PW32THREAD Win32Thread = PsGetWin32Thread();
 
   MenuObject = (PMENU_OBJECT)ObmCreateObject(
-      Win32Thread->Desktop->WindowStation->HandleTable, Handle,
+      gHandleTable, Handle,
       otMenu, sizeof(MENU_OBJECT));
 
   if(!MenuObject)
@@ -367,7 +366,7 @@
     return NULL;
 
   MenuObject = (PMENU_OBJECT)ObmCreateObject(
-    PsGetWin32Thread()->Desktop->WindowStation->HandleTable, &Handle,
+    gHandleTable, &Handle,
     otMenu, sizeof(MENU_OBJECT));
   if(!MenuObject)
     return NULL;

Modified: trunk/reactos/subsys/win32k/ntuser/monitor.c
--- trunk/reactos/subsys/win32k/ntuser/monitor.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/monitor.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -91,7 +91,7 @@
   HANDLE Handle;
   PMONITOR_OBJECT Monitor;
 
-  Monitor = ObmCreateObject(PsGetWin32Thread()->Desktop->WindowStation->HandleTable, &Handle, otMonitor, sizeof (MONITOR_OBJECT));
+  Monitor = ObmCreateObject(gHandleTable, &Handle, otMonitor, sizeof (MONITOR_OBJECT));
   if (Monitor == NULL)
     {
       return NULL;
@@ -141,7 +141,7 @@
   PMONITOR_OBJECT Monitor;
   NTSTATUS Status;
 
-  Status = ObmReferenceObjectByHandle(PsGetWin32Thread()->Desktop->WindowStation->HandleTable, hMonitor, otMonitor, (PVOID *)&Monitor);
+  Status = ObmReferenceObjectByHandle(gHandleTable, hMonitor, otMonitor, (PVOID *)&Monitor);
   if (!NT_SUCCESS(Status) || Monitor == NULL)
     {
       /* FIXME: SetLastNtError( status ); ? */

Modified: trunk/reactos/subsys/win32k/ntuser/msgqueue.c
--- trunk/reactos/subsys/win32k/ntuser/msgqueue.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/msgqueue.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -733,7 +733,7 @@
     }
 
   WinSta = Win32Thread->Desktop->WindowStation;
-  Status = ObmReferenceObjectByHandle(WinSta->HandleTable,
+  Status = ObmReferenceObjectByHandle(gHandleTable,
                                       hWnd, otWindow, (PVOID*)&Window);
   if (!NT_SUCCESS(Status))
     {

Modified: trunk/reactos/subsys/win32k/ntuser/ntuser.c
--- trunk/reactos/subsys/win32k/ntuser/ntuser.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/ntuser.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -49,6 +49,15 @@
    
 //   DPRINT("Enter InitUserImpl\n");
 //   ExInitializeResourceLite(&UserLock);
+
+
+   gHandleTable = ObmCreateHandleTable();
+   if (!gHandleTable)
+   {
+      DPRINT("Failed creating handle table\n");
+      return STATUS_INSUFFICIENT_RESOURCES;
+   }
+
    ExInitializeFastMutex(&UserLock);
   
    return STATUS_SUCCESS;

Modified: trunk/reactos/subsys/win32k/ntuser/object.c
--- trunk/reactos/subsys/win32k/ntuser/object.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/object.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -40,6 +40,9 @@
 #define USER_BODY_TO_HEADER(ObjectBody) \
   ((PUSER_OBJECT_HEADER)(((PUSER_OBJECT_HEADER)ObjectBody) - 1))
 
+
+PUSER_HANDLE_TABLE gHandleTable = NULL;
+
 /* FUNCTIONS *****************************************************************/
 
 VOID FASTCALL

Modified: trunk/reactos/subsys/win32k/ntuser/window.c
--- trunk/reactos/subsys/win32k/ntuser/window.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/window.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -129,7 +129,7 @@
 
    if(Thread->Desktop != NULL)
    {
-     Status = ObmReferenceObjectByHandle(Thread->Desktop->WindowStation->HandleTable,
+     Status = ObmReferenceObjectByHandle(gHandleTable,
                                          hWnd, otWindow, (PVOID*)&WindowObject);
      if (NT_SUCCESS(Status))
      {
@@ -418,7 +418,7 @@
   IntUnlinkWindow(Window);
 
   IntReferenceWindowObject(Window);
-  ObmCloseHandle(ThreadData->Desktop->WindowStation->HandleTable, Window->Self);
+  ObmCloseHandle(gHandleTable, Window->Self);
 
   IntDestroyScrollBars(Window);
 
@@ -1498,7 +1498,7 @@
 
   /* Create the window object. */
   WindowObject = (PWINDOW_OBJECT)
-    ObmCreateObject(PsGetWin32Thread()->Desktop->WindowStation->HandleTable, &Handle,
+    ObmCreateObject(gHandleTable, &Handle,
         otWindow, sizeof(WINDOW_OBJECT) + ClassObject->cbWndExtra
         );
 

Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c
--- trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -1256,7 +1256,7 @@
 //  HRGN VisibleRgn;
 
   Status =
-    ObmReferenceObjectByHandle(PsGetWin32Thread()->Desktop->WindowStation->HandleTable,
+    ObmReferenceObjectByHandle(gHandleTable,
 			       Wnd,
 			       otWindow,
 			       (PVOID*)&Window);

Modified: trunk/reactos/subsys/win32k/ntuser/winsta.c
--- trunk/reactos/subsys/win32k/ntuser/winsta.c	2005-09-06 09:35:39 UTC (rev 17693)
+++ trunk/reactos/subsys/win32k/ntuser/winsta.c	2005-09-06 10:05:31 UTC (rev 17694)
@@ -535,18 +535,6 @@
      return 0;
    }
 
-   WindowStationObject->HandleTable = ObmCreateHandleTable();
-   if (!WindowStationObject->HandleTable)
-   {
-      DPRINT("Failed creating handle table\n");
-      ExFreePool(CurInfo);
-      ExFreePool(WindowStationName.Buffer);
-      /* FIXME - Delete window station object */
-      ObDereferenceObject(WindowStationObject);
-      SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
-      return 0;
-   }
-
    InitHotKeys(WindowStationObject);
 
    CurInfo->Enabled = FALSE;