Release 960712

Fri Jul 12 17:43:05 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [controls/scroll.c]
	Use Win32 heap functions to allocate scroll-bar info structure.

	* [debugger/dbg.y] [debugger/registers.c]
	Added support for FS and GS segment registers.
	Check that segment registers value are OK before returning from
	the signal handler.

	* [tools/build.c] [if1632/relay.c] [loader/builtin.c]
	Changed relay debugging for Win32 function: the relay code now
	passes the entry point address instead of the function name.

	* [tools/build.c] [miscemu/*.c]
	Added support for data entry points in Win32 DLLs.
	Added 'cdecl' function type for Win32.
	For 'register' function, the relay code now passes a pointer to
	the SIGCONTEXT structure.
	
	* [include/registers.h] [include/wine.h]
	Moved SIGCONTEXT structure definition in registers.h.

	* [loader/pe_image.c]
	Don't die at once if some Win32 entry points cannot be found, but
	set them to NULL, just like we do for Win16. This allows some
	programs to go further before crashing.

	* [loader/task.c] [loader/main.c]
	Moved global initializations from InitTask() to MAIN_Init(), as
	they no longer need a task context with the new SEGPTR heap functions.

	* [memory/string.c]
	Added lstrcpynAtoW and lstrcpynWtoA; not real API functions, but
 	very convenient.

	* [windows/graphics.c]
	Partially implemented DrawEdge().

	* [windows/timer.c] [windows/caret.c]
	Implemented Win32 timer handling. Updated caret management to use
	Win32 timers (avoids having to use a Win16 callback).

	* [windows/win.c]
	Prevent programs from setting some style bits with
	SetWindowLong(). This should fix some BadMatch crashes.
	Link new windows at the end of the linked list.

	* [windows/winpos.c]
	Don't try to activate a child window in ShowWindow().

	* [windows/winproc.c]
	Added a 32->32 thunk to support Ansi-Unicode translation.

Wed Jul 10 22:11:12 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [files/directory.c]
	Additional (undocumented) return value for GetTempDrive() added.

	* [files/dos_fs.c] [files/file.c] [include/windows.h]
	GetTempFileName32* added.
	GetShortPathName* added.

	* [memory/string.c]
	Win16 lstrcpy() can get NULL ptrs as argument and survive.

	* [misc/lzexpand.c]
	LZOpenFile(): also try opening with compressed filename if normal
 	open fails.

	* [misc/ole2nls.c] [misc/lstr.c] [include/windows.h]
	Char* added.
	CompareString* added.

Sun Jul  7 01:22:14 1996  Jukka Iivonen <iivonen@cc.helsinki.fi>

	* [objects/font.c] [if1632/gdi32.spec]
	CreateFontIndirect32A and CreateFontIndirect32W added.

	* [misc/ole2nls.c]
	GetUserDefaultLCID return values updated for new languages.
	Finnish support added for GetLocaleInfoA.

	* [object/palette] [gdi32.spec]
	RealizePalette32 and SelectPalette32 added.
	
Sat Jul  6 17:27:30 1996  Ronan Waide  <root@waider.ie>

	* [misc/shell.c]
	Fixup for SHELL_FindExecutable so that File->Run from progman
	works once more. Still needs some more fixups - grep for FIXME in
	this file.
diff --git a/ANNOUNCE b/ANNOUNCE
index decf527..b90a4db 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,12 +1,13 @@
-This is release 960705 of Wine, the MS Windows emulator.  This is still a
+This is release 960712 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-960705: (see ChangeLog for details)
-	- New window procedure thunks.
+WHAT'S NEW with Wine-960712: (see ChangeLog for details)
+	- Many built-in debugger improvements.
+	- Some more Win32 functions.
 	- Lots of bug fixes.
 
 See the README file in the distribution for installation instructions.
@@ -15,10 +16,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-960705.tar.gz
-    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-960705.tar.gz
-    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-960705.tar.gz
-    aris.com:/pub/linux/ALPHA/Wine/development/Wine-960705.tar.gz
+    sunsite.unc.edu:/pub/Linux/ALPHA/wine/development/Wine-960712.tar.gz
+    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-960712.tar.gz
+    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-960712.tar.gz
+    aris.com:/pub/linux/ALPHA/Wine/development/Wine-960712.tar.gz
 
 It should also be available from any site that mirrors tsx-11 or sunsite.
 
diff --git a/ChangeLog b/ChangeLog
index 7b3b3bc..5139957 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,98 @@
 ----------------------------------------------------------------------
+Fri Jul 12 17:43:05 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>
+
+	* [controls/scroll.c]
+	Use Win32 heap functions to allocate scroll-bar info structure.
+
+	* [debugger/dbg.y] [debugger/registers.c]
+	Added support for FS and GS segment registers.
+	Check that segment registers value are OK before returning from
+	the signal handler.
+
+	* [tools/build.c] [if1632/relay.c] [loader/builtin.c]
+	Changed relay debugging for Win32 function: the relay code now
+	passes the entry point address instead of the function name.
+
+	* [tools/build.c] [miscemu/*.c]
+	Added support for data entry points in Win32 DLLs.
+	Added 'cdecl' function type for Win32.
+	For 'register' function, the relay code now passes a pointer to
+	the SIGCONTEXT structure.
+	
+	* [include/registers.h] [include/wine.h]
+	Moved SIGCONTEXT structure definition in registers.h.
+
+	* [loader/pe_image.c]
+	Don't die at once if some Win32 entry points cannot be found, but
+	set them to NULL, just like we do for Win16. This allows some
+	programs to go further before crashing.
+
+	* [loader/task.c] [loader/main.c]
+	Moved global initializations from InitTask() to MAIN_Init(), as
+	they no longer need a task context with the new SEGPTR heap functions.
+
+	* [memory/string.c]
+	Added lstrcpynAtoW and lstrcpynWtoA; not real API functions, but
+ 	very convenient.
+
+	* [windows/graphics.c]
+	Partially implemented DrawEdge().
+
+	* [windows/timer.c] [windows/caret.c]
+	Implemented Win32 timer handling. Updated caret management to use
+	Win32 timers (avoids having to use a Win16 callback).
+
+	* [windows/win.c]
+	Prevent programs from setting some style bits with
+	SetWindowLong(). This should fix some BadMatch crashes.
+	Link new windows at the end of the linked list.
+
+	* [windows/winpos.c]
+	Don't try to activate a child window in ShowWindow().
+
+	* [windows/winproc.c]
+	Added a 32->32 thunk to support Ansi-Unicode translation.
+
+Wed Jul 10 22:11:12 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
+
+	* [files/directory.c]
+	Additional (undocumented) return value for GetTempDrive() added.
+
+	* [files/dos_fs.c] [files/file.c] [include/windows.h]
+	GetTempFileName32* added.
+	GetShortPathName* added.
+
+	* [memory/string.c]
+	Win16 lstrcpy() can get NULL ptrs as argument and survive.
+
+	* [misc/lzexpand.c]
+	LZOpenFile(): also try opening with compressed filename if normal
+ 	open fails.
+
+	* [misc/ole2nls.c] [misc/lstr.c] [include/windows.h]
+	Char* added.
+	CompareString* added.
+
+Sun Jul  7 01:22:14  Jukka Iivonen <iivonen@cc.helsinki.fi>
+
+	* [objects/font.c] [if1632/gdi32.spec]
+	CreateFontIndirect32A and CreateFontIndirect32W added.
+
+	* [misc/ole2nls.c]
+	GetUserDefaultLCID return values updated for new languages.
+	Finnish support added for GetLocaleInfoA.
+
+	* [object/palette] [gdi32.spec]
+	RealizePalette32 and SelectPalette32 added.
+	
+Sat Jul  6 17:27:30 1996  Ronan Waide  <root@waider.ie>
+
+	* [misc/shell.c]
+	Fixup for SHELL_FindExecutable so that File->Run from progman
+	works once more. Still needs some more fixups - grep for FIXME in
+	this file.
+
+----------------------------------------------------------------------
 Fri Jul  5 16:27:43 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>
 
 	* [controls/desktop.c]
@@ -461,7 +555,7 @@
 	* [misc/main.c]
 	Result of option "-fixedmap" is to turn flag on.
 
-Thu May 23 19:15:41 1996  Waider  <root@waider.ie>
+Thu May 23 19:15:41 1996  Ronan Waide  <root@waider.ie>
 
 	* [misc/shell.c]
 	ShellExecute and FindExecutable now both use common code to
diff --git a/DEVELOPERS-HINTS b/DEVELOPERS-HINTS
index a4be04e..8a0a147 100644
--- a/DEVELOPERS-HINTS
+++ b/DEVELOPERS-HINTS
@@ -124,12 +124,10 @@
 Wines 32-bit stack.  This task is handled by the code in the "if1632"
 directory.  To define a new API entry point handler you must place a
 new entry in the appropriate API specification file.  These files are
-named *.spec.  For example, the API specification file for the USER DLL
-is contained in the file user.spec.  These entries are processed by
-the "build" program to create dll_*.s and dll_tab_*.c.  The dll_*.s
-files contain the entry point code for each API call, and the dll_tab_*.s
-files contain tables used by relay.c to translate arguments and transfer
-control to the proper handler.  The format of the *.spec files is
+named *.spec.  For example, the API specification file for the USER
+DLL is contained in the file user.spec.  These entries are processed
+by the "build" program to create an assembly file containing the entry
+point code for each API call.  The format of the *.spec files is
 documented in the file "tools/build-spec.txt".
 
 
diff --git a/controls/combo.c b/controls/combo.c
index 10ed406..7006776 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -256,12 +256,7 @@
 
   hOldFont = SelectObject(hdc, lphl->hFont);
 
-#ifdef WINELIB32
-  hBrush = SendMessage32A(lphl->hParent, WM_CTLCOLORLISTBOX, hdc, hwnd);
-#else
-  hBrush = SendMessage16(lphl->hParent, WM_CTLCOLOR, hdc,
-                         MAKELONG(hwnd, CTLCOLOR_LISTBOX));
-#endif
+  hBrush = SendMessage32A( lphl->hParent, WM_CTLCOLORLISTBOX, hdc, hwnd );
   if (hBrush == 0) hBrush = GetStockObject(WHITE_BRUSH);
 
   lpls = ListBoxGetItem(lphl,lphl->ItemFocused);
diff --git a/controls/edit.c b/controls/edit.c
index 62be0ea..f96c3c1 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -85,31 +85,18 @@
 
 #define EDITSTATEPTR(wndPtr) (*(EDITSTATE **)((wndPtr)->wExtra))
 
-#ifdef WINELIB32
 #define EDIT_SEND_CTLCOLOR(wndPtr,hdc) \
-		SendMessage32A((wndPtr)->parent->hwndSelf, WM_CTLCOLOREDIT, \
-				(WPARAM)(hdc), (LPARAM)(wndPtr)->hwndSelf)
+    (SendMessage32A((wndPtr)->parent->hwndSelf, WM_CTLCOLOREDIT, \
+                    (WPARAM)(hdc), (LPARAM)(wndPtr)->hwndSelf ))
 #define EDIT_NOTIFY_PARENT(wndPtr, wNotifyCode) \
-		SendMessage32A((wndPtr)->parent->hwndSelf, WM_COMMAND, \
-				MAKEWPARAM((wndPtr)->wIDmenu, wNotifyCode), \
-				(LPARAM)(wndPtr)->hwndSelf )
+    (SendMessage32A((wndPtr)->parent->hwndSelf, WM_COMMAND, \
+                    MAKEWPARAM((wndPtr)->wIDmenu, wNotifyCode), \
+                    (LPARAM)(wndPtr)->hwndSelf ))
 #define DPRINTF_EDIT_MSG(str) \
-		dprintf_edit(stddeb, \
-			"edit: " str ": hwnd=%08x, wParam=%08x, lParam=%08lx\n", \
-			(UINT)hwnd, (UINT)wParam, (DWORD)lParam)
-#else
-#define EDIT_SEND_CTLCOLOR(wndPtr,hdc) \
-		SendMessage16((wndPtr)->parent->hwndSelf, WM_CTLCOLOR, \
-				(WPARAM)(hdc), MAKELPARAM((wndPtr)->hwndSelf, CTLCOLOR_EDIT))
-#define EDIT_NOTIFY_PARENT(wndPtr, wNotifyCode) \
-		SendMessage16((wndPtr)->parent->hwndSelf, WM_COMMAND, \
-				(wndPtr)->wIDmenu, \
-				MAKELPARAM((wndPtr)->hwndSelf, wNotifyCode))
-#define DPRINTF_EDIT_MSG(str) \
-		dprintf_edit(stddeb, \
-			"edit: " str ": hwnd=%04x, wParam=%04x, lParam=%08lx\n", \
-			(UINT)hwnd, (UINT)wParam, (DWORD)lParam)
-#endif
+    dprintf_edit(stddeb, \
+                 "edit: " str ": hwnd=%04x, wParam=%04x, lParam=%08x\n", \
+                 (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam)
+
 
 /*********************************************************************
  *
diff --git a/controls/listbox.c b/controls/listbox.c
index 0a31780..b3a5b8d 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -19,7 +19,6 @@
 #include <string.h>
 #include <ctype.h>
 #include "windows.h"
-#include "user.h"
 #include "win.h"
 #include "gdi.h"
 #include "msdos.h"
@@ -32,34 +31,12 @@
 #include "debug.h"
 #include "xmalloc.h"
 
-#if 0
-#define LIST_HEAP_ALLOC(lphl,f,size) ((int)HEAP_Alloc(&lphl->Heap,f,size) & 0xffff)
-#define LIST_HEAP_FREE(lphl,handle) (HEAP_Free(&lphl->Heap,LIST_HEAP_ADDR(lphl,handle)))
-#define LIST_HEAP_ADDR(lphl,handle) \
-    ((void *)((handle) ? ((handle) | ((int)lphl->Heap & 0xffff0000)) : 0))
-#else
-/* FIXME: shouldn't each listbox have its own heap? */
-#if 0
-#define LIST_HEAP_ALLOC(lphl,f,size) USER_HEAP_ALLOC(size)
-#define LIST_HEAP_FREE(lphl,handle)  USER_HEAP_FREE(handle)
-#define LIST_HEAP_ADDR(lphl,handle)  USER_HEAP_LIN_ADDR(handle)
-#define LIST_HEAP_SEG_ADDR(lphl,handle) USER_HEAP_SEG_ADDR(handle)
-#else
-/* Something like this maybe ? */
 #define LIST_HEAP_ALLOC(lphl,f,size) \
-            LOCAL_Alloc( lphl->HeapSel, LMEM_FIXED, (size) )
-#if 0
-#define LIST_HEAP_REALLOC(handle,size) \
-            LOCAL_ReAlloc( USER_HeapSel, (handle), (size), LMEM_FIXED )
-#endif
+    LOCAL_Alloc( lphl->HeapSel, LMEM_FIXED, (size) )
 #define LIST_HEAP_FREE(lphl,handle) \
-            LOCAL_Free( lphl->HeapSel, (handle) )
+    LOCAL_Free( lphl->HeapSel, (handle) )
 #define LIST_HEAP_ADDR(lphl,handle)  \
-            ((handle) ? PTR_SEG_OFF_TO_LIN(lphl->HeapSel, (handle)) : NULL)
-#define LIST_HEAP_SEG_ADDR(lphl,handle)  \
-            ((handle) ? MAKELONG((handle), lphl->HeapSel) : 0)
-#endif
-#endif
+    ((handle) ? PTR_SEG_OFF_TO_LIN(lphl->HeapSel, (handle)) : NULL)
 
 #define LIST_HEAP_SIZE 0x10000
 
@@ -128,13 +105,8 @@
     ListBoxAskMeasure(lphl,&dummyls);
   }
 
-/* WINELIBS list boxes do not operate on local heaps */
-#ifndef WINELIB
   lphl->HeapSel = GlobalAlloc16(GMEM_FIXED,LIST_HEAP_SIZE);
   LocalInit( lphl->HeapSel, 0, LIST_HEAP_SIZE-1);
-#else
-  lphl->HeapSel = 0;
-#endif
 }
 
 void DestroyListBoxStruct(LPHEADLIST lphl)
@@ -154,13 +126,8 @@
 void ListBoxSendNotification(LPHEADLIST lphl, WORD code)
 {
   if (lphl->dwStyle & LBS_NOTIFY)
-#ifdef WINELIB32
-    SendMessage32A(lphl->hParent, WM_COMMAND,
-                   MAKEWPARAM(lphl->CtlID,code), (LPARAM)lphl->hSelf);
-#else
-    SendMessage16(lphl->hParent, WM_COMMAND,
-                  lphl->CtlID, MAKELONG(lphl->hSelf, code));
-#endif
+      SendMessage32A( lphl->hParent, WM_COMMAND,
+                      MAKEWPARAM( lphl->CtlID, code), (LPARAM)lphl->hSelf );
 }
 
 
@@ -303,25 +270,20 @@
 
 void ListBoxAskMeasure(LPHEADLIST lphl, LPLISTSTRUCT lpls)  
 {
-  HANDLE hTemp = USER_HEAP_ALLOC( sizeof(MEASUREITEMSTRUCT16) );
-  MEASUREITEMSTRUCT16 *lpmeasure = (MEASUREITEMSTRUCT16 *) USER_HEAP_LIN_ADDR(hTemp);
+    MEASUREITEMSTRUCT16 *lpmeasure = SEGPTR_NEW(MEASUREITEMSTRUCT16);
+    if (!lpmeasure) return;
+    *lpmeasure = lpls->mis;
+    lpmeasure->itemHeight = lphl->StdItemHeight;
+    SendMessage16( lphl->hParent, WM_MEASUREITEM, lphl->CtlID,
+                   (LPARAM)SEGPTR_GET(lpmeasure) );
 
-  if (lpmeasure == NULL) {
-    fprintf(stdnimp,"ListBoxAskMeasure() out of memory !\n");
-    return;
-  }
- 
-  *lpmeasure = lpls->mis;
-  lpmeasure->itemHeight = lphl->StdItemHeight;
-  SendMessage16(lphl->hParent, WM_MEASUREITEM, lphl->CtlID, (LPARAM)USER_HEAP_SEG_ADDR(hTemp));
-
-  if (lphl->dwStyle & LBS_OWNERDRAWFIXED) {
-    if (lpmeasure->itemHeight > lphl->StdItemHeight)
-      lphl->StdItemHeight = lpmeasure->itemHeight;
-    lpls->mis.itemHeight = lpmeasure->itemHeight;
-  }
-
-  USER_HEAP_FREE(hTemp);			
+    if (lphl->dwStyle & LBS_OWNERDRAWFIXED)
+    {
+        if (lpmeasure->itemHeight > lphl->StdItemHeight)
+            lphl->StdItemHeight = lpmeasure->itemHeight;
+        lpls->mis.itemHeight = lpmeasure->itemHeight;
+    }
+    SEGPTR_FREE(lpmeasure);
 }
 
 /* -------------------- strings and item data ---------------------- */
@@ -975,11 +937,9 @@
      InvalidateRect16( hwnd, &rectsel, TRUE );
    }
 
-#ifndef WINELIB
   if (GetWindowLong32A(lphl->hSelf,GWL_EXSTYLE) & WS_EX_DRAGDETECT)
      if( DragDetect(lphl->hSelf,MAKEPOINT16(lParam)) )
          SendMessage16(lphl->hParent, WM_BEGINDRAG,0,0L);
-#endif
   return 0;
 }
 
@@ -1005,15 +965,8 @@
 {
   LPHEADLIST lphl = ListBoxGetStorageHeader(hwnd);
 
-#ifdef WINELIB32
-  SendMessage32A(lphl->hParent, WM_COMMAND, 
-                 MAKEWPARAM(GetWindowWord(hwnd,GWW_ID),LBN_DBLCLK),
-                 (LPARAM)hwnd);
-#else
   SendMessage16(lphl->hParent, WM_COMMAND, GetWindowWord(hwnd,GWW_ID),
 		MAKELONG(hwnd, LBN_DBLCLK));
-#endif
-
   return 0;
 }
 
@@ -1311,14 +1264,8 @@
 
   hOldFont = SelectObject(hdc, lphl->hFont);
 
-#ifdef WINELIB32
-  hBrush = (HBRUSH) SendMessage16(lphl->hParent, WM_CTLCOLORLISTBOX, (WPARAM)hdc,
-                                  (LPARAM)hwnd);
-#else
-  hBrush = SendMessage16(lphl->hParent, WM_CTLCOLOR, hdc,
-                         MAKELONG(hwnd, CTLCOLOR_LISTBOX));
-#endif
-
+  hBrush = (HBRUSH)SendMessage32A( lphl->hParent, WM_CTLCOLORLISTBOX,
+                                   (WPARAM)hdc, (LPARAM)hwnd);
   if (hBrush == 0) hBrush = GetStockObject(WHITE_BRUSH);
 
   FillRect16(hdc, &rect, hBrush);
diff --git a/controls/menu.c b/controls/menu.c
index a99da2a..49bd762 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -303,13 +303,8 @@
 	    if (p && (p[1] != '&') && (toupper(p[1]) == key)) return i;
 	}
     }
-#ifdef WINELIB32
     menuchar = SendMessage32A( hwndOwner, WM_MENUCHAR, 
-                               MAKEWPARAM(key,menu->wFlags), hmenu );
-#else
-    menuchar = SendMessage16( hwndOwner, WM_MENUCHAR, key,
-                              MAKELONG( menu->wFlags, hmenu ) );
-#endif
+                               MAKEWPARAM( key, menu->wFlags ), hmenu );
     if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
     if (HIWORD(menuchar) == 1) return -2;
     return -1;
@@ -860,17 +855,9 @@
         {
 	    NC_DrawSysButton( lppop->hWnd, hdc, TRUE );
             if (sendMenuSelect)
-#ifdef WINELIB32
-/* FIX: LostInfo */
-                SendMessage32A( hwndOwner, WM_MENUSELECT,
-                             MAKEWPARAM( WIN_FindWndPtr(lppop->hWnd)->hSysMenu,
-                                         lppop->wFlags | MF_MOUSESELECT ),
-                             (LPARAM)hmenu );
-#else
                 SendMessage16( hwndOwner, WM_MENUSELECT,
                              WIN_FindWndPtr(lppop->hWnd)->hSysMenu,
                              MAKELONG(lppop->wFlags | MF_MOUSESELECT, hmenu));
-#endif
         }
 	else
 	{
@@ -878,30 +865,14 @@
 	    MENU_DrawMenuItem( lppop->hWnd, hdc, &lppop->items[lppop->FocusedItem],
                                lppop->Height, !(lppop->wFlags & MF_POPUP) );
             if (sendMenuSelect)
-#ifdef WINELIB32
-                SendMessage32A( hwndOwner, WM_MENUSELECT,
-                             MAKEWPARAM( lppop->items[lppop->FocusedItem].item_id,
-                                         lppop->items[lppop->FocusedItem].item_flags| 
-                                         MF_MOUSESELECT ),
-                             (LPARAM) hmenu );
-#else
 	        SendMessage16( hwndOwner, WM_MENUSELECT,
                              lppop->items[lppop->FocusedItem].item_id,
                              MAKELONG( lppop->items[lppop->FocusedItem].item_flags | MF_MOUSESELECT, hmenu));
-#endif
 	}
     }
-#ifdef WINELIB32
-/* FIX: Lost Info */
-    else if (sendMenuSelect)
-        SendMessage32A( hwndOwner, WM_MENUSELECT, 
-                     MAKEWPARAM( (DWORD)hmenu, lppop->wFlags | MF_MOUSESELECT),
-                     hmenu );
-#else
     else if (sendMenuSelect)
         SendMessage16( hwndOwner, WM_MENUSELECT, hmenu,
-                     MAKELONG( lppop->wFlags | MF_MOUSESELECT, hmenu ) );
-#endif
+                       MAKELONG( lppop->wFlags | MF_MOUSESELECT, hmenu ) );
 
     ReleaseDC( lppop->hWnd, hdc );
 }
diff --git a/controls/scroll.c b/controls/scroll.c
index 4bf9479..04321df 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -16,11 +16,10 @@
 #include "syscolor.h"
 #include "sysmetrics.h"
 #include "scroll.h"
-#include "user.h"
 #include "graphics.h"
+#include "heap.h"
 #include "win.h"
 #include "stddebug.h"
-/* #define DEBUG_SCROLL */
 #include "debug.h"
 
 
@@ -94,38 +93,39 @@
     hRgArrowI = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_RGARROWI));
 }
 
+
 /***********************************************************************
  *           SCROLL_GetPtrScrollInfo
  */
 static SCROLLINFO *SCROLL_GetPtrScrollInfo( WND* wndPtr, int nBar )
 {
-    HANDLE handle;
+    SCROLLINFO *infoPtr;
 
     if (!wndPtr) return NULL;
     switch(nBar)
     {
-        case SB_HORZ: handle = wndPtr->hHScroll; break;
-        case SB_VERT: handle = wndPtr->hVScroll; break;
-        case SB_CTL:  return (SCROLLINFO *)wndPtr->wExtra;
+        case SB_HORZ: infoPtr = (SCROLLINFO *)wndPtr->pHScroll; break;
+        case SB_VERT: infoPtr = (SCROLLINFO *)wndPtr->pVScroll; break;
+        case SB_CTL:  infoPtr = (SCROLLINFO *)wndPtr->wExtra; break;
         default:      return NULL;
     }
 
-    if (!handle)  /* Create the info structure if needed */
+    if (!infoPtr)  /* Create the info structure if needed */
     {
-        if ((handle = USER_HEAP_ALLOC( sizeof(SCROLLINFO) )))
+        if ((infoPtr = HeapAlloc( SystemHeap, 0, sizeof(SCROLLINFO) )))
         {
-            SCROLLINFO *infoPtr = (SCROLLINFO *) USER_HEAP_LIN_ADDR( handle );
             infoPtr->MinVal = infoPtr->CurVal = 0;
             infoPtr->MaxVal = 100;
             infoPtr->flags  = ESB_ENABLE_BOTH;
-            if (nBar == SB_HORZ) wndPtr->hHScroll = handle;
-            else wndPtr->hVScroll = handle;
+            if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
+            else wndPtr->pVScroll = infoPtr;
         }
         if (!hUpArrow) SCROLL_LoadBitmaps();
     }
-    return (SCROLLINFO *) USER_HEAP_LIN_ADDR( handle );
+    return infoPtr;
 }
 
+
 /***********************************************************************
  *           SCROLL_GetScrollInfo
  */
@@ -364,13 +364,8 @@
     {
         if (nBar == SB_CTL)  /* Only scrollbar controls send WM_CTLCOLOR */
         {
-#ifdef WINELIB32
-            HBRUSH hbrush = SendMessage32A( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
-                                         hdc, hwnd );
-#else
-            HBRUSH hbrush = SendMessage16( GetParent(hwnd), WM_CTLCOLOR, hdc,
-                                          MAKELONG(hwnd, CTLCOLOR_SCROLLBAR) );
-#endif
+            HBRUSH hbrush = SendMessage32A( GetParent(hwnd),
+                                            WM_CTLCOLORSCROLLBAR, hdc, hwnd );
             SelectObject( hdc, hbrush );
         }
         else SelectObject( hdc, sysColorObjects.hbrushScrollbar );
@@ -524,15 +519,9 @@
     default:
         return;
     }
-#ifdef WINELIB32
     SendMessage32A( GetParent(hwnd),
-                 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
-                 msg, hwnd );
-#else
-    SendMessage16( GetParent(hwnd),
-                 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
-                 msg, MAKELONG( 0, hwnd ));
-#endif
+                    (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
+                    msg, hwnd );
 }
 
 
@@ -619,19 +608,14 @@
         {
             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
             {
-#ifdef WINELIB32
                 SendMessage32A( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_LINEUP, hwndCtl );
-#else
-                SendMessage16( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_LINEUP, MAKELONG( 0, hwndCtl ));
-#endif
-                SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-                                SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-                                (FARPROC)0 );
+                                SB_LINEUP, hwndCtl );
+                SetSystemTimer32( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
+                                  SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
+                                  (TIMERPROC32)0 );
             }
         }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
+        else KillSystemTimer32( hwnd, SCROLL_TIMER );
         break;
 
     case SCROLL_TOP_RECT:
@@ -642,19 +626,14 @@
         {
             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
             {
-#ifdef WINELIB32
                 SendMessage32A( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_PAGEUP, hwndCtl );
-#else
-                SendMessage16( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_PAGEUP, MAKELONG( 0, hwndCtl ));
-#endif
-                SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-                                SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-                                (FARPROC)0 );
+                                SB_PAGEUP, hwndCtl );
+                SetSystemTimer32( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
+                                  SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
+                                  (TIMERPROC32)0 );
             }
         }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
+        else KillSystemTimer32( hwnd, SCROLL_TIMER );
         break;
 
     case SCROLL_THUMB:
@@ -686,13 +665,8 @@
                                  trackThumbPos + lastMousePos - lastClickPos );
                 /* Save tracking info */
                 uTrackingPos = trackThumbPos + pos - lastClickPos;
-#ifdef WINELIB32
                 SendMessage32A( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             MAKEWPARAM(SB_THUMBTRACK,val), hwndCtl );
-#else
-                SendMessage16( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_THUMBTRACK, MAKELONG( val, hwndCtl ));
-#endif
+                                MAKEWPARAM( SB_THUMBTRACK, val ), hwndCtl );
                 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
                                         arrowSize, uTrackingPos );
             }
@@ -707,19 +681,14 @@
         {
             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
             {
-#ifdef WINELIB32
                 SendMessage32A( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_PAGEDOWN, hwndCtl );
-#else
-                SendMessage16( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_PAGEDOWN, MAKELONG( 0, hwndCtl ));
-#endif
-                SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-                                SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-                                (FARPROC)0 );
+                                SB_PAGEDOWN, hwndCtl );
+                SetSystemTimer32( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
+                                  SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
+                                  (TIMERPROC32)0 );
             }
         }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
+        else KillSystemTimer32( hwnd, SCROLL_TIMER );
         break;
         
     case SCROLL_BOTTOM_ARROW:
@@ -729,19 +698,14 @@
         {
             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
             {
-#ifdef WINELIB32
                 SendMessage32A( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_LINEDOWN, hwndCtl );
-#else
-                SendMessage16( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                             SB_LINEDOWN, MAKELONG( 0, hwndCtl ));
-#endif
-                SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
-                                SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
-                                (FARPROC)0 );
+                                SB_LINEDOWN, hwndCtl );
+                SetSystemTimer32( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
+                                  SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
+                                  (TIMERPROC32)0 );
             }
         }
-        else KillSystemTimer( hwnd, SCROLL_TIMER );
+        else KillSystemTimer32( hwnd, SCROLL_TIMER );
         break;
     }
 
@@ -751,22 +715,12 @@
         {
             UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
                                  trackThumbPos + lastMousePos - lastClickPos );
-#ifdef WINELIB32
             SendMessage32A( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                         MAKEWPARAM(SB_THUMBPOSITION,val), hwndCtl );
-#else
-            SendMessage16( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                         SB_THUMBPOSITION, MAKELONG( val, hwndCtl ) );
-#endif
+                            MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl );
         }
         else
-#ifdef WINELIB32
             SendMessage32A( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                         SB_ENDSCROLL, hwndCtl );
-#else
-            SendMessage16( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
-                         SB_ENDSCROLL, MAKELONG( 0, hwndCtl ) );
-#endif
+                            SB_ENDSCROLL, hwndCtl );
         trackHitTest = SCROLL_NOWHERE;  /* Terminate tracking */
     }
 
diff --git a/controls/static.c b/controls/static.c
index 9384040..aa8e1a7 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -222,13 +222,8 @@
 	wFormat |= DT_NOPREFIX;
 
     if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
-#ifdef WINELIB32
     hBrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
                              hdc, wndPtr->hwndSelf );
-#else
-    hBrush = SendMessage16( GetParent(wndPtr->hwndSelf), WM_CTLCOLOR, (WORD)hdc,
-                            MAKELONG(wndPtr->hwndSelf, CTLCOLOR_STATIC));
-#endif
     if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
     FillRect16(hdc, &rc, hBrush);
     if (wndPtr->text) DrawText16( hdc, wndPtr->text, -1, &rc, wFormat );
@@ -281,13 +276,8 @@
     STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
 
     GetClientRect16( wndPtr->hwndSelf, &rc);
-#ifdef WINELIB32
     hbrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
                              hdc, wndPtr->hwndSelf );
-#else
-    hbrush = SendMessage16( GetParent(wndPtr->hwndSelf), WM_CTLCOLOR, hdc,
-                            MAKELONG(wndPtr->hwndSelf, CTLCOLOR_STATIC));
-#endif
     FillRect16( hdc, &rc, hbrush );
     if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
 }
diff --git a/debugger/break.c b/debugger/break.c
index be92e1f..1e48763 100644
--- a/debugger/break.c
+++ b/debugger/break.c
@@ -37,31 +37,25 @@
  */
 static void DEBUG_SetOpcode( const DBG_ADDR *addr, BYTE op )
 {
-    if (addr->seg)
+    BYTE *ptr;
+
+    if (addr->seg) ptr = (BYTE *)PTR_SEG_OFF_TO_LIN( addr->seg, addr->off );
+    else ptr = (BYTE *)addr->off;
+
+    /* There are a couple of problems with this. On Linux prior to
+       1.1.62, this call fails (ENOACCESS) due to a bug in fs/exec.c.
+       This code is currently not tested at all on BSD.
+       How do I get the old protection in order to restore it later on?
+       */
+    if (mprotect((caddr_t)((int)ptr & (~4095)), 4096,
+                 PROT_READ | PROT_WRITE | PROT_EXEC) == -1)
     {
-        *(BYTE *)PTR_SEG_OFF_TO_LIN( addr->seg, addr->off ) = op;
+        perror( "Can't set break point" );
+        return;
     }
-    else  /* 32-bit code, so we have to change the protection first */
-    {
-        /* There are a couple of problems with this. On Linux prior to
-           1.1.62, this call fails (ENOACCESS) due to a bug in fs/exec.c.
-           This code is currently not tested at all on BSD.
-           How do I determine the page size in a more symbolic manner?
-           And why does mprotect need that start address of the page
-           in the first place?
-           Not that portability matters, this code is i386 only anyways...
-           How do I get the old protection in order to restore it later on?
-        */
-        if (mprotect((caddr_t)(addr->off & (~4095)), 4096,
-                     PROT_READ | PROT_WRITE | PROT_EXEC) == -1)
-        {
-            perror( "Can't set break point" );
-            return;
-	}
-        *(BYTE *)addr->off = op;
-	mprotect((caddr_t)(addr->off & ~4095), 4096,
-                  PROT_READ | PROT_EXEC );
-    }
+    *ptr = op;
+    /* mprotect((caddr_t)(addr->off & ~4095), 4096,
+       PROT_READ | PROT_EXEC ); */
 }
 
 
diff --git a/debugger/dbg.y b/debugger/dbg.y
index 45e806b..9a006a2 100644
--- a/debugger/dbg.y
+++ b/debugger/dbg.y
@@ -234,6 +234,7 @@
     static int loaded_symbols = 0;
     char SymbolTableFile[256];
     int instr_len = 0, newmode;
+    BOOL32 ret_ok;
 #ifdef YYDEBUG
     yydebug = 0;
 #endif
@@ -295,6 +296,7 @@
             instr_len = addr.off - EIP_reg(DEBUG_context);
         }
 
+        ret_ok = 0;
         do
         {
             issue_prompt();
@@ -303,7 +305,9 @@
             addr.seg = CS_reg(DEBUG_context);
             addr.off = EIP_reg(DEBUG_context);
             DBG_FIX_ADDR_SEG( &addr, 0 );
-        } while (!DBG_CHECK_READ_PTR( &addr, 1 ));
+            ret_ok = DEBUG_ValidateRegisters();
+            if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 );
+        } while (!ret_ok);
     }
 
     DEBUG_RestartExecution( regs, dbg_exec_mode, instr_len );
diff --git a/debugger/debug.l b/debugger/debug.l
index 709c23a..abd10bf 100644
--- a/debugger/debug.l
+++ b/debugger/debug.l
@@ -80,6 +80,8 @@
 $ds     { yylval.reg = REG_DS;  return tREG; }
 $cs     { yylval.reg = REG_CS;  return tREG; }
 $ss     { yylval.reg = REG_SS;  return tREG; }
+$fs     { yylval.reg = REG_FS;  return tREG; }
+$gs     { yylval.reg = REG_GS;  return tREG; }
 
 info|inf|in			{ return tINFO; }
 show|sho|sh			{ return tINFO; }
@@ -169,7 +171,11 @@
     {
         flush_symbols();
         line = readline ("Wine-dbg>");
-        if (!line) exit(0);
+        if (!line)
+        {
+            fprintf( stderr, "\n" );
+            exit(0);
+        }
 
         /* Remove leading and trailing whitespace from the line */
 
diff --git a/debugger/hash.c b/debugger/hash.c
index 39dbdab..459878d 100644
--- a/debugger/hash.c
+++ b/debugger/hash.c
@@ -212,7 +212,7 @@
     DBG_ADDR addr;
     char buffer[256];
     unsigned char *cpnt, *name;
-    unsigned int address;
+    FARPROC16 address;
     BOOL ok;
 
     for (ok = ModuleFirst(&entry); ok; ok = ModuleNext(&entry))
diff --git a/debugger/memory.c b/debugger/memory.c
index cfe16a2..62d33060 100644
--- a/debugger/memory.c
+++ b/debugger/memory.c
@@ -7,6 +7,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include "windows.h"
 #include "debugger.h"
 
 
diff --git a/debugger/registers.c b/debugger/registers.c
index 57aaf96..66b38f3 100644
--- a/debugger/registers.c
+++ b/debugger/registers.c
@@ -7,11 +7,8 @@
 #include <stdio.h>
 #include "debugger.h"
 
-
 SIGCONTEXT *DEBUG_context;
 
-
-
 /***********************************************************************
  *           DEBUG_SetRegister
  *
@@ -45,6 +42,20 @@
         case REG_DS:  DS_reg(DEBUG_context)  = val; break;
         case REG_ES:  ES_reg(DEBUG_context)  = val; break;
         case REG_SS:  SS_reg(DEBUG_context)  = val; break;
+#ifdef FS_reg
+        case REG_FS:  FS_reg(DEBUG_context)  = val; break;
+#else
+        case REG_FS:
+            fprintf( stderr, "Register %fs not supported on this system\n ");
+            break;
+#endif
+#ifdef GS_reg
+        case REG_GS:  GS_reg(DEBUG_context)  = val; break;
+#else
+        case REG_GS:
+            fprintf( stderr, "Register %gs not supported on this system\n ");
+            break;
+#endif
     }
 }
 
@@ -82,6 +93,20 @@
         case REG_DS:  return DS_reg(DEBUG_context);
         case REG_ES:  return ES_reg(DEBUG_context);
         case REG_SS:  return SS_reg(DEBUG_context);
+#ifdef FS_reg
+        case REG_FS:  return FS_reg(DEBUG_context);
+#else
+        case REG_FS:
+            fprintf( stderr, "Register %fs not supported on this system\n ");
+            return 0;
+#endif
+#ifdef GS_reg
+        case REG_GS:  return GS_reg(DEBUG_context);
+#else
+        case REG_GS:
+            fprintf( stderr, "Register %gs not supported on this system\n ");
+            return 0;
+#endif
     }
     return 0;  /* should not happen */
 }
@@ -98,13 +123,18 @@
     fprintf(stderr,"Register dump:\n");
 
     /* First get the segment registers out of the way */
-    fprintf( stderr," CS:%04x SS:%04x DS:%04x ES:%04x\n",
+    fprintf( stderr," CS:%04x SS:%04x DS:%04x ES:%04x",
              CS_reg(DEBUG_context), SS_reg(DEBUG_context),
              DS_reg(DEBUG_context), ES_reg(DEBUG_context) );
-
+#ifdef FS_reg
+    fprintf( stderr, " FS:%04x", FS_reg(DEBUG_context) );
+#endif
+#ifdef GS_reg
+    fprintf( stderr, " GS:%04x", GS_reg(DEBUG_context) );
+#endif
     if (dbg_mode == 16)
     {
-        fprintf( stderr," IP:%04x SP:%04x BP:%04x FLAGS:%04x\n",
+        fprintf( stderr,"\n IP:%04x SP:%04x BP:%04x FLAGS:%04x\n",
                  IP_reg(DEBUG_context), SP_reg(DEBUG_context),
                  BP_reg(DEBUG_context), FL_reg(DEBUG_context) );
 	fprintf( stderr," AX:%04x BX:%04x CX:%04x DX:%04x SI:%04x DI:%04x\n",
@@ -114,7 +144,7 @@
     }
     else  /* 32-bit mode */
     {
-        fprintf( stderr, " EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx\n", 
+        fprintf( stderr, "\n EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx\n", 
                  EIP_reg(DEBUG_context), ESP_reg(DEBUG_context),
                  EBP_reg(DEBUG_context), EFL_reg(DEBUG_context) );
 	fprintf( stderr, " EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n", 
@@ -125,3 +155,52 @@
     }
 }
 
+
+/***********************************************************************
+ *           DEBUG_ValidateRegisters
+ *
+ * Make sure all registers have a correct value for returning from
+ * the signal handler.
+ */
+BOOL32 DEBUG_ValidateRegisters(void)
+{
+/* Check that a selector is a valid ring-3 LDT selector, or a NULL selector */
+#define CHECK_SEG(seg,name) \
+    if (((seg) & ~3) && \
+        ((((seg) & 7) != 7) || IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(seg)))) \
+    { \
+        fprintf( stderr, "*** Invalid value for %s register: %04x\n", \
+                 (name), (seg) ); \
+        return FALSE; \
+    }
+
+    if (CS_reg(DEBUG_context) != WINE_CODE_SELECTOR)
+        CHECK_SEG( CS_reg(DEBUG_context), "CS" );
+    if (SS_reg(DEBUG_context) != WINE_DATA_SELECTOR)
+        CHECK_SEG( SS_reg(DEBUG_context), "SS" );
+    if (DS_reg(DEBUG_context) != WINE_DATA_SELECTOR)
+        CHECK_SEG( DS_reg(DEBUG_context), "DS" );
+    if (ES_reg(DEBUG_context) != WINE_DATA_SELECTOR)
+        CHECK_SEG( ES_reg(DEBUG_context), "ES" );
+    if (FS_reg(DEBUG_context) != WINE_DATA_SELECTOR)
+        CHECK_SEG( FS_reg(DEBUG_context), "FS" );
+    if (GS_reg(DEBUG_context) != WINE_DATA_SELECTOR)
+        CHECK_SEG( GS_reg(DEBUG_context), "GS" );
+
+    /* Check that CS and SS are not NULL */
+
+    if (!(CS_reg(DEBUG_context) & ~3))
+    {
+        fprintf( stderr, "*** Invalid value for CS register: %04x\n",
+                 CS_reg(DEBUG_context) );
+        return FALSE;
+    }
+    if (!(SS_reg(DEBUG_context) & ~3))
+    {
+        fprintf( stderr, "*** Invalid value for SS register: %04x\n",
+                 SS_reg(DEBUG_context) );
+        return FALSE;
+    }
+    return TRUE;
+#undef CHECK_SEG
+}
diff --git a/files/directory.c b/files/directory.c
index 285468e..10fcf64 100644
--- a/files/directory.c
+++ b/files/directory.c
@@ -248,10 +248,24 @@
  */
 BYTE GetTempDrive( BYTE ignored )
 {
+    /* FIXME: apparently Windows does something with the ignored byte */
     return DIR_TempDosDir[0];
 }
 
 
+UINT32 WIN16_GetTempDrive( BYTE ignored )
+{
+    /* A closer look at krnl386.exe shows what the SDK doesn't mention:
+     *
+     * returns:
+     *	 AL: driveletter
+     *   AH: ':'		- yes, some kernel code even does stosw with
+     *                            the returned AX.
+     *   DX: 1 for success
+     */
+    return MAKELONG( GetTempDrive(ignored) | (':' << 8), 1 );
+}
+
 /***********************************************************************
  *           GetWindowsDirectory   (KERNEL.134)
  */
diff --git a/files/dos_fs.c b/files/dos_fs.c
index 6e3efd8..e2086ec 100644
--- a/files/dos_fs.c
+++ b/files/dos_fs.c
@@ -24,6 +24,8 @@
 #include "msdos.h"
 #include "stddebug.h"
 #include "debug.h"
+#include "xmalloc.h"
+#include "string32.h"
 
 /* Chars we don't want to see in DOS file names */
 #define INVALID_DOS_CHARS  "*?<>|\"+=,;[] \345"
@@ -716,3 +718,32 @@
     dir = NULL;
     return 0;  /* End of directory */
 }
+
+
+/***********************************************************************
+ *           GetShortPathNameA   (KERNEL32.271)
+ */
+DWORD GetShortPathName32A( LPCSTR longpath, LPSTR shortpath, DWORD shortlen )
+{
+    LPCSTR dostruename;
+
+    dprintf_dosfs( stddeb, "GetShortPathName32A(%s,%p,%ld)\n",
+                   longpath, shortpath, shortlen );
+
+    dostruename = DOSFS_GetDosTrueName( longpath, 0 );
+    lstrcpyn32A( shortpath, dostruename, shortlen );
+    return strlen(dostruename);
+}
+
+
+/***********************************************************************
+ *           GetShortPathNameW   (KERNEL32.272)
+ */
+DWORD GetShortPathName32W( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen )
+{
+    LPSTR longpatha = STRING32_DupUniToAnsi( longpath );
+    LPCSTR dostruename = DOSFS_GetDosTrueName( longpatha, 0 );
+    free( longpatha );
+    lstrcpynAtoW( shortpath, dostruename, shortlen );
+    return strlen(dostruename);
+}
diff --git a/files/drive.c b/files/drive.c
index b57267b..fb15297 100644
--- a/files/drive.c
+++ b/files/drive.c
@@ -11,7 +11,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#if defined(__linux__) || defined(sun)
+#if defined(__linux__) || defined(sun) || defined(hpux)
 #include <sys/vfs.h>
 #endif
 #if defined(__NetBSD__) || defined(__FreeBSD__)
diff --git a/files/file.c b/files/file.c
index e324d3f..3264c08 100644
--- a/files/file.c
+++ b/files/file.c
@@ -526,13 +526,12 @@
 
 
 /***********************************************************************
- *           GetTempFileName   (KERNEL.97)
+ *           GetTempFileName16   (KERNEL.97)
  */
-INT GetTempFileName( BYTE drive, LPCSTR prefix, UINT unique, LPSTR buffer )
+UINT16 GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
+                          LPSTR buffer )
 {
-    int i;
-    UINT num = unique ? (unique & 0xffff) : time(NULL) & 0xffff;
-    char *p;
+    char temppath[144];
 
     if ((drive & TF_FORCEDRIVE) &&
         !DRIVE_IsValid( toupper(drive & ~TF_FORCEDRIVE) - 'A' ))
@@ -543,15 +542,28 @@
     }
 
     if (drive & TF_FORCEDRIVE)
-    {
-        sprintf( buffer, "%c:", drive & ~TF_FORCEDRIVE );
-    }
+        sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
     else
     {
-        GetTempPath32A( 132, buffer );  /* buffer must be at least 144 */
-        strcat( buffer, "\\" );
+        GetTempPath32A( 132, temppath );
+        strcat( temppath, "\\" );
     }
+    return (UINT16)GetTempFileName32A( temppath, prefix, unique, buffer );
+}
 
+
+/***********************************************************************
+ *           GetTempFileName32A   (KERNEL32.290)
+ */
+UINT32 GetTempFileName32A( LPCSTR path, LPCSTR prefix, UINT32 unique,
+                           LPSTR buffer)
+{
+    LPSTR p;
+    int i;
+    UINT32 num = unique ? (unique & 0xffff) : time(NULL) & 0xffff;
+
+    if (!path) return 0;
+    strcpy( buffer, path );
     p = buffer + strlen(buffer);
     *p++ = '~';
     for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++;
@@ -587,9 +599,30 @@
 
 
 /***********************************************************************
- *           OpenFile   (KERNEL.74)
+ *           GetTempFileName32W   (KERNEL32.291)
  */
-HFILE OpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode )
+UINT32 GetTempFileName32W( LPCWSTR path, LPCWSTR prefix, UINT32 unique,
+                           LPWSTR buffer )
+{
+    LPSTR   patha,prefixa;
+    char    buffera[144];
+    UINT32  ret;
+
+    if (!path) return 0;
+    patha	= STRING32_DupUniToAnsi(path);
+    prefixa	= STRING32_DupUniToAnsi(prefix);
+    ret 	= GetTempFileName32A( patha, prefixa, unique, buffera );
+    STRING32_AnsiToUni( buffer, buffera );
+    free(patha);
+    free(prefixa);
+    return ret;
+}
+
+
+/***********************************************************************
+ *           OpenFile   (KERNEL.74) (KERNEL32.396)
+ */
+HFILE OpenFile( LPCSTR name, OFSTRUCT *ofs, UINT32 mode )
 {
     DOS_FILE *file;
     HFILE hFileRet;
@@ -771,7 +804,7 @@
 
 
 /***********************************************************************
- *           _lclose   (KERNEL.81)
+ *           _lclose   (KERNEL.81) (KERNEL32.592)
  */
 HFILE _lclose( HFILE hFile )
 {
@@ -795,9 +828,9 @@
 
 
 /***********************************************************************
- *           _lcreat   (KERNEL.83)
+ *           _lcreat   (KERNEL.83) (KERNEL32.593)
  */
-HFILE _lcreat( LPCSTR path, INT attr )
+HFILE _lcreat( LPCSTR path, INT32 attr )
 {
     DOS_FILE *file;
     HFILE handle;
@@ -856,9 +889,9 @@
 
 
 /***********************************************************************
- *           _lopen   (KERNEL.85)
+ *           _lopen   (KERNEL.85) (KERNEL32.595)
  */
-HFILE _lopen( LPCSTR path, INT mode )
+HFILE _lopen( LPCSTR path, INT32 mode )
 {
     DOS_FILE *file;
     int unixMode;
diff --git a/if1632/Makefile.in b/if1632/Makefile.in
index d54fde2..1158685 100644
--- a/if1632/Makefile.in
+++ b/if1632/Makefile.in
@@ -79,7 +79,7 @@
 	$(BUILD) -callfrom16 `cat $(SPEC_FILES) | grep CallFrom16_ | sed 's/.*CallFrom16_\(.*\)/\1/' | sort | uniq` > callfrom16.S
 
 callfrom32.S: $(SPEC_FILES)
-	$(BUILD) -callfrom32 `cat $(SPEC_FILES) | grep CallFrom32_ | sed 's/.*CallFrom32_\([0-9]*\)/\1/' | sort | uniq` > callfrom32.S
+	$(BUILD) -callfrom32 `cat $(SPEC_FILES) | grep CallFrom32_ | sed 's/.*CallFrom32_\(.*\)/\1/' | sort | uniq` > callfrom32.S
 
 callto16.S: $(TOPSRC)/include/callback.h $(BUILD)
 	$(BUILD) -callto16 `cat $(TOPSRC)/include/callback.h | grep "extern.*CallTo16_" | sed 's/.*CallTo16_\(.*\)(.*/\1/' | sort | uniq` > callto16.S
diff --git a/if1632/callback.c b/if1632/callback.c
deleted file mode 100644
index 1baeaa5..0000000
--- a/if1632/callback.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef WINELIB
-/*
-static char RCSId[] = "$Id: wine.c,v 1.2 1993/07/04 04:04:21 root Exp root $";
-static char Copyright[] = "Copyright  Robert J. Amstadt, 1993";
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "windows.h"
-#include "callback.h"
-#include "stackframe.h"
-#include "stddebug.h"
-#include "debug.h"
-
-
-
-
-#endif /* !WINELIB */
diff --git a/if1632/crtdll.spec b/if1632/crtdll.spec
index 5cdb2ca..02e1b03 100644
--- a/if1632/crtdll.spec
+++ b/if1632/crtdll.spec
@@ -60,7 +60,7 @@
 056 stub _clearfp
 057 stub _close
 058 stub _commit
-059 stub _commode_dll
+059 long _commode_dll(0)
 060 stub _control87
 061 stub _controlfp
 062 stub _copysign
@@ -105,7 +105,7 @@
 101 stub _finite
 102 stub _flsbuf
 103 stub _flushall
-104 stub _fmode_dll
+104 long _fmode_dll(0)
 105 stub _fpclass
 106 stub _fpieee_flt
 107 stub _fpreset
diff --git a/if1632/gdi.spec b/if1632/gdi.spec
index 1dfb7a6..92186e3 100644
--- a/if1632/gdi.spec
+++ b/if1632/gdi.spec
@@ -65,7 +65,7 @@
 55  pascal16 CreateEllipticRgnIndirect(ptr) CreateEllipticRgnIndirect16
 56  pascal16 CreateFont(s_word s_word s_word s_word s_word word word word
                         word word word word word ptr) CreateFont
-57  pascal16 CreateFontIndirect(ptr) CreateFontIndirect
+57  pascal16 CreateFontIndirect(ptr) CreateFontIndirect16
 58  pascal16 CreateHatchBrush(word long) CreateHatchBrush
 60  pascal16 CreatePatternBrush(word) CreatePatternBrush
 61  pascal16 CreatePen(s_word s_word long) CreatePen
diff --git a/if1632/gdi32.spec b/if1632/gdi32.spec
index 5305d54..bf606d2 100644
--- a/if1632/gdi32.spec
+++ b/if1632/gdi32.spec
@@ -4,7 +4,7 @@
 
 0000 stub AbortDoc
 0001 stub AbortPath
-0002 stub AddFontResourceA
+0002 stdcall AddFontResourceA(ptr) AddFontResource
 0003 stub AddFontResourceTracking
 0004 stub AddFontResourceW
 0005 stub AngleArc
@@ -36,7 +36,7 @@
 0031 stdcall CreateCompatibleDC(long) CreateCompatibleDC
 0032 stub CreateDCA
 0033 stub CreateDCW
-0034 stub CreateDIBPatternBrush
+0034 stdcall CreateDIBPatternBrush(long long) CreateDIBPatternBrush
 0035 stub CreateDIBPatternBrushPt
 0036 stub CreateDIBSection
 0037 stub CreateDIBitmap
@@ -46,8 +46,8 @@
 0041 stub CreateEnhMetaFileA
 0042 stub CreateEnhMetaFileW
 0043 stub CreateFontA
-0044 stub CreateFontIndirectA
-0045 stub CreateFontIndirectW
+0044 stdcall CreateFontIndirectA(ptr) CreateFontIndirect32A
+0045 stdcall CreateFontIndirectW(ptr) CreateFontIndirect32W
 0046 stub CreateFontW
 0047 stub CreateHalftonePalette
 0048 stub CreateHatchBrush
@@ -98,7 +98,7 @@
 0093 stub ExtCreatePen
 0094 stub ExtCreateRegion
 0095 stub ExtEscape
-0096 stub ExtFloodFill
+0096 stdcall ExtFloodFill(long long long long long) ExtFloodFill
 0097 stub ExtSelectClipRgn
 0098 stdcall ExtTextOutA(long long long long ptr ptr long ptr) ExtTextOut32A
 0099 stdcall ExtTextOutW(long long long long ptr ptr long ptr) ExtTextOut32W
@@ -106,7 +106,7 @@
 0101 stub FillRgn
 0102 stub FixBrushOrgEx
 0103 stub FlattenPath
-0104 stub FloodFill
+0104 stdcall FloodFill(long long long long) FloodFill
 0105 stub FrameRgn
 0106 stub FreeImageColorMatcher
 0107 stub GdiAssociateObject
@@ -224,7 +224,7 @@
 0219 stdcall GetRgnBox(long ptr) GetRgnBox32
 0220 stdcall GetStockObject(long) GetStockObject
 0221 stub GetStretchBltMode
-0222 stub GetSystemPaletteEntries
+0222 stdcall GetSystemPaletteEntries(long long long ptr) GetSystemPaletteEntries
 0223 stub GetSystemPaletteUse
 0224 stub GetTextAlign
 0225 stub GetTextCharacterExtra
@@ -282,7 +282,7 @@
 0277 stub PolylineTo
 0278 stdcall PtInRegion(long long long) PtInRegion
 0279 stub PtVisible
-0280 stub RealizePalette
+0280 stdcall RealizePalette(long) RealizePalette32
 0281 stdcall RectInRegion(long ptr) RectInRegion32
 0282 stdcall RectVisible(long ptr) RectVisible32
 0283 stdcall Rectangle(long long long long long) Rectangle
@@ -302,13 +302,13 @@
 0297 stub SelectClipRgn
 0298 stub SelectFontLocal
 0299 stdcall SelectObject(long long) SelectObject
-0300 stub SelectPalette
+0300 stdcall SelectPalette(long long long) SelectPalette32
 0301 stub SetAbortProc
 0302 stub SetArcDirection
 0303 stdcall SetBitmapBits(long long ptr) SetBitmapBits
 0304 stdcall SetBitmapDimensionEx(long long long ptr) SetBitmapDimensionEx32
 0305 stdcall SetBkColor(long long) SetBkColor
-0306 stub SetBkMode
+0306 stdcall SetBkMode(long long) SetBkMode
 0307 stub SetBoundsRect
 0308 stub SetBrushOrgEx
 0309 stub SetColorAdjustment
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index 11723e1..4111ce2 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -46,7 +46,7 @@
 47  pascal16 GetModuleHandle(segptr) WIN16_GetModuleHandle
 48  pascal16 GetModuleUsage(word) GetModuleUsage
 49  pascal16 GetModuleFileName(word ptr s_word) GetModuleFileName
-50  pascal GetProcAddress(word segptr) GetProcAddress
+50  pascal GetProcAddress(word segptr) GetProcAddress16
 51  pascal MakeProcInstance(segptr word) MakeProcInstance16
 52  pascal16 FreeProcInstance(segptr) FreeProcInstance16
 53  stub CallProcInstance
@@ -88,12 +88,12 @@
 89  pascal   lstrcat(segptr segptr) lstrcat16
 90  pascal16 lstrlen(ptr) lstrlen16
 91  register InitTask() InitTask
-92  pascal16 GetTempDrive(byte) GetTempDrive
+92  pascal   GetTempDrive(byte) WIN16_GetTempDrive
 93  pascal16 GetCodeHandle(segptr) GetCodeHandle
 94  stub DefineHandleTable
 95  pascal16 LoadLibrary(ptr) LoadLibrary
 96  pascal16 FreeLibrary(word) FreeLibrary
-97  pascal16 GetTempFileName(byte ptr word ptr) GetTempFileName
+97  pascal16 GetTempFileName(byte ptr word ptr) GetTempFileName16
 98  stub GetLastDiskChange
 99  stub GetLPErrMode
 100 stub ValidateCodeSegments
diff --git a/if1632/kernel32.spec b/if1632/kernel32.spec
index 7a60849..eb8dfff 100644
--- a/if1632/kernel32.spec
+++ b/if1632/kernel32.spec
@@ -31,8 +31,8 @@
 0026 stub CommConfigDialogA
 0027 stub CommConfigDialogW
 0028 stub CompareFileTime
-0029 stdcall CompareStringA(long long ptr long ptr long) CompareStringA
-0030 stub CompareStringW
+0029 stdcall CompareStringA(long long ptr long ptr long) CompareString32A
+0030 stdcall CompareStringW(long long ptr long ptr long) CompareString32W
 0031 stub ConnectNamedPipe
 0032 stub ConsoleMenuControl
 0033 stub ConsoleSubst
@@ -259,7 +259,7 @@
 0254 stub GetPrivateProfileSectionW
 0255 stdcall GetPrivateProfileStringA(ptr ptr ptr ptr long ptr) GetPrivateProfileString
 0256 stub GetPrivateProfileStringW
-0257	stdcall GetProcAddress(long long)	WIN32_GetProcAddress
+0257 stdcall GetProcAddress(long ptr) GetProcAddress32
 0258 stdcall GetProcessAffinityMask(long ptr ptr)	GetProcessAffinityMask
 0259 stdcall GetProcessHeap() GetProcessHeap
 0260 stub GetProcessHeaps
@@ -273,9 +273,9 @@
 0268 stdcall GetProfileStringA(ptr ptr ptr ptr long) GetProfileString
 0269 stub GetProfileStringW
 0270 stub GetQueuedCompletionStatus
-0271 stub GetShortPathNameA
-0272 stub GetShortPathNameW
-0273	stdcall GetStartupInfoA(ptr) GetStartupInfoA
+0271 stdcall GetShortPathNameA(ptr ptr long) GetShortPathName32A
+0272 stdcall GetShortPathNameW(ptr ptr long) GetShortPathName32W
+0273 stdcall GetStartupInfoA(ptr) GetStartupInfoA
 0274 stub GetStartupInfoW
 0275	stdcall GetStdHandle(long)	GetStdHandle
 0276 stub GetStringTypeA
@@ -292,8 +292,8 @@
 0287 stub GetTapeParameters
 0288 stub GetTapePosition
 0289 stub GetTapeStatus
-0290 stub GetTempFileNameA
-0291 stub GetTempFileNameW
+0290 stdcall GetTempFileNameA(ptr ptr long ptr) GetTempFileName32A
+0291 stdcall GetTempFileNameW(ptr ptr long ptr) GetTempFileName32W
 0292 stdcall GetTempPathA(long ptr) GetTempPath32A
 0293 stdcall GetTempPathW(long ptr) GetTempPath32W
 0294	stdcall GetThreadContext(long ptr)	GetThreadContext
@@ -301,11 +301,11 @@
 0296 stub GetThreadPriority
 0297 stub GetThreadSelectorEntry
 0298 stub GetThreadTimes
-0299    stdcall GetTickCount() GetTickCount
+0299 stdcall GetTickCount() GetTickCount
 0300 stub GetTimeFormatA
 0301 stub GetTimeFormatW
 0302    stdcall GetTimeZoneInformation(ptr) GetTimeZoneInformation
-0303 stub GetUserDefaultLCID
+0303 stdcall GetUserDefaultLCID() GetUserDefaultLCID
 0304 stub GetUserDefaultLangID
 0305 stub GetVDMCurrentDirectories
 0306 stdcall GetVersion() GetVersion32
@@ -398,8 +398,8 @@
 0393 stub OpenConsoleW
 0394 stub OpenEventA
 0395 stub OpenEventW
-0396 stub OpenFile
-0397 	stdcall OpenFileMappingA(long long ptr) OpenFileMapping
+0396 stdcall OpenFile(ptr ptr long) OpenFile
+0397 stdcall OpenFileMappingA(long long ptr) OpenFileMapping
 0398 stub OpenFileMappingW
 0399 stub OpenMutexA
 0400 stub OpenMutexW
@@ -594,10 +594,10 @@
 0589 stub WriteTapemark
 0590 stub _hread
 0591 stub _hwrite
-0592 stub _lclose
-0593 stub _lcreat
+0592 stdcall _lclose(long) _lclose
+0593 stdcall _lcreat(ptr long) _lcreat
 0594 stub _llseek
-0595 stub _lopen
+0595 stdcall _lopen(ptr long) _lopen
 0596 stub _lread
 0597 stub _lwrite
 0598 stdcall lstrcat(ptr ptr) lstrcat32A
diff --git a/if1632/ole2nls.spec b/if1632/ole2nls.spec
index ae5892b..49b2b2f 100644
--- a/if1632/ole2nls.spec
+++ b/if1632/ole2nls.spec
@@ -8,7 +8,7 @@
 5 pascal GetLocaleInfoA(long long ptr word) GetLocaleInfoA
 6 stub LCMAPSTRINGA
 7 stub GETSTRINGTYPEA
-8 pascal16 CompareStringA(long long ptr word ptr word) CompareStringA
+8 pascal16 CompareStringA(long long ptr word ptr word) CompareString16
 #9 WEP
 10 stub LIBMAIN
 11 stub NOTIFYWINDOWPROC
diff --git a/if1632/relay.c b/if1632/relay.c
index 6d4c75e..9ecb6da 100644
--- a/if1632/relay.c
+++ b/if1632/relay.c
@@ -64,24 +64,19 @@
  *           RELAY_DebugCallFrom16
  */
 void RELAY_DebugCallFrom16( int func_type, char *args,
-                            void *entry_point, int args32 )
+                            void *entry_point, SIGCONTEXT *context )
 {
     STACK16FRAME *frame;
-    NE_MODULE *pModule;
     WORD ordinal;
-    char *args16, *name;
+    char *args16;
     int i;
 
     if (!debugging_relay) return;
 
     frame = CURRENT_STACK16;
-    pModule = BUILTIN_GetEntryPoint( frame->entry_cs, frame->entry_ip,
-                                     &ordinal, &name );
-    printf( "Call %.*s.%d: %.*s(",
-            *((BYTE *)pModule + pModule->name_table),
-            (char *)pModule + pModule->name_table + 1,
-            ordinal, *name, name + 1 );
-
+    printf( "Call %s(", BUILTIN_GetEntryPoint16( frame->entry_cs,
+                                                 frame->entry_ip,
+                                                 &ordinal ));
     args16 = (char *)frame->args;
     for (i = 0; i < strlen(args); i++)
     {
@@ -122,13 +117,10 @@
     printf( ") ret=%04x:%04x ds=%04x\n", frame->cs, frame->ip, frame->ds );
 
     if (func_type == 2)  /* register function */
-    {
-        SIGCONTEXT *context = (SIGCONTEXT *)&args32;
         printf( "     AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
                 AX_reg(context), BX_reg(context), CX_reg(context),
                 DX_reg(context), SI_reg(context), DI_reg(context),
                 ES_reg(context), EFL_reg(context) );
-    }
 }
 
 
@@ -138,9 +130,7 @@
 void RELAY_DebugCallFrom16Ret( int func_type, int ret_val, int args32 )
 {
     STACK16FRAME *frame;
-    NE_MODULE *pModule;
     WORD ordinal;
-    char *name;
 
     if (*(DWORD *)PTR_SEG_TO_LIN(IF1632_Stack32_base) != 0xDEADBEEF)
     {
@@ -149,14 +139,10 @@
     }
     if (!debugging_relay) return;
 
-    frame   = CURRENT_STACK16;
-    pModule = BUILTIN_GetEntryPoint( frame->entry_cs, frame->entry_ip,
-                                     &ordinal, &name );
-    printf( "Ret  %.*s.%d: %.*s() ",
-            *((BYTE *)pModule + pModule->name_table),
-            (char *)pModule + pModule->name_table + 1,
-            ordinal, *name, name + 1 );
-
+    frame = CURRENT_STACK16;
+    printf( "Ret  %s() ", BUILTIN_GetEntryPoint16( frame->entry_cs,
+                                                   frame->entry_ip,
+                                                   &ordinal ));
     switch(func_type)
     {
     case 0: /* long */
@@ -191,15 +177,10 @@
 void RELAY_Unimplemented16(void)
 {
     WORD ordinal;
-    char *name;
     STACK16FRAME *frame = CURRENT_STACK16;
-    NE_MODULE *pModule  = BUILTIN_GetEntryPoint( frame->entry_cs,
-                                                 frame->entry_ip,
-                                                 &ordinal, &name );
-    fprintf( stderr, "No handler for Win16 routine %.*s.%d (%.*s) called from %04x:%04x\n",
-             *((BYTE *)pModule + pModule->name_table),
-             (char *)pModule + pModule->name_table + 1,
-             ordinal, *name, name + 1, frame->cs, frame->ip );
+    fprintf(stderr,"No handler for Win16 routine %s (called from %04x:%04x)\n",
+            BUILTIN_GetEntryPoint16(frame->entry_cs,frame->entry_ip,&ordinal),
+            frame->cs, frame->ip );
     TASK_KillCurrentTask(1);
 }
 
@@ -211,11 +192,11 @@
  * as 'stub' in the spec file).
  * (The args are the same than for RELAY_DebugCallFrom32).
  */
-void RELAY_Unimplemented32( int nb_args, void *entry_point,
-                            const char *func_name, int ebp, int ret_addr )
+void RELAY_Unimplemented32( int nb_args, void *relay_addr,
+                            void *entry_point, int ebp, int ret_addr )
 {
-    fprintf( stderr, "No handler for Win32 routine %s called from %08x\n",
-             func_name, ret_addr );
+    fprintf( stderr, "No handler for Win32 routine %s (called from %08x)\n",
+             BUILTIN_GetEntryPoint32( relay_addr ), ret_addr );
     TASK_KillCurrentTask(1);
 }
 
@@ -246,13 +227,13 @@
 /***********************************************************************
  *           RELAY_DebugCallFrom32
  */
-void RELAY_DebugCallFrom32( int nb_args, void *entry_point,
-                            const char *func_name, int ebp, int ret_addr,
-                            int arg1 )
+void RELAY_DebugCallFrom32( int nb_args, void *relay_addr,
+                            void *entry_point, int ebp, int ret_addr, int arg1)
 {
-    int  *parg;
+    int *parg;
+
     if (!debugging_relay) return;
-    printf( "Call %s(", func_name );
+    printf( "Call %s(", BUILTIN_GetEntryPoint32( relay_addr ));
     for (parg = &arg1; nb_args; parg++, nb_args--)
     {
         printf( "%08x", *parg );
@@ -265,12 +246,12 @@
 /***********************************************************************
  *           RELAY_DebugCallFrom32Ret
  */
-void RELAY_DebugCallFrom32Ret( int ret_val, void *entry_point,
-                               const char *func_name, int ebp, int ret_addr )
+void RELAY_DebugCallFrom32Ret( int ret_val, void *relay_addr,
+                               void *entry_point, int ebp, int ret_addr )
 {
     if (!debugging_relay) return;
     printf( "Ret  %s() retval=0x%08x ret=%08x\n",
-            func_name, ret_val, ret_addr );
+            BUILTIN_GetEntryPoint32( relay_addr ), ret_val, ret_addr );
 }
 
 
diff --git a/if1632/user.spec b/if1632/user.spec
index c0828b8..fbe9fb1 100644
--- a/if1632/user.spec
+++ b/if1632/user.spec
@@ -9,9 +9,9 @@
 5   pascal16 InitApp(word) USER_InitApp
 6   pascal16 PostQuitMessage(word) PostQuitMessage
 7   pascal16 ExitWindows(long word) ExitWindows
-10  pascal16 SetTimer(word word word segptr) SetTimer
-11  pascal16 SetSystemTimer(word word word segptr) SetSystemTimer
-12  pascal16 KillTimer(word word) KillTimer
+10  pascal16 SetTimer(word word word segptr) SetTimer16
+11  pascal16 SetSystemTimer(word word word segptr) SetSystemTimer16
+12  pascal16 KillTimer(word word) KillTimer16
 13  pascal   GetTickCount() GetTickCount
 14  pascal   GetTimerResolution() GetTimerResolution
 15  pascal   GetCurrentTime() GetCurrentTime
@@ -168,7 +168,7 @@
 166 pascal16 HideCaret(word) HideCaret
 167 pascal16 ShowCaret(word) ShowCaret
 168 pascal16 SetCaretBlinkTime(word) SetCaretBlinkTime
-169 pascal16 GetCaretBlinkTime() GetCaretBlinkTime
+169 pascal16 GetCaretBlinkTime() GetCaretBlinkTime16
 170 pascal16 ArrangeIconicWindows(word) ArrangeIconicWindows
 171 pascal16 WinHelp(word ptr word long) WinHelp
 172 stub SwitchToThisWindow
@@ -181,7 +181,7 @@
 179 pascal16 GetSystemMetrics(word) GetSystemMetrics
 180 pascal   GetSysColor(word) GetSysColor
 181 pascal16 SetSysColors(word ptr ptr) SetSysColors
-182 pascal16 KillSystemTimer(word word) KillSystemTimer
+182 pascal16 KillSystemTimer(word word) KillSystemTimer16
 183 pascal16 GetCaretPos(ptr) GetCaretPos16
 184 stub QuerySendMessage
 185 pascal16 GrayString(word word segptr segptr s_word s_word s_word s_word s_word) GrayString
@@ -224,7 +224,7 @@
 221 pascal16 ScrollDC(word s_word s_word ptr ptr word ptr) ScrollDC
 222 pascal16 GetKeyboardState(ptr) GetKeyboardState
 223 pascal16 SetKeyboardState(ptr) SetKeyboardState
-224 pascal16 GetWindowTask(word) GetWindowTask
+224 pascal16 GetWindowTask(word) GetWindowTask16
 225 pascal16 EnumTaskWindows(word segptr long) EnumTaskWindows16
 226 stub LockInput
 227 pascal16 GetNextDlgGroupItem(word word word) GetNextDlgGroupItem
@@ -329,8 +329,8 @@
 359 pascal16 GetDCEx(word word long) GetDCEx
 362 pascal16 DCHook(word word long long) DCHook
 364 stub LookupIconIDFromDirectoryEx
-368 pascal16 CopyIcon(word word) CopyIcon
-369 pascal16 CopyCursor(word word) CopyCursor
+368 pascal16 CopyIcon(word word) CopyIcon16
+369 pascal16 CopyCursor(word word) CopyCursor16
 370 pascal16 GetWindowPlacement(word ptr) GetWindowPlacement16
 371 pascal16 SetWindowPlacement(word ptr) SetWindowPlacement16
 372 stub GetInternalIconHeader
@@ -382,10 +382,10 @@
 430 pascal16 lstrcmp(ptr ptr) lstrcmp16
 431 pascal   AnsiUpper(segptr) WIN16_AnsiUpper
 432 pascal   AnsiLower(segptr) WIN16_AnsiLower
-433 pascal16 IsCharAlpha(byte) IsCharAlpha
-434 pascal16 IsCharAlphanumeric(byte) IsCharAlphanumeric
-435 pascal16 IsCharUpper(byte) IsCharUpper
-436 pascal16 IsCharLower(byte) IsCharLower
+433 pascal16 IsCharAlpha(byte) IsCharAlpha16
+434 pascal16 IsCharAlphanumeric(byte) IsCharAlphanumeric16
+435 pascal16 IsCharUpper(byte) IsCharUpper16
+436 pascal16 IsCharLower(byte) IsCharLower16
 437 pascal16 AnsiUpperBuff(ptr word) AnsiUpperBuff
 438 pascal16 AnsiLowerBuff(ptr word) AnsiLowerBuff
 441 stub InsertMenuItem
@@ -484,10 +484,10 @@
 652 stub GetKeyboardLayoutList
 654 stub UnloadKeyboardLayout
 655 stub PostPostedMessages
-656 pascal16 DrawFrameControl(word ptr word word) DrawFrameControl
+656 pascal16 DrawFrameControl(word ptr word word) DrawFrameControl16
 657 stub DrawCaptionTemp
 658 stub DispatchInput
-659 pascal16 DrawEdge(word ptr word word) DrawEdge
+659 pascal16 DrawEdge(word ptr word word) DrawEdge16
 660 stub DrawCaption
 661 stub SetSysColorsTemp
 662 stub DrawMenubarTemp
diff --git a/if1632/user32.spec b/if1632/user32.spec
index c7c2316..ce2432c 100644
--- a/if1632/user32.spec
+++ b/if1632/user32.spec
@@ -26,30 +26,30 @@
 0021 stub ChangeClipboardChain
 0022 stdcall ChangeMenuA(long long ptr long long) ChangeMenu32A
 0023 stdcall ChangeMenuW(long long ptr long long) ChangeMenu32W
-0024 stub CharLowerA
-0025 stub CharLowerBuffA
-0026 stub CharLowerBuffW
-0027 stub CharLowerW
-0028 stub CharNextA
-0029 stub CharNextExA
-0030 stub CharNextExW
-0031 stub CharNextW
-0032 stub CharPrevA
-0033 stub CharPrevExA
-0034 stub CharPrevExW
-0035 stub CharPrevW
-0036 stub CharToOemA
-0037 stub CharToOemBuffA
-0038 stub CharToOemBuffW
-0039 stub CharToOemW
-0040 stub CharUpperA
-0041 stub CharUpperBuffA
-0042 stub CharUpperBuffW
-0043 stub CharUpperW
-0044 stub CheckDlgButton
+0024 stdcall CharLowerA(ptr) CharLower32A
+0025 stdcall CharLowerBuffA(ptr long) CharLowerBuff32A
+0026 stdcall CharLowerBuffW(ptr long) CharLowerBuff32W
+0027 stdcall CharLowerW(ptr) CharLower32W
+0028 stdcall CharNextA(ptr) CharNext32A
+0029 stdcall CharNextExA(long ptr long) CharNextEx32A
+0030 stdcall CharNextExW(long ptr long) CharNextEx32W
+0031 stdcall CharNextW(ptr) CharNext32W
+0032 stdcall CharPrevA(ptr ptr) CharPrev32A
+0033 stdcall CharPrevExA(long ptr ptr long) CharPrevEx32A
+0034 stdcall CharPrevExW(long ptr ptr long) CharPrevEx32W
+0035 stdcall CharPrevW(ptr ptr) CharPrev32W
+0036 stdcall CharToOemA(ptr ptr) CharToOem32A
+0037 stdcall CharToOemBuffA(ptr ptr long) CharToOemBuff32A
+0038 stdcall CharToOemBuffW(ptr ptr long) CharToOemBuff32W
+0039 stdcall CharToOemW(ptr ptr) CharToOem32W
+0040 stdcall CharUpperA(ptr) CharUpper32A
+0041 stdcall CharUpperBuffA(ptr long) CharUpperBuff32A
+0042 stdcall CharUpperBuffW(ptr long) CharUpperBuff32W
+0043 stdcall CharUpperW(ptr) CharUpper32W
+0044 stdcall CheckDlgButton(long long long) CheckDlgButton
 0045 stdcall CheckMenuItem(long long long) CheckMenuItem
 0046 stub CheckMenuRadioItem
-0047 stub CheckRadioButton
+0047 stdcall CheckRadioButton(long long long long) CheckRadioButton
 0048 stdcall ChildWindowFromPoint(long long long) ChildWindowFromPoint32
 0049 stub ChildWindowFromPointEx
 0050 stub ClientThreadConnect
@@ -61,13 +61,13 @@
 0056 stub CloseWindowStation
 0057 stub CopyAcceleratorTableA
 0058 stub CopyAcceleratorTableW
-0059 stub CopyIcon
+0059 stdcall CopyIcon(long) CopyIcon32
 0060 stub CopyImage
 0061 stdcall CopyRect(ptr ptr) CopyRect32
 0062 stub CountClipboardFormats
 0063 stub CreateAcceleratorTableA
 0064 stub CreateAcceleratorTableW
-0065 stub CreateCaret
+0065 stdcall CreateCaret(long long long long) CreateCaret
 0066 stub CreateCursor
 0067 stub CreateDesktopA
 0068 stub CreateDesktopW
@@ -134,7 +134,7 @@
 0127 stub DeferWindowPos
 0128 stub DeleteMenu
 0129 stub DestroyAcceleratorTable
-0130 stub DestroyCaret
+0130 stdcall DestroyCaret() DestroyCaret
 0131 stub DestroyCursor
 0132 stub DestroyIcon
 0133 stub DestroyMenu
@@ -158,10 +158,10 @@
 0151 stub DragObject
 0152 stub DrawAnimatedRects
 0153 stub DrawCaption
-0154 stub DrawEdge
+0154 stdcall DrawEdge(long ptr long long) DrawEdge32
 0155 stdcall DrawFocusRect(long ptr) DrawFocusRect32
 0156 stub DrawFrame
-0157 stub DrawFrameControl
+0157 stdcall DrawFrameControl(long ptr long long) DrawFrameControl32
 0158 stub DrawIcon
 0159 stub DrawIconEx
 0160 stdcall DrawMenuBar(long) DrawMenuBar
@@ -212,7 +212,7 @@
 0205 stdcall GetAppCompatFlags(long) GetAppCompatFlags
 0206 stub GetAsyncKeyState
 0207 stub GetCapture
-0208 stub GetCaretBlinkTime
+0208 stdcall GetCaretBlinkTime() GetCaretBlinkTime32
 0209 stdcall GetCaretPos(ptr) GetCaretPos32
 0210 stdcall GetClassInfoA(long ptr ptr) GetClassInfo32A
 0211 stdcall GetClassInfoExA(long ptr ptr) GetClassInfoEx32A
@@ -237,7 +237,7 @@
 0230 stub GetDCEx
 0231 stdcall GetDesktopWindow() GetDesktopWindow
 0232 stub GetDialogBaseUnits
-0233 stub GetDlgCtrlID
+0233 stdcall GetDlgCtrlID(long) GetDlgCtrlID
 0234 stdcall GetDlgItem(long long) GetDlgItem
 0235 stdcall GetDlgItemInt(long long long long) GetDlgItemInt
 0236 stdcall GetDlgItemTextA(long long ptr long) GetDlgItemText32A
@@ -320,7 +320,7 @@
 0313 stdcall GetWindowWord(long long) GetWindowWord
 0314 stub GrayStringA
 0315 stub GrayStringW
-0316 stub HideCaret
+0316 stdcall HideCaret(long) HideCaret
 0317 stub HiliteMenuItem
 0318 stub ImpersonateDdeClientWindow
 0319 stub InSendMessage
@@ -334,14 +334,14 @@
 0327 stdcall InvalidateRect(long ptr long) InvalidateRect32
 0328 stdcall InvalidateRgn(long long long) InvalidateRgn
 0329 stdcall InvertRect(long ptr) InvertRect32
-0330 stub IsCharAlphaA
-0331 stub IsCharAlphaNumericA
-0332 stub IsCharAlphaNumericW
-0333 stub IsCharAlphaW
-0334 stub IsCharLowerA
-0335 stub IsCharLowerW
-0336 stub IsCharUpperA
-0337 stub IsCharUpperW
+0330 stdcall IsCharAlphaA(long) IsCharAlpha32A
+0331 stdcall IsCharAlphaNumericA(long) IsCharAlphaNumeric32A
+0332 stdcall IsCharAlphaNumericW(long) IsCharAlphaNumeric32W
+0333 stdcall IsCharAlphaW(long) IsCharAlpha32W
+0334 stdcall IsCharLowerA(long) IsCharLower32A
+0335 stdcall IsCharLowerW(long) IsCharLower32W
+0336 stdcall IsCharUpperA(long) IsCharUpper32A
+0337 stdcall IsCharUpperW(long) IsCharUpper32W
 0338 stub IsChild
 0339 stub IsClipboardFormatAvailable
 0340 stub IsDialogMessage
@@ -351,13 +351,13 @@
 0344 stdcall IsIconic(long) IsIconic
 0345 stub IsMenu
 0346 stdcall IsRectEmpty(ptr) IsRectEmpty32
-0347 stub IsWindow
+0347 stdcall IsWindow(long) IsWindow
 0348 stdcall IsWindowEnabled(long) IsWindowEnabled
 0349 stdcall IsWindowUnicode(long) IsWindowUnicode
 0350 stdcall IsWindowVisible(long) IsWindowVisible
 0351 stub IsZoomed
-0352 stub KillSystemTimer
-0353 stdcall KillTimer(long long) KillTimer
+0352 stdcall KillSystemTimer(long long) KillSystemTimer32
+0353 stdcall KillTimer(long long) KillTimer32
 0354 	stdcall LoadAcceleratorsA(long ptr) WIN32_LoadAcceleratorsA
 0355 stdcall LoadAcceleratorsW(long ptr)	WIN32_LoadAcceleratorsW
 0356 	stdcall LoadBitmapA(long ptr) WIN32_LoadBitmapA
@@ -405,10 +405,10 @@
 0398 stdcall MoveWindow(long long long long long long) MoveWindow
 0399 stub MsgWaitForMultipleObjects
 0400 stub OemKeyScan
-0401 stub OemToCharA
-0402 stub OemToCharBuffA
-0403 stub OemToCharBuffW
-0404 stub OemToCharW
+0401 stdcall OemToCharA(ptr ptr) OemToChar32A
+0402 stdcall OemToCharBuffA(ptr ptr long) OemToCharBuff32A
+0403 stdcall OemToCharBuffW(ptr ptr long) OemToCharBuff32W
+0404 stdcall OemToCharW(ptr ptr) OemToChar32W
 0405 stdcall OffsetRect(ptr long long) OffsetRect32
 0406 stub OpenClipboard
 0407 stub OpenDesktopA
@@ -468,8 +468,8 @@
 0461 stub ServerSetFunctionPointers
 0462 stub SetActiveWindow
 0463 stdcall SetCapture(long) SetCapture
-0464 stub SetCaretBlinkTime
-0465 stub SetCaretPos
+0464 stdcall SetCaretBlinkTime(long) SetCaretBlinkTime
+0465 stdcall SetCaretPos(long long) SetCaretPos
 0466 stdcall SetClassLongA(long long long) SetClassLong32A
 0467 stdcall SetClassLongW(long long long) SetClassLong32W
 0468 stdcall SetClassWord(long long long) SetClassWord
@@ -484,7 +484,7 @@
 0477 stdcall SetDlgItemTextA(long long ptr) SetDlgItemText32A
 0478 stdcall SetDlgItemTextW(long long ptr) SetDlgItemText32W
 0479 stub SetDoubleClickTime
-0480 stub SetFocus
+0480 stdcall SetFocus(long) SetFocus
 0481 stub SetForegroundWindow
 0482 stdcall SetInternalWindowPos(long long ptr ptr) SetInternalWindowPos32
 0483 stub SetKeyboardState
@@ -512,9 +512,9 @@
 0505 stub SetSysColorsTemp
 0506 stub SetSystemCursor
 0507 stub SetSystemMenu
-0508 stub SetSystemTimer
+0508 stdcall SetSystemTimer(long long long ptr) SetSystemTimer32
 0509 stub SetThreadDesktop
-0510 stdcall SetTimer(long long long long) USER32_SetTimer
+0510 stdcall SetTimer(long long long ptr) SetTimer32
 0511 stub SetUserObjectInformationA
 0512 stub SetUserObjectInformationW
 0513 stub SetUserObjectSecurity
@@ -532,7 +532,7 @@
 0525 stdcall SetWindowsHookExA(long long long long) SetWindowsHookEx32A
 0526 stub SetWindowsHookExW
 0527 stub SetWindowsHookW
-0528 stub ShowCaret
+0528 stdcall ShowCaret(long) ShowCaret
 0529 stdcall ShowCursor(long) ShowCursor
 0530 stub ShowOwnedPopups
 0531 stub ShowScrollBar
diff --git a/if1632/wprocs.spec b/if1632/wprocs.spec
index 4e47f58..1f7b233 100644
--- a/if1632/wprocs.spec
+++ b/if1632/wprocs.spec
@@ -20,9 +20,7 @@
 20 pascal PrintDlgProc(word word word long) PrintDlgProc
 21 pascal AboutDlgProc(word word word long) AboutDlgProc
 22 pascal ComboLBoxWndProc(word word word long) ComboLBoxWndProc
-23 pascal16 CARET_Callback(word word word long) CARET_Callback
 24 pascal16 TASK_Reschedule() TASK_Reschedule
-25 pascal MMSysTimeCallback(word word word long) MMSysTimeCallback
 26 register Win32CallToStart() PE_Win32CallToStart
 27 pascal EntryAddrProc(word word) MODULE_GetEntryPoint
 28 pascal MyAlloc(word word word) MODULE_AllocateSegment
diff --git a/include/brush.h b/include/brush.h
index 6803254..d1836b3 100644
--- a/include/brush.h
+++ b/include/brush.h
@@ -9,9 +9,7 @@
 
 #include "gdi.h"
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* GDI logical brush object */
 typedef struct
@@ -20,9 +18,7 @@
     LOGBRUSH16  logbrush WINE_PACKED;
 } BRUSHOBJ;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 extern BOOL BRUSH_Init(void);
 extern int BRUSH_GetObject( BRUSHOBJ * brush, int count, LPSTR buffer );
diff --git a/include/callback.h b/include/callback.h
index b45373b..89d231a 100644
--- a/include/callback.h
+++ b/include/callback.h
@@ -1,5 +1,5 @@
 /*
- * 16-bit mode callback functions
+ * Callback functions
  *
  * Copyright 1995 Alexandre Julliard
  */
@@ -77,16 +77,16 @@
 #define CallWindowsExitProc( func, nExitType ) \
     CallTo16_word_w( func, CURRENT_DS, nExitType )
 #define CallWndProc16( func, ds, hwnd, msg, wParam, lParam ) \
-    CallTo16_long_wwwl( func, ds, hwnd, msg, wParam, lParam )
+    CallTo16_long_wwwl( (FARPROC16)(func), ds, hwnd, msg, wParam, lParam )
 #define CallWordBreakProc( func, lpch, ichCurrent, cch, code ) \
     CallTo16_word_lwww( func, CURRENT_DS, lpch, ichCurrent, cch, code )
 #define CallWndProcNCCREATE16( func, ds, exStyle, clsName, winName, style, \
                                x, y, cx, cy, hparent, hmenu, instance, \
                                params, hwnd, msg, wParam, lParam ) \
-    CallTo16_long_lllllllwlwwwl( func, ds, exStyle, clsName, winName, style, \
-                                 MAKELONG(y,x), MAKELONG(cy,cx), \
-                                 MAKELONG(hmenu,hparent), instance, params, \
-                                 hwnd, msg, wParam, lParam )
+    CallTo16_long_lllllllwlwwwl( (FARPROC16)(func), ds, exStyle, clsName, \
+                              winName, style, MAKELONG(y,x), MAKELONG(cy,cx), \
+                              MAKELONG(hmenu,hparent), instance, params, \
+                              hwnd, msg, wParam, lParam )
 
 /* List of the 32-bit callback functions. This list is used  */
 /* by the build program to generate the file if1632/callto32.S */
diff --git a/include/commdlg.h b/include/commdlg.h
index 47efc9d..0140d32 100644
--- a/include/commdlg.h
+++ b/include/commdlg.h
@@ -11,10 +11,6 @@
 
 #include "wintypes.h"		/* needed for CHOOSEFONT structure */
 
-#ifndef WINELIB
-#pragma pack(1)
-#endif
-
 #define RT_CURSOR           MAKEINTRESOURCE(1)
 #define RT_BITMAP           MAKEINTRESOURCE(2)
 #define RT_ICON             MAKEINTRESOURCE(3)
@@ -29,10 +25,6 @@
 #define RT_GROUP_CURSOR     MAKEINTRESOURCE(12)
 #define RT_GROUP_ICON       MAKEINTRESOURCE(14)
 
-#ifndef HGLOBAL
-#define HGLOBAL     HANDLE
-#endif
-
 #define OFN_READONLY                 0x00000001
 #define OFN_OVERWRITEPROMPT          0x00000002
 #define OFN_HIDEREADONLY             0x00000004
@@ -55,7 +47,6 @@
 #define OFN_SHARENOWARN          1
 #define OFN_SHAREWARN            0
 
-
 typedef struct {
 	DWORD		lStructSize;
 	HWND		hwndOwner;
@@ -75,8 +66,7 @@
 	UINT		nFileExtension;
 	SEGPTR		lpstrDefExt;
 	LPARAM 		lCustData;
-/*	UINT 		(CALLBACK *lpfnHook)(HWND, UINT, WPARAM, LPARAM);*/
-        FARPROC         lpfnHook;
+        WNDPROC16       lpfnHook;
 	SEGPTR 		lpTemplateName;
 	}   OPENFILENAME;
 typedef OPENFILENAME * LPOPENFILENAME;
@@ -90,7 +80,7 @@
 	COLORREF       *lpCustColors;
 	DWORD 		Flags;
 	LPARAM		lCustData;
-	UINT		(*lpfnHook)(HWND, UINT, WPARAM, LPARAM);
+        WNDPROC16       lpfnHook;
 	SEGPTR 		lpTemplateName;
 	} CHOOSECOLOR;
 typedef CHOOSECOLOR *LPCHOOSECOLOR;
@@ -114,8 +104,7 @@
 	UINT		wFindWhatLen;           /* size of find buffer      */
 	UINT 		wReplaceWithLen;        /* size of replace buffer   */
 	LPARAM 		lCustData;              /* data passed to hook fn.  */
-/*	UINT		(CALLBACK* lpfnHook)(HWND, UINT, WPARAM, LPARAM); */
-        FARPROC         lpfnHook;
+        WNDPROC16       lpfnHook;
 	SEGPTR 		lpTemplateName;         /* custom template name     */
 	} FINDREPLACE;
 typedef FINDREPLACE *LPFINDREPLACE;
@@ -139,6 +128,8 @@
 #define FR_HIDEWHOLEWORD                0x00010000
 
 
+#pragma pack(1)
+
 typedef struct {
 	DWORD			lStructSize;
 	HWND			hwndOwner;          /* caller's window handle   */
@@ -148,8 +139,7 @@
 	DWORD			Flags WINE_PACKED;  /* enum. type flags         */
 	COLORREF		rgbColors;          /* returned text color      */
 	LPARAM	                lCustData;          /* data passed to hook fn.  */
-/*	UINT (CALLBACK* lpfnHook)(HWND, UINT, WPARAM, LPARAM);*/
-        FARPROC                 lpfnHook;
+        WNDPROC16               lpfnHook;
 	SEGPTR			lpTemplateName;     /* custom template name     */
 	HINSTANCE		hInstance;          /* instance handle of.EXE that   */
 							/* contains cust. dlg. template  */
@@ -164,6 +154,7 @@
 	} CHOOSEFONT;
 typedef CHOOSEFONT *LPCHOOSEFONT;
 
+#pragma pack(4)
 
 #define CF_SCREENFONTS               0x00000001
 #define CF_PRINTERFONTS              0x00000002
@@ -226,10 +217,8 @@
 	UINT		nCopies;
 	HINSTANCE 	hInstance;
 	LPARAM 		lCustData;
-/*	UINT		(CALLBACK* lpfnPrintHook)(HWND, UINT, WPARAM, LPARAM);
-	UINT		(CALLBACK* lpfnSetupHook)(HWND, UINT, WPARAM, LPARAM);*/
-        FARPROC         lpfnPrintHook;
-        FARPROC         lpfnSetupHook;
+        WNDPROC16       lpfnPrintHook;
+        WNDPROC16       lpfnSetupHook;
 	SEGPTR 		lpPrintTemplateName;
 	SEGPTR 		lpSetupTemplateName;
 	HGLOBAL 	hPrintTemplate;
@@ -237,7 +226,6 @@
 	} PRINTDLG;
 typedef PRINTDLG * LPPRINTDLG;
 
-
 #define PD_ALLPAGES                  0x00000000
 #define PD_SELECTION                 0x00000001
 #define PD_PAGENUMS                  0x00000002
@@ -306,10 +294,6 @@
 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
 LRESULT FormatCharDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
 
-#ifndef WINELIB
-#pragma pack(4)
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/cursoricon.h b/include/cursoricon.h
index 214ddbf..1555b18 100644
--- a/include/cursoricon.h
+++ b/include/cursoricon.h
@@ -10,10 +10,6 @@
 #include <X11/Xlib.h>
 #include "windows.h"
 
-#ifndef WINELIB
-#pragma pack(1)
-#endif
-
 typedef struct
 {
     BYTE   bWidth;
@@ -42,6 +38,8 @@
     CURSORDIRENTRY  cursor;
 } CURSORICONDIRENTRY;
 
+#pragma pack(1)
+
 typedef struct
 {
     WORD                idReserved;
@@ -50,9 +48,7 @@
     CURSORICONDIRENTRY  idEntries[1] WINE_PACKED;
 } CURSORICONDIR;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 extern Cursor CURSORICON_XCursor;  /* Current X cursor */
 
diff --git a/include/debug.h b/include/debug.h
index 0e0ab86..8936cca 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -36,7 +36,6 @@
 #undef DEBUG_DOSFS
 #undef DEBUG_DRIVER
 #undef DEBUG_EDIT
-#undef DEBUG_ENUM
 #undef DEBUG_ENV
 #undef DEBUG_EVENT
 #undef DEBUG_EXEC
@@ -114,7 +113,6 @@
 #define DEBUG_DOSFS
 #define DEBUG_DRIVER
 #define DEBUG_EDIT
-#define DEBUG_ENUM
 #define DEBUG_ENV
 #define DEBUG_EVENT
 #define DEBUG_EXEC
@@ -274,11 +272,6 @@
 #else
     0,
 #endif
-#ifdef DEBUG_ENUM
-    1,
-#else
-    0,
-#endif
 #ifdef DEBUG_ENV
     1,
 #else
@@ -817,21 +810,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_enum if(!debug_msg_enabled[20]) ; else fprintf
-#define debugging_enum debug_msg_enabled[20]
-#else
-#ifdef DEBUG_ENUM
-#define dprintf_enum fprintf
-#define debugging_enum 1
-#else
-#define dprintf_enum while(0) fprintf
-#define debugging_enum 0
-#endif
-#endif
-
-#ifdef DEBUG_RUNTIME
-#define dprintf_env if(!debug_msg_enabled[21]) ; else fprintf
-#define debugging_env debug_msg_enabled[21]
+#define dprintf_env if(!debug_msg_enabled[20]) ; else fprintf
+#define debugging_env debug_msg_enabled[20]
 #else
 #ifdef DEBUG_ENV
 #define dprintf_env fprintf
@@ -843,8 +823,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_event if(!debug_msg_enabled[22]) ; else fprintf
-#define debugging_event debug_msg_enabled[22]
+#define dprintf_event if(!debug_msg_enabled[21]) ; else fprintf
+#define debugging_event debug_msg_enabled[21]
 #else
 #ifdef DEBUG_EVENT
 #define dprintf_event fprintf
@@ -856,8 +836,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_exec if(!debug_msg_enabled[23]) ; else fprintf
-#define debugging_exec debug_msg_enabled[23]
+#define dprintf_exec if(!debug_msg_enabled[22]) ; else fprintf
+#define debugging_exec debug_msg_enabled[22]
 #else
 #ifdef DEBUG_EXEC
 #define dprintf_exec fprintf
@@ -869,8 +849,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_file if(!debug_msg_enabled[24]) ; else fprintf
-#define debugging_file debug_msg_enabled[24]
+#define dprintf_file if(!debug_msg_enabled[23]) ; else fprintf
+#define debugging_file debug_msg_enabled[23]
 #else
 #ifdef DEBUG_FILE
 #define dprintf_file fprintf
@@ -882,8 +862,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_fixup if(!debug_msg_enabled[25]) ; else fprintf
-#define debugging_fixup debug_msg_enabled[25]
+#define dprintf_fixup if(!debug_msg_enabled[24]) ; else fprintf
+#define debugging_fixup debug_msg_enabled[24]
 #else
 #ifdef DEBUG_FIXUP
 #define dprintf_fixup fprintf
@@ -895,8 +875,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_font if(!debug_msg_enabled[26]) ; else fprintf
-#define debugging_font debug_msg_enabled[26]
+#define dprintf_font if(!debug_msg_enabled[25]) ; else fprintf
+#define debugging_font debug_msg_enabled[25]
 #else
 #ifdef DEBUG_FONT
 #define dprintf_font fprintf
@@ -908,8 +888,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_gdi if(!debug_msg_enabled[27]) ; else fprintf
-#define debugging_gdi debug_msg_enabled[27]
+#define dprintf_gdi if(!debug_msg_enabled[26]) ; else fprintf
+#define debugging_gdi debug_msg_enabled[26]
 #else
 #ifdef DEBUG_GDI
 #define dprintf_gdi fprintf
@@ -921,8 +901,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_global if(!debug_msg_enabled[28]) ; else fprintf
-#define debugging_global debug_msg_enabled[28]
+#define dprintf_global if(!debug_msg_enabled[27]) ; else fprintf
+#define debugging_global debug_msg_enabled[27]
 #else
 #ifdef DEBUG_GLOBAL
 #define dprintf_global fprintf
@@ -934,8 +914,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_graphics if(!debug_msg_enabled[29]) ; else fprintf
-#define debugging_graphics debug_msg_enabled[29]
+#define dprintf_graphics if(!debug_msg_enabled[28]) ; else fprintf
+#define debugging_graphics debug_msg_enabled[28]
 #else
 #ifdef DEBUG_GRAPHICS
 #define dprintf_graphics fprintf
@@ -947,8 +927,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_heap if(!debug_msg_enabled[30]) ; else fprintf
-#define debugging_heap debug_msg_enabled[30]
+#define dprintf_heap if(!debug_msg_enabled[29]) ; else fprintf
+#define debugging_heap debug_msg_enabled[29]
 #else
 #ifdef DEBUG_HEAP
 #define dprintf_heap fprintf
@@ -960,8 +940,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_hook if(!debug_msg_enabled[31]) ; else fprintf
-#define debugging_hook debug_msg_enabled[31]
+#define dprintf_hook if(!debug_msg_enabled[30]) ; else fprintf
+#define debugging_hook debug_msg_enabled[30]
 #else
 #ifdef DEBUG_HOOK
 #define dprintf_hook fprintf
@@ -973,8 +953,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_icon if(!debug_msg_enabled[32]) ; else fprintf
-#define debugging_icon debug_msg_enabled[32]
+#define dprintf_icon if(!debug_msg_enabled[31]) ; else fprintf
+#define debugging_icon debug_msg_enabled[31]
 #else
 #ifdef DEBUG_ICON
 #define dprintf_icon fprintf
@@ -986,8 +966,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_int if(!debug_msg_enabled[33]) ; else fprintf
-#define debugging_int debug_msg_enabled[33]
+#define dprintf_int if(!debug_msg_enabled[32]) ; else fprintf
+#define debugging_int debug_msg_enabled[32]
 #else
 #ifdef DEBUG_INT
 #define dprintf_int fprintf
@@ -999,8 +979,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_key if(!debug_msg_enabled[34]) ; else fprintf
-#define debugging_key debug_msg_enabled[34]
+#define dprintf_key if(!debug_msg_enabled[33]) ; else fprintf
+#define debugging_key debug_msg_enabled[33]
 #else
 #ifdef DEBUG_KEY
 #define dprintf_key fprintf
@@ -1012,8 +992,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_keyboard if(!debug_msg_enabled[35]) ; else fprintf
-#define debugging_keyboard debug_msg_enabled[35]
+#define dprintf_keyboard if(!debug_msg_enabled[34]) ; else fprintf
+#define debugging_keyboard debug_msg_enabled[34]
 #else
 #ifdef DEBUG_KEYBOARD
 #define dprintf_keyboard fprintf
@@ -1025,8 +1005,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ldt if(!debug_msg_enabled[36]) ; else fprintf
-#define debugging_ldt debug_msg_enabled[36]
+#define dprintf_ldt if(!debug_msg_enabled[35]) ; else fprintf
+#define debugging_ldt debug_msg_enabled[35]
 #else
 #ifdef DEBUG_LDT
 #define dprintf_ldt fprintf
@@ -1038,8 +1018,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_listbox if(!debug_msg_enabled[37]) ; else fprintf
-#define debugging_listbox debug_msg_enabled[37]
+#define dprintf_listbox if(!debug_msg_enabled[36]) ; else fprintf
+#define debugging_listbox debug_msg_enabled[36]
 #else
 #ifdef DEBUG_LISTBOX
 #define dprintf_listbox fprintf
@@ -1051,8 +1031,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_local if(!debug_msg_enabled[38]) ; else fprintf
-#define debugging_local debug_msg_enabled[38]
+#define dprintf_local if(!debug_msg_enabled[37]) ; else fprintf
+#define debugging_local debug_msg_enabled[37]
 #else
 #ifdef DEBUG_LOCAL
 #define dprintf_local fprintf
@@ -1064,8 +1044,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mci if(!debug_msg_enabled[39]) ; else fprintf
-#define debugging_mci debug_msg_enabled[39]
+#define dprintf_mci if(!debug_msg_enabled[38]) ; else fprintf
+#define debugging_mci debug_msg_enabled[38]
 #else
 #ifdef DEBUG_MCI
 #define dprintf_mci fprintf
@@ -1077,8 +1057,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mcianim if(!debug_msg_enabled[40]) ; else fprintf
-#define debugging_mcianim debug_msg_enabled[40]
+#define dprintf_mcianim if(!debug_msg_enabled[39]) ; else fprintf
+#define debugging_mcianim debug_msg_enabled[39]
 #else
 #ifdef DEBUG_MCIANIM
 #define dprintf_mcianim fprintf
@@ -1090,8 +1070,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mciwave if(!debug_msg_enabled[41]) ; else fprintf
-#define debugging_mciwave debug_msg_enabled[41]
+#define dprintf_mciwave if(!debug_msg_enabled[40]) ; else fprintf
+#define debugging_mciwave debug_msg_enabled[40]
 #else
 #ifdef DEBUG_MCIWAVE
 #define dprintf_mciwave fprintf
@@ -1103,8 +1083,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mdi if(!debug_msg_enabled[42]) ; else fprintf
-#define debugging_mdi debug_msg_enabled[42]
+#define dprintf_mdi if(!debug_msg_enabled[41]) ; else fprintf
+#define debugging_mdi debug_msg_enabled[41]
 #else
 #ifdef DEBUG_MDI
 #define dprintf_mdi fprintf
@@ -1116,8 +1096,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_menu if(!debug_msg_enabled[43]) ; else fprintf
-#define debugging_menu debug_msg_enabled[43]
+#define dprintf_menu if(!debug_msg_enabled[42]) ; else fprintf
+#define debugging_menu debug_msg_enabled[42]
 #else
 #ifdef DEBUG_MENU
 #define dprintf_menu fprintf
@@ -1129,8 +1109,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_message if(!debug_msg_enabled[44]) ; else fprintf
-#define debugging_message debug_msg_enabled[44]
+#define dprintf_message if(!debug_msg_enabled[43]) ; else fprintf
+#define debugging_message debug_msg_enabled[43]
 #else
 #ifdef DEBUG_MESSAGE
 #define dprintf_message fprintf
@@ -1142,8 +1122,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_metafile if(!debug_msg_enabled[45]) ; else fprintf
-#define debugging_metafile debug_msg_enabled[45]
+#define dprintf_metafile if(!debug_msg_enabled[44]) ; else fprintf
+#define debugging_metafile debug_msg_enabled[44]
 #else
 #ifdef DEBUG_METAFILE
 #define dprintf_metafile fprintf
@@ -1155,8 +1135,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_midi if(!debug_msg_enabled[46]) ; else fprintf
-#define debugging_midi debug_msg_enabled[46]
+#define dprintf_midi if(!debug_msg_enabled[45]) ; else fprintf
+#define debugging_midi debug_msg_enabled[45]
 #else
 #ifdef DEBUG_MIDI
 #define dprintf_midi fprintf
@@ -1168,8 +1148,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmio if(!debug_msg_enabled[47]) ; else fprintf
-#define debugging_mmio debug_msg_enabled[47]
+#define dprintf_mmio if(!debug_msg_enabled[46]) ; else fprintf
+#define debugging_mmio debug_msg_enabled[46]
 #else
 #ifdef DEBUG_MMIO
 #define dprintf_mmio fprintf
@@ -1181,8 +1161,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmsys if(!debug_msg_enabled[48]) ; else fprintf
-#define debugging_mmsys debug_msg_enabled[48]
+#define dprintf_mmsys if(!debug_msg_enabled[47]) ; else fprintf
+#define debugging_mmsys debug_msg_enabled[47]
 #else
 #ifdef DEBUG_MMSYS
 #define dprintf_mmsys fprintf
@@ -1194,8 +1174,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_mmtime if(!debug_msg_enabled[49]) ; else fprintf
-#define debugging_mmtime debug_msg_enabled[49]
+#define dprintf_mmtime if(!debug_msg_enabled[48]) ; else fprintf
+#define debugging_mmtime debug_msg_enabled[48]
 #else
 #ifdef DEBUG_MMTIME
 #define dprintf_mmtime fprintf
@@ -1207,8 +1187,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_module if(!debug_msg_enabled[50]) ; else fprintf
-#define debugging_module debug_msg_enabled[50]
+#define dprintf_module if(!debug_msg_enabled[49]) ; else fprintf
+#define debugging_module debug_msg_enabled[49]
 #else
 #ifdef DEBUG_MODULE
 #define dprintf_module fprintf
@@ -1220,8 +1200,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_msg if(!debug_msg_enabled[51]) ; else fprintf
-#define debugging_msg debug_msg_enabled[51]
+#define dprintf_msg if(!debug_msg_enabled[50]) ; else fprintf
+#define debugging_msg debug_msg_enabled[50]
 #else
 #ifdef DEBUG_MSG
 #define dprintf_msg fprintf
@@ -1233,8 +1213,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_nonclient if(!debug_msg_enabled[52]) ; else fprintf
-#define debugging_nonclient debug_msg_enabled[52]
+#define dprintf_nonclient if(!debug_msg_enabled[51]) ; else fprintf
+#define debugging_nonclient debug_msg_enabled[51]
 #else
 #ifdef DEBUG_NONCLIENT
 #define dprintf_nonclient fprintf
@@ -1246,8 +1226,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ole if(!debug_msg_enabled[53]) ; else fprintf
-#define debugging_ole debug_msg_enabled[53]
+#define dprintf_ole if(!debug_msg_enabled[52]) ; else fprintf
+#define debugging_ole debug_msg_enabled[52]
 #else
 #ifdef DEBUG_OLE
 #define dprintf_ole fprintf
@@ -1259,8 +1239,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_palette if(!debug_msg_enabled[54]) ; else fprintf
-#define debugging_palette debug_msg_enabled[54]
+#define dprintf_palette if(!debug_msg_enabled[53]) ; else fprintf
+#define debugging_palette debug_msg_enabled[53]
 #else
 #ifdef DEBUG_PALETTE
 #define dprintf_palette fprintf
@@ -1272,8 +1252,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_profile if(!debug_msg_enabled[55]) ; else fprintf
-#define debugging_profile debug_msg_enabled[55]
+#define dprintf_profile if(!debug_msg_enabled[54]) ; else fprintf
+#define debugging_profile debug_msg_enabled[54]
 #else
 #ifdef DEBUG_PROFILE
 #define dprintf_profile fprintf
@@ -1285,8 +1265,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_prop if(!debug_msg_enabled[56]) ; else fprintf
-#define debugging_prop debug_msg_enabled[56]
+#define dprintf_prop if(!debug_msg_enabled[55]) ; else fprintf
+#define debugging_prop debug_msg_enabled[55]
 #else
 #ifdef DEBUG_PROP
 #define dprintf_prop fprintf
@@ -1298,8 +1278,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_reg if(!debug_msg_enabled[57]) ; else fprintf
-#define debugging_reg debug_msg_enabled[57]
+#define dprintf_reg if(!debug_msg_enabled[56]) ; else fprintf
+#define debugging_reg debug_msg_enabled[56]
 #else
 #ifdef DEBUG_REG
 #define dprintf_reg fprintf
@@ -1311,8 +1291,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_region if(!debug_msg_enabled[58]) ; else fprintf
-#define debugging_region debug_msg_enabled[58]
+#define dprintf_region if(!debug_msg_enabled[57]) ; else fprintf
+#define debugging_region debug_msg_enabled[57]
 #else
 #ifdef DEBUG_REGION
 #define dprintf_region fprintf
@@ -1324,8 +1304,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_relay if(!debug_msg_enabled[59]) ; else fprintf
-#define debugging_relay debug_msg_enabled[59]
+#define dprintf_relay if(!debug_msg_enabled[58]) ; else fprintf
+#define debugging_relay debug_msg_enabled[58]
 #else
 #ifdef DEBUG_RELAY
 #define dprintf_relay fprintf
@@ -1337,8 +1317,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_resource if(!debug_msg_enabled[60]) ; else fprintf
-#define debugging_resource debug_msg_enabled[60]
+#define dprintf_resource if(!debug_msg_enabled[59]) ; else fprintf
+#define debugging_resource debug_msg_enabled[59]
 #else
 #ifdef DEBUG_RESOURCE
 #define dprintf_resource fprintf
@@ -1350,8 +1330,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_scroll if(!debug_msg_enabled[61]) ; else fprintf
-#define debugging_scroll debug_msg_enabled[61]
+#define dprintf_scroll if(!debug_msg_enabled[60]) ; else fprintf
+#define debugging_scroll debug_msg_enabled[60]
 #else
 #ifdef DEBUG_SCROLL
 #define dprintf_scroll fprintf
@@ -1363,8 +1343,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_selector if(!debug_msg_enabled[62]) ; else fprintf
-#define debugging_selector debug_msg_enabled[62]
+#define dprintf_selector if(!debug_msg_enabled[61]) ; else fprintf
+#define debugging_selector debug_msg_enabled[61]
 #else
 #ifdef DEBUG_SELECTOR
 #define dprintf_selector fprintf
@@ -1376,8 +1356,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_sem if(!debug_msg_enabled[63]) ; else fprintf
-#define debugging_sem debug_msg_enabled[63]
+#define dprintf_sem if(!debug_msg_enabled[62]) ; else fprintf
+#define debugging_sem debug_msg_enabled[62]
 #else
 #ifdef DEBUG_SEM
 #define dprintf_sem fprintf
@@ -1389,8 +1369,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_shm if(!debug_msg_enabled[64]) ; else fprintf
-#define debugging_shm debug_msg_enabled[64]
+#define dprintf_shm if(!debug_msg_enabled[63]) ; else fprintf
+#define debugging_shm debug_msg_enabled[63]
 #else
 #ifdef DEBUG_SHM
 #define dprintf_shm fprintf
@@ -1402,8 +1382,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_stress if(!debug_msg_enabled[65]) ; else fprintf
-#define debugging_stress debug_msg_enabled[65]
+#define dprintf_stress if(!debug_msg_enabled[64]) ; else fprintf
+#define debugging_stress debug_msg_enabled[64]
 #else
 #ifdef DEBUG_STRESS
 #define dprintf_stress fprintf
@@ -1415,8 +1395,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_syscolor if(!debug_msg_enabled[66]) ; else fprintf
-#define debugging_syscolor debug_msg_enabled[66]
+#define dprintf_syscolor if(!debug_msg_enabled[65]) ; else fprintf
+#define debugging_syscolor debug_msg_enabled[65]
 #else
 #ifdef DEBUG_SYSCOLOR
 #define dprintf_syscolor fprintf
@@ -1428,8 +1408,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_task if(!debug_msg_enabled[67]) ; else fprintf
-#define debugging_task debug_msg_enabled[67]
+#define dprintf_task if(!debug_msg_enabled[66]) ; else fprintf
+#define debugging_task debug_msg_enabled[66]
 #else
 #ifdef DEBUG_TASK
 #define dprintf_task fprintf
@@ -1441,8 +1421,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_text if(!debug_msg_enabled[68]) ; else fprintf
-#define debugging_text debug_msg_enabled[68]
+#define dprintf_text if(!debug_msg_enabled[67]) ; else fprintf
+#define debugging_text debug_msg_enabled[67]
 #else
 #ifdef DEBUG_TEXT
 #define dprintf_text fprintf
@@ -1454,8 +1434,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_timer if(!debug_msg_enabled[69]) ; else fprintf
-#define debugging_timer debug_msg_enabled[69]
+#define dprintf_timer if(!debug_msg_enabled[68]) ; else fprintf
+#define debugging_timer debug_msg_enabled[68]
 #else
 #ifdef DEBUG_TIMER
 #define dprintf_timer fprintf
@@ -1467,8 +1447,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_toolhelp if(!debug_msg_enabled[70]) ; else fprintf
-#define debugging_toolhelp debug_msg_enabled[70]
+#define dprintf_toolhelp if(!debug_msg_enabled[69]) ; else fprintf
+#define debugging_toolhelp debug_msg_enabled[69]
 #else
 #ifdef DEBUG_TOOLHELP
 #define dprintf_toolhelp fprintf
@@ -1480,8 +1460,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_vxd if(!debug_msg_enabled[71]) ; else fprintf
-#define debugging_vxd debug_msg_enabled[71]
+#define dprintf_vxd if(!debug_msg_enabled[70]) ; else fprintf
+#define debugging_vxd debug_msg_enabled[70]
 #else
 #ifdef DEBUG_VXD
 #define dprintf_vxd fprintf
@@ -1493,8 +1473,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win if(!debug_msg_enabled[72]) ; else fprintf
-#define debugging_win debug_msg_enabled[72]
+#define dprintf_win if(!debug_msg_enabled[71]) ; else fprintf
+#define debugging_win debug_msg_enabled[71]
 #else
 #ifdef DEBUG_WIN
 #define dprintf_win fprintf
@@ -1506,8 +1486,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win32 if(!debug_msg_enabled[73]) ; else fprintf
-#define debugging_win32 debug_msg_enabled[73]
+#define dprintf_win32 if(!debug_msg_enabled[72]) ; else fprintf
+#define debugging_win32 debug_msg_enabled[72]
 #else
 #ifdef DEBUG_WIN32
 #define dprintf_win32 fprintf
@@ -1519,8 +1499,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_winsock if(!debug_msg_enabled[74]) ; else fprintf
-#define debugging_winsock debug_msg_enabled[74]
+#define dprintf_winsock if(!debug_msg_enabled[73]) ; else fprintf
+#define debugging_winsock debug_msg_enabled[73]
 #else
 #ifdef DEBUG_WINSOCK
 #define dprintf_winsock fprintf
@@ -1555,7 +1535,6 @@
     "dosfs",
     "driver",
     "edit",
-    "enum",
     "env",
     "event",
     "exec",
diff --git a/include/debugger.h b/include/debugger.h
index 6cb3e97..ebdefc4 100644
--- a/include/debugger.h
+++ b/include/debugger.h
@@ -4,12 +4,11 @@
  * Copyright 1995 Alexandre Julliard
  */
 
-#ifndef DEBUGGER_H
-#define DEBUGGER_H
+#ifndef __WINE_DEBUGGER_H
+#define __WINE_DEBUGGER_H
 
 #include "ldt.h"
 #include "registers.h"
-#include "wine.h"
 
 #define STEP_FLAG 0x100 /* single step flag */
 
@@ -50,7 +49,7 @@
     REG_EDI, REG_EBP, REG_EFL, REG_EIP, REG_ESP,
     REG_AX, REG_BX, REG_CX, REG_DX, REG_SI,
     REG_DI, REG_BP, REG_FL, REG_IP, REG_SP,
-    REG_CS, REG_DS, REG_ES, REG_SS
+    REG_CS, REG_DS, REG_ES, REG_SS, REG_FS, REG_GS
 };
 
 
@@ -104,6 +103,7 @@
 extern void DEBUG_SetRegister( enum debug_regs reg, int val );
 extern int DEBUG_GetRegister( enum debug_regs reg );
 extern void DEBUG_InfoRegisters(void);
+extern BOOL32 DEBUG_ValidateRegisters(void);
 
   /* debugger/stack.c */
 extern void DEBUG_InfoStack(void);
@@ -113,4 +113,4 @@
 extern void DEBUG_EnterDebugger(void);
 extern void wine_debug( int signal, SIGCONTEXT *regs );
 
-#endif  /* DEBUGGER_H */
+#endif  /* __WINE_DEBUGGER_H */
diff --git a/include/font.h b/include/font.h
index 8372ebd..f282a0d 100644
--- a/include/font.h
+++ b/include/font.h
@@ -9,9 +9,7 @@
 
 #include "gdi.h"
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* GDI logical font object */
 typedef struct
@@ -20,6 +18,8 @@
     LOGFONT16   logfont WINE_PACKED;
 } FONTOBJ;
 
+#pragma pack(4)
+
 /* may be switched... */
 #define GGO_BITMAP	0x4F4D
 #define GGO_NATIVE	0x4F50
@@ -39,9 +39,6 @@
 	DWORD	eM22;
 } MAT2,*LPMAT2;
 
-#ifndef WINELIB
-#pragma pack(4)
-#endif
 
 extern BOOL FONT_Init( void );
 extern int FONT_GetObject( FONTOBJ * font, int count, LPSTR buffer );
diff --git a/include/gdi.h b/include/gdi.h
index 7bb9aa1..8a1ef42 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -28,10 +28,6 @@
 #define METAFILE_DC_MAGIC     0x4f51
 #define MAGIC_DONTCARE	      0xffff
 
-#ifndef WINELIB
-#pragma pack(1)
-#endif
-
 typedef struct tagGDIOBJHDR
 {
     HANDLE16    hNext;
@@ -75,11 +71,6 @@
     WORD   colorRes;      /* 108: color resolution */    
 } DeviceCaps;
 
-#ifndef WINELIB
-#pragma pack(4)
-#endif
-
-
   /* Device independent DC information */
 typedef struct
 {
@@ -265,15 +256,9 @@
 #define GDI_HEAP_FREE(handle) \
             LOCAL_Free( GDI_HeapSel, (handle) )
 #define GDI_HEAP_LIN_ADDR(handle)  \
-            ((handle) ? PTR_SEG_OFF_TO_LIN(GDI_HeapSel, (handle)) : NULL)
-
-#ifdef WINELIB
-#define GDI_HEAP_SEG_ADDR(handle) ((SEGPTR)GDI_HEAP_LIN_ADDR(handle))
-#else
+         ((handle) ? PTR_SEG_OFF_TO_LIN(GDI_HeapSel, (handle)) : NULL)
 #define GDI_HEAP_SEG_ADDR(handle)  \
-            ((handle) ? MAKELONG((handle), GDI_HeapSel) : 0)
-
-#endif  /* WINELIB */
+         ((handle) ? PTR_SEG_OFF_TO_SEGPTR(GDI_HeapSel, (handle)) : (SEGPTR)0)
 
 extern BOOL32 GDI_Init(void);
 extern HANDLE16 GDI_AllocObject( WORD, WORD );
diff --git a/include/hook.h b/include/hook.h
index eb04e86..3a4284a 100644
--- a/include/hook.h
+++ b/include/hook.h
@@ -11,9 +11,7 @@
 #include "ldt.h"
 #include "callback.h"
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* Hook data (pointed to by a HHOOK) */
 typedef struct
@@ -26,9 +24,7 @@
     WORD       inHookProc;         /* 0c TRUE if in this->proc */
 } HOOKDATA;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 #define HOOK_MAGIC  ((int)'H' | (int)'K' << 8)  /* 'HK' */
 
diff --git a/include/kernel.h b/include/kernel.h
deleted file mode 100644
index f8bf0f5..0000000
--- a/include/kernel.h
+++ /dev/null
@@ -1,4 +0,0 @@
-extern int KERNEL_LockSegment(int segment);
-extern int KERNEL_UnlockSegment(int segment);
-extern KERNEL_InitTask(void);
-extern int KERNEL_WaitEvent(int task);
diff --git a/include/lzexpand.h b/include/lzexpand.h
index 380ee98..b368272 100644
--- a/include/lzexpand.h
+++ b/include/lzexpand.h
@@ -3,26 +3,6 @@
  * Copyright 1996 Marcus Meissner
  */
 
-INT16      LZStart(void);
-HFILE      LZInit(HFILE);
-void       LZDone(void);
-LONG       LZSeek(HFILE,LONG,INT32);
-LONG       LZCopy(HFILE,HFILE);
-void       LZClose(HFILE);
-LONG       CopyLZFile(HFILE,HFILE);
-
-INT16      GetExpandedName16(LPCSTR,LPSTR);
-INT32      GetExpandedName32A(LPCSTR,LPSTR);
-INT32      GetExpandedName32W(LPCWSTR,LPWSTR);
-#define    GetExpandedName WINELIB_NAME_AW(GetExpandedName)
-HFILE      LZOpenFile16(LPCSTR,LPOFSTRUCT,UINT16);
-HFILE      LZOpenFile32A(LPCSTR,LPOFSTRUCT,UINT32);
-HFILE      LZOpenFile32W(LPCWSTR,LPOFSTRUCT,UINT32);
-#define    LZOpenFile WINELIB_NAME_AW(LZOpenFile)
-INT16      LZRead16(HFILE,SEGPTR,UINT16); 
-INT32      LZRead32(HFILE,LPVOID,UINT32); 
-#define    LZRead WINELIB_NAME(LZRead)
-
 #define LZERROR_BADINHANDLE	0xFFFF	/* -1 */
 #define LZERROR_BADOUTHANDLE	0xFFFE	/* -2 */
 #define LZERROR_READ		0xFFFD	/* -3 */
diff --git a/include/message.h b/include/message.h
index 365ee59..ba77b6d 100644
--- a/include/message.h
+++ b/include/message.h
@@ -17,13 +17,13 @@
 				    short code, WORD flags, BOOL sendIdle );
 
 /* timer.c */
-extern void TIMER_RemoveWindowTimers( HWND hwnd );
-extern void TIMER_RemoveQueueTimers( HQUEUE hqueue );
-extern void TIMER_SwitchQueue( HQUEUE hOldQueue, HQUEUE hNewQueue );
+extern void TIMER_RemoveWindowTimers( HWND32 hwnd );
+extern void TIMER_RemoveQueueTimers( HQUEUE16 hqueue );
+extern void TIMER_SwitchQueue( HQUEUE16 hOldQueue, HQUEUE16 hNewQueue );
 extern LONG TIMER_GetNextExpiration(void);
 extern void TIMER_ExpireTimers(void);
-extern BOOL TIMER_GetTimerMsg( MSG16 *msg, HWND hwnd,
-                               HQUEUE hQueue, BOOL remove );
+extern BOOL32 TIMER_GetTimerMsg( MSG16 *msg, HWND32 hwnd,
+                                 HQUEUE16 hQueue, BOOL32 remove );
 
 /* event.c */
 extern BOOL EVENT_WaitXEvent( BOOL sleep );
diff --git a/include/miscemu.h b/include/miscemu.h
index dd05077..90b9184 100644
--- a/include/miscemu.h
+++ b/include/miscemu.h
@@ -7,28 +7,29 @@
 #ifndef __WINE_MISCEMU_H
 #define __WINE_MISCEMU_H
 
+#include <stdio.h>
 #include "wintypes.h"
 #include "registers.h"
 
   /* miscemu/dosmem.c */
-extern BOOL DOSMEM_Init(void);
+extern BOOL32 DOSMEM_Init(void);
 extern void DOSMEM_Tick(void);
 extern void DOSMEM_FillBiosSegment(void);
-extern HANDLE DOSMEM_BiosSeg;
+extern HANDLE16 DOSMEM_BiosSeg;
 
   /* miscemu/instr.c */
-extern BOOL INSTR_EmulateInstruction( SIGCONTEXT *context );
+extern BOOL32 INSTR_EmulateInstruction( SIGCONTEXT *context );
 
   /* miscemu/interrupts.c */
-extern BOOL INT_Init(void);
-extern SEGPTR INT_GetHandler( BYTE intnum );
-extern void INT_SetHandler( BYTE intnum, SEGPTR handler );
+extern BOOL32 INT_Init(void);
+extern FARPROC16 INT_GetHandler( BYTE intnum );
+extern void INT_SetHandler( BYTE intnum, FARPROC16 handler );
 
   /* miscemu/int1a.c */
 extern DWORD INT1A_GetTicksSinceMidnight(void);
 
   /* miscemu/int21.c */
-extern BOOL INT21_Init(void);
+extern BOOL32 INT21_Init(void);
 
   /* miscemu/ioports.c */
 extern DWORD inport( int port, int count );
diff --git a/include/module.h b/include/module.h
index 4eed450..322328a 100644
--- a/include/module.h
+++ b/include/module.h
@@ -10,10 +10,6 @@
 #include "wintypes.h"
 #include "pe_image.h"
 
-#ifndef WINELIB
-#pragma pack(1)
-#endif
-
   /* In-memory module structure. See 'Windows Internals' p. 219 */
 typedef struct
 {
@@ -84,16 +80,19 @@
     FARPROC16 SetOwner;      /* Set Owner procedure, exported by wine */
 } SELFLOADHEADER;
 
-  /* Parameters for LoadModule() */
+#pragma pack(1)
 
+  /* Parameters for LoadModule() */
 typedef struct
 {
-    HANDLE16 hEnvironment;  /* Environment segment */
-    SEGPTR   cmdLine;       /* Command-line */
-    SEGPTR   showCmd;       /* Code for ShowWindow() */
-    SEGPTR   reserved;
+    HANDLE16 hEnvironment;         /* Environment segment */
+    SEGPTR   cmdLine WINE_PACKED;  /* Command-line */
+    SEGPTR   showCmd WINE_PACKED;  /* Code for ShowWindow() */
+    SEGPTR   reserved WINE_PACKED;
 } LOADPARAMS;
 
+#pragma pack(4)
+
 /* Resource types */
 typedef struct resource_typeinfo_s NE_TYPEINFO;
 typedef struct resource_nameinfo_s NE_NAMEINFO;
@@ -111,10 +110,6 @@
     ((struct pe_data *)(((pModule)->flags & NE_FFLAGS_WIN32) ? \
                     ((NE_WIN32_EXTRAINFO *)((pModule) + 1))->pe_module : 0))
 
-#ifndef WINELIB
-#pragma pack(4)
-#endif
-
 /* module.c */
 extern NE_MODULE *MODULE_GetPtr( HMODULE16 hModule );
 extern void MODULE_DumpModule( HMODULE16 hmodule );
@@ -124,7 +119,7 @@
 extern void MODULE_RegisterModule( NE_MODULE *pModule );
 extern HINSTANCE16 MODULE_GetInstance( HMODULE16 hModule );
 extern WORD MODULE_GetOrdinal( HMODULE16 hModule, const char *name );
-extern SEGPTR MODULE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
+extern FARPROC16 MODULE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
 extern BOOL16 MODULE_SetEntryPoint( HMODULE16 hModule, WORD ordinal,
                                     WORD offset );
 extern FARPROC16 MODULE_GetWndProcEntry16( const char *name );
@@ -132,9 +127,9 @@
 /* builtin.c */
 extern BOOL16 BUILTIN_Init(void);
 extern HMODULE16 BUILTIN_LoadModule( LPCSTR name, BOOL16 force );
-extern NE_MODULE *BUILTIN_GetEntryPoint( WORD cs, WORD ip,
-                                         WORD *pOrd, char **ppName );
-extern DWORD BUILTIN_GetProcAddress32( NE_MODULE *pModule, char *function );
+extern LPCSTR BUILTIN_GetEntryPoint16( WORD cs, WORD ip, WORD *pOrd );
+extern LPCSTR BUILTIN_GetEntryPoint32( void *relay );
+extern FARPROC32 BUILTIN_GetProcAddress32(NE_MODULE *pModule, LPCSTR function);
 extern BOOL16 BUILTIN_ParseDLLOptions( const char *str );
 extern void BUILTIN_PrintDLLs(void);
 
diff --git a/include/palette.h b/include/palette.h
index d5145f2..6345d7b 100644
--- a/include/palette.h
+++ b/include/palette.h
@@ -9,9 +9,7 @@
 
 #include "gdi.h"
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* GDI logical palette object */
 typedef struct
@@ -20,10 +18,8 @@
     LOGPALETTE  logpalette WINE_PACKED;
 } PALETTEOBJ;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 extern int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer );
      
-#endif /* __WINE_FONT_H */
+#endif /* __WINE_PALETTE_H */
diff --git a/include/pe_image.h b/include/pe_image.h
index a60c893..c174fa4 100644
--- a/include/pe_image.h
+++ b/include/pe_image.h
@@ -20,6 +20,7 @@
 typedef struct pe_data PE_MODULE;
 
 extern int PE_unloadImage(HMODULE32 hModule);
+extern FARPROC32 PE_FindExportedFunction(struct pe_data *pe, LPCSTR funcName);
 extern void my_wcstombs(char * result, u_short * source, int len);
 
 #endif /* __WINE_PE_IMAGE_H */
diff --git a/include/pen.h b/include/pen.h
index 55858ec..d9c8ff9 100644
--- a/include/pen.h
+++ b/include/pen.h
@@ -9,9 +9,7 @@
 
 #include "gdi.h"
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* GDI logical pen object */
 typedef struct
@@ -20,9 +18,7 @@
     LOGPEN16    logpen WINE_PACKED;
 } PENOBJ;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 extern int PEN_GetObject( PENOBJ * pen, int count, LPSTR buffer );
 extern HPEN16 PEN_SelectObject( DC * dc, HPEN16 hpen, PENOBJ * pen );
diff --git a/include/queue.h b/include/queue.h
index f0e254f..8743eb7 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -9,10 +9,6 @@
 
 #include "windows.h"
 
-#ifndef WINELIB
-#pragma pack(1)
-#endif
-
   /* Message as stored in the queue (contains the extraInfo field) */
 typedef struct tagQMSG
 {
@@ -20,11 +16,12 @@
     MSG16   msg;
 } QMSG;
 
+#pragma pack(1)
 
 typedef struct tagMESSAGEQUEUE
 {
-  HQUEUE    next;                   /* 00 Next queue */
-  HTASK     hTask;                  /* 02 hTask owning the queue */
+  HQUEUE16  next;                   /* 00 Next queue */
+  HTASK16   hTask;                  /* 02 hTask owning the queue */
   WORD      msgSize;                /* 04 Size of messages in the queue */
   WORD      msgCount;               /* 06 Number of waiting messages */
   WORD      nextMessage;            /* 08 Next message to be retrieved */
@@ -32,22 +29,22 @@
   WORD      queueSize;              /* 0c Size of the queue */
   DWORD     GetMessageTimeVal WINE_PACKED;  /* 0e Value for GetMessageTime */
   DWORD     GetMessagePosVal WINE_PACKED;   /* 12 Value for GetMessagePos */
-  HQUEUE    self;                   /* 16 Handle to self (was: reserved) */
+  HQUEUE16  self;                   /* 16 Handle to self (was: reserved) */
   DWORD     GetMessageExtraInfoVal; /* 18 Value for GetMessageExtraInfo */
   WORD      reserved2;              /* 1c Unknown */
   LPARAM    lParam WINE_PACKED;     /* 1e Next 4 values set by SendMessage */
-  WPARAM    wParam;                 /* 22 */
-  UINT      msg;                    /* 24 */
-  HWND      hWnd;                   /* 26 */
+  WPARAM16  wParam;                 /* 22 */
+  UINT16    msg;                    /* 24 */
+  HWND16    hWnd;                   /* 26 */
   DWORD     SendMessageReturn;      /* 28 Return value for SendMessage */
   WORD      wPostQMsg;              /* 2c PostQuitMessage flag */
   WORD      wExitCode;              /* 2e PostQuitMessage exit code */
   WORD      flags;                  /* 30 Queue flags */
   WORD      reserved3[2];           /* 32 Unknown */
   WORD      wWinVersion;            /* 36 Expected Windows version */
-  HQUEUE    InSendMessageHandle;    /* 38 Queue of task that sent a message */
-  HTASK     hSendingTask;           /* 3a Handle of task that sent a message */
-  HTASK     hPrevSendingTask;       /* 3c Handle of previous sender */
+  HQUEUE16  InSendMessageHandle;    /* 38 Queue of task that sent a message */
+  HTASK16   hSendingTask;           /* 3a Handle of task that sent a message */
+  HTASK16   hPrevSendingTask;       /* 3c Handle of previous sender */
   WORD      wPaintCount;            /* 3e Number of WM_PAINT needed */
   WORD      wTimerCount;            /* 40 Number of timers for this task */
   WORD      changeBits;             /* 42 Changed wake-up bits */
@@ -60,9 +57,7 @@
   QMSG      messages[1];            /* 6e Queue messages */
 } MESSAGEQUEUE;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 /* Extra (undocumented) queue wake bits; not sure about the values */
 #define QS_SMRESULT      0x0100  /* Queue has a SendMessage() result */
@@ -71,22 +66,22 @@
 /* Queue flags */
 #define QUEUE_FLAG_REPLIED  0x0001  /* Replied to a SendMessage() */
 
-extern void QUEUE_DumpQueue( HQUEUE hQueue );
+extern void QUEUE_DumpQueue( HQUEUE16 hQueue );
 extern void QUEUE_WalkQueues(void);
 extern MESSAGEQUEUE *QUEUE_GetSysQueue(void);
 extern void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit );
 extern void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit );
 extern void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue );
 extern void QUEUE_WaitBits( WORD bits );
-extern void QUEUE_IncPaintCount( HQUEUE hQueue );
-extern void QUEUE_DecPaintCount( HQUEUE hQueue );
-extern void QUEUE_IncTimerCount( HQUEUE hQueue );
-extern void QUEUE_DecTimerCount( HQUEUE hQueue );
-extern BOOL QUEUE_CreateSysMsgQueue( int size );
-extern BOOL QUEUE_DeleteMsgQueue( HQUEUE hQueue );
-extern HTASK QUEUE_GetQueueTask( HQUEUE hQueue );
-extern BOOL QUEUE_AddMsg( HQUEUE hQueue, MSG16 * msg, DWORD extraInfo );
-extern int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND hwnd,
+extern void QUEUE_IncPaintCount( HQUEUE16 hQueue );
+extern void QUEUE_DecPaintCount( HQUEUE16 hQueue );
+extern void QUEUE_IncTimerCount( HQUEUE16 hQueue );
+extern void QUEUE_DecTimerCount( HQUEUE16 hQueue );
+extern BOOL32 QUEUE_CreateSysMsgQueue( int size );
+extern BOOL32 QUEUE_DeleteMsgQueue( HQUEUE16 hQueue );
+extern HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue );
+extern BOOL32 QUEUE_AddMsg( HQUEUE16 hQueue, MSG16 * msg, DWORD extraInfo );
+extern int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND32 hwnd,
                           int first, int last );
 extern void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, int pos );
 extern void hardware_event( WORD message, WORD wParam, LONG lParam,
diff --git a/include/registers.h b/include/registers.h
index 1f919a5..bfff59a 100644
--- a/include/registers.h
+++ b/include/registers.h
@@ -7,8 +7,70 @@
 #ifndef __WINE_REGISTERS_H
 #define __WINE_REGISTERS_H
 
-#include <windows.h>
-#include "wine.h"
+#include "wintypes.h"
+
+#ifndef WINELIB
+
+#ifdef i386
+extern int runtime_cpu (void);
+#else
+static inline int runtime_cpu(void) { return 3; }
+#endif
+
+#ifdef linux
+typedef struct
+{
+    unsigned short sc_gs, __gsh;
+    unsigned short sc_fs, __fsh;
+    unsigned short sc_es, __esh;
+    unsigned short sc_ds, __dsh;
+    unsigned long sc_edi;
+    unsigned long sc_esi;
+    unsigned long sc_ebp;
+    unsigned long sc_esp;
+    unsigned long sc_ebx;
+    unsigned long sc_edx;
+    unsigned long sc_ecx;
+    unsigned long sc_eax;
+    unsigned long sc_trapno;
+    unsigned long sc_err;
+    unsigned long sc_eip;
+    unsigned short sc_cs, __csh;
+    unsigned long sc_eflags;
+    unsigned long esp_at_signal;
+    unsigned short sc_ss, __ssh;
+    unsigned long i387;
+    unsigned long oldmask;
+    unsigned long cr2;
+} SIGCONTEXT;
+#define WINE_DATA_SELECTOR 0x2b
+#define WINE_CODE_SELECTOR 0x23
+#endif  /* linux */
+
+#ifdef __NetBSD__
+#include <signal.h>
+typedef struct sigcontext SIGCONTEXT;
+#define WINE_DATA_SELECTOR 0x1f
+#define WINE_CODE_SELECTOR 0x17
+#endif  /* NetBSD */
+
+#if defined(__svr4__) || defined(_SCO_DS)
+#include <signal.h>
+#ifdef _SCO_DS
+#include <sys/regset.h>
+#endif
+#include <sys/ucontext.h>
+typedef struct ucontext SIGCONTEXT;
+#define WINE_DATA_SELECTOR 0x1f
+#define WINE_CODE_SELECTOR 0x17
+#endif  /* svr4 || SCO_DS */
+
+#ifdef __FreeBSD__
+#include <signal.h>
+typedef struct sigcontext SIGCONTEXT;
+#define WINE_DATA_SELECTOR 0x27
+#define WINE_CODE_SELECTOR 0x1f
+#endif  /* FreeBSD */
 
 #if !defined(__svr4__) && !defined(_SCO_DS)
 
@@ -125,4 +187,12 @@
 #define SET_CFLAG(context)   (EFL_reg(context) |= 0x0001)
 #define RESET_CFLAG(context) (EFL_reg(context) &= 0xfffffffe)
 
+#else  /* ifndef WINELIB */
+
+typedef void SIGCONTEXT;
+#define WINE_DATA_SELECTOR 0x00
+#define WINE_CODE_SELECTOR 0x00
+
+#endif  /* ifndef WINELIB */
+
 #endif /* __WINE_REGISTERS_H */
diff --git a/include/stackframe.h b/include/stackframe.h
index e52eb14..77bb0e0 100644
--- a/include/stackframe.h
+++ b/include/stackframe.h
@@ -4,15 +4,13 @@
  * Copyright 1995 Alexandre Julliard
  */
 
-#ifndef WINE_STACKFRAME_H
-#define WINE_STACKFRAME_H
+#ifndef __WINE_STACKFRAME_H
+#define __WINE_STACKFRAME_H
 
 #include <windows.h>
 #include "ldt.h"
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* 16-bit stack layout after CallFrom16() */
 typedef struct
@@ -45,9 +43,7 @@
     DWORD   args[1];        /* arguments to 16-bit function */
 } STACK32FRAME;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
   /* Saved 16-bit stack for current process (Win16 only) */
 extern WORD IF1632_Saved16_ss;
@@ -80,4 +76,4 @@
 #define MAKE_SEGPTR(ptr)   ((SEGPTR)ptr)
 #endif
 
-#endif /* WINE_STACKFRAME_H */
+#endif /* __WINE_STACKFRAME_H */
diff --git a/include/stddebug.h b/include/stddebug.h
index eb1e0ec..fc531a9 100644
--- a/include/stddebug.h
+++ b/include/stddebug.h
@@ -96,7 +96,6 @@
 #undef DEBUG_DOSFS
 #undef DEBUG_DRIVER
 #undef DEBUG_EDIT
-#undef DEBUG_ENUM
 #undef DEBUG_ENV
 #undef DEBUG_EVENT
 #undef DEBUG_EXEC
@@ -174,7 +173,6 @@
 #define DEBUG_DOSFS
 #define DEBUG_DRIVER
 #define DEBUG_EDIT
-#define DEBUG_ENUM
 #define DEBUG_ENV
 #define DEBUG_EVENT
 #define DEBUG_EXEC
diff --git a/include/struct32.h b/include/struct32.h
index 0fe7769..0e43982 100644
--- a/include/struct32.h
+++ b/include/struct32.h
@@ -1,12 +1,8 @@
 /* Structure definitions for Win32 -- used only internally */
-#ifndef _STRUCT32_H
-#define _STRUCT32_H
+#ifndef __WINE__STRUCT32_H
+#define __WINE__STRUCT32_H
 #include "handle32.h"
 
-#ifndef WINELIB
-#pragma pack(1)
-#endif
-
 void STRUCT32_RECT32to16(const RECT32*,RECT16*);
 void STRUCT32_RECT16to32(const RECT16*,RECT32*);
 void STRUCT32_POINT32to16(const POINT32*,POINT16*);
@@ -24,23 +20,14 @@
                                            NCCALCSIZE_PARAMS32* to,
                                            int validRects );
 
-
-typedef struct {
-	DWORD style;
-	DWORD dwExtendedStyle;
-	WORD noOfItems WINE_PACKED;
-	short x WINE_PACKED;
-	short y WINE_PACKED;
-	WORD cx WINE_PACKED;
-	WORD cy WINE_PACKED;
-} DLGTEMPLATE32;
-
 void STRUCT32_MSG16to32(const MSG16 *msg16,MSG32 *msg32);
 void STRUCT32_MSG32to16(const MSG32 *msg32,MSG16 *msg16);
 
 void STRUCT32_CREATESTRUCT32Ato16(const CREATESTRUCT32A*,CREATESTRUCT16*);
 void STRUCT32_CREATESTRUCT16to32A(const CREATESTRUCT16*,CREATESTRUCT32A*);
 
+#pragma pack(1)
+
 typedef struct {
 	BYTE   bWidth;
 	BYTE   bHeight;
@@ -77,9 +64,6 @@
 } CURSORICONDIR32;
 
 
-
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
-#endif
+#endif  /* __WINE_STRUCT32_H */
diff --git a/include/task.h b/include/task.h
index f9a8b9c..307dd8e 100644
--- a/include/task.h
+++ b/include/task.h
@@ -9,31 +9,29 @@
 
 #include "wintypes.h"
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* Process database (i.e. a normal DOS PSP) */
 
 typedef struct
 {
-    WORD   int20;                   /* 00 int 20h instruction */
-    WORD   nextParagraph;           /* 02 Segment of next paragraph */
-    BYTE   reserved1;
-    BYTE   dispatcher[5];           /* 05 Long call to DOS */
-    SEGPTR savedint22 WINE_PACKED;  /* 0a Saved int 22h handler */
-    SEGPTR savedint23 WINE_PACKED;  /* 0e Saved int 23h handler */
-    SEGPTR savedint24 WINE_PACKED;  /* 12 Saved int 24h handler */
-    WORD   parentPSP;               /* 16 Selector of parent PSP */
-    BYTE   fileHandles[20];         /* 18 Open file handles */
-    HANDLE environment;             /* 2c Selector of environment */
-    WORD   reserved2[2];
-    WORD   nbFiles;                 /* 32 Number of file handles */
-    SEGPTR fileHandlesPtr;          /* 34 Pointer to file handle table */
-    WORD   reserved3[18];
-    BYTE   fcb1[16];                /* 5c First FCB */
-    BYTE   fcb2[20];                /* 6c Second FCB */
-    BYTE   cmdLine[128];            /* 80 Command-line (first byte is len) */
+    WORD      int20;                   /* 00 int 20h instruction */
+    WORD      nextParagraph;           /* 02 Segment of next paragraph */
+    BYTE      reserved1;
+    BYTE      dispatcher[5];           /* 05 Long call to DOS */
+    FARPROC16 savedint22 WINE_PACKED;  /* 0a Saved int 22h handler */
+    FARPROC16 savedint23 WINE_PACKED;  /* 0e Saved int 23h handler */
+    FARPROC16 savedint24 WINE_PACKED;  /* 12 Saved int 24h handler */
+    WORD      parentPSP;               /* 16 Selector of parent PSP */
+    BYTE      fileHandles[20];         /* 18 Open file handles */
+    HANDLE16  environment;             /* 2c Selector of environment */
+    WORD      reserved2[2];
+    WORD      nbFiles;                 /* 32 Number of file handles */
+    SEGPTR    fileHandlesPtr;          /* 34 Pointer to file handle table */
+    WORD      reserved3[18];
+    BYTE      fcb1[16];                /* 5c First FCB */
+    BYTE      fcb2[20];                /* 6c Second FCB */
+    BYTE      cmdLine[128];            /* 80 Command-line (first byte is len)*/
 } PDB;
 
 
@@ -107,9 +105,7 @@
 #define TDBF_OS2APP     0x0008
 #define TDBF_WIN32S     0x0010
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 extern BOOL TASK_Init(void);
 extern HTASK TASK_CreateTask( HMODULE hModule, HANDLE hInstance,
diff --git a/include/user.h b/include/user.h
index e4eead7..f22fa1a 100644
--- a/include/user.h
+++ b/include/user.h
@@ -19,13 +19,8 @@
 #define USER_HEAP_FREE(handle) \
             LOCAL_Free( USER_HeapSel, (handle) )
 #define USER_HEAP_LIN_ADDR(handle)  \
-            ((handle) ? PTR_SEG_OFF_TO_LIN(USER_HeapSel, (handle)) : NULL)
-
-#ifdef WINELIB
-#define USER_HEAP_SEG_ADDR(handle)  ((SEGPTR)(USER_HEAP_LIN_ADDR(handle)))
-#else
+         ((handle) ? PTR_SEG_OFF_TO_LIN(USER_HeapSel, (handle)) : NULL)
 #define USER_HEAP_SEG_ADDR(handle)  \
-            ((handle) ? MAKELONG((handle), USER_HeapSel) : 0)
-#endif  /* WINELIB */
+         ((handle) ? PTR_SEG_OFF_TO_SEGPTR(USER_HeapSel, (handle)) : (SEGPTR)0)
 
 #endif  /* USER_H */
diff --git a/include/ver.h b/include/ver.h
index 8672d86..d626967 100644
--- a/include/ver.h
+++ b/include/ver.h
@@ -136,59 +136,6 @@
 		DWORD off,DWORD reslen,LPVOID data
 );
 
-DWORD GetFileVersionInfoSize16(LPCSTR filename,LPDWORD handle);
-DWORD GetFileVersionInfoSize32A(LPCSTR filename,LPDWORD handle);
-DWORD GetFileVersionInfoSize32W(LPCWSTR filename,LPDWORD handle);
-#define GetFileVersionInfoSize WINELIB_NAME_AW(GetFileVersionInfoSize)
-
-DWORD GetFileVersionInfo16(LPCSTR filename,DWORD handle,DWORD datasize,LPVOID data);
-DWORD GetFileVersionInfo32A(LPCSTR filename,DWORD handle,DWORD datasize,LPVOID data);
-DWORD GetFileVersionInfo32W(LPCWSTR filename,DWORD handle,DWORD datasize,LPVOID data);
-#define GetFileVersionInfo WINELIB_NAME_AW(GetFileVersionInfo)
-
-DWORD
-VerFindFile16(
-	UINT16 flags,LPCSTR filename,LPCSTR windir,LPCSTR appdir,
-	LPSTR curdir,UINT16 *curdirlen,LPSTR destdir,UINT16 *destdirlen
-);
-DWORD
-VerFindFile32A(
-	UINT32 flags,LPCSTR filename,LPCSTR windir,LPCSTR appdir,
-	LPSTR curdir,UINT32 *curdirlen,LPSTR destdir,UINT32 *destdirlen
-);
-DWORD
-VerFindFile32W(
-	UINT32 flags,LPCWSTR filename,LPCWSTR windir,LPCWSTR appdir,
-	LPWSTR curdir,UINT32 *curdirlen,LPWSTR destdir,UINT32 *destdirlen
-);
-#define VerFindFile WINELIB_NAME_AW(VerFindFile)
-
-DWORD
-VerInstallFile16(
-	UINT16 flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
-	LPCSTR destdir,LPSTR tmpfile,UINT16 *tmpfilelen
-);
-DWORD
-VerInstallFile32A(
-	UINT32 flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
-	LPCSTR destdir,LPSTR tmpfile,UINT32 *tmpfilelen
-);
-DWORD
-VerInstallFile32W(
-	UINT32 flags,LPCWSTR srcfilename,LPCWSTR destfilename,LPCWSTR srcdir,
-	LPCWSTR destdir,LPWSTR tmpfile,UINT32 *tmpfilelen
-);
-#define VerInstallFile WINELIB_NAME_AW(VerInstallFile)
-
-DWORD VerLanguageName16(UINT16 lang,LPSTR langname,UINT16 langnamelen);
-DWORD VerLanguageName32A(UINT32 lang,LPSTR langname,UINT32 langnamelen);
-DWORD VerLanguageName32W(UINT32 lang,LPWSTR langname,UINT32 langnamelen);
-#define VerLanguageName WINELIB_NAME_AW(VerLanguageName)
-
-DWORD VerQueryValue16(SEGPTR block,LPCSTR subblock,SEGPTR *buffer,UINT16 *buflen);
-DWORD VerQueryValue32A(LPVOID block,LPCSTR subblock,LPVOID *buffer,UINT32 *buflen);
-DWORD VerQueryValue32W(LPVOID block,LPCWSTR subblock,LPVOID *buffer,UINT32 *buflen);
-#define VerQueryValue WINELIB_NAME_AW(VerQueryValue)
 
 /* 20 GETFILEVERSIONINFORAW */
 
diff --git a/include/win.h b/include/win.h
index 7a36cec..37938c1 100644
--- a/include/win.h
+++ b/include/win.h
@@ -45,14 +45,14 @@
     POINT16        ptIconPos;     /* Icon position */
     POINT16        ptMaxPos;      /* Maximized window position */
     LPSTR          text;          /* Window text */
+    void          *pVScroll;      /* Vertical scroll-bar info */
+    void          *pHScroll;      /* Horizontal scroll-bar info */
     HGLOBAL        hmemTaskQ;     /* Task queue global memory handle */
     HRGN           hrgnUpdate;    /* Update region */
     HWND           hwndLastActive;/* Last active popup hwnd */
     DWORD          dwStyle;       /* Window style (from CreateWindow) */
     DWORD          dwExStyle;     /* Extended style (from CreateWindowEx) */
     HANDLE         hdce;          /* Window DCE (if CS_OWNDC or CS_CLASSDC) */
-    HANDLE         hVScroll;      /* Vertical scroll-bar info */
-    HANDLE         hHScroll;      /* Horizontal scroll-bar info */
     UINT           wIDmenu;       /* ID or hmenu (from CreateWindow) */
     WORD           flags;         /* Misc. flags (see below) */
     Window         window;        /* X window (only for top-level windows) */
diff --git a/include/windows.h b/include/windows.h
index 16e6f80..72fea65 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -1449,15 +1449,15 @@
 typedef KANJISTRUCT *NPKANJISTRUCT;
 typedef KANJISTRUCT *PKANJISTRUCT;
 
+#define OFS_MAXPATHNAME 128
 typedef struct
 {
     BYTE cBytes;
     BYTE fFixedDisk;
     WORD nErrCode;
     BYTE reserved[4];
-    BYTE szPathName[128];
-} OFSTRUCT;
-typedef OFSTRUCT *LPOFSTRUCT;
+    BYTE szPathName[OFS_MAXPATHNAME];
+} OFSTRUCT, *LPOFSTRUCT;
 
 #define OF_READ               0x0000
 #define OF_WRITE              0x0001
@@ -2247,6 +2247,43 @@
 #define DT_NOPREFIX 2048
 #define DT_INTERNAL 4096
 
+/* DrawEdge() flags */
+#define BDR_RAISEDOUTER    0x0001
+#define BDR_SUNKENOUTER    0x0002
+#define BDR_RAISEDINNER    0x0004
+#define BDR_SUNKENINNER    0x0008
+
+#define BDR_OUTER          0x0003
+#define BDR_INNER          0x000c
+#define BDR_RAISED         0x0005
+#define BDR_SUNKEN         0x000a
+
+#define EDGE_RAISED        (BDR_RAISEDOUTER | BDR_RAISEDINNER)
+#define EDGE_SUNKEN        (BDR_SUNKENOUTER | BDR_SUNKENINNER)
+#define EDGE_ETCHED        (BDR_SUNKENOUTER | BDR_RAISEDINNER)
+#define EDGE_BUMP          (BDR_RAISEDOUTER | BDR_SUNKENINNER)
+
+/* border flags */
+#define BF_LEFT            0x0001
+#define BF_TOP             0x0002
+#define BF_RIGHT           0x0004
+#define BF_BOTTOM          0x0008
+#define BF_DIAGONAL        0x0010
+#define BF_MIDDLE          0x0800  /* Fill in the middle */
+#define BF_SOFT            0x1000  /* For softer buttons */
+#define BF_ADJUST          0x2000  /* Calculate the space left over */
+#define BF_FLAT            0x4000  /* For flat rather than 3D borders */
+#define BF_MONO            0x8000  /* For monochrome borders */
+#define BF_TOPLEFT         (BF_TOP | BF_LEFT)
+#define BF_TOPRIGHT        (BF_TOP | BF_RIGHT)
+#define BF_BOTTOMLEFT      (BF_BOTTOM | BF_LEFT)
+#define BF_BOTTOMRIGHT     (BF_BOTTOM | BF_RIGHT)
+#define BF_RECT            (BF_LEFT | BF_TOP | BF_RIGHT | BF_BOTTOM)
+#define BF_DIAGONAL_ENDTOPRIGHT     (BF_DIAGONAL | BF_TOP | BF_RIGHT)
+#define BF_DIAGONAL_ENDTOPLEFT      (BF_DIAGONAL | BF_TOP | BF_LEFT)
+#define BF_DIAGONAL_ENDBOTTOMLEFT   (BF_DIAGONAL | BF_BOTTOM | BF_LEFT)
+#define BF_DIAGONAL_ENDBOTTOMRIGHT  (BF_DIAGONAL | BF_BOTTOM | BF_RIGHT)
+
 /* Window Styles */
 #define WS_OVERLAPPED    0x00000000L
 #define WS_POPUP         0x80000000L
@@ -3153,6 +3190,8 @@
 WORD       FreeSelector(WORD);
 DWORD      GetBitmapDimension(HBITMAP16);
 HTASK16    GetCurrentTask(void);
+HINSTANCE16 GetTaskDS(void);
+HQUEUE16   GetTaskQueue(HTASK16);
 BOOL16     LocalInit(HANDLE16,WORD,WORD);
 DWORD      OffsetViewportOrg(HDC16,INT16,INT16);
 DWORD      OffsetWindowOrg(HDC16,INT16,INT16);
@@ -3183,6 +3222,7 @@
 DWORD      HeapSize(HANDLE32,DWORD,LPVOID);
 BOOL32     HeapUnlock(HANDLE32);
 BOOL32     HeapValidate(HANDLE32,DWORD,LPVOID);
+BOOL32     IsWindowUnicode(HWND32);
 VOID       RtlFillMemory(LPVOID,UINT32,UINT32);
 VOID       RtlMoveMemory(LPVOID,LPCVOID,UINT32);
 VOID       RtlZeroMemory(LPVOID,UINT32);
@@ -3191,31 +3231,55 @@
 
 /* Declarations for functions that are the same in Win16 and Win32 */
 
+BOOL16     CheckDlgButton(HWND32,INT32,UINT32);
+BOOL16     CheckRadioButton(HWND32,UINT32,UINT32,UINT32);
 INT16      CombineRgn(HRGN32,HRGN32,HRGN32,INT32);
+LONG       CopyLZFile(HFILE,HFILE);
 HBITMAP16  CreateBitmap(INT32,INT32,UINT32,UINT32,LPCVOID);
+BOOL16     CreateCaret(HWND32,HBITMAP32,INT32,INT32);
 HBITMAP16  CreateCompatibleBitmap(HDC32,INT32,INT32);
 HBITMAP16  CreateDiscardableBitmap(HDC32,INT32,INT32);
 HRGN16     CreateEllipticRgn(INT32,INT32,INT32,INT32);
 HRGN16     CreateRectRgn(INT32,INT32,INT32,INT32);
 HRGN16     CreateRoundRectRgn(INT32,INT32,INT32,INT32,INT32,INT32);
+BOOL16     DestroyCaret(void);
 BOOL16     EndDialog(HWND32,INT32);
 BOOL16     EqualRgn(HRGN32,HRGN32);
 INT16      ExcludeUpdateRgn(HDC32,HWND32);
+BOOL16     ExtFloodFill(HDC32,INT32,INT32,COLORREF,UINT32);
+BOOL16     FloodFill(HDC32,INT32,INT32,COLORREF);
 DWORD      GetAppCompatFlags(HTASK32);
 LONG       GetBitmapBits(HBITMAP32,LONG,LPVOID);
 WORD       GetClassWord(HWND32,INT32);
+INT16      GetDlgCtrlID(HWND32);
+DWORD      GetTickCount(void);
 INT16      GetUpdateRgn(HWND32,HRGN32,BOOL32);
 WORD       GetWindowWord(HWND32,INT32);
+BOOL16     HideCaret(HWND32);
+BOOL16     IsWindow(HWND32);
+void       LZClose(HFILE);
+LONG       LZCopy(HFILE,HFILE);
+void       LZDone(void);
+HFILE      LZInit(HFILE);
+LONG       LZSeek(HFILE,LONG,INT32);
+INT16      LZStart(void);
 INT16      OffsetRgn(HRGN32,INT32,INT32);
+HFILE      OpenFile(LPCSTR,OFSTRUCT*,UINT32);
 BOOL16     PtInRegion(HRGN32,INT32,INT32);
 DWORD      RegCloseKey(HKEY);
 DWORD      RegFlushKey(HKEY);
 LONG       SetBitmapBits(HBITMAP32,LONG,LPCVOID);
+BOOL16     SetCaretBlinkTime(UINT32);
+BOOL16     SetCaretPos(INT32,INT32);
 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       SetRectRgn(HRGN32,INT32,INT32,INT32,INT32);
 WORD       SetWindowWord(HWND32,INT32,WORD);
+BOOL16     ShowCaret(HWND32);
+HFILE      _lclose(HFILE);
+HFILE      _lcreat(LPCSTR,INT32);
+HFILE      _lopen(LPCSTR,INT32);
 
 /* Declarations for functions that change between Win16 and Win32 */
 
@@ -3240,6 +3304,36 @@
 BOOL32     ChangeMenu32A(HMENU32,UINT32,LPCSTR,UINT32,UINT32);
 BOOL32     ChangeMenu32W(HMENU32,UINT32,LPCWSTR,UINT32,UINT32);
 #define    ChangeMenu WINELIB_NAME_AW(ChangeMenu)
+LPSTR      CharLower32A(LPSTR);
+LPWSTR     CharLower32W(LPWSTR);
+#define    CharLower WINELIB_NAME_AW(CharLower)
+DWORD      CharLowerBuff32A(LPSTR,DWORD);
+DWORD      CharLowerBuff32W(LPWSTR,DWORD);
+#define    CharLowerBuff WINELIB_NAME_AW(CharLowerBuff)
+LPSTR      CharNext32A(LPCSTR);
+LPWSTR     CharNext32W(LPCWSTR);
+#define    CharNext WINELIB_NAME_AW(CharNext)
+LPSTR      CharNextEx32A(WORD,LPCSTR,DWORD);
+LPWSTR     CharNextEx32W(WORD,LPCWSTR,DWORD);
+#define    CharNextEx WINELIB_NAME_AW(CharNextEx)
+LPSTR      CharPrev32A(LPCSTR,LPCSTR);
+LPWSTR     CharPrev32W(LPCWSTR,LPCWSTR);
+#define    CharPrev WINELIB_NAME_AW(CharPrev)
+LPSTR      CharPrevEx32A(WORD,LPCSTR,LPCSTR,DWORD);
+LPWSTR     CharPrevEx32W(WORD,LPCWSTR,LPCWSTR,DWORD);
+#define    CharPrevEx WINELIB_NAME_AW(CharPrevEx)
+LPSTR      CharUpper32A(LPSTR);
+LPWSTR     CharUpper32W(LPWSTR);
+#define    CharUpper WINELIB_NAME_AW(CharUpper)
+DWORD      CharUpperBuff32A(LPSTR,DWORD);
+DWORD      CharUpperBuff32W(LPWSTR,DWORD);
+#define    CharUpperBuff WINELIB_NAME_AW(CharUpperBuff)
+BOOL32     CharToOem32A(LPSTR,LPSTR);
+BOOL32     CharToOem32W(LPCWSTR,LPSTR);
+#define    CharToOem WINELIB_NAME_AW(CharToOem)
+BOOL32     CharToOemBuff32A(LPSTR,LPSTR,DWORD);
+BOOL32     CharToOemBuff32W(LPCWSTR,LPSTR,DWORD);
+#define    CharToOemBuff WINELIB_NAME_AW(CharToOemBuff)
 HWND16     ChildWindowFromPoint16(HWND16,POINT16);
 HWND32     ChildWindowFromPoint32(HWND32,POINT32);
 #define    ChildWindowFromPoint WINELIB_NAME(ChildWindowFromPoint)
@@ -3249,6 +3343,16 @@
 BOOL16     ClipCursor16(const RECT16*);
 BOOL32     ClipCursor32(const RECT32*);
 #define    ClipCursor WINELIB_NAME(ClipCursor)
+UINT16     CompareString16(DWORD,DWORD,LPCSTR,DWORD,LPCSTR,DWORD);
+UINT32     CompareString32A(DWORD,DWORD,LPCSTR,DWORD,LPCSTR,DWORD);
+UINT32     CompareString32W(DWORD,DWORD,LPCWSTR,DWORD,LPCWSTR,DWORD);
+#define    CompareString WINELIB_NAME_AW(CompareString)
+HCURSOR16  CopyCursor16(HINSTANCE16,HCURSOR16);
+#define    CopyCursor32(cur) ((HCURSOR32)CopyIcon32((HICON32)(cur)))
+#define    CopyCursor WINELIB_NAME(CopyCursor)
+HICON16    CopyIcon16(HINSTANCE16,HICON16);
+HICON32    CopyIcon32(HICON32);
+#define    CopyIcon WINELIB_NAME(CopyIcon)
 BOOL16     CopyRect16(RECT16*,const RECT16*);
 BOOL32     CopyRect32(RECT32*,const RECT32*);
 #define    CopyRect WINELIB_NAME(CopyRect)
@@ -3282,6 +3386,10 @@
 HRGN16     CreateEllipticRgnIndirect16(const RECT16 *);
 HRGN32     CreateEllipticRgnIndirect32(const RECT32 *);
 #define    CreateEllipticRgnIndirect WINELIB_NAME(CreateEllipticRgnIndirect)
+HFONT16    CreateFontIndirect16(const LOGFONT16*);
+HFONT32    CreateFontIndirect32A(const LOGFONT32A*);
+HFONT32    CreateFontIndirect32W(const LOGFONT32W*);
+#define    CreateFontIndirect WINELIB_NAME_AW(CreateFontIndirect)
 HRGN16     CreatePolyPolygonRgn16(const POINT16*,const INT16*,INT16,INT16);
 HRGN32     CreatePolyPolygonRgn32(const POINT32*,const INT32*,INT32,INT32);
 #define    CreatePolyPolygonRgn WINELIB_NAME(CreatePolyPolygonRgn)
@@ -3352,9 +3460,15 @@
 BOOL16     DPtoLP16(HDC16,LPPOINT16,INT16);
 BOOL32     DPtoLP32(HDC32,LPPOINT32,INT32);
 #define    DPtoLP WINELIB_NAME(DPtoLP)
+BOOL16     DrawEdge16(HDC16,LPRECT16,UINT16,UINT16);
+BOOL32     DrawEdge32(HDC32,LPRECT32,UINT32,UINT32);
+#define    DrawEdge WINELIB_NAME(DrawEdge)
 void       DrawFocusRect16(HDC16,const RECT16*);
 void       DrawFocusRect32(HDC32,const RECT32*);
 #define    DrawFocusRect WINELIB_NAME(DrawFocusRect)
+BOOL16     DrawFrameControl16(HDC16,LPRECT16,UINT16,UINT16);
+BOOL32     DrawFrameControl32(HDC32,LPRECT32,UINT32,UINT32);
+#define    DrawFrameControl WINELIB_NAME(DrawFrameControl)
 INT16      DrawText16(HDC16,LPCSTR,INT16,LPRECT16,UINT16);
 INT32      DrawText32A(HDC32,LPCSTR,INT32,LPRECT32,UINT32);
 INT32      DrawText32W(HDC32,LPCWSTR,INT32,LPRECT32,UINT32);
@@ -3397,7 +3511,7 @@
 #define    FreeModule32(handle) FreeLibrary32(handle)
 #define    FreeModule WINELIB_NAME(FreeModule)
 void       FreeProcInstance16(FARPROC16);
-#define    FreeProcInstance32(proc) (proc)
+#define    FreeProcInstance32(proc) /*nothing*/
 #define    FreeProcInstance WINELIB_NAME(FreeProcInstance)
 BOOL16     GetBitmapDimensionEx16(HBITMAP16,LPSIZE16);
 BOOL32     GetBitmapDimensionEx32(HBITMAP32,LPSIZE32);
@@ -3405,8 +3519,11 @@
 BOOL16     GetBrushOrgEx16(HDC16,LPPOINT16);
 BOOL32     GetBrushOrgEx32(HDC32,LPPOINT32);
 #define    GetBrushOrgEx WINELIB_NAME(GetBrushOrgEx)
-void       GetCaretPos16(LPPOINT16);
-void       GetCaretPos32(LPPOINT32);
+UINT16     GetCaretBlinkTime16(void);
+UINT32     GetCaretBlinkTime32(void);
+#define    GetCaretBlinkTime WINELIB_NAME(GetCaretBlinkTime)
+VOID       GetCaretPos16(LPPOINT16);
+BOOL32     GetCaretPos32(LPPOINT32);
 #define    GetCaretPos WINELIB_NAME(GetCaretPos)
 BOOL16     GetClassInfo16(HINSTANCE16,SEGPTR,WNDCLASS16 *);
 BOOL32     GetClassInfo32A(HINSTANCE32,LPCSTR,WNDCLASS32A *);
@@ -3455,6 +3572,18 @@
 UINT32     GetDriveType32A(LPCSTR);
 UINT32     GetDriveType32W(LPCWSTR);
 #define    GetDriveType WINELIB_NAME_AW(GetDriveType)
+INT16      GetExpandedName16(LPCSTR,LPSTR);
+INT32      GetExpandedName32A(LPCSTR,LPSTR);
+INT32      GetExpandedName32W(LPCWSTR,LPWSTR);
+#define    GetExpandedName WINELIB_NAME_AW(GetExpandedName)
+DWORD      GetFileVersionInfoSize16(LPCSTR,LPDWORD);
+DWORD      GetFileVersionInfoSize32A(LPCSTR,LPDWORD);
+DWORD      GetFileVersionInfoSize32W(LPCWSTR,LPDWORD);
+#define    GetFileVersionInfoSize WINELIB_NAME_AW(GetFileVersionInfoSize)
+DWORD      GetFileVersionInfo16(LPCSTR,DWORD,DWORD,LPVOID);
+DWORD      GetFileVersionInfo32A(LPCSTR,DWORD,DWORD,LPVOID);
+DWORD      GetFileVersionInfo32W(LPCWSTR,DWORD,DWORD,LPVOID);
+#define    GetFileVersionInfo WINELIB_NAME_AW(GetFileVersionInfo)
 UINT16     GetInternalWindowPos16(HWND16,LPRECT16,LPPOINT16);
 UINT32     GetInternalWindowPos32(HWND32,LPRECT32,LPPOINT32);
 #define    GetInternalWindowPos WINELIB_NAME(GetInternalWindowPos)
@@ -3465,13 +3594,23 @@
 INT32      GetObject32A(HANDLE32,INT32,LPVOID);
 INT32      GetObject32W(HANDLE32,INT32,LPVOID);
 #define    GetObject WINELIB_NAME_AW(GetObject)
+FARPROC16  GetProcAddress16(HMODULE16,SEGPTR);
+FARPROC32  GetProcAddress32(HMODULE32,LPCSTR);
+#define    GetProcAddress WINELIB_NAME(GetProcAddress)
 INT16      GetRgnBox16(HRGN16,LPRECT16);
 INT32      GetRgnBox32(HRGN32,LPRECT32);
 #define    GetRgnBox WINELIB_NAME(GetRgnBox)
+DWORD      GetShortPathName32A(LPCSTR,LPSTR,DWORD);
+DWORD      GetShortPathName32W(LPCWSTR,LPWSTR,DWORD);
+#define    GetShortPathName WINELIB_NAME_AW(GetShortPathName)
 UINT16     GetSystemDirectory16(LPSTR,UINT16);
 UINT32     GetSystemDirectory32A(LPSTR,UINT32);
 UINT32     GetSystemDirectory32W(LPWSTR,UINT32);
 #define    GetSystemDirectory WINELIB_NAME_AW(GetSystemDirectory)
+UINT16     GetTempFileName16(BYTE,LPCSTR,UINT16,LPSTR);
+UINT32     GetTempFileName32A(LPCSTR,LPCSTR,UINT32,LPSTR);
+UINT32     GetTempFileName32W(LPCWSTR,LPCWSTR,UINT32,LPWSTR);
+#define    GetTempFileName WINELIB_NAME_AW(GetTempFileName)
 UINT32     GetTempPath32A(UINT32,LPSTR);
 UINT32     GetTempPath32W(UINT32,LPWSTR);
 #define    GetTempPath WINELIB_NAME_AW(GetTempPath)
@@ -3511,6 +3650,9 @@
 void       GetWindowRect16(HWND16,LPRECT16);
 void       GetWindowRect32(HWND32,LPRECT32);
 #define    GetWindowRect WINELIB_NAME(GetWindowRect)
+HTASK16    GetWindowTask16(HWND16);
+#define    GetWindowTask32(hwnd) ((HTASK32)GetWindowThreadProcessId(hwnd,NULL))
+#define    GetWindowTask WINELIB_NAME(GetWindowTask)
 INT16      GetWindowText16(HWND16,SEGPTR,INT16);
 INT32      GetWindowText32A(HWND32,LPSTR,INT32);
 INT32      GetWindowText32W(HWND32,LPWSTR,INT32);
@@ -3570,9 +3712,38 @@
 void       InvertRect16(HDC16,const RECT16*);
 void       InvertRect32(HDC32,const RECT32*);
 #define    InvertRect WINELIB_NAME(InvertRect)
+BOOL16     IsCharAlpha16(CHAR);
+BOOL32     IsCharAlpha32A(CHAR);
+BOOL32     IsCharAlpha32W(WCHAR);
+#define    IsCharAlpha WINELIB_NAME_AW(IsCharAlpha)
+BOOL16     IsCharAlphaNumeric16(CHAR);
+BOOL32     IsCharAlphaNumeric32A(CHAR);
+BOOL32     IsCharAlphaNumeric32W(WCHAR);
+#define    IsCharAlphaNumeric WINELIB_NAME_AW(IsCharAlphaNumeric)
+BOOL16     IsCharLower16(CHAR);
+BOOL32     IsCharLower32A(CHAR);
+BOOL32     IsCharLower32W(WCHAR);
+#define    IsCharLower WINELIB_NAME_AW(IsCharLower)
+BOOL16     IsCharUpper16(CHAR);
+BOOL32     IsCharUpper32A(CHAR);
+BOOL32     IsCharUpper32W(WCHAR);
+#define    IsCharUpper WINELIB_NAME_AW(IsCharUpper)
 BOOL16     IsRectEmpty16(const RECT16*);
 BOOL32     IsRectEmpty32(const RECT32*);
 #define    IsRectEmpty WINELIB_NAME(IsRectEmpty)
+BOOL16     KillSystemTimer16(HWND16,UINT16);
+BOOL32     KillSystemTimer32(HWND32,UINT32);
+#define    KillSystemTimer WINELIB_NAME(KillSystemTimer)
+BOOL16     KillTimer16(HWND16,UINT16);
+BOOL32     KillTimer32(HWND32,UINT32);
+#define    KillTimer WINELIB_NAME(KillTimer)
+HFILE      LZOpenFile16(LPCSTR,LPOFSTRUCT,UINT16);
+HFILE      LZOpenFile32A(LPCSTR,LPOFSTRUCT,UINT32);
+HFILE      LZOpenFile32W(LPCWSTR,LPOFSTRUCT,UINT32);
+#define    LZOpenFile WINELIB_NAME_AW(LZOpenFile)
+INT16      LZRead16(HFILE,SEGPTR,UINT16); 
+INT32      LZRead32(HFILE,LPVOID,UINT32); 
+#define    LZRead WINELIB_NAME(LZRead)
 HMENU16    LoadMenuIndirect16(LPCVOID);
 HMENU32    LoadMenuIndirect32A(LPCVOID);
 HMENU32    LoadMenuIndirect32W(LPCVOID);
@@ -3632,6 +3803,12 @@
 INT16      MulDiv16(INT16,INT16,INT16);
 INT32      MulDiv32(INT32,INT32,INT32);
 #define    MulDiv WINELIB_NAME(MulDiv)
+BOOL32     OemToChar32A(LPSTR,LPSTR);
+BOOL32     OemToChar32W(LPCSTR,LPWSTR);
+#define    OemToChar WINELIB_NAME_AW(OemToChar)
+BOOL32     OemToCharBuff32A(LPSTR,LPSTR,DWORD);
+BOOL32     OemToCharBuff32W(LPCSTR,LPWSTR,DWORD);
+#define    OemToCharBuff WINELIB_NAME_AW(OemToCharBuff)
 void       OffsetRect16(LPRECT16,INT16,INT16);
 void       OffsetRect32(LPRECT32,INT32,INT32);
 #define    OffsetRect WINELIB_NAME(OffsetRect)
@@ -3785,6 +3962,12 @@
 void       SetRectEmpty16(LPRECT16);
 void       SetRectEmpty32(LPRECT32);
 #define    SetRectEmpty WINELIB_NAME(SetRectEmpty)
+UINT16     SetSystemTimer16(HWND16,UINT16,UINT16,TIMERPROC16);
+UINT32     SetSystemTimer32(HWND32,UINT32,UINT32,TIMERPROC32);
+#define    SetSystemTimer WINELIB_NAME(SetSystemTimer)
+UINT16     SetTimer16(HWND16,UINT16,UINT16,TIMERPROC16);
+UINT32     SetTimer32(HWND32,UINT32,UINT32,TIMERPROC32);
+#define    SetTimer WINELIB_NAME(SetTimer)
 BOOL16     SetViewportExtEx16(HDC16,INT16,INT16,LPSIZE16);
 BOOL32     SetViewportExtEx32(HDC32,INT32,INT32,LPSIZE32);
 #define    SetViewportExtEx WINELIB_NAME(SetViewportExtEx)
@@ -3831,6 +4014,22 @@
 void       ValidateRect16(HWND16,const RECT16*);
 void       ValidateRect32(HWND32,const RECT32*);
 #define    ValidateRect WINELIB_NAME(ValidateRect)
+DWORD      VerFindFile16(UINT16,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT16*,LPSTR,UINT16*);
+DWORD      VerFindFile32A(UINT32,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT32*,LPSTR,UINT32*);
+DWORD      VerFindFile32W(UINT32,LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT32*,LPWSTR,UINT32*);
+#define    VerFindFile WINELIB_NAME_AW(VerFindFile)
+DWORD      VerInstallFile16(UINT16,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT16*);
+DWORD      VerInstallFile32A(UINT32,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT32*);
+DWORD      VerInstallFile32W(UINT32,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT32*);
+#define    VerInstallFile WINELIB_NAME_AW(VerInstallFile)
+DWORD      VerLanguageName16(UINT16,LPSTR,UINT16);
+DWORD      VerLanguageName32A(UINT32,LPSTR,UINT32);
+DWORD      VerLanguageName32W(UINT32,LPWSTR,UINT32);
+#define    VerLanguageName WINELIB_NAME_AW(VerLanguageName)
+DWORD      VerQueryValue16(SEGPTR,LPCSTR,SEGPTR*,UINT16*);
+DWORD      VerQueryValue32A(LPVOID,LPCSTR,LPVOID*,UINT32*);
+DWORD      VerQueryValue32W(LPVOID,LPCWSTR,LPVOID*,UINT32*);
+#define    VerQueryValue WINELIB_NAME_AW(VerQueryValue)
 HWND16     WindowFromPoint16(POINT16);
 HWND32     WindowFromPoint32(POINT32);
 #define    WindowFromPoint WINELIB_NAME(WindowFromPoint)
@@ -3862,14 +4061,6 @@
 INT32      lstrlen32A(LPCSTR);
 INT32      lstrlen32W(LPCWSTR);
 #define    lstrlen WINELIB_NAME_AW(lstrlen)
-INT16      lstrncmp16(LPCSTR,LPCSTR,INT16);
-INT32      lstrncmp32A(LPCSTR,LPCSTR,INT32);
-INT32      lstrncmp32W(LPCWSTR,LPCWSTR,INT32);
-#define    lstrncmp WINELIB_NAME_AW(lstrncmp)
-INT16      lstrncmpi16(LPCSTR,LPCSTR,INT16);
-INT32      lstrncmpi32A(LPCSTR,LPCSTR,INT32);
-INT32      lstrncmpi32W(LPCWSTR,LPCWSTR,INT32);
-#define    lstrncmpi WINELIB_NAME_AW(lstrncmpi)
 INT16      wsnprintf16(LPSTR,UINT16,LPCSTR,...);
 INT32      wsnprintf32A(LPSTR,UINT32,LPCSTR,...);
 INT32      wsnprintf32W(LPWSTR,UINT32,LPCWSTR,...);
@@ -3887,6 +4078,15 @@
 INT32      wvsprintf32W(LPWSTR,LPCWSTR,LPCVOID);
 #define    wvsprintf WINELIB_NAME_AW(wvsprintf)
 
+/* Extra functions that don't exist in the Windows API */
+
+INT32      lstrncmp32A(LPCSTR,LPCSTR,INT32);
+INT32      lstrncmp32W(LPCWSTR,LPCWSTR,INT32);
+INT32      lstrncmpi32A(LPCSTR,LPCSTR,INT32);
+INT32      lstrncmpi32W(LPCWSTR,LPCWSTR,INT32);
+LPWSTR     lstrcpynAtoW(LPWSTR,LPCSTR,INT32);
+LPSTR      lstrcpynWtoA(LPSTR,LPCWSTR,INT32);
+
 /* Library data types defined as a transition aid for the emulator. */
 /* These should _not_ be used in the emulator and will be removed someday. */
 
@@ -3958,7 +4158,7 @@
 UINT       AnsiLowerBuff(LPSTR,UINT);
 SEGPTR     AnsiNext(SEGPTR);
 SEGPTR     AnsiPrev(SEGPTR,SEGPTR);
-INT        AnsiToOem(LPSTR,LPSTR);
+INT        AnsiToOem(LPCSTR,LPSTR);
 void       AnsiToOemBuff(LPCSTR,LPSTR,UINT);
 LPSTR      AnsiUpper(LPSTR);
 UINT       AnsiUpperBuff(LPSTR,UINT);
@@ -3975,9 +4175,7 @@
 INT        Catch(LPCATCHBUF);
 BOOL       ChangeClipboardChain(HWND,HWND);
 WORD       ChangeSelector(WORD,WORD);
-BOOL       CheckDlgButton(HWND,INT,UINT);
 INT        CheckMenuItem(HMENU,UINT,UINT);
-BOOL       CheckRadioButton(HWND,UINT,UINT,UINT);
 BOOL       Chord(HDC,INT,INT,INT,INT,INT,INT,INT,INT);
 int        ClearCommBreak(int);
 BOOL       CloseClipboard(void);
@@ -3986,18 +4184,10 @@
 void       CloseSound(void);
 BOOL       CloseWindow(HWND);
 int        ConvertRequest(HWND,LPKANJISTRUCT);
-#ifdef WINELIB32
-HCURSOR    CopyCursor(HCURSOR); /* Win32 */
-HICON      CopyIcon(HICON); /* Win32 */
-#else
-HCURSOR    CopyCursor(HINSTANCE,HCURSOR); /* Win16 */
-HICON      CopyIcon(HINSTANCE,HICON); /* Win16 */
-#endif
 HMETAFILE  CopyMetaFile(HMETAFILE,LPCSTR);
 INT        CountClipboardFormats(void);
 INT        CountVoiceNotes(INT);
 HBRUSH     CreateBrushIndirect(const LOGBRUSH16*);
-BOOL       CreateCaret(HWND,HBITMAP,INT,INT);
 HDC        CreateCompatibleDC(HDC);
 HCURSOR    CreateCursor(HANDLE,INT,INT,INT,INT,const BYTE*,const BYTE*);
 HANDLE     CreateCursorIconIndirect(HANDLE,CURSORICONINFO*,const BYTE*,const BYTE*);
@@ -4005,7 +4195,6 @@
 HBRUSH     CreateDIBPatternBrush(HGLOBAL,UINT);
 HBITMAP    CreateDIBitmap(HDC,BITMAPINFOHEADER*,DWORD,LPVOID,BITMAPINFO*,UINT);
 HFONT      CreateFont(INT,INT,INT,INT,INT,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,LPCSTR);
-HFONT      CreateFontIndirect(const LOGFONT16*);
 HBRUSH     CreateHatchBrush(INT,COLORREF);
 HDC        CreateIC(LPCSTR,LPCSTR,LPCSTR,const DEVMODE*);
 HICON      CreateIcon(HINSTANCE,INT,INT,BYTE,BYTE,const BYTE*,const BYTE*);
@@ -4025,7 +4214,6 @@
 BOOL       DeleteMenu(HMENU,UINT,UINT);
 BOOL       DeleteMetaFile(HMETAFILE);
 BOOL       DeleteObject(HGDIOBJ16);
-BOOL       DestroyCaret(void);
 BOOL       DestroyCursor(HCURSOR);
 BOOL       DestroyIcon(HICON);
 BOOL       DestroyMenu(HMENU);
@@ -4059,7 +4247,6 @@
 int        ExcludeClipRect(HDC,short,short,short,short);
 int        ExcludeVisRect(HDC,short,short,short,short);
 BOOL       ExitWindows(DWORD,WORD);
-BOOL       ExtFloodFill(HDC,INT,INT,COLORREF,WORD);
 HICON      ExtractIcon(HINSTANCE,LPCSTR,WORD);
 HANDLE16   FarGetOwner(HANDLE16);
 void       FarSetOwner(HANDLE16,HANDLE16);
@@ -4070,7 +4257,6 @@
 HINSTANCE  FindExecutable(LPCSTR,LPCSTR,LPSTR);
 HRSRC      FindResource(HINSTANCE,SEGPTR,SEGPTR);
 BOOL       FlashWindow(HWND,BOOL);
-BOOL       FloodFill(HDC,INT,INT,COLORREF);
 int        FlushComm(int,int);
 BOOL       FrameRgn(HDC,HRGN,HBRUSH,int,int);
 void       FreeLibrary(HANDLE);
@@ -4086,7 +4272,6 @@
 WORD       GetBkMode(HDC);
 DWORD      GetBrushOrg(HDC);
 HWND       GetCapture(void);
-WORD       GetCaretBlinkTime(void);
 BOOL       GetCharABCWidths(HDC,UINT,UINT,LPABC16);
 BOOL       GetCharWidth(HDC,WORD,WORD,LPINT16);
 HRGN       GetClipRgn(HDC);
@@ -4115,7 +4300,6 @@
 HWND       GetDesktopWindow(void);
 int        GetDeviceCaps(HDC,WORD);
 DWORD      GetDialogBaseUnits(void);
-int        GetDlgCtrlID(HWND);
 HWND       GetDlgItem(HWND,WORD);
 WORD       GetDlgItemInt(HWND,WORD,BOOL*,BOOL);
 WORD       GetDoubleClickTime(void);
@@ -4165,7 +4349,6 @@
 int        GetPriorityClipboardFormat(WORD*,short);
 UINT       GetPrivateProfileInt(LPCSTR,LPCSTR,INT,LPCSTR);
 INT        GetPrivateProfileString(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT,LPCSTR);
-FARPROC    GetProcAddress(HANDLE,SEGPTR);
 UINT       GetProfileInt(LPCSTR,LPCSTR,INT);
 INT        GetProfileString(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT);
 HANDLE     GetProp(HWND,SEGPTR);
@@ -4189,10 +4372,7 @@
 BOOL       GetSystemPowerStatus(LPSYSTEM_POWER_STATUS);
 VOID       GetSystemTime(LPSYSTEMTIME); /* Win32 */
 DWORD      GetTabbedTextExtent(HDC,LPSTR,int,int,LPINT16);
-HINSTANCE  GetTaskDS(void);
-HQUEUE     GetTaskQueue(HTASK);
 BYTE       GetTempDrive(BYTE);
-INT        GetTempFileName(BYTE,LPCSTR,UINT,LPSTR);
 WORD       GetTextAlign(HDC);
 short      GetTextCharacterExtra(HDC);
 COLORREF   GetTextColor(HDC);
@@ -4200,7 +4380,6 @@
 INT        GetTextFace(HDC,INT,LPSTR);
 LPINT16    GetThresholdEvent(void);
 int        GetThresholdStatus(void);
-DWORD      GetTickCount(void);
 HWND       GetTopWindow(HWND);
 LONG       GetVersion(void);
 DWORD      GetViewportExt(HDC);
@@ -4211,7 +4390,6 @@
 HDC        GetWindowDC(HWND);
 DWORD      GetWindowExt(HDC);
 DWORD      GetWindowOrg(HDC);
-HANDLE     GetWindowTask(HWND);
 int        GetWindowTextLength(HWND);
 UINT       GetWindowsDirectory(LPSTR,UINT);
 DWORD      GlobalDOSAlloc(DWORD);
@@ -4228,7 +4406,6 @@
 void       GlobalUnfix(HGLOBAL16);
 SEGPTR     GlobalWire(HGLOBAL16);
 BOOL       GrayString(HDC,HBRUSH,FARPROC,LPARAM,INT,INT,INT,INT,INT);
-void       HideCaret(HWND);
 BOOL       HiliteMenuItem(HWND,HMENU,UINT,UINT);
 BOOL       InSendMessage(void);
 WORD       InitAtomTable(WORD);
@@ -4243,10 +4420,6 @@
 BOOL       IsBadReadPtr(SEGPTR,WORD);
 BOOL       IsBadStringPtr(SEGPTR,WORD);
 BOOL       IsBadWritePtr(SEGPTR,WORD);
-BOOL       IsCharAlpha(char);
-BOOL       IsCharAlphaNumeric(char);
-BOOL       IsCharLower(char);
-BOOL       IsCharUpper(char);
 BOOL       IsChild(HWND,HWND);
 BOOL       IsClipboardFormatAvailable(WORD);
 BOOL       IsDialogMessage(HWND,LPMSG16);
@@ -4256,13 +4429,9 @@
 BOOL       IsMenu(HMENU);
 BOOL       IsTask(HTASK);
 HTASK      IsTaskLocked(void);
-BOOL       IsWindow(HWND);
 BOOL       IsWindowEnabled(HWND);
-BOOL       IsWindowUnicode(HWND);
 BOOL       IsWindowVisible(HWND);
 BOOL       IsZoomed(HWND);
-BOOL       KillSystemTimer(HWND,WORD);
-BOOL       KillTimer(HWND,WORD);
 void       LimitEmsPages(DWORD);
 void       LineDDA(short,short,short,short,FARPROC,long);
 BOOL       LineTo(HDC,short,short);
@@ -4284,12 +4453,11 @@
 DWORD      MoveTo(HDC,short,short);
 BOOL       MoveWindow(HWND,short,short,short,short,BOOL);
 DWORD      OemKeyScan(WORD);
-BOOL       OemToAnsi(LPSTR,LPSTR);
-void       OemToAnsiBuff(LPSTR,LPSTR,INT);
+BOOL       OemToAnsi(LPCSTR,LPSTR);
+void       OemToAnsiBuff(LPCSTR,LPSTR,INT);
 int        OffsetClipRgn(HDC,short,short);
 BOOL       OpenClipboard(HWND);
 int        OpenComm(LPCSTR,UINT,UINT);
-HFILE      OpenFile(LPCSTR,OFSTRUCT*,UINT);
 BOOL       OpenIcon(HWND);
 int        OpenSound(void);
 void       OutputDebugString(LPCSTR);
@@ -4344,8 +4512,6 @@
 WORD       SetBkMode(HDC,WORD);
 DWORD      SetBrushOrg(HDC,short,short);
 HWND       SetCapture(HWND);
-void       SetCaretBlinkTime(WORD);
-void       SetCaretPos(short,short);
 HANDLE     SetClipboardData(WORD,HANDLE);
 HWND       SetClipboardViewer(HWND);
 int        SetCommBreak(int);
@@ -4393,13 +4559,11 @@
 WORD       SetSystemPaletteUse(HDC,WORD);
 BOOL       SetSystemPowerState(BOOL, BOOL);
 BOOL       SetSystemTime(const SYSTEMTIME*);
-WORD       SetSystemTimer(HWND,WORD,WORD,FARPROC);
 HQUEUE     SetTaskQueue(HTASK,HQUEUE);
 WORD       SetTextAlign(HDC,WORD);
 short      SetTextCharacterExtra(HDC,short);
 DWORD      SetTextColor(HDC,DWORD);
 short      SetTextJustification(HDC,short,short);
-WORD       SetTimer(HWND,WORD,WORD,FARPROC);
 int        SetVoiceAccent(int,int,int,int,int);
 int        SetVoiceEnvelope(int,int,int);
 int        SetVoiceNote(int,int,int,int);
@@ -4411,7 +4575,6 @@
 FARPROC    SetWindowsHook(short,FARPROC);
 HHOOK      SetWindowsHookEx(short,HOOKPROC,HINSTANCE,HTASK);
 HINSTANCE  ShellExecute(HWND,LPCSTR,LPCSTR,LPSTR,LPCSTR,INT);
-void       ShowCaret(HWND);
 int        ShowCursor(BOOL);
 void       ShowOwnedPopups(HWND,BOOL);
 void       ShowScrollBar(HWND,WORD,BOOL);
@@ -4460,10 +4623,7 @@
 void       Yield(void);
 LONG       _hread(HFILE,SEGPTR,LONG);
 LONG       _hwrite(HFILE,LPCSTR,LONG);
-HFILE      _lclose(HFILE);
-HFILE      _lcreat(LPCSTR,INT);
 LONG       _llseek(HFILE,LONG,INT);
-HFILE      _lopen(LPCSTR,INT);
 INT        _lread(HFILE,SEGPTR,WORD);
 INT        _lwrite(HFILE,LPCSTR,WORD);
 
diff --git a/include/wine.h b/include/wine.h
deleted file mode 100644
index bcfffca..0000000
--- a/include/wine.h
+++ /dev/null
@@ -1,75 +0,0 @@
-#ifndef  __WINE_WINE_H
-#define  __WINE_WINE_H
-
-#ifdef i386
-extern int runtime_cpu (void);
-#else
-static inline int runtime_cpu(void) { return 3; }
-#endif
-
-#ifndef WINELIB
-
-#ifdef linux
-typedef struct
-{
-	unsigned short sc_gs, __gsh;
-	unsigned short sc_fs, __fsh;
-	unsigned short sc_es, __esh;
-	unsigned short sc_ds, __dsh;
-	unsigned long sc_edi;
-	unsigned long sc_esi;
-	unsigned long sc_ebp;
-	unsigned long sc_esp;
-	unsigned long sc_ebx;
-	unsigned long sc_edx;
-	unsigned long sc_ecx;
-	unsigned long sc_eax;
-	unsigned long sc_trapno;
-	unsigned long sc_err;
-	unsigned long sc_eip;
-	unsigned short sc_cs, __csh;
-	unsigned long sc_eflags;
-	unsigned long esp_at_signal;
-	unsigned short sc_ss, __ssh;
-	unsigned long i387;
-	unsigned long oldmask;
-	unsigned long cr2;
-} SIGCONTEXT;
-#define WINE_DATA_SELECTOR 0x2b
-#define WINE_CODE_SELECTOR 0x23
-#endif  /* linux */
-
-#ifdef __NetBSD__
-#include <signal.h>
-typedef struct sigcontext SIGCONTEXT;
-#define WINE_DATA_SELECTOR 0x1f
-#define WINE_CODE_SELECTOR 0x17
-#endif  /* NetBSD */
-
-#if defined(__svr4__) || defined(_SCO_DS)
-#include <signal.h>
-#ifdef _SCO_DS
-#include <sys/regset.h>
-#endif
-#include <sys/ucontext.h>
-typedef struct ucontext SIGCONTEXT;
-#define WINE_DATA_SELECTOR 0x1f
-#define WINE_CODE_SELECTOR 0x17
-#endif  /* svr4 || SCO_DS */
-
-#ifdef __FreeBSD__
-#include <signal.h>
-typedef struct sigcontext SIGCONTEXT;
-#define WINE_DATA_SELECTOR 0x27
-#define WINE_CODE_SELECTOR 0x1f
-#endif  /* FreeBSD */
-
-#else  /* WINELIB */
-
-typedef void SIGCONTEXT;
-#define WINE_DATA_SELECTOR 0x00
-#define WINE_CODE_SELECTOR 0x00
-
-#endif  /* WINELIB */
-
-#endif /* __WINE_WINE_H */
diff --git a/include/winproc.h b/include/winproc.h
index fd9b22a..f5ce4f5 100644
--- a/include/winproc.h
+++ b/include/winproc.h
@@ -26,4 +26,33 @@
 extern void WINPROC_FreeProc( HWINDOWPROC proc );
 extern WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc );
 
+extern INT32 WINPROC_MapMsg32ATo32W( UINT32 msg, WPARAM32 wParam,
+                                     LPARAM *plparam );
+extern INT32 WINPROC_MapMsg32WTo32A( UINT32 msg, WPARAM32 wParam,
+                                     LPARAM *plparam );
+extern INT32 WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16,
+                                    UINT32 *pmsg32, WPARAM32 *pwparam32,
+                                    LPARAM *plparam );
+extern INT32 WINPROC_MapMsg16To32W( UINT16 msg16, WPARAM16 wParam16,
+                                    UINT32 *pmsg32, WPARAM32 *pwparam32,
+                                    LPARAM *plparam );
+extern INT32 WINPROC_MapMsg32ATo16( UINT32 msg32, WPARAM32 wParam32,
+                                    UINT16 *pmsg16, WPARAM16 *pwparam16,
+                                    LPARAM *plparam );
+extern INT32 WINPROC_MapMsg32WTo16( UINT32 msg32, WPARAM32 wParam32,
+                                    UINT16 *pmsg16, WPARAM16 *pwparam16,
+                                    LPARAM *plparam );
+extern void WINPROC_UnmapMsg32ATo32W( UINT32 msg, WPARAM32 wParam,
+                                      LPARAM lParam );
+extern void WINPROC_UnmapMsg32WTo32A( UINT32 msg, WPARAM32 wParam,
+                                      LPARAM lParam );
+extern void WINPROC_UnmapMsg16To32A( UINT32 msg, WPARAM32 wParam,
+                                     LPARAM lParam );
+extern void WINPROC_UnmapMsg16To32W( UINT32 msg, WPARAM32 wParam,
+                                     LPARAM lParam );
+extern void WINPROC_UnmapMsg32ATo16( UINT16 msg, WPARAM16 wParam,
+                                     LPARAM lParam );
+extern void WINPROC_UnmapMsg32WTo16( UINT16 msg, WPARAM16 wParam,
+                                     LPARAM lParam );
+
 #endif  /* __WINE_WINPROC_H */
diff --git a/include/wintypes.h b/include/wintypes.h
index 4f6c53e..9fe61f2 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -151,23 +151,17 @@
 
 /* Callback function pointers types for Win16. */
 
-#ifdef WINELIB
 typedef LRESULT (*DLGPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
 typedef LRESULT (*FARPROC16)();
+typedef VOID (*TIMERPROC16)(HWND16,UINT16,UINT16,DWORD);
 typedef LRESULT (*WNDENUMPROC16)(HWND16,LPARAM);
 typedef LRESULT (*WNDPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
-#else
-/* Function pointers are SEGPTR in Win16 */
-typedef SEGPTR DLGPROC16;
-typedef SEGPTR FARPROC16;
-typedef SEGPTR WNDENUMPROC16;
-typedef SEGPTR WNDPROC16;
-#endif
 
 /* Callback function pointers types for Win32. */
 
 typedef LRESULT (*DLGPROC32)(HWND32,UINT32,WPARAM32,LPARAM);
 typedef LRESULT (*FARPROC32)();
+typedef VOID (*TIMERPROC32)(HWND32,UINT32,UINT32,DWORD);
 typedef LRESULT (*WNDENUMPROC32)(HWND32,LPARAM);
 typedef LRESULT (*WNDPROC32)(HWND32,UINT32,WPARAM32,LPARAM);
 
diff --git a/library/miscstubs.c b/library/miscstubs.c
index c6b61bf..ca70c35 100644
--- a/library/miscstubs.c
+++ b/library/miscstubs.c
@@ -44,7 +44,6 @@
 WORD CallTo16_word_ ( FARPROC func, WORD arg ) { return func(arg); }
 
 extern LRESULT AboutDlgProc(HWND,UINT,WPARAM,LPARAM);
-extern LRESULT CARET_Callback(HWND,UINT,WPARAM,LPARAM);
 extern LRESULT ColorDlgProc(HWND,UINT,WPARAM,LPARAM);
 extern LRESULT ComboBoxWndProc(HWND,UINT,WPARAM,LPARAM);
 extern LRESULT ComboLBoxWndProc(HWND,UINT,WPARAM,LPARAM);
@@ -78,7 +77,6 @@
 {
 #define MAP_STR_TO_PROC(str,proc) if(!strcmp(name,str))return proc
   MAP_STR_TO_PROC("AboutDlgProc",AboutDlgProc);
-  MAP_STR_TO_PROC("CARET_Callback",CARET_Callback);
   MAP_STR_TO_PROC("ColorDlgProc",ColorDlgProc);
   MAP_STR_TO_PROC("ComboBoxWndProc",ComboBoxWndProc);
   MAP_STR_TO_PROC("ComboLBoxWndProc",ComboLBoxWndProc);
diff --git a/library/sup.c b/library/sup.c
index 797b96c..194d7e7 100644
--- a/library/sup.c
+++ b/library/sup.c
@@ -2,7 +2,6 @@
 #include <unistd.h>
 #include "windows.h"
 #include "callback.h"
-#include "wine.h"
 #include "arch.h"
 #include "neexe.h"
 
diff --git a/library/winestub.c b/library/winestub.c
index 2f5e722..b5323b8 100644
--- a/library/winestub.c
+++ b/library/winestub.c
@@ -1,7 +1,6 @@
 /* Sample winestub.c file for compiling programs with libwine.so. */
 
 #include "windows.h"
-#include "wine.h"
 #ifdef WIN_DEBUG
 #include <stdio.h>
 #endif
diff --git a/library/winmain.c b/library/winmain.c
index 4508a34..f048062 100644
--- a/library/winmain.c
+++ b/library/winmain.c
@@ -2,7 +2,6 @@
 #include <string.h>
 #include <malloc.h>
 #include "windows.h"
-#include "wine.h"
 #include "xmalloc.h"
 
 extern int MAIN_Init(void);
@@ -31,9 +30,6 @@
   hInstance = WinExec( *argv, SW_SHOWNORMAL );
   TASK_Reschedule();
   USER_InitApp( hInstance );
-  /* Perform global initialisations that need a task context */
-  if (!WIDGETS_Init()) return -1;
-  if (!WIN_CreateDesktopWindow()) return -1;
 
 #ifdef WINELIBDLL
   return (int)hInstance;
diff --git a/loader/builtin.c b/loader/builtin.c
index 0d90272..73ebcd5 100644
--- a/loader/builtin.c
+++ b/loader/builtin.c
@@ -59,7 +59,6 @@
 #define DLL_FLAG_ALWAYS_USED 0x02  /* Always use built-in DLL */
 #define DLL_FLAG_WIN32       0x04  /* DLL is a Win32 DLL */
 
-
 /* 16-bit DLLs */
 
 extern const DLL_DESCRIPTOR KERNEL_Descriptor;
@@ -146,7 +145,7 @@
     { &ADVAPI32_Descriptor, 0 },
     { &COMCTL32_Descriptor, 0 },
     { &COMDLG32_Descriptor, 0 },
-    { &CRTDLL_Descriptor, 0 },
+    { &CRTDLL_Descriptor,   0 },
     { &OLE32_Descriptor,    0 },
     { &GDI32_Descriptor,    0 },
     { &KERNEL32_Descriptor, DLL_FLAG_ALWAYS_USED },
@@ -230,6 +229,7 @@
     if (pModule->flags & NE_FFLAGS_WIN32)
     {
         pModule->pe_module = (PE_MODULE *)table;
+        table->flags |= DLL_FLAG_WIN32;
     }
     else  /* Win16 module */
     {
@@ -265,13 +265,14 @@
 
 
 /***********************************************************************
- *           BUILTIN_GetEntryPoint
+ *           BUILTIN_GetEntryPoint16
  *
- * Return the built-in module, ordinal and name corresponding
- * to a CS:IP address. This is used only by relay debugging.
+ * Return the ordinal and name corresponding to a CS:IP address.
+ * This is used only by relay debugging.
  */
-NE_MODULE *BUILTIN_GetEntryPoint( WORD cs, WORD ip, WORD *pOrd, char **ppName )
+LPCSTR BUILTIN_GetEntryPoint16( WORD cs, WORD ip, WORD *pOrd )
 {
+    static char buffer[80];
     WORD ordinal, i, max_offset;
     register BYTE *p;
     NE_MODULE *pModule;
@@ -324,18 +325,62 @@
     /* (built-in modules have no non-resident table)   */
     
     p = (BYTE *)pModule + pModule->name_table;
-    *ppName = "???";
     while (*p)
     {
         p += *p + 1 + sizeof(WORD);
-        if (*(WORD *)(p + *p + 1) == *pOrd)
-        {
-            *ppName = (char *)p;
-            break;
-        }
+        if (*(WORD *)(p + *p + 1) == *pOrd) break;
     }
 
-    return pModule;
+    sprintf( buffer, "%.*s.%d: %.*s",
+             *((BYTE *)pModule + pModule->name_table),
+             (char *)pModule + pModule->name_table + 1,
+             *pOrd, *p, (char *)(p + 1) );
+    return buffer;
+}
+
+
+/***********************************************************************
+ *           BUILTIN_GetEntryPoint32
+ *
+ * Return the name of the DLL entry point corresponding
+ * to a relay entry point address. This is used only by relay debugging.
+ */
+LPCSTR BUILTIN_GetEntryPoint32( void *relay )
+{
+    static char buffer[80];
+    BUILTIN_DLL *dll;
+    const void **funcs;
+    int first, i, size;
+
+    /* First find the module */
+
+    for (dll = BuiltinDLLs; dll->descr; dll++)
+        if ((dll->flags & DLL_FLAG_WIN32) &&
+            (dll->descr->u.win32.functions[0] <= relay) &&
+            (dll->descr->u.win32.functions[dll->descr->u.win32.size-1] >relay))
+            break;
+    if (!dll->descr)
+    {
+        sprintf( buffer, "???.???: %08x", (UINT32)relay );
+        return buffer;
+    }
+
+    /* Do a binary search for the function */
+
+    relay = (BYTE *)relay - 11;  /* The relay entry point is 11 bytes long */
+    funcs = dll->descr->u.win32.functions;
+    first = i = 0;
+    size = dll->descr->u.win32.size;
+    while (first < size)
+    {
+        i = (first + size) / 2;
+        if (funcs[i] == relay) break;
+        if (funcs[i] > relay) size = i;
+        else first = i + 1;
+    }
+    sprintf( buffer, "%s.%d: %s",
+             dll->descr->name, i, dll->descr->u.win32.names[i] );
+    return buffer;
 }
 
 
@@ -345,12 +390,12 @@
  * Implementation of GetProcAddress() for built-in Win32 modules.
  * FIXME: this should be unified with the real GetProcAddress32().
  */
-DWORD BUILTIN_GetProcAddress32( NE_MODULE *pModule, char *function )
+FARPROC32 BUILTIN_GetProcAddress32( NE_MODULE *pModule, LPCSTR function )
 {
     BUILTIN_DLL *dll = (BUILTIN_DLL *)pModule->pe_module;
     const WIN32_DESCRIPTOR *info = &dll->descr->u.win32;
 
-    if (!dll) return 0;
+    if (!dll) return NULL;
 
     if (HIWORD(function))  /* Find function by name */
     {
@@ -360,7 +405,7 @@
                         function, dll->descr->name );
         for (i = 0; i < info->size; i++)
             if (info->names[i] && !strcmp( function, info->names[i] ))
-                return (DWORD)info->functions[i];
+                return (FARPROC32)info->functions[i];
     }
     else  /* Find function by ordinal */
     {
@@ -368,9 +413,9 @@
         dprintf_module( stddeb, "Looking for ordinal %d in %s\n",
                         ordinal, dll->descr->name );
         if (ordinal && ordinal < info->size)
-            return (DWORD)info->functions[ordinal - info->base];
+            return (FARPROC32)info->functions[ordinal - info->base];
     }
-    return 0;
+    return NULL;
 }
 
 
diff --git a/loader/main.c b/loader/main.c
index 02917c4..01b6511 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -40,7 +40,6 @@
 #include "stddebug.h"
 #include "debug.h"
 
-void init_wine_signals(void);
 
 HANDLE32 SystemHeap = 0;
 HANDLE32 SegptrHeap = 0;
@@ -50,7 +49,9 @@
  */
 int MAIN_Init(void)
 {
-    extern BOOL RELAY_Init(void);
+    extern BOOL32 RELAY_Init(void);
+    extern BOOL32 SIGNAL_Init(void);
+    extern BOOL32 WIDGETS_Init(void);
 
     int queueSize;
 
@@ -61,9 +62,6 @@
     /* Load the configuration file */
     if (!PROFILE_LoadWineIni()) return 0;
 
-    /* Initialize message spying */
-    if (!SPY_Init()) return 0;
-
 #ifdef WINELIB
     /* Create USER and GDI heap */
     USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
@@ -71,12 +69,24 @@
     GDI_HeapSel  = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
     LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
 #else
-      /* Initialize relay code */
+    /* Initialize relay code */
     if (!RELAY_Init()) return 0;
 
-      /* Create built-in modules */
+    /* Create built-in modules */
     if (!BUILTIN_Init()) return 0;
-#endif
+
+    /* Initialize interrupt vectors */
+    if (!INT_Init()) return 0;
+
+      /* Initialize DOS memory */
+    if (!DOSMEM_Init()) return 0;
+
+      /* Initialize the DOS interrupt */
+    if (!INT21_Init()) return 0;
+
+      /* Initialize signal handling */
+    if (!SIGNAL_Init()) return 0;
+#endif  /* WINELIB */
 
     /* Initialise DOS drives */
     if (!DRIVE_Init()) return 0;
@@ -90,19 +100,6 @@
       /* Initialize communications */
     COMM_Init();
 
-#ifndef WINELIB
-      /* Initialize interrupt vectors */
-    if (!INT_Init()) return 0;
-
-      /* Initialize DOS memory */
-    if (!DOSMEM_Init()) return 0;
-
-      /* Initialize signal handling */
-    init_wine_signals();
-
-      /* Initialize the DOS memory */
-    if (!INT21_Init()) return 0;
-#endif
       /* registry initialisation */
     SHELL_LoadRegistry();
     
@@ -122,12 +119,21 @@
     /* Initialize window procedures */
     if (!WINPROC_Init()) return 0;
 
+    /* Initialize built-in window classes */
+    if (!WIDGETS_Init()) return 0;
+
       /* Initialize dialog manager */
     if (!DIALOG_Init()) return 0;
 
       /* Initialize menus */
     if (!MENU_Init()) return 0;
 
+    /* Create desktop window */
+    if (!WIN_CreateDesktopWindow()) return 0;
+
+    /* Initialize message spying */
+    if (!SPY_Init()) return 0;
+
       /* Initialize Win32 data structures */
     if (!KERN32_Init()) return 0;
 
diff --git a/loader/module.c b/loader/module.c
index c643c7d..63c44e2 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -19,14 +19,13 @@
 #include "ldt.h"
 #include "module.h"
 #include "neexe.h"
+#include "registers.h"
 #include "stackframe.h"
 #include "task.h"
 #include "toolhelp.h"
 #include "stddebug.h"
 #include "debug.h"
-
 #include "callback.h"
-#include "wine.h"
 
 extern HINSTANCE PE_LoadModule( int fd, OFSTRUCT *ofs, LOADPARAMS* params );
 
@@ -663,7 +662,7 @@
  *
  * Return the entry point for a given ordinal.
  */
-SEGPTR MODULE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
+FARPROC16 MODULE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
 {
     NE_MODULE *pModule;
     WORD curOrdinal = 1;
@@ -704,7 +703,7 @@
 
     if (sel == 0xfe) sel = 0xffff;  /* constant entry */
     else sel = (WORD)(DWORD)NE_SEG_TABLE(pModule)[sel-1].selector;
-    return PTR_SEG_OFF_TO_SEGPTR( sel, offset );
+    return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
 }
 
 
@@ -1403,12 +1402,12 @@
 
 
 /***********************************************************************
- *           GetProcAddress   (KERNEL.50)
+ *           GetProcAddress16   (KERNEL.50)
  */
-FARPROC GetProcAddress( HANDLE hModule, SEGPTR name )
+FARPROC16 GetProcAddress16( HMODULE16 hModule, SEGPTR name )
 {
     WORD ordinal;
-    SEGPTR ret;
+    FARPROC16 ret;
 
     if (!hModule) hModule = GetCurrentTask();
     hModule = GetExePtr( hModule );
@@ -1425,12 +1424,34 @@
         dprintf_module( stddeb, "GetProcAddress: %04x %04x\n",
                         hModule, ordinal );
     }
-    if (!ordinal) return (FARPROC)0;
+    if (!ordinal) return (FARPROC16)0;
 
     ret = MODULE_GetEntryPoint( hModule, ordinal );
 
-    dprintf_module( stddeb, "GetProcAddress: returning %08lx\n", (DWORD)ret );
-    return (FARPROC)ret;
+    dprintf_module( stddeb, "GetProcAddress: returning %08x\n", (UINT32)ret );
+    return ret;
+}
+
+
+/***********************************************************************
+ *           GetProcAddress32   (KERNEL32.257)
+ */
+FARPROC32 GetProcAddress32( HMODULE32 hModule, LPCSTR function )
+{
+#ifndef WINELIB
+    NE_MODULE *pModule;
+
+    hModule = GetExePtr( hModule );
+    if (!(pModule = MODULE_GetPtr( hModule )))
+        return (FARPROC32)0;
+    if (!(pModule->flags & NE_FFLAGS_WIN32) || !pModule->pe_module)
+        return (FARPROC32)0;
+    if (pModule->flags & NE_FFLAGS_BUILTIN)
+        return BUILTIN_GetProcAddress32( pModule, function );
+    return PE_FindExportedFunction( pModule->pe_module, function );
+#else
+    return NULL;
+#endif
 }
 
 
diff --git a/loader/ne_image.c b/loader/ne_image.c
index 9ef9966..359242b 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -37,7 +37,7 @@
     WORD *pModuleTable;
     WORD count, i, offset;
     HMODULE module;
-    DWORD address;
+    FARPROC16 address;
     int fd;
     struct relocation_entry_s *rep, *reloc_entries;
     BYTE *func_name;
@@ -242,7 +242,7 @@
 	    }
 	    else
 	    {
-                address = PTR_SEG_OFF_TO_SEGPTR( pSegTable[rep->target1-1].selector, rep->target2 );
+                address = (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( pSegTable[rep->target1-1].selector, rep->target2 );
 	    }
 	    
 	    dprintf_fixup(stddeb,"%d: %04x:%04x\n", 
@@ -288,9 +288,9 @@
                               pSeg->selector, offset, *sp, additive ? " additive":"");
                 offset = *sp;
 		if(additive)
-                    *(unsigned char*)sp = (unsigned char)((address+offset) & 0xFF);
+                    *(unsigned char*)sp = (unsigned char)(((int)address+offset) & 0xFF);
 		else
-                    *(unsigned char*)sp = (unsigned char)(address & 0xFF);
+                    *(unsigned char*)sp = (unsigned char)((int)address & 0xFF);
             }
             while (offset != 0xffff && !additive);
             break;
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 296560a..e95c39f 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -101,7 +101,7 @@
     }
 }
 
-static DWORD PE_FindExportedFunction(struct pe_data *pe, char* funcName)
+FARPROC32 PE_FindExportedFunction(struct pe_data *pe, LPCSTR funcName)
 {
 	struct PE_Export_Directory * exports = pe->pe_export;
 	unsigned load_addr = pe->load_addr;
@@ -109,7 +109,8 @@
 	u_long * function;
 	u_char ** name, *ename;
 	int i;
-	if(!exports)return 0;
+
+	if (!exports) return NULL;
 	ordinal = (u_short *) (((char *) load_addr) + (int) exports->Address_Of_Name_Ordinals);
 	function = (u_long *)  (((char *) load_addr) + (int) exports->AddressOfFunctions);
 	name = (u_char **)  (((char *) load_addr) + (int) exports->AddressOfNames);
@@ -119,27 +120,16 @@
 		{
 			ename =  (char *) (((char *) load_addr) + (int) *name);
 			if(strcmp(ename,funcName)==0)
-				return load_addr+*function;
+				return (FARPROC32)(load_addr + *function);
 		}else{
 			if(funcName == (int)*ordinal + exports->Base)
-				return load_addr+*function;
+				return (FARPROC32)(load_addr + *function);
 		}
 		function++;
 		ordinal++;
 		name++;
 	}
-	return 0;
-}
-
-DWORD PE_GetProcAddress(HMODULE hModule, char* function)
-{
-    NE_MODULE *pModule;
-
-    if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-    if (!(pModule->flags & NE_FFLAGS_WIN32) || !pModule->pe_module) return 0;
-    if (pModule->flags & NE_FFLAGS_BUILTIN)
-        return BUILTIN_GetProcAddress32( pModule, function );
-    return PE_FindExportedFunction( pModule->pe_module, function );
+	return NULL;
 }
 
 void fixup_imports(struct pe_data *pe, HMODULE hModule)
@@ -211,24 +201,24 @@
 	  {
 		int ordinal=*import_list & (0x80000000-1);
 		dprintf_win32(stddeb,"--- Ordinal %s,%d\n", Module, ordinal);
-		*thunk_list = WIN32_GetProcAddress(MODULE_FindModule(Module),
-			ordinal);
+		*thunk_list = GetProcAddress32(MODULE_FindModule(Module),
+                                               (LPCSTR)ordinal);
 	  	if(!*thunk_list)
 	  	{
-	  		fprintf(stderr,"No implementation for %s.%d\n",Module, 
-				ordinal);
-			fixup_failed=1;
+	  		fprintf(stderr,"No implementation for %s.%d, setting to NULL\n",
+                                Module, ordinal);
+			/* fixup_failed=1; */
 	  	}
 	  }else{ /* import by name */
 	  dprintf_win32(stddeb, "--- %s %s.%d\n", pe_name->Name, Module, pe_name->Hint);
 #ifndef WINELIB /* FIXME: JBP: Should this happen in libwine.a? */
-	  	*thunk_list = WIN32_GetProcAddress(MODULE_FindModule(Module),
-				pe_name->Name);
+	  	*thunk_list = GetProcAddress32(MODULE_FindModule(Module),
+                                               pe_name->Name);
 	  if(!*thunk_list)
 	  {
-	  	fprintf(stderr,"No implementation for %s.%d(%s)\n",Module, 
-			pe_name->Hint, pe_name->Name);
-		fixup_failed=1;
+	  	fprintf(stderr,"No implementation for %s.%d(%s), setting to NULL\n",
+                        Module, pe_name->Hint, pe_name->Name);
+		/* fixup_failed=1; */
 	  }
 
 #else
@@ -251,15 +241,15 @@
         }
         dprintf_win32(stddeb, "--- %s %s.%d\n", pe_name->Name, Module, pe_name->Hint);
 #ifndef WINELIB /* FIXME: JBP: Should this happen in libwine.a? */
-	/* FIXME: Both calls should be unified into GetProcAddress */
-        *thunk_list = WIN32_GetProcAddress(MODULE_FindModule(Module),
-                                           pe_name->Name);
+        *thunk_list = GetProcAddress32(MODULE_FindModule(Module),
+                                       pe_name->Name);
 #else
         fprintf(stderr,"JBP: Call to RELAY32_GetEntryPoint being ignored.\n");
 #endif
         if(!*thunk_list) {
-          fprintf(stderr,"No implementation for %s.%d\n",Module, pe_name->Hint);
-          fixup_failed=1;
+          fprintf(stderr,"No implementation for %s.%d, setting to NULL\n",
+                  Module, pe_name->Hint);
+          /* fixup_failed=1; */
         }
         thunk_list++;
       }
@@ -533,7 +523,7 @@
 }
 
 HINSTANCE MODULE_CreateInstance(HMODULE hModule,LOADPARAMS *params);
-void InitTask(SIGCONTEXT context);
+void InitTask( SIGCONTEXT *context );
 
 HINSTANCE PE_LoadModule( int fd, OFSTRUCT *ofs, LOADPARAMS* params )
 {
@@ -644,18 +634,18 @@
 int USER_InitApp(HINSTANCE hInstance);
 void PE_InitTEB(int hTEB);
 
-void PE_Win32CallToStart(SIGCONTEXT context)
+void PE_Win32CallToStart( SIGCONTEXT *context )
 {
     int fs;
     HMODULE hModule;
     NE_MODULE *pModule;
 
     dprintf_win32(stddeb,"Going to start Win32 program\n");	
-    InitTask(context);
+    InitTask( &context );
     hModule = GetExePtr( GetCurrentTask() );
     pModule = MODULE_GetPtr( hModule );
     USER_InitApp( hModule );
-    fs=(int)GlobalAlloc16(GHND,0x10000);
+    fs=(int)GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, 0x10000 );
     PE_InitTEB(fs);
     __asm__ __volatile__("movw %w0,%%fs"::"r" (fs));
     CallTaskStart32( (FARPROC)(pModule->pe_module->load_addr + 
diff --git a/loader/signal.c b/loader/signal.c
index 0aea7fe..c072334 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -168,9 +168,9 @@
 
 
 /**********************************************************************
- *		init_wine_signals
+ *		SIGNAL_Init
  */
-void init_wine_signals(void)
+BOOL32 SIGNAL_Init(void)
 {
 #if defined(__NetBSD__) || defined(__FreeBSD__)
     struct sigaltstack ss;
@@ -178,13 +178,13 @@
     if ((ss.ss_sp = malloc(MINSIGSTKSZ)) == NULL) {
         fprintf(stderr, "Unable to allocate signal stack (%d bytes)\n",
                 MINSIGSTKSZ);
-        exit(1);
+        return FALSE;
     }
     ss.ss_size = MINSIGSTKSZ;
     ss.ss_flags = 0;
     if (sigaltstack(&ss, NULL) < 0) {
         perror("sigstack");
-        exit(1);
+        return FALSE;
     }
 #endif  /* __FreeBSD__ || __NetBSD__ */
 
@@ -194,13 +194,13 @@
     if ((ss.ss_sp = malloc(SIGSTKSZ) ) == NULL) {
         fprintf(stderr, "Unable to allocate signal stack (%d bytes)\n",
                 SIGSTKSZ);
-        exit(1);
+        return FALSE;
     }
     ss.ss_size = SIGSTKSZ;
     ss.ss_flags = 0;
     if (sigaltstack(&ss, NULL) < 0) {
         perror("sigstack");
-        exit(1);
+        return FALSE;
     }
 #endif  /* __svr4__ || _SCO_DS */
     
@@ -216,6 +216,7 @@
 #ifdef CONFIG_IPC
     SIGNAL_SetHandler( SIGUSR2, (void (*)())stop_wait ); /* For IPC */
 #endif
+    return TRUE;
 }
 
 
diff --git a/loader/task.c b/loader/task.c
index 43c7d87..1cfeb3a 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -468,7 +468,7 @@
     pTask->pdb.int20 = 0x20cd;
 #ifndef WINELIB
     pTask->pdb.dispatcher[0] = 0x9a;  /* ljmp */
-    *(DWORD *)&pTask->pdb.dispatcher[1] = MODULE_GetEntryPoint( GetModuleHandle("KERNEL"), 102 );  /* KERNEL.102 is DOS3Call() */
+    *(FARPROC16 *)&pTask->pdb.dispatcher[1] = MODULE_GetEntryPoint( GetModuleHandle("KERNEL"), 102 );  /* KERNEL.102 is DOS3Call() */
     pTask->pdb.savedint22 = INT_GetHandler( 0x22 );
     pTask->pdb.savedint23 = INT_GetHandler( 0x23 );
     pTask->pdb.savedint24 = INT_GetHandler( 0x24 );
@@ -766,10 +766,9 @@
 #ifdef WINELIB
 void InitTask(void)
 #else
-void InitTask( SIGCONTEXT context )
+void InitTask( SIGCONTEXT *context )
 #endif
 {
-    static int firstTask = 1;
     TDB *pTask;
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
@@ -777,27 +776,11 @@
     LONG stacklow, stackhi;
 
 #ifndef WINELIB
-    EAX_reg(&context) = 0;
+    EAX_reg(context) = 0;
 #endif
     if (!(pTask = (TDB *)GlobalLock16( hCurrentTask ))) return;
     if (!(pModule = MODULE_GetPtr( pTask->hModule ))) return;
 
-    if (firstTask)
-    {
-        extern BOOL WIDGETS_Init(void);
-        extern BOOL WIN_CreateDesktopWindow(void);
-
-        /* Perform global initialisations that need a task context */
-
-          /* Initialize built-in window classes */
-        if (!WIDGETS_Init()) return;
-
-          /* Create desktop window */
-        if (!WIN_CreateDesktopWindow()) return;
-
-        firstTask = 0;
-    }
-
 #ifndef WINELIB
     NE_InitializeDLLs( pTask->hModule );
 
@@ -809,13 +792,13 @@
      * di     instance handle of the new task
      * es:bx  pointer to command-line inside PSP
      */
-    EAX_reg(&context) = 1;
-    EBX_reg(&context) = 0x81;
-    ECX_reg(&context) = pModule->stack_size;
-    EDX_reg(&context) = pTask->nCmdShow;
-    ESI_reg(&context) = (DWORD)pTask->hPrevInstance;
-    EDI_reg(&context) = (DWORD)pTask->hInstance;
-    ES_reg (&context) = (WORD)pTask->hPDB;
+    EAX_reg(context) = 1;
+    EBX_reg(context) = 0x81;
+    ECX_reg(context) = pModule->stack_size;
+    EDX_reg(context) = pTask->nCmdShow;
+    ESI_reg(context) = (DWORD)pTask->hPrevInstance;
+    EDI_reg(context) = (DWORD)pTask->hInstance;
+    ES_reg (context) = (WORD)pTask->hPDB;
 
     /* Initialize the local heap */
     if ( pModule->heap_size )
@@ -824,7 +807,6 @@
     }    
 #endif
 
-
     /* Initialize the INSTANCEDATA structure */
     pSegTable = NE_SEG_TABLE( pModule );
     stacklow = pSegTable[pModule->ss - 1].minsize;
@@ -1059,7 +1041,7 @@
 /***********************************************************************
  *           GetTaskQueue  (KERNEL.35)
  */
-HQUEUE GetTaskQueue( HANDLE hTask )
+HQUEUE16 GetTaskQueue( HTASK16 hTask )
 {
     TDB *pTask;
 
@@ -1073,9 +1055,9 @@
  *           GetTaskQueueDS  (KERNEL.118)
  */
 #ifndef WINELIB
-void GetTaskQueueDS( SIGCONTEXT context )
+void GetTaskQueueDS( SIGCONTEXT *context )
 {
-    DS_reg(&context) = GlobalHandleToSel( GetTaskQueue(0) );
+    DS_reg(context) = GlobalHandleToSel( GetTaskQueue(0) );
 }
 #endif  /* WINELIB */
 
@@ -1084,9 +1066,9 @@
  *           GetTaskQueueES  (KERNEL.119)
  */
 #ifndef WINELIB
-void GetTaskQueueES( SIGCONTEXT context )
+void GetTaskQueueES( SIGCONTEXT *context )
 {
-    ES_reg(&context) = GlobalHandleToSel( GetTaskQueue(0) );
+    ES_reg(context) = GlobalHandleToSel( GetTaskQueue(0) );
 }
 #endif  /* WINELIB */
 
@@ -1171,7 +1153,7 @@
 /***********************************************************************
  *           GetTaskDS   (KERNEL.155)
  */
-HINSTANCE GetTaskDS(void)
+HINSTANCE16 GetTaskDS(void)
 {
     TDB *pTask;
 
diff --git a/memory/atom.c b/memory/atom.c
index 4d8db56..986df85 100644
--- a/memory/atom.c
+++ b/memory/atom.c
@@ -20,7 +20,6 @@
 #include "instance.h"
 #include "ldt.h"
 #include "stackframe.h"
-#include "string32.h"
 #include "user.h"
 
 #ifdef CONFIG_IPC
@@ -360,7 +359,7 @@
 {
     char buffer[MAX_ATOM_LEN+1];
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
-    STRING32_UniToAnsi( buffer, str );  /* FIXME: 'str' length? */
+    lstrcpynWtoA( buffer, str, sizeof(buffer) );
     return ATOM_AddAtom( USER_HeapSel, buffer );
 }
 
@@ -407,7 +406,7 @@
 {
     char buffer[MAX_ATOM_LEN+1];
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
-    STRING32_UniToAnsi( buffer, str );  /* FIXME: 'str' length? */
+    lstrcpynWtoA( buffer, str, sizeof(buffer) );
     return ATOM_FindAtom( USER_HeapSel, buffer );
 }
 
@@ -437,10 +436,8 @@
  */
 UINT32 GlobalGetAtomName32W( ATOM atom, LPWSTR buffer, INT32 count )
 {
-    UINT32 len;
     char tmp[MAX_ATOM_LEN+1];
-    if (count > sizeof(tmp)) count = sizeof(tmp);
-    len = ATOM_GetAtomName( USER_HeapSel, atom, tmp, count );
-    STRING32_AnsiToUni( buffer, tmp );  /* FIXME: len? */
-    return len;
+    ATOM_GetAtomName( USER_HeapSel, atom, tmp, sizeof(tmp) );
+    lstrcpynAtoW( buffer, tmp, count );
+    return lstrlen32W( buffer );
 }
diff --git a/memory/global.c b/memory/global.c
index 111885c..c21f5ce 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -405,7 +405,6 @@
  */
 SEGPTR WIN16_GlobalLock16( HGLOBAL16 handle )
 {
-#ifndef WINELIB
     dprintf_global( stddeb, "WIN16_GlobalLock16(%04x) -> %08lx\n",
                     handle, MAKELONG( 0, GlobalHandleToSel(handle)) );
     if (!handle) return 0;
@@ -417,9 +416,6 @@
 
     if (!GET_ARENA_PTR(handle)->base) return (SEGPTR)0;
     return PTR_SEG_OFF_TO_SEGPTR( GlobalHandleToSel(handle), 0 );
-#else  /* WINELIB */
-    return GlobalLock16( handle );
-#endif  /* WINELIB */
 }
 
 
diff --git a/memory/heap.c b/memory/heap.c
index a2a60b6..acdd8df 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -938,7 +938,7 @@
     flags &= HEAP_NO_SERIALIZE;
     flags |= heapPtr->flags;
     if (!(flags & HEAP_NO_SERIALIZE)) HeapLock( heap );
-    if (!HeapValidate( heap, HEAP_NO_SERIALIZE, ptr ))
+    if (!ptr || !HeapValidate( heap, HEAP_NO_SERIALIZE, ptr ))
     {
         if (!(flags & HEAP_NO_SERIALIZE)) HeapUnlock( heap );
         SetLastError( ERROR_INVALID_PARAMETER );
diff --git a/memory/ldt.c b/memory/ldt.c
index 5ed3cbfd..20ba25e 100644
--- a/memory/ldt.c
+++ b/memory/ldt.c
@@ -202,7 +202,6 @@
  *
  * Print the content of the LDT on stdout.
  */
-#ifndef WINELIB
 void LDT_Print( int start, int length )
 {
     int i;
@@ -232,4 +231,3 @@
                 flags[0], flags[1], flags[2] );
     }
 }
-#endif  /* WINELIB */
diff --git a/memory/local.c b/memory/local.c
index 5994e61..502d738 100644
--- a/memory/local.c
+++ b/memory/local.c
@@ -1603,9 +1603,6 @@
     return TRUE;
 }
 
-#ifndef WINELIB
-
-#endif  /* WINELIB */
 
 /***********************************************************************
  *           LocalAlloc32   (KERNEL32.371)
diff --git a/memory/string.c b/memory/string.c
index 88cd5f5..399eb06 100644
--- a/memory/string.c
+++ b/memory/string.c
@@ -176,6 +176,7 @@
  */
 LPSTR lstrcpy32A( LPSTR dst, LPCSTR src )
 {
+    if (!src || !dst) return NULL;
     strcpy( dst, src );
     return dst;
 }
@@ -262,15 +263,6 @@
 
 
 /***********************************************************************
- *           lstrncmp16   (Not a Windows API)
- */
-INT16 lstrncmp16( LPCSTR str1, LPCSTR str2, INT16 n )
-{
-    return (INT16)lstrncmp32A( str1, str2, n );
-}
-
-
-/***********************************************************************
  *           lstrncmp32A   (Not a Windows API)
  */
 INT32 lstrncmp32A( LPCSTR str1, LPCSTR str2, INT32 n )
@@ -291,15 +283,6 @@
 
 
 /***********************************************************************
- *           lstrncmpi16   (Not a Windows API)
- */
-INT16 lstrncmpi16( LPCSTR str1, LPCSTR str2, INT16 n )
-{
-    return (INT16)lstrncmpi32A( str1, str2, n );
-}
-
-
-/***********************************************************************
  *           lstrncmpi32A   (Not a Windows API)
  */
 INT32 lstrncmpi32A( LPCSTR str1, LPCSTR str2, INT32 n )
@@ -337,6 +320,30 @@
 
 
 /***********************************************************************
+ *           lstrcpynAtoW   (Not a Windows API)
+ */
+LPWSTR lstrcpynAtoW( LPWSTR dst, LPCSTR src, INT32 n )
+{
+    LPWSTR p = dst;
+    while ((n-- > 1) && *src) *p++ = (WCHAR)(unsigned char)*src++;
+    *p = 0;
+    return dst;
+}
+
+
+/***********************************************************************
+ *           lstrcpynWtoA   (Not a Windows API)
+ */
+LPSTR lstrcpynWtoA( LPSTR dst, LPCWSTR src, INT32 n )
+{
+    LPSTR p = dst;
+    while ((n-- > 1) && *src) *p++ = (CHAR)*src++;
+    *p = 0;
+    return dst;
+}
+
+
+/***********************************************************************
  *           RtlFillMemory   (KERNEL32.441)
  */
 VOID RtlFillMemory( LPVOID ptr, UINT32 len, UINT32 fill )
@@ -359,7 +366,16 @@
         return;
     }
     /* do it the hard way (FIXME: could do better than this) */
-    while (len--) *((BYTE *)dst)++ = *((BYTE *)src)++;
+    if (dst < src)
+    {
+        while (len--) *((BYTE *)dst)++ = *((BYTE *)src)++;
+    }
+    else
+    {
+        dst = (BYTE *)dst + len - 1;
+        src = (BYTE *)src + len - 1;
+        while (len--) *((BYTE *)dst)-- = *((BYTE *)src)--;
+    }
 }
 
 
diff --git a/misc/commdlg.c b/misc/commdlg.c
index dc5a829..3745eaf 100644
--- a/misc/commdlg.c
+++ b/misc/commdlg.c
@@ -85,8 +85,8 @@
 
     hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpofn->hwndOwner,
-                                   MODULE_GetWndProcEntry16("FileOpenDlgProc"),
-                                   (DWORD)lpofn );
+                        (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
+                        (DWORD)lpofn );
 
     if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
     {
@@ -127,8 +127,8 @@
 
     hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpofn->hwndOwner,
-                                   MODULE_GetWndProcEntry16("FileSaveDlgProc"),
-                                   (DWORD)lpofn); 
+                        (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
+                        (DWORD)lpofn); 
     if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
     {
         if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( hDlgTmpl );
@@ -705,8 +705,8 @@
     hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
     if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
     bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
-                                        MODULE_GetWndProcEntry16("FindTextDlgProc"),
-                                        (DWORD)lpFind );
+                        (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
+                        (DWORD)lpFind );
     GlobalUnlock16( hDlgTmpl );
     SYSRES_FreeResource( hDlgTmpl );
     return bRet;
@@ -734,8 +734,8 @@
     hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
     if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
     bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
-                                        MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
-                                        (DWORD)lpFind );
+                     (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
+                     (DWORD)lpFind );
     GlobalUnlock16( hDlgTmpl );
     SYSRES_FreeResource( hDlgTmpl );
     return bRet;
@@ -980,10 +980,10 @@
 
     hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpPrint->hwndOwner,
-                                   (lpPrint->Flags & PD_PRINTSETUP) ?
-                                     MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
-                                     MODULE_GetWndProcEntry16("PrintDlgProc"),
-                                   (DWORD)lpPrint );
+                               (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
+                                MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
+                                MODULE_GetWndProcEntry16("PrintDlgProc")),
+                               (DWORD)lpPrint );
     SYSRES_FreeResource( hDlgTmpl );
     return bRet;
 }
@@ -1117,8 +1117,8 @@
     }
     hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChCol->hwndOwner,
-                                     MODULE_GetWndProcEntry16("ColorDlgProc"), 
-                                     (DWORD)lpChCol );
+                           (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
+                           (DWORD)lpChCol );
     if (!(lpChCol->Flags & CC_ENABLETEMPLATEHANDLE))
     {
         if (lpChCol->Flags & CC_ENABLETEMPLATE) FreeResource( hDlgTmpl );
@@ -1903,7 +1903,7 @@
    for (i=0x2bf;i<0x2c5;i++)
      SendMessage16(GetDlgItem(hDlg,i),EM_LIMITTEXT,3,0);      /* max 3 digits:  xyz  */
    if (CC_HookCallChk(lpp->lpcc))
-      res=CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
+      res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
    return res;
 }
 
@@ -2013,7 +2013,7 @@
 	       if (lpp->lpcc->hwndOwner)
 		   SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
 	       if (CC_HookCallChk(lpp->lpcc))
-		   CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,
+		   CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
 		      WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
 	       break;
 
@@ -2123,7 +2123,7 @@
      return FALSE;
   res=0;
   if (CC_HookCallChk(lpp->lpcc))
-     res=CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
+     res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
   if (res)
      return res;
  }
@@ -2198,8 +2198,8 @@
     }
     hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChFont->hwndOwner,
-                                   MODULE_GetWndProcEntry16("FormatCharDlgProc"), 
-                                   (DWORD)lpChFont );
+                      (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
+                      (DWORD)lpChFont );
     if (!(lpChFont->Flags & CF_ENABLETEMPLATEHANDLE))
     {
         if (lpChFont->Flags & CF_ENABLETEMPLATE) FreeResource( hDlgTmpl );
@@ -2290,7 +2290,7 @@
    {
      lplf->lfItalic=fontstyles[i].italic;
      lplf->lfWeight=fontstyles[i].weight;
-     hf=CreateFontIndirect(lplf);
+     hf=CreateFontIndirect16(lplf);
      hf=SelectObject(hdc,hf);
      GetTextMetrics16(hdc,lptm);
      hf=SelectObject(hdc,hf);
@@ -2698,7 +2698,7 @@
 		    lpxx->lfQuality=DEFAULT_QUALITY;
                     lpcf->iPointSize= -10*lpxx->lfHeight;
 
-		    hFont=CreateFontIndirect(lpxx);
+		    hFont=CreateFontIndirect16(lpxx);
 		    if (hFont)
 		      SendDlgItemMessage16(hDlg,stc6,WM_SETFONT,hFont,TRUE);
 		    /* FIXME: Delete old font ...? */  
diff --git a/misc/lstr.c b/misc/lstr.c
index e01fb7f..2c811e3 100644
--- a/misc/lstr.c
+++ b/misc/lstr.c
@@ -2,6 +2,7 @@
  * String functions
  *
  * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
+ * Copyright 1996 Marcus Meissner
  */
 
 #include <stdio.h>
@@ -17,6 +18,7 @@
 #include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
+#include "string32.h"
 
 #define ToUpper(c)	toupper(c)
 #define ToLower(c)	tolower(c)
@@ -61,25 +63,25 @@
 /* Funny to divide them between user and kernel. */
 
 /* IsCharAlpha USER 433 */
-BOOL IsCharAlpha(char ch)
+BOOL16 IsCharAlpha16(CHAR ch)
 {
   return isalpha(ch);   /* This is probably not right for NLS */
 }
 
 /* IsCharAlphanumeric USER 434 */
-BOOL IsCharAlphanumeric(char ch)
+BOOL16 IsCharAlphanumeric16(CHAR ch)
 {
-  return (ch < '0') ? 0 : (ch <= '9');
+    return isalnum(ch);
 }
 
 /* IsCharUpper USER 435 */
-BOOL IsCharUpper(char ch)
+BOOL16 IsCharUpper16(CHAR ch)
 {
   return isupper(ch);
 }
 
 /* IsCharLower USER 436 */
-BOOL IsCharLower(char ch)
+BOOL16 IsCharLower16(CHAR ch)
 {
   return islower(ch);
 }
@@ -203,7 +205,7 @@
 
 
 /* AnsiToOem Keyboard.5 */
-INT AnsiToOem(LPSTR lpAnsiStr, LPSTR lpOemStr)
+INT AnsiToOem(LPCSTR lpAnsiStr, LPSTR lpOemStr)
 {
     dprintf_keyboard(stddeb, "AnsiToOem: %s\n", lpAnsiStr);
     while(*lpAnsiStr){
@@ -214,7 +216,7 @@
 }
 
 /* OemToAnsi Keyboard.6 */
-BOOL OemToAnsi(LPSTR lpOemStr, LPSTR lpAnsiStr)
+BOOL OemToAnsi(LPCSTR lpOemStr, LPSTR lpAnsiStr)
 {
     dprintf_keyboard(stddeb, "OemToAnsi: %s\n", lpOemStr);
     while(*lpOemStr){
@@ -233,7 +235,7 @@
 }
 
 /* OemToAnsi Keyboard.135 */
-void OemToAnsiBuff(LPSTR lpOemStr, LPSTR lpAnsiStr, INT nLength)
+void OemToAnsiBuff(LPCSTR lpOemStr, LPSTR lpAnsiStr, INT nLength)
 {
   int i;
   for(i=0;i<nLength;i++)
@@ -257,3 +259,375 @@
              module ? module : "???", buffer );
     free( buffer );
 }
+
+/***********************************************************************
+ *           CharNextA   (USER32.28)
+ */
+LPSTR CharNext32A(LPCSTR x)
+{
+    if (*x) return (LPSTR)(x+1);
+    else return (LPSTR)x;
+}
+
+/***********************************************************************
+ *           CharNextExA   (USER32.29)
+ */
+LPSTR CharNextEx32A(WORD codepage,LPCSTR x,DWORD flags)
+{
+    /* FIXME: add DBCS / codepage stuff */
+    if (*x) return (LPSTR)(x+1);
+    else return (LPSTR)x;
+}
+
+/***********************************************************************
+ *           CharNextExW   (USER32.30)
+ */
+LPWSTR CharNextEx32W(WORD codepage,LPCWSTR x,DWORD flags)
+{
+    /* FIXME: add DBCS / codepage stuff */
+    if (*x) return (LPWSTR)(x+1);
+    else return (LPWSTR)x;
+}
+
+/***********************************************************************
+ *           CharNextW   (USER32.31)
+ */
+LPWSTR CharNext32W(LPCWSTR x)
+{
+    if (*x) return (LPWSTR)(x+1);
+    else return (LPWSTR)x;
+}
+
+/***********************************************************************
+ *           CharPrevA   (USER32.32)
+ */
+LPSTR CharPrev32A(LPCSTR start,LPCSTR x)
+{
+    if (x>start) return (LPSTR)(x-1);
+    else return (LPSTR)x;
+}
+
+/***********************************************************************
+ *           CharPrevExA   (USER32.33)
+ */
+LPSTR CharPrevEx32A(WORD codepage,LPCSTR start,LPCSTR x,DWORD flags)
+{
+    /* FIXME: add DBCS / codepage stuff */
+    if (x>start) return (LPSTR)(x-1);
+    else return (LPSTR)x;
+}
+
+/***********************************************************************
+ *           CharPrevExW   (USER32.34)
+ */
+LPWSTR CharPrevEx32W(WORD codepage,LPCWSTR start,LPCWSTR x,DWORD flags)
+{
+    /* FIXME: add DBCS / codepage stuff */
+    if (x>start) return (LPWSTR)(x-1);
+    else return (LPWSTR)x;
+}
+
+/***********************************************************************
+ *           CharPrevW   (USER32.35)
+ */
+LPWSTR CharPrev32W(LPCWSTR start,LPCWSTR x)
+{
+    if (x>start) return (LPWSTR)(x-1);
+    else return (LPWSTR)x;
+}
+
+/***********************************************************************
+ *           CharLowerA   (USER32.24)
+ * FIXME: handle current locale
+ */
+LPSTR CharLower32A(LPSTR x)
+{
+    LPSTR	s;
+
+    if (HIWORD(x))
+    {
+        s=x;
+        while (*s)
+        {
+            *s=tolower(*s);
+            s++;
+        }
+        return x;
+    }
+    else return (LPSTR)tolower(LOWORD(x));
+}
+
+/***********************************************************************
+ *           CharLowerBuffA   (USER32.25)
+ * FIXME: handle current locale
+ */
+DWORD CharLowerBuff32A(LPSTR x,DWORD buflen)
+{
+    DWORD done=0;
+
+    while (*x && (buflen--))
+    {
+        *x=tolower(*x);
+        x++;
+        done++;
+    }
+    return done;
+}
+
+/***********************************************************************
+ *           CharLowerBuffW   (USER32.26)
+ * FIXME: handle current locale
+ */
+DWORD CharLowerBuff32W(LPWSTR x,DWORD buflen)
+{
+    DWORD done=0;
+
+    while (*x && (buflen--))
+    {
+        *x=tolower(*x);
+        x++;
+        done++;
+    }
+    return done;
+}
+
+/***********************************************************************
+ *           CharLowerW   (USER32.27)
+ * FIXME: handle current locale
+ */
+LPWSTR CharLower32W(LPWSTR x)
+{
+    if (HIWORD(x))
+    {
+        LPWSTR s = x;
+        while (*s)
+        {
+            *s=tolower(*s);
+            s++;
+        }
+        return x;
+    }
+    else return (LPWSTR)tolower(LOWORD(x));
+}
+
+/***********************************************************************
+ *           CharUpperA   (USER32.40)
+ * FIXME: handle current locale
+ */
+LPSTR CharUpper32A(LPSTR x)
+{
+    if (HIWORD(x))
+    {
+        LPSTR s = x;
+        while (*s)
+        {
+            *s=toupper(*s);
+            s++;
+        }
+        return x;
+    }
+    else return (LPSTR)toupper(LOWORD(x));
+}
+
+/***********************************************************************
+ *           CharUpperBuffA   (USER32.41)
+ * FIXME: handle current locale
+ */
+DWORD CharUpperBuff32A(LPSTR x,DWORD buflen)
+{
+    DWORD done=0;
+
+    while (*x && (buflen--))
+    {
+        *x=toupper(*x);
+        x++;
+        done++;
+    }
+    return done;
+}
+
+/***********************************************************************
+ *           CharUpperBuffW   (USER32.42)
+ * FIXME: handle current locale
+ */
+DWORD CharUpperBuff32W(LPWSTR x,DWORD buflen)
+{
+    DWORD done=0;
+
+    while (*x && (buflen--))
+    {
+        *x=toupper(*x);
+        x++;
+        done++;
+    }
+    return done;
+}
+
+/***********************************************************************
+ *           CharUpperW   (USER32.43)
+ * FIXME: handle current locale
+ */
+LPWSTR CharUpper32W(LPWSTR x)
+{
+    if (HIWORD(x))
+    {
+        LPWSTR s = x;
+        while (*s)
+        {
+            *s=toupper(*s);
+            s++;
+        }
+        return x;
+    }
+    else return (LPWSTR)toupper(LOWORD(x));
+}
+
+/***********************************************************************
+ *           IsCharAlphaA   (USER32.330)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharAlpha32A(CHAR x)
+{
+    return isalpha(x);
+}
+
+/***********************************************************************
+ *           IsCharAlphaNumericA   (USER32.331)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharAlphaNumeric32A(CHAR x)
+{
+    return isalnum(x);
+}
+
+/***********************************************************************
+ *           IsCharAlphaNumericW   (USER32.332)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharAlphaNumeric32W(WCHAR x)
+{
+    return isalnum(x);
+}
+
+/***********************************************************************
+ *           IsCharAlphaW   (USER32.333)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharAlpha32W(WCHAR x)
+{
+    return isalpha(x);
+}
+
+/***********************************************************************
+ *           IsCharAlphaW   (USER32.334)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharLower32A(CHAR x)
+{
+    return islower(x);
+}
+
+/***********************************************************************
+ *           IsCharAlphaW   (USER32.335)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharLower32W(WCHAR x)
+{
+    return islower(x);
+}
+
+/***********************************************************************
+ *           IsCharAlphaW   (USER32.336)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharUpper32A(CHAR x)
+{
+    return isupper(x);
+}
+
+/***********************************************************************
+ *           IsCharAlphaW   (USER32.337)
+ * FIXME: handle current locale
+ */
+BOOL32 IsCharUpper32W(WCHAR x)
+{
+    return isupper(x);
+}
+
+/***********************************************************************
+ *           CharToOemA   (USER32.36)
+ */
+BOOL32 CharToOem32A(LPSTR s,LPSTR d)
+{
+    AnsiToOem(s,d);
+    return TRUE;
+}
+
+/***********************************************************************
+ *           CharToOemBuffA   (USER32.37)
+ */
+BOOL32 CharToOemBuff32A(LPSTR s,LPSTR d,DWORD len)
+{
+    AnsiToOemBuff(s,d,len);
+    return TRUE;
+}
+
+/***********************************************************************
+ *           CharToOemBuffW   (USER32.38)
+ */
+BOOL32 CharToOemBuff32W(LPCWSTR s,LPSTR d,DWORD len)
+{
+    LPSTR	x=STRING32_DupUniToAnsi(s);
+    AnsiToOemBuff(x,d,len);
+    return TRUE;
+}
+
+/***********************************************************************
+ *           CharToOemW   (USER32.39)
+ */
+BOOL32 CharToOem32W(LPCWSTR s,LPSTR d)
+{
+    LPSTR	x=STRING32_DupUniToAnsi(s);
+    AnsiToOem(x,d);
+    return TRUE;
+}
+
+/***********************************************************************
+ *           OemToCharA   (USER32.401)
+ */
+BOOL32 OemToChar32A(LPSTR s,LPSTR d)
+{
+    OemToAnsi(s,d);
+    return TRUE;
+}
+
+/***********************************************************************
+ *           OemToCharBuffA   (USER32.402)
+ */
+BOOL32 OemToCharBuff32A(LPSTR s,LPSTR d,DWORD len)
+{
+    OemToAnsiBuff(s,d,len);
+    return TRUE;
+}
+
+/***********************************************************************
+ *           OemToCharBuffW   (USER32.403)
+ */
+BOOL32 OemToCharBuff32W(LPCSTR s,LPWSTR d,DWORD len)
+{
+    LPSTR x=(char*)xmalloc(strlen(s));
+    OemToAnsiBuff((LPSTR)s,x,len);
+    STRING32_AnsiToUni(d,x);
+    return TRUE;
+}
+
+/***********************************************************************
+ *           OemToCharW   (USER32.404)
+ */
+BOOL32 OemToChar32W(LPCSTR s,LPWSTR d)
+{
+    LPSTR x=(char*)xmalloc(strlen(s));
+    OemToAnsi((LPSTR)s,x);
+    STRING32_AnsiToUni(d,x);
+    return TRUE;
+}
diff --git a/misc/lzexpand.c b/misc/lzexpand.c
index 7726d96..45b3655 100644
--- a/misc/lzexpand.c
+++ b/misc/lzexpand.c
@@ -25,7 +25,6 @@
 
 #define strdupW2A(x)	STRING32_DupUniToAnsi(x)
 #define strdupA2W(x)	STRING32_DupAnsiToUni(x)
-#define strcpyWA(a,b)	STRING32_UniToAnsi(a,b)
 #define strcpyAW(a,b)	STRING32_AnsiToUni(a,b)
 
 /* The readahead length of the decompressor. Reading single bytes
@@ -470,6 +469,23 @@
 #undef BUFLEN
 }
 
+/* reverses GetExpandedPathname */
+static LPSTR LZEXPAND_MangleName( LPCSTR fn )
+{
+    char *p;
+    char *mfn = (char *)xmalloc( strlen(fn) + 3 ); /* "._" and \0 */
+    strcpy( mfn, fn );
+    if (!(p = strrchr( mfn, '\\' ))) p = mfn;
+    if ((p = strchr( p, '.' )))
+    {
+        p++;
+        if (strlen(p) < 3) strcat( p, "_" );  /* append '_' */
+        else p[strlen(p)-1] = '_';  /* replace last character */
+    }
+    else strcat( mfn, "._" );	/* append "._" */
+    return mfn;
+}
+
 /*
  * LZOpenFile				[LZEXPAND.2]
  * Opens a file. If not compressed, open it as a normal file.
@@ -481,6 +497,12 @@
 	dprintf_file(stddeb,"LZOpenFile(%s,%p,%d)\n",fn,ofs,mode);
 	/* 0x70 represents all OF_SHARE_* flags, ignore them for the check */
 	fd=OpenFile(fn,ofs,mode);
+	if (fd==HFILE_ERROR)
+        {
+            LPSTR mfn = LZEXPAND_MangleName(fn);
+            fd = OpenFile(mfn,ofs,mode);
+            free( mfn );
+	}
 	if ((mode&~0x70)!=OF_READ)
 		return fd;
 	if (fd==HFILE_ERROR)
diff --git a/misc/main.c b/misc/main.c
index 2e01aa0..34dbccc 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -17,7 +17,6 @@
 #include <X11/Xresource.h>
 #include <X11/Xutil.h>
 #include <X11/cursorfont.h>
-#include "wine.h"
 #include "message.h"
 #include "module.h"
 #include "msdos.h"
@@ -25,6 +24,7 @@
 #include "winsock.h"
 #include "options.h"
 #include "desktop.h"
+#include "registers.h"
 #include "shell.h"
 #include "winbase.h"
 #include "string32.h"
@@ -1021,9 +1021,6 @@
 	XKeyboardControl	keyboard_value;
 
 
-	fprintf(stderr, "SystemParametersInfo: action %d, param %x, flag %x\n", 
-			uAction, uParam, fuWinIni);
-
 	switch (uAction) {
 		case SPI_GETBEEP:
 			XGetKeyboardControl(display, &keyboard_state);
diff --git a/misc/ole2disp.c b/misc/ole2disp.c
index e738adc..69a08bf 100644
--- a/misc/ole2disp.c
+++ b/misc/ole2disp.c
@@ -6,8 +6,7 @@
 
 #include "windows.h"
 #include "ole2.h"
-#include "global.h"
-#include "local.h"
+#include "heap.h"
 #include "ldt.h"
 #include "stddebug.h"
 #include "debug.h"
@@ -17,39 +16,21 @@
    as ISO-8859 */
 
 typedef DWORD	BSTR;
-HGLOBAL	BSTRheapsel=0;
-#define BSTR_HEAP_SIZE	65536
 
 static BSTR BSTR_AllocBytes(int n)
 {
-	HLOCAL16 mem;
-	if(!BSTRheapsel)
-	{
-		BSTRheapsel=GlobalAlloc16(GMEM_FIXED,BSTR_HEAP_SIZE);
-		LocalInit(BSTRheapsel,0,BSTR_HEAP_SIZE-1);
-	}
-	if(!BSTRheapsel)
-		return 0;
-	mem=LOCAL_Alloc(BSTRheapsel,LMEM_FIXED,n);
-#ifdef WINELIB32
-	return (BSTR)mem;
-#else
-	return mem ? MAKELONG(mem,BSTRheapsel) : 0;
-#endif
+    void *ptr = SEGPTR_ALLOC(n);
+    return SEGPTR_GET(ptr);
 }
 
 static void BSTR_Free(BSTR in)
 {
-#ifdef WINELIB32
-	LOCAL_Free(BSTRheapsel, (HANDLE)in);
-#else
-	LOCAL_Free(BSTRheapsel, LOWORD(in));
-#endif
+    SEGPTR_FREE( PTR_SEG_TO_LIN(in) );
 }
 
 static void* BSTR_GetAddr(BSTR in)
 {
-	return in ? PTR_SEG_TO_LIN(in) : 0;
+    return in ? PTR_SEG_TO_LIN(in) : 0;
 }
 
 /***********************************************************************
diff --git a/misc/ole2nls.c b/misc/ole2nls.c
index 110fa55..5a59bc32 100644
--- a/misc/ole2nls.c
+++ b/misc/ole2nls.c
@@ -24,16 +24,16 @@
     switch(Options.language)
     {
     case LANG_En: return 0x09;
-    case LANG_Es: return 0x07; /* Just a Guess :-) */
+    case LANG_Es: return 0x0a;
     case LANG_De: return 0x07;
     case LANG_No: return 0x14;
-    case LANG_Fr:
-    case LANG_Fi:
-    case LANG_Da:
-    case LANG_Cz:
-    case LANG_Eo:
-    case LANG_It:
-    case LANG_Ko:
+    case LANG_Fr: return 0x0c;
+    case LANG_Fi: return 0x0b;
+    case LANG_Da: return 0x06;
+    case LANG_Cz: return 0x05;
+    case LANG_Eo: return 0x25; /* not official */
+    case LANG_It: return 0x10;
+    case LANG_Ko: return 0x12;
     default:
 	return 0;  /* Neutral language */
     }
@@ -525,7 +525,130 @@
 /* LOCVAL(LOCALE_INEGSYMPRECEDES) */
 /* LOCVAL(LOCALE_INEGSEPBYSPACE) */
     break;  /* LANG(Eo) */
-    
+
+    case LANG_Fi:
+LOCVAL(LOCALE_ILANGUAGE,"11")
+LOCVAL(LOCALE_SLANGUAGE,"Suomi")
+LOCVAL(LOCALE_SENGLANGUAGE,"Finnish")
+LOCVAL(LOCALE_SABBREVLANGNAME,"fin")
+LOCVAL(LOCALE_SNATIVELANGNAME,"suomi")
+LOCVAL(LOCALE_ICOUNTRY,"49")
+LOCVAL(LOCALE_SCOUNTRY,"Suomi")
+LOCVAL(LOCALE_SENGCOUNTRY,"Finland")
+LOCVAL(LOCALE_SABBREVCTRYNAME,"Fin")
+LOCVAL(LOCALE_SNATIVECTRYNAME,"Suomi")
+LOCVAL(LOCALE_IDEFAULTLANGUAGE,"11")
+LOCVAL(LOCALE_IDEFAULTCOUNTRY,"358")
+/* 
+LOCVAL(LOCALE_IDEFAULTCODEPAGE)
+LOCVAL(LOCALE_IDEFAULTANSICODEPAGE)
+*/
+LOCVAL(LOCALE_SLIST,";")
+LOCVAL(LOCALE_IMEASURE,"0")
+LOCVAL(LOCALE_SDECIMAL,",")
+LOCVAL(LOCALE_STHOUSAND,".")
+/*
+LOCVAL(LOCALE_SGROUPING)
+*/
+LOCVAL(LOCALE_IDIGITS,"2")
+LOCVAL(LOCALE_ILZERO,"1")
+/*
+LOCVAL(LOCALE_INEGNUMBER)
+Is this "0123456789" ??
+LOCVAL(LOCALE_SNATIVEDIGITS)
+*/
+LOCVAL(LOCALE_SCURRENCY,"mk")
+/*
+LOCVAL(LOCALE_SINTLSYMBOL)
+LOCVAL(LOCALE_SMONDECIMALSEP)
+LOCVAL(LOCALE_SMONTHOUSANDSEP)
+LOCVAL(LOCALE_SMONGROUPING)
+*/
+LOCVAL(LOCALE_ICURRDIGITS,"2")
+/*
+LOCVAL(LOCALE_IINTLCURRDIGITS)
+*/
+LOCVAL(LOCALE_ICURRENCY,"3")
+LOCVAL(LOCALE_INEGCURR,"8")
+LOCVAL(LOCALE_SDATE,".")
+LOCVAL(LOCALE_STIME,":")
+LOCVAL(LOCALE_SSHORTDATE,"dd.MM.yyyy")
+LOCVAL(LOCALE_SLONGDATE,"ddd, d. MMMM yyyy")
+/*
+LOCVAL(LOCALE_STIMEFORMAT)
+*/
+LOCVAL(LOCALE_IDATE,"1")
+/*
+LOCVAL(LOCALE_ILDATE)
+*/
+LOCVAL(LOCALE_ITIME,"1")
+/*
+LOCVAL(LOCALE_ITIMEMARKPOSN)
+LOCVAL(LOCALE_ICENTURY)
+*/
+LOCVAL(LOCALE_ITLZERO,"1")
+/*
+LOCVAL(LOCALE_IDAYLZERO)
+LOCVAL(LOCALE_IMONLZERO)
+LOCVAL(LOCALE_S1159)
+LOCVAL(LOCALE_S2359)
+LOCVAL(LOCALE_ICALENDARTYPE)
+LOCVAL(LOCALE_IOPTIONALCALENDAR)
+LOCVAL(LOCALE_IFIRSTDAYOFWEEK)
+LOCVAL(LOCALE_IFIRSTWEEKOFYEAR)
+*/
+LOCVAL(LOCALE_SDAYNAME1,"maanantai")
+LOCVAL(LOCALE_SDAYNAME2,"tiistai")
+LOCVAL(LOCALE_SDAYNAME3,"keskiviikko")
+LOCVAL(LOCALE_SDAYNAME4,"torstai")
+LOCVAL(LOCALE_SDAYNAME5,"perjantai")
+LOCVAL(LOCALE_SDAYNAME6,"lauantai")
+LOCVAL(LOCALE_SDAYNAME7,"sunnuntai")
+LOCVAL(LOCALE_SABBREVDAYNAME1,"Ma")
+LOCVAL(LOCALE_SABBREVDAYNAME2,"Ti")
+LOCVAL(LOCALE_SABBREVDAYNAME3,"Ke")
+LOCVAL(LOCALE_SABBREVDAYNAME4,"To")
+LOCVAL(LOCALE_SABBREVDAYNAME5,"Pe")
+LOCVAL(LOCALE_SABBREVDAYNAME6,"La")
+LOCVAL(LOCALE_SABBREVDAYNAME7,"Su")
+LOCVAL(LOCALE_SMONTHNAME1,"tammikuu")
+LOCVAL(LOCALE_SMONTHNAME2,"helmikuu")
+LOCVAL(LOCALE_SMONTHNAME3,"maaliskuu")
+LOCVAL(LOCALE_SMONTHNAME4,"huhtikuu")
+LOCVAL(LOCALE_SMONTHNAME5,"toukokuu")
+LOCVAL(LOCALE_SMONTHNAME6,"kesäkuu")
+LOCVAL(LOCALE_SMONTHNAME7,"heinäkuu")
+LOCVAL(LOCALE_SMONTHNAME8,"elokuu")
+LOCVAL(LOCALE_SMONTHNAME9,"syyskuu")
+LOCVAL(LOCALE_SMONTHNAME10,"lokakuu")
+LOCVAL(LOCALE_SMONTHNAME11,"marraskuu")
+LOCVAL(LOCALE_SMONTHNAME12,"joulukuu")
+LOCVAL(LOCALE_SMONTHNAME13,"")
+LOCVAL(LOCALE_SABBREVMONTHNAME1,"tammi")
+LOCVAL(LOCALE_SABBREVMONTHNAME2,"helmi")
+LOCVAL(LOCALE_SABBREVMONTHNAME3,"maalis")
+LOCVAL(LOCALE_SABBREVMONTHNAME4,"huhti")
+LOCVAL(LOCALE_SABBREVMONTHNAME5,"touko")
+LOCVAL(LOCALE_SABBREVMONTHNAME6,"kesä")
+LOCVAL(LOCALE_SABBREVMONTHNAME7,"heinä")
+LOCVAL(LOCALE_SABBREVMONTHNAME8,"elo")
+LOCVAL(LOCALE_SABBREVMONTHNAME9,"syys")
+LOCVAL(LOCALE_SABBREVMONTHNAME10,"loka")
+LOCVAL(LOCALE_SABBREVMONTHNAME11,"marras")
+LOCVAL(LOCALE_SABBREVMONTHNAME12,"joulu")
+LOCVAL(LOCALE_SABBREVMONTHNAME13,"")
+/*
+LOCVAL(LOCALE_SPOSITIVESIGN)
+LOCVAL(LOCALE_SNEGATIVESIGN)
+LOCVAL(LOCALE_IPOSSIGNPOSN)
+LOCVAL(LOCALE_INEGSIGNPOSN)
+LOCVAL(LOCALE_IPOSSYMPRECEDES)
+LOCVAL(LOCALE_IPOSSEPBYSPACE)
+LOCVAL(LOCALE_INEGSYMPRECEDES)
+LOCVAL(LOCALE_INEGSEPBYSPACE)
+*/
+    break;  /* LANG(Fi) */
+
     case LANG_It:
 LOCVAL(LOCALE_ILANGUAGE,"9")
 LOCVAL(LOCALE_SLANGUAGE,"Italiano")
@@ -671,11 +794,21 @@
 
 
 /***********************************************************************
- *           CompareStringA       (OLE2NLS.8)
- * This implementation ignores the locale, and trusts in libc
+ *           CompareString16       (OLE2NLS.8)
  */
-int CompareStringA(DWORD lcid, DWORD fdwStyle, 
-	char *s1, int l1, char *s2,int l2)
+UINT16 CompareString16(DWORD lcid,DWORD fdwStyle,
+	LPCSTR s1,DWORD l1,LPCSTR s2,DWORD l2)
+{
+	return (UINT16)CompareString32A(lcid,fdwStyle,s1,l1,s2,l2);
+}
+
+/***********************************************************************
+ *           CompareString32A   (KERNEL32.29)
+ * This implementation ignores the locale
+ * FIXME
+ */
+UINT32 CompareString32A(DWORD lcid, DWORD fdwStyle, 
+	LPCSTR s1, DWORD l1, LPCSTR s2,DWORD l2)
 {
 	int len,ret;
 	if(fdwStyle & NORM_IGNORENONSPACE)
@@ -700,6 +833,35 @@
 }
 
 /***********************************************************************
+ *           CompareString32W       (KERNEL32.30)
+ * This implementation ignores the locale
+ * FIXME
+ */
+UINT32 CompareString32W(DWORD lcid, DWORD fdwStyle, 
+	LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
+{
+	int len,ret;
+	if(fdwStyle & NORM_IGNORENONSPACE)
+		fprintf(stdnimp,"CompareStringW:IGNORENONSPACE not supprted\n");
+	if(fdwStyle & NORM_IGNORESYMBOLS)
+		fprintf(stdnimp,"CompareStringW:IGNORESYMBOLS not supported\n");
+
+	/* Is strcmp defaulting to string sort or to word sort?? */
+	/* FIXME: Handle NORM_STRINGSORT */
+	l1 = (l1==-1)?lstrlen32W(s1):l1;
+	l2 = (l2==-1)?lstrlen32W(s2):l2;
+	len = l1<l2 ? l1:l2;
+	ret = (fdwStyle & NORM_IGNORECASE) ?
+		lstrncmpi32W(s1,s2,len)	: lstrncmp32W(s1,s2,len);
+	/* not equal, return 1 or 3 */
+	if(ret!=0) return ret+2;
+	/* same len, return 2 */
+	if(l1==l2) return 2;
+	/* the longer one is lexically greater */
+	return (l1<l2)? 1 : 3;
+}
+
+/***********************************************************************
  *           SetLocalInfoA       (KERNEL32.499)
  */
 BOOL SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data) {
diff --git a/misc/port.c b/misc/port.c
index 165a6df..ef3b3d7 100644
--- a/misc/port.c
+++ b/misc/port.c
@@ -1,3 +1,4 @@
+#include <sys/types.h>
 #include <sys/time.h>
 
 #ifndef HAVE_USLEEP
@@ -9,7 +10,7 @@
     delay.tv_sec = 0;
     delay.tv_usec = useconds;
 
-    (void) select (0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &delay);
+    select( 0, 0, 0, 0, &delay );
     return 0;
 }
 
diff --git a/misc/shell.c b/misc/shell.c
index a8eb3f9..1025acb 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -140,7 +140,9 @@
     }
 
     /* First thing we need is the file's extension */
-    extension = strchr( lpFile, '.' ); /* Assumes first "." is the one... */
+    extension = strrchr( lpFile, '.' ); /* Assume last "." is the one; */
+					/* File->Run in progman uses */
+					/* .\FILE.EXE :( */
     if ((extension == NULL) || (extension == &lpFile[strlen(lpFile)]))
     {
 	return 31; /* no association */
@@ -179,7 +181,10 @@
 	    dprintf_exec(stddeb, "SHELL_FindExecutable: found %s\n",
 			 lpResult);
 	    return 33; /* Greater than 32 to indicate success FIXME */
-		       /* what are the correct values here? */
+		       /* According to the docs, I should be returning */
+		       /* a handle for the executable. Does this mean */
+		       /* I'm supposed to open the executable file or */
+		       /* something? More RTFM, I guess... */
 	}
 	tok=strtok(NULL, " \t");
     }
@@ -320,11 +325,7 @@
  
   switch(msg) {
    case WM_INITDIALOG:
-#ifdef WINELIB32
     SendDlgItemMessage32A(hWnd,stc1,STM_SETICON,lParam,0);
-#else
-    SendDlgItemMessage16(hWnd,stc1,STM_SETICON,LOWORD(lParam),0);
-#endif
     GetWindowText32A(hWnd, Template, sizeof(Template));
     sprintf(AppTitle, Template, AppName);
     SetWindowText32A(hWnd, AppTitle);
diff --git a/misc/spy.c b/misc/spy.c
index 8425ad9..1681c9e 100644
--- a/misc/spy.c
+++ b/misc/spy.c
@@ -461,7 +461,7 @@
     case SPY_SENDMESSAGE32:
         {
             char taskName[30];
-            HTASK hTask = GetWindowTask(hWnd);
+            HTASK hTask = GetWindowTask16(hWnd);
             if (hTask == GetCurrentTask()) strcpy( taskName, "self" );
             else if (!hTask) strcpy( taskName, "Wine" );
             else sprintf( taskName, "task %04x %s",
diff --git a/misc/user.c b/misc/user.c
index 8976d77..eadf06b 100644
--- a/misc/user.c
+++ b/misc/user.c
@@ -19,7 +19,6 @@
 
 WORD USER_HeapSel = 0;
 
-#ifndef WINELIB
 
 extern HTASK	TASK_GetNextTask(HTASK);
 extern void	QUEUE_SetDoomedQueue(HQUEUE);
@@ -62,7 +61,7 @@
 /***********************************************************************
  *           SystemHeapInfo   (TOOLHELP.71)
  */
-BOOL SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
+BOOL16 SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
 {
     pHeapInfo->wUserFreePercent = GetFreeSystemResources( GFSR_USERRESOURCES );
     pHeapInfo->wGDIFreePercent  = GetFreeSystemResources( GFSR_GDIRESOURCES );
@@ -71,7 +70,6 @@
     return TRUE;
 }
 
-#endif  /* WINELIB */
 
 /***********************************************************************
  *           TimerCount   (TOOLHELP.80)
diff --git a/miscemu/dosmem.c b/miscemu/dosmem.c
index ed5bd16..95f1aa0 100644
--- a/miscemu/dosmem.c
+++ b/miscemu/dosmem.c
@@ -16,7 +16,7 @@
 #include "module.h"
 
 
-HANDLE DOSMEM_BiosSeg;  /* BIOS data segment at 0x40:0 */
+HANDLE16 DOSMEM_BiosSeg;  /* BIOS data segment at 0x40:0 */
 
 
 #pragma pack(1)
@@ -84,7 +84,7 @@
  * Create the dos memory segments, and store them into the KERNEL
  * exported values. BUILTIN_Init() must already have been called.
  */
-BOOL DOSMEM_Init(void)
+BOOL32 DOSMEM_Init(void)
 {
     HMODULE16 hModule = GetModuleHandle( "KERNEL" );
     char *dosmem;
diff --git a/miscemu/dpmi.c b/miscemu/dpmi.c
index 4c7e67f..788f70b 100644
--- a/miscemu/dpmi.c
+++ b/miscemu/dpmi.c
@@ -11,8 +11,6 @@
 #include "windows.h"
 #include "ldt.h"
 #include "module.h"
-#include "registers.h"
-#include "wine.h"
 #include "miscemu.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
@@ -48,34 +46,34 @@
  *
  * Handler for int 31h (DPMI).
  */
-void INT_Int31Handler( SIGCONTEXT context )
+void INT_Int31Handler( SIGCONTEXT *context )
 {
     DWORD dw;
     BYTE *ptr;
 
-    RESET_CFLAG(&context);
-    switch(AX_reg(&context))
+    RESET_CFLAG(context);
+    switch(AX_reg(context))
     {
     case 0x0000:  /* Allocate LDT descriptors */
-        if (!(AX_reg(&context) = AllocSelectorArray( CX_reg(&context) )))
+        if (!(AX_reg(context) = AllocSelectorArray( CX_reg(context) )))
         {
-            AX_reg(&context) = 0x8011;  /* descriptor unavailable */
-            SET_CFLAG(&context);
+            AX_reg(context) = 0x8011;  /* descriptor unavailable */
+            SET_CFLAG(context);
         }
         break;
 
     case 0x0001:  /* Free LDT descriptor */
-        if (FreeSelector( BX_reg(&context) ))
+        if (FreeSelector( BX_reg(context) ))
         {
-            AX_reg(&context) = 0x8022;  /* invalid selector */
-            SET_CFLAG(&context);
+            AX_reg(context) = 0x8022;  /* invalid selector */
+            SET_CFLAG(context);
         }
         break;
 
     case 0x0002:  /* Real mode segment to descriptor */
         {
             WORD entryPoint = 0;  /* KERNEL entry point for descriptor */
-            switch(BX_reg(&context))
+            switch(BX_reg(context))
             {
             case 0x0000: entryPoint = 183; break;  /* __0000H */
             case 0x0040: entryPoint = 193; break;  /* __0040H */
@@ -88,97 +86,98 @@
             case 0xf000: entryPoint = 194; break;  /* __F000H */
             default:
                 fprintf( stderr, "DPMI: real-mode seg to descriptor %04x not possible\n",
-                         BX_reg(&context) );
-                AX_reg(&context) = 0x8011;
-                SET_CFLAG(&context);
+                         BX_reg(context) );
+                AX_reg(context) = 0x8011;
+                SET_CFLAG(context);
                 break;
             }
             if (entryPoint) 
-                AX_reg(&context) = LOWORD(MODULE_GetEntryPoint( 
+                AX_reg(context) = LOWORD(MODULE_GetEntryPoint( 
                                                    GetModuleHandle( "KERNEL" ),
                                                    entryPoint ));
         }
         break;
 
     case 0x0003:  /* Get next selector increment */
-        AX_reg(&context) = __AHINCR;
+        AX_reg(context) = __AHINCR;
         break;
 
     case 0x0004:  /* Lock selector (not supported) */
-        AX_reg(&context) = 0;  /* FIXME: is this a correct return value? */
+        AX_reg(context) = 0;  /* FIXME: is this a correct return value? */
         break;
 
     case 0x0005:  /* Unlock selector (not supported) */
-        AX_reg(&context) = 0;  /* FIXME: is this a correct return value? */
+        AX_reg(context) = 0;  /* FIXME: is this a correct return value? */
         break;
 
     case 0x0006:  /* Get selector base address */
-        if (!(dw = GetSelectorBase( BX_reg(&context) )))
+        if (!(dw = GetSelectorBase( BX_reg(context) )))
         {
-            AX_reg(&context) = 0x8022;  /* invalid selector */
-            SET_CFLAG(&context);
+            AX_reg(context) = 0x8022;  /* invalid selector */
+            SET_CFLAG(context);
         }
         else
         {
-            CX_reg(&context) = HIWORD(dw);
-            DX_reg(&context) = LOWORD(dw);
+            CX_reg(context) = HIWORD(dw);
+            DX_reg(context) = LOWORD(dw);
         }
         break;
 
     case 0x0007:  /* Set selector base address */
-        SetSelectorBase( BX_reg(&context),
-                         MAKELONG( DX_reg(&context), CX_reg(&context) ) );
+        SetSelectorBase( BX_reg(context),
+                         MAKELONG( DX_reg(context), CX_reg(context) ) );
         break;
 
     case 0x0008:  /* Set selector limit */
-        SetSelectorLimit( BX_reg(&context),
-                          MAKELONG( DX_reg(&context), CX_reg(&context) ) );
+        SetSelectorLimit( BX_reg(context),
+                          MAKELONG( DX_reg(context), CX_reg(context) ) );
         break;
 
     case 0x0009:  /* Set selector access rights */
-        SelectorAccessRights( BX_reg(&context), 1, CX_reg(&context) );
+        SelectorAccessRights( BX_reg(context), 1, CX_reg(context) );
 
     case 0x000a:  /* Allocate selector alias */
-        if (!(AX_reg(&context) = AllocCStoDSAlias( BX_reg(&context) )))
+        if (!(AX_reg(context) = AllocCStoDSAlias( BX_reg(context) )))
         {
-            AX_reg(&context) = 0x8011;  /* descriptor unavailable */
-            SET_CFLAG(&context);
+            AX_reg(context) = 0x8011;  /* descriptor unavailable */
+            SET_CFLAG(context);
         }
         break;
 
     case 0x000b:  /* Get descriptor */
         {
             ldt_entry entry;
-            LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context) ), &entry );
+            LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context) ), &entry );
             /* FIXME: should use ES:EDI for 32-bit clients */
-            LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(&context),
-                                                  DI_reg(&context) ), &entry );
+            LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context),
+                                                  DI_reg(context) ), &entry );
         }
         break;
 
     case 0x000c:  /* Set descriptor */
         {
             ldt_entry entry;
-            LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(&context),
-                                                  DI_reg(&context) ), &entry );
-            LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context) ), &entry );
+            LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context),
+                                                  DI_reg(context) ), &entry );
+            LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context) ), &entry );
         }
         break;
 
     case 0x000d:  /* Allocate specific LDT descriptor */
-        AX_reg(&context) = 0x8011; /* descriptor unavailable */
-        SET_CFLAG(&context);
+        AX_reg(context) = 0x8011; /* descriptor unavailable */
+        SET_CFLAG(context);
         break;
 
     case 0x0204:  /* Get protected mode interrupt vector */
-	dw = (DWORD)INT_GetHandler( BL_reg(&context) );
-	CX_reg(&context) = HIWORD(dw);
-	DX_reg(&context) = LOWORD(dw);
+	dw = (DWORD)INT_GetHandler( BL_reg(context) );
+	CX_reg(context) = HIWORD(dw);
+	DX_reg(context) = LOWORD(dw);
 	break;
 
     case 0x0205:  /* Set protected mode interrupt vector */
-	INT_SetHandler( BL_reg(&context),
-                     PTR_SEG_OFF_TO_SEGPTR(CX_reg(&context),DX_reg(&context)));
+	INT_SetHandler( BL_reg(context),
+                        (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context),
+                                                          DX_reg(context) ));
 	break;
 
     case 0x0300:  /* Simulate real mode interrupt 
@@ -187,100 +186,90 @@
         *  Currently we just print it out and return error.
         */
         {
-            REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(&context), DI_reg(&context) );
+            REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
             fprintf(stdnimp,
                     "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
                     "                ESI=%08lx EDI=%08lx ES=%04x DS=%04x\n",
-                    BL_reg(&context), p->eax, p->ebx, p->ecx, p->edx,
+                    BL_reg(context), p->eax, p->ebx, p->ecx, p->edx,
                     p->esi, p->edi, p->es, p->ds );
 
             /* Compton's 1995 encyclopedia does its MSCDEX calls through
              * this interrupt.  Why?  Who knows...
              */
-            if ((BL_reg(&context) == 0x2f) && ((p->eax & 0xFF00) == 0x1500))
+            if ((BL_reg(context) == 0x2f) && ((p->eax & 0xFF00) == 0x1500))
             {
-                SIGCONTEXT context2;
-                EAX_reg(&context2) = p->eax;
-                EBX_reg(&context2) = p->ebx;
-                ECX_reg(&context2) = p->ecx;
-                EDX_reg(&context2) = p->edx;
-                ES_reg(&context2) = p->es;
-                do_mscdex(&context2);
-                p->eax = EAX_reg(&context2);
-                p->ebx = EBX_reg(&context2);
-                p->ecx = ECX_reg(&context2);
-                p->edx = EDX_reg(&context2);
+                do_mscdex( context );
             }
-            else SET_CFLAG(&context);
+            else SET_CFLAG(context);
         }
         break;
 
     case 0x0301:  /* Call real mode procedure with far return */
         {
-            REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(&context), DI_reg(&context) );
+            REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
             fprintf(stdnimp,
                     "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
                     "              ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
                     p->eax, p->ebx, p->ecx, p->edx,
                     p->esi, p->edi, p->es, p->ds, p->cs, p->ip );
-            SET_CFLAG(&context);
+            SET_CFLAG(context);
         }
         break;
 
     case 0x0302:  /* Call real mode procedure with interrupt return */
         {
-            REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(&context), DI_reg(&context) );
+            REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
             fprintf(stdnimp,
                     "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
                     "                  ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
                     p->eax, p->ebx, p->ecx, p->edx,
                     p->esi, p->edi, p->es, p->ds, p->cs, p->ip );
-            SET_CFLAG(&context);
+            SET_CFLAG(context);
         }
         break;
 
     case 0x0400:  /* Get DPMI version */
-        AX_reg(&context) = 0x005a;  /* DPMI version 0.90 */
-        BX_reg(&context) = 0x0005;  /* Flags: 32-bit, virtual memory */
-        CL_reg(&context) = runtime_cpu ();
-        DX_reg(&context) = 0x0102;  /* Master/slave interrupt controller base*/
+        AX_reg(context) = 0x005a;  /* DPMI version 0.90 */
+        BX_reg(context) = 0x0005;  /* Flags: 32-bit, virtual memory */
+        CL_reg(context) = runtime_cpu ();
+        DX_reg(context) = 0x0102;  /* Master/slave interrupt controller base*/
         break;
 
     case 0x0500:  /* Get free memory information */
-        ptr = (BYTE *)PTR_SEG_OFF_TO_LIN( ES_reg(&context), DI_reg(&context) );
+        ptr = (BYTE *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
         *(DWORD *)ptr = 0x00ff0000; /* Largest block available */
         memset( ptr + 4, 0xff, 0x2c );  /* No other information supported */
         break;
 
     case 0x0501:  /* Allocate memory block */
-        if (!(ptr = (BYTE *)malloc( MAKELONG( CX_reg(&context),
-                                              BX_reg(&context) ) )))
+        if (!(ptr = (BYTE *)malloc( MAKELONG( CX_reg(context),
+                                              BX_reg(context) ) )))
         {
-            AX_reg(&context) = 0x8012;  /* linear memory not available */
-            SET_CFLAG(&context);
+            AX_reg(context) = 0x8012;  /* linear memory not available */
+            SET_CFLAG(context);
         }
         else
         {
-            BX_reg(&context) = SI_reg(&context) = HIWORD(ptr);
-            CX_reg(&context) = DI_reg(&context) = LOWORD(ptr);
+            BX_reg(context) = SI_reg(context) = HIWORD(ptr);
+            CX_reg(context) = DI_reg(context) = LOWORD(ptr);
         }
         break;
 
     case 0x0502:  /* Free memory block */
-        free( (void *)MAKELONG( DI_reg(&context), SI_reg(&context) ) );
+        free( (void *)MAKELONG( DI_reg(context), SI_reg(context) ) );
         break;
 
     case 0x0503:  /* Resize memory block */
-        if (!(ptr = (BYTE *)realloc( (void *)MAKELONG(DI_reg(&context),SI_reg(&context)),
-                                     MAKELONG(CX_reg(&context),BX_reg(&context)))))
+        if (!(ptr = (BYTE *)realloc( (void *)MAKELONG(DI_reg(context),SI_reg(context)),
+                                     MAKELONG(CX_reg(context),BX_reg(context)))))
         {
-            AX_reg(&context) = 0x8012;  /* linear memory not available */
-            SET_CFLAG(&context);
+            AX_reg(context) = 0x8012;  /* linear memory not available */
+            SET_CFLAG(context);
         }
         else
         {
-            BX_reg(&context) = SI_reg(&context) = HIWORD(ptr);
-            CX_reg(&context) = DI_reg(&context) = LOWORD(ptr);
+            BX_reg(context) = SI_reg(context) = HIWORD(ptr);
+            CX_reg(context) = DI_reg(context) = LOWORD(ptr);
         }
         break;
 
@@ -297,8 +286,8 @@
         break;  /* Just ignore it */
 
     case 0x0604:  /* Get page size */
-        BX_reg(&context) = 0;
-        CX_reg(&context) = 4096;
+        BX_reg(context) = 0;
+        CX_reg(context) = 4096;
 	break;
 
     case 0x0702:  /* Mark page as demand-paging candidate */
@@ -308,9 +297,9 @@
         break;  /* Just ignore it */
 
     default:
-        INT_BARF( &context, 0x31 );
-        AX_reg(&context) = 0x8001;  /* unsupported function */
-        SET_CFLAG(&context);
+        INT_BARF( context, 0x31 );
+        AX_reg(context) = 0x8001;  /* unsupported function */
+        SET_CFLAG(context);
         break;
     }
 }
diff --git a/miscemu/emulate.c b/miscemu/emulate.c
index 37dec4e..0fcdc7e 100644
--- a/miscemu/emulate.c
+++ b/miscemu/emulate.c
@@ -1,8 +1,6 @@
 #include <stdlib.h>
 #include <stdio.h>
-#include "wine.h"
 #include "miscemu.h"
-#include "registers.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
 #include "debug.h"
@@ -30,27 +28,27 @@
  */
 /* FIXME: Only skeletal implementation for now */
 
-void WIN87_fpmath( SIGCONTEXT context )
+void WIN87_fpmath( SIGCONTEXT *context )
 {
     dprintf_int(stddeb, "_fpmath: (cs:eip=%x:%lx es=%x bx=%04x ax=%04x dx==%04x)\n",
-                 CS_reg(&context), EIP_reg(&context),
-                 ES_reg(&context), BX_reg(&context),
-                 AX_reg(&context), DX_reg(&context) );
+                 CS_reg(context), EIP_reg(context),
+                 ES_reg(context), BX_reg(context),
+                 AX_reg(context), DX_reg(context) );
 
-    switch(BX_reg(&context))
+    switch(BX_reg(context))
     {
     case 0: /* install (increase instanceref) emulator, install NMI vector */
-        AX_reg(&context) = 0;
+        AX_reg(context) = 0;
         break;
 
     case 1: /* Init Emulator */
-        AX_reg(&context) = 0;
+        AX_reg(context) = 0;
         break;
 
     case 2: /* deinstall emulator (decrease instanceref), deinstall NMI vector	
              * if zero. Every '0' call should have a matching '2' call.
              */
-        AX_reg(&context) = 0;   	
+        AX_reg(context) = 0;   	
         break;
 
     case 3:
@@ -79,8 +77,8 @@
 /* FIXME: could someone who really understands asm() fix this please? --AJ */
 /*            __asm__("fistp %0;wait" : "=m" (dw) : : "memory"); */
             dprintf_int(stddeb,"emulate.c:On top of stack was %ld\n",dw);
-            AX_reg(&context) = LOWORD(dw);
-            DX_reg(&context) = HIWORD(dw);
+            AX_reg(context) = LOWORD(dw);
+            DX_reg(context) = HIWORD(dw);
         }
         break;
 
@@ -91,19 +89,19 @@
         break;
 
     case 10: /* dunno. but looks like returning nr. of things on stack in AX */
-	AX_reg(&context) = 0;
+	AX_reg(context) = 0;
         break;
 
     case 11: /* just returns the installed flag in DX:AX */
-        DX_reg(&context) = 0;
-        AX_reg(&context) = 1;
+        DX_reg(context) = 0;
+        AX_reg(context) = 1;
         break;
 
     case 12: /* save AX in some internal state var */
         break;
 
     default: /* error. Say that loud and clear */
-        AX_reg(&context) = DX_reg(&context) = 0xFFFF;
+        AX_reg(context) = DX_reg(context) = 0xFFFF;
         break;
     }
 }
diff --git a/miscemu/instr.c b/miscemu/instr.c
index 0b2e957..3f19015 100644
--- a/miscemu/instr.c
+++ b/miscemu/instr.c
@@ -8,7 +8,6 @@
 #include "windows.h"
 #include "ldt.h"
 #include "miscemu.h"
-#include "registers.h"
 
 
 #define STACK_reg(context) \
@@ -279,7 +278,7 @@
  *
  * Emulate a priviledged instruction. Returns TRUE if emulation successful.
  */
-BOOL INSTR_EmulateInstruction( SIGCONTEXT *context )
+BOOL32 INSTR_EmulateInstruction( SIGCONTEXT *context )
 {
     int prefix, segprefix, prefixlen, len, repX, long_op, long_addr;
     BYTE *instr;
@@ -552,7 +551,7 @@
             }
             else
             {
-                SEGPTR addr = INT_GetHandler( instr[1] );
+                FARPROC16 addr = INT_GetHandler( instr[1] );
                 WORD *stack = (WORD *)STACK_PTR( context );
                 /* Push the flags and return address on the stack */
                 *(--stack) = FL_reg(context);
diff --git a/miscemu/int10.c b/miscemu/int10.c
index c22ba05..f9f7cf2 100644
--- a/miscemu/int10.c
+++ b/miscemu/int10.c
@@ -1,7 +1,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include "registers.h"
-#include "wine.h"
 #include "miscemu.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
@@ -13,27 +11,27 @@
  *
  * Handler for int 10h (video).
  */
-void INT_Int10Handler( SIGCONTEXT context )
+void INT_Int10Handler( SIGCONTEXT *context )
 {
-    switch(AH_reg(&context))
+    switch(AH_reg(context))
     {
     case 0x0f:
-        AL_reg(&context) = 0x5b;
+        AL_reg(context) = 0x5b;
         break;
 
     case 0x12:
-        if (BL_reg(&context) == 0x10)
+        if (BL_reg(context) == 0x10)
         {
-            BX_reg(&context) = 0x0003;
-            CX_reg(&context) = 0x0009;
+            BX_reg(context) = 0x0003;
+            CX_reg(context) = 0x0009;
         }
         break;
 			
     case 0x1a:
-        BX_reg(&context) = 0x0008;
+        BX_reg(context) = 0x0008;
         break;
 
     default:
-        INT_BARF( &context, 0x10 );
+        INT_BARF( context, 0x10 );
     }
 }
diff --git a/miscemu/int13.c b/miscemu/int13.c
index 20f72c1..3fda6f2 100644
--- a/miscemu/int13.c
+++ b/miscemu/int13.c
@@ -1,7 +1,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include "registers.h"
-#include "wine.h"
 #include "miscemu.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
@@ -13,28 +11,28 @@
  *
  * Handler for int 13h (disk I/O).
  */
-void INT_Int13Handler( SIGCONTEXT context )
+void INT_Int13Handler( SIGCONTEXT *context )
 {
-    switch(AH_reg(&context))
+    switch(AH_reg(context))
     {
 	case 0x00:                            /* RESET DISK SYSTEM     */
 	case 0x04:                            /* VERIFY DISK SECTOR(S) */
-		AH_reg(&context) = 0;
+		AH_reg(context) = 0;
 		break;
 	       
 	case 0x05:                                     /* FORMAT TRACK */
-		AH_reg(&context) = 0x0c;
-                SET_CFLAG(&context);
+		AH_reg(context) = 0x0c;
+                SET_CFLAG(context);
 		break;
 
 	case 0x06:             /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
 	case 0x07:             /* FORMAT DRIVE STARTING AT GIVEN TRACK  */ 
-		AH_reg(&context) = 0x0c;
+		AH_reg(context) = 0x0c;
 		break;
 
 	case 0x08:                              /* GET DRIVE PARAMETERS  */
-		AH_reg(&context) = (DL_reg(&context) & 0x80) ? 0x07 : 0x01;
-                SET_CFLAG(&context);
+		AH_reg(context) = (DL_reg(context) & 0x80) ? 0x07 : 0x01;
+                SET_CFLAG(context);
 		break;
 
         case 0x09:         /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
@@ -43,18 +41,18 @@
 	case 0x10:         /* CHECK IF DRIVE READY                        */
 	case 0x11:         /* RECALIBRATE DRIVE                           */
 	case 0x14:         /* CONTROLLER INTERNAL DIAGNOSTIC              */
-		AH_reg(&context) = 0;
+		AH_reg(context) = 0;
 		break;
 
 	case 0x0e:                    /* READ SECTOR BUFFER (XT only)      */
 	case 0x0f:                    /* WRITE SECTOR BUFFER (XT only)     */
         case 0x12:                    /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
 	case 0x13:                    /* DRIVE DIAGNOSTIC (XT,PS)          */
-		AH_reg(&context) = 0x01;
-                SET_CFLAG(&context);
+		AH_reg(context) = 0x01;
+                SET_CFLAG(context);
 		break;
 
 	default:
-		INT_BARF( &context, 0x13 );
+		INT_BARF( context, 0x13 );
     }
 }
diff --git a/miscemu/int1a.c b/miscemu/int1a.c
index 9a0ddf0..5017010 100644
--- a/miscemu/int1a.c
+++ b/miscemu/int1a.c
@@ -2,8 +2,6 @@
 #include <sys/time.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "registers.h"
-#include "wine.h"
 #include "options.h"
 #include "miscemu.h"
 #include "stddebug.h"
@@ -42,19 +40,19 @@
  *
  * Handler for int 1ah (date and time).
  */
-void INT_Int1aHandler( SIGCONTEXT context )
+void INT_Int1aHandler( SIGCONTEXT *context )
 {
     time_t ltime;
     DWORD ticks;
     struct tm *bdtime;
 
-    switch(AH_reg(&context))
+    switch(AH_reg(context))
     {
 	case 0:
             ticks = INT1A_GetTicksSinceMidnight();
-            CX_reg(&context) = HIWORD(ticks);
-            DX_reg(&context) = LOWORD(ticks);
-            AX_reg(&context) = 0;  /* No midnight rollover */
+            CX_reg(context) = HIWORD(ticks);
+            DX_reg(context) = LOWORD(ticks);
+            AX_reg(context) = 0;  /* No midnight rollover */
             dprintf_int(stddeb,"int1a_00 // ticks=%ld\n", ticks);
             break;
 		
@@ -62,17 +60,17 @@
 		ltime = time(NULL);
 		bdtime = localtime(&ltime);
 		
-		CX_reg(&context) = (BIN_TO_BCD(bdtime->tm_hour)<<8) |
-                                    BIN_TO_BCD(bdtime->tm_min);
-		DX_reg(&context) = (BIN_TO_BCD(bdtime->tm_sec)<<8);
+		CX_reg(context) = (BIN_TO_BCD(bdtime->tm_hour)<<8) |
+                                   BIN_TO_BCD(bdtime->tm_min);
+		DX_reg(context) = (BIN_TO_BCD(bdtime->tm_sec)<<8);
 
 	case 4:
 		ltime = time(NULL);
 		bdtime = localtime(&ltime);
-		CX_reg(&context) = (BIN_TO_BCD(bdtime->tm_year/100)<<8) |
-                                    BIN_TO_BCD((bdtime->tm_year-1900)%100);
-		DX_reg(&context) = (BIN_TO_BCD(bdtime->tm_mon)<<8) |
-                                    BIN_TO_BCD(bdtime->tm_mday);
+		CX_reg(context) = (BIN_TO_BCD(bdtime->tm_year/100)<<8) |
+                                   BIN_TO_BCD((bdtime->tm_year-1900)%100);
+		DX_reg(context) = (BIN_TO_BCD(bdtime->tm_mon)<<8) |
+                                   BIN_TO_BCD(bdtime->tm_mday);
 		break;
 
 		/* setting the time,date or RTC is not allow -EB */
@@ -89,6 +87,6 @@
 		break;
 
 	default:
-		INT_BARF( &context, 0x1a );
+		INT_BARF( context, 0x1a );
     }
 }
diff --git a/miscemu/int21.c b/miscemu/int21.c
index d301ca6..79176dc 100644
--- a/miscemu/int21.c
+++ b/miscemu/int21.c
@@ -20,7 +20,6 @@
 #include "file.h"
 #include "windows.h"
 #include "msdos.h"
-#include "registers.h"
 #include "ldt.h"
 #include "task.h"
 #include "options.h"
@@ -901,27 +900,27 @@
 /***********************************************************************
  *           DOS3Call  (KERNEL.102)
  */
-void DOS3Call( SIGCONTEXT context )
+void DOS3Call( SIGCONTEXT *context )
 {
     dprintf_int( stddeb, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
                  "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
-                 AX_reg(&context), BX_reg(&context), CX_reg(&context),
-                 DX_reg(&context), SI_reg(&context), DI_reg(&context),
-                 DS_reg(&context), ES_reg(&context), EFL_reg(&context));
+                 AX_reg(context), BX_reg(context), CX_reg(context),
+                 DX_reg(context), SI_reg(context), DI_reg(context),
+                 DS_reg(context), ES_reg(context), EFL_reg(context));
 
-    if (AH_reg(&context) == 0x59)  /* Get extended error info */
+    if (AH_reg(context) == 0x59)  /* Get extended error info */
     {
-        AX_reg(&context) = DOS_ExtendedError;
-        BH_reg(&context) = DOS_ErrorClass;
-        BL_reg(&context) = DOS_ErrorAction;
-        CH_reg(&context) = DOS_ErrorLocus;
+        AX_reg(context) = DOS_ExtendedError;
+        BH_reg(context) = DOS_ErrorClass;
+        BL_reg(context) = DOS_ErrorAction;
+        CH_reg(context) = DOS_ErrorLocus;
         return;
     }
 
     DOS_ERROR( 0, 0, 0, 0 );
-    RESET_CFLAG(&context);  /* Not sure if this is a good idea */
+    RESET_CFLAG(context);  /* Not sure if this is a good idea */
 
-    switch(AH_reg(&context)) 
+    switch(AH_reg(context)) 
     {
     case 0x00: /* TERMINATE PROGRAM */
         TASK_KillCurrentTask( 0 );
@@ -957,7 +956,7 @@
                   "SWITCHAR" - SET SWITCH CHARACTER
                   "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
     case 0x54: /* GET VERIFY FLAG */
-        INT_BARF( &context, 0x21 );
+        INT_BARF( context, 0x21 );
         break;
 
     case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
@@ -965,322 +964,323 @@
     case 0x1e:
     case 0x20:
     case 0x6b: /* NULL FUNCTION */
-        AL_reg(&context) = 0;
+        AL_reg(context) = 0;
         break;
 	
     case 0x5c: /* "FLOCK" - RECORD LOCKING */
-        fLock(&context);
+        fLock(context);
         break;
 
     case 0x0d: /* DISK BUFFER FLUSH */
-        RESET_CFLAG(&context); /* dos 6+ only */
+        RESET_CFLAG(context); /* dos 6+ only */
         break;
 
     case 0x0e: /* SELECT DEFAULT DRIVE */
-        DRIVE_SetCurrentDrive( DL_reg(&context) );
-        AL_reg(&context) = MAX_DOS_DRIVES;
+        DRIVE_SetCurrentDrive( DL_reg(context) );
+        AL_reg(context) = MAX_DOS_DRIVES;
         break;
 
     case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
-        if (!INT21_FindFirstFCB(&context))
+        if (!INT21_FindFirstFCB(context))
         {
-            AL_reg(&context) = 0xff;
+            AL_reg(context) = 0xff;
             break;
         }
         /* else fall through */
 
     case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
-        AL_reg(&context) = INT21_FindNextFCB(&context) ? 0x00 : 0xff;
+        AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
         break;
 
     case 0x13: /* DELETE FILE USING FCB */
-        DeleteFileFCB(&context);
+        DeleteFileFCB(context);
         break;
             
     case 0x17: /* RENAME FILE USING FCB */
-        RenameFileFCB(&context);
+        RenameFileFCB(context);
         break;
 
     case 0x19: /* GET CURRENT DEFAULT DRIVE */
-        AL_reg(&context) = DRIVE_GetCurrentDrive();
+        AL_reg(context) = DRIVE_GetCurrentDrive();
         break;
 
     case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
         {
             TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
-            pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(&context),DX_reg(&context));
+            pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
             dprintf_int(stddeb, "int21: Set DTA: %08lx\n", pTask->dta);
         }
         break;
 
     case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
-        DL_reg(&context) = 0;
-        if (!INT21_GetDriveAllocInfo(&context)) AX_reg(&context) = 0xffff;
+        DL_reg(context) = 0;
+        if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
         break;
 	
     case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
-        if (!INT21_GetDriveAllocInfo(&context)) AX_reg(&context) = 0xffff;
+        if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
         break;
 
     case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
-        GetDrivePB(&context, DRIVE_GetCurrentDrive());
+        GetDrivePB(context, DRIVE_GetCurrentDrive());
         break;
 		
     case 0x25: /* SET INTERRUPT VECTOR */
-        INT_SetHandler( AL_reg(&context),
-                   PTR_SEG_OFF_TO_SEGPTR( DS_reg(&context), DX_reg(&context)));
+        INT_SetHandler( AL_reg(context),
+                        (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
+                                                          DX_reg(context)));
         break;
 
     case 0x2a: /* GET SYSTEM DATE */
-        GetSystemDate(&context);
+        GetSystemDate(context);
         break;
 
     case 0x2b: /* SET SYSTEM DATE */
         fprintf( stdnimp, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
-                 DL_reg(&context), DH_reg(&context), CX_reg(&context) );
-        AL_reg(&context) = 0;  /* Let's pretend we succeeded */
+                 DL_reg(context), DH_reg(context), CX_reg(context) );
+        AL_reg(context) = 0;  /* Let's pretend we succeeded */
         break;
 
     case 0x2c: /* GET SYSTEM TIME */
-        INT21_GetSystemTime(&context);
+        INT21_GetSystemTime(context);
         break;
 
     case 0x2d: /* SET SYSTEM TIME */
         fprintf( stdnimp, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
-                 CH_reg(&context), CL_reg(&context),
-                 DH_reg(&context), DL_reg(&context) );
-        AL_reg(&context) = 0;  /* Let's pretend we succeeded */
+                 CH_reg(context), CL_reg(context),
+                 DH_reg(context), DL_reg(context) );
+        AL_reg(context) = 0;  /* Let's pretend we succeeded */
         break;
 
     case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
         {
             TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
-            ES_reg(&context) = SELECTOROF( pTask->dta );
-            BX_reg(&context) = OFFSETOF( pTask->dta );
+            ES_reg(context) = SELECTOROF( pTask->dta );
+            BX_reg(context) = OFFSETOF( pTask->dta );
         }
         break;
             
     case 0x30: /* GET DOS VERSION */
-        AX_reg(&context) = DOSVERSION;
-        BX_reg(&context) = 0x0012;     /* 0x123456 is Wine's serial # */
-        CX_reg(&context) = 0x3456;
+        AX_reg(context) = DOSVERSION;
+        BX_reg(context) = 0x0012;     /* 0x123456 is Wine's serial # */
+        CX_reg(context) = 0x3456;
         break;
 
     case 0x31: /* TERMINATE AND STAY RESIDENT */
-        INT_BARF( &context, 0x21 );
+        INT_BARF( context, 0x21 );
         break;
 
     case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
-        GetDrivePB(&context, DOS_GET_DRIVE( DL_reg(&context) ) );
+        GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
         break;
 
     case 0x33: /* MULTIPLEXED */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
 	      case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
-                DL_reg(&context) = 0;
+                DL_reg(context) = 0;
 		break;
 
 	      case 0x01: /* SET EXTENDED BREAK STATE */
 		break;		
 		
 	      case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
-		DL_reg(&context) = 0;
+		DL_reg(context) = 0;
 		break;
 
 	      case 0x05: /* GET BOOT DRIVE */
-		DL_reg(&context) = 2;
+		DL_reg(context) = 2;
 		/* c: is Wine's bootdrive */
 		break;
 				
 	      case 0x06: /* GET TRUE VERSION NUMBER */
-		BX_reg(&context) = DOSVERSION;
-		DX_reg(&context) = 0x00;
+		BX_reg(context) = DOSVERSION;
+		DX_reg(context) = 0x00;
 		break;
 
 	      default:
-                INT_BARF( &context, 0x21 );
+                INT_BARF( context, 0x21 );
 		break;			
         }
         break;	
 	    
     case 0x34: /* GET ADDRESS OF INDOS FLAG */
-        ES_reg(&context) = DosHeapHandle;
-        BX_reg(&context) = (int)&heap->InDosFlag - (int)heap;
+        ES_reg(context) = DosHeapHandle;
+        BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
         break;
 
     case 0x35: /* GET INTERRUPT VECTOR */
         {
-            SEGPTR addr = INT_GetHandler( AL_reg(&context) );
-            ES_reg(&context) = SELECTOROF(addr);
-            BX_reg(&context) = OFFSETOF(addr);
+            FARPROC16 addr = INT_GetHandler( AL_reg(context) );
+            ES_reg(context) = SELECTOROF(addr);
+            BX_reg(context) = OFFSETOF(addr);
         }
         break;
 
     case 0x36: /* GET FREE DISK SPACE */
-        if (!INT21_GetFreeDiskSpace(&context)) AX_reg(&context) = 0xffff;
+        if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
         break;
 
     case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
-        AX_reg(&context) = 0x02; /* no country support available */
-        SET_CFLAG(&context);
+        AX_reg(context) = 0x02; /* no country support available */
+        SET_CFLAG(context);
         break;
 
     case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
-        if (!CreateDirectory32A( PTR_SEG_OFF_TO_LIN( DS_reg(&context),
-                                                     DX_reg(&context) ), NULL))
+        if (!CreateDirectory32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
+                                                     DX_reg(context) ), NULL))
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 	
     case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
-        if (!RemoveDirectory32A( PTR_SEG_OFF_TO_LIN( DS_reg(&context),
-                                                     DX_reg(&context) )))
+        if (!RemoveDirectory32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
+                                                     DX_reg(context) )))
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
-        INT21_ChangeDir(&context);
+        INT21_ChangeDir(context);
         break;
 	
     case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
-        AX_reg(&context) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(&context),
-                                    DX_reg(&context) ), CX_reg(&context) );
-        if (AX_reg(&context) == (WORD)HFILE_ERROR)
+        AX_reg(context) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(context),
+                                    DX_reg(context) ), CX_reg(context) );
+        if (AX_reg(context) == (WORD)HFILE_ERROR)
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
-        OpenExistingFile(&context);
+        OpenExistingFile(context);
         break;
 
     case 0x3e: /* "CLOSE" - CLOSE FILE */
-        if ((AX_reg(&context) = _lclose( BX_reg(&context) )) != 0)
+        if ((AX_reg(context) = _lclose( BX_reg(context) )) != 0)
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
         {
-            LONG result = _hread( BX_reg(&context),
-                                  PTR_SEG_OFF_TO_SEGPTR( DS_reg(&context),
-                                                         DX_reg(&context) ),
-                                  CX_reg(&context) );
+            LONG result = _hread( BX_reg(context),
+                                  PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
+                                                         DX_reg(context) ),
+                                  CX_reg(context) );
             if (result == -1)
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
-            else AX_reg(&context) = (WORD)result;
+            else AX_reg(context) = (WORD)result;
         }
         break;
 
     case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
         {
-            LONG result = _hwrite( BX_reg(&context),
-                                   PTR_SEG_OFF_TO_LIN( DS_reg(&context),
-                                                       DX_reg(&context) ),
-                                   CX_reg(&context) );
+            LONG result = _hwrite( BX_reg(context),
+                                   PTR_SEG_OFF_TO_LIN( DS_reg(context),
+                                                       DX_reg(context) ),
+                                   CX_reg(context) );
             if (result == -1)
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
-            else AX_reg(&context) = (WORD)result;
+            else AX_reg(context) = (WORD)result;
         }
         break;
 
     case 0x41: /* "UNLINK" - DELETE FILE */
-        if (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(&context),
-                                                DX_reg(&context) )))
+        if (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
+                                                DX_reg(context) )))
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }		
         break;
 
     case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
         {
-            LONG status = _llseek( BX_reg(&context),
-                                   MAKELONG(DX_reg(&context),CX_reg(&context)),
-                                   AL_reg(&context) );
+            LONG status = _llseek( BX_reg(context),
+                                   MAKELONG(DX_reg(context),CX_reg(context)),
+                                   AL_reg(context) );
             if (status == HFILE_ERROR)
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
                 break;
             }
-            AX_reg(&context) = LOWORD(status);
-            DX_reg(&context) = HIWORD(status);
+            AX_reg(context) = LOWORD(status);
+            DX_reg(context) = HIWORD(status);
         }
         break;
 
     case 0x43: /* FILE ATTRIBUTES */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
         case 0x00:
-            if (!INT21_GetFileAttribute(&context))
+            if (!INT21_GetFileAttribute(context))
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
             break;
         case 0x01:
-            RESET_CFLAG(&context);
+            RESET_CFLAG(context);
             break;
         }
         break;
 	
     case 0x44: /* IOCTL */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
         case 0x00:
-            ioctlGetDeviceInfo(&context);
+            ioctlGetDeviceInfo(context);
             break;
 
         case 0x01:
             break;
 
         case 0x08:   /* Check if drive is removable. */
-            switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(&context) )))
+            switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
             {
             case DRIVE_CANNOTDETERMINE:
                 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
-                AX_reg(&context) = ER_InvalidDrive;
-                SET_CFLAG(&context);
+                AX_reg(context) = ER_InvalidDrive;
+                SET_CFLAG(context);
                 break;
             case DRIVE_REMOVABLE:
-                AX_reg(&context) = 0;      /* removable */
+                AX_reg(context) = 0;      /* removable */
                 break;
             default:
-                AX_reg(&context) = 1;   /* not removable */
+                AX_reg(context) = 1;   /* not removable */
                 break;
             }
             break;
 
         case 0x09:   /* CHECK IF BLOCK DEVICE REMOTE */
-            switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(&context) )))
+            switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
             {
             case DRIVE_CANNOTDETERMINE:
                 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
-                AX_reg(&context) = ER_InvalidDrive;
-                SET_CFLAG(&context);
+                AX_reg(context) = ER_InvalidDrive;
+                SET_CFLAG(context);
                 break;
             case DRIVE_REMOTE:
-                DX_reg(&context) = (1<<9) | (1<<12);  /* remote */
+                DX_reg(context) = (1<<9) | (1<<12);  /* remote */
                 break;
             default:
-                DX_reg(&context) = 0;  /* FIXME: use driver attr here */
+                DX_reg(context) = 0;  /* FIXME: use driver attr here */
                 break;
             }
             break;
@@ -1289,97 +1289,97 @@
             /* returns DX, bit 15 set if remote, bit 14 set if date/time
              * not set on close
              */
-            DX_reg(&context) = 0;
+            DX_reg(context) = 0;
             break;
 
         case 0x0b:   /* SET SHARING RETRY COUNT */
-            if (!CX_reg(&context))
+            if (!CX_reg(context))
             { 
-                AX_reg(&context) = 1;
-                SET_CFLAG(&context);
+                AX_reg(context) = 1;
+                SET_CFLAG(context);
                 break;
             }
-            sharing_pause = CX_reg(&context);
-            if (!DX_reg(&context))
-                sharing_retries = DX_reg(&context);
-            RESET_CFLAG(&context);
+            sharing_pause = CX_reg(context);
+            if (!DX_reg(context))
+                sharing_retries = DX_reg(context);
+            RESET_CFLAG(context);
             break;
 
         case 0x0d:
-            ioctlGenericBlkDevReq(&context);
+            ioctlGenericBlkDevReq(context);
             break;
 
         case 0x0F:   /* Set logical drive mapping */
             /* FIXME: Not implemented at the moment, always returns error
              */
-            INT_BARF( &context, 0x21 );
-            AX_reg(&context) = 0x0001; /* invalid function */
-            SET_CFLAG(&context);
+            INT_BARF( context, 0x21 );
+            AX_reg(context) = 0x0001; /* invalid function */
+            SET_CFLAG(context);
             break;
                 
         default:
-            INT_BARF( &context, 0x21 );
+            INT_BARF( context, 0x21 );
             break;
         }
         break;
 
     case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
-        if ((AX_reg(&context) = FILE_Dup(BX_reg(&context))) == (WORD)HFILE_ERROR)
+        if ((AX_reg(context) = FILE_Dup(BX_reg(context))) == (WORD)HFILE_ERROR)
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
-        if (FILE_Dup2( BX_reg(&context), CX_reg(&context) ) == HFILE_ERROR)
+        if (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR)
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
-        if (!INT21_GetCurrentDirectory(&context))
+        if (!INT21_GetCurrentDirectory(context))
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
-        else AX_reg(&context) = 0x0100; 
+        else AX_reg(context) = 0x0100; 
         /* intlist: many Microsoft products for Windows rely on this */
         break;
 	
     case 0x48: /* ALLOCATE MEMORY */
     case 0x49: /* FREE MEMORY */
     case 0x4a: /* RESIZE MEMORY BLOCK */
-        INT_BARF( &context, 0x21 );
+        INT_BARF( context, 0x21 );
         break;
 	
     case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
-        AX_reg(&context) = WinExec( PTR_SEG_OFF_TO_LIN( DS_reg(&context),
-                                                        DX_reg(&context) ),
+        AX_reg(context) = WinExec( PTR_SEG_OFF_TO_LIN( DS_reg(context),
+                                                        DX_reg(context) ),
                                     SW_NORMAL );
-        if (AX_reg(&context) < 32) SET_CFLAG(&context);
+        if (AX_reg(context) < 32) SET_CFLAG(context);
         break;		
 	
     case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
-        TASK_KillCurrentTask( AL_reg(&context) );
+        TASK_KillCurrentTask( AL_reg(context) );
         break;
 
     case 0x4d: /* GET RETURN CODE */
-        AX_reg(&context) = 0; /* normal exit */
+        AX_reg(context) = 0; /* normal exit */
         break;
 
     case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
-        if (!INT21_FindFirst(&context)) break;
+        if (!INT21_FindFirst(context)) break;
         /* fall through */
 
     case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
-        if (!INT21_FindNext(&context))
+        if (!INT21_FindNext(context))
         {
             DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
-            AX_reg(&context) = ER_NoMoreFiles;
-            SET_CFLAG(&context);
+            AX_reg(context) = ER_NoMoreFiles;
+            SET_CFLAG(context);
         }
         break;
 
@@ -1387,75 +1387,75 @@
     case 0x62: /* GET PSP ADDRESS */
         /* FIXME: should we return the original DOS PSP upon */
         /*        Windows startup ? */
-        BX_reg(&context) = GetCurrentPDB();
+        BX_reg(context) = GetCurrentPDB();
         break;
 
     case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
-        ES_reg(&context) = 0x0;
-        BX_reg(&context) = 0x0;
-        INT_BARF( &context, 0x21 );
+        ES_reg(context) = 0x0;
+        BX_reg(context) = 0x0;
+        INT_BARF( context, 0x21 );
         break;
 
     case 0x56: /* "RENAME" - RENAME FILE */
-        if (!INT21_RenameFile(&context))
+        if (!INT21_RenameFile(context))
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x57: /* FILE DATE AND TIME */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
         case 0x00:  /* Get */
-            if (!FILE_GetDateTime( BX_reg(&context), &DX_reg(&context),
-                                   &CX_reg(&context), TRUE ))
+            if (!FILE_GetDateTime( BX_reg(context), &DX_reg(context),
+                                   &CX_reg(context), TRUE ))
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
             break;
 
         case 0x01:  /* Set */
-            if (!FILE_SetDateTime( BX_reg(&context), DX_reg(&context),
-                                   CX_reg(&context) ))
+            if (!FILE_SetDateTime( BX_reg(context), DX_reg(context),
+                                   CX_reg(context) ))
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
             break;
         }
         break;
 
     case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
         case 0x00:
-            AX_reg(&context) = 1;
+            AX_reg(context) = 1;
             break;
         case 0x02:
-            AX_reg(&context) = 0;
+            AX_reg(context) = 0;
             break;
         case 0x01:
         case 0x03:
             break;
         }
-        RESET_CFLAG(&context);
+        RESET_CFLAG(context);
         break;
 
     case 0x5a: /* CREATE TEMPORARY FILE */
-        if (!INT21_CreateTempFile(&context))
+        if (!INT21_CreateTempFile(context))
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x5b: /* CREATE NEW FILE */
-        if ((AX_reg(&context) = _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(&context),DX_reg(&context)), 0 )) == (WORD)HFILE_ERROR)
+        if ((AX_reg(context) = _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)), 0 )) == (WORD)HFILE_ERROR)
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
@@ -1463,54 +1463,54 @@
     case 0x5e:
         /* network software not installed */
         DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
-        AX_reg(&context) = DOS_ExtendedError;
-        SET_CFLAG(&context);
+        AX_reg(context) = DOS_ExtendedError;
+        SET_CFLAG(context);
         break;
 
     case 0x5f: /* NETWORK */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
         case 0x07: /* ENABLE DRIVE */
-            if (!DRIVE_Enable( DL_reg(&context) ))
+            if (!DRIVE_Enable( DL_reg(context) ))
             {
                 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
             break;
 
         case 0x08: /* DISABLE DRIVE */
-            if (!DRIVE_Disable( DL_reg(&context) ))
+            if (!DRIVE_Disable( DL_reg(context) ))
             {
                 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             } 
             break;
 
         default:
             /* network software not installed */
             DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
             break;
         }
         break;
 
     case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
         {
-            const char *truename = DOSFS_GetDosTrueName( PTR_SEG_OFF_TO_LIN(DS_reg(&context),SI_reg(&context) ), FALSE );
+            const char *truename = DOSFS_GetDosTrueName( PTR_SEG_OFF_TO_LIN(DS_reg(context),SI_reg(context) ), FALSE );
             if (!truename)
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
             else
             {
-                lstrcpyn32A( PTR_SEG_OFF_TO_LIN( ES_reg(&context),
-                                                 DI_reg(&context) ),
+                lstrcpyn32A( PTR_SEG_OFF_TO_LIN( ES_reg(context),
+                                                 DI_reg(context) ),
                              truename, 128 );
-                AX_reg(&context) = 0;
+                AX_reg(context) = 0;
             }
         }
         break;
@@ -1519,66 +1519,66 @@
     case 0x63: /* UNUSED */
     case 0x64: /* OS/2 DOS BOX */
     case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
-        INT_BARF( &context, 0x21 );
-        SET_CFLAG(&context);
+        INT_BARF( context, 0x21 );
+        SET_CFLAG(context);
         break;
 	
     case 0x66: /* GLOBAL CODE PAGE TABLE */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
         case 0x01:
-            DX_reg(&context) = BX_reg(&context) = CodePage;
-            RESET_CFLAG(&context);
+            DX_reg(context) = BX_reg(context) = CodePage;
+            RESET_CFLAG(context);
             break;			
         case 0x02: 
-            CodePage = BX_reg(&context);
-            RESET_CFLAG(&context);
+            CodePage = BX_reg(context);
+            RESET_CFLAG(context);
             break;
         }
         break;
 
     case 0x67: /* SET HANDLE COUNT */
-        SetHandleCount( BX_reg(&context) );
+        SetHandleCount( BX_reg(context) );
         if (DOS_ExtendedError)
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;
 
     case 0x68: /* "FFLUSH" - COMMIT FILE */
     case 0x6a: /* COMMIT FILE */
-        if (!FlushFileBuffers( BX_reg(&context) ))
+        if (!FlushFileBuffers( BX_reg(context) ))
         {
-            AX_reg(&context) = DOS_ExtendedError;
-            SET_CFLAG(&context);
+            AX_reg(context) = DOS_ExtendedError;
+            SET_CFLAG(context);
         }
         break;		
 	
     case 0x69: /* DISK SERIAL NUMBER */
-        switch (AL_reg(&context))
+        switch (AL_reg(context))
         {
         case 0x00:
-            if (!INT21_GetDiskSerialNumber(&context))
+            if (!INT21_GetDiskSerialNumber(context))
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
-            else AX_reg(&context) = 0;
+            else AX_reg(context) = 0;
             break;
         case 0x01:
-            if (!INT21_SetDiskSerialNumber(&context))
+            if (!INT21_SetDiskSerialNumber(context))
             {
-                AX_reg(&context) = DOS_ExtendedError;
-                SET_CFLAG(&context);
+                AX_reg(context) = DOS_ExtendedError;
+                SET_CFLAG(context);
             }
-            else AX_reg(&context) = 1;
+            else AX_reg(context) = 1;
             break;
         }
         break;
     
     case 0x6C: /* Extended Open/Create*/
-        ExtendedOpenCreateFile(&context);
+        ExtendedOpenCreateFile(context);
         break;
 	
     case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
@@ -1586,10 +1586,10 @@
     case 0x72: /* MS-DOS 7 (Windows95) - ??? */
     case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
         dprintf_int(stddeb,"int21: windows95 function AX %04x\n",
-                    AX_reg(&context));
+                    AX_reg(context));
         dprintf_int(stddeb, "        returning unimplemented\n");
-        SET_CFLAG(&context);
-        AL_reg(&context) = 0;
+        SET_CFLAG(context);
+        AL_reg(context) = 0;
         break;
 
     case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
@@ -1597,18 +1597,18 @@
         break;
 
     default:
-        INT_BARF( &context, 0x21 );
+        INT_BARF( context, 0x21 );
         break;
     }
     dprintf_int( stddeb, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
                  "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
-                 AX_reg(&context), BX_reg(&context), CX_reg(&context),
-                 DX_reg(&context), SI_reg(&context), DI_reg(&context),
-                 DS_reg(&context), ES_reg(&context), EFL_reg(&context));
+                 AX_reg(context), BX_reg(context), CX_reg(context),
+                 DX_reg(context), SI_reg(context), DI_reg(context),
+                 DS_reg(context), ES_reg(context), EFL_reg(context));
 }
 
 
-BOOL INT21_Init(void)
+BOOL32 INT21_Init(void)
 {
     if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
     {
diff --git a/miscemu/int25.c b/miscemu/int25.c
index 1f4832d..f1b8052 100644
--- a/miscemu/int25.c
+++ b/miscemu/int25.c
@@ -1,10 +1,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "registers.h"
 #include "msdos.h"
 #include "ldt.h"
-#include "wine.h"
 #include "miscemu.h"
 #include "drive.h"
 #include "stddebug.h"
@@ -16,19 +14,19 @@
  *
  * Handler for int 25h (absolute disk read).
  */
-void INT_Int25Handler( SIGCONTEXT context )
+void INT_Int25Handler( SIGCONTEXT *context )
 {
-    BYTE *dataptr = PTR_SEG_OFF_TO_LIN( DS_reg(&context), BX_reg(&context) );
+    BYTE *dataptr = PTR_SEG_OFF_TO_LIN( DS_reg(context), BX_reg(context) );
     DWORD begin, length;
 
-    if (!DRIVE_IsValid(AL_reg(&context)))
+    if (!DRIVE_IsValid(AL_reg(context)))
     {
-        SET_CFLAG(&context);
-        AX_reg(&context) = 0x0101;        /* unknown unit */
+        SET_CFLAG(context);
+        AX_reg(context) = 0x0101;        /* unknown unit */
         return;
     }
 
-    if (CX_reg(&context) == 0xffff)
+    if (CX_reg(context) == 0xffff)
     {
         begin   = *(DWORD *)dataptr;
         length  = *(WORD *)(dataptr + 4);
@@ -36,12 +34,12 @@
     }
     else
     {
-        begin = DX_reg(&context);
-        length = CX_reg(&context);
+        begin  = DX_reg(context);
+        length = CX_reg(context);
     }
     dprintf_int( stdnimp, "int25: abs diskread, drive %d, sector %ld, "
                  "count %ld, buffer %d\n",
-                 AL_reg(&context), begin, length, (int) dataptr);
+                 AL_reg(context), begin, length, (int) dataptr);
 
     memset(dataptr, 0, length * 512);
 
@@ -49,5 +47,5 @@
 
     if (begin == 1) *dataptr = 0xf8;
 
-    RESET_CFLAG(&context);
+    RESET_CFLAG(context);
 }
diff --git a/miscemu/int26.c b/miscemu/int26.c
index 270de63..4009184 100644
--- a/miscemu/int26.c
+++ b/miscemu/int26.c
@@ -1,9 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include "registers.h"
 #include "msdos.h"
 #include "ldt.h"
-#include "wine.h"
 #include "miscemu.h"
 #include "drive.h"
 #include "stddebug.h"
@@ -15,19 +13,19 @@
  *
  * Handler for int 26h (absolute disk read).
  */
-void INT_Int26Handler( SIGCONTEXT context )
+void INT_Int26Handler( SIGCONTEXT *context )
 {
-    BYTE *dataptr = PTR_SEG_OFF_TO_LIN( DS_reg(&context), BX_reg(&context) );
+    BYTE *dataptr = PTR_SEG_OFF_TO_LIN( DS_reg(context), BX_reg(context) );
     DWORD begin, length;
 
-    if (!DRIVE_IsValid(AL_reg(&context)))
+    if (!DRIVE_IsValid(AL_reg(context)))
     {
-        SET_CFLAG(&context);
-        AX_reg(&context) = 0x0101;        /* unknown unit */
+        SET_CFLAG(context);
+        AX_reg(context) = 0x0101;        /* unknown unit */
         return;
     }
 
-    if (CX_reg(&context) == 0xffff)
+    if (CX_reg(context) == 0xffff)
     {
         begin   = *(DWORD *)dataptr;
         length  = *(WORD *)(dataptr + 4);
@@ -35,13 +33,13 @@
     }
     else
     {
-        begin = DX_reg(&context);
-        length = CX_reg(&context);
+        begin  = DX_reg(context);
+        length = CX_reg(context);
     }
 		
     dprintf_int( stdnimp,"int26: abs diskwrite, drive %d, sector %ld, "
                  "count %ld, buffer %d\n",
-                 AL_reg(&context), begin, length, (int) dataptr );
+                 AL_reg(context), begin, length, (int) dataptr );
 
-    RESET_CFLAG(&context);
+    RESET_CFLAG(context);
 }
diff --git a/miscemu/int2a.c b/miscemu/int2a.c
index 4dfa3e9..c41b10d 100644
--- a/miscemu/int2a.c
+++ b/miscemu/int2a.c
@@ -1,8 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "msdos.h"
-#include "wine.h"
-#include "registers.h"
 #include "miscemu.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
@@ -13,14 +11,14 @@
  *
  * Handler for int 2ah (network).
  */
-void INT_Int2aHandler( SIGCONTEXT context )
+void INT_Int2aHandler( SIGCONTEXT *context )
 {
-    switch(AH_reg(&context))
+    switch(AH_reg(context))
     {
     case 0x00:                             /* NETWORK INSTALLATION CHECK */
         break;
 		
     default:
-	INT_BARF( &context, 0x2a );
+	INT_BARF( context, 0x2a );
     }
 }
diff --git a/miscemu/int2f.c b/miscemu/int2f.c
index ad8817d..b8b6277 100644
--- a/miscemu/int2f.c
+++ b/miscemu/int2f.c
@@ -2,9 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include "registers.h"
 #include "ldt.h"
-#include "wine.h"
 #include "drive.h"
 #include "msdos.h"
 #include "miscemu.h"
@@ -25,24 +23,24 @@
  *
  * Handler for int 2fh (multiplex).
  */
-void INT_Int2fHandler( SIGCONTEXT context )
+void INT_Int2fHandler( SIGCONTEXT *context )
 {
-    switch(AH_reg(&context))
+    switch(AH_reg(context))
     {
     case 0x10:
-        AL_reg(&context) = 0xff; /* share is installed */
+        AL_reg(context) = 0xff; /* share is installed */
         break;
 
     case 0x15: /* mscdex */
-        do_mscdex(&context);
+        do_mscdex(context);
         break;
 
     case 0x16:
-        do_int2f_16( &context );
+        do_int2f_16( context );
         break;
 
     case 0x4a:
-        switch(AL_reg(&context))
+        switch(AL_reg(context))
         {
 	case 0x10:  /* smartdrv */
 	    break;  /* not installed */
@@ -51,14 +49,14 @@
         case 0x12:  /* realtime compression interface */
             break;  /* not installed */
         default:
-            INT_BARF( &context, 0x2f );
+            INT_BARF( context, 0x2f );
         }
         break;
     case 0xb7:  /* append */
-        AL_reg(&context) = 0; /* not installed */
+        AL_reg(context) = 0; /* not installed */
         break;
     default:
-        INT_BARF( &context, 0x2f );
+        INT_BARF( context, 0x2f );
         break;
     }
 }
@@ -100,8 +98,8 @@
 	break;
 
     case 0x84:  /* Get device API entry point */
-        addr = MODULE_GetEntryPoint( GetModuleHandle("WPROCS"),
-                                     VXD_BASE + BX_reg(context) );
+        addr = (DWORD)MODULE_GetEntryPoint( GetModuleHandle("WPROCS"),
+                                            VXD_BASE + BX_reg(context) );
         if (!addr)  /* not supported */
         {
 	    fprintf( stderr,"Application attempted to access VxD %04x\n",
diff --git a/miscemu/int4b.c b/miscemu/int4b.c
index e78e285..ecf07fa 100644
--- a/miscemu/int4b.c
+++ b/miscemu/int4b.c
@@ -3,32 +3,26 @@
  *
  */
 
-#include "wine.h"
 #include "miscemu.h"
-#include "stddebug.h"
-/* #define DEBUG_INT */
-#include "debug.h"
-#include "registers.h"
-
 
 /***********************************************************************
  *           INT_Int4bHandler
  *
  */
-void INT_Int4bHandler( SIGCONTEXT context )
+void INT_Int4bHandler( SIGCONTEXT *context )
 {
 
-  switch(AH_reg(&context))
+  switch(AH_reg(context))
    {
 	case 0x81: /* Virtual DMA Spec (IBM SCSI interface) */   
-             if(AL_reg(&context) != 0x02) /* if not install check */
+             if(AL_reg(context) != 0x02) /* if not install check */
 		{
-		 SET_CFLAG(&context);		 
-		 AL_reg(&context) = 0x0f; /* function is not implemented */
+		 SET_CFLAG(context);		 
+		 AL_reg(context) = 0x0f; /* function is not implemented */
 		}
 	     break;
         default:
-	     INT_BARF(&context, 0x4b);
+	     INT_BARF(context, 0x4b);
     }
 }
 
diff --git a/miscemu/int5c.c b/miscemu/int5c.c
index 190c0e1..575d2e9 100644
--- a/miscemu/int5c.c
+++ b/miscemu/int5c.c
@@ -5,12 +5,9 @@
  */
 
 #include "ldt.h"
-#include "wine.h"
 #include "miscemu.h"
 #include "stddebug.h"
-/* #define DEBUG_INT */
 #include "debug.h"
-#include "registers.h"
 
 
 /***********************************************************************
@@ -18,14 +15,14 @@
  *
  * Also handler for interrupt 5c. 
  */
-void NetBIOSCall( SIGCONTEXT context )
+void NetBIOSCall( SIGCONTEXT *context )
 {
   BYTE* ptr;
 
-  ptr = (BYTE*) PTR_SEG_OFF_TO_LIN(ES_reg(&context),BX_reg(&context));
+  ptr = (BYTE*) PTR_SEG_OFF_TO_LIN(ES_reg(context),BX_reg(context));
 
   fprintf(stdnimp,"NetBIOSCall: command code %02x (ignored)\n",*ptr);
   
-  AL_reg(&context) = *(ptr+0x01) = 0xFB; /* NetBIOS emulator not found */
+  AL_reg(context) = *(ptr+0x01) = 0xFB; /* NetBIOS emulator not found */
 }
 
diff --git a/miscemu/interrupts.c b/miscemu/interrupts.c
index 3b3d3fe..6fa7cb7 100644
--- a/miscemu/interrupts.c
+++ b/miscemu/interrupts.c
@@ -11,12 +11,11 @@
 #include "miscemu.h"
 #include "msdos.h"
 #include "module.h"
-#include "registers.h"
 #include "stackframe.h"
 #include "stddebug.h"
 #include "debug.h"
 
-static SEGPTR INT_Vectors[256];
+static FARPROC16 INT_Vectors[256];
 
   /* Ordinal number for interrupt 0 handler in WPROCS.DLL */
 #define FIRST_INTERRUPT_ORDINAL 100
@@ -25,7 +24,7 @@
 /**********************************************************************
  *	    INT_Init
  */
-BOOL INT_Init(void)
+BOOL32 INT_Init(void)
 {
     WORD vector;
     HMODULE16 hModule = GetModuleHandle( "WPROCS" );
@@ -48,7 +47,7 @@
  *
  * Return the interrupt vector for a given interrupt.
  */
-SEGPTR INT_GetHandler( BYTE intnum )
+FARPROC16 INT_GetHandler( BYTE intnum )
 {
     return INT_Vectors[intnum];
 }
@@ -59,7 +58,7 @@
  *
  * Set the interrupt handler for a given interrupt.
  */
-void INT_SetHandler( BYTE intnum, SEGPTR handler )
+void INT_SetHandler( BYTE intnum, FARPROC16 handler )
 {
     dprintf_int( stddeb, "Set interrupt vector %02x <- %04x:%04x\n",
                  intnum, HIWORD(handler), LOWORD(handler) );
@@ -70,13 +69,12 @@
 /**********************************************************************
  *	    INT_DummyHandler
  */
-void INT_DummyHandler( SIGCONTEXT context )
+void INT_DummyHandler( SIGCONTEXT *context )
 {
     WORD ordinal;
-    char *name;
     STACK16FRAME *frame = CURRENT_STACK16;
-    BUILTIN_GetEntryPoint( frame->entry_cs, frame->entry_ip, &ordinal, &name );
-    INT_BARF( &context, ordinal - FIRST_INTERRUPT_ORDINAL );
+    BUILTIN_GetEntryPoint16( frame->entry_cs, frame->entry_ip, &ordinal );
+    INT_BARF( context, ordinal - FIRST_INTERRUPT_ORDINAL );
 }
 
 
@@ -85,7 +83,7 @@
  *
  * Handler for int 11h (get equipment list).
  */
-void INT_Int11Handler( SIGCONTEXT context )
+void INT_Int11Handler( SIGCONTEXT *context )
 {
     int diskdrives = 0;
     int parallelports = 0;
@@ -134,8 +132,8 @@
     if (parallelports > 3)		/* 2 bits -- maximum value = 3 */
         parallelports=3;
     
-    AX_reg(&context) = (diskdrives << 6) | (serialports << 9) | 
-                       (parallelports << 14) | 0x02;
+    AX_reg(context) = (diskdrives << 6) | (serialports << 9) | 
+                      (parallelports << 14) | 0x02;
 }
 
 
@@ -144,9 +142,9 @@
  *
  * Handler for int 12h (get memory size).
  */
-void INT_Int12Handler( SIGCONTEXT context )
+void INT_Int12Handler( SIGCONTEXT *context )
 {
-    AX_reg(&context) = 640;
+    AX_reg(context) = 640;
 }
 
 
@@ -155,9 +153,9 @@
  *
  * Handler for int 15h.
  */
-void INT_Int15Handler( SIGCONTEXT context )
+void INT_Int15Handler( SIGCONTEXT *context )
 {
-    INT_BARF( &context, 0x15 );
+    INT_BARF( context, 0x15 );
 }
 
 
@@ -166,7 +164,7 @@
  *
  * Handler for int 16h (keyboard).
  */
-void INT_Int16Handler( SIGCONTEXT context )
+void INT_Int16Handler( SIGCONTEXT *context )
 {
-    INT_BARF( &context, 0x16 );
+    INT_BARF( context, 0x16 );
 }
diff --git a/miscemu/vxd.c b/miscemu/vxd.c
index b1bb3b0..0a5a188 100644
--- a/miscemu/vxd.c
+++ b/miscemu/vxd.c
@@ -8,7 +8,6 @@
 #include "windows.h"
 #include "msdos.h"
 #include "miscemu.h"
-#include "wine.h"
 #include "stddebug.h"
 /* #define DEBUG_VXD */
 #include "debug.h"
@@ -17,43 +16,43 @@
 /***********************************************************************
  *           VXD_PageFile
  */
-void VXD_PageFile( SIGCONTEXT context )
+void VXD_PageFile( SIGCONTEXT *context )
 {
     /* taken from Ralf Brown's Interrupt List */
 
     dprintf_vxd(stddeb,"VxD PageFile called ...\n");
 
-    switch(AX_reg(&context)) 
+    switch(AX_reg(context)) 
     {
     case 0x00: /* get version, is this windows version? */
 	dprintf_vxd(stddeb,"VxD PageFile: returning version\n");
-        AX_reg(&context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
-	RESET_CFLAG(&context);
+        AX_reg(context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+	RESET_CFLAG(context);
 	break;
 
     case 0x01: /* get swap file info */
 	dprintf_vxd(stddeb,"VxD PageFile: returning swap file info\n");
-	AX_reg(&context) = 0x00; /* paging disabled */
-	ECX_reg(&context) = 0;   /* maximum size of paging file */	
+	AX_reg(context) = 0x00; /* paging disabled */
+	ECX_reg(context) = 0;   /* maximum size of paging file */	
 	/* FIXME: do I touch DS:SI or DS:DI? */
-	RESET_CFLAG(&context);
+	RESET_CFLAG(context);
 	break;
 
     case 0x02: /* delete permanent swap on exit */
 	dprintf_vxd(stddeb,"VxD PageFile: supposed to delete swap\n");
-	RESET_CFLAG(&context);
+	RESET_CFLAG(context);
 	break;
 
     case 0x03: /* current temporary swap file size */
 	dprintf_vxd(stddeb,"VxD PageFile: what is current temp. swap size\n");
-	RESET_CFLAG(&context);
+	RESET_CFLAG(context);
 	break;
 
     case 0x04: /* read or write?? INTERRUP.D */
     case 0x05: /* cancel?? INTERRUP.D */
     case 0x06: /* test I/O valid INTERRUP.D */
     default:
-	INT_BARF( &context, 0x2f);
+	INT_BARF( context, 0x2f);
 	break;
     }
 }
@@ -62,16 +61,16 @@
 /***********************************************************************
  *           VXD_Shell
  */
-void VXD_Shell( SIGCONTEXT context )
+void VXD_Shell( SIGCONTEXT *context )
 {
     dprintf_vxd(stddeb,"VxD Shell called ...\n");
 
-    switch (DX_reg(&context)) /* Ralf Brown says EDX, but I use DX instead */
+    switch (DX_reg(context)) /* Ralf Brown says EDX, but I use DX instead */
     {
     case 0x0000:
 	dprintf_vxd(stddeb,"VxD Shell: returning version\n");
-        AX_reg(&context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
-	EBX_reg(&context) = 1; /* system VM Handle */
+        AX_reg(context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+	EBX_reg(context) = 1; /* system VM Handle */
 	break;
 
     case 0x0001:
@@ -79,8 +78,8 @@
     case 0x0003:
     case 0x0004:
     case 0x0005:
-	dprintf_vxd(stddeb,"VxD Shell: EDX = %08lx\n",EDX_reg(&context));
-	INT_BARF( &context, 0x2f);
+	dprintf_vxd(stddeb,"VxD Shell: EDX = %08lx\n",EDX_reg(context));
+	INT_BARF( context, 0x2f);
 	break;
 
     case 0x0006: /* SHELL_Get_VM_State */
@@ -90,7 +89,7 @@
          * so for now let's do nothing. I can (hopefully) get this
          * by the next release
          */
-	/* RESET_CFLAG(&context); */
+	/* RESET_CFLAG(context); */
 	break;
 
     case 0x0007:
@@ -110,8 +109,8 @@
     case 0x0015:
     case 0x0016:
     default:
- 	dprintf_vxd(stddeb,"VxD Shell: EDX = %08lx\n",EDX_reg(&context)); 
-	INT_BARF( &context, 0x2f);
+ 	dprintf_vxd(stddeb,"VxD Shell: EDX = %08lx\n",EDX_reg(context)); 
+	INT_BARF( context, 0x2f);
 	break;
     }
 }
@@ -120,22 +119,22 @@
 /***********************************************************************
  *           VXD_Comm
  */
-void VXD_Comm( SIGCONTEXT context )
+void VXD_Comm( SIGCONTEXT *context )
 {
     dprintf_vxd(stddeb,"VxD Comm called ...\n");
 
-    switch (AX_reg(&context))
+    switch (AX_reg(context))
     {
     case 0x0000: /* get version */
 	dprintf_vxd(stddeb,"VxD Comm: returning version\n");
-        AX_reg(&context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
-	RESET_CFLAG(&context);
+        AX_reg(context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+	RESET_CFLAG(context);
 	break;
 
     case 0x0001: /* set port global */
     case 0x0002: /* get focus */
     case 0x0003: /* virtualise port */
     default:
-        INT_BARF( &context, 0x2f);
+        INT_BARF( context, 0x2f);
     }
 }
diff --git a/multimedia/audio.c b/multimedia/audio.c
index b97ca58..8f941e9 100644
--- a/multimedia/audio.c
+++ b/multimedia/audio.c
@@ -128,9 +128,6 @@
 		MCIWavDev[wDevID].nUseCount = 1;
 		MCIWavDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE;
 		}
-	dprintf_mciwave(stddeb,"WAVE_mciOpen // before setting lParams->wDeviceID // winstack=%p ds=%04X ss=%04X sp=%04X\n",
-		(BYTE *)CURRENT_STACK16->args, 
-		CURRENT_STACK16->ds, IF1632_Saved16_ss, IF1632_Saved16_sp);
 	lpParms->wDeviceID = wDevID;
 	dprintf_mciwave(stddeb,"WAVE_mciOpen // wDevID=%04X\n", wDevID);
 	dprintf_mciwave(stddeb,"WAVE_mciOpen // before OPEN_ELEMENT\n");
diff --git a/multimedia/joystick.c b/multimedia/joystick.c
index 9eff801..821957b 100644
--- a/multimedia/joystick.c
+++ b/multimedia/joystick.c
@@ -4,8 +4,6 @@
  * Copyright 1993 Martin Ayotte
  */
 
-#ifndef WINELIB
-
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -94,5 +92,3 @@
     fprintf(stdnimp, "EMPTY STUB !!! JoySetCalibration(%04X);\n", wID);
     return MMSYSERR_NODRIVER;
 }
-
-#endif
diff --git a/multimedia/mcistring.c b/multimedia/mcistring.c
index 8e7c2d4..5abd42a 100644
--- a/multimedia/mcistring.c
+++ b/multimedia/mcistring.c
@@ -24,11 +24,6 @@
 #include "debug.h"
 #include "xmalloc.h"
 
-#ifdef WINELIB32
-#define UIFMT "%u"
-#else
-#define UIFMT "%hu"
-#endif
 
 extern MCI_OPEN_DRIVER_PARMS	mciDrv[MAXMCIDRIVERS];
 
@@ -71,21 +66,19 @@
 } while(0)
 
 /* calling DriverProc. We need to pass the struct as SEGMENTED POINTER. */
-#define _MCI_CALL_DRIVER(cmd,params) {\
-	DWORD	xparams;\
-	xparams=MAKE_SEGPTR(&params);\
+#define _MCI_CALL_DRIVER(cmd,params) \
 	switch(uDevTyp) {\
 	case MCI_DEVTYPE_CD_AUDIO:\
-		res=CDAUDIO_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags, xparams);\
+		res=CDAUDIO_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags, (DWORD)(params));\
 		break;\
 	case MCI_DEVTYPE_WAVEFORM_AUDIO:\
-		res=WAVE_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags,xparams);\
+		res=WAVE_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags,(DWORD)(params));\
 		break;\
 	case MCI_DEVTYPE_SEQUENCER:\
-		res=MIDI_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags,xparams);\
+		res=MIDI_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags,(DWORD)(params));\
 		break;\
 	case MCI_DEVTYPE_ANIMATION:\
-		res=ANIM_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags,xparams);\
+		res=ANIM_DriverProc(mciDrv[wDevID].wDeviceID,0,cmd,dwFlags,(DWORD)(params));\
 		break;\
 	case MCI_DEVTYPE_DIGITAL_VIDEO:\
 		dprintf_mci(stddeb,"_MCI_CALL_DRIVER //No DIGITAL_VIDEO yet !\n");\
@@ -95,8 +88,7 @@
 		dprintf_mci(stddeb,"_MCI_CALL_DRIVER //Invalid Device Name '%s' !\n",dev);\
 		res=MCIERR_INVALID_DEVICE_NAME;\
 		break;\
-	}\
-}
+	}
 /* we need to have strings in 16 bit space for some things 
  * FIXME: this is bad.
  */
@@ -433,7 +425,7 @@
 		fprintf(stdnimp,__FILE__":MCISTR_Open:unknown parameter passed %s, please report.\n",keywords[i]);
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_OPEN,U);
+	_MCI_CALL_DRIVER( MCI_OPEN, MAKE_SEGPTR(&U) );
 	if (res==0)
 		memcpy(&mciOpenDrv[wDevID],&U.openParams,sizeof(MCI_OPEN_PARMS));
 	return res;
@@ -451,7 +443,7 @@
 	dwFlags	= MCI_STATUS_ITEM;
 	statusParams.dwItem	= MCI_STATUS_TIME_FORMAT;
 	statusParams.dwReturn	= 0;
-	_MCI_CALL_DRIVER(MCI_STATUS,statusParams);
+	_MCI_CALL_DRIVER( MCI_STATUS, MAKE_SEGPTR(&statusParams) );
 	if (res==0) *timef=statusParams.dwReturn;
 	return res;
 }
@@ -621,7 +613,7 @@
 	if (!statusParams.dwItem) 
 		return MCIERR_MISSING_STRING_ARGUMENT;
 
-	_MCI_CALL_DRIVER(MCI_STATUS,statusParams);
+	_MCI_CALL_DRIVER( MCI_STATUS, MAKE_SEGPTR(&statusParams) );
 	if (res==0)
 		_MCISTR_convreturn(type,statusParams.dwReturn,lpstrReturnString,uReturnLength,uDevTyp,timef);
 	return res;
@@ -761,14 +753,14 @@
 				i+=2;\
 				continue;\
 			}
-			WII("formattag",MCI_WAVE_SET_FORMATTAG,UIFMT,wFormatTag);
-			WII("channels",MCI_WAVE_SET_CHANNELS,UIFMT,nChannels);
+			WII("formattag",MCI_WAVE_SET_FORMATTAG,"%hu",wFormatTag);
+			WII("channels",MCI_WAVE_SET_CHANNELS,"%hu",nChannels);
 			WII("bytespersec",MCI_WAVE_SET_AVGBYTESPERSEC,"%lu",nAvgBytesPerSec);
 			WII("samplespersec",MCI_WAVE_SET_SAMPLESPERSEC,"%lu",nSamplesPerSec);
-			WII("alignment",MCI_WAVE_SET_BLOCKALIGN,UIFMT,nBlockAlign);
-			WII("bitspersample",MCI_WAVE_SET_BITSPERSAMPLE,UIFMT,wBitsPerSample);
-			WII("input",MCI_WAVE_INPUT,UIFMT,wInput);
-			WII("output",MCI_WAVE_OUTPUT,UIFMT,wOutput);
+			WII("alignment",MCI_WAVE_SET_BLOCKALIGN,"%hu",nBlockAlign);
+			WII("bitspersample",MCI_WAVE_SET_BITSPERSAMPLE,"%hu",wBitsPerSample);
+			WII("input",MCI_WAVE_INPUT,"%hu",wInput);
+			WII("output",MCI_WAVE_OUTPUT,"%hu",wOutput);
 #undef WII
 			break;
 		case MCI_DEVTYPE_SEQUENCER:
@@ -822,7 +814,7 @@
 	}
 	if (!dwFlags)
 		return MCIERR_MISSING_STRING_ARGUMENT;
-	_MCI_CALL_DRIVER(MCI_SET,U);
+	_MCI_CALL_DRIVER( MCI_SET, MAKE_SEGPTR(&U) );
 	return res;
 }
 
@@ -852,7 +844,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_BREAK,breakParams);
+	_MCI_CALL_DRIVER( MCI_BREAK, MAKE_SEGPTR(&breakParams) );
 	return res;
 }
 
@@ -971,7 +963,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_GETDEVCAPS,gdcParams);
+	_MCI_CALL_DRIVER( MCI_GETDEVCAPS, MAKE_SEGPTR(&gdcParams) );
 	/* no timeformat needed */
 	if (res==0)
 		_MCISTR_convreturn(type,gdcParams.dwReturn,lpstrReturnString,uReturnLength,uDevTyp,0);
@@ -987,7 +979,7 @@
 	int	res;
 
 	genParams.dwCallback=0;
-	_MCI_CALL_DRIVER(MCI_RESUME,genParams);
+	_MCI_CALL_DRIVER( MCI_RESUME, MAKE_SEGPTR(&genParams) );
 	return res;
 }
 
@@ -997,7 +989,7 @@
 	MCI_GENERIC_PARMS	genParams;
 	int			res;
 	genParams.dwCallback=0;
-	_MCI_CALL_DRIVER(MCI_PAUSE,genParams);
+	_MCI_CALL_DRIVER( MCI_PAUSE, MAKE_SEGPTR(&genParams) );
 	return res;
 }
 
@@ -1007,7 +999,7 @@
 	MCI_GENERIC_PARMS	genParams;
 	int			res;
 	genParams.dwCallback=0;
-	_MCI_CALL_DRIVER(MCI_STOP,genParams);
+	_MCI_CALL_DRIVER( MCI_STOP, MAKE_SEGPTR(&genParams) );
 	return res;
 }
 
@@ -1081,7 +1073,7 @@
 		FLAG1("overwrite",MCI_RECORD_OVERWRITE);
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_RECORD,recordParams);
+	_MCI_CALL_DRIVER( MCI_RECORD, MAKE_SEGPTR(&recordParams) );
 	return res;
 }
 
@@ -1192,7 +1184,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_PLAY,U);
+	_MCI_CALL_DRIVER( MCI_PLAY, MAKE_SEGPTR(&U) );
 	return res;
 }
 
@@ -1264,7 +1256,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_SEEK,seekParams);
+	_MCI_CALL_DRIVER( MCI_SEEK, MAKE_SEGPTR(&seekParams) );
 	return res;
 }
 
@@ -1274,7 +1266,7 @@
 	MCI_GENERIC_PARMS	closeParams;
 	int			res;
 
-	_MCI_CALL_DRIVER(MCI_CLOSE,closeParams);
+	_MCI_CALL_DRIVER( MCI_CLOSE, MAKE_SEGPTR(&closeParams) );
 	return res;
 }
 
@@ -1312,7 +1304,7 @@
 	/* MCI driver will fill in lpstrReturn, dwRetSize.
 	 * FIXME: I don't know if this is correct behaviour
 	 */
-	_MCI_CALL_DRIVER(MCI_INFO,infoParams);
+	_MCI_CALL_DRIVER( MCI_INFO, MAKE_SEGPTR(&infoParams) );
 	if (res==0)
 		_MCI_STR(infoParams.lpstrReturn);
 	return res;
@@ -1409,7 +1401,7 @@
 	strcpy(PTR_SEG_TO_LIN(U.loadParams.lpfilename),s);
 	free(s);
 	dwFlags |= MCI_LOAD_FILE;
-	_MCI_CALL_DRIVER(MCI_LOAD,U);
+	_MCI_CALL_DRIVER( MCI_LOAD, MAKE_SEGPTR(&U) );
 	USER_HEAP_FREE(x);
 	return res;
 }
@@ -1461,7 +1453,7 @@
 	strcpy(PTR_SEG_TO_LIN(U.saveParams.lpfilename),s);
 	free(s);
 	dwFlags |= MCI_LOAD_FILE;
-	_MCI_CALL_DRIVER(MCI_SAVE,U);
+	_MCI_CALL_DRIVER( MCI_SAVE, MAKE_SEGPTR(&U) );
 	USER_HEAP_FREE(x);
 	return res;
 }
@@ -1484,7 +1476,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_CUE,cueParams);
+	_MCI_CALL_DRIVER( MCI_CUE, MAKE_SEGPTR(&cueParams) );
 	return res;
 }
 
@@ -1551,7 +1543,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_DELETE,deleteParams);
+	_MCI_CALL_DRIVER( MCI_DELETE, MAKE_SEGPTR(&deleteParams) );
 	return res;
 }
 
@@ -1585,7 +1577,7 @@
 	strcpy(PTR_SEG_TO_LIN(escapeParams.lpstrCommand),s);
 	free(s);
 	dwFlags |= MCI_VD_ESCAPE_STRING;
-	_MCI_CALL_DRIVER(MCI_ESCAPE,escapeParams);
+	_MCI_CALL_DRIVER( MCI_ESCAPE, MAKE_SEGPTR(&escapeParams) );
 	USER_HEAP_FREE(x);
 	return res;
 }
@@ -1612,7 +1604,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_UNFREEZE,unfreezeParams);
+	_MCI_CALL_DRIVER( MCI_UNFREEZE, MAKE_SEGPTR(&unfreezeParams) );
 	return res;
 }
 /* freeze [part of] the overlayed video 
@@ -1637,7 +1629,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_FREEZE,freezeParams);
+	_MCI_CALL_DRIVER( MCI_FREEZE, MAKE_SEGPTR(&freezeParams) );
 	return res;
 }
 
@@ -1695,7 +1687,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_PUT,U);
+	_MCI_CALL_DRIVER( MCI_PUT, MAKE_SEGPTR(&U) );
 	return res;
 }
 
@@ -1717,7 +1709,7 @@
 		FLAG1("normal",MCI_ANIM_REALIZE_NORM);
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_REALIZE,realizeParams);
+	_MCI_CALL_DRIVER( MCI_REALIZE, MAKE_SEGPTR(&realizeParams) );
 	return res;
 }
 
@@ -1738,7 +1730,7 @@
 		FLAG1("down",MCI_VD_SPIN_UP);
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_SPIN,spinParams);
+	_MCI_CALL_DRIVER( MCI_SPIN, MAKE_SEGPTR(&spinParams) );
 	return res;
 }
 
@@ -1778,7 +1770,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_STEP,U);
+	_MCI_CALL_DRIVER( MCI_STEP, MAKE_SEGPTR(&U) );
 	return res;
 }
 
@@ -1811,7 +1803,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_UPDATE,updateParams);
+	_MCI_CALL_DRIVER( MCI_UPDATE, MAKE_SEGPTR(&updateParams) );
 	return res;
 }
 
@@ -1848,7 +1840,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_WHERE,U);
+	_MCI_CALL_DRIVER( MCI_WHERE, MAKE_SEGPTR(&U) );
 	if (res==0) {
 		char	buf[100];
 		switch (uDevTyp) {
@@ -2029,7 +2021,7 @@
 		}
 		i++;
 	}
-	_MCI_CALL_DRIVER(MCI_WINDOW,U);
+	_MCI_CALL_DRIVER( MCI_WINDOW, MAKE_SEGPTR(&U) );
 	if (s) free(s);
 	return res;
 }
diff --git a/multimedia/time.c b/multimedia/time.c
index b49dfb7..78e306c 100644
--- a/multimedia/time.c
+++ b/multimedia/time.c
@@ -40,9 +40,10 @@
 static LPTIMERENTRY lpTimerList = NULL;
 
 /**************************************************************************
- * 				MMSysTimeCallback	[internal]
+ *           TIME_MMSysTimeCallback
  */
-WORD MMSysTimeCallback(HWND hWnd, WORD wMsg, INT nID, DWORD dwTime)
+static VOID TIME_MMSysTimeCallback( HWND32 hwnd, UINT32 msg,
+                                    UINT32 id, DWORD dwTime )
 {
     LPTIMERENTRY lpTimer = lpTimerList;
     mmSysTimeMS.u.ms += 33;
@@ -53,7 +54,7 @@
 	    lpTimer->wCurTime = lpTimer->wDelay;
 	    if (lpTimer->lpFunc != (FARPROC) NULL) {
 		dprintf_mmtime(stddeb, "MMSysTimeCallback // before CallBack16 !\n");
-		dprintf_mmtime(stddeb, "MMSysTimeCallback // lpFunc=%08lx wTimerID=%04X dwUser=%08lX !\n",
+		dprintf_mmtime(stddeb, "MMSysTimeCallback // lpFunc=%p wTimerID=%04X dwUser=%08lX !\n",
 			lpTimer->lpFunc, lpTimer->wTimerID, lpTimer->dwUser);
 		dprintf_mmtime(stddeb, "MMSysTimeCallback // hInstance=%04X !\n", lpTimer->hInstance);
 
@@ -83,7 +84,6 @@
 	}
 	lpTimer = lpTimer->Next;
     }
-    return 0;
 }
 
 /**************************************************************************
@@ -102,7 +102,7 @@
 	mmSysTimeSMPTE.u.smpte.frame = 0;
 	mmSysTimeSMPTE.u.smpte.fps = 0;
 	mmSysTimeSMPTE.u.smpte.dummy = 0;
-	SetTimer(0, 1, 33, MODULE_GetWndProcEntry16("MMSysTimeCallback"));
+	SetTimer32( 0, 1, 33, TIME_MMSysTimeCallback );
     }
 }
 
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
index 223c0c3..3a003a1 100644
--- a/objects/cursoricon.c
+++ b/objects/cursoricon.c
@@ -552,39 +552,33 @@
 
 
 /***********************************************************************
- *           CopyIcon    (USER.368)
+ *           CopyIcon16    (USER.368)
  */
-#ifdef WINELIB
-HICON CopyIcon( HICON hIcon )
+HICON16 CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
 {
-    dprintf_icon( stddeb, "CopyIcon: %04x\n", hIcon );
-    return CURSORICON_Copy( 0, hIcon );
-}
-#else
-HICON CopyIcon( HANDLE hInstance, HICON hIcon )
-{
-    dprintf_icon( stddeb, "CopyIcon: %04x %04x\n", hInstance, hIcon );
+    dprintf_icon( stddeb, "CopyIcon16: %04x %04x\n", hInstance, hIcon );
     return CURSORICON_Copy( hInstance, hIcon );
 }
-#endif
 
 
 /***********************************************************************
- *           CopyCursor    (USER.369)
+ *           CopyIcon32    (USER32.59)
  */
-#ifdef WINELIB
-HCURSOR CopyCursor( HCURSOR hCursor )
+HICON32 CopyIcon32( HICON32 hIcon )
 {
-    dprintf_cursor( stddeb, "CopyCursor: %04x\n", hCursor );
-    return CURSORICON_Copy( 0, hCursor );
+    dprintf_icon( stddeb, "CopyIcon32: %04x\n", hIcon );
+    return CURSORICON_Copy( 0, hIcon );
 }
-#else
-HCURSOR CopyCursor( HANDLE hInstance, HCURSOR hCursor )
+
+
+/***********************************************************************
+ *           CopyCursor16    (USER.369)
+ */
+HCURSOR16 CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
 {
-    dprintf_cursor( stddeb, "CopyCursor: %04x %04x\n", hInstance, hCursor );
+    dprintf_cursor( stddeb, "CopyCursor16: %04x %04x\n", hInstance, hCursor );
     return CURSORICON_Copy( hInstance, hCursor );
 }
-#endif
 
 
 /***********************************************************************
diff --git a/objects/dcvalues.c b/objects/dcvalues.c
index b1b959b..c330f41 100644
--- a/objects/dcvalues.c
+++ b/objects/dcvalues.c
@@ -3,8 +3,8 @@
  *
  * Copyright 1993 Alexandre Julliard
  *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
+ */
+
 #include "gdi.h"
 #include "metafile.h"
 
diff --git a/objects/font.c b/objects/font.c
index 39dac67..29a7602 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -356,18 +356,18 @@
 
 
 /***********************************************************************
- *           CreateFontIndirect    (GDI.57)
+ *           CreateFontIndirect16   (GDI.57)
  */
-HFONT CreateFontIndirect( const LOGFONT16 * font )
+HFONT16 CreateFontIndirect16( const LOGFONT16 *font )
 {
     FONTOBJ * fontPtr;
-    HFONT hfont;
+    HFONT16 hfont;
 
     if (!font)
-	{
-	fprintf(stderr, "CreateFontIndirect : font is NULL : returning NULL\n");
+    {
+	fprintf(stderr,"CreateFontIndirect: font is NULL : returning NULL\n");
 	return 0;
-	}
+    }
     hfont = GDI_AllocObject( sizeof(FONTOBJ), FONT_MAGIC );
     if (!hfont) return 0;
     fontPtr = (FONTOBJ *) GDI_HEAP_LIN_ADDR( hfont );
@@ -380,6 +380,56 @@
 
 
 /***********************************************************************
+ *           CreateFontIndirect32A   (GDI32.44)
+ */
+HFONT32 CreateFontIndirect32A( const LOGFONT32A *font )
+{
+    LOGFONT16 font16;
+
+    font16.lfHeight         = (INT16)font->lfHeight;
+    font16.lfWidth          = (INT16)font->lfWidth;
+    font16.lfEscapement     = (INT16)font->lfEscapement;
+    font16.lfOrientation    = (INT16)font->lfOrientation;
+    font16.lfWeight         = (INT16)font->lfWeight;
+    font16.lfItalic         = font->lfItalic;
+    font16.lfUnderline      = font->lfUnderline;
+    font16.lfStrikeOut      = font->lfStrikeOut;
+    font16.lfCharSet        = font->lfCharSet;
+    font16.lfOutPrecision   = font->lfOutPrecision;
+    font16.lfClipPrecision  = font->lfClipPrecision;
+    font16.lfQuality        = font->lfQuality;
+    font16.lfPitchAndFamily = font->lfPitchAndFamily;
+    lstrcpyn32A( font16.lfFaceName, font->lfFaceName, LF_FACESIZE );
+    return CreateFontIndirect16( &font16 );
+}
+
+
+/***********************************************************************
+ *           CreateFontIndirect32W   (GDI32.45)
+ */
+HFONT32 CreateFontIndirect32W( const LOGFONT32W *font )
+{
+    LOGFONT16 font16;
+
+    font16.lfHeight         = (INT16)font->lfHeight;
+    font16.lfWidth          = (INT16)font->lfWidth;
+    font16.lfEscapement     = (INT16)font->lfEscapement;
+    font16.lfOrientation    = (INT16)font->lfOrientation;
+    font16.lfWeight         = (INT16)font->lfWeight;
+    font16.lfItalic         = font->lfItalic;
+    font16.lfUnderline      = font->lfUnderline;
+    font16.lfStrikeOut      = font->lfStrikeOut;
+    font16.lfCharSet        = font->lfCharSet;
+    font16.lfOutPrecision   = font->lfOutPrecision;
+    font16.lfClipPrecision  = font->lfClipPrecision;
+    font16.lfQuality        = font->lfQuality;
+    font16.lfPitchAndFamily = font->lfPitchAndFamily;
+    lstrcpynWtoA( font16.lfFaceName, font->lfFaceName, LF_FACESIZE );
+    return CreateFontIndirect16( &font16 );
+}
+
+
+/***********************************************************************
  *           CreateFont    (GDI.56)
  */
 HFONT CreateFont( INT height, INT width, INT esc, INT orient, INT weight,
@@ -390,13 +440,9 @@
     LOGFONT16 logfont = {height, width, esc, orient, weight, italic, underline,
                       strikeout, charset, outpres, clippres, quality, pitch, };
     dprintf_font(stddeb,"CreateFont(%d,%d)\n", height, width);
-    if (name)
-	{
-	strncpy( logfont.lfFaceName, name, LF_FACESIZE - 1 );
-	logfont.lfFaceName[LF_FACESIZE - 1] = '\0';
-	}
+    if (name) lstrcpyn32A(logfont.lfFaceName,name,sizeof(logfont.lfFaceName));
     else logfont.lfFaceName[0] = '\0';
-    return CreateFontIndirect( &logfont );
+    return CreateFontIndirect16( &logfont );
 }
 
 
@@ -1092,13 +1138,13 @@
     dprintf_font(stddeb,"EnumFonts // enum '%s' !\n", lpLogFontList[i]->lfFaceName);
     dprintf_font(stddeb,"EnumFonts // %p !\n", lpLogFontList[i]);
     memcpy(lpLogFont, lpLogFontList[i], sizeof(LOGFONT16) + LF_FACESIZE);
-    hFont = CreateFontIndirect(lpLogFont);
+    hFont = CreateFontIndirect16(lpLogFont);
     hOldFont = SelectObject(hDC, hFont);
     GetTextMetrics16(hDC, lptm);
     SelectObject(hDC, hOldFont);
     DeleteObject(hFont);
     dprintf_font(stddeb,"EnumFonts // i=%d lpLogFont=%p lptm=%p\n", i, lpLogFont, lptm);
-    nRet = CallEnumFontsProc(lpEnumFunc, GDI_HEAP_SEG_ADDR(hLog),
+    nRet = CallEnumFontsProc((FARPROC16)lpEnumFunc, GDI_HEAP_SEG_ADDR(hLog),
 			     GDI_HEAP_SEG_ADDR(hMet), 0, (LONG)lpData );
     if (nRet == 0) {
       dprintf_font(stddeb,"EnumFonts // EnumEnd requested by application !\n");
@@ -1161,14 +1207,14 @@
     memcpy(lpEnumLogFont, lpLogFontList[i], sizeof(LOGFONT16));
     strcpy(lpEnumLogFont->elfFullName,"");
     strcpy(lpEnumLogFont->elfStyle,"");
-    hFont = CreateFontIndirect((LPLOGFONT16)lpEnumLogFont);
+    hFont = CreateFontIndirect16((LPLOGFONT16)lpEnumLogFont);
     hOldFont = SelectObject(hDC, hFont);
     GetTextMetrics16(hDC, lptm);
     SelectObject(hDC, hOldFont);
     DeleteObject(hFont);
     dprintf_font(stddeb, "EnumFontFamilies // i=%d lpLogFont=%p lptm=%p\n", i, lpEnumLogFont, lptm);
     
-    nRet = CallEnumFontFamProc( lpEnumFunc,
+    nRet = CallEnumFontFamProc( (FARPROC16)lpEnumFunc,
 			       GDI_HEAP_SEG_ADDR(hLog),
 			       GDI_HEAP_SEG_ADDR(hMet),
 			       0, lpData );
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index 98289bc..7568e63 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -453,8 +453,8 @@
             pen->lopnWidth.x = 1;
             pen->lopnWidth.y = 0;
             pen->lopnColor   = solid_colors[i];
-            retval = CallEnumObjectsProc( lpEnumFunc, SEGPTR_GET(pen),
-                                          lParam );
+            retval = CallEnumObjectsProc( (FARPROC16)lpEnumFunc,
+                                          SEGPTR_GET(pen), lParam );
             dprintf_gdi( stddeb, "EnumObject: solid pen %08lx, ret=%d\n",
                          solid_colors[i], retval);
             if (!retval) break;
@@ -470,8 +470,8 @@
             brush->lbStyle = BS_SOLID;
             brush->lbColor = solid_colors[i];
             brush->lbHatch = 0;
-            retval = CallEnumObjectsProc( lpEnumFunc, SEGPTR_GET(brush),
-                                          lParam );
+            retval = CallEnumObjectsProc( (FARPROC16)lpEnumFunc,
+                                          SEGPTR_GET(brush), lParam );
             dprintf_gdi( stddeb, "EnumObject: solid brush %08lx, ret=%d\n",
                          solid_colors[i], retval);
             if (!retval) break;
@@ -483,8 +483,8 @@
             brush->lbStyle = BS_HATCHED;
             brush->lbColor = RGB(0,0,0);
             brush->lbHatch = i;
-            retval = CallEnumObjectsProc( lpEnumFunc, SEGPTR_GET(brush),
-                                          lParam );
+            retval = CallEnumObjectsProc( (FARPROC16)lpEnumFunc,
+                                          SEGPTR_GET(brush), lParam );
             dprintf_gdi( stddeb, "EnumObject: hatched brush %d, ret=%d\n",
                          i, retval);
             if (!retval) break;
diff --git a/objects/metafile.c b/objects/metafile.c
index bbaa8c4..f3fb1a7 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -326,8 +326,9 @@
     while (offset < (mh->mtSize * 2))
     {
 	mr = (METARECORD *)((char *)mh + offset);
-        if (!CallEnumMetafileProc(lpEnumFunc, hdc, ht, MAKE_SEGPTR(mr),  /* FIXME!! */
-                                  mh->mtNoObjects, (LONG)lpData))
+        if (!CallEnumMetafileProc( (FARPROC16)lpEnumFunc, hdc, ht,
+                                   MAKE_SEGPTR(mr),  /* FIXME!! */
+                                   mh->mtNoObjects, (LONG)lpData))
 	    break;
 
 	offset += (mr->rdSize * 2);
@@ -568,7 +569,7 @@
 
     case META_CREATEFONTINDIRECT:
 	MF_AddHandle(ht, nHandles, 
-		     CreateFontIndirect((LOGFONT16 *)(&(mr->rdParam))));
+		     CreateFontIndirect16((LOGFONT16 *)(&(mr->rdParam))));
 	break;
 
     case META_CREATEBRUSHINDIRECT:
diff --git a/objects/palette.c b/objects/palette.c
index 1e76dce..d0cf94e 100644
--- a/objects/palette.c
+++ b/objects/palette.c
@@ -304,6 +304,15 @@
 
 
 /***********************************************************************
+ *           SelectPalette32    (GDI32.300)
+ */
+HPALETTE16 SelectPalette32(HDC hDC, HPALETTE16 hPal, BOOL bForceBackground)
+{
+    return GDISelectPalette( hDC, hPal );
+}
+
+
+/***********************************************************************
  *           RealizePalette    (USER.283)
  */
 UINT RealizePalette(HDC hDC)
@@ -311,3 +320,12 @@
     return GDIRealizePalette( hDC );
 }
 
+
+/***********************************************************************
+ *           RealizePalette32    (GDI32.280)
+ */
+UINT RealizePalette32(HDC hDC)
+{
+    return GDIRealizePalette( hDC );
+}
+
diff --git a/tools/build-spec.txt b/tools/build-spec.txt
index 88887c1..a3fca04 100644
--- a/tools/build-spec.txt
+++ b/tools/build-spec.txt
@@ -1,6 +1,7 @@
 name	NAME
 type    win16|win32
-id	ID_NUMBER
+[base   ORDINAL]
+[heap   SIZE]
 
 ORDINAL VARTYPE EXPORTNAME (DATA [DATA [DATA [...]]])
 
@@ -17,10 +18,12 @@
 --------------------
 General:
 
-    "name", "type" and "id" fields are mandatory.  Specific ordinal
+    "name" and "type" fields are mandatory.  Specific ordinal
 declarations are optional, but the default handler will print an error
-message.  Lines whose first character is a '#' will be ignored as
-comments.
+message.  "base" gives the offset of the first ordinal; default is 0.
+"heap" is the size of the module local heap (only valid for Win16
+modules); default is no local heap.  Lines whose first character is a
+'#' will be ignored as comments.
 
 Variable ordinals:
 
@@ -33,19 +36,36 @@
 by "0x".  The following example defines the variable "VariableA" at
 ordinal 2 and containing 4 bytes:
 
-	2 byte VariableA -1 0xff 0 0
+	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
-dynamic linking and the format of the 16-bit stack. "ORDINAL" is replaced
-by the ordinal number corresponding to the function.  "FUNCTYPE" should be
-"pascal16" or "pascal" for 16-bit or 32-bit return values.  "ARGTYPE"
-should be "byte", "word", "long", "ptr" (linear pointer), "s_byte" (signed
-byte), "s_word" (signed word), "s_long" (signed long), or "segptr"
-(segmented pointer).  "HANDLERNAME" is the name of the actual function that
-will process the request in 32-bit mode.
+dynamic linking and the format of the arguments. "ORDINAL" is replaced
+by the ordinal number corresponding to the function.
+
+"FUNCTYPE" should be one of:
+- "pascal16" for a Win16 function returning a 16-bit value
+- "pascal" for a Win16 function returning a 32-bit value
+- "register" for a function using CPU register to pass arguments
+- "stdcall" for a normal Win32 function
+- "cdecl" for a Win32 function using the C calling convention
+
+"ARGTYPE" should be one of:
+- "byte"
+- "word"
+- "long"
+- "ptr" (linear pointer)
+- "s_byte" (signed byte)
+- "s_word" (signed word)
+- "s_long" (signed long)
+- "segptr" (segmented pointer).
+
+Only "ptr" and "long" are valid for Win32 functions.
+
+"HANDLERNAME" is the name of the actual Wine function that will
+process the request in 32-bit mode.
 
     This first example defines an entry point for the CreateWindow()
 call (the ordinal 100 is just an example):
diff --git a/tools/build.c b/tools/build.c
index d72a5fc..6a44683 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -24,16 +24,17 @@
 #endif
 
 #define TYPE_INVALID     0
-#define TYPE_BYTE        1
-#define TYPE_WORD        2
-#define TYPE_LONG        3
-#define TYPE_PASCAL_16   4
-#define TYPE_PASCAL      5
-#define TYPE_REGISTER    6
-#define TYPE_ABS         7
-#define TYPE_RETURN      8
-#define TYPE_STUB        9
-#define TYPE_STDCALL    10
+#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) */
 
 #define MAX_ORDINALS	1299
 
@@ -295,6 +296,11 @@
             fprintf( stderr, "%d: 'stdcall' not supported for Win16\n", Line );
             exit(1);
         }
+        if (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))
@@ -354,7 +360,8 @@
         exit(1);
     }
     fdp->arg_types[i] = '\0';
-
+    if ((type == TYPE_STDCALL) && !i)
+        odp->type = TYPE_CDECL; /* stdcall is the same as cdecl for 0 args */
     strcpy(fdp->internal_name, GetToken());
     return 0;
 }
@@ -468,6 +475,8 @@
         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)
@@ -811,6 +820,7 @@
     pModule->magic = NE_SIGNATURE;
     pModule->count = 1;
     pModule->next = 0;
+    pModule->dgroup_entry = 0;
     pModule->flags = NE_FFLAGS_SINGLEDATA | NE_FFLAGS_BUILTIN |
                      NE_FFLAGS_LIBMODULE | NE_FFLAGS_WIN32;
     pModule->dgroup = 0;
@@ -900,7 +910,8 @@
     ORDDEF *odp;
     ORDFUNCDEF *fdp;
     ORDRETDEF *rdp;
-    int i, module_size;
+    int i, module_size, len;
+    char buffer[1024];
 
     printf( "/* File generated automatically; do not edit! */\n" );
     printf( "\t.text\n" );
@@ -916,39 +927,68 @@
         switch (odp->type)
         {
         case TYPE_INVALID:
-            printf( "/* %s.%d */\n", DLLName, i );
-            printf( "\t.align 4\n" );
-            printf( "%s_%d:\n", DLLName, i );
-            printf( "\tpushl %%ebp\n" );
-            printf( "\tpushl $Name_%d\n", i );
-            printf( "\tpushl $" PREFIX "%s\n", STUB_CALLBACK );
-            printf( "\tjmp " PREFIX "CallFrom32_0\n" );
             break;
 
         case TYPE_STDCALL:
+        case TYPE_CDECL:
         case TYPE_STUB:
             printf( "/* %s.%d (%s) */\n",
                      DLLName, i, odp->export_name);
-            printf( "\t.align 4\n" );
             printf( "%s_%d:\n", DLLName, i );
             printf( "\tpushl %%ebp\n" );
-            printf( "\tpushl $Name_%d\n", i );
             printf( "\tpushl $" PREFIX "%s\n", fdp->internal_name );
-            printf( "\tjmp " PREFIX "CallFrom32_%d\n", strlen(fdp->arg_types));
+            printf( "\tcall " PREFIX "CallFrom32_%s_%d\n",
+                    (odp->type == TYPE_STDCALL) ? "stdcall" : "cdecl",
+                    strlen(fdp->arg_types));
+            printf( "\tnop\n" );
             break;
 
         case TYPE_RETURN:
             printf( "/* %s.%d (%s) */\n",
                      DLLName, i, odp->export_name);
-            printf( "\t.align 4\n" );
             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( "\tret $%d\n", rdp->arg_size );
+            if (rdp->arg_size)
+            {
+                printf( "\tret $%d\n", rdp->arg_size );
+                printf( "\tnop\n" );
+                printf( "\tnop\n" );
+            }
             else printf( "\tret\n" );
             break;
 
+        case TYPE_BYTE:
+            printf( "/* %s.%d (%s) */\n",
+                     DLLName, i, odp->export_name);
+            printf( "\t.data\n" );
+            printf( "%s_%d:\n", DLLName, i );
+            len = StoreVariableCode( buffer, 1, odp );
+            DumpBytes( buffer, len, NULL, NULL );
+            printf( "\t.text\n" );
+            break;
+
+        case TYPE_WORD:
+            printf( "/* %s.%d (%s) */\n",
+                     DLLName, i, odp->export_name);
+            printf( "\t.data\n" );
+            printf( "%s_%d:\n", DLLName, i );
+            len = StoreVariableCode( buffer, 2, odp );
+            DumpBytes( buffer, len, NULL, NULL );
+            printf( "\t.text\n" );
+            break;
+
+        case TYPE_LONG:
+            printf( "/* %s.%d (%s) */\n",
+                     DLLName, i, odp->export_name);
+            printf( "\t.data\n" );
+            printf( "%s_%d:\n", DLLName, i );
+            len = StoreVariableCode( buffer, 4, odp );
+            DumpBytes( buffer, len, NULL, NULL );
+            printf( "\t.text\n" );
+            break;
+
         default:
             fprintf(stderr,"build: function type %d not available for Win32\n",
                     odp->type);
@@ -964,7 +1004,11 @@
     printf( "\t.align 4\n" );
     printf( "Functions:\n" );
     odp = OrdinalDefinitions;
-    for (i = 0; i <= Limit; i++, odp++) printf("\t.long %s_%d\n", DLLName, i);
+    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);
+    }
 
     /* Output the DLL names table */
 
@@ -980,11 +1024,8 @@
 
     for (i = 0, odp = OrdinalDefinitions; i <= Limit; i++, odp++)
     {
-        printf( "Name_%d:\t", i );
-        if (odp->type == TYPE_INVALID)
-            printf( ".ascii \"%s.%d\\0\"\n", DLLName, i );
-        else
-            printf( ".ascii \"%s\\0\"\n", odp->export_name );
+        if (odp->type != TYPE_INVALID)
+            printf( "Name_%d:\t.ascii \"%s\\0\"\n", i, odp->export_name );
     }
 
     /* Output the DLL descriptor */
@@ -1482,6 +1523,8 @@
     printf( "\tpopw %%ss\n" );
     printf( "\tleal -%d(%%ebp),%%esp\n",
             reg_func ? sizeof(SIGCONTEXT) : 4 * strlen(args) );
+    if (reg_func)  /* Push the address of the context struct */
+        printf( "\tpushl %%esp\n" );
 
     /* Setup %ebp to point to the previous stack frame (built by CallTo16) */
 
@@ -1840,19 +1883,37 @@
  * (ebp+8)   arg1
  * (ebp+4)   ret addr
  * (ebp)     ebp
- * (ebp-4)   func name
- * (ebp-8)   entry point
+ * (ebp-4)   entry point
+ * (ebp-8)   func name
  */
-static void BuildCallFrom32Func( int args )
+static void BuildCallFrom32Func( const char *profile )
 {
+    int args, stdcall;
+
+    if (!strncmp( profile, "stdcall", 7 ))
+    {
+        stdcall = 1;
+        args = atoi( profile + 8 );
+    }
+    else if (!strncmp( profile, "cdecl", 5 ))
+    {
+        stdcall = 0;
+        args = atoi( profile + 6 );
+    }
+    else
+    {
+        fprintf( stderr, "Invalid function profile '%s'\n", profile );
+        return;
+    }
+
     /* Function header */
 
     printf( "/**********\n" );
-    printf( " * " PREFIX "CallFrom32_%d\n", args );
+    printf( " * " PREFIX "CallFrom32_%s\n", profile );
     printf( " **********/\n" );
     printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "CallFrom32_%d\n\n", args );
-    printf( PREFIX "CallFrom32_%d:\n", args );
+    printf( "\t.globl " PREFIX "CallFrom32_%s\n\n", profile );
+    printf( PREFIX "CallFrom32_%s:\n", profile );
 
     /* Entry code */
 
@@ -1884,7 +1945,7 @@
 
     /* Call the function */
 
-    printf( "\tcall -8(%%ebp)\n" );
+    printf( "\tcall -4(%%ebp)\n" );
 
     /* Print the debugging info */
 
@@ -1901,7 +1962,7 @@
 
     /* Return, removing arguments */
 
-    if (args) printf( "\tret $%d\n", args * 4 );
+    if (args && stdcall) printf( "\tret $%d\n", args * 4 );
     else printf( "\tret\n" );
 }
 
@@ -2045,7 +2106,7 @@
 
         /* Build the callback functions */
 
-        for (i = 2; i < argc; i++) BuildCallFrom32Func( atoi(argv[i]) );
+        for (i = 2; i < argc; i++) BuildCallFrom32Func( argv[i] );
     }
     else if (!strcmp( argv[1], "-callto32" ))  /* Wine-to-32-bit callbacks */
     {
diff --git a/win32/except.c b/win32/except.c
index 8e42cc4..25d2585 100644
--- a/win32/except.c
+++ b/win32/except.c
@@ -44,7 +44,7 @@
 
 void EXC_Init(void)
 {
-    pTopExcHandler = (LPTOP_LEVEL_EXCEPTION_FILTER)PE_GetProcAddress(
+    pTopExcHandler = (LPTOP_LEVEL_EXCEPTION_FILTER)GetProcAddress32(
                                                  GetModuleHandle("KERNEL32"),
                                                  "UnhandledExceptionFilter" );
 }
diff --git a/win32/process.c b/win32/process.c
index 44ec155..2a41875 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -11,6 +11,7 @@
 #include "winerror.h"
 #include "kernel32.h"
 #include "handle32.h"
+#include "task.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -22,7 +23,7 @@
 
 void ExitProcess(DWORD status)
 {
-        exit(status);
+    TASK_KillCurrentTask( status );
 }
 
 /***********************************************************************
@@ -128,18 +129,6 @@
 	return TRUE;
 }
 
-#ifndef WINELIB
-/***********************************************************************
- *          WIN32_GetProcAddress
- */
-void* WIN32_GetProcAddress(HANDLE32 hModule, char* function)
-{
-	dprintf_module( stddeb, "WIN32_GetProcAddress(%08x,%s)\n",
-		hModule, function);
-	return PE_GetProcAddress(GetExePtr(hModule),function);
-}
-#endif  /* WINELIB */
-
 /**********************************************************************
  *          GetProcessAffinityMask
  */
diff --git a/win32/resource.c b/win32/resource.c
index 0bd6f4d..2b852bc 100644
--- a/win32/resource.c
+++ b/win32/resource.c
@@ -293,7 +293,7 @@
     return hAccel;
 #else
 	fprintf(stderr,"LoadAcceleratorsW: not implemented\n");
-	return 0;
+	return 0x100;  /* Return something anyway */
 #endif
 }
 
diff --git a/win32/user32.c b/win32/user32.c
index 47035de..6b1e455 100644
--- a/win32/user32.c
+++ b/win32/user32.c
@@ -80,11 +80,3 @@
 	/* FIXME: Should perform Unicode translation on specific messages */
 	return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
 }
-
-UINT USER32_SetTimer(HWND hwnd, UINT id, UINT timeout, void *proc)
-
-{
-    dprintf_win32(stddeb, "USER32_SetTimer: %d %d %d %08lx\n", hwnd, id, timeout,
-(LONG)proc );
-    return SetTimer( hwnd, id, timeout, MAKE_SEGPTR(proc));
-}   
diff --git a/windows/caret.c b/windows/caret.c
index 902d309..e7f4b65 100644
--- a/windows/caret.c
+++ b/windows/caret.c
@@ -14,16 +14,16 @@
 
 typedef struct
 {
-    HWND          hwnd;
-    short         hidden;
-    BOOL          on;
-    short         x;
-    short         y;
-    short         width;
-    short         height;
-    HBRUSH        hBrush;
-    WORD          timeout;
-    WORD          timerid;
+    HWND32     hwnd;
+    UINT32     hidden;
+    BOOL32     on;
+    INT32      x;
+    INT32      y;
+    INT32      width;
+    INT32      height;
+    HBRUSH16   hBrush;
+    UINT32     timeout;
+    UINT32     timerid;
 } CARET;
 
 typedef enum
@@ -33,13 +33,13 @@
     CARET_TOGGLE,
 } DISPLAY_CARET;
 
-static CARET Caret = { 0, };
+static CARET Caret;
 
 
 /*****************************************************************
  *              CARET_GetHwnd
  */
-HWND CARET_GetHwnd()
+HWND32 CARET_GetHwnd()
 {
     return Caret.hwnd;
 }
@@ -47,10 +47,10 @@
 /*****************************************************************
  *               CARET_DisplayCaret
  */
-void CARET_DisplayCaret(DISPLAY_CARET status)
+static void CARET_DisplayCaret( DISPLAY_CARET status )
 {
-    HDC hdc;
-    HBRUSH hPrevBrush;
+    HDC16 hdc;
+    HBRUSH16 hPrevBrush;
 
     if (Caret.on && (status == CARET_ON)) return;
     if (!Caret.on && (status == CARET_OFF)) return;
@@ -69,37 +69,35 @@
 /*****************************************************************
  *               CARET_Callback
  */
-WORD CARET_Callback(HWND hwnd, WORD msg, WORD timerid, LONG ctime)
+static VOID CARET_Callback( HWND32 hwnd, UINT32 msg, UINT32 id, DWORD ctime)
 {
     dprintf_caret(stddeb,"CARET_Callback: hwnd=%04x, timerid=%d, caret=%d\n",
-                  hwnd, timerid, Caret.on);
-	
+                  hwnd, id, Caret.on);
     CARET_DisplayCaret(CARET_TOGGLE);
-    return 0;
 }
 
 
 /*****************************************************************
  *               CARET_SetTimer
  */
-void CARET_SetTimer(void)
+static void CARET_SetTimer(void)
 {
-    if (Caret.timerid) KillSystemTimer((HWND)0, Caret.timerid);
-    Caret.timerid = SetSystemTimer((HWND)0, 0, Caret.timeout,
-                                   MODULE_GetWndProcEntry16("CARET_Callback"));
+    if (Caret.timerid) KillSystemTimer32( (HWND32)0, Caret.timerid );
+    Caret.timerid = SetSystemTimer32( (HWND32)0, 0, Caret.timeout,
+                                      CARET_Callback );
 }
 
 
 /*****************************************************************
  *               CARET_ResetTimer
  */
-void CARET_ResetTimer(void)
+static void CARET_ResetTimer(void)
 {
     if (Caret.timerid) 
     {
-	KillSystemTimer((HWND)0, Caret.timerid);
-	Caret.timerid = SetSystemTimer((HWND)0, 0, Caret.timeout,
-                                   MODULE_GetWndProcEntry16("CARET_Callback"));
+	KillSystemTimer32( (HWND32)0, Caret.timerid );
+	Caret.timerid = SetSystemTimer32( (HWND32)0, 0, Caret.timeout,
+                                          CARET_Callback );
     }
 }
 
@@ -107,20 +105,20 @@
 /*****************************************************************
  *               CARET_KillTimer
  */
-void CARET_KillTimer(void)
+static void CARET_KillTimer(void)
 {
     if (Caret.timerid) 
     {
-	KillSystemTimer((HWND)0, Caret.timerid);
+	KillSystemTimer32( (HWND32)0, Caret.timerid );
 	Caret.timerid = 0;
     }
 }
 
 
 /*****************************************************************
- *               CreateCaret          (USER.163)
+ *           CreateCaret   (USER.163) (USER32.65)
  */
-BOOL CreateCaret(HWND hwnd, HBITMAP bitmap, INT width, INT height)
+BOOL16 CreateCaret( HWND32 hwnd, HBITMAP32 bitmap, INT32 width, INT32 height )
 {
     dprintf_caret(stddeb,"CreateCaret: hwnd=%04x\n", hwnd);
 
@@ -158,10 +156,9 @@
    
 
 /*****************************************************************
- *               DestroyCaret         (USER.164)
+ *           DestroyCaret   (USER.164) (USER32.130)
  */
-
-BOOL DestroyCaret()
+BOOL16 DestroyCaret(void)
 {
     if (!Caret.hwnd) return FALSE;
 
@@ -171,20 +168,18 @@
     DeleteObject( Caret.hBrush );
     CARET_KillTimer();
     CARET_DisplayCaret(CARET_OFF);
-
     Caret.hwnd = 0;
     return TRUE;
 }
 
 
 /*****************************************************************
- *               SetCaretPos          (USER.165)
+ *           SetCaretPos   (USER.165) (USER32.465)
  */
-
-void SetCaretPos(short x, short y)
+BOOL16 SetCaretPos( INT32 x, INT32 y)
 {
-    if (!Caret.hwnd) return;
-    if ((x == Caret.x) && (y == Caret.y)) return;
+    if (!Caret.hwnd) return FALSE;
+    if ((x == Caret.x) && (y == Caret.y)) return TRUE;
 
     dprintf_caret(stddeb,"SetCaretPos: x=%d, y=%d\n", x, y);
 
@@ -197,16 +192,17 @@
 	CARET_DisplayCaret(CARET_ON);
 	CARET_SetTimer();
     }
+    return TRUE;
 }
 
-/*****************************************************************
- *               HideCaret            (USER.166)
- */
 
-void HideCaret(HWND hwnd)
+/*****************************************************************
+ *           HideCaret   (USER.166) (USER32.316)
+ */
+BOOL16 HideCaret( HWND32 hwnd )
 {
-    if (!Caret.hwnd) return;
-    if (hwnd && (Caret.hwnd != hwnd)) return;
+    if (!Caret.hwnd) return FALSE;
+    if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
 
     dprintf_caret(stddeb,"HideCaret: hwnd=%04x, hidden=%d\n",
                   hwnd, Caret.hidden);
@@ -214,17 +210,17 @@
     CARET_KillTimer();
     CARET_DisplayCaret(CARET_OFF);
     Caret.hidden++;
+    return TRUE;
 }
 
 
 /*****************************************************************
- *               ShowCaret            (USER.167)
+ *           ShowCaret   (USER.167) (USER32.528)
  */
-
-void ShowCaret(HWND hwnd)
+BOOL16 ShowCaret( HWND32 hwnd )
 {
-    if (!Caret.hwnd) return;
-    if (hwnd && (Caret.hwnd != hwnd)) return;
+    if (!Caret.hwnd) return FALSE;
+    if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
 
     dprintf_caret(stddeb,"ShowCaret: hwnd=%04x, hidden=%d\n",
 		hwnd, Caret.hidden);
@@ -238,61 +234,66 @@
 	    CARET_SetTimer();
 	}
     }
+    return TRUE;
 }
 
 
 /*****************************************************************
- *               SetCaretBlinkTime    (USER.168)
+ *           SetCaretBlinkTime   (USER.168) (USER32.464)
  */
-
-void SetCaretBlinkTime(WORD msecs)
+BOOL16 SetCaretBlinkTime( UINT32 msecs )
 {
-    if (!Caret.hwnd) return;
+    if (!Caret.hwnd) return FALSE;
 
     dprintf_caret(stddeb,"SetCaretBlinkTime: hwnd=%04x, msecs=%d\n",
 		Caret.hwnd, msecs);
 
     Caret.timeout = msecs;
     CARET_ResetTimer();
+    return TRUE;
 }
 
 
 /*****************************************************************
- *               GetCaretBlinkTime    (USER.169)
+ *           GetCaretBlinkTime16   (USER.169)
  */
+UINT16 GetCaretBlinkTime16(void)
+{
+    return (UINT16)GetCaretBlinkTime32();
+}
 
-WORD GetCaretBlinkTime()
+
+/*****************************************************************
+ *           GetCaretBlinkTime32   (USER32.208)
+ */
+UINT32 GetCaretBlinkTime32(void)
 {
     if (!Caret.hwnd) return 0;
-
-    dprintf_caret(stddeb,"GetCaretBlinkTime: hwnd=%04x, msecs=%d\n",
-		Caret.hwnd, Caret.timeout);
-
     return Caret.timeout;
 }
 
 
 /*****************************************************************
- *               GetCaretPos16          (USER.183)
+ *           GetCaretPos16   (USER.183)
  */
-void GetCaretPos16( LPPOINT16 pt )
+VOID GetCaretPos16( LPPOINT16 pt )
 {
     if (!Caret.hwnd || !pt) return;
 
     dprintf_caret(stddeb,"GetCaretPos: hwnd=%04x, pt=%p, x=%d, y=%d\n",
                   Caret.hwnd, pt, Caret.x, Caret.y);
-
-    pt->x = Caret.x;
-    pt->y = Caret.y;
+    pt->x = (INT16)Caret.x;
+    pt->y = (INT16)Caret.y;
 }
 
 
 /*****************************************************************
- *               GetCaretPos32          (USER32.209)
+ *           GetCaretPos32   (USER32.209)
  */
-void GetCaretPos32( LPPOINT32 pt )
+BOOL32 GetCaretPos32( LPPOINT32 pt )
 {
-    if (!Caret.hwnd || !pt) return;
+    if (!Caret.hwnd || !pt) return FALSE;
     pt->x = Caret.x;
     pt->y = Caret.y;
+    return TRUE;
 }
diff --git a/windows/defwnd.c b/windows/defwnd.c
index caca49e..7d63ce1 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -121,9 +121,9 @@
     case WM_NCDESTROY:
 	if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
 	wndPtr->text = NULL;
-	if (wndPtr->hVScroll) USER_HEAP_FREE(wndPtr->hVScroll);
-	if (wndPtr->hHScroll) USER_HEAP_FREE(wndPtr->hHScroll);
-        wndPtr->hVScroll = wndPtr->hHScroll = 0;
+	if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
+	if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
+        wndPtr->pVScroll = wndPtr->pHScroll = NULL;
 	return 0;
 	
     case WM_PAINT:
diff --git a/windows/dialog.c b/windows/dialog.c
index ce5a675..7e86721 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -295,11 +295,6 @@
         }
         if (!hwndCtrl) return FALSE;
 
-        /* Make the control last one in Z-order, so that controls remain
-           in the order in which they were created */
-	SetWindowPos( hwndCtrl, HWND_BOTTOM, 0, 0, 0, 0,
-                      SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
-
             /* Send initialisation messages to the control */
         if (dlgInfo->hUserFont) SendMessage32A( hwndCtrl, WM_SETFONT,
                                                (WPARAM)dlgInfo->hUserFont, 0 );
@@ -548,7 +543,10 @@
     rect.bottom -= rect.top;
 
     if ((INT16)template.x == CW_USEDEFAULT16)
-        rect.left = rect.top = CW_USEDEFAULT16;
+    {
+        rect.left = rect.top = (procType == WIN_PROC_16) ? CW_USEDEFAULT16
+                                                         : CW_USEDEFAULT32;
+    }
     else
     {
         rect.left += template.x * xUnit / 4;
@@ -929,36 +927,20 @@
             break;
 
         case VK_ESCAPE:
-#ifdef WINELIB32
-            SendMessage32A( hwndDlg, WM_COMMAND, 
-                            MAKEWPARAM( IDCANCEL, 0 ),
-                            (LPARAM)GetDlgItem(hwndDlg,IDCANCEL) );
-#else
-            SendMessage16( hwndDlg, WM_COMMAND, IDCANCEL,
-                           MAKELPARAM( GetDlgItem(hwndDlg,IDCANCEL), 0 ));
-#endif
+            SendMessage32A( hwndDlg, WM_COMMAND, IDCANCEL,
+                            (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
             break;
 
         case VK_RETURN:
             {
                 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
                 if (HIWORD(dw) == DC_HASDEFID)
-#ifdef WINELIB32
                     SendMessage32A( hwndDlg, WM_COMMAND, 
                                     MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
-                                   (LPARAM)GetDlgItem( hwndDlg, LOWORD(dw) ) );
+                                    (LPARAM)GetDlgItem( hwndDlg, LOWORD(dw) ));
                 else
-                    SendMessage32A( hwndDlg, WM_COMMAND, 
-                                    MAKEWPARAM( IDOK, 0 ),
-                                    (LPARAM)GetDlgItem(hwndDlg,IDOK) );
-#else
-                    SendMessage16( hwndDlg, WM_COMMAND, LOWORD(dw),
-                                 MAKELPARAM( GetDlgItem( hwndDlg, LOWORD(dw) ),
-                                             BN_CLICKED ));
-                else
-                    SendMessage16( hwndDlg, WM_COMMAND, IDOK,
-                                 MAKELPARAM( GetDlgItem(hwndDlg,IDOK), 0 ));
-#endif
+                    SendMessage32A( hwndDlg, WM_COMMAND, IDOK,
+                                    (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
             }
             break;
 
@@ -985,9 +967,9 @@
 
 
 /****************************************************************
- *         GetDlgCtrlID           (USER.277)
+ *         GetDlgCtrlID   (USER.277) (USER32.233)
  */
-int GetDlgCtrlID( HWND hwnd )
+INT16 GetDlgCtrlID( HWND32 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr(hwnd);
     if (wndPtr) return wndPtr->wIDmenu;
@@ -1164,9 +1146,9 @@
 
 
 /***********************************************************************
- *           CheckDlgButton   (USER.97)
+ *           CheckDlgButton   (USER.97) (USER32.44)
  */
-BOOL CheckDlgButton( HWND hwnd, INT id, UINT check )
+BOOL16 CheckDlgButton( HWND32 hwnd, INT32 id, UINT32 check )
 {
     SendDlgItemMessage32A( hwnd, id, BM_SETCHECK32, check, 0 );
     return TRUE;
@@ -1183,9 +1165,10 @@
 
 
 /***********************************************************************
- *           CheckRadioButton   (USER.96)
+ *           CheckRadioButton   (USER.96) (USER32.47)
  */
-BOOL CheckRadioButton( HWND hwndDlg, UINT firstID, UINT lastID, UINT checkID )
+BOOL16 CheckRadioButton( HWND32 hwndDlg, UINT32 firstID, UINT32 lastID,
+                         UINT32 checkID )
 {
     WND *pWnd = WIN_FindWndPtr( hwndDlg );
     if (!pWnd) return FALSE;
diff --git a/windows/event.c b/windows/event.c
index 4a87d91..cf14d07 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -884,7 +884,7 @@
  *           Mouse_Event   (USER.299)
  */
 #ifndef WINELIB
-void Mouse_Event( SIGCONTEXT context )
+void Mouse_Event( SIGCONTEXT *context )
 {
     /* Register values:
      * AX = mouse event
@@ -897,25 +897,25 @@
     int rootX, rootY, childX, childY;
     unsigned int state;
 
-    if (AX_reg(&context) & ME_MOVE)
+    if (AX_reg(context) & ME_MOVE)
     {
         /* We have to actually move the cursor */
         XWarpPointer( display, rootWindow, None, 0, 0, 0, 0,
-                      (short)BX_reg(&context), (short)CX_reg(&context) );
+                      (short)BX_reg(context), (short)CX_reg(context) );
         return;
     }
     if (!XQueryPointer( display, rootWindow, &root, &child,
                         &rootX, &rootY, &childX, &childY, &state )) return;
-    if (AX_reg(&context) & ME_LDOWN)
+    if (AX_reg(context) & ME_LDOWN)
         hardware_event( WM_LBUTTONDOWN, EVENT_XStateToKeyState( state ), 0L,
                         rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
-    if (AX_reg(&context) & ME_LUP)
+    if (AX_reg(context) & ME_LUP)
         hardware_event( WM_LBUTTONUP, EVENT_XStateToKeyState( state ), 0L,
                         rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
-    if (AX_reg(&context) & ME_RDOWN)
+    if (AX_reg(context) & ME_RDOWN)
         hardware_event( WM_RBUTTONDOWN, EVENT_XStateToKeyState( state ), 0L,
                         rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
-    if (AX_reg(&context) & ME_RUP)
+    if (AX_reg(context) & ME_RUP)
         hardware_event( WM_RBUTTONUP, EVENT_XStateToKeyState( state ), 0L,
                         rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
 }
diff --git a/windows/graphics.c b/windows/graphics.c
index 00770c7..f1cb9e7 100644
--- a/windows/graphics.c
+++ b/windows/graphics.c
@@ -991,8 +991,8 @@
  *
  * Main flood-fill routine.
  */
-static BOOL GRAPH_DoFloodFill( DC *dc, RECT16 *rect, INT16 x, INT16 y,
-                               COLORREF color, WORD fillType )
+static BOOL16 GRAPH_DoFloodFill( DC *dc, RECT16 *rect, INT32 x, INT32 y,
+                                 COLORREF color, UINT32 fillType )
 {
     XImage *image;
 
@@ -1021,9 +1021,10 @@
 
 
 /**********************************************************************
- *          ExtFloodFill  (GDI.372)
+ *          ExtFloodFill  (GDI.372) (GDI32.96)
  */
-BOOL ExtFloodFill( HDC hdc, INT x, INT y, COLORREF color, WORD fillType )
+BOOL16 ExtFloodFill( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
+                     UINT32 fillType )
 {
     RECT16 rect;
     DC *dc;
@@ -1049,32 +1050,129 @@
 
 
 /**********************************************************************
- *          FloodFill  (GDI.25)
+ *          FloodFill  (GDI.25) (GDI32.104)
  */
-BOOL FloodFill( HDC hdc, INT x, INT y, COLORREF color )
+BOOL16 FloodFill( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
 {
     return ExtFloodFill( hdc, x, y, color, FLOODFILLBORDER );
 }
 
 
 /**********************************************************************
- *          DrawEdge  (USER.659)
+ *          DrawEdge16   (USER.659)
  */
-BOOL DrawEdge(HDC hdc, LPRECT16 qrc, UINT edge, UINT flags)
+BOOL16 DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
 {
-	fprintf(stdnimp,"DrawEdge(%x,%p,%d,%x), empty stub!\n",
-		hdc,qrc,edge,flags
-	);
-	return TRUE;
+    RECT32 rect32;
+    BOOL32 ret;
+
+    CONV_RECT16TO32( rc, &rect32 );
+    ret = DrawEdge32( hdc, &rect32, edge, flags );
+    CONV_RECT32TO16( &rect32, rc );
+    return ret;
 }
 
+
 /**********************************************************************
- *          DrawFrameControl  (USER.656)
+ *          DrawEdge32   (USER32.154)
  */
-BOOL DrawFrameControl(HDC hdc, LPRECT16 qrc, UINT edge, UINT flags)
+BOOL32 DrawEdge32( HDC32 hdc, LPRECT32 rc, UINT32 edge, UINT32 flags )
 {
-	fprintf(stdnimp,"DrawFrameControl(%x,%p,%d,%x), empty stub!\n",
-		hdc,qrc,edge,flags
-	);
-	return TRUE;
+    HBRUSH hbrushOld;
+
+    if (flags >= BF_DIAGONAL)
+        fprintf( stderr, "DrawEdge: unsupported flags %04x\n", flags );
+
+    dprintf_graphics( stddeb, "DrawEdge: %04x %d,%d-%d,%d %04x %04x\n",
+                      hdc, rc->left, rc->top, rc->right, rc->bottom,
+                      edge, flags );
+
+    /* First do all the raised edges */
+
+    SelectObject( hdc, sysColorObjects.hbrushBtnHighlight );
+    if (edge & BDR_RAISEDOUTER)
+    {
+        if (flags & BF_LEFT) PatBlt( hdc, rc->left, rc->top,
+                                     1, rc->bottom - rc->top - 1, PATCOPY );
+        if (flags & BF_TOP) PatBlt( hdc, rc->left, rc->top,
+                                     rc->right - rc->left - 1, 1, PATCOPY );
+    }
+    if (edge & BDR_SUNKENOUTER)
+    {
+        if (flags & BF_RIGHT) PatBlt( hdc, rc->right - 1, rc->top,
+                                      1, rc->bottom - rc->top, PATCOPY );
+        if (flags & BF_BOTTOM) PatBlt( hdc, rc->left, rc->bottom - 1,
+                                       rc->right - rc->left, 1, PATCOPY );
+    }
+    if (edge & BDR_RAISEDINNER)
+    {
+        if (flags & BF_LEFT) PatBlt( hdc, rc->left + 1, rc->top + 1, 
+                                     1, rc->bottom - rc->top - 2, PATCOPY );
+        if (flags & BF_TOP) PatBlt( hdc, rc->left + 1, rc->top + 1,
+                                     rc->right - rc->left - 2, 1, PATCOPY );
+    }
+    if (edge & BDR_SUNKENINNER)
+    {
+        if (flags & BF_RIGHT) PatBlt( hdc, rc->right - 2, rc->top + 1,
+                                     1, rc->bottom - rc->top - 2, PATCOPY );
+        if (flags & BF_BOTTOM) PatBlt( hdc, rc->left + 1, rc->bottom - 2,
+                                       rc->right - rc->left - 2, 1, PATCOPY );
+    }
+
+    /* Then do all the sunken edges */
+
+    hbrushOld = SelectObject( hdc, sysColorObjects.hbrushBtnShadow );
+    if (edge & BDR_SUNKENOUTER)
+    {
+        if (flags & BF_LEFT) PatBlt( hdc, rc->left, rc->top,
+                                     1, rc->bottom - rc->top - 1, PATCOPY );
+        if (flags & BF_TOP) PatBlt( hdc, rc->left, rc->top,
+                                     rc->right - rc->left - 1, 1, PATCOPY );
+    }
+    if (edge & BDR_RAISEDOUTER)
+    {
+        if (flags & BF_RIGHT) PatBlt( hdc, rc->right - 1, rc->top,
+                                      1, rc->bottom - rc->top, PATCOPY );
+        if (flags & BF_BOTTOM) PatBlt( hdc, rc->left, rc->bottom - 1,
+                                       rc->right - rc->left, 1, PATCOPY );
+    }
+    if (edge & BDR_SUNKENINNER)
+    {
+        if (flags & BF_LEFT) PatBlt( hdc, rc->left + 1, rc->top + 1, 
+                                     1, rc->bottom - rc->top - 2, PATCOPY );
+        if (flags & BF_TOP) PatBlt( hdc, rc->left + 1, rc->top + 1,
+                                     rc->right - rc->left - 2, 1, PATCOPY );
+    }
+    if (edge & BDR_RAISEDINNER)
+    {
+        if (flags & BF_RIGHT) PatBlt( hdc, rc->right - 2, rc->top + 1,
+                                     1, rc->bottom - rc->top - 2, PATCOPY );
+        if (flags & BF_BOTTOM) PatBlt( hdc, rc->left + 1, rc->bottom - 2,
+                                       rc->right - rc->left - 2, 1, PATCOPY );
+    }
+
+    SelectObject( hdc, hbrushOld );
+    return TRUE;
+}
+
+
+/**********************************************************************
+ *          DrawFrameControl16  (USER.656)
+ */
+BOOL16 DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
+{
+    fprintf( stdnimp,"DrawFrameControl16(%x,%p,%d,%x), empty stub!\n",
+             hdc,rc,edge,flags );
+    return TRUE;
+}
+
+
+/**********************************************************************
+ *          DrawFrameControl32  (USER32.157)
+ */
+BOOL32 DrawFrameControl32( HDC32 hdc, LPRECT32 rc, UINT32 edge, UINT32 flags )
+{
+    fprintf( stdnimp,"DrawFrameControl32(%x,%p,%d,%x), empty stub!\n",
+             hdc,rc,edge,flags );
+    return TRUE;
 }
diff --git a/windows/message.c b/windows/message.c
index 4713f6e..62c4c93 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -253,7 +253,7 @@
         if ((first || last) && 
             ((msg->message < first) || (msg->message > last))) continue;
         if ((msg->hwnd != GetDesktopWindow()) && 
-            (GetWindowTask(msg->hwnd) != GetCurrentTask()))
+            (GetWindowTask16(msg->hwnd) != GetCurrentTask()))
             continue;  /* Not for this task */
         if (remove)
         {
@@ -662,7 +662,6 @@
         return TRUE;
     }
 
-
     HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, 1,
                     (LPARAM)MAKE_SEGPTR(&msgstruct) );
     hwnd   = msgstruct.hWnd;
@@ -676,13 +675,7 @@
         return 0;
     }
     if (wndPtr->hmemTaskQ != GetTaskQueue(0))
-    {
-#if 0
-        fprintf( stderr, "SendMessage16: intertask message not supported\n" );
-        return 0;
-#endif
         return MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam );
-    }
 
     SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
     ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
@@ -718,6 +711,19 @@
         fprintf( stderr, "SendMessage32A: invalid hwnd %08x\n", hwnd );
         return 0;
     }
+
+    if (WINPROC_GetProcType( wndPtr->winproc ) == WIN_PROC_16)
+    {
+        /* Use SendMessage16 for now to get hooks right */
+        UINT16 msg16;
+        WPARAM16 wParam16;
+        if (WINPROC_MapMsg32ATo16( msg, wParam, &msg16, &wParam16, &lParam ) == -1)
+            return 0;
+        ret = SendMessage16( hwnd, msg16, wParam16, lParam );
+        WINPROC_UnmapMsg32ATo16( msg16, wParam16, lParam );
+        return ret;
+    }
+
     if (wndPtr->hmemTaskQ != GetTaskQueue(0))
     {
         fprintf( stderr, "SendMessage32A: intertask message not supported\n" );
@@ -895,7 +901,7 @@
 
 
 /***********************************************************************
- *           GetTickCount    (USER.13) (KERNEL32.299)
+ *           GetTickCount   (USER.13) (KERNEL32.299)
  */
 DWORD GetTickCount(void)
 {
diff --git a/windows/painting.c b/windows/painting.c
index e9c8283..29a58cb 100644
--- a/windows/painting.c
+++ b/windows/painting.c
@@ -196,17 +196,12 @@
 {
       /* Send WM_CTLCOLOR message if needed */
 
-    if ((DWORD)hbrush <= CTLCOLOR_MAX)
+    if ((UINT32)hbrush <= CTLCOLOR_MAX)
     {
 	if (!hwndParent) return;
-#ifdef WINELIB32
 	hbrush = (HBRUSH)SendMessage32A( hwndParent, 
-                                         WM_CTLCOLORMSGBOX+(DWORD)hbrush,
+                                         WM_CTLCOLORMSGBOX + (UINT32)hbrush,
                                          (WPARAM)hdc, (LPARAM)hwnd );
-#else
-	hbrush = (HBRUSH)SendMessage16( hwndParent, WM_CTLCOLOR,
-                                        hdc, MAKELONG( hwnd, hbrush ) );
-#endif
     }
     if (hbrush) FillRect16( hdc, rect, hbrush );
 }
@@ -217,13 +212,8 @@
  */
 HBRUSH GetControlBrush( HWND hwnd, HDC hdc, WORD control )
 {
-#ifdef WINELIB32
     return (HBRUSH)SendMessage32A( GetParent(hwnd), WM_CTLCOLOR+control,
                                    (WPARAM)hdc, (LPARAM)hwnd );
-#else
-    return (HBRUSH)SendMessage16( GetParent(hwnd), WM_CTLCOLOR,
-                                  hdc, MAKELONG( hwnd, control ) );
-#endif
 }
 
 
diff --git a/windows/property.c b/windows/property.c
index 9d3a0dc..dc5303c 100644
--- a/windows/property.c
+++ b/windows/property.c
@@ -133,7 +133,7 @@
           /* Already get the next in case the callback */
           /* function removes the current property.    */
         hProp = prop->next;
-        ret = CallEnumPropProc( func, hwnd,
+        ret = CallEnumPropProc( (FARPROC16)func, hwnd,
                                 prop->atom ? 
                                   (LONG)MAKELONG( prop->atom, 0 )
 				:
diff --git a/windows/queue.c b/windows/queue.c
index c1406c1..85ebc17 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -36,7 +36,7 @@
 /***********************************************************************
  *	     QUEUE_DumpQueue
  */
-void QUEUE_DumpQueue( HQUEUE hQueue )
+void QUEUE_DumpQueue( HQUEUE16 hQueue )
 {
     MESSAGEQUEUE *pq; 
 
@@ -127,7 +127,7 @@
  *
  * Unlinks and deletes a message queue.
  */
-BOOL QUEUE_DeleteMsgQueue( HQUEUE hQueue )
+BOOL32 QUEUE_DeleteMsgQueue( HQUEUE16 hQueue )
 {
     MESSAGEQUEUE * msgQueue = (MESSAGEQUEUE*)GlobalLock16(hQueue);
     HQUEUE *pPrev;
@@ -159,7 +159,7 @@
  * Create the system message queue, and set the double-click speed.
  * Must be called only once.
  */
-BOOL QUEUE_CreateSysMsgQueue( int size )
+BOOL32 QUEUE_CreateSysMsgQueue( int size )
 {
     if (size > MAX_QUEUE_SIZE) size = MAX_QUEUE_SIZE;
     else if (size <= 0) size = 1;
@@ -302,7 +302,7 @@
  *
  * Add a message to the queue. Return FALSE if queue is full.
  */
-BOOL QUEUE_AddMsg( HQUEUE hQueue, MSG16 * msg, DWORD extraInfo )
+BOOL32 QUEUE_AddMsg( HQUEUE16 hQueue, MSG16 * msg, DWORD extraInfo )
 {
     int pos;
     MESSAGEQUEUE *msgQueue;
@@ -334,7 +334,7 @@
  *
  * Find a message matching the given parameters. Return -1 if none available.
  */
-int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND hwnd, int first, int last )
+int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND32 hwnd, int first, int last )
 {
     int i, pos = msgQueue->nextMessage;
 
@@ -488,7 +488,7 @@
 /***********************************************************************
  *	     QUEUE_GetQueueTask
  */
-HTASK QUEUE_GetQueueTask( HQUEUE hQueue )
+HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue )
 {
     MESSAGEQUEUE *queue = GlobalLock16( hQueue );
     return (queue) ? queue->hTask : 0 ;
@@ -498,7 +498,7 @@
 /***********************************************************************
  *           QUEUE_IncPaintCount
  */
-void QUEUE_IncPaintCount( HQUEUE hQueue )
+void QUEUE_IncPaintCount( HQUEUE16 hQueue )
 {
     MESSAGEQUEUE *queue;
 
@@ -511,7 +511,7 @@
 /***********************************************************************
  *           QUEUE_DecPaintCount
  */
-void QUEUE_DecPaintCount( HQUEUE hQueue )
+void QUEUE_DecPaintCount( HQUEUE16 hQueue )
 {
     MESSAGEQUEUE *queue;
 
@@ -524,7 +524,7 @@
 /***********************************************************************
  *           QUEUE_IncTimerCount
  */
-void QUEUE_IncTimerCount( HQUEUE hQueue )
+void QUEUE_IncTimerCount( HQUEUE16 hQueue )
 {
     MESSAGEQUEUE *queue;
 
@@ -537,7 +537,7 @@
 /***********************************************************************
  *           QUEUE_DecTimerCount
  */
-void QUEUE_DecTimerCount( HQUEUE hQueue )
+void QUEUE_DecTimerCount( HQUEUE16 hQueue )
 {
     MESSAGEQUEUE *queue;
 
@@ -561,9 +561,9 @@
 
 
 /***********************************************************************
- *           GetWindowTask   (USER.224)
+ *           GetWindowTask16   (USER.224)
  */
-HTASK GetWindowTask( HWND hwnd )
+HTASK16 GetWindowTask16( HWND16 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
diff --git a/windows/timer.c b/windows/timer.c
index 31e3940..4f4ef67 100644
--- a/windows/timer.c
+++ b/windows/timer.c
@@ -4,8 +4,10 @@
  * Copyright 1993 Alexandre Julliard
  */
 
+#define NO_TRANSITION_TYPES  /* This file is Win32-clean */
 #include "windows.h"
 #include "queue.h"
+#include "winproc.h"
 #include "stddebug.h"
 /* #define DEBUG_TIMER */
 #include "debug.h"
@@ -13,14 +15,14 @@
 
 typedef struct tagTIMER
 {
-    HWND             hwnd;
-    HQUEUE	     hq;
-    WORD             msg;  /* WM_TIMER or WM_SYSTIMER */
-    WORD             id;
-    WORD             timeout;
+    HWND32           hwnd;
+    HQUEUE16         hq;
+    UINT16           msg;  /* WM_TIMER or WM_SYSTIMER */
+    UINT32           id;
+    UINT32           timeout;
     struct tagTIMER *next;
     DWORD            expires;  /* Next expiration, or 0 if already expired */
-    FARPROC          proc;
+    HWINDOWPROC      proc;
 } TIMER;
 
 #define NB_TIMERS            34
@@ -86,14 +88,14 @@
     pTimer->msg     = 0;
     pTimer->id      = 0;
     pTimer->timeout = 0;
-    pTimer->proc    = 0;
+    WINPROC_FreeProc( pTimer->proc );
 }
 
 
 /***********************************************************************
  *           TIMER_SwitchQueue
  */
-void TIMER_SwitchQueue(HQUEUE old, HQUEUE new)
+void TIMER_SwitchQueue( HQUEUE16 old, HQUEUE16 new )
 {
     TIMER * pT = pNextTimer;
 
@@ -110,7 +112,7 @@
  *
  * Remove all timers for a given window.
  */
-void TIMER_RemoveWindowTimers( HWND hwnd )
+void TIMER_RemoveWindowTimers( HWND32 hwnd )
 {
     int i;
     TIMER *pTimer;
@@ -126,7 +128,7 @@
  *
  * Remove all timers for a given queue.
  */
-void TIMER_RemoveQueueTimers( HQUEUE hqueue )
+void TIMER_RemoveQueueTimers( HQUEUE16 hqueue )
 {
     int i;
     TIMER *pTimer;
@@ -187,7 +189,8 @@
  *
  * Build a message for an expired timer.
  */
-BOOL TIMER_GetTimerMsg( MSG16 *msg, HWND hwnd, HQUEUE hQueue, BOOL remove )
+BOOL32 TIMER_GetTimerMsg( MSG16 *msg, HWND32 hwnd,
+                          HQUEUE16 hQueue, BOOL32 remove )
 {
     TIMER *pTimer = pNextTimer;
     DWORD curTime = GetTickCount();
@@ -204,9 +207,9 @@
 		   pTimer->hwnd, pTimer->msg, pTimer->id, (DWORD)pTimer->proc);
 
       /* Build the message */
-    msg->hwnd    = pTimer->hwnd;
+    msg->hwnd    = (HWND16)pTimer->hwnd;
     msg->message = pTimer->msg;
-    msg->wParam  = pTimer->id;
+    msg->wParam  = (UINT16)pTimer->id;
     msg->lParam  = (LONG)pTimer->proc;
     msg->time    = curTime;
     return TRUE;
@@ -216,14 +219,13 @@
 /***********************************************************************
  *           TIMER_SetTimer
  */
-static WORD TIMER_SetTimer( HWND hwnd, WORD id, WORD timeout,
-			    FARPROC proc, BOOL sys )
+static UINT32 TIMER_SetTimer( HWND32 hwnd, UINT32 id, UINT32 timeout,
+                              WNDPROC16 proc, WINDOWPROCTYPE type, BOOL32 sys )
 {
     int i;
     TIMER * pTimer;
 
     if (!timeout) return 0;
-/*    if (!hwnd && !proc) return 0; */
 
       /* Check if there's already a timer with the same hwnd and id */
 
@@ -234,7 +236,9 @@
               /* Got one: set new values and return */
             TIMER_RemoveTimer( pTimer );
             pTimer->timeout = timeout;
-            pTimer->proc    = proc;
+            WINPROC_FreeProc( pTimer->proc );
+            pTimer->proc = (HWINDOWPROC)0;
+            if (proc) WINPROC_SetProc( &pTimer->proc, proc, type );
             pTimer->expires = GetTickCount() + timeout;
             TIMER_InsertTimer( pTimer );
             return id;
@@ -252,27 +256,27 @@
       /* Add the timer */
 
     pTimer->hwnd    = hwnd;
-    pTimer->hq	    = (hwnd) ? GetTaskQueue( GetWindowTask( hwnd ) )
+    pTimer->hq	    = (hwnd) ? GetTaskQueue( GetWindowTask16( hwnd ) )
 			     : GetTaskQueue( 0 );
     pTimer->msg     = sys ? WM_SYSTIMER : WM_TIMER;
     pTimer->id      = id;
     pTimer->timeout = timeout;
     pTimer->expires = GetTickCount() + timeout;
-    pTimer->proc    = proc;
-    dprintf_timer(stddeb, "Timer added: %p, %04x, %04x, %04x, %08lx\n", 
-		  pTimer, pTimer->hwnd, pTimer->msg, pTimer->id, (DWORD)pTimer->proc);
+    pTimer->proc    = (HWINDOWPROC)0;
+    if (proc) WINPROC_SetProc( &pTimer->proc, proc, type );
+    dprintf_timer( stddeb, "Timer added: %p, %04x, %04x, %04x, %08lx\n", 
+		   pTimer, pTimer->hwnd, pTimer->msg, pTimer->id,
+                   (DWORD)pTimer->proc );
     TIMER_InsertTimer( pTimer );
-    if (!id)
-	return TRUE;
-    else
-	return id;
+    if (!id) return TRUE;
+    else return id;
 }
 
 
 /***********************************************************************
  *           TIMER_KillTimer
  */
-static BOOL TIMER_KillTimer( HWND hwnd, WORD id, BOOL sys )
+static BOOL32 TIMER_KillTimer( HWND32 hwnd, UINT32 id, BOOL32 sys )
 {
     int i;
     TIMER * pTimer;
@@ -295,41 +299,90 @@
 
 
 /***********************************************************************
- *           SetTimer   (USER.10)
+ *           SetTimer16   (USER.10)
  */
-WORD SetTimer( HWND hwnd, WORD id, WORD timeout, FARPROC proc )
+UINT16 SetTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout, TIMERPROC16 proc )
 {
-    dprintf_timer(stddeb, "SetTimer: %04x %d %d %08lx\n", hwnd, id, timeout, (LONG)proc );
-    return TIMER_SetTimer( hwnd, id, timeout, proc, FALSE );
+    dprintf_timer( stddeb, "SetTimer16: %04x %d %d %08lx\n",
+                   hwnd, id, timeout, (LONG)proc );
+    return TIMER_SetTimer( hwnd, id, timeout, (WNDPROC16)proc,
+                           WIN_PROC_16, FALSE );
 }
 
 
 /***********************************************************************
- *           SetSystemTimer   (USER.11)
+ *           SetTimer32   (USER32.510)
  */
-WORD SetSystemTimer( HWND hwnd, WORD id, WORD timeout, FARPROC proc )
+UINT32 SetTimer32( HWND32 hwnd, UINT32 id, UINT32 timeout, TIMERPROC32 proc )
 {
-    dprintf_timer(stddeb, "SetSystemTimer: %04x %d %d %08lx\n", 
-		  hwnd, id, timeout, (LONG)proc );
-    return TIMER_SetTimer( hwnd, id, timeout, proc, TRUE );
+    dprintf_timer( stddeb, "SetTimer32: %04x %d %d %08lx\n",
+                   hwnd, id, timeout, (LONG)proc );
+    return TIMER_SetTimer( hwnd, id, timeout, (WNDPROC16)proc,
+                           WIN_PROC_32A, FALSE );
 }
 
 
 /***********************************************************************
- *           KillTimer   (USER.12)
+ *           SetSystemTimer16   (USER.11)
  */
-BOOL KillTimer( HWND hwnd, WORD id )
+UINT16 SetSystemTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout,
+                         TIMERPROC16 proc )
 {
-    dprintf_timer(stddeb, "KillTimer: %04x %d\n", hwnd, id );
+    dprintf_timer( stddeb, "SetSystemTimer16: %04x %d %d %08lx\n", 
+                   hwnd, id, timeout, (LONG)proc );
+    return TIMER_SetTimer( hwnd, id, timeout, (WNDPROC16)proc,
+                           WIN_PROC_16, TRUE );
+}
+
+
+/***********************************************************************
+ *           SetSystemTimer32   (USER32.508)
+ */
+UINT32 SetSystemTimer32( HWND32 hwnd, UINT32 id, UINT32 timeout,
+                         TIMERPROC32 proc )
+{
+    dprintf_timer( stddeb, "SetSystemTimer32: %04x %d %d %08lx\n", 
+                   hwnd, id, timeout, (LONG)proc );
+    return TIMER_SetTimer( hwnd, id, timeout, (WNDPROC16)proc,
+                           WIN_PROC_32A, TRUE );
+}
+
+
+/***********************************************************************
+ *           KillTimer16   (USER.12)
+ */
+BOOL16 KillTimer16( HWND16 hwnd, UINT16 id )
+{
+    dprintf_timer(stddeb, "KillTimer16: %04x %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, FALSE );
 }
 
 
 /***********************************************************************
- *           KillSystemTimer   (USER.182)
+ *           KillTimer32   (USER32.353)
  */
-BOOL KillSystemTimer( HWND hwnd, WORD id )
+BOOL32 KillTimer32( HWND32 hwnd, UINT32 id )
 {
-    dprintf_timer(stddeb, "KillSystemTimer: %04x %d\n", hwnd, id );
+    dprintf_timer(stddeb, "KillTimer32: %04x %d\n", hwnd, id );
+    return TIMER_KillTimer( hwnd, id, FALSE );
+}
+
+
+/***********************************************************************
+ *           KillSystemTimer16   (USER.182)
+ */
+BOOL16 KillSystemTimer16( HWND16 hwnd, UINT16 id )
+{
+    dprintf_timer( stddeb, "KillSystemTimer16: %04x %d\n", hwnd, id );
+    return TIMER_KillTimer( hwnd, id, TRUE );
+}
+
+
+/***********************************************************************
+ *           KillSystemTimer32   (USER32.352)
+ */
+BOOL32 KillSystemTimer32( HWND32 hwnd, UINT32 id )
+{
+    dprintf_timer( stddeb, "KillSystemTimer32: %04x %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, TRUE );
 }
diff --git a/windows/win.c b/windows/win.c
index 7fc2b25..83a8c36 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -94,7 +94,7 @@
              "inst=%04x  taskQ=%04x  updRgn=%04x  active=%04x hdce=%04x  idmenu=%04x\n"
              "style=%08lx  exstyle=%08lx  wndproc=%08x  text='%s'\n"
              "client=%d,%d-%d,%d  window=%d,%d-%d,%d  iconpos=%d,%d  maxpos=%d,%d\n"
-             "sysmenu=%04x  flags=%04x  props=%04x  vscroll=%04x  hscroll=%04x\n",
+             "sysmenu=%04x  flags=%04x  props=%04x  vscroll=%p  hscroll=%p\n",
              ptr->next, ptr->child, ptr->parent, ptr->owner,
              ptr->class, className, ptr->hInstance, ptr->hmemTaskQ,
              ptr->hrgnUpdate, ptr->hwndLastActive, ptr->hdce, ptr->wIDmenu,
@@ -104,7 +104,7 @@
              ptr->rectClient.bottom, ptr->rectWindow.left, ptr->rectWindow.top,
              ptr->rectWindow.right, ptr->rectWindow.bottom, ptr->ptIconPos.x,
              ptr->ptIconPos.y, ptr->ptMaxPos.x, ptr->ptMaxPos.y, ptr->hSysMenu,
-             ptr->flags, ptr->hProp, ptr->hVScroll, ptr->hHScroll );
+             ptr->flags, ptr->hProp, ptr->pVScroll, ptr->pHScroll );
 
     if (ptr->class->cbWndExtra)
     {
@@ -403,8 +403,8 @@
                                      WS_CLIPSIBLINGS;
     pWndDesktop->dwExStyle         = 0;
     pWndDesktop->hdce              = 0;
-    pWndDesktop->hVScroll          = 0;
-    pWndDesktop->hHScroll          = 0;
+    pWndDesktop->pVScroll          = NULL;
+    pWndDesktop->pHScroll          = NULL;
     pWndDesktop->wIDmenu           = 0;
     pWndDesktop->flags             = 0;
     pWndDesktop->window            = rootWindow;
@@ -525,8 +525,8 @@
     wndPtr->dwExStyle      = cs->dwExStyle;
     wndPtr->wIDmenu        = 0;
     wndPtr->flags          = 0;
-    wndPtr->hVScroll       = 0;
-    wndPtr->hHScroll       = 0;
+    wndPtr->pVScroll       = NULL;
+    wndPtr->pHScroll       = NULL;
     wndPtr->hSysMenu       = MENU_GetDefSysMenu();
     wndPtr->hProp          = 0;
     wndPtr->userdata       = 0;
@@ -555,7 +555,7 @@
 
     /* Insert the window in the linked list */
 
-    WIN_LinkWindow( hwnd, HWND_TOP );
+    WIN_LinkWindow( hwnd, HWND_BOTTOM );
 
     /* Send the WM_GETMINMAXINFO message and fix the size if needed */
 
@@ -1139,7 +1139,7 @@
 /***********************************************************************
  *           IsWindowUnicode   (USER32.349)
  */
-BOOL IsWindowUnicode( HWND hwnd )
+BOOL32 IsWindowUnicode( HWND32 hwnd )
 {
     WND * wndPtr; 
 
@@ -1295,8 +1295,13 @@
             retval = (LONG)WINPROC_GetProc( wndPtr->winproc, type );
             WINPROC_SetProc( &wndPtr->winproc, (WNDPROC16)newval, type );
             return retval;
+	case GWL_STYLE:
+            ptr = &wndPtr->dwStyle;
+            /* Some bits can't be changed this way */
+            newval &= ~(WS_VISIBLE | WS_CHILD);
+            newval |= (*ptr & (WS_VISIBLE | WS_CHILD));
+            break;
         case GWL_USERDATA: ptr = &wndPtr->userdata; break;
-	case GWL_STYLE:    ptr = &wndPtr->dwStyle; break;
         case GWL_EXSTYLE:  ptr = &wndPtr->dwExStyle; break;
 	default:
             fprintf( stderr, "SetWindowLong: invalid offset %d\n", offset );
@@ -1428,9 +1433,9 @@
 
 
 /*******************************************************************
- *         IsWindow    (USER.47)
+ *         IsWindow   (USER.47) (USER32.347)
  */
-BOOL IsWindow( HWND hwnd )
+BOOL16 IsWindow( HWND32 hwnd )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     return ((wndPtr != NULL) && (wndPtr->dwMagic == WND_MAGIC));
@@ -1656,7 +1661,8 @@
     {
         /* Make sure that the window still exists */
         if (!IsWindow((*ppWnd)->hwndSelf)) continue;
-        if (!CallEnumWindowsProc16( lpEnumFunc, (*ppWnd)->hwndSelf, lParam ))
+        if (!CallEnumWindowsProc16( (FARPROC16)lpEnumFunc,
+                                    (*ppWnd)->hwndSelf, lParam ))
             break;
     }
     HeapFree( SystemHeap, 0, list );
@@ -1711,7 +1717,8 @@
         /* Make sure that the window still exists */
         if (!IsWindow((*ppWnd)->hwndSelf)) continue;
         if ((*ppWnd)->hmemTaskQ != hQueue) continue;  /* Check the queue */
-        if (!CallEnumWindowsProc16( func, (*ppWnd)->hwndSelf, lParam ))
+        if (!CallEnumWindowsProc16( (FARPROC16)func,
+                                    (*ppWnd)->hwndSelf, lParam ))
             break;
     }
     HeapFree( SystemHeap, 0, list );
@@ -1761,7 +1768,7 @@
         if (!IsWindow((*ppWnd)->hwndSelf)) continue;
         /* Build children list first */
         if (!(childList = WIN_BuildWinArray( *ppWnd ))) return FALSE;
-        if (!CallEnumWindowsProc16( func, (*ppWnd)->hwndSelf, lParam ))
+        if (!CallEnumWindowsProc16((FARPROC16)func,(*ppWnd)->hwndSelf,lParam))
             return FALSE;
         ret = WIN_EnumChildWindows16( childList, func, lParam );
         HeapFree( SystemHeap, 0, childList );
diff --git a/windows/winpos.c b/windows/winpos.c
index 1acf4b5..fcf56ba 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -656,6 +656,8 @@
 	    break;
     }
 
+    /* We can't activate a child window */
+    if (wndPtr->dwStyle & WS_CHILD) swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
     SendMessage16( hwnd, WM_SHOWWINDOW, (cmd != SW_HIDE), 0 );
     SetWindowPos( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
 
@@ -961,14 +963,9 @@
 
     wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
     SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
-#ifdef WINELIB32
     SendMessage32A( hWnd, WM_ACTIVATE,
-		 MAKEWPARAM( (fMouse)?WA_CLICKACTIVE:WA_ACTIVE, wIconized),
+		 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
 		 (LPARAM)hwndPrevActive );
-#else
-    SendMessage16( hWnd, WM_ACTIVATE, (fMouse)? WA_CLICKACTIVE : WA_ACTIVE,
-		 MAKELONG(hwndPrevActive,wIconized));
-#endif
 
     if( !IsWindow(hWnd) ) return 0;
 
diff --git a/windows/winproc.c b/windows/winproc.c
index ff10000..501acfe 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -10,12 +10,14 @@
 #include "callback.h"
 #include "heap.h"
 #include "ldt.h"
+#include "registers.h"
 #include "stackframe.h"
 #include "string32.h"
 #include "struct32.h"
 #include "win.h"
-#include "wine.h"
 #include "winproc.h"
+#include "stddebug.h"
+#include "debug.h"
 
 /* Window procedure 16-bit thunk; see BuildSpec16Files() in tools/build.c */
 typedef struct
@@ -36,7 +38,7 @@
 typedef struct
 {
     BYTE       popl_eax;             /* popl  %eax (return address) */
-    BYTE       pushl;                /* pushl $proc */
+    BYTE       pushl_func;           /* pushl $proc */
     WNDPROC16  proc WINE_PACKED;
     BYTE       pushl_eax;            /* pushl %eax */
     BYTE       pushl_ebp;            /* pushl %ebp */
@@ -44,10 +46,17 @@
     LPCSTR     name WINE_PACKED;
     BYTE       pushl_thunk;          /* pushl $thunkfrom32 */
     void     (*thunk32)() WINE_PACKED;
-    BYTE       jmp;                  /* jmp   relay */
+    BYTE       jmp;                  /* jmp   relay (relative jump)*/
     void     (*relay)() WINE_PACKED;
 } WINPROC_THUNK_FROM32;
 
+/* Simple jmp to call 32-bit procedure directly */
+typedef struct
+{
+    BYTE       jmp;                  /* jmp  proc (relative jump) */
+    WNDPROC32  proc WINE_PACKED;
+} WINPROC_JUMP;
+
 typedef union
 {
     WINPROC_THUNK_FROM16  t_from16;
@@ -57,6 +66,7 @@
 typedef struct tagWINDOWPROC
 {
     WINPROC_THUNK         thunk;    /* Thunk */
+    WINPROC_JUMP          jmp;      /* Jump */
     struct tagWINDOWPROC *next;     /* Next window proc */
     UINT32                magic;    /* Magic number */
     WINDOWPROCTYPE        type;     /* Function type */
@@ -84,10 +94,10 @@
 
 #ifndef WINELIB
 extern void CallFrom16_long_wwwll(void);
-extern void CallFrom32_5(void);
+extern void CallFrom32_stdcall_5(void);
 #else
 static void CallFrom16_long_wwwll(void) {}
-static void CallFrom32_5(void) {}
+static void CallFrom32_stdcall_5(void) {}
 #endif  /* WINELIB */
 
 /* Reference 16->32A thunk */
@@ -114,8 +124,8 @@
     WINE_CODE_SELECTOR
 };
 
-/* Reference 32A->16 thunk */
-static const WINPROC_THUNK_FROM32 WINPROC_ThunkRef32ATo16 =
+/* Reference 32->16 thunk */
+static const WINPROC_THUNK_FROM32 WINPROC_ThunkRef32To16 =
 {
     0x58,                                       /* popl  %eax */
     0x68, 0x00000000,                           /* pushl $proc16 */
@@ -123,9 +133,14 @@
     0x55,                                       /* pushl %ebp */
     0x68, "WINPROC_CallProc32ATo16",            /* pushl $name */
     0x68, (void (*)())WINPROC_CallProc32ATo16,  /* pushl $thunk32 */
-    0xe9, CallFrom32_5                          /* jmp   relay */
+    0xe9, CallFrom32_stdcall_5                  /* jmp   relay */
 };
 
+/* Reference 32->32 jump */
+static const WINPROC_JUMP WINPROC_JumpRef =
+{
+    0xe9, 0x00000000                            /* jmp   proc (relative) */
+};
 
 static HANDLE32 WinProcHeap;
 
@@ -151,22 +166,37 @@
  */
 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
 {
+    BYTE *ptr;
     WINDOWPROC *proc;
 
     /* Check for a linear pointer */
 
     if (HEAP_IsInsideHeap( WinProcHeap, 0, (LPVOID)handle ))
     {
-        proc = (WINDOWPROC *)handle;
-        if (proc->magic == WINPROC_MAGIC) return proc;
+        ptr = (BYTE *)handle;
+        /* First check if it is the jmp address */
+        if (*ptr == WINPROC_JumpRef.jmp)
+            ptr -= (int)&((WINDOWPROC *)0)->jmp -
+                   (int)&((WINDOWPROC *)0)->thunk;
+        /* Now it must be the thunk address */
+        if (*ptr == WINPROC_ThunkRef16To32A.popl_eax)
+            ptr -= (int)&((WINDOWPROC *)0)->thunk;
+        /* Now we have a pointer to the WINDOWPROC struct */
+        if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
+            return (WINDOWPROC *)ptr;
     }
 
     /* Check for a segmented pointer */
 
-    if (!IsBadReadPtr( (SEGPTR)handle, sizeof(WINDOWPROC) ))
+    if (!IsBadReadPtr( (SEGPTR)handle, sizeof(WINDOWPROC)-sizeof(proc->thunk)))
     {
-        proc = (WINDOWPROC *)PTR_SEG_TO_LIN(handle);
-        if (proc->magic == WINPROC_MAGIC) return proc;
+        ptr = (BYTE *)PTR_SEG_TO_LIN(handle);
+        /* It must be the thunk address */
+        if (*ptr == WINPROC_ThunkRef32To16.popl_eax)
+            ptr -= (int)&((WINDOWPROC *)0)->thunk;
+        /* Now we have a pointer to the WINDOWPROC struct */
+        if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
+            return (WINDOWPROC *)ptr;
     }
 
     return NULL;
@@ -197,7 +227,7 @@
         switch(type)
         {
         case WIN_PROC_16:
-            proc->thunk.t_from32 = WINPROC_ThunkRef32ATo16;
+            proc->thunk.t_from32 = WINPROC_ThunkRef32To16;
             proc->thunk.t_from32.proc = func;
             /* We need to fix the relative jump target */
             proc->thunk.t_from32.relay = (void (*)())((DWORD)proc->thunk.t_from32.relay -
@@ -206,10 +236,18 @@
         case WIN_PROC_32A:
             proc->thunk.t_from16 = WINPROC_ThunkRef16To32A;
             proc->thunk.t_from16.proc = (FARPROC32)func;
+            proc->jmp = WINPROC_JumpRef;
+            /* Fixup relative jump */
+            proc->jmp.proc = (WNDPROC32)((DWORD)func -
+                                                 (DWORD)(&proc->jmp.proc + 1));
             break;
         case WIN_PROC_32W:
             proc->thunk.t_from16 = WINPROC_ThunkRef16To32W;
-            proc->thunk.t_from16.proc = (FARPROC32)func;
+            proc->thunk.t_from16.proc = (WNDPROC32)func;
+            proc->jmp = WINPROC_JumpRef;
+            /* Fixup relative jump */
+            proc->jmp.proc = (WNDPROC32)((DWORD)func -
+                                                 (DWORD)(&proc->jmp.proc + 1));
             break;
         default:
             /* Should not happen */
@@ -219,6 +257,8 @@
         proc->type  = type;
     }
     proc->next  = NULL;
+    dprintf_win( stddeb, "WINPROC_AllocWinProc(%08x,%d): returning %08x\n",
+                 (UINT32)func, type, (UINT32)proc );
     return proc;
 }
 
@@ -235,14 +275,15 @@
         if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
             return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
         else
-            return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0, proc );
+            return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
+                                              &((WINDOWPROC *)proc)->thunk );
     }
     else  /* We want a 32-bit address */
     {
         if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
-            return (WNDPROC16)proc;
+            return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
         else
-            return (WNDPROC16)((WINDOWPROC *)proc)->thunk.t_from16.proc;
+            return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
     }
 }
 
@@ -293,6 +334,8 @@
 
     /* Add the win proc at the head of the list */
 
+    dprintf_win( stddeb, "WINPROC_SetProc(%08x,%08x,%d): res=%08x\n",
+                 (UINT32)*pFirst, (UINT32)func, type, (UINT32)proc );
     proc->next  = *(WINDOWPROC **)pFirst;
     *(WINDOWPROC **)pFirst = proc;
     return TRUE;
@@ -309,6 +352,7 @@
     while (proc)
     {
         WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
+        dprintf_win( stddeb, "WINPROC_FreeProc: freeing %08x\n", (UINT32)proc);
         HeapFree( WinProcHeap, 0, proc );
         proc = next;
     }
@@ -383,7 +427,7 @@
     case WM_GETTEXT:
         {
             LPARAM *ptr = (LPARAM *)lParam - 1;
-            STRING32_UniToAnsi( (LPSTR)*ptr, (LPWSTR)(ptr + 1) );
+            lstrcpynWtoA( (LPSTR)*ptr, (LPWSTR)(ptr + 1), wParam );
             HeapFree( SystemHeap, 0, ptr );
         }
         break;
@@ -457,7 +501,7 @@
     case WM_GETTEXT:
         {
             LPARAM *ptr = (LPARAM *)lParam - 1;
-            STRING32_AnsiToUni( (LPWSTR)*ptr, (LPSTR)(ptr + 1) );
+            lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)(ptr + 1), wParam );
             HeapFree( SystemHeap, 0, ptr );
         }
         break;
@@ -780,11 +824,13 @@
     case WM_ACTIVATE:
     case WM_CHARTOITEM:
     case WM_COMMAND:
-    case WM_HSCROLL:
     case WM_VKEYTOITEM:
-    case WM_VSCROLL:
         *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
         return 0;
+    case WM_HSCROLL:
+    case WM_VSCROLL:
+        *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
+        return 0;
     case WM_CTLCOLORMSGBOX:
     case WM_CTLCOLOREDIT:
     case WM_CTLCOLORLISTBOX:
@@ -1169,23 +1215,7 @@
 
     if (WINPROC_MapMsg32ATo16( msg, wParam, &msg16, &wParam16, &lParam ) == -1)
         return 0;
-#ifndef WINELIB
-    if ((msg16 == WM_CREATE) || (msg16 == WM_NCCREATE))
-    {
-        CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
-        /* Build the CREATESTRUCT on the 16-bit stack. */
-        /* This is really ugly, but some programs (notably the */
-        /* "Undocumented Windows" examples) want it that way.  */
-        result = CallWndProcNCCREATE16( func, ds, cs->dwExStyle,
-                      cs->lpszClass, cs->lpszName, cs->style, cs->x, cs->y,
-                      cs->cx, cs->cy, cs->hwndParent, cs->hMenu, cs->hInstance,
-                      (LONG)cs->lpCreateParams, hwnd, msg16, wParam16,
-                      MAKELONG( IF1632_Saved16_sp-sizeof(CREATESTRUCT16),
-                                IF1632_Saved16_ss ) );
-    }
-    else
-#endif  /* WINELIB */
-        result = CallWndProc16( func, ds, hwnd, msg16, wParam16, lParam );
+    result = CallWndProc16( func, ds, hwnd, msg16, wParam16, lParam );
     WINPROC_UnmapMsg32ATo16( msg16, wParam16, lParam );
     return result;
 }
@@ -1242,6 +1272,22 @@
     case WIN_PROC_16:
         if (!proc->thunk.t_from32.proc) return 0;
         wndPtr = WIN_FindWndPtr( hwnd );
+#ifndef WINELIB
+        if ((msg == WM_CREATE) || (msg == WM_NCCREATE))
+        {
+            CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
+            /* Build the CREATESTRUCT on the 16-bit stack. */
+            /* This is really ugly, but some programs (notably the */
+            /* "Undocumented Windows" examples) want it that way.  */
+            return CallWndProcNCCREATE16( proc->thunk.t_from32.proc,
+                      wndPtr ? wndPtr->hInstance : CURRENT_DS, cs->dwExStyle,
+                      cs->lpszClass, cs->lpszName, cs->style, cs->x, cs->y,
+                      cs->cx, cs->cy, cs->hwndParent, cs->hMenu, cs->hInstance,
+                      (LONG)cs->lpCreateParams, hwnd, msg, wParam,
+                      MAKELONG( IF1632_Saved16_sp-sizeof(CREATESTRUCT16),
+                                IF1632_Saved16_ss ) );
+        }
+#endif
         return CallWndProc16( proc->thunk.t_from32.proc,
                               wndPtr ? wndPtr->hInstance : CURRENT_DS,
                               hwnd, msg, wParam, lParam );