Fixed packing and layout of many system structures.

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 0bd64e4..281f1a8 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -287,7 +287,7 @@
         DWORD len = info->NameLength / sizeof(WCHAR);
         DWORD cls_len = info->ClassLength / sizeof(WCHAR);
 
-        if (ft) *ft = info->LastWriteTime;
+        if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
 
         if (len >= *name_len || (class_len && (cls_len >= *class_len)))
             status = STATUS_BUFFER_OVERFLOW;
@@ -351,7 +351,7 @@
                                              info->ClassLength / sizeof(WCHAR),
                                              NULL, 0, NULL, NULL );
 
-        if (ft) *ft = info->LastWriteTime;
+        if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
 
         if (len >= *name_len || (class_len && (cls_len >= *class_len)))
             status = STATUS_BUFFER_OVERFLOW;
@@ -472,7 +472,7 @@
     if (values) *values = info->Values;
     if (max_value) *max_value = info->MaxValueNameLen;
     if (max_data) *max_data = info->MaxValueDataLen;
-    if (modif) *modif = info->LastWriteTime;
+    if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
 
  done:
     if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
@@ -542,7 +542,7 @@
     if (values) *values = info->Values;
     if (max_value) *max_value = info->MaxValueNameLen;
     if (max_data) *max_data = info->MaxValueDataLen;
-    if (modif) *modif = info->LastWriteTime;
+    if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
 
  done:
     if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c
index f355fd6..f0b934e 100644
--- a/dlls/ntdll/reg.c
+++ b/dlls/ntdll/reg.c
@@ -161,9 +161,9 @@
     WCHAR *class_ptr = (WCHAR *)((char *)name_ptr + name_size);
     int class_size = server_data_size(req) - sizeof(WCHAR) - name_size;
     int fixed_size;
-    FILETIME modif;
+    LARGE_INTEGER modif;
 
-    RtlSecondsSince1970ToTime( req->modif, &modif );
+    RtlSecondsSince1970ToTime( req->modif, (FILETIME *)&modif );
 
     switch(info_class)
     {
diff --git a/include/commctrl.h b/include/commctrl.h
index bec4025..ea244d5 100644
--- a/include/commctrl.h
+++ b/include/commctrl.h
@@ -744,6 +744,8 @@
     LPARAM    lParam;
     INT     iImage;
     INT     iOrder;
+    UINT    type;
+    LPVOID  pvFilter;
 } HDITEMA, *LPHDITEMA;
 
 typedef struct _HD_ITEMW
@@ -757,6 +759,8 @@
     LPARAM    lParam;
     INT     iImage;
     INT     iOrder;
+    UINT    type;
+    LPVOID  pvFilter;
 } HDITEMW, *LPHDITEMW;
 
 #define HDITEM   WINELIB_NAME_AW(HDITEM)
@@ -1148,7 +1152,7 @@
     HKEY   hkr;
     LPCWSTR pszSubKey;
     LPCWSTR pszValueName;
-} TBSAVEPARAMSAW, *LPTBSAVEPARAMSAW;
+} TBSAVEPARAMSW, *LPTBSAVEPARAMSW;
 
 #define TBSAVEPARAMS   WINELIB_NAME_AW(TBSAVEPARAMS)
 #define LPTBSAVEPARAMS WINELIB_NAME_AW(LPTBSAVEPARAMS)
@@ -2250,12 +2254,14 @@
 #define NMTVGETINFOTIP WINELIB_NAME_AW(NMTVGETINFOTIP)
 #define LPNMTVGETINFOTIP WINELIB_NAME_AW(LPNMTVGETINFOTIP)
 
+#include "pshpack1.h"
 typedef struct tagTVKEYDOWN
 {
     NMHDR hdr;
     WORD wVKey;
     UINT flags;
 } NMTVKEYDOWN, *LPNMTVKEYDOWN;
+#include "poppack.h"
 
 #define TV_KEYDOWN      NMTVKEYDOWN
 
