Release 960811

Sun Aug 11 13:00:20 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [configure.in] [include/acconfig.h] [tools/build.c]
	Added check for underscore on external symbols.

	* [memory/selector.c] [memory/global.c]
	Fixed FreeSelector() to free only one selector.
	Added SELECTOR_FreeBlock() to free an array of selectors.

	* [objects/color.c]
	Fixed a bug in COLOR_ToLogical() that caused GetPixel() to fail on
	hi-color displays.

	* [tools/build.c] [if1632/crtdll.spec]
	Added 'extern' type, used for external variables or functions.

	* [windows/winpos.c]
	Allow de-activating a window in WINPOS_ChangeActiveWindow().

	* [windows/winproc.c]
	Added 32-to-16 translation for button messages.
	Fixed WINPROC_GetPtr() to avoid crashes on 32-bit procedures that
	happen to be valid SEGPTRs.

Sat Aug 10 18:22:25 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [windows/message.c]
	Removed a FIXME in MSG_PeekHardwareMsg(): produces correct 
	data for the JOURNALRECORD-hook (using EVENTMSG16 structure).

	* [if1632/gdi.spec] [include/windows.h] [objects/metafile.c]
	Introduced undocumented API function IsValidMetaFile(), plus a
 	minor fix in last patch of CopyMetaFile().

	* [objects/gdiobj.c]
	Removed a FIXME in IsGDIObject(): added magic word check.

Sun Aug 10 18:10:10 1996  Bruce Milner <Bruce.Milner@genetics.utah.edu>

	* [controls/statuswin.c]
	First pass at implementing the StatusWindow class.

	* [include/commctrl.h]
	Header file for common controls.

	* [controls/widgets.c]
	Added InitCommonControls().

	* [if1632/comctl32.spec]
	Add DrawStatusTextA, CreateStatusWindowA, InitCommonControls.

	* [win32/findfile.c] [if1632/kernel32.spec]
	Add FindNextFile32A, FindClose.
	Modified FindFirstFile32A so it works with FindNextFile32A.

	* [include/winbase.h]
	Fixed WIN32_FIND_DATA structure member names.

Sat Aug 10 09:00:00 1996  Alex Korobka <alex@phm30.pharm.sunysb.edu>

	* [windows/scroll.c]
	Changed scrolling routines to benefit from DCE code update.

Thu Aug  8 18:05:09 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [files/file.c]
	SearchPath* could get NULL for lastpart argument.

	* [if1632/build-spec.txt] [documentation/debugging]
	Varargs documentation added, debugging hints updated.

	* [if1632/crtdll.spec][misc/crtdll.c][misc/Makefile.in]
	Started to implement CRTDLL.

	* [if1632/wsock32.spec]
	Some thunks to standard libc functions (structures have the same
 	elements, but perhaps wrong offset due to packing).

	* [include/kernel32.h][include/windows.h][win32/*.c][loader/main.c]
	Merged kernel32.h into windows.h.

	* [misc/lstr.c]
	Enhanced FormatMessage().

	* [misc/main.c] [if1632/kernel.spec] [include/windows.h]
	GetVersion() updated to new naming standard.
	Changed language handling to support language ids.

	* [misc/shell.c]
	Enhanced FindExecutable, so it finds files in the search path too.

	* [win32/environment.c]
	GetCommandLine* updated.

	* [loader/resource.c] [loader/pe_resource.c]
	FindResourceEx32* added.
	Loading of messagetables added.
	Language handling now uses Wine default language id.
diff --git a/ANNOUNCE b/ANNOUNCE
index 85363a8..95f9f61 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,13 +1,14 @@
-This is release 960805 of Wine, the MS Windows emulator.  This is still a
+This is release 960811 of Wine, the MS Windows emulator.  This is still a
 developer's only release.  There are many bugs and many unimplemented API
 features.  Most applications still do not work correctly.
 
 Patches should be submitted to "julliard@lrc.epfl.ch".  Please don't
 forget to include a ChangeLog entry.
 
-WHAT'S NEW with Wine-960805: (see ChangeLog for details)
-	- More metafile features.
-	- Some more Win32 code.
+WHAT'S NEW with Wine-960811: (see ChangeLog for details)
+	- Status window class.
+	- Some CRTDLL support.
+	- Fixes to scrolling code.
 	- Lots of bug fixes.
 
 See the README file in the distribution for installation instructions.
@@ -16,10 +17,10 @@
 the release is available at the ftp sites.  The sources will be available
 from the following locations:
 
-    sunsite.unc.edu:/pub/Linux/ALPHA/wine/development/Wine-960805.tar.gz
-    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-960805.tar.gz
-    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-960805.tar.gz
-    aris.com:/pub/linux/ALPHA/Wine/development/Wine-960805.tar.gz
+    sunsite.unc.edu:/pub/Linux/ALPHA/wine/development/Wine-960811.tar.gz
+    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-960811.tar.gz
+    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-960811.tar.gz
+    aris.com:/pub/linux/ALPHA/Wine/development/Wine-960811.tar.gz
 
 It should also be available from any site that mirrors tsx-11 or sunsite.
 
diff --git a/ChangeLog b/ChangeLog
index 7ce0a96..447a6ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,104 @@
 ----------------------------------------------------------------------
+Sun Aug 11 13:00:20 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>
+
+	* [configure.in] [include/acconfig.h] [tools/build.c]
+	Added check for underscore on external symbols.
+
+	* [memory/selector.c] [memory/global.c]
+	Fixed FreeSelector() to free only one selector.
+	Added SELECTOR_FreeBlock() to free an array of selectors.
+
+	* [objects/color.c]
+	Fixed a bug in COLOR_ToLogical() that caused GetPixel() to fail on
+	hi-color displays.
+
+	* [tools/build.c] [if1632/crtdll.spec]
+	Added 'extern' type, used for external variables or functions.
+
+	* [windows/winpos.c]
+	Allow de-activating a window in WINPOS_ChangeActiveWindow().
+
+	* [windows/winproc.c]
+	Added 32-to-16 translation for button messages.
+	Fixed WINPROC_GetPtr() to avoid crashes on 32-bit procedures that
+	happen to be valid SEGPTRs.
+
+Sat Aug 10 18:22:25 1996  Albrecht Kleine  <kleine@ak.sax.de>
+
+	* [windows/message.c]
+	Removed a FIXME in MSG_PeekHardwareMsg(): produces correct 
+	data for the JOURNALRECORD-hook (using EVENTMSG16 structure).
+
+	* [if1632/gdi.spec] [include/windows.h] [objects/metafile.c]
+	Introduced undocumented API function IsValidMetaFile(), plus a
+ 	minor fix in last patch of CopyMetaFile().
+
+	* [objects/gdiobj.c]
+	Removed a FIXME in IsGDIObject(): added magic word check.
+
+Sun Aug 10 18:10:10 1996  Bruce Milner <Bruce.Milner@genetics.utah.edu>
+
+	* [controls/statuswin.c]
+	First pass at implementing the StatusWindow class.
+
+	* [include/commctrl.h]
+	Header file for common controls.
+
+	* [controls/widgets.c]
+	Added InitCommonControls().
+
+	* [if1632/comctl32.spec]
+	Add DrawStatusTextA, CreateStatusWindowA, InitCommonControls.
+
+	* [win32/findfile.c] [if1632/kernel32.spec]
+	Add FindNextFile32A, FindClose.
+	Modified FindFirstFile32A so it works with FindNextFile32A.
+
+	* [include/winbase.h]
+	Fixed WIN32_FIND_DATA structure member names.
+
+Sat Aug 10 09:00:00 1996  Alex Korobka <alex@phm30.pharm.sunysb.edu>
+
+	* [windows/scroll.c]
+	Changed scrolling routines to benefit from DCE code update.
+
+Thu Aug  8 18:05:09 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
+
+	* [files/file.c]
+	SearchPath* could get NULL for lastpart argument.
+
+	* [if1632/build-spec.txt] [documentation/debugging]
+	Varargs documentation added, debugging hints updated.
+
+	* [if1632/crtdll.spec][misc/crtdll.c][misc/Makefile.in]
+	Started to implement CRTDLL.
+
+	* [if1632/wsock32.spec]
+	Some thunks to standard libc functions (structures have the same
+ 	elements, but perhaps wrong offset due to packing).
+
+	* [include/kernel32.h][include/windows.h][win32/*.c][loader/main.c]
+	Merged kernel32.h into windows.h.
+
+	* [misc/lstr.c]
+	Enhanced FormatMessage().
+
+	* [misc/main.c] [if1632/kernel.spec] [include/windows.h]
+	GetVersion() updated to new naming standard.
+	Changed language handling to support language ids.
+
+	* [misc/shell.c]
+	Enhanced FindExecutable, so it finds files in the search path too.
+
+	* [win32/environment.c]
+	GetCommandLine* updated.
+
+	* [loader/resource.c] [loader/pe_resource.c]
+	FindResourceEx32* added.
+	Loading of messagetables added.
+	Language handling now uses Wine default language id.
+
+----------------------------------------------------------------------
 Sun Aug  4 18:18:48 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>
 
 	* [controls/scroll.c]
diff --git a/Makefile.in b/Makefile.in
index 89031f3..714e480 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -137,4 +137,10 @@
 	$(RM) config.* Make.rules include/config.h
 	$(RM) `find . \( -name Makefile -o -size 0 \) -print`
 
+configure: configure.in
+	autoconf
+
+include/config.h.in: configure.in include/acconfig.h
+	autoheader -l include
+
 dummy:
diff --git a/configure b/configure
index 49f45df..47cc41d 100755
--- a/configure
+++ b/configure
@@ -1615,6 +1615,48 @@
 fi
 
 
+echo $ac_n "checking "whether external symbols need an underscore prefix"""... $ac_c" 1>&6
+if eval "test \"`echo '$''{'ac_cv_c_extern_prefix'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  saved_libs=$LIBS
+LIBS="conftest_asm.s $LIBS"
+cat > conftest_asm.s <<EOF
+	.globl _ac_test
+_ac_test:
+	.long 0
+EOF
+cat > conftest.$ac_ext <<EOF
+#line 1631 "configure"
+#include "confdefs.h"
+extern int ac_test;
+int main() { return 0; }
+int t() {
+if (ac_test) return 1
+; return 0; }
+EOF
+if { (eval echo configure:1639: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
+  rm -rf conftest*
+  ac_cv_c_extern_prefix="yes"
+else
+  rm -rf conftest*
+  ac_cv_c_extern_prefix="no"
+fi
+rm -f conftest*
+
+LIBS=$saved_libs
+fi
+
+echo "$ac_t""$ac_cv_c_extern_prefix" 1>&6
+if test "$ac_cv_c_extern_prefix" = "yes"
+then
+  cat >> confdefs.h <<\EOF
+#define NEED_UNDERSCORE_PREFIX 1
+EOF
+
+fi
+
+
 for ac_func in memmove tcgetattr usleep
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
@@ -1622,7 +1664,7 @@
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1626 "configure"
+#line 1668 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -1646,7 +1688,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1650: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
+if { (eval echo configure:1692: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -1673,7 +1715,7 @@
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1677 "configure"
+#line 1719 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -1728,7 +1770,7 @@
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1732 "configure"
+#line 1774 "configure"
 #include "confdefs.h"
 
 int main() { return 0; }
@@ -1778,7 +1820,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1782: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1824: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_const=yes
 else
@@ -1802,7 +1844,7 @@
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1806 "configure"
+#line 1848 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdarg.h>
@@ -1810,7 +1852,7 @@
 #include <float.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1814: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1856: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1825,7 +1867,7 @@
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1829 "configure"
+#line 1871 "configure"
 #include "confdefs.h"
 #include <string.h>
 EOF
@@ -1843,7 +1885,7 @@
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1847 "configure"
+#line 1889 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 EOF
@@ -1864,7 +1906,7 @@
   :
 else
 cat > conftest.$ac_ext <<EOF
-#line 1868 "configure"
+#line 1910 "configure"
 #include "confdefs.h"
 #include <ctype.h>
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
@@ -1875,7 +1917,7 @@
 exit (0); }
 
 EOF
-{ (eval echo configure:1879: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
+{ (eval echo configure:1921: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
 if test -s conftest && (./conftest; exit) 2>/dev/null; then
   :
 else
@@ -1899,7 +1941,7 @@
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1903 "configure"
+#line 1945 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
diff --git a/configure.in b/configure.in
index 97f991e..d305a3b 100644
--- a/configure.in
+++ b/configure.in
@@ -66,6 +66,25 @@
   fi
 fi
 
+dnl **** Check for underscore on external symbols ****
+
+AC_CACHE_CHECK("whether external symbols need an underscore prefix",
+               ac_cv_c_extern_prefix,
+[saved_libs=$LIBS
+LIBS="conftest_asm.s $LIBS"
+cat > conftest_asm.s <<EOF
+	.globl _ac_test
+_ac_test:
+	.long 0
+EOF
+AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1],
+            ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no")
+LIBS=$saved_libs])
+if test "$ac_cv_c_extern_prefix" = "yes"
+then
+  AC_DEFINE(NEED_UNDERSCORE_PREFIX)
+fi
+
 dnl **** Check for functions and header files ****
 
 AC_CHECK_FUNCS(memmove tcgetattr usleep)
diff --git a/controls/Makefile.in b/controls/Makefile.in
index 6dde058..0b99780 100644
--- a/controls/Makefile.in
+++ b/controls/Makefile.in
@@ -11,6 +11,7 @@
 	menu.c \
 	scroll.c \
 	static.c \
+	status.c \
 	widgets.c
 
 all: $(MODULE).o
diff --git a/controls/combo.c b/controls/combo.c
index d7563a9..213a3e3 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -163,7 +163,7 @@
      lphc->RectButton.bottom = lphc->RectButton.top + lphl->StdItemHeight;
      SetWindowPos(hwnd, 0, 0, 0, rect.right -rect.left + 2*SYSMETRICS_CXBORDER,
 		 lphl->StdItemHeight + 2*SYSMETRICS_CYBORDER,
-		 SWP_NOMOVE | SWP_NOZORDER | SWP_NOSENDCHANGING);
+		 SWP_NOMOVE | SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOACTIVATE);
      dprintf_combo(stddeb,(cstyle & 3)==CBS_DROPDOWN ? "CBS_DROPDOWN\n": "CBS_DROPDOWNLIST\n");
      break;
      
@@ -615,7 +615,8 @@
     lphc->DropDownVisible = wParam;
     GetWindowRect32(hwnd,&rect);
     SetWindowPos(lphc->hWndLBox, 0, rect.left, rect.top+lphc->LBoxTop, 0, 0,
-		 SWP_NOSIZE | (wParam ? SWP_SHOWWINDOW : SWP_HIDEWINDOW));
+		 SWP_NOSIZE | SWP_NOACTIVATE |
+                 (wParam ? SWP_SHOWWINDOW : SWP_HIDEWINDOW));
     if (!wParam) SetFocus(hwnd);
   }
   return 0;
@@ -1005,7 +1006,7 @@
   int        y;
   RECT16     rectsel;
 
-  SetFocus(hwnd);
+/*  SetFocus(hwnd); */
   SetCapture(hwnd);
 
   lphl->PrevFocused = lphl->ItemFocused;
@@ -1213,6 +1214,8 @@
      case WM_MOUSEMOVE: return CBLMouseMove(hwnd, wParam, lParam);
      case WM_VSCROLL: return CBLVScroll(hwnd, wParam, lParam);
      case WM_SIZE: return CBLCheckSize(hwnd);
+     case WM_MOUSEACTIVATE:  /* We don't want to be activated */
+	return MA_NOACTIVATE;
     }
     return DefWindowProc16(hwnd, message, wParam, lParam);
 }
