Merge to trunk HEAD(r36856)
authorSamuel Serapion <samuel.serapion@gmail.com>
Mon, 20 Oct 2008 21:36:03 +0000 (21:36 +0000)
committerSamuel Serapion <samuel.serapion@gmail.com>
Mon, 20 Oct 2008 21:36:03 +0000 (21:36 +0000)
svn path=/branches/ros-amd64-bringup/; revision=36862

25 files changed:
1  2 
reactos/base/applications/mscutils/servman/mainwnd.c
reactos/boot/freeldr/freeldr/freeldr.rbuild
reactos/dll/3rdparty/mesa32/mesa32.rbuild
reactos/dll/cpl/ncpa/ncpa.rbuild
reactos/dll/win32/advapi32/sec/misc.c
reactos/dll/win32/gdi32/misc/stubs.c
reactos/dll/win32/netcfgx/lang/de-DE.rc
reactos/dll/win32/user32/include/user32.h
reactos/drivers/network/dd/pcnet/pcnet.c
reactos/include/ddk/winddk.h
reactos/include/reactos/win32k/ntuser.h
reactos/ntoskrnl/mm/section.c
reactos/subsystems/win32/win32k/ntuser/callback.c
reactos/subsystems/win32/win32k/ntuser/class.c
reactos/subsystems/win32/win32k/ntuser/hook.c
reactos/subsystems/win32/win32k/ntuser/kbdlayout.c
reactos/subsystems/win32/win32k/ntuser/menu.c
reactos/subsystems/win32/win32k/ntuser/misc.c
reactos/subsystems/win32/win32k/ntuser/painting.c
reactos/subsystems/win32/win32k/ntuser/simplecall.c
reactos/tools/rbuild/backend/mingw/modulehandler.cpp
reactos/tools/rbuild/module.cpp
reactos/tools/widl/client.c
reactos/tools/widl/server.c
reactos/tools/widl/typegen.c

@@@ -161,7 -161,7 +161,7 @@@ VOID SetMenuAndButtonStates(PMAIN_WND_I
      for (i = ID_START; i <= ID_RESTART; i++)
      {
          EnableMenuItem(hMainMenu, i, MF_GRAYED);
-         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), ID_START, MF_GRAYED);
+         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0), i, MF_GRAYED);
          SendMessage(Info->hTool, TB_SETSTATE, i,
                      (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
      }
@@@ -432,7 -432,7 +432,7 @@@ MainWndCommand(PMAIN_WND_INFO Info
              ret = DialogBoxParam(hInstance,
                                   MAKEINTRESOURCE(IDD_DLG_CREATE),
                                   Info->hMainWnd,
 -                                 (DLGPROC)CreateDialogProc,
 +                                 CreateDialogProc,
                                   (LPARAM)Info);
              if (ret == IDOK)
                  RefreshServiceList(Info);
                  DialogBoxParam(hInstance,
                                 MAKEINTRESOURCE(IDD_DLG_DELETE),
                                 Info->hMainWnd,
 -                               (DLGPROC)DeleteDialogProc,
 +                               DeleteDialogProc,
                                 (LPARAM)Info);
              }
              else
              DialogBox(hInstance,
                        MAKEINTRESOURCE(IDD_ABOUTBOX),
                        Info->hMainWnd,
 -                      (DLGPROC)AboutDialogProc);
 +                      AboutDialogProc);
              SetFocus(Info->hListView);
          break;
  
@@@ -11,7 -11,7 +11,7 @@@
                        <library>freeldr_main</library>
                        <library>rossym</library>
                        <library>cmlib</library>
-                       <library>rtl</library>
+                       <library>rtl_kmode</library>
                        <library>libcntpr</library>
                        <linkerflag>-static</linkerflag>
                        <linkerflag>-lgcc</linkerflag>
                        <library>ppcmmu</library>
                </module>
        </if>
 +      <if property="ARCH" value="amd64">
 +              <module name="freeldr" type="bootloader">
 +                      <bootstrap installbase="loader" />
 +                      <library>freeldr_startup</library>
 +                      <library>freeldr_base64k</library>
 +                      <library>freeldr_base</library>
 +                      <library>freeldr_arch</library>
 +                      <library>freeldr_main</library>
 +                      <library>rossym</library>
 +                      <library>cmlib</library>
 +                      <library>rtl</library>
 +                      <library>libcntpr</library>
 +                      <linkerflag>-static</linkerflag>
 +                      <linkerflag>-lgcc</linkerflag>
 +              </module>
 +      </if>
  </group>
@@@ -5,6 -5,7 +5,6 @@@
        <linkerflag>-enable-stdcall-fixup</linkerflag>
        <library>ntdll</library>
        <library>kernel32</library>
 -      <library>msvcrt</library>
        <library>user32</library>
        <define name="USE_EXTERNAL_DXTN_LIB" />
        <!-- The following is autogenrated by Makefile.ReactOS -->
                <file>prog_parameter.c</file>
                <file>prog_print.c</file>
                <file>prog_statevars.c</file>
+               <file>prog_uniform.c</file>
                <file>program.c</file>
                <file>programopt.c</file>
                <directory name="grammar">
                <file>x86-64.c</file>
        </directory>
  </directory>
- </module>
+ </module>
@@@ -1,20 -1,12 +1,13 @@@
  <?xml version="1.0"?>
  <!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
  <module name="ncpa" type="win32dll" extension=".cpl" baseaddress="${BASEADDRESS_NCPA}" installbase="system32" installname="ncpa.cpl" unicode="yes">
 -      <importlibrary definition="ncpa.def" />
 +      <importlibrary definition="ncpa.spec.def" />
        <include base="ncpa">.</include>
        <define name="_WIN32_IE">0x600</define>
        <define name="_WIN32_WINNT">0x600</define>
-       <library>wine</library>
        <library>kernel32</library>
        <library>advapi32</library>
-       <library>user32</library>
-       <library>comctl32</library>
-       <library>iphlpapi</library>
-       <library>ws2_32</library>
-       <library>dhcpcsvc</library>
+       <library>shell32</library>
        <file>ncpa.c</file>
-       <file>tcpip_properties.c</file>
-       <file>ncpa.rc</file>
 +      <file>ncpa.spec</file>
  </module>