@@ -2870,12 +2876,14 @@
 
 #define LV_DISPINFO     NMLVDISPINFO
 
+#include "pshpack1.h"
 typedef struct tagLVKEYDOWN
 {
   NMHDR hdr;
   WORD  wVKey;
   UINT flags;
 } NMLVKEYDOWN, *LPNMLVKEYDOWN;
+#include "poppack.h"
 
 #define LV_KEYDOWN     NMLVKEYDOWN
 
@@ -3307,12 +3315,14 @@
 #define TCN_SELCHANGING         (TCN_FIRST - 2)
 #define TCN_GETOBJECT      (TCN_FIRST - 3)
 
+#include "pshpack1.h"
 typedef struct tagTCKEYDOWN
 {
     NMHDR hdr;
     WORD wVKey;
     UINT flags;
 } NMTCKEYDOWN;
+#include "poppack.h"
 
 #define TC_KEYDOWN              NMTCKEYDOWN
 
diff --git a/include/dplay.h b/include/dplay.h
index 524b4cd..89326e5 100644
--- a/include/dplay.h
+++ b/include/dplay.h
@@ -8,8 +8,6 @@
 extern "C" {
 #endif /* defined(__cplusplus) */
 
-#include "pshpack1.h"
-
 typedef LPVOID (*LPRGLPVOID)[];
 typedef LPRGLPVOID PRGPVOID, LPRGPVOID, PRGLPVOID, PAPVOID, LPAPVOID, PALPVOID, LPALPVOID;
 
@@ -401,8 +399,6 @@
 
 #define DPESC_TIMEDOUT          0x00000001
 
-#include "poppack.h"
-
 /*****************************************************************************
  * IDirectPlay interface
  */
diff --git a/include/dplobby.h b/include/dplobby.h
index 83384c7..b159020 100644
--- a/include/dplobby.h
+++ b/include/dplobby.h
@@ -7,8 +7,6 @@
 extern "C" {
 #endif /* defined(__cplusplus) */
 
-#include "pshpack1.h"
-
 /*****************************************************************************
  * Predeclare the interfaces
  */
@@ -348,8 +346,6 @@
     LPVOID          lpContext,
     DWORD           dwFlags );
 
-#include "poppack.h"
-
 /*****************************************************************************
  * IDirectPlayLobby and IDirectPlayLobbyA interface
  */
diff --git a/include/mmsystem.h b/include/mmsystem.h
index 31430ec..f75a6f2 100644
--- a/include/mmsystem.h
+++ b/include/mmsystem.h
@@ -549,13 +549,13 @@
     LPSTR	lpData;		/* pointer to locked data block */
     DWORD	dwBufferLength;	/* length of data in data block */
     DWORD	dwBytesRecorded;/* used for input only */
-    DWORD	dwUser;		/* for client's use */
+    DWORD_PTR	dwUser;		/* for client's use */
     DWORD	dwFlags;	/* assorted flags (see defines) */
     struct midihdr_tag *lpNext;	/* reserved for driver */
     DWORD	reserved;	/* reserved for driver */
     DWORD	dwOffset;	/* offset of playback in case of 
 				 * MIDISTRM buffer */
-    DWORD	dwReserved[4];	/* reserved for driver */
+    DWORD_PTR	dwReserved[8];	/* reserved for driver */
 } MIDIHDR, *LPMIDIHDR;
 
 #define MHDR_DONE       0x00000001       /* done bit */
diff --git a/include/nb30.h b/include/nb30.h
index ae1350b..4526d00 100644
--- a/include/nb30.h
+++ b/include/nb30.h
@@ -21,8 +21,6 @@
 #define NCBASTAT       0x33
 #define NCBENUM        0x37
 