diff --git a/controls/edit.c b/controls/edit.c
index c646fb6..69507b9 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -2177,7 +2177,7 @@
 {
 	UINT s = LOWORD(EDIT_EM_GetSel(wndPtr, 0, 0L));
 	UINT e = HIWORD(EDIT_EM_GetSel(wndPtr, 0, 0L));
-	HGLOBAL hdst;
+	HGLOBAL16 hdst;
 	char *text;
 	char *dst;
 	char *src;
@@ -2717,7 +2717,7 @@
  */
 static LRESULT EDIT_WM_Paste(WND *wndPtr, WPARAM wParam, LPARAM lParam)
 {
-	HGLOBAL hsrc;
+	HGLOBAL16 hsrc;
 	char *src;
 
 	OpenClipboard(wndPtr->hwndSelf);
diff --git a/controls/menu.c b/controls/menu.c
index a83db51..fc36acb 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -107,7 +107,7 @@
 static HMENU MENU_CopySysMenu(void)
 {
     HMENU hMenu;
-    HGLOBAL handle;
+    HGLOBAL16 handle;
     POPUPMENU *menu;
 
     if (!(handle = SYSRES_LoadResource( SYSRES_MENU_SYSMENU ))) return 0;
diff --git a/controls/static.c b/controls/static.c
index 72ded64..faa8241 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -46,9 +46,9 @@
  *
  * Set the icon for an SS_ICON control.
  */
-static HICON STATIC_SetIcon( WND *wndPtr, HICON hicon )
+static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
 {
-    HICON prevIcon;
+    HICON16 prevIcon;
     STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
 
     if ((wndPtr->dwStyle & 0x0f) != SS_ICON) return 0;
@@ -167,7 +167,7 @@
 	    return infoPtr->hIcon;
 
 	case STM_SETICON:
-            lResult = STATIC_SetIcon( wndPtr, (HICON)wParam );
+            lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
             InvalidateRect32( hWnd, NULL, FALSE );
             UpdateWindow( hWnd );
 	    break;
diff --git a/controls/status.c b/controls/status.c
new file mode 100644
index 0000000..0b6eb80
--- /dev/null
+++ b/controls/status.c
@@ -0,0 +1,499 @@
+/*
+ * Interface code to StatusWindow widget/control
+ *
+ * Copyright 1996 Bruce Milner
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "windows.h"
+#include "status.h"
+#include "commctrl.h"
+#include "heap.h"
+#include "syscolor.h"
+#include "win.h"
+
+/*
+ * Run tests using Waite Group Windows95 API Bible Vol. 1&2
+ * The second cdrom contains executables drawstat.exe,gettext.exe,
+ * simple.exe, getparts.exe, setparts.exe, statwnd.exe
+ */
+
+/*
+ * Fixme/Todo
+ * 1) Add size grip to status bar - SBARS_SIZEGRIP
+ * 2) Don't hard code bar to bottom of window, allow CCS_TOP also
+ * 3) Fix SBT_OWNERDRAW
+ * 4) Add DrawStatusText32A funtion
+ */
+
+static STATUSWINDOWINFO *GetStatusInfo(HWND32 hwnd)
+{
+    WND *wndPtr;
+
+    wndPtr = WIN_FindWndPtr(hwnd);
+    return ((STATUSWINDOWINFO *) &wndPtr->wExtra[0]);
+}
+
+/***********************************************************************
+ *           DrawStatusText32A   (COMCTL32.3)
+ */
+void DrawStatusText32A( HDC32 hdc, LPRECT32 lprc, LPCSTR text, UINT32 style )
+{
+    RECT32		r, rt;
+    int	oldbkmode;
+
+    r = *lprc;
+
+    if (style == 0 ||
+	style == SBT_POPOUT) {
+	InflateRect32(&r, -1, -1);
+	SelectObject(hdc, sysColorObjects.hbrushScrollbar);
+	Rectangle(hdc, r.left, r.top, r.right, r.bottom);
+
+	/* draw border */
+	SelectObject(hdc, sysColorObjects.hpenWindowFrame);
+	if (style == 0)
+	    DrawEdge32(hdc, &r, EDGE_SUNKEN, BF_RECT);
+	else
+	    DrawEdge32(hdc, &r, EDGE_RAISED, BF_RECT);
+    }
+    else if (style == SBT_NOBORDERS) {
+	SelectObject(hdc, sysColorObjects.hbrushScrollbar);
+	Rectangle(hdc, r.left, r.top, r.right, r.bottom);
+    }
+    else {	/* fixme for SBT_OWNERDRAW, SBT_RTLREADING */
+	
+    }
+
+    /* now draw text */
+    if ((style != SBT_OWNERDRAW) && text) {
+	SelectObject(hdc, sysColorObjects.hpenWindowText);
+	oldbkmode = SetBkMode(hdc, TRANSPARENT);
+	rt = r;
+	rt.left += 3;
+	DrawText32A(hdc, text, lstrlen32A(text),
+		    &rt, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
+
+	if (oldbkmode != TRANSPARENT)
+	    SetBkMode(hdc, oldbkmode);
+    }
+}
+
+static BOOL32 SW_Refresh( HWND32 hwnd, HDC32 hdc, STATUSWINDOWINFO *self )
+{
+	int	i;
+
+	if (!IsWindowVisible(hwnd)) {
+	    return (TRUE);
+	}
+
+	if (self->simple) {
+	    DrawStatusText32A(hdc,
+			      &self->part0.bound,
+			      self->part0.text,
+			      self->part0.style);
+	}
+	else {
+	    for (i = 0; i < self->numParts; i++) {
+		DrawStatusText32A(hdc,
+				  &self->parts[i].bound,
+				  self->parts[i].text,
+				  self->parts[i].style);
+	    }
+	}
+
+	return TRUE;
+}
+
+
+static LRESULT
+SW_GetBorders(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    LPINT32	out;
+
+    /* FIXME for sizegrips */
+    out = (LPINT32) lParam;
+    out[0] = 1; /* vertical border width */
+    out[1] = 1; /* horizontal border width */
+    out[2] = 1; /* width of border between rectangles */
+    return TRUE;
+}
+
+static void
+SW_SetPartBounds(HWND32 hwnd, STATUSWINDOWINFO *self)
+{
+    int	i;
+    RECT32	rect, *r;
+    STATUSWINDOWPART *part;
+    int	sep = 1;
+
+    /* get our window size */
+    GetClientRect32(hwnd, &rect);
+
+    /* set bounds for simple rectangle */
+    self->part0.bound = rect;
+
+    /* set bounds for non-simple rectangles */
+    for (i = 0; i < self->numParts; i++) {
+	part = &self->parts[i];
+	r = &self->parts[i].bound;
+	r->top = rect.top;
+	r->bottom = rect.bottom;
+	if (i == 0)
+	    r->left = 0;
+	else
+	    r->left = self->parts[i-1].bound.right+sep;
+	if (part->x == -1)
+	    r->right = rect.right;
+	else
+	    r->right = part->x;
+    }
+}
+
+static LRESULT
+SW_SetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    int	part_num;
+    int	style;
+    LPSTR	text;
+    int	len;
+    STATUSWINDOWPART *part;
+
+    text = (LPSTR) lParam;
+    part_num = ((INT32) wParam) & 0x00ff;
+    style = ((INT32) wParam) & 0xff00;
+
+    if (part_num > 255)
+	return FALSE;
+
+    if (self->simple)
+	part = &self->part0;
+    else
+	part = &self->parts[part_num];
+    part->style = style;
+    if (style == SBT_OWNERDRAW) {
+	part->text = text;
+    }
+    else {
+	/* duplicate string */
+	if (part->text)
+	    HeapFree(SystemHeap, 0, part->text);
+	part->text = 0;
+	if (text && (len = lstrlen32A(text))) {
+	    part->text = HeapAlloc(SystemHeap, 0, len+1);
+	    lstrcpy32A(part->text, text);
+	}
+    }
+    InvalidateRect32(hwnd, &part->bound, FALSE);
+    return TRUE;
+}
+
+static LRESULT
+SW_SetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    HDC32	hdc;
+    LPINT32 parts;
+    STATUSWINDOWPART *	tmp;
+    int	i;
+    int	oldNumParts;
+
+    if (self->simple) {
+	self->simple = FALSE;
+    }
+    oldNumParts = self->numParts;
+    self->numParts = (INT32) wParam;
+    parts = (LPINT32) lParam;
+    if (oldNumParts > self->numParts) {
+	for (i = self->numParts ; i < oldNumParts; i++) {
+	    if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
+		HeapFree(SystemHeap, 0, self->parts[i].text);
+	}
+    }
+    else if (oldNumParts < self->numParts) {
+	tmp = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY,
+			sizeof(STATUSWINDOWPART) * self->numParts);
+	for (i = 0; i < oldNumParts; i++) {
+	    tmp[i] = self->parts[i];
+	}
+	if (self->parts)
+	    HeapFree(SystemHeap, 0, self->parts);
+	self->parts = tmp;
+    }
+    
+    for (i = 0; i < self->numParts; i++) {
+	self->parts[i].x = parts[i];
+    }
+    SW_SetPartBounds(hwnd, self);
+
+    hdc = GetDC(hwnd);
+    SW_Refresh(hwnd, hdc, self);
+    ReleaseDC(hwnd, hdc);
+    return TRUE;
+}
+
+static LRESULT
+SW_GetParts(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    LPINT32 parts;
+    INT32	num_parts;
+    int	i;
+
+    self = GetStatusInfo(hwnd);
+    num_parts = (INT32) wParam;
+    parts = (LPINT32) lParam;
+    if (parts) {
+	return (self->numParts);
+	for (i = 0; i < num_parts; i++) {
+	    parts[i] = self->parts[i].x;
+	}
+    }
+    return (self->numParts);
+}
+
+static LRESULT
+SW_Create(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    RECT32	rect;
+    LPCREATESTRUCT32A lpCreate = (LPCREATESTRUCT32A) lParam;
+    int	height, width;
+    HDC32	hdc;
+    HWND32	parent;
+
+    self->numParts = 0;
+    self->parts = 0;
+    self->simple = TRUE;
+    GetClientRect32(hwnd, &rect);
+
+    /* initialize simple case */
+    self->part0.bound = rect;
+    self->part0.text = 0;
+    self->part0.x = 0;
+    self->part0.style = 0;
+
+    height = 40;
+    if ((hdc = GetDC(0))) {
+	TEXTMETRIC32A tm;
+	GetTextMetrics32A(hdc, &tm);
+	self->textHeight = tm.tmHeight;
+	ReleaseDC(0, hdc);
+    }
+
+    parent = GetParent(hwnd);
+    GetClientRect32(parent, &rect);
+    width = rect.right - rect.left;
+    height = (self->textHeight * 3)/2;
+    MoveWindow(hwnd, lpCreate->x, lpCreate->y-1, width, height, FALSE);
+    SW_SetPartBounds(hwnd, self);
+    return 0;
+}
+
+static LRESULT
+SW_GetRect(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    int	part_num;
+    LPRECT32  rect;
+
+    part_num = ((INT32) wParam) & 0x00ff;
+    rect = (LPRECT32) lParam;
+    if (self->simple)
+	*rect = self->part0.bound;
+    else
+	*rect = self->parts[part_num].bound;
+    return TRUE;
+}
+
+static LRESULT
+SW_GetText(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    int	part_num;
+    LRESULT	result;
+    STATUSWINDOWPART *part;
+    LPSTR	out_text;
+
+    part_num = ((INT32) wParam) & 0x00ff;
+    out_text = (LPSTR) lParam;
+    if (self->simple)
+	part = &self->part0;
+    else
+	part = &self->parts[part_num];
+
+    if (part->style == SBT_OWNERDRAW)
+	result = (LRESULT) part->text;
+    else {
+	result = part->text ? lstrlen32A(part->text) : 0;
+	result |= (part->style << 16);
+	if (out_text) {
+	    lstrcpy32A(out_text, part->text);
+	}
+    }
+    return result;
+}
+
+static LRESULT
+SW_GetTextLength(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    int	part_num;
+    STATUSWINDOWPART *part;
+    DWORD	result;
+
+    part_num = ((INT32) wParam) & 0x00ff;
+
+    if (self->simple)
+	part = &self->part0;
+    else
+	part = &self->parts[part_num];
+
+    if (part->text)
+	result = lstrlen32A(part->text);
+    else
+	result = 0;
+
+    result |= (part->style << 16);
+    return result;
+}
+
+static LRESULT
+SW_SetMinHeight(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    /* FIXME */
+    /* size is wParam | 2*pixels_of_horz_border */
+    return TRUE;
+}
+
+static LRESULT
+SW_Simple(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    BOOL32 simple;
+    HDC32	hdc;
+
+    simple = (BOOL32) wParam;
+    self->simple = simple;
+    hdc = GetDC(hwnd);
+    SW_Refresh(hwnd, hdc, self);
+    ReleaseDC(hwnd, hdc);
+    return TRUE;
+}
+
+static LRESULT
+SW_Size(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    /* Need to resize width to match parent */
+    INT32	width, height, x, y;
+    RECT32	parent_rect;
+    HWND32	parent;
+
+    INT32  	flags;
+
+    flags = (INT32) wParam;
+
+    /* FIXME for flags =
+     * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, SIZE_RESTORED
+     */
+
+    if (flags == SIZE_RESTORED) {
+	/* width and height don't apply */
+	parent = GetParent(hwnd);
+	GetClientRect32(parent, &parent_rect);
+	height = (self->textHeight * 3)/2;
+	width = parent_rect.right - parent_rect.left;
+	x = parent_rect.left;
+	y = parent_rect.bottom - height;
+	MoveWindow(hwnd, parent_rect.left, parent_rect.bottom - height - 1,
+		   width, height, TRUE);
+	SW_SetPartBounds(hwnd, self);
+    }
+    return 0;
+}
+
+static LRESULT
+SW_Destroy(STATUSWINDOWINFO *self, HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
+{
+    int	i;
+
+    for (i = 0; i < self->numParts; i++) {
+	if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
+	    HeapFree(SystemHeap, 0, self->parts[i].text);
+    }
+    if (self->part0.text && (self->part0.style != SBT_OWNERDRAW))
+	HeapFree(SystemHeap, 0, self->part0.text);
+    HeapFree(SystemHeap, 0, self->parts);
+    return 0;
+}
+
+
+
+static LRESULT
+SW_Paint(STATUSWINDOWINFO *self, HWND32 hwnd)
+{
+    HDC32 hdc;
+    PAINTSTRUCT32	ps;
+
+    hdc = BeginPaint32(hwnd, &ps);
+    SW_Refresh(hwnd, hdc, self);
+    EndPaint32(hwnd, &ps);
+    return 0;
+}
+
+LRESULT StatusWindowProc( HWND32 hwnd, UINT32 msg,
+                          WPARAM32 wParam, LPARAM lParam )
+{
+    STATUSWINDOWINFO *self;
+
+    self = GetStatusInfo(hwnd);
+
+    switch (msg) {
+    case SB_GETBORDERS:
+	return SW_GetBorders(self, hwnd, wParam, lParam);
+    case SB_GETPARTS:
+	return SW_GetParts(self, hwnd, wParam, lParam);
+    case SB_GETRECT:
+	return SW_GetRect(self, hwnd, wParam, lParam);
+    case SB_GETTEXT32A:
+	return SW_GetText(self, hwnd, wParam, lParam);
+    case SB_GETTEXTLENGTH32A:
+	return SW_GetTextLength(self, hwnd, wParam, lParam);
+    case SB_SETMINHEIGHT:
+	return SW_SetMinHeight(self, hwnd, wParam, lParam);
+    case SB_SETPARTS:	
+	return SW_SetParts(self, hwnd, wParam, lParam);
+    case SB_SETTEXT32A:
+	return SW_SetText(self, hwnd, wParam, lParam);
+    case SB_SIMPLE:
+	return SW_Simple(self, hwnd, wParam, lParam);
+
+    case WM_CREATE:
+	return SW_Create(self, hwnd, wParam, lParam);
+    case WM_DESTROY:
+	return SW_Destroy(self, hwnd, wParam, lParam);
+    case WM_PAINT:
+	return SW_Paint(self, hwnd);
+    case WM_SIZE:
+	return SW_Size(self, hwnd, wParam, lParam);
+    default:
+	return DefWindowProc32A(hwnd, msg, wParam, lParam);
+    }
+    return 0;
+}
+
+
+/***********************************************************************
+ *           CreateStatusWindow32A   (COMCTL32.4)
+ */
+HWND32 CreateStatusWindow32A( INT32 style, LPCSTR text, HWND32 parent,
+                              UINT32 wid )
+{
+    HWND32 ret;
+    ATOM atom;
+
+    atom = GlobalFindAtom32A(STATUSCLASSNAME32A);
+    if (!atom) {
+	/* Some apps don't call InitCommonControls */
+	InitCommonControls();
+    }
+
+    ret = CreateWindowEx32A(0, STATUSCLASSNAME32A, "Status Window",
+			    style, CW_USEDEFAULT32, CW_USEDEFAULT32,
+			    CW_USEDEFAULT32, CW_USEDEFAULT32, parent, 0, 0, 0);
+    return (ret);
+}
diff --git a/controls/widgets.c b/controls/widgets.c
index 4f8a78c..eccaa10 100644
--- a/controls/widgets.c
+++ b/controls/widgets.c
@@ -5,8 +5,10 @@
  */
 
 #include "win.h"
+#include "commctrl.h"
 #include "button.h"
 #include "static.h"
+#include "status.h"
 #include "scroll.h"
 #include "desktop.h"
 #include "mdi.h"
@@ -49,6 +51,7 @@
 #define NB_BUILTIN_CLASSES16 \
          (sizeof(WIDGETS_BuiltinClasses16)/sizeof(WIDGETS_BuiltinClasses16[0]))
 
+
 static WNDCLASS32A WIDGETS_BuiltinClasses32[] =
 {
     { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC,
@@ -61,6 +64,16 @@
          (sizeof(WIDGETS_BuiltinClasses32)/sizeof(WIDGETS_BuiltinClasses32[0]))
 
 
+static WNDCLASS32A WIDGETS_CommonControls32[] =
+{
+    { CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW, StatusWindowProc, 0,
+      sizeof(STATUSWINDOWINFO), 0, 0, 0, 0, 0, STATUSCLASSNAME32A },
+};
+
+#define NB_COMMON_CONTROLS32 \
+         (sizeof(WIDGETS_CommonControls32)/sizeof(WIDGETS_CommonControls32[0]))
+
+
 /***********************************************************************
  *           WIDGETS_Init
  * 
@@ -108,3 +121,23 @@
     SEGPTR_FREE(name);
     return TRUE;
 }
+
+
+/***********************************************************************
+ *           InitCommonControls   (COMCTL32.15)
+ */
+void InitCommonControls(void)
+{
+    int i;
+    char name[30];
+    WNDCLASS32A *class32 = WIDGETS_CommonControls32;
+
+    for (i = 0; i < NB_COMMON_CONTROLS32; i++, class32++)
+    {
+        /* Just to make sure the string is > 0x10000 */
+        strcpy( name, (char *)class32->lpszClassName );
+        class32->lpszClassName = name;
+        class32->hCursor = LoadCursor16( 0, IDC_ARROW );
+        RegisterClass32A( class32 );
+    }
+}
diff --git a/documentation/debugging b/documentation/debugging
index 1cee434..4b8bead 100644
--- a/documentation/debugging
+++ b/documentation/debugging
@@ -63,6 +63,7 @@
                                   ^^^^^^
 				  |Returnvalue is 16 bit and has the value 7.
 
+
  3. If you have found a misbehaving function, try to find out why it
     misbehaves. Find the function in the source code. Try to make sense of
     the arguments passed. Usually there is a
@@ -70,15 +71,30 @@
     function. Rerun wine with "-debugmsg +xyz,+relay" added to the
     commandline.
 
+ 4. If the crash happened in a function in WINE, find out the exact line using
+    gdb (the sample crash has another reason):
+|... somewhere in the backtrace ...
+|5 0x080e5ad8 (CreateWindowEx32A+0xd8)
+|...
+|$ gdb wine
+|...
+|(gdb) l *0x080e5ad8
+|0x80e5ad8 is in CreateWindowEx32A (win.c:837).
+|...
+|837         return WIN_CreateWindowEx( &cs, classAtom, FALSE );
+|...
 
- 4. If those information isn't clear enough or if you want to know more about
+
+ 5. If those information isn't clear enough or if you want to know more about
     what's happening in the function itself, try running wine with "-debugmsg
     +all", which dumps ALL included debug information in wine.
 
- 5. If that isn't enough add more debug output for yourself into the
+ 6. If that isn't enough add more debug output for yourself into the
     functions you find relevant.
+    You might also try to run the program in gdb instead of using the
+    WINE-debugger.
   
- 6. You can also set a breakpoint for that function. Start wine with the
+ 7. You can also set a breakpoint for that function. Start wine with the
     "-debug" option added to the commandline. After loading the executable
     wine will enter the internal debugger. Use "break KERNEL.LSTRLEN"
     (replace by function you want to debug, CASE IS RELEVANT.) to set a
@@ -95,7 +111,7 @@
 
   Switch to UNIX shell, get the process-ID using "ps -a|grep wine", and do a
   "kill -HUP <pid>" (without " and <>). Wine will then enter its internal
-  debugger and you can procede as explained above.
+  debugger and you can proceed as explained above.
 
 Program reports an error with a Messagebox
 ==========================================
@@ -113,6 +129,44 @@
   above.
 
 
+Disassembling programs:
+=======================
+  You may also try to disassemble the offending program to check for 
+  undocumented features and/or use of them.
+  The best, freely available, disassembler for win16 programs is
+  Windows Codeback, archivename wcbxxx.zip, which usually can be found
+  in the Cica-Mirror subdirectory on the WINE ftpsites. (See ANNOUNCE).
+  Disassembling win32 programs is currenty only possible using 
+  Windows Disassembler 32, archivename something like wdasm32x.zip on
+  ftp.winsite.com and mirrors.
+  Understanding disassembled code is just a question of exercise.
+  Most code out there uses standard C function entries (for it is usually 
+  written in C). Win16 function entries usually look like that:
+|  	push bp
+|	mov bp, sp
+|	... function code ..
+|	retf XXXX 	<--------- XXXX is number of bytes of arguments
+
+  This is a FAR function with no local storage. The arguments usually start
+  at [bp+6] with increasing offsets. Note, that [bp+6] belongs to the RIGHTMOST 
+  argument, for exported win16 functions use the PASCAL calling convention.
+  So, if we use strcmp(a,b) with a and b both 32 bit variables b would be at
+  [bp+6] and a at [bp+10].
+  Most functions make also use of local storage in the stackframe:
+|	enter 0086, 00
+|	... function code ...
+|	leave
+|	retf XXXX
+  This does mostly the same as above, but also adds 0x86 bytes of
+  stackstorage, which is accessed using [bp-xx].
+  Before calling a function, arguments are pushed on the stack using something
+  like this:
+|	push word ptr [bp-02]	<- will be at [bp+8]
+|	push di			<- will be at [bp+6]
+|	call KERNEL.LSTRLEN
+  Here first the selector and then the offset to the passed string are pushed.
+
+
 Sample debugging session:
 =========================
 
diff --git a/documentation/user_module b/documentation/user_module
index 6b6bfd7..4335f9c 100644
--- a/documentation/user_module
+++ b/documentation/user_module
@@ -205,13 +205,13 @@
 	
 
     b) Intertask/interthread SendMessage. The system has to inform the
-       target queue about the forthcoming message, then it has to
-       carry out the context switch and wait until the result is
-       available.  In Win16 it is done by putting necessary parameters
-       into the queue structure and do a DirectedYield() call.
-       However, in Win32 there could be several messages pending sent
-       by preemptively executing threads, and in this case SendMessage
-       has to build some sort of message queue for sent
-       messages. Another issue is what to do with messages sent to the
-       sender when it is blocked inside its own SendMessage. At this
-       point Wine does not address any of these problems.
+       target queue about the forthcoming message, then it has to carry 
+       out the context switch and wait until the result is available.  
+       Win16 stores necessary parameters in the queue structure and then 
+       calls DirectedYield() function.  However, in Win32 there could be 
+       several messages pending sent by preemptively executing threads, 
+       and in this case SendMessage has to build some sort of message 
+       queue for sent messages. Another issue is what to do with messages 
+       sent to the sender when it is blocked inside its own SendMessage. 
+       At this point Wine addresses very few of these problems.
+
diff --git a/files/file.c b/files/file.c
index 940ebe1..583471b 100644
--- a/files/file.c
+++ b/files/file.c
@@ -906,10 +906,12 @@
     	p=p+1;
     else
         p=testpath;
-    if (p-testpath<buflen)
-	*lastpart=(p-testpath)+buf;
-    else
-    	*lastpart=NULL;
+    if (lastpart) {
+	if (p-testpath<buflen)
+	    *lastpart=(p-testpath)+buf;
+	else
+	    *lastpart=NULL;
+    }
     dprintf_file(stddeb,"	-> found %s,last part is %s\n",testpath,p);
     return strlen(testpath);
 }
@@ -930,10 +932,12 @@
 
 	ret=SearchPath32A(pathA,fnA,extA,buflen,bufA,&lastpartA);
 	lstrcpynAtoW(buf,bufA,buflen);
-	if (lastpartA)
-		*lastpart = buf+(lastpartA-bufA);
-	else
-		*lastpart = NULL;
+	if (lastpart) {
+		if (lastpartA)
+			*lastpart = buf+(lastpartA-bufA);
+		else
+			*lastpart = NULL;
+	}
 	free(bufA);
 	free(fnA);
 	if (pathA) free(pathA);
diff --git a/if1632/comctl32.spec b/if1632/comctl32.spec
index f6b93fa..90b5e5d 100644
--- a/if1632/comctl32.spec
+++ b/if1632/comctl32.spec
@@ -5,8 +5,8 @@
 00 stub MenuHelp
 01 stub ShowHideMenuCtl
 02 stub GetEffectiveClientRect
-03 stub DrawStatusTextA
-04 stub CreateStatusWindowA
+03 stdcall DrawStatusTextA(long ptr ptr long) DrawStatusText32A
+04 stdcall CreateStatusWindowA(long ptr long long) CreateStatusWindow32A
 05 stub CreateToolbar
 06 stub CreateMappedBitmap
 07 stub CreatePropertySheetPage
@@ -17,7 +17,7 @@
 12 stub LBItemFromPt
 13 stub DrawInsert
 14 stub CreateUpDownControl
-15 return InitCommonControls 4 0
+15 stdcall InitCommonControls() InitCommonControls
 16 stub CreateStatusWindowW
 17 stub CreateToolbarEx
 18 stub DestroyPropertySheetPage
diff --git a/if1632/crtdll.spec b/if1632/crtdll.spec
index 02e1b03..8f9a2b7 100644
--- a/if1632/crtdll.spec
+++ b/if1632/crtdll.spec
@@ -1,3 +1,4 @@
+# C RunTime DLL. All functions use cdecl!
 name	crtdll
 type	win32
 base	1
@@ -23,9 +24,9 @@
 019 stub _CItanh
 020 stub _HUGE_dll
 021 stub _XcptFilter
-022 stub __GetMainArgs
-023 stub __argc_dll
-024 stub __argv_dll
+022 cdecl __GetMainArgs(ptr ptr ptr long) CRTDLL__GetMainArgs
+023 extern __argc_dll CRTDLL_argc_dll
+024 extern __argv_dll CRTDLL_argv_dll
 025 stub __dllonexit
 026 stub __doserrno
 027 stub __fpecode
@@ -39,13 +40,13 @@
 035 stub __toascii
 036 stub _abnormal_termination
 037 stub _access
-038 stub _acmdln_dll
+038 extern _acmdln_dll CRTDLL_acmdln_dll
 039 stub _aexit_rtn_dll
 040 stub _amsg_exit
 041 stub _assert
-042 stub _basemajor_dll
-043 stub _baseminor_dll
-044 stub _baseversion_dll
+042 extern _basemajor_dll CRTDLL_basemajor_dll
+043 extern _baseminor_dll CRTDLL_baseminor_dll
+044 extern _baseversion_dll CRTDLL_baseversion_dll
 045 stub _beep
 046 stub _beginthread
 047 stub _c_exit
@@ -76,7 +77,7 @@
 072 stub _dup2
 073 stub _ecvt
 074 stub _endthread
-075 stub _environ_dll
+075 extern _environ_dll CRTDLL_environ_dll
 076 stub _eof
 077 stub _errno
 078 stub _except_handler2
@@ -136,9 +137,9 @@
 132 stub _heapset
 133 stub _heapwalk
 134 stub _hypot
-135 stub _initterm
+135 cdecl _initterm(ptr ptr) CRTDLL__initterm
 136 stub _iob
-137 stub _isatty
+137 cdecl _isatty(long) CRTDLL__isatty
 138 stub _isctype
 139 stub _ismbbalnum
 140 stub _ismbbalpha
@@ -242,11 +243,11 @@
 238 stub _onexit
 239 stub _open
 240 stub _open_osfhandle
-241 stub _osmajor_dll
-242 stub _osminor_dll
-243 stub _osmode_dll
-244 stub _osver_dll
-245 stub _osversion_dll
+241 extern _osmajor_dll CRTDLL_osmajor_dll
+242 extern _osminor_dll CRTDLL_osminor_dll
+243 long _osmode_dll(0)
+244 extern _osver_dll CRTDLL_osver_dll
+245 extern _osversion_dll CRTDLL_osversion_dll
 246 stub _pclose
 247 stub _pctype_dll
 248 stub _pgmptr_dll
@@ -330,10 +331,10 @@
 326 stub _wcsrev
 327 stub _wcsset
 328 stub _wcsupr
-329 stub _winmajor_dll
-330 stub _winminor_dll
-331 stub _winver_dll
-332 stub _write
+329 extern _winmajor_dll CRTDLL_winmajor_dll
+330 extern _winminor_dll CRTDLL_winminor_dll
+331 extern _winver_dll CRTDLL_winver_dll
+332 cdecl _write(long ptr long) CRTDLL__write
 333 stub _wtoi
 334 stub _wtol
 335 stub _y0
@@ -360,13 +361,13 @@
 356 stub ctime
 357 stub difftime
 358 stub div
-359 stub exit
+359 cdecl exit(long) CRTDLL_exit
 360 stub exp
 361 stub fabs
 362 stub fclose
 363 stub feof
 364 stub ferror
-365 stub fflush
+365 cdecl fflush(ptr) CRTDLL_fflush
 366 stub fgetc
 367 stub fgetpos
 368 stub fgets
@@ -374,7 +375,7 @@
 370 stub floor
 371 stub fmod
 372 stub fopen
-373 stub fprintf
+373 cdecl fprintf() CRTDLL_fprintf
 374 stub fputc
 375 stub fputs
 376 stub fputwc
@@ -392,7 +393,7 @@
 388 stub getc
 389 stub getchar
 390 stub getenv
-391 stub gets
+391 cdecl gets(ptr) CRTDLL_gets
 392 stub gmtime
 393 stub is_wctype
 394 stub isalnum
@@ -441,9 +442,9 @@
 437 stub modf
 438 stub perror
 439 stub pow
-440 stub printf
+440 cdecl printf() CRTDLL_printf
 441 stub putc
-442 stub putchar
+442 cdecl putchar(long) CRTDLL_putchar
 443 stub puts
 444 stub qsort
 445 stub raise
@@ -461,7 +462,7 @@
 457 stub sinh
 458 stub sprintf
 459 stub sqrt
-460 stub srand
+460 cdecl srand(long) CRTDLL_srand
 461 stub sscanf
 462 stub strcat
 463 stub strchr
@@ -489,11 +490,11 @@
 485 stub system
 486 stub tan
 487 stub tanh
-488 stub time
+488 cdecl time(ptr) CRTDLL_time
 489 stub tmpfile
 490 stub tmpnam
 491 stub tolower
-492 stub toupper
+492 cdecl toupper(long) CRTDLL_toupper
 493 stub towlower
 494 stub towupper
 495 stub ungetc
diff --git a/if1632/except.S b/if1632/except.S
index 2b522ca..66fb861 100644
--- a/if1632/except.S
+++ b/if1632/except.S
@@ -4,28 +4,26 @@
  * Copyright (c) 1996 Onno Hovers, (onno@stack.urc.tue.nl)
  *
  */
-#if defined(__svr4__) || defined(_SCO_DS)
-#define __ELF__ 1
-#endif
+#include "../include/config.h"
 
-#ifndef __ELF__
+#ifdef NEED_UNDERSCORE_PREFIX
 
      .globl _EXC_CallUnhandledExceptionFilter
  _EXC_CallUnhandledExceptionFilter:
 
-#else  /* __ELF__ */
+#else
 
      .globl EXC_CallUnhandledExceptionFilter
  EXC_CallUnhandledExceptionFilter:
 
-#endif  /* __ELF__ */
+#endif  /* NEED_UNDERSCORE_PREFIX */
      leal   4(%esp),%eax
      pushl  %eax
-#ifndef __ELF__
+#ifdef NEED_UNDERSCORE_PREFIX
      call   *_pTopExcHandler
-#else  /* __ELF__ */
+#else
      call   *pTopExcHandler
-#endif  /* __ELF__ */
+#endif  /* NEED_UNDERSCORE_PREFIX */
      movl   %ebp,%esp
      ret
 
@@ -95,7 +93,7 @@
 #define PARM_EBP              4
 #define PARM_EFLAGS           0
 
-#ifndef __ELF__
+#ifdef NEED_UNDERSCORE_PREFIX
 	.globl _RaiseException
 
  _RaiseException:
@@ -107,7 +105,7 @@
  _RtlUnwind:
        push   $_EXC_RtlUnwind
 
-#else  /* __ELF__ */
+#else  /* NEED_UNDERSCORE_PREFIX */
        .globl RaiseException
 
  RaiseException:
@@ -118,7 +116,7 @@
 
  RtlUnwind:
        push   $EXC_RtlUnwind
-#endif  /* __ELF__ */
+#endif  /* NEED_UNDERSCORE_PREFIX */
 
  ContextCall:
        pushl  %ebp
diff --git a/if1632/gdi.spec b/if1632/gdi.spec
index b7e804e..cf39e6f 100644
--- a/if1632/gdi.spec
+++ b/if1632/gdi.spec
@@ -269,7 +269,7 @@
 405 stub FINALGDIINIT
 407 stub CREATEUSERBITMAP
 409 stub CREATEUSERDISCARDABLEBITMAP
-410 stub ISVALIDMETAFILE
+410 pascal16 IsValidMetaFile (word) IsValidMetaFile
 411 pascal16 GetCurLogFont(word) GetCurLogFont
 412 pascal16 IsDCCurrentPalette(word) IsDCCurrentPalette
 439 pascal16 StretchDIBits (word s_word s_word word word word word
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index e7bf177..493754f 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -3,7 +3,7 @@
 
 1   stub FatalExit
 2   stub ExitKernel
-3   pascal GetVersion() GetVersion
+3   pascal GetVersion() GetVersion16
 4   pascal16 LocalInit(word word word) LocalInit
 5   pascal16 LocalAlloc(word word) LocalAlloc16
 6   pascal16 LocalReAlloc(word word word) LocalReAlloc16
diff --git a/if1632/kernel32.spec b/if1632/kernel32.spec
index 0b9bd3a..16cf10d 100644
--- a/if1632/kernel32.spec
+++ b/if1632/kernel32.spec
@@ -121,18 +121,18 @@
 0116 stub FillConsoleOutputCharacterW
 0117 stub FindAtomA
 0118 stub FindAtomW
-0119 stub FindClose
+0119 stdcall FindClose(long) FindClose
 0120 stub FindCloseChangeNotification
 0121 stub FindFirstChangeNotificationA
 0122 stub FindFirstChangeNotificationW
 0123 stdcall FindFirstFileA(ptr ptr) FindFirstFile32A
 0124 stub FindFirstFileW
 0125 stub FindNextChangeNotification
-0126 stub FindNextFileA
+0126 stdcall FindNextFileA(long ptr) FindNextFile32A
 0127 stub FindNextFileW
 0128 stdcall FindResourceA(long ptr ptr) FindResource32A
-0129 stub FindResourceExA
-0130 stub FindResourceExW
+0129 stdcall FindResourceExA(long ptr ptr long) FindResourceEx32A
+0130 stdcall FindResourceExW(long ptr ptr long) FindResourceEx32W
 0131 stdcall FindResourceW(long ptr ptr) FindResource32W
 0132 stub FlushConsoleInputBuffer
 0133 stdcall FlushFileBuffers(long) FlushFileBuffers
@@ -140,7 +140,7 @@
 0135 stub FlushViewOfFile
 0136 stub FoldStringA
 0137 stub FoldStringW
-0138 stdcall FormatMessageA(long ptr long long ptr long ptr) FormatMessage32A
+0138 stdcall FormatMessageA() WIN32_FormatMessage32A
 0139 stub FormatMessageW
 0140 stub FreeConsole
 0141 stdcall FreeEnvironmentStringsA(ptr)	FreeEnvironmentStringsA
@@ -163,8 +163,8 @@
 0158 stub GetCommProperties
 0159 stdcall GetCommState(long ptr) GetCommState32
 0160 stdcall GetCommTimeouts(long ptr) GetCommTimeouts
-0161 stdcall GetCommandLineA()	GetCommandLineA
-0162 stub GetCommandLineW
+0161 stdcall GetCommandLineA() GetCommandLine32A
+0162 stdcall GetCommandLineW() GetCommandLine32W
 0163 stub GetCompressedFileSizeA
 0164 stub GetCompressedFileSizeW
 0165 stub GetComputerNameA
diff --git a/if1632/shell32.spec b/if1632/shell32.spec
index 33a458d..acb26b4 100644
--- a/if1632/shell32.spec
+++ b/if1632/shell32.spec
@@ -33,7 +33,7 @@
 0028 stub FindExeDlgProc
 0029 stub FindExecutableA
 0030 stub FindExecutableW
-0031 stub FreeIconList
+0031 return FreeIconList 4 0
 0032 stub InternalExtractIconListA
 0033 stub InternalExtractIconListW
 0034 stub OpenAs_RunDLL
diff --git a/if1632/wsock32.spec b/if1632/wsock32.spec
index f20befb..67c7908 100644
--- a/if1632/wsock32.spec
+++ b/if1632/wsock32.spec
@@ -11,8 +11,8 @@
 007 stub getsockopt
 008 stub htonl
 009 stub htons
-010 stub inet_addr
-011 stub inet_ntoa
+010 stdcall inet_addr(ptr) inet_addr
+011 stdcall inet_ntoa(ptr) inet_ntoa
 012 stub ioctlsocket
 013 stub listen
 014 stub ntohl
@@ -25,11 +25,11 @@
 021 stub setsockopt
 022 stub shutdown
 023 stub socket
-051 stub gethostbyaddr
+051 stdcall gethostbyaddr(ptr long long) gethostbyaddr
 052 stub gethostbyname
 053 stub getprotobyname
 054 stub getprotobynumber
-055 stub getservbyname
+055 stdcall getservbyname(ptr ptr) getservbyname
 056 stub getservbyport
 057 stub gethostname
 101 stub WSAAsyncSelect
@@ -46,21 +46,21 @@
 112 stub WSASetLastError
 113 stub WSACancelBlockingCall
 114 stub WSAIsBlocking
-115 stub WSAStartup
-116 stub WSACleanup
+115 stdcall WSAStartup(long ptr) WSAStartup
+116 stdcall WSACleanup() WSACleanup
 151 stub __WSAFDIsSet
 #500 stub WEP
 # applications *should* 'degrade gracefully if these are not present
 # ... as it is, they don't
 #1000 stub WSApSetPostRoutine
-#1100 stub inet_network
-#1101 stub getnetbyname
+1100 stub inet_network
+1101 stub getnetbyname
 #1102 stub rcmd
 #1103 stub rexec
 #1104 stub rresvport
 #1105 stub sethostname
 #1106 stub dn_expand
-#1107 stub WSARecvEx
+1107 stub WSARecvEx
 1108 stub s_perror
 1109 stub GetAddressByNameA
 1110 stub GetAddressByNameW
diff --git a/include/acconfig.h b/include/acconfig.h
new file mode 100644
index 0000000..00d85cd
--- /dev/null
+++ b/include/acconfig.h
@@ -0,0 +1,7 @@
+/*
+ * This file is used by 'autoheader' to generate the list of symbols
+ * defined in the 'configure' script.
+ */
+
+/* Define if symbols declared in assembly code need an underscore prefix */
+#undef NEED_UNDERSCORE_PREFIX
diff --git a/include/advapi32.h b/include/advapi32.h
index 5de3830..3bd8cff 100644
--- a/include/advapi32.h
+++ b/include/advapi32.h
@@ -1,7 +1,6 @@
 #ifndef __WINE_ADVAPI32_H
 #define __WINE_ADVAPI32_H
 #include "shell.h"
-#include "kernel32.h"
 
 BOOL GetUserNameA (char * lpBuffer, DWORD  *nSize);
 
diff --git a/include/bitmap.h b/include/bitmap.h
index e9cafb7..7528707 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -48,7 +48,7 @@
 extern int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse );
 
   /* objects/oembitmap.c */
-extern HBITMAP OBM_LoadBitmap( WORD id );
-extern HANDLE OBM_LoadCursorIcon( WORD id, BOOL fCursor );
+extern HBITMAP16 OBM_LoadBitmap( WORD id );
+extern HGLOBAL16 OBM_LoadCursorIcon( WORD id, BOOL32 fCursor );
 
 #endif  /* __WINE_BITMAP_H */
diff --git a/include/callback.h b/include/callback.h
index 0339a89..5921cad 100644
--- a/include/callback.h
+++ b/include/callback.h
@@ -64,6 +64,8 @@
                                  style, MAKELONG(y,x), MAKELONG(cy,cx), \
                                  MAKELONG(hmenu,hparent), instance, params, \
                                  hwnd, msg, wParam, lParam )
+#define _InitTermProc( func ) CallTo32_0( (FARPROC32)func )
+
 
 /* List of the 32-bit callback functions. This list is used  */
 /* by the build program to generate the file if1632/callto32.S */
@@ -99,6 +101,8 @@
     (*func)( hwnd, msg, wParam, lParam )
 #define CallWordBreakProc( func, lpch, ichCurrent, cch, code ) \
     (*func)( lpch, ichCurrent, cch, code )
+#define _InitTermProc( func ) (*func)()
+
 
 #endif  /* WINELIB */
 
diff --git a/include/commctrl.h b/include/commctrl.h
new file mode 100644
index 0000000..a16e7bf
--- /dev/null
+++ b/include/commctrl.h
@@ -0,0 +1,51 @@
+/*
+ * Common controls definitions
+ */
+
+#ifndef __WINE_COMMCTRL_H
+#define __WINE_COMMCTRL_H
+
+#include "windows.h"
+
+void       InitCommonControls(void);
+
+/* StatusWindow */
+
+#define STATUSCLASSNAME16  "msctls_statusbar"
+#define STATUSCLASSNAME32A "msctls_statusbar32"
+#define STATUSCLASSNAME32W "msctls_statusbar32"
+#define STATUSCLASSNAME WINELIB_NAME_AW(STATUSCLASSNAME)
+
+#define SB_SETTEXT32A         (WM_USER+1)
+#define SB_SETTEXT32W         (WM_USER+11)
+#define SB_SETTEXT WINELIB_NAME_AW(SB_SETTEXT)
+#define SB_GETTEXT32A         (WM_USER+2)
+#define SB_GETTEXT32W         (WM_USER+13)
+#define SB_GETTEXT WINELIB_NAME_AW(SB_GETTEXT)
+#define SB_GETTEXTLENGTH32A   (WM_USER+3)
+#define SB_GETTEXTLENGTH32W   (WM_USER+12)
+#define SB_GETTEXTLENGTH WINELIB_NAME_AW(SB_GETTEXTLENGTH)
+
+#define SB_SETPARTS           (WM_USER+4)
+#define SB_GETPARTS           (WM_USER+6)
+#define SB_GETBORDERS         (WM_USER+7)
+#define SB_SETMINHEIGHT       (WM_USER+8)
+#define SB_SIMPLE             (WM_USER+9)
+#define SB_GETRECT            (WM_USER+10)
+
+#define SBT_NOBORDERS         0x0100
+#define SBT_POPOUT            0x0200
+#define SBT_RTLREADING        0x0400
+#define SBT_OWNERDRAW         0x1000
+
+#define CCS_BOTTOM            0x0003
+#define SBARS_SIZEGRIP        0x0100
+
+HWND32     CreateStatusWindow32A(INT32,LPCSTR,HWND32,UINT32);
+HWND32     CreateStatusWindow32W(INT32,LPCWSTR,HWND32,UINT32);
+#define    CreateStatusWindow WINELIB_NAME_AW(CreateStatusWindow)
+VOID       DrawStatusText32A(HDC32,LPRECT32,LPCSTR,UINT32);
+VOID       DrawStatusText32W(HDC32,LPRECT32,LPCWSTR,UINT32);
+#define    DrawStatusText WINELIB_NAME_AW(DrawStatusText)
+
+#endif  /* __WINE_COMMCTRL_H */
diff --git a/include/commdlg.h b/include/commdlg.h
index 0140d32..1a01a7c 100644
--- a/include/commdlg.h
+++ b/include/commdlg.h
@@ -206,8 +206,8 @@
 typedef struct {
 	DWORD 		lStructSize;
 	HWND 		hwndOwner;
-	HGLOBAL		hDevMode;
-	HGLOBAL		hDevNames;
+	HGLOBAL16       hDevMode;
+	HGLOBAL16       hDevNames;
 	HDC	       	hDC;
 	DWORD 		Flags;
 	UINT		nFromPage;
@@ -221,8 +221,8 @@
         WNDPROC16       lpfnSetupHook;
 	SEGPTR 		lpPrintTemplateName;
 	SEGPTR 		lpSetupTemplateName;
-	HGLOBAL 	hPrintTemplate;
-	HGLOBAL 	hSetupTemplate;
+	HGLOBAL16       hPrintTemplate;
+	HGLOBAL16       hSetupTemplate;
 	} PRINTDLG;
 typedef PRINTDLG * LPPRINTDLG;
 
diff --git a/include/config.h.in b/include/config.h.in
index 0bbdd70..638652a 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -15,6 +15,9 @@
 /* Define if you have the ANSI C header files.  */
 #undef STDC_HEADERS
 
+/* Define if symbols declared in assembly code need an underscore prefix */
+#undef NEED_UNDERSCORE_PREFIX
+
 /* Define if you have the memmove function.  */
 #undef HAVE_MEMMOVE
 
diff --git a/include/dde_mem.h b/include/dde_mem.h
index b2c3079..bdcdf3e 100644
--- a/include/dde_mem.h
+++ b/include/dde_mem.h
@@ -23,12 +23,12 @@
     REL_PTR rel;
 }DDE_HWND;
 
-WORD DDE_SyncHandle(HGLOBAL handle, WORD sel);
+WORD DDE_SyncHandle(HGLOBAL16 handle, WORD sel);
 void *DDE_malloc(unsigned int flags,unsigned long size, SHMDATA *shmdata);
 HANDLE DDE_GlobalReAlloc(WORD,long,WORD);
-HGLOBAL DDE_GlobalFree(HGLOBAL block);
-void *DDE_AttachHandle(HGLOBAL handle, SEGPTR *segptr);
-WORD DDE_GlobalHandleToSel( HGLOBAL handle );
+HGLOBAL16 DDE_GlobalFree(HGLOBAL16 block);
+void *DDE_AttachHandle(HGLOBAL16 handle, SEGPTR *segptr);
+WORD DDE_GlobalHandleToSel( HGLOBAL16 handle );
 int DDE_GlobalUnlock(int);
 HANDLE DDE_GlobalSize(WORD);
 HANDLE DDE_GlobalHandle(WORD);
diff --git a/include/debug.h b/include/debug.h
index 8936cca..a36689e 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -28,6 +28,7 @@
 #undef DEBUG_COMBO
 #undef DEBUG_COMM
 #undef DEBUG_COMMDLG
+#undef DEBUG_CRTDLL
 #undef DEBUG_CURSOR
 #undef DEBUG_DC
 #undef DEBUG_DDE
@@ -105,6 +106,7 @@
 #define DEBUG_COMBO
 #define DEBUG_COMM
 #define DEBUG_COMMDLG
+#define DEBUG_CRTDLL
 #define DEBUG_CURSOR
 #define DEBUG_DC
 #define DEBUG_DDE
@@ -232,6 +234,11 @@
 #else
     0,
 #endif
+#ifdef DEBUG_CRTDLL
+    1,
+#else
+    0,
+#endif
 #ifdef DEBUG_CURSOR
     1,
 #else
@@ -706,8 +713,21 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_cursor if(!debug_msg_enabled[12]) ; else fprintf
-#define debugging_cursor debug_msg_enabled[12]
+#define dprintf_crtdll if(!debug_msg_enabled[12]) ; else fprintf
+#define debugging_crtdll debug_msg_enabled[12]
+#else
+#ifdef DEBUG_CRTDLL
+#define dprintf_crtdll fprintf
+#define debugging_crtdll 1
+#else
+#define dprintf_crtdll while(0) fprintf
+#define debugging_crtdll 0
+#endif
+#endif
+
+#ifdef DEBUG_RUNTIME
+#define dprintf_cursor if(!debug_msg_enabled[13]) ; else fprintf
+#define debugging_cursor debug_msg_enabled[13]
 #else
 #ifdef DEBUG_CURSOR
 #define dprintf_cursor fprintf
@@ -719,8 +739,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dc if(!debug_msg_enabled[13]) ; else fprintf
-#define debugging_dc debug_msg_enabled[13]
+#define dprintf_dc if(!debug_msg_enabled[14]) ; else fprintf
+#define debugging_dc debug_msg_enabled[14]
 #else
 #ifdef DEBUG_DC
 #define dprintf_dc fprintf
@@ -732,8 +752,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dde if(!debug_msg_enabled[14]) ; else fprintf
-#define debugging_dde debug_msg_enabled[14]
+#define dprintf_dde if(!debug_msg_enabled[15]) ; else fprintf
+#define debugging_dde debug_msg_enabled[15]
 #else
 #ifdef DEBUG_DDE
 #define dprintf_dde fprintf
@@ -745,8 +765,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dialog if(!debug_msg_enabled[15]) ; else fprintf
-#define debugging_dialog debug_msg_enabled[15]
+#define dprintf_dialog if(!debug_msg_enabled[16]) ; else fprintf
+#define debugging_dialog debug_msg_enabled[16]
 #else
 #ifdef DEBUG_DIALOG
 #define dprintf_dialog fprintf
@@ -758,8 +778,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dll if(!debug_msg_enabled[16]) ; else fprintf
-#define debugging_dll debug_msg_enabled[16]
+#define dprintf_dll if(!debug_msg_enabled[17]) ; else fprintf
+#define debugging_dll debug_msg_enabled[17]
 #else
 #ifdef DEBUG_DLL
 #define dprintf_dll fprintf
@@ -771,8 +791,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_dosfs if(!debug_msg_enabled[17]) ; else fprintf
-#define debugging_dosfs debug_msg_enabled[17]
+#define dprintf_dosfs if(!debug_msg_enabled[18]) ; else fprintf
+#define debugging_dosfs debug_msg_enabled[18]
 #else
 #ifdef DEBUG_DOSFS
 #define dprintf_dosfs fprintf
@@ -784,8 +804,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_driver if(!debug_msg_enabled[18]) ; else fprintf
-#define debugging_driver debug_msg_enabled[18]
+#define dprintf_driver if(!debug_msg_enabled[19]) ; else fprintf
+#define debugging_driver debug_msg_enabled[19]
 #else
 #ifdef DEBUG_DRIVER
 #define dprintf_driver fprintf
@@ -797,8 +817,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_edit if(!debug_msg_enabled[19]) ; else fprintf
-#define debugging_edit debug_msg_enabled[19]
+#define dprintf_edit if(!debug_msg_enabled[20]) ; else fprintf
+#define debugging_edit debug_msg_enabled[20]
 #else
 #ifdef DEBUG_EDIT
 #define dprintf_edit fprintf
@@ -810,8 +830,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_env if(!debug_msg_enabled[20]) ; else fprintf
-#define debugging_env debug_msg_enabled[20]
+#define dprintf_env if(!debug_msg_enabled[21]) ; else fprintf
+#define debugging_env debug_msg_enabled[21]
 #else
 #ifdef DEBUG_ENV
 #define dprintf_env fprintf
@@ -823,8 +843,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_event if(!debug_msg_enabled[21]) ; else fprintf
-#define debugging_event debug_msg_enabled[21]
+#define dprintf_event if(!debug_msg_enabled[22]) ; else fprintf
+#define debugging_event debug_msg_enabled[22]
 #else
 #ifdef DEBUG_EVENT
 #define dprintf_event fprintf
@@ -836,8 +856,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_exec if(!debug_msg_enabled[22]) ; else fprintf
-#define debugging_exec debug_msg_enabled[22]
+#define dprintf_exec if(!debug_msg_enabled[23]) ; else fprintf
+#define debugging_exec debug_msg_enabled[23]
 #else
 #ifdef DEBUG_EXEC
 #define dprintf_exec fprintf
@@ -849,8 +869,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_file if(!debug_msg_enabled[23]) ; else fprintf
-#define debugging_file debug_msg_enabled[23]
+#define dprintf_file if(!debug_msg_enabled[24]) ; else fprintf
+#define debugging_file debug_msg_enabled[24]
 #else
 #ifdef DEBUG_FILE
 #define dprintf_file fprintf
@@ -862,8 +882,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_fixup if(!debug_msg_enabled[24]) ; else fprintf
-#define debugging_fixup debug_msg_enabled[24]
+#define dprintf_fixup if(!debug_msg_enabled[25]) ; else fprintf
+#define debugging_fixup debug_msg_enabled[25]
 #else
 #ifdef DEBUG_FIXUP
 #define dprintf_fixup fprintf
@@ -875,8 +895,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_font if(!debug_msg_enabled[25]) ; else fprintf
-#define debugging_font debug_msg_enabled[25]
+#define dprintf_font if(!debug_msg_enabled[26]) ; else fprintf
+#define debugging_font debug_msg_enabled[26]
 #else
 #ifdef DEBUG_FONT
 #define dprintf_font fprintf
@@ -888,8 +908,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_gdi if(!debug_msg_enabled[26]) ; else fprintf
-#define debugging_gdi debug_msg_enabled[26]
+#define dprintf_gdi if(!debug_msg_enabled[27]) ; else fprintf
+#define debugging_gdi debug_msg_enabled[27]
 #else
 #ifdef DEBUG_GDI
 #define dprintf_gdi fprintf
@@ -901,8 +921,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_global if(!debug_msg_enabled[27]) ; else fprintf
-#define debugging_global debug_msg_enabled[27]
+#define dprintf_global if(!debug_msg_enabled[28]) ; else fprintf
+#define debugging_global debug_msg_enabled[28]
 #else
 #ifdef DEBUG_GLOBAL
 #define dprintf_global fprintf
@@ -914,8 +934,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_graphics if(!debug_msg_enabled[28]) ; else fprintf
-#define debugging_graphics debug_msg_enabled[28]
+#define dprintf_graphics if(!debug_msg_enabled[29]) ; else fprintf
+#define debugging_graphics debug_msg_enabled[29]
 #else
 #ifdef DEBUG_GRAPHICS
 #define dprintf_graphics fprintf
@@ -927,8 +947,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_heap if(!debug_msg_enabled[29]) ; else fprintf
-#define debugging_heap debug_msg_enabled[29]
+#define dprintf_heap if(!debug_msg_enabled[30]) ; else fprintf
+#define debugging_heap debug_msg_enabled[30]
 #else
 #ifdef DEBUG_HEAP
 #define dprintf_heap fprintf
@@ -940,8 +960,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_hook if(!debug_msg_enabled[30]) ; else fprintf
-#define debugging_hook debug_msg_enabled[30]
+#define dprintf_hook if(!debug_msg_enabled[31]) ; else fprintf
+#define debugging_hook debug_msg_enabled[31]
 #else
 #ifdef DEBUG_HOOK
 #define dprintf_hook fprintf
@@ -953,8 +973,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_icon if(!debug_msg_enabled[31]) ; else fprintf
-#define debugging_icon debug_msg_enabled[31]
+#define dprintf_icon if(!debug_msg_enabled[32]) ; else fprintf
+#define debugging_icon debug_msg_enabled[32]
 #else
 #ifdef DEBUG_ICON
 #define dprintf_icon fprintf
@@ -966,8 +986,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_int if(!debug_msg_enabled[32]) ; else fprintf
-#define debugging_int debug_msg_enabled[32]
+#define dprintf_int if(!debug_msg_enabled[33]) ; else fprintf
+#define debugging_int debug_msg_enabled[33]
 #else
 #ifdef DEBUG_INT
 #define dprintf_int fprintf
@@ -979,8 +999,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_key if(!debug_msg_enabled[33]) ; else fprintf
-#define debugging_key debug_msg_enabled[33]
+#define dprintf_key if(!debug_msg_enabled[34]) ; else fprintf
+#define debugging_key debug_msg_enabled[34]
 #else
 #ifdef DEBUG_KEY
 #define dprintf_key fprintf
@@ -992,8 +1012,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_keyboard if(!debug_msg_enabled[34]) ; else fprintf
-#define debugging_keyboard debug_msg_enabled[34]
+#define dprintf_keyboard if(!debug_msg_enabled[35]) ; else fprintf
+#define debugging_keyboard debug_msg_enabled[35]
 #else
 #ifdef DEBUG_KEYBOARD
 #define dprintf_keyboard fprintf
@@ -1005,8 +1025,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ldt if(!debug_msg_enabled[35]) ; else fprintf
-#define debugging_ldt debug_msg_enabled[35]
+#define dprintf_ldt if(!debug_msg_enabled[36]) ; else fprintf
+#define debugging_ldt debug_msg_enabled[36]
 #else
 #ifdef DEBUG_LDT
 #define dprintf_ldt fprintf
@@ -1018,8 +1038,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_listbox if(!debug_msg_enabled[36]) ; else fprintf
-#define debugging_listbox debug_msg_enabled[36]
+#define dprintf_listbox if(!debug_msg_enabled[37]) ; else fprintf
+#define debugging_listbox debug_msg_enabled[37]
 #else
 #ifdef DEBUG_LISTBOX
 #define dprintf_listbox fprintf
@@ -1031,8 +1051,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_local if(!debug_msg_enabled[37]) ; else fprintf
-#define debugging_local debug_msg_enabled[37]
+#define dprintf_local if(!debug_msg_enabled[38]) ; else fprintf
+#define debugging_local debug_msg_enabled[38]
 #else
 #ifdef DEBUG_LOCAL
 #define dprintf_local fprintf
@@ -1044,8 +1064,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mci if(!debug_msg_enabled[38]) ; else fprintf
-#define debugging_mci debug_msg_enabled[38]
+#define dprintf_mci if(!debug_msg_enabled[39]) ; else fprintf
+#define debugging_mci debug_msg_enabled[39]
 #else
 #ifdef DEBUG_MCI
 #define dprintf_mci fprintf
@@ -1057,8 +1077,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mcianim if(!debug_msg_enabled[39]) ; else fprintf
-#define debugging_mcianim debug_msg_enabled[39]
+#define dprintf_mcianim if(!debug_msg_enabled[40]) ; else fprintf
+#define debugging_mcianim debug_msg_enabled[40]
 #else
 #ifdef DEBUG_MCIANIM
 #define dprintf_mcianim fprintf
@@ -1070,8 +1090,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mciwave if(!debug_msg_enabled[40]) ; else fprintf
-#define debugging_mciwave debug_msg_enabled[40]
+#define dprintf_mciwave if(!debug_msg_enabled[41]) ; else fprintf
+#define debugging_mciwave debug_msg_enabled[41]
 #else
 #ifdef DEBUG_MCIWAVE
 #define dprintf_mciwave fprintf
@@ -1083,8 +1103,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mdi if(!debug_msg_enabled[41]) ; else fprintf
-#define debugging_mdi debug_msg_enabled[41]
+#define dprintf_mdi if(!debug_msg_enabled[42]) ; else fprintf
+#define debugging_mdi debug_msg_enabled[42]
 #else
 #ifdef DEBUG_MDI
 #define dprintf_mdi fprintf
@@ -1096,8 +1116,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_menu if(!debug_msg_enabled[42]) ; else fprintf
-#define debugging_menu debug_msg_enabled[42]
+#define dprintf_menu if(!debug_msg_enabled[43]) ; else fprintf
+#define debugging_menu debug_msg_enabled[43]
 #else
 #ifdef DEBUG_MENU
 #define dprintf_menu fprintf
@@ -1109,8 +1129,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_message if(!debug_msg_enabled[43]) ; else fprintf
-#define debugging_message debug_msg_enabled[43]
+#define dprintf_message if(!debug_msg_enabled[44]) ; else fprintf
+#define debugging_message debug_msg_enabled[44]
 #else
 #ifdef DEBUG_MESSAGE
 #define dprintf_message fprintf
@@ -1122,8 +1142,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_metafile if(!debug_msg_enabled[44]) ; else fprintf
-#define debugging_metafile debug_msg_enabled[44]
+#define dprintf_metafile if(!debug_msg_enabled[45]) ; else fprintf
+#define debugging_metafile debug_msg_enabled[45]
 #else
 #ifdef DEBUG_METAFILE
 #define dprintf_metafile fprintf
@@ -1135,8 +1155,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_midi if(!debug_msg_enabled[45]) ; else fprintf
-#define debugging_midi debug_msg_enabled[45]
+#define dprintf_midi if(!debug_msg_enabled[46]) ; else fprintf
+#define debugging_midi debug_msg_enabled[46]
 #else
 #ifdef DEBUG_MIDI
 #define dprintf_midi fprintf
@@ -1148,8 +1168,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmio if(!debug_msg_enabled[46]) ; else fprintf
-#define debugging_mmio debug_msg_enabled[46]
+#define dprintf_mmio if(!debug_msg_enabled[47]) ; else fprintf
+#define debugging_mmio debug_msg_enabled[47]
 #else
 #ifdef DEBUG_MMIO
 #define dprintf_mmio fprintf
@@ -1161,8 +1181,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmsys if(!debug_msg_enabled[47]) ; else fprintf
-#define debugging_mmsys debug_msg_enabled[47]
+#define dprintf_mmsys if(!debug_msg_enabled[48]) ; else fprintf
+#define debugging_mmsys debug_msg_enabled[48]
 #else
 #ifdef DEBUG_MMSYS
 #define dprintf_mmsys fprintf
@@ -1174,8 +1194,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmtime if(!debug_msg_enabled[48]) ; else fprintf
-#define debugging_mmtime debug_msg_enabled[48]
+#define dprintf_mmtime if(!debug_msg_enabled[49]) ; else fprintf
+#define debugging_mmtime debug_msg_enabled[49]
 #else
 #ifdef DEBUG_MMTIME
 #define dprintf_mmtime fprintf
@@ -1187,8 +1207,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_module if(!debug_msg_enabled[49]) ; else fprintf
-#define debugging_module debug_msg_enabled[49]
+#define dprintf_module if(!debug_msg_enabled[50]) ; else fprintf
+#define debugging_module debug_msg_enabled[50]
 #else
 #ifdef DEBUG_MODULE
 #define dprintf_module fprintf
@@ -1200,8 +1220,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_msg if(!debug_msg_enabled[50]) ; else fprintf
-#define debugging_msg debug_msg_enabled[50]
+#define dprintf_msg if(!debug_msg_enabled[51]) ; else fprintf
+#define debugging_msg debug_msg_enabled[51]
 #else
 #ifdef DEBUG_MSG
 #define dprintf_msg fprintf
@@ -1213,8 +1233,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_nonclient if(!debug_msg_enabled[51]) ; else fprintf
-#define debugging_nonclient debug_msg_enabled[51]
+#define dprintf_nonclient if(!debug_msg_enabled[52]) ; else fprintf
+#define debugging_nonclient debug_msg_enabled[52]
 #else
 #ifdef DEBUG_NONCLIENT
 #define dprintf_nonclient fprintf
@@ -1226,8 +1246,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ole if(!debug_msg_enabled[52]) ; else fprintf
-#define debugging_ole debug_msg_enabled[52]
+#define dprintf_ole if(!debug_msg_enabled[53]) ; else fprintf
+#define debugging_ole debug_msg_enabled[53]
 #else
 #ifdef DEBUG_OLE
 #define dprintf_ole fprintf
@@ -1239,8 +1259,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_palette if(!debug_msg_enabled[53]) ; else fprintf
-#define debugging_palette debug_msg_enabled[53]
+#define dprintf_palette if(!debug_msg_enabled[54]) ; else fprintf
+#define debugging_palette debug_msg_enabled[54]
 #else
 #ifdef DEBUG_PALETTE
 #define dprintf_palette fprintf
@@ -1252,8 +1272,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_profile if(!debug_msg_enabled[54]) ; else fprintf
-#define debugging_profile debug_msg_enabled[54]
+#define dprintf_profile if(!debug_msg_enabled[55]) ; else fprintf
+#define debugging_profile debug_msg_enabled[55]
 #else
 #ifdef DEBUG_PROFILE
 #define dprintf_profile fprintf
@@ -1265,8 +1285,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_prop if(!debug_msg_enabled[55]) ; else fprintf
-#define debugging_prop debug_msg_enabled[55]
+#define dprintf_prop if(!debug_msg_enabled[56]) ; else fprintf
+#define debugging_prop debug_msg_enabled[56]
 #else
 #ifdef DEBUG_PROP
 #define dprintf_prop fprintf
@@ -1278,8 +1298,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_reg if(!debug_msg_enabled[56]) ; else fprintf
-#define debugging_reg debug_msg_enabled[56]
+#define dprintf_reg if(!debug_msg_enabled[57]) ; else fprintf
+#define debugging_reg debug_msg_enabled[57]
 #else
 #ifdef DEBUG_REG
 #define dprintf_reg fprintf
@@ -1291,8 +1311,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_region if(!debug_msg_enabled[57]) ; else fprintf
-#define debugging_region debug_msg_enabled[57]
+#define dprintf_region if(!debug_msg_enabled[58]) ; else fprintf
+#define debugging_region debug_msg_enabled[58]
 #else
 #ifdef DEBUG_REGION
 #define dprintf_region fprintf
@@ -1304,8 +1324,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_relay if(!debug_msg_enabled[58]) ; else fprintf
-#define debugging_relay debug_msg_enabled[58]
+#define dprintf_relay if(!debug_msg_enabled[59]) ; else fprintf
+#define debugging_relay debug_msg_enabled[59]
 #else
 #ifdef DEBUG_RELAY
 #define dprintf_relay fprintf
@@ -1317,8 +1337,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_resource if(!debug_msg_enabled[59]) ; else fprintf
-#define debugging_resource debug_msg_enabled[59]
+#define dprintf_resource if(!debug_msg_enabled[60]) ; else fprintf
+#define debugging_resource debug_msg_enabled[60]
 #else
 #ifdef DEBUG_RESOURCE
 #define dprintf_resource fprintf
@@ -1330,8 +1350,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_scroll if(!debug_msg_enabled[60]) ; else fprintf
-#define debugging_scroll debug_msg_enabled[60]
+#define dprintf_scroll if(!debug_msg_enabled[61]) ; else fprintf
+#define debugging_scroll debug_msg_enabled[61]
 #else
 #ifdef DEBUG_SCROLL
 #define dprintf_scroll fprintf
@@ -1343,8 +1363,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_selector if(!debug_msg_enabled[61]) ; else fprintf
-#define debugging_selector debug_msg_enabled[61]
+#define dprintf_selector if(!debug_msg_enabled[62]) ; else fprintf
+#define debugging_selector debug_msg_enabled[62]
 #else
 #ifdef DEBUG_SELECTOR
 #define dprintf_selector fprintf
@@ -1356,8 +1376,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_sem if(!debug_msg_enabled[62]) ; else fprintf
-#define debugging_sem debug_msg_enabled[62]
+#define dprintf_sem if(!debug_msg_enabled[63]) ; else fprintf
+#define debugging_sem debug_msg_enabled[63]
 #else
 #ifdef DEBUG_SEM
 #define dprintf_sem fprintf
@@ -1369,8 +1389,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_shm if(!debug_msg_enabled[63]) ; else fprintf
-#define debugging_shm debug_msg_enabled[63]
+#define dprintf_shm if(!debug_msg_enabled[64]) ; else fprintf
+#define debugging_shm debug_msg_enabled[64]
 #else
 #ifdef DEBUG_SHM
 #define dprintf_shm fprintf
@@ -1382,8 +1402,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_stress if(!debug_msg_enabled[64]) ; else fprintf
-#define debugging_stress debug_msg_enabled[64]
+#define dprintf_stress if(!debug_msg_enabled[65]) ; else fprintf
+#define debugging_stress debug_msg_enabled[65]
 #else
 #ifdef DEBUG_STRESS
 #define dprintf_stress fprintf
@@ -1395,8 +1415,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_syscolor if(!debug_msg_enabled[65]) ; else fprintf
-#define debugging_syscolor debug_msg_enabled[65]
+#define dprintf_syscolor if(!debug_msg_enabled[66]) ; else fprintf
+#define debugging_syscolor debug_msg_enabled[66]
 #else
 #ifdef DEBUG_SYSCOLOR
 #define dprintf_syscolor fprintf
@@ -1408,8 +1428,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_task if(!debug_msg_enabled[66]) ; else fprintf
-#define debugging_task debug_msg_enabled[66]
+#define dprintf_task if(!debug_msg_enabled[67]) ; else fprintf
+#define debugging_task debug_msg_enabled[67]
 #else
 #ifdef DEBUG_TASK
 #define dprintf_task fprintf
@@ -1421,8 +1441,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_text if(!debug_msg_enabled[67]) ; else fprintf
-#define debugging_text debug_msg_enabled[67]
+#define dprintf_text if(!debug_msg_enabled[68]) ; else fprintf
+#define debugging_text debug_msg_enabled[68]
 #else
 #ifdef DEBUG_TEXT
 #define dprintf_text fprintf
@@ -1434,8 +1454,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_timer if(!debug_msg_enabled[68]) ; else fprintf
-#define debugging_timer debug_msg_enabled[68]
+#define dprintf_timer if(!debug_msg_enabled[69]) ; else fprintf
+#define debugging_timer debug_msg_enabled[69]
 #else
 #ifdef DEBUG_TIMER
 #define dprintf_timer fprintf
@@ -1447,8 +1467,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_toolhelp if(!debug_msg_enabled[69]) ; else fprintf
-#define debugging_toolhelp debug_msg_enabled[69]
+#define dprintf_toolhelp if(!debug_msg_enabled[70]) ; else fprintf
+#define debugging_toolhelp debug_msg_enabled[70]
 #else
 #ifdef DEBUG_TOOLHELP
 #define dprintf_toolhelp fprintf
@@ -1460,8 +1480,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_vxd if(!debug_msg_enabled[70]) ; else fprintf
-#define debugging_vxd debug_msg_enabled[70]
+#define dprintf_vxd if(!debug_msg_enabled[71]) ; else fprintf
+#define debugging_vxd debug_msg_enabled[71]
 #else
 #ifdef DEBUG_VXD
 #define dprintf_vxd fprintf
@@ -1473,8 +1493,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win if(!debug_msg_enabled[71]) ; else fprintf
-#define debugging_win debug_msg_enabled[71]
+#define dprintf_win if(!debug_msg_enabled[72]) ; else fprintf
+#define debugging_win debug_msg_enabled[72]
 #else
 #ifdef DEBUG_WIN
 #define dprintf_win fprintf
@@ -1486,8 +1506,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win32 if(!debug_msg_enabled[72]) ; else fprintf
-#define debugging_win32 debug_msg_enabled[72]
+#define dprintf_win32 if(!debug_msg_enabled[73]) ; else fprintf
+#define debugging_win32 debug_msg_enabled[73]
 #else
 #ifdef DEBUG_WIN32
 #define dprintf_win32 fprintf
@@ -1499,8 +1519,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_winsock if(!debug_msg_enabled[73]) ; else fprintf
-#define debugging_winsock debug_msg_enabled[73]
+#define dprintf_winsock if(!debug_msg_enabled[74]) ; else fprintf
+#define debugging_winsock debug_msg_enabled[74]
 #else
 #ifdef DEBUG_WINSOCK
 #define dprintf_winsock fprintf
@@ -1527,6 +1547,7 @@
     "combo",
     "comm",
     "commdlg",
+    "crtdll",
     "cursor",
     "dc",
     "dde",
diff --git a/include/driver.h b/include/driver.h
index 63e0651..a033802 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -54,7 +54,7 @@
     DRIVERPROC            lpDrvProc;
 } DRIVERITEM, *LPDRIVERITEM;
 
-LRESULT DefDriverProc(DWORD dwDevID, HDRVR hDriv, UINT16 wMsg, 
+LRESULT DefDriverProc(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, 
                       LPARAM dwParam1, LPARAM dwParam2);
 HDRVR16 OpenDriver(LPSTR szDriverName, LPSTR szSectionName, LPARAM lParam2);
 LRESULT CloseDriver(HDRVR16 hDriver, LPARAM lParam1, LPARAM lParam2);
diff --git a/include/kernel32.h b/include/kernel32.h
deleted file mode 100644
index ab3b567..0000000
--- a/include/kernel32.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/* kernel32.h - 95-09-14  Cameron Heide
- *
- * Win32 functions, structures, and types related to kernel functions
- */
-#ifndef __WINE_KERNEL32_H
-#define __WINE_KERNEL32_H
-
-#include <stddef.h>
-
-int KERN32_Init(void);
-void SetLastError(DWORD error);
-DWORD ErrnoToLastError(int errno_num);
-void ExitProcess(DWORD exitcode);
-
-/* Code page information.
- */
-typedef struct {
-        DWORD MaxCharSize;
-        BYTE DefaultChar[2];
-        BYTE LeadBytes[5];
-} CPINFO, *LPCPINFO;
-
-/* The 'overlapped' data structure used by async I/O functions.
- */
-typedef struct {
-        DWORD Internal;
-        DWORD InternalHigh;
-        DWORD Offset;
-        DWORD OffsetHigh;
-        HANDLE32 hEvent;
-} OVERLAPPED, *LPOVERLAPPED;
-
-/* Process startup information.
- */
-typedef struct {
-        DWORD cb;
-        LPSTR lpReserved;
-        LPSTR lpDesktop;
-        LPSTR lpTitle;
-        DWORD dwX;
-        DWORD dwY;
-        DWORD dwXSize;
-        DWORD dwYSize;
-        DWORD dwXCountChars;
-        DWORD dwYCountChars;
-        DWORD dwFillAttribute;
-        DWORD dwFlags;
-        WORD wShowWindow;
-        WORD cbReserved2;
-        BYTE *lpReserved2;
-        HANDLE32 hStdInput;
-        HANDLE32 hStdOutput;
-        HANDLE32 hStdError;
-} STARTUPINFO, *LPSTARTUPINFO;
-
-typedef struct {
-        LONG Bias;
-        WCHAR StandardName[32];
-        SYSTEMTIME StandardDate;
-        LONG StandardBias;
-        WCHAR DaylightName[32];
-        SYSTEMTIME DaylightDate;
-        LONG DaylightBias;
-} TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
-
-#define TIME_ZONE_ID_UNKNOWN    0
-#define TIME_ZONE_ID_STANDARD   1
-#define TIME_ZONE_ID_DAYLIGHT   2
-
-
-/* File object type definitions
- */
-#define FILE_TYPE_UNKNOWN       0
-#define FILE_TYPE_DISK          1
-#define FILE_TYPE_CHAR          2
-#define FILE_TYPE_PIPE          3
-#define FILE_TYPE_REMOTE        32768
-
-/* File creation flags
- */
-#define GENERIC_READ            0x80000000L
-#define GENERIC_WRITE           0x40000000L
-#define CREATE_NEW              1
-#define CREATE_ALWAYS           2
-#define OPEN_EXISTING           3
-#define OPEN_ALWAYS             4
-#define TRUNCATE_EXISTING       5
-
-/* Standard handle identifiers
- */
-#define STD_INPUT_HANDLE        ((DWORD) -10)
-#define STD_OUTPUT_HANDLE       ((DWORD) -11)
-#define STD_ERROR_HANDLE        ((DWORD) -12)
-
-typedef struct
-{
-  int dwFileAttributes;
-  FILETIME ftCreationTime;
-  FILETIME ftLastAccessTime;
-  FILETIME ftLastWriteTime;
-  int dwVolumeSerialNumber;
-  int nFileSizeHigh;
-  int nFileSizeLow;
-  int nNumberOfLinks;
-  int nFileIndexHigh;
-  int nFileIndexLow;
-} BY_HANDLE_FILE_INFORMATION ;
-
-/* File attribute flags
- */
-#define FILE_ATTRIBUTE_ARCHIVE          0x0020
-#define FILE_ATTRIBUTE_COMPRESSED       0x0800
-#define FILE_ATTRIBUTE_DIRECTORY        0x0010
-#define FILE_ATTRIBUTE_HIDDEN           0x0002
-#define FILE_ATTRIBUTE_NORMAL           0x0080
-#define FILE_ATTRIBUTE_READONLY         0x0001
-#define FILE_ATTRIBUTE_SYSTEM           0x0004
-#define FILE_ATTRIBUTE_TEMPORARY        0x0100
-#define FILE_ATTRIBUTE_ATOMIC_WRITE     0x0200
-#define FILE_ATTRIBUTE_XACTION_WRITE    0x0400
-
-BOOL32     SetTimeZoneInformation(const TIME_ZONE_INFORMATION*);
-
-#endif  /* __WINE_KERNEL32_H */
diff --git a/include/libres.h b/include/libres.h
index b7e9dcd..f1e9628 100644
--- a/include/libres.h
+++ b/include/libres.h
@@ -9,10 +9,10 @@
 #include "wintypes.h"
 #include "resource.h"
 
-extern INT     LIBRES_AccessResource( HINSTANCE hModule, HRSRC hRsrc );
-extern HGLOBAL LIBRES_AllocResource( HINSTANCE hModule, HRSRC hRsrc, DWORD size );
+extern INT     LIBRES_AccessResource( HINSTANCE hModule, HRSRC32 hRsrc );
+extern HGLOBAL32 LIBRES_AllocResource( HINSTANCE hModule, HRSRC32 hRsrc, DWORD size );
 extern HRSRC32 LIBRES_FindResource( HINSTANCE hModule, LPCSTR name, LPCSTR type );
-extern BOOL    LIBRES_FreeResource( HGLOBAL handle );
+extern BOOL    LIBRES_FreeResource( HGLOBAL32 handle );
 extern HGLOBAL32 LIBRES_LoadResource( HINSTANCE hModule, HRSRC32 hRsrc );
 extern LPVOID  LIBRES_LockResource( HGLOBAL32 handle );
 extern DWORD   LIBRES_SizeofResource( HINSTANCE hModule, HRSRC32 hRsrc );
diff --git a/include/metafile.h b/include/metafile.h
index 06f4e63..5e475c1 100644
--- a/include/metafile.h
+++ b/include/metafile.h
@@ -13,7 +13,7 @@
 #define MFVERSION 0x300
 #define META_EOF 0x0000
 
-HMETAFILE MF_WriteRecord(HMETAFILE hmf, METARECORD *mr, WORD rlen);
+HMETAFILE16 MF_WriteRecord(HMETAFILE16 hmf, METARECORD *mr, WORD rlen);
 int MF_AddHandle(HANDLETABLE16 *ht, WORD htlen, HANDLE hobj);
 int MF_AddHandleInternal(HANDLE hobj);
 BOOL MF_MetaParam0(DC *dc, short func);
diff --git a/include/mmsystem.h b/include/mmsystem.h
index 063e995..4d35773 100644
--- a/include/mmsystem.h
+++ b/include/mmsystem.h
@@ -108,7 +108,7 @@
 #define CALLBACK_TASK       0x00020000l    /* dwCallback is a HTASK */
 #define CALLBACK_FUNCTION   0x00030000l    /* dwCallback is a FARPROC */
 
-typedef void (*LPDRVCALLBACK) (HDRVR h, UINT uMessage, DWORD dwUser, DWORD dw1, DWORD dw2);
+typedef void (*LPDRVCALLBACK) (HDRVR16 h, UINT uMessage, DWORD dwUser, DWORD dw1, DWORD dw2);
 
 #define MM_MICROSOFT            1       /* Microsoft Corp. */
 
@@ -148,8 +148,8 @@
 #define WAVERR_SYNC           (WAVERR_BASE + 3)    /* device is synchronous */
 #define WAVERR_LASTERROR      (WAVERR_BASE + 3)    /* last error in range */
 
-typedef HWAVEIN *LPHWAVEIN;
-typedef HWAVEOUT *LPHWAVEOUT;
+typedef HWAVEIN16 *LPHWAVEIN16;
+typedef HWAVEOUT16 *LPHWAVEOUT16;
 typedef LPDRVCALLBACK LPWAVECALLBACK;
 
 #define WOM_OPEN        MM_WOM_OPEN
@@ -243,50 +243,50 @@
 UINT waveOutSetVolume(UINT uDeviceID, DWORD dwVolume);
 UINT waveOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
 UINT waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT waveOutOpen(HWAVEOUT * lphWaveOut, UINT uDeviceID,
+UINT waveOutOpen(HWAVEOUT16 * lphWaveOut, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT waveOutClose(HWAVEOUT hWaveOut);
-UINT waveOutPrepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutClose(HWAVEOUT16 hWaveOut);
+UINT waveOutPrepareHeader(HWAVEOUT16 hWaveOut,
      WAVEHDR * lpWaveOutHdr, UINT uSize);
-UINT waveOutUnprepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutUnprepareHeader(HWAVEOUT16 hWaveOut,
     WAVEHDR * lpWaveOutHdr, UINT uSize);
-UINT waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR * lpWaveOutHdr,
+UINT waveOutWrite(HWAVEOUT16 hWaveOut, WAVEHDR * lpWaveOutHdr,
     UINT uSize);
-UINT waveOutPause(HWAVEOUT hWaveOut);
-UINT waveOutRestart(HWAVEOUT hWaveOut);
-UINT waveOutReset(HWAVEOUT hWaveOut);
-UINT waveOutBreakLoop(HWAVEOUT hWaveOut);
-UINT waveOutGetPosition(HWAVEOUT hWaveOut, MMTIME * lpInfo,
+UINT waveOutPause(HWAVEOUT16 hWaveOut);
+UINT waveOutRestart(HWAVEOUT16 hWaveOut);
+UINT waveOutReset(HWAVEOUT16 hWaveOut);
+UINT waveOutBreakLoop(HWAVEOUT16 hWaveOut);
+UINT waveOutGetPosition(HWAVEOUT16 hWaveOut, MMTIME * lpInfo,
     UINT uSize);
-UINT waveOutGetPitch(HWAVEOUT hWaveOut, DWORD * lpdwPitch);
-UINT waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dwPitch);
-UINT waveOutGetPlaybackRate(HWAVEOUT hWaveOut, DWORD * lpdwRate);
-UINT waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dwRate);
-UINT waveOutGetID(HWAVEOUT hWaveOut, UINT * lpuDeviceID);
+UINT waveOutGetPitch(HWAVEOUT16 hWaveOut, DWORD * lpdwPitch);
+UINT waveOutSetPitch(HWAVEOUT16 hWaveOut, DWORD dwPitch);
+UINT waveOutGetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD * lpdwRate);
+UINT waveOutSetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD dwRate);
+UINT waveOutGetID(HWAVEOUT16 hWaveOut, UINT * lpuDeviceID);
 
-DWORD waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD waveOutMessage(HWAVEOUT16 hWaveOut, UINT uMessage, DWORD dw1, DWORD dw2);
 
 UINT waveInGetNumDevs(void);
 UINT waveInGetDevCaps(UINT uDeviceID, WAVEINCAPS * lpCaps,
     UINT uSize);
 UINT waveInGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT waveInOpen(HWAVEIN * lphWaveIn, UINT uDeviceID,
+UINT waveInOpen(HWAVEIN16 * lphWaveIn, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT waveInClose(HWAVEIN hWaveIn);
-UINT waveInPrepareHeader(HWAVEIN hWaveIn,
+UINT waveInClose(HWAVEIN16 hWaveIn);
+UINT waveInPrepareHeader(HWAVEIN16 hWaveIn,
     WAVEHDR * lpWaveInHdr, UINT uSize);
-UINT waveInUnprepareHeader(HWAVEIN hWaveIn,
+UINT waveInUnprepareHeader(HWAVEIN16 hWaveIn,
     WAVEHDR * lpWaveInHdr, UINT uSize);
-UINT waveInAddBuffer(HWAVEIN hWaveIn,
+UINT waveInAddBuffer(HWAVEIN16 hWaveIn,
     WAVEHDR * lpWaveInHdr, UINT uSize);
-UINT waveInStart(HWAVEIN hWaveIn);
-UINT waveInStop(HWAVEIN hWaveIn);
-UINT waveInReset(HWAVEIN hWaveIn);
-UINT waveInGetPosition(HWAVEIN hWaveIn, MMTIME * lpInfo,
+UINT waveInStart(HWAVEIN16 hWaveIn);
+UINT waveInStop(HWAVEIN16 hWaveIn);
+UINT waveInReset(HWAVEIN16 hWaveIn);
+UINT waveInGetPosition(HWAVEIN16 hWaveIn, MMTIME * lpInfo,
     UINT uSize);
-UINT waveInGetID(HWAVEIN hWaveIn, UINT * lpuDeviceID);
+UINT waveInGetID(HWAVEIN16 hWaveIn, UINT * lpuDeviceID);
 
-DWORD waveInMessage(HWAVEIN hWaveIn, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD waveInMessage(HWAVEIN16 hWaveIn, UINT uMessage, DWORD dw1, DWORD dw2);
 
 #define MIDIERR_UNPREPARED    (MIDIERR_BASE + 0)   /* header not prepared */
 #define MIDIERR_STILLPLAYING  (MIDIERR_BASE + 1)   /* still something playing */
@@ -296,8 +296,8 @@
 #define MIDIERR_INVALIDSETUP  (MIDIERR_BASE + 5)   /* invalid setup */
 #define MIDIERR_LASTERROR     (MIDIERR_BASE + 5)   /* last error in range */
 
-typedef HMIDIIN  *LPHMIDIIN;
-typedef HMIDIOUT  *LPHMIDIOUT;
+typedef HMIDIIN16  *LPHMIDIIN16;
+typedef HMIDIOUT16  *LPHMIDIOUT16;
 typedef LPDRVCALLBACK LPMIDICALLBACK;
 #define MIDIPATCHSIZE   128
 typedef WORD PATCHARRAY[MIDIPATCHSIZE];
@@ -376,44 +376,44 @@
 UINT midiOutSetVolume(UINT uDeviceID, DWORD dwVolume);
 UINT midiOutGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
 UINT midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT midiOutOpen(HMIDIOUT * lphMidiOut, UINT uDeviceID,
+UINT midiOutOpen(HMIDIOUT16 * lphMidiOut, UINT uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT midiOutClose(HMIDIOUT hMidiOut);
-UINT midiOutPrepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutClose(HMIDIOUT16 hMidiOut);
+UINT midiOutPrepareHeader(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT uSize);
-UINT midiOutUnprepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutUnprepareHeader(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT uSize);
-UINT midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg);
-UINT midiOutLongMsg(HMIDIOUT hMidiOut,
+UINT midiOutShortMsg(HMIDIOUT16 hMidiOut, DWORD dwMsg);
+UINT midiOutLongMsg(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT uSize);
-UINT midiOutReset(HMIDIOUT hMidiOut);
-UINT midiOutCachePatches(HMIDIOUT hMidiOut,
+UINT midiOutReset(HMIDIOUT16 hMidiOut);
+UINT midiOutCachePatches(HMIDIOUT16 hMidiOut,
     UINT uBank, WORD * lpwPatchArray, UINT uFlags);
-UINT midiOutCacheDrumPatches(HMIDIOUT hMidiOut,
+UINT midiOutCacheDrumPatches(HMIDIOUT16 hMidiOut,
     UINT uPatch, WORD * lpwKeyArray, UINT uFlags);
-UINT midiOutGetID(HMIDIOUT hMidiOut, UINT * lpuDeviceID);
+UINT midiOutGetID(HMIDIOUT16 hMidiOut, UINT * lpuDeviceID);
 
-DWORD midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD midiOutMessage(HMIDIOUT16 hMidiOut, UINT uMessage, DWORD dw1, DWORD dw2);
 
 UINT midiInGetNumDevs(void);
 UINT midiInGetDevCaps(UINT uDeviceID,
     LPMIDIINCAPS lpCaps, UINT uSize);
 UINT midiInGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-UINT midiInOpen(HMIDIIN * lphMidiIn, UINT uDeviceID,
+UINT midiInOpen(HMIDIIN16 * lphMidiIn, UINT uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT midiInClose(HMIDIIN hMidiIn);
-UINT midiInPrepareHeader(HMIDIIN hMidiIn,
+UINT midiInClose(HMIDIIN16 hMidiIn);
+UINT midiInPrepareHeader(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT uSize);
-UINT midiInUnprepareHeader(HMIDIIN hMidiIn,
+UINT midiInUnprepareHeader(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT uSize);
-UINT midiInAddBuffer(HMIDIIN hMidiIn,
+UINT midiInAddBuffer(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT uSize);
-UINT midiInStart(HMIDIIN hMidiIn);
-UINT midiInStop(HMIDIIN hMidiIn);
-UINT midiInReset(HMIDIIN hMidiIn);
-UINT midiInGetID(HMIDIIN hMidiIn, UINT * lpuDeviceID);
+UINT midiInStart(HMIDIIN16 hMidiIn);
+UINT midiInStop(HMIDIIN16 hMidiIn);
+UINT midiInReset(HMIDIIN16 hMidiIn);
+UINT midiInGetID(HMIDIIN16 hMidiIn, UINT * lpuDeviceID);
 
-DWORD midiInMessage(HMIDIIN hMidiIn, UINT uMessage, DWORD dw1, DWORD dw2);
+DWORD midiInMessage(HMIDIIN16 hMidiIn, UINT uMessage, DWORD dw1, DWORD dw2);
 
 #define AUX_MAPPER     (-1)
 
@@ -547,7 +547,7 @@
         /* other fields maintained by MMIO */
         DWORD           dwReserved1;    /* reserved for MMIO use */
         DWORD           dwReserved2;    /* reserved for MMIO use */
-        HMMIO           hmmio;          /* handle to open file */
+        HMMIO16         hmmio;          /* handle to open file */
 } MMIOINFO, *LPMMIOINFO;
 
 typedef struct _MMCKINFO
@@ -624,28 +624,28 @@
 FOURCC mmioStringToFOURCC(LPCSTR sz, UINT uFlags);
 LPMMIOPROC mmioInstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
     DWORD dwFlags);
-HMMIO mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo,
+HMMIO16 mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo,
     DWORD dwOpenFlags);
 
 UINT mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
      MMIOINFO * lpmmioinfo, DWORD dwRenameFlags);
 
-UINT mmioClose(HMMIO hmmio, UINT uFlags);
-LONG mmioRead(HMMIO hmmio, HPSTR pch, LONG cch);
-LONG mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch);
-LONG mmioSeek(HMMIO hmmio, LONG lOffset, int iOrigin);
-UINT mmioGetInfo(HMMIO hmmio, MMIOINFO * lpmmioinfo, UINT uFlags);
-UINT mmioSetInfo(HMMIO hmmio, const MMIOINFO * lpmmioinfo, UINT uFlags);
-UINT mmioSetBuffer(HMMIO hmmio, LPSTR pchBuffer, LONG cchBuffer,
+UINT mmioClose(HMMIO16 hmmio, UINT uFlags);
+LONG mmioRead(HMMIO16 hmmio, HPSTR pch, LONG cch);
+LONG mmioWrite(HMMIO16 hmmio, HPCSTR pch, LONG cch);
+LONG mmioSeek(HMMIO16 hmmio, LONG lOffset, int iOrigin);
+UINT mmioGetInfo(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT uFlags);
+UINT mmioSetInfo(HMMIO16 hmmio, const MMIOINFO * lpmmioinfo, UINT uFlags);
+UINT mmioSetBuffer(HMMIO16 hmmio, LPSTR pchBuffer, LONG cchBuffer,
     UINT uFlags);
-UINT mmioFlush(HMMIO hmmio, UINT uFlags);
-UINT mmioAdvance(HMMIO hmmio, MMIOINFO * lpmmioinfo, UINT uFlags);
-LONG mmioSendMessage(HMMIO hmmio, UINT uMessage,
+UINT mmioFlush(HMMIO16 hmmio, UINT uFlags);
+UINT mmioAdvance(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT uFlags);
+LONG mmioSendMessage(HMMIO16 hmmio, UINT uMessage,
     LPARAM lParam1, LPARAM lParam2);
-UINT mmioDescend(HMMIO hmmio, MMCKINFO * lpck,
+UINT mmioDescend(HMMIO16 hmmio, MMCKINFO * lpck,
     const MMCKINFO * lpckParent, UINT uFlags);
-UINT mmioAscend(HMMIO hmmio, MMCKINFO * lpck, UINT uFlags);
-UINT mmioCreateChunk(HMMIO hmmio, MMCKINFO * lpck, UINT uFlags);
+UINT mmioAscend(HMMIO16 hmmio, MMCKINFO * lpck, UINT uFlags);
+UINT mmioCreateChunk(HMMIO16 hmmio, MMCKINFO * lpck, UINT uFlags);
 
 typedef UINT (*YIELDPROC) (UINT uDeviceID, DWORD dwYieldData);
 
@@ -1476,19 +1476,19 @@
 typedef struct {
 	DWORD   	dwCallback;
 	DWORD   	dwInstance;
-	HMIDIOUT	hMidi;
+	HMIDIOUT16	hMidi;
 	DWORD   	dwFlags;
 } PORTALLOC, *LPPORTALLOC;
 
 typedef struct {
-	HWAVE			hWave;
+	HWAVE16			hWave;
 	LPWAVEFORMAT	lpFormat;
 	DWORD			dwCallBack;
 	DWORD			dwInstance;
 } WAVEOPENDESC, *LPWAVEOPENDESC;
 
 typedef struct {
-	HMIDI			hMidi;
+	HMIDI16			hMidi;
 	DWORD			dwCallback;
 	DWORD			dwInstance;
 } MIDIOPENDESC, *LPMIDIOPENDESC;
diff --git a/include/ole.h b/include/ole.h
index 9e3795d..a85f105 100644
--- a/include/ole.h
+++ b/include/ole.h
@@ -170,7 +170,7 @@
 	OLESTATUS	(*GetObject)(LPOLESERVERDOC,OLE_LPCSTR,LPOLEOBJECT*,LPOLECLIENT);
 	OLESTATUS	(*Release)(LPOLESERVERDOC);
 	OLESTATUS	(*SetColorScheme)(LPOLESERVERDOC,LPLOGPALETTE);
-	OLESTATUS	(*Execute)(LPOLESERVERDOC,HGLOBAL);
+	OLESTATUS	(*Execute)(LPOLESERVERDOC,HGLOBAL16);
 } OLESERVERDOCVTBL;
 typedef OLESERVERDOCVTBL*	LPOLESERVERDOCVTBL;
 typedef struct _OLESERVERDOC {
@@ -210,7 +210,7 @@
 	OLESTATUS	(*DoVerb)(LPOLEOBJECT,UINT,BOOL,BOOL);
 	OLESTATUS	(*GetData)(LPOLEOBJECT,OLECLIPFORMAT,HANDLE *);
 	OLESTATUS	(*SetData)(LPOLEOBJECT,OLECLIPFORMAT,HANDLE);
-	OLESTATUS	(*SetTargetDevice)(LPOLEOBJECT,HGLOBAL);
+	OLESTATUS	(*SetTargetDevice)(LPOLEOBJECT,HGLOBAL16);
 	OLESTATUS	(*SetBounds)(LPOLEOBJECT,LPRECT16);
 	OLESTATUS	(*EnumFormats)(LPOLEOBJECT,OLECLIPFORMAT);
 	OLESTATUS	(*SetColorScheme)(LPOLEOBJECT,LPLOGPALETTE);
@@ -223,7 +223,7 @@
 	OLESTATUS	(*CopyToClipBoard)(LPOLEOBJECT);
 	OLESTATUS	(*Draw)(LPOLEOBJECT,HDC,LPRECT16,LPRECT16,HDC);
 	OLESTATUS	(*Activate)(LPOLEOBJECT,UINT,BOOL,BOOL,HWND,LPRECT16);
-	OLESTATUS	(*Execute)(LPOLEOBJECT,HGLOBAL,UINT);
+	OLESTATUS	(*Execute)(LPOLEOBJECT,HGLOBAL16,UINT);
 	OLESTATUS	(*Close)(LPOLEOBJECT);
 	OLESTATUS	(*Update)(LPOLEOBJECT);
 	OLESTATUS	(*Reconnect)(LPOLEOBJECT);
diff --git a/include/queue.h b/include/queue.h
index 8743eb7..e861d85 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -68,6 +68,8 @@
 
 extern void QUEUE_DumpQueue( HQUEUE16 hQueue );
 extern void QUEUE_WalkQueues(void);
+extern HQUEUE16 QUEUE_GetDoomedQueue();
+extern void QUEUE_SetDoomedQueue( HQUEUE16 hQueue );
 extern MESSAGEQUEUE *QUEUE_GetSysQueue(void);
 extern void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit );
 extern void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit );
diff --git a/include/region.h b/include/region.h
index e73fc23..5aecf71 100644
--- a/include/region.h
+++ b/include/region.h
@@ -18,6 +18,7 @@
 
 
 extern BOOL16 REGION_DeleteObject( HRGN32 hrgn, RGNOBJ * obj );
+extern BOOL16 REGION_UnionRectWithRgn( HRGN32 hrgn, LPRECT16 lpRect );
 extern BOOL16 REGION_FrameRgn( HRGN32 dest, HRGN32 src, INT32 x, INT32 y );
 
 #endif  /* __WINE_REGION_H */
diff --git a/include/resource.h b/include/resource.h
index 7f202c0..e54ea95 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -43,15 +43,16 @@
 #define WINE_CONSTRUCTOR
 #endif
 
-extern int NE_AccessResource( HMODULE16 hModule, HRSRC hRsrc );
-extern BOOL NE_FreeResource( HMODULE16 hModule, HGLOBAL handle );
-extern HRSRC NE_FindResource( HMODULE16 hModule, SEGPTR typeId, SEGPTR resId );
-extern DWORD NE_SizeofResource( HMODULE16 hModule, HRSRC hRsrc );
-extern SEGPTR NE_LockResource( HMODULE16 hModule, HGLOBAL handle );
-extern HGLOBAL NE_AllocResource( HMODULE16 hModule, HRSRC hRsrc, DWORD size );
-extern HGLOBAL NE_LoadResource( HMODULE16 hModule,  HRSRC hRsrc );
+extern int NE_AccessResource( HMODULE16 hModule, HRSRC16 hRsrc );
+extern BOOL NE_FreeResource( HMODULE16 hModule, HGLOBAL16 handle );
+extern HRSRC16 NE_FindResource(HMODULE16 hModule, SEGPTR typeId, SEGPTR resId);
+extern DWORD NE_SizeofResource( HMODULE16 hModule, HRSRC16 hRsrc );
+extern SEGPTR NE_LockResource( HMODULE16 hModule, HGLOBAL16 handle );
+extern HGLOBAL16 NE_AllocResource( HMODULE16 hModule, HRSRC16 hRsrc,
+                                   DWORD size );
+extern HGLOBAL16 NE_LoadResource( HMODULE16 hModule,  HRSRC16 hRsrc );
 
-extern HANDLE SYSRES_LoadResource( SYSTEM_RESOURCE id );
-extern void SYSRES_FreeResource( HANDLE handle );
+extern HGLOBAL16 SYSRES_LoadResource( SYSTEM_RESOURCE id );
+extern void SYSRES_FreeResource( HGLOBAL16 handle );
 
 #endif /* __WINE_RESOURCE_H */
diff --git a/include/selectors.h b/include/selectors.h
index f5e3800..66495c7 100644
--- a/include/selectors.h
+++ b/include/selectors.h
@@ -16,5 +16,6 @@
 extern WORD SELECTOR_ReallocBlock( WORD sel, const void *base, DWORD size,
                                    enum seg_type type, BOOL32 is32bit,
                                    BOOL32 readonly );
+extern void SELECTOR_FreeBlock( WORD sel, WORD count );
 
 #endif /* __WINE_SELECTORS_H */
diff --git a/include/shell.h b/include/shell.h
index 045d2a0..565dbd0 100644
--- a/include/shell.h
+++ b/include/shell.h
@@ -9,7 +9,8 @@
 #include "windows.h"
 #include "winreg.h"
 
-extern INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon);
+extern INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
+                      HICON16 hIcon);
 extern void SHELL_LoadRegistry();
 extern void SHELL_SaveRegistry();
 extern void SHELL_Init();
diff --git a/include/static.h b/include/static.h
index dfe7148..b91fab9 100644
--- a/include/static.h
+++ b/include/static.h
@@ -12,9 +12,9 @@
   /* Extra info for STATIC windows */
 typedef struct
 {
-    HFONT  hFont;   /* Control font (or 0 for system font) */
-    WORD   dummy;   /* Don't know what MS-Windows puts in there */
-    HICON  hIcon;   /* Icon handle for SS_ICON controls */ 
+    HFONT16  hFont;   /* Control font (or 0 for system font) */
+    WORD     dummy;   /* Don't know what MS-Windows puts in there */
+    HICON16  hIcon;   /* Icon handle for SS_ICON controls */ 
 } STATICINFO;
 
 extern LRESULT StaticWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam );
diff --git a/include/status.h b/include/status.h
new file mode 100644
index 0000000..424394f
--- /dev/null
+++ b/include/status.h
@@ -0,0 +1,30 @@
+/*
+ * Status window definitions
+ *
+ * Copyright 1996 Bruce Milner
+ */
+
+#ifndef __WINE_STATUS_H
+#define __WINE_STATUS_H
+
+LRESULT StatusWindowProc( HWND32 hwnd, UINT32 msg,
+                          WPARAM32 wParam, LPARAM lParam );
+
+typedef struct
+{
+    INT32	x;
+    INT32	style;
+    RECT32	bound;
+    LPSTR	text;
+} STATUSWINDOWPART;
+
+typedef struct
+{
+    UINT16              numParts;
+    UINT16              textHeight;
+    BOOL32              simple;
+    STATUSWINDOWPART	part0;	/* simple window */
+    STATUSWINDOWPART   *parts;
+} STATUSWINDOWINFO;
+
+#endif  /* __WINE_STATUS_H */
diff --git a/include/stddebug.h b/include/stddebug.h
index fc531a9..8139e9c 100644
--- a/include/stddebug.h
+++ b/include/stddebug.h
@@ -88,6 +88,7 @@
 #undef DEBUG_COMBO
 #undef DEBUG_COMM
 #undef DEBUG_COMMDLG
+#undef DEBUG_CRTDLL
 #undef DEBUG_CURSOR
 #undef DEBUG_DC
 #undef DEBUG_DDE
@@ -165,6 +166,7 @@
 #define DEBUG_COMBO
 #define DEBUG_COMM
 #define DEBUG_COMMDLG
+#define DEBUG_CRTDLL
 #define DEBUG_CURSOR
 #define DEBUG_DC
 #define DEBUG_DDE
diff --git a/include/syscolor.h b/include/syscolor.h
index c1f75c7..a7b5809 100644
--- a/include/syscolor.h
+++ b/include/syscolor.h
@@ -11,27 +11,27 @@
 
 struct SysColorObjects
 {
-    HBRUSH hbrushScrollbar;        /* COLOR_SCROLLBAR           */
-                                   /* COLOR_BACKGROUND          */
-    HBRUSH hbrushActiveCaption;    /* COLOR_ACTIVECAPTION       */
-    HBRUSH hbrushInactiveCaption;  /* COLOR_INACTIVECAPTION     */
-    HBRUSH hbrushMenu;             /* COLOR_MENU                */
-    HBRUSH hbrushWindow;           /* COLOR_WINDOW              */
-    HPEN16 hpenWindowFrame;        /* COLOR_WINDOWFRAME         */
-                                   /* COLOR_MENUTEXT            */
-    HPEN16 hpenWindowText;         /* COLOR_WINDOWTEXT          */
-                                   /* COLOR_CAPTIONTEXT         */
-    HBRUSH hbrushActiveBorder;     /* COLOR_ACTIVEBORDER        */
-    HBRUSH hbrushInactiveBorder;   /* COLOR_INACTIVEBORDER      */
-                                   /* COLOR_APPWORKSPACE        */
-    HBRUSH hbrushHighlight;        /* COLOR_HIGHLIGHT           */
-                                   /* COLOR_HIGHLIGHTTEXT       */
-    HBRUSH hbrushBtnFace;          /* COLOR_BTNFACE             */
-    HBRUSH hbrushBtnShadow;        /* COLOR_BTNSHADOW           */
-                                   /* COLOR_GRAYTEXT            */
-                                   /* COLOR_BTNTEXT             */
-                                   /* COLOR_INACTIVECAPTIONTEXT */
-    HBRUSH hbrushBtnHighlight;     /* COLOR_BTNHIGHLIGHT        */
+    HBRUSH16 hbrushScrollbar;        /* COLOR_SCROLLBAR           */
+                                     /* COLOR_BACKGROUND          */
+    HBRUSH16 hbrushActiveCaption;    /* COLOR_ACTIVECAPTION       */
+    HBRUSH16 hbrushInactiveCaption;  /* COLOR_INACTIVECAPTION     */
+    HBRUSH16 hbrushMenu;             /* COLOR_MENU                */
+    HBRUSH16 hbrushWindow;           /* COLOR_WINDOW              */
+    HPEN16   hpenWindowFrame;        /* COLOR_WINDOWFRAME         */
+                                     /* COLOR_MENUTEXT            */
+    HPEN16   hpenWindowText;         /* COLOR_WINDOWTEXT          */
+                                     /* COLOR_CAPTIONTEXT         */
+    HBRUSH16 hbrushActiveBorder;     /* COLOR_ACTIVEBORDER        */
+    HBRUSH16 hbrushInactiveBorder;   /* COLOR_INACTIVEBORDER      */
+                                     /* COLOR_APPWORKSPACE        */
+    HBRUSH16 hbrushHighlight;        /* COLOR_HIGHLIGHT           */
+                                     /* COLOR_HIGHLIGHTTEXT       */
+    HBRUSH16 hbrushBtnFace;          /* COLOR_BTNFACE             */
+    HBRUSH16 hbrushBtnShadow;        /* COLOR_BTNSHADOW           */
+                                     /* COLOR_GRAYTEXT            */
+                                     /* COLOR_BTNTEXT             */
+                                     /* COLOR_INACTIVECAPTIONTEXT */
+    HBRUSH16 hbrushBtnHighlight;     /* COLOR_BTNHIGHLIGHT        */
 };
 
 extern void SYSCOLOR_Init(void);
diff --git a/include/winbase.h b/include/winbase.h
index 1583f35..536e73f 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -135,28 +135,30 @@
 
 typedef struct
 {
-    DWORD     FileAttributes;
-    FILETIME  CreationTime;
-    FILETIME  LastAccessTime;
-    FILETIME  LastWriteTime;
-    DWORD     FileSizeHigh;
-    DWORD     FileSizeLow;
-    DWORD     reserved[2];
-    CHAR      FileName[260];
-    CHAR      AlternateName[14];
+    DWORD     dwFileAttributes;
+    FILETIME  ftCreationTime;
+    FILETIME  ftLastAccessTime;
+    FILETIME  ftLastWriteTime;
+    DWORD     nFileSizeHigh;
+    DWORD     nFileSizeLow;
+    DWORD     dwReserved0;
+    DWORD     dwReserved1;
+    CHAR      cFileName[260];
+    CHAR      cAlternateFileName[14];
 } WIN32_FIND_DATA32A, *LPWIN32_FIND_DATA32A;
 
 typedef struct
 {
-    DWORD     FileAttributes;
-    FILETIME  CreationTime;
-    FILETIME  LastAccessTime;
-    FILETIME  LastWriteTime;
-    DWORD     FileSizeHigh;
-    DWORD     FileSizeLow;
-    DWORD     reserved[2];
-    WCHAR     FileName[260];
-    WCHAR     AlternateName[14];
+    DWORD     dwFileAttributes;
+    FILETIME  ftCreationTime;
+    FILETIME  ftLastAccessTime;
+    FILETIME  ftLastWriteTime;
+    DWORD     nFileSizeHigh;
+    DWORD     nFileSizeLow;
+    DWORD     dwReserved0;
+    DWORD     dwReserved1;
+    WCHAR     cFileName[260];
+    WCHAR     cAlternateName[14];
 } WIN32_FIND_DATA32W, *LPWIN32_FIND_DATA32W;
 
 DECL_WINELIB_TYPE_AW(WIN32_FIND_DATA);
diff --git a/include/windows.h b/include/windows.h
index 2e6fa9f..d1275cd 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -1795,6 +1795,7 @@
 #define RT_FONT 	    MAKEINTRESOURCE(8)
 #define RT_ACCELERATOR	    MAKEINTRESOURCE(9)
 #define RT_RCDATA	    MAKEINTRESOURCE(10)
+#define RT_MESSAGELIST      MAKEINTRESOURCE(11)
 #define RT_GROUP_CURSOR     MAKEINTRESOURCE(12)
 #define RT_GROUP_ICON	    MAKEINTRESOURCE(14)
 
@@ -3180,6 +3181,115 @@
         WORD wMilliseconds;
 } SYSTEMTIME, *LPSYSTEMTIME;
 
+
+/* Code page information.
+ */
+typedef struct {
+        DWORD MaxCharSize;
+        BYTE DefaultChar[2];
+        BYTE LeadBytes[5];
+} CPINFO, *LPCPINFO;
+
+/* The 'overlapped' data structure used by async I/O functions.
+ */
+typedef struct {
+        DWORD Internal;
+        DWORD InternalHigh;
+        DWORD Offset;
+        DWORD OffsetHigh;
+        HANDLE32 hEvent;
+} OVERLAPPED, *LPOVERLAPPED;
+
+/* Process startup information.
+ */
+typedef struct {
+        DWORD cb;
+        LPSTR lpReserved;
+        LPSTR lpDesktop;
+        LPSTR lpTitle;
+        DWORD dwX;
+        DWORD dwY;
+        DWORD dwXSize;
+        DWORD dwYSize;
+        DWORD dwXCountChars;
+        DWORD dwYCountChars;
+        DWORD dwFillAttribute;
+        DWORD dwFlags;
+        WORD wShowWindow;
+        WORD cbReserved2;
+        BYTE *lpReserved2;
+        HANDLE32 hStdInput;
+        HANDLE32 hStdOutput;
+        HANDLE32 hStdError;
+} STARTUPINFO, *LPSTARTUPINFO;
+
+typedef struct {
+        LONG Bias;
+        WCHAR StandardName[32];
+        SYSTEMTIME StandardDate;
+        LONG StandardBias;
+        WCHAR DaylightName[32];
+        SYSTEMTIME DaylightDate;
+        LONG DaylightBias;
+} TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
+
+#define TIME_ZONE_ID_UNKNOWN    0
+#define TIME_ZONE_ID_STANDARD   1
+#define TIME_ZONE_ID_DAYLIGHT   2
+
+
+/* File object type definitions
+ */
+#define FILE_TYPE_UNKNOWN       0
+#define FILE_TYPE_DISK          1
+#define FILE_TYPE_CHAR          2
+#define FILE_TYPE_PIPE          3
+#define FILE_TYPE_REMOTE        32768
+
+/* File creation flags
+ */
+#define GENERIC_READ            0x80000000L
+#define GENERIC_WRITE           0x40000000L
+#define CREATE_NEW              1
+#define CREATE_ALWAYS           2
+#define OPEN_EXISTING           3
+#define OPEN_ALWAYS             4
+#define TRUNCATE_EXISTING       5
+
+/* Standard handle identifiers
+ */
+#define STD_INPUT_HANDLE        ((DWORD) -10)
+#define STD_OUTPUT_HANDLE       ((DWORD) -11)
+#define STD_ERROR_HANDLE        ((DWORD) -12)
+
+typedef struct
+{
+  int dwFileAttributes;
+  FILETIME ftCreationTime;
+  FILETIME ftLastAccessTime;
+  FILETIME ftLastWriteTime;
+  int dwVolumeSerialNumber;
+  int nFileSizeHigh;
+  int nFileSizeLow;
+  int nNumberOfLinks;
+  int nFileIndexHigh;
+  int nFileIndexLow;
+} BY_HANDLE_FILE_INFORMATION ;
+
+/* File attribute flags
+ */
+#define FILE_ATTRIBUTE_ARCHIVE          0x0020
+#define FILE_ATTRIBUTE_COMPRESSED       0x0800
+#define FILE_ATTRIBUTE_DIRECTORY        0x0010
+#define FILE_ATTRIBUTE_HIDDEN           0x0002
+#define FILE_ATTRIBUTE_NORMAL           0x0080
+#define FILE_ATTRIBUTE_READONLY         0x0001
+#define FILE_ATTRIBUTE_SYSTEM           0x0004
+#define FILE_ATTRIBUTE_TEMPORARY        0x0100
+#define FILE_ATTRIBUTE_ATOMIC_WRITE     0x0200
+#define FILE_ATTRIBUTE_XACTION_WRITE    0x0400
+
+
 /* WinHelp internal structure */
 typedef struct {
 	WORD size;
@@ -3337,7 +3447,14 @@
 INT32      EnumPropsEx32W(HWND32,PROPENUMPROCEX32W,LPARAM);
 #define    EnumPropsEx WINELIB_NAME_AW(EnumPropsEx)
 BOOL32     EnumThreadWindows(DWORD,WNDENUMPROC32,LPARAM);
+void       ExitProcess(DWORD);
+HRSRC32    FindResourceEx32A(HINSTANCE32,LPCSTR,LPCSTR,WORD);
+HRSRC32    FindResourceEx32W(HINSTANCE32,LPCWSTR,LPCWSTR,WORD);
+#define    FindResourceEx WINELIB_NAME_AW(FindResourceEx)
 BOOL32     FlushFileBuffers(HFILE);
+LPCSTR     GetCommandLine32A();
+LPCWSTR    GetCommandLine32W();
+#define    GetCommandLine WINELIB_NAME_AW(GetCommandLine)
 BOOL32     GetCommTimeouts(HANDLE32,LPCOMMTIMEOUTS);
 DWORD      GetLogicalDrives(void);
 HANDLE32   GetProcessHeap(void);
@@ -3377,6 +3494,7 @@
 BOOL32     SetCommMask(HANDLE32,DWORD);
 BOOL32     SetCommTimeouts(HANDLE32,LPCOMMTIMEOUTS);
 BOOL32     SetBrushOrgEx(HDC32,INT32,INT32,LPPOINT32);
+BOOL32     SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION);
 LPVOID     VirtualAlloc(LPVOID,DWORD,DWORD,DWORD);
 BOOL32     VirtualFree(LPVOID,DWORD,DWORD);
 
@@ -3426,6 +3544,7 @@
 WORD       SetClassWord(HWND32,INT32,WORD);
 INT16      SetDIBits(HDC32,HBITMAP32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
 INT16      SetDIBitsToDevice(HDC32,INT32,INT32,DWORD,DWORD,INT32,INT32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
+void       SetLastError(DWORD); /* FIXME: not 100% sure about that */
 VOID       SetRectRgn(HRGN32,INT32,INT32,INT32,INT32);
 WORD       SetWindowWord(HWND32,INT32,WORD);
 BOOL16     ShowCaret(HWND32);
@@ -3822,6 +3941,9 @@
 BOOL16     GetUpdateRect16(HWND16,LPRECT16,BOOL16);
 BOOL32     GetUpdateRect32(HWND32,LPRECT32,BOOL32);
 #define    GetUpdateRect WINELIB_NAME(GetUpdateRect)
+LONG       GetVersion16(void);
+LONG       GetVersion32(void);
+#define    GetVersion WINELIB_NAME(GetVersion)
 BOOL16     GetViewportExtEx16(HDC16,LPPOINT16);
 BOOL32     GetViewportExtEx32(HDC32,LPPOINT32);
 #define    GetViewportExtEx WINELIB_NAME(GetViewportExtEx)
@@ -4310,6 +4432,8 @@
 
 /* Extra functions that don't exist in the Windows API */
 
+INT32      LoadMessage32A(HINSTANCE32,UINT32,WORD,LPSTR,INT32);
+INT32      LoadMessage32W(HINSTANCE32,UINT32,WORD,LPWSTR,INT32);
 INT32      lstrncmp32A(LPCSTR,LPCSTR,INT32);
 INT32      lstrncmp32W(LPCWSTR,LPCWSTR,INT32);
 INT32      lstrncmpi32A(LPCSTR,LPCSTR,INT32);
@@ -4331,26 +4455,12 @@
 typedef HANDLE32 HANDLE;
 typedef HANDLE32 HBITMAP;
 typedef HANDLE32 HBRUSH;
-typedef HANDLE32 HCURSOR;
 typedef HANDLE32 HDC;
-typedef HANDLE32 HDRVR;
 typedef HANDLE32 HFONT;
-typedef HANDLE32 HGLOBAL;
-typedef HANDLE32 HICON;
 typedef HANDLE32 HINSTANCE;
 typedef HANDLE32 HMENU;
-typedef HANDLE32 HMETAFILE;
-typedef HANDLE32 HMIDI;
-typedef HANDLE32 HMIDIIN;
-typedef HANDLE32 HMIDIOUT;
-typedef HANDLE32 HMMIO;
-typedef HANDLE32 HQUEUE;
 typedef HANDLE32 HRGN;
-typedef HANDLE32 HRSRC;
 typedef HANDLE32 HTASK;
-typedef HANDLE32 HWAVE;
-typedef HANDLE32 HWAVEIN;
-typedef HANDLE32 HWAVEOUT;
 typedef HANDLE32 HWND;
 # else  /* WINELIB32 */
 typedef INT16 INT;
@@ -4360,26 +4470,12 @@
 typedef HANDLE16 HANDLE;
 typedef HANDLE16 HBITMAP;
 typedef HANDLE16 HBRUSH;
-typedef HANDLE16 HCURSOR;
 typedef HANDLE16 HDC;
-typedef HANDLE16 HDRVR;
 typedef HANDLE16 HFONT;
-typedef HANDLE16 HGLOBAL;
-typedef HANDLE16 HICON;
 typedef HANDLE16 HINSTANCE;
 typedef HANDLE16 HMENU;
-typedef HANDLE16 HMETAFILE;
-typedef HANDLE16 HMIDI;
-typedef HANDLE16 HMIDIIN;
-typedef HANDLE16 HMIDIOUT;
-typedef HANDLE16 HMMIO;
-typedef HANDLE16 HQUEUE;
 typedef HANDLE16 HRGN;
-typedef HANDLE16 HRSRC;
 typedef HANDLE16 HTASK;
-typedef HANDLE16 HWAVE;
-typedef HANDLE16 HWAVEIN;
-typedef HANDLE16 HWAVEOUT;
 typedef HANDLE16 HWND;
 # endif  /* WINELIB32 */
 #endif  /* __WINE__ */
@@ -4387,7 +4483,7 @@
 /* Callback function pointers types. */
 
 #ifdef WINELIB
-typedef LONG (*DRIVERPROC)(DWORD, HDRVR, UINT, LPARAM, LPARAM);
+typedef LONG (*DRIVERPROC)(DWORD, HDRVR16, UINT, LPARAM, LPARAM);
 typedef int (*EDITWORDBREAKPROC)(LPSTR lpch, int ichCurrent, int cch,int code);
 #else
 typedef SEGPTR DRIVERPROC;
@@ -4421,23 +4517,23 @@
 INT        CheckMenuItem(HMENU,UINT,UINT);
 BOOL       Chord(HDC,INT,INT,INT,INT,INT,INT,INT,INT);
 BOOL       CloseClipboard(void);
-HMETAFILE  CloseMetaFile(HDC);
+HMETAFILE16 CloseMetaFile(HDC);
 void       CloseSound(void);
 BOOL       CloseWindow(HWND);
 int        ConvertRequest(HWND,LPKANJISTRUCT);
-HMETAFILE  CopyMetaFile(HMETAFILE,LPCSTR);
+HMETAFILE16 CopyMetaFile(HMETAFILE16,LPCSTR);
 INT        CountClipboardFormats(void);
 INT        CountVoiceNotes(INT);
 HBRUSH     CreateBrushIndirect(const LOGBRUSH16*);
 HDC        CreateCompatibleDC(HDC);
-HCURSOR    CreateCursor(HANDLE,INT,INT,INT,INT,const BYTE*,const BYTE*);
+HCURSOR16  CreateCursor(HANDLE,INT,INT,INT,INT,const BYTE*,const BYTE*);
 HANDLE     CreateCursorIconIndirect(HANDLE,CURSORICONINFO*,const BYTE*,const BYTE*);
 HDC        CreateDC(LPCSTR,LPCSTR,LPCSTR,const DEVMODE*);
-HBRUSH     CreateDIBPatternBrush(HGLOBAL,UINT);
+HBRUSH     CreateDIBPatternBrush(HGLOBAL16,UINT);
 HBITMAP    CreateDIBitmap(HDC,BITMAPINFOHEADER*,DWORD,LPVOID,BITMAPINFO*,UINT);
 HBRUSH     CreateHatchBrush(INT,COLORREF);
 HDC        CreateIC(LPCSTR,LPCSTR,LPCSTR,const DEVMODE*);
-HICON      CreateIcon(HINSTANCE,INT,INT,BYTE,BYTE,const BYTE*,const BYTE*);
+HICON16    CreateIcon(HINSTANCE,INT,INT,BYTE,BYTE,const BYTE*,const BYTE*);
 HMENU      CreateMenu(void);
 HDC        CreateMetaFile(LPCSTR);
 HPALETTE16 CreatePalette(const LOGPALETTE*);
@@ -4452,10 +4548,10 @@
 ATOM       DeleteAtom(ATOM);
 BOOL       DeleteDC(HDC);
 BOOL       DeleteMenu(HMENU,UINT,UINT);
-BOOL       DeleteMetaFile(HMETAFILE);
+BOOL       DeleteMetaFile(HMETAFILE16);
 BOOL       DeleteObject(HGDIOBJ16);
-BOOL       DestroyCursor(HCURSOR);
-BOOL       DestroyIcon(HICON);
+BOOL       DestroyCursor(HCURSOR16);
+BOOL       DestroyIcon(HICON16);
 BOOL       DestroyMenu(HMENU);
 BOOL       DestroyWindow(HWND);
 HANDLE     DirectResAlloc(HANDLE,WORD,WORD);
@@ -4465,8 +4561,8 @@
 BOOL       DlgDirSelect(HWND,LPSTR,INT);
 BOOL       DlgDirSelectComboBox(HWND,LPSTR,INT);
 BOOL16     DragDetect(HWND16,POINT16);
-DWORD      DragObject(HWND, HWND, WORD, HANDLE, WORD, HCURSOR);
-BOOL       DrawIcon(HDC,INT,INT,HICON);
+DWORD      DragObject(HWND, HWND, WORD, HANDLE, WORD, HCURSOR16);
+BOOL       DrawIcon(HDC,INT,INT,HICON16);
 void       DrawMenuBar(HWND);
 DWORD      DumpIcon(SEGPTR,WORD*,SEGPTR*,SEGPTR*);
 BOOL       Ellipse(HDC,INT,INT,INT,INT);
@@ -4479,13 +4575,13 @@
 UINT       EnumClipboardFormats(UINT);
 INT        EnumFontFamilies(HDC,LPCSTR,FONTENUMPROC16,LPARAM);
 INT        EnumFonts(HDC,LPCSTR,FONTENUMPROC16,LPARAM);
-BOOL       EnumMetaFile(HDC,HMETAFILE,MFENUMPROC16,LPARAM);
+BOOL       EnumMetaFile(HDC,HMETAFILE16,MFENUMPROC16,LPARAM);
 INT        EnumObjects(HDC,INT,GOBJENUMPROC16,LPARAM);
 INT        Escape(HDC,INT,INT,LPCSTR,LPVOID);
 int        ExcludeClipRect(HDC,short,short,short,short);
 int        ExcludeVisRect(HDC,short,short,short,short);
 BOOL       ExitWindows(DWORD,WORD);
-HICON      ExtractIcon(HINSTANCE,LPCSTR,WORD);
+HICON16    ExtractIcon(HINSTANCE,LPCSTR,WORD);
 void       FatalAppExit(UINT,LPCSTR);
 void       FatalExit(int);
 BOOL       FillRgn(HDC,HRGN,HBRUSH);
@@ -4518,7 +4614,7 @@
 HANDLE     GetCurrentPDB(void);
 DWORD      GetCurrentPosition(HDC);
 DWORD      GetCurrentTime(void);
-HCURSOR    GetCursor(void);
+HCURSOR16  GetCursor(void);
 HDC        GetDC(HWND);
 HDC        GetDCEx(HWND,HRGN,DWORD);
 DWORD      GetDCHook(HDC,FARPROC16*);
@@ -4608,7 +4704,6 @@
 LPINT16    GetThresholdEvent(void);
 int        GetThresholdStatus(void);
 HWND       GetTopWindow(HWND);
-LONG       GetVersion(void);
 DWORD      GetViewportExt(HDC);
 DWORD      GetViewportOrg(HDC);
 BOOL       GetWinDebugInfo(LPWINDEBUGINFO,UINT);
@@ -4656,6 +4751,7 @@
 BOOL       IsMenu(HMENU);
 BOOL       IsTask(HTASK);
 HTASK      IsTaskLocked(void);
+BOOL       IsValidMetaFile(HMETAFILE16);
 BOOL       IsWindowEnabled(HWND);
 BOOL       IsWindowVisible(HWND);
 BOOL       IsZoomed(HWND);
@@ -4730,7 +4826,7 @@
 void       SetConvertHook(BOOL);
 BOOL       SetConvertParams(int,int);
 BOOL32     SetCurrentDirectory(LPCSTR);
-HCURSOR    SetCursor(HCURSOR);
+HCURSOR16  SetCursor(HCURSOR16);
 void       SetCursorPos(short,short);
 BOOL       SetDCHook(HDC,FARPROC16,DWORD);
 void       SetDCState(HDC,HDC);
@@ -4767,7 +4863,7 @@
 WORD       SetSystemPaletteUse(HDC,WORD);
 BOOL       SetSystemPowerState(BOOL, BOOL);
 BOOL       SetSystemTime(const SYSTEMTIME*);
-HQUEUE     SetTaskQueue(HTASK,HQUEUE);
+HQUEUE16   SetTaskQueue(HTASK16,HQUEUE16);
 WORD       SetTextAlign(HDC,WORD);
 short      SetTextCharacterExtra(HDC,short);
 DWORD      SetTextColor(HDC,DWORD);
@@ -4787,7 +4883,7 @@
 void       ShowOwnedPopups(HWND,BOOL);
 void       ShowScrollBar(HWND,WORD,BOOL);
 BOOL       ShowWindow(HWND,int);
-DWORD      SizeofResource(HMODULE16,HRSRC);
+DWORD      SizeofResource(HMODULE16,HRSRC16);
 VOID       Sleep(DWORD); /* Win32 */
 int        StartSound(void);
 int        StopSound(void);
diff --git a/include/wintypes.h b/include/wintypes.h
index 5345511..93a6905 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -116,13 +116,13 @@
 typedef HKEY           *LPHKEY;
 typedef HMIXEROBJ      *LPHMIXEROBJ;
 
-/* Special case: a segmented pointer is just a pointer in the library. */
+/* Special case: a segmented pointer is just a pointer in the user's code. */
 
-#ifdef WINELIB
-typedef void* SEGPTR;
-#else  /* WINELIB */
+#ifdef __WINE__
 typedef DWORD SEGPTR;
-#endif /* WINELIB */
+#else
+typedef void* SEGPTR;
+#endif /* __WINE__ */
 
 /* Handle types that exist both in Win16 and Win32. */
 
diff --git a/ipc/dde_mem.c b/ipc/dde_mem.c
index 5e9c03d..5f10ede 100644
--- a/ipc/dde_mem.c
+++ b/ipc/dde_mem.c
@@ -55,7 +55,7 @@
  *   h    - the handle.
  * RETURN: pointer to handle info.
  */
-static struct handle_info *locate_handle(HGLOBAL h, struct local_shm_map *map)
+static struct handle_info *locate_handle(HGLOBAL16 h, struct local_shm_map *map)
 {
   struct shm_block *block;
   
@@ -79,7 +79,7 @@
 }
 
 /* dde_alloc_handle: allocate shared DDE handle */
-static HGLOBAL dde_alloc_handle()
+static HGLOBAL16 dde_alloc_handle()
 {
   int bit_nr;
 
@@ -101,7 +101,7 @@
     struct shm_block *block;
     struct handle_info *h_info;
     struct local_shm_map *curr;
-    HGLOBAL handle;
+    HGLOBAL16 handle;
     
     dprintf_global(stddeb,"DDE_malloc flags %4X, size %ld\n", flags, size);
     DDE_IPC_init();		/* make sure main shm block allocated */ 
@@ -167,7 +167,7 @@
     return (char *)HINFO2DATAPTR(h_info);
 }
 
-HGLOBAL DDE_GlobalFree(HGLOBAL h)
+HGLOBAL16 DDE_GlobalFree(HGLOBAL16 h)
 {
   struct handle_info *h_info;
   int handle_index= h & 0x7fff;
@@ -193,7 +193,7 @@
   return 0;
 }
 
-WORD DDE_SyncHandle(HGLOBAL handle, WORD sel)
+WORD DDE_SyncHandle(HGLOBAL16 handle, WORD sel)
     
 {
     struct handle_info *h_info;
@@ -228,12 +228,12 @@
  *   32 bit pointer to the memory.
  */
 
-void *DDE_AttachHandle(HGLOBAL handle, SEGPTR *segptr)
+void *DDE_AttachHandle(HGLOBAL16 handle, SEGPTR *segptr)
 {
   struct handle_info *h_info;
   SHMDATA shmdata;
   void *ptr;
-  HGLOBAL hOwner = GetCurrentPDB();
+  HGLOBAL16 hOwner = GetCurrentPDB();
 
   assert(is_dde_handle(handle));
   if (segptr != NULL)
diff --git a/ipc/wine_test_stub.c b/ipc/wine_test_stub.c
index 76cc952..4ecfa75 100644
--- a/ipc/wine_test_stub.c
+++ b/ipc/wine_test_stub.c
@@ -75,8 +75,8 @@
 }
 
 /* stub that partially emulates the true GLOBAL_CreateBlock function */
-HGLOBAL GLOBAL_CreateBlock( WORD flags, void *ptr, DWORD size,
-                            HGLOBAL hOwner, BOOL isCode,
+HGLOBAL16 GLOBAL_CreateBlock( WORD flags, void *ptr, DWORD size,
+                            HGLOBAL16 hOwner, BOOL isCode,
                             BOOL is32Bit, BOOL isReadOnly,
 			    SHMDATA *shmdata  )
 {
diff --git a/library/libres.c b/library/libres.c
index f7b450e..2093ee9 100644
--- a/library/libres.c
+++ b/library/libres.c
@@ -99,7 +99,7 @@
 /**********************************************************************
  *	    LIBRES_FreeResource    
  */
-BOOL LIBRES_FreeResource( HGLOBAL handle )
+BOOL LIBRES_FreeResource( HGLOBAL32 handle )
 {
   return 0; /* Obsolete in Win32 */
 }
@@ -108,7 +108,7 @@
 /**********************************************************************
  *	    LIBRES_AccessResource    
  */
-INT LIBRES_AccessResource( HINSTANCE hModule, HRSRC hRsrc )
+INT LIBRES_AccessResource( HINSTANCE hModule, HRSRC32 hRsrc )
 {
   WINELIB_UNIMP("LIBRES_AccessResource()");
   return -1; /* Obsolete in Win32 */
@@ -127,7 +127,7 @@
 /**********************************************************************
  *	    LIBRES_AllocResource    
  */
-HGLOBAL LIBRES_AllocResource( HINSTANCE hModule, HRSRC hRsrc, DWORD size )
+HGLOBAL32 LIBRES_AllocResource( HINSTANCE hModule, HRSRC32 hRsrc, DWORD size )
 {
   WINELIB_UNIMP("LIBRES_AllocResource()");
   return 0; /* Obsolete in Win32 */
diff --git a/loader/main.c b/loader/main.c
index 235faea..28f9987 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -16,7 +16,6 @@
 #include "comm.h"
 #include "win.h"
 #include "menu.h"
-#include "kernel32.h"
 #include "atom.h"
 #include "dialog.h"
 #include "directory.h"
@@ -59,6 +58,7 @@
     extern BOOL32 RELAY_Init(void);
     extern BOOL32 SIGNAL_Init(void);
     extern BOOL32 WIDGETS_Init(void);
+    extern int KERN32_Init(void);
 
     int queueSize;
 
diff --git a/loader/ne_image.c b/loader/ne_image.c
index a32007e..a900e83 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -20,6 +20,7 @@
 #include "arch.h"
 #include "selectors.h"
 #include "callback.h"
+#include "file.h"
 #include "module.h"
 #include "stackframe.h"
 #include "stddebug.h"
diff --git a/loader/ne_resource.c b/loader/ne_resource.c
index bd74e65..99e32b7 100644
--- a/loader/ne_resource.c
+++ b/loader/ne_resource.c
@@ -35,7 +35,7 @@
     NE_MODULE *pModule;
     NE_TYPEINFO *pTypeInfo;
     NE_NAMEINFO *pNameInfo;
-    HGLOBAL handle;
+    HGLOBAL16 handle;
     WORD *p;
     DWORD ret = 0;
     int count;
@@ -101,8 +101,8 @@
  *
  * Find a resource once the type info structure has been found.
  */
-static HRSRC NE_FindResourceFromType( NE_MODULE *pModule,
-                                      NE_TYPEINFO *pTypeInfo, SEGPTR resId )
+static HRSRC16 NE_FindResourceFromType( NE_MODULE *pModule,
+                                        NE_TYPEINFO *pTypeInfo, SEGPTR resId )
 {
     BYTE *p;
     int count;
@@ -117,7 +117,7 @@
             if (pNameInfo->id & 0x8000) continue;
             p = (BYTE *)pModule + pModule->res_table + pNameInfo->id;
             if ((*p == len) && !lstrncmpi32A( p+1, str, len ))
-                return (HRSRC)((int)pNameInfo - (int)pModule);
+                return (HRSRC16)((int)pNameInfo - (int)pModule);
         }
     }
     else  /* Numeric resource id */
@@ -125,7 +125,7 @@
         WORD id = LOWORD(resId) | 0x8000;
         for (count = pTypeInfo->count; count > 0; count--, pNameInfo++)
             if (pNameInfo->id == id) 
-	      return (HRSRC)((int)pNameInfo - (int)pModule);
+	      return (HRSRC16)((int)pNameInfo - (int)pModule);
     }
     return 0;
 }
@@ -134,10 +134,10 @@
 /***********************************************************************
  *           NE_FindResource
  */
-HRSRC NE_FindResource( HMODULE16 hModule, SEGPTR typeId, SEGPTR resId )
+HRSRC16 NE_FindResource( HMODULE16 hModule, SEGPTR typeId, SEGPTR resId )
 {
     NE_TYPEINFO *pTypeInfo;
-    HRSRC hRsrc;
+    HRSRC16 hRsrc;
 
     NE_MODULE *pModule = MODULE_GetPtr( hModule );
     if (!pModule || !pModule->res_table) return 0;
@@ -211,7 +211,7 @@
 /***********************************************************************
  *           NE_AllocResource
  */
-HGLOBAL NE_AllocResource( HMODULE16 hModule, HRSRC hRsrc, DWORD size )
+HGLOBAL16 NE_AllocResource( HMODULE16 hModule, HRSRC16 hRsrc, DWORD size )
 {
     NE_NAMEINFO *pNameInfo=NULL;
     WORD sizeShift;
@@ -231,7 +231,7 @@
 /***********************************************************************
  *           NE_AccessResource
  */
-int NE_AccessResource( HMODULE16 hModule, HRSRC hRsrc )
+int NE_AccessResource( HMODULE16 hModule, HRSRC16 hRsrc )
 {
     NE_NAMEINFO *pNameInfo=NULL;
     int fd;
@@ -254,7 +254,7 @@
 /***********************************************************************
  *           NE_SizeofResource
  */
-DWORD NE_SizeofResource( HMODULE16 hModule, HRSRC hRsrc )
+DWORD NE_SizeofResource( HMODULE16 hModule, HRSRC16 hRsrc )
 {
     NE_NAMEINFO *pNameInfo=NULL;
     WORD sizeShift;
@@ -272,7 +272,7 @@
 /***********************************************************************
  *           NE_LoadResource
  */
-HGLOBAL NE_LoadResource( HMODULE16 hModule,  HRSRC hRsrc )
+HGLOBAL16 NE_LoadResource( HMODULE16 hModule,  HRSRC16 hRsrc )
 {
     NE_NAMEINFO *pNameInfo=NULL;
     WORD sizeShift;
@@ -307,7 +307,7 @@
 /***********************************************************************
  *           NE_LockResource
  */
-SEGPTR NE_LockResource( HMODULE16 hModule, HGLOBAL handle )
+SEGPTR NE_LockResource( HMODULE16 hModule, HGLOBAL16 handle )
 {
     /* May need to reload the resource if discarded */
 
@@ -318,7 +318,7 @@
 /***********************************************************************
  *           NE_FreeResource
  */
-BOOL NE_FreeResource( HMODULE16 hModule, HGLOBAL handle )
+BOOL NE_FreeResource( HMODULE16 hModule, HGLOBAL16 handle )
 {
     NE_TYPEINFO *pTypeInfo;
     NE_NAMEINFO *pNameInfo;
diff --git a/loader/pe_resource.c b/loader/pe_resource.c
index fd3a302..1f9fa13 100644
--- a/loader/pe_resource.c
+++ b/loader/pe_resource.c
@@ -15,7 +15,6 @@
 #include <sys/types.h>
 #include "wintypes.h"
 #include "windows.h"
-#include "kernel32.h"
 #include "pe_image.h"
 #include "module.h"
 #include "handle32.h"
@@ -29,8 +28,6 @@
 #include "stddebug.h"
 #include "debug.h"
 
-int language = 0x0409;
-
 #define PrintIdA(name) \
     if (HIWORD((DWORD)name)) \
         dprintf_resource( stddeb, "'%s'", name); \
@@ -116,9 +113,11 @@
 }
 
 /**********************************************************************
- *	    PE_FindResource32W
+ *	    PE_FindResourceEx32W
  */
-HANDLE32 PE_FindResource32W( HINSTANCE hModule, LPCWSTR name, LPCWSTR type )
+HANDLE32 PE_FindResourceEx32W( 
+	HINSTANCE hModule, LPCWSTR name, LPCWSTR type, WORD lang
+)
 {
     PE_MODULE *pe;
     NE_MODULE *pModule;
@@ -142,7 +141,7 @@
 	return 0;
     if ((resdirptr = GetResDirEntryW(resdirptr, name, root)) == NULL)
 	return 0;
-    result = (HANDLE32)GetResDirEntryW(resdirptr, (LPCWSTR)language, root);
+    result = (HANDLE32)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT32)lang, root);
 	/* Try LANG_NEUTRAL, too */
     if(!result)
         return (HANDLE32)GetResDirEntryW(resdirptr, (LPCWSTR)0, root);
diff --git a/loader/resource.c b/loader/resource.c
index cea0057..d96398a 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -32,6 +32,7 @@
     else \
         dprintf_resource( stddeb, "#%04x", LOWORD(name)); 
 
+extern WORD WINE_LanguageId;
 
 /**********************************************************************
  *	    FindResource16    (KERNEL.60)
@@ -72,6 +73,15 @@
  */
 HANDLE32 FindResource32A( HINSTANCE32 hModule, LPCSTR name, LPCSTR type )
 {
+    return FindResourceEx32A(hModule,name,type,WINE_LanguageId);
+}
+
+/**********************************************************************
+ *	    FindResourceEx32A    (KERNEL32.129)
+ */
+HANDLE32 FindResourceEx32A(
+	HINSTANCE32 hModule,LPCSTR name,LPCSTR type,WORD lang
+) {
     LPWSTR xname,xtype;
     HANDLE32 ret;
 
@@ -79,7 +89,7 @@
     else xname = (LPWSTR)name;
     if (HIWORD((DWORD)type)) xtype = STRING32_DupAnsiToUni(type);
     else xtype = (LPWSTR)type;
-    ret = FindResource32W(hModule,xname,xtype);
+    ret = FindResourceEx32W(hModule,xname,xtype,lang);
     if (HIWORD((DWORD)name)) free(xname);
     if (HIWORD((DWORD)type)) free(xtype);
     return ret;
@@ -87,16 +97,14 @@
 
 
 /**********************************************************************
- *	    FindResource32W    (KERNEL32.131)
+ *	    FindResourceEx32W    (KERNEL32.130)
  */
-HRSRC32 FindResource32W( HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type )
-{
+HRSRC32 FindResourceEx32W(
+	HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type, WORD lang
+) {
 #ifndef WINELIB
     NE_MODULE *pModule;
 
-    /* Sometimes we get passed hModule = 0x00000000. FIXME: is GetTaskDS()
-     * ok?
-     */
     if (!hModule) hModule = GetTaskDS();
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "FindResource32W: module=%08x type=", hModule );
@@ -106,12 +114,20 @@
     dprintf_resource( stddeb, "\n" );
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
     if (!(pModule->flags & NE_FFLAGS_WIN32)) return 0;
-    return PE_FindResource32W(hModule,name,type);
+    return PE_FindResourceEx32W(hModule,name,type,lang);
 #else
     return LIBRES_FindResource( hModule, name, type );
 #endif
 }
 
+/**********************************************************************
+ *	    FindResource32W    (KERNEL32.131)
+ */
+HRSRC32 FindResource32W( HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type )
+{
+    return FindResourceEx32W(hModule,name,type,WINE_LanguageId);
+}
+
 
 /**********************************************************************
  *	    LoadResource16    (KERNEL.61)
@@ -642,11 +658,121 @@
 INT32
 LoadString32A(HINSTANCE32 instance,UINT32 resource_id,LPSTR buffer,int buflen)
 {
-    LPWSTR buffer2 = (LPWSTR)xmalloc(buflen*2);
+    LPWSTR buffer2 = buffer?(LPWSTR)xmalloc(buflen*2):NULL;
     INT32 retval = LoadString32W(instance,resource_id,buffer2,buflen);
 
-    STRING32_UniToAnsi(buffer,buffer2);
-    free(buffer2);
+    if (buffer) {
+	STRING32_UniToAnsi(buffer,buffer2);
+	free(buffer2);
+    }
+    return retval;
+}
+
+/* Messages...used by FormatMessage32* (KERNEL32.something)
+ * 
+ * They can be specified either directly or using a message ID and
+ * loading them from the resource.
+ * 
+ * The resourcedata has following format:
+ * start:
+ * 0: DWORD nrofentries
+ * nrofentries * subentry:
+ *	0: DWORD firstentry
+ *	4: DWORD lastentry
+ *      8: DWORD offset from start to the stringentries
+ *
+ * (lastentry-firstentry) * stringentry:
+ * 0: WORD len (0 marks end)
+ * 2: WORD unknown (flags?)
+ * 4: CHAR[len-4]
+ * 	(stringentry i of a subentry refers to the ID 'firstentry+i')
+ *
+ * Yes, ANSI strings in win32 resources. Go figure.
+ */
+
+/**********************************************************************
+ *	LoadMessage32A		(internal)
+ */
+INT32
+LoadMessage32A(
+	HINSTANCE32 instance,UINT32 id,WORD lang,LPSTR buffer,int buflen
+) {
+    HGLOBAL32	hmem;
+    HRSRC32	hrsrc;
+    BYTE	*p;
+    int		nrofentries,i,slen;
+    struct	_subentry {
+    	DWORD	firstentry;
+	DWORD	lastentry;
+	DWORD	offset;
+    } *se;
+    struct	_stringentry {
+    	WORD	len;
+	WORD	unknown;
+	CHAR	str[1];
+    } *stre;
+
+    dprintf_resource(stddeb, "LoadMessage: instance = %04x, id = %04x, buffer = %08x, "
+	   "length = %d\n", instance, (int)id, (int) buffer, buflen);
+
+    /*FIXME: I am not sure about the '1' ... But I've only seen those entries*/
+    hrsrc = FindResourceEx32W(instance,(LPWSTR)1,(LPCWSTR)RT_MESSAGELIST,lang);
+    if (!hrsrc) return 0;
+    hmem = LoadResource32( instance, hrsrc );
+    if (!hmem) return 0;
+    
+    p = LockResource32(hmem);
+    nrofentries = *(DWORD*)p;
+    stre = NULL;
+    se = (struct _subentry*)(p+4);
+    for (i=nrofentries;i--;) {
+    	if ((id>=se->firstentry) && (id<se->lastentry)) {
+	    stre = (struct _stringentry*)(p+se->offset);
+	    id	-= se->firstentry;
+	    break;
+	}
+	se++;
+    }
+    if (!stre)
+    	return 0;
+    for (i=id;i--;) {
+    	if (!(slen=stre->len))
+		return 0;
+    	stre = (struct _stringentry*)(((char*)stre)+slen);
+    }
+    slen=stre->len;
+    dprintf_resource(stddeb,"	- strlen=%d\n",slen);
+    i = MIN(buflen - 1, slen);
+    if (buffer == NULL)
+	return slen; /* different to LoadString */
+    if (i>0) {
+	lstrcpyn32A(buffer,stre->str,i);
+	buffer[i]=0;
+    } else {
+	if (buflen>1) {
+	    buffer[0]=0;
+	    return 0;
+	}
+    }
+    if (buffer)
+	    dprintf_resource(stddeb,"LoadMessage // '%s' copied !\n", buffer);
+    return i;
+}
+
+/**********************************************************************
+ *	LoadMessage32W	(internal)
+ */
+INT32
+LoadMessage32W(
+	HINSTANCE32 instance,UINT32 id,WORD lang,LPWSTR buffer,int buflen
+) {
+    LPSTR buffer2 = buffer?(LPSTR)xmalloc(buflen):NULL;
+    INT32 retval = LoadMessage32A(instance,id,lang,buffer2,buflen);
+
+    if (buffer) {
+	STRING32_AnsiToUni(buffer,buffer2);
+	free(buffer2);
+    }
     return retval;
 }
 
diff --git a/loader/task.c b/loader/task.c
index b1bea0d..4eb6234 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -38,7 +38,7 @@
   /* Must not be greater than 64k, or MAKE_SEGPTR won't work */
 #define STACK32_SIZE 0x10000
 
-extern void USER_AppExit(HTASK, HINSTANCE, HQUEUE );
+extern void USER_AppExit( HTASK16, HINSTANCE16, HQUEUE16 );
 
   /* Saved 16-bit stack for current process (Win16 only) */
 WORD IF1632_Saved16_ss = 0;
@@ -254,7 +254,7 @@
  * Create a thunk free-list in segment 'handle', starting from offset 'offset'
  * and containing 'count' entries.
  */
-static void TASK_CreateThunks( HGLOBAL handle, WORD offset, WORD count )
+static void TASK_CreateThunks( HGLOBAL16 handle, WORD offset, WORD count )
 {
     int i;
     WORD free;
@@ -1030,9 +1030,9 @@
 /***********************************************************************
  *           SetTaskQueue  (KERNEL.34)
  */
-HQUEUE SetTaskQueue( HANDLE hTask, HQUEUE hQueue )
+HQUEUE16 SetTaskQueue( HTASK16 hTask, HQUEUE16 hQueue )
 {
-    HQUEUE hPrev;
+    HQUEUE16 hPrev;
     TDB *pTask;
 
     if (!hTask) hTask = hCurrentTask;
diff --git a/memory/global.c b/memory/global.c
index f88d129..c7a06cc 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -111,7 +111,7 @@
 
     if (!(pArena = GLOBAL_GetArena( sel, selcount )))
     {
-        FreeSelector( sel );
+        SELECTOR_FreeBlock( sel, selcount );
         return 0;
     }
 
@@ -159,11 +159,13 @@
 BOOL16 GLOBAL_FreeBlock( HGLOBAL16 handle )
 {
     WORD sel;
+    GLOBALARENA *pArena;
 
     if (!handle) return TRUE;
-    sel = GlobalHandleToSel( handle );
-    if (FreeSelector( sel )) return FALSE;  /* failed */
-    memset( GET_ARENA_PTR(sel), 0, sizeof(GLOBALARENA) );
+    sel = GlobalHandleToSel( handle ); 
+    pArena = GET_ARENA_PTR(sel);
+    SELECTOR_FreeBlock( sel, (pArena->size + 0xffff) / 0x10000 );
+    memset( pArena, 0, sizeof(GLOBALARENA) );
     return TRUE;
 }
 
@@ -226,7 +228,7 @@
  * Find the arena  for a given handle
  * (when handle is not serial - e.g. DDE)
  */
-static GLOBALARENA *GLOBAL_FindArena( HGLOBAL handle)
+static GLOBALARENA *GLOBAL_FindArena( HGLOBAL16 handle)
 {
     int i;
     for (i = globalArenaSize-1 ; i>=0 ; i--) {
@@ -241,7 +243,7 @@
  *           DDE_GlobalHandleToSel
  */
 
-WORD DDE_GlobalHandleToSel( HGLOBAL handle )
+WORD DDE_GlobalHandleToSel( HGLOBAL16 handle )
 {
     GLOBALARENA *pArena;
     SEGPTR segptr;
@@ -341,7 +343,7 @@
     ptr = HeapReAlloc( SystemHeap, 0, ptr, size );
     if (!ptr)
     {
-        FreeSelector( sel );
+        SELECTOR_FreeBlock( sel, (oldsize + 0xffff) / 0x10000 );
         memset( pArena, 0, sizeof(GLOBALARENA) );
         return 0;
     }
@@ -360,7 +362,7 @@
     if (!(pNewArena = GLOBAL_GetArena( sel, selcount )))
     {
         HeapFree( SystemHeap, 0, ptr );
-        FreeSelector( sel );
+        SELECTOR_FreeBlock( sel, selcount );
         return 0;
     }
 
diff --git a/memory/heap.c b/memory/heap.c
index 5c3573c..d2f25af 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -10,7 +10,6 @@
 #include <string.h>
 #include "windows.h"
 #include "debugger.h"
-#include "kernel32.h"  /* for CRITICAL_SECTION */
 #include "selectors.h"
 #include "winbase.h"
 #include "winerror.h"
diff --git a/memory/selector.c b/memory/selector.c
index ecf7df4..bec8469 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -64,31 +64,8 @@
  */
 WORD FreeSelector( WORD sel )
 {
-    WORD i, count, nextsel;
-    ldt_entry entry;
-    STACK16FRAME *frame;
-
-    dprintf_selector( stddeb, "FreeSelector(%04x)\n", sel );
     if (IS_SELECTOR_FREE(sel)) return sel;  /* error */
-    count = (GET_SEL_LIMIT(sel) >> 16) + 1;
-    sel &= ~(__AHINCR - 1);  /* clear bottom bits of selector */
-    nextsel = sel + (count << __AHSHIFT);
-    memset( &entry, 0, sizeof(entry) );  /* clear the LDT entries */
-    /* FIXME: is it correct to free the whole array? */
-    for (i = SELECTOR_TO_ENTRY(sel); count; i++, count--)
-    {
-        LDT_SetEntry( i, &entry );
-        ldt_flags_copy[i] &= ~LDT_FLAGS_ALLOCATED;
-    }
-
-    /* Clear the saved 16-bit selector */
-    frame = CURRENT_STACK16;
-    while (frame)
-    {
-        if ((frame->ds >= sel) && (frame->ds < nextsel)) frame->ds = 0;
-        if ((frame->es >= sel) && (frame->es < nextsel)) frame->es = 0;
-	frame = PTR_SEG_OFF_TO_LIN(frame->saved_ss, frame->saved_sp);
-    }
+    SELECTOR_FreeBlock( sel, 1 );
     return 0;
 }
 
@@ -147,6 +124,38 @@
 
 
 /***********************************************************************
+ *           SELECTOR_FreeBlock
+ *
+ * Free a block of selectors.
+ */
+void SELECTOR_FreeBlock( WORD sel, WORD count )
+{
+    WORD i, nextsel;
+    ldt_entry entry;
+    STACK16FRAME *frame;
+
+    dprintf_selector( stddeb, "SELECTOR_FreeBlock(%04x,%d)\n", sel, count );
+    sel &= ~(__AHINCR - 1);  /* clear bottom bits of selector */
+    nextsel = sel + (count << __AHSHIFT);
+    memset( &entry, 0, sizeof(entry) );  /* clear the LDT entries */
+    for (i = SELECTOR_TO_ENTRY(sel); count; i++, count--)
+    {
+        LDT_SetEntry( i, &entry );
+        ldt_flags_copy[i] &= ~LDT_FLAGS_ALLOCATED;
+    }
+
+    /* Clear the saved 16-bit selector */
+    frame = CURRENT_STACK16;
+    while (frame)
+    {
+        if ((frame->ds >= sel) && (frame->ds < nextsel)) frame->ds = 0;
+        if ((frame->es >= sel) && (frame->es < nextsel)) frame->es = 0;
+	frame = PTR_SEG_OFF_TO_LIN(frame->saved_ss, frame->saved_sp);
+    }
+}
+
+
+/***********************************************************************
  *           SELECTOR_ReallocBlock
  *
  * Change the size of a block of selectors.
@@ -155,7 +164,6 @@
                            enum seg_type type, BOOL32 is32bit, BOOL32 readonly)
 {
     WORD i, oldcount, newcount;
-    ldt_entry entry;
 
     if (!size) size = 1;
     oldcount = (GET_SEL_LIMIT(sel) >> 16) + 1;
@@ -171,7 +179,7 @@
 
         if (i < newcount)  /* they are not free */
         {
-            FreeSelector( sel );
+            SELECTOR_FreeBlock( sel, oldcount );
             sel = AllocSelectorArray( newcount );
         }
         else  /* mark the selectors as allocated */
@@ -182,12 +190,8 @@
     }
     else if (oldcount > newcount) /* We need to remove selectors */
     {
-        memset( &entry, 0, sizeof(entry) );  /* clear the LDT entries */
-        for (i = oldcount; i < newcount; i++)
-        {
-            LDT_SetEntry( SELECTOR_TO_ENTRY(sel) + i, &entry );
-            ldt_flags_copy[SELECTOR_TO_ENTRY(sel) + i] &= ~LDT_FLAGS_ALLOCATED;
-        }
+        SELECTOR_FreeBlock( ENTRY_TO_SELECTOR(SELECTOR_TO_ENTRY(sel)+newcount),
+                            oldcount - newcount );
     }
     if (sel) SELECTOR_SetEntries( sel, base, size, type, is32bit, readonly );
     return sel;
diff --git a/misc/Makefile.in b/misc/Makefile.in
index a3acb9e..0d9d3a9 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -7,6 +7,7 @@
 	comm.c \
 	commdlg.c \
 	compobj.c \
+	crtdll.c \
 	driver.c \
 	exec.c \
 	escape.c \
diff --git a/misc/commdlg.c b/misc/commdlg.c
index 723d577..bc1a62e 100644
--- a/misc/commdlg.c
+++ b/misc/commdlg.c
@@ -1571,7 +1571,7 @@
  HBRUSH hbrush;
  HDC hdc ;
  RECT16 rect,client;
- HCURSOR hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
+ HCURSOR16 hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
 
  GetClientRect16(hwnd,&client);
  hdc=GetDC(hwnd);
@@ -2383,7 +2383,7 @@
   int i,j,res,init=0;
   long l;
   LPLOGFONT16 lpxx;
-  HCURSOR hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
+  HCURSOR16 hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
   LPCHOOSEFONT lpcf;
 
   SetWindowLong32A(hDlg, DWL_USER, lParam); 
@@ -2635,7 +2635,7 @@
 		      i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL,0,0);
 		      if (i!=CB_ERR)
 		      {
-		        HCURSOR hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
+		        HCURSOR16 hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
                         SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT,i,(LPARAM)MAKE_SEGPTR(buffer));
 	                dprintf_commdlg(stddeb,"WM_COMMAND/cmb1 =>%s\n",buffer);
        		        EnumFontFamilies(hdc,buffer,FontStyleEnumProc,
diff --git a/misc/crtdll.c b/misc/crtdll.c
new file mode 100644
index 0000000..e73d8c2
--- /dev/null
+++ b/misc/crtdll.c
@@ -0,0 +1,178 @@
+/*
+ * The C RunTime DLL
+ * 
+ * Implements C run-time functionality as known from UNIX.
+ *
+ * Copyright 1996 Marcus Meissner
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <ctype.h>
+#include "win.h"
+#include "windows.h"
+#include "stddebug.h"
+#include "debug.h"
+#include "module.h"
+#include "callback.h"
+#include "xmalloc.h"
+
+UINT32 CRTDLL_argc_dll;         /* CRTDLL.23 */
+LPSTR *CRTDLL_argv_dll;         /* CRTDLL.24 */
+LPSTR  CRTDLL_acmdln_dll;       /* CRTDLL.38 */
+UINT32 CRTDLL_basemajor_dll;    /* CRTDLL.42 */
+UINT32 CRTDLL_baseminor_dll;    /* CRTDLL.43 */
+UINT32 CRTDLL_baseversion_dll;  /* CRTDLL.44 */
+LPSTR  CRTDLL_environ_dll;      /* CRTDLL.75 */
+UINT32 CRTDLL_osmajor_dll;      /* CRTDLL.241 */
+UINT32 CRTDLL_osminor_dll;      /* CRTDLL.242 */
+UINT32 CRTDLL_osver_dll;        /* CRTDLL.244 */
+UINT32 CRTDLL_osversion_dll;    /* CRTDLL.245 */
+UINT32 CRTDLL_winmajor_dll;     /* CRTDLL.329 */
+UINT32 CRTDLL_winminor_dll;     /* CRTDLL.330 */
+UINT32 CRTDLL_winver_dll;       /* CRTDLL.331 */
+
+DWORD
+CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,LPSTR *environ,DWORD flag)
+{
+        char *cmdline;
+        char  **xargv;
+	int	xargc,i,afterlastspace;
+	DWORD	version;
+
+	dprintf_crtdll(stderr,"__GetMainArgs(%p,%p,%p,%ld).\n",
+		argc,argv,environ,flag
+	);
+	CRTDLL_acmdln_dll = cmdline = xstrdup( GetCommandLine32A() );
+
+	version	= GetVersion32();
+	CRTDLL_osver_dll       = version >> 16;
+	CRTDLL_winminor_dll    = version & 0xFF;
+	CRTDLL_winmajor_dll    = (version>>8) & 0xFF;
+	CRTDLL_baseversion_dll = version >> 16;
+	CRTDLL_winver_dll      = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
+	CRTDLL_baseminor_dll   = (version >> 16) & 0xFF;
+	CRTDLL_basemajor_dll   = (version >> 24) & 0xFF;
+	CRTDLL_osversion_dll   = version & 0xFFFF;
+	CRTDLL_osminor_dll     = version & 0xFF;
+	CRTDLL_osmajor_dll     = (version>>8) & 0xFF;
+
+	/* missing heapinit */
+	/* missing threading init */
+
+	i=0;xargv=NULL;xargc=0;afterlastspace=0;
+	while (cmdline[i]) {
+		if (cmdline[i]==' ') {
+			xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc));
+			cmdline[i]='\0';
+			xargv[xargc-1] = xstrdup(cmdline+afterlastspace);
+			i++;
+			while (cmdline[i]==' ')
+				i++;
+			if (cmdline[i])
+				afterlastspace=i;
+		} else
+			i++;
+	}
+	xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc));
+	cmdline[i]='\0';
+	xargv[xargc-1] = xstrdup(cmdline+afterlastspace);
+	CRTDLL_argc_dll	= xargc;
+	*argc		= xargc;
+	CRTDLL_argv_dll	= xargv;
+	*argv		= xargv;
+
+	/* FIXME ... use real environment */
+	*environ	= xmalloc(sizeof(LPSTR));
+	CRTDLL_environ_dll = *environ;
+	(*environ)[0] = NULL;
+	return 0;
+}
+
+typedef void (*_INITTERMFUN)();
+DWORD
+CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
+{
+	_INITTERMFUN	*current;
+
+	dprintf_crtdll(stddeb,"_initterm(%p,%p)\n",start,end);
+	current=start;
+	while (current<end) {
+		if (*current)
+			_InitTermProc(*current);
+		current++;
+	}
+	return 0;
+}
+
+void
+CRTDLL_srand(DWORD seed) {
+	/* FIXME: should of course be thread? process? local */
+	srand(seed);
+}
+
+int
+CRTDLL_fprintf(DWORD *args) {
+	/* FIXME: use args[0] */
+	return vfprintf(stderr,(LPSTR)(args[1]),args+2);
+}
+
+int
+CRTDLL_printf(DWORD *args) {
+	return vfprintf(stdout,(LPSTR)(args[0]),args+1);
+}
+
+time_t
+CRTDLL_time(time_t *timeptr) {
+	time_t	curtime = time(NULL);
+
+	if (timeptr)
+		*timeptr = curtime;
+	return curtime;
+}
+
+BOOL32
+CRTDLL__isatty(DWORD x) {
+	dprintf_crtdll(stderr,"CRTDLL__isatty(%ld)\n",x);
+	return TRUE;
+}
+
+INT32
+CRTDLL__write(DWORD x,LPVOID buf,DWORD len) {
+	if (x<=2)
+		return write(x,buf,len);
+	/* hmm ... */
+	dprintf_crtdll(stderr,"CRTDLL__write(%ld,%p,%ld)\n",x,buf,len);
+	return len;
+}
+
+void
+CRTDLL_exit(DWORD ret) {
+	dprintf_crtdll(stderr,"CRTDLL_exit(%ld)\n",ret);
+	ExitProcess(ret);
+}
+
+void
+CRTDLL_fflush(DWORD x) {
+	dprintf_crtdll(stderr,"CRTDLL_fflush(%ld)\n",x);
+}
+
+/* BAD, for the whole WINE process blocks... just done this way to test
+ * windows95's ftp.exe.
+ */
+LPSTR 
+CRTDLL_gets(LPSTR buf) {
+	return gets(buf);
+}
+
+CHAR
+CRTDLL_toupper(CHAR x) {
+	return toupper(x);
+}
+
+void
+CRTDLL_putchar(INT32 x) {
+	putchar(x);
+}
diff --git a/misc/driver.c b/misc/driver.c
index 4cc9043..e09113b 100644
--- a/misc/driver.c
+++ b/misc/driver.c
@@ -211,7 +211,7 @@
 /**************************************************************************
  *				DefDriverProc			[USER.255]
  */
-LRESULT DefDriverProc(DWORD dwDevID, HDRVR hDriv, UINT16 wMsg, 
+LRESULT DefDriverProc(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, 
 		      LPARAM lParam1, LPARAM lParam2)
 {
     switch(wMsg)
diff --git a/misc/lstr.c b/misc/lstr.c
index fc0de18..9f2d01c 100644
--- a/misc/lstr.c
+++ b/misc/lstr.c
@@ -559,6 +559,8 @@
  */
 BOOL32 CharToOem32A(LPSTR s,LPSTR d)
 {
+    if (!s || !d)
+    	return TRUE;
     AnsiToOem(s,d);
     return TRUE;
 }
@@ -633,8 +635,8 @@
 }
 
 /***********************************************************************
- *           FormatMessageA   (KERNEL32.138)
- * FIXME: missing wrap, function has no clue about varargs handling
+ *           FormatMessageA   (KERNEL32.138) Library Version
+ * FIXME: missing wrap,FROM_SYSTEM message-loading,
  */
 DWORD
 FormatMessage32A(
@@ -644,29 +646,36 @@
 	DWORD	dwLanguageId,
 	LPSTR	lpBuffer,
 	DWORD	nSize,
-	LPDWORD	*Arguments /* va_list *Arguments */
+	LPDWORD	args /* va_list *args */
 ) {
 	LPSTR	target,t;
 	DWORD	talloced;
 	LPSTR	from,f;
 	DWORD	width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
+	DWORD	nolinefeed = 0;
 
-	fprintf(stddeb,"FormatMessage32A(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n",
-		dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,
-		nSize,Arguments
+	dprintf_resource(stddeb,
+		"FormatMessage32A(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n",
+		dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args
 	);
 	if (width) 
 		fprintf(stdnimp,"	- line wrapping not supported.\n");
 	from = NULL;
 	if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
-		from = (LPSTR)lpSource;
+		from = xstrdup((LPSTR)lpSource);
 	if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
 		/* gather information from system message tables ... */
 		fprintf(stdnimp,"	- FORMAT_MESSAGE_FROM_SYSTEM not implemented.\n");
 	}
 	if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
-		/* gather information from module's message tables ... */
-		fprintf(stdnimp,"	- FORMAT_MESSAGE_FROM_HMODULE not implemented.\n");
+		INT32	bufsize;
+
+		dwMessageId &= 0xFFFF;
+		bufsize=LoadMessage32A(0,dwMessageId,dwLanguageId,NULL,100);
+		if (bufsize) {
+			from = (char*)xmalloc(bufsize+1);
+			LoadMessage32A(0,dwMessageId,dwLanguageId,from,bufsize+1);
+		}
 	}
 	target	= (char*)xmalloc(100);
 	t	= target;
@@ -683,12 +692,11 @@
 
 	if (from) {
 		f=from;
-		fprintf(stddeb,"	from is %s\n",from);
 		while (*f) {
 			if (*f=='%') {
 				int	insertnr;
 				char	*fmtstr,*sprintfbuf,*x;
-				DWORD	arg1,arg2,arg3;
+				DWORD	*argliststart;
 
 				f++;
 				if (!*f) {
@@ -705,47 +713,35 @@
 					case '8':case '9':
 						f++;
 						insertnr=insertnr*10+*f-'0';
+						f++;
 						break;
-					default:break;
+					default:
+						f++;
+						break;
 					}
-					if (f[1]=='!') {
-						f+=2;
+					if (*f=='!') {
+						f++;
 						if (NULL!=(x=strchr(f,'!'))) {
 							*x='\0';
-							fmtstr=strdup(f);
+							fmtstr=xmalloc(strlen(f)+2);
+							sprintf(fmtstr,"%%%s",f);
 							f=x+1;
 						}
-					} else {
+					} else
 						fmtstr=strdup("%s");
-					}
+					if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY)
+						argliststart=args+insertnr-1;
+					else
+						/* FIXME: not sure that this is
+						 * correct for unix-c-varargs.
+						 */
+						argliststart=((DWORD*)&args)+insertnr-1;
 
-					if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) {
-						DWORD	*args = (DWORD*)Arguments;
-						arg1 = args[insertnr-1];
-						arg2 = args[insertnr+0];
-						arg3 = args[insertnr+1];
-					} else {
-						/* 
-						int	i;
-						va_list	vl;
-
-						vl=va_start(Arguments,7);
-						for (i=insertnr;i--;)
-							va_arg(vl,DWORD);
-						arg1 = va_arg(vl,DWORD);
-						arg2 = va_arg(vl,DWORD);
-						arg3 = va_arg(vl,DWORD);
-						va_end(vl);
-						*/
-						fprintf(stdnimp,"	- varargs not supported yet.\n");
-					}
-
-					if (fmtstr[strlen(fmtstr)]=='s') {
-						sprintfbuf=(char*)xmalloc(strlen((LPSTR)arg1)+1);
-					} else {
+					if (fmtstr[strlen(fmtstr)]=='s')
+						sprintfbuf=(char*)xmalloc(strlen((LPSTR)argliststart[0])+1);
+					else
 						sprintfbuf=(char*)xmalloc(100);
-					}
-					sprintf(sprintfbuf,fmtstr,arg1,arg2,arg3);
+					vsprintf(sprintfbuf,fmtstr,argliststart);
 					x=sprintfbuf;
 					while (*x) {
 						ADD_TO_T(*x++);
@@ -753,6 +749,10 @@
 					free(sprintfbuf);
 					free(fmtstr);
 					break;
+				case '0':
+					nolinefeed=1;
+					f++;
+					break;
 				default:ADD_TO_T(*f++)
 					break;
 
@@ -763,6 +763,8 @@
 		}
 		*t='\0';
 	}
+	if (!nolinefeed && t[-1]!='\n')
+		ADD_TO_T('\n');
 	talloced = strlen(target)+1;
 	if (nSize && talloced<nSize) {
 		target = (char*)xrealloc(target,nSize);
@@ -774,5 +776,46 @@
 	} else
 		strncpy(lpBuffer,target,nSize);
 	free(target);
-	return strlen(lpBuffer);
+	if (from) free(from);
+	return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ? 
+			strlen(*(LPSTR*)lpBuffer):
+			strlen(lpBuffer);
+}
+
+/***********************************************************************
+ *           FormatMessageA   (KERNEL32.138) Emulator Version
+ */
+DWORD
+WIN32_FormatMessage32A(DWORD *args) {
+	DWORD	dwFlags		= args[0];
+	LPCVOID	lpSource	= (LPCVOID)args[1];
+	DWORD	dwMessageId	= args[2];
+	DWORD	dwLanguageId	= args[3];
+	LPSTR	lpBuffer	= (LPSTR)args[4];
+	DWORD	nSize		= args[5];
+	DWORD	*xargs;
+
+	/* convert possible varargs to an argument array look-a-like */
+
+	if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) {
+		xargs=(DWORD*)args[6];
+	} else {
+		/* args[6] is a pointer to a pointer to the start of 
+		 * a list of arguments.
+		 */
+		if (args[6])
+			xargs=(DWORD*)(((DWORD*)args[6])[0]);
+		else
+			xargs=NULL;
+		dwFlags|=FORMAT_MESSAGE_ARGUMENT_ARRAY;
+	}
+	return FormatMessage32A(
+		dwFlags,
+		lpSource,
+		dwMessageId,
+		dwLanguageId,
+		lpBuffer,
+		nSize,
+		xargs
+	);
 }
diff --git a/misc/main.c b/misc/main.c
index 690775e..c02aaea 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -55,22 +55,27 @@
 "Jan Willamowius, Carl Williams, Karl Guenter Wuensch, Eric Youngdale, "
 "and James Youngman. ";
 
-const char * langNames[] =
+const struct _langentry {
+	char *name;
+	WORD langid;
+} languages[] =
 {
-    "En",  /* LANG_En */
-    "Es",  /* LANG_Es */
-    "De",  /* LANG_De */
-    "No",  /* LANG_No */
-    "Fr",  /* LANG_Fr */
-    "Fi",  /* LANG_Fi */
-    "Da",  /* LANG_Da */
-    "Cz",  /* LANG_Cz */
-    "Eo",  /* LANG_Eo */
-    "It",  /* LANG_It */
-    "Ko",  /* LANG_Ko */
-    NULL
+    {"En",0x0409},	/* LANG_En */
+    {"Es",0x040A},	/* LANG_Es */
+    {"De",0x0407},	/* LANG_De */
+    {"No",0x0414},	/* LANG_No */
+    {"Fr",0x0400},	/* LANG_Fr */
+    {"Fi",0x040B},	/* LANG_Fi */
+    {"Da",0x0406},	/* LANG_Da */
+    {"Cz",0x0405},	/* LANG_Cz */
+    {"Eo",     0},	/* LANG_Eo */ /* FIXME languageid */
+    {"It",0x0410},	/* LANG_It */
+    {"Ko",0x0412},	/* LANG_Ko */
+    {NULL,0}
 };
 
+WORD WINE_LanguageId = 0;
+
 #define WINE_CLASS    "Wine"    /* Class name for resources */
 
 typedef struct tagENVENTRY {
@@ -284,16 +289,19 @@
  */
 static void MAIN_ParseLanguageOption( char *arg )
 {
-    const char **p = langNames;
+    const struct _langentry *p = languages;
 
     Options.language = LANG_En;  /* First language */
-    for (p = langNames; *p; p++)
+    for (;p->name;p++)
     {
-        if (!lstrcmpi32A( *p, arg )) return;
+        if (!lstrcmpi32A( p->name, arg )) {
+	    WINE_LanguageId = p->langid;
+	    return;
+	}
         Options.language++;
     }
     fprintf( stderr, "Invalid language specified '%s'. Supported languages are: ", arg );
-    for (p = langNames; *p; p++) fprintf( stderr, "%s ", *p );
+    for (p = languages; p->name; p++) fprintf( stderr, "%s ", p->name );
     fprintf( stderr, "\n" );
     exit(1);
 }
@@ -678,9 +686,9 @@
 
 
 /***********************************************************************
- *      GetVersion (KERNEL.3)
+ *      GetVersion16   (KERNEL.3)
  */
-LONG GetVersion(void)
+LONG GetVersion16(void)
 {
     if (getVersion16) return getVersion16;
     return MAKELONG( WINVERSION, WINDOSVER );
diff --git a/misc/registry.c b/misc/registry.c
index 31c41a8..6064937 100644
--- a/misc/registry.c
+++ b/misc/registry.c
@@ -19,6 +19,7 @@
 #include "windows.h"
 #include "win.h"
 #include "winerror.h"
+#include "file.h"
 #include "string32.h"	
 #include "stddebug.h"
 #include "debug.h"
diff --git a/misc/shell.c b/misc/shell.c
index e9dbbcb..0f146e1 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -124,6 +124,7 @@
     HINSTANCE retval=31;    /* default - 'No association was found' */
     char *tok;              /* token pointer */
     int i;                  /* random counter */
+    char xlpFile[256];          /* result of SearchPath */
 
     dprintf_exec(stddeb, "SHELL_FindExecutable: File %s, Dir %s\n", 
 		 (lpFile != NULL?lpFile:"-"), 
@@ -132,18 +133,19 @@
     lpResult[0]='\0'; /* Start off with an empty return string */
 
     /* trap NULL parameters on entry */
-    if (( lpFile == NULL ) || ( lpDirectory == NULL ) || 
-	( lpResult == NULL ) || ( lpOperation == NULL ))
+    if (( lpFile == NULL ) || ( lpResult == NULL ) || ( lpOperation == NULL ))
     {
 	/* FIXME - should throw a warning, perhaps! */
 	return 2; /* File not found. Close enough, I guess. */
     }
+    if (SearchPath32A(lpDirectory,lpFile,NULL,sizeof(xlpFile),xlpFile,NULL))
+    	lpFile = xlpFile;
 
     /* First thing we need is the file's extension */
-    extension = strrchr( lpFile, '.' ); /* Assume last "." is the one; */
+    extension = strrchr( xlpFile, '.' ); /* Assume last "." is the one; */
 					/* File->Run in progman uses */
 					/* .\FILE.EXE :( */
-    if ((extension == NULL) || (extension == &lpFile[strlen(lpFile)]))
+    if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
     {
 	return 31; /* no association */
     }
@@ -176,7 +178,7 @@
     {
 	if (strcmp(tok, &tmpext[1])==0) /* have to skip the leading "." */
 	{
-	    strcpy(lpResult, lpFile); /* Need to perhaps check that */
+	    strcpy(lpResult, xlpFile); /* Need to perhaps check that */
 				      /* the file has a path attached */
 	    dprintf_exec(stddeb, "SHELL_FindExecutable: found %s\n",
 			 lpResult);
@@ -212,7 +214,7 @@
 	    if (tok != NULL)
 	    {
 		tok[0]='\0'; /* truncate string at the percent */
-		strcat( lpResult, lpFile ); /* what if no dir in lpFile? */
+		strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
 		tok=strstr( command, "%1" );
 		if ((tok!=NULL) && (strlen(tok)>2))
 		{
@@ -235,7 +237,7 @@
 	    if (tok != NULL)
 	    {
 		tok[0]='\0';
-		strcat( lpResult, lpFile ); /* what if no dir in lpFile? */
+		strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
 		tok=strstr( command, "^" ); /* see above */
 		if ((tok != NULL) && (strlen(tok)>5))
 		{
@@ -300,8 +302,7 @@
     lpResult[0]='\0'; /* Start off with an empty return string */
 
     /* trap NULL parameters on entry */
-    if (( lpFile == NULL ) || ( lpDirectory == NULL ) || 
-	( lpResult == NULL ))
+    if (( lpFile == NULL ) || ( lpResult == NULL ))
     {
 	/* FIXME - should throw a warning, perhaps! */
 	return 2; /* File not found. Close enough, I guess. */
@@ -346,7 +347,7 @@
 /*************************************************************************
  *				ShellAbout		[SHELL.22]
  */
-INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon)
+INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON16 hIcon)
 {
     HANDLE handle;
     BOOL bRet;
@@ -435,10 +436,10 @@
  *
  * This abortion is called directly by Progman
  */
-HICON InternalExtractIcon(HINSTANCE hInstance, LPCSTR lpszExeFileName, UINT nIconIndex, WORD n )
+HICON16 InternalExtractIcon(HINSTANCE hInstance, LPCSTR lpszExeFileName, UINT nIconIndex, WORD n )
 {
   HANDLE 	hRet = 0;
-  HICON*	RetPtr = NULL;
+  HICON16*	RetPtr = NULL;
   BYTE*  	pData;
   OFSTRUCT 	ofs;
   HFILE 	hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
@@ -448,8 +449,8 @@
 
   if( hFile == HFILE_ERROR || !n ) return 0;
 
-  hRet = GlobalAlloc16( GMEM_FIXED, sizeof(HICON)*n);
-  RetPtr = (HICON*)GlobalLock16(hRet);
+  hRet = GlobalAlloc16( GMEM_FIXED, sizeof(HICON16)*n);
+  RetPtr = (HICON16*)GlobalLock16(hRet);
 
  *RetPtr = (n == 0xFFFF)? 0: 1;				/* error return values */
 
@@ -495,7 +496,7 @@
             if( nIconIndex == (UINT)-1 ) RetPtr[0] = iconDirCount;
 	    else if( nIconIndex < iconDirCount )
 	      {
-		  HANDLE hIcon;
+		  HICON16 hIcon;
 		  UINT   i, icon;
 
 		  if( n > iconDirCount - nIconIndex ) n = iconDirCount - nIconIndex;
@@ -531,14 +532,14 @@
 /*************************************************************************
  *				ExtractIcon 		[SHELL.34]
  */
-HICON ExtractIcon(HINSTANCE hInstance, LPCSTR lpszExeFileName, WORD nIconIndex)
+HICON16 ExtractIcon(HINSTANCE hInstance, LPCSTR lpszExeFileName, WORD nIconIndex)
 {
   HANDLE handle = InternalExtractIcon(hInstance,lpszExeFileName,nIconIndex, 1);
 
   if( handle )
     {
-      HICON* ptr = (HICON*)GlobalLock16(handle);
-      HICON  hIcon = *ptr;
+      HICON16* ptr = (HICON16*)GlobalLock16(handle);
+      HICON16  hIcon = *ptr;
 
       GlobalFree16(handle);
       return hIcon;
diff --git a/misc/user.c b/misc/user.c
index eadf06b..3885e09 100644
--- a/misc/user.c
+++ b/misc/user.c
@@ -21,7 +21,6 @@
 
 
 extern HTASK	TASK_GetNextTask(HTASK);
-extern void	QUEUE_SetDoomedQueue(HQUEUE);
 
 /***********************************************************************
  *           GetFreeSystemResources   (USER.284)
@@ -109,7 +108,7 @@
 /**********************************************************************
  *					USER_AppExit
  */
-void USER_AppExit(HTASK hTask, HINSTANCE hInstance, HQUEUE hQueue)
+void USER_AppExit( HTASK16 hTask, HINSTANCE16 hInstance, HQUEUE16 hQueue )
 {
     /* FIXME: flush send messages (which are not implemented yet),
      *        empty clipboard if needed, maybe destroy menus (Windows
diff --git a/multimedia/audio.c b/multimedia/audio.c
index 8f941e9..e342cfa 100644
--- a/multimedia/audio.c
+++ b/multimedia/audio.c
@@ -71,7 +71,7 @@
     BOOL    fShareable;         /* TRUE if first open was shareable */
     WORD    wNotifyDeviceID;    /* MCI device ID with a pending notification */
     HANDLE  hCallback;          /* Callback handle for pending notification */
-	HMMIO	hFile;				/* mmio file handle open as Element		*/
+	HMMIO16	hFile;				/* mmio file handle open as Element		*/
 	MCI_WAVE_OPEN_PARMS openParms;
 	PCMWAVEFORMAT	WaveFormat;
 	WAVEHDR		WaveHdr;
@@ -1580,7 +1580,7 @@
 /**************************************************************************
 * 				AUDIO_DriverProc		[sample driver]
 */
-LONG WAVE_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2)
 {
 #ifdef linux
diff --git a/multimedia/mcianim.c b/multimedia/mcianim.c
index 895042c..abfd6b0 100644
--- a/multimedia/mcianim.c
+++ b/multimedia/mcianim.c
@@ -605,7 +605,7 @@
 /**************************************************************************
 * 				ANIM_DriverProc		[sample driver]
 */
-LONG ANIM_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 #ifdef linux
diff --git a/multimedia/mcicda.c b/multimedia/mcicda.c
index 80c2151..ed7a7f4 100644
--- a/multimedia/mcicda.c
+++ b/multimedia/mcicda.c
@@ -834,7 +834,7 @@
 /**************************************************************************
 * 				CDAUDIO_DriverProc		[sample driver]
 */
-LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 #ifdef linux
diff --git a/multimedia/mcistring.c b/multimedia/mcistring.c
index 895a113..721cd1e 100644
--- a/multimedia/mcistring.c
+++ b/multimedia/mcistring.c
@@ -19,6 +19,7 @@
 #include "user.h"
 #include "driver.h"
 #include "mmsystem.h"
+#include "stackframe.h"
 #include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
@@ -31,16 +32,16 @@
  */
 extern MCI_OPEN_PARMS		mciOpenDrv[MAXMCIDRIVERS];
 
-LONG DrvDefDriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		      DWORD dwParam1, DWORD dwParam2);
 
-LONG WAVE_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
-LONG MIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
-LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 			DWORD dwParam1, DWORD dwParam2);
-LONG ANIM_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
 
 /* The reason why I just don't lowercase the keywords array in 
diff --git a/multimedia/midi.c b/multimedia/midi.c
index 84a5210..2d9e67f 100644
--- a/multimedia/midi.c
+++ b/multimedia/midi.c
@@ -66,7 +66,7 @@
 	BOOL    fShareable;         /* TRUE if first open was shareable */
 	WORD    wNotifyDeviceID;    /* MCI device ID with a pending notification */
 	HANDLE  hCallback;          /* Callback handle for pending notification */
-	HMMIO	hFile;				/* mmio file handle open as Element		*/
+	HMMIO16	hFile;				/* mmio file handle open as Element		*/
 	DWORD	dwBeginData;
 	DWORD	dwTotalLen;
 	WORD	wFormat;
@@ -1267,7 +1267,7 @@
 /**************************************************************************
 * 				MIDI_DriverProc		[sample driver]
 */
-LONG MIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2)
 {
 #ifdef linux
diff --git a/multimedia/mmsystem.c b/multimedia/mmsystem.c
index e974c8b..91dd742 100644
--- a/multimedia/mmsystem.c
+++ b/multimedia/mmsystem.c
@@ -37,16 +37,16 @@
 
 UINT midiGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
 UINT waveGetErrorText(UINT uError, LPSTR lpText, UINT uSize);
-LONG DrvDefDriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		      DWORD dwParam1, DWORD dwParam2);
 
-LONG WAVE_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
-LONG MIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
-LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 			DWORD dwParam1, DWORD dwParam2);
-LONG ANIM_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
 
 /**************************************************************************
@@ -65,7 +65,7 @@
 */
 BOOL sndPlaySound(LPCSTR lpszSoundName, UINT uFlags)
 {
-	HMMIO			hmmio;
+	HMMIO16			hmmio;
 	MMCKINFO		mmckInfo;
 	MMCKINFO		ckMainRIFF;
 	HANDLE			hFormat;
@@ -192,7 +192,7 @@
 /**************************************************************************
 * 				DriverProc	[MMSYSTEM.6]
 */
-LRESULT DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LRESULT DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2)
 {
 	return DrvDefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
@@ -751,7 +751,7 @@
 */
 DWORD mciSendCommand(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2)
 {
-	HDRVR	hDrv = 0;
+	HDRVR16	hDrv = 0;
 	dprintf_mci(stddeb, "mciSendCommand(%04X, %04X, %08lX, %08lX)\n", 
 					wDevID, wMsg, dwParam1, dwParam2);
 	switch(wMsg) {
@@ -913,10 +913,10 @@
 /**************************************************************************
 * 				midiOutOpen    		[MMSYSTEM.204]
 */
-UINT midiOutOpen(HMIDIOUT * lphMidiOut, UINT uDeviceID,
+UINT midiOutOpen(HMIDIOUT16 * lphMidiOut, UINT uDeviceID,
 		 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
-	HMIDI	hMidiOut;
+	HMIDI16	hMidiOut;
 	LPMIDIOPENDESC	lpDesc;
 	LPMIDIOPENDESC	lp16Desc;
 	DWORD	dwRet = 0;
@@ -951,7 +951,7 @@
 /**************************************************************************
 * 				midiOutClose		[MMSYSTEM.205]
 */
-UINT midiOutClose(HMIDIOUT hMidiOut)
+UINT midiOutClose(HMIDIOUT16 hMidiOut)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutClose(%04X)\n", hMidiOut);
@@ -963,7 +963,7 @@
 /**************************************************************************
 * 				midiOutPrepareHeader	[MMSYSTEM.206]
 */
-UINT midiOutPrepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutPrepareHeader(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
@@ -978,7 +978,7 @@
 /**************************************************************************
 * 				midiOutUnprepareHeader	[MMSYSTEM.207]
 */
-UINT midiOutUnprepareHeader(HMIDIOUT hMidiOut,
+UINT midiOutUnprepareHeader(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
@@ -993,7 +993,7 @@
 /**************************************************************************
 * 				midiOutShortMsg		[MMSYSTEM.208]
 */
-UINT midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
+UINT midiOutShortMsg(HMIDIOUT16 hMidiOut, DWORD dwMsg)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutShortMsg(%04X, %08lX)\n", hMidiOut, dwMsg);
@@ -1005,7 +1005,7 @@
 /**************************************************************************
 * 				midiOutLongMsg		[MMSYSTEM.209]
 */
-UINT midiOutLongMsg(HMIDIOUT hMidiOut,
+UINT midiOutLongMsg(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
@@ -1020,7 +1020,7 @@
 /**************************************************************************
 * 				midiOutReset		[MMSYSTEM.210]
 */
-UINT midiOutReset(HMIDIOUT hMidiOut)
+UINT midiOutReset(HMIDIOUT16 hMidiOut)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutReset(%04X)\n", hMidiOut);
@@ -1052,7 +1052,7 @@
 /**************************************************************************
 * 				midiOutCachePatches		[MMSYSTEM.213]
 */
-UINT midiOutCachePatches(HMIDIOUT hMidiOut,
+UINT midiOutCachePatches(HMIDIOUT16 hMidiOut,
     UINT uBank, WORD * lpwPatchArray, UINT uFlags)
 {
         /* not really necessary to support this */
@@ -1063,7 +1063,7 @@
 /**************************************************************************
 * 				midiOutCacheDrumPatches	[MMSYSTEM.214]
 */
-UINT midiOutCacheDrumPatches(HMIDIOUT hMidiOut,
+UINT midiOutCacheDrumPatches(HMIDIOUT16 hMidiOut,
     UINT uPatch, WORD * lpwKeyArray, UINT uFlags)
 {
 	fprintf(stdnimp, "midiOutCacheDrumPatchesi: not supported yet\n");
@@ -1073,7 +1073,7 @@
 /**************************************************************************
 * 				midiOutGetID		[MMSYSTEM.215]
 */
-UINT midiOutGetID(HMIDIOUT hMidiOut, UINT * lpuDeviceID)
+UINT midiOutGetID(HMIDIOUT16 hMidiOut, UINT * lpuDeviceID)
 {
 	dprintf_mmsys(stddeb, "midiOutGetID\n");
 	return 0;
@@ -1082,7 +1082,7 @@
 /**************************************************************************
 * 				midiOutMessage		[MMSYSTEM.216]
 */
-DWORD midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage, 
+DWORD midiOutMessage(HMIDIOUT16 hMidiOut, UINT uMessage, 
 						DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
@@ -1128,10 +1128,10 @@
 /**************************************************************************
 * 				midiInOpen		[MMSYSTEM.304]
 */
-UINT midiInOpen(HMIDIIN * lphMidiIn, UINT uDeviceID,
+UINT midiInOpen(HMIDIIN16 * lphMidiIn, UINT uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
-	HMIDI	hMidiIn;
+	HMIDI16	hMidiIn;
 	LPMIDIOPENDESC	lpDesc;
 	LPMIDIOPENDESC	lp16Desc;
 	DWORD	dwRet = 0;
@@ -1166,7 +1166,7 @@
 /**************************************************************************
 * 				midiInClose		[MMSYSTEM.305]
 */
-UINT midiInClose(HMIDIIN hMidiIn)
+UINT midiInClose(HMIDIIN16 hMidiIn)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiInClose(%04X)\n", hMidiIn);
@@ -1178,7 +1178,7 @@
 /**************************************************************************
 * 				midiInPrepareHeader	[MMSYSTEM.306]
 */
-UINT midiInPrepareHeader(HMIDIIN hMidiIn,
+UINT midiInPrepareHeader(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
@@ -1193,7 +1193,7 @@
 /**************************************************************************
 * 				midiInUnprepareHeader	[MMSYSTEM.307]
 */
-UINT midiInUnprepareHeader(HMIDIIN hMidiIn,
+UINT midiInUnprepareHeader(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
@@ -1208,7 +1208,7 @@
 /**************************************************************************
 * 				midiInAddBuffer		[MMSYSTEM.308]
 */
-UINT midiInAddBuffer(HMIDIIN hMidiIn,
+UINT midiInAddBuffer(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT uSize)
 {
 	dprintf_mmsys(stddeb, "midiInAddBuffer\n");
@@ -1218,7 +1218,7 @@
 /**************************************************************************
 * 				midiInStart			[MMSYSTEM.309]
 */
-UINT midiInStart(HMIDIIN hMidiIn)
+UINT midiInStart(HMIDIIN16 hMidiIn)
 {
 	dprintf_mmsys(stddeb, "midiInStart\n");
 	return 0;
@@ -1227,7 +1227,7 @@
 /**************************************************************************
 * 				midiInStop			[MMSYSTEM.310]
 */
-UINT midiInStop(HMIDIIN hMidiIn)
+UINT midiInStop(HMIDIIN16 hMidiIn)
 {
 	dprintf_mmsys(stddeb, "midiInStop\n");
 	return 0;
@@ -1236,7 +1236,7 @@
 /**************************************************************************
 * 				midiInReset			[MMSYSTEM.311]
 */
-UINT midiInReset(HMIDIIN hMidiIn)
+UINT midiInReset(HMIDIIN16 hMidiIn)
 {
 	dprintf_mmsys(stddeb, "midiInReset\n");
 	return 0;
@@ -1245,7 +1245,7 @@
 /**************************************************************************
 * 				midiInGetID			[MMSYSTEM.312]
 */
-UINT midiInGetID(HMIDIIN hMidiIn, UINT * lpuDeviceID)
+UINT midiInGetID(HMIDIIN16 hMidiIn, UINT * lpuDeviceID)
 {
 	dprintf_mmsys(stddeb, "midiInGetID\n");
 	return 0;
@@ -1254,7 +1254,7 @@
 /**************************************************************************
 * 				midiInMessage		[MMSYSTEM.313]
 */
-DWORD midiInMessage(HMIDIIN hMidiIn, UINT uMessage, 
+DWORD midiInMessage(HMIDIIN16 hMidiIn, UINT uMessage, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
@@ -1366,10 +1366,10 @@
 /**************************************************************************
 * 				waveOutOpen			[MMSYSTEM.404]
 */
-UINT waveOutOpen(HWAVEOUT * lphWaveOut, UINT uDeviceID,
+UINT waveOutOpen(HWAVEOUT16 * lphWaveOut, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
-	HWAVE	hWaveOut;
+	HWAVEOUT16 hWaveOut;
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEOPENDESC	lp16Desc;
 	DWORD	dwRet = 0;
@@ -1412,7 +1412,7 @@
 /**************************************************************************
 * 				waveOutClose		[MMSYSTEM.405]
 */
-UINT waveOutClose(HWAVEOUT hWaveOut)
+UINT waveOutClose(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutClose(%04X)\n", hWaveOut);
@@ -1424,7 +1424,7 @@
 /**************************************************************************
 * 				waveOutPrepareHeader	[MMSYSTEM.406]
 */
-UINT waveOutPrepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutPrepareHeader(HWAVEOUT16 hWaveOut,
      WAVEHDR * lpWaveOutHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
@@ -1439,7 +1439,7 @@
 /**************************************************************************
 * 				waveOutUnprepareHeader	[MMSYSTEM.407]
 */
-UINT waveOutUnprepareHeader(HWAVEOUT hWaveOut,
+UINT waveOutUnprepareHeader(HWAVEOUT16 hWaveOut,
     WAVEHDR * lpWaveOutHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
@@ -1454,7 +1454,7 @@
 /**************************************************************************
 * 				waveOutWrite		[MMSYSTEM.408]
 */
-UINT waveOutWrite(HWAVEOUT hWaveOut, WAVEHDR * lpWaveOutHdr,  UINT uSize)
+UINT waveOutWrite(HWAVEOUT16 hWaveOut, WAVEHDR * lpWaveOutHdr,  UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutWrite(%04X, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
@@ -1467,7 +1467,7 @@
 /**************************************************************************
 * 				waveOutPause		[MMSYSTEM.409]
 */
-UINT waveOutPause(HWAVEOUT hWaveOut)
+UINT waveOutPause(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutPause(%04X)\n", hWaveOut);
@@ -1479,7 +1479,7 @@
 /**************************************************************************
 * 				waveOutRestart		[MMSYSTEM.410]
 */
-UINT waveOutRestart(HWAVEOUT hWaveOut)
+UINT waveOutRestart(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutRestart(%04X)\n", hWaveOut);
@@ -1491,7 +1491,7 @@
 /**************************************************************************
 * 				waveOutReset		[MMSYSTEM.411]
 */
-UINT waveOutReset(HWAVEOUT hWaveOut)
+UINT waveOutReset(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutReset(%04X)\n", hWaveOut);
@@ -1503,7 +1503,7 @@
 /**************************************************************************
 * 				waveOutGetPosition	[MMSYSTEM.412]
 */
-UINT waveOutGetPosition(HWAVEOUT hWaveOut, MMTIME * lpTime, UINT uSize)
+UINT waveOutGetPosition(HWAVEOUT16 hWaveOut, MMTIME * lpTime, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetPosition(%04X, %p, %u);\n", hWaveOut, lpTime, uSize);
@@ -1516,7 +1516,7 @@
 /**************************************************************************
 * 				waveOutGetPitch		[MMSYSTEM.413]
 */
-UINT waveOutGetPitch(HWAVEOUT hWaveOut, DWORD * lpdwPitch)
+UINT waveOutGetPitch(HWAVEOUT16 hWaveOut, DWORD * lpdwPitch)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetPitch(%04X, %p);\n", hWaveOut, lpdwPitch);
@@ -1529,7 +1529,7 @@
 /**************************************************************************
 * 				waveOutSetPitch		[MMSYSTEM.414]
 */
-UINT waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dwPitch)
+UINT waveOutSetPitch(HWAVEOUT16 hWaveOut, DWORD dwPitch)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutSetPitch(%04X, %08lX);\n", hWaveOut, dwPitch);
@@ -1559,7 +1559,7 @@
 /**************************************************************************
 * 				waveOutGetPlaybackRate	[MMSYSTEM.417]
 */
-UINT waveOutGetPlaybackRate(HWAVEOUT hWaveOut, DWORD * lpdwRate)
+UINT waveOutGetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD * lpdwRate)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetPlaybackRate(%04X, %p);\n", hWaveOut, lpdwRate);
@@ -1572,7 +1572,7 @@
 /**************************************************************************
 * 				waveOutSetPlaybackRate	[MMSYSTEM.418]
 */
-UINT waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dwRate)
+UINT waveOutSetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD dwRate)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutSetPlaybackRate(%04X, %08lX);\n", hWaveOut, dwRate);
@@ -1585,7 +1585,7 @@
 /**************************************************************************
 * 				waveOutBreakLoop 	[MMSYSTEM.419]
 */
-UINT waveOutBreakLoop(HWAVEOUT hWaveOut)
+UINT waveOutBreakLoop(HWAVEOUT16 hWaveOut)
 {
 	dprintf_mmsys(stddeb, "waveOutBreakLoop(%04X)\n", hWaveOut);
 	return MMSYSERR_INVALHANDLE;
@@ -1594,7 +1594,7 @@
 /**************************************************************************
 * 				waveOutGetID	 	[MMSYSTEM.420]
 */
-UINT waveOutGetID(HWAVEOUT hWaveOut, UINT * lpuDeviceID)
+UINT waveOutGetID(HWAVEOUT16 hWaveOut, UINT * lpuDeviceID)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetID(%04X, %p);\n", hWaveOut, lpuDeviceID);
@@ -1610,7 +1610,7 @@
 /**************************************************************************
 * 				waveOutMessage 		[MMSYSTEM.421]
 */
-DWORD waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, 
+DWORD waveOutMessage(HWAVEOUT16 hWaveOut, UINT uMessage, 
 							DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
@@ -1657,10 +1657,10 @@
 /**************************************************************************
 * 				waveInOpen			[MMSYSTEM.504]
 */
-UINT waveInOpen(HWAVEIN * lphWaveIn, UINT uDeviceID,
+UINT waveInOpen(HWAVEIN16 * lphWaveIn, UINT uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
-	HWAVE	hWaveIn;
+	HWAVEIN16 hWaveIn;
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEOPENDESC	lp16Desc;
 	DWORD	dwRet = 0;
@@ -1704,7 +1704,7 @@
 /**************************************************************************
 * 				waveInClose			[MMSYSTEM.505]
 */
-UINT waveInClose(HWAVEIN hWaveIn)
+UINT waveInClose(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveInClose(%04X)\n", hWaveIn);
@@ -1717,7 +1717,7 @@
 /**************************************************************************
 * 				waveInPrepareHeader		[MMSYSTEM.506]
 */
-UINT waveInPrepareHeader(HWAVEIN hWaveIn,
+UINT waveInPrepareHeader(HWAVEIN16 hWaveIn,
     WAVEHDR * lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
@@ -1740,7 +1740,7 @@
 /**************************************************************************
 * 				waveInUnprepareHeader	[MMSYSTEM.507]
 */
-UINT waveInUnprepareHeader(HWAVEIN hWaveIn,
+UINT waveInUnprepareHeader(HWAVEIN16 hWaveIn,
     WAVEHDR * lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
@@ -1762,7 +1762,7 @@
 /**************************************************************************
 * 				waveInAddBuffer		[MMSYSTEM.508]
 */
-UINT waveInAddBuffer(HWAVEIN hWaveIn,
+UINT waveInAddBuffer(HWAVEIN16 hWaveIn,
     WAVEHDR * lpWaveInHdr, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
@@ -1784,7 +1784,7 @@
 /**************************************************************************
 * 				waveInStart			[MMSYSTEM.509]
 */
-UINT waveInStart(HWAVEIN hWaveIn)
+UINT waveInStart(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveInStart(%04X)\n", hWaveIn);
@@ -1797,7 +1797,7 @@
 /**************************************************************************
 * 				waveInStop			[MMSYSTEM.510]
 */
-UINT waveInStop(HWAVEIN hWaveIn)
+UINT waveInStop(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveInStop(%04X)\n", hWaveIn);
@@ -1810,7 +1810,7 @@
 /**************************************************************************
 * 				waveInReset			[MMSYSTEM.511]
 */
-UINT waveInReset(HWAVEIN hWaveIn)
+UINT waveInReset(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveInReset(%04X)\n", hWaveIn);
@@ -1823,7 +1823,7 @@
 /**************************************************************************
 * 				waveInGetPosition	[MMSYSTEM.512]
 */
-UINT waveInGetPosition(HWAVEIN hWaveIn, MMTIME * lpTime, UINT uSize)
+UINT waveInGetPosition(HWAVEIN16 hWaveIn, MMTIME * lpTime, UINT uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveInGetPosition(%04X, %p, %u);\n", hWaveIn, lpTime, uSize);
@@ -1837,7 +1837,7 @@
 /**************************************************************************
 * 				waveInGetID			[MMSYSTEM.513]
 */
-UINT waveInGetID(HWAVEIN hWaveIn, UINT * lpuDeviceID)
+UINT waveInGetID(HWAVEIN16 hWaveIn, UINT * lpuDeviceID)
 {
 	dprintf_mmsys(stddeb, "waveInGetID\n");
 	if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
@@ -1848,7 +1848,7 @@
 /**************************************************************************
 * 				waveInMessage 		[MMSYSTEM.514]
 */
-DWORD waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
+DWORD waveInMessage(HWAVEIN16 hWaveIn, UINT uMessage,
 		    DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
@@ -1863,10 +1863,10 @@
 /**************************************************************************
 * 				mmioOpen       		[MMSYSTEM.1210]
 */
-HMMIO mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo, DWORD dwOpenFlags)
+HMMIO16 mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo, DWORD dwOpenFlags)
 {
 	int		hFile;
-	HANDLE		hmmio;
+	HMMIO16		hmmio;
 	OFSTRUCT	ofs;
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmsys(stddeb, "mmioOpen('%s', %p, %08lX);\n", szFileName, lpmmioinfo, dwOpenFlags);
@@ -1887,7 +1887,7 @@
 /**************************************************************************
 * 				mmioClose      		[MMSYSTEM.1211]
 */
-UINT mmioClose(HMMIO hmmio, UINT uFlags)
+UINT mmioClose(HMMIO16 hmmio, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmsys(stddeb, "mmioClose(%04X, %04X);\n", hmmio, uFlags);
@@ -1904,7 +1904,7 @@
 /**************************************************************************
 * 				mmioRead	       	[MMSYSTEM.1212]
 */
-LONG mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
+LONG mmioRead(HMMIO16 hmmio, HPSTR pch, LONG cch)
 {
 	LONG		count;
 	LPMMIOINFO	lpmminfo;
@@ -1922,7 +1922,7 @@
 /**************************************************************************
 * 				mmioWrite      		[MMSYSTEM.1213]
 */
-LONG mmioWrite(HMMIO hmmio, HPCSTR pch, LONG cch)
+LONG mmioWrite(HMMIO16 hmmio, HPCSTR pch, LONG cch)
 {
 	LONG		count;
 	LPMMIOINFO	lpmminfo;
@@ -1937,7 +1937,7 @@
 /**************************************************************************
 * 				mmioSeek       		[MMSYSTEM.1214]
 */
-LONG mmioSeek(HMMIO hmmio, LONG lOffset, int iOrigin)
+LONG mmioSeek(HMMIO16 hmmio, LONG lOffset, int iOrigin)
 {
 	int		count;
 	LPMMIOINFO	lpmminfo;
@@ -1955,7 +1955,7 @@
 /**************************************************************************
 * 				mmioGetInfo	       	[MMSYSTEM.1215]
 */
-UINT mmioGetInfo(HMMIO hmmio, MMIOINFO * lpmmioinfo, UINT uFlags)
+UINT mmioGetInfo(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmsys(stddeb, "mmioGetInfo\n");
@@ -1969,7 +1969,7 @@
 /**************************************************************************
 * 				mmioSetInfo    		[MMSYSTEM.1216]
 */
-UINT mmioSetInfo(HMMIO hmmio, const MMIOINFO * lpmmioinfo, UINT uFlags)
+UINT mmioSetInfo(HMMIO16 hmmio, const MMIOINFO * lpmmioinfo, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmsys(stddeb, "mmioSetInfo\n");
@@ -1982,7 +1982,7 @@
 /**************************************************************************
 * 				mmioSetBuffer		[MMSYSTEM.1217]
 */
-UINT mmioSetBuffer(HMMIO hmmio, LPSTR pchBuffer, 
+UINT mmioSetBuffer(HMMIO16 hmmio, LPSTR pchBuffer, 
 						LONG cchBuffer, UINT uFlags)
 {
 	dprintf_mmsys(stddeb, "mmioSetBuffer // empty stub \n");
@@ -1992,7 +1992,7 @@
 /**************************************************************************
 * 				mmioFlush      		[MMSYSTEM.1218]
 */
-UINT mmioFlush(HMMIO hmmio, UINT uFlags)
+UINT mmioFlush(HMMIO16 hmmio, UINT uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmsys(stddeb, "mmioFlush(%04X, %04X)\n", hmmio, uFlags);
@@ -2005,7 +2005,7 @@
 /**************************************************************************
 * 				mmioAdvance    		[MMSYSTEM.1219]
 */
-UINT mmioAdvance(HMMIO hmmio, MMIOINFO * lpmmioinfo, UINT uFlags)
+UINT mmioAdvance(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT uFlags)
 {
 	int		count = 0;
 	LPMMIOINFO	lpmminfo;
@@ -2048,7 +2048,7 @@
 /**************************************************************************
 * 				mmioSendMessage		[MMSYSTEM.1222]
 */
-LRESULT mmioSendMessage(HMMIO hmmio, UINT uMessage,
+LRESULT mmioSendMessage(HMMIO16 hmmio, UINT uMessage,
 					    LPARAM lParam1, LPARAM lParam2)
 {
 	dprintf_mmsys(stddeb, "mmioSendMessage // empty stub \n");
@@ -2058,7 +2058,7 @@
 /**************************************************************************
 * 				mmioDescend	       	[MMSYSTEM.1223]
 */
-UINT mmioDescend(HMMIO hmmio, MMCKINFO * lpck,
+UINT mmioDescend(HMMIO16 hmmio, MMCKINFO * lpck,
 		    const MMCKINFO * lpckParent, UINT uFlags)
 {
 	DWORD	dwfcc, dwOldPos;
@@ -2119,7 +2119,7 @@
 /**************************************************************************
 * 				mmioAscend     		[MMSYSTEM.1224]
 */
-UINT mmioAscend(HMMIO hmmio, MMCKINFO * lpck, UINT uFlags)
+UINT mmioAscend(HMMIO16 hmmio, MMCKINFO * lpck, UINT uFlags)
 {
 	dprintf_mmsys(stddeb, "mmioAscend // empty stub !\n");
 	return 0;
@@ -2128,7 +2128,7 @@
 /**************************************************************************
 * 				mmioCreateChunk		[MMSYSTEM.1225]
 */
-UINT mmioCreateChunk(HMMIO hmmio, MMCKINFO * lpck, UINT uFlags)
+UINT mmioCreateChunk(HMMIO16 hmmio, MMCKINFO * lpck, UINT uFlags)
 {
 	dprintf_mmsys(stddeb, "mmioCreateChunk // empty stub \n");
 	return 0;
@@ -2149,7 +2149,7 @@
 /**************************************************************************
 * 				DrvOpen	       		[MMSYSTEM.1100]
 */
-HDRVR DrvOpen(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
+HDRVR16 DrvOpen(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
 {
 	dprintf_mmsys(stddeb, "DrvOpen('%s', '%s', %08lX);\n",
 		lpDriverName, lpSectionName, lParam);
@@ -2160,7 +2160,7 @@
 /**************************************************************************
 * 				DrvClose       		[MMSYSTEM.1101]
 */
-LRESULT DrvClose(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
+LRESULT DrvClose(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
 {
 	dprintf_mmsys(stddeb, "DrvClose(%04X, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
 	return CloseDriver(hDrvr, lParam1, lParam2);
@@ -2170,7 +2170,7 @@
 /**************************************************************************
 * 				DrvSendMessage		[MMSYSTEM.1102]
 */
-LRESULT DrvSendMessage(HDRVR hDriver, WORD msg, LPARAM lParam1, LPARAM lParam2)
+LRESULT DrvSendMessage(HDRVR16 hDriver, WORD msg, LPARAM lParam1, LPARAM lParam2)
 {
 	DWORD 	dwDevID = 0;
 	dprintf_mmsys(stddeb, "DrvSendMessage(%04X, %04X, %08lX, %08lX);\n",
@@ -2183,7 +2183,7 @@
 /**************************************************************************
 * 				DrvGetModuleHandle	[MMSYSTEM.1103]
 */
-HANDLE DrvGetModuleHandle(HDRVR hDrvr)
+HANDLE DrvGetModuleHandle(HDRVR16 hDrvr)
 {
 	dprintf_mmsys(stddeb, "DrvGetModuleHandle(%04X);\n", hDrvr);
         return 0;
@@ -2193,7 +2193,7 @@
 /**************************************************************************
 * 				DrvDefDriverProc	[MMSYSTEM.1104]
 */
-LRESULT DrvDefDriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg, 
+LRESULT DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2)
 {
 	return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
diff --git a/objects/bitblt.c b/objects/bitblt.c
index 1cb29bb..4a9489c 100644
--- a/objects/bitblt.c
+++ b/objects/bitblt.c
@@ -660,8 +660,9 @@
         memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
                 widthDst*sizeof(int) );
 
-    hstretch = ((widthSrc < widthDst) || (mode == STRETCH_DELETESCANS));
-    vstretch = ((heightSrc < heightDst) || (mode == STRETCH_DELETESCANS));
+    hstretch = (widthSrc < widthDst);
+    vstretch = (heightSrc < heightDst);
+
     xinc = hstretch ? ((int)widthSrc << 16) / widthDst :
                       ((int)widthDst << 16) / widthSrc;
 
diff --git a/objects/brush.c b/objects/brush.c
index 00553ab..27c847f 100644
--- a/objects/brush.c
+++ b/objects/brush.c
@@ -190,7 +190,7 @@
 /***********************************************************************
  *           CreateDIBPatternBrush    (GDI.445)
  */
-HBRUSH CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
+HBRUSH CreateDIBPatternBrush( HGLOBAL16 hbitmap, UINT coloruse )
 {
     LOGBRUSH16 logbrush = { BS_DIBPATTERN, coloruse, 0 };
     BITMAPINFO *info, *newInfo;
diff --git a/objects/color.c b/objects/color.c
index 308d191..5ed37ec 100644
--- a/objects/color.c
+++ b/objects/color.c
@@ -736,9 +736,9 @@
 
     if ( cSpace.flags & COLOR_FIXED && !COLOR_Graymax )
        {
-         color.red = pixel >> COLOR_Redshift;
-         color.green = pixel >> COLOR_Greenshift;
-         color.blue = pixel >> COLOR_Blueshift;
+         color.red = (pixel >> COLOR_Redshift) & COLOR_Redmax;
+         color.green = (pixel >> COLOR_Greenshift) & COLOR_Greenmax;
+         color.blue = (pixel >> COLOR_Blueshift) & COLOR_Bluemax;
        }
     else if ((screenDepth <= 8) && (pixel < 256) && 
 	    !(cSpace.flags & (COLOR_VIRTUAL | COLOR_FIXED)) )
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
index 5a35ff8..2b1c67f 100644
--- a/objects/cursoricon.c
+++ b/objects/cursoricon.c
@@ -38,7 +38,7 @@
 extern UINT16 COLOR_GetSystemPaletteSize();
 
 Cursor CURSORICON_XCursor = None;  /* Current X cursor */
-static HCURSOR hActiveCursor = 0;  /* Active cursor */
+static HCURSOR16 hActiveCursor = 0;  /* Active cursor */
 static int CURSOR_ShowCount = 0;   /* Cursor display count */
 static RECT32 CURSOR_ClipRect;       /* Cursor clipping rect */
 
@@ -371,7 +371,7 @@
                                int height, int colors, BOOL fCursor )
 {
     HANDLE handle,hRet;
-    HRSRC  hRsrc;
+    HRSRC16 hRsrc;
     CURSORICONDIRENTRY dirEntry;
 
     if (!hInstance)  /* OEM cursor/icon */
@@ -433,7 +433,7 @@
  * FIXME: if icon is passed returns a copy of OCR_DRAGOBJECT cursor
  *	  but should actually convert icon to cursor.
  */
-HCURSOR CURSORICON_IconToCursor(HICON hIcon)
+HCURSOR16 CURSORICON_IconToCursor(HICON16 hIcon)
 {
  CURSORICONINFO *ptr = NULL;
 
@@ -499,9 +499,9 @@
 /***********************************************************************
  *           CreateCursor    (USER.406)
  */
-HCURSOR CreateCursor( HINSTANCE hInstance, INT xHotSpot, INT yHotSpot,
-                      INT nWidth, INT nHeight,
-                      const BYTE *lpANDbits, const BYTE *lpXORbits )
+HCURSOR16 CreateCursor( HINSTANCE hInstance, INT xHotSpot, INT yHotSpot,
+                        INT nWidth, INT nHeight,
+                        const BYTE *lpANDbits, const BYTE *lpXORbits )
 {
     CURSORICONINFO info = { { xHotSpot, yHotSpot }, nWidth, nHeight, 0, 1, 1 };
 
@@ -514,7 +514,7 @@
 /***********************************************************************
  *           CreateIcon    (USER.407)
  */
-HICON CreateIcon( HINSTANCE hInstance, INT nWidth, INT nHeight, BYTE bPlanes,
+HICON16 CreateIcon( HINSTANCE hInstance, INT nWidth, INT nHeight, BYTE bPlanes,
                   BYTE bBitsPixel, const BYTE* lpANDbits, const BYTE* lpXORbits)
 {
     CURSORICONINFO info = { { 0, 0 }, nWidth, nHeight, 0, bPlanes, bBitsPixel };
@@ -585,7 +585,7 @@
 /***********************************************************************
  *           DestroyIcon    (USER.457)
  */
-BOOL DestroyIcon( HICON hIcon )
+BOOL DestroyIcon( HICON16 hIcon )
 {
     dprintf_icon( stddeb, "DestroyIcon: %04x\n", hIcon );
     /* FIXME: should check for OEM icon here */
@@ -596,7 +596,7 @@
 /***********************************************************************
  *           DestroyCursor    (USER.458)
  */
-BOOL DestroyCursor( HCURSOR hCursor )
+BOOL DestroyCursor( HCURSOR16 hCursor )
 {
     dprintf_cursor( stddeb, "DestroyCursor: %04x\n", hCursor );
     /* FIXME: should check for OEM cursor here */
@@ -607,7 +607,7 @@
 /***********************************************************************
  *           DrawIcon    (USER.84)
  */
-BOOL DrawIcon( HDC hdc, INT x, INT y, HICON hIcon )
+BOOL DrawIcon( HDC hdc, INT x, INT y, HICON16 hIcon )
 {
     CURSORICONINFO *ptr;
     HDC hMemDC;
@@ -665,7 +665,7 @@
  *
  * Change the X cursor. Helper function for SetCursor() and ShowCursor().
  */
-static BOOL CURSORICON_SetCursor( HCURSOR hCursor )
+static BOOL CURSORICON_SetCursor( HCURSOR16 hCursor )
 {
     Pixmap pixmapBits, pixmapMask, pixmapAll;
     XColor fg, bg;
@@ -803,9 +803,9 @@
 /***********************************************************************
  *           SetCursor    (USER.69)
  */
-HCURSOR SetCursor( HCURSOR hCursor )
+HCURSOR16 SetCursor( HCURSOR16 hCursor )
 {
-    HCURSOR hOldCursor;
+    HCURSOR16 hOldCursor;
 
     if (hCursor == hActiveCursor) return hActiveCursor;  /* No change */
     dprintf_cursor( stddeb, "SetCursor: %04x\n", hCursor );
@@ -852,7 +852,7 @@
 /***********************************************************************
  *           GetCursor    (USER.247)
  */
-HCURSOR GetCursor(void)
+HCURSOR16 GetCursor(void)
 {
     return hActiveCursor;
 }
@@ -973,7 +973,7 @@
 /**********************************************************************
  *	    LoadIconHandler    (USER.456)
  */
-HICON LoadIconHandler( HANDLE hResource, BOOL bNew )
+HICON16 LoadIconHandler( HANDLE hResource, BOOL bNew )
 {
     dprintf_cursor(stddeb,"LoadIconHandler: hRes=%04x\n",hResource);
 
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index c406140..d36acda 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -515,11 +515,10 @@
  */
 BOOL IsGDIObject(HANDLE handle)
 {
-    GDIOBJHDR *object;
-
-    object = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
-    /* FIXME: should check magic here */
-    return (object != NULL);
+    GDIOBJHDR *object = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+    if (object)
+      return (object->wMagic>=PEN_MAGIC && object->wMagic<= METAFILE_DC_MAGIC);
+    return FALSE;
 }
 
 
diff --git a/objects/metafile.c b/objects/metafile.c
index 3c2ad1a..d3e21e3 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -25,9 +25,9 @@
  *         GetMetafile         GDI.124 By Kenny MacDonald 30 Nov 94
  */
 
-HMETAFILE GetMetaFile(LPSTR lpFilename)
+HMETAFILE16 GetMetaFile(LPSTR lpFilename)
 {
-  HMETAFILE hmf;
+  HMETAFILE16 hmf;
   METAHEADER *mh;
   HFILE hFile;
   DWORD size;
@@ -146,9 +146,9 @@
  *         CopyMetafile         GDI.151 Niels de Carpentier, April 1996
  */
 
-HMETAFILE CopyMetaFile(HMETAFILE hSrcMetaFile, LPCSTR lpFilename)
+HMETAFILE16 CopyMetaFile(HMETAFILE16 hSrcMetaFile, LPCSTR lpFilename)
 {
-    HMETAFILE handle = 0;
+    HMETAFILE16 handle = 0;
     METAHEADER *mh;
     METAHEADER *mh2;
     int hFile;
@@ -168,12 +168,9 @@
 	mh->mtType=1;        /* disk file version stores 1 here */
 	i=_lwrite(hFile, (char *)mh, mh->mtSize * 2) ;
 	mh->mtType=j;        /* restore old value  [0 or 1] */	
+        _lclose(hFile);
 	if (i == -1)
-	    {
-	    _lclose(hFile);
 	    return 0;
-	    }
-	_lclose(hFile);
         }
     else                     /* memory based metafile */
         {
@@ -186,16 +183,35 @@
     return handle;
 }
 
+/******************************************************************
+ *         IsValidMetaFile   (GDI.410)
+ *         (This is not exactly what windows does, see "Undoc Win")
+ */
+
+BOOL IsValidMetaFile(HMETAFILE16 hmf)
+{
+    BOOL resu=FALSE;
+    METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
+    if (mh)
+      if (mh->mtType == 1 || mh->mtType == 0) 
+        if (mh->mtHeaderSize == MFHEADERSIZE/sizeof(INT16))
+          if (mh->mtVersion == MFVERSION)
+            resu=TRUE;
+    GlobalUnlock16(hmf);            
+    dprintf_metafile(stddeb,"IsValidMetaFile %x => %d\n",hmf,resu);
+    return resu;         
+}
+
 
 /******************************************************************
  *         CloseMetafile         GDI.126
  */
 
-HMETAFILE CloseMetaFile(HDC hdc)
+HMETAFILE16 CloseMetaFile(HDC hdc)
 {
     DC *dc;
     METAHEADER *mh;
-    HMETAFILE hmf;
+    HMETAFILE16 hmf;
     HFILE hFile;
     
     dprintf_metafile(stddeb,"CloseMetaFile\n");
@@ -248,7 +264,7 @@
  *         DeleteMetafile         GDI.127
  */
 
-BOOL DeleteMetaFile(HMETAFILE hmf)
+BOOL DeleteMetaFile(HMETAFILE16 hmf)
 {
     METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
 
@@ -264,7 +280,7 @@
  *         PlayMetafile         GDI.123
  */
 
-BOOL PlayMetaFile(HDC hdc, HMETAFILE hmf)
+BOOL PlayMetaFile(HDC hdc, HMETAFILE16 hmf)
 {
     METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
     METARECORD *mr;
@@ -307,7 +323,7 @@
  *                                    Niels de carpentier, april 1996
  */
 
-BOOL EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC16 lpEnumFunc,LPARAM lpData)
+BOOL EnumMetaFile(HDC hdc, HMETAFILE16 hmf, MFENUMPROC16 lpEnumFunc,LPARAM lpData)
 {
     METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
     METARECORD *mr;
@@ -740,7 +756,7 @@
  * Trade in a meta file object handle for a handle to the meta file memory
  */
 
-HANDLE GetMetaFileBits(HMETAFILE hmf)
+HANDLE GetMetaFileBits(HMETAFILE16 hmf)
 {
     dprintf_metafile(stddeb,"GetMetaFileBits: hMem out: %04x\n", hmf);
 
@@ -753,7 +769,7 @@
  * Trade in a meta file memory handle for a handle to a meta file object
  */
 
-HMETAFILE SetMetaFileBits(HANDLE hMem)
+HMETAFILE16 SetMetaFileBits(HANDLE hMem)
 {
     dprintf_metafile(stddeb,"SetMetaFileBits: hmf out: %04x\n", hMem);
 
@@ -764,7 +780,7 @@
  *         MF_WriteRecord
  */
 
-HMETAFILE MF_WriteRecord(HMETAFILE hmf, METARECORD *mr, WORD rlen)
+HMETAFILE16 MF_WriteRecord(HMETAFILE16 hmf, METARECORD *mr, WORD rlen)
 {
     DWORD len;
     METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
@@ -860,7 +876,7 @@
 {
     char buffer[8];
     METARECORD *mr = (METARECORD *)&buffer;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     
     mr->rdSize = 3;
     mr->rdFunction = func;
@@ -878,7 +894,7 @@
 {
     char buffer[8];
     METARECORD *mr = (METARECORD *)&buffer;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     
     mr->rdSize = 4;
     mr->rdFunction = func;
@@ -897,7 +913,7 @@
 {
     char buffer[10];
     METARECORD *mr = (METARECORD *)&buffer;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     
     mr->rdSize = 5;
     mr->rdFunction = func;
@@ -919,7 +935,7 @@
 {
     char buffer[14];
     METARECORD *mr = (METARECORD *)&buffer;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     
     mr->rdSize = 7;
     mr->rdFunction = func;
@@ -943,7 +959,7 @@
 {
     char buffer[18];
     METARECORD *mr = (METARECORD *)&buffer;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     
     mr->rdSize = 9;
     mr->rdFunction = func;
@@ -969,7 +985,7 @@
 {
     char buffer[22];
     METARECORD *mr = (METARECORD *)&buffer;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     
     mr->rdSize = 11;
     mr->rdFunction = func;
@@ -995,7 +1011,7 @@
 BOOL MF_CreateBrushIndirect(DC *dc, HBRUSH hBrush, LOGBRUSH16 *logbrush)
 {
     int index;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     char buffer[sizeof(METARECORD) - 2 + sizeof(LOGBRUSH16)];
     METARECORD *mr = (METARECORD *)&buffer;
     METAHEADER *mh;
@@ -1039,7 +1055,7 @@
     BITMAPINFO *info;
     BITMAPINFOHEADER *infohdr;
     int index;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     char buffer[sizeof(METARECORD)];
     METAHEADER *mh;
 
@@ -1124,7 +1140,7 @@
 BOOL MF_CreatePenIndirect(DC *dc, HPEN16 hPen, LOGPEN16 *logpen)
 {
     int index;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     char buffer[sizeof(METARECORD) - 2 + sizeof(LOGPEN16)];
     METARECORD *mr = (METARECORD *)&buffer;
     METAHEADER *mh;
@@ -1161,7 +1177,7 @@
 BOOL MF_CreateFontIndirect(DC *dc, HFONT hFont, LOGFONT16 *logfont)
 {
     int index;
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     char buffer[sizeof(METARECORD) - 2 + sizeof(LOGFONT16)];
     METARECORD *mr = (METARECORD *)&buffer;
     METAHEADER *mh;
@@ -1196,7 +1212,7 @@
  */
 BOOL MF_TextOut(DC *dc, short x, short y, LPCSTR str, short count)
 {
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     DWORD len;
     HANDLE hmr;
     METARECORD *mr;
@@ -1225,7 +1241,7 @@
 BOOL MF_ExtTextOut(DC *dc, short x, short y, UINT16 flags, const RECT16 *rect,
                    LPCSTR str, short count, const INT16 *lpDx)
 {
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     DWORD len;
     HANDLE hmr;
     METARECORD *mr;
@@ -1259,7 +1275,7 @@
  */
 BOOL MF_MetaPoly(DC *dc, short func, LPPOINT16 pt, short count)
 {
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     DWORD len;
     HANDLE hmr;
     METARECORD *mr;
@@ -1287,7 +1303,7 @@
 BOOL MF_BitBlt(DC *dcDest, short xDest, short yDest, short width,
 	       short height, HDC hdcSrc, short xSrc, short ySrc, DWORD rop)
 {
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     DWORD len;
     HANDLE hmr;
     METARECORD *mr;
@@ -1339,7 +1355,7 @@
 		   short heightDest, HDC hdcSrc, short xSrc, short ySrc, 
 		   short widthSrc, short heightSrc, DWORD rop)
 {
-    HMETAFILE handle;
+    HMETAFILE16 handle;
     DWORD len;
     HANDLE hmr;
     METARECORD *mr;
diff --git a/objects/oembitmap.c b/objects/oembitmap.c
index 3de567fa..819e82a 100644
--- a/objects/oembitmap.c
+++ b/objects/oembitmap.c
@@ -216,7 +216,7 @@
 #endif
 };
 
-static HCURSOR OBM_Cursors[NB_CURSORS];
+static HGLOBAL16 OBM_Cursors[NB_CURSORS];
 
 
   /* All the colors used in the xpm files must be included in this   */
@@ -299,10 +299,10 @@
  *
  * Allocate a GDI bitmap.
  */
-static HBITMAP OBM_MakeBitmap( WORD width, WORD height,
-                               WORD bpp, Pixmap pixmap )
+static HBITMAP16 OBM_MakeBitmap( WORD width, WORD height,
+                                 WORD bpp, Pixmap pixmap )
 {
-    HBITMAP hbitmap;
+    HBITMAP16 hbitmap;
     BITMAPOBJ * bmpObjPtr;
 
     if (!pixmap) return 0;
@@ -330,8 +330,8 @@
  *
  * Create the 2 bitmaps from XPM data.
  */
-static BOOL OBM_CreateBitmaps( char **data, BOOL color, HBITMAP *hBitmap,
-                               HBITMAP *hBitmapMask, POINT16 *hotspot )
+static BOOL OBM_CreateBitmaps( char **data, BOOL color, HBITMAP16 *hBitmap,
+                               HBITMAP16 *hBitmapMask, POINT16 *hotspot )
 {
     Pixmap pixmap, pixmask;
     XpmAttributes *attrs;
@@ -377,9 +377,9 @@
 /***********************************************************************
  *           OBM_LoadBitmap
  */
-HBITMAP OBM_LoadBitmap( WORD id )
+HBITMAP16 OBM_LoadBitmap( WORD id )
 {
-    HBITMAP hbitmap;
+    HBITMAP16 hbitmap;
 
     if ((id < OBM_FIRST) || (id > OBM_LAST)) return 0;
     id -= OBM_FIRST;
@@ -401,12 +401,12 @@
 /***********************************************************************
  *           OBM_LoadCursorIcon
  */
-HANDLE OBM_LoadCursorIcon( WORD id, BOOL fCursor )
+HGLOBAL16 OBM_LoadCursorIcon( WORD id, BOOL32 fCursor )
 {
-    HANDLE handle;
+    HGLOBAL16 handle;
     CURSORICONINFO *pInfo;
     BITMAPOBJ *bmpXor, *bmpAnd;
-    HBITMAP hXorBits, hAndBits;
+    HBITMAP16 hXorBits, hAndBits;
     POINT16 hotspot;
     int sizeXor, sizeAnd;
 
diff --git a/objects/region.c b/objects/region.c
index 0b43fb9..a5e5cd6 100644
--- a/objects/region.c
+++ b/objects/region.c
@@ -424,6 +424,35 @@
 }
 
 /***********************************************************************
+ *           REGION_UnionRectWithRgn
+ *
+ * Add rectangle to region
+ */
+BOOL16 REGION_UnionRectWithRgn( HRGN32 hRgn, LPRECT16 rc )
+{
+  RGNOBJ 	*rgnObj = (RGNOBJ*) GDI_GetObjPtr( hRgn, REGION_MAGIC );
+  XRectangle     rect = { rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top };
+  BOOL16	 ret = 0; 
+
+  if( rgnObj )
+  {
+    if( !rgnObj->xrgn )
+    {
+      if (!(rgnObj->xrgn = XCreateRegion()))
+      {
+         GDI_FreeObject( hRgn );
+         return 0;
+      }
+      ret = SIMPLEREGION; 
+    }
+    else
+      ret = COMPLEXREGION;
+    XUnionRectWithRegion( &rect, rgnObj->xrgn, rgnObj->xrgn );
+  }
+  return ret;
+}
+
+/***********************************************************************
  *           REGION_CreateFrameRgn
  *
  * Create a region that is a frame around another region
diff --git a/resources/sysres.c b/resources/sysres.c
index 0b9f95b..ca79f6a 100644
--- a/resources/sysres.c
+++ b/resources/sysres.c
@@ -42,7 +42,7 @@
  *
  * Create a global memory block for a system resource.
  */
-HANDLE SYSRES_LoadResource( SYSTEM_RESOURCE id )
+HGLOBAL16 SYSRES_LoadResource( SYSTEM_RESOURCE id )
 {
     const struct resource *resPtr;
 
@@ -57,7 +57,7 @@
  *
  * Free a global memory block for a system resource.
  */
-void SYSRES_FreeResource( HANDLE handle )
+void SYSRES_FreeResource( HGLOBAL16 handle )
 {
     GLOBAL_FreeBlock( handle );
 }
diff --git a/tools/build-spec.txt b/tools/build-spec.txt
index a3fca04..cb78f01 100644
--- a/tools/build-spec.txt
+++ b/tools/build-spec.txt
@@ -13,10 +13,13 @@
 
 ORDINAL return EXPORTNAME ARGLENGTH RETVALUE
 
+ORDINAL extern EXPORTNAME SYMBOLNAME
+
 # COMMENT_TEXT
 
 --------------------
 General:
+========
 
     "name" and "type" fields are mandatory.  Specific ordinal
 declarations are optional, but the default handler will print an error
@@ -26,6 +29,7 @@
 '#' will be ignored as comments.
 
 Variable ordinals:
+==================
 
     This type defines data storage at the ordinal specified.  You may
 store items as bytes, 16-bit words, or 32-bit words.
@@ -39,6 +43,7 @@
 	2 byte VariableA(-1 0xff 0 0)
 
 Function ordinals:
+==================
 
     This type defines a function entry point.  The prototype defined by
 "EXPORTNAME ([ARGTYPE [ARGTYPE [...]]])" specifies the name available for
@@ -79,13 +84,21 @@
 
 	100 pascal GetFocus() WIN_GetFocus()
 
+To declare a function using a variable number of arguments, specify
+the function as taking no arguments. In this special case, in Win32
+the called function will be passed a pointer to the first arg; in
+Win16, the args are available with CURRENT_STACK16->args. See the
+wsprintf* functions in user.spec and user32.spec for an example.
+
 Stub ordinals:
+==============
 
     This type defines a stub function. It makes the name and ordinal
 available for dynamic linking, but will terminate execution with an
 error message if the function is ever called.
 
 Equate ordinals:
+================
 
     This type defines an ordinal as an absolute value.
 "ORDINAL" is replaced by the ordinal number corresponding to the
@@ -93,6 +106,7 @@
 "DATA" can be a decimal number or a hex number preceeded by "0x".
 
 Return ordinals:
+================
 
     This type defines a function entry point whose handler should do
 nothing but return a value.
@@ -100,3 +114,11 @@
 variable.  ARGLENGTH is the number of bytes that need to be removed
 from the stack before returning to the caller.  RETVALUE is the
 return value which will be passed back to the caller.
+
+Extern ordinals:
+================
+
+    This type defines an entry that simply maps to a Wine symbol
+(variable or function); "EXPORTNAME" will point to the symbol
+"SYMBOLNAME" that must be defined in C code. This type only works with
+Win32.
diff --git a/tools/build.c b/tools/build.c
index 3f18bde..554f9ec 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -10,31 +10,53 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include "wintypes.h"
 #include "registers.h"
 #include "winerror.h"  /* for ERROR_CALL_NOT_IMPLEMENTED */
 #include "module.h"
 #include "neexe.h"
 #include "windows.h"
 
-/* ELF symbols do not have an underscore in front */
-#if defined (__ELF__) || defined (__svr4__) || defined(_SCO_DS)
-#define PREFIX
+#ifdef NEED_UNDERSCORE_PREFIX
+# define PREFIX "_"
 #else
-#define PREFIX "_"
+# define PREFIX
 #endif
 
-#define TYPE_INVALID     0
-#define TYPE_BYTE        1  /* byte variable */
-#define TYPE_WORD        2  /* word variable */
-#define TYPE_LONG        3  /* long variable */
-#define TYPE_PASCAL_16   4  /* pascal function with 16-bit return (Win16) */
-#define TYPE_PASCAL      5  /* pascal function with 32-bit return (Win16) */
-#define TYPE_REGISTER    6  /* register function (Win16) */
-#define TYPE_ABS         7  /* absolute value */
-#define TYPE_RETURN      8  /* simple return value function */
-#define TYPE_STUB        9  /* unimplemented stub */
-#define TYPE_STDCALL    10  /* stdcall function (Win32) */
-#define TYPE_CDECL      11  /* cdecl function (Win32) */
+typedef enum
+{
+    TYPE_INVALID,
+    TYPE_BYTE,         /* byte variable */
+    TYPE_WORD,         /* word variable */
+    TYPE_LONG,         /* long variable */
+    TYPE_PASCAL_16,    /* pascal function with 16-bit return (Win16) */
+    TYPE_PASCAL,       /* pascal function with 32-bit return (Win16) */
+    TYPE_REGISTER,     /* register function (Win16) */
+    TYPE_ABS,          /* absolute value */
+    TYPE_RETURN,       /* simple return value function */
+    TYPE_STUB,         /* unimplemented stub */
+    TYPE_STDCALL,      /* stdcall function (Win32) */
+    TYPE_CDECL,        /* cdecl function (Win32) */
+    TYPE_EXTERN,       /* external symbol (Win32) */
+    TYPE_NBTYPES
+} ORD_TYPE;
+
+static const char * const TypeNames[TYPE_NBTYPES] =
+{
+    NULL,
+    "byte",         /* TYPE_BYTE */
+    "word",         /* TYPE_WORD */
+    "long",         /* TYPE_LONG */
+    "pascal16",     /* TYPE_PASCAL_16 */
+    "pascal",       /* TYPE_PASCAL */
+    "register",     /* TYPE_REGISTER */
+    "equate",       /* TYPE_ABS */
+    "return",       /* TYPE_RETURN */
+    "stub",         /* TYPE_STUB */
+    "stdcall",      /* TYPE_STDCALL */
+    "cdecl",        /* TYPE_CDECL */
+    "extern"        /* TYPE_EXTERN */
+};
 
 #define MAX_ORDINALS	1299
 
@@ -42,43 +64,60 @@
 #define STUB_CALLBACK \
   ((SpecType == SPEC_WIN16) ? "RELAY_Unimplemented16": "RELAY_Unimplemented32")
 
-enum SPEC_TYPE
+typedef enum
 {
     SPEC_INVALID,
     SPEC_WIN16,
     SPEC_WIN32
-};
+} SPEC_TYPE;
 
-typedef struct ordinal_definition_s
-{
-    int type;
-    int offset;
-    char export_name[80];
-    void *additional_data;
-} ORDDEF;
-
-typedef struct ordinal_variable_definition_s
+typedef struct
 {
     int n_values;
     int *values;
-} ORDVARDEF;
+} ORD_VARIABLE;
 
-typedef struct ordinal_function_definition_s
+typedef struct
 {
     int  n_args;
     char arg_types[32];
-    char internal_name[80];
-} ORDFUNCDEF;
+    char link_name[80];
+} ORD_FUNCTION;
 
-typedef struct ordinal_return_definition_s
+typedef struct
 {
     int arg_size;
     int ret_value;
-} ORDRETDEF;
+} ORD_RETURN;
+
+typedef struct
+{
+    int value;
+} ORD_ABS;
+
+typedef struct
+{
+    char link_name[80];
+} ORD_EXTERN;
+
+typedef struct
+{
+    ORD_TYPE    type;
+    int         offset;
+    char        name[80];
+    union
+    {
+        ORD_VARIABLE   var;
+        ORD_FUNCTION   func;
+        ORD_RETURN     ret;
+        ORD_ABS        abs;
+        ORD_EXTERN     ext;
+    } u;
+} ORDDEF;
 
 static ORDDEF OrdinalDefinitions[MAX_ORDINALS];
 
-static enum SPEC_TYPE SpecType = SPEC_INVALID;
+static SPEC_TYPE SpecType = SPEC_INVALID;
 char DLLName[80];
 int Limit = 0;
 int Base = 0;
@@ -211,20 +250,14 @@
     return token;
 }
 
-static int ParseVariable(int ordinal, int type)
+static int ParseVariable( ORDDEF *odp )
 {
-    ORDDEF *odp;
-    ORDVARDEF *vdp;
-    char export_name[80];
-    char *token;
     char *endptr;
     int *value_array;
     int n_values;
     int value_array_size;
     
-    strcpy(export_name, GetToken());
-
-    token = GetToken();
+    char *token = GetToken();
     if (*token != '(')
     {
 	fprintf(stderr, "%d: Expected '(' got '%s'\n", Line, token);
@@ -262,48 +295,33 @@
 	exit(1);
     }
 
-    if (ordinal >= MAX_ORDINALS)
-    {
-	fprintf(stderr, "%d: Ordinal number too large\n", Line);
-	exit(1);
-    }
-    
-    odp = &OrdinalDefinitions[ordinal];
-    odp->type = type;
-    strcpy(odp->export_name, export_name);
-
-    vdp = xmalloc(sizeof(*vdp));
-    odp->additional_data = vdp;
-    
-    vdp->n_values = n_values;
-    vdp->values = xrealloc(value_array, sizeof(*value_array) * n_values);
+    odp->u.var.n_values = n_values;
+    odp->u.var.values = xrealloc(value_array, sizeof(*value_array) * n_values);
 
     return 0;
 }
 
-static int ParseExportFunction(int ordinal, int type)
+static int ParseExportFunction( ORDDEF *odp )
 {
     char *token;
-    ORDDEF *odp;
-    ORDFUNCDEF *fdp;
     int i;
 
     switch(SpecType)
     {
     case SPEC_WIN16:
-        if (type == TYPE_STDCALL)
+        if (odp->type == TYPE_STDCALL)
         {
             fprintf( stderr, "%d: 'stdcall' not supported for Win16\n", Line );
             exit(1);
         }
-        if (type == TYPE_CDECL)
+        if (odp->type == TYPE_CDECL)
         {
             fprintf( stderr, "%d: 'cdecl' not supported for Win16\n", Line );
             exit(1);
         }
         break;
     case SPEC_WIN32:
-        if ((type == TYPE_PASCAL) || (type == TYPE_PASCAL_16))
+        if ((odp->type == TYPE_PASCAL) || (odp->type == TYPE_PASCAL_16))
         {
             fprintf( stderr, "%d: 'pascal' not supported for Win32\n", Line );
             exit(1);
@@ -312,11 +330,6 @@
     default:
         break;
     }
-    odp = &OrdinalDefinitions[ordinal];
-    strcpy(odp->export_name, GetToken());
-    odp->type = type;
-    fdp = xmalloc(sizeof(*fdp));
-    odp->additional_data = fdp;
 
     token = GetToken();
     if (*token != '(')
@@ -325,20 +338,20 @@
 	exit(1);
     }
 
-    for (i = 0; i < sizeof(fdp->arg_types)-1; i++)
+    for (i = 0; i < sizeof(odp->u.func.arg_types)-1; i++)
     {
 	token = GetToken();
 	if (*token == ')')
 	    break;
 
         if (!strcmp(token, "byte") || !strcmp(token, "word"))
-            fdp->arg_types[i] = 'w';
+            odp->u.func.arg_types[i] = 'w';
         else if (!strcmp(token, "s_byte") || !strcmp(token, "s_word"))
-            fdp->arg_types[i] = 's';
+            odp->u.func.arg_types[i] = 's';
         else if (!strcmp(token, "long") || !strcmp(token, "segptr"))
-            fdp->arg_types[i] = 'l';
+            odp->u.func.arg_types[i] = 'l';
         else if (!strcmp(token, "ptr"))
-            fdp->arg_types[i] = 'p';
+            odp->u.func.arg_types[i] = 'p';
         else
         {
             fprintf(stderr, "%d: Unknown variable type '%s'\n", Line, token);
@@ -359,25 +372,25 @@
         fprintf( stderr, "%d: Too many arguments\n", Line );
         exit(1);
     }
-    fdp->arg_types[i] = '\0';
-    if ((type == TYPE_STDCALL) && !i)
+    odp->u.func.arg_types[i] = '\0';
+    if ((odp->type == TYPE_STDCALL) && !i)
         odp->type = TYPE_CDECL; /* stdcall is the same as cdecl for 0 args */
-    strcpy(fdp->internal_name, GetToken());
+    strcpy(odp->u.func.link_name, GetToken());
     return 0;
 }
 
-static int ParseEquate(int ordinal)
-{
-    ORDDEF *odp;
-    char *token;
-    char *endptr;
-    int value;
-    
-    odp = &OrdinalDefinitions[ordinal];
-    strcpy(odp->export_name, GetToken());
 
-    token = GetToken();
-    value = strtol(token, &endptr, 0);
+/*******************************************************************
+ *         ParseEquate
+ *
+ * Parse an 'equate' definition.
+ */
+static int ParseEquate( ORDDEF *odp )
+{
+    char *endptr;
+    
+    char *token = GetToken();
+    int value = strtol(token, &endptr, 0);
     if (endptr == NULL || *endptr != '\0')
     {
 	fprintf(stderr, "%d: Expected number value, got '%s'\n", Line,
@@ -385,28 +398,23 @@
 	exit(1);
     }
 
-    odp->type = TYPE_ABS;
-    odp->additional_data = (void *) value;
-
+    odp->u.abs.value = value;
     return 0;
 }
 
-static int ParseReturn(int ordinal)
+
+/*******************************************************************
+ *         ParseReturn
+ *
+ * Parse a 'return' definition.
+ */
+static int ParseReturn( ORDDEF *odp )
 {
-    ORDDEF *odp;
-    ORDRETDEF *rdp;
     char *token;
     char *endptr;
     
-    rdp = xmalloc(sizeof(*rdp));
-    
-    odp = &OrdinalDefinitions[ordinal];
-    strcpy(odp->export_name, GetToken());
-    odp->type = TYPE_RETURN;
-    odp->additional_data = rdp;
-
     token = GetToken();
-    rdp->arg_size = strtol(token, &endptr, 0);
+    odp->u.ret.arg_size = strtol(token, &endptr, 0);
     if (endptr == NULL || *endptr != '\0')
     {
 	fprintf(stderr, "%d: Expected number value, got '%s'\n", Line,
@@ -415,7 +423,7 @@
     }
 
     token = GetToken();
-    rdp->ret_value = strtol(token, &endptr, 0);
+    odp->u.ret.ret_value = strtol(token, &endptr, 0);
     if (endptr == NULL || *endptr != '\0')
     {
 	fprintf(stderr, "%d: Expected number value, got '%s'\n", Line,
@@ -427,26 +435,46 @@
 }
 
 
-static int ParseStub( int ordinal )
+/*******************************************************************
+ *         ParseStub
+ *
+ * Parse a 'stub' definition.
+ */
+static int ParseStub( ORDDEF *odp )
 {
-    ORDDEF *odp;
-    ORDFUNCDEF *fdp;
-    
-    odp = &OrdinalDefinitions[ordinal];
-    strcpy( odp->export_name, GetToken() );
-    odp->type = TYPE_STUB;
-    fdp = xmalloc(sizeof(*fdp));
-    odp->additional_data = fdp;
-    fdp->arg_types[0] = '\0';
-    strcpy( fdp->internal_name, STUB_CALLBACK );
+    odp->u.func.arg_types[0] = '\0';
+    strcpy( odp->u.func.link_name, STUB_CALLBACK );
     return 0;
 }
 
 
+/*******************************************************************
+ *         ParseExtern
+ *
+ * Parse an 'extern' definition.
+ */
+static int ParseExtern( ORDDEF *odp )
+{
+    if (SpecType == SPEC_WIN16)
+    {
+        fprintf( stderr, "%d: 'extern' not supported for Win16\n", Line );
+        exit(1);
+    }
+    strcpy( odp->u.ext.link_name, GetToken() );
+    return 0;
+}
+
+
+/*******************************************************************
+ *         ParseOrdinal
+ *
+ * Parse an ordinal definition.
+ */
 static int ParseOrdinal(int ordinal)
 {
+    ORDDEF *odp;
     char *token;
-    
+
     if (ordinal >= MAX_ORDINALS)
     {
 	fprintf(stderr, "%d: Ordinal number too large\n", Line);
@@ -454,39 +482,56 @@
     }
     if (ordinal > Limit) Limit = ordinal;
 
-    token = GetToken();
-    if (token == NULL)
+    odp = &OrdinalDefinitions[ordinal];
+    if (!(token = GetToken()))
     {
 	fprintf(stderr, "%d: Expected type after ordinal\n", Line);
 	exit(1);
     }
 
-    if (strcmp(token, "byte") == 0)
-	return ParseVariable(ordinal, TYPE_BYTE);
-    if (strcmp(token, "word") == 0)
-	return ParseVariable(ordinal, TYPE_WORD);
-    if (strcmp(token, "long") == 0)
-	return ParseVariable(ordinal, TYPE_LONG);
-    if (strcmp(token, "pascal") == 0)
-	return ParseExportFunction(ordinal, TYPE_PASCAL);
-    if (strcmp(token, "pascal16") == 0)
-	return ParseExportFunction(ordinal, TYPE_PASCAL_16);
-    if (strcmp(token, "register") == 0)
-        return ParseExportFunction(ordinal, TYPE_REGISTER);
-    if (strcmp(token, "stdcall") == 0)
-        return ParseExportFunction(ordinal, TYPE_STDCALL);
-    if (strcmp(token, "cdecl") == 0)
-        return ParseExportFunction(ordinal, TYPE_CDECL);
-    if (strcmp(token, "equate") == 0)
-	return ParseEquate(ordinal);
-    if (strcmp(token, "return") == 0)
-	return ParseReturn(ordinal);
-    if (strcmp(token, "stub") == 0)
-	return ParseStub(ordinal);
-    fprintf(stderr, 
-            "%d: Expected type after ordinal, found '%s' instead\n",
-            Line, token);
-    exit(1);
+    for (odp->type = 0; odp->type < TYPE_NBTYPES; odp->type++)
+        if (TypeNames[odp->type] && !strcmp( token, TypeNames[odp->type] ))
+            break;
+
+    if (odp->type >= TYPE_NBTYPES)
+    {
+        fprintf( stderr,
+                 "%d: Expected type after ordinal, found '%s' instead\n",
+                 Line, token );
+        exit(1);
+    }
+
+    if (!(token = GetToken()))
+    {
+        fprintf( stderr, "%d: Expected name after type\n", Line );
+        exit(1);
+    }
+    strcpy( odp->name, token );
+
+    switch(odp->type)
+    {
+    case TYPE_BYTE:
+    case TYPE_WORD:
+    case TYPE_LONG:
+	return ParseVariable( odp );
+    case TYPE_PASCAL_16:
+    case TYPE_PASCAL:
+    case TYPE_REGISTER:
+    case TYPE_STDCALL:
+    case TYPE_CDECL:
+	return ParseExportFunction( odp );
+    case TYPE_ABS:
+	return ParseEquate( odp );
+    case TYPE_RETURN:
+	return ParseReturn( odp );
+    case TYPE_STUB:
+	return ParseStub( odp );
+    case TYPE_EXTERN:
+	return ParseExtern( odp );
+    default:
+        fprintf( stderr, "Should not happen\n" );
+        exit(1);
+    }
 }
 
 static int ParseTopLevel(void)
@@ -559,26 +604,24 @@
  */
 static int StoreVariableCode( unsigned char *buffer, int size, ORDDEF *odp )
 {
-    ORDVARDEF *vdp;
     int i;
 
-    vdp = odp->additional_data;
     switch(size)
     {
     case 1:
-        for (i = 0; i < vdp->n_values; i++)
-            buffer[i] = vdp->values[i];
+        for (i = 0; i < odp->u.var.n_values; i++)
+            buffer[i] = odp->u.var.values[i];
         break;
     case 2:
-        for (i = 0; i < vdp->n_values; i++)
-            ((unsigned short *)buffer)[i] = vdp->values[i];
+        for (i = 0; i < odp->u.var.n_values; i++)
+            ((unsigned short *)buffer)[i] = odp->u.var.values[i];
         break;
     case 4:
-        for (i = 0; i < vdp->n_values; i++)
-            ((unsigned int *)buffer)[i] = vdp->values[i];
+        for (i = 0; i < odp->u.var.n_values; i++)
+            ((unsigned int *)buffer)[i] = odp->u.var.values[i];
         break;
     }
-    return vdp->n_values * size;
+    return odp->u.var.n_values * size;
 }
 
 
@@ -719,9 +762,9 @@
     odp = OrdinalDefinitions + 1;
     for (i = 1; i <= Limit; i++, odp++)
     {
-        if (!odp->export_name[0]) continue;
-        *pstr = strlen( odp->export_name );
-        strcpy( pstr + 1, odp->export_name );
+        if (!odp->name[0]) continue;
+        *pstr = strlen( odp->name );
+        strcpy( pstr + 1, odp->name );
         strupper( pstr + 1 );
         pstr += *pstr + 1;
         *(WORD *)pstr = i;
@@ -740,10 +783,6 @@
 
 	switch (odp->type)
 	{
-        case TYPE_INVALID:
-            selector = 0;  /* Invalid selector */
-            break;
-
         case TYPE_PASCAL:
         case TYPE_PASCAL_16:
         case TYPE_REGISTER:
@@ -761,6 +800,10 @@
         case TYPE_ABS:
             selector = 0xfe;  /* Constant selector */
             break;
+
+        default:
+            selector = 0;  /* Invalid selector */
+            break;
         }
 
           /* create a new bundle if necessary */
@@ -908,8 +951,6 @@
 static void BuildSpec32Files(void)
 {
     ORDDEF *odp;
-    ORDFUNCDEF *fdp;
-    ORDRETDEF *rdp;
     int i, module_size, len;
     char buffer[1024];
 
@@ -921,9 +962,6 @@
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
     {
-        fdp = odp->additional_data;
-        rdp = odp->additional_data;
-
         switch (odp->type)
         {
         case TYPE_INVALID:
@@ -933,26 +971,26 @@
         case TYPE_CDECL:
         case TYPE_STUB:
             printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->export_name);
+                     DLLName, i, odp->name);
             printf( "%s_%d:\n", DLLName, i );
             printf( "\tpushl %%ebp\n" );
-            printf( "\tpushl $" PREFIX "%s\n", fdp->internal_name );
+            printf( "\tpushl $" PREFIX "%s\n", odp->u.func.link_name );
             printf( "\tcall " PREFIX "CallFrom32_%s_%d\n",
                     (odp->type == TYPE_STDCALL) ? "stdcall" : "cdecl",
-                    strlen(fdp->arg_types));
+                    strlen(odp->u.func.arg_types));
             printf( "\tnop\n" );
             break;
 
         case TYPE_RETURN:
             printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->export_name);
+                     DLLName, i, odp->name);
             printf( "%s_%d:\n", DLLName, i );
             printf( "\tmovl $%d,%%eax\n", ERROR_CALL_NOT_IMPLEMENTED );
             printf( "\tmovl %%eax," PREFIX "WIN32_LastError\n" );
-            printf( "\tmovl $%d,%%eax\n", rdp->ret_value );
-            if (rdp->arg_size)
+            printf( "\tmovl $%d,%%eax\n", odp->u.ret.ret_value );
+            if (odp->u.ret.arg_size)
             {
-                printf( "\tret $%d\n", rdp->arg_size );
+                printf( "\tret $%d\n", odp->u.ret.arg_size );
                 printf( "\tnop\n" );
                 printf( "\tnop\n" );
             }
@@ -961,7 +999,7 @@
 
         case TYPE_BYTE:
             printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->export_name);
+                     DLLName, i, odp->name);
             printf( "\t.data\n" );
             printf( "%s_%d:\n", DLLName, i );
             len = StoreVariableCode( buffer, 1, odp );
@@ -971,7 +1009,7 @@
 
         case TYPE_WORD:
             printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->export_name);
+                     DLLName, i, odp->name);
             printf( "\t.data\n" );
             printf( "%s_%d:\n", DLLName, i );
             len = StoreVariableCode( buffer, 2, odp );
@@ -981,7 +1019,7 @@
 
         case TYPE_LONG:
             printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->export_name);
+                     DLLName, i, odp->name);
             printf( "\t.data\n" );
             printf( "%s_%d:\n", DLLName, i );
             len = StoreVariableCode( buffer, 4, odp );
@@ -989,6 +1027,9 @@
             printf( "\t.text\n" );
             break;
 
+        case TYPE_EXTERN:
+            break;
+
         default:
             fprintf(stderr,"build: function type %d not available for Win32\n",
                     odp->type);
@@ -1006,8 +1047,18 @@
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
     {
-        if (odp->type == TYPE_INVALID) printf( "\t.long 0\n" );
-        else printf("\t.long %s_%d\n", DLLName, i);
+        switch(odp->type)
+        {
+        case TYPE_INVALID:
+            printf( "\t.long 0\n" );
+            break;
+        case TYPE_EXTERN:
+            printf( "\t.long " PREFIX "%s\n", odp->u.ext.link_name );
+            break;
+        default:
+            printf( "\t.long %s_%d\n", DLLName, i );
+            break;
+        }
     }
 
     /* Output the DLL names table */
@@ -1025,7 +1076,7 @@
     for (i = 0, odp = OrdinalDefinitions; i <= Limit; i++, odp++)
     {
         if (odp->type != TYPE_INVALID)
-            printf( "Name_%d:\t.ascii \"%s\\0\"\n", i, odp->export_name );
+            printf( "Name_%d:\t.ascii \"%s\\0\"\n", i, odp->name );
     }
 
     /* Output the DLL descriptor */
@@ -1052,8 +1103,6 @@
 static void BuildSpec16Files(void)
 {
     ORDDEF *odp;
-    ORDFUNCDEF *fdp;
-    ORDRETDEF *rdp;
     int i;
     int code_offset, data_offset, module_size;
     unsigned char *data;
@@ -1070,9 +1119,6 @@
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
     {
-        fdp = odp->additional_data;
-        rdp = odp->additional_data;
-	    
         switch (odp->type)
         {
           case TYPE_INVALID:
@@ -1080,7 +1126,7 @@
             break;
 
           case TYPE_ABS:
-            odp->offset = (int)odp->additional_data & 0xffff;
+            odp->offset = LOWORD(odp->u.abs.value);
             break;
 
           case TYPE_BYTE:
@@ -1100,11 +1146,11 @@
 
           case TYPE_RETURN:
             printf( "/* %s.%d */\n", DLLName, i);
-            printf( "\tmovw $%d,%%ax\n", rdp->ret_value & 0xffff );
-            printf( "\tmovw $%d,%%dx\n", (rdp->ret_value >> 16) & 0xffff);
+            printf( "\tmovw $%d,%%ax\n", LOWORD(odp->u.ret.ret_value) );
+            printf( "\tmovw $%d,%%dx\n", HIWORD(odp->u.ret.ret_value) );
             printf( "\t.byte 0x66\n");
-            if (rdp->arg_size != 0)
-                printf( "\tlret $%d\n\n", rdp->arg_size);
+            if (odp->u.ret.arg_size != 0)
+                printf( "\tlret $%d\n\n", odp->u.ret.arg_size);
             else
             {
                 printf( "\tlret\n");
@@ -1121,13 +1167,13 @@
           case TYPE_STUB:
             printf( "/* %s.%d */\n", DLLName, i);
             printf( "\tpushw %%bp\n" );
-            printf( "\tpushl $" PREFIX "%s\n", fdp->internal_name );
+            printf( "\tpushl $" PREFIX "%s\n", odp->u.func.link_name );
             /* FreeBSD does not understand lcall, so do it the hard way */
             printf( "\t.byte 0x9a /*lcall*/\n" );
             printf( "\t.long " PREFIX "CallFrom16_%s_%s\n",
                     (odp->type == TYPE_REGISTER) ? "regs" :
                     (odp->type == TYPE_PASCAL) ? "long" : "word",
-                    fdp->arg_types );
+                    odp->u.func.arg_types );
             printf( "\t.byte 0x%02x,0x%02x\n", /* Some asms don't have .word */
                     LOBYTE(WINE_CODE_SELECTOR), HIBYTE(WINE_CODE_SELECTOR) );
             printf( "\tnop\n" );
diff --git a/win32/code_page.c b/win32/code_page.c
index 43dc261..731dd45 100644
--- a/win32/code_page.c
+++ b/win32/code_page.c
@@ -7,7 +7,6 @@
 #include <stdio.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "winnls.h"
 #include "stddebug.h"
 #include "debug.h"
diff --git a/win32/console.c b/win32/console.c
index 48215cf..d933df5 100644
--- a/win32/console.c
+++ b/win32/console.c
@@ -7,7 +7,6 @@
 #include <stdio.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "wincon.h"
 #include "stddebug.h"
 #include "debug.h"
diff --git a/win32/environment.c b/win32/environment.c
index 3ea2385..85d4083 100644
--- a/win32/environment.c
+++ b/win32/environment.c
@@ -9,7 +9,6 @@
 #include <unistd.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "module.h"
 #include "task.h"
 #include "stddebug.h"
@@ -19,7 +18,7 @@
 /***********************************************************************
  *           GetCommandLineA      (KERNEL32.161)
  */
-LPSTR GetCommandLineA(void)
+LPCSTR GetCommandLine32A(void)
 {
     static char buffer[256];
     char *cp;
@@ -37,6 +36,17 @@
     return buffer;
 }
 
+/***********************************************************************
+ *           GetCommandLineW      (KERNEL32.162)
+ */
+LPCWSTR GetCommandLine32W(void)
+{
+    static WCHAR buffer[256];
+
+    lstrcpynAtoW(buffer,GetCommandLine32A(),256);
+    return buffer;
+}
+
 
 /***********************************************************************
  *           GetSystemPowerStatus      (KERNEL32.621)
diff --git a/win32/error.c b/win32/error.c
index 242bcc0..8a8ac31 100644
--- a/win32/error.c
+++ b/win32/error.c
@@ -8,7 +8,6 @@
 #include <errno.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "stddebug.h"
 #include "debug.h"
 
diff --git a/win32/except.c b/win32/except.c
index 25d2585..50186ee 100644
--- a/win32/except.c
+++ b/win32/except.c
@@ -35,7 +35,6 @@
 #include <stdio.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "stddebug.h"
 #include "debug.h"
 #include "except.h"
diff --git a/win32/file.c b/win32/file.c
index ffb0b2f..c07faa0 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -16,7 +16,6 @@
 #include "windows.h"
 #include "winbase.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "handle32.h"
 #include "dos_fs.h"
 #include "stddebug.h"
diff --git a/win32/findfile.c b/win32/findfile.c
index 47b9d9e..f0a672b 100644
--- a/win32/findfile.c
+++ b/win32/findfile.c
@@ -5,50 +5,150 @@
 #include "windows.h"
 #include "winbase.h"
 #include "dos_fs.h"
+#include "heap.h"
+#include <ctype.h>
+
+#define PATH_LEN 260
+
+struct FindFileContext32 {
+    DIR *	dir;
+    char mask[PATH_LEN];
+    char path[PATH_LEN];
+};
+
+typedef struct FindFileContext32 FindFileContext32;
+
+const char *DOSFS_Hash(const char *, int);
+
+/* example D:\*.dbs */
+
+static BOOL32 MatchWildCard(LPCSTR file, LPCSTR mask)
+{
+    int	len;
+
+    /* We should check volume information to see if long filenames possible.
+     */
+
+    len = strlen(file);
+
+    while (*file) {
+	if (*mask == '*') {
+	    if (*(mask+1)) {
+		while (*file && (toupper(*file) != *(mask+1))) file++;
+		if (!*file)
+		    return FALSE;
+	    }
+	    else
+		break;
+	}
+	else {
+	    if (*mask != '?' && *mask != toupper(*file)) {
+		return FALSE;
+	    }
+	    file++;
+	}
+	mask++;
+    }
+    return (TRUE);
+}
+
+/*************************************************************************
+ *              FindNextFile32A             (KERNEL32.126)
+ */
+
+BOOL32 FindNextFile32A(HANDLE32 handle, LPWIN32_FIND_DATA32A data)
+{
+    FindFileContext32 *context;
+    struct dirent *dirent;
+    char  dosname[14];
+
+    memset(data, 0, sizeof(WIN32_FIND_DATA32A));
+    context = (FindFileContext32 *) handle;
+
+    while ((dirent = readdir(context->dir)) != NULL) {
+	if (strcmp(dirent->d_name, "..") == 0 ||
+	    strcmp(dirent->d_name, ".") == 0)
+	    continue;
+
+	strcpy(dosname, DOSFS_Hash(dirent->d_name, FALSE));
+
+	if (MatchWildCard(dirent->d_name, context->mask)) {
+	    /* Full file name - is this a long file name?
+	     * If it is, we should probably use the dirent
+	     * instead of the dos hashed name.
+	     */
+	    strcpy(data->cFileName, dosname);
+
+	    /* file name expressed in 8.3 format */
+	    strcpy(data->cAlternateFileName, dosname);
+	    return (TRUE);
+	}
+    }
+    
+    return (FALSE);
+}
+
+/*************************************************************************
+ *              FindFirstFile32A             (KERNEL32.123)
+ */
 
 HANDLE32 FindFirstFile32A(LPCSTR lpfilename, 
 			  LPWIN32_FIND_DATA32A lpFindFileData)
-
 {
-	char *unixpath = DOSFS_GetUnixFileName(lpfilename, FALSE);
-	char *p;
-	char *path;
-	char *mask;
-	DIR *dir;
-	struct dirent *dirent;
-	int namelen;
-	char *foundname;
+    const char *unixpath;
+    char *slash, *p;
+    FindFileContext32 *context;
 
+    context = HeapAlloc(SystemHeap, 0, sizeof(FindFileContext32));
+    if (!context)
+	return (INVALID_HANDLE_VALUE);
+
+    slash = strrchr(lpfilename, '\\');
+    if (slash) {
+	lstrcpyn32A(context->path, lpfilename, slash - lpfilename + 1);
+	context->path[slash - lpfilename + 1] = '\0';
+	unixpath = DOSFS_GetUnixFileName(context->path, FALSE);
 	if (!unixpath) {
-		/* FIXME: SetLastError(??) */
-		return INVALID_HANDLE_VALUE;
+	    /* FIXME: SetLastError(??) */
+	    HeapFree(SystemHeap, 0, context);
+	    return INVALID_HANDLE_VALUE;
 	}
-	p = strrchr(unixpath, '/');
-	if (p) {
-		*p = '\0';
-		path = unixpath;
-		mask = p + 1;
-	} else {
-		path = ".";
-		mask = unixpath;
-	}
-	dir = opendir(path);
-	if (!dir) {
-		/* FIXME: SetLastError(??) */
-		return INVALID_HANDLE_VALUE;
-	}
-	while ((dirent = readdir(dir)) != NULL) {
-		if (!DOSFS_Match(DOSFS_Hash(dirent->d_name, TRUE)))
-			continue;
-		/* FIXME: Ought to fiddle to avoid
-                   returning ./.. in drive root */
-		namelen = strlen(path) + strlen(dirent->d_name);
-		foundname = xmalloc(namelen+1);
-		strcpy(foundname, path);
-		strcat(foundname, dirent->d_name);
-		strcpy(lpFindFileData->FileName, DOSFS_GetDosTrueName(foundname, TRUE));
-		free(foundname);
-		return dir;
-	}
+	lstrcpy32A(context->mask, slash+1);
+    }
+    else {
+	context->path[0] = '\0';
+	unixpath = ".";
+	lstrcpy32A(context->mask, lpfilename);
+    }
+
+    context->dir = opendir(unixpath);
+    if (!context->dir) {
+	/* FIXME: SetLastError(??) */
+	HeapFree(SystemHeap, 0, context);
 	return INVALID_HANDLE_VALUE;
+    }
+
+    strcpy(context->mask, slash+1);
+
+    /* uppercase mask in place */
+    for (p = context->mask ; *p; p++)
+	*p = toupper(*p);
+
+    if (!FindNextFile32A((HANDLE32) context, lpFindFileData))
+	return (INVALID_HANDLE_VALUE);
+    return ((HANDLE32) context);
+}
+
+/*************************************************************************
+ *              FindClose             (KERNEL32.119)
+ */
+BOOL32 FindClose(HANDLE32 handle)
+{
+    FindFileContext32 *context;
+
+    context = (FindFileContext32 *) handle;
+    if (context->dir)
+	closedir(context->dir);
+    HeapFree(SystemHeap, 0, context);
+    return (TRUE);
 }
diff --git a/win32/init.c b/win32/init.c
index 91f0128..4b4b7cb 100644
--- a/win32/init.c
+++ b/win32/init.c
@@ -9,7 +9,6 @@
 #include <unistd.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "handle32.h"
 #include "except.h"
 #include "task.h"
diff --git a/win32/memory.c b/win32/memory.c
index 952c2e2..86bca6e 100644
--- a/win32/memory.c
+++ b/win32/memory.c
@@ -14,7 +14,6 @@
 #include <stdlib.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "winbase.h"
 #include "handle32.h"
 #include "stddebug.h"
diff --git a/win32/newfns.c b/win32/newfns.c
index 31d116b..4ea3beb 100644
--- a/win32/newfns.c
+++ b/win32/newfns.c
@@ -10,7 +10,6 @@
 #include <stdio.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "stddebug.h"
 #include "debug.h"
 
diff --git a/win32/process.c b/win32/process.c
index 47c2873..eb02e54 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -9,7 +9,6 @@
 #include <unistd.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "handle32.h"
 #include "task.h"
 #include "stddebug.h"
diff --git a/win32/thread.c b/win32/thread.c
index 1d539dc..6b67874 100644
--- a/win32/thread.c
+++ b/win32/thread.c
@@ -10,7 +10,6 @@
 #include "windows.h"
 #include "winbase.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
diff --git a/win32/time.c b/win32/time.c
index 3ac2e9c..797cbe7 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -10,7 +10,6 @@
 #include <unistd.h>
 #include "windows.h"
 #include "winerror.h"
-#include "kernel32.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -119,7 +118,7 @@
 /***********************************************************************
  *              SetTimeZoneInformation  (KERNEL32.515)
  */
-BOOL32 SetTimeZoneInformation(const TIME_ZONE_INFORMATION *tzinfo)
+BOOL32 SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo)
 {
     struct timezone tz;
 
diff --git a/windows/dce.c b/windows/dce.c
index 58ada2a..b52d547 100644
--- a/windows/dce.c
+++ b/windows/dce.c
@@ -302,8 +302,9 @@
     int xoffset, yoffset;
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
-      /* Get visible rectangle and create a region with it 
-       * FIXME: do we really need to calculate vis rgns for X windows? 
+      /* Get visible rectangle and create a region with it. 
+       * do we really need to calculate vis rgns for X windows? 
+       * - yes, to clip child windows.
        */
 
     if (!wndPtr || !DCE_GetVisRect( wndPtr, !(flags & DCX_WINDOW), &rect ))
diff --git a/windows/defwnd.c b/windows/defwnd.c
index 87dc7d4..43b4ddc 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -319,7 +319,7 @@
 
     case WM_QUERYDRAGICON:
         {
-            HICON hI = 0;
+            HICON16 hI = 0;
             UINT16 len = 1;
             while(len < 64)
 		if( (hI = LoadIcon16(wndPtr->hInstance,MAKEINTRESOURCE(len))) )
diff --git a/windows/dialog.c b/windows/dialog.c
index 3fbcb14..21ff837 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -623,7 +623,7 @@
                             HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
 {
     HWND16 hwnd = 0;
-    HRSRC hRsrc;
+    HRSRC16 hRsrc;
     HGLOBAL16 hmem;
     LPCVOID data;
 
diff --git a/windows/mdi.c b/windows/mdi.c
index 2ff08e2..3d1984c 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -841,7 +841,7 @@
 BOOL MDI_AugmentFrameMenu(MDICLIENTINFO* ci, WND *frame, HWND hChild)
 {
  WND*		child = WIN_FindWndPtr(hChild);
- HGLOBAL        handle;
+ HGLOBAL16      handle;
  HMENU  	hSysPopup = 0;
 
  dprintf_mdi(stddeb,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame,hChild);
diff --git a/windows/message.c b/windows/message.c
index 82d04dd..82870e4 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -13,6 +13,7 @@
 #include "win.h"
 #include "gdi.h"
 #include "sysmetrics.h"
+#include "heap.h"
 #include "hook.h"
 #include "spy.h"
 #include "stackframe.h"
@@ -259,13 +260,37 @@
         if ((msg->hwnd != GetDesktopWindow()) && 
             (GetWindowTask16(msg->hwnd) != GetCurrentTask()))
             continue;  /* Not for this task */
-        if (remove)
+        if (remove && HOOK_GetHook( WH_JOURNALRECORD, GetTaskQueue(0) ))
         {
-            MSG16 tmpMsg = *msg; /* FIXME */
-            HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION,
-                            0, (LPARAM)MAKE_SEGPTR(&tmpMsg) );
-            QUEUE_RemoveMsg( sysMsgQueue, pos );
+            EVENTMSG16 *event = SEGPTR_NEW(EVENTMSG16);
+            if (event)
+            {
+                event->message = msg->message;
+                event->time = msg->time;
+                if ((msg->message >= WM_KEYFIRST) &&
+                    (msg->message <= WM_KEYLAST))
+                {
+                    event->paramL = (msg->wParam & 0xFF) |
+                                    (HIWORD(msg->lParam) << 8);
+                    event->paramH = msg->lParam & 0x7FFF;  
+                    if (HIWORD(msg->lParam) & 0x0100)
+                        event->paramH |= 0x8000;  /* special_key - bit */
+                    HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION,
+                                    0, (LPARAM)SEGPTR_GET(event) );
+                }
+                else if ((msg->message >= WM_MOUSEFIRST) &&
+                         (msg->message <= WM_MOUSELAST))
+                {
+                    event->paramL = LOWORD(msg->lParam);       /* X pos */
+                    event->paramH = HIWORD(msg->lParam);       /* Y pos */ 
+                    ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
+                    HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION,
+                                    0, (LPARAM)SEGPTR_GET(event) );
+                }
+                SEGPTR_FREE(event);
+            }
         }
+        if (remove) QUEUE_RemoveMsg( sysMsgQueue, pos );
         return TRUE;
     }
     return FALSE;
@@ -295,8 +320,8 @@
  *
  * Implementation of an inter-task SendMessage.
  */
-static LRESULT MSG_SendMessage( HQUEUE hDestQueue, HWND hwnd, UINT msg,
-                         WPARAM wParam, LPARAM lParam )
+static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND hwnd, UINT msg,
+                                WPARAM wParam, LPARAM lParam )
 {
     MESSAGEQUEUE *queue, *destQ;
 
@@ -372,7 +397,7 @@
 {
     int pos, mask;
     MESSAGEQUEUE *msgQueue;
-    HQUEUE	  hQueue;
+    HQUEUE16 hQueue;
 
 #ifdef CONFIG_IPC
     DDE_TestDDE(hwnd);	/* do we have dde handling in the window ?*/
@@ -681,6 +706,8 @@
         fprintf( stderr, "SendMessage16: invalid hwnd %04x\n", hwnd );
         return 0;
     }
+    if (wndPtr->hmemTaskQ == QUEUE_GetDoomedQueue())
+        return 0;  /* Don't send anything if the task is dying */
     if (wndPtr->hmemTaskQ != GetTaskQueue(0))
         return MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam );
 
@@ -731,6 +758,8 @@
         return ret;
     }
 
+    if (wndPtr->hmemTaskQ == QUEUE_GetDoomedQueue())
+        return 0;  /* Don't send anything if the task is dying */
     if (wndPtr->hmemTaskQ != GetTaskQueue(0))
     {
         fprintf( stderr, "SendMessage32A: intertask message not supported\n" );
@@ -771,6 +800,8 @@
         fprintf( stderr, "SendMessage32W: invalid hwnd %08x\n", hwnd );
         return 0;
     }
+    if (wndPtr->hmemTaskQ == QUEUE_GetDoomedQueue())
+        return 0;  /* Don't send anything if the task is dying */
     if (wndPtr->hmemTaskQ != GetTaskQueue(0))
     {
         fprintf( stderr, "SendMessage32W: intertask message not supported\n" );
diff --git a/windows/property.c b/windows/property.c
index 22bcf98..4b0796b 100644
--- a/windows/property.c
+++ b/windows/property.c
@@ -5,6 +5,7 @@
  */
 
 #define NO_TRANSITION_TYPES  /* This file is Win32-clean */
+#include <stdlib.h>
 #include <string.h>
 #include "win.h"
 #include "heap.h"
diff --git a/windows/queue.c b/windows/queue.c
index 1d3437e..3ae6306 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -22,18 +22,6 @@
 static MESSAGEQUEUE *sysMsgQueue = NULL;
 
 /***********************************************************************
- *	     QUEUE_GetDoomedQueue/QUEUE_SetDoomedQueue
- */
-HQUEUE QUEUE_GetDoomedQueue()
-{
-  return hDoomedQueue;
-}
-void QUEUE_SetDoomedQueue(HQUEUE hQueue)
-{
-  hDoomedQueue = hQueue;
-}
-
-/***********************************************************************
  *	     QUEUE_DumpQueue
  */
 void QUEUE_DumpQueue( HQUEUE16 hQueue )
@@ -75,7 +63,7 @@
  */
 void QUEUE_WalkQueues(void)
 {
-    HQUEUE hQueue = hFirstQueue;
+    HQUEUE16 hQueue = hFirstQueue;
 
     fprintf( stderr, "Queue Size Msgs Task\n" );
     while (hQueue)
@@ -96,13 +84,31 @@
 
 
 /***********************************************************************
+ *	     QUEUE_GetDoomedQueue/QUEUE_SetDoomedQueue
+ */
+HQUEUE16 QUEUE_GetDoomedQueue()
+{
+    return hDoomedQueue;
+}
+
+
+/***********************************************************************
+ *	     QUEUE_SetDoomedQueue
+ */
+void QUEUE_SetDoomedQueue( HQUEUE16 hQueue )
+{
+    hDoomedQueue = hQueue;
+}
+
+
+/***********************************************************************
  *           QUEUE_CreateMsgQueue
  *
  * Creates a message queue. Doesn't link it into queue list!
  */
-static HQUEUE QUEUE_CreateMsgQueue( int size )
+static HQUEUE16 QUEUE_CreateMsgQueue( int size )
 {
-    HQUEUE hQueue;
+    HQUEUE16 hQueue;
     MESSAGEQUEUE * msgQueue;
     int queueSize;
     TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
@@ -249,7 +255,7 @@
     WPARAM wParam;
     LPARAM lParam;
     LRESULT result = 0;
-    HQUEUE oldSender;
+    HQUEUE16 oldSender;
 
     printf( "ReceiveMessage\n" );
     if (!(queue->wakeBits & QS_SENDMESSAGE)) return;
@@ -395,7 +401,7 @@
 {
     HWND hwnd;
     WORD wakeBit;
-    HQUEUE hQueue;
+    HQUEUE16 hQueue;
     MESSAGEQUEUE *queue = NULL;
 
     if ((message >= WM_KEYFIRST) && (message <= WM_KEYLAST)) wakeBit = QS_KEY;
@@ -577,7 +583,7 @@
  */
 BOOL SetMessageQueue( int size )
 {
-    HQUEUE hQueue, hNewQueue;
+    HQUEUE16 hQueue, hNewQueue;
     MESSAGEQUEUE *queuePtr;
 
     dprintf_msg(stddeb,"SetMessageQueue: task %04x size %i\n", GetCurrentTask(), size); 
diff --git a/windows/scroll.c b/windows/scroll.c
index d00330b..7c11953 100644
--- a/windows/scroll.c
+++ b/windows/scroll.c
@@ -2,7 +2,7 @@
  * Scroll windows and DCs
  *
  * Copyright  David W. Metcalfe, 1993
- *	      Alex Korobka       1995
+ *	      Alex Korobka       1995,1996
  *
  *
  */
@@ -12,101 +12,17 @@
 #include "class.h"
 #include "win.h"
 #include "gdi.h"
+#include "region.h"
 #include "sysmetrics.h"
 #include "stddebug.h"
 /* #define DEBUG_SCROLL */
 #include "debug.h"
 
-extern HRGN DCE_GetVisRgn(HWND, WORD);		/* windows/dce.c */
 extern HWND CARET_GetHwnd();			/* windows/caret.c */
 extern void CLIPPING_UpdateGCRegion(DC* );	/* objects/clipping.c */
 
 static int RgnType;
 
-
-/* -----------------------------------------------------------------------
- *	       SCROLL_TraceChildren
- * 
- * Returns a region invalidated by children, siblings, and/or ansectors
- * in the window rectangle or client rectangle
- *
- * dcx can have DCX_WINDOW, DCX_CLIPCHILDREN, DCX_CLIPSIBLINGS set
- */
-
-HRGN	SCROLL_TraceChildren( WND* wndScroll, short dx, short dy, WORD dcx)
-{
- HRGN		hRgnWnd;
- HRGN		hUpdateRgn,hCombineRgn;
-
- if( !wndScroll || ( !dx && !dy) ) return 0;
-
- if( dcx & DCX_WINDOW )
-	 hRgnWnd   = CreateRectRgnIndirect16(&wndScroll->rectWindow);
- else
-	{
-	 RECT32 rect = { 0, 0, wndScroll->rectClient.right - wndScroll->rectClient.left,
-			       wndScroll->rectClient.bottom - wndScroll->rectClient.top };
-
- 	 hRgnWnd   = CreateRectRgnIndirect32(&rect);
-	}
-
- hUpdateRgn  = DCE_GetVisRgn( wndScroll->hwndSelf, dcx );
- hCombineRgn = CreateRectRgn(0,0,0,0);
-
- if( !hUpdateRgn || !hCombineRgn )
-      {
-	DeleteObject( hUpdateRgn? hUpdateRgn : hCombineRgn);
-	DeleteObject(hRgnWnd);
-	return 0;
-      }
-
- OffsetRgn( hUpdateRgn, dx, dy);
- CombineRgn(hCombineRgn, hRgnWnd, hUpdateRgn, RGN_DIFF);
- 
- DeleteObject(hRgnWnd);
- DeleteObject(hUpdateRgn);
-
- return hCombineRgn;
-}
-
-
-/* ----------------------------------------------------------------------
- *	       SCROLL_ScrollChildren
- */
-BOOL	SCROLL_ScrollChildren( WND* wndScroll, short dx, short dy)
-{
- WND           *wndPtr = NULL;
- HRGN		hUpdateRgn;
- BOOL		b = 0;
-
- if( !wndScroll || ( !dx && !dy )) return 0;
-
- dprintf_scroll(stddeb,"SCROLL_ScrollChildren: hwnd %04x dx=%i dy=%i\n",wndScroll->hwndSelf,dx,dy);
-
- /* get a region in client rect invalidated by siblings and ansectors */
- hUpdateRgn = SCROLL_TraceChildren(wndScroll, dx , dy, DCX_CLIPSIBLINGS);
-
-   /* update children coordinates */
-   for (wndPtr = wndScroll->child; wndPtr; wndPtr = wndPtr->next)
-   {
-	/* we can check if window intersects with clipRect parameter
-	 * and do not move it if not - just a thought.     - AK
-	 */
-	SetWindowPos(wndPtr->hwndSelf, 0, wndPtr->rectWindow.left + dx,
-                     wndPtr->rectWindow.top  + dy, 0,0, SWP_NOZORDER |
-                     SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
-                     SWP_DEFERERASE );
-  } 
-
- /* invalidate uncovered region and paint frames */
- b = RedrawWindow32( wndScroll->hwndSelf, NULL, hUpdateRgn, 
-		     RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW | RDW_ALLCHILDREN ); 
-
- DeleteObject( hUpdateRgn);
- return b;
-}
-
-
 /*************************************************************************
  *             ScrollWindow         (USER.61)
  *
@@ -119,14 +35,13 @@
     HWND 	hCaretWnd = CARET_GetHwnd();
     WND*	wndScroll = WIN_FindWndPtr( hwnd );
 
-    dprintf_scroll(stddeb,"ScrollWindow: dx=%d, dy=%d, lpRect =%08lx clipRect=%i,%i,%i,%i\n", 
-	    dx, dy, (LONG)rect, (int)((clipRect)?clipRect->left:0),
+    dprintf_scroll(stddeb,"ScrollWindow: hwnd=%04x, dx=%d, dy=%d, lpRect =%08lx clipRect=%i,%i,%i,%i\n", 
+	    hwnd, dx, dy, (LONG)rect, (int)((clipRect)?clipRect->left:0),
                                 (int)((clipRect)?clipRect->top:0),
                                 (int)((clipRect)?clipRect->right:0), 
                                 (int)((clipRect)?clipRect->bottom:0));
 
-    /* if rect is NULL children have to be moved */
-    if ( !rect )
+    if ( !rect ) /* do not clip children */
        {
 	  GetClientRect16(hwnd, &rc);
 	  hrgnClip = CreateRectRgnIndirect16( &rc );
@@ -135,21 +50,17 @@
               HideCaret(hCaretWnd);
           else hCaretWnd = 0;
  
-	  /* children will be Blt'ed too */
 	  hdc      = GetDCEx(hwnd, hrgnClip, DCX_CACHE | DCX_CLIPSIBLINGS);
           DeleteObject(hrgnClip);
        }
-    else
+    else	/* clip children */
        {
 	  GetClientRect16(hwnd,&rc);
-	  dprintf_scroll(stddeb,"\trect=%i %i %i %i client=%i %i %i %i\n",
-			 (int)rect->left,(int)rect->top,(int)rect->right,
-			 (int)rect->bottom,(int)rc.left,(int)rc.top,
-			 (int)rc.right,(int)rc.bottom);
+	  CopyRect16(&rc, rect);
 
           if (hCaretWnd == hwnd) HideCaret(hCaretWnd);
           else hCaretWnd = 0;
-          CopyRect16(&rc, rect);
+
 	  hdc = GetDC(hwnd);
        }
 
@@ -158,34 +69,28 @@
     else
 	CopyRect16(&cliprc, clipRect);
 
-    /* move window update region (if any) */
-
-    if( wndScroll->hrgnUpdate > 1 )
-	OffsetRgn( wndScroll->hrgnUpdate, dx, dy );
-
     hrgnUpdate = CreateRectRgn(0, 0, 0, 0);
     ScrollDC(hdc, dx, dy, &rc, &cliprc, hrgnUpdate, NULL);
     ReleaseDC(hwnd, hdc);
 
-    if( !rect )
-      {
-         /* FIXME: this doesn't take into account hrgnUpdate */
+    if( !rect )		/* move child windows and update region */
+    { 
+      WND*	wndPtr;
 
-         if( !SCROLL_ScrollChildren( wndScroll, dx,dy) )
-	     InvalidateRgn(hwnd, hrgnUpdate, TRUE);
-      }
-    else
-      {
-        HRGN hrgnInv = SCROLL_TraceChildren( wndScroll ,dx,dy,DCX_CLIPCHILDREN |
-						              DCX_CLIPSIBLINGS );
-        if( hrgnInv )
-        {
-	    CombineRgn(hrgnUpdate,hrgnInv,hrgnUpdate,RGN_OR);
-            DeleteObject(hrgnInv);
-        }
+      if( wndScroll->hrgnUpdate > 1 )
+	OffsetRgn( wndScroll->hrgnUpdate, dx, dy );
 
-        RedrawWindow32( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW);
-      }
+      for (wndPtr = wndScroll->child; wndPtr; wndPtr = wndPtr->next)
+        SetWindowPos(wndPtr->hwndSelf, 0, wndPtr->rectWindow.left + dx,
+                     wndPtr->rectWindow.top  + dy, 0,0, SWP_NOZORDER |
+                     SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
+                     SWP_DEFERERASE );
+    }
+
+    /* RDW_ALLCHILDREN is to account for dialog controls */
+
+    RedrawWindow32( hwnd, NULL, hrgnUpdate, RDW_ALLCHILDREN |
+					    RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW);
 
     DeleteObject(hrgnUpdate);
     if( hCaretWnd ) ShowCaret(hCaretWnd);
@@ -210,15 +115,15 @@
                    dx, dy, hrgnUpdate, rcUpdate, cliprc, rc ? rc->left : 0,
                    rc ? rc->top : 0, rc ? rc->right : 0, rc ? rc->bottom : 0 );
 
-    if (rc == NULL || !hdc || !dc)
-	return FALSE;
+    if ( !dc || !hdc ) return FALSE;
 
     /* set clipping region */
 
+    if ( !rc ) GetClipBox16( hdc, &rectClip );
+    else rectClip = *rc;
+
     if (cliprc)
-	IntersectRect16(&rectClip,rc,cliprc);
-    else
-	rectClip = *rc;
+	IntersectRect16(&rectClip,&rectClip,cliprc);
 
     if( rectClip.left >= rectClip.right || rectClip.top >= rectClip.bottom )
 	return FALSE;
@@ -228,9 +133,7 @@
 
     if( hrgnClip )
       {
-        /* call UpdateGCRegion directly to avoid
-         * one more temporary region
-	 */ 
+        /* save a copy and change cliprgn directly */
 
         CombineRgn( hrgnScrollClip, hrgnClip, 0, RGN_COPY );
         SetRectRgn( hrgnClip, rectClip.left, rectClip.top, rectClip.right, rectClip.bottom );
@@ -238,33 +141,33 @@
 	CLIPPING_UpdateGCRegion( dc );
       }
     else
-        SelectClipRgn( hdc, hrgnScrollClip ); 
+        SelectClipRgn( hdc, hrgnScrollClip );
 
     /* translate coordinates */
 
     if (dx > 0)
     {
-	src.x = XDPTOLP(dc, rc->left);
-	dest.x = XDPTOLP(dc, rc->left + abs(dx));
+	src.x = XDPTOLP(dc, rectClip.left);
+	dest.x = XDPTOLP(dc, rectClip.left + abs(dx));
     }
     else
     {
-	src.x = XDPTOLP(dc, rc->left + abs(dx));
-	dest.x = XDPTOLP(dc, rc->left);
+	src.x = XDPTOLP(dc, rectClip.left + abs(dx));
+	dest.x = XDPTOLP(dc, rectClip.left);
     }
     if (dy > 0)
     {
-	src.y = YDPTOLP(dc, rc->top);
-	dest.y = YDPTOLP(dc, rc->top + abs(dy));
+	src.y = YDPTOLP(dc, rectClip.top);
+	dest.y = YDPTOLP(dc, rectClip.top + abs(dy));
     }
     else
     {
-	src.y = YDPTOLP(dc, rc->top + abs(dy));
-	dest.y = YDPTOLP(dc, rc->top);
+	src.y = YDPTOLP(dc, rectClip.top + abs(dy));
+	dest.y = YDPTOLP(dc, rectClip.top);
     }
 
-    width = rc->right - rc->left - abs(dx);
-    height = rc->bottom - rc->top - abs(dy);
+    width = rectClip.right - rectClip.left - abs(dx);
+    height = rectClip.bottom - rectClip.top - abs(dy);
 
     /* copy bits */
 
@@ -274,45 +177,38 @@
 
     /* compute update areas */
 
-    if (hrgnUpdate)
+    if (hrgnUpdate || rcUpdate)
     {
-	HRGN hrgn1,hrgn2;
+	HRGN   hrgn1 = (hrgnUpdate)?hrgnUpdate:CreateRectRgn( 0,0,0,0 );
 
-	if (dx > 0)
-	    hrgn1 = CreateRectRgn(rc->left, rc->top, rc->left+dx, rc->bottom);
-	else if (dx < 0)
-	    hrgn1 = CreateRectRgn(rc->right+dx, rc->top, rc->right, 
-				  rc->bottom);
+	if( dc->w.hVisRgn )
+	{
+	  CombineRgn( hrgn1, dc->w.hVisRgn, 0, RGN_COPY);
+	  CombineRgn( hrgn1, hrgn1, (hrgnClip)?hrgnClip:hrgnScrollClip, RGN_AND);
+	  OffsetRgn( hrgn1, dx, dy );
+	  CombineRgn( hrgn1, dc->w.hVisRgn, hrgn1, RGN_DIFF);
+	  RgnType = CombineRgn( hrgn1, hrgn1, (hrgnClip)?hrgnClip:hrgnScrollClip, RGN_AND);
+	}
 	else
-	    hrgn1 = CreateRectRgn(0, 0, 0, 0);
+	{
+	  RECT16	rect;
 
-	if (dy > 0)
-	    hrgn2 = CreateRectRgn(rc->left, rc->top, rc->right, rc->top+dy);
-	else if (dy < 0)
-	    hrgn2 = CreateRectRgn(rc->left, rc->bottom+dy, rc->right, 
-				  rc->bottom);
-	else
-	    hrgn2 = CreateRectRgn(0, 0, 0, 0);
+          rect = rectClip;				/* vertical band */
+          if (dx > 0) rect.right = rect.left + dx;
+          else if (dx < 0) rect.left = rect.right + dx;
+          else SetRectEmpty16( &rect );
+          SetRectRgn( hrgn1, rect.left, rect.top, rect.right, rect.bottom );
 
-	RgnType = CombineRgn(hrgnUpdate, hrgn1, hrgn2, RGN_OR);
-	DeleteObject(hrgn1);
-	DeleteObject(hrgn2);
-        if (rcUpdate) GetRgnBox16( hrgnUpdate, rcUpdate );
-    }
-    else if (rcUpdate)
-    {
-	RECT16 rx,ry;
+          rect = rectClip;				/* horizontal band */
+          if (dy > 0) rect.bottom = rect.top + dy;
+          else if (dy < 0) rect.top = rect.bottom + dy;
+          else SetRectEmpty16( &rect );
 
-	rx = ry = *rc;
-	if( dx > 0 )  	  rx.right = rc->left+dx; 
-	else if (dx < 0)  rx.left = rc->right+dx; 
-	else SetRectEmpty16( &rx );
+          RgnType = REGION_UnionRectWithRgn( hrgn1, &rect );
+	}
 
-        if( dy > 0 )      ry.bottom = rc->top+dy;
-        else if (dy < 0)  ry.top = rc->bottom+dy;
-        else SetRectEmpty16( &ry );
-
-	UnionRect16( rcUpdate, &rx, &ry );
+	if (rcUpdate) GetRgnBox16( hrgn1, rcUpdate );
+	if (!hrgnUpdate) DeleteObject( hrgn1 );
     }
 
     /* restore clipping region */
@@ -327,9 +223,8 @@
 /*************************************************************************
  *             ScrollWindowEx       (USER.319)
  *
- * FIXME: broken
+ * FIXME: broken, is there a program that actually uses it?
  *
- * SCROLL_TraceChildren can help
  */
 
 int ScrollWindowEx(HWND hwnd, short dx, short dy, LPRECT16 rect, LPRECT16 clipRect,
diff --git a/windows/win.c b/windows/win.c
index 845d9ac..63e8564 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -43,8 +43,7 @@
 static WORD wDragWidth = 4;
 static WORD wDragHeight= 3;
 
-extern HCURSOR CURSORICON_IconToCursor(HICON);
-extern HQUEUE  QUEUE_GetDoomedQueue();
+extern HCURSOR16 CURSORICON_IconToCursor(HICON16);
 
 /***********************************************************************
  *           WIN_FindWndPtr
@@ -343,7 +342,7 @@
 /***********************************************************************
  *	     WIN_DestroyQueueWindows
  */
-void WIN_DestroyQueueWindows( WND* wnd, HQUEUE hQueue )
+void WIN_DestroyQueueWindows( WND* wnd, HQUEUE16 hQueue )
 {
     WND* next;
 
@@ -905,8 +904,7 @@
 		      SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE );
     if ((hwnd == GetCapture()) || IsChild( hwnd, GetCapture() ))
 	ReleaseCapture();
-    if (!QUEUE_GetDoomedQueue())
-        WIN_SendParentNotify( hwnd, WM_DESTROY, wndPtr->wIDmenu, (LONG)hwnd );
+    WIN_SendParentNotify( hwnd, WM_DESTROY, wndPtr->wIDmenu, (LONG)hwnd );
 
     CLIPBOARD_DisOwn( hwnd );
 
@@ -1981,17 +1979,17 @@
  *
  */
 DWORD DragObject(HWND hwndScope, HWND hWnd, WORD wObj, HANDLE hOfStruct,
-                WORD szList , HCURSOR hCursor)
+                WORD szList , HCURSOR16 hCursor)
 {
  MSG16	 	msg;
  LPDRAGINFO	lpDragInfo;
  SEGPTR		spDragInfo;
- HCURSOR 	hDragCursor=0, hOldCursor=0, hBummer=0;
+ HCURSOR16 	hDragCursor=0, hOldCursor=0, hBummer=0;
  HANDLE		hDragInfo  = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO));
  WND           *wndPtr = WIN_FindWndPtr(hWnd);
  DWORD		dwRet = 0;
  short	 	dragDone = 0;
- HCURSOR	hCurrentCursor = 0;
+ HCURSOR16	hCurrentCursor = 0;
  HWND		hCurrentWnd = 0;
  WORD	        btemp;
 
diff --git a/windows/winpos.c b/windows/winpos.c
index 9e1a9cc..c6132bb 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -866,6 +866,7 @@
     WND                   *wndTemp         = WIN_FindWndPtr(hwndActive);
     CBTACTIVATESTRUCT16   *cbtStruct;
     WORD                   wIconized=0;
+    HANDLE hNewActiveQueue;
 
     /* FIXME: When proper support for cooperative multitasking is in place 
      *        hActiveQ will be global 
@@ -874,10 +875,10 @@
     HANDLE                 hActiveQ = 0;   
 
     /* paranoid checks */
-    if( !hWnd || hWnd == GetDesktopWindow() || hWnd == hwndActive )
+    if( hWnd == GetDesktopWindow() || hWnd == hwndActive )
 	return 0;
 
-    if( GetTaskQueue(0) != wndPtr->hmemTaskQ )
+    if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
 	return 0;
 
     if( wndTemp )
@@ -918,7 +919,7 @@
     hwndActive = hWnd;
 
     /* send palette messages */
-    if( SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L) )
+    if (hWnd && SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
 	SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L );
 
     /* if prev wnd is minimized redraw icon title 
@@ -932,7 +933,7 @@
   */
 
     /* managed windows will get ConfigureNotify event */  
-    if (!(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
+    if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
     {
 	/* check Z-order and bring hWnd to the top */
 	for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
@@ -941,18 +942,18 @@
 	if( wndTemp != wndPtr )
 	    SetWindowPos(hWnd, HWND_TOP, 0,0,0,0, 
 			 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
+        if( !IsWindow(hWnd) ) return 0;
     }
 
-    if( !IsWindow(hWnd) ) return 0;
-
     if (hwndPrevActive)
     {
         wndTemp = WIN_FindWndPtr( hwndPrevActive );
         if (wndTemp) hActiveQ = wndTemp->hmemTaskQ;
     }
+    hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
 
     /* send WM_ACTIVATEAPP if necessary */
-    if (hActiveQ != wndPtr->hmemTaskQ)
+    if (hActiveQ != hNewActiveQueue)
     {
         WND **list, **ppWnd;
 
@@ -964,7 +965,7 @@
                 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
                 if ((*ppWnd)->hmemTaskQ != hActiveQ) continue;
                 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
-                               0, QUEUE_GetQueueTask(wndPtr->hmemTaskQ) );
+                               0, QUEUE_GetQueueTask(hNewActiveQueue) );
             }
             HeapFree( SystemHeap, 0, list );
         }
@@ -975,7 +976,7 @@
             {
                 /* Make sure that the window still exists */
                 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
-                if ((*ppWnd)->hmemTaskQ != wndPtr->hmemTaskQ) continue;
+                if ((*ppWnd)->hmemTaskQ != hNewActiveQueue) continue;
                 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
                                1, QUEUE_GetQueueTask( hActiveQ ) );
             }
@@ -984,19 +985,22 @@
 	if (!IsWindow(hWnd)) return 0;
     }
 
-    /* walk up to the first unowned window */
-    wndTemp = wndPtr;
-    while (wndTemp->owner) wndTemp = wndTemp->owner;
-    /* and set last active owned popup */
-    wndTemp->hwndLastActive = hWnd;
+    if (hWnd)
+    {
+        /* walk up to the first unowned window */
+        wndTemp = wndPtr;
+        while (wndTemp->owner) wndTemp = wndTemp->owner;
+        /* and set last active owned popup */
+        wndTemp->hwndLastActive = hWnd;
 
-    wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
-    SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
-    SendMessage32A( hWnd, WM_ACTIVATE,
+        wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
+        SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
+        SendMessage32A( hWnd, WM_ACTIVATE,
 		 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
 		 (LPARAM)hwndPrevActive );
 
-    if( !IsWindow(hWnd) ) return 0;
+        if( !IsWindow(hWnd) ) return 0;
+    }
 
     /* change focus if possible */
     if( fChangeFocus && GetFocus() )
@@ -1024,6 +1028,8 @@
 {
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
+    if (!hWnd) return WINPOS_SetActiveWindow( 0, mouseMsg, TRUE );
+
     if( !wndPtr ) return FALSE;
 
     /* child windows get WM_CHILDACTIVATE message */
diff --git a/windows/winproc.c b/windows/winproc.c
index 06057c0..79f99c4 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -147,6 +147,7 @@
     if (!IsBadReadPtr( (SEGPTR)handle, sizeof(WINDOWPROC)-sizeof(proc->thunk)))
     {
         ptr = (BYTE *)PTR_SEG_TO_LIN(handle);
+        if (!HEAP_IsInsideHeap( WinProcHeap, 0, ptr )) return NULL;
         /* It must be the thunk address */
         if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
         /* Now we have a pointer to the WINDOWPROC struct */
@@ -906,6 +907,13 @@
     *pwparam16 = (WPARAM16)LOWORD(wParam32);
     switch(msg32)
     {
+    case BM_GETCHECK32:
+    case BM_SETCHECK32:
+    case BM_GETSTATE32:
+    case BM_SETSTATE32:
+    case BM_SETSTYLE32:
+        *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK32);
+        return 0;
     case WM_ACTIVATE:
     case WM_CHARTOITEM:
     case WM_COMMAND: