diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c
index c972e9868344f1433087d05dc607add5c8d4e6df..c1c3cbb54213543b61c3ed3b95465c68da33fc5a 100644
--- a/dlls/comctl32/comctl32undoc.c
+++ b/dlls/comctl32/comctl32undoc.c
@@ -20,11 +20,14 @@
 #include <stdlib.h> /* atoi */
 #include <ctype.h>
 
+#include "commctrl.h"
+#include "objbase.h"
 #include "winbase.h"
 #include "winerror.h"
+
 #include "wine/unicode.h"
-#include "objbase.h"
-#include "commctrl.h"
+#include "comctl32.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(commctrl);
diff --git a/dlls/ddraw/dclipper/main.c b/dlls/ddraw/dclipper/main.c
index 1102a70bbf68ad1d8d989f7d926cc3202ddddb85..b7fc60f4f045ef441f482d1ddd8ffb506798d209 100644
--- a/dlls/ddraw/dclipper/main.c
+++ b/dlls/ddraw/dclipper/main.c
@@ -8,12 +8,16 @@
 
 #include <stdlib.h>
 #include <string.h>
+
+#include "ddraw.h"
 #include "winerror.h"
-#include "debugtools.h"
+
 #include "ddraw_private.h"
 #include "dclipper/main.h"
 #include "ddraw/main.h"
 
+#include "debugtools.h"
+
 DEFAULT_DEBUG_CHANNEL(ddraw);
 
 /******************************************************************************
diff --git a/dlls/ddraw/direct3d/mesa.c b/dlls/ddraw/direct3d/mesa.c
index 71efa267b9283d15cbdf81b0b87f892ea597055e..ea4d5b9d5fb89b2ce0594d00ffc45f8bfb88ec22 100644
--- a/dlls/ddraw/direct3d/mesa.c
+++ b/dlls/ddraw/direct3d/mesa.c
@@ -6,13 +6,15 @@
 #include <string.h>
 #include <stdio.h>
 
-#include "winerror.h"
-#include "ddraw.h"
 #include "d3d.h"
-#include "options.h"
-#include "debugtools.h"
+#include "ddraw.h"
+#include "winerror.h"
 
+#include "ddraw_private.h"
 #include "mesa_private.h"
+#include "options.h"
+
+#include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(ddraw);
 
diff --git a/dlls/ddraw/dsurface/wndproc.c b/dlls/ddraw/dsurface/wndproc.c
index def18798aa207f6916e879aa6f0b35f85a378e2a..3c12f72dca4d06ca3ed7f55e309dd873bd0671c5 100644
--- a/dlls/ddraw/dsurface/wndproc.c
+++ b/dlls/ddraw/dsurface/wndproc.c
@@ -4,14 +4,17 @@
  */
 
 #include "config.h"
-#include "winerror.h"
 
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "debugtools.h"
+#include "winerror.h"
+
 #include "ddraw_private.h"
+#include "wndproc.h"
+
+#include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(ddraw);
 
diff --git a/dlls/ddraw/helper.c b/dlls/ddraw/helper.c
index 52f984b9802a51a4be7e531301a100a7d56aa170..8d29f1575ea9e94211e1454535e7a21ad90de8be 100644
--- a/dlls/ddraw/helper.c
+++ b/dlls/ddraw/helper.c
@@ -10,14 +10,17 @@
 
 #include <stddef.h>
 
+#include "d3d.h"
+#include "ddraw.h"
 #include "winerror.h"
-#include "heap.h"
+
 #include "wine/exception.h"
-#include "ddraw.h"
-#include "d3d.h"
-#include "debugtools.h"
+#include "ddraw_private.h"
+#include "heap.h"
 #include "options.h"
 
+#include "debugtools.h"
+
 DEFAULT_DEBUG_CHANNEL(ddraw);
 
 /******************************************************************************
@@ -217,9 +220,7 @@ void DDRAW_dump_paletteformat(DWORD dwFlags)
     DDRAW_dump_flags(dwFlags, flags, sizeof(flags)/sizeof(flags[0]));
 }
 
-void DDRAW_dump_pixelformat(void *in) {
-    LPDDPIXELFORMAT pf = (LPDDPIXELFORMAT) in;
-
+void DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf) {
     DPRINTF("( ");
     DDRAW_dump_pixelformat_flag(pf->dwFlags);
     if (pf->dwFlags & DDPF_FOURCC) {
@@ -282,9 +283,7 @@ static void DDRAW_dump_DWORD(const void *in) {
 static void DDRAW_dump_PTR(const void *in) {
     DPRINTF("%p", *((const void **) in));
 }
-void DDRAW_dump_DDCOLORKEY(const void *in) {
-    const DDCOLORKEY *ddck = (const DDCOLORKEY *) in;
-
+void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck) {
     DPRINTF(" Low : %ld  - High : %ld", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
 }
 
diff --git a/dlls/kernel/comm.c b/dlls/kernel/comm.c
index 4188f7364ed228da4a90a734728e5399ce67a3b6..8415c82944408be381685d654bd597a686960214 100644
--- a/dlls/kernel/comm.c
+++ b/dlls/kernel/comm.c
@@ -51,14 +51,17 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <sys/poll.h>
-
-#include "windef.h"
 #ifdef HAVE_SYS_MODEM_H
 # include <sys/modem.h>
 #endif
 #ifdef HAVE_SYS_STRTIO_H
 # include <sys/strtio.h>
 #endif
+
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winuser.h"
 #include "heap.h"
 #include "options.h"
 #include "wine/port.h"
diff --git a/dlls/kernel/kernel_main.c b/dlls/kernel/kernel_main.c
index 1b585cbf4dd0787a4b8e10685d5de480a77bd714..382f185540e5c8d410dbbc10abfa4b00a9851832 100644
--- a/dlls/kernel/kernel_main.c
+++ b/dlls/kernel/kernel_main.c
@@ -2,17 +2,20 @@
  * Kernel initialization code
  */
 
+#include "config.h"
+
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
 
 #include "winbase.h"
-#include "wine/winbase16.h"
 
+#include "wine/winbase16.h"
+#include "callback.h"
+#include "global.h"
+#include "miscemu.h"
 #include "module.h"
 #include "task.h"
-#include "miscemu.h"
-#include "global.h"
 
 extern void CODEPAGE_Init(void);
 extern BOOL RELAY_Init(void);
diff --git a/dlls/msacm/pcmconverter.c b/dlls/msacm/pcmconverter.c
index 14f99de7b54889d6d74b5c95c92fdc056f937233..f895a84afc8d470458608fd44a19a68ecf386767 100644
--- a/dlls/msacm/pcmconverter.c
+++ b/dlls/msacm/pcmconverter.c
@@ -15,14 +15,20 @@
  *	  embedded driver handling scheme in msacm32.dll which isn't done yet
  */
 
+#include "config.h"
+
 #include <assert.h>
 #include <string.h>
-#include "winnls.h"
+
+#include "msacm.h"
 #include "winbase.h"
 #include "wingdi.h"
+#include "winnls.h"
 #include "winuser.h"
-#include "msacm.h"
+
 #include "msacmdrv.h"
+#include "wineacm.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(msacm);
diff --git a/dlls/msvcrt/errno.c b/dlls/msvcrt/errno.c
index 971c9e0f7779cba2bf3677f809cb267ffc9d7733..48e54608776ae222cc68673a51c3204aed4932f5 100644
--- a/dlls/msvcrt/errno.c
+++ b/dlls/msvcrt/errno.c
@@ -9,7 +9,10 @@
 
 #include <stdio.h>
 #include <string.h>
+
 #include "msvcrt/conio.h"
+#include "msvcrt/stdlib.h"
+#include "msvcrt/string.h"
 
 
 DEFAULT_DEBUG_CHANNEL(msvcrt);