@@@ -188,7 -188,7 +188,7 @@@ CheckNtMartaPresent(VOID
  {
      DWORD ErrorCode;
  
 -    if (InterlockedCompareExchangePointer(&NtMarta,
 +    if (InterlockedCompareExchangePointer((PVOID)&NtMarta,
                                            NULL,
                                            NULL) == NULL)
      {
          if (ErrorCode == ERROR_SUCCESS)
          {
              /* try change the NtMarta pointer */
 -            if (InterlockedCompareExchangePointer(&NtMarta,
 +            if (InterlockedCompareExchangePointer((PVOID)&NtMarta,
                                                    &NtMartaStatic,
                                                    NULL) != NULL)
              {
  VOID
  UnloadNtMarta(VOID)
  {
 -    if (InterlockedExchangePointer(&NtMarta,
 +    if (InterlockedExchangePointer((PVOID)&NtMarta,
                                     NULL) != NULL)
      {
          FreeLibrary(NtMartaStatic.hDllInstance);
@@@ -338,16 -338,7 +338,7 @@@ GetFileSecurityW(LPCWSTR lpFileName
  
      TRACE("GetFileSecurityW() called\n");
  
-     if (RequestedInformation &
-         (OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION))
-     {
-         AccessMask |= READ_CONTROL;
-     }
-     if (RequestedInformation & SACL_SECURITY_INFORMATION)
-     {
-         AccessMask |= ACCESS_SYSTEM_SECURITY;
-     }
+     QuerySecurityAccessMask(RequestedInformation, &AccessMask);
  
      if (!RtlDosPathNameToNtPathName_U(lpFileName,
                                        &FileName,
@@@ -483,21 -474,7 +474,7 @@@ SetFileSecurityW(LPCWSTR lpFileName
  
      TRACE("SetFileSecurityW() called\n");
  
-     if (SecurityInformation &
-         (OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION))
-     {
-         AccessMask |= WRITE_OWNER;
-     }
-     if (SecurityInformation & DACL_SECURITY_INFORMATION)
-     {
-         AccessMask |= WRITE_DAC;
-     }
-     if (SecurityInformation & SACL_SECURITY_INFORMATION)
-     {
-         AccessMask |= ACCESS_SYSTEM_SECURITY;
-     }
+     SetSecurityAccessMask(SecurityInformation, &AccessMask);
  
      if (!RtlDosPathNameToNtPathName_U(lpFileName,
                                        &FileName,
@@@ -968,7 -968,7 +968,7 @@@ GetGlyphOutlineWow
   */
  DWORD
  STDCALL
 -gdiPlaySpoolStream(
 +GdiPlaySpoolStream(
        DWORD   a0,
        DWORD   a1,
        DWORD   a2,
@@@ -1239,27 -1239,6 +1239,6 @@@ GetTextExtentExPointWPri(HDC hdc
      return NtGdiGetTextExtentExW(hdc,lpwsz,cwc,dxMax,pcCh,pdxOut,psize,0);
  }
  
- /*
-  * @implemented
-  */
- INT
- STDCALL
- GetTextFaceAliasW(HDC hdc,
-                   int cChar,
-                   LPWSTR pszOut)
- {
-     INT retValue = 0;
-     if ((!pszOut) || (cChar))
-     {
-         retValue = NtGdiGetTextFaceW(hdc,cChar,pszOut,TRUE);
-     }
-     else
-     {
-         SetLastError(ERROR_INVALID_PARAMETER);
-     }
-     return retValue;
- }
  /*
   * @unimplemented
   */
@@@ -117,7 -117,7 +117,7 @@@ BEGI
      LTEXT "IP-Adresse:", -1, 5, 15, 70, 12
      LTEXT "Subnetzmaske:", -1, 5, 30, 70, 12
      CONTROL "",IDC_SUBNETMASK,"SysIPAddress32", WS_TABSTOP, 100, 30, 80, 12
-     PUSHBUTTON "", IDOK, 50, 50, 50, 14, WS_TABSTOP
+     PUSHBUTTON "", IDC_OK, 50, 50, 50, 14, WS_TABSTOP
      PUSHBUTTON "Abbrechen", IDCANCEL, 110, 50, 50, 14, WS_TABSTOP
  END
  
@@@ -131,7 -131,7 +131,7 @@@ BEGI
      CHECKBOX "Automatische Metrik", IDC_USEMETRIC, 15, 30, 190, 12, BS_AUTOCHECKBOX | WS_TABSTOP
      LTEXT "&Metric:", IDC_METRICTXT, 5, 45, 45, 12, WS_DISABLED
      EDITTEXT IDC_METRIC, 100, 45, 50, 12, WS_TABSTOP | ES_NUMBER | WS_DISABLED
-     PUSHBUTTON "", IDOK, 50, 60, 50, 14, WS_TABSTOP
+     PUSHBUTTON "", IDC_OK, 50, 60, 50, 14, WS_TABSTOP
      PUSHBUTTON "Abbrechen", IDCANCEL, 110, 60, 50, 14, WS_TABSTOP
  END
  
@@@ -142,7 -142,7 +142,7 @@@ FONT 8, "MS Shell Dlg
  BEGIN
      CONTROL "",IDC_IPADDR,"SysIPAddress32",WS_TABSTOP, 5, 25, 80, 12
      LTEXT "DNS-Server:", -1, 5, 10, 120, 12
-     PUSHBUTTON "", IDOK, 50, 50, 50, 14, WS_TABSTOP
+     PUSHBUTTON "", IDC_OK, 50, 50, 50, 14, WS_TABSTOP
      PUSHBUTTON "Abbrechen", IDCANCEL, 110, 50, 50, 14, WS_TABSTOP
  END
  
@@@ -153,7 -153,7 +153,7 @@@ FONT 8, "MS Shell Dlg
  BEGIN
      EDITTEXT IDC_SUFFIX, 5, 25, 190, 12, WS_TABSTOP
      LTEXT "Domänensuffix:", -1, 5, 10, 120, 12
-     PUSHBUTTON "", IDOK, 50, 50, 50, 14, WS_TABSTOP
+     PUSHBUTTON "", IDC_OK, 50, 50, 50, 14, WS_TABSTOP
      PUSHBUTTON "Abbrechen", IDCANCEL, 110, 50, 50, 14, WS_TABSTOP
  END
  
@@@ -181,7 -181,7 +181,7 @@@ BEGI
      CONTROL "", IDC_IP_LIST, "SysListView32", LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP, 211, 62, 72, 75
      PUSHBUTTON "Hinzufügen...", IDC_IP_ADD, 215, 141, 50, 14, WS_TABSTOP
      PUSHBUTTON "Entfernen", IDC_IP_DEL, 215, 161, 50, 14, WS_TABSTOP
-     PUSHBUTTON "OK", IDOK, 150, 190, 50, 14, WS_TABSTOP
+     PUSHBUTTON "OK", IDC_OK, 150, 190, 50, 14, WS_TABSTOP
      PUSHBUTTON "Abbrechen", IDCANCEL, 210, 190, 50, 14, WS_TABSTOP
  END
  
@@@ -192,7 -192,7 +192,7 @@@ FONT 8, "MS Shell Dlg
  BEGIN
      EDITTEXT IDC_PORT_VAL, 5, 30, 70, 12, WS_TABSTOP | ES_NUMBER
      LTEXT "", IDC_PORT_DESC, 5, 15, 40, 12
-     PUSHBUTTON "OK", IDOK, 120, 15, 50, 14, WS_TABSTOP
+     PUSHBUTTON "OK", IDC_OK, 120, 15, 50, 14, WS_TABSTOP
      PUSHBUTTON "Abbrechen", IDCANCEL, 120, 30, 50, 14, WS_TABSTOP
  END
  
@@@ -227,4 -227,3 +227,4 @@@ BEGI
        IDS_DUP_IPADDR      "Die IP-Adresse ist bereits in der Liste vorhanden."
        IDS_DUP_GW          "Der Standardgateway ist bereits in der Liste vorhanden."
  END
- >>>>>>> .merge-right.r36700\r
++>>>>>>> .merge-right.r36700
@@@ -64,20 -64,23 +64,23 @@@ SharedPtrToUser(PVOID Ptr
  static __inline PVOID
  DesktopPtrToUser(PVOID Ptr)
  {
-     PW32THREADINFO ti = GetW32ThreadInfo();
+     GetW32ThreadInfo();
+     PCLIENTINFO pci = GetWin32ClientInfo();
+     PDESKTOPINFO pdi = pci->pDeskInfo;
      ASSERT(Ptr != NULL);
-     ASSERT(ti != NULL);
-     if ((ULONG_PTR)Ptr >= (ULONG_PTR)ti->DesktopHeapBase &&
-         (ULONG_PTR)Ptr < (ULONG_PTR)ti->DesktopHeapBase + ti->DesktopHeapLimit)
+     ASSERT(pdi != NULL);
+     if ((ULONG_PTR)Ptr >= (ULONG_PTR)pdi->pvDesktopBase &&
+         (ULONG_PTR)Ptr < (ULONG_PTR)pdi->pvDesktopLimit)
      {
-         return (PVOID)((ULONG_PTR)Ptr - ti->DesktopHeapDelta);
+         return (PVOID)((ULONG_PTR)Ptr - pci->ulClientDelta);
      }
      else
      {
          /* NOTE: This is slow as it requires a call to win32k. This should only be
                   neccessary if a thread wants to access an object on a different
                   desktop */
 -        return NtUserGetDesktopMapping(Ptr);
 +        return (PVOID)NtUserGetDesktopMapping(Ptr);
      }
  }
  
@@@ -96,11 -99,11 +99,11 @@@ IsThreadHooked(PW32THREADINFO ti
      return ti->Hooks != 0;
  }
  
- static __inline PDESKTOP
+ static __inline PDESKTOPINFO
  GetThreadDesktopInfo(VOID)
  {
      PW32THREADINFO ti;
-     PDESKTOP di = NULL;
+     PDESKTOPINFO di = NULL;
  
      ti = GetW32ThreadInfo();
      if (ti != NULL)
@@@ -139,7 -139,7 +139,7 @@@ MiniportHandleInterrupt
  
                RtlZeroMemory(Descriptor, sizeof(RECEIVE_DESCRIPTOR));
                Descriptor->RBADR =
 -                  (ULONG)(Adapter->ReceiveBufferPtrPhys + Adapter->CurrentReceiveDescriptorIndex * BUFFER_SIZE);
 +                  (ULONG_PTR)(Adapter->ReceiveBufferPtrPhys + Adapter->CurrentReceiveDescriptorIndex * BUFFER_SIZE);
                Descriptor->BCNT = (-BUFFER_SIZE) | 0xf000;
                Descriptor->FLAGS |= RD_OWN;
  
@@@ -325,14 -325,14 +325,14 @@@ MiAllocateSharedMemory
        return NDIS_STATUS_RESOURCES;
      }
  
 -  if(((ULONG)Adapter->InitializationBlockVirt & 0x00000003) != 0)
 +  if(((ULONG_PTR)Adapter->InitializationBlockVirt & 0x00000003) != 0)
      {
        DPRINT("address 0x%x not dword-aligned\n", Adapter->InitializationBlockVirt);
        BREAKPOINT;
        return NDIS_STATUS_RESOURCES;
      }
  
 -  Adapter->InitializationBlockPhys = (PINITIALIZATION_BLOCK)NdisGetPhysicalAddressLow(PhysicalAddress);
 +  Adapter->InitializationBlockPhys = (PINITIALIZATION_BLOCK)(ptrdiff_t)NdisGetPhysicalAddressLow(PhysicalAddress);
  
    /* allocate the transport descriptor ring */
    Adapter->TransmitDescriptorRingLength = sizeof(TRANSMIT_DESCRIPTOR) * NUMBER_OF_BUFFERS;
        return NDIS_STATUS_RESOURCES;
      }
  
 -  if(((ULONG)Adapter->TransmitDescriptorRingVirt & 0x00000003) != 0)
 +  if(((ULONG_PTR)Adapter->TransmitDescriptorRingVirt & 0x00000003) != 0)
      {
        DPRINT("address 0x%x not dword-aligned\n", Adapter->TransmitDescriptorRingVirt);
        BREAKPOINT;
        return NDIS_STATUS_RESOURCES;
      }
  
 -  Adapter->TransmitDescriptorRingPhys = (PTRANSMIT_DESCRIPTOR)NdisGetPhysicalAddressLow(PhysicalAddress);
 +  Adapter->TransmitDescriptorRingPhys = (PTRANSMIT_DESCRIPTOR)(ptrdiff_t)NdisGetPhysicalAddressLow(PhysicalAddress);
    RtlZeroMemory(Adapter->TransmitDescriptorRingVirt, sizeof(TRANSMIT_DESCRIPTOR) * NUMBER_OF_BUFFERS);
  
    /* allocate the receive descriptor ring */
        return NDIS_STATUS_RESOURCES;
      }
  
 -  if(((ULONG)Adapter->ReceiveDescriptorRingVirt & 0x00000003) != 0)
 +  if(((ULONG_PTR)Adapter->ReceiveDescriptorRingVirt & 0x00000003) != 0)
      {
        DPRINT("address 0x%x not dword-aligned\n", Adapter->ReceiveDescriptorRingVirt);
        BREAKPOINT;
        return NDIS_STATUS_RESOURCES;
      }
  
 -  Adapter->ReceiveDescriptorRingPhys = (PRECEIVE_DESCRIPTOR)NdisGetPhysicalAddressLow(PhysicalAddress);
 +  Adapter->ReceiveDescriptorRingPhys = (PRECEIVE_DESCRIPTOR)(ptrdiff_t)NdisGetPhysicalAddressLow(PhysicalAddress);
    RtlZeroMemory(Adapter->ReceiveDescriptorRingVirt, sizeof(RECEIVE_DESCRIPTOR) * NUMBER_OF_BUFFERS);
  
    /* allocate transmit buffers */
        return NDIS_STATUS_RESOURCES;
      }
  
 -  if(((ULONG)Adapter->TransmitBufferPtrVirt & 0x00000003) != 0)
 +  if(((ULONG_PTR)Adapter->TransmitBufferPtrVirt & 0x00000003) != 0)
      {
        DPRINT("address 0x%x not dword-aligned\n", Adapter->TransmitBufferPtrVirt);
        BREAKPOINT;
        return NDIS_STATUS_RESOURCES;
      }
  
 -  Adapter->TransmitBufferPtrPhys = (PCHAR)NdisGetPhysicalAddressLow(PhysicalAddress);
 +  Adapter->TransmitBufferPtrPhys = (PCHAR)(ULONG_PTR)NdisGetPhysicalAddressLow(PhysicalAddress);
    RtlZeroMemory(Adapter->TransmitBufferPtrVirt, BUFFER_SIZE * NUMBER_OF_BUFFERS);
  
    /* allocate receive buffers */
        return NDIS_STATUS_RESOURCES;
      }
  
 -  if(((ULONG)Adapter->ReceiveBufferPtrVirt & 0x00000003) != 0)
 +  if(((ULONG_PTR)Adapter->ReceiveBufferPtrVirt & 0x00000003) != 0)
      {
        DPRINT("address 0x%x not dword-aligned\n", Adapter->ReceiveBufferPtrVirt);
        BREAKPOINT;
        return NDIS_STATUS_RESOURCES;
      }
  
 -  Adapter->ReceiveBufferPtrPhys = (PCHAR)NdisGetPhysicalAddressLow(PhysicalAddress);
 +  Adapter->ReceiveBufferPtrPhys = (PCHAR)(ULONG_PTR)NdisGetPhysicalAddressLow(PhysicalAddress);
    RtlZeroMemory(Adapter->ReceiveBufferPtrVirt, BUFFER_SIZE * NUMBER_OF_BUFFERS);
  
    /* initialize tx descriptors */
    TransmitDescriptor = Adapter->TransmitDescriptorRingVirt;
    for(i = 0; i < NUMBER_OF_BUFFERS; i++)
      {
 -      (TransmitDescriptor+i)->TBADR = (ULONG)Adapter->TransmitBufferPtrPhys + i * BUFFER_SIZE;
 +      (TransmitDescriptor+i)->TBADR = (ULONG_PTR)Adapter->TransmitBufferPtrPhys + i * BUFFER_SIZE;
        (TransmitDescriptor+i)->BCNT = 0xf000 | -BUFFER_SIZE; /* 2's compliment  + set top 4 bits */
        (TransmitDescriptor+i)->FLAGS = TD1_STP | TD1_ENP;
      }
    ReceiveDescriptor = Adapter->ReceiveDescriptorRingVirt;
    for(i = 0; i < NUMBER_OF_BUFFERS; i++)
      {
 -      (ReceiveDescriptor+i)->RBADR = (ULONG)Adapter->ReceiveBufferPtrPhys + i * BUFFER_SIZE;
 +      (ReceiveDescriptor+i)->RBADR = (ULONG_PTR)Adapter->ReceiveBufferPtrPhys + i * BUFFER_SIZE;
        (ReceiveDescriptor+i)->BCNT = 0xf000 | -BUFFER_SIZE; /* 2's compliment  + set top 4 bits */
        (ReceiveDescriptor+i)->FLAGS = RD_OWN;
      }
@@@ -469,12 -469,12 +469,12 @@@ MiPrepareInitializationBlock
  
    /* set up receive ring */
    DPRINT("Receive ring physical address: 0x%x\n", Adapter->ReceiveDescriptorRingPhys);
 -  Adapter->InitializationBlockVirt->RDRA = (ULONG)Adapter->ReceiveDescriptorRingPhys;
 +  Adapter->InitializationBlockVirt->RDRA = (ULONG_PTR)Adapter->ReceiveDescriptorRingPhys;
    Adapter->InitializationBlockVirt->RLEN = (LOG_NUMBER_OF_BUFFERS << 4) & 0xf0;
  
    /* set up transmit ring */
    DPRINT("Transmit ring physical address: 0x%x\n", Adapter->TransmitDescriptorRingPhys);
 -  Adapter->InitializationBlockVirt->TDRA = (ULONG)Adapter->TransmitDescriptorRingPhys;
 +  Adapter->InitializationBlockVirt->TDRA = (ULONG_PTR)Adapter->TransmitDescriptorRingPhys;
    Adapter->InitializationBlockVirt->TLEN = (LOG_NUMBER_OF_BUFFERS << 4) & 0xf0;
  }
  
@@@ -493,35 -493,35 +493,35 @@@ MiFreeSharedMemory
  
    if(Adapter->InitializationBlockVirt)
      {
 -      PhysicalAddress.u.LowPart = (ULONG)Adapter->InitializationBlockPhys;
 +      PhysicalAddress.u.LowPart = (ULONG_PTR)Adapter->InitializationBlockPhys;
        NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->InitializationBlockLength,
            FALSE, Adapter->InitializationBlockVirt, PhysicalAddress);
      }
  
    if(Adapter->TransmitDescriptorRingVirt)
      {
 -      PhysicalAddress.u.LowPart = (ULONG)Adapter->TransmitDescriptorRingPhys;
 +      PhysicalAddress.u.LowPart = (ULONG_PTR)Adapter->TransmitDescriptorRingPhys;
        NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->TransmitDescriptorRingLength,
          FALSE, Adapter->TransmitDescriptorRingVirt, PhysicalAddress);
      }
  
    if(Adapter->ReceiveDescriptorRingVirt)
      {
 -      PhysicalAddress.u.LowPart = (ULONG)Adapter->ReceiveDescriptorRingPhys;
 +      PhysicalAddress.u.LowPart = (ULONG_PTR)Adapter->ReceiveDescriptorRingPhys;
        NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->ReceiveDescriptorRingLength,
            FALSE, Adapter->ReceiveDescriptorRingVirt, PhysicalAddress);
      }
  
    if(Adapter->TransmitBufferPtrVirt)
      {
 -      PhysicalAddress.u.LowPart = (ULONG)Adapter->TransmitBufferPtrPhys;
 +      PhysicalAddress.u.LowPart = (ULONG_PTR)Adapter->TransmitBufferPtrPhys;
        NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->TransmitBufferLength,
            FALSE, Adapter->TransmitBufferPtrVirt, PhysicalAddress);
      }
  
    if(Adapter->ReceiveBufferPtrVirt)
      {
 -      PhysicalAddress.u.LowPart = (ULONG)Adapter->ReceiveBufferPtrPhys;
 +      PhysicalAddress.u.LowPart = (ULONG_PTR)Adapter->ReceiveBufferPtrPhys;
        NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->ReceiveBufferLength,
            FALSE, Adapter->ReceiveBufferPtrVirt, PhysicalAddress);
      }
@@@ -573,6 -573,9 +573,9 @@@ MiniportHalt
    /* deregister i/o port range */
    NdisMDeregisterIoPortRange(Adapter->MiniportAdapterHandle, Adapter->IoBaseAddress, NUMBER_OF_PORTS, (PVOID)Adapter->PortOffset);
  
+   /* deregister the shutdown routine */
+   NdisMDeregisterAdapterShutdownHandler(Adapter->MiniportAdapterHandle);
    /* free shared memory */
    MiFreeSharedMemory(Adapter);
  
@@@ -697,9 -700,9 +700,9 @@@ MiInitChip
  
    /* set up csr1 and csr2 with init block */
    NdisRawWritePortUshort(Adapter->PortOffset + RAP, CSR1);
 -  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)((ULONG)Adapter->InitializationBlockPhys & 0xffff));
 +  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)((ULONG_PTR)Adapter->InitializationBlockPhys & 0xffff));
    NdisRawWritePortUshort(Adapter->PortOffset + RAP, CSR2);
 -  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)((ULONG)Adapter->InitializationBlockPhys >> 16) & 0xffff);
 +  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)((ULONG_PTR)Adapter->InitializationBlockPhys >> 16) & 0xffff);
  
    DPRINT("programmed with init block\n");
  
@@@ -781,6 -784,18 +784,18 @@@ MiTestCard
  }
  #endif
  
+ VOID
+ STDCALL
+ MiniportShutdown( PVOID Context )
+ {
+   PADAPTER Adapter = Context;
+   DPRINT("Stopping the chip\n");
+   NdisRawWritePortUshort(Adapter->PortOffset + RAP, CSR0);
+   NdisRawWritePortUshort(Adapter->PortOffset + RDP, CSR0_STOP);
+ }
  static NDIS_STATUS
  STDCALL
  MiniportInitialize(
      ASSERT(0);
  #endif
  
+   NdisMRegisterAdapterShutdownHandler(Adapter->MiniportAdapterHandle, Adapter, MiniportShutdown);
    DPRINT("returning 0x%x\n", Status);
    *OpenErrorStatus = Status;
    return Status;
@@@ -1759,25 -1759,8 +1759,25 @@@ typedef struct _CM_PARTIAL_RESOURCE_DES
      struct {
        ULONG Level;
        ULONG Vector;
 -      ULONG Affinity;
 +      KAFFINITY Affinity;
      } Interrupt;
 +#if (NTDDI_VERSION >= NTDDI_LONGHORN)
 +    struct {
 +      union {
 +        struct {
 +          USHORT Reserved;
 +          USHORT MessageCount;
 +          ULONG Vector;
 +          KAFFINITY Affinity;
 +        } Raw;
 +        struct {
 +          ULONG Level;
 +          ULONG Vector;
 +          KAFFINITY Affinity;
 +        } Translated;
 +      };
 +    } MessageInterrupt;
 +#endif
      struct {
        PHYSICAL_ADDRESS Start;
        ULONG Length;
        ULONG Reserved1;
        ULONG Reserved2;
      } DeviceSpecificData;
 +#if (NTDDI_VERSION >= NTDDI_LONGHORN)
 +    struct {
 +      PHYSICAL_ADDRESS Start;
 +      ULONG Length40;
 +    } Memory40;
 +    struct {
 +      PHYSICAL_ADDRESS Start;
 +      ULONG Length48;
 +    } Memory48;
 +    struct {
 +      PHYSICAL_ADDRESS Start;
 +      ULONG Length64;
 +    } Memory64;
 +#endif
    } u;
  } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  
@@@ -5470,8 -5439,6 +5470,8 @@@ typedef struct _KPCR 
    ULONG HalReserved[16];            // For use by Hal
  } KPCR, *PKPCR;                 /* 54 */
  
 +#define KeGetPcr()                      PCR
 +
  typedef struct _KFLOATING_SAVE {
    ULONG  ControlWord;
    ULONG  StatusWord;
@@@ -5689,8 -5656,6 +5689,8 @@@ typedef struct _KPCR 
    UCHAR  Number;                /* 51 */
  } KPCR, *PKPCR;                 /* 54 */
  
 +#define KeGetPcr()                      PCR
 +
  static __inline
  ULONG
  DDKAPI
@@@ -5725,8 -5690,6 +5725,8 @@@ typedef struct _KPCR 
      ULONG  IDR;                   /* 30 */
  } KPCR, *PKPCR;
  
 +#define KeGetPcr()                      PCR
 +
  typedef struct _KFLOATING_SAVE {
  } KFLOATING_SAVE, *PKFLOATING_SAVE;
  
@@@ -5824,7 -5787,6 +5824,7 @@@ typedef struct _PCIBUSDAT
  } PCIBUSDATA, *PPCIBUSDATA;
  
  
 +/** INTERLOCKED FUNCTIONS *****************************************************/
  
  #if !defined(__INTERLOCKED_DECLARED)
  #define __INTERLOCKED_DECLARED