-#include "pshpack1.h"
-
 typedef struct _NCB
 {
 	UCHAR	ncb_command;
@@ -54,8 +52,8 @@
 	WORD	frmr_xmit;
 	WORD	iframe_recv_error;
 	WORD	xmit_aborts;
-	WORD	xmit_success;
-	WORD	recv_success;
+	DWORD	xmit_success;
+	DWORD	recv_success;
 	WORD	iframe_xmit_error;
 	WORD	recv_buffer_unavail;
 	WORD	t1_timeouts;
diff --git a/include/ntddk.h b/include/ntddk.h
index 69b3d19..8d13fa1 100644
--- a/include/ntddk.h
+++ b/include/ntddk.h
@@ -11,8 +11,6 @@
 #include "winreg.h"
 #include "winbase.h"	/* fixme: should be taken out sometimes */
 
-#include "pshpack1.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -39,7 +37,7 @@
 
  /* key information */
 typedef struct _KEY_BASIC_INFORMATION {
-	FILETIME	LastWriteTime;
+	LARGE_INTEGER	LastWriteTime;
 	ULONG		TitleIndex;
 	ULONG		NameLength;
 	WCHAR		Name[1];
@@ -47,7 +45,7 @@
 
 typedef struct _KEY_NODE_INFORMATION 
 {
-	FILETIME	LastWriteTime;
+	LARGE_INTEGER	LastWriteTime;
 	ULONG		TitleIndex;
 	ULONG		ClassOffset;
 	ULONG		ClassLength;
@@ -58,7 +56,7 @@
 
 typedef struct _KEY_FULL_INFORMATION 
 {
-	FILETIME	LastWriteTime;
+	LARGE_INTEGER	LastWriteTime;
 	ULONG		TitleIndex;
 	ULONG		ClassOffset;
 	ULONG		ClassLength;
@@ -951,6 +949,4 @@
 }
 #endif
 
-#include "poppack.h"
-
 #endif
diff --git a/include/ntdef.h b/include/ntdef.h
index c992bec..742f32a 100644
--- a/include/ntdef.h
+++ b/include/ntdef.h
@@ -4,8 +4,6 @@
 #include "basetsd.h"
 #include "windef.h"
 
-#include "pshpack1.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -95,6 +93,4 @@
 }
 #endif
 
-#include "poppack.h"
-
 #endif
diff --git a/include/winbase.h b/include/winbase.h
index 3855bad..f880122 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -7,7 +7,6 @@
 
 #include "basetsd.h"
 #include "windef.h"
-#include "pshpack1.h"
 
 #ifndef RC_INVOKED
 #include <stdarg.h>
@@ -976,9 +975,6 @@
 	DWORD	WriteTotalTimeoutConstant;
 } COMMTIMEOUTS,*LPCOMMTIMEOUTS;
 
-
-#include "poppack.h"
-
 typedef void CALLBACK (*PAPCFUNC)(ULONG_PTR);
 typedef void CALLBACK (*PTIMERAPCROUTINE)(LPVOID,DWORD,DWORD);
   
diff --git a/include/wingdi.h b/include/wingdi.h
index ee8de33..79101df 100644
--- a/include/wingdi.h
+++ b/include/wingdi.h
@@ -6,9 +6,6 @@
 extern "C" {
 #endif
 
-
-#include "pshpack1.h"
-
 typedef struct _ABCFLOAT {
     FLOAT   abcfA;
     FLOAT   abcfB;
@@ -1076,7 +1073,6 @@
 #define NTM_BOLD        0x00000020L
 #define NTM_ITALIC      0x00000001L
 
-#include "pshpack4.h"
 typedef struct
 {
     LONG      tmHeight;
@@ -1132,7 +1128,6 @@
     UINT      ntmCellHeight;
     UINT      ntmAvgWidth;
 } NEWTEXTMETRICW, *PNEWTEXTMETRICW, *LPNEWTEXTMETRICW;
-#include "poppack.h"
 
 DECL_WINELIB_TYPE_AW(NEWTEXTMETRIC)
 DECL_WINELIB_TYPE_AW(PNEWTEXTMETRIC)
@@ -1640,6 +1635,7 @@
   BYTE rgbtRed;
 } RGBTRIPLE;
 
+#include "pshpack2.h"
 typedef struct
 {
     WORD    bfType;
@@ -1648,6 +1644,7 @@
     WORD    bfReserved2;
     DWORD   bfOffBits;
 } BITMAPFILEHEADER, *PBITMAPFILEHEADER, *LPBITMAPFILEHEADER;
+#include "poppack.h"
 
 #define MAKEPOINTS(l)  (*((POINTS *)&(l)))
 
@@ -1785,6 +1782,7 @@
 
 #define CLR_INVALID         0xffffffff
 /* Metafile header structure */
+#include "pshpack2.h"
 typedef struct
 {
     WORD       mtType;
@@ -1795,6 +1793,7 @@
     DWORD      mtMaxRecord;
     WORD       mtNoParameters;
 } METAHEADER, *PMETAHEADER, *LPMETAHEADER;
+#include "poppack.h"
 
 /* Metafile typical record structure */
 typedef struct
@@ -2959,9 +2958,11 @@
 
 typedef struct {
     DWORD	cb;
-    BYTE	DeviceName[32];
-    BYTE	DeviceString[128];
+    CHAR	DeviceName[32];
+    CHAR	DeviceString[128];
     DWORD	StateFlags;
+    CHAR	DeviceID[128];
+    CHAR	DeviceKey[128];
 } DISPLAY_DEVICEA,*PDISPLAY_DEVICEA,*LPDISPLAY_DEVICEA;      
 
 typedef struct {
@@ -2969,6 +2970,8 @@
     WCHAR	DeviceName[32];
     WCHAR	DeviceString[128];
     DWORD	StateFlags;
+    WCHAR	DeviceID[128];
+    WCHAR	DeviceKey[128];
 } DISPLAY_DEVICEW,*PDISPLAY_DEVICEW,*LPDISPLAY_DEVICEW;      
 DECL_WINELIB_TYPE_AW(DISPLAY_DEVICE)
 DECL_WINELIB_TYPE_AW(PDISPLAY_DEVICE)
@@ -2984,8 +2987,6 @@
 #define GDI_ERROR                               (0xFFFFFFFFL)
 #define HGDI_ERROR                              ((HANDLE)0xFFFFFFFFL)
 
-#include "poppack.h"
-
 INT       WINAPI AbortDoc(HDC);
 BOOL      WINAPI AbortPath(HDC);
 INT       WINAPI AddFontResourceA(LPCSTR);
diff --git a/include/winnt.h b/include/winnt.h
index 4c12835..e5ede8a 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -396,8 +396,6 @@
     typedef a          *P##a,       *LP##a
 #endif /*STRICT*/
 
-
-#include "pshpack1.h"
 /* Defines */
 
 /* Argument 1 passed to the DllEntryProc. */
@@ -576,6 +574,8 @@
     DWORD   Cr0NpxState;
 } FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
 
+#define MAXIMUM_SUPPORTED_EXTENSION     512
+
 typedef struct _CONTEXT86
 {
     DWORD   ContextFlags;
@@ -612,6 +612,8 @@
     DWORD   EFlags;
     DWORD   Esp;
     DWORD   SegSs;
+
+    BYTE    ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
 } CONTEXT86;
 
 #define CONTEXT_X86       0x00010000
@@ -2299,8 +2301,6 @@
   PEXCEPTION_HANDLER       Handler;
 } EXCEPTION_FRAME, *PEXCEPTION_FRAME;
 