@@ -19,7 +22,7 @@ DEFAULT_DEBUG_CHANNEL(msvcrt);
 void MSVCRT__set_errno(int err)
 {
   int *errno = GET_THREAD_VAR_PTR(errno);
-  int *doserrno = GET_THREAD_VAR_PTR(doserrno);
+  unsigned long *doserrno = GET_THREAD_VAR_PTR(doserrno);
 
   *doserrno = err;
 
@@ -86,7 +89,7 @@ int* MSVCRT__errno(void)
 /*********************************************************************
  *		__doserrno (MSVCRT.@)
  */
-int* __doserrno(void)
+unsigned long* __doserrno(void)
 {
   return GET_THREAD_VAR_PTR(doserrno);
 }
@@ -102,7 +105,7 @@ char* MSVCRT_strerror(int err)
 /**********************************************************************
  *		_strerror	(MSVCRT.@)
  */
-const char* _strerror(const char* err)
+char* _strerror(const char* err)
 {
   static char strerrbuff[256]; /* FIXME: Per thread, nprintf */
   sprintf(strerrbuff,"%s: %s\n",err,MSVCRT_strerror(GET_THREAD_VAR(errno)));
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index e6a7a934f2b0acda9debd089db058dc32cb577bf..7b930422e76261e116122490d16569b00692abae 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -8,8 +8,10 @@
  * Not currently binary compatible with win32. MSVCRT_mbctype must be
  * populated correctly and the ismb* functions should reference it.
  */
+
 #include "msvcrt.h"
 
+#include "msvcrt/stdlib.h"
 #include "msvcrt/string.h"
 
 
@@ -184,7 +186,7 @@ char *_mbsrchr(const char *s,unsigned int x)
 /*********************************************************************
  *		mbtowc(MSVCRT.@)
  */
-int MSVCRT_mbtowc(WCHAR *dst, const unsigned char *str, unsigned int n)
+int MSVCRT_mbtowc(WCHAR *dst, const char *str, unsigned int n)
 {
   if(n <= 0 || !str)
     return 0;
@@ -385,7 +387,7 @@ char *_mbsnset(char *str, unsigned int c, unsigned int len)
 /*********************************************************************
  *		_mbstrlen(MSVCRT.@)
  */
-int _mbstrlen(const unsigned char *str)
+MSVCRT_size_t _mbstrlen(const char *str)
 {
   if(MSVCRT___mb_cur_max > 1)
   {
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index b4368da99dfd4f67699b905650db3c93f15d7d6b..a079ac2496ecbaac59ce6665d0385cf4e52f1484 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -17,7 +17,7 @@ extern DWORD MSVCRT_tls_index;
 typedef struct __MSVCRT_thread_data
 {
   int errno;
-  int doserrno;
+  unsigned long doserrno;
 } MSVCRT_thread_data;
 
 #define GET_THREAD_DATA(x) \
diff --git a/dlls/user/lstr.c b/dlls/user/lstr.c
index 48c73564c9fccfe0f4c31712b8f429270664baf4..cc8b2a13b46e62184557b49b5f17742ce0315933 100644
--- a/dlls/user/lstr.c
+++ b/dlls/user/lstr.c
@@ -6,22 +6,24 @@
  * Copyright 1996 Marcus Meissner
  */
 
+#include "config.h"
+
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-#include "windef.h"
 #include "winbase.h"
-#include "winnls.h"
 #include "winerror.h"
+
+#include "wine/exception.h"
+#include "wine/keyboard16.h"
+#include "wine/unicode.h"
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
-#include "wine/unicode.h"
-#include "wine/exception.h"
-
 #include "heap.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(resource);
diff --git a/dlls/user/wsprintf.c b/dlls/user/wsprintf.c
index 5c07af1d0f09222ed506d0fbdd4d905fad887a62..1911e0cf0ee4b42fd49432f55ec12f3068d1431a 100644
--- a/dlls/user/wsprintf.c
+++ b/dlls/user/wsprintf.c
@@ -7,11 +7,15 @@
 #include <stdarg.h>
 #include <string.h>
 #include <stdio.h>
-#include "wine/winbase16.h"
-#include "windef.h"
+
+#include "winbase.h"
 #include "wingdi.h"
 #include "winuser.h"
+
+#include "wine/winbase16.h"
+#include "wine/winuser16.h"
 #include "stackframe.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(string);
diff --git a/dlls/version/resource.c b/dlls/version/resource.c
index b533c7f0f659cf142d17af8a1ed91a9ef01e32ca..126ad29bef4eecb13fd150b4c5cab294011c1782 100644
--- a/dlls/version/resource.c
+++ b/dlls/version/resource.c
@@ -6,20 +6,21 @@
  * Copyright 1999 Ulrich Weigand
  */
 
+#include "config.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "config.h"
-
 #include "winbase.h"
-#include "wine/winbase16.h"
-#include "winnls.h"
-#include "wine/unicode.h"
+#include "lzexpand.h"
 
+#include "wine/unicode.h"
+#include "wine/winbase16.h"
+#include "wine/winuser16.h"
 #include "winver.h"
-#include "lzexpand.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(ver);
diff --git a/dlls/winmm/joystick.c b/dlls/winmm/joystick.c
index 667398f474dacc898a36b1e0d42e54419de6e3fa..0e9b8a97ca07165baa5a51f62e968a2bc50112df 100644
--- a/dlls/winmm/joystick.c
+++ b/dlls/winmm/joystick.c
@@ -15,11 +15,16 @@
 #include <string.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+
+#include "mmsystem.h"
 #include "winbase.h"
 #include "winnls.h"
 #include "wingdi.h"
 #include "winuser.h"
+
+#include "wine/mmsystem16.h"
 #include "winemm.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(mmsys);
diff --git a/dlls/winmm/mci.c b/dlls/winmm/mci.c
index f3aca250a459bf74a3ba12add1253e86b93a9cfb..64c409db77ff55b32580cc57bf6611973d31542a 100644
--- a/dlls/winmm/mci.c
+++ b/dlls/winmm/mci.c
@@ -10,15 +10,19 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "mmsystem.h"
 #include "winbase.h"
 #include "wingdi.h"
+#include "winreg.h"
 #include "winuser.h"
+
+#include "wine/mmsystem16.h"
+#include "wine/winbase16.h"
+#include "digitalv.h"
 #include "heap.h"
 #include "winemm.h"
-#include "digitalv.h"
-#include "wine/winbase16.h"
+
 #include "debugtools.h" 
-#include "winreg.h"
 
 DEFAULT_DEBUG_CHANNEL(mci);
 
diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c
index 53ad279034daac37dbbf8d4c63aebdc0cc36f393..af60b3ad1f08429bef354b833a78d99f02cef4a9 100644
--- a/dlls/winmm/mmio.c
+++ b/dlls/winmm/mmio.c
@@ -22,13 +22,17 @@
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
+
+#include "mmsystem.h"
 #include "windef.h"
+
+#include "wine/mmsystem16.h"
 #include "wine/winbase16.h"
 #include "heap.h"
-#include "mmsystem.h"
-#include "debugtools.h"
 #include "winemm.h"
 
+#include "debugtools.h"
+
 DEFAULT_DEBUG_CHANNEL(mmio);
 
 /**************************************************************************
diff --git a/dlls/winmm/mmsystem.c b/dlls/winmm/mmsystem.c
index 88fb28b5f839240bb6c4371c999aa2aa3a470483..5f6a3452fbe2f985cc215026b252cb1e2bce28d6 100644
--- a/dlls/winmm/mmsystem.c
+++ b/dlls/winmm/mmsystem.c
@@ -20,13 +20,17 @@
 
 #include <string.h>
 
+#include "mmsystem.h"
 #include "winbase.h"
 #include "wingdi.h"
+
+#include "wine/mmsystem16.h"
 #include "wine/winuser16.h"
 #include "heap.h"
+#include "ntddk.h"
 #include "winemm.h"
+
 #include "debugtools.h"
-#include "ntddk.h"
 
 DEFAULT_DEBUG_CHANNEL(mmsys);
 
diff --git a/dlls/winmm/time.c b/dlls/winmm/time.c
index 40c3fe52e57a650adb283d5afae1fcb913444a67..0f2a3c37aaa80715ad15f57c952bcf656d453ce7 100644
--- a/dlls/winmm/time.c
+++ b/dlls/winmm/time.c
@@ -6,17 +6,23 @@
  * Copyright 1993 Martin Ayotte
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <time.h>
 #include <sys/time.h>
 #include <unistd.h>
 
+#include "mmsystem.h"
 #include "windef.h"
 #include "winbase.h"
 #include "wingdi.h"
 #include "winuser.h"
+
+#include "wine/mmsystem16.h"
 #include "winemm.h"
+
 #include "debugtools.h"
-#include "wine/port.h"
 
 DEFAULT_DEBUG_CHANNEL(mmtime);
 
diff --git a/files/dos_fs.c b/files/dos_fs.c
index 655e5008415b3e61a6951b101a2909289821d2f7..ee449fdf1806b9b5d6d1ae41ded74a4f2e77a6cc 100644
--- a/files/dos_fs.c
+++ b/files/dos_fs.c
@@ -6,6 +6,7 @@
  */
 
 #include "config.h"
+
 #include <sys/types.h>
 #include <ctype.h>
 #include <dirent.h>
@@ -22,17 +23,19 @@
 #include <unistd.h>
 
 #include "windef.h"
-#include "ntddk.h"
-#include "winnls.h"
-#include "wine/winbase16.h"
-#include "wine/unicode.h"
 #include "winerror.h"
+#include "wingdi.h"
+
+#include "wine/unicode.h"
+#include "wine/winbase16.h"
 #include "drive.h"
 #include "file.h"
 #include "heap.h"
 #include "msdos.h"
-#include "server.h"
+#include "ntddk.h"
 #include "options.h"
+#include "server.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(dosfs);
diff --git a/graphics/win16drv/objects.c b/graphics/win16drv/objects.c
index fde57999177acf6703f14c41f38f4e015ec254ba..824cd4513820787db0a29340768600c446dc1f3e 100644
--- a/graphics/win16drv/objects.c
+++ b/graphics/win16drv/objects.c
@@ -4,12 +4,17 @@
  * Copyright 1993 Alexandre Julliard
  */
 
+#include "config.h"
+
 #include <stdlib.h>
 #include <stdio.h>
+
 #include "bitmap.h"
 #include "brush.h"
 #include "font.h"
 #include "pen.h"
+#include "win16drv.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(gdi);
diff --git a/graphics/x11drv/objects.c b/graphics/x11drv/objects.c
index e91f6b69387d4f75b27c659d61312507bb4a5baf..839647d0776b594834e8e7b69999138f2e74ad3f 100644
--- a/graphics/x11drv/objects.c
+++ b/graphics/x11drv/objects.c
@@ -13,6 +13,8 @@
 #include "brush.h"
 #include "font.h"
 #include "pen.h"
+#include "x11drv.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(gdi);
diff --git a/include/msvcrt/string.h b/include/msvcrt/string.h
index c9c22ae564285390c6698bb11af4e3d9212b0fcd..d803cced2125f8cfac43bce6ccca9d265fe5c622 100644
--- a/include/msvcrt/string.h
+++ b/include/msvcrt/string.h
@@ -34,7 +34,7 @@ void*       _memccpy(void*,const void*,int,MSVCRT(size_t));
 int         _memicmp(const void*,const void*,MSVCRT(size_t));
 int         _strcmpi(const char*,const char*);
 char*       _strdup(const char*);
-char*       _strerror(int);
+char*       _strerror(const char*);
 int         _stricmp(const char*,const char*);
 int         _stricoll(const char*,const char*);
 char*       _strlwr(char*);
diff --git a/include/wine/winuser16.h b/include/wine/winuser16.h
index c48697568e295f13b490380ed254cdc23da0c3f3..2829c1caebe0e962ed6433a598c38ce720ebfd17 100644
--- a/include/wine/winuser16.h
+++ b/include/wine/winuser16.h
@@ -567,7 +567,6 @@ FARPROC16   WINAPI SetWindowsHook16(INT16,HOOKPROC16);
 HHOOK       WINAPI SetWindowsHookEx16(INT16,HOOKPROC16,HINSTANCE16,HTASK16);
 BOOL16      WINAPI UnhookWindowsHook16(INT16,HOOKPROC16);
 BOOL16      WINAPI UnhookWindowsHookEx16(HHOOK);
-INT16       WINAPI wvsnprintf16(LPSTR,UINT16,LPCSTR,LPCVOID);
 VOID        WINAPI CalcChildScroll16(HWND16,WORD);
 VOID        WINAPI CascadeChildWindows16(HWND16,WORD);
 INT16       WINAPI CloseComm16(INT16);
diff --git a/include/winuser.h b/include/winuser.h
index 1261967f140207a186d64424f155344bd749fea0..9675580329daa167a7764338dedb38fb710d7408 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -3735,11 +3735,12 @@ UINT      WINAPI MapVirtualKeyW(UINT,UINT);
 UINT        WINAPI MapVirtualKeyExA(UINT,UINT,HKL);
 UINT        WINAPI MapVirtualKeyExW(UINT,UINT,HKL);
 #define     MapVirtualKeyEx WINELIB_NAME_AW(MapVirtualKeyEx)
-BOOL      WINAPI MapDialogRect(HWND,LPRECT);
-INT       WINAPI MapWindowPoints(HWND,HWND,LPPOINT,UINT);
-BOOL      WINAPI MessageBeep(UINT);
-INT       WINAPI MessageBoxA(HWND,LPCSTR,LPCSTR,UINT);
-INT       WINAPI MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT);
+BOOL        WINAPI MapDialogRect(HWND,LPRECT);
+INT         WINAPI MapWindowPoints(HWND,HWND,LPPOINT,UINT);
+UINT        WINAPI MenuItemFromPoint(HWND,HMENU,POINT);
+BOOL        WINAPI MessageBeep(UINT);
+INT         WINAPI MessageBoxA(HWND,LPCSTR,LPCSTR,UINT);
+INT         WINAPI MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT);
 #define     MessageBox WINELIB_NAME_AW(MessageBox)
 INT       WINAPI MessageBoxIndirectA(LPMSGBOXPARAMSA);
 INT       WINAPI MessageBoxIndirectW(LPMSGBOXPARAMSW);
diff --git a/loader/task.c b/loader/task.c
index 200b9b98a90d917504a92f03163e0147e78a84fe..5b3819fddb5207eb1c90f04818c92e0f6467f105 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -4,14 +4,21 @@
  * Copyright 1995 Alexandre Julliard
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <unistd.h>
 
-#include "wine/port.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winnt.h"
+#include "winuser.h"
+#include "winsock.h"
+
 #include "wine/winbase16.h"
-#include "ntddk.h"
 #include "callback.h"
 #include "drive.h"
 #include "file.h"
@@ -19,18 +26,17 @@
 #include "instance.h"
 #include "miscemu.h"
 #include "module.h"
+#include "ntddk.h"
 #include "selectors.h"
+#include "services.h"
+#include "server.h"
+#include "syslevel.h"
 #include "stackframe.h"
 #include "task.h"
 #include "thread.h"
 #include "toolhelp.h"
-#include "winnt.h"
-#include "syslevel.h"
-#include "winsock.h"
-#include "debugtools.h"
-#include "services.h"
-#include "server.h"
 
+#include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(task);
 DECLARE_DEBUG_CHANNEL(relay);
diff --git a/memory/environ.c b/memory/environ.c
index 6f479069af2c43b0cc82720f91ef53dd46da4185..2bf27850cba919e115f453a71562ad5377c5bd09 100644
--- a/memory/environ.c
+++ b/memory/environ.c
@@ -4,14 +4,18 @@
  * Copyright 1996, 1998 Alexandre Julliard
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <stdlib.h>
 #include <string.h>
-#include "wine/port.h"
+
 #include "windef.h"
-#include "winnls.h"
 #include "winerror.h"
-#include "ntddk.h"
+
+#include "wine/winbase16.h"
 #include "heap.h"
+#include "ntddk.h"
 #include "selectors.h"
 
 /* Win32 process environment database */
diff --git a/misc/registry.c b/misc/registry.c
index f39da22f98c90ace44399d391a8ab1aeb538e249..05ca70261dfc61a5205508166878f3ecf3f00de2 100644
--- a/misc/registry.c
+++ b/misc/registry.c
@@ -29,18 +29,21 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_MMAN_H
+# include <sys/mman.h>
+#endif
+
 #include "winerror.h"
+#include "winnt.h"
+#include "winreg.h"
+
+#include "wine/winbase16.h"
 #include "file.h"
 #include "heap.h"
-#include "debugtools.h"
 #include "options.h"
-#include "winreg.h"
 #include "server.h"
-#ifdef HAVE_SYS_MMAN_H
-# include <sys/mman.h>
-#endif
-#include "winnt.h"
 
+#include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(reg);
 
diff --git a/msdos/dosconf.c b/msdos/dosconf.c
index 0e7ee449f69027bf9804d841df2f2502b3657eae..1f6c18b09662658e7c4d9155e0940fbc02753212 100644
--- a/msdos/dosconf.c
+++ b/msdos/dosconf.c
@@ -5,16 +5,22 @@
  *
  */
 
+#include "config.h"
+
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
+
 #include "winbase.h"
+
+#include "file.h"
+#include "miscemu.h"
 #include "msdos.h"
-#include "debugtools.h"
 #include "options.h"
-#include "file.h"
+
+#include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(profile);
 
diff --git a/msdos/int29.c b/msdos/int29.c
index cf50a0bd1403b50f4b3a72b8c3ef28db70bc7589..8ffaa56c80242c615f503be0c2df0e3d3a38c86b 100644
--- a/msdos/int29.c
+++ b/msdos/int29.c
@@ -3,9 +3,11 @@
  */
 
 #include "config.h"
-#include "windef.h"
+
 #include "winnt.h"
+
 #include "console.h"
+#include "miscemu.h"
 
 /**********************************************************************
  *	    INT_Int29Handler
diff --git a/msdos/ppdev.c b/msdos/ppdev.c
index c8b49fc643808ac7729a32151aec1a08ceba6891..78a102a11c2b32d9c4b87fc0be43d584f134dc4b 100644
--- a/msdos/ppdev.c
+++ b/msdos/ppdev.c
@@ -4,11 +4,7 @@
 
 #include "config.h"
 
-#include "debugtools.h"
-
-DEFAULT_DEBUG_CHANNEL(int);
-
-#ifdef  HAVE_PPDEV
+#ifdef HAVE_PPDEV
 
 #include <stdlib.h>
 #include <sys/types.h>
@@ -21,6 +17,11 @@ DEFAULT_DEBUG_CHANNEL(int);
 #include "winerror.h"
 #include "winreg.h"
 
+#include "miscemu.h"
+
+#include "debugtools.h"
+
+DEFAULT_DEBUG_CHANNEL(int);
 
 typedef struct _PPDEVICESTRUCT{
   int fd; /* NULL if device not available */
@@ -272,6 +273,8 @@ BOOL IO_pp_outp(int port, DWORD* res)
 
 #else /* HAVE_PPDEV */
 
+#include "windef.h"
+
 char IO_pp_init(void)
 {
   return 1;
diff --git a/objects/brush.c b/objects/brush.c
index bc36fd641934a36fda8d69c939ace56927ca2331..cef8f523c86cc4a4d687fe1cb58477fe366aa9af 100644
--- a/objects/brush.c
+++ b/objects/brush.c
@@ -4,10 +4,17 @@
  * Copyright 1993, 1994  Alexandre Julliard
  */
 
+#include "config.h"
+
 #include <string.h>
+
 #include "winbase.h"
-#include "brush.h"
+#include "wingdi.h"
+
+#include "wine/wingdi16.h"
 #include "bitmap.h"
+#include "brush.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(gdi);
diff --git a/objects/metafile.c b/objects/metafile.c
index 8691df8d95dd25c6e27c6ae96613cf881e687e54..ed5d0e32c2123bc29402017c880c31b8119db9f3 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -30,16 +30,20 @@
  * HDMD - 14/4/1999
  */  
 
+#include "config.h"
 
 #include <string.h>
 #include <fcntl.h>
+
 #include "wine/winbase16.h"
-#include "metafile.h"
+#include "wine/wingdi16.h"
 #include "bitmap.h"
+#include "global.h"
 #include "heap.h"
+#include "metafile.h"
 #include "toolhelp.h"
+
 #include "debugtools.h"
-#include "global.h"
 
 DEFAULT_DEBUG_CHANNEL(metafile);
 
diff --git a/objects/pen.c b/objects/pen.c
index e64bc6807591b349552999c6878012255f0572b2..ae55d64a9e4aebee20d13178e6645300965a8fa2 100644
--- a/objects/pen.c
+++ b/objects/pen.c
@@ -4,8 +4,16 @@
  * Copyright 1993 Alexandre Julliard
  */
 
+#include "config.h"
+
 #include <string.h>
+
+#include "windef.h"
+#include "wingdi.h"
+
+#include "wine/wingdi16.h"
 #include "pen.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(gdi);
diff --git a/win32/file.c b/win32/file.c
index 36eb56b5c02f7ff421fbffcd3f8dac561e3bc067..c0a4591e00f3b534889c0432cc96c33fdacb4b69 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -21,10 +21,14 @@
 #include <fcntl.h>
 #include <string.h>
 #include <time.h>
+
 #include "winbase.h"
 #include "winerror.h"
+
+#include "wine/winbase16.h"
 #include "file.h"
 #include "heap.h"
+
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(file);