@@@ -5941,97 -5903,64 +5941,97 @@@ InterlockedExchangeAdd
  #define InterlockedPushEntrySList(Head, Entry) ExpInterlockedPushEntrySList(Head, Entry)
  #define InterlockedFlushSList(Head) ExpInterlockedFlushSList(Head)
  #define QueryDepthSList(Head) ExQueryDepthSList(Head)
 -#endif // !defined(_WINBASE_
 +#endif // !defined(_WINBASE_)
  
  #endif // _M_AMD64
  
  #endif /* !__INTERLOCKED_DECLARED */
  
 +
 +/** SPINLOCK FUNCTIONS ********************************************************/
 +
  NTKERNELAPI
 -VOID
 +BOOLEAN
  FASTCALL
 -KefAcquireSpinLockAtDpcLevel(
 -  IN PKSPIN_LOCK  SpinLock);
 +KeTryToAcquireSpinLockAtDpcLevel(
 +    IN OUT PKSPIN_LOCK SpinLock
 +);
 +
 +#if defined (_X86_)
  
  NTKERNELAPI
  VOID
 -FASTCALL
 -KefReleaseSpinLockFromDpcLevel(
 +NTAPI
 +KeInitializeSpinLock(
    IN PKSPIN_LOCK  SpinLock);
  
 -#if defined(_M_AMD64)
 -NTKERNELAPI
 +NTHALAPI
  KIRQL
  FASTCALL
  KfAcquireSpinLock(
    IN PKSPIN_LOCK SpinLock);
  
 -NTKERNELAPI
 +NTHALAPI
  VOID
  FASTCALL
  KfReleaseSpinLock(
    IN PKSPIN_LOCK SpinLock,
    IN KIRQL NewIrql);
 -#else
 -NTHALAPI
 -KIRQL
 -FASTCALL
 -KfAcquireSpinLock(
 -  IN PKSPIN_LOCK SpinLock);
  
 -NTHALAPI
 +NTKERNELAPI
  VOID
  FASTCALL
 -KfReleaseSpinLock(
 -  IN PKSPIN_LOCK SpinLock,
 -  IN KIRQL NewIrql);
 -#endif
 +KefAcquireSpinLockAtDpcLevel(
 +  IN PKSPIN_LOCK  SpinLock);
  
  NTKERNELAPI
 -BOOLEAN
 +VOID
  FASTCALL
 -KeTryToAcquireSpinLockAtDpcLevel(
 -    IN OUT PKSPIN_LOCK SpinLock
 -);
 +KefReleaseSpinLockFromDpcLevel(
 +  IN PKSPIN_LOCK  SpinLock);
  
  #define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
  #define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
  #define KeAcquireSpinLock(a,b)  *(b) = KfAcquireSpinLock(a)
  #define KeReleaseSpinLock(a,b)  KfReleaseSpinLock(a,b)
  
 +#else // !defined (_X86_)
 +
 +FORCEINLINE
 +VOID
 +NTAPI
 +KeInitializeSpinLock(
 +  PKSPIN_LOCK SpinLock)
 +{
 +    *SpinLock = 0;
 +}
 +
 +NTKERNELAPI
 +VOID
 +KeReleaseSpinLock(
 +  IN PKSPIN_LOCK SpinLock,
 +  IN KIRQL NewIrql);
 +
 +NTKERNELAPI
 +VOID
 +KeAcquireSpinLockAtDpcLevel(
 +  IN PKSPIN_LOCK SpinLock);
 +
 +NTKERNELAPI
 +VOID
 +KeReleaseSpinLockFromDpcLevel(
 +  IN PKSPIN_LOCK SpinLock);
 +
 +NTKERNELAPI
 +KIRQL
 +KeAcquireSpinLockRaiseToDpc(
 +  IN PKSPIN_LOCK SpinLock);
 +
 +#define KeAcquireSpinLock(SpinLock, OldIrql) \
 +  *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
 +
 +#endif // !defined (_X86_)
 +
  #define RtlCopyMemoryNonTemporal RtlCopyMemory
  
  #define KeGetDcacheFillSize() 1L
@@@ -6430,23 -6359,17 +6430,23 @@@ RtlConvertLongToLargeInteger(LONG Signe
      return Result;
  }
  
 +static __inline
 +LARGE_INTEGER
 +NTAPI_INLINE
 +RtlConvertUlongToLargeInteger(
 +  ULONG UnsignedInteger)
 +{
 +    LARGE_INTEGER ret;
 +    ret.QuadPart = UnsignedInteger;
 +    return ret;
 +}
 +
  NTSYSAPI
  LUID
  NTAPI
  RtlConvertLongToLuid(
    IN LONG  Long);
  
 -NTSYSAPI
 -LARGE_INTEGER
 -NTAPI
 -RtlConvertUlongToLargeInteger(
 -  IN ULONG  UnsignedInteger);
  
  NTSYSAPI
  LUID
@@@ -6454,37 -6377,6 +6454,37 @@@ NTAP
  RtlConvertUlongToLuid(
    ULONG  Ulong);
  
 +#ifdef _M_AMD64
 +
 +static __inline
 +LARGE_INTEGER
 +NTAPI_INLINE
 +RtlExtendedIntegerMultiply(
 +  LARGE_INTEGER Multiplicand,
 +  LONG Multiplier)
 +{
 +    LARGE_INTEGER ret;
 +    ret.QuadPart = Multiplicand.QuadPart * Multiplier;
 +    return ret;
 +}
 +
 +static __inline
 +LARGE_INTEGER
 +NTAPI_INLINE
 +RtlExtendedLargeIntegerDivide(
 +  LARGE_INTEGER Dividend,
 +  ULONG Divisor,
 +  PULONG Remainder)
 +{
 +    LARGE_INTEGER ret;
 +    ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
 +    if (Remainder)
 +        *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
 +    return ret;
 +}
 +
 +#endif
 +
  /*
   * VOID
   * RtlCopyMemory(
@@@ -7763,7 -7655,7 +7763,7 @@@ VOI
  NTAPI
  ProbeForRead(
    IN CONST VOID  *Address,
-   IN ULONG  Length,
+   IN SIZE_T  Length,
    IN ULONG  Alignment);
  
  NTKERNELAPI
@@@ -7771,7 -7663,7 +7771,7 @@@ VOI
  NTAPI
  ProbeForWrite(
    IN PVOID  Address,
-   IN ULONG  Length,
+   IN SIZE_T  Length,
    IN ULONG  Alignment);
  
  
@@@ -9690,6 -9582,12 +9690,6 @@@ KeInitializeSemaphore
    IN LONG  Count,
    IN LONG  Limit);
  
 -NTKERNELAPI
 -VOID
 -NTAPI
 -KeInitializeSpinLock(
 -  IN PKSPIN_LOCK  SpinLock);
 -
  NTKERNELAPI
  VOID
  NTAPI
@@@ -11207,8 -11105,8 +11207,8 @@@ NtMapViewOfSection
    IN HANDLE  SectionHandle,
    IN HANDLE  ProcessHandle,
    IN OUT PVOID  *BaseAddress,
 -  IN ULONG  ZeroBits,
 -  IN ULONG  CommitSize,
 +  IN ULONG_PTR  ZeroBits,
 +  IN SIZE_T  CommitSize,
    IN OUT PLARGE_INTEGER  SectionOffset  OPTIONAL,
    IN OUT PSIZE_T  ViewSize,
    IN SECTION_INHERIT  InheritDisposition,
@@@ -11222,8 -11120,8 +11222,8 @@@ ZwMapViewOfSection
    IN HANDLE  SectionHandle,
    IN HANDLE  ProcessHandle,
    IN OUT PVOID  *BaseAddress,
 -  IN ULONG  ZeroBits,
 -  IN ULONG  CommitSize,
 +  IN ULONG_PTR  ZeroBits,
 +  IN SIZE_T  CommitSize,
    IN OUT PLARGE_INTEGER  SectionOffset  OPTIONAL,
    IN OUT PSIZE_T  ViewSize,
    IN SECTION_INHERIT  InheritDisposition,
@@@ -35,8 -35,11 +35,11 @@@ typedef struct _USER_OBJHD
      HANDLE Handle;
  } USER_OBJHDR, PUSER_OBJHDR;
  
- typedef struct _DESKTOP
+ typedef struct _DESKTOPINFO
  {
+     PVOID pvDesktopBase;
+     PVOID pvDesktopLimit;
      HANDLE hKernelHeap;
      ULONG_PTR HeapLimit;
      HWND hTaskManWindow;
@@@ -54,7 -57,7 +57,7 @@@
      };
  
      WCHAR szDesktopName[1];
- } DESKTOP, *PDESKTOP;
+ } DESKTOPINFO, *PDESKTOPINFO;
  
  typedef struct _CALLPROC
  {
@@@ -70,7 -73,7 +73,7 @@@ typedef struct _WINDOWCLAS
      struct _WINDOWCLASS *Next;
      struct _WINDOWCLASS *Clone;
      struct _WINDOWCLASS *Base;
-     PDESKTOP Desktop;
+     struct _DESKTOP *rpdeskParent;
      RTL_ATOM Atom;
      ULONG Windows;
  
@@@ -113,6 -116,7 +116,7 @@@ typedef struct _WINDO
               is moved to this structure */
      struct _W32PROCESSINFO *pi; /* FIXME: Move to object header some day */
      struct _W32THREADINFO *ti;
+     struct _DESKTOP *pdesktop;
      RECT WindowRect;
      RECT ClientRect;
  
@@@ -297,6 -301,11 +301,11 @@@ typedef struct _W32PROCESSINF
  typedef struct _CLIENTTHREADINFO
  {
      DWORD CTI_flags;
+     WORD  fsChangeBits;
+     WORD  fsWakeBits;
+     WORD  fsWakeBitsJournal;
+     WORD  fsWakeMask;
+     LONG  timeLastRead;
      DWORD dwcPumpHook;
  } CLIENTTHREADINFO, *PCLIENTTHREADINFO;
  
@@@ -304,15 -313,11 +313,11 @@@ typedef struct _W32THREADINF
  {
      PW32PROCESSINFO pi; /* [USER] */
      PW32PROCESSINFO kpi; /* [KERNEL] */
-     PDESKTOP Desktop;
-     PVOID DesktopHeapBase;
-     ULONG_PTR DesktopHeapLimit;
-     ULONG_PTR DesktopHeapDelta;
+     PDESKTOPINFO Desktop;
+ //    PVOID DesktopHeapBase;
+ //    ULONG_PTR DesktopHeapLimit;
      /* A mask of what hooks are currently active */
      ULONG Hooks;
-     /* Application compatibility flags */
-     DWORD AppCompatFlags;
-     DWORD AppCompatFlags2;
      CLIENTTHREADINFO ClientThreadInfo;
  } W32THREADINFO, *PW32THREADINFO;
  
@@@ -340,34 -345,39 +345,39 @@@ typedef struct _CALLBACKWN
  
  #define CI_CURTHPRHOOK    0x00000010
  
- typedef struct _W32CLIENTINFO
+ typedef struct _CLIENTINFO
  {
      ULONG CI_flags;
      ULONG cSpins;
-     ULONG ulWindowsVersion;
-     ULONG ulAppCompatFlags;
-     ULONG ulAppCompatFlags2;
+     DWORD dwExpWinVer;
+     DWORD dwCompatFlags;
+     DWORD dwCompatFlags2;
      DWORD dwTIFlags;
-     PVOID pDeskInfo;
+     PDESKTOPINFO pDeskInfo;
      ULONG_PTR ulClientDelta;
      PHOOK phkCurrent;
      ULONG fsHooks;
-     HWND  hWND;  // Will be replaced with CALLBACKWND.
-     PVOID pvWND; // " "
+     CALLBACKWND CallbackWnd;
      ULONG Win32ClientInfo;
      DWORD dwHookCurrent;
-     ULONG Win32ClientInfo1;
+     INT cInDDEMLCallback;
      PCLIENTTHREADINFO pClientThreadInfo;
      DWORD dwHookData;
      DWORD dwKeyCache;
-     ULONG Win32ClientInfo2[7];
+     DWORD afKeyState[2];
+     DWORD dwAsyncKeyCache;
+     DWORD afAsyncKeyState[2];
+     DWORD afAsyncKeyStateRecentDow[2];
+     HKL hKL;
      USHORT CodePage;
-     USHORT csCF;
-     HANDLE hKL;
+     USHORT achDbcsCF;
      ULONG Win32ClientInfo3[35];
- } W32CLIENTINFO, *PW32CLIENTINFO;
+ } CLIENTINFO, *PCLIENTINFO;
+ /* Make sure it fits exactly into the TEB */
+ C_ASSERT(sizeof(CLIENTINFO) == FIELD_OFFSET(TEB, glDispatchTable) - FIELD_OFFSET(TEB, Win32ClientInfo));
  
- #define GetWin32ClientInfo() (PW32CLIENTINFO)(NtCurrentTeb()->Win32ClientInfo)
+ #define GetWin32ClientInfo() ((PCLIENTINFO)(NtCurrentTeb()->Win32ClientInfo))
  
  // Server event activity bits.
  #define SRV_EVENT_MENU            0x0001
@@@ -882,18 -892,18 +892,18 @@@ NtUserCallNextHookEx
    LPARAM lParam,
    BOOL Ansi);
  
 -DWORD
 +DWORD_PTR
  NTAPI
  NtUserCallNoParam(
    DWORD Routine);
  
 -DWORD
 +DWORD_PTR
  NTAPI
  NtUserCallOneParam(
    DWORD Param,
    DWORD Routine);
  
 -DWORD
 +DWORD_PTR
  NTAPI
  NtUserCallTwoParam(
    DWORD Param1,
@@@ -1618,7 -1628,7 +1628,7 @@@ enum ThreadStateRoutine
      THREADSTATE_TASKMANWINDOW
  };
  
 -DWORD
 +DWORD_PTR
  NTAPI
  NtUserGetThreadState(
    DWORD Routine);
@@@ -150,18 -150,59 +150,59 @@@ NTAP
  MmGetFileNameForAddress(IN PVOID Address,
                          OUT PUNICODE_STRING ModuleName)
  {
-     /*
-      * FIXME: TODO.
-      * Filip says to get the MM_AVL_TABLE from EPROCESS,
-      * then use the MmMarea routines to locate the Marea that
-      * corresponds to the address. Then make sure it's a section
-      * view type (MEMORY_AREA_SECTION_VIEW) and use the marea's
-      * per-type union to get the .u.SectionView.Section pointer to
-      * the SECTION_OBJECT. Then we can use MmGetFileNameForSection
-      * to get the full filename.
-      */
-     RtlCreateUnicodeString(ModuleName, L"C:\\ReactOS\\system32\\ntdll.dll");
-     return STATUS_SUCCESS;
+    PROS_SECTION_OBJECT Section;
+    PMEMORY_AREA MemoryArea;
+    PMM_AVL_TABLE AddressSpace;
+    POBJECT_NAME_INFORMATION ModuleNameInformation;
+    NTSTATUS Status = STATUS_ADDRESS_NOT_ASSOCIATED;
+    /* Get the MM_AVL_TABLE from EPROCESS */
+    if (Address >= MmSystemRangeStart)
+    {
+       AddressSpace = MmGetKernelAddressSpace();
+    }
+    else
+    {
+       AddressSpace = &PsGetCurrentProcess()->VadRoot;
+    }
+    /* Lock address space */
+    MmLockAddressSpace(AddressSpace);
+    /* Locate the memory area for the process by address */
+    MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, Address);
+    /* Make sure it's a section view type */
+    if ((MemoryArea != NULL) && (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW))
+    {
+       /* Get the section pointer to the SECTION_OBJECT */
+       Section = MemoryArea->Data.SectionData.Section;
+       /* Unlock address space */
+       MmUnlockAddressSpace(AddressSpace);
+       /* Get the filename of the section */
+       Status = MmGetFileNameForSection(Section,&ModuleNameInformation);
+       if (NT_SUCCESS(Status))
+       {
+          /* Init modulename */
+          RtlCreateUnicodeString(ModuleName,
+                                 ModuleNameInformation->Name.Buffer);
+          /* Free temp taged buffer from MmGetFileNameForSection() */
+          ExFreePoolWithTag(ModuleNameInformation, TAG('M', 'm', ' ', ' '));
+          DPRINT("Found ModuleName %S by address %p\n",
+                 ModuleName->Buffer,Address);
+       }
+    }
+    else
+    {
+       /* Unlock address space */
+       MmUnlockAddressSpace(AddressSpace);
+    }
+    return Status;
  }
  
  /* Note: Mmsp prefix denotes "Memory Manager Section Private". */