-#include "poppack.h"
-
 /*
  * function pointer to a exception filter
  */
@@ -2923,11 +2923,13 @@
     WORD    Reserved;
 } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
 
+#include "pshpack2.h"
+
 typedef struct _IMAGE_BASE_RELOCATION
 {
 	DWORD	VirtualAddress;
 	DWORD	SizeOfBlock;
-	WORD	TypeOffset[1];
+	/* WORD	TypeOffset[1]; */
 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
 
 typedef struct _IMAGE_RELOCATION
@@ -2941,6 +2943,8 @@
 } IMAGE_RELOCATION;
 typedef IMAGE_RELOCATION *PIMAGE_RELOCATION;
 
+#include "poppack.h"
+
 #define IMAGE_SIZEOF_RELOCATION 10
 
 /* generic relocation types */
@@ -3389,7 +3393,6 @@
 #ifndef _SECURITY_DEFINED
 #define _SECURITY_DEFINED
 
-#include "pshpack1.h"
 
 typedef DWORD ACCESS_MASK, *PACCESS_MASK;
 
@@ -3481,12 +3484,8 @@
 
 #define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR)) 
 
-#include "poppack.h"
-
 #endif /* _SECURITY_DEFINED */
 
-#include "pshpack1.h"
-
 /* 
  * SID_AND_ATTRIBUTES
  */
@@ -3596,10 +3595,12 @@
     LONG HighPart;
 } LUID, *PLUID;
 
+#include "pshpack4.h"
 typedef struct _LUID_AND_ATTRIBUTES {
   LUID   Luid;
   DWORD  Attributes;
 } LUID_AND_ATTRIBUTES;
+#include "poppack.h"
 
 /*
  * PRIVILEGE_SET
@@ -3685,7 +3686,7 @@
   DWORD				Length;
   SECURITY_IMPERSONATION_LEVEL	ImpersonationLevel;
   SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
-  BOOL				EffectiveOnly;
+  BOOLEAN			EffectiveOnly;
 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
 
 /*
@@ -4079,8 +4080,6 @@
 
 #include "guiddef.h"
 
-#include "poppack.h"
-
 typedef struct _RTL_CRITICAL_SECTION_DEBUG 
 {
   WORD   Type;
diff --git a/include/winuser.h b/include/winuser.h
index 1822a53..68434e0 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -9,9 +9,6 @@
 extern "C" {
 #endif
 
-#include "pshpack1.h"
-
-
 /* Define a bunch of callback types */
 
 #if defined(STRICT) || defined(__WINE__)
@@ -1442,14 +1439,14 @@
 
 typedef struct
 {
-    WORD    mkSize;
+    DWORD   mkSize;
     CHAR    mkKeyList;
     CHAR    szKeyphrase[1];
 } MULTIKEYHELPA, *PMULTIKEYHELPA, *LPMULTIKEYHELPA;
 
 typedef struct
 {
-    WORD    mkSize;
+    DWORD   mkSize;
     WCHAR   mkKeyList;
     WCHAR   szKeyphrase[1];
 } MULTIKEYHELPW, *PMULTIKEYHELPW, *LPMULTIKEYHELPW;
@@ -1459,22 +1456,22 @@
 DECL_WINELIB_TYPE_AW(LPMULTIKEYHELP)
 
 typedef struct {
-	WORD wStructSize;
-	WORD x;
-	WORD y;
-	WORD dx;
-	WORD dy;
-	WORD wMax;
+	int wStructSize;
+	int x;
+	int y;
+	int dx;
+	int dy;
+	int wMax;
 	CHAR rgchMember[2];
 } HELPWININFOA, *PHELPWININFOA, *LPHELPWININFOA;
 
 typedef struct {
-	WORD wStructSize;
-	WORD x;
-	WORD y;
-	WORD dx;
-	WORD dy;
-	WORD wMax;
+	int wStructSize;
+	int x;
+	int y;
+	int dx;
+	int dy;
+	int wMax;
 	WCHAR rgchMember[2];
 } HELPWININFOW, *PHELPWININFOW, *LPHELPWININFOW;
 
@@ -2138,6 +2135,8 @@
 
 typedef BOOL  CALLBACK (*MONITORENUMPROC)(HMONITOR,HDC,LPRECT,LPARAM);
 