@@@ -2052,7 -2093,7 +2093,7 @@@ NTSTATUS STDCAL
  MmQuerySectionView(PMEMORY_AREA MemoryArea,
                     PVOID Address,
                     PMEMORY_BASIC_INFORMATION Info,
 -                   PULONG ResultLength)
 +                   PSIZE_T ResultLength)
  {
     PMM_REGION Region;
     PVOID RegionBaseAddress;
@@@ -2381,7 -2422,6 +2422,7 @@@ MmCreateDataFileSection(PROS_SECTION_OB
     LARGE_INTEGER Offset;
     CHAR Buffer;
     FILE_STANDARD_INFORMATION FileInfo;
 +   ULONG Length;
  
     /*
      * Create the section
                                     FileStandardInformation,
                                     sizeof(FILE_STANDARD_INFORMATION),
                                     &FileInfo,
 -                                   &Iosb.Information);
 +                                   &Length);
 +   Iosb.Information = Length;
     if (!NT_SUCCESS(Status))
     {
        ObDereferenceObject(Section);
@@@ -4187,8 -4226,8 +4228,8 @@@ NTSTATUS STDCAL
  NtQuerySection(IN HANDLE SectionHandle,
                 IN SECTION_INFORMATION_CLASS SectionInformationClass,
                 OUT PVOID SectionInformation,
 -               IN ULONG SectionInformationLength,
 -               OUT PULONG ResultLength  OPTIONAL)
 +               IN SIZE_T SectionInformationLength,
 +               OUT PSIZE_T ResultLength  OPTIONAL)
  {
     PROS_SECTION_OBJECT Section;
     KPROCESSOR_MODE PreviousMode;
@@@ -4735,7 -4774,7 +4776,7 @@@ MmForceSectionClosed 
  NTSTATUS STDCALL
  MmMapViewInSystemSpace (IN PVOID SectionObject,
                          OUT PVOID * MappedBase,
 -                        IN OUT PULONG ViewSize)
 +                        IN OUT PSIZE_T ViewSize)
  {
     PROS_SECTION_OBJECT Section;
     PMM_AVL_TABLE AddressSpace;
@@@ -42,7 -42,7 +42,7 @@@
  
  typedef struct _INT_CALLBACK_HEADER
  {
-    /* list entry in the W32THREAD structure */
+    /* list entry in the THREADINFO structure */
     LIST_ENTRY ListEntry;
  }
  INT_CALLBACK_HEADER, *PINT_CALLBACK_HEADER;
@@@ -51,7 -51,7 +51,7 @@@ PVOID FASTCAL
  IntCbAllocateMemory(ULONG Size)
  {
     PINT_CALLBACK_HEADER Mem;
-    PW32THREAD W32Thread;
+    PTHREADINFO W32Thread;
  
     if(!(Mem = ExAllocatePoolWithTag(PagedPool, Size + sizeof(INT_CALLBACK_HEADER),
                                      TAG_CALLBACK)))
@@@ -73,7 -73,7 +73,7 @@@ VOID FASTCAL
  IntCbFreeMemory(PVOID Data)
  {
     PINT_CALLBACK_HEADER Mem;
-    PW32THREAD W32Thread;
+    PTHREADINFO W32Thread;
  
     ASSERT(Data);
  
@@@ -90,7 -90,7 +90,7 @@@
  }
  
  VOID FASTCALL
- IntCleanupThreadCallbacks(PW32THREAD W32Thread)
+ IntCleanupThreadCallbacks(PTHREADINFO W32Thread)
  {
     PLIST_ENTRY CurrentEntry;
     PINT_CALLBACK_HEADER Mem;
@@@ -116,22 -116,22 +116,22 @@@ IntSetTebWndCallback (HWND * hWnd, PVOI
  {
    HWND hWndS = *hWnd;
    PWINDOW_OBJECT Window = UserGetWindowObject(*hWnd);
-   PW32CLIENTINFO ClientInfo = GetWin32ClientInfo();
+   PCLIENTINFO ClientInfo = GetWin32ClientInfo();
  
-   *hWnd = ClientInfo->hWND;
-   *pWnd = ClientInfo->pvWND;
+   *hWnd = ClientInfo->CallbackWnd.hWnd;
+   *pWnd = ClientInfo->CallbackWnd.pvWnd;
  
-   ClientInfo->hWND  = hWndS;
-   ClientInfo->pvWND = DesktopHeapAddressToUser(Window->Wnd);
+   ClientInfo->CallbackWnd.hWnd  = hWndS;
+   ClientInfo->CallbackWnd.pvWnd = DesktopHeapAddressToUser(Window->Wnd);
  }
  
  static VOID
  IntRestoreTebWndCallback (HWND hWnd, PVOID pWnd)
  {
-   PW32CLIENTINFO ClientInfo = GetWin32ClientInfo();
+   PCLIENTINFO ClientInfo = GetWin32ClientInfo();
  
-   ClientInfo->hWND  = hWnd;
-   ClientInfo->pvWND = pWnd;
+   ClientInfo->CallbackWnd.hWnd = hWnd;
+   ClientInfo->CallbackWnd.pvWnd = pWnd;
  }
  
  /* FUNCTIONS *****************************************************************/
@@@ -440,7 -440,7 +440,7 @@@ co_IntCallHookProc(INT HookId
                 {
                    RtlCopyMemory(Extra, ClassName->Buffer, ClassName->Length);
                    CbtCreatewndExtra->Cs.lpszClass =
 -                     (LPCWSTR) MAKELONG(Extra - (PCHAR) CbtCreatewndExtra, 1);
 +                     (LPCWSTR)(ULONG_PTR) MAKELONG(Extra - (PCHAR) CbtCreatewndExtra, 1);
                    Extra += ClassName->Length;
                    *((WCHAR *) Extra) = L'\0';
                 }
@@@ -573,7 -573,7 +573,7 @@@ co_IntCallEventProc(HWINEVENTHOOK hook
     IntRestoreTebWndCallback (hWnd, pWnd);
  
     IntCbFreeMemory(Argument);
 -  
 +
     if (!NT_SUCCESS(Status))
     {
        return 0;
@@@ -85,9 -85,9 +85,9 @@@ IntDestroyClass(IN OUT PWINDOWCLASS Cla
      }
  
      /* free the structure */
-     if (Class->Desktop != NULL)
+     if (Class->rpdeskParent != NULL)
      {
-         DesktopHeapFree(Class->Desktop,
+         DesktopHeapFree(Class->rpdeskParent,
                          Class);
      }
      else
@@@ -403,7 -403,7 +403,7 @@@ IntGetClassForDesktop(IN OUT PWINDOWCLA
      ASSERT(Desktop != NULL);
      ASSERT(BaseClass->Base == BaseClass);
  
-     if (BaseClass->Desktop == Desktop)
+     if (BaseClass->rpdeskParent == Desktop)
      {
          /* it is most likely that a window is created on the same
             desktop as the window class. */
          return BaseClass;
      }
  
-     if (BaseClass->Desktop == NULL)
+     if (BaseClass->rpdeskParent == NULL)
      {
          ASSERT(BaseClass->Windows == 0);
          ASSERT(BaseClass->Clone == NULL);
          Class = BaseClass->Clone;
          while (Class != NULL)
          {
-             if (Class->Desktop == Desktop)
+             if (Class->rpdeskParent == Desktop)
              {
                  ASSERT(Class->Base == BaseClass);
                  ASSERT(Class->Clone == NULL);
                            ClassSize);
  
              /* update some pointers and link the class */
-             Class->Desktop = Desktop;
+             Class->rpdeskParent = Desktop;
              Class->Windows = 0;
  
-             if (BaseClass->Desktop == NULL)
+             if (BaseClass->rpdeskParent == NULL)
              {
                  /* we don't really need the base class on the shared
                     heap anymore, delete it so the only class left is
                  Class->Clone = NULL;
                  Class->Base = BaseClass;
                  Class->Next = BaseClass->Clone;
 -                (void)InterlockedExchangePointer(&BaseClass->Clone,
 +                (void)InterlockedExchangePointer((VOID*)&BaseClass->Clone,
                                                   Class);
              }
          }
@@@ -528,9 -528,9 +528,9 @@@ IntMakeCloneBaseClass(IN OUT PWINDOWCLA
  
      ASSERT(Class->Base != Class);
      ASSERT(Class->Base->Clone != NULL);
-     ASSERT(Class->Desktop != NULL);
+     ASSERT(Class->rpdeskParent != NULL);
      ASSERT(Class->Windows != 0);
-     ASSERT(Class->Base->Desktop != NULL);
+     ASSERT(Class->Base->rpdeskParent != NULL);
      ASSERT(Class->Base->Windows == 0);
  
      /* unlink the clone */
  
  VOID
  IntDereferenceClass(IN OUT PWINDOWCLASS Class,
-                     IN PDESKTOP Desktop,
+                     IN PDESKTOPINFO Desktop,
                      IN PW32PROCESSINFO pi)
  {
      PWINDOWCLASS *PrevLink, BaseClass, CurrentClass;
@@@ -648,7 -648,7 +648,7 @@@ IntMoveClassToSharedHeap(IN OUT PWINDOW
      SIZE_T ClassSize;
  
      ASSERT(Class->Base == Class);
-     ASSERT(Class->Desktop != NULL);
+     ASSERT(Class->rpdeskParent != NULL);
      ASSERT(Class->Windows == 0);
      ASSERT(Class->Clone == NULL);
  
                        Class,
                        ClassSize);
  
-         NewClass->Desktop = NULL;
+         NewClass->rpdeskParent = NULL;
          NewClass->Base = NewClass;
  
          /* replace the class in the list */
@@@ -704,7 -704,7 +704,7 @@@ IntCheckDesktopClasses(IN PDESKTOP Desk
  
          ASSERT(Class->Base == Class);
  
-         if (Class->Desktop == Desktop &&
+         if (Class->rpdeskParent == Desktop &&
              Class->Windows == 0)
          {
              /* there shouldn't be any clones around anymore! */
@@@ -838,7 -838,7 +838,7 @@@ IntCreateClass(IN CONST WNDCLASSEXW* lp
          RtlZeroMemory(Class,
                        ClassSize);
  
-         Class->Desktop = Desktop;
+         Class->rpdeskParent = Desktop;
          Class->Base = Class;
          Class->Atom = Atom;
  
@@@ -1131,6 -1131,7 +1131,7 @@@ UserRegisterClass(IN CONST WNDCLASSEXW
                    IN WNDPROC wpExtra,
                    IN DWORD dwFlags)
  {
+     PTHREADINFO pti;
      PW32THREADINFO ti;
      PW32PROCESSINFO pi;
      PWINDOWCLASS Class;
  
      /* NOTE: Accessing the buffers in ClassName and MenuName may raise exceptions! */
  
+     pti = PsGetCurrentThreadWin32Thread();
      ti = GetW32ThreadInfo();
      if (ti == NULL || !ti->kpi->RegisteredSysClasses)
      {
                             MenuName,
                             wpExtra,
                             dwFlags,
-                            ti->Desktop,
+                            pti->Desktop,
                             pi);
  
      if (Class != NULL)
@@@ -72,9 -72,9 +72,9 @@@ PHOOK FASTCALL IntGetHookObject(HHOOK h
  static PHOOK
  IntAddHook(PETHREAD Thread, int HookId, BOOLEAN Global, PWINSTATION_OBJECT WinStaObj)
  {
-    PW32THREAD W32Thread;
+    PTHREADINFO W32Thread;
     PHOOK Hook;
-    PHOOKTABLE Table = Global ? GlobalHooks : MsqGetHooks(((PW32THREAD)Thread->Tcb.Win32Thread)->MessageQueue);
+    PHOOKTABLE Table = Global ? GlobalHooks : MsqGetHooks(((PTHREADINFO)Thread->Tcb.Win32Thread)->MessageQueue);
     HANDLE Handle;
  
     if (NULL == Table)
@@@ -90,7 -90,7 +90,7 @@@
        }
        else
        {
-          MsqSetHooks(((PW32THREAD)Thread->Tcb.Win32Thread)->MessageQueue, Table);
+          MsqSetHooks(((PTHREADINFO)Thread->Tcb.Win32Thread)->MessageQueue, Table);
        }
     }
  
  
     if (Thread)
     {
-       W32Thread = ((PW32THREAD)Thread->Tcb.Win32Thread);
+       W32Thread = ((PTHREADINFO)Thread->Tcb.Win32Thread);
        ASSERT(W32Thread != NULL);
        W32Thread->Hooks |= HOOKID_TO_FLAG(HookId);
        if (W32Thread->ThreadInfo != NULL)
@@@ -130,7 -130,7 +130,7 @@@ IntGetTable(PHOOK Hook
        return GlobalHooks;
     }
  
-    return MsqGetHooks(((PW32THREAD)Hook->Thread->Tcb.Win32Thread)->MessageQueue);
+    return MsqGetHooks(((PTHREADINFO)Hook->Thread->Tcb.Win32Thread)->MessageQueue);
  }
  
  /* get the first hook in the chain */
@@@ -208,7 -208,7 +208,7 @@@ IntFreeHook(PHOOKTABLE Table, PHOOK Hoo
  static VOID
  IntRemoveHook(PHOOK Hook, PWINSTATION_OBJECT WinStaObj, BOOL TableAlreadyLocked)
  {
-    PW32THREAD W32Thread;
+    PTHREADINFO W32Thread;
     PHOOKTABLE Table = IntGetTable(Hook);
  
     ASSERT(NULL != Table);
        return;
     }
  
-    W32Thread = ((PW32THREAD)Hook->Thread->Tcb.Win32Thread);
+    W32Thread = ((PTHREADINFO)Hook->Thread->Tcb.Win32Thread);
     ASSERT(W32Thread != NULL);
     W32Thread->Hooks &= ~HOOKID_TO_FLAG(Hook->HookId);
     if (W32Thread->ThreadInfo != NULL)
@@@ -274,8 -274,8 +274,8 @@@ IntCallLowLevelHook(PHOOK Hook, INT Cod
  
     /* FIXME should get timeout from
      * HKEY_CURRENT_USER\Control Panel\Desktop\LowLevelHooksTimeout */
-    Status = co_MsqSendMessage(((PW32THREAD)Hook->Thread->Tcb.Win32Thread)->MessageQueue,
+    Status = co_MsqSendMessage(((PTHREADINFO)Hook->Thread->Tcb.Win32Thread)->MessageQueue,
 -                                    (HWND) Code,
 +                               (HWND)(UINT_PTR)Code,
                                     Hook->HookId,
                                           wParam,
                                           lParam,
@@@ -295,8 -295,8 +295,8 @@@ FASTCAL
  co_HOOK_CallHooks(INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
  {
     PHOOK Hook, SaveHook;
-    PW32THREAD Win32Thread;
-    PW32CLIENTINFO ClientInfo;
+    PTHREADINFO pti;
+    PCLIENTINFO ClientInfo;
     PHOOKTABLE Table;
     LRESULT Result;
     PWINSTATION_OBJECT WinStaObj;
  
     ASSERT(WH_MINHOOK <= HookId && HookId <= WH_MAXHOOK);
  
-    Win32Thread = PsGetCurrentThreadWin32Thread();
-    if (NULL == Win32Thread)
+    pti = PsGetCurrentThreadWin32Thread();
+    if (!pti)
     {
        Table = NULL;
     }
     else
     {
-       Table = MsqGetHooks(Win32Thread->MessageQueue);
+       Table = MsqGetHooks(pti->MessageQueue);
     }
  
     if (NULL == Table || ! (Hook = IntGetFirstValidHook(Table, HookId)))
     }
     else
     {
-       IntReleaseHookChain(MsqGetHooks(PsGetCurrentThreadWin32Thread()->MessageQueue), HookId, WinStaObj);
+       IntReleaseHookChain(MsqGetHooks(pti->MessageQueue), HookId, WinStaObj);
        IntReleaseHookChain(GlobalHooks, HookId, WinStaObj);
        ObDereferenceObject(WinStaObj);
     }
@@@ -886,7 -886,7 +886,7 @@@ NtUserCallNextHookEx
     BOOL Ansi)
  {
     PHOOK HookObj, NextObj;
-    PW32CLIENTINFO ClientInfo;
+    PCLIENTINFO ClientInfo;
     PWINSTATION_OBJECT WinStaObj;
     NTSTATUS Status;
     DECLARE_RETURN(LRESULT);
@@@ -942,7 -942,7 +942,7 @@@ CLEANUP
  HHOOK
  STDCALL
  NtUserSetWindowsHookAW(
 -   int idHook, 
 +   int idHook,
     HOOKPROC lpfn,
     BOOL Ansi)
  {
@@@ -962,7 -962,7 +962,7 @@@ NtUserSetWindowsHookEx
     BOOL Ansi)
  {
     PWINSTATION_OBJECT WinStaObj;
-    PW32CLIENTINFO ClientInfo;
+    PCLIENTINFO ClientInfo;
     BOOLEAN Global;
     PETHREAD Thread;
     PHOOK Hook;
        }
        Mod = NULL;
        Global = FALSE;
 -      if (! NT_SUCCESS(PsLookupThreadByThreadId((HANDLE) ThreadId, &Thread)))
 +      if (! NT_SUCCESS(PsLookupThreadByThreadId((HANDLE)(DWORD_PTR)ThreadId, &Thread)))
        {
           DPRINT1("Invalid thread id 0x%x\n", ThreadId);
           SetLastWin32Error(ERROR_INVALID_PARAMETER);
@@@ -1214,5 -1214,5 +1214,5 @@@ CLEANUP
     UserLeave();
     END_CLEANUP;
  }
 - 
 +
  /* EOF */
@@@ -228,7 -228,7 +228,7 @@@ static PKBL UserLoadDllAndCreateKbl(DWO
        hKl |= 0xe001 << 16; /* FIXME */\r
     else hKl |= hKl << 16;\r
  \r
 -   NewKbl->hkl = (HKL) hKl;\r
 +   NewKbl->hkl = (HKL)(ULONG_PTR) hKl;\r
     NewKbl->klid = LocaleId;\r
     NewKbl->Flags = 0;\r
     NewKbl->RefCount = 0;\r
@@@ -407,7 -407,7 +407,7 @@@ BOOL UserUnloadKbl(PKBL pKbl
     return TRUE;\r
  }\r
  \r
- static PKBL co_UserActivateKbl(PW32THREAD w32Thread, PKBL pKbl, UINT Flags)\r
+ static PKBL co_UserActivateKbl(PTHREADINFO w32Thread, PKBL pKbl, UINT Flags)\r
  {\r
     PKBL Prev;\r
  \r
@@@ -444,7 -444,7 +444,7 @@@ UserGetKeyboardLayout
  {\r
     NTSTATUS Status;\r
     PETHREAD Thread;\r
-    PW32THREAD W32Thread;\r
+    PTHREADINFO W32Thread;\r
     HKL Ret;\r
  \r
     if(!dwThreadId)\r
        return W32Thread->KeyboardLayout->hkl;\r
     }\r
  \r
 -   Status = PsLookupThreadByThreadId((HANDLE)dwThreadId, &Thread);\r
 +   Status = PsLookupThreadByThreadId((HANDLE)(DWORD_PTR)dwThreadId, &Thread);\r
     if(!NT_SUCCESS(Status))\r
     {\r
        SetLastWin32Error(ERROR_INVALID_PARAMETER);\r
@@@ -523,13 -523,15 +523,15 @@@ NtUserGetKeyboardLayoutName
  {\r
     BOOL ret = FALSE;\r
     PKBL pKbl;\r
+    PTHREADINFO pti;\r
  \r
     UserEnterShared();\r
  \r
     _SEH_TRY\r
     {\r
        ProbeForWrite(lpszName, KL_NAMELENGTH*sizeof(WCHAR), 1);\r
-       pKbl = PsGetCurrentThreadWin32Thread()->KeyboardLayout;\r
+       pti = PsGetCurrentThreadWin32Thread();\r
+       pKbl = pti->KeyboardLayout;\r
        RtlCopyMemory(lpszName,  pKbl->Name, KL_NAMELENGTH*sizeof(WCHAR));\r
        ret = TRUE;\r
     }\r
@@@ -614,7 -616,7 +616,7 @@@ NtUserActivateKeyboardLayout
  {\r
     PKBL pKbl;\r
     HKL Ret = NULL;\r
-    PW32THREAD pWThread;\r
+    PTHREADINFO pWThread;\r
  \r
     UserEnterExclusive();\r
  \r
@@@ -313,6 -313,7 +313,7 @@@ PMENU_OBJECT FASTCAL
  IntCreateMenu(PHANDLE Handle, BOOL IsMenuBar)
  {
     PMENU_OBJECT Menu;
+    PW32PROCESS CurrentWin32Process;
  
     Menu = (PMENU_OBJECT)UserCreateObject(
               gHandleTable, Handle,
     Menu->MenuItemList = NULL;
  
     /* Insert menu item into process menu handle list */
-    InsertTailList(&PsGetCurrentProcessWin32Process()->MenuListHead, &Menu->ListEntry);
+    CurrentWin32Process = PsGetCurrentProcessWin32Process();
+    InsertTailList(&CurrentWin32Process->MenuListHead, &Menu->ListEntry);
  
     return Menu;
  }
@@@ -416,6 -418,7 +418,7 @@@ IntCloneMenuItems(PMENU_OBJECT Destinat
  PMENU_OBJECT FASTCALL
  IntCloneMenu(PMENU_OBJECT Source)
  {
+    PW32PROCESS CurrentWin32Process;
     HANDLE hMenu;
     PMENU_OBJECT Menu;
  
     Menu->MenuItemList = NULL;
  
     /* Insert menu item into process menu handle list */
-    InsertTailList(&PsGetCurrentProcessWin32Process()->MenuListHead, &Menu->ListEntry);
+    CurrentWin32Process = PsGetCurrentProcessWin32Process();
+    InsertTailList(&CurrentWin32Process->MenuListHead, &Menu->ListEntry);
  
     IntCloneMenuItems(Menu, Source);
  
@@@ -1885,7 -1889,7 +1889,7 @@@ NtUserGetMenuBarInfo
          RETURN(FALSE);
       }
  
 -   hMenu = (HMENU)WindowObject->Wnd->IDMenu;
 +   hMenu = (HMENU)(DWORD_PTR)WindowObject->Wnd->IDMenu;
  
     if (!(MenuObject = UserGetMenuObject(hMenu)))
       {
@@@ -2188,7 -2192,7 +2192,7 @@@ NtUserHiliteMenuItem
        RETURN(FALSE);
     }
  
 -   if(Window->Wnd->IDMenu == (UINT)hMenu)
 +   if(Window->Wnd->IDMenu == (UINT)(UINT_PTR)hMenu)
     {
        RETURN( IntHiliteMenuItem(Window, Menu, uItemHilite, uHilite));
     }
@@@ -2595,7 -2599,7 +2599,7 @@@ NtUserThunkedMenuItemInfo
        if bInsert == TRUE call NtUserInsertMenuItem() else NtUserSetMenuItemInfo()   */
  
     if (bInsert) return UserInsertMenuItem(hMenu, uItem, fByPosition, lpmii);
 -   
 +
     UNIMPLEMENTED
     return 0;
  }
  /*
   * @unimplemented
   */
 -DWORD STDCALL
 +DWORD_PTR STDCALL
  NtUserGetThreadState(
     DWORD Routine)
  {
 -   DECLARE_RETURN(DWORD);
 +   DWORD_PTR ret = 0;
  
     DPRINT("Enter NtUserGetThreadState\n");
     if (Routine != THREADSTATE_GETTHREADINFO)
     {
        case THREADSTATE_GETTHREADINFO:
           GetW32ThreadInfo();
 -         RETURN(0);
 -
 +         break;
        case THREADSTATE_FOCUSWINDOW:
 -         RETURN( (DWORD)IntGetThreadFocusWindow());
 +         ret = (DWORD_PTR)IntGetThreadFocusWindow();
 +         break;
        case THREADSTATE_CAPTUREWINDOW:
           /* FIXME should use UserEnterShared */
 -         RETURN( (DWORD)IntGetCapture());
 +         ret = (DWORD_PTR)IntGetCapture();
 +         break;
        case THREADSTATE_PROGMANWINDOW:
 -         RETURN( (DWORD)GetW32ThreadInfo()->Desktop->hProgmanWindow);
 +         ret = (DWORD_PTR)GetW32ThreadInfo()->Desktop->hProgmanWindow;
 +         break;
        case THREADSTATE_TASKMANWINDOW:
 -         RETURN( (DWORD)GetW32ThreadInfo()->Desktop->hTaskManWindow);
 +         ret = (DWORD_PTR)GetW32ThreadInfo()->Desktop->hTaskManWindow;
 +         break;
        case THREADSTATE_ACTIVEWINDOW:
 -         RETURN ( (DWORD)UserGetActiveWindow());
 +         ret = (DWORD_PTR)UserGetActiveWindow();
 +         break;
     }
 -   RETURN( 0);
  
 -CLEANUP:
 -   DPRINT("Leave NtUserGetThreadState, ret=%i\n",_ret_);
 +   DPRINT("Leave NtUserGetThreadState, ret=%i\n", ret);
     UserLeave();
 -   END_CLEANUP;
 +
 +   return ret;
  }
  
  
@@@ -104,7 -101,7 +104,7 @@@ NtUserGetGUIThreadInfo
     NTSTATUS Status;
     PTHRDCARETINFO CaretInfo;
     GUITHREADINFO SafeGui;
-    PDESKTOP_OBJECT Desktop;
+    PDESKTOP Desktop;
     PUSER_MESSAGE_QUEUE MsgQueue;
     PETHREAD Thread = NULL;
     DECLARE_RETURN(BOOLEAN);
  
     if(idThread)
     {
 -      Status = PsLookupThreadByThreadId((HANDLE)idThread, &Thread);
 +      Status = PsLookupThreadByThreadId((HANDLE)(DWORD_PTR)idThread, &Thread);
        if(!NT_SUCCESS(Status))
        {
           SetLastWin32Error(ERROR_ACCESS_DENIED);
           RETURN( FALSE);
        }
-       Desktop = ((PW32THREAD)Thread->Tcb.Win32Thread)->Desktop;
+       Desktop = ((PTHREADINFO)Thread->Tcb.Win32Thread)->Desktop;
     }
     else
     {
        /* get the foreground thread */
-       PW32THREAD W32Thread = (PW32THREAD)PsGetCurrentThread()->Tcb.Win32Thread;
+       PTHREADINFO W32Thread = (PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread;
        Desktop = W32Thread->Desktop;
        if(Desktop)
        {
@@@ -419,7 -416,7 +419,7 @@@ GetW32ProcessInfo(VOID
                                  (ULONG_PTR)W32Process->HeapMappings.UserMapping;
              pi->psi = gpsi;
  
 -            if (InterlockedCompareExchangePointer(&W32Process->ProcessInfo,
 +            if (InterlockedCompareExchangePointer((PVOID*)&W32Process->ProcessInfo,
                                                    pi,
                                                    NULL) != NULL)
              {
@@@ -440,8 -437,8 +440,8 @@@ GetW32ThreadInfo(VOID
  {
      PTEB Teb;
      PW32THREADINFO ti;
-     PW32CLIENTINFO ci;
-     PW32THREAD W32Thread = PsGetCurrentThreadWin32Thread();
+     PCLIENTINFO ci;
+     PTHREADINFO W32Thread = PsGetCurrentThreadWin32Thread();
  
      if (W32Thread == NULL)
      {
          return NULL;
      }
  
-     /* allocate a W32THREAD structure if neccessary */
+     /* allocate a THREADINFO structure if neccessary */
      if (W32Thread->ThreadInfo == NULL)
      {
          ti = UserHeapAlloc(sizeof(W32THREADINFO));
              if (W32Thread->Desktop != NULL)
              {
                  ti->Desktop = W32Thread->Desktop->DesktopInfo;
-                 ti->DesktopHeapBase = W32Thread->Desktop->DesktopInfo->hKernelHeap;
-                 ti->DesktopHeapLimit = W32Thread->Desktop->DesktopInfo->HeapLimit;
-                 ti->DesktopHeapDelta = DesktopHeapGetUserDelta();
              }
              else
              {
                  ti->Desktop = NULL;
-                 ti->DesktopHeapBase = NULL;
-                 ti->DesktopHeapLimit = 0;
-                 ti->DesktopHeapDelta = 0;
              }
  
              W32Thread->ThreadInfo = ti;
              /* update the TEB */
              Teb = NtCurrentTeb();
-             ci = ((PW32CLIENTINFO)Teb->Win32ClientInfo);
+             ci = GetWin32ClientInfo();
              _SEH_TRY
              {
                  ProbeForWrite(Teb,
@@@ -636,7 -636,7 +636,7 @@@ IntIsWindowDirty(PWINDOW_OBJECT Window
  }
  
  HWND FASTCALL
- IntFindWindowToRepaint(PWINDOW_OBJECT Window, PW32THREAD Thread)
+ IntFindWindowToRepaint(PWINDOW_OBJECT Window, PTHREADINFO Thread)
  {
     HWND hChild;
     PWINDOW_OBJECT TempWindow;
  
  BOOL FASTCALL
  IntGetPaintMessage(HWND hWnd, UINT MsgFilterMin, UINT MsgFilterMax,
-                    PW32THREAD Thread, MSG *Message, BOOL Remove)
+                    PTHREADINFO Thread, MSG *Message, BOOL Remove)
  {
     PUSER_MESSAGE_QUEUE MessageQueue = (PUSER_MESSAGE_QUEUE)Thread->MessageQueue;
  
@@@ -714,14 -714,14 +714,14 @@@ stati
  HWND FASTCALL
  co_IntFixCaret(PWINDOW_OBJECT Window, LPRECT lprc, UINT flags)
  {
-    PDESKTOP_OBJECT Desktop;
+    PDESKTOP Desktop;
     PTHRDCARETINFO CaretInfo;
     HWND hWndCaret;
     PWINDOW_OBJECT WndCaret;
  
     ASSERT_REFS_CO(Window);
  
-    Desktop = ((PW32THREAD)PsGetCurrentThread()->Tcb.Win32Thread)->Desktop;
+    Desktop = ((PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread)->Desktop;
     CaretInfo = ((PUSER_MESSAGE_QUEUE)Desktop->ActiveMessageQueue)->CaretInfo;
     hWndCaret = CaretInfo->hWnd;
  
@@@ -1665,7 -1665,7 +1665,7 @@@ BOOL UserDrawCaption
          && !(Wnd->ExStyle & WS_EX_TOOLWINDOW);
     }
     else
 -     HasIcon = (BOOL) hIcon;
 +     HasIcon = (hIcon != 0);
  
     IconWidth = UserGetSystemMetrics(SM_CXSIZE) + Padding;
  
@@@ -74,12 -74,12 +74,12 @@@ co_IntRegisterLogonProcess(HANDLE Proce
  /*
   * @unimplemented
   */
 -DWORD
 +DWORD_PTR
  STDCALL
  NtUserCallNoParam(DWORD Routine)
  {
 -   DWORD Result = 0;
 -   DECLARE_RETURN(DWORD);
 +   DWORD_PTR Result = 0;
 +   DECLARE_RETURN(DWORD_PTR);
  
     DPRINT("Enter NtUserCallNoParam\n");
     UserEnterExclusive();
     switch(Routine)
     {
        case NOPARAM_ROUTINE_CREATEMENU:
 -         Result = (DWORD)UserCreateMenu(FALSE);
 +         Result = (DWORD_PTR)UserCreateMenu(FALSE);
           break;
  
        case NOPARAM_ROUTINE_CREATEMENUPOPUP:
 -         Result = (DWORD)UserCreateMenu(TRUE);
 +         Result = (DWORD_PTR)UserCreateMenu(TRUE);
           break;
  
        case NOPARAM_ROUTINE_DESTROY_CARET:
 -         Result = (DWORD)co_IntDestroyCaret(PsGetCurrentThread()->Tcb.Win32Thread);
 +         Result = (DWORD_PTR)co_IntDestroyCaret(PsGetCurrentThread()->Tcb.Win32Thread);
           break;
  
        case NOPARAM_ROUTINE_INIT_MESSAGE_PUMP:
 -         Result = (DWORD)IntInitMessagePumpHook();
 +         Result = (DWORD_PTR)IntInitMessagePumpHook();
           break;
  
        case NOPARAM_ROUTINE_UNINIT_MESSAGE_PUMP:
 -         Result = (DWORD)IntUninitMessagePumpHook();
 +         Result = (DWORD_PTR)IntUninitMessagePumpHook();
           break;
  
        case NOPARAM_ROUTINE_GETMESSAGEEXTRAINFO:
 -         Result = (DWORD)MsqGetMessageExtraInfo();
 +         Result = (DWORD_PTR)MsqGetMessageExtraInfo();
           break;
  
        case NOPARAM_ROUTINE_ANYPOPUP:
 -         Result = (DWORD)IntAnyPopup();
 +         Result = (DWORD_PTR)IntAnyPopup();
           break;
  
        case NOPARAM_ROUTINE_CSRSS_INITIALIZED:
 -         Result = (DWORD)CsrInit();
 +         Result = (DWORD_PTR)CsrInit();
           break;
  
        case NOPARAM_ROUTINE_MSQCLEARWAKEMASK:
 -         RETURN( (DWORD)IntMsqClearWakeMask());
 +         RETURN( (DWORD_PTR)IntMsqClearWakeMask());
  
        default:
           DPRINT1("Calling invalid routine number 0x%x in NtUserCallNoParam\n", Routine);
@@@ -138,13 -138,13 +138,13 @@@ CLEANUP
  /*
   * @implemented
   */
 -DWORD
 +DWORD_PTR
  STDCALL
  NtUserCallOneParam(
     DWORD Param,
     DWORD Routine)
  {
 -   DECLARE_RETURN(DWORD);
 +   DECLARE_RETURN(DWORD_PTR);
  
     DPRINT("Enter NtUserCallOneParam\n");
  
     switch(Routine)
     {
        case ONEPARAM_ROUTINE_SHOWCURSOR:
 -         RETURN( (DWORD)UserShowCursor((BOOL)Param) );
 +         RETURN( (DWORD_PTR)UserShowCursor((BOOL)Param) );
  
        case ONEPARAM_ROUTINE_GETDESKTOPMAPPING:
           {
               {
                  /* Try convert the pointer to a user mode pointer if the desktop is
                     mapped into the process */
 -                RETURN((DWORD)DesktopHeapAddressToUser((PVOID)Param));
 +                RETURN((DWORD_PTR)DesktopHeapAddressToUser((PVOID)Param));
               }
               else
               {
        case ONEPARAM_ROUTINE_GETMENU:
           {
              PWINDOW_OBJECT Window;
 -            DWORD Result;
 +            DWORD_PTR Result;
  
              if(!(Window = UserGetWindowObject((HWND)Param)))
              {
                 RETURN( FALSE);
              }
  
 -            Result = (DWORD)Window->Wnd->IDMenu;
 +            Result = Window->Wnd->IDMenu;
  
              RETURN( Result);
           }
        case ONEPARAM_ROUTINE_ISWINDOWUNICODE:
           {
              PWINDOW_OBJECT Window;
 -            DWORD Result;
 +            DWORD_PTR Result;
  
              Window = UserGetWindowObject((HWND)Param);
              if(!Window)
           }
  
        case ONEPARAM_ROUTINE_WINDOWFROMDC:
 -         RETURN( (DWORD)IntWindowFromDC((HDC)Param));
 +         RETURN( (DWORD_PTR)IntWindowFromDC((HDC)Param));
  
        case ONEPARAM_ROUTINE_GETWNDCONTEXTHLPID:
           {
              PWINDOW_OBJECT Window;
 -            DWORD Result;
 +            DWORD_PTR Result;
  
              Window = UserGetWindowObject((HWND)Param);
              if(!Window)
           {
              PWINSTATION_OBJECT WinSta;
              NTSTATUS Status;
 -            DWORD Result;
 +            DWORD_PTR Result;
  
              Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation,
                                                      KernelMode,
                                                      0,
                                                      &WinSta);
              if (!NT_SUCCESS(Status))
 -               RETURN( (DWORD)FALSE);
 +               RETURN( (DWORD_PTR)FALSE);
  
              /* FIXME
 -            Result = (DWORD)IntSwapMouseButton(WinStaObject, (BOOL)Param); */
 +            Result = (DWORD_PTR)IntSwapMouseButton(WinStaObject, (BOOL)Param); */
              Result = 0;
  
              ObDereferenceObject(WinSta);
           }
  
        case ONEPARAM_ROUTINE_SWITCHCARETSHOWING:
 -         RETURN( (DWORD)IntSwitchCaretShowing((PVOID)Param));
 +         RETURN( (DWORD_PTR)IntSwitchCaretShowing((PVOID)Param));
  
        case ONEPARAM_ROUTINE_SETCARETBLINKTIME:
 -         RETURN( (DWORD)IntSetCaretBlinkTime((UINT)Param));
 +         RETURN( (DWORD_PTR)IntSetCaretBlinkTime((UINT)Param));
  
        case ONEPARAM_ROUTINE_GETWINDOWINSTANCE:
           {
                 RETURN( FALSE);
              }
  
 -            Result = (DWORD)Window->Wnd->Instance;
 +            Result = (DWORD_PTR)Window->Wnd->Instance;
              RETURN( Result);
           }
  
        case ONEPARAM_ROUTINE_SETMESSAGEEXTRAINFO:
 -         RETURN( (DWORD)MsqSetMessageExtraInfo((LPARAM)Param));
 +         RETURN( (DWORD_PTR)MsqSetMessageExtraInfo((LPARAM)Param));
  
        case ONEPARAM_ROUTINE_CREATECURICONHANDLE:
           {
              }
  
              ObDereferenceObject(WinSta);
 -            RETURN((DWORD)CurIcon->Self);
 +            RETURN((DWORD_PTR)CurIcon->Self);
           }
  
        case ONEPARAM_ROUTINE_GETCURSORPOSITION:
              POINT Pos;
  
              if(!Param)
 -               RETURN( (DWORD)FALSE);
 +               RETURN( (DWORD_PTR)FALSE);
              Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation,
                                                      KernelMode,
                                                      0,
                                                      &WinSta);
              if (!NT_SUCCESS(Status))
 -               RETURN( (DWORD)FALSE);
 +               RETURN( (DWORD_PTR)FALSE);
  
              /* FIXME - check if process has WINSTA_READATTRIBUTES */
              IntGetCursorLocation(WinSta, &Pos);
  
              ObDereferenceObject(WinSta);
  
 -            RETURN( (DWORD)TRUE);
 +            RETURN( (DWORD_PTR)TRUE);
           }
  
        case ONEPARAM_ROUTINE_ISWINDOWINDESTROY:
           {
              PWINDOW_OBJECT Window;
 -            DWORD Result;
 +            DWORD_PTR Result;
  
              if(!(Window = UserGetWindowObject((HWND)Param)))
              {
                 RETURN( FALSE);
              }
  
 -            Result = (DWORD)IntIsWindowInDestroy(Window);
 +            Result = (DWORD_PTR)IntIsWindowInDestroy(Window);
  
              RETURN( Result);
           }
           }
  
        case ONEPARAM_ROUTINE_MSQSETWAKEMASK:
 -         RETURN( (DWORD)IntMsqSetWakeMask(Param));
 +         RETURN( (DWORD_PTR)IntMsqSetWakeMask(Param));
  
        case ONEPARAM_ROUTINE_GETKEYBOARDTYPE:
           RETURN( UserGetKeyboardType(Param));
  
        case ONEPARAM_ROUTINE_GETKEYBOARDLAYOUT:
 -         RETURN( (DWORD)UserGetKeyboardLayout(Param));
 +         RETURN( (DWORD_PTR)UserGetKeyboardLayout(Param));
  
        case ONEPARAM_ROUTINE_REGISTERUSERMODULE:
        {
@@@ -415,7 -415,7 +415,7 @@@ CLEANUP
  /*
   * @implemented
   */
 -DWORD
 +DWORD_PTR
  STDCALL
  NtUserCallTwoParam(
     DWORD Param1,
  {
     NTSTATUS Status;
     PWINDOW_OBJECT Window;
 -   DECLARE_RETURN(DWORD);
 +   DECLARE_RETURN(DWORD_PTR);
  
     DPRINT("Enter NtUserCallTwoParam\n");
     UserEnterExclusive();
     {
        case TWOPARAM_ROUTINE_GETWINDOWRGNBOX:
           {
 -            DWORD Ret;
 +            DWORD_PTR Ret;
              RECT rcRect;
              Window = UserGetWindowObject((HWND)Param1);
              if (!Window) RETURN(ERROR);
  
 -            Ret = (DWORD)IntGetWindowRgnBox(Window, &rcRect);
 +            Ret = (DWORD_PTR)IntGetWindowRgnBox(Window, &rcRect);
              Status = MmCopyToCaller((PVOID)Param2, &rcRect, sizeof(RECT));
              if(!NT_SUCCESS(Status))
              {
              Window = UserGetWindowObject((HWND)Param1);
              if (!Window) RETURN(ERROR);
  
 -            RETURN( (DWORD)IntGetWindowRgn(Window, (HRGN)Param2));
 +            RETURN( (DWORD_PTR)IntGetWindowRgn(Window, (HRGN)Param2));
           }
        case TWOPARAM_ROUTINE_SETMENUBARHEIGHT:
           {
 -            DWORD Ret;
 +            DWORD_PTR Ret;
              PMENU_OBJECT MenuObject = IntGetMenuObject((HMENU)Param1);
              if(!MenuObject)
                 RETURN( 0);
                 MenuObject->MenuInfo.Height = (int)Param2;
              }
              else
 -               Ret = (DWORD)MenuObject->MenuInfo.Height;
 +               Ret = (DWORD_PTR)MenuObject->MenuInfo.Height;
              IntReleaseMenuObject(MenuObject);
              RETURN( Ret);
           }
              Ret = IntSetMenuItemRect(MenuObject, smir.uItem, smir.fByPosition, &smir.rcRect);
  
              IntReleaseMenuObject(MenuObject);
 -            RETURN( (DWORD)Ret);
 +            RETURN( (DWORD_PTR)Ret);
           }
  
        case TWOPARAM_ROUTINE_SETGUITHRDHANDLE:
           {
-             PUSER_MESSAGE_QUEUE MsgQueue = ((PW32THREAD)PsGetCurrentThread()->Tcb.Win32Thread)->MessageQueue;
+             PUSER_MESSAGE_QUEUE MsgQueue = ((PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread)->MessageQueue;
  
              ASSERT(MsgQueue);
 -            RETURN( (DWORD)MsqSetStateWindow(MsgQueue, (ULONG)Param1, (HWND)Param2));
 +            RETURN( (DWORD_PTR)MsqSetStateWindow(MsgQueue, (ULONG)Param1, (HWND)Param2));
           }
  
        case TWOPARAM_ROUTINE_ENABLEWINDOW:
           Window = UserGetWindowObject((HWND)Param1);
           if (!Window) RETURN(0);
  
 -         RETURN( (DWORD)IntShowOwnedPopups(Window, (BOOL) Param2));
 +         RETURN( (DWORD_PTR)IntShowOwnedPopups(Window, (BOOL) Param2));
        }
  
        case TWOPARAM_ROUTINE_ROS_UPDATEUISTATE:
  
           if(!(Window = UserGetWindowObject((HWND)Param1)))
           {
 -            RETURN( (DWORD)FALSE);
 +            RETURN( (DWORD_PTR)FALSE);
           }
  
           Window->Wnd->ContextHelpId = Param2;
  
 -         RETURN( (DWORD)TRUE);
 +         RETURN( (DWORD_PTR)TRUE);
  
        case TWOPARAM_ROUTINE_SETCARETPOS:
 -         RETURN( (DWORD)co_IntSetCaretPos((int)Param1, (int)Param2));
 +         RETURN( (DWORD_PTR)co_IntSetCaretPos((int)Param1, (int)Param2));
  
        case TWOPARAM_ROUTINE_GETWINDOWINFO:
           {
              WINDOWINFO wi;
 -            DWORD Ret;
 +            DWORD_PTR Ret;
  
              if(!(Window = UserGetWindowObject((HWND)Param1)))
              {
              }
  #endif
  
 -            if((Ret = (DWORD)IntGetWindowInfo(Window, &wi)))
 +            if((Ret = (DWORD_PTR)IntGetWindowInfo(Window, &wi)))
              {
                 Status = MmCopyToCaller((PVOID)Param2, &wi, sizeof(WINDOWINFO));
                 if(!NT_SUCCESS(Status))
           }
  
        case TWOPARAM_ROUTINE_REGISTERLOGONPROC:
 -         RETURN( (DWORD)co_IntRegisterLogonProcess((HANDLE)Param1, (BOOL)Param2));
 +         RETURN( (DWORD_PTR)co_IntRegisterLogonProcess((HANDLE)Param1, (BOOL)Param2));
  
        case TWOPARAM_ROUTINE_GETSYSCOLORBRUSHES:
        case TWOPARAM_ROUTINE_GETSYSCOLORPENS:
        case TWOPARAM_ROUTINE_GETSYSCOLORS:
           {
 -            DWORD Ret = 0;
 +            DWORD_PTR Ret = 0;
              union
              {
                 PVOID Pointer;
                 switch(Routine)
                 {
                    case TWOPARAM_ROUTINE_GETSYSCOLORBRUSHES:
 -                     Ret = (DWORD)IntGetSysColorBrushes(Buffer.Brushes, (UINT)Param2);
 +                     Ret = (DWORD_PTR)IntGetSysColorBrushes(Buffer.Brushes, (UINT)Param2);
                       break;
                    case TWOPARAM_ROUTINE_GETSYSCOLORPENS:
 -                     Ret = (DWORD)IntGetSysColorPens(Buffer.Pens, (UINT)Param2);
 +                     Ret = (DWORD_PTR)IntGetSysColorPens(Buffer.Pens, (UINT)Param2);
                       break;
                    case TWOPARAM_ROUTINE_GETSYSCOLORS:
 -                     Ret = (DWORD)IntGetSysColors(Buffer.Colors, (UINT)Param2);
 +                     Ret = (DWORD_PTR)IntGetSysColors(Buffer.Colors, (UINT)Param2);
                       break;
                    default:
                       Ret = 0;
  
        case TWOPARAM_ROUTINE_ROS_REGSYSCLASSES:
        {
 -          DWORD Ret = 0;
 +          DWORD_PTR Ret = 0;
            DWORD Count = Param1;
            PREGISTER_SYSCLASS RegSysClassArray = (PREGISTER_SYSCLASS)Param2;
  
                                      Count,
                                      2);
  
 -                  Ret = (DWORD)UserRegisterSystemClasses(Count,
 +                  Ret = (DWORD_PTR)UserRegisterSystemClasses(Count,
                                                           RegSysClassArray);
                }
                _SEH_HANDLE
@@@ -409,8 -409,6 +409,8 @@@ MingwModuleHandler::GetObjectFilename 
                newExtension = ".rc";
        else if ( extension == ".spec" || extension == ".SPEC" )
                newExtension = ".stubs.o";
 +      else if ( extension == ".pspec" || extension == ".PSPEC" )
 +              newExtension = ".stubs.o";
        else if ( extension == ".idl" || extension == ".IDL" )
        {
                if ( module.type == RpcServer )
@@@ -1020,7 -1018,7 +1020,7 @@@ MingwModuleHandler::GetPrecompiledHeade
        if ( !module.pch || !use_pch )
                return NULL;
        return new FileLocation ( IntermediateDirectory,
-                                 module.pch->file->relative_path,
+                                 module.pch->file->relative_path + "/.gch_" + module.name,
                                  module.pch->file->name + ".gch" );
  }
  
@@@ -1080,21 -1078,6 +1080,21 @@@ Rule winebuildKMRule ( "$(INTERMEDIATE)
                         "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.c",
                         "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.o",
                         "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
 +Rule winebuildPCRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec.def: $(source)$(dependencies) $(WINEBUILD_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
 +                       "\t$(ECHO_WINEBLD)\n"
 +                       "\t${gcc} -xc -E $(source) -I. > $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec\n"
 +                       "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).spec.def --def -E $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec\n"
 +                       "$(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).stubs.c: $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).spec $(WINEBUILD_TARGET)\n"
 +                       "\t$(ECHO_WINEBLD)\n"
 +                       "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).stubs.c --pedll $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec\n"
 +                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.c$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
 +                       "\t$(ECHO_CC)\n"
 +                       "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
 +                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec",
 +                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec.def",
 +                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.c",
 +                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.o",
 +                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
  Rule winebuildRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec.def: $(source)$(dependencies) $(WINEBUILD_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                       "\t$(ECHO_WINEBLD)\n"
                       "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).spec.def --def -E $(source)\n"
@@@ -1208,13 -1191,12 +1208,12 @@@ MingwModuleHandler::GenerateGccCommand 
  string
  MingwModuleHandler::GetPropertyValue ( const Module& module, const std::string& name )
  {
-       for ( size_t i = 0; i < module.project.non_if_data.properties.size (); i++ )
-       {
-               const Property& property = *module.project.non_if_data.properties[i];
-               if ( property.name == name )
-                       return property.value;
-       }
-       return string ( "" );
+       const Property* property = module.project.LookupProperty(name);
+       if (property)
+               return property->value;
+       else
+               return string ( "" );
  }
  
  /* caller needs to delete the returned object */
@@@ -1280,7 -1262,6 +1279,7 @@@ MingwModuleHandler::GenerateCommands 
                { HostDontCare, TypeDontCare, ".mc", &wmcRule },
                { HostFalse, Kernel, ".spec", &winebuildKMRule },
                { HostFalse, KernelModeDLL, ".spec", &winebuildKMRule },
 +              { HostDontCare, TypeDontCare, ".pspec", &winebuildPCRule },
                { HostDontCare, TypeDontCare, ".spec", &winebuildRule },
                { HostDontCare, RpcServer, ".idl", &widlServerRule },
                { HostDontCare, RpcClient, ".idl", &widlClientRule },
@@@ -2099,14 -2080,14 +2098,14 @@@ MingwModuleHandler::GetDefaultDependenc
        if ( ModuleHandlerInformations[module.type].DefaultHost == HostTrue )
                return;
  
-       if (module.name != "psdk" && 
+       if (module.name != "psdk" &&
                module.name != "dxsdk")
        {
                dependencies.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
                dependencies.push_back ( "$(DXSDK_TARGET) $(dxsdk_HEADERS)" );
        }
  
-       if (module.name != "errcodes" && 
+       if (module.name != "errcodes" &&
                module.name != "bugcodes" &&
                module.name != "ntstatus")
        {
@@@ -2997,9 -2978,9 +2996,9 @@@ voi
  MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
        const string& bootcdDirectory )
  {
-       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::const_iterator p = module.project.modules.begin (); p != module.project.modules.end (); ++ p )
        {
-               const Module& m = *module.project.modules[i];
+               const Module& m = *p->second;
                if ( !m.enabled )
                        continue;
                if ( m.bootstrap != NULL )
@@@ -3034,9 -3015,9 +3033,9 @@@ voi
  MingwIsoModuleHandler::GetBootstrapCdDirectories ( vector<FileLocation>& out,
                                                     const string& bootcdDirectory )
  {
-       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::const_iterator p = module.project.modules.begin (); p != module.project.modules.end (); ++ p )
        {
-               const Module& m = *module.project.modules[i];
+               const Module& m = *p->second;
                if ( !m.enabled )
                        continue;
                if ( m.bootstrap != NULL )
@@@ -3079,9 -3060,9 +3078,9 @@@ voi
  MingwIsoModuleHandler::GetBootstrapCdFiles (
        vector<FileLocation>& out ) const
  {
-       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::const_iterator p = module.project.modules.begin (); p != module.project.modules.end (); ++ p )
        {
-               const Module& m = *module.project.modules[i];
+               const Module& m = *p->second;
                if ( !m.enabled )
                        continue;
                if ( m.bootstrap != NULL )
@@@ -3157,9 -3138,9 +3156,9 @@@ MingwIsoModuleHandler::GenerateIsoModul
  
        vSourceFiles.push_back ( reactosDff );
  
-       /* 
+       /*
                We use only the name and not full FileLocation(ouput) because Iso/LiveIso are an exception to the general rule.
-               Iso/LiveIso outputs are generated in code base root 
+               Iso/LiveIso outputs are generated in code base root
        */
        string IsoName = module.output->name;
  
@@@ -3235,9 -3216,9 +3234,9 @@@ voi
  MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string& livecdDirectory,
                                                        string& reactosDirectory )
  {
-       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::const_iterator p = module.project.modules.begin (); p != module.project.modules.end (); ++ p )
        {
-               const Module& m = *module.project.modules[i];
+               const Module& m = *p->second;
                if ( !m.enabled )
                        continue;
                if ( m.install )
@@@ -3338,9 -3319,9 +3337,9 @@@ MingwLiveIsoModuleHandler::GenerateLive
  
        const FileLocation *isoboot = bootModule->output;
  
-       /* 
+       /*
                We use only the name and not full FileLocation(ouput) because Iso/LiveIso are an exception to the general rule.
-               Iso/LiveIso outputs are generated in code base root 
+               Iso/LiveIso outputs are generated in code base root
        */
        IsoName = module.output->name;
  
@@@ -3453,7 -3434,7 +3452,7 @@@ MingwCabinetModuleHandler::Process (
        string targetMacro ( GetTargetMacro (module) );
  
        GenerateRules ();
-       
        const FileLocation *target_file = GetTargetFilename ( module, NULL );
        fprintf ( fMakefile, "%s: $(CABMAN_TARGET) | %s\n",
                  targetMacro.c_str (),
@@@ -189,11 -189,11 +189,11 @@@ IfableData::IfableData( 
  {
  }
  
- void IfableData::ExtractModules( std::vector<Module*> &modules )
+ void IfableData::ExtractModules( std::map<std::string, Module*> &modules )
  {
        size_t i;
        for ( i = 0; i < this->modules.size (); i++ )
-               modules.push_back(this->modules[i]);
+               modules.insert(std::make_pair(this->modules[i]->name, this->modules[i]));
  }
  
  IfableData::~IfableData()
                delete defines[i];
        for ( i = 0; i < libraries.size (); i++ )
                delete libraries[i];
-       for ( i = 0; i < properties.size (); i++ )
-               delete properties[i];
+       for ( std::map<std::string, Property*>::const_iterator p = properties.begin(); p != properties.end(); ++ p )
+               delete p->second;
        for ( i = 0; i < compilerFlags.size (); i++ )
                delete compilerFlags[i];
        for ( i = 0; i < modules.size(); i++ )
@@@ -224,8 -224,8 +224,8 @@@ void IfableData::ProcessXML (
                defines[i]->ProcessXML ();
        for ( i = 0; i < libraries.size (); i++ )
                libraries[i]->ProcessXML ();
-       for ( i = 0; i < properties.size(); i++ )
-               properties[i]->ProcessXML ();
+       for ( std::map<std::string, Property*>::const_iterator p = properties.begin(); p != properties.end(); ++ p )
+               p->second->ProcessXML ();
        for ( i = 0; i < compilerFlags.size(); i++ )
                compilerFlags[i]->ProcessXML ();
        for ( i = 0; i < compilationUnits.size (); i++ )
@@@ -527,7 -527,7 +527,7 @@@ Module::~Module (
        if ( autoRegister )
                delete autoRegister;
        if ( output )
-               delete output;          
+               delete output;
  }
  
  void
@@@ -1059,7 -1059,7 +1059,7 @@@ Module::GetDefaultModuleEntrypoint () c
              return "DllMainCRTStartup@12";
                case NativeCUI:
              if (Environment::GetArch() == "arm") return "NtProcessStartup";
-             return "NtProcessStartup@4";            
+             return "NtProcessStartup@4";
                case Win32DLL:
                case Win32OCX:
              if (Environment::GetArch() == "arm") return "DllMain";
@@@ -1244,14 -1244,6 +1244,14 @@@ Module::GetEntryPoint(bool leadingUnder
                result = "_";
  
        result += entrypoint;
 +
 +      if (Environment::GetArch() == "amd64")
 +      {
 +              size_t at_index = result.find_last_of( '@' );
 +              if ( at_index != result.npos )
 +                      return result.substr (0, at_index );
 +      }
 +
        return result;
  }
  
@@@ -70,6 -70,20 +70,20 @@@ static void check_pointers(const func_
      }
  }
  
+ const var_t* get_context_handle_var(const func_t* func)
+ {
+     const var_t* var;
+     if (!func->args)
+         return NULL;
+     LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
+         if (is_attr(var->attrs, ATTR_IN) && is_context_handle(var->type))
+             return var;
+     return NULL;
+ }
  static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
  {
      const func_t *func;
      {
          const var_t *def = func->def;
          const var_t* explicit_handle_var;
+         const var_t* explicit_generic_handle_var = NULL;
+         const var_t* context_handle_var = NULL;
          int has_full_pointer = is_full_pointer_function(func);
  
          /* check for a defined binding handle */
          explicit_handle_var = get_explicit_handle_var(func);
+         if (!explicit_handle_var)
+         {
+             explicit_generic_handle_var = get_explicit_generic_handle_var(func);
+             if (!explicit_generic_handle_var)
+                 context_handle_var = get_context_handle_var(func);
+         }
          if (explicit_handle)
          {
-             if (!explicit_handle_var)
+             if (!explicit_handle_var && !explicit_generic_handle_var && !context_handle_var)
              {
                  error("%s() does not define an explicit binding handle!\n", def->name);
                  return;
              }
          }
  
-         write_type_decl_left(client, def->type);
-         if (needs_space_after(def->type))
+         write_type_decl_left(client, get_func_return_type(func));
+         if (needs_space_after(get_func_return_type(func)))
            fprintf(client, " ");
          write_prefix_name(client, prefix_client, def);
          fprintf(client, "(\n");
          indent++;
  
          /* declare return value '_RetVal' */
-         if (!is_void(def->type))
+         if (!is_void(get_func_return_type(func)))
          {
              print_client("");
-             write_type_decl_left(client, def->type);
+             write_type_decl_left(client, get_func_return_type(func));
              fprintf(client, " _RetVal;\n");
          }
  
-         if (implicit_handle || explicit_handle_var)
+         if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var)
              print_client("RPC_BINDING_HANDLE _Handle = 0;\n");
  
          print_client("RPC_MESSAGE _RpcMessage;\n");
          print_client("MIDL_STUB_MESSAGE _StubMsg;\n");
-         if (!is_void(def->type) && decl_indirect(def->type))
+         if (!is_void(get_func_return_type(func)) && decl_indirect(get_func_return_type(func)))
          {
              print_client("void *_p_%s = &%s;\n",
                           "_RetVal", "_RetVal");
              print_client("_Handle = %s;\n", explicit_handle_var->name);
              fprintf(client, "\n");
          }
+         else if (explicit_generic_handle_var)
+         {
+             print_client("_Handle = %s_bind(%s);\n",
+                 get_explicit_generic_handle_type(explicit_generic_handle_var)->name,
+                 explicit_generic_handle_var->name);
+             fprintf(client, "\n");
+         }
+         else if (context_handle_var)
+         {
+             /* if the context_handle attribute appears in the chain of types
+              * without pointers being followed, then the context handle must
+              * be direct, otherwise it is a pointer */
+             int is_ch_ptr = is_aliaschain_attr(context_handle_var->type, ATTR_CONTEXTHANDLE) ? FALSE : TRUE;
+             print_client("if (%s%s != 0)\n", is_ch_ptr ? "*" : "", context_handle_var->name);
+             indent++;
+             print_client("_Handle = NDRCContextBinding(%s%s);\n", is_ch_ptr ? "*" : "", context_handle_var->name);
+             indent--;
+             fprintf(client, "\n");
+         }
  
          write_remoting_arguments(client, indent, func, PASS_IN, PHASE_BUFFERSIZE);
  
          indent++;
          print_client("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
          print_client("_StubMsg.BufferLength,\n");
-         if (implicit_handle || explicit_handle_var)
+         if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var)
              print_client("_Handle);\n");
          else
              print_client("%s__MIDL_AutoBindHandle);\n", iface->name);
          write_remoting_arguments(client, indent, func, PASS_OUT, PHASE_UNMARSHAL);
  
          /* unmarshal return value */
-         if (!is_void(def->type))
+         if (!is_void(get_func_return_type(func)))
          {
-             if (decl_indirect(def->type))
+             if (decl_indirect(get_func_return_type(func)))
                  print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
-             else if (is_ptr(def->type) || is_array(def->type))
+             else if (is_ptr(get_func_return_type(func)) || is_array(get_func_return_type(func)))
                  print_client("%s = 0;\n", "_RetVal");
              write_remoting_arguments(client, indent, func, PASS_RETURN, PHASE_UNMARSHAL);
          }
          if (func->args)
          {
              LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
-                 *proc_offset += get_size_procformatstring_var(var);
+                 *proc_offset += get_size_procformatstring_type(var->name, var->type, var->attrs);
          }
-         if (!is_void(def->type))
-             *proc_offset += get_size_procformatstring_var(def);
+         if (!is_void(get_func_return_type(func)))
+             *proc_offset += get_size_procformatstring_type("return value", get_func_return_type(func), NULL);
          else
              *proc_offset += 2; /* FC_END and FC_PAD */
  
  
          print_client("NdrFreeBuffer((PMIDL_STUB_MESSAGE)&_StubMsg);\n");
  
+         if (!implicit_handle && explicit_generic_handle_var)
+         {
+             fprintf(client, "\n");
+             print_client("if (_Handle)\n");
+             indent++;
+             print_client("%s_unbind(%s, _Handle);\n",
+                 get_explicit_generic_handle_type(explicit_generic_handle_var)->name,
+                 explicit_generic_handle_var->name);
+             indent--;
+         }
          indent--;
          print_client("}\n");
          print_client("RpcEndFinally\n");
  
  
          /* emit return code */
-         if (!is_void(def->type))
+         if (!is_void(get_func_return_type(func)))
          {
              fprintf(client, "\n");
              print_client("return _RetVal;\n");
@@@ -437,7 -489,7 +489,7 @@@ void write_client(ifref_list_t *ifaces
              write_function_stubs(iface->iface, &proc_offset);
  
              print_client("#if !defined(__RPC_WIN32__)\n");
 -            print_client("#error  Invalid build platform for this stub.\n");
 +            print_client("//#error  Invalid build platform for this stub.\n");
              print_client("#endif\n");
  
              fprintf(client, "\n");
@@@ -60,13 -60,21 +60,21 @@@ static void write_function_stubs(type_
      LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
      {
          const var_t *def = func->def;
+         const var_t* context_handle_var = NULL;
+         const var_t* explicit_generic_handle_var = NULL;
          int has_full_pointer = is_full_pointer_function(func);
  
          /* check for a defined binding handle */
          explicit_handle_var = get_explicit_handle_var(func);
+         if (!explicit_handle_var)
+         {
+             explicit_generic_handle_var = get_explicit_generic_handle_var(func);
+             if (!explicit_generic_handle_var)
+                 context_handle_var = get_context_handle_var(func);
+         }
          if (explicit_handle)
          {
-             if (!explicit_handle_var)
+             if (!explicit_handle_var && !explicit_generic_handle_var && !context_handle_var)
              {
                  error("%s() does not define an explicit binding handle!\n", def->name);
                  return;
          assign_stub_out_args(server, indent, func);
  
          /* Call the real server function */
-         if (!is_void(def->type))
+         if (!is_void(get_func_return_type(func)))
              print_server("_RetVal = ");
          else
              print_server("");
                      fprintf(server, ",\n");
                  if (is_context_handle(var->type))
                  {
+                     /* if the context_handle attribute appears in the chain of types
+                      * without pointers being followed, then the context handle must
+                      * be direct, otherwise it is a pointer */
+                     int is_ch_ptr = is_aliaschain_attr(var->type, ATTR_CONTEXTHANDLE) ? FALSE : TRUE;
                      print_server("(");
                      write_type_decl_left(server, var->type);
-                     fprintf(server, ")%sNDRSContextValue(%s)", is_ptr(var->type) ? "" : "*", var->name);
+                     fprintf(server, ")%sNDRSContextValue(%s)", is_ch_ptr ? "" : "*", var->name);
                  }
                  else
                  {
          {
              write_remoting_arguments(server, indent, func, PASS_OUT, PHASE_BUFFERSIZE);
  
-             if (!is_void(def->type))
+             if (!is_void(get_func_return_type(func)))
                  write_remoting_arguments(server, indent, func, PASS_RETURN, PHASE_BUFFERSIZE);
  
              print_server("_pRpcMessage->BufferLength = _StubMsg.BufferLength;\n");
          write_remoting_arguments(server, indent, func, PASS_OUT, PHASE_MARSHAL);
  
          /* marshall the return value */
-         if (!is_void(def->type))
+         if (!is_void(get_func_return_type(func)))
              write_remoting_arguments(server, indent, func, PASS_RETURN, PHASE_MARSHAL);
  
          indent--;
@@@ -440,7 -452,7 +452,7 @@@ void write_server(ifref_list_t *ifaces
              write_function_stubs(iface->iface, &proc_offset);
      
              print_server("#if !defined(__RPC_WIN32__)\n");
 -            print_server("#error  Invalid build platform for this stub.\n");
 +            print_server("//#error  Invalid build platform for this stub.\n");
              print_server("#endif\n");
  
              fprintf(server, "\n");
@@@ -58,6 -58,9 +58,9 @@@ static size_t write_struct_tfs(FILE *fi
  static int write_embedded_types(FILE *file, const attr_list_t *attrs, type_t *type,
                                  const char *name, int write_ptr, unsigned int *tfsoff);
  static const var_t *find_array_or_string_in_struct(const type_t *type);
+ static size_t write_string_tfs(FILE *file, const attr_list_t *attrs,
+                                type_t *type,
+                                const char *name, unsigned int *typestring_offset);
  
  const char *string_of_type(unsigned char type)
  {
@@@ -165,7 -168,7 +168,7 @@@ static int type_has_pointers(const type
      else if (is_struct(type->type))
      {
          const var_t *field;
-         if (type->fields) LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
+         if (type->fields_or_args) LIST_FOR_EACH_ENTRY( field, type->fields_or_args, const var_t, entry )
          {
              if (type_has_pointers(field->type))
                  return TRUE;
          const var_t *field;
          if (type->type == RPC_FC_ENCAPSULATED_UNION)
          {
-             const var_t *uv = LIST_ENTRY(list_tail(type->fields), const var_t, entry);
-             fields = uv->type->fields;
+             const var_t *uv = LIST_ENTRY(list_tail(type->fields_or_args), const var_t, entry);
+             fields = uv->type->fields_or_args;
          }
          else
-             fields = type->fields;
+             fields = type->fields_or_args;
          if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
          {
              if (field->type && type_has_pointers(field->type))
@@@ -205,7 -208,7 +208,7 @@@ static int type_has_full_pointer(const 
      else if (is_struct(type->type))
      {
          const var_t *field;
-         if (type->fields) LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
+         if (type->fields_or_args) LIST_FOR_EACH_ENTRY( field, type->fields_or_args, const var_t, entry )
          {
              if (type_has_full_pointer(field->type))
                  return TRUE;
          const var_t *field;
          if (type->type == RPC_FC_ENCAPSULATED_UNION)
          {
-             const var_t *uv = LIST_ENTRY(list_tail(type->fields), const var_t, entry);
-             fields = uv->type->fields;
+             const var_t *uv = LIST_ENTRY(list_tail(type->fields_or_args), const var_t, entry);
+             fields = uv->type->fields_or_args;
          }
          else
-             fields = type->fields;
+             fields = type->fields_or_args;
          if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
          {
              if (field->type && type_has_full_pointer(field->type))
@@@ -415,8 -418,8 +418,8 @@@ void write_parameters_init(FILE *file, 
  {
      const var_t *var;
  
-     if (!is_void(func->def->type))
-         write_var_init(file, indent, func->def->type, "_RetVal");
+     if (!is_void(get_func_return_type(func)))
+         write_var_init(file, indent, get_func_return_type(func), "_RetVal");
  
      if (!func->args)
          return;
@@@ -490,14 -493,16 +493,16 @@@ int decl_indirect(const type_t *t
              && !is_array(t));
  }
  
- static size_t write_procformatstring_var(FILE *file, int indent,
-                                          const var_t *var, int is_return)
+ static size_t write_procformatstring_type(FILE *file, int indent,
+                                           const char *name,
+                                           const type_t *type,
+                                           const attr_list_t *attrs,
+                                           int is_return)
  {
      size_t size;
-     const type_t *type = var->type;
  
-     int is_in = is_attr(var->attrs, ATTR_IN);
-     int is_out = is_attr(var->attrs, ATTR_OUT);
+     int is_in = is_attr(attrs, ATTR_IN);
+     int is_out = is_attr(attrs, ATTR_OUT);
  
      if (!is_in && !is_out) is_in = TRUE;
  
          }
          else
          {
-             error("Unknown/unsupported type: %s (0x%02x)\n", var->name, type->type);
+             error("Unknown/unsupported type: %s (0x%02x)\n", name, type->type);
              size = 0;
          }
      }
@@@ -570,18 -575,17 +575,17 @@@ void write_procformatstring(FILE *file
                  if (func->args)
                  {
                      LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
-                         write_procformatstring_var(file, indent, var, FALSE);
+                         write_procformatstring_type(file, indent, var->name, var->type, var->attrs, FALSE);
                  }
  
                  /* emit return value data */
-                 var = func->def;
-                 if (is_void(var->type))
+                 if (is_void(get_func_return_type(func)))
                  {
                      print_file(file, indent, "0x5b,    /* FC_END */\n");
                      print_file(file, indent, "0x5c,    /* FC_PAD */\n");
                  }
                  else
-                     write_procformatstring_var(file, indent, var, TRUE);
+                     write_procformatstring_type(file, indent, "return value", get_func_return_type(func), NULL, TRUE);
              }
          }
      }
@@@ -706,7 -710,7 +710,7 @@@ static size_t write_conf_or_var_desc(FI
          size_t offset = 0;
          const var_t *var;
  
-         if (structure->fields) LIST_FOR_EACH_ENTRY( var, structure->fields, const var_t, entry )
+         if (structure->fields_or_args) LIST_FOR_EACH_ENTRY( var, structure->fields_or_args, const var_t, entry )
          {
              unsigned int align = 0;
              /* FIXME: take alignment into account */
@@@ -921,11 -925,11 +925,11 @@@ size_t type_memsize(const type_t *t, un
      case RPC_FC_CSTRUCT:
      case RPC_FC_PSTRUCT:
      case RPC_FC_BOGUS_STRUCT:
-         size = fields_memsize(t->fields, align);
+         size = fields_memsize(t->fields_or_args, align);
          break;
      case RPC_FC_ENCAPSULATED_UNION:
      case RPC_FC_NON_ENCAPSULATED_UNION:
-         size = union_memsize(t->fields, align);
+         size = union_memsize(t->fields_or_args, align);
          break;
      case RPC_FC_SMFARRAY:
      case RPC_FC_LGFARRAY:
  int is_full_pointer_function(const func_t *func)
  {
      const var_t *var;
-     if (type_has_full_pointer(func->def->type))
+     if (type_has_full_pointer(get_func_return_type(func)))
          return TRUE;
      if (!func->args)
          return FALSE;
@@@ -981,27 -985,13 +985,13 @@@ static unsigned int write_nonsimple_poi
      return 4;
  }
  
- static unsigned char conf_string_type_of_char_type(unsigned char t)
- {
-     switch (t)
-     {
-     case RPC_FC_BYTE:
-     case RPC_FC_CHAR:
-         return RPC_FC_C_CSTRING;
-     case RPC_FC_WCHAR:
-         return RPC_FC_C_WSTRING;
-     }
-     error("string_type_of_char_type: unrecognized type %d\n", t);
-     return 0;
- }
  static unsigned int write_simple_pointer(FILE *file, const type_t *type)
  {
-     unsigned char fc
-         = is_string_type(type->attrs, type)
-         ? conf_string_type_of_char_type(type->ref->type)
-         : type->ref->type;
+     unsigned char fc = type->ref->type;
+     /* for historical reasons, write_simple_pointer also handled string types,
+      * but no longer does. catch bad uses of the function with this check */
+     if (is_string_type(type->attrs, type))
+         error("write_simple_pointer: can't handle type %s which is a string type\n", type->name);
      print_file(file, 2, "0x%02x, 0x8,\t/* %s [simple_pointer] */\n",
                 type->type, string_of_type(type->type));
      print_file(file, 2, "0x%02x,\t/* %s */\n", fc, string_of_type(fc));
@@@ -1157,7 -1147,7 +1147,7 @@@ static void write_end(FILE *file, unsig
  static void write_descriptors(FILE *file, type_t *type, unsigned int *tfsoff)
  {
      unsigned int offset = 0;
-     var_list_t *fs = type->fields;
+     var_list_t *fs = type->fields_or_args;
      var_t *f;
  
      if (fs) LIST_FOR_EACH_ENTRY(f, fs, var_t, entry)
@@@ -1202,7 -1192,12 +1192,12 @@@ static int write_no_repeat_pointer_desc
          *typestring_offset += 6;
  
          if (is_ptr(type))
-             write_pointer_tfs(file, type, typestring_offset);
+         {
+             if (is_string_type(type->attrs, type))
+                 write_string_tfs(file, NULL, type, NULL, typestring_offset);
+             else
+                 write_pointer_tfs(file, type, typestring_offset);
+         }
          else
          {
              unsigned absoff = type->typestring_offset;
      if (is_non_complex_struct(type))
      {
          const var_t *v;
-         LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
+         LIST_FOR_EACH_ENTRY( v, type->fields_or_args, const var_t, entry )
              written += write_no_repeat_pointer_descriptions(
                  file, v->type,
                  offset_in_memory, offset_in_buffer, typestring_offset);
@@@ -1268,7 -1263,9 +1263,9 @@@ static int write_pointer_description_of
          }
          *typestring_offset += 4;
  
-         if (processed(type->ref) || is_base_type(type->ref->type))
+         if (is_string_type(attrs, type))
+             write_string_tfs(file, NULL, type, NULL, typestring_offset);
+         else if (processed(type->ref) || is_base_type(type->ref->type))
              write_pointer_tfs(file, type, typestring_offset);
          else
              error("write_pointer_description_offsets: type format string unknown\n");
      {
          /* otherwise search for interesting fields to parse */
          const var_t *v;
-         LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
+         LIST_FOR_EACH_ENTRY( v, type->fields_or_args, const var_t, entry )
          {
              written += write_pointer_description_offsets(
                  file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
@@@ -1349,7 -1346,7 +1346,7 @@@ static int write_fixed_array_pointer_de
      else if (is_struct(type->type))
      {
          const var_t *v;
-         LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
+         LIST_FOR_EACH_ENTRY( v, type->fields_or_args, const var_t, entry )
          {
              pointer_count += write_fixed_array_pointer_descriptions(
                  file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
@@@ -1460,7 -1457,7 +1457,7 @@@ static int write_varying_array_pointer_
      else if (is_struct(type->type))
      {
          const var_t *v;
-         LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
+         LIST_FOR_EACH_ENTRY( v, type->fields_or_args, const var_t, entry )
          {
              pointer_count += write_varying_array_pointer_descriptions(
                  file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
@@@ -1535,18 -1532,18 +1532,18 @@@ int is_declptr(const type_t *t
  
  static size_t write_string_tfs(FILE *file, const attr_list_t *attrs,
                                 type_t *type,
-                                const char *name, unsigned int *typestring_offset,
-                                int toplevel)
+                                const char *name, unsigned int *typestring_offset)
  {
      size_t start_offset;
      unsigned char rtype;
  
-     if (toplevel && is_declptr(type))
+     if (is_declptr(type))
      {
          unsigned char flag = is_conformant_array(type) ? 0 : RPC_FC_P_SIMPLEPOINTER;
          int pointer_type = is_ptr(type) ? type->type : get_attrv(attrs, ATTR_POINTERTYPE);
          if (!pointer_type)
              pointer_type = RPC_FC_RP;
+         print_start_tfs_comment(file, type, *typestring_offset);
          print_file(file, 2,"0x%x, 0x%x,\t/* %s%s */\n",
                     pointer_type, flag, string_of_type(pointer_type),
                     flag ? " [simple_pointer]" : "");
@@@ -1733,7 -1730,7 +1730,7 @@@ static size_t write_array_tfs(FILE *fil
  
  static const var_t *find_array_or_string_in_struct(const type_t *type)
  {
-     const var_t *last_field = LIST_ENTRY( list_tail(type->fields), const var_t, entry );
+     const var_t *last_field = LIST_ENTRY( list_tail(type->fields_or_args), const var_t, entry );
      const type_t *ft = last_field->type;
  
      if (ft->declarray && is_conformant_array(ft))
@@@ -1753,7 -1750,7 +1750,7 @@@ static void write_struct_members(FILE *
      int salign = -1;
      int padding;
  
-     if (type->fields) LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
+     if (type->fields_or_args) LIST_FOR_EACH_ENTRY( field, type->fields_or_args, const var_t, entry )
      {
          type_t *ft = field->type;
          if (!ft->declarray || !is_conformant_array(ft))
@@@ -1819,7 -1816,7 +1816,7 @@@ static size_t write_struct_tfs(FILE *fi
          error("structure size for %s exceeds %d bytes by %d bytes\n",
                name, USHRT_MAX, total_size - USHRT_MAX);
  
-     if (type->fields) LIST_FOR_EACH_ENTRY(f, type->fields, var_t, entry)
+     if (type->fields_or_args) LIST_FOR_EACH_ENTRY(f, type->fields_or_args, var_t, entry)
          has_pointers |= write_embedded_types(file, f->attrs, f->type, f->name,
                                               FALSE, tfsoff);
      if (!has_pointers) has_pointers = type_has_pointers(type);
      if (array && !processed(array->type))
          array_offset
              = is_attr(array->attrs, ATTR_STRING)
-             ? write_string_tfs(file, array->attrs, array->type, array->name, tfsoff, FALSE)
+             ? write_string_tfs(file, array->attrs, array->type, array->name, tfsoff)
              : write_array_tfs(file, array->attrs, array->type, array->name, tfsoff);
  
      corroff = *tfsoff;
  
      if (type->type == RPC_FC_BOGUS_STRUCT)
      {
-         const var_list_t *fs = type->fields;
+         const var_list_t *fs = type->fields_or_args;
          const var_t *f;
  
          type->ptrdesc = *tfsoff;
          {
              type_t *ft = f->type;
              if (is_ptr(ft))
-                 write_pointer_tfs(file, ft, tfsoff);
+             {
+                 if (is_string_type(f->attrs, ft))
+                     write_string_tfs(file, f->attrs, ft, f->name, tfsoff);
+                 else
+                     write_pointer_tfs(file, ft, tfsoff);
+             }
              else if (!ft->declarray && is_conformant_array(ft))
              {
                  unsigned int absoff = ft->typestring_offset;
@@@ -1988,11 -1990,11 +1990,11 @@@ static size_t write_union_tfs(FILE *fil
  
      if (type->type == RPC_FC_ENCAPSULATED_UNION)
      {
-         const var_t *uv = LIST_ENTRY(list_tail(type->fields), const var_t, entry);
-         fields = uv->type->fields;
+         const var_t *uv = LIST_ENTRY(list_tail(type->fields_or_args), const var_t, entry);
+         fields = uv->type->fields_or_args;
      }
      else
-         fields = type->fields;
+         fields = type->fields_or_args;
  
      if (fields) LIST_FOR_EACH_ENTRY(f, fields, var_t, entry)
      {
      print_start_tfs_comment(file, type, start_offset);
      if (type->type == RPC_FC_ENCAPSULATED_UNION)
      {
-         const var_t *sv = LIST_ENTRY(list_head(type->fields), const var_t, entry);
+         const var_t *sv = LIST_ENTRY(list_head(type->fields_or_args), const var_t, entry);
          const type_t *st = sv->type;
  
          switch (st->type)
@@@ -2181,8 -2183,8 +2183,8 @@@ static size_t write_typeformatstring_va
          return type->typestring_offset;
      }
  
-     if ((last_ptr(type) || last_array(type)) && is_ptrchain_attr(var, ATTR_STRING))
-         return write_string_tfs(file, var->attrs, type, var->name, typeformat_offset, TRUE);
+     if (is_string_type(var->attrs, type))
+         return write_string_tfs(file, var->attrs, type, var->name, typeformat_offset);
  
      if (is_array(type))
      {
@@@ -2286,6 -2288,10 +2288,10 @@@ static int write_embedded_types(FILE *f
      {
          write_user_tfs(file, type, tfsoff);
      }
+     else if (is_string_type(attrs, type))
+     {
+         write_string_tfs(file, attrs, type, name, tfsoff);
+     }
      else if (is_ptr(type))
      {
          type_t *ref = type->ref;
              retmask |= 1;
          }
      }
-     else if (last_array(type) && is_attr(attrs, ATTR_STRING))
-     {
-         write_string_tfs(file, attrs, type, name, tfsoff, FALSE);
-     }
      else if (type->declarray && is_conformant_array(type))
          ;    /* conformant arrays and strings are handled specially */
      else if (is_array(type))
@@@ -2355,12 -2357,16 +2357,16 @@@ static size_t process_tfs(FILE *file, c
              {
                  if (is_local(func->def->attrs)) continue;
  
-                 if (!is_void(func->def->type))
-                     update_tfsoff(func->def->type,
+                 if (!is_void(get_func_return_type(func)))
+                 {
+                     var_t v = *func->def;
+                     v.type = get_func_return_type(func);
+                     update_tfsoff(get_func_return_type(func),
                                    write_typeformatstring_var(
-                                       file, 2, NULL, func->def->type,
-                                       func->def, &typeformat_offset),
+                                       file, 2, NULL, get_func_return_type(func),
+                                       &v, &typeformat_offset),
                                    file);
+                 }
  
                  current_func = func;
                  if (func->args)
@@@ -2452,8 -2458,8 +2458,8 @@@ static unsigned int get_required_buffer
          {
              size_t size = 0;
              const var_t *field;
-             if (!type->fields) return 0;
-             LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
+             if (!type->fields_or_args) return 0;
+             LIST_FOR_EACH_ENTRY( field, type->fields_or_args, const var_t, entry )
              {
                  unsigned int alignment;
                  size += get_required_buffer_size_type(field->type, field->name,
@@@ -2507,8 -2513,8 +2513,8 @@@ static unsigned int get_required_buffer
                  const var_t *field;
                  unsigned int size = 36;
  
-                 if (!type->fields) return size;
-                 LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
+                 if (!type->fields_or_args) return size;
+                 LIST_FOR_EACH_ENTRY( field, type->fields_or_args, const var_t, entry )
                  {
                      unsigned int align;
                      size += get_required_buffer_size_type(
                      unsigned int size = 36;
                      const var_t *field;
  
-                     if (!type->fields) return size;
-                     LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
+                     if (!type->fields_or_args) return size;
+                     LIST_FOR_EACH_ENTRY( field, type->fields_or_args, const var_t, entry )
                      {
                          unsigned int align;
                          size += get_required_buffer_size_type(
@@@ -2567,9 -2573,11 +2573,11 @@@ static unsigned int get_function_buffer
          }
      }
  
-     if (pass == PASS_OUT && !is_void(func->def->type))
+     if (pass == PASS_OUT && !is_void(get_func_return_type(func)))
      {
-         total_size += get_required_buffer_size(func->def, &alignment, PASS_RETURN);
+         var_t v = *func->def;
+         v.type = get_func_return_type(func);
+         total_size += get_required_buffer_size(&v, &alignment, PASS_RETURN);
          total_size += alignment;
      }
      return total_size;
@@@ -2673,8 -2681,8 +2681,8 @@@ void print_phase_basetype(FILE *file, i
      }
  
      if (phase == PHASE_MARSHAL)
 -        print_file(file, indent, "MIDL_memset(_StubMsg.Buffer, 0, (0x%x - (long)_StubMsg.Buffer) & 0x%x);\n", alignment, alignment - 1);
 -    print_file(file, indent, "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
 +        print_file(file, indent, "MIDL_memset(_StubMsg.Buffer, 0, (0x%x - (size_t)_StubMsg.Buffer) & 0x%x);\n", alignment, alignment - 1);
 +    print_file(file, indent, "_StubMsg.Buffer = (unsigned char *)(((size_t)_StubMsg.Buffer + %u) & ~0x%x);\n",
                  alignment - 1, alignment - 1);
  
      if (phase == PHASE_MARSHAL)
@@@ -2778,9 -2786,13 +2786,13 @@@ static void write_remoting_arg(FILE *fi
          {
              if (pass == PASS_IN)
              {
+                 /* if the context_handle attribute appears in the chain of types
+                  * without pointers being followed, then the context handle must
+                  * be direct, otherwise it is a pointer */
+                 int is_ch_ptr = is_aliaschain_attr(type, ATTR_CONTEXTHANDLE) ? FALSE : TRUE;
                  print_file(file, indent, "NdrClientContextMarshall(\n");
                  print_file(file, indent + 1, "&_StubMsg,\n");
-                 print_file(file, indent + 1, "(NDR_CCONTEXT)%s%s,\n", is_ptr(type) ? "*" : "", var->name);
+                 print_file(file, indent + 1, "(NDR_CCONTEXT)%s%s,\n", is_ch_ptr ? "*" : "", var->name);
                  print_file(file, indent + 1, "%s);\n", in_attr && out_attr ? "1" : "0");
              }
              else
@@@ -3008,6 -3020,7 +3020,7 @@@ void write_remoting_arguments(FILE *fil
      {
          var_t var;
          var = *func->def;
+         var.type = get_func_return_type(func);
          var.name = xstrdup( "_RetVal" );
          write_remoting_arg( file, indent, func, pass, phase, &var );
          free( var.name );
  }
  
  
- size_t get_size_procformatstring_var(const var_t *var)
+ size_t get_size_procformatstring_type(const char *name, const type_t *type, const attr_list_t *attrs)
  {
-     return write_procformatstring_var(NULL, 0, var, FALSE);
+     return write_procformatstring_type(NULL, 0, name, type, attrs, FALSE);
  }
  
  
@@@ -3037,13 -3050,13 +3050,13 @@@ size_t get_size_procformatstring_func(c
      /* argument list size */
      if (func->args)
          LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
-             size += get_size_procformatstring_var(var);
+             size += get_size_procformatstring_type(var->name, var->type, var->attrs);
  
      /* return value size */
-     if (is_void(func->def->type))
+     if (is_void(get_func_return_type(func)))
          size += 2; /* FC_END and FC_PAD */
      else
-         size += get_size_procformatstring_var(func->def);
+         size += get_size_procformatstring_type("return value", get_func_return_type(func), NULL);
  
      return size;
  }
@@@ -3175,14 -3188,13 +3188,13 @@@ void declare_stub_args( FILE *file, in
  {
      int in_attr, out_attr;
      int i = 0;
-     const var_t *def = func->def;
      const var_t *var;
  
      /* declare return value '_RetVal' */
-     if (!is_void(def->type))
+     if (!is_void(get_func_return_type(func)))
      {
          print_file(file, indent, "");
-         write_type_decl_left(file, def->type);
+         write_type_decl_left(file, get_func_return_type(func));
          fprintf(file, " _RetVal;\n");
      }
  
@@@ -3299,7 -3311,7 +3311,7 @@@ int write_expr_eval_routines(FILE *file
      LIST_FOR_EACH_ENTRY(eval, &expr_eval_routines, struct expr_eval_routine, entry)
      {
          const char *name = eval->structure->name;
-         const var_list_t *fields = eval->structure->fields;
+         const var_list_t *fields = eval->structure->fields_or_args;
          result = 1;
  
          print_file(file, 0, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",