+#include "pshpack2.h"
+
 /* FIXME: use this instead of LPCVOID for CreateDialogIndirectParam
    and DialogBoxIndirectParam */
 typedef struct tagDLGTEMPLATE
@@ -2176,6 +2175,7 @@
 typedef DLGITEMTEMPLATE *LPDLGITEMTEMPLATEW;
 DECL_WINELIB_TYPE_AW(LPDLGITEMTEMPLATE)
 
+#include "poppack.h"
 
   /* CBT hook values */
 #define HCBT_MOVESIZE	    0
@@ -3272,8 +3272,6 @@
 
 #define DEVICE_NOTIFY_WINDOW_HANDLE     0x00000000
 
-
-#include "poppack.h"
 #define     EnumTaskWindows(handle,proc,lparam) \
             EnumThreadWindows(handle,proc,lparam)
 #define     OemToAnsiA OemToCharA
diff --git a/loader/pe_image.c b/loader/pe_image.c
index cafea32..52629b7 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -405,7 +405,8 @@
           rel = (IMAGE_BASE_RELOCATION*)((char*)rel + rel->SizeOfBlock))
     {
         char *page = base + rel->VirtualAddress;
-        int i, count = (rel->SizeOfBlock - 8) / sizeof(rel->TypeOffset);
+        WORD *TypeOffset = (WORD *)(rel + 1);
+        int i, count = (rel->SizeOfBlock - sizeof(*rel)) / sizeof(*TypeOffset);
 
         if (!count) continue;
 
@@ -424,8 +425,8 @@
         /* patching in reverse order */
         for (i = 0 ; i < count; i++)
         {
-            int offset = rel->TypeOffset[i] & 0xFFF;
-            int type = rel->TypeOffset[i] >> 12;
+            int offset = TypeOffset[i] & 0xFFF;
+            int type = TypeOffset[i] >> 12;
             switch(type)
             {
             case IMAGE_REL_BASED_ABSOLUTE:
diff --git a/memory/registry.c b/memory/registry.c
index dc2ef37..1470254 100644
--- a/memory/registry.c
+++ b/memory/registry.c
@@ -158,7 +158,7 @@
                                              info->ClassLength / sizeof(WCHAR),
                                              NULL, 0, NULL, NULL );
 
-        if (ft) *ft = info->LastWriteTime;
+        if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
 
         if (len >= *name_len || (class_len && (cls_len >= *class_len)))
             status = STATUS_BUFFER_OVERFLOW;
@@ -259,7 +259,7 @@
         if (values) *values = info->Values;
         if (max_value) *max_value = info->MaxValueNameLen;
         if (max_data) *max_data = info->MaxValueDataLen;
-        if (modif) *modif = info->LastWriteTime;
+        if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
     }
 
     if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
diff --git a/msdos/vxd.c b/msdos/vxd.c
index f8640ae..8f5f8b3 100644
--- a/msdos/vxd.c
+++ b/msdos/vxd.c
@@ -788,15 +788,16 @@
             while (r && r->VirtualAddress)
             {
                 LPBYTE page  = module->baseAddr + r->VirtualAddress;
-                int    count = (r->SizeOfBlock - 8) / 2;
+                WORD *TypeOffset = (WORD *)(r + 1);
+                int count = (r->SizeOfBlock - sizeof(*r)) / sizeof(*TypeOffset);
 
                 TRACE("MapModule: %d relocations for page %08lx\n", 
                            count, (DWORD)page);
 
                 for(i = 0; i < count; i++)
                 {
-                    int offset = r->TypeOffset[i] & 0xFFF;
-                    int type   = r->TypeOffset[i] >> 12;
+                    int offset = TypeOffset[i] & 0xFFF;
+                    int type   = TypeOffset[i] >> 12;
                     switch(type)
                     {
                     case IMAGE_REL_BASED_ABSOLUTE: