From a0b2b1d0f6d11d61eb42473fa090d00937399e44 Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Sun, 16 Nov 1997 17:38:29 +0000
Subject: [PATCH] Release 971116

Sun Nov 16 07:42:44 1997  Alex Korobka <alex@trantor.pharm.sunysb.edu>

	* [windows/dce.c] [windows/clipboard.c] [windows/nonclient.c]
	Bug fixes.

	* [misc/shell.c] [resources/*]
	New "About" dialog.

Sat Nov 15 17:30:18 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [configure.in] [Makefile.in]
	Replaced --with-library option by --disable-emulator. The default
 	is now to build both the library and the emulator.
	Renamed --with options to --enable to follow autoconf guidelines.

	* [loader/main.c] [miscemu/main.c] (New file)
	Split initialization in WinelibInit/EmulatorInit.

	* [loader/*.c]
	Removed all remaining #ifdef's WINELIB.

	* [controls/widgets.c] [windows/mdi.c]
	Converted MDIClientWndProc to 32-bit.

	* [debugger/break.c] [if1632/signal.c] [include/selectors.h]
	  [scheduler/thread.c]
	Code and data selector values are now computed at run-time.

	* [library/libres.c]
	Moved to loader/ directory.

	* [misc/main.c] [misc/version.c] (New file)
	Moved all version stuff to version.c. Cleaned up a bit.

	* [msdos/dpmi.c]
	Update the REALMODECALL structure on return from real-mode
	interrupt.

	* [windows/event.c] [windows/keyboard.c]
	Changed the way event coordinates are determined. Don't rely on
	the ConfigureNotify event values. This should fix all problems
	with cursor position in -desktop and -managed modes.

Sat Nov 15 16:09:36 1997  Slaven Rezic  <eserte@cs.tu-berlin.de>

	* [controls/button.c]
	(BUTTON_CheckAutoRadioButton): Prevent possible endless loop.

Wed Nov 12 03:42:45 1997  Chris Faherty <chrisf@america.com>

	* [misc/ver.c]
	Changed VerInstall32A to assume srcdir as destination if destdir
	is blank.  This was causing alot of DLL installation into SYSTEM
	directory to fail.

	* [loader/ne_image.c]
	NE_LoadSegment buffer[100] was too small and getting overruns.
	Changed it to buffer[200].

Sat Nov  8 06:09:57 1997  Len White <phreak@cgocable.net>

	* [misc/ddeml.c] [include/ddeml.h] [if1632/ddeml.spec]
	Added stub functions DdeConnectList(), DdeQueryNextServer(),
	DdeDisconnectList(), DdeSetUserHandle(), DdeAbandonTransaction(),
	DdePostAdvise(), DdeCreateDataHandle(), DdeAddData(), DdeGetData(),
	DdeAccessData(), DdeUnaccessData(), DdeEnableCallback(),
	DdeCmpStringHandles().

Fri Nov  7 19:44:26 1997  Olaf Flebbe  <o.flebbe@science-computing.de>

	* [files/directory.c]
	Fix typo in directory.c [broke loading of cdplayer on nt40]

	* [misc/main.c]
	Implemented -winver nt40.

	* [loader/resource.c] [user32.spec]
	Stubs for CopyAcceleratorTable, Destroy AcceleratorTable.

Thu Nov  6 22:37:04 1997  Morten Welinder  <welinder@rentec.com>

	* [files/drive.c]
	(GetDiskFreeSpace32A): Cap at 2GB.

	* [include/windows.h]
	Prototype DrawIconEx and CreateDIBSection32.
	Define OBM_RADIOCHECK.
	Add DI_* macros.

	* [objects/dib.c] [if1632/gdi.spec]
	CreateDIBSection is a WINAPI.  Renamed to CreateDIBSection32.
	Implement CreateDIBSection16.

	* [if1632/user.spec] [if1632/user32.spec]
	Add DrawIconEx.

	* [objects/cursoricon.c]
	(CopyIcon32): Fix bogus implementation.

	* [objects/bitmap.c]
	(CopyBitmap32): New function.
	(CopyImage32): Do bitmaps.

	* [graphics/x11drv/text.c]
	(X11DRV_ExtTextOut): Change ascent and descent default to avoid
	zero-thinkness overstrike line.

	* [include/debugstr.h] [misc/debugstr.c]
	New files.

	* [msdos/dpmi.c]
	Don't prototype do_mscdex. In INT_Int31Handler, handle real-mode
	int 0x21, ah=0x52.

	* [msdos/int2f.c]
	Add dummys for 0x1681 and 0x1682.

	* [misc/registry.c]
	Fix memory leaks in RegDeleteKey32W.

	* [objects/text.c]
	In TEXT_NextLine, fix another off-by-one bug.

	* [include/bitmaps/obm_radiocheck]
	New file.  (It a small circle used to radio-button menu items
	when selected.)

	* [objects/oembitmap.c]
	Add obm_radiocheck.

	* [include/windows.h] [if1632/user32.spec] [controls/menu.c]
	  [if1632/user.spec]
	Define CheckMenuRadioItem{16,32}.  Define GetMenuItemRect{16,32}.

Wed Nov  5 11:30:14 1997  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
	* [misc/main.c]
	Auto adjust versions depending on binary.

Tue Nov  4 15:21:00 1997  Kristian Nielsen  <kristian.nielsen@risoe.dk>

	* [controls/listbox.c]
	Paint full background in listbox items with tab stops enabled.

	* [if1632/thunk.c]
	Copy some more message parameter structures (DRAWITEMSTRUCT16,
	COMPAREITEMSTRUCT16) to the stack segment to fix broken programs
	that need this.

	* [windows/dce.c]
	Only clip sibling windows when the parent has the WS_CLIPSIBLINGS
	style set.

	* [windows/focus.c]
	Make order of events in FOCUS_SwitchFocus() reflect API docs.

	* [windows/defdlg.c]
	Fix problem with loss of focus in some dialogs.

	* [win32/code_page.c]
	Fix return value for MultiByteToWideChar().

	* [BUGS]
	BCW now works.
---
 ANNOUNCE                         |  18 +-
 BUGS                             |   6 +-
 ChangeLog                        | 167 ++++++++++++-
 Make.rules.in                    |   2 +-
 Makefile.in                      |  43 ++--
 README                           |  11 +-
 configure                        | 230 ++++++++---------
 configure.in                     |  30 ++-
 controls/Makefile.in             |   2 +-
 controls/button.c                |  39 ++-
 controls/edit.c                  |  45 ++--
 controls/listbox.c               |   5 +
 controls/menu.c                  | 158 ++++++++++--
 controls/static.c                |   2 +-
 controls/widgets.c               |  68 +-----
 debugger/break.c                 |  10 +-
 debugger/dbg.y                   |   7 +-
 debugger/hash.c                  |  65 +++--
 debugger/msc.c                   |  12 +-
 debugger/registers.c             |  30 ++-
 debugger/source.c                |  10 +-
 debugger/stack.c                 |  13 +-
 documentation/debugging          |   4 +-
 documentation/internals          |  18 +-
 files/Makefile.in                |   2 +-
 files/directory.c                |   2 +-
 files/drive.c                    |   5 +
 files/file.c                     |   4 +-
 graphics/Makefile.in             |   2 +-
 graphics/metafiledrv/Makefile.in |   2 +-
 graphics/win16drv/brush.c        |   4 +-
 graphics/win16drv/init.c         |   4 +-
 graphics/win16drv/pen.c          |   4 +-
 graphics/win16drv/prtdrv.c       |   8 +-
 graphics/x11drv/Makefile.in      |   2 +-
 graphics/x11drv/text.c           |   4 +-
 graphics/x11drv/xfont.c          |   9 +-
 if1632/builtin.c                 |   3 +-
 if1632/ddeml.spec                |  26 +-
 if1632/gdi.spec                  |   2 +-
 if1632/gdi32.spec                |  10 +-
 if1632/shell32.spec              |   3 +-
 if1632/signal.c                  |  24 +-
 if1632/thunk.c                   |  35 ++-
 if1632/user.spec                 |   4 +-
 if1632/user32.spec               |  12 +-
 if1632/wprocs.spec               |   1 -
 include/accel.h                  |  36 ---
 include/bitmaps/obm_radiocheck   |  23 ++
 include/bitmaps/ocr_ibeam        |   2 +-
 include/callback.h               |   1 +
 include/clipboard.h              |   7 +-
 include/dce.h                    |   2 +-
 include/ddeml.h                  |  16 ++
 include/debugger.h               |  10 +-
 include/debugstr.h               |  15 ++
 include/gdi.h                    |   1 -
 include/keyboard.h               |   2 +-
 include/mdi.h                    |  24 +-
 include/mmsystem.h               |  34 +--
 include/module.h                 |   4 +-
 include/msdos.h                  |   6 +-
 include/nonclient.h              |   3 +-
 include/options.h                |   4 +
 include/selectors.h              |  42 ++--
 include/sig_context.h            |  20 +-
 include/version.h                |   1 +
 include/win.h                    |   4 +-
 include/win16drv.h               |   8 +-
 include/windows.h                |  57 +++++
 include/wintypes.h               |  33 +--
 ipc/Makefile.in                  |   2 +-
 library/Makefile.in              |  17 +-
 library/miscstubs.c              |  44 ----
 library/winestub.c               |  10 +-
 loader/Makefile.in               |   3 +-
 {library => loader}/libres.c     |   0
 loader/main.c                    | 192 ++++++---------
 loader/module.c                  | 307 +++++++++--------------
 loader/ne_image.c                | 137 ++++++++++-
 loader/pe_image.c                |  22 +-
 loader/resource.c                | 266 +++++++++++---------
 loader/task.c                    |  67 +++--
 memory/Makefile.in               |   2 +-
 memory/selector.c                |  10 +-
 memory/string.c                  |  70 ++++--
 misc/Makefile.in                 |   4 +-
 misc/callback.c                  |   1 +
 misc/ddeml.c                     | 121 +++++++++
 misc/debugstr.c                  | 127 ++++++++++
 misc/main.c                      | 344 ++------------------------
 misc/ole2nls.c                   |   4 +-
 misc/registry.c                  |  45 +++-
 misc/shell.c                     | 281 ++++++++++++++++++++-
 misc/ver.c                       |  30 ++-
 misc/version.c                   | 262 ++++++++++++++++++++
 miscemu/Makefile.in              |   3 +-
 miscemu/main.c                   | 120 +++++++++
 msdos/Makefile.in                |   2 +-
 msdos/dpmi.c                     | 297 +++++++++++++---------
 msdos/int2f.c                    |   9 +-
 multimedia/Makefile.in           |   2 +-
 objects/Makefile.in              |   2 +-
 objects/bitmap.c                 |  19 +-
 objects/cursoricon.c             |  81 +++++-
 objects/dib.c                    |  48 +++-
 objects/font.c                   |   6 +-
 objects/gdiobj.c                 |  17 +-
 objects/oembitmap.c              |   4 +-
 objects/region.c                 | 133 ++++++----
 objects/text.c                   |   7 +-
 programs/progman/Makefile.in     |   2 +-
 programs/progman/main.c          |   7 +-
 programs/winhelp/Makefile.in     |   1 +
 programs/winhelp/winhelp.c       |   6 +-
 resources/Makefile.in            |   2 +-
 resources/sysres_Cz.rc           |  14 +-
 resources/sysres_Da.rc           |  14 +-
 resources/sysres_De.rc           |  13 +-
 resources/sysres_En.rc           |  14 +-
 resources/sysres_Eo.rc           |  14 +-
 resources/sysres_Es.rc           |  14 +-
 resources/sysres_Fi.rc           |  14 +-
 resources/sysres_Fr.rc           |  14 +-
 resources/sysres_Hu.rc           |  14 +-
 resources/sysres_It.rc           |  13 +-
 resources/sysres_Ko.rc           |  14 +-
 resources/sysres_No.rc           |  14 +-
 resources/sysres_Pl.rc           |  15 +-
 resources/sysres_Po.rc           |  16 +-
 scheduler/Makefile.in            |   2 +-
 scheduler/thread.c               |  21 +-
 tools/build.c                    |  33 +--
 tools/examine-relay              |  61 +++++
 win32/Makefile.in                |   2 +-
 win32/code_page.c                |   6 +-
 windows/Makefile.in              |   2 +-
 windows/clipboard.c              | 408 +++++++++++++++++--------------
 windows/dce.c                    |  36 +--
 windows/defdlg.c                 |   3 +-
 windows/defwnd.c                 |  46 ++--
 windows/event.c                  | 230 ++++++++++-------
 windows/focus.c                  |   5 +-
 windows/keyboard.c               |  55 +++--
 windows/mdi.c                    | 331 ++++++++++++-------------
 windows/nonclient.c              | 176 ++++++-------
 windows/painting.c               |  49 ++--
 windows/queue.c                  |   2 +
 windows/user.c                   |   2 +
 windows/win.c                    |  44 ++--
 windows/winpos.c                 |   8 +-
 windows/winproc.c                |   6 +-
 152 files changed, 3880 insertions(+), 2503 deletions(-)
 delete mode 100644 include/accel.h
 create mode 100644 include/bitmaps/obm_radiocheck
 create mode 100644 include/debugstr.h
 create mode 100644 include/version.h
 delete mode 100644 library/miscstubs.c
 rename {library => loader}/libres.c (100%)
 create mode 100644 misc/debugstr.c
 create mode 100644 misc/version.c
 create mode 100644 miscemu/main.c
 create mode 100755 tools/examine-relay

diff --git a/ANNOUNCE b/ANNOUNCE
index d0eb735281b..d05e8faa650 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,14 +1,14 @@
-This is release 971101 of Wine, the MS Windows emulator.  This is still a
+This is release 971116 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-971101: (see ChangeLog for details)
-	- Win32 version of multimedia functions.
-	- ASPI support.
-	- Better DCE handling (in progress).
+WHAT'S NEW with Wine-971116: (see ChangeLog for details)
+	- Emulator and library unification.
+	- New About dialog.
+	- Menus improvements.
 	- Lots of bug fixes.
 
 See the README file in the distribution for installation instructions.
@@ -17,10 +17,10 @@ Because of lags created by using mirror, this message may reach you before
 the release is available at the ftp sites.  The sources will be available
 from the following locations:
 
-  ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine/development/Wine-971101.tar.gz
-  ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/development/Wine-971101.tar.gz
-  ftp://ftp.infomagic.com/pub/mirrors/linux/wine/development/Wine-971101.tar.gz
-  ftp://ftp.progsoc.uts.edu.au/pub/Wine/development/Wine-971101.tar.gz
+  ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine/development/Wine-971116.tar.gz
+  ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/development/Wine-971116.tar.gz
+  ftp://ftp.infomagic.com/pub/mirrors/linux/wine/development/Wine-971116.tar.gz
+  ftp://ftp.progsoc.uts.edu.au/pub/Wine/development/Wine-971116.tar.gz
 
 It should also be available from any site that mirrors tsx-11 or sunsite.
 
diff --git a/BUGS b/BUGS
index 8b769fee8ce..dff1e4df9a9 100644
--- a/BUGS
+++ b/BUGS
@@ -5,7 +5,7 @@ done something for one of the problems. You are encouraged to
 add new entries and, more importantly, remove those for the 
 bugs you fixed ;-)
 ------------------------------------------------------------
-As of Oct 1997 -
+As of Nov 1997 -
 
 General:
 
@@ -36,9 +36,7 @@ General:
 
 Miscellaneous:
 
- * Missing menu separators in BCW, other programs.
-
- * BCW fails with "bad class 'MessageWindow'" message.
+ * Invisible controls in BCW dialogs.
 
  * MIRC is unable to show 'Options' dialog.
 
diff --git a/ChangeLog b/ChangeLog
index aa26de686f6..8b4b830caa3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,168 @@
+----------------------------------------------------------------------
+Sun Nov 16 07:42:44 1997  Alex Korobka <alex@trantor.pharm.sunysb.edu>
+
+	* [windows/dce.c] [windows/clipboard.c] [windows/nonclient.c]
+	Bug fixes.
+
+	* [misc/shell.c] [resources/*]
+	New "About" dialog.
+
+Sat Nov 15 17:30:18 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>
+
+	* [configure.in] [Makefile.in]
+	Replaced --with-library option by --disable-emulator. The default
+ 	is now to build both the library and the emulator.
+	Renamed --with options to --enable to follow autoconf guidelines.
+
+	* [loader/main.c] [miscemu/main.c] (New file)
+	Split initialization in WinelibInit/EmulatorInit.
+
+	* [loader/*.c]
+	Removed all remaining #ifdef's WINELIB.
+
+	* [controls/widgets.c] [windows/mdi.c]
+	Converted MDIClientWndProc to 32-bit.
+
+	* [debugger/break.c] [if1632/signal.c] [include/selectors.h]
+	  [scheduler/thread.c]
+	Code and data selector values are now computed at run-time.
+
+	* [library/libres.c]
+	Moved to loader/ directory.
+
+	* [misc/main.c] [misc/version.c] (New file)
+	Moved all version stuff to version.c. Cleaned up a bit.
+
+	* [msdos/dpmi.c]
+	Update the REALMODECALL structure on return from real-mode
+	interrupt.
+
+	* [windows/event.c] [windows/keyboard.c]
+	Changed the way event coordinates are determined. Don't rely on
+	the ConfigureNotify event values. This should fix all problems
+	with cursor position in -desktop and -managed modes.
+
+Sat Nov 15 16:09:36 1997  Slaven Rezic  <eserte@cs.tu-berlin.de>
+
+	* [controls/button.c]
+	(BUTTON_CheckAutoRadioButton): Prevent possible endless loop.
+
+Wed Nov 12 03:42:45 1997  Chris Faherty <chrisf@america.com>
+
+	* [misc/ver.c]
+	Changed VerInstall32A to assume srcdir as destination if destdir
+	is blank.  This was causing alot of DLL installation into SYSTEM
+	directory to fail.
+
+	* [loader/ne_image.c]
+	NE_LoadSegment buffer[100] was too small and getting overruns.
+	Changed it to buffer[200].
+
+Sat Nov  8 06:09:57 1997  Len White <phreak@cgocable.net>
+
+	* [misc/ddeml.c] [include/ddeml.h] [if1632/ddeml.spec]
+	Added stub functions DdeConnectList(), DdeQueryNextServer(),
+	DdeDisconnectList(), DdeSetUserHandle(), DdeAbandonTransaction(),
+	DdePostAdvise(), DdeCreateDataHandle(), DdeAddData(), DdeGetData(),
+	DdeAccessData(), DdeUnaccessData(), DdeEnableCallback(),
+	DdeCmpStringHandles().
+
+Fri Nov  7 19:44:26 1997  Olaf Flebbe  <o.flebbe@science-computing.de>
+
+	* [files/directory.c]
+	Fix typo in directory.c [broke loading of cdplayer on nt40]
+
+	* [misc/main.c]
+	Implemented -winver nt40.
+
+	* [loader/resource.c] [user32.spec]
+	Stubs for CopyAcceleratorTable, Destroy AcceleratorTable.
+
+Thu Nov  6 22:37:04 1997  Morten Welinder  <welinder@rentec.com>
+
+	* [files/drive.c]
+	(GetDiskFreeSpace32A): Cap at 2GB.
+
+	* [include/windows.h]
+	Prototype DrawIconEx and CreateDIBSection32.
+	Define OBM_RADIOCHECK.
+	Add DI_* macros.
+
+	* [objects/dib.c] [if1632/gdi.spec]
+	CreateDIBSection is a WINAPI.  Renamed to CreateDIBSection32.
+	Implement CreateDIBSection16.
+
+	* [if1632/user.spec] [if1632/user32.spec]
+	Add DrawIconEx.
+
+	* [objects/cursoricon.c]
+	(CopyIcon32): Fix bogus implementation.
+
+	* [objects/bitmap.c]
+	(CopyBitmap32): New function.
+	(CopyImage32): Do bitmaps.
+
+	* [graphics/x11drv/text.c]
+	(X11DRV_ExtTextOut): Change ascent and descent default to avoid
+	zero-thinkness overstrike line.
+
+	* [include/debugstr.h] [misc/debugstr.c]
+	New files.
+
+	* [msdos/dpmi.c]
+	Don't prototype do_mscdex. In INT_Int31Handler, handle real-mode
+	int 0x21, ah=0x52.
+
+	* [msdos/int2f.c]
+	Add dummys for 0x1681 and 0x1682.
+
+	* [misc/registry.c]
+	Fix memory leaks in RegDeleteKey32W.
+
+	* [objects/text.c]
+	In TEXT_NextLine, fix another off-by-one bug.
+
+	* [include/bitmaps/obm_radiocheck]
+	New file.  (It a small circle used to radio-button menu items
+	when selected.)
+	
+	* [objects/oembitmap.c]
+	Add obm_radiocheck.
+
+	* [include/windows.h] [if1632/user32.spec] [controls/menu.c]
+	  [if1632/user.spec]
+	Define CheckMenuRadioItem{16,32}.  Define GetMenuItemRect{16,32}.
+
+Wed Nov  5 11:30:14 1997  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
+	* [misc/main.c]
+	Auto adjust versions depending on binary.
+
+Tue Nov  4 15:21:00 1997  Kristian Nielsen  <kristian.nielsen@risoe.dk>
+
+	* [controls/listbox.c]
+	Paint full background in listbox items with tab stops enabled.
+
+	* [if1632/thunk.c]
+	Copy some more message parameter structures (DRAWITEMSTRUCT16,
+	COMPAREITEMSTRUCT16) to the stack segment to fix broken programs
+	that need this.
+
+	* [windows/dce.c]
+	Only clip sibling windows when the parent has the WS_CLIPSIBLINGS
+	style set.
+
+	* [windows/focus.c]
+	Make order of events in FOCUS_SwitchFocus() reflect API docs.
+
+	* [windows/defdlg.c]
+	Fix problem with loss of focus in some dialogs.
+
+	* [win32/code_page.c]
+	Fix return value for MultiByteToWideChar().
+
+	* [BUGS]
+	BCW now works.
+
 ----------------------------------------------------------------------
 Thu Oct 30 21:52:23 1997  Martin Boehme <boehme@informatik.mu-luebeck.de>
 
@@ -108,7 +273,7 @@ Sun Oct 26 14:25:00 1997  Nikita V. Youshchenko <yoush@cs.msu.su>
 	* [include/drive.h] [files/drive.c] [msdos/int21.c]
 	Partially implemented DOS drive mapping (int21 AX=440F).
 
-Sat Oct 25 13:03:29 1997  Alexandre Julliard  <Alexandre.Julliard@urbanet.ch>
+Sat Oct 25 13:03:29 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>
 
 	* [debugger/debug.l]
 	Support '.' in identifiers. Use "x . y" to access structure
diff --git a/Make.rules.in b/Make.rules.in
index 6a94c60fc7c..e27e88b82d5 100644
--- a/Make.rules.in
+++ b/Make.rules.in
@@ -23,7 +23,7 @@ X_CFLAGS  = @X_CFLAGS@
 X_LIBS    = @X_LIBS@
 XPM_LIB   = -lXpm
 XLIB      = @X_PRE_LIBS@ -lXext -lX11 @X_EXTRA_LIBS@
-WINELIB   = $(WINESTUB) $(TOPOBJDIR)/@MAIN_TARGET@
+WINELIB   = $(WINESTUB) $(TOPOBJDIR)/@LIB_TARGET@
 LDLIBS    = @LDLIBS@
 YACC      = @YACC@
 LEX       = @LEX@
diff --git a/Makefile.in b/Makefile.in
index 8028391251d..32b77efae95 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,6 +1,7 @@
 # This Makefile understands the following targets:
 #
 # all (default):	build wine
+# lib:                  build libwine
 # clean:		remove all intermediate files
 # distclean:		also remove all files created by configure
 # install:              install everything
@@ -11,6 +12,7 @@
 # Main target to build
 
 MAIN_TARGET = @MAIN_TARGET@
+LIB_TARGET  = @LIB_TARGET@
 
 # Directories
 
@@ -20,7 +22,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 
-COMMONSUBDIRS = \
+LIBSUBDIRS = \
 	rc \
 	controls \
 	files \
@@ -28,6 +30,7 @@ COMMONSUBDIRS = \
 	graphics/metafiledrv \
 	graphics/x11drv \
 	ipc \
+	library \
 	loader \
 	memory \
 	misc \
@@ -46,27 +49,24 @@ EMUSUBDIRS = \
 	if1632 \
 	miscemu
 
-LIBSUBDIRS = library
-
 PROGSUBDIRS = libtest programs
 
 DOCSUBDIRS = documentation
 
 # All sub-directories
 ALLSUBDIRS = \
-	$(COMMONSUBDIRS) \
-	$(EMUSUBDIRS) \
 	$(LIBSUBDIRS) \
+	$(EMUSUBDIRS) \
 	$(PROGSUBDIRS) \
 	$(DOCSUBDIRS)
 
 # Sub-directories to run make depend into
-DEPENDSUBDIRS = $(COMMONSUBDIRS) $(LIBSUBDIRS) $(EMUSUBDIRS) $(DOCSUBDIRS)
+DEPENDSUBDIRS = $(LIBSUBDIRS) $(EMUSUBDIRS) $(DOCSUBDIRS)
 
 # Sub-directories to run make install into
 INSTALLSUBDIRS = $(DOCSUBDIRS)
 
-COMMONOBJS = \
+LIBOBJS = \
 	controls/controls.o \
 	files/files.o \
 	graphics/graphics.o \
@@ -90,34 +90,33 @@ EMUOBJS = \
 	if1632/if1632.o \
 	miscemu/miscemu.o
 
-LIBOBJS = library/library.o
-
 all: $(MAIN_TARGET)
 
 @MAKE_RULES@
 
 install:: install_$(MAIN_TARGET)
 
-wine wine.sym: $(COMMONSUBDIRS) $(EMUSUBDIRS) dummy
-	$(CC) -o wine $(COMMONOBJS) $(EMUOBJS) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LDLIBS)
-	nm -n wine | grep -v _compiled >wine.sym
+emu: wine
 
-install_wine: dummy
-	$(INSTALL_PROGRAM) wine $(bindir)/wine
+lib: $(LIB_TARGET)
+
+wine wine.sym: $(LIB_TARGET) $(EMUSUBDIRS) dummy
+	$(CC) -o wine $(EMUOBJS) $(LIB_TARGET) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LDLIBS)
+	nm -n wine | grep -v _compiled >wine.sym
 
-libwine.a: $(COMMONSUBDIRS) $(LIBSUBDIRS) dummy
+libwine.a: $(LIBSUBDIRS) dummy
 	$(RM) $@
-	$(AR) $@ $(COMMONOBJS) $(LIBOBJS)
+	$(AR) $@ $(LIBOBJS)
 	$(RANLIB) $@
 
-install_libwine.a: install_includes
-	$(INSTALL_DATA) libwine.a $(libdir)
+libwine.so.1.0: $(LIBSUBDIRS) dummy
+	$(CC) -shared -Wl,-soname,libwine.so -o$@ $(LIBOBJS) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LDLIBS)
 
-libwine.so.1.0: $(COMMONSUBDIRS) $(LIBSUBDIRS) dummy
-	$(CC) -shared -Wl,-soname,libwine.so -o$@ $(COMMONOBJS) $(LIBOBJS) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LDLIBS)
+install_emu: dummy
+	$(INSTALL_PROGRAM) wine $(bindir)/wine
 
-install_libwine.so.1.0: install_includes
-	$(INSTALL_DATA) libwine.so.1.0 $(libdir)
+install_lib: install_includes
+	$(INSTALL_DATA) $(LIB_TARGET) $(libdir)
 
 install_includes: dummy
 	if [ -d $(includedir) ]; then : ; else $(MKDIR) $(includedir); fi 
diff --git a/README b/README
index 01bc7919fe3..bd900e2fae7 100644
--- a/README
+++ b/README
@@ -23,13 +23,12 @@ it are probably available on the ftp site where you got Wine. They can
 also be found on ftp.x.org and all its mirror sites.
 
 To build Wine, first do a "./configure" and then a "make depend; make".
-The executable "wine" will be built.  "wine" will load and run 16-bit
-Windows executables.
+This will build the library "libwine.a" and the program "wine".
 
-To build Winelib, do a "./configure --with-library", and then a "make
-depend; make". The library "winelib.a" will be built, allowing to
-compile Windows source code under Unix. If you have an ELF compiler,
-you can use "./configure --with-dll" instead to build a shared library.
+The program "wine" will load and run Windows executables.
+The library "libwine.a" can be used to compile and link Windows source
+code under Unix.  If you have an ELF compiler, you can use
+"./configure --enable-dll" to build a shared library instead.
 
 To upgrade to a new release by using a patch file, first cd to the
 top-level directory of the release (the one containing this README
diff --git a/configure b/configure
index d56268675ac..83ba00865f2 100755
--- a/configure
+++ b/configure
@@ -13,11 +13,11 @@ ac_help=
 ac_default_prefix=/usr/local
 # Any additions from configure.in:
 ac_help="$ac_help
-  --with-library          build Wine as a library instead of an emulator"
+  --disable-emulator      build only the Wine library, not the emulator"
 ac_help="$ac_help
-  --with-dll              build Wine as a DLL instead of an emulator"
+  --enable-dll            build the Wine library as a DLL"
 ac_help="$ac_help
-  --with-ipc              use inter-process communication for DDE"
+  --enable-ipc            use inter-process communication for DDE"
 ac_help="$ac_help
   --with-x                use the X Window System"
 
@@ -553,26 +553,27 @@ test -z "$LDLIBS" && LDLIBS=-lm
 test -z "$PROGEXT" && PROGEXT="" 
 
 
-# Check whether --with-library or --without-library was given.
-if test "${with_library+set}" = set; then
-  withval="$with_library"
-  OPTIONS="-DWINELIB" MAIN_TARGET="libwine.a"
-else
-  OPTIONS="" MAIN_TARGET="wine"
+MAIN_TARGET=emu
+LIB_TARGET=libwine.a
+
+# Check whether --enable-emulator or --disable-emulator was given.
+if test "${enable_emulator+set}" = set; then
+  enableval="$enable_emulator"
+  if test "$enableval" = "no"; then MAIN_TARGET="lib"; fi
 fi
 
 
-# Check whether --with-dll or --without-dll was given.
-if test "${with_dll+set}" = set; then
-  withval="$with_dll"
-  OPTIONS="-DWINELIB" MAIN_TARGET="libwine.so.1.0"
+# Check whether --enable-dll or --disable-dll was given.
+if test "${enable_dll+set}" = set; then
+  enableval="$enable_dll"
+  if test "$enableval" = "no"; then : ; else LIB_TARGET="libwine.so.1.0"; fi
 fi
 
 
 # Check whether --with-ipc or --without-ipc was given.
 if test "${with_ipc+set}" = set; then
   withval="$with_ipc"
-  OPTIONS="$OPTIONS -DCONFIG_IPC"
+  if test "$enableval" = "no"; then : ; else OPTIONS="-DCONFIG_IPC"; fi
 fi
 
 
@@ -580,8 +581,9 @@ fi
 
 
 
+
 echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
-echo "configure:585: checking whether ${MAKE-make} sets \${MAKE}" >&5
+echo "configure:587: checking whether ${MAKE-make} sets \${MAKE}" >&5
 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -610,7 +612,7 @@ fi
 # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:614: checking for $ac_word" >&5
+echo "configure:616: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -639,7 +641,7 @@ if test -z "$CC"; then
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:643: checking for $ac_word" >&5
+echo "configure:645: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -687,7 +689,7 @@ fi
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:691: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:693: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -697,11 +699,11 @@ ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS
 cross_compiling=$ac_cv_prog_cc_cross
 
 cat > conftest.$ac_ext <<EOF
-#line 701 "configure"
+#line 703 "configure"
 #include "confdefs.h"
 main(){return(0);}
 EOF
-if { (eval echo configure:705: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:707: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
@@ -721,12 +723,12 @@ if test $ac_cv_prog_cc_works = no; then
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:725: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:727: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:730: checking whether we are using GNU C" >&5
+echo "configure:732: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -735,7 +737,7 @@ else
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:739: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:741: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
@@ -750,7 +752,7 @@ if test $ac_cv_prog_gcc = yes; then
   ac_save_CFLAGS="$CFLAGS"
   CFLAGS=
   echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:754: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:756: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -778,7 +780,7 @@ else
 fi
 
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:782: checking how to run the C preprocessor" >&5
+echo "configure:784: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
@@ -793,13 +795,13 @@ else
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 797 "configure"
+#line 799 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:803: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:805: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   :
@@ -810,13 +812,13 @@ else
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 814 "configure"
+#line 816 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:820: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:822: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   :
@@ -843,7 +845,7 @@ echo "$ac_t""$CPP" 1>&6
 # Uses ac_ vars as temps to allow command line to override cache and checks.
 # --without-x overrides everything else, but does not touch the cache.
 echo $ac_n "checking for X""... $ac_c" 1>&6
-echo "configure:847: checking for X" >&5
+echo "configure:849: checking for X" >&5
 
 # Check whether --with-x or --without-x was given.
 if test "${with_x+set}" = set; then
@@ -905,12 +907,12 @@ if test "$ac_x_includes" = NO; then
 
   # First, try using that file with no special directory specified.
 cat > conftest.$ac_ext <<EOF
-#line 909 "configure"
+#line 911 "configure"
 #include "confdefs.h"
 #include <$x_direct_test_include>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:914: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:916: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -979,14 +981,14 @@ if test "$ac_x_libraries" = NO; then
   ac_save_LIBS="$LIBS"
   LIBS="-l$x_direct_test_library $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 983 "configure"
+#line 985 "configure"
 #include "confdefs.h"
 
 int main() {
 ${x_direct_test_function}()
 ; return 0; }
 EOF
-if { (eval echo configure:990: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:992: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   LIBS="$ac_save_LIBS"
 # We can link X programs with no special library path.
@@ -1092,17 +1094,17 @@ else
     case "`(uname -sr) 2>/dev/null`" in
     "SunOS 5"*)
       echo $ac_n "checking whether -R must be followed by a space""... $ac_c" 1>&6
-echo "configure:1096: checking whether -R must be followed by a space" >&5
+echo "configure:1098: checking whether -R must be followed by a space" >&5
       ac_xsave_LIBS="$LIBS"; LIBS="$LIBS -R$x_libraries"
       cat > conftest.$ac_ext <<EOF
-#line 1099 "configure"
+#line 1101 "configure"
 #include "confdefs.h"
 
 int main() {
 
 ; return 0; }
 EOF
-if { (eval echo configure:1106: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1108: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   ac_R_nospace=yes
 else
@@ -1118,14 +1120,14 @@ rm -f conftest*
       else
 	LIBS="$ac_xsave_LIBS -R $x_libraries"
 	cat > conftest.$ac_ext <<EOF
-#line 1122 "configure"
+#line 1124 "configure"
 #include "confdefs.h"
 
 int main() {
 
 ; return 0; }
 EOF
-if { (eval echo configure:1129: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1131: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   ac_R_space=yes
 else
@@ -1157,7 +1159,7 @@ rm -f conftest*
     # libraries were built with DECnet support.  And karl@cs.umb.edu says
     # the Alpha needs dnet_stub (dnet does not exist).
     echo $ac_n "checking for dnet_ntoa in -ldnet""... $ac_c" 1>&6
-echo "configure:1161: checking for dnet_ntoa in -ldnet" >&5
+echo "configure:1163: checking for dnet_ntoa in -ldnet" >&5
 ac_lib_var=`echo dnet'_'dnet_ntoa | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1165,7 +1167,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-ldnet  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1169 "configure"
+#line 1171 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1176,7 +1178,7 @@ int main() {
 dnet_ntoa()
 ; return 0; }
 EOF
-if { (eval echo configure:1180: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1182: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1198,7 +1200,7 @@ fi
 
     if test $ac_cv_lib_dnet_dnet_ntoa = no; then
       echo $ac_n "checking for dnet_ntoa in -ldnet_stub""... $ac_c" 1>&6
-echo "configure:1202: checking for dnet_ntoa in -ldnet_stub" >&5
+echo "configure:1204: checking for dnet_ntoa in -ldnet_stub" >&5
 ac_lib_var=`echo dnet_stub'_'dnet_ntoa | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1206,7 +1208,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-ldnet_stub  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1210 "configure"
+#line 1212 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1217,7 +1219,7 @@ int main() {
 dnet_ntoa()
 ; return 0; }
 EOF
-if { (eval echo configure:1221: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1223: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1246,12 +1248,12 @@ fi
     # The nsl library prevents programs from opening the X display
     # on Irix 5.2, according to dickey@clark.net.
     echo $ac_n "checking for gethostbyname""... $ac_c" 1>&6
-echo "configure:1250: checking for gethostbyname" >&5
+echo "configure:1252: checking for gethostbyname" >&5
 if eval "test \"`echo '$''{'ac_cv_func_gethostbyname'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1255 "configure"
+#line 1257 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char gethostbyname(); below.  */
@@ -1274,7 +1276,7 @@ gethostbyname();
 
 ; return 0; }
 EOF
-if { (eval echo configure:1278: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1280: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_gethostbyname=yes"
 else
@@ -1295,7 +1297,7 @@ fi
 
     if test $ac_cv_func_gethostbyname = no; then
       echo $ac_n "checking for gethostbyname in -lnsl""... $ac_c" 1>&6
-echo "configure:1299: checking for gethostbyname in -lnsl" >&5
+echo "configure:1301: checking for gethostbyname in -lnsl" >&5
 ac_lib_var=`echo nsl'_'gethostbyname | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1303,7 +1305,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lnsl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1307 "configure"
+#line 1309 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1314,7 +1316,7 @@ int main() {
 gethostbyname()
 ; return 0; }
 EOF
-if { (eval echo configure:1318: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1320: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1344,12 +1346,12 @@ fi
     # -lsocket must be given before -lnsl if both are needed.
     # We assume that if connect needs -lnsl, so does gethostbyname.
     echo $ac_n "checking for connect""... $ac_c" 1>&6
-echo "configure:1348: checking for connect" >&5
+echo "configure:1350: checking for connect" >&5
 if eval "test \"`echo '$''{'ac_cv_func_connect'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1353 "configure"
+#line 1355 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char connect(); below.  */
@@ -1372,7 +1374,7 @@ connect();
 
 ; return 0; }
 EOF
-if { (eval echo configure:1376: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1378: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_connect=yes"
 else
@@ -1393,7 +1395,7 @@ fi
 
     if test $ac_cv_func_connect = no; then
       echo $ac_n "checking for connect in -lsocket""... $ac_c" 1>&6
-echo "configure:1397: checking for connect in -lsocket" >&5
+echo "configure:1399: checking for connect in -lsocket" >&5
 ac_lib_var=`echo socket'_'connect | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1401,7 +1403,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lsocket $X_EXTRA_LIBS $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1405 "configure"
+#line 1407 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1412,7 +1414,7 @@ int main() {
 connect()
 ; return 0; }
 EOF
-if { (eval echo configure:1416: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1418: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1436,12 +1438,12 @@ fi
 
     # gomez@mi.uni-erlangen.de says -lposix is necessary on A/UX.
     echo $ac_n "checking for remove""... $ac_c" 1>&6
-echo "configure:1440: checking for remove" >&5
+echo "configure:1442: checking for remove" >&5
 if eval "test \"`echo '$''{'ac_cv_func_remove'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1445 "configure"
+#line 1447 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char remove(); below.  */
@@ -1464,7 +1466,7 @@ remove();
 
 ; return 0; }
 EOF
-if { (eval echo configure:1468: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1470: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_remove=yes"
 else
@@ -1485,7 +1487,7 @@ fi
 
     if test $ac_cv_func_remove = no; then
       echo $ac_n "checking for remove in -lposix""... $ac_c" 1>&6
-echo "configure:1489: checking for remove in -lposix" >&5
+echo "configure:1491: checking for remove in -lposix" >&5
 ac_lib_var=`echo posix'_'remove | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1493,7 +1495,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lposix  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1497 "configure"
+#line 1499 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1504,7 +1506,7 @@ int main() {
 remove()
 ; return 0; }
 EOF
-if { (eval echo configure:1508: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1510: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1528,12 +1530,12 @@ fi
 
     # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
     echo $ac_n "checking for shmat""... $ac_c" 1>&6
-echo "configure:1532: checking for shmat" >&5
+echo "configure:1534: checking for shmat" >&5
 if eval "test \"`echo '$''{'ac_cv_func_shmat'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1537 "configure"
+#line 1539 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char shmat(); below.  */
@@ -1556,7 +1558,7 @@ shmat();
 
 ; return 0; }
 EOF
-if { (eval echo configure:1560: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1562: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_shmat=yes"
 else
@@ -1577,7 +1579,7 @@ fi
 
     if test $ac_cv_func_shmat = no; then
       echo $ac_n "checking for shmat in -lipc""... $ac_c" 1>&6
-echo "configure:1581: checking for shmat in -lipc" >&5
+echo "configure:1583: checking for shmat in -lipc" >&5
 ac_lib_var=`echo ipc'_'shmat | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1585,7 +1587,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lipc  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1589 "configure"
+#line 1591 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1596,7 +1598,7 @@ int main() {
 shmat()
 ; return 0; }
 EOF
-if { (eval echo configure:1600: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1602: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1629,7 +1631,7 @@ fi
   # libraries we check for below, so use a different variable.
   #  --interran@uluru.Stanford.EDU, kb@cs.umb.edu.
   echo $ac_n "checking for IceConnectionNumber in -lICE""... $ac_c" 1>&6
-echo "configure:1633: checking for IceConnectionNumber in -lICE" >&5
+echo "configure:1635: checking for IceConnectionNumber in -lICE" >&5
 ac_lib_var=`echo ICE'_'IceConnectionNumber | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1637,7 +1639,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lICE  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1641 "configure"
+#line 1643 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1648,7 +1650,7 @@ int main() {
 IceConnectionNumber()
 ; return 0; }
 EOF
-if { (eval echo configure:1652: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1654: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1677,7 +1679,7 @@ do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1681: checking for $ac_word" >&5
+echo "configure:1683: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_YACC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1709,7 +1711,7 @@ test -n "$YACC" || YACC="yacc"
 # Extract the first word of "flex", so it can be a program name with args.
 set dummy flex; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1713: checking for $ac_word" >&5
+echo "configure:1715: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_LEX'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1742,7 +1744,7 @@ then
   *) ac_lib=l ;;
   esac
   echo $ac_n "checking for yywrap in -l$ac_lib""... $ac_c" 1>&6
-echo "configure:1746: checking for yywrap in -l$ac_lib" >&5
+echo "configure:1748: checking for yywrap in -l$ac_lib" >&5
 ac_lib_var=`echo $ac_lib'_'yywrap | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1750,7 +1752,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-l$ac_lib  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1754 "configure"
+#line 1756 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1761,7 +1763,7 @@ int main() {
 yywrap()
 ; return 0; }
 EOF
-if { (eval echo configure:1765: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1767: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1786,7 +1788,7 @@ fi
 # Extract the first word of "ranlib", so it can be a program name with args.
 set dummy ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1790: checking for $ac_word" >&5
+echo "configure:1792: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1823,7 +1825,7 @@ fi
 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
 # ./install, which can be erroneously created by make from ./install.sh.
 echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:1827: checking for a BSD compatible install" >&5
+echo "configure:1829: checking for a BSD compatible install" >&5
 if test -z "$INSTALL"; then
 if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1873,7 +1875,7 @@ test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 
 echo $ac_n "checking whether ln -s works""... $ac_c" 1>&6
-echo "configure:1877: checking whether ln -s works" >&5
+echo "configure:1879: checking whether ln -s works" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_LN_S'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1894,7 +1896,7 @@ else
 fi
 
 echo $ac_n "checking for i386_set_ldt in -li386""... $ac_c" 1>&6
-echo "configure:1898: checking for i386_set_ldt in -li386" >&5
+echo "configure:1900: checking for i386_set_ldt in -li386" >&5
 ac_lib_var=`echo i386'_'i386_set_ldt | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1902,7 +1904,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-li386  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1906 "configure"
+#line 1908 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1913,7 +1915,7 @@ int main() {
 i386_set_ldt()
 ; return 0; }
 EOF
-if { (eval echo configure:1917: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1919: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1941,7 +1943,7 @@ if test "x${GCC}" = "xyes"
 then
   CFLAGS="$CFLAGS -Wall"
   echo $ac_n "checking "for gcc strength-reduce bug"""... $ac_c" 1>&6
-echo "configure:1945: checking "for gcc strength-reduce bug"" >&5
+echo "configure:1947: checking "for gcc strength-reduce bug"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_gcc_strength_bug'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1949,7 +1951,7 @@ else
   ac_cv_c_gcc_strength_bug="yes"
 else
   cat > conftest.$ac_ext <<EOF
-#line 1953 "configure"
+#line 1955 "configure"
 #include "confdefs.h"
 
 int main(void) {
@@ -1960,7 +1962,7 @@ int main(void) {
   exit( Array[1] != -2 );
 }
 EOF
-if { (eval echo configure:1964: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1966: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   ac_cv_c_gcc_strength_bug="no"
 else
@@ -1983,7 +1985,7 @@ fi
 
 
 echo $ac_n "checking "whether external symbols need an underscore prefix"""... $ac_c" 1>&6
-echo "configure:1987: checking "whether external symbols need an underscore prefix"" >&5
+echo "configure:1989: checking "whether external symbols need an underscore prefix"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_extern_prefix'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1995,14 +1997,14 @@ _ac_test:
 	.long 0
 EOF
 cat > conftest.$ac_ext <<EOF
-#line 1999 "configure"
+#line 2001 "configure"
 #include "confdefs.h"
 extern int ac_test;
 int main() {
 if (ac_test) return 1
 ; return 0; }
 EOF
-if { (eval echo configure:2006: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2008: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   ac_cv_c_extern_prefix="yes"
 else
@@ -2025,24 +2027,25 @@ EOF
 fi
 
 
-if test "$MAIN_TARGET" = "libwine.so.1.0"
+DLLFLAGS=""
+if test "$LIB_TARGET" = "libwine.so.1.0"
 then
   echo $ac_n "checking "whether we can build a dll"""... $ac_c" 1>&6
-echo "configure:2032: checking "whether we can build a dll"" >&5
+echo "configure:2035: checking "whether we can build a dll"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_dll'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   saved_cflags=$CFLAGS
   CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0"
   cat > conftest.$ac_ext <<EOF
-#line 2039 "configure"
+#line 2042 "configure"
 #include "confdefs.h"
 
 int main() {
 return 1
 ; return 0; }
 EOF
-if { (eval echo configure:2046: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2049: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   ac_cv_c_dll="yes"
 else
@@ -2059,22 +2062,23 @@ fi
 echo "$ac_t""$ac_cv_c_dll" 1>&6
   if test "$ac_cv_c_dll" = "yes"
   then
-    CFLAGS="$CFLAGS -fPIC"
+    DLLFLAGS="-fPIC"
   else
-    MAIN_TARGET="libwine.a"
+    LIB_TARGET="libwine.a"
   fi
 fi
 
 
+
 for ac_func in memmove tcgetattr usleep wait4 waitpid
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2073: checking for $ac_func" >&5
+echo "configure:2077: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2078 "configure"
+#line 2082 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2097,7 +2101,7 @@ $ac_func();
 
 ; return 0; }
 EOF
-if { (eval echo configure:2101: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2105: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -2122,12 +2126,12 @@ fi
 done
 
 echo $ac_n "checking whether stat file-mode macros are broken""... $ac_c" 1>&6
-echo "configure:2126: checking whether stat file-mode macros are broken" >&5
+echo "configure:2130: checking whether stat file-mode macros are broken" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stat_broken'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2131 "configure"
+#line 2135 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -2178,12 +2182,12 @@ EOF
 fi
 
 echo $ac_n "checking for working const""... $ac_c" 1>&6
-echo "configure:2182: checking for working const" >&5
+echo "configure:2186: checking for working const" >&5
 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2187 "configure"
+#line 2191 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -2232,7 +2236,7 @@ ccp = (char const *const *) p;
 
 ; return 0; }
 EOF
-if { (eval echo configure:2236: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2240: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_const=yes
 else
@@ -2253,12 +2257,12 @@ EOF
 fi
 
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:2257: checking for ANSI C header files" >&5
+echo "configure:2261: checking for ANSI C header files" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2262 "configure"
+#line 2266 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdarg.h>
@@ -2266,7 +2270,7 @@ else
 #include <float.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2270: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2274: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2283,7 +2287,7 @@ rm -f conftest*
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 2287 "configure"
+#line 2291 "configure"
 #include "confdefs.h"
 #include <string.h>
 EOF
@@ -2301,7 +2305,7 @@ fi
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 2305 "configure"
+#line 2309 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 EOF
@@ -2322,7 +2326,7 @@ if test "$cross_compiling" = yes; then
   :
 else
   cat > conftest.$ac_ext <<EOF
-#line 2326 "configure"
+#line 2330 "configure"
 #include "confdefs.h"
 #include <ctype.h>
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
@@ -2333,7 +2337,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
 exit (0); }
 
 EOF
-if { (eval echo configure:2337: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2341: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   :
 else
@@ -2357,12 +2361,12 @@ EOF
 fi
 
 echo $ac_n "checking for size_t""... $ac_c" 1>&6
-echo "configure:2361: checking for size_t" >&5
+echo "configure:2365: checking for size_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2366 "configure"
+#line 2370 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -2558,6 +2562,7 @@ s%@mandir@%$mandir%g
 s%@LDLIBS@%$LDLIBS%g
 s%@PROGEXT@%$PROGEXT%g
 s%@MAIN_TARGET@%$MAIN_TARGET%g
+s%@LIB_TARGET@%$LIB_TARGET%g
 s%@OPTIONS@%$OPTIONS%g
 s%@SET_MAKE@%$SET_MAKE%g
 s%@CC@%$CC%g
@@ -2573,6 +2578,7 @@ s%@RANLIB@%$RANLIB%g
 s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
 s%@INSTALL_DATA@%$INSTALL_DATA%g
 s%@LN_S@%$LN_S%g
+s%@DLLFLAGS@%$DLLFLAGS%g
 /@MAKE_RULES@/r $MAKE_RULES
 s%@MAKE_RULES@%%g
 
diff --git a/configure.in b/configure.in
index 9e97d28a102..9e4d70201d5 100644
--- a/configure.in
+++ b/configure.in
@@ -12,20 +12,24 @@ test -z "$PROGEXT" && PROGEXT="" AC_SUBST(PROGEXT)
 
 dnl **** Command-line arguments ****
 
-AC_ARG_WITH(library,
-[  --with-library          build Wine as a library instead of an emulator],
-[OPTIONS="-DWINELIB" MAIN_TARGET="libwine.a"],
-[OPTIONS="" MAIN_TARGET="wine"])
+dnl Default values
+MAIN_TARGET=emu
+LIB_TARGET=libwine.a
 
-AC_ARG_WITH(dll,
-[  --with-dll              build Wine as a DLL instead of an emulator],
-[OPTIONS="-DWINELIB" MAIN_TARGET="libwine.so.1.0"])
+AC_ARG_ENABLE(emulator,
+[  --disable-emulator      build only the Wine library, not the emulator],
+[if test "$enableval" = "no"; then MAIN_TARGET="lib"; fi])
+
+AC_ARG_ENABLE(dll,
+[  --enable-dll            build the Wine library as a DLL],
+[if test "$enableval" = "no"; then : ; else LIB_TARGET="libwine.so.1.0"; fi])
 
 AC_ARG_WITH(ipc,
-[  --with-ipc              use inter-process communication for DDE],
-[OPTIONS="$OPTIONS -DCONFIG_IPC"])
+[  --enable-ipc            use inter-process communication for DDE],
+[if test "$enableval" = "no"; then : ; else OPTIONS="-DCONFIG_IPC"; fi])
 
 AC_SUBST(MAIN_TARGET)
+AC_SUBST(LIB_TARGET)
 AC_SUBST(OPTIONS)
 
 dnl **** Check for some programs and libraries ****
@@ -89,7 +93,8 @@ fi
 
 dnl **** Check for working dll ****
 
-if test "$MAIN_TARGET" = "libwine.so.1.0"
+DLLFLAGS=""
+if test "$LIB_TARGET" = "libwine.so.1.0"
 then
   AC_CACHE_CHECK("whether we can build a dll",
                  ac_cv_c_dll,
@@ -100,11 +105,12 @@ then
   ])
   if test "$ac_cv_c_dll" = "yes"
   then
-    CFLAGS="$CFLAGS -fPIC"
+    DLLFLAGS="-fPIC"
   else
-    MAIN_TARGET="libwine.a"
+    LIB_TARGET="libwine.a"
   fi
 fi
+AC_SUBST(DLLFLAGS)
 
 dnl **** Check for functions and header files ****
 
diff --git a/controls/Makefile.in b/controls/Makefile.in
index 2974ba52664..3a64a7b0c5b 100644
--- a/controls/Makefile.in
+++ b/controls/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/controls/button.c b/controls/button.c
index 27e73c4d769..836070d83e0 100644
--- a/controls/button.c
+++ b/controls/button.c
@@ -110,15 +110,16 @@ LRESULT WINAPI ButtonWndProc( HWND32 hWnd, UINT32 uMsg,
         return 0;
 
     case WM_ERASEBKGND:
-        break;
+        return 1;
 
     case WM_PAINT:
         if (btnPaintFunc[style])
         {
             PAINTSTRUCT32 ps;
-            HDC32 hdc = BeginPaint32( hWnd, &ps );
+            HDC32 hdc = wParam ? (HDC32)wParam : BeginPaint32( hWnd, &ps );
+	    SetBkMode32( hdc, OPAQUE );
             (btnPaintFunc[style])( wndPtr, hdc, ODA_DRAWENTIRE );
-            EndPaint32( hWnd, &ps );
+            if( !wParam ) EndPaint32( hWnd, &ps );
         }
         break;
 
@@ -384,7 +385,15 @@ static void CB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
     rbox = rtext = client;
 
     if (infoPtr->hFont) SelectObject32( hDC, infoPtr->hFont );
-    hBrush = BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
+
+    /* Something is still not right, checkboxes (and edit controls)
+     * in wsping32 have white backgrounds instead of dark grey.
+     * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
+     * particular case and the background is not painted at all.
+     */
+
+    hBrush = GetControlBrush( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
+
     if (wndPtr->dwStyle & BS_LEFTTEXT) 
     {
 	/* magic +4 is what CTL3D expects */
@@ -423,6 +432,7 @@ static void CB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
                 SetTextColor32( hDC, GetSysColor32(COLOR_GRAYTEXT) );
             DrawText16( hDC, wndPtr->text, textlen, &rtext,
                         DT_SINGLELINE | DT_VCENTER );
+	    textlen = 0; /* skip DrawText() below */
         }
     }
 
@@ -453,14 +463,19 @@ static void CB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
  */
 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
 {
-    HWND32 parent, sibling;
+    HWND32 parent, sibling, start;
     if (!(wndPtr->dwStyle & WS_CHILD)) return;
     parent = wndPtr->parent->hwndSelf;
-    for(sibling = GetNextDlgGroupItem32( parent, wndPtr->hwndSelf, FALSE );
-        sibling != wndPtr->hwndSelf && sibling != 0;
-        sibling = GetNextDlgGroupItem32( parent, sibling, FALSE ))
-	    if((WIN_FindWndPtr(sibling)->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)
-		SendMessage32A( sibling, BM_SETCHECK32, BUTTON_UNCHECKED, 0 );
+    /* assure that starting control is not disabled or invisible */
+    start = sibling = GetNextDlgGroupItem32( parent, wndPtr->hwndSelf, TRUE );
+    do
+    {
+        if (!sibling) break;
+        if ((wndPtr->hwndSelf != sibling) &&
+            ((WIN_FindWndPtr(sibling)->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
+            SendMessage32A( sibling, BM_SETCHECK32, BUTTON_UNCHECKED, 0 );
+        sibling = GetNextDlgGroupItem32( parent, sibling, FALSE );
+    } while (sibling != start);
 }
 
 
@@ -506,9 +521,9 @@ static void UB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
     GetClientRect16( wndPtr->hwndSelf, &rc);
 
     if (infoPtr->hFont) SelectObject32( hDC, infoPtr->hFont );
-    hBrush = BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
-    FillRect16( hDC, &rc, hBrush );
+    hBrush = GetControlBrush( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
 
+    FillRect16( hDC, &rc, hBrush );
     if ((action == ODA_FOCUS) ||
         ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
         DrawFocusRect16( hDC, &rc );
diff --git a/controls/edit.c b/controls/edit.c
index c6bcafee16f..a2858950242 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -1055,24 +1055,33 @@ static INT32 EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y, LPBOOL3
 		dc = GetDC32(wnd->hwndSelf);
 		if (es->font)
 			old_font = SelectObject32(dc, es->font);
-		if (x < 0) {
-			x = -x;
-			/* FIXME: inefficient algorithm */
-			for (index = es->x_offset ; index ; index--) {
-				GetTextExtentPoint32A(dc, text + index,
-						es->x_offset - index, &size);
-				if (size.cx > x)
-					break;
-			}
-		} else {
-			INT32 len = lstrlen32A(es->text);
-			/* FIXME: inefficient algorithm */
-			for (index = es->x_offset ; index < len ; index++) {
-				GetTextExtentPoint32A(dc, text + es->x_offset,
-						index - es->x_offset, &size);
-				if (size.cx >= x)
-					break;
-			}
+		if (x < 0)
+                {
+                    INT32 low = 0;
+                    INT32 high = es->x_offset;
+                    while (low < high - 1)
+                    {
+                        INT32 mid = (low + high) / 2;
+                        GetTextExtentPoint32A( dc, text + mid,
+                                               es->x_offset - mid, &size );
+                        if (size.cx > -x) low = mid;
+                        else high = mid;
+                    }
+                    index = low;
+		}
+                else
+                {
+                    INT32 low = es->x_offset;
+                    INT32 high = lstrlen32A(es->text) + 1;
+                    while (low < high - 1)
+                    {
+                        INT32 mid = (low + high) / 2;
+                        GetTextExtentPoint32A( dc, text + es->x_offset,
+                                               mid - es->x_offset, &size );
+                        if (size.cx > x) high = mid;
+                        else low = mid;
+                    }
+                    index = low;
 		}
 		if (es->style & ES_PASSWORD)
 			HeapFree(es->heap, 0 ,text);
diff --git a/controls/listbox.c b/controls/listbox.c
index 165f483e141..f163c479e8b 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -492,9 +492,14 @@ static void LISTBOX_PaintItem( WND *wnd, LB_DESCR *descr, HDC32 hdc,
 			   ETO_OPAQUE | ETO_CLIPPED, rect, item->str,
 			   strlen(item->str), NULL );
         else
+	{
+	    /* Output empty string to paint background in the full width. */
+	    ExtTextOut32A( hdc, rect->left + 1, rect->top + 1,
+                           ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL );
 	    TabbedTextOut32A( hdc, rect->left + 1 , rect->top + 1,
 			      item->str, strlen(item->str), 
 			      descr->nb_tabs, descr->tabs, 0);
+	}
         if (item && item->selected)
         {
             SetBkColor32( hdc, oldBk );
diff --git a/controls/menu.c b/controls/menu.c
index a31b2f1449b..35a89f18a4c 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -3,6 +3,7 @@
  *
  * Copyright 1993 Martin Ayotte
  * Copyright 1994 Alexandre Julliard
+ * Copyright 1997 Morten Welinder
  */
 
 /*
@@ -142,6 +143,7 @@ typedef struct
 static WORD check_bitmap_width = 0, check_bitmap_height = 0;
 static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
 
+static HBITMAP32 hStdRadioCheck = 0;
 static HBITMAP32 hStdCheck = 0;
 static HBITMAP32 hStdMnArrow = 0;
 static HBRUSH32 hShadeBrush = 0;
@@ -316,38 +318,50 @@ HMENU32 MENU_GetSysMenu( HWND32 hWnd, HMENU32 hPopupMenu )
  */
 BOOL32 MENU_Init()
 {
+    HBITMAP32 hBitmap;
+    static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
+					    0x55, 0, 0xAA, 0,
+					    0x55, 0, 0xAA, 0,
+					    0x55, 0, 0xAA, 0 };
+
     /* Load menu bitmaps */
+    hStdCheck = LoadBitmap32A(0, (LPSTR)MAKEINTRESOURCE(OBM_CHECK));
+    hStdRadioCheck = LoadBitmap32A(0, (LPSTR)MAKEINTRESOURCE(OBM_RADIOCHECK));
+    hStdMnArrow = LoadBitmap32A(0, (LPSTR)MAKEINTRESOURCE(OBM_MNARROW));
 
-    if ((hStdCheck = LoadBitmap32A( 0, (LPSTR)MAKEINTRESOURCE(OBM_CHECK) )))
+    if (hStdCheck)
     {
 	BITMAP32 bm;
-
 	GetObject32A( hStdCheck, sizeof(bm), &bm );
 	check_bitmap_width = bm.bmWidth;
 	check_bitmap_height = bm.bmHeight;
+    } else
+	 return FALSE;
+
+    /* Assume that radio checks have the same size as regular check.  */
+    if (!hStdRadioCheck)
+	 return FALSE;
 
-	if ((hStdMnArrow = LoadBitmap32A(0,(LPSTR)MAKEINTRESOURCE(OBM_MNARROW))))
+    if (hStdMnArrow)
 	{
-	    HBITMAP32 hBitmap;
-	    static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
-						    0x55, 0, 0xAA, 0,
-						    0x55, 0, 0xAA, 0,
-						    0x55, 0, 0xAA, 0 };
+	 BITMAP32 bm;
 	    GetObject32A( hStdMnArrow, sizeof(bm), &bm );
 	    arrow_bitmap_width = bm.bmWidth;
 	    arrow_bitmap_height = bm.bmHeight;
+    } else
+	 return FALSE;
 
-	    if((hBitmap = CreateBitmap32( 8, 8, 1, 1, shade_bits)))
+    if ((hBitmap = CreateBitmap32( 8, 8, 1, 1, shade_bits)))
 	    {
 		if((hShadeBrush = CreatePatternBrush32( hBitmap )))
 		{
 		    DeleteObject32( hBitmap );
-		    if((MENU_DefSysPopup = MENU_CopySysPopup())) return TRUE;
-		}
-	    }
+	      if ((MENU_DefSysPopup = MENU_CopySysPopup()))
+		   return TRUE;
 	}
     }
-    return FALSE;	/* failure */
+
+    return FALSE;
 }
 
 /***********************************************************************
@@ -720,7 +734,7 @@ static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND32 hwndOwner )
 /***********************************************************************
  *           MENU_MenuBarCalcSize
  *
- * FIXME: Word 6 implements it's own MDI and it's 'close window' bitmap
+ * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
  * height is off by 1 pixel which causes lengthy window relocations when
  * active document window is maximized/restored.
  *
@@ -936,10 +950,16 @@ static void MENU_DrawMenuItem( HWND32 hwnd, HDC32 hdc, MENUITEM *lpitem,
 	   */
 
 	if (lpitem->fState & MF_CHECKED)
-            GRAPH_DrawBitmap( hdc, lpitem->hCheckBit ? lpitem->hCheckBit
-			      : hStdCheck, rect.left, (y - check_bitmap_height) / 2, 
-			      0, 0, check_bitmap_width, check_bitmap_height, TRUE );
-        else if (lpitem->hUnCheckBit)
+	{
+	    HBITMAP32 bm =
+		 lpitem->hCheckBit ? lpitem->hCheckBit :
+		 ((lpitem->fType & MFT_RADIOCHECK)
+		  ? hStdRadioCheck : hStdCheck);
+            GRAPH_DrawBitmap( hdc, bm, rect.left,
+			      (y - check_bitmap_height) / 2,
+			      0, 0, check_bitmap_width,
+			      check_bitmap_height, TRUE );
+        } else if (lpitem->hUnCheckBit)
             GRAPH_DrawBitmap( hdc, lpitem->hUnCheckBit, rect.left,
 			      (y - check_bitmap_height) / 2, 0, 0,
 			      check_bitmap_width, check_bitmap_height, TRUE );
@@ -3872,3 +3892,105 @@ BOOL32 WINAPI InsertMenuItem32W(HMENU32 hMenu, UINT32 uItem, BOOL32 bypos,
     MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos);
     return SetMenuItemInfo32_common(item, (const MENUITEMINFO32A*)lpmii, TRUE);
 }
+
+/**********************************************************************
+ *		CheckMenuRadioItem32    (USER32.47)
+ */
+
+BOOL32 WINAPI CheckMenuRadioItem32(HMENU32 hMenu,
+				   UINT32 first, UINT32 last, UINT32 check,
+				   BOOL32 bypos)
+{
+     MENUITEM *mifirst, *milast, *micheck;
+     HMENU32 mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
+
+     dprintf_menu (stddeb,
+		   "CheckMenuRadioItem32: ox%x: %d-%d, check %d, bypos=%d\n",
+		   hMenu, first, last, check, bypos);
+
+     mifirst = MENU_FindItem (&mfirst, &first, bypos);
+     milast = MENU_FindItem (&mlast, &last, bypos);
+     micheck = MENU_FindItem (&mcheck, &check, bypos);
+
+     if (mifirst == NULL || milast == NULL || micheck == NULL ||
+	 mifirst > milast || mfirst != mlast || mfirst != mcheck ||
+	 micheck > milast || micheck < mifirst)
+	  return FALSE;
+
+     while (mifirst <= milast)
+     {
+	  if (mifirst == micheck)
+	  {
+	       mifirst->fType |= MFT_RADIOCHECK;
+	       mifirst->fState |= MFS_CHECKED;
+	  } else {
+	       mifirst->fType &= ~MFT_RADIOCHECK;
+	       mifirst->fState &= ~MFS_CHECKED;
+	  }
+	  mifirst++;
+     }
+
+     return TRUE;
+}
+
+/**********************************************************************
+ *		CheckMenuRadioItem16    (not a Windows API)
+ */
+
+BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu,
+				   UINT16 first, UINT16 last, UINT16 check,
+				   BOOL16 bypos)
+{
+     return CheckMenuRadioItem32 (hMenu, first, last, check, bypos);
+}
+
+/**********************************************************************
+ *		GetMenuItemRect32    (USER32.266)
+ */
+
+BOOL32 WINAPI GetMenuItemRect32 (HWND32 hwnd, HMENU32 hMenu, UINT32 uItem,
+				 LPRECT32 rect)
+{
+     RECT32 saverect, clientrect;
+     BOOL32 barp;
+     HDC32 hdc;
+     WND *wndPtr;
+     MENUITEM *item;
+     HMENU32 orghMenu = hMenu;
+
+     dprintf_menu (stddeb, "GetMenuItemRect32 (0x%x,0x%x,%d,%p)\n",
+		   hwnd, hMenu, uItem, rect);
+
+     item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
+     wndPtr = WIN_FindWndPtr (hwnd);
+     if (!rect || !item || !wndPtr) return FALSE;
+
+     GetClientRect32( hwnd, &clientrect );
+     hdc = GetDCEx32( hwnd, 0, DCX_CACHE | DCX_WINDOW );
+     barp = (hMenu == orghMenu);
+
+     saverect = item->rect;
+     MENU_CalcItemSize (hdc, item, hwnd,
+			clientrect.left, clientrect.top, barp);
+     *rect = item->rect;
+     item->rect = saverect;
+
+     ReleaseDC32( hwnd, hdc );
+     return TRUE;
+}
+
+/**********************************************************************
+ *		GetMenuItemRect16    (USER.665)
+ */
+
+BOOL16 WINAPI GetMenuItemRect16 (HWND16 hwnd, HMENU16 hMenu, UINT16 uItem,
+				 LPRECT16 rect)
+{
+     RECT32 r32;
+     BOOL32 res;
+
+     if (!rect) return FALSE;
+     res = GetMenuItemRect32 (hwnd, hMenu, uItem, &r32);
+     CONV_RECT32TO16 (&r32, rect);
+     return res;
+}
diff --git a/controls/static.c b/controls/static.c
index 0e565f28c7a..9f1e6806acb 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -84,7 +84,7 @@ static HICON16 STATIC_SetBitmap( WND *wndPtr, HICON16 hicon )
 {
     HICON16 prevIcon;
     STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
-    BITMAPOBJ *info = GDI_HEAP_LOCK(hicon);
+    BITMAPOBJ *info = (BITMAPOBJ *)GDI_HEAP_LOCK(hicon);
 
     if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
     if (hicon && !info) {
diff --git a/controls/widgets.c b/controls/widgets.c
index 81af00ae4b1..acb95606129 100644
--- a/controls/widgets.c
+++ b/controls/widgets.c
@@ -32,31 +32,9 @@ extern LRESULT WINAPI PopupMenuWndProc( HWND32 hwnd, UINT32 msg,
 extern LRESULT WINAPI IconTitleWndProc( HWND32 hwnd, UINT32 msg,
                                         WPARAM32 wParam, LPARAM lParam );
 
-/* Win16 class info */
+/* Built-in classes */
 
-typedef struct
-{
-    UINT16     style;
-    INT16      wndExtra;
-    HBRUSH16   background;
-    LPCSTR     procName;
-    LPCSTR     className;
-} BUILTIN_CLASS_INFO16;
-
-/* Win16 built-in classes */
-
-static const BUILTIN_CLASS_INFO16 WIDGETS_BuiltinClasses16[] =
-{
-    { CS_GLOBALCLASS, sizeof(MDICLIENTINFO),
-      STOCK_LTGRAY_BRUSH, "MDIClientWndProc", "MDIClient" }
-};
-
-#define NB_BUILTIN_CLASSES16 \
-         (sizeof(WIDGETS_BuiltinClasses16)/sizeof(WIDGETS_BuiltinClasses16[0]))
-
-/* Win32 built-in classes */
-
-static WNDCLASS32A WIDGETS_BuiltinClasses32[BIC32_NB_CLASSES] =
+static WNDCLASS32A WIDGETS_BuiltinClasses[BIC32_NB_CLASSES] =
 {
     /* BIC32_BUTTON */
     { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC,
@@ -82,6 +60,9 @@ static WNDCLASS32A WIDGETS_BuiltinClasses32[BIC32_NB_CLASSES] =
     /* BIC32_SCROLL */
     { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC,
       ScrollBarWndProc, 0, sizeof(SCROLLBAR_INFO), 0, 0, IDC_ARROW, 0, 0, "ScrollBar"},
+    /* BIC32_MDICLIENT */
+    { CS_GLOBALCLASS, MDIClientWndProc,
+      0, sizeof(MDICLIENTINFO), 0, 0, 0, STOCK_LTGRAY_BRUSH, 0, "MDIClient" },
     /* BIC32_DESKTOP */
     { CS_GLOBALCLASS, DesktopWndProc, 0, sizeof(DESKTOPINFO),
       0, 0, IDC_ARROW, 0, 0, DESKTOP_CLASS_NAME },
@@ -103,45 +84,22 @@ static ATOM bicAtomTable[BIC32_NB_CLASSES];
 BOOL32 WIDGETS_Init(void)
 {
     int i;
-    char *name;
-    const BUILTIN_CLASS_INFO16 *info16 = WIDGETS_BuiltinClasses16;
-    WNDCLASS16 class16;
-    WNDCLASS32A *class32 = WIDGETS_BuiltinClasses32;
-
-    if (!(name = SEGPTR_ALLOC( 20 * sizeof(char) ))) return FALSE;
-
-    /* Create 16-bit classes */
-
-    class16.cbClsExtra    = 0;
-    class16.hInstance     = 0;
-    class16.hIcon         = 0;
-    class16.hCursor       = LoadCursor16( 0, IDC_ARROW );
-    class16.lpszMenuName  = (SEGPTR)0;
-    class16.lpszClassName = SEGPTR_GET(name);
-    for (i = 0; i < NB_BUILTIN_CLASSES16; i++, info16++)
-    {
-        class16.style         = info16->style;
-        class16.lpfnWndProc   = (WNDPROC16)MODULE_GetWndProcEntry16( info16->procName );
-        class16.cbWndExtra    = info16->wndExtra;
-        class16.hbrBackground = info16->background;
-        strcpy( name, info16->className );
-        if (!RegisterClass16( &class16 )) return FALSE;
-    }
+    WNDCLASS32A *cls = WIDGETS_BuiltinClasses;
 
-    /* Create 32-bit classes */
+    /* Create builtin classes */
 
-    for (i = 0; i < BIC32_NB_CLASSES; i++, class32++)
+    for (i = 0; i < BIC32_NB_CLASSES; i++, cls++)
     {
+        char name[20];
         /* Just to make sure the string is > 0x10000 */
-        strcpy( name, (char *)class32->lpszClassName );
-        class32->lpszClassName = name;
-        class32->hCursor = LoadCursor16( 0, class32->hCursor );
-        if (!(bicAtomTable[i] = RegisterClass32A( class32 ))) return FALSE;
+        strcpy( name, (char *)cls->lpszClassName );
+        cls->lpszClassName = name;
+        cls->hCursor = LoadCursor16( 0, cls->hCursor );
+        if (!(bicAtomTable[i] = RegisterClass32A( cls ))) return FALSE;
     }
 
     /* FIXME: hack to enable using built-in controls with Windows COMCTL32 */
     InitCommonControls();
-    SEGPTR_FREE(name);
     return TRUE;
 }
 
diff --git a/debugger/break.c b/debugger/break.c
index f26f7be2736..19d33865493 100644
--- a/debugger/break.c
+++ b/debugger/break.c
@@ -388,12 +388,13 @@ BOOL32 DEBUG_ShouldContinue( enum exec_mode mode, int * count )
     DBG_ADDR cond_addr;
     int bpnum;
     struct list_id list;
+    WORD cs;
 
       /* If not single-stepping, back up over the int3 instruction */
     if (!(EFL_reg(&DEBUG_context) & STEP_FLAG)) EIP_reg(&DEBUG_context)--;
 
-    addr.seg = (CS_reg(&DEBUG_context) == WINE_CODE_SELECTOR) ? 
-                0 : CS_reg(&DEBUG_context);
+    GET_CS(cs);
+    addr.seg = (CS_reg(&DEBUG_context) == cs) ? 0 : CS_reg(&DEBUG_context);
     addr.off = EIP_reg(&DEBUG_context);
         
     bpnum = DEBUG_FindBreakpoint( &addr );
@@ -512,9 +513,10 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count )
     unsigned int * value;
     enum exec_mode ret_mode;
     BYTE *instr;
+    WORD cs;
 
-    addr.seg = (CS_reg(&DEBUG_context) == WINE_CODE_SELECTOR) ?
-                0 : CS_reg(&DEBUG_context);
+    GET_CS(cs);
+    addr.seg = (CS_reg(&DEBUG_context) == cs) ? 0 : CS_reg(&DEBUG_context);
     addr.off = EIP_reg(&DEBUG_context);
 
     /*
diff --git a/debugger/dbg.y b/debugger/dbg.y
index cd84c903b9f..5fa4b5bded5 100644
--- a/debugger/dbg.y
+++ b/debugger/dbg.y
@@ -441,13 +441,8 @@ static void DEBUG_Main( int signal )
 	    DEBUG_ReadSymbolTable( SymbolTableFile );
         }
 
-	/*
-	 * Read COFF, MSC, etc debug information that we noted when we
-	 * started up the executable.
-	 */
-	DEBUG_ProcessDeferredDebug();
-
         DEBUG_LoadEntryPoints();
+	DEBUG_ProcessDeferredDebug();
 	fprintf(stderr,"\n");
     }
 
diff --git a/debugger/hash.c b/debugger/hash.c
index dc81bd63a12..815715a0fd2 100644
--- a/debugger/hash.c
+++ b/debugger/hash.c
@@ -633,21 +633,19 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
 	 * Try and find the nearest line number to the current offset.
 	 */
 	if( nearest->linetab != NULL )
-	  {
-	    /*
-	     * FIXME - this is an inefficient linear search.  A binary
-	     * search would be better if this gets to be a performance
-	     * bottleneck.
-	     */
-	    for(i=0; i < nearest->n_lines; i++)
-	      {
-		if( addr->off < nearest->linetab[i].pc_offset.off )
-		{
-		  break;
-		}
-		lineno = nearest->linetab[i].line_number;
-	      }
-	  }
+        {
+            low = 0;
+            high = nearest->n_lines;
+            while ((high - low) > 1)
+            {
+                mid = (high + low) / 2;
+                if (addr->off < nearest->linetab[mid].pc_offset.off)
+                    high = mid;
+                else
+                    low = mid;
+            }
+            lineno = nearest->linetab[low].line_number;
+        }
 
 	if( lineno != -1 )
 	  {
@@ -799,6 +797,7 @@ static void DEBUG_LoadEntryPoints32( PE_MODULE *pe, const char *name )
     char buffer[256];
     int i, j;
     IMAGE_EXPORT_DIRECTORY *exports;
+    IMAGE_DATA_DIRECTORY *debug_dir;
     DWORD load_addr;
     WORD *ordinals;
     void **functions;
@@ -859,6 +858,11 @@ static void DEBUG_LoadEntryPoints32( PE_MODULE *pe, const char *name )
         addr.off = (DWORD)RVA( functions[i] );
         DEBUG_AddSymbol( buffer, &addr, NULL, SYM_WIN32 | SYM_FUNC );
     }
+
+    debug_dir = &pe->pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
+    if (debug_dir->Size)
+        DEBUG_RegisterDebugInfo( pe, load_addr, name,
+                                 debug_dir->VirtualAddress, debug_dir->Size );
 #undef RVA
 }
 
@@ -976,7 +980,6 @@ int DEBUG_CheckLinenoStatus( const DBG_ADDR *addr)
 {
     struct name_hash * nearest = NULL;
     int mid, high, low;
-    int i;
 
     if( sortlist_valid == FALSE )
       {
@@ -1100,24 +1103,18 @@ int DEBUG_CheckLinenoStatus( const DBG_ADDR *addr)
     if( (nearest->sourcefile != NULL)
 	&& (addr->off - nearest->addr.off < 0x100000) )
       {
-	/*
-	 * FIXME - this is an inefficient linear search.  A binary
-	 * search would be better if this gets to be a performance
-	 * bottleneck.
-	 */
-	for(i=0; i < nearest->n_lines; i++)
-	  {
-	    if( addr->off == nearest->linetab[i].pc_offset.off )
-	      {
-		return AT_LINENUMBER;
-	      }
-	    if( addr->off < nearest->linetab[i].pc_offset.off )
-	      {
-		break;
-	      }
-	  }
-
-	return NOT_ON_LINENUMBER;
+          low = 0;
+          high = nearest->n_lines;
+          while ((high - low) > 1)
+          {
+              mid = (high + low) / 2;
+              if (addr->off < nearest->linetab[mid].pc_offset.off) high = mid;
+              else low = mid;
+          }
+          if (addr->off == nearest->linetab[low].pc_offset.off)
+              return AT_LINENUMBER;
+          else
+              return NOT_ON_LINENUMBER;
       }
 
     return FUNC_HAS_NO_LINES;
diff --git a/debugger/msc.c b/debugger/msc.c
index 3bc69afacec..8094d86f505 100644
--- a/debugger/msc.c
+++ b/debugger/msc.c
@@ -34,11 +34,6 @@
 #include "peexe.h"
 #include "xmalloc.h"
 
-/*
- * This is used so that we have some idea of what we are in fact loading
- * at any given time.
- */
-char * DEBUG_curr_module = NULL;
 
 /*
  * This is an index we use to keep track of the debug information
@@ -886,7 +881,8 @@ DEBUG_InitCVDataTypes()
  * We don't fully process it here for performance reasons.
  */
 int
-DEBUG_RegisterDebugInfo(struct pe_data * pe,int load_addr, u_long v_addr, u_long size)
+DEBUG_RegisterDebugInfo(struct pe_data * pe,int load_addr,
+                        const char *module_name, u_long v_addr, u_long size)
 {
   int			  has_codeview = FALSE;
   int			  rtn = FALSE;
@@ -956,13 +952,13 @@ DEBUG_RegisterDebugInfo(struct pe_data * pe,int load_addr, u_long v_addr, u_long
 	   * to proceed if we know what we need to do next.
 	   */
 	  deefer->dbg_size = dbgptr->SizeOfData;
-	  deefer->dbg_info = pe->mappeddll+dbgptr->PointerToRawData;
+	  deefer->dbg_info = (char *)(pe->mappeddll+dbgptr->PointerToRawData);
 	  deefer->load_addr = (char *) load_addr;
 	  deefer->dbgdir = dbgptr;
 	  deefer->next = dbglist;
 	  deefer->loaded = FALSE;
 	  deefer->dbg_index = DEBUG_next_index;
-	  deefer->module_name = xstrdup(DEBUG_curr_module);
+	  deefer->module_name = xstrdup(module_name);
 
 	  deefer->sectp = pe->pe_seg;
 	  deefer->nsect = pe->pe_header->FileHeader.NumberOfSections;
diff --git a/debugger/registers.c b/debugger/registers.c
index c280bb77b29..6ab0bac6aa6 100644
--- a/debugger/registers.c
+++ b/debugger/registers.c
@@ -147,13 +147,13 @@ void DEBUG_SetSigContext( const SIGCONTEXT *sigcontext )
 #ifdef FS_sig
     FS_reg(&DEBUG_context)  = LOWORD(FS_sig(sigcontext));
 #else
-    __asm__("movw %%fs,%w0":"=r" (FS_reg(&DEBUG_context)));
+    GET_FS( FS_reg(&DEBUG_context) );
     FS_reg(&DEBUG_context) &= 0xffff;
 #endif
 #ifdef GS_sig
     GS_reg(&DEBUG_context)  = LOWORD(GS_sig(sigcontext));
 #else
-    __asm__("movw %%gs,%w0":"=r" (GS_reg(&DEBUG_context)));
+    GET_GS( GS_reg(&DEBUG_context) );
     GS_reg(&DEBUG_context) &= 0xffff;
 #endif
 }
@@ -183,12 +183,12 @@ void DEBUG_GetSigContext( SIGCONTEXT *sigcontext )
 #ifdef FS_sig
     FS_sig(sigcontext)  = FS_reg(&DEBUG_context);
 #else
-    __asm__("movw %w0,%%fs"::"r" (FS_reg(&DEBUG_context)));
+    SET_FS( FS_reg(&DEBUG_context) );
 #endif
 #ifdef GS_sig
     GS_sig(sigcontext)  = GS_reg(&DEBUG_context);
 #else
-    __asm__("movw %w0,%%gs"::"r" (GS_reg(&DEBUG_context)));
+    SET_GS( GS_reg(&DEBUG_context) );
 #endif
 }
 
@@ -239,6 +239,8 @@ void DEBUG_InfoRegisters(void)
  */
 BOOL32 DEBUG_ValidateRegisters(void)
 {
+    WORD cs, ds;
+
 /* Check that a selector is a valid ring-3 LDT selector, or a NULL selector */
 #define CHECK_SEG(seg,name) \
     if (((seg) & ~3) && \
@@ -249,18 +251,14 @@ BOOL32 DEBUG_ValidateRegisters(void)
         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" );
+    GET_CS(cs);
+    GET_DS(ds);
+    if (CS_reg(&DEBUG_context) != cs) CHECK_SEG(CS_reg(&DEBUG_context), "CS");
+    if (SS_reg(&DEBUG_context) != ds) CHECK_SEG(SS_reg(&DEBUG_context), "SS");
+    if (DS_reg(&DEBUG_context) != ds) CHECK_SEG(DS_reg(&DEBUG_context), "DS");
+    if (ES_reg(&DEBUG_context) != ds) CHECK_SEG(ES_reg(&DEBUG_context), "ES");
+    if (FS_reg(&DEBUG_context) != ds) CHECK_SEG(FS_reg(&DEBUG_context), "FS");
+    if (GS_reg(&DEBUG_context) != ds) CHECK_SEG(GS_reg(&DEBUG_context), "GS");
 
     /* Check that CS and SS are not NULL */
 
diff --git a/debugger/source.c b/debugger/source.c
index 56b686a49fc..1a37195b069 100644
--- a/debugger/source.c
+++ b/debugger/source.c
@@ -480,7 +480,6 @@ DEBUG_Disassemble(const DBG_ADDR *xstart,const DBG_ADDR *xend,int offset)
   DBG_ADDR	last;
   DBG_ADDR	end,start;
 
-
   if (xstart) {
     start=*xstart;
     _disassemble_fixaddr(&start);
@@ -491,9 +490,12 @@ DEBUG_Disassemble(const DBG_ADDR *xstart,const DBG_ADDR *xend,int offset)
   }
   if (!xstart && !xend) {
     last = DEBUG_LastDisassemble;
-    if (!last.seg && !last.off) {
-      last.seg = (CS_reg(&DEBUG_context)==WINE_CODE_SELECTOR)?0:CS_reg(&DEBUG_context);
-      last.off = EIP_reg(&DEBUG_context);
+    if (!last.seg && !last.off)
+    {
+        WORD cs;
+        GET_CS(cs);
+        last.seg = (CS_reg(&DEBUG_context) == cs) ? 0 : CS_reg(&DEBUG_context);
+        last.off = EIP_reg(&DEBUG_context);
     }
     for (i=0;i<offset;i++)
       if (!_disassemble(&last)) break;
diff --git a/debugger/stack.c b/debugger/stack.c
index ca2bcc78841..fe9f5cb2f18 100644
--- a/debugger/stack.c
+++ b/debugger/stack.c
@@ -52,9 +52,11 @@ typedef struct
 void DEBUG_InfoStack(void)
 {
     DBG_ADDR addr;
+    WORD ss;
 
     fprintf(stderr,"Stack dump:\n");
-    if ((SS_reg(&DEBUG_context) == WINE_DATA_SELECTOR) ||
+    GET_SS(ss);
+    if ((SS_reg(&DEBUG_context) == ss) ||
         (GET_SEL_FLAGS(SS_reg(&DEBUG_context)) & LDT_FLAGS_32BIT))
     {  /* 32-bit mode */
         addr.seg = 0;
@@ -82,9 +84,11 @@ void DEBUG_BackTrace(void)
 {
     DBG_ADDR addr;
     int frameno = 0;
+    WORD ss;
 
     fprintf(stderr,"Backtrace:\n");
-    if (SS_reg(&DEBUG_context) == WINE_DATA_SELECTOR)  /* 32-bit mode */
+    GET_SS(ss);
+    if (SS_reg(&DEBUG_context) == ss)  /* 32-bit mode */
     {
         nframe = 1;
         if (frames) free( frames );
@@ -158,14 +162,15 @@ void DEBUG_BackTrace(void)
  */
 void DEBUG_SilentBackTrace(void)
 {
+    WORD ss;
     DBG_ADDR addr;
     int frameno = 0;
 
     nframe = 1;
     if (frames) free( frames );
     frames = (struct bt_info *) xmalloc( sizeof(struct bt_info) );
-
-    if (SS_reg(&DEBUG_context) == WINE_DATA_SELECTOR)  /* 32-bit mode */
+    GET_SS(ss);
+    if (SS_reg(&DEBUG_context) == ss)  /* 32-bit mode */
     {
         addr.seg = 0;
         addr.off = EIP_reg(&DEBUG_context);
diff --git a/documentation/debugging b/documentation/debugging
index 51bd0fcbced..1686ae72a9e 100644
--- a/documentation/debugging
+++ b/documentation/debugging
@@ -101,7 +101,9 @@ Program hangs, nothing happens
 
   Switch to UNIX shell, get the process-ID using "ps -a|grep wine", and do a
   "kill -HUP <pid>" (without " and <>). Wine will then enter its internal
-  debugger and you can proceed as explained above.
+  debugger and you can proceed as explained above. Also, you can use -debug
+  switch and then you can get into internal debugger by pressing Ctrl-C in 
+  the terminal where you run Wine.
 
 Program reports an error with a Messagebox
 ==========================================
diff --git a/documentation/internals b/documentation/internals
index 10bc578c0fa..5ffd800327d 100644
--- a/documentation/internals
+++ b/documentation/internals
@@ -17,6 +17,7 @@ stuff (rectangles, clipboard, WNet, etc). Wine USER code is
 located in windows/, controls/, and misc/ directories.
 
 1. Windowing subsystem
+----------------------
 
    windows/win.c
    windows/winpos.c
@@ -58,15 +59,17 @@ located in windows/, controls/, and misc/ directories.
    active window ("foreground window" in Win32) is moved to the front
    of z-order unless its top-level ancestor owns popup windows.
 
-   All these issues are dealt with (or supposed to be) in 
-   windows/winpos.c
+   All these issues are dealt with (or supposed to be) in windows/winpos.c 
+   with SetWindowPos() being the primary interface to the window manager.
 
    Wine specifics: in default and managed mode each top-level window
    gets its own X counterpart with desktop window being basically a 
    fake stub. In desktop mode, however, only desktop window has an X
-   window associated with it.
+   window associated with it. Also, SetWindowPos() should eventually be
+   implemented via Begin/End/DeferWindowPos() calls and not the other way
+   around.
 
-2. Visible region, clipping region and update region
+   1.1 Visible region, clipping region and update region
 
    windows/dce.c
    windows/winpos.c
@@ -143,9 +146,12 @@ located in windows/, controls/, and misc/ directories.
    the DC cache to recalculate visible regions for entries whose windows 
    were involved in the operation. DC entries (DCE) can be either private
    to the window, or private to the window class, or shared between all 
-   windows. Windows 3.1 limits the number of shared DCEs to 5. 
+   windows (Windows 3.1 limits the number of shared DCEs to 5).
+
+   1.2
 
-3. Messaging subsystem
+2. Messaging subsystem
+----------------------
 
    windows/queue.c
    windows/message.c
diff --git a/files/Makefile.in b/files/Makefile.in
index 788ae6d5f21..55b76a93c5d 100644
--- a/files/Makefile.in
+++ b/files/Makefile.in
@@ -1,6 +1,6 @@
 prefix     = @prefix@
 sysconfdir = @sysconfdir@
-DEFS       = -D__WINE__ -DETCDIR=\"$(sysconfdir)\"
+DEFS       = @DLLFLAGS@ -D__WINE__ -DETCDIR=\"$(sysconfdir)\"
 TOPSRCDIR  = @top_srcdir@
 TOPOBJDIR  = ..
 SRCDIR     = @srcdir@
diff --git a/files/directory.c b/files/directory.c
index 0f45fa968ea..b4ddb7ed10e 100644
--- a/files/directory.c
+++ b/files/directory.c
@@ -631,7 +631,7 @@ DWORD WINAPI SearchPath32W( LPCWSTR path, LPCWSTR name, LPCWSTR ext,
     while (*res == '/') res++;
     if (buflen)
     {
-        if (buflen > 3) lstrcpynAtoW( buffer + 3, res + 1, buflen - 3 );
+        if (buflen > 3) lstrcpynAtoW( buffer + 3, res, buflen - 3 ); 
         for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
         if (lastpart)
         {
diff --git a/files/drive.c b/files/drive.c
index fc592c6c021..f874df833ae 100644
--- a/files/drive.c
+++ b/files/drive.c
@@ -314,6 +314,7 @@ int DRIVE_FindDriveRoot( const char **path )
         while (!IS_END_OF_NAME(*p)) *next++ = *p++;
         *next = 0;
     }
+    *next = 0;
 
     if (rootdrive != -1)
         dprintf_dosfs( stddeb, "DRIVE_FindDriveRoot: %s -> drive %c:, root='%s', name='%s'\n",
@@ -618,6 +619,10 @@ BOOL32 WINAPI GetDiskFreeSpace32A( LPCSTR root, LPDWORD cluster_sectors,
     }
     if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE;
 
+    /* Cap the size and available at 2GB as per specs.  */
+    if (size > 0x7fffffff) size = 0x7fffffff;
+    if (available > 0x7fffffff) available = 0x7fffffff;
+
     *sector_bytes    = 512;
     size            /= 512;
     available       /= 512;
diff --git a/files/file.c b/files/file.c
index 51d443baba3..f60a115ea2a 100644
--- a/files/file.c
+++ b/files/file.c
@@ -1286,8 +1286,8 @@ LPVOID FILE_dommap( FILE_OBJECT *file, LPVOID start,
     }
 /*    printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
     /* Reserve the memory with an anonymous mmap */
-    ret = FILE_mmap( NULL, start, size_high, size_low, 0, 0,
-                     PROT_READ | PROT_WRITE, flags );
+    ret = FILE_dommap( NULL, start, size_high, size_low, 0, 0,
+                       PROT_READ | PROT_WRITE, flags );
     if (ret == (LPVOID)-1) return ret;
     /* Now read in the file */
     if ((pos = lseek( fd, offset_low, SEEK_SET )) == -1)
diff --git a/graphics/Makefile.in b/graphics/Makefile.in
index 9cab411392a..5912d90fdb6 100644
--- a/graphics/Makefile.in
+++ b/graphics/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/graphics/metafiledrv/Makefile.in b/graphics/metafiledrv/Makefile.in
index b0cd835bd98..16c4aae67d6 100644
--- a/graphics/metafiledrv/Makefile.in
+++ b/graphics/metafiledrv/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
diff --git a/graphics/win16drv/brush.c b/graphics/win16drv/brush.c
index d64b14e3d61..7edc8b77ea0 100644
--- a/graphics/win16drv/brush.c
+++ b/graphics/win16drv/brush.c
@@ -21,12 +21,12 @@ HBRUSH32 WIN16DRV_BRUSH_SelectObject( DC * dc, HBRUSH32 hbrush,
     lBrush16.lbStyle = brush->logbrush.lbStyle;
     lBrush16.lbColor = brush->logbrush.lbColor;
     lBrush16.lbHatch = brush->logbrush.lbHatch;
-    nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, OBJ_BRUSH,
+    nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, DRVOBJ_BRUSH,
                                   &lBrush16, NULL, 
                                   0); 
     /*  may need to realloc segptrFOntInfo*/
     physDev->segptrBrushInfo = WIN16_GlobalLock16(GlobalAlloc16(GHND, nSize));
-    nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, OBJ_BRUSH,
+    nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_BRUSH,
                                  &lBrush16, 
                                  (LPVOID)physDev->segptrBrushInfo, 
                                  win16drv_SegPtr_TextXForm); 
diff --git a/graphics/win16drv/init.c b/graphics/win16drv/init.c
index ba0a454006b..62811862e30 100644
--- a/graphics/win16drv/init.c
+++ b/graphics/win16drv/init.c
@@ -354,13 +354,13 @@ BOOL32 WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
     /* TTD should calculate this */
     
     /* First get the size of the realized font */
-    nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, OBJ_FONT,
+    nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_FONT,
 				 &pLPD->paPrinterFonts[0], NULL, 
 				 0);
     
     physDev->segptrFontInfo = WIN16_GlobalLock16(GlobalAlloc16(GHND, nSize));
     /* Realize the font */
-    PRTDRV_RealizeObject(physDev->segptrPDEVICE, OBJ_FONT,
+    PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_FONT,
 			 &pLPD->paPrinterFonts[0], 
 			 (LPVOID)physDev->segptrFontInfo, 
 			 win16drv_SegPtr_TextXForm);
diff --git a/graphics/win16drv/pen.c b/graphics/win16drv/pen.c
index d4b5933ff2f..a26ea9989be 100644
--- a/graphics/win16drv/pen.c
+++ b/graphics/win16drv/pen.c
@@ -25,12 +25,12 @@ HPEN32 WIN16DRV_PEN_SelectObject( DC * dc, HPEN32 hpen, PENOBJ * pen )
     lPen16.lopnWidth.x = pen->logpen.lopnWidth.x;
     lPen16.lopnWidth.y = pen->logpen.lopnWidth.y;
     lPen16.lopnColor   = pen->logpen.lopnColor;
-    nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, OBJ_PEN,
+    nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, DRVOBJ_PEN,
                                   &lPen16, NULL, 
                                   0); 
     /*  may need to realloc segptrFOntInfo*/
     physDev->segptrPenInfo = WIN16_GlobalLock16(GlobalAlloc16(GHND, nSize));
-    nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, OBJ_PEN,
+    nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_PEN,
                                  &lPen16, 
                                  (LPVOID)physDev->segptrPenInfo, 
                                  0); 
diff --git a/graphics/win16drv/prtdrv.c b/graphics/win16drv/prtdrv.c
index 4d22cffcbe9..8d7f550a9e0 100644
--- a/graphics/win16drv/prtdrv.c
+++ b/graphics/win16drv/prtdrv.c
@@ -428,16 +428,16 @@ DWORD PRTDRV_RealizeObject(LPPDEVICE lpDestDev, WORD wStyle,
 	
 	switch (wStyle)
 	{
-        case OBJ_BRUSH:
+        case DRVOBJ_BRUSH:
             nSize = sizeof (LOGBRUSH16);
             break;
-        case OBJ_FONT: 
+        case DRVOBJ_FONT: 
             nSize = sizeof(LOGFONT16); 
             break;
-        case OBJ_PEN:
+        case DRVOBJ_PEN:
             nSize = sizeof(LOGPEN16); 
             break;
-        case OBJ_PBITMAP:
+        case DRVOBJ_PBITMAP:
         default:
 	    fprintf(stderr, "PRTDRV_RealizeObject: Object type %d not supported\n", wStyle);
             nSize = 0;
diff --git a/graphics/x11drv/Makefile.in b/graphics/x11drv/Makefile.in
index d7fc1fd6271..fba445120e0 100644
--- a/graphics/x11drv/Makefile.in
+++ b/graphics/x11drv/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
diff --git a/graphics/x11drv/text.c b/graphics/x11drv/text.c
index 984d295efe3..357d8e2fba4 100644
--- a/graphics/x11drv/text.c
+++ b/graphics/x11drv/text.c
@@ -266,9 +266,9 @@ X11DRV_ExtTextOut( DC *dc, INT32 x, INT32 y, UINT32 flags,
     {
 	long lineAscent, lineDescent;
 	if (!XGetFontProperty( font, XA_STRIKEOUT_ASCENT, &lineAscent ))
-	    lineAscent = font->ascent / 3;
+	    lineAscent = font->ascent / 2;
 	if (!XGetFontProperty( font, XA_STRIKEOUT_DESCENT, &lineDescent ))
-	    lineDescent = -lineAscent;
+	    lineDescent = -lineAscent * 2 / 3;
 	XSetLineAttributes( display, dc->u.x.gc, lineAscent + lineDescent,
 			    LineSolid, CapRound, JoinBevel ); 
 	XDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c
index b02b710e653..9b988cf155b 100644
--- a/graphics/x11drv/xfont.c
+++ b/graphics/x11drv/xfont.c
@@ -99,6 +99,7 @@ static const char*	INIFontMetrics = "/.cachedmetrics";
 static const char*	INIFontSection = "fonts";
 static const char*	INISubSection = "Alias";
 static const char*	INIDefault = "Default";
+static const char*	INIDefaultFixed = "DefaultFixed";
 static const char*	INIResolution = "Resolution";
 static const char*	INIGlobalMetrics = "FontMetrics";
 
@@ -782,6 +783,7 @@ static void XFONT_WindowsNames( char* buffer )
     char* 	lpstr, *lpch;
     int		i, up;
     BYTE	bFamilyStyle;
+    const char*	relocTable[] = { INIDefaultFixed, INIDefault, NULL };
 
     for( fr = fontList; fr ; fr = fr->next )
     {
@@ -828,8 +830,9 @@ static void XFONT_WindowsNames( char* buffer )
 	fr->fr_flags |= FR_NAMESET;
     }
 
-    if( PROFILE_GetWineIniString( INIFontSection, INIDefault, "", buffer, 128 ) )
-    {
+    for( up = 0; relocTable[up]; up++ )
+      if( PROFILE_GetWineIniString( INIFontSection, relocTable[up], "", buffer, 128 ) )
+      {
 	while( *buffer && isspace(*buffer) ) buffer++;
 	for( fr = NULL, pfr = fontList; pfr; pfr = pfr->next )
 	{
@@ -846,7 +849,7 @@ static void XFONT_WindowsNames( char* buffer )
 	     }
 	     fr = pfr;
 	}
-    }
+      }
 }
 
 /***********************************************************************
diff --git a/if1632/builtin.c b/if1632/builtin.c
index 95e29e35730..d21f294f6a3 100644
--- a/if1632/builtin.c
+++ b/if1632/builtin.c
@@ -601,6 +601,8 @@ void BUILTIN_PrintDLLs(void)
     int i;
     BUILTIN_DLL *dll;
 
+    fprintf(stderr,"Example: -dll -ole2    Do not use emulated OLE2.DLL\n");
+    fprintf(stderr,"Available DLLs:\n");
     for (i = 0, dll = BuiltinDLLs; dll->descr; dll++)
     {
         if (!(dll->flags & DLL_FLAG_ALWAYS_USED))
@@ -608,5 +610,4 @@ void BUILTIN_PrintDLLs(void)
                      ((++i) % 8) ? ' ' : '\n' );
     }
     fprintf(stderr,"\n");
-    exit(1);
 }
diff --git a/if1632/ddeml.spec b/if1632/ddeml.spec
index 46c2420bf51..991d20c5d5c 100644
--- a/if1632/ddeml.spec
+++ b/if1632/ddeml.spec
@@ -3,22 +3,22 @@ type	win16
 
 2 pascal16 DdeInitialize(ptr segptr long long) DdeInitialize16
 3 pascal16 DdeUninitialize(long) DdeUninitialize16
-4 stub DdeConnectList #(long word word word ptr) DdeConnectList
-5 stub DdeQueryNextServer #(word word) DdeQueryNextServer
-6 stub DdeDisconnectList #(word) DdeDisconnectList
+4 pascal DdeConnectList(long word word word ptr) DdeConnectList
+5 pascal DdeQueryNextServer(word word) DdeQueryNextServer
+6 pascal DdeDisconnectList(word) DdeDisconnectList
 7 pascal   DdeConnect(long long long ptr) DdeConnect16
 8 pascal16 DdeDisconnect(long) DdeDisconnect16
 9 stub DdeQueryConvInfo #(word long ptr) DdeQueryConvInfo
-10 stub DdeSetUserHandle #(word long long) DdeSetUserHandle
+10 pascal DdeSetUserHandle(word long long) DdeSetUserHandle
 11 pascal   DdeClientTransaction(ptr long long long s_word s_word long ptr)
             DdeClientTransaction16
-12 stub DdeAbandonTransaction #(long word long) DdeAbandonTransaction
-13 stub DdePostAdvise #(long word word) DdePostAdvise
-14 stub DdeCreateDataHandle #(long ptr long long word word word) DdeCreateDataHandle
-15 stub DdeAddData #(word ptr long long) DdeAddData
-16 stub DdeGetData #(word ptr long long) DdeGetData
-17 stub DdeAccessData #(word ptr) DdeAccessData
-18 stub DdeUnaccessData #(word) DdeUnaccessData
+12 pascal DdeAbandonTransaction(long word long) DdeAbandonTransaction
+13 pascal DdePostAdvise(long word word) DdePostAdvise
+14 pascal DdeCreateDataHandle(long ptr long long word word word) DdeCreateDataHandle
+15 pascal DdeAddData(word ptr long long) DdeAddData
+16 pascal DdeGetData(word ptr long long) DdeGetData
+17 pascal DdeAccessData(word ptr) DdeAccessData
+18 pascal DdeUnaccessData(word) DdeUnaccessData
 19 pascal16 DdeFreeDataHandle(long) DdeFreeDataHandle16
 20 pascal16 DdeGetLastError(long) DdeGetLastError16
 21 pascal   DdeCreateStringHandle(long str s_word) DdeCreateStringHandle16
@@ -26,8 +26,8 @@ type	win16
 23 stub DdeQueryString #(long word ptr long word) DdeQueryString
 24 pascal16 DdeKeepStringHandle(long long) DdeKeepStringHandle16
 
-26 stub DdeEnableCallback #(long word word) DdeEnableCallback
+26 pascal DdeEnableCallback(long word word) DdeEnableCallback
 27 pascal   DdeNameService(long long long s_word) DdeNameService16
 
-36 stub DdeCmpStringHandles #(word word) DdeCmpStringHandles
+36 pascal DdeCmpStringHandles(word word) DdeCmpStringHandles
 37 pascal   DdeReconnect(long) DdeReconnect
diff --git a/if1632/gdi.spec b/if1632/gdi.spec
index f365ed981b9..07848fcd934 100644
--- a/if1632/gdi.spec
+++ b/if1632/gdi.spec
@@ -315,7 +315,7 @@ file	gdi.exe
 485 pascal16 ScaleWindowExtEx(word s_word s_word s_word s_word ptr)
              ScaleWindowExtEx16
 486 pascal16 GetAspectRatioFilterEx(word ptr) GetAspectRatioFilterEx16
-489 stub CreateDIBSection
+489 pascal16 CreateDIBSection(word ptr word ptr word long) CreateDIBSection16
 490 stub CloseEnhMetafile
 491 stub CopyEnhMetafile
 492 stub CreateEnhMetafile
diff --git a/if1632/gdi32.spec b/if1632/gdi32.spec
index 3a3abe95b5c..e33959842e2 100644
--- a/if1632/gdi32.spec
+++ b/if1632/gdi32.spec
@@ -37,7 +37,7 @@ type	win32
  33 stdcall CreateDCW(wstr wstr wstr ptr) CreateDC32W
  34 stdcall CreateDIBPatternBrush(long long) CreateDIBPatternBrush32
  35 stub CreateDIBPatternBrushPt
- 36 stdcall CreateDIBSection(long ptr long ptr long long) CreateDIBSection
+ 36 stdcall CreateDIBSection(long ptr long ptr long long) CreateDIBSection32
  37 stdcall CreateDIBitmap(long ptr long ptr ptr long) CreateDIBitmap32
  38 stdcall CreateDiscardableBitmap(long long long) CreateDiscardableBitmap32
  39 stdcall CreateEllipticRgn(long long long long) CreateEllipticRgn32
@@ -234,10 +234,10 @@ type	win32
 227 stdcall GetTextColor(long) GetTextColor32
 228 stdcall GetTextExtentExPointA(long str long long ptr ptr ptr) GetTextExtentExPoint32A
 229 stdcall GetTextExtentExPointW(long wstr long long ptr ptr ptr) GetTextExtentExPoint32W
-230 stdcall GetTextExtentPoint32A(long str long ptr) GetTextExtentPoint32A
-231 stdcall GetTextExtentPoint32W(long wstr long ptr) GetTextExtentPoint32W
-232 stdcall GetTextExtentPointA(long str long ptr) GetTextExtentPoint32ABuggy
-233 stdcall GetTextExtentPointW(long wstr long ptr) GetTextExtentPoint32WBuggy
+230 stdcall GetTextExtentPoint32A(long ptr long ptr) GetTextExtentPoint32A
+231 stdcall GetTextExtentPoint32W(long ptr long ptr) GetTextExtentPoint32W
+232 stdcall GetTextExtentPointA(long ptr long ptr) GetTextExtentPoint32ABuggy
+233 stdcall GetTextExtentPointW(long ptr long ptr) GetTextExtentPoint32WBuggy
 234 stdcall GetTextFaceA(long long ptr) GetTextFace32A
 235 stdcall GetTextFaceW(long long ptr) GetTextFace32W
 236 stdcall GetTextMetricsA(long ptr) GetTextMetrics32A
diff --git a/if1632/shell32.spec b/if1632/shell32.spec
index a064b46d92f..04d1ab79d61 100644
--- a/if1632/shell32.spec
+++ b/if1632/shell32.spec
@@ -5,12 +5,13 @@ type	win32
 # (these need to have these exact ordinals, for some win95 dlls 
 #  import shell32.dll by ordinal)
 
+   2 stub SHELL32_2
    3 stub CheckEscapesA
    6 stub CheckEscapesW
    7 stdcall CommandLineToArgvW(ptr ptr) CommandLineToArgvW
    8 stub Control_FillCache_RunDLL
   12 stdcall Control_RunDLL(long long long long) Control_RunDLL
-  14 stub DllGetClassObject
+  14 stdcall DllGetClassObject(long long ptr) SHELL32_DllGetClassObject
   22 stub DoEnvironmentSubstA
   33 stub SHELL32_33
   34 stub SHELL32_34
diff --git a/if1632/signal.c b/if1632/signal.c
index d5810d173e1..003e0627648 100644
--- a/if1632/signal.c
+++ b/if1632/signal.c
@@ -32,18 +32,6 @@
 #include "miscemu.h"
 #include "thread.h"
 
-/* Signal handler declaration */
-
-#ifdef linux
-# define HANDLER_DEF(name) void name (int signal, SIGCONTEXT context)
-# define HANDLER_CONTEXT (&context)
-#elif defined(__svr4__) || defined(_SCO_DS)
-# define HANDLER_DEF(name) void name(int signal, void *siginfo, SIGCONTEXT *context)
-# define HANDLER_CONTEXT context
-#else
-# define HANDLER_DEF(name) void name(int signal, int code, SIGCONTEXT *context)
-# define HANDLER_CONTEXT context
-#endif
 
 extern void SIGNAL_SetHandler( int sig, void (*func)(), int flags );
 extern BOOL32 INSTR_EmulateInstruction( SIGCONTEXT *context );
@@ -80,7 +68,9 @@ static HANDLER_DEF(SIGNAL_trap)
  */
 static HANDLER_DEF(SIGNAL_fault)
 {
-    if (CS_sig(HANDLER_CONTEXT) == WINE_CODE_SELECTOR)
+    WORD cs;
+    GET_CS(cs);
+    if (CS_sig(HANDLER_CONTEXT) == cs)
     {
         fprintf( stderr, "Segmentation fault in 32-bit code (0x%08lx).\n",
                  EIP_sig(HANDLER_CONTEXT) );
@@ -120,13 +110,13 @@ static void SIGNAL_SetSigContext( const SIGCONTEXT *sigcontext,
 #ifdef FS_sig
     FS_reg(context)  = LOWORD(FS_sig(sigcontext));
 #else
-    __asm__("movw %%fs,%w0":"=r" (FS_reg(&DEBUG_context)));
+    GET_FS( FS_reg(&DEBUG_context) );
     FS_reg(context) &= 0xffff;
 #endif
 #ifdef GS_sig
     GS_reg(context)  = LOWORD(GS_sig(sigcontext));
 #else
-    __asm__("movw %%gs,%w0":"=r" (GS_reg(&DEBUG_context)));
+    GET_GS( GS_reg(&DEBUG_context) );
     GS_reg(context) &= 0xffff;
 #endif
 }
@@ -157,12 +147,12 @@ static void SIGNAL_GetSigContext( SIGCONTEXT *sigcontext,
 #ifdef FS_sig
     FS_sig(sigcontext)  = FS_reg(context);
 #else
-    __asm__("movw %w0,%%fs"::"r" (FS_reg(context)));
+    SET_FS( FS_reg(&DEBUG_context) );
 #endif
 #ifdef GS_sig
     GS_sig(sigcontext)  = GS_reg(context);
 #else
-    __asm__("movw %w0,%%gs"::"r" (GS_reg(context)));
+    SET_GS( GS_reg(&DEBUG_context) );
 #endif
 }
 
diff --git a/if1632/thunk.c b/if1632/thunk.c
index 0502f28f176..4a9a446987c 100644
--- a/if1632/thunk.c
+++ b/if1632/thunk.c
@@ -93,11 +93,14 @@ static void WINAPI THUNK_CallTaskReschedule(void);
 /* TASK_Reschedule() 16-bit entry point */
 static FARPROC16 TASK_RescheduleProc;
 
+extern void CallFrom16_long_wwwll(void);
+
 /* Callbacks function table for the emulator */
 static const CALLBACKS_TABLE CALLBACK_EmulatorTable =
 {
     (void *)CallTo16_regs_short,           /* CallRegisterProc */
     THUNK_CallTaskReschedule,              /* CallTaskRescheduleProc */
+    CallFrom16_long_wwwll,                 /* CallFrom16WndProc */
     THUNK_CallWndProc16,                   /* CallWndProc */
     (void *)CallTo16_long_lwwll,           /* CallDriverProc */
     (void *)CallTo16_word_wwlll,           /* CallDriverCallback */
@@ -209,16 +212,32 @@ static LRESULT WINAPI THUNK_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
     EBP_reg(&context) = OFFSETOF(IF1632_Saved16_ss_sp)
                         + (WORD)&((STACK16FRAME*)0)->bp;
 
-    if (((msg == WM_CREATE) || (msg == WM_NCCREATE)) && lParam)
+    if (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.  */
-        CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
-        offset = sizeof(*cs);
-        lParam = STACK16_PUSH( offset );
-        memcpy( PTR_SEG_TO_LIN(lParam), cs, offset );
+	/* Some programs (eg. the "Undocumented Windows" examples, JWP) only
+           work if structures passed in lParam are placed in the stack/data
+           segment. Programmers easily make the mistake of converting lParam
+           to a near rather than a far pointer, since Windows apparently
+           allows this. We copy the structures to the 16 bit stack; this is
+           ugly but makes these programs work. */
+	switch (msg)
+	{
+	  case WM_CREATE:
+	  case WM_NCCREATE:
+	    offset = sizeof(CREATESTRUCT16); break;
+	  case WM_DRAWITEM:
+	    offset = sizeof(DRAWITEMSTRUCT16); break;
+	  case WM_COMPAREITEM:
+	    offset = sizeof(COMPAREITEMSTRUCT16); break;
+	}
+	if (offset)
+	{
+	    void *s = PTR_SEG_TO_LIN(lParam);
+	    lParam = STACK16_PUSH( offset );
+	    memcpy( PTR_SEG_TO_LIN(lParam), s, offset );
+	}
     }
+
     args = (WORD *)CURRENT_STACK16 - 7;
     args[0] = LOWORD(lParam);
     args[1] = HIWORD(lParam);
diff --git a/if1632/user.spec b/if1632/user.spec
index dd58ec909dc..521deb9cf0b 100644
--- a/if1632/user.spec
+++ b/if1632/user.spec
@@ -348,7 +348,7 @@ file	user.exe
 389 stub LoadImage
 390 stub CopyImage
 391 stub SignalProc32
-394 stub DrawIconEx
+394 pascal16 DrawIconEx(word word word word word word word word word) DrawIconEx16
 395 stub GetIconInfo
 397 pascal16 RegisterClassEx(ptr) RegisterClassEx16
 398 pascal16 GetClassInfoEx(word segstr ptr) GetClassInfoEx16
@@ -491,7 +491,7 @@ file	user.exe
 662 stub DrawMenubarTemp
 663 stub GetMenuDefaultItem
 664 stub SetMenuDefaultItem
-665 stub GetMenuItemRect
+665 pascal16 GetMenuItemRect(word word word ptr) GetMenuItemRect16
 666 stub CheckMenuRadioItem
 667 stub TrackPopupMenuEx
 668 stub SetWindowRgn
diff --git a/if1632/user32.spec b/if1632/user32.spec
index b6f321b321f..91782b65c98 100644
--- a/if1632/user32.spec
+++ b/if1632/user32.spec
@@ -47,7 +47,7 @@ type	win32
  44 stdcall CharUpperW(wstr) CharUpper32W
  45 stdcall CheckDlgButton(long long long) CheckDlgButton32
  46 stdcall CheckMenuItem(long long long) CheckMenuItem32
- 47 stub CheckMenuRadioItem
+ 47 stdcall CheckMenuRadioItem(long long long long long) CheckMenuRadioItem32
  48 stdcall CheckRadioButton(long long long long) CheckRadioButton32
  49 stdcall ChildWindowFromPoint(long long long) ChildWindowFromPoint32
  50 stub ChildWindowFromPointEx
@@ -58,8 +58,8 @@ type	win32
  55 stub CloseDesktop
  56 stdcall CloseWindow(long) CloseWindow32
  57 stub CloseWindowStation
- 58 stub CopyAcceleratorTableA
- 59 stub CopyAcceleratorTableW
+ 58 stdcall CopyAcceleratorTableA(long ptr long) CopyAcceleratorTable32A
+ 59 stdcall CopyAcceleratorTableW(long ptr long) CopyAcceleratorTable32W
  60 stdcall CopyIcon(long) CopyIcon32
  61 stdcall CopyImage(long long long long long) CopyImage32
  62 stdcall CopyRect(ptr ptr) CopyRect32
@@ -132,7 +132,7 @@ type	win32
 127 stdcall DefWindowProcW(long long long long) DefWindowProc32W
 128 stdcall DeferWindowPos(long long long long long long long long) DeferWindowPos32
 129 stdcall DeleteMenu(long long long) DeleteMenu32
-130 stub DestroyAcceleratorTable
+130 stdcall DestroyAcceleratorTable(long) DestroyAcceleratorTable
 131 stdcall DestroyCaret() DestroyCaret32
 132 stdcall DestroyCursor(long) DestroyCursor32
 133 stdcall DestroyIcon(long) DestroyIcon32
@@ -162,7 +162,7 @@ type	win32
 157 stub DrawFrame
 158 stdcall DrawFrameControl(long ptr long long) DrawFrameControl32
 159 stdcall DrawIcon(long long long long) DrawIcon32
-160 stub DrawIconEx
+160 stdcall DrawIconEx(long long long long long long long long long) DrawIconEx32
 161 stdcall DrawMenuBar(long) DrawMenuBar32
 162 stdcall DrawStateA(long long ptr long long long long long long long) DrawState32A
 163 stub DrawStateW
@@ -268,7 +268,7 @@ type	win32
 263 stdcall GetMenuItemID(long long) GetMenuItemID32
 264 stdcall GetMenuItemInfoA(long long long ptr) GetMenuItemInfo32A
 265 stdcall GetMenuItemInfoW(long long long ptr) GetMenuItemInfo32W
-266 stub GetMenuItemRect
+266 stdcall GetMenuItemRect(long long long ptr) GetMenuItemRect32
 267 stdcall GetMenuState(long long long) GetMenuState32
 268 stdcall GetMenuStringA(long long ptr long long) GetMenuString32A
 269 stdcall GetMenuStringW(long long ptr long long) GetMenuString32W
diff --git a/if1632/wprocs.spec b/if1632/wprocs.spec
index 351c974f679..f73a118a34b 100644
--- a/if1632/wprocs.spec
+++ b/if1632/wprocs.spec
@@ -1,7 +1,6 @@
 name	wprocs
 type	win16
 
-10 pascal MDIClientWndProc(word word word long) MDIClientWndProc
 14 pascal FileOpenDlgProc(word word word long) FileOpenDlgProc
 15 pascal FileSaveDlgProc(word word word long) FileSaveDlgProc
 16 pascal ColorDlgProc(word word word long) ColorDlgProc
diff --git a/include/accel.h b/include/accel.h
deleted file mode 100644
index e9b3be87453..00000000000
--- a/include/accel.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * structure definitions for ACCELERATORS
- *
- * taken straight from Win32 SDK includes
- */
-
-#ifndef __WINE_ACCEL_H
-#define __WINE_ACCEL_H
-
-#include "windows.h"
-
-#pragma pack(1)
-
-#define	FVIRTKEY	TRUE          /* Assumed to be == TRUE */
-#define	FNOINVERT	0x02
-#define	FSHIFT		0x04
-#define	FCONTROL	0x08
-#define	FALT		0x10
-
-typedef struct tagACCEL16 {
-	BYTE	fVirt;		/* Also called the flags field */
-	WORD	key;
-	WORD	cmd;
-} ACCEL16, *LPACCEL16;
-
-typedef struct tagACCEL32 {
-	BYTE	fVirt;		/* Also called the flags field */
-	BYTE	pad0;
-	WORD	key;
-	WORD	cmd;
-	WORD	pad1;
-} ACCEL32, *LPACCEL32;
-
-#pragma pack(4)
-
-#endif  /* __WINE_ACCEL_H */
diff --git a/include/bitmaps/obm_radiocheck b/include/bitmaps/obm_radiocheck
new file mode 100644
index 00000000000..e2cc4e8d667
--- /dev/null
+++ b/include/bitmaps/obm_radiocheck
@@ -0,0 +1,23 @@
+/* XPM */
+static char *obm_radiocheck[] = {
+/* size */
+"14 14 2 1",
+/* colors */
+".	s white	c white",
+"#	s black	c black",
+/* pixels */
+"..............",
+"..............",
+"..............",
+".....####.....",
+"....######....",
+"...########...",
+"...########...",
+"...########...",
+"...########...",
+"....######....",
+".....####.....",
+"..............",
+"..............",
+".............."
+};
diff --git a/include/bitmaps/ocr_ibeam b/include/bitmaps/ocr_ibeam
index 5f77564b15b..e372a1eab6a 100644
--- a/include/bitmaps/ocr_ibeam
+++ b/include/bitmaps/ocr_ibeam
@@ -1,6 +1,6 @@
 /* XPM */
 static char * ocr_ibeam[] = {
-"32 32 2 1 0 8",
+"32 32 2 1 3 8",
 " 	s black c black",
 ".	s None	c None",
 "   .   .........................",
diff --git a/include/callback.h b/include/callback.h
index cbb235e7236..86b604f004f 100644
--- a/include/callback.h
+++ b/include/callback.h
@@ -21,6 +21,7 @@ typedef struct
 {
     VOID (CALLBACK *CallRegisterProc)( CONTEXT *, INT32 );
     VOID (CALLBACK *CallTaskRescheduleProc)(void);
+    VOID (CALLBACK *CallFrom16WndProc)(void);
     LRESULT (CALLBACK *CallWndProc)( WNDPROC16, HWND16, UINT16,
                                      WPARAM16, LPARAM );
     LRESULT (CALLBACK *CallDriverProc)( DRIVERPROC16, DWORD, HDRVR16,
diff --git a/include/clipboard.h b/include/clipboard.h
index d0070df18b2..69ef1d73550 100644
--- a/include/clipboard.h
+++ b/include/clipboard.h
@@ -1,9 +1,10 @@
 #ifndef __WINE_CLIPBOARD_H
 #define __WINE_CLIPBOARD_H
 
-void CLIPBOARD_ReadSelection(Window w,Atom prop);
-void CLIPBOARD_ReleaseSelection(Window w,HWND32 hwnd);
-void CLIPBOARD_DisOwn(WND* pWnd);
+void CLIPBOARD_ResetLock(HQUEUE16 hqRef, HQUEUE16 hqNew);
+void CLIPBOARD_ResetOwner(WND* pWnd);
+void CLIPBOARD_ReadSelection(Window w, Atom prop);
+void CLIPBOARD_ReleaseSelection(Window w, HWND32 hwnd);
 BOOL32 CLIPBOARD_IsPresent(WORD wFormat);
 
 #endif /* __WINE_CLIPBOARD_H */
diff --git a/include/dce.h b/include/dce.h
index 9718df6ad4c..11d235ff304 100644
--- a/include/dce.h
+++ b/include/dce.h
@@ -52,6 +52,6 @@ extern DCE*  DCE_FreeDCE( DCE *dce );
 extern void  DCE_FreeWindowDCE( WND* );
 extern INT16 DCE_ExcludeRgn( HDC32, WND*, HRGN32 );
 extern HRGN32 DCE_GetVisRgn( HWND32, WORD );
-extern BOOL32 DCE_InvalidateDCE( WND*, RECT32* );
+extern BOOL32 DCE_InvalidateDCE( WND*, const RECT32* );
 
 #endif  /* __WINE_DCE_H */
diff --git a/include/ddeml.h b/include/ddeml.h
index d2d4d11be6d..845a58b7d20 100644
--- a/include/ddeml.h
+++ b/include/ddeml.h
@@ -2,6 +2,7 @@
  * DDEML library definitions
  *
  * Copyright 1997 Alexandre Julliard
+ * Copyright 1997 Len White
  */
 
 #ifndef __WINE__DDEML_H
@@ -50,12 +51,17 @@ UINT32    WINAPI DdeInitialize32W(LPDWORD,PFNCALLBACK32,DWORD,DWORD);
 BOOL16    WINAPI DdeUninitialize16(DWORD);
 BOOL32    WINAPI DdeUninitialize32(DWORD);
 #define   DdeUninitialize WINELIB_NAME(DdeUninitialize)
+HCONVLIST WINAPI DdeConnectList(DWORD,HSZ,HSZ,HCONVLIST,LPCONVCONTEXT16);
+HCONV     WINAPI DdeQueryNextServer(HCONVLIST, HCONV);
+BOOL16    WINAPI DdeDisconnectList(HCONVLIST);
 HCONV     WINAPI DdeConnect16(DWORD,HSZ,HSZ,LPCONVCONTEXT16);
 HCONV     WINAPI DdeConnect32(DWORD,HSZ,HSZ,LPCONVCONTEXT32);
 #define   DdeConnect WINELIB_NAME(DdeConnect)
 BOOL16    WINAPI DdeDisconnect16(HCONV);
 BOOL32    WINAPI DdeDisconnect32(HCONV);
 #define   DdeDisconnect WINELIB_NAME(DdeDisconnect)
+BOOL16    WINAPI DdeSetUserHandle(HCONV,DWORD,DWORD);
+HDDEDATA  WINAPI DdeCreateHandleData(DWORD,LPBYTE,DWORD,DWORD,HSZ,UINT16,UINT16);
 HCONV     WINAPI DdeReconnect(HCONV);
 HSZ       WINAPI DdeCreateStringHandle16(DWORD,LPCSTR,INT16);
 HSZ       WINAPI DdeCreateStringHandle32A(DWORD,LPCSTR,INT32);
@@ -75,6 +81,16 @@ HDDEDATA  WINAPI DdeClientTransaction16(LPVOID,DWORD,HCONV,HSZ,UINT16,
 HDDEDATA  WINAPI DdeClientTransaction32(LPBYTE,DWORD,HCONV,HSZ,UINT32,
                                         UINT32,DWORD,LPDWORD);
 #define   DdeClientTransaction WINELIB_NAME(DdeClientTransaction)
+BOOL16    WINAPI DdeAbandonTransaction(DWORD,HCONV,DWORD);
+BOOL16    WINAPI DdePostAdvise(DWORD,HSZ,HSZ);
+HDDEDATA  WINAPI DdeAddData(HDDEDATA,LPBYTE,DWORD,DWORD);
+DWORD     WINAPI DdeGetData(HDDEDATA,LPBYTE,DWORD,DWORD);
+LPBYTE    WINAPI DdeAccessData(HDDEDATA,LPDWORD);
+BOOL16    WINAPI DdeUnaccessData(HDDEDATA);
+BOOL16    WINAPI DdeEnableCallback(DWORD,HCONV,UINT16);
+int       WINAPI DdeCmpStringHandles(HSZ,HSZ);
+
+
 HDDEDATA  WINAPI DdeNameService16(DWORD,HSZ,HSZ,UINT16);
 HDDEDATA  WINAPI DdeNameService32(DWORD,HSZ,HSZ,UINT32);
 #define   DdeNameService WINELIB_NAME(DdeNameService)
diff --git a/include/debugger.h b/include/debugger.h
index 2d7d0253bfe..b872b3c4d13 100644
--- a/include/debugger.h
+++ b/include/debugger.h
@@ -86,9 +86,9 @@ typedef struct wine_locals WineLocals;
 
 
 #define DBG_FIX_ADDR_SEG(addr,default) \
-    { if ((addr)->seg == 0xffffffff) (addr)->seg = (default); \
-      if (((addr)->seg == WINE_CODE_SELECTOR) || \
-           (addr)->seg == WINE_DATA_SELECTOR) (addr)->seg = 0; }
+    { WORD cs, ds; GET_CS(cs); GET_DS(ds); \
+      if ((addr)->seg == 0xffffffff) (addr)->seg = (default); \
+      if (((addr)->seg == cs) || (addr)->seg == ds) (addr)->seg = 0; }
 
 #define DBG_ADDR_TO_LIN(addr) \
     ((addr)->seg ? (char *)PTR_SEG_OFF_TO_LIN((addr)->seg,(addr)->off) \
@@ -266,8 +266,8 @@ extern int  DEBUG_GetCurrentFrame(struct name_hash ** name,
 extern int DEBUG_ReadExecutableDbgInfo(void);
 
   /* debugger/msc.c */
-extern int DEBUG_RegisterDebugInfo(struct pe_data *pe,
-				   int, unsigned long, unsigned long);
+extern int DEBUG_RegisterDebugInfo(struct pe_data *pe, int, const char *,
+				   unsigned long, unsigned long);
 extern int DEBUG_ProcessDeferredDebug(void);
 extern int DEBUG_RegisterELFDebugInfo(int load_addr, u_long size, char * name);
 extern void DEBUG_InfoShare(void);
diff --git a/include/debugstr.h b/include/debugstr.h
new file mode 100644
index 00000000000..20ac865c48a
--- /dev/null
+++ b/include/debugstr.h
@@ -0,0 +1,15 @@
+#ifndef __WINE_DEBUGSTR_H
+#define __WINE_DEBUGSTR_H
+
+#include "wintypes.h"
+
+/* These function return a printable version of a string, including
+   quotes.  The string will be valid for some time, but not indefinitely
+   as strings are re-used.  */
+
+LPSTR debugstr_an (LPCSTR s, int n);
+LPSTR debugstr_a (LPCSTR s);
+LPSTR debugstr_wn (LPCWSTR s, int n);
+LPSTR debugstr_w (LPCWSTR s);
+
+#endif /* __WINE_DEBUGSTR_H */
diff --git a/include/gdi.h b/include/gdi.h
index 4f2c4e1aed9..d744a415302 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -318,6 +318,5 @@ extern Display * display;
 extern Screen * screen;
 extern Window rootWindow;
 extern int screenWidth, screenHeight, screenDepth;
-extern int desktopX, desktopY;   /* misc/main.c */
 
 #endif  /* __WINE_GDI_H */
diff --git a/include/keyboard.h b/include/keyboard.h
index 9465e3caaad..230927334bf 100644
--- a/include/keyboard.h
+++ b/include/keyboard.h
@@ -14,6 +14,6 @@ extern BYTE QueueKeyStateTable[256];
 extern BYTE AsyncKeyStateTable[256];
 
 extern BOOL32 KEYBOARD_Init(void);
-extern void KEYBOARD_HandleEvent( XKeyEvent *event );
+extern void KEYBOARD_HandleEvent( WND *pWnd, XKeyEvent *event );
 
 #endif  /* __WINE_KEYBOARD_H */
diff --git a/include/mdi.h b/include/mdi.h
index 38e58721282..d6f6a0920d7 100644
--- a/include/mdi.h
+++ b/include/mdi.h
@@ -20,21 +20,21 @@
 
 #define WM_MDICALCCHILDSCROLL   0x10AC /* this is exactly what Windows uses */
 
-extern LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, 
-                                       WPARAM16 wParam, LPARAM lParam);
+extern LRESULT WINAPI MDIClientWndProc( HWND32 hwnd, UINT32 message, 
+                                        WPARAM32 wParam, LPARAM lParam );
 
 typedef struct 
 {
-    UINT16   	nActiveChildren;
-    HWND16   	hwndChildMaximized;
-    HWND16   	hwndActiveChild;
-    HMENU16  	hWindowMenu;
-    UINT32   	idFirstChild;
-    LPSTR 	frameTitle;
-    UINT16	nTotalCreated;
-    UINT16   	mdiFlags;
-    UINT16   	sbRecalc;		/* SB_xxx flags for scrollbar fixup */
-    HWND16   	self;
+    UINT32      nActiveChildren;
+    HWND32      hwndChildMaximized;
+    HWND32      hwndActiveChild;
+    HMENU32     hWindowMenu;
+    UINT32      idFirstChild;
+    LPSTR       frameTitle;
+    UINT32      nTotalCreated;
+    UINT32      mdiFlags;
+    UINT32      sbRecalc;   /* SB_xxx flags for scrollbar fixup */
+    HWND32      self;
 } MDICLIENTINFO;
 
 #endif /* __WINE_MDI_H */
diff --git a/include/mmsystem.h b/include/mmsystem.h
index dce9cb006be..fa5a50b7ad4 100644
--- a/include/mmsystem.h
+++ b/include/mmsystem.h
@@ -26,7 +26,7 @@ typedef UINT32	MMVERSION32;
 DECL_WINELIB_TYPE(MMVERSION);
 typedef UINT16	MCIDEVICEID16;
 typedef UINT32	MCIDEVICEID32;
-DECL_WINELIB_TYPE(MCIDEVICE);
+DECL_WINELIB_TYPE(MCIDEVICEID);
 
 typedef struct {
     UINT16    wType;		/* indicates the contents of the union */
@@ -257,8 +257,8 @@ typedef struct {
     WORD	wReserved1;		/* padding */
     DWORD	dwSupport;		/* functionality supported by driver */
 } WAVEOUTCAPS32W, *LPWAVEOUTCAPS32W;
-DECL_WINELIB_TYPE(WAVEOUTCAPS);
-DECL_WINELIB_TYPE(LPWAVEOUTCAPS);
+DECL_WINELIB_TYPE_AW(WAVEOUTCAPS);
+DECL_WINELIB_TYPE_AW(LPWAVEOUTCAPS);
 
 #define WAVECAPS_PITCH          0x0001   /* supports pitch control */
 #define WAVECAPS_PLAYBACKRATE   0x0002   /* supports playback rate control */
@@ -293,8 +293,8 @@ typedef struct {
     WORD	wChannels;		/* number of channels supported */
     WORD	wReserved1;
 } WAVEINCAPS32W, *LPWAVEINCAPS32W;
-DECL_WINELIB_TYPE(WAVEINCAPS);
-DECL_WINELIB_TYPE(LPWAVEINCAPS);
+DECL_WINELIB_TYPE_AW(WAVEINCAPS);
+DECL_WINELIB_TYPE_AW(LPWAVEINCAPS);
 
 #define WAVE_INVALIDFORMAT     0x00000000       /* invalid format */
 #define WAVE_FORMAT_1M08       0x00000001       /* 11.025 kHz, Mono,   8-bit  */
@@ -1181,8 +1181,8 @@ typedef struct {
     WCHAR	szName[MIXER_LONG_NAME_CHARS];
 } MIXERCONTROLDETAILS_LISTTEXT32W,*LPMIXERCONTROLDETAILS_LISTTEXT32W;
 
-DECL_WINELIB_TYPE_AW(MIXERCONTROLDETAILS);
-DECL_WINELIB_TYPE_AW(LPMIXERCONTROLDETAILS);
+DECL_WINELIB_TYPE_AW(MIXERCONTROLDETAILS_LISTTEXT);
+DECL_WINELIB_TYPE_AW(LPMIXERCONTROLDETAILS_LISTTEXT);
 
 /*  MIXER_GETCONTROLDETAILSF_VALUE */
 typedef struct {
@@ -1773,8 +1773,8 @@ typedef struct {
 	DWORD   dwRetSize;
 } MCI_INFO_PARMS32W, *LPMCI_INFO_PARMS32W;
 
-DECL_WINELIB_TYPE(MCI_INFO_PARMS);
-DECL_WINELIB_TYPE(LPMCI_INFO_PARMS);
+DECL_WINELIB_TYPE_AW(MCI_INFO_PARMS);
+DECL_WINELIB_TYPE_AW(LPMCI_INFO_PARMS);
 
 typedef struct {
 	DWORD   dwCallback;
@@ -1858,8 +1858,8 @@ typedef struct {
 	LPCWSTR	lpfilename;
 } MCI_LOAD_PARMS32W, *LPMCI_LOAD_PARMS32W;
 
-DECL_WINELIB_TYPE(MCI_LOAD_PARMS);
-DECL_WINELIB_TYPE(LPMCI_LOAD_PARMS);
+DECL_WINELIB_TYPE_AW(MCI_LOAD_PARMS);
+DECL_WINELIB_TYPE_AW(LPMCI_LOAD_PARMS);
 
 typedef struct {
 	DWORD   dwCallback;
@@ -1932,8 +1932,8 @@ typedef struct {
 	LPCWSTR	lpstrCommand;
 } MCI_VD_ESCAPE_PARMS32W, *LPMCI_VD_ESCAPE_PARMS32W;
 
-DECL_WINELIB_TYPE(MCI_VD_ESCAPE_PARMS);
-DECL_WINELIB_TYPE(LPMCI_VD_ESCAPE_PARMS);
+DECL_WINELIB_TYPE_AW(MCI_VD_ESCAPE_PARMS);
+DECL_WINELIB_TYPE_AW(LPMCI_VD_ESCAPE_PARMS);
 
 #define MCI_WAVE_OPEN_BUFFER            0x00010000L
 
@@ -2190,8 +2190,8 @@ typedef struct {
 	LPCWSTR	lpstrText;
 } MCI_ANIM_WINDOW_PARMS32W, *LPMCI_ANIM_WINDOW_PARMS32W;
 
-DECL_WINELIB_TYPE(MCI_ANIM_WINDOW_PARMS);
-DECL_WINELIB_TYPE(LPMCI_ANIM_WINDOW_PARMS);
+DECL_WINELIB_TYPE_AW(MCI_ANIM_WINDOW_PARMS);
+DECL_WINELIB_TYPE_AW(LPMCI_ANIM_WINDOW_PARMS);
 
 typedef struct {
 	DWORD   dwCallback;
@@ -2320,8 +2320,8 @@ typedef struct {
 	LPCWSTR	lpstrText;
 } MCI_OVLY_WINDOW_PARMS32W, *LPMCI_OVLY_WINDOW_PARMS32W;
 
-DECL_WINELIB_TYPE_AW(MCI_OVLY_OPEN_WINDOW_PARMS);
-DECL_WINELIB_TYPE_AW(LPMCI_OVLY_OPEN_WINDOW_PARMS);
+DECL_WINELIB_TYPE_AW(MCI_OVLY_WINDOW_PARMS);
+DECL_WINELIB_TYPE_AW(LPMCI_OVLY_WINDOW_PARMS);
 
 typedef struct {
 	DWORD   dwCallback;
diff --git a/include/module.h b/include/module.h
index 5b7cb2ba955..4abfc6144be 100644
--- a/include/module.h
+++ b/include/module.h
@@ -142,7 +142,9 @@ extern BOOL32 BUILTIN_ParseDLLOptions( const char *str );
 extern void BUILTIN_PrintDLLs(void);
 
 /* ne_image.c */
-extern BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum );
+extern BOOL32 NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
+extern BOOL32 NE_LoadAllSegments( NE_MODULE *pModule );
+extern BOOL32 NE_LoadDLLs( NE_MODULE *pModule );
 extern void NE_FixupPrologs( NE_MODULE *pModule );
 extern void NE_InitializeDLLs( HMODULE16 hModule );
 
diff --git a/include/msdos.h b/include/msdos.h
index 1cc09b1ad57..9a9017aac69 100644
--- a/include/msdos.h
+++ b/include/msdos.h
@@ -5,6 +5,7 @@
 #include <dirent.h>
 #include "windows.h"
 #include "comm.h"
+#include "winnt.h"
 
 struct fcb {
         BYTE drive;
@@ -55,8 +56,6 @@ typedef struct
     DWORD  filesize;             /* 1c file size */
 } DOS_DIRENTRY_LAYOUT;
 
-#define WINVERSION 0x0a03      /* Windows version 3.10 */
-
 #define MAX_DOS_DRIVES	26
 
 extern struct DosDeviceStruct COM[MAX_PORTS];
@@ -157,4 +156,7 @@ extern BYTE DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus;
 #define EL_Serial            0x04
 #define EL_Memory            0x05
 
+void WINAPI DOS3Call( CONTEXT *context );
+void do_mscdex( CONTEXT *context );
+
 #endif /* __WINE_MSDOS_H */
diff --git a/include/nonclient.h b/include/nonclient.h
index 8b5b60027fd..2bc595adf6d 100644
--- a/include/nonclient.h
+++ b/include/nonclient.h
@@ -13,8 +13,7 @@ extern LONG NC_HandleNCPaint( HWND32 hwnd , HRGN32 clip);
 extern LONG NC_HandleNCActivate( WND *pwnd, WPARAM16 wParam );
 extern LONG NC_HandleNCCalcSize( WND *pWnd, RECT32 *winRect );
 extern LONG NC_HandleNCHitTest( HWND32 hwnd, POINT16 pt );
-extern LONG NC_HandleNCLButtonDown( HWND32 hwnd, WPARAM16 wParam,
-                                    LPARAM lParam );
+extern LONG NC_HandleNCLButtonDown( WND* pWnd, WPARAM16 wParam, LPARAM lParam );
 extern LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam);
 extern LONG NC_HandleSysCommand( HWND32 hwnd, WPARAM16 wParam, POINT16 pt );
 extern LONG NC_HandleSetCursor( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam );
diff --git a/include/options.h b/include/options.h
index ba48841a544..c68158e98c0 100644
--- a/include/options.h
+++ b/include/options.h
@@ -48,6 +48,7 @@ struct options
     char * desktopGeometry; /* NULL when no desktop */
     char * programName;     /* To use when loading resources */
     char * argv0;           /* argv[0] of Wine process */
+    char  *dllFlags;        /* -dll flags (hack for Winelib support) */
     int    usePrivateMap;
     int    useFixedMap;
     int    synchronous;     /* X synchronous mode */
@@ -81,4 +82,7 @@ extern int PROFILE_GetWineIniBool( char const *section, char const *key_name,
 				   int def );
 extern char* PROFILE_GetStringItem( char* );
 
+/* Version functions */
+extern void VERSION_ParseVersion( char *arg );
+
 #endif  /* __WINE_OPTIONS_H */
diff --git a/include/selectors.h b/include/selectors.h
index 7fcde5ec98c..8ca897f355e 100644
--- a/include/selectors.h
+++ b/include/selectors.h
@@ -7,7 +7,7 @@
 #ifndef __WINE_SELECTORS_H
 #define __WINE_SELECTORS_H
 
-#include "windows.h"
+#include "wintypes.h"
 #include "ldt.h"
 
 extern WORD SELECTOR_AllocBlock( const void *base, DWORD size,
@@ -18,24 +18,26 @@ extern WORD SELECTOR_ReallocBlock( WORD sel, const void *base, DWORD size,
                                    BOOL32 readonly );
 extern void SELECTOR_FreeBlock( WORD sel, WORD count );
 
-#if defined(linux)
-# define WINE_DATA_SELECTOR 0x2b
-# define WINE_CODE_SELECTOR 0x23
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-# define WINE_DATA_SELECTOR 0x1f
-# define WINE_CODE_SELECTOR 0x17
-#elif defined(__FreeBSD__)
-# define WINE_DATA_SELECTOR 0x27
-# define WINE_CODE_SELECTOR 0x1f
-#elif defined(__svr4__) || defined(_SCO_DS)
-# define WINE_DATA_SELECTOR 0x1f
-# define WINE_CODE_SELECTOR 0x17
-#elif defined(__EMX__)
-# define WINE_DATA_SELECTOR 0x53 /* Is this always true? */
-# define WINE_CODE_SELECTOR 0x5b
-#else
-# define WINE_DATA_SELECTOR 0x00
-# define WINE_CODE_SELECTOR 0x00
-#endif
+#ifdef __i386__
+# define __GET_SEG(seg,res) __asm__( "movw %%" seg ",%w0" : "=r" (res) )
+# define __SET_SEG(seg,val) __asm__( "movw %w0,%%" seg : : "r" (val) )
+#else  /* __i386__ */
+# define __GET_SEG(seg,res) ((res) = 0)
+# define __SET_SEG(seg,val) /* nothing */
+#endif  /* __i386__ */
+
+#define GET_CS(cs) __GET_SEG("cs",cs)
+#define GET_DS(ds) __GET_SEG("ds",ds)
+#define GET_ES(es) __GET_SEG("es",es)
+#define GET_FS(fs) __GET_SEG("fs",fs)
+#define GET_GS(gs) __GET_SEG("gs",gs)
+#define GET_SS(ss) __GET_SEG("ss",ss)
+
+#define SET_CS(cs) __SET_SEG("cs",cs)
+#define SET_DS(ds) __SET_SEG("ds",ds)
+#define SET_ES(es) __SET_SEG("es",es)
+#define SET_FS(fs) __SET_SEG("fs",fs)
+#define SET_GS(gs) __SET_SEG("gs",gs)
+#define SET_SS(ss) __SET_SEG("ss",ss)
 
 #endif /* __WINE_SELECTORS_H */
diff --git a/include/sig_context.h b/include/sig_context.h
index b971b9797ba..0e7b01ef42a 100644
--- a/include/sig_context.h
+++ b/include/sig_context.h
@@ -7,9 +7,7 @@
 #ifndef __WINE_SIG_CONTEXT_H
 #define __WINE_SIG_CONTEXT_H
 
-#ifdef WINELIB
-#error This file must not be used in Winelib
-#endif
+#ifdef __i386__
 
 #ifdef linux
 typedef struct
@@ -37,20 +35,34 @@ typedef struct
     unsigned long oldmask;
     unsigned long cr2;
 } SIGCONTEXT;
+
+#define HANDLER_DEF(name) void name (int signal, SIGCONTEXT context)
+#define HANDLER_CONTEXT (&context)
+
 #endif  /* linux */
 
 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+
 #include <signal.h>
 typedef struct sigcontext SIGCONTEXT;
+
+#define HANDLER_DEF(name) void name(int signal, int code, SIGCONTEXT *context)
+#define HANDLER_CONTEXT context
+
 #endif  /* FreeBSD */
 
 #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 HANDLER_DEF(name) void name(int signal, void *siginfo, SIGCONTEXT *context)
+#define HANDLER_CONTEXT context
+
 #endif  /* svr4 || SCO_DS */
 
 #ifdef __EMX__
@@ -202,4 +214,6 @@ typedef struct _CONTEXT		/* Note 1 */
                             
 #define FL_sig(context)      (*(WORD*)&EFL_sig(context))
 
+#endif /* __i386__ */
+
 #endif /* __WINE_SIG_CONTEXT_H */
diff --git a/include/version.h b/include/version.h
new file mode 100644
index 00000000000..0bf94c8aecd
--- /dev/null
+++ b/include/version.h
@@ -0,0 +1 @@
+#define WINE_RELEASE_INFO "Wine release 971116"
diff --git a/include/win.h b/include/win.h
index 128a20fe528..07dd3b24315 100644
--- a/include/win.h
+++ b/include/win.h
@@ -39,6 +39,7 @@ typedef enum
     BIC32_POPUPMENU,
     BIC32_STATIC,
     BIC32_SCROLL,
+    BIC32_MDICLIENT,
     BIC32_DESKTOP,
     BIC32_DIALOG,
     BIC32_ICONTITLE,
@@ -127,7 +128,8 @@ extern BOOL32 WIN_IsWindowDrawable(WND*, BOOL32 );
 extern HINSTANCE32 WIN_GetWindowInstance( HWND32 hwnd );
 extern WND**  WIN_BuildWinArray( WND *wndPtr, UINT32 bwa, UINT32* pnum );
 
-extern void DEFWND_SetText( WND *wndPtr, LPCSTR text );		      /* windows/defwnd.c */
+extern void DEFWND_SetText( WND *wndPtr, LPCSTR text );
+extern HBRUSH32 DEFWND_ControlColor( HDC32 hDC, UINT16 ctlType );     /* windows/defwnd.c */
 
 extern void PROPERTY_RemoveWindowProps( WND *pWnd );  		      /* windows/property.c */
 
diff --git a/include/win16drv.h b/include/win16drv.h
index 62d9d7f8bab..d219358733c 100644
--- a/include/win16drv.h
+++ b/include/win16drv.h
@@ -149,10 +149,10 @@ typedef struct WINE_ENUM_PRINTER_FONT_CALLBACK
     LOADED_PRINTER_DRIVER *pLPD;    	/* Printer driver info */
 } WEPFC;
 
-#define OBJ_PEN 	1       
-#define OBJ_BRUSH 	2  
-#define OBJ_FONT 	3   
-#define OBJ_PBITMAP 	5
+#define DRVOBJ_PEN 	1       
+#define DRVOBJ_BRUSH 	2  
+#define DRVOBJ_FONT 	3   
+#define DRVOBJ_PBITMAP 	5
 
 /* Win16 printer driver physical DC */
 typedef struct
diff --git a/include/windows.h b/include/windows.h
index a37a6697a8f..e93a7dd79ad 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -1947,6 +1947,40 @@ typedef struct {
 	HBITMAP32	hbmColor;
 } ICONINFO,*LPICONINFO;
 
+
+#define	FVIRTKEY	TRUE          /* Assumed to be == TRUE */
+#define	FNOINVERT	0x02
+#define	FSHIFT		0x04
+#define	FCONTROL	0x08
+#define	FALT		0x10
+
+typedef struct
+{
+    BYTE   fVirt;
+    WORD   key;
+    WORD   cmd;
+} ACCEL16, *LPACCEL16;
+
+typedef struct
+{
+    BYTE   fVirt;
+    BYTE   pad0;
+    WORD   key;
+    WORD   cmd;
+    WORD   pad1;
+} ACCEL32, *LPACCEL32;
+
+DECL_WINELIB_TYPE(ACCEL);
+DECL_WINELIB_TYPE(LPACCEL);
+
+
+/* Flags for DrawIconEx.  */
+#define DI_MASK                 1
+#define DI_IMAGE                2
+#define DI_NORMAL               (DI_MASK | DI_IMAGE)
+#define DI_COMPAT               4
+#define DI_DEFAULTSIZE          8
+
 typedef struct {
 	BYTE i;  /* much more .... */
 } KANJISTRUCT;
@@ -2452,6 +2486,9 @@ typedef struct tagCOMSTAT
 #define OBM_CDROM           32729
 #define OBM_TRTYPE          32728
 
+/* Wine extension, I think.  */
+#define OBM_RADIOCHECK      32727
+
 #define OBM_OLD_CLOSE       32767
 #define OBM_SIZE            32766
 #define OBM_OLD_UPARROW     32765
@@ -5450,6 +5487,9 @@ BOOL32      WINAPI AreFileApisANSI(void);
 BOOL32      WINAPI Beep(DWORD,DWORD);
 BOOL32      WINAPI ClearCommError(INT32,LPDWORD,LPCOMSTAT);
 BOOL32      WINAPI CloseHandle(HANDLE32);
+INT32       WINAPI CopyAcceleratorTable32A(HACCEL32,LPACCEL32,INT32);
+INT32       WINAPI CopyAcceleratorTable32W(HACCEL32,LPACCEL32,INT32);
+#define     CopyAcceleratorTable WINELIB_NAME_AW(CopyAcceleratorTable)
 BOOL32      WINAPI CopyFile32A(LPCSTR,LPCSTR,BOOL32);
 BOOL32      WINAPI CopyFile32W(LPCWSTR,LPCWSTR,BOOL32);
 #define     CopyFile WINELIB_NAME_AW(CopyFile)
@@ -5474,6 +5514,7 @@ HANDLE32    WINAPI CreateMutex32W(LPSECURITY_ATTRIBUTES,BOOL32,LPCWSTR);
 HANDLE32    WINAPI CreateSemaphore32A(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCSTR);
 HANDLE32    WINAPI CreateSemaphore32W(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCWSTR);
 #define     CreateSemaphore WINELIB_NAME_AW(CreateSemaphore)
+BOOL32      WINAPI DestroyAcceleratorTable(HACCEL32);
 BOOL32      WINAPI DisableThreadLibraryCalls(HMODULE32);
 BOOL32      WINAPI DosDateTimeToFileTime(WORD,WORD,LPFILETIME);
 INT32       WINAPI EnumPropsEx32A(HWND32,PROPENUMPROCEX32A,LPARAM);
@@ -5874,6 +5915,9 @@ BOOL32      WINAPI CheckDlgButton32(HWND32,INT32,UINT32);
 BOOL16      WINAPI CheckMenuItem16(HMENU16,UINT16,UINT16);
 DWORD       WINAPI CheckMenuItem32(HMENU32,UINT32,UINT32);
 #define     CheckMenuItem WINELIB_NAME(CheckMenuItem)
+BOOL16      WINAPI CheckMenuRadioButton16(HMENU16,UINT16,UINT16,UINT16,BOOL16);
+BOOL32      WINAPI CheckMenuRadioButton32(HMENU32,UINT32,UINT32,UINT32,BOOL32);
+#define     CheckMenuRadioButton WINELIB_NAME(CheckMenuRadioButton)
 BOOL16      WINAPI CheckRadioButton16(HWND16,UINT16,UINT16,UINT16);
 BOOL32      WINAPI CheckRadioButton32(HWND32,UINT32,UINT32,UINT32);
 #define     CheckRadioButton WINELIB_NAME(CheckRadioButton)
@@ -5986,6 +6030,11 @@ HBITMAP32   WINAPI CreateDIBitmap32(HDC32,const BITMAPINFOHEADER*,DWORD,
 HBRUSH16    WINAPI CreateDIBPatternBrush16(HGLOBAL16,UINT16);
 HBRUSH32    WINAPI CreateDIBPatternBrush32(HGLOBAL32,UINT32);
 #define     CreateDIBPatternBrush WINELIB_NAME(CreateDIBPatternBrush)
+HBITMAP16   WINAPI CreateDIBSection16 (HDC16, BITMAPINFO *, UINT16,
+				       LPVOID **, HANDLE16, DWORD offset);
+HBITMAP32   WINAPI CreateDIBSection32 (HDC32, BITMAPINFO *, UINT32,
+				       LPVOID **, HANDLE32, DWORD offset);
+#define     CreateDIBSection WINELIB_NAME(CreateDIBSection)
 BOOL16      WINAPI CreateDirectory16(LPCSTR,LPVOID);
 BOOL32      WINAPI CreateDirectory32A(LPCSTR,LPSECURITY_ATTRIBUTES);
 BOOL32      WINAPI CreateDirectory32W(LPCWSTR,LPSECURITY_ATTRIBUTES);
@@ -6206,6 +6255,11 @@ BOOL32      WINAPI DrawFrameControl32(HDC32,LPRECT32,UINT32,UINT32);
 BOOL16      WINAPI DrawIcon16(HDC16,INT16,INT16,HICON16);
 BOOL32      WINAPI DrawIcon32(HDC32,INT32,INT32,HICON32);
 #define     DrawIcon WINELIB_NAME(DrawIcon)
+BOOL16      WINAPI DrawIconEx16(HDC16,INT16,INT16,HICON16,INT16,INT16,
+				UINT16,HBRUSH16,UINT16);
+BOOL32      WINAPI DrawIconEx32(HDC32,INT32,INT32,HICON32,INT32,INT32,
+				UINT32,HBRUSH32,UINT32);
+#define     DrawIconEx WINELIB_NAME(DrawIconEx)
 VOID        WINAPI DrawMenuBar16(HWND16);
 BOOL32      WINAPI DrawMenuBar32(HWND32);
 #define     DrawMenuBar WINELIB_NAME(DrawMenuBar)
@@ -6596,6 +6650,9 @@ INT32       WINAPI GetMenuItemCount32(HMENU32);
 UINT16      WINAPI GetMenuItemID16(HMENU16,INT16);
 UINT32      WINAPI GetMenuItemID32(HMENU32,INT32);
 #define     GetMenuItemID WINELIB_NAME(GetMenuItemID)
+BOOL16      WINAPI GetMenuItemRect16(HWND16,HMENU16,UINT16,LPRECT16);
+BOOL32      WINAPI GetMenuItemRect32(HWND32,HMENU32,UINT32,LPRECT32);
+#define     GetMenuItemRect WINELIB_NAME(GetMenuItemRect)
 UINT16      WINAPI GetMenuState16(HMENU16,UINT16,UINT16);
 UINT32      WINAPI GetMenuState32(HMENU32,UINT32,UINT32);
 #define     GetMenuState WINELIB_NAME(GetMenuState)
diff --git a/include/wintypes.h b/include/wintypes.h
index 7cf79d53bce..c54a42ff3ef 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -8,32 +8,21 @@
 #define __WINE_WINTYPES_H
 
 #ifdef __WINE__
-#include "config.h"
-#endif
-
-#if !defined(__WINE__) && !defined(WINELIB)
-/* If we are not compiling Wine, then we should be using Winelib */
-#error You must use 'configure --with-library' to build Winelib programs
-#define WINELIB
-#endif
-
-#ifdef WINELIB
-# ifdef WINELIB16
-#  undef WINELIB32
-# else
-#  ifndef WINELIB32
-#   define WINELIB32
-#  endif
-# endif
-#else
-# ifdef WINELIB32
-#  undef WINELIB16
+# include "config.h"
+# undef WINELIB
+# undef WINELIB16
+# undef WINELIB32
+# undef UNICODE
+#else  /* __WINE__ */
+# ifndef WINELIB
 #  define WINELIB
 # endif
 # ifdef WINELIB16
-#  define WINELIB
+#  undef WINELIB32
+# else
+#  define WINELIB32
 # endif
-#endif
+#endif  /* __WINE__ */
 
 /* Macros to map Winelib names to the correct implementation name */
 /* depending on WINELIB16, WINELIB32 and UNICODE macros.          */
diff --git a/ipc/Makefile.in b/ipc/Makefile.in
index 3d563140155..c14bbbe71bb 100644
--- a/ipc/Makefile.in
+++ b/ipc/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/library/Makefile.in b/library/Makefile.in
index 4fd19a14fd9..193b0feb9f4 100644
--- a/library/Makefile.in
+++ b/library/Makefile.in
@@ -4,23 +4,10 @@ TOPOBJDIR = ..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
-LIBMODULE = library
 
-LIB_SRCS = \
-	libres.c \
-	miscstubs.c
+C_SRCS = winestub.c
 
-STUB_SRCS = winestub.c
-
-LIB_OBJS  = $(LIB_SRCS:.c=.o)
-STUB_OBJS = $(STUB_SRCS:.c=.o)
-
-C_SRCS = $(LIB_SRCS) $(STUB_SRCS)
-
-all: $(LIBMODULE).o $(STUB_OBJS)
-
-$(LIBMODULE).o: $(LIB_OBJS)
-	$(LDCOMBINE) $(LIB_OBJS) -o $(LIBMODULE).o
+all: $(C_SRCS:.c=.o)
 
 @MAKE_RULES@
 
diff --git a/library/miscstubs.c b/library/miscstubs.c
deleted file mode 100644
index 7e61917bcae..00000000000
--- a/library/miscstubs.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * JBP (Jim Peterson <jspeter@birch.ee.vt.edu>): Lots of stubs needed for
- *      libwine.a.
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "wintypes.h"
-
-
-/* for windows/winproc.c */
-void CallFrom16_long_wwwll(void) {}
-
-extern LRESULT ColorDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
-extern LRESULT FileOpenDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
-extern LRESULT FileSaveDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
-extern LRESULT FindTextDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
-extern LRESULT MDIClientWndProc(HWND16,UINT16,WPARAM16,LPARAM);
-extern LRESULT PrintDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
-extern LRESULT PrintSetupDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
-extern LRESULT ReplaceTextDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
-
-/***********************************************************************
- *           MODULE_GetWndProcEntry16 (not a Windows API function)
- *
- * Return an entry point from the WPROCS dll.
- */
-FARPROC16 MODULE_GetWndProcEntry16( char *name )
-{
-#define MAP_STR_TO_PROC(str,proc) if(!strcmp(name,str))return (FARPROC16)proc
-  MAP_STR_TO_PROC("ColorDlgProc",ColorDlgProc);
-  MAP_STR_TO_PROC("FileOpenDlgProc",FileOpenDlgProc);
-  MAP_STR_TO_PROC("FileSaveDlgProc",FileSaveDlgProc);
-  MAP_STR_TO_PROC("FindTextDlgProc",FindTextDlgProc);
-  MAP_STR_TO_PROC("MDIClientWndProc",MDIClientWndProc);
-  MAP_STR_TO_PROC("PrintDlgProc",PrintDlgProc);
-  MAP_STR_TO_PROC("PrintSetupDlgProc",PrintSetupDlgProc);
-  MAP_STR_TO_PROC("ReplaceTextDlgProc",ReplaceTextDlgProc);
-  fprintf(stderr,"warning: No mapping for %s(), add one in library/miscstubs.c\n",name);
-  assert( FALSE );
-  return NULL;
-}
diff --git a/library/winestub.c b/library/winestub.c
index 39946b3962d..ac18da2a72b 100644
--- a/library/winestub.c
+++ b/library/winestub.c
@@ -4,8 +4,14 @@
 #include "windows.h"
 #include "xmalloc.h"
 
+/* Stubs needed for linking with Winelib */
+/* FIXME: this should not be necessary */
+FARPROC32 BUILTIN_GetProcAddress32( void *mod, LPCSTR func ) { return 0; }
+HMODULE32 BUILTIN_LoadModule( LPCSTR name, BOOL32 force ) { return 0; }
+
+
 extern int PASCAL WinMain(HINSTANCE32,HINSTANCE32,LPSTR,int);
-extern int MAIN_Init(void);
+extern int MAIN_WinelibInit(void);
 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
 extern void TASK_Reschedule(void);
 
@@ -32,7 +38,7 @@ int main( int argc, char *argv [] )
   else lpszCmdParam[0] = '\0';
   for (i = 2; i < argc; i++) strcat(strcat(lpszCmdParam, " "), argv[i]);
 
-  if(!MAIN_Init()) return 0; /* JBP: Needed for DosDrives[] structure, etc. */
+  if(!MAIN_WinelibInit()) return 0;
   hInstance = WinExec32( *argv, SW_SHOWNORMAL );
   TASK_Reschedule();
   InitApp( hInstance );
diff --git a/loader/Makefile.in b/loader/Makefile.in
index 39f2b3093c2..549c3c1f8e8 100644
--- a/loader/Makefile.in
+++ b/loader/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
@@ -6,6 +6,7 @@ VPATH     = @srcdir@
 MODULE    = loader
 
 C_SRCS = \
+	libres.c \
 	main.c \
 	module.c \
 	ne_image.c \
diff --git a/library/libres.c b/loader/libres.c
similarity index 100%
rename from library/libres.c
rename to loader/libres.c
diff --git a/loader/main.c b/loader/main.c
index d5bd59eb738..ed75c116e3f 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -1,7 +1,7 @@
 /*
-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";
-*/
+ * Main initialization code
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -23,7 +23,6 @@ static char Copyright[] = "Copyright  Robert J. Amstadt, 1993";
 #include "queue.h"
 #include "syscolor.h"
 #include "sysmetrics.h"
-#include "callback.h"
 #include "file.h"
 #include "gdi.h"
 #include "heap.h"
@@ -41,78 +40,48 @@ static char Copyright[] = "Copyright  Robert J. Amstadt, 1993";
 #include "stddebug.h"
 #include "debug.h"
 
-#ifndef WINELIB
-#include "debugger.h"
-#endif
 
 int __winelib = 1;  /* Winelib run-time flag */
 
 HANDLE32 SystemHeap = 0;
 HANDLE32 SegptrHeap = 0;
 
+
 /***********************************************************************
- *           Main initialisation routine
+ *           Kernel initialisation routine
  */
-int MAIN_Init(void)
+BOOL32 MAIN_KernelInit(void)
 {
     extern BOOL32 EVENT_Init(void);
-    extern BOOL32 RELAY_Init(void);
-    extern BOOL32 WIN16DRV_Init(void);
     extern BOOL32 VIRTUAL_Init(void);
-    extern BOOL32 WIDGETS_Init(void);
-
-    int queueSize;
 
     /* Initialize virtual memory management */
-    if (!VIRTUAL_Init()) return 0;
+    if (!VIRTUAL_Init()) return FALSE;
 
     /* Create the system and SEGPTR heaps */
-    if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return 0;
-    if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return 0;
+    if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return FALSE;
+    if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return FALSE;
 
     /* Load the configuration file */
-    if (!PROFILE_LoadWineIni()) return 0;
+    if (!PROFILE_LoadWineIni()) return FALSE;
 
       /* Initialize DOS memory */
-    if (!DOSMEM_Init()) return 0;
+    if (!DOSMEM_Init()) return FALSE;
 
       /* Initialize signal handling */
-    if (!SIGNAL_Init()) return 0;
-
-      /* Initialize event handling */
-    if (!EVENT_Init()) return 0;
-
-#ifdef WINELIB
-    /* Create USER and GDI heap */
-    USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
-    LocalInit( USER_HeapSel, 0, 0xffff );
-    GDI_HeapSel  = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
-    LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
-#else
-    /* Initialize relay code */
-    if (!RELAY_Init()) return 0;
-
-      /* Initialize signal handling */
-    if (!SIGNAL_InitEmulator()) return 0;
-
-    /* Create the Win16 printer driver */
-    if (!WIN16DRV_Init()) return 0;
-#endif  /* WINELIB */
-
-    /* Initialize Wine tweaks */
-    if (!TWEAK_Init()) return 0;
-
-    /* Initialize OEM Bitmaps */
-    if (!OBM_Init()) return 0;
+    if (!SIGNAL_Init()) return FALSE;
 
     /* Initialise DOS drives */
-    if (!DRIVE_Init()) return 0;
+    if (!DRIVE_Init()) return FALSE;
 
     /* Initialise DOS directories */
-    if (!DIR_Init()) return 0;
+    if (!DIR_Init()) return FALSE;
 
     /* Initialize tasks */
-    if (!TASK_Init()) return 0;
+    if (!TASK_Init()) return FALSE;
+
+      /* Initialize event handling */
+    if (!EVENT_Init()) return FALSE;
 
     /* Initialize communications */
     COMM_Init();
@@ -120,14 +89,45 @@ int MAIN_Init(void)
     /* Initialize IO-port permissions */
     IO_port_init();
 
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           USER (and GDI) initialisation routine
+ */
+BOOL32 MAIN_UserInit(void)
+{
+    extern BOOL32 WIDGETS_Init(void);
+
+    int queueSize;
+
+    /* Create USER and GDI heap */
+    if (!USER_HeapSel)
+    {
+        USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
+        LocalInit( USER_HeapSel, 0, 0xffff );
+    }
+    if (!GDI_HeapSel)
+    {
+        GDI_HeapSel  = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
+        LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
+    }
+
+    /* Initialize Wine tweaks */
+    if (!TWEAK_Init()) return FALSE;
+
+    /* Initialize OEM Bitmaps */
+    if (!OBM_Init()) return FALSE;
+
     /* registry initialisation */
     SHELL_LoadRegistry();
     
     /* Global atom table initialisation */
-    if (!ATOM_Init()) return 0;
+    if (!ATOM_Init()) return FALSE;
 
     /* GDI initialisation */
-    if (!GDI_Init()) return 0;
+    if (!GDI_Init()) return FALSE;
 
     /* Initialize system colors and metrics*/
     SYSMETRICS_Init();
@@ -137,103 +137,49 @@ int MAIN_Init(void)
     DCE_Init();
 
     /* Initialize keyboard */
-    if (!KEYBOARD_Init()) return 0;
+    if (!KEYBOARD_Init()) return FALSE;
 
     /* Initialize window procedures */
-    if (!WINPROC_Init()) return 0;
+    if (!WINPROC_Init()) return FALSE;
 
     /* Initialize built-in window classes */
-    if (!WIDGETS_Init()) return 0;
+    if (!WIDGETS_Init()) return FALSE;
 
     /* Initialize dialog manager */
-    if (!DIALOG_Init()) return 0;
+    if (!DIALOG_Init()) return FALSE;
 
     /* Initialize menus */
-    if (!MENU_Init()) return 0;
+    if (!MENU_Init()) return FALSE;
 
     /* Create desktop window */
-    if (!WIN_CreateDesktopWindow()) return 0;
+    if (!WIN_CreateDesktopWindow()) return FALSE;
 
     /* Initialize message spying */
-    if (!SPY_Init()) return 0;
+    if (!SPY_Init()) return FALSE;
 
     /* Check wine.conf for old/bad entries */
-    if (!TWEAK_CheckConfiguration()) return 0;
+    if (!TWEAK_CheckConfiguration()) return FALSE;
 
     /* Create system message queue */
     queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
-    if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
+    if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
 
     /* Set double click time */
     SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
 
-    return 1;
+    return TRUE;
 }
 
 
-#ifndef WINELIB
-/**********************************************************************
- *					main
+/***********************************************************************
+ *           Winelib initialisation routine
  */
-int main(int argc, char *argv[] )
+int MAIN_WinelibInit(void)
 {
-    extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
-    extern void *CALL32_Init(void);
-    extern char * DEBUG_argv0;
-
-    int i,loaded;
-    HINSTANCE32 handle;
-
-    __winelib = 0;  /* First of all, clear the Winelib flag */
+    /* Initialize the kernel */
+    if (!MAIN_KernelInit()) return 0;
 
-    /*
-     * Save this so that the internal debugger can get a hold of it if
-     * it needs to.
-     */
-    DEBUG_argv0 = argv[0];
-
-    if (!MAIN_WineInit( &argc, argv )) return 1;
-    if (!MAIN_Init()) return 1;
-
-    /* Initialize CALL32 routines */
-    /* This needs to be done just before task-switching starts */
-    IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
-
-    loaded=0;
-    for (i = 1; i < argc; i++)
-    {
-        if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
-        {
-            fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
-            switch (handle)
-            {
-            case 2: fprintf( stderr, "file not found\n" ); break;
-            case 11: fprintf( stderr, "invalid exe file\n" ); break;
-            case 21: fprintf( stderr, "win32 executable\n" ); break;
-            default: fprintf( stderr, "error=%d\n", handle ); break;
-            }
-            return 1;
-        }
-	loaded++;
-    }
-
-    if (!loaded) { /* nothing loaded */
-    	extern void MAIN_Usage(char*);
-    	MAIN_Usage(argv[0]);
-	return 1;
-    }
-
-    if (!GetNumTasks())
-    {
-        fprintf( stderr, "wine: no executable file found.\n" );
-        return 0;
-    }
-
-    if (Options.debug) DEBUG_AddModuleBreakpoints();
-
-    Yield();  /* Start the first task */
-    fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
-    return 0;
+    /* Initialize all the USER stuff */
+    if (!MAIN_UserInit()) return 0;
+    return 1;
 }
-
-#endif /* #ifndef WINELIB */
diff --git a/loader/module.c b/loader/module.c
index c1d3047dac4..202f189cdfd 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -4,6 +4,7 @@
  * Copyright 1995 Alexandre Julliard
  */
 
+#include <assert.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -918,20 +919,54 @@ BOOL16 MODULE_SetEntryPoint( HMODULE32 hModule, WORD ordinal, WORD offset )
  *
  * Return an entry point from the WPROCS dll.
  */
-#ifndef WINELIB
-FARPROC16 MODULE_GetWndProcEntry16( const char *name )
+FARPROC16 MODULE_GetWndProcEntry16( LPCSTR name )
 {
-    WORD ordinal;
-    FARPROC16 ret;
-    static HMODULE32 hModule = 0;
+    FARPROC16 ret = NULL;
+
+    if (__winelib)
+    {
+        /* FIXME: hack for Winelib */
+        extern LRESULT ColorDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
+        extern LRESULT FileOpenDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
+        extern LRESULT FileSaveDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
+        extern LRESULT FindTextDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
+        extern LRESULT PrintDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
+        extern LRESULT PrintSetupDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
+        extern LRESULT ReplaceTextDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
+
+        if (!strcmp(name,"ColorDlgProc"))
+            return (FARPROC16)ColorDlgProc;
+        if (!strcmp(name,"FileOpenDlgProc"))
+            return (FARPROC16)FileOpenDlgProc;
+        if (!strcmp(name,"FileSaveDlgProc"))
+            return (FARPROC16)FileSaveDlgProc;
+        if (!strcmp(name,"FindTextDlgProc"))
+            return (FARPROC16)FindTextDlgProc;
+        if (!strcmp(name,"PrintDlgProc"))
+            return (FARPROC16)PrintDlgProc;
+        if (!strcmp(name,"PrintSetupDlgProc"))
+            return (FARPROC16)PrintSetupDlgProc;
+        if (!strcmp(name,"ReplaceTextDlgProc"))
+            return (FARPROC16)ReplaceTextDlgProc;
+        fprintf(stderr,"warning: No mapping for %s(), add one in library/miscstubs.c\n",name);
+        assert( FALSE );
+        return NULL;
+    }
+    else
+    {
+        WORD ordinal;
+        static HMODULE32 hModule = 0;
 
-    if (!hModule) hModule = GetModuleHandle16( "WPROCS" );
-    ordinal = MODULE_GetOrdinal( hModule, name );
-    if (!(ret = MODULE_GetEntryPoint( hModule, ordinal )))
-        fprintf( stderr, "GetWndProc16: %s not found, please report\n", name );
+        if (!hModule) hModule = GetModuleHandle16( "WPROCS" );
+        ordinal = MODULE_GetOrdinal( hModule, name );
+        if (!(ret = MODULE_GetEntryPoint( hModule, ordinal )))
+        {            
+            fprintf( stderr, "GetWndProc16: %s not found\n", name );
+            assert( FALSE );
+        }
+    }
     return ret;
 }
-#endif
 
 
 /***********************************************************************
@@ -1109,203 +1144,97 @@ HINSTANCE16 MODULE_Load( LPCSTR name, LPVOID paramBlock, UINT16 uFlags)
     NE_MODULE *pModule;
     LOADPARAMS *params = (LOADPARAMS *)paramBlock;
     OFSTRUCT ofs;
-#ifndef WINELIB
-    WORD *pModRef, *pDLLs;
     HFILE32 hFile;
-    int i;
-    extern const char * DEBUG_curr_module;
-
-    hModule = MODULE_FindModule( name );
 
-    if (!hModule)  /* We have to load the module */
+    if (__winelib)
     {
-        /* Try to load the built-in first if not disabled */
-        if ((hModule = BUILTIN_LoadModule( name, FALSE ))) return hModule;
+        lstrcpyn32A( ofs.szPathName, name, sizeof(ofs.szPathName) );
+        if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return hModule;
+        pModule = (NE_MODULE *)GlobalLock16( hModule );
+        hPrevInstance = 0;
+        hInstance = MODULE_CreateInstance( hModule, params );
+    }
+    else
+    {
+        hModule = MODULE_FindModule( name );
 
-        if ((hFile = OpenFile32( name, &ofs, OF_READ )) == HFILE_ERROR32)
+        if (!hModule)  /* We have to load the module */
         {
-            /* Now try the built-in even if disabled */
-            if ((hModule = BUILTIN_LoadModule( name, TRUE )))
+            /* Try to load the built-in first if not disabled */
+            if ((hModule = BUILTIN_LoadModule( name, FALSE ))) return hModule;
+            
+            if ((hFile = OpenFile32( name, &ofs, OF_READ )) == HFILE_ERROR32)
             {
-                fprintf( stderr, "Warning: could not load Windows DLL '%s', using built-in module.\n", name );
-                return hModule;
+                /* Now try the built-in even if disabled */
+                if ((hModule = BUILTIN_LoadModule( name, TRUE )))
+                {
+                    fprintf( stderr, "Warning: could not load Windows DLL '%s', using built-in module.\n", name );
+                    return hModule;
+                }
+                return 2;  /* File not found */
             }
-            return 2;  /* File not found */
-        }
 
-	/*
-	 * Record this so that the internal debugger gets some
-	 * record of what it is that we are working with.
-	 */
-	DEBUG_curr_module = name;
-
-          /* Create the module structure */
-
-        hModule = MODULE_LoadExeHeader( hFile, &ofs );
-        if (hModule < 32)
-        {
-            if (hModule == 21)
-                hModule = PE_LoadModule( hFile, &ofs, paramBlock );
-	    else _lclose32( hFile );
+            /* Create the module structure */
 
+            hModule = MODULE_LoadExeHeader( hFile, &ofs );
             if (hModule < 32)
-                fprintf( stderr, "LoadModule: can't load '%s', error=%d\n",
-                         name, hModule );
-            return hModule;
-        }
-        _lclose32( hFile );
-        pModule = MODULE_GetPtr( hModule );
-	pModule->flags |= uFlags; /* stamp implicitly loaded modules */
-
-          /* Allocate the segments for this module */
-
-        MODULE_CreateSegments( hModule );
+            {
+                if (hModule == 21)
+                    hModule = PE_LoadModule( hFile, &ofs, paramBlock );
+                else _lclose32( hFile );
 
-        hPrevInstance = 0;
-        hInstance = MODULE_CreateInstance( hModule, (LOADPARAMS*)paramBlock );
+                if (hModule < 32)
+                    fprintf( stderr, "LoadModule: can't load '%s', error=%d\n",
+                             name, hModule );
+                return hModule;
+            }
+            _lclose32( hFile );
+            pModule = MODULE_GetPtr( hModule );
+            pModule->flags |= uFlags; /* stamp implicitly loaded modules */
 
-          /* Load the referenced DLLs */
+            /* Allocate the segments for this module */
 
-        pModRef = (WORD *)((char *)pModule + pModule->modref_table);
-        pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
-        for (i = 0; i < pModule->modref_count; i++, pModRef++)
-        {
-            char buffer[256];
-            BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
-            memcpy( buffer, pstr + 1, *pstr );
-            strcpy( buffer + *pstr, ".dll" );
-            dprintf_module( stddeb, "Loading '%s'\n", buffer );
-            if (!(*pModRef = MODULE_FindModule( buffer )))
-            {
-                /* If the DLL is not loaded yet, load it and store */
-                /* its handle in the list of DLLs to initialize.   */
-                HMODULE16 hDLL;
+            MODULE_CreateSegments( hModule );
+            hPrevInstance = 0;
+            hInstance = MODULE_CreateInstance(hModule,(LOADPARAMS*)paramBlock);
 
-                if ((hDLL = MODULE_Load( buffer, (LPVOID)-1, NE_FFLAGS_IMPLICIT )) == 2)
-                {
-                    /* file not found */
-                    char *p;
-
-                    /* Try with prepending the path of the current module */
-                    GetModuleFileName16( hModule, buffer, sizeof(buffer) );
-                    if (!(p = strrchr( buffer, '\\' ))) p = buffer;
-                    memcpy( p + 1, pstr + 1, *pstr );
-                    strcpy( p + 1 + *pstr, ".dll" );
-                    hDLL = MODULE_Load( buffer, (LPVOID)-1, NE_FFLAGS_IMPLICIT );
-                }
-                if (hDLL < 32)
-                {
-		    /* FIXME: cleanup what was done */
+            /* Load the referenced DLLs */
 
-                    fprintf( stderr, "Could not load '%s' required by '%s', error = %d\n",
-                             buffer, name, hDLL );
-                    return 2;  /* file not found */
-                }
-                *pModRef = MODULE_HANDLEtoHMODULE16( hDLL );
-                *pDLLs++ = *pModRef;
-            }
-            else  /* Increment the reference count of the DLL */
-            {
-                NE_MODULE *pOldDLL = MODULE_GetPtr( *pModRef );
-                if (pOldDLL) pOldDLL->count++;
-            }
-        }
+            if (!NE_LoadDLLs( pModule )) return 2;  /* File not found */
 
-          /* Load the segments */
+            /* Load the segments */
 
-	if (pModule->flags & NE_FFLAGS_SELFLOAD)
-	{
-                HFILE32 hf;
-		/* Handle self loading modules */
-		SEGTABLEENTRY * pSegTable = (SEGTABLEENTRY *) NE_SEG_TABLE(pModule);
-		SELFLOADHEADER *selfloadheader;
-                STACK16FRAME *stack16Top;
-		HMODULE16 hselfload = GetModuleHandle16("WPROCS");
-                DWORD oldstack;
-		WORD saved_dgroup = pSegTable[pModule->dgroup - 1].selector;
-
-		dprintf_module(stddeb, "MODULE_Load: %*.*s is a self-loading module!\n",
-					*((BYTE*)pModule + pModule->name_table),
-					*((BYTE*)pModule + pModule->name_table),
-					 (char *)pModule + pModule->name_table + 1);
-
-		NE_LoadSegment( hModule, 1 );
-		selfloadheader = (SELFLOADHEADER *)
-			PTR_SEG_OFF_TO_LIN(pSegTable->selector, 0);
-		selfloadheader->EntryAddrProc = 
-                                           MODULE_GetEntryPoint(hselfload,27);
-		selfloadheader->MyAlloc  = MODULE_GetEntryPoint(hselfload,28);
-		selfloadheader->SetOwner = MODULE_GetEntryPoint(GetModuleHandle16("KERNEL"),403);
-		pModule->self_loading_sel = GlobalHandleToSel(
-					GLOBAL_Alloc (GMEM_ZEROINIT,
-					0xFF00, hModule, FALSE, FALSE, FALSE)
-					);
-		oldstack = IF1632_Saved16_ss_sp;
-		IF1632_Saved16_ss_sp =
-                    PTR_SEG_OFF_TO_SEGPTR( pModule->self_loading_sel,
-                                           0xff00 - sizeof(*stack16Top) );
-                stack16Top = CURRENT_STACK16;
-                stack16Top->saved_ss_sp = 0;
-                stack16Top->ebp = 0;
-                stack16Top->ds = stack16Top->es = pModule->self_loading_sel;
-                stack16Top->entry_point = 0;
-                stack16Top->entry_ip = 0;
-                stack16Top->entry_cs = 0;
-                stack16Top->bp = 0;
-                stack16Top->ip = 0;
-                stack16Top->cs = 0;
-
-                hf = FILE_DupUnixHandle( MODULE_OpenFile( hModule ) );
-                Callbacks->CallBootAppProc( selfloadheader->BootApp,
-                                            hModule, hf );
-                _lclose32(hf);
-		/* some BootApp procs overwrite the selector of dgroup */
-		pSegTable[pModule->dgroup - 1].selector = saved_dgroup;
-		IF1632_Saved16_ss_sp = oldstack;
-		for (i = 2; i <= pModule->seg_count; i++)
-                    NE_LoadSegment( hModule, i );
-	} 
-	else
-        {
-            for (i = 1; i <= pModule->seg_count; i++)
-                NE_LoadSegment( hModule, i );
-        }
+            NE_LoadAllSegments( pModule );
 
-          /* Fixup the functions prologs */
+            /* Fixup the functions prologs */
 
-        NE_FixupPrologs( pModule );
+            NE_FixupPrologs( pModule );
 
-          /* Make sure the usage count is 1 on the first loading of  */
-          /* the module, even if it contains circular DLL references */
+            /* Make sure the usage count is 1 on the first loading of  */
+            /* the module, even if it contains circular DLL references */
 
-        pModule->count = 1;
+            pModule->count = 1;
 
-	  /* Call initialization rountines for all loaded DLLs. Note that
-	   * when we load implicitly linked DLLs this will be done by the InitTask().
-	   */
-
-        if ((pModule->flags & (NE_FFLAGS_LIBMODULE | NE_FFLAGS_IMPLICIT)) ==
-			       NE_FFLAGS_LIBMODULE ) NE_InitializeDLLs( hModule );
-    }
-    else /* module is already loaded, just create a new data segment if it's a task */
-    {
-        pModule = MODULE_GetPtr( hModule );
-        hPrevInstance = MODULE_GetInstance( hModule );
-        hInstance = MODULE_CreateInstance( hModule, params );
-        if (hInstance != hPrevInstance)  /* not a library */
-            NE_LoadSegment( hModule, pModule->dgroup );
-        pModule->count++;
-    }
+            /* Call initialization rountines for all loaded DLLs. Note that
+             * when we load implicitly linked DLLs this will be done by InitTask().
+             */
 
-#else
-    lstrcpyn32A( ofs.szPathName, name, sizeof(ofs.szPathName) );
-    if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return hModule;
-    pModule = (NE_MODULE *)GlobalLock16( hModule );
-    hPrevInstance = 0;
-    hInstance = MODULE_CreateInstance( hModule, params );
-#endif /* WINELIB */
+            if ((pModule->flags & (NE_FFLAGS_LIBMODULE | NE_FFLAGS_IMPLICIT)) ==
+                                       NE_FFLAGS_LIBMODULE )
+                NE_InitializeDLLs( hModule );
+        }
+        else /* module is already loaded, just create a new data segment if it's a task */
+        {
+            pModule = MODULE_GetPtr( hModule );
+            hPrevInstance = MODULE_GetInstance( hModule );
+            hInstance = MODULE_CreateInstance( hModule, params );
+            if (hInstance != hPrevInstance)  /* not a library */
+                NE_LoadSegment( pModule, pModule->dgroup );
+            pModule->count++;
+        }
+    } /* !winelib */
 
-      /* Create a task for this instance */
+    /* Create a task for this instance */
 
     if (!(pModule->flags & NE_FFLAGS_LIBMODULE) && (paramBlock != (LPVOID)-1))
     {
@@ -1675,13 +1604,9 @@ HINSTANCE32 WINAPI WinExec32( LPCSTR lpCmdLine, UINT32 nCmdShow )
 
 	if (use_load_module)
 	{
-#ifdef WINELIB
-	    /* WINELIB: Use LoadModule() only for the program itself */
-	    use_load_module = 0;
-	    params.hEnvironment = (HGLOBAL16)GetDOSEnvironment();
-#else
+	    /* Winelib: Use LoadModule() only for the program itself */
+	    if (__winelib) use_load_module = 0;
 	    params.hEnvironment = (HGLOBAL16)SELECTOROF( GetDOSEnvironment() );
-#endif  /* WINELIB */
 	    params.cmdLine  = (SEGPTR)WIN16_GlobalLock16( cmdLineHandle );
 	    params.showCmd  = (SEGPTR)WIN16_GlobalLock16( cmdShowHandle );
 	    params.reserved = 0;
@@ -1840,7 +1765,6 @@ FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, SEGPTR name )
  */
 FARPROC32 WINAPI GetProcAddress32( HMODULE32 hModule, LPCSTR function )
 {
-#ifndef WINELIB
     NE_MODULE *pModule;
 
     if (HIWORD(function))
@@ -1858,9 +1782,6 @@ FARPROC32 WINAPI GetProcAddress32( HMODULE32 hModule, LPCSTR function )
 	return (FARPROC32)0;
     }
     return PE_FindExportedFunction( pModule->pe_module, function );
-#else
-    return NULL;
-#endif
 }
 
 /***********************************************************************
diff --git a/loader/ne_image.c b/loader/ne_image.c
index 5fadcef7d54..d42e5bcad64 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -16,6 +16,7 @@
 #include <errno.h>
 #include "neexe.h"
 #include "windows.h"
+#include "global.h"
 #include "task.h"
 #include "selectors.h"
 #include "callback.h"
@@ -30,9 +31,8 @@
 /***********************************************************************
  *           NE_LoadSegment
  */
-BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum )
+BOOL32 NE_LoadSegment( NE_MODULE *pModule, WORD segnum )
 {
-    NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable, *pSeg;
     WORD *pModuleTable;
     WORD count, i, offset;
@@ -44,18 +44,17 @@ BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum )
     int size;
     char* mem;
 
-    char buffer[100];
+    char buffer[256];
     int ordinal, additive;
     unsigned short *sp;
 
-    if (!(pModule = MODULE_GetPtr( hModule ))) return FALSE;
     pSegTable = NE_SEG_TABLE( pModule );
     pSeg = pSegTable + segnum - 1;
     pModuleTable = NE_MODULE_TABLE( pModule );
 
     if (!pSeg->filepos) return TRUE;  /* No file image, just return */
 	
-    fd = MODULE_OpenFile( hModule );
+    fd = MODULE_OpenFile( pModule->self );
     dprintf_module( stddeb, "Loading segment %d, selector=%04x\n",
                     segnum, pSeg->selector );
     lseek( fd, pSeg->filepos << pModule->alignment, SEEK_SET );
@@ -88,7 +87,7 @@ BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum )
         stack16Top->ip = 0;
         stack16Top->cs = 0;
  	newselector = Callbacks->CallLoadAppSegProc(selfloadheader->LoadAppSeg,
-                                                    hModule, hf, segnum );
+                                                   pModule->self, hf, segnum );
         _lclose32( hf );
  	if (newselector != oldselector) {
  	  /* Self loaders like creating their own selectors; 
@@ -218,16 +217,14 @@ BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum )
             if (!address)
             {
                 NE_MODULE *pTarget = MODULE_GetPtr( module );
-                fprintf( stderr, "Warning: no handler for %*.*s.%s, setting to 0:0\n",
-                        *((BYTE *)pTarget + pTarget->name_table),
+                fprintf( stderr, "Warning: no handler for %.*s.%s, setting to 0:0\n",
                         *((BYTE *)pTarget + pTarget->name_table),
                         (char *)pTarget + pTarget->name_table + 1, func_name );
             }
             if (debugging_fixup)
             {
                 NE_MODULE *pTarget = MODULE_GetPtr( module );
-                fprintf( stddeb,"%d: %*.*s.%s=%04x:%04x\n", i + 1, 
-                         *((BYTE *)pTarget + pTarget->name_table),
+                fprintf( stddeb,"%d: %.*s.%s=%04x:%04x\n", i + 1, 
                          *((BYTE *)pTarget + pTarget->name_table),
                          (char *)pTarget + pTarget->name_table + 1,
                          func_name, HIWORD(address), LOWORD(address) );
@@ -237,7 +234,7 @@ BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum )
 	  case NE_RELTYPE_INTERNAL:
 	    if ((rep->target1 & 0xff) == 0xff)
 	    {
-		address  = MODULE_GetEntryPoint( hModule, rep->target2 );
+		address  = MODULE_GetEntryPoint( pModule->self, rep->target2 );
 	    }
 	    else
 	    {
@@ -282,7 +279,7 @@ BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum )
         /* we ignore it for now */
 	if (rep->address_type > NE_RADDR_OFFSET32)
             fprintf( stderr, "WARNING: module %s: unknown reloc addr type = 0x%02x. Please report.\n",
-                     MODULE_GetModuleName(hModule), rep->address_type );
+                     MODULE_GetModuleName(pModule->self), rep->address_type );
 
 	switch (rep->address_type & 0x7f)
 	{
@@ -357,6 +354,122 @@ BOOL32 NE_LoadSegment( HMODULE16 hModule, WORD segnum )
 }
 
 
+/***********************************************************************
+ *           NE_LoadAllSegments
+ */
+BOOL32 NE_LoadAllSegments( NE_MODULE *pModule )
+{
+    int i;
+
+    if (pModule->flags & NE_FFLAGS_SELFLOAD)
+    {
+        HFILE32 hf;
+        /* Handle self loading modules */
+        SEGTABLEENTRY * pSegTable = (SEGTABLEENTRY *) NE_SEG_TABLE(pModule);
+        SELFLOADHEADER *selfloadheader;
+        STACK16FRAME *stack16Top;
+        HMODULE16 hselfload = GetModuleHandle16("WPROCS");
+        DWORD oldstack;
+        WORD saved_dgroup = pSegTable[pModule->dgroup - 1].selector;
+
+        dprintf_module(stddeb, "MODULE_Load: %.*s is a self-loading module!\n",
+                       *((BYTE*)pModule + pModule->name_table),
+                       (char *)pModule + pModule->name_table + 1);
+        if (!NE_LoadSegment( pModule, 1 )) return FALSE;
+        selfloadheader = (SELFLOADHEADER *)
+                          PTR_SEG_OFF_TO_LIN(pSegTable->selector, 0);
+        selfloadheader->EntryAddrProc = MODULE_GetEntryPoint(hselfload,27);
+        selfloadheader->MyAlloc  = MODULE_GetEntryPoint(hselfload,28);
+        selfloadheader->SetOwner = MODULE_GetEntryPoint(GetModuleHandle16("KERNEL"),403);
+        pModule->self_loading_sel = GlobalHandleToSel(GLOBAL_Alloc(GMEM_ZEROINIT, 0xFF00, pModule->self, FALSE, FALSE, FALSE));
+        oldstack = IF1632_Saved16_ss_sp;
+        IF1632_Saved16_ss_sp = PTR_SEG_OFF_TO_SEGPTR(pModule->self_loading_sel,
+                                                0xff00 - sizeof(*stack16Top) );
+        stack16Top = CURRENT_STACK16;
+        stack16Top->saved_ss_sp = 0;
+        stack16Top->ebp = 0;
+        stack16Top->ds = stack16Top->es = pModule->self_loading_sel;
+        stack16Top->entry_point = 0;
+        stack16Top->entry_ip = 0;
+        stack16Top->entry_cs = 0;
+        stack16Top->bp = 0;
+        stack16Top->ip = 0;
+        stack16Top->cs = 0;
+
+        hf = FILE_DupUnixHandle( MODULE_OpenFile( pModule->self ) );
+        Callbacks->CallBootAppProc(selfloadheader->BootApp, pModule->self, hf);
+        _lclose32(hf);
+        /* some BootApp procs overwrite the selector of dgroup */
+        pSegTable[pModule->dgroup - 1].selector = saved_dgroup;
+        IF1632_Saved16_ss_sp = oldstack;
+        for (i = 2; i <= pModule->seg_count; i++)
+            if (!NE_LoadSegment( pModule, i )) return FALSE;
+    }
+    else
+    {
+        for (i = 1; i <= pModule->seg_count; i++)
+            if (!NE_LoadSegment( pModule, i )) return FALSE;
+    }
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           NE_LoadDLLs
+ */
+BOOL32 NE_LoadDLLs( NE_MODULE *pModule )
+{
+    int i;
+    WORD *pModRef = (WORD *)((char *)pModule + pModule->modref_table);
+    WORD *pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
+
+    for (i = 0; i < pModule->modref_count; i++, pModRef++)
+    {
+        char buffer[256];
+        BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
+        memcpy( buffer, pstr + 1, *pstr );
+        strcpy( buffer + *pstr, ".dll" );
+        dprintf_module( stddeb, "Loading '%s'\n", buffer );
+        if (!(*pModRef = MODULE_FindModule( buffer )))
+        {
+            /* If the DLL is not loaded yet, load it and store */
+            /* its handle in the list of DLLs to initialize.   */
+            HMODULE16 hDLL;
+
+            if ((hDLL = MODULE_Load( buffer, (LPVOID)-1, NE_FFLAGS_IMPLICIT )) == 2)
+            {
+                /* file not found */
+                char *p;
+
+                /* Try with prepending the path of the current module */
+                GetModuleFileName16( pModule->self, buffer, sizeof(buffer) );
+                if (!(p = strrchr( buffer, '\\' ))) p = buffer;
+                memcpy( p + 1, pstr + 1, *pstr );
+                strcpy( p + 1 + *pstr, ".dll" );
+                hDLL = MODULE_Load( buffer, (LPVOID)-1, NE_FFLAGS_IMPLICIT );
+            }
+            if (hDLL < 32)
+            {
+                /* FIXME: cleanup what was done */
+
+                fprintf( stderr, "Could not load '%s' required by '%.*s', error = %d\n",
+                         buffer, *((BYTE*)pModule + pModule->name_table),
+                         (char *)pModule + pModule->name_table + 1, hDLL );
+                return FALSE;
+            }
+            *pModRef = MODULE_HANDLEtoHMODULE16( hDLL );
+            *pDLLs++ = *pModRef;
+        }
+        else  /* Increment the reference count of the DLL */
+        {
+            NE_MODULE *pOldDLL = MODULE_GetPtr( *pModRef );
+            if (pOldDLL) pOldDLL->count++;
+        }
+    }
+    return TRUE;
+}
+
+
 /***********************************************************************
  *           NE_FixupPrologs
  *
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 07b147c250c..17bd23061a3 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -34,9 +34,6 @@
 #include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
-#ifndef WINELIB
-#include "debugger.h"
-#endif
 
 static void PE_InitDLL(PE_MODREF* modref, DWORD type, LPVOID lpReserved);
 
@@ -49,7 +46,7 @@ void dump_exports(IMAGE_EXPORT_DIRECTORY * pe_exports, unsigned int load_addr)
   int		i, j;
   u_short	*ordinal;
   u_long	*function,*functions;
-  u_char	**name,*ename;
+  u_char	**name;
 
   Module = (char*)RVA(pe_exports->Name);
   dprintf_win32(stddeb,"\n*******EXPORT DATA*******\nModule name is %s, %ld functions, %ld names\n", 
@@ -65,7 +62,7 @@ void dump_exports(IMAGE_EXPORT_DIRECTORY * pe_exports, unsigned int load_addr)
   for (i=0;i<pe_exports->NumberOfFunctions;i++, function++)
   {
       if (!*function) continue;  /* No such function */
-      dprintf_win32( stddeb,"%4d  %08lx", i + pe_exports->Base, *function );
+      dprintf_win32( stddeb,"%4ld  %08lx", i + pe_exports->Base, *function );
       /* Check if we have a name for it */
       for (j = 0; j < pe_exports->NumberOfNames; j++)
           if (ordinal[j] == i)
@@ -584,16 +581,6 @@ PE_MapImage(PE_MODULE *pe,PDB32 *process, OFSTRUCT *ofs, DWORD flags) {
 		pem->pe_reloc = (void *) RVA(dir.VirtualAddress);
 	}
 
-#ifndef WINELIB
-	if(pe->pe_header->OptionalHeader.DataDirectory
-		[IMAGE_DIRECTORY_ENTRY_DEBUG].Size)
-	  {
-	    DEBUG_RegisterDebugInfo(pe, load_addr, 
-			pe->pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress,
-			pe->pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size);
-	  }
-#endif
-
 	if(pe->pe_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_COPYRIGHT].Size)
 		dprintf_win32(stdnimp,"Copyright string ignored\n");
@@ -667,20 +654,17 @@ HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, HFILE32 hFile, DWORD flags) {
 		pModule = MODULE_GetPtr(hModule);
 	} else {
 
-#ifndef WINELIB
 		/* try to load builtin, enabled modules first */
 		if ((hModule = BUILTIN_LoadModule( name, FALSE )))
 			return hModule;
-#endif
+
 		/* try to open the specified file */
 		if (HFILE_ERROR32==(hFile=OpenFile32(name,&ofs,OF_READ))) {
-#ifndef WINELIB
 			/* Now try the built-in even if disabled */
 			if ((hModule = BUILTIN_LoadModule( name, TRUE ))) {
 				fprintf( stderr, "Warning: could not load Windows DLL '%s', using built-in module.\n", name );
 				return hModule;
 			}
-#endif
 			return 1;
 		}
 		if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) {
diff --git a/loader/resource.c b/loader/resource.c
index fee5cfaeef2..0017fa78ac0 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -18,7 +18,6 @@
 #include "heap.h"
 #include "neexe.h"
 #include "task.h"
-#include "accel.h"
 #include "module.h"
 #include "resource.h"
 #include "stddebug.h"
@@ -63,14 +62,16 @@ HRSRC16 WINAPI FindResource16( HMODULE16 hModule, SEGPTR name, SEGPTR type )
 
     if ((pModule = MODULE_GetPtr( hModule )))
     {
-#ifndef WINELIB
-	if (pModule->flags & NE_FFLAGS_WIN32)
-	    fprintf(stderr,"FindResource16: %s", NEWin32FailureString);
-	else
-	    return NE_FindResource( hModule, type, name );
-#else
-	return LIBRES_FindResource16( hModule, name, type );
-#endif
+        if (!__winelib)
+        {
+            if (pModule->flags & NE_FFLAGS_WIN32)
+                fprintf(stderr,"FindResource16: %s", NEWin32FailureString);
+            else
+                return NE_FindResource( hModule, type, name );
+        }
+        else return LIBRES_FindResource16( hModule,
+                                           (LPCSTR)PTR_SEG_TO_LIN(name),
+                                           (LPCSTR)PTR_SEG_TO_LIN(type) );
     }
     return 0;
 }
@@ -114,28 +115,29 @@ HANDLE32 WINAPI FindResourceEx32A( HINSTANCE32 hModule, LPCSTR name,
 HRSRC32 WINAPI FindResourceEx32W( HINSTANCE32 hModule, LPCWSTR name,
                                   LPCWSTR type, WORD lang )
 {
-#ifndef WINELIB
-    NE_MODULE *pModule;
-
-    if (!hModule) hModule = GetTaskDS();
-    hModule = MODULE_HANDLEtoHMODULE32( hModule );
-    dprintf_resource(stddeb, "FindResource32W: module=%08x type=", hModule );
-    if (HIWORD(type))
-    	dprintf_resource(stddeb,"%p",type);
-    else
-	dprintf_resource(stddeb,"#%p",type);
-    dprintf_resource( stddeb, " name=" );
-    if (HIWORD(name))
-    	dprintf_resource(stddeb,"%p",name);
-    else
-	dprintf_resource(stddeb,"#%p",name);
-    dprintf_resource( stddeb, "\n" );
-    if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-    if (!(pModule->flags & NE_FFLAGS_WIN32)) return 0;
-    return PE_FindResourceEx32W(hModule,name,type,lang);
-#else
-    return LIBRES_FindResource32( hModule, name, type );
-#endif
+    if (!__winelib)
+    {
+        NE_MODULE *pModule;
+
+        if (!hModule) hModule = GetTaskDS();
+        hModule = MODULE_HANDLEtoHMODULE32( hModule );
+        dprintf_resource(stddeb, "FindResource32W: module=%08x type=",
+                         hModule );
+        if (HIWORD(type))
+            dprintf_resource(stddeb,"%p",type);
+        else
+            dprintf_resource(stddeb,"#%p",type);
+        dprintf_resource( stddeb, " name=" );
+        if (HIWORD(name))
+            dprintf_resource(stddeb,"%p",name);
+        else
+            dprintf_resource(stddeb,"#%p",name);
+        dprintf_resource( stddeb, "\n" );
+        if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
+        if (!(pModule->flags & NE_FFLAGS_WIN32)) return 0;
+        return PE_FindResourceEx32W(hModule,name,type,lang);
+    }
+    else return LIBRES_FindResource32( hModule, name, type );
 }
 
 /**********************************************************************
@@ -160,14 +162,14 @@ HGLOBAL16 WINAPI LoadResource16( HMODULE16 hModule, HRSRC16 hRsrc )
     if (!hRsrc) return 0;
     if ((pModule = MODULE_GetPtr( hModule )))
     {
-#ifndef WINELIB
-	if (pModule->flags & NE_FFLAGS_WIN32)
-	    fprintf(stderr,"LoadResource16: %s", NEWin32FailureString);
-	else
-	    return NE_LoadResource( hModule, hRsrc );
-#else
-	return LIBRES_LoadResource( hModule, hRsrc );
-#endif
+        if (!__winelib)
+        {
+            if (pModule->flags & NE_FFLAGS_WIN32)
+                fprintf(stderr,"LoadResource16: %s", NEWin32FailureString);
+            else
+                return NE_LoadResource( hModule, hRsrc );
+        }
+        else return LIBRES_LoadResource( hModule, hRsrc );
     }
     return 0;
 }
@@ -177,25 +179,25 @@ HGLOBAL16 WINAPI LoadResource16( HMODULE16 hModule, HRSRC16 hRsrc )
  */
 HGLOBAL32 WINAPI LoadResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
 {
-#ifndef WINELIB
-    NE_MODULE *pModule;
-
-    if (!hModule) hModule = GetTaskDS(); /* FIXME: see FindResource32W */
-    hModule = MODULE_HANDLEtoHMODULE32( hModule );
-    dprintf_resource(stddeb, "LoadResource32: module=%04x res=%04x\n",
-                     hModule, hRsrc );
-    if (!hRsrc) return 0;
-
-    if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-    if (!(pModule->flags & NE_FFLAGS_WIN32))
+    if (!__winelib)
     {
-    	fprintf(stderr,"LoadResource32: %s", PEWin16FailureString );
-   	return 0;  /* FIXME? */
+        NE_MODULE *pModule;
+
+        if (!hModule) hModule = GetTaskDS(); /* FIXME: see FindResource32W */
+        hModule = MODULE_HANDLEtoHMODULE32( hModule );
+        dprintf_resource(stddeb, "LoadResource32: module=%04x res=%04x\n",
+                         hModule, hRsrc );
+        if (!hRsrc) return 0;
+
+        if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
+        if (!(pModule->flags & NE_FFLAGS_WIN32))
+        {
+            fprintf(stderr,"LoadResource32: %s", PEWin16FailureString );
+            return 0;  /* FIXME? */
+        }
+        return PE_LoadResource32(hModule,hRsrc);
     }
-    return PE_LoadResource32(hModule,hRsrc);
-#else
-    return LIBRES_LoadResource( hModule, hRsrc );
-#endif
+    else return LIBRES_LoadResource( hModule, hRsrc );
 }
 
 
@@ -205,7 +207,6 @@ HGLOBAL32 WINAPI LoadResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
 /* 16-bit version */
 SEGPTR WINAPI WIN16_LockResource16(HGLOBAL16 handle)
 {
-#ifndef WINELIB
     HMODULE16 hModule;
     NE_MODULE *pModule;
 
@@ -219,31 +220,28 @@ SEGPTR WINAPI WIN16_LockResource16(HGLOBAL16 handle)
         return 0;
     }
     return NE_LockResource( hModule, handle );
-#else
-    return LIBRES_LockResource( handle );
-#endif
 }
 
-/* WINELIB 16-bit version */
+/* Winelib 16-bit version */
 LPVOID WINAPI LockResource16( HGLOBAL16 handle )
 {
-#ifndef WINELIB
-    HMODULE16 hModule;
-    NE_MODULE *pModule;
-
-    dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
-    if (!handle) return NULL;
-    hModule = MODULE_HANDLEtoHMODULE16( handle );
-    if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-    if (pModule->flags & NE_FFLAGS_WIN32)
+    if (!__winelib)
     {
-        fprintf(stderr,"LockResource16: %s", NEWin32FailureString);
-        return 0;
+        HMODULE16 hModule;
+        NE_MODULE *pModule;
+
+        dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
+        if (!handle) return NULL;
+        hModule = MODULE_HANDLEtoHMODULE16( handle );
+        if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
+        if (pModule->flags & NE_FFLAGS_WIN32)
+        {
+            fprintf(stderr,"LockResource16: %s", NEWin32FailureString);
+            return 0;
+        }
+        return (LPSTR)PTR_SEG_TO_LIN( NE_LockResource( hModule, handle ) );
     }
-    return (LPSTR)PTR_SEG_TO_LIN( NE_LockResource( hModule, handle ) );
-#else
-    return LIBRES_LockResource( handle );
-#endif
+    else return LIBRES_LockResource( handle );
 }
 
 
@@ -261,23 +259,23 @@ LPVOID WINAPI LockResource32( HGLOBAL32 handle )
  */
 BOOL16 WINAPI FreeResource16( HGLOBAL16 handle )
 {
-#ifndef WINELIB
-    HMODULE16 hModule;
-    NE_MODULE *pModule;
-
-    dprintf_resource(stddeb, "FreeResource16: handle=%04x\n", handle );
-    if (!handle) return FALSE;
-    hModule = MODULE_HANDLEtoHMODULE16( handle );
-    if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-    if (pModule->flags & NE_FFLAGS_WIN32)
+    if (!__winelib)
     {
-        fprintf(stderr,"FreeResource16: %s", NEWin32FailureString);
-        return 0;
+        HMODULE16 hModule;
+        NE_MODULE *pModule;
+
+        dprintf_resource(stddeb, "FreeResource16: handle=%04x\n", handle );
+        if (!handle) return FALSE;
+        hModule = MODULE_HANDLEtoHMODULE16( handle );
+        if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
+        if (pModule->flags & NE_FFLAGS_WIN32)
+        {
+            fprintf(stderr,"FreeResource16: %s", NEWin32FailureString);
+            return 0;
+        }
+        return NE_FreeResource( hModule, handle );
     }
-    return NE_FreeResource( hModule, handle );
-#else
-    return LIBRES_FreeResource( handle );
-#endif
+    else return LIBRES_FreeResource( handle );
 }
 
 /**********************************************************************
@@ -302,16 +300,16 @@ INT16 WINAPI AccessResource16( HINSTANCE16 hModule, HRSRC16 hRsrc )
                      hModule, hRsrc );
     if (!hRsrc) return 0;
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-#ifndef WINELIB
-    if (pModule->flags & NE_FFLAGS_WIN32)
+    if (!__winelib)
     {
-        fprintf(stderr,"AccessResource16: %s", NEWin32FailureString);
-        return 0;
+        if (pModule->flags & NE_FFLAGS_WIN32)
+        {
+            fprintf(stderr,"AccessResource16: %s", NEWin32FailureString);
+            return 0;
+        }
+        return NE_AccessResource( hModule, hRsrc );
     }
-    return NE_AccessResource( hModule, hRsrc );
-#else
-    return LIBRES_AccessResource( hModule, hRsrc );
-#endif
+    else return LIBRES_AccessResource( hModule, hRsrc );
 }
 
 
@@ -340,16 +338,16 @@ DWORD WINAPI SizeofResource16( HMODULE16 hModule, HRSRC16 hRsrc )
     dprintf_resource(stddeb, "SizeofResource16: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-#ifndef WINELIB
-    if (pModule->flags & NE_FFLAGS_WIN32)
+    if (!__winelib)
     {
-        fprintf(stderr,"SizeOfResource16: %s", NEWin32FailureString);
-        return 0;
+        if (pModule->flags & NE_FFLAGS_WIN32)
+        {
+            fprintf(stderr,"SizeOfResource16: %s", NEWin32FailureString);
+            return 0;
+        }
+        return NE_SizeofResource( hModule, hRsrc );
     }
-    return NE_SizeofResource( hModule, hRsrc );
-#else
-    return LIBRES_SizeofResource( hModule, hRsrc );
-#endif
+    else return LIBRES_SizeofResource( hModule, hRsrc );
 }
 
 
@@ -361,12 +359,12 @@ DWORD WINAPI SizeofResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
     hModule = MODULE_HANDLEtoHMODULE32( hModule );
     dprintf_resource(stddeb, "SizeofResource32: module=%04x res=%04x\n",
                      hModule, hRsrc );
-#ifndef WINELIB
-    return PE_SizeofResource32(hModule,hRsrc);
-#else
-    fprintf(stderr,"SizeofResource32: not implemented\n");
-    return 0;
-#endif
+    if (!__winelib) return PE_SizeofResource32(hModule,hRsrc);
+    else
+    {
+        fprintf(stderr,"SizeofResource32: not implemented\n");
+        return 0;
+    }
 }
 
 
@@ -382,16 +380,16 @@ HGLOBAL16 WINAPI AllocResource16( HMODULE16 hModule, HRSRC16 hRsrc, DWORD size)
                      hModule, hRsrc, size );
     if (!hRsrc) return 0;
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-#ifndef WINELIB
-    if (pModule->flags & NE_FFLAGS_WIN32)
+    if (!__winelib)
     {
-        fprintf(stderr,"AllocResource16: %s", NEWin32FailureString);
-        return 0;
+        if (pModule->flags & NE_FFLAGS_WIN32)
+        {
+            fprintf(stderr,"AllocResource16: %s", NEWin32FailureString);
+            return 0;
+        }
+        return NE_AllocResource( hModule, hRsrc, size );
     }
-    return NE_AllocResource( hModule, hRsrc, size );
-#else
-    return LIBRES_AllocResource( hModule, hRsrc, size );
-#endif
+    else return LIBRES_AllocResource( hModule, hRsrc, size );
 }
 
 /**********************************************************************
@@ -471,7 +469,33 @@ HACCEL32 WINAPI LoadAccelerators32A(HINSTANCE32 instance,LPCSTR lpTableName)
 	return result;
 }
 
+/**********************************************************************
+ *             CopyAcceleratorTable32A   (USER32.58)
+ */
+INT32 WINAPI CopyAcceleratorTable32A(HACCEL32 src, LPACCEL32 dst, INT32 entries)
+{
+  fprintf(stderr,"CopyAcceleratorTable32A: not implemented: %d\n", entries);
+  return 0;
+}
+
+/**********************************************************************
+ *             CopyAcceleratorTable32W   (USER32.59)
+ */
+INT32 WINAPI CopyAcceleratorTable32W(HACCEL32 src, LPACCEL32 dst, INT32 entries)
+{
+  fprintf(stderr,"CopyAcceleratorTable32W: not implemented: %d\n", entries);
+  return 0;
+}
 
+/**********************************************************************
+ *             DestroyAcceleratorTable   (USER32.130)
+ */
+BOOL32 WINAPI DestroyAcceleratorTable( HACCEL32 handle )
+{
+  fprintf(stderr,"DestroyAcceleratorTable: not implemented\n");
+  return TRUE;
+}
+  
 /**********************************************************************
  *					LoadString16
  */
diff --git a/loader/task.c b/loader/task.c
index b0c44caddf9..4c5d51ff292 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -65,9 +65,7 @@ BOOL32 TASK_Init(void)
     if (!(hDOSEnvironment = TASK_CreateDOSEnvironment()))
         fprintf( stderr, "Not enough memory for DOS Environment\n" );
     TASK_SystemTHDB.teb_sel = SELECTOR_AllocBlock( &TASK_SystemTHDB, 0x1000, SEGMENT_DATA, TRUE, FALSE );
-#ifdef __i386__
-    __asm__ __volatile__("movw %w0,%%fs"::"r"(TASK_SystemTHDB.teb_sel));
-#endif
+    SET_FS( TASK_SystemTHDB.teb_sel );
     return (hDOSEnvironment != 0);
 }
 
@@ -334,7 +332,6 @@ static BOOL32 TASK_FreeThunk( HTASK16 hTask, SEGPTR thunk )
  * 32-bit entry point for a new task. This function is responsible for
  * setting up the registers and jumping to the 16-bit entry point.
  */
-#ifndef WINELIB
 static void TASK_CallToStart(void)
 {
     int exit_code = 1;
@@ -354,9 +351,7 @@ static void TASK_CallToStart(void)
 
         InitTask( NULL );
         InitApp( pTask->hModule );
-#ifdef __i386__
-        __asm__ __volatile__("movw %w0,%%fs"::"r" (pCurrentThread->teb_sel));
-#endif
+        SET_FS( pCurrentThread->teb_sel );
         PE_InitializeDLLs( pCurrentProcess, DLL_PROCESS_ATTACH, (LPVOID)-1 );
         dprintf_relay( stddeb, "CallTo32(entryproc=%p)\n", entry );
         exit_code = entry();
@@ -398,7 +393,6 @@ static void TASK_CallToStart(void)
         TASK_KillCurrentTask( 1 );
     }
 }
-#endif
 
 
 /***********************************************************************
@@ -415,13 +409,10 @@ HTASK16 TASK_CreateTask( HMODULE16 hModule, HINSTANCE16 hInstance,
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
     LPSTR name;
+    WORD sp;
     char *stack32Top;
     STACK16FRAME *frame16;
     STACK32FRAME *frame32;
-#ifndef WINELIB
-    extern DWORD CALLTO16_RetAddr_regs;
-    extern void CALLTO16_Restore();
-#endif
     
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
     pSegTable = NE_SEG_TABLE( pModule );
@@ -489,10 +480,8 @@ HTASK16 TASK_CreateTask( HMODULE16 hModule, HINSTANCE16 hInstance,
 
     pTask->pdb.int20 = 0x20cd;
     pTask->pdb.dispatcher[0] = 0x9a;  /* ljmp */
-#ifndef WINELIB
-    *(FARPROC16 *)&pTask->pdb.dispatcher[1] = MODULE_GetEntryPoint(
-            GetModuleHandle16("KERNEL"), 102 );  /* KERNEL.102 is DOS3Call() */
-#endif
+    PUT_DWORD(&pTask->pdb.dispatcher[1], (DWORD)MODULE_GetEntryPoint(
+           GetModuleHandle16("KERNEL"), 102 ));  /* KERNEL.102 is DOS3Call() */
     pTask->pdb.savedint22 = INT_GetHandler( 0x22 );
     pTask->pdb.savedint23 = INT_GetHandler( 0x23 );
     pTask->pdb.savedint24 = INT_GetHandler( 0x24 );
@@ -538,11 +527,9 @@ HTASK16 TASK_CreateTask( HMODULE16 hModule, HINSTANCE16 hInstance,
 		pCurrentProcess->exe_modref->pe_module->pe_header->OptionalHeader.AddressOfEntryPoint);
      */
         pTask->thdb = THREAD_Create( pdb32, 0, 0 );
-#ifndef WINELIB
         /* FIXME: should not be done here */
         pCurrentThread = pTask->thdb;
         PE_InitTls( pdb32 );
-#endif
     }
     else
         pTask->thdb = THREAD_Create( pdb32, 0, NULL );
@@ -558,32 +545,26 @@ HTASK16 TASK_CreateTask( HMODULE16 hModule, HINSTANCE16 hInstance,
     frame32->edx = 0;
     frame32->ecx = 0;
     frame32->ebx = 0;
-    frame32->ebp = 0;
-#ifndef WINELIB
-    frame32->restore_addr = (DWORD)CALLTO16_Restore;
     frame32->retaddr = (DWORD)TASK_CallToStart;
-    frame32->codeselector = WINE_CODE_SELECTOR;
-#endif
+    /* The remaining fields will be initialized in TASK_Reschedule */
 
     /* Create the 16-bit stack frame */
 
-    pTask->ss_sp = PTR_SEG_OFF_TO_SEGPTR( hInstance,
-                        ((pModule->sp != 0) ? pModule->sp :
-                pSegTable[pModule->ss-1].minsize + pModule->stack_size) & ~1 );
-    pTask->ss_sp -= sizeof(STACK16FRAME) - sizeof(DWORD) /* for saved %esp */;
+    if (!(sp = pModule->sp))
+        sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
+    sp &= ~1;
+    pTask->ss_sp = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
+    pTask->ss_sp -= sizeof(STACK16FRAME) + sizeof(DWORD) /* for saved %esp */;
     frame16 = (STACK16FRAME *)PTR_SEG_TO_LIN( pTask->ss_sp );
     frame16->saved_ss_sp = 0;
-    frame16->ebp = 0;
+    frame16->ebp = sp + (int)&((STACK16FRAME *)0)->bp;
+    frame16->bp = LOWORD(frame16->ebp);
     frame16->ds = frame16->es = pTask->hInstance;
     frame16->entry_point = 0;
-    frame16->entry_ip = 0;
     frame16->entry_cs = 0;
-    frame16->bp = 0;
+    /* The remaining fields will be initialized in TASK_Reschedule */
+
     *(STACK32FRAME **)(frame16 + 1) = frame32; /* Store the 32-bit %esp */
-#ifndef WINELIB
-    frame16->ip = LOWORD( CALLTO16_RetAddr_regs );
-    frame16->cs = HIWORD( CALLTO16_RetAddr_regs );
-#endif  /* WINELIB */
 
       /* If there's no 16-bit stack yet, use a part of the new task stack */
       /* This is only needed to have a stack to switch from on the first  */
@@ -717,6 +698,7 @@ void TASK_Reschedule(void)
 {
     TDB *pOldTask = NULL, *pNewTask;
     HTASK16 hTask = 0;
+    STACK16FRAME *newframe16;
 
 #ifdef CONFIG_IPC
     dde_reschedule();
@@ -788,6 +770,23 @@ void TASK_Reschedule(void)
     TASK_LinkTask( hTask );
     pNewTask->priority--;
 
+    /* Finish initializing the new task stack if necessary */
+
+    newframe16 = (STACK16FRAME *)PTR_SEG_TO_LIN( pNewTask->ss_sp );
+    if (!newframe16->entry_cs)
+    {
+        STACK16FRAME *oldframe16 = CURRENT_STACK16;
+        STACK32FRAME *oldframe32 = *(STACK32FRAME **)(oldframe16 + 1);
+        STACK32FRAME *newframe32 = *(STACK32FRAME **)(newframe16 + 1);
+        newframe16->entry_ip     = oldframe16->entry_ip;
+        newframe16->entry_cs     = oldframe16->entry_cs;
+        newframe16->ip           = oldframe16->ip;
+        newframe16->cs           = oldframe16->cs;
+        newframe32->ebp          = oldframe32->ebp;
+        newframe32->restore_addr = oldframe32->restore_addr;
+        newframe32->codeselector = oldframe32->codeselector;
+    }
+    
     /* Switch to the new stack */
 
     hCurrentTask = hTask;
diff --git a/memory/Makefile.in b/memory/Makefile.in
index 0214f918b9d..01235a2ebf4 100644
--- a/memory/Makefile.in
+++ b/memory/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/memory/selector.c b/memory/selector.c
index 2966095e94d..5c4777519f0 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -144,16 +144,14 @@ void SELECTOR_FreeBlock( WORD sel, WORD count )
         /* Check if we are freeing current %fs or %gs selector */
 
         WORD fs, gs;
-
-        __asm__("movw %%fs,%w0":"=r" (fs));
+        GET_FS(fs);
         if ((fs >= sel) && (fs < nextsel))
         {
             fprintf( stderr, "SELECTOR_FreeBlock: freeing %%fs selector (%04x), not good.\n", fs );
-            __asm__("movw %w0,%%fs"::"r" (0));
+            SET_FS( 0 );
         }
-        __asm__("movw %%gs,%w0":"=r" (gs));
-        if ((gs >= sel) && (gs < nextsel))
-            __asm__("movw %w0,%%gs"::"r" (0));
+        GET_GS(gs);
+        if ((gs >= sel) && (gs < nextsel)) SET_GS( 0 );
     }
 #endif  /* __i386__ */
 
diff --git a/memory/string.c b/memory/string.c
index 88b72c4f785..969aeee3eb7 100644
--- a/memory/string.c
+++ b/memory/string.c
@@ -12,6 +12,7 @@
 #include "ldt.h"
 #include "stddebug.h"
 #include "debug.h"
+#include "debugstr.h"
 
 static const BYTE STRING_Oem2Ansi[256] =
 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\244"
@@ -77,8 +78,8 @@ SEGPTR WINAPI lstrcat16( SEGPTR dst, LPCSTR src )
  */
 LPSTR WINAPI lstrcat32A( LPSTR dst, LPCSTR src )
 {
-    dprintf_string(stddeb,"strcat: Append '%s' to '%s'\n",
-		 (src)?src:"NULL",(dst)?dst:"NULL");
+    dprintf_string(stddeb,"strcat: Append %s to %s\n",
+		   debugstr_a (src), debugstr_a (dst));
     strcat( dst, src );
     return dst;
 }
@@ -90,6 +91,8 @@ LPSTR WINAPI lstrcat32A( LPSTR dst, LPCSTR src )
 LPWSTR WINAPI lstrcat32W( LPWSTR dst, LPCWSTR src )
 {
     register LPWSTR p = dst;
+    dprintf_string(stddeb,"strcat: Append L%s to L%s\n",
+		   debugstr_w (src), debugstr_w (dst));
     while (*p) p++;
     while ((*p++ = *src++));
     return dst;
@@ -112,8 +115,8 @@ SEGPTR WINAPI lstrcatn16( SEGPTR dst, LPCSTR src, INT16 n )
 LPSTR WINAPI lstrcatn32A( LPSTR dst, LPCSTR src, INT32 n )
 {
     register LPSTR p = dst;
-    dprintf_string(stddeb,"strcatn add %d chars from '%s' to '%s'\n",
-		 n,(src)?src:"NULL",(dst)?dst:"NULL");
+    dprintf_string(stddeb,"strcatn add %d chars from %s to %s\n",
+		   n, debugstr_an (src, n), debugstr_a (dst));
     while (*p) p++;
     if ((n -= (INT32)(p - dst)) <= 0) return dst;
     lstrcpyn32A( p, src, n );
@@ -127,6 +130,8 @@ LPSTR WINAPI lstrcatn32A( LPSTR dst, LPCSTR src, INT32 n )
 LPWSTR WINAPI lstrcatn32W( LPWSTR dst, LPCWSTR src, INT32 n )
 {
     register LPWSTR p = dst;
+    dprintf_string(stddeb,"strcatn add %d chars from L%s to L%s\n",
+		   n, debugstr_wn (src, n), debugstr_w (dst));
     while (*p) p++;
     if ((n -= (INT32)(p - dst)) <= 0) return dst;
     lstrcpyn32W( p, src, n );
@@ -148,14 +153,13 @@ INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
  */
 INT32 WINAPI lstrcmp32A( LPCSTR str1, LPCSTR str2 )
 {
+    dprintf_string(stddeb,"strcmp: %s and %s\n",
+		   debugstr_a (str1), debugstr_a (str2));
     /* Win95 KERNEL32.DLL does it that way. Hands off! */
     if (!str1 || !str2) {
     	SetLastError(ERROR_INVALID_PARAMETER);
 	return 0;
     }
-
-    dprintf_string(stddeb,"strcmp: '%s' and '%s'\n",
-		 (str1)?str1:"NULL",(str2)?str2:"NULL");
     return (INT32)strcmp( str1, str2 );
 }
 
@@ -165,6 +169,8 @@ INT32 WINAPI lstrcmp32A( LPCSTR str1, LPCSTR str2 )
  */
 INT32 WINAPI lstrcmp32W( LPCWSTR str1, LPCWSTR str2 )
 {
+    dprintf_string(stddeb,"strcmp: L%s and L%s\n",
+		   debugstr_w (str1), debugstr_w (str2));
     if (!str1 || !str2) {
     	SetLastError(ERROR_INVALID_PARAMETER);
 	return 0;
@@ -190,12 +196,12 @@ INT32 WINAPI lstrcmpi32A( LPCSTR str1, LPCSTR str2 )
 {
     INT32 res;
 
+    dprintf_string(stddeb,"strcmpi %s and %s\n",
+		   debugstr_a (str1), debugstr_a (str2));
     if (!str1 || !str2) {
     	SetLastError(ERROR_INVALID_PARAMETER);
 	return 0;
     }
-    dprintf_string(stddeb,"strcmpi '%s' and '%s'\n",
-		 (str1)?str1:"NULL",(str2)?str2:"NULL");
     while (*str1)
     {
         if ((res = toupper(*str1) - toupper(*str2)) != 0) return res;
@@ -213,6 +219,11 @@ INT32 WINAPI lstrcmpi32W( LPCWSTR str1, LPCWSTR str2 )
 {
     INT32 res;
 
+#if 0
+    /* Too much!  (From registry loading.)  */
+    dprintf_string(stddeb,"strcmpi L%s and L%s\n",
+		   debugstr_w (str1), debugstr_w (str2));
+#endif
     if (!str1 || !str2) {
     	SetLastError(ERROR_INVALID_PARAMETER);
 	return 0;
@@ -243,8 +254,7 @@ SEGPTR WINAPI lstrcpy16( SEGPTR dst, LPCSTR src )
  */
 LPSTR WINAPI lstrcpy32A( LPSTR dst, LPCSTR src )
 {
-    dprintf_string(stddeb,"strcpy '%s'\n",
-		 (src)?src:"NULL");
+    dprintf_string(stddeb,"strcpy %s\n", debugstr_a (src));
     if (!src || !dst) return NULL;
     strcpy( dst, src );
     return dst;
@@ -257,6 +267,7 @@ LPSTR WINAPI lstrcpy32A( LPSTR dst, LPCSTR src )
 LPWSTR WINAPI lstrcpy32W( LPWSTR dst, LPCWSTR src )
 {
     register LPWSTR p = dst;
+    dprintf_string(stddeb,"strcpy L%s\n", debugstr_w (src));
     while ((*p++ = *src++));
     return dst;
 }
@@ -278,8 +289,8 @@ SEGPTR WINAPI lstrcpyn16( SEGPTR dst, LPCSTR src, INT16 n )
 LPSTR WINAPI lstrcpyn32A( LPSTR dst, LPCSTR src, INT32 n )
 {
     LPSTR p = dst;
-    dprintf_string(stddeb,"strcpyn '%s' for %d chars\n",
-		 (src)?src:"NULL",n);
+    dprintf_string(stddeb,"strcpyn %s for %d chars\n",
+		   debugstr_an (src,n), n);
     while ((n-- > 1) && *src) *p++ = *src++;
     if (n >= 0) *p = 0;
     return dst;
@@ -292,6 +303,8 @@ LPSTR WINAPI lstrcpyn32A( LPSTR dst, LPCSTR src, INT32 n )
 LPWSTR WINAPI lstrcpyn32W( LPWSTR dst, LPCWSTR src, INT32 n )
 {
     LPWSTR p = dst;
+    dprintf_string(stddeb,"strcpyn L%s for %d chars\n",
+		   debugstr_wn (src,n), n);
     while ((n-- > 1) && *src) *p++ = *src++;
     if (n >= 0) *p = 0;
     return dst;
@@ -316,7 +329,7 @@ INT32 WINAPI lstrlen32A( LPCSTR str )
      * in lstrlen() ... we check only for NULL pointer reference.
      * - Marcus Meissner
      */
-    dprintf_string(stddeb,"strlen '%s'\n", (str)?str:"NULL");
+    dprintf_string(stddeb,"strlen %s\n", debugstr_a (str));
     if (!str) return 0;
     return (INT32)strlen(str);
 }
@@ -328,6 +341,7 @@ INT32 WINAPI lstrlen32A( LPCSTR str )
 INT32 WINAPI lstrlen32W( LPCWSTR str )
 {
     INT32 len = 0;
+    dprintf_string(stddeb,"strlen L%s\n", debugstr_w (str));
     if (!str) return 0;
     while (*str++) len++;
     return len;
@@ -339,8 +353,8 @@ INT32 WINAPI lstrlen32W( LPCWSTR str )
  */
 INT32 WINAPI lstrncmp32A( LPCSTR str1, LPCSTR str2, INT32 n )
 {
-    dprintf_string(stddeb,"strncmp '%s' and '%s' for %d chars\n",
-		 (str1)?str1:"NULL",(str2)?str2:"NULL",n);
+    dprintf_string(stddeb,"strncmp %s and %s for %d chars\n",
+		   debugstr_an (str1, n), debugstr_an (str2, n), n);
     return (INT32)strncmp( str1, str2, n );
 }
 
@@ -350,6 +364,8 @@ INT32 WINAPI lstrncmp32A( LPCSTR str1, LPCSTR str2, INT32 n )
  */
 INT32 WINAPI lstrncmp32W( LPCWSTR str1, LPCWSTR str2, INT32 n )
 {
+    dprintf_string(stddeb,"strncmp L%s and L%s for %d chars\n",
+		   debugstr_wn (str1, n), debugstr_wn (str2, n), n);
     if (!n) return 0;
     while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
     return (INT32)(*str1 - *str2);
@@ -363,8 +379,8 @@ INT32 WINAPI lstrncmpi32A( LPCSTR str1, LPCSTR str2, INT32 n )
 {
     INT32 res;
 
-    dprintf_string(stddeb,"strncmpi '%s' and '%s' for %d chars\n",
-		 (str1)?str1:"NULL",(str2)?str2:"NULL",n);
+    dprintf_string(stddeb,"strncmpi %s and %s for %d chars\n",
+		   debugstr_an (str1, n), debugstr_an (str2, n), n);
     if (!n) return 0;
     while ((--n > 0) && *str1)
       if ( (res = toupper(*str1++) - toupper(*str2++)) ) return res;
@@ -380,6 +396,8 @@ INT32 WINAPI lstrncmpi32W( LPCWSTR str1, LPCWSTR str2, INT32 n )
 {
     INT32 res;
 
+    dprintf_string(stddeb,"strncmpi L%s and L%s for %d chars\n",
+		   debugstr_wn (str1, n), debugstr_wn (str2, n), n);
     if (!n) return 0;
     while ((--n > 0) && *str1)
     {
@@ -517,10 +535,11 @@ void WINAPI OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len )
  */
 BOOL32 WINAPI CharToOem32A( LPCSTR s, LPSTR d )
 {
+    LPSTR oldd = d;
     if (!s || !d) return TRUE;
-    dprintf_string(stddeb,"CharToOem '%s'\n", (s)?s:"NULL");
+    dprintf_string (stddeb,"CharToOem %s\n", debugstr_a (s));
     while ((*d++ = ANSI_TO_OEM(*s++)));
-    dprintf_string(stddeb," to '%s'\n", (d)?d:"NULL");
+    dprintf_string (stddeb,"       to %s\n", debugstr_a (oldd));
     return TRUE;
 }
 
@@ -550,7 +569,11 @@ BOOL32 WINAPI CharToOemBuff32W( LPCWSTR s, LPSTR d, DWORD len )
  */
 BOOL32 WINAPI CharToOem32W( LPCWSTR s, LPSTR d )
 {
+    LPSTR oldd = d;
+    if (!s || !d) return TRUE;
+    dprintf_string (stddeb,"CharToOem L%s\n", debugstr_w (s));
     while ((*d++ = ANSI_TO_OEM(*s++)));
+    dprintf_string (stddeb,"       to %s\n", debugstr_a (oldd));
     return TRUE;
 }
 
@@ -561,9 +584,9 @@ BOOL32 WINAPI CharToOem32W( LPCWSTR s, LPSTR d )
 BOOL32 WINAPI OemToChar32A( LPCSTR s, LPSTR d )
 {
     LPSTR oldd = d;
-    dprintf_string(stddeb,"OemToChar '%s'\n", (s)?s:"NULL");
+    dprintf_string(stddeb,"OemToChar %s\n", debugstr_a (s));
     while ((*d++ = OEM_TO_ANSI(*s++)));
-    dprintf_string(stddeb," to '%s'\n", oldd);
+    dprintf_string(stddeb,"       to %s\n", debugstr_a (oldd));
     return TRUE;
 }
 
@@ -573,7 +596,7 @@ BOOL32 WINAPI OemToChar32A( LPCSTR s, LPSTR d )
  */
 BOOL32 WINAPI OemToCharBuff32A( LPCSTR s, LPSTR d, DWORD len )
 {
-    dprintf_string(stddeb,"OemToCharBuff '%s' for %ld chars\n", (s)?s:"NULL",len);
+    dprintf_string(stddeb,"OemToCharBuff %s\n", debugstr_an (s, len));
     while (len--) *d++ = OEM_TO_ANSI(*s++);
     return TRUE;
 }
@@ -584,6 +607,7 @@ BOOL32 WINAPI OemToCharBuff32A( LPCSTR s, LPSTR d, DWORD len )
  */
 BOOL32 WINAPI OemToCharBuff32W( LPCSTR s, LPWSTR d, DWORD len )
 {
+    dprintf_string(stddeb,"OemToCharBuff %s\n", debugstr_an (s, len));
     while (len--) *d++ = (WCHAR)OEM_TO_ANSI(*s++);
     return TRUE;
 }
diff --git a/misc/Makefile.in b/misc/Makefile.in
index 1038b9319c8..9a5b752ad31 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
@@ -14,6 +14,7 @@ C_SRCS = \
 	crtdll.c \
 	cpu.c \
 	ddeml.c \
+	debugstr.c \
 	error.c \
 	lstr.c \
 	lzexpand.c \
@@ -37,6 +38,7 @@ C_SRCS = \
 	toolhelp.c \
 	tweak.c \
 	ver.c \
+	version.c \
 	w32sys.c \
 	winsock.c \
 	winsock_dns.c \
diff --git a/misc/callback.c b/misc/callback.c
index d8e90814cb7..c379a90e949 100644
--- a/misc/callback.c
+++ b/misc/callback.c
@@ -132,6 +132,7 @@ static const CALLBACKS_TABLE CALLBACK_WinelibTable =
 {
     CALLBACK_CallRegisterProc,     /* CallRegisterProc */
     TASK_Reschedule,               /* CallTaskRescheduleProc */
+    NULL,                          /* CallFrom16WndProc */
     CALLBACK_CallWndProc,          /* CallWndProc */
     CALLBACK_CallDriverProc,       /* CallDriverProc */
     CALLBACK_CallDriverCallback,   /* CallDriverCallback */
diff --git a/misc/ddeml.c b/misc/ddeml.c
index 823265ec2b9..b430475dcfe 100644
--- a/misc/ddeml.c
+++ b/misc/ddeml.c
@@ -2,6 +2,7 @@
  * DDEML library
  *
  * Copyright 1997 Alexandre Julliard
+ * Copyright 1997 Len White
  */
 
 /* Only empty stubs for now */
@@ -63,6 +64,33 @@ BOOL32 WINAPI DdeUninitialize32( DWORD idInst )
     return TRUE;
 }
 
+/*****************************************************************
+ *            DdeConnectList (DDEML.4)
+ */
+HCONVLIST WINAPI DdeConnectList( DWORD idInst, HSZ hszService, HSZ hszTopic,
+        HCONVLIST hConvList, LPCONVCONTEXT16 pCC )
+{
+    fprintf( stdnimp, "DdeConnectList: empty stub\n" );
+    return 0;
+}
+
+/*****************************************************************
+ *            DdeQueryNextServer (DDEML.5)
+ */
+HCONV WINAPI DdeQueryNextServer( HCONVLIST hConvList, HCONV hConvPrev )
+{
+    fprintf( stdnimp, "DdeQueryNextServer: empty stub\n" );
+    return 0;
+}
+
+/*****************************************************************
+ *            DdeDisconnectList (DDEML.6)
+ */
+BOOL16 WINAPI DdeDisconnectList( HCONVLIST hConvList )
+{
+    fprintf( stdnimp, "DdeDisconnectList: empty stub\n" );
+    return 0;
+}
 
 /*****************************************************************
  *            DdeConnect16   (DDEML.7)
@@ -94,6 +122,23 @@ BOOL16 WINAPI DdeDisconnect16( HCONV hConv )
     return (BOOL16)DdeDisconnect32( hConv );
 }
 
+/*****************************************************************
+ *            DdeSetUserHandle (DDEML.10)
+ */
+BOOL16 WINAPI DdeSetUserHandle( HCONV hConv, DWORD id, DWORD hUser )
+{
+    fprintf( stdnimp, "DdeSetUserHandle: empty stub\n" );
+    return 0;
+}
+
+/*****************************************************************
+ *            DdeCreateDataHandle (DDEML.14)
+ */
+HDDEDATA WINAPI DdeCreateDataHandle( DWORD idInst, LPBYTE pSrc, DWORD cb, DWORD cbOff, HSZ hszItem, UINT16 wFmt, UINT16 afCmd )
+{
+    fprintf( stdnimp, "DdeCreateDataHandle: empty stub\n" );
+    return 0;
+}
 
 /*****************************************************************
  *            DdeDisconnect32   (USER32.97)
@@ -226,6 +271,71 @@ HDDEDATA WINAPI DdeClientTransaction32( LPBYTE pData, DWORD cbData,
     return 0;
 }
 
+/*****************************************************************
+ *            DdeAbandonTransaction (DDEML.12)
+ */
+BOOL16 WINAPI DdeAbandonTransaction( DWORD idInst, HCONV hConv, 
+                                     DWORD idTransaction )
+{
+    fprintf( stdnimp, "DdeAbandonTransaction: empty stub\n" );
+    return 0;
+}
+
+/*****************************************************************
+ *            DdePostAdvise (DDEML.13)
+ */
+BOOL16 WINAPI DdePostAdvise( DWORD idInst, HSZ hszTopic, HSZ hszItem )
+{
+    fprintf( stdnimp, "DdePostAdvise: empty stub\n" );
+    return 0;
+}
+
+/*****************************************************************
+ *            DdeAddData (DDEML.15)
+ */
+HDDEDATA WINAPI DdeAddData( HDDEDATA hData, LPBYTE pSrc, DWORD cb,
+                            DWORD cbOff )
+{
+    fprintf( stdnimp, "DdeAddData: empty stub\n" );
+    return 0;
+}
+
+/*****************************************************************
+ *            DdeGetData (DDEML.16)
+ */
+DWORD WINAPI DdeGetData( HDDEDATA hData, LPBYTE pDst, DWORD cbMax, 
+                         DWORD cbOff )
+{
+    fprintf( stdnimp, "DdeGetData: empty stub\n" );
+    return 0;
+}
+
+/*****************************************************************
+ *            DdeAccessData (DDEML.17)
+ */
+LPBYTE WINAPI DdeAccessData( HDDEDATA hData, LPDWORD pcbDataSize )
+{
+     fprintf( stdnimp, "DdeAccessData: empty stub\n" );
+     return 0;
+}
+
+/*****************************************************************
+ *            DdeUnaccessData (DDEML.18)
+ */
+BOOL16 WINAPI DdeUnaccessData( HDDEDATA hData )
+{
+     fprintf( stdnimp, "DdeUnaccessData: empty stub\n" );
+     return 0;
+}
+
+/*****************************************************************
+ *            DdeEnableCallback (DDEML.26)
+ */
+BOOL16 WINAPI DdeEnableCallback( DWORD idInst, HCONV hConv, UINT16 wCmd )
+{
+     fprintf( stdnimp, "DdeEnableCallback: empty stub\n" );
+     return 0;
+}
 
 /*****************************************************************
  *            DdeNameService16  (DDEML.27)
@@ -266,3 +376,14 @@ UINT32 WINAPI DdeGetLastError32( DWORD idInst )
     return 0;
 }
 
+/*****************************************************************
+ *            DdeCmpStringHandles (DDEML.36)
+ */
+int WINAPI DdeCmpStringHandles( HSZ hsz1, HSZ hsz2 )
+{
+     fprintf( stdnimp, "DdeCmpStringHandles: empty stub\n" );
+     return 0;
+}
+
+
+
diff --git a/misc/debugstr.c b/misc/debugstr.c
new file mode 100644
index 00000000000..2ef4649b0d5
--- /dev/null
+++ b/misc/debugstr.c
@@ -0,0 +1,127 @@
+#include "debugstr.h"
+#include "xmalloc.h"
+#include <stdlib.h>
+
+/* ---------------------------------------------------------------------- */
+
+#define SAVE_STRING_COUNT 50
+static void *strings[SAVE_STRING_COUNT];
+static int nextstring;
+
+/* ---------------------------------------------------------------------- */
+
+static void *
+gimme1 (int n)
+{
+  void *res;
+  if (strings[nextstring]) free (strings[nextstring]);
+  res = strings[nextstring] = xmalloc (n);
+  if (++nextstring == SAVE_STRING_COUNT) nextstring = 0;
+  return res;
+}
+
+/* ---------------------------------------------------------------------- */
+
+LPSTR
+debugstr_an (LPCSTR src, int n)
+{
+  LPSTR dst, res;
+
+  if (!src) return "(null)";
+  if (n < 0) n = 0;
+  dst = res = gimme1 (n * 4 + 10);
+  *dst++ = '"';
+  while (n-- > 0 && *src)
+    {
+      BYTE c = *src++;
+      switch (c)
+	{
+	case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
+	case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
+	case '\t': *dst++ = '\\'; *dst++ = 't'; break;
+	case '"': *dst++ = '\\'; *dst++ = '"'; break;
+	case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
+	default:
+	  if (c >= ' ' && c <= 126)
+	    *dst++ = c;
+	  else
+	    {
+	      *dst++ = '\\';
+	      *dst++ = '0' + ((c >> 6) & 7);
+	      *dst++ = '0' + ((c >> 3) & 7);
+	      *dst++ = '0' + ((c >> 0) & 7);
+	    }
+	}
+    }
+  if (*src)
+    {
+      *dst++ = '.';
+      *dst++ = '.';
+      *dst++ = '.';
+    }
+  *dst++ = '"';
+  *dst = 0;
+  return res;
+}
+
+/* ---------------------------------------------------------------------- */
+
+LPSTR
+debugstr_a (LPCSTR s)
+{
+  return debugstr_an (s, 80);
+}
+
+/* ---------------------------------------------------------------------- */
+
+LPSTR
+debugstr_wn (LPCWSTR src, int n)
+{
+  LPSTR dst, res;
+
+  if (!src) return "(null)";
+  if (n < 0) n = 0;
+  dst = res = gimme1 (n * 4 + 10);
+  *dst++ = '"';
+  while (n-- > 0 && *src)
+    {
+      WORD c = *src++;
+      switch (c)
+	{
+	case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
+	case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
+	case '\t': *dst++ = '\\'; *dst++ = 't'; break;
+	case '"': *dst++ = '\\'; *dst++ = '"'; break;
+	case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
+	default:
+	  if (c >= ' ' && c <= 126)
+	    *dst++ = c;
+	  else
+	    {
+	      *dst++ = '\\';
+	      *dst++ = '0' + ((c >> 6) & 7);
+	      *dst++ = '0' + ((c >> 3) & 7);
+	      *dst++ = '0' + ((c >> 0) & 7);
+	    }
+	}
+    }
+  if (*src)
+    {
+      *dst++ = '.';
+      *dst++ = '.';
+      *dst++ = '.';
+    }
+  *dst++ = '"';
+  *dst = 0;
+  return res;
+}
+
+/* ---------------------------------------------------------------------- */
+
+LPSTR
+debugstr_w (LPCWSTR s)
+{
+  return debugstr_wn (s, 80);
+}
+
+/* ---------------------------------------------------------------------- */
diff --git a/misc/main.c b/misc/main.c
index 67c037c69b7..14049055815 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -20,138 +20,21 @@
 #include <X11/cursorfont.h>
 #include "heap.h"
 #include "message.h"
-#include "module.h"
 #include "msdos.h"
 #include "windows.h"
 #include "color.h"
 #include "winsock.h"
 #include "options.h"
 #include "desktop.h"
+#include "process.h"
 #include "shell.h"
 #include "winbase.h"
 #define DEBUG_DEFINE_VARIABLES
 #include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
+#include "version.h"
 
-const char people[] = "Wine is available thanks to the work of "
-"Bob Amstadt, "
-"Dag Asheim, "
-"Martin Ayotte, "
-"Peter Bajusz, "
-"Georg Beyerle, "
-"Ross Biro, "
-"Uwe Bonnes, "
-"Erik Bos, "
-"Fons Botman, "
-"John Brezak, "
-"Andrew Bulhak, "
-"John Burton, "
-"Niels de Carpentier, "
-"Jimen Ching, "
-"David A. Cuthbert, "
-"Huw D. M. Davies, "
-"Roman Dolejsi, "
-"Frans van Dorsselaer, "
-"Chris Faherty, "
-"Paul Falstad, "
-"David Faure, "
-"Claus Fischer, "
-"Olaf Flebbe, "
-"Chad Fraleigh, "
-"Peter Galbavy, "
-"Ramon Garcia, "
-"Matthew Ghio, "
-"Jody Goldberg, "
-"Hans de Graaff, "
-"Charles M. Hannum, "
-"Adrian Harvey, "
-"John Harvey, "
-"Cameron Heide, "
-"Jochen Hoenicke, "
-"Onno Hovers, "
-"Jeffrey Hsu, "
-"Miguel de Icaza, "
-"Jukka Iivonen, "
-"Lee Jaekil, "
-"Alexandre Julliard, "
-"Bang Jun-Young, "
-"Pavel Kankovsky, "
-"Jochen Karrer, "
-"Andreas Kirschbaum, "
-"Albrecht Kleine, "
-"Jon Konrath, "
-"Alex Korobka, "
-"Greg Kreider, "
-"Anand Kumria, "
-"Scott A. Laird, "
-"Andrew Lewycky, "
-"Martin von Loewis, "
-"Michiel van Loon, "
-"Kenneth MacDonald, "
-"Peter MacDonald, "
-"William Magro, "
-"Juergen Marquardt, "
-"Ricardo Massaro, "
-"Marcus Meissner, "
-"Graham Menhennitt, "
-"David Metcalfe, "
-"Bruce Milner, "
-"Steffen Moeller, "
-"Andreas Mohr, "
-"Philippe De Muyter, "
-"Itai Nahshon, "
-"Henrik Olsen, "
-"Michael Patra, "
-"Dimitrie O. Paun, "
-"Jim Peterson, "
-"Robert Pouliot, "
-"Keith Reynolds, "
-"Slaven Rezic, "
-"John Richardson, "
-"Rick Richardson, "
-"Doug Ridgway, "
-"Bernhard Rosenkraenzer, "
-"Johannes Ruscheinski, "
-"Thomas Sandford, "
-"Constantine Sapuntzakis, "
-"Pablo Saratxaga, "
-"Daniel Schepler, "
-"Peter Schlaile, "
-"Ulrich Schmid, "
-"Bernd Schmidt, "
-"Ingo Schneider, "
-"Victor Schneider, "
-"Yngvi Sigurjonsson, "
-"Stephen Simmons, "
-"Rick Sladkey, "
-"William Smith, "
-"Dominik Strasser, "
-"Vadim Strizhevsky, "
-"Erik Svendsen, "
-"Tristan Tarrant, "
-"Andrew Taylor, "
-"Duncan C Thomson, "
-"Goran Thyni, "
-"Jimmy Tirtawangsa, "
-"Jon Tombs, "
-"Linus Torvalds, "
-"Gregory Trubetskoy, "
-"Petri Tuomola, "
-"Michael Veksler, "
-"Sven Verdoolaege, "
-"Ronan Waide, "
-"Eric Warnke, "
-"Manfred Weichel, "
-"Morten Welinder, "
-"Lawson Whitney, "
-"Jan Willamowius, "
-"Carl Williams, "
-"Karl Guenter Wuensch, "
-"Eric Youngdale, "
-"James Youngman, "
-"Mikolaj Zalewski, "
-"and John Zero.";
 
 const WINE_LANGUAGE_DEF Languages[] =
 {
@@ -183,19 +66,13 @@ Screen *screen;
 Window rootWindow;
 int screenWidth = 0, screenHeight = 0;  /* Desktop window dimensions */
 int screenDepth = 0;  /* Screen depth to use */
-int desktopX = 0, desktopY = 0;  /* Desktop window position (if any) */
-
-/* Default version is the same as -winver win31 */
-static LONG getVersion16 = MAKELONG( WINVERSION, 0x0616 ); /* DOS 6.22 */
-static LONG getVersion32 = MAKELONG( WINVERSION, 0x8000 );
-static OSVERSIONINFO32A getVersionEx = { sizeof(OSVERSIONINFO32A), 3, 10, 0,
-                                         VER_PLATFORM_WIN32s, "Win32s 1.3" };
 
 struct options Options =
 {  /* default options */
     NULL,           /* desktopGeometry */
     NULL,           /* programName */
     NULL,           /* argv0 */
+    NULL,           /* dllFlags */
     FALSE,          /* usePrivateMap */
     FALSE,          /* useFixedMap */
     FALSE,          /* synchronous */
@@ -262,20 +139,19 @@ static XrmOptionDescRec optionsTable[] =
   "    -perfect        Favor correctness over speed for graphical operations\n" \
   "    -privatemap     Use a private color map\n" \
   "    -synchronous    Turn on synchronous display mode\n" \
-  "    -winver         Version to imitate (one of win31,win95,nt351)\n"
+  "    -version        Display the Wine version\n" \
+  "    -winver         Version to imitate (one of win31,win95,nt351,nt40)\n"
 
 
 
 /***********************************************************************
  *           MAIN_Usage
  */
-#ifndef WINELIB32
 void MAIN_Usage( char *name )
 {
     fprintf( stderr, USAGE, name );
     exit(1);
 }
-#endif
 
 
 /***********************************************************************
@@ -375,7 +251,6 @@ BOOL32 ParseDebugOptions(char *options)
 
 #endif
 
-
 /***********************************************************************
  *           MAIN_ParseLanguageOption
  *
@@ -419,48 +294,6 @@ static void MAIN_ParseModeOption( char *arg )
     }
 }
 
-/**********************************************************************
- *           MAIN_ParseVersion
- */
-static void MAIN_ParseVersion( char *arg )
-{
-    /* If you add any other options, 
-       verify the values you return on the real thing */
-    if(strcmp(arg,"win31")==0) 
-    {
-        getVersion16 = 0x06160A03;
-        /* FIXME: My Win32s installation failed to execute the
-           MSVC 4 test program. So check these values */
-        getVersion32 = 0x80000A03;
-        getVersionEx.dwMajorVersion=3;
-        getVersionEx.dwMinorVersion=10;
-        getVersionEx.dwBuildNumber=0;
-        getVersionEx.dwPlatformId=VER_PLATFORM_WIN32s;
-        strcpy(getVersionEx.szCSDVersion,"Win32s 1.3");
-    }
-    else if(strcmp(arg, "win95")==0)
-    {
-        getVersion16 = 0x07005F03;
-        getVersion32 = 0xC0000004;
-        getVersionEx.dwMajorVersion=4;
-        getVersionEx.dwMinorVersion=0;
-        getVersionEx.dwBuildNumber=0x40003B6;
-        getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS;
-        strcpy(getVersionEx.szCSDVersion,"");
-    }
-    else if(strcmp(arg, "nt351")==0)
-    {
-        getVersion16 = 0x05000A03;
-        getVersion32 = 0x04213303;
-        getVersionEx.dwMajorVersion=3;
-        getVersionEx.dwMinorVersion=51;
-        getVersionEx.dwBuildNumber=0x421;
-        getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_NT;
-        strcpy(getVersionEx.szCSDVersion,"Service Pack 2");
-    }
-    else fprintf(stderr, "Unknown winver system code - ignored\n");
-}
-
 /***********************************************************************
  *           MAIN_ParseOptions
  *
@@ -478,19 +311,15 @@ static void MAIN_ParseOptions( int *argc, char *argv[] )
     Options.argv0 = argv[0];
 
       /* Get display name from command line */
-    for (i = 1; i < *argc - 1; i++)
-        if (!strcmp( argv[i], "-display" ))
-	{
-	    display_name = argv[i+1];
-	    break;
+    for (i = 1; i < *argc; i++)
+    {
+        if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
+        if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
+        {
+            printf( "%s\n", WINE_RELEASE_INFO );
+            exit(0);
         }
-
-#ifdef WINELIB
-    /* Need to assemble command line and pass it to WinMain */
-#else
-    if (*argc < 2 || lstrcmpi32A(argv[1], "-h") == 0) 
-    	MAIN_Usage( argv[0] );
-#endif
+    }
 
       /* Open display */
 
@@ -574,24 +403,20 @@ static void MAIN_ParseOptions( int *argc, char *argv[] )
 #endif
       }
 
-      if(MAIN_GetResource( db, ".dll", &value))
+      if (MAIN_GetResource( db, ".dll", &value))
       {
-#ifndef WINELIB
-          if (!BUILTIN_ParseDLLOptions( (char*)value.addr ))
+          /* Hack: store option value in Options to be retrieved */
+          /* later on inside the emulator code. */
+          if (!__winelib) Options.dllFlags = xstrdup((char *)value.addr);
+          else
           {
-              fprintf(stderr,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv[0]);
-              fprintf(stderr,"Example: -dll -ole2    Do not use emulated OLE2.DLL\n");
-              fprintf(stderr,"Available DLLs:\n");
-              BUILTIN_PrintDLLs();
+              fprintf( stderr, "-dll not supported in Winelib\n" );
               exit(1);
           }
-#else
-          fprintf(stderr,"-dll not supported in libwine\n");
-#endif
       }
 
-      if(MAIN_GetResource( db, ".winver", &value))
-          MAIN_ParseVersion( (char*)value.addr );
+      if (MAIN_GetResource( db, ".winver", &value))
+          VERSION_ParseVersion( (char*)value.addr );
 }
 
 
@@ -600,7 +425,7 @@ static void MAIN_ParseOptions( int *argc, char *argv[] )
  */
 static void MAIN_CreateDesktop( int argc, char *argv[] )
 {
-    int flags;
+    int x, y, flags;
     unsigned int width = 640, height = 480;  /* Default size = 640x480 */
     char *name = "Wine desktop";
     XSizeHints *size_hints;
@@ -610,8 +435,7 @@ static void MAIN_CreateDesktop( int argc, char *argv[] )
     XTextProperty window_name;
     Atom XA_WM_DELETE_WINDOW;
 
-    flags = XParseGeometry( Options.desktopGeometry,
-			    &desktopX, &desktopY, &width, &height );
+    flags = XParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
     screenWidth  = width;
     screenHeight = height;
 
@@ -619,12 +443,11 @@ static void MAIN_CreateDesktop( int argc, char *argv[] )
 
     win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
 	                 PointerMotionMask | ButtonPressMask |
-			 ButtonReleaseMask | EnterWindowMask | 
-			 StructureNotifyMask;
+			 ButtonReleaseMask | EnterWindowMask;
     win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
 
     rootWindow = XCreateWindow( display, DefaultRootWindow(display),
-			        desktopX, desktopY, width, height, 0,
+			        x, y, width, height, 0,
 			        CopyFromParent, InputOutput, CopyFromParent,
 			        CWEventMask | CWCursor, &win_attr );
 
@@ -806,99 +629,6 @@ BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
 }
 
 
-/***********************************************************************
- *      GetVersion16   (KERNEL.3)
- */
-LONG WINAPI GetVersion16(void)
-{
-    return getVersion16;
-}
-
-
-/***********************************************************************
- *      GetVersion32   (KERNEL32.427)
- */
-LONG WINAPI GetVersion32(void)
-{
-    return getVersion32;
-}
-
-
-/***********************************************************************
- *      GetVersionExA
- */
-BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
-{
-    if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32A))
-    {
-        fprintf(stddeb,"wrong OSVERSIONINFO size from app");
-        return FALSE;
-    }
-    v->dwMajorVersion = getVersionEx.dwMajorVersion;
-    v->dwMinorVersion = getVersionEx.dwMinorVersion;
-    v->dwBuildNumber = getVersionEx.dwBuildNumber;
-    v->dwPlatformId = getVersionEx.dwPlatformId;
-    strcpy(v->szCSDVersion, getVersionEx.szCSDVersion);
-    return TRUE;
-}
-
-
-/***********************************************************************
- *     GetVersionExW
- */
-BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
-{
-	OSVERSIONINFO32A v1;
-	if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
-	{
-		fprintf(stddeb,"wrong OSVERSIONINFO size from app");
-		return FALSE;
-	}
-	v1.dwOSVersionInfoSize=sizeof(v1);
-	GetVersionEx32A(&v1);
-	v->dwMajorVersion = v1.dwMajorVersion;
-	v->dwMinorVersion = v1.dwMinorVersion;
-	v->dwBuildNumber = v1.dwBuildNumber;
-	v->dwPlatformId = v1.dwPlatformId;
-        lstrcpyAtoW( v->szCSDVersion, v1.szCSDVersion );
-	return TRUE;
-}
-
-/***********************************************************************
- *	GetWinFlags (KERNEL.132)
- */
-DWORD WINAPI GetWinFlags(void)
-{
-  static const long cpuflags[5] =
-    { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
-  SYSTEM_INFO	si;
-  long result = 0,cpuflag;
-
-  GetSystemInfo(&si);
-
-  /* There doesn't seem to be any Pentium flag.  */
-  cpuflag = cpuflags[MIN (si.wProcessorLevel, 4)];
-
-  switch(Options.mode) {
-  case MODE_STANDARD:
-    result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
-    break;
-
-  case MODE_ENHANCED:
-    result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
-    break;
-
-  default:
-    fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
-    break;
-  }
-  if (si.wProcessorLevel>=4)
-      result |= WF_HASCPUID;
-  if( getVersionEx.dwPlatformId == VER_PLATFORM_WIN32_NT )
-      result |= WF_WIN32WOW; /* undocumented WF_WINNT */
-  return result;
-}
-
 /***********************************************************************
  *	GetTimerResolution (USER.14)
  */
@@ -1302,27 +1032,3 @@ void WINAPI FileCDR(FARPROC16 x)
 {
 	printf("FileCDR(%8x)\n", (int) x);
 }
-
-/***********************************************************************
-*	GetWinDebugInfo (KERNEL.355)
-*/
-BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
-{
-	printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
-	/* 0 means not in debugging mode/version */
-	/* Can this type of debugging be used in wine ? */
-	/* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
-	return 0;
-}
-
-/***********************************************************************
-*	GetWinDebugInfo (KERNEL.355)
-*/
-BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
-{
-	printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
-	/* 0 means not in debugging mode/version */
-	/* Can this type of debugging be used in wine ? */
-	/* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
-	return 0;
-}
diff --git a/misc/ole2nls.c b/misc/ole2nls.c
index 5264c464386..6f1810010ff 100644
--- a/misc/ole2nls.c
+++ b/misc/ole2nls.c
@@ -2112,7 +2112,7 @@ INT32 WINAPI LCMapString32W(
 INT32 WINAPI GetDateFormat32A(LCID locale,DWORD flags,LPSYSTEMTIME xtime,
 			      LPCSTR format, LPSTR date,INT32 datelen
 ) {
-	fprintf(stderr,"GetDateFormat(0x%04x,0x%08lx,%p,%s,%p,%d), stub\n",
+	fprintf(stderr,"GetDateFormat(0x%04lx,0x%08lx,%p,%s,%p,%d), stub\n",
 		locale,flags,xtime,format,date,datelen
 	);
 	lstrcpyn32A(date,"1.4.1997",datelen);
@@ -2122,7 +2122,7 @@ INT32 WINAPI GetDateFormat32A(LCID locale,DWORD flags,LPSYSTEMTIME xtime,
 INT32 WINAPI GetTimeFormat32A(LCID locale,DWORD flags,LPSYSTEMTIME xtime,
 			      LPCSTR format, LPSTR timestr,INT32 timelen
 ) {
-	fprintf(stderr,"GetDateFormat(0x%04x,0x%08lx,%p,%s,%p,%d), stub\n",
+	fprintf(stderr,"GetDateFormat(0x%04lx,0x%08lx,%p,%s,%p,%d), stub\n",
 		locale,flags,xtime,format,timestr,timelen
 	);
 	lstrcpyn32A(timestr,"00:00:42",timelen);
diff --git a/misc/registry.c b/misc/registry.c
index a2c47b08e5c..3cddd698b1a 100644
--- a/misc/registry.c
+++ b/misc/registry.c
@@ -1054,17 +1054,27 @@ _w95dkecomp(struct _w95nr2da *a,struct _w95nr2da *b){return a->dkeaddr-b->dkeadd
 
 static struct _w95key*
 _w95dkelookup(unsigned long dkeaddr,int n,struct _w95nr2da *nr2da,struct _w95key *keys) {
-	int	i,off;
+	int	i;
+        int     left, right;
 
 	if (dkeaddr == 0xFFFFFFFF)
 		return NULL;
 	if (dkeaddr<0x20)
 		return NULL;
 	dkeaddr=_w95_adj_da(dkeaddr+0x1c);
-	off = (dkeaddr-0x3c)/0x1c;
-	for (i=0;i<n;i++)
-		if (nr2da[(i+off)%n].dkeaddr == dkeaddr)
-			return keys+nr2da[(i+off)%n].nr;
+        left=0;
+        right=n-1;
+        while(left<=right)
+        {
+           i=(left+right)/2;
+           
+           if(nr2da[i].dkeaddr == dkeaddr)
+              return keys+nr2da[i].nr;
+           else if(nr2da[i].dkeaddr < dkeaddr)
+              left=i+1;
+           else
+              right=i-1;
+        }
 	/* 0x3C happens often, just report unusual values */
 	if (dkeaddr!=0x3c)
 		dprintf_reg(stddeb,"search hasn't found dkeaddr %lx?\n",dkeaddr);
@@ -2759,23 +2769,30 @@ DWORD WINAPI RegDeleteKey32W(HKEY hkey,LPWSTR lpszSubKey) {
 		hkey,W2C(lpszSubKey,0)
 	);
 	lpNextKey	= lookup_hkey(hkey);
-	if (!lpNextKey)
+	if (!lpNextKey) {
+		dprintf_reg (stddeb, "  Badkey[1].\n");
 		return SHELL_ERROR_BADKEY;
+	}
 	/* we need to know the previous key in the hier. */
-	if (!lpszSubKey || !*lpszSubKey)
+	if (!lpszSubKey || !*lpszSubKey) {
+		dprintf_reg (stddeb, "  Badkey[2].\n");
 		return SHELL_ERROR_BADKEY;
+	}
 	split_keypath(lpszSubKey,&wps,&wpc);
 	i 	= 0;
 	lpxkey	= lpNextKey;
 	while (i<wpc-1) {
 		lpxkey=lpNextKey->nextsub;
 		while (lpxkey) {
+			dprintf_reg (stddeb, "  Scanning [%s]\n",
+				     W2C (lpxkey->keyname, 0));
 			if (!lstrcmpi32W(wps[i],lpxkey->keyname))
 				break;
 			lpxkey=lpxkey->next;
 		}
 		if (!lpxkey) {
 			FREE_KEY_PATH;
+			dprintf_reg (stddeb, "  Not found.\n");
 			/* not found is success */
 			return SHELL_ERROR_SUCCESS;
 		}
@@ -2785,15 +2802,24 @@ DWORD WINAPI RegDeleteKey32W(HKEY hkey,LPWSTR lpszSubKey) {
 	lpxkey	= lpNextKey->nextsub;
 	lplpPrevKey = &(lpNextKey->nextsub);
 	while (lpxkey) {
+		dprintf_reg (stddeb, "  Scanning [%s]\n",
+			     W2C (lpxkey->keyname, 0));
 		if (!lstrcmpi32W(wps[i],lpxkey->keyname))
 			break;
 		lplpPrevKey	= &(lpxkey->next);
 		lpxkey		= lpxkey->next;
 	}
-	if (!lpxkey)
+	if (!lpxkey) {
+		FREE_KEY_PATH;
+		dprintf_reg (stddeb, "  Not found.\n");
+		return SHELL_ERROR_BADKEY;
 		return SHELL_ERROR_SUCCESS;
-	if (lpxkey->nextsub)
+	}
+	if (lpxkey->nextsub) {
+		FREE_KEY_PATH;
+		dprintf_reg (stddeb, "  Not empty.\n");
 		return SHELL_ERROR_CANTWRITE;
+	}
 	*lplpPrevKey	= lpxkey->next;
 	free(lpxkey->keyname);
 	if (lpxkey->class)
@@ -2802,6 +2828,7 @@ DWORD WINAPI RegDeleteKey32W(HKEY hkey,LPWSTR lpszSubKey) {
 		free(lpxkey->values);
 	free(lpxkey);
 	FREE_KEY_PATH;
+	dprintf_reg (stddeb, "  Done.\n");
 	return	SHELL_ERROR_SUCCESS;
 }
 
diff --git a/misc/shell.c b/misc/shell.c
index 0de6093fc5c..a824ab06c19 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -15,11 +15,135 @@
 #include "resource.h"
 #include "dlgs.h"
 #include "win.h"
+#include "graphics.h"
 #include "cursoricon.h"
 #include "stddebug.h"
 #include "debug.h"
 #include "winreg.h"
 
+static const char * const SHELL_People[] =
+{
+    "Bob Amstadt",
+    "Dag Asheim",
+    "Martin Ayotte",
+    "Peter Bajusz",
+    "Georg Beyerle",
+    "Ross Biro",
+    "Uwe Bonnes",
+    "Erik Bos",
+    "Fons Botman",
+    "John Brezak",
+    "Andrew Bulhak",
+    "John Burton",
+    "Niels de Carpentier",
+    "Jimen Ching",
+    "David A. Cuthbert",
+    "Huw D. M. Davies",
+    "Roman Dolejsi",
+    "Frans van Dorsselaer",
+    "Chris Faherty",
+    "Paul Falstad",
+    "David Faure",
+    "Claus Fischer",
+    "Olaf Flebbe",
+    "Chad Fraleigh",
+    "Peter Galbavy",
+    "Ramon Garcia",
+    "Matthew Ghio",
+    "Jody Goldberg",
+    "Hans de Graaff",
+    "Charles M. Hannum",
+    "Adrian Harvey",
+    "John Harvey",
+    "Cameron Heide",
+    "Jochen Hoenicke",
+    "Onno Hovers",
+    "Jeffrey Hsu",
+    "Miguel de Icaza",
+    "Jukka Iivonen",
+    "Lee Jaekil",
+    "Alexandre Julliard",
+    "Bang Jun-Young",
+    "Pavel Kankovsky",
+    "Jochen Karrer",
+    "Andreas Kirschbaum",
+    "Albrecht Kleine",
+    "Jon Konrath",
+    "Alex Korobka",
+    "Greg Kreider",
+    "Anand Kumria",
+    "Scott A. Laird",
+    "Andrew Lewycky",
+    "Martin von Loewis",
+    "Michiel van Loon",
+    "Kenneth MacDonald",
+    "Peter MacDonald",
+    "William Magro",
+    "Juergen Marquardt",
+    "Ricardo Massaro",
+    "Marcus Meissner",
+    "Graham Menhennitt",
+    "David Metcalfe",
+    "Bruce Milner",
+    "Steffen Moeller",
+    "Andreas Mohr",
+    "Philippe De Muyter",
+    "Itai Nahshon",
+    "Henrik Olsen",
+    "Michael Patra",
+    "Dimitrie O. Paun",
+    "Jim Peterson",
+    "Robert Pouliot",
+    "Keith Reynolds",
+    "Slaven Rezic",
+    "John Richardson",
+    "Rick Richardson",
+    "Doug Ridgway",
+    "Bernhard Rosenkraenzer",
+    "Johannes Ruscheinski",
+    "Thomas Sandford",
+    "Constantine Sapuntzakis",
+    "Pablo Saratxaga",
+    "Daniel Schepler",
+    "Peter Schlaile",
+    "Ulrich Schmid",
+    "Bernd Schmidt",
+    "Ingo Schneider",
+    "Victor Schneider",
+    "Yngvi Sigurjonsson",
+    "Stephen Simmons",
+    "Rick Sladkey",
+    "William Smith",
+    "Dominik Strasser",
+    "Vadim Strizhevsky",
+    "Erik Svendsen",
+    "Tristan Tarrant",
+    "Andrew Taylor",
+    "Duncan C Thomson",
+    "Goran Thyni",
+    "Jimmy Tirtawangsa",
+    "Jon Tombs",
+    "Linus Torvalds",
+    "Gregory Trubetskoy",
+    "Petri Tuomola",
+    "Michael Veksler",
+    "Sven Verdoolaege",
+    "Ronan Waide",
+    "Eric Warnke",
+    "Manfred Weichel",
+    "Morten Welinder",
+    "Lawson Whitney",
+    "Jan Willamowius",
+    "Carl Williams",
+    "Karl Guenter Wuensch",
+    "Eric Youngdale",
+    "James Youngman",
+    "Mikolaj Zalewski",
+    "John Zero",
+    NULL
+};
+
+
 /* .ICO file ICONDIR definitions */
 
 #pragma pack(1)
@@ -395,6 +519,27 @@ typedef struct
     HICON32 hIcon;
 } ABOUT_INFO;
 
+#define		IDC_STATIC_TEXT		100
+#define		IDC_LISTBOX		99
+#define		IDC_WINE_TEXT		98
+
+#define		DROP_FIELD_TOP		(-15)
+#define		DROP_FIELD_HEIGHT	15
+
+extern HICON32 hIconTitleFont;
+
+static BOOL32 __get_dropline( HWND32 hWnd, LPRECT32 lprect )
+{
+    HWND32 hWndCtl = GetDlgItem32(hWnd, IDC_WINE_TEXT);
+    if( hWndCtl )
+    {
+	GetWindowRect32( hWndCtl, lprect );
+	MapWindowPoints32( 0, hWnd, (LPPOINT32)lprect, 2 );
+	lprect->bottom = (lprect->top += DROP_FIELD_TOP);
+	return TRUE;
+    }
+    return FALSE;
+}
 
 /*************************************************************************
  *             AboutDlgProc32  (not an exported API function)
@@ -402,6 +547,7 @@ typedef struct
 LRESULT WINAPI AboutDlgProc32( HWND32 hWnd, UINT32 msg, WPARAM32 wParam,
                                LPARAM lParam )
 {
+    HWND32 hWndCtl;
     char Template[512], AppTitle[512];
 
     switch(msg)
@@ -411,15 +557,123 @@ LRESULT WINAPI AboutDlgProc32( HWND32 hWnd, UINT32 msg, WPARAM32 wParam,
             ABOUT_INFO *info = (ABOUT_INFO *)lParam;
             if (info)
             {
+                const char* const *pstr = SHELL_People;
                 SendDlgItemMessage32A(hWnd, stc1, STM_SETICON32,info->hIcon, 0);
                 GetWindowText32A( hWnd, Template, sizeof(Template) );
                 sprintf( AppTitle, Template, info->szApp );
                 SetWindowText32A( hWnd, AppTitle );
-                SetWindowText32A( GetDlgItem32(hWnd,100), info->szOtherStuff );
+                SetWindowText32A( GetDlgItem32(hWnd, IDC_STATIC_TEXT),
+                                  info->szOtherStuff );
+                hWndCtl = GetDlgItem32(hWnd, IDC_LISTBOX);
+                SendMessage32A( hWndCtl, WM_SETREDRAW, 0, 0 );
+                SendMessage32A( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
+                while (*pstr)
+                {
+                    SendMessage32A( hWndCtl, LB_ADDSTRING32,
+                                    (WPARAM32)-1, (LPARAM)*pstr );
+                    pstr++;
+                }
+                SendMessage32A( hWndCtl, WM_SETREDRAW, 1, 0 );
             }
         }
         return 1;
 
+    case WM_PAINT:
+	{
+	    RECT32 rect;
+	    PAINTSTRUCT32 ps;
+	    HDC32 hDC = BeginPaint32( hWnd, &ps );
+
+	    if( __get_dropline( hWnd, &rect ) )
+		GRAPH_DrawLines( hDC, (LPPOINT32)&rect, 1, GetStockObject32( BLACK_PEN ) );
+	    EndPaint32( hWnd, &ps );
+	}
+	break;
+
+    case WM_LBTRACKPOINT:
+
+	hWndCtl = GetDlgItem32(hWnd, IDC_LISTBOX);
+	if( (INT16)GetKeyState16( VK_CONTROL ) < 0 )
+	{
+	    if( DragDetect32( hWndCtl, *((LPPOINT32)&lParam) ) )
+	    {
+		INT32 idx = SendMessage32A( hWndCtl, LB_GETCURSEL32, 0, 0 );
+		if( idx != -1 )
+		{
+		    INT32 length = SendMessage32A( hWndCtl, LB_GETTEXTLEN32, (WPARAM32)idx, 0 );
+		    HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
+		    char* pstr = (char*)GlobalLock16( hMemObj );
+
+		    if( pstr )
+		    {
+			HCURSOR16 hCursor = LoadCursor16( 0, MAKEINTRESOURCE(OCR_DRAGOBJECT) );
+			SendMessage32A( hWndCtl, LB_GETTEXT32, (WPARAM32)idx, (LPARAM)pstr );
+			SendMessage32A( hWndCtl, LB_DELETESTRING32, (WPARAM32)idx, 0 );
+			UpdateWindow32( hWndCtl );
+			if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
+			    SendMessage32A( hWndCtl, LB_ADDSTRING32, (WPARAM32)-1, (LPARAM)pstr );
+		    }
+		    if( hMemObj ) GlobalFree16( hMemObj );
+		}
+	    }
+	}
+	break;
+
+    case WM_QUERYDROPOBJECT:
+	if( wParam == 0 )
+	{
+	    LPDRAGINFO lpDragInfo = (LPDRAGINFO)PTR_SEG_TO_LIN((SEGPTR)lParam);
+	    if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
+	    {
+		RECT32 rect;
+		if( __get_dropline( hWnd, &rect ) )
+		{
+		    POINT32 pt = { lpDragInfo->pt.x, lpDragInfo->pt.y };
+		    rect.bottom += DROP_FIELD_HEIGHT;
+		    if( PtInRect32( &rect, pt ) )
+		    {
+			SetWindowLong32A( hWnd, DWL_MSGRESULT, 1 );
+			return TRUE;
+		    }
+		}
+	    }
+	}
+	break;
+
+    case WM_DROPOBJECT:
+	if( wParam == hWnd )
+	{
+	    LPDRAGINFO lpDragInfo = (LPDRAGINFO)PTR_SEG_TO_LIN((SEGPTR)lParam);
+	    if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
+	    {
+		char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
+		if( pstr )
+		{
+		    static char __appendix_str[] = " with";
+
+		    hWndCtl = GetDlgItem32( hWnd, IDC_WINE_TEXT );
+		    SendMessage32A( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
+		    if( !lstrncmp32A( Template, "WINE", 4 ) )
+			SetWindowText32A( GetDlgItem32(hWnd, IDC_STATIC_TEXT), Template );
+		    else
+		    {
+			char* pch = Template + strlen(Template) - strlen(__appendix_str);
+			*pch = '\0';
+			SendMessage32A( GetDlgItem32(hWnd, IDC_LISTBOX), LB_ADDSTRING32, 
+					(WPARAM32)-1, (LPARAM)Template );
+		    }
+
+		    lstrcpy32A( Template, pstr );
+		    lstrcat32A( Template, __appendix_str );
+		    SetWindowText32A( hWndCtl, Template );
+
+		    SetWindowLong32A( hWnd, DWL_MSGRESULT, 1 );
+		    return TRUE;
+		}
+	    }
+	}
+	break;
+
     case WM_COMMAND:
         if (wParam == IDOK)
         {
@@ -1067,3 +1321,28 @@ void WINAPI FreeIconList( DWORD dw )
 {
     fprintf( stdnimp, "FreeIconList: empty stub\n" );
 }
+
+/*************************************************************************
+ *			 SHELL32_DllGetClassObject   [SHELL32.14]
+ *
+ * http://premium.microsoft.com/msdn/library/sdkdoc/api2_48fo.htm
+ */
+
+/* This is the wrong place, but where is the right one?  */
+typedef UINT32 REFCLSID32;
+typedef UINT32 REFIID32;
+typedef UINT32 HRESULT32;
+#define E_OUTOFMEMORY 0x8007000EL
+
+HRESULT32 WINAPI SHELL32_DllGetClassObject (REFCLSID32 clsid,
+					    REFIID32 riid,
+					    LPVOID *ppv)
+{
+  HRESULT32 hres = E_OUTOFMEMORY; 
+  *ppv = NULL; 
+
+  fprintf (stdnimp, "SHELL32_DllGetClassObject (0x%x,0x%x,%p) -- STUB\n",
+	   clsid, riid, ppv);
+
+  return hres;
+}
diff --git a/misc/ver.c b/misc/ver.c
index e81a539b08a..422e6c3a5ba 100644
--- a/misc/ver.c
+++ b/misc/ver.c
@@ -166,8 +166,7 @@ static int  testFileExclusiveExistence(
 }
 
 
-int
-read_xx_header(HFILE32 lzfd) {
+static int read_xx_header(HFILE32 lzfd) {
 	IMAGE_DOS_HEADER	mzh;
 	char			magic[2];
 
@@ -189,8 +188,7 @@ read_xx_header(HFILE32 lzfd) {
 }
 
 
-int
-find_ne_resource(
+static int find_ne_resource(
 	HFILE32 lzfd,SEGPTR typeid,SEGPTR resid,
 	BYTE **resdata,int *reslen,DWORD *off
 ) {
@@ -319,7 +317,7 @@ extern LPIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(
 /* Loads the specified PE resource.
  * FIXME: shouldn't load the whole image
  */
-int
+static int
 find_pe_resource(
 	HFILE32 lzfd,LPWSTR typeid,LPWSTR resid,
 	BYTE **resdata,int *reslen,DWORD *off
@@ -471,7 +469,7 @@ DWORD WINAPI GetFileResource(LPCSTR filename,SEGPTR restype,SEGPTR resid,
 			res= find_ne_resource(lzfd,restype,resid,&resdata,&reslen,&off);
 			break;
 		case IMAGE_NT_SIGNATURE:
-			res= find_pe_resource(lzfd,restype,resid,&resdata,&reslen,&off);
+			res= find_pe_resource(lzfd,(LPWSTR)restype,(LPWSTR)resid,&resdata,&reslen,&off);
 			break;
 		}
 		LZClose32(lzfd);
@@ -938,10 +936,14 @@ _error2vif(DWORD error) {
     }
 }
 
+/* VerInstallFile32A
+ */
+
 DWORD WINAPI VerInstallFile32A(
 	UINT32 flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
  	LPCSTR destdir,LPCSTR curdir,LPSTR tmpfile,UINT32 *tmpfilelen )
 {
+    LPCSTR pdest;
     char	destfn[260],tmpfn[260],srcfn[260];
     HFILE32	hfsrc,hfdst;
     DWORD	attr,ret,xret,tmplast;
@@ -953,12 +955,14 @@ DWORD WINAPI VerInstallFile32A(
     );
     xret = 0;
     sprintf(srcfn,"%s\\%s",srcdir,srcfilename);
-    sprintf(destfn,"%s\\%s",destdir,destfilename);
+    if (!destdir || !*destdir) pdest = srcdir;
+    else pdest = destdir;
+    sprintf(destfn,"%s\\%s",pdest,destfilename);
     hfsrc=LZOpenFile32A(srcfn,&ofs,OF_READ);
     if (hfsrc==HFILE_ERROR32)
     	return VIF_CANNOTREADSRC;
-    sprintf(tmpfn,"%s\\%s",destdir,destfilename);
-    tmplast=strlen(destdir)+1;
+    sprintf(tmpfn,"%s\\%s",pdest,destfilename);
+    tmplast=strlen(pdest)+1;
     attr = GetFileAttributes32A(tmpfn);
     if (attr!=-1) {
 	if (attr & FILE_ATTRIBUTE_READONLY) {
@@ -970,8 +974,8 @@ DWORD WINAPI VerInstallFile32A(
     attr = -1;
     if (flags & VIFF_FORCEINSTALL) {
     	if (tmpfile[0]) {
-	    sprintf(tmpfn,"%s\\%s",destdir,tmpfile);
-	    tmplast = strlen(destdir)+1;
+	    sprintf(tmpfn,"%s\\%s",pdest,tmpfile);
+	    tmplast = strlen(pdest)+1;
 	    attr = GetFileAttributes32A(tmpfn);
 	    /* if it exists, it has been copied by the call before.
 	     * we jump over the copy part... 
@@ -981,7 +985,7 @@ DWORD WINAPI VerInstallFile32A(
     if (attr == -1) {
     	char	*s;
 
-	GetTempFileName32A(destdir,"ver",0,tmpfn); /* should not fail ... */
+	GetTempFileName32A(pdest,"ver",0,tmpfn); /* should not fail ... */
 	s=strrchr(tmpfn,'\\');
 	if (s)
 	    tmplast = s-tmpfn;
@@ -1078,7 +1082,7 @@ DWORD WINAPI VerInstallFile32A(
 	if ((!(flags & VIFF_DONTDELETEOLD))	&& 
 	    curdir				&& 
 	    *curdir				&&
-	    lstrcmpi32A(curdir,destdir)
+	    lstrcmpi32A(curdir,pdest)
 	) {
 	    char curfn[260];
 
diff --git a/misc/version.c b/misc/version.c
new file mode 100644
index 00000000000..5e0d7bb2b86
--- /dev/null
+++ b/misc/version.c
@@ -0,0 +1,262 @@
+/*
+ * Windows version functions
+ *
+ * Copyright 1997 Alexandre Julliard
+ * Copyright 1997 Marcus Meissner
+ */
+
+#include <stdio.h>
+#include "windows.h"
+#include "winbase.h"
+#include "process.h"
+#include "options.h"
+
+typedef enum
+{
+    WIN31, /* Windows 3.1 */
+    WIN95, /* Windows 95 */
+    NT351, /* Windows NT 3.51 */
+    NT40,  /* Windows NT 4.0 */
+    NB_VERSIONS
+} VERSION;
+
+typedef struct
+{
+    LONG             getVersion16; 
+    LONG             getVersion32;
+    OSVERSIONINFO32A getVersionEx;
+} VERSION_DATA;
+
+
+/* FIXME: compare values below with original and fix */
+static const VERSION_DATA VersionData[NB_VERSIONS] =
+{
+    /* WIN31 */
+    {
+	MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
+	MAKELONG( 0x0a03, 0x8000 ),
+	{
+            sizeof(OSVERSIONINFO32A), 3, 10, 0,
+            VER_PLATFORM_WIN32s, "Win32s 1.3" 
+	}
+    },
+    /* WIN95 */
+    {
+        0x07005F03,
+        0xC0000004,
+	{
+            sizeof(OSVERSIONINFO32A), 4, 0, 0x40003B6,
+            VER_PLATFORM_WIN32_WINDOWS, "Win95"
+	}
+    },
+    /* NT351 */
+    {
+        0x05000A03,
+        0x04213303,
+        {
+            sizeof(OSVERSIONINFO32A), 3, 51, 0x421,
+            VER_PLATFORM_WIN32_NT, "Service Pack 2"
+	}
+    },
+    /* NT40 */
+    {
+        0x05000A03,
+        0x05650004,
+        {
+            sizeof(OSVERSIONINFO32A), 4, 0, 0x565,
+            VER_PLATFORM_WIN32_NT, "Service Pack 3"
+        }
+    }
+};
+
+static const char *VersionNames[NB_VERSIONS] =
+{
+    "win31",
+    "win95",
+    "nt351",
+    "nt40"
+};
+
+/* the current version has not been autodetected but forced via cmdline */
+static BOOL32 versionForced = FALSE;
+static VERSION defaultVersion = WIN31;
+
+
+/**********************************************************************
+ *         VERSION_ParseVersion
+ */
+void VERSION_ParseVersion( char *arg )
+{
+    int i;
+    for (i = 0; i < NB_VERSIONS; i++)
+    {
+        if (!strcmp( VersionNames[i], arg ))
+        {
+            defaultVersion = (VERSION)i;
+            versionForced = TRUE;
+            return;
+        }
+    }
+    fprintf( stderr, "Invalid winver value '%s' specified.\n", arg );
+    fprintf( stderr, "Valid versions are:" );
+    for (i = 0; i < NB_VERSIONS; i++)
+        fprintf( stderr, " '%s'%c", VersionNames[i],
+                 (i == NB_VERSIONS - 1) ? '\n' : ',' );
+}
+
+
+/**********************************************************************
+ *         VERSION_get_version
+ */
+static VERSION VERSION_GetVersion(void)
+{
+    LPIMAGE_NT_HEADERS peheader;	
+
+    if (versionForced) /* user has overridden any sensible checks */
+        return defaultVersion;
+    if (!pCurrentProcess) /* at startuptime probably */
+        return defaultVersion;
+    if (!pCurrentProcess->exe_modref)
+        return WIN31; /* FIXME: hmm, look at DDB.version ? */
+    peheader = pCurrentProcess->exe_modref->pe_module->pe_header;
+    if (peheader->OptionalHeader.MajorSubsystemVersion == 4)
+        /* FIXME: NT4 has the same majorversion; add a check here for it. */
+        return WIN95;
+    if (peheader->OptionalHeader.MajorSubsystemVersion == 3)
+    {
+        /* Win3.10 */
+        if (peheader->OptionalHeader.MinorSubsystemVersion <= 11) return WIN31;
+        /* NT 3.51 */
+        if (peheader->OptionalHeader.MinorSubsystemVersion == 51) return NT351;
+    }
+    fprintf(stderr,"VERSION_GetVersion: unknown subsystem version: %04x.%04x, please report.\n",
+            peheader->OptionalHeader.MajorSubsystemVersion,
+            peheader->OptionalHeader.MinorSubsystemVersion );
+    return defaultVersion;
+}
+
+
+/***********************************************************************
+ *         GetVersion16   (KERNEL.3)
+ */
+LONG WINAPI GetVersion16(void)
+{
+    VERSION ver = VERSION_GetVersion();
+    return VersionData[ver].getVersion16;
+}
+
+
+/***********************************************************************
+ *         GetVersion32   (KERNEL32.427)
+ */
+LONG WINAPI GetVersion32(void)
+{
+    VERSION ver = VERSION_GetVersion();
+    return VersionData[ver].getVersion32;
+}
+
+
+/***********************************************************************
+ *         GetVersionEx32A   (KERNEL32.428)
+ */
+BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
+{
+    VERSION ver = VERSION_GetVersion();
+    if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO32A))
+    {
+        fprintf(stderr,"wrong OSVERSIONINFO size from app");
+        return FALSE;
+    }
+    v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
+    v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
+    v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
+    v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
+    strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *         GetVersionEx32W   (KERNEL32.429)
+ */
+BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
+{
+    VERSION ver = VERSION_GetVersion();
+    if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
+    {
+        fprintf(stderr,"wrong OSVERSIONINFO size from app");
+        return FALSE;
+    }
+    v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
+    v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
+    v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
+    v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
+    lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *	    GetWinFlags   (KERNEL.132)
+ */
+DWORD WINAPI GetWinFlags(void)
+{
+  static const long cpuflags[5] =
+    { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
+  SYSTEM_INFO si;
+  OSVERSIONINFO32A ovi;
+  DWORD result;
+
+  GetSystemInfo(&si);
+
+  /* There doesn't seem to be any Pentium flag.  */
+  result = cpuflags[MIN (si.wProcessorLevel, 4)];
+
+  switch(Options.mode)
+  {
+  case MODE_STANDARD:
+      result |= WF_STANDARD | WF_PMODE | WF_80x87;
+      break;
+
+  case MODE_ENHANCED:
+      result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
+      break;
+
+  default:
+      fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
+      break;
+  }
+  if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
+  ovi.dwOSVersionInfoSize = sizeof(ovi);
+  GetVersionEx32A(&ovi);
+  if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
+      result |= WF_WIN32WOW; /* undocumented WF_WINNT */
+  return result;
+}
+
+
+/***********************************************************************
+ *	    GetWinDebugInfo   (KERNEL.355)
+ */
+BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
+{
+    printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n",
+           (unsigned long)lpwdi, flags);
+    /* 0 means not in debugging mode/version */
+    /* Can this type of debugging be used in wine ? */
+    /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
+    return 0;
+}
+
+
+/***********************************************************************
+ *	    SetWinDebugInfo   (KERNEL.356)
+ */
+BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
+{
+    printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
+    /* 0 means not in debugging mode/version */
+    /* Can this type of debugging be used in wine ? */
+    /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
+    return 0;
+}
diff --git a/miscemu/Makefile.in b/miscemu/Makefile.in
index d6c0b52956c..dcfdbbe5368 100644
--- a/miscemu/Makefile.in
+++ b/miscemu/Makefile.in
@@ -7,7 +7,8 @@ MODULE    = miscemu
 
 C_SRCS = \
 	emulate.c \
-	instr.c
+	instr.c \
+	main.c
 
 all: $(MODULE).o
 
diff --git a/miscemu/main.c b/miscemu/main.c
new file mode 100644
index 00000000000..98dc871bb65
--- /dev/null
+++ b/miscemu/main.c
@@ -0,0 +1,120 @@
+/*
+ * Emulator initialisation code
+ *
+ */
+
+#include <stdio.h>
+#include "windows.h"
+#include "callback.h"
+#include "debugger.h"
+#include "miscemu.h"
+#include "module.h"
+#include "options.h"
+
+
+/***********************************************************************
+ *           Emulator initialisation
+ */
+BOOL32 MAIN_EmulatorInit(void)
+{
+    extern BOOL32 MAIN_KernelInit(void);
+    extern BOOL32 MAIN_UserInit(void);
+    extern BOOL32 WIN16DRV_Init(void);
+    extern BOOL32 RELAY_Init(void);
+
+    /* Initialize the kernel */
+    if (!MAIN_KernelInit()) return FALSE;
+
+    /* Initialize relay code */
+    if (!RELAY_Init()) return FALSE;
+
+      /* Initialize signal handling */
+    if (!SIGNAL_InitEmulator()) return FALSE;
+
+    /* Create the Win16 printer driver */
+    if (!WIN16DRV_Init()) return FALSE;
+
+    /* Initialize all the USER stuff */
+    return MAIN_UserInit();
+}
+
+
+/**********************************************************************
+ *           main
+ */
+int main( int argc, char *argv[] )
+{
+    extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
+    extern void *CALL32_Init(void);
+    extern char * DEBUG_argv0;
+
+    int i,loaded;
+    HINSTANCE32 handle;
+
+    __winelib = 0;  /* First of all, clear the Winelib flag */
+
+    /*
+     * Save this so that the internal debugger can get a hold of it if
+     * it needs to.
+     */
+    DEBUG_argv0 = argv[0];
+
+    if (!MAIN_WineInit( &argc, argv )) return 1;
+
+    /* Handle -dll option (hack) */
+
+    if (Options.dllFlags)
+    {
+        if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
+        {
+            fprintf( stderr, "%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
+                     argv[0] );
+            BUILTIN_PrintDLLs();
+            exit(1);
+        }
+    }
+
+    /* Initialize everything */
+
+    if (!MAIN_EmulatorInit()) return 1;
+
+    /* Initialize CALL32 routines */
+    /* This needs to be done just before task-switching starts */
+    IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
+
+    loaded=0;
+    for (i = 1; i < argc; i++)
+    {
+        if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
+        {
+            fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
+            switch (handle)
+            {
+            case 2: fprintf( stderr, "file not found\n" ); break;
+            case 11: fprintf( stderr, "invalid exe file\n" ); break;
+            case 21: fprintf( stderr, "win32 executable\n" ); break;
+            default: fprintf( stderr, "error=%d\n", handle ); break;
+            }
+            return 1;
+        }
+	loaded++;
+    }
+
+    if (!loaded) { /* nothing loaded */
+    	extern void MAIN_Usage(char*);
+    	MAIN_Usage(argv[0]);
+	return 1;
+    }
+
+    if (!GetNumTasks())
+    {
+        fprintf( stderr, "wine: no executable file found.\n" );
+        return 0;
+    }
+
+    if (Options.debug) DEBUG_AddModuleBreakpoints();
+
+    Yield();  /* Start the first task */
+    fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
+    return 0;
+}
diff --git a/msdos/Makefile.in b/msdos/Makefile.in
index a11285baabc..31be80e5b08 100644
--- a/msdos/Makefile.in
+++ b/msdos/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/msdos/dpmi.c b/msdos/dpmi.c
index 189a99ba8f6..0a5feb401d3 100644
--- a/msdos/dpmi.c
+++ b/msdos/dpmi.c
@@ -34,7 +34,7 @@ typedef struct
     DWORD edx;
     DWORD ecx;
     DWORD eax;
-    WORD  flags;
+    WORD  fl;
     WORD  es;
     WORD  ds;
     WORD  fs;
@@ -45,7 +45,186 @@ typedef struct
     WORD  ss;
 } REALMODECALL;
 
-extern void do_mscdex( CONTEXT *context );
+
+
+/**********************************************************************
+ *	    INT_GetRealModeContext
+ */
+static void INT_GetRealModeContext( REALMODECALL *call, CONTEXT *context )
+{
+    EAX_reg(context) = call->eax;
+    EBX_reg(context) = call->ebx;
+    ECX_reg(context) = call->ecx;
+    EDX_reg(context) = call->edx;
+    ESI_reg(context) = call->esi;
+    EDI_reg(context) = call->edi;
+    EBP_reg(context) = call->ebp;
+    EFL_reg(context) = call->fl;
+    EIP_reg(context) = call->ip;
+    ESP_reg(context) = call->sp;
+    CS_reg(context)  = call->cs;
+    DS_reg(context)  = call->ds;
+    ES_reg(context)  = call->es;
+    FS_reg(context)  = call->fs;
+    GS_reg(context)  = call->gs;
+}
+
+
+/**********************************************************************
+ *	    INT_SetRealModeContext
+ */
+static void INT_SetRealModeContext( REALMODECALL *call, CONTEXT *context )
+{
+    call->eax = EAX_reg(context);
+    call->ebx = EBX_reg(context);
+    call->ecx = ECX_reg(context);
+    call->edx = EDX_reg(context);
+    call->esi = ESI_reg(context);
+    call->edi = EDI_reg(context);
+    call->ebp = EBP_reg(context);
+    call->fl  = FL_reg(context);
+    call->ip  = IP_reg(context);
+    call->sp  = SP_reg(context);
+    call->cs  = CS_reg(context);
+    call->ds  = DS_reg(context);
+    call->es  = ES_reg(context);
+    call->fs  = FS_reg(context);
+    call->gs  = GS_reg(context);
+}
+
+
+/**********************************************************************
+ *	    INT_DoRealModeInt
+ */
+static void INT_DoRealModeInt( CONTEXT *context )
+{
+    CONTEXT realmode_ctx;
+    REALMODECALL *call = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context),
+                                                          DI_reg(context) );
+    INT_GetRealModeContext( call, &realmode_ctx );
+
+    RESET_CFLAG(context);
+    switch (BL_reg(context))
+    {
+    case 0x2f:	/* int2f */
+        switch (AH_reg(&realmode_ctx))
+        {
+        case 0x15:
+            /* MSCDEX hook */
+            do_mscdex( &realmode_ctx );
+            break;
+        default:
+            SET_CFLAG(context);
+            break;
+        }
+        break;
+    case 0x21:	/* int21 */
+        switch (AH_reg(&realmode_ctx))
+        {
+        case 0x52:
+            ES_reg(&realmode_ctx) = 0;
+            EBX_reg(&realmode_ctx) = 0;
+            break;
+        case 0x65:
+            switch (AL_reg(&realmode_ctx))
+            {
+            case 0x06:
+                {/* get collate table */
+                    /* ES:DI is a REALMODE pointer to 5 byte dosmem 
+                     * we fill that with 0x6, realmode pointer to collateTB
+                     */
+                    char *table = DOSMEM_MapRealToLinear(
+                       MAKELONG(EDI_reg(&realmode_ctx),ES_reg(&realmode_ctx)));
+                    *(BYTE*)table      = 0x06;
+                    *(DWORD*)(table+1) = DOSMEM_CollateTable;
+                    CX_reg(&realmode_ctx) = 258;/*FIXME: size of table?*/
+                    break;
+                }
+            default:
+                SET_CFLAG(context);
+                break;
+            }
+            break;
+        case 0x44:
+            switch (AL_reg(&realmode_ctx))
+            {
+            case 0x0D:
+                {/* generic block device request */
+                    BYTE *dataptr = DOSMEM_MapRealToLinear(
+                       MAKELONG(EDX_reg(&realmode_ctx),DS_reg(&realmode_ctx)));
+                    int drive = DOS_GET_DRIVE(BL_reg(&realmode_ctx));
+                    if (CH_reg(&realmode_ctx) != 0x08)
+                    {
+                        SET_CFLAG(context);
+                        break;
+                    }
+                    switch (CL_reg(&realmode_ctx))
+                    {
+                    case 0x66:
+                        {
+			    char    label[12],fsname[9],path[4];
+			    DWORD   serial;
+
+			    strcpy(path,"x:\\");path[0]=drive+'A';
+			    GetVolumeInformation32A(path,label,12,&serial,NULL,NULL,fsname,9);
+			    *(WORD*)dataptr         = 0;
+			    memcpy(dataptr+2,&serial,4);
+			    memcpy(dataptr+6,label  ,11);
+			    memcpy(dataptr+17,fsname,8);
+			    break;
+                        }
+                    case 0x60:	/* get device parameters */
+                                /* used by defrag.exe of win95 */
+                        memset(dataptr, 0, 0x26);
+                        dataptr[0] = 0x04;
+                        dataptr[6] = 0; /* media type */
+                        if (drive > 1)
+                        {
+                            dataptr[1] = 0x05; /* fixed disk */
+                            setword(&dataptr[2], 0x01); /* non removable */
+                            setword(&dataptr[4], 0x300); /* # of cylinders */
+                        }
+                        else
+                        {
+                            dataptr[1] = 0x07; /* block dev, floppy */
+                            setword(&dataptr[2], 0x02); /* removable */
+                            setword(&dataptr[4], 80); /* # of cylinders */
+                        }
+                        CreateBPB(drive, &dataptr[7]);
+                        break;
+                    default:
+                        SET_CFLAG(context);
+                        break;
+                    }
+                }
+            break;
+            default:
+                SET_CFLAG(context);
+                break;
+            }
+            break;
+        default:
+            SET_CFLAG(context);
+            break;
+        }
+        break;
+    default:
+        SET_CFLAG(context);
+        break;
+    }
+
+    if (EFL_reg(context)&1)
+        fprintf(stdnimp,
+                "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
+                "                ESI=%08lx EDI=%08lx DS=%04lx ES=%04lx\n",
+                BL_reg(context), EAX_reg(&realmode_ctx),
+                EBX_reg(&realmode_ctx), ECX_reg(&realmode_ctx),
+                EDX_reg(&realmode_ctx), ESI_reg(&realmode_ctx),
+                EDI_reg(&realmode_ctx), DS_reg(&realmode_ctx),
+                ES_reg(&realmode_ctx) );
+    INT_SetRealModeContext( call, &realmode_ctx );
+}
+
 
 /**********************************************************************
  *	    INT_Int31Handler
@@ -206,118 +385,10 @@ void WINAPI INT_Int31Handler( CONTEXT *context )
                                                           DX_reg(context) ));
 	break;
 
-    case 0x0300:  /* Simulate real mode interrupt 
-        *  Interrupt number is in BL, flags are in BH
-        *  ES:DI points to real-mode call structure  
-        *  Currently we just print it out and return error.
-        */
-	RESET_CFLAG(context);
-        {
-            REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
-
-	    switch (BL_reg(context)) {
-	    case 0x2f:	/* int2f */
-	    	switch ((p->eax & 0xFF00)>>8) {
-		case 0x15:
-			/* MSCDEX hook */
-			AX_reg(context) = p->eax & 0xFFFF;
-                	do_mscdex( context );
-			break;
-		default:
-			SET_CFLAG(context);
-			break;
-		}
-		break;
-	    case 0x21:	/* int21 */
-	    	switch ((p->eax & 0xFF00)>>8) {
-		case 0x65:
-		    switch (p->eax & 0xFF) {
-		    case 06:{/* get collate table */
-		        char	*table;
-		        /* ES:DI is a REALMODE pointer to 5 byte dosmem 
-			 * we fill that with 0x6, realmode pointer to collateTB
-			 */
-			table = DOSMEM_MapRealToLinear(MAKELONG(p->edi,p->es));
-			*(BYTE*)table		= 0x06;
-			*(DWORD*)(table+1)	= DOSMEM_CollateTable;
-
-			CX_reg(context)		= 258;/*FIXME: size of table?*/
-			break;
-		    }
-		    default:
-            		SET_CFLAG(context);
-		    }
-		    break;
-		case 0x44:
-		    switch (p->eax & 0xFF) {
-		    case 0x0D:{/* generic block device request */
-		    	BYTE	*dataptr = DOSMEM_MapRealToLinear((p->ds)*0x1000+(p->edx & 0xFFFF));
-			int	drive = DOS_GET_DRIVE(p->ebx&0xFF); 
-
-		    	if ((p->ecx & 0xFF00) != 0x0800) {
-				SET_CFLAG(context);
-				break;
-			}
-			switch (p->ecx & 0xFF) {
-			case 0x66:{ 
-
-			    char    label[12],fsname[9],path[4];
-			    DWORD   serial;
-
-			    strcpy(path,"x:\\");path[0]=drive+'A';
-			    GetVolumeInformation32A(path,label,12,&serial,NULL,NULL,fsname,9);
-			    *(WORD*)dataptr         = 0;
-			    memcpy(dataptr+2,&serial,4);
-			    memcpy(dataptr+6,label  ,11);
-			    memcpy(dataptr+17,fsname,8);
-			    break;
-                        }
-			case 0x60:	/* get device parameters */
-					/* used by defrag.exe of win95 */
-                            memset(dataptr, 0, 0x26);
-                            dataptr[0] = 0x04;
-                            dataptr[6] = 0; /* media type */
-                            if (drive > 1) {
-                                dataptr[1] = 0x05; /* fixed disk */
-                                setword(&dataptr[2], 0x01); /* non removable */
-                                setword(&dataptr[4], 0x300); /* # of cylinders */
-                            } else {
-                                dataptr[1] = 0x07; /* block dev, floppy */
-                                setword(&dataptr[2], 0x02); /* removable */
-                                setword(&dataptr[4], 80); /* # of cylinders */
-                            }
-                            CreateBPB(drive, &dataptr[7]);
-			    break;
-			default:
-			    SET_CFLAG(context);
-			    break;
-			}
-		    }
-		    	break;
-		    default:
-            		SET_CFLAG(context);
-			break;
-		    }
-		    break;
-		default:
-            	    SET_CFLAG(context);
-		    break;
-		}
-		break;
-	    default:
-		SET_CFLAG(context);
-		break;
-	    }
-	    if (EFL_reg(context)&1) {
-	        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,
-                    p->esi, p->edi, p->es, p->ds
-		);
-	    }
-        }
+    case 0x0300:  /* Simulate real mode interrupt */
+        INT_DoRealModeInt( 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) );
diff --git a/msdos/int2f.c b/msdos/int2f.c
index b43e3b254da..2f4d56ef927 100644
--- a/msdos/int2f.c
+++ b/msdos/int2f.c
@@ -19,7 +19,6 @@
 #define VXD_BASE 400
 
 static void do_int2f_16( CONTEXT *context );
-void do_mscdex( CONTEXT *context );
 
 /**********************************************************************
  *	    INT_Int2fHandler
@@ -93,6 +92,14 @@ static void do_int2f_16( CONTEXT *context )
 	sleep(0);
         break;
 
+    case 0x81: /* Begin critical section.  */
+        /* FIXME? */
+        break;
+
+    case 0x82: /* End critical section.  */
+        /* FIXME? */
+        break;
+
     case 0x83:  /* Return Current Virtual Machine ID */
         /* Virtual Machines are usually created/destroyed when Windows runs
          * DOS programs. Since we never do, we are always in the System VM.
diff --git a/multimedia/Makefile.in b/multimedia/Makefile.in
index 8f20e178d73..2f2f157861c 100644
--- a/multimedia/Makefile.in
+++ b/multimedia/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/objects/Makefile.in b/objects/Makefile.in
index 953c68d2fc4..aecffd0c5e5 100644
--- a/objects/Makefile.in
+++ b/objects/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 18df9836c66..c6fbbe18bfe 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -541,6 +541,23 @@ HANDLE32 WINAPI LoadImage32W( HINSTANCE32 hinst, LPCWSTR name, UINT32 type,
 	return 0;
 }
 
+/**********************************************************************
+ *          CopyBitmap32 (not an API)
+ *
+ */
+HBITMAP32 WINAPI CopyBitmap32 (HBITMAP32 hnd)
+{
+    HBITMAP32 res = 0;
+    BITMAP32 bmp;
+
+    if (GetObject32A (hnd, sizeof (bmp), &bmp))
+    {
+	res = CreateBitmapIndirect32 (&bmp);
+	SetBitmapBits32 (res, bmp.bmWidthBytes * bmp.bmHeight, bmp.bmBits);
+    }
+    return res;
+}
+
 /**********************************************************************
  *	    CopyImage32    (USER32.60)
  *
@@ -553,7 +570,7 @@ HANDLE32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
     switch (type)
     {
 	case IMAGE_BITMAP:
-		return hnd;	/* FIXME ... need to copy here */
+		return CopyBitmap32(hnd);
 	case IMAGE_ICON:
 		return CopyIcon32(hnd);
 	case IMAGE_CURSOR:
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
index 2a7cc6dd92b..569b6abfa7c 100644
--- a/objects/cursoricon.c
+++ b/objects/cursoricon.c
@@ -818,8 +818,10 @@ HICON16 WINAPI CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
  */
 HICON32 WINAPI CopyIcon32( HICON32 hIcon )
 {
+  HTASK16 hTask = GetCurrentTask ();
+  TDB* pTask = (TDB *) GlobalLock16 (hTask);
     dprintf_icon( stddeb, "CopyIcon32: %04x\n", hIcon );
-    return CURSORICON_Copy( 0, hIcon );
+  return CURSORICON_Copy( pTask->hInstance, hIcon );
 }
 
 
@@ -1497,3 +1499,80 @@ HICON32 WINAPI CreateIconIndirect(LPICONINFO iconinfo) {
     }
     return hObj;
 }
+
+/**********************************************************************
+ *          DrawIconEx16		(USER.394)
+ */
+
+BOOL16 WINAPI DrawIconEx16 (HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
+			    INT16 cxWidth, INT16 cyWidth, UINT16 istep,
+			    HBRUSH16 hbr, UINT16 flags)
+{
+  return DrawIconEx32 (hdc, xLeft, yTop, hIcon, cxWidth, cyWidth,
+		       istep, hbr, flags);
+}
+
+/**********************************************************************
+ *          DrawIconEx32		(USER32.160)
+ */
+
+BOOL32 WINAPI DrawIconEx32 (HDC32 hdc, INT32 x0, INT32 y0, HICON32 hIcon,
+			    INT32 cxWidth, INT32 cyWidth, UINT32 istep,
+			    HBRUSH32 hbr, UINT32 flags)
+{
+    CURSORICONINFO *ptr = (CURSORICONINFO *)GlobalLock16 (hIcon);
+    HDC32 hMemDC = CreateCompatibleDC32 (hdc);
+    BOOL32 result = FALSE;
+
+    dprintf_icon (stddeb, "DrawIconEx32: part stub.\n");
+
+    if (hMemDC && ptr)
+    {
+	HBITMAP32 hXorBits, hAndBits;
+	COLORREF oldFg, oldBg;
+
+	/* Calculate the size of the destination image.  */
+	if (cxWidth == 0)
+	    if (flags & DI_DEFAULTSIZE)
+		cxWidth = GetSystemMetrics32 (SM_CXICON);
+	    else
+		cxWidth = ptr->nWidth;
+	if (cyWidth == 0)
+	    if (flags & DI_DEFAULTSIZE)
+		cyWidth = GetSystemMetrics32 (SM_CYICON);
+	    else
+		cyWidth = ptr->nHeight;
+
+	hXorBits = CreateBitmap32 ( ptr->nWidth, ptr->nHeight,
+				    ptr->bPlanes, ptr->bBitsPerPixel,
+				    (char *)(ptr + 1)
+				    + ptr->nHeight *
+				    BITMAP_WIDTH_BYTES(ptr->nWidth,1) );
+	hAndBits = CreateBitmap32 ( cxWidth, cyWidth,
+				    1, 1, (char *)(ptr+1) );
+	oldFg = SetTextColor32( hdc, RGB(0,0,0) );
+	oldBg = SetBkColor32( hdc, RGB(255,255,255) );
+
+	if (hXorBits && hAndBits)
+	{
+	    HBITMAP32 hBitTemp = SelectObject32( hMemDC, hAndBits );
+	    if (flags & DI_MASK)
+		BitBlt32 (hdc, x0, y0, cxWidth, cyWidth,
+			  hMemDC, 0, 0, SRCAND);
+	    SelectObject32( hMemDC, hXorBits );
+	    if (flags & DI_IMAGE)
+		BitBlt32 (hdc, x0, y0, cxWidth, cyWidth,
+			  hMemDC, 0, 0, SRCPAINT);
+	    SelectObject32( hMemDC, hBitTemp );
+	    result = TRUE;
+	}
+
+	SetTextColor32( hdc, oldFg );
+	SetBkColor32( hdc, oldBg );
+	if (hXorBits) DeleteObject32( hXorBits );
+	if (hAndBits) DeleteObject32( hAndBits );
+    }
+    if (hMemDC) DeleteDC32( hMemDC );
+    GlobalUnlock16( hIcon );
+    return result;
+}
diff --git a/objects/dib.c b/objects/dib.c
index 1f9318351de..88cb033753e 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -47,7 +47,7 @@ typedef struct
 /***********************************************************************
  *           DIB_Init
  */
-BOOL32 DIB_Init()
+BOOL32 DIB_Init(void)
 {
     int		i;
     XImage*	testimage;
@@ -1127,14 +1127,44 @@ HBITMAP32 WINAPI CreateDIBitmap32( HDC32 hdc, const BITMAPINFOHEADER *header,
     return handle;
 }
 
-HBITMAP32 CreateDIBSection(
-	HDC32 hdc,BITMAPINFO *bmi,UINT32 usage, LPVOID **bits,HANDLE32 section,
-	DWORD offset
-) {
-	fprintf(stderr,"CreateDIBSection(%d,[w=%ld,h=%ld],%d,%p,0x%08x,%ld),stub\n",
-		hdc,bmi->bmiHeader.biWidth,bmi->bmiHeader.biHeight,usage,bits,section,offset
+/***********************************************************************
+ *           CreateDIBSection16    (GDI.489)
+ */
+HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, BITMAPINFO *bmi, UINT16 usage,
+				     LPVOID **bits, HANDLE16 section,
+				     DWORD offset)
+{
+  return CreateDIBSection32 (hdc, bmi, usage, bits, section, offset);
+}
+
+/***********************************************************************
+ *           CreateDIBSection32    (GDI32.36)
+ */
+HBITMAP32 WINAPI CreateDIBSection32 (HDC32 hdc, BITMAPINFO *bmi, UINT32 usage,
+				     LPVOID **bits,HANDLE32 section,
+				     DWORD offset)
+{
+  HBITMAP32 res = 0;
+
+  fprintf(stderr,
+	  "CreateDIBSection(%d,[w=%ld,h=%ld],%d,%p,0x%08x,%ld),semistub\n",
+	  hdc,bmi->bmiHeader.biWidth,bmi->bmiHeader.biHeight,
+	  usage,bits,section,offset
 	);
-	*bits = 0xCafeBabe;
+  /* FIXME.  The following line isn't quite right.  */
+  res = CreateDIBitmap32 (hdc, &bmi->bmiHeader, 0, NULL, bmi, 0);
+  if (res)
+    {
+      BITMAP32 bmp;
+      if (GetObject32A (res, sizeof (bmp), &bmp))
+	{
+	  *bits = bmp.bmBits;
+	  return res;
+	}
+    }
+
+  /* Error.  */
+  if (res) DeleteObject32 (res);
+  *bits = NULL;
 	return 0;
 }
-
diff --git a/objects/font.c b/objects/font.c
index 93173f97cb1..f65f01611b6 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -14,6 +14,7 @@
 #include "options.h"
 #include "stddebug.h"
 #include "debug.h"
+#include "debugstr.h"
 
 #define ENUM_UNICODE	0x00000001
 
@@ -715,8 +716,9 @@ BOOL32 WINAPI GetTextExtentPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
         !dc->funcs->pGetTextExtentPoint( dc, str, count, size ))
         return FALSE;
 
-    dprintf_font(stddeb,"GetTextExtentPoint(%08x '%.*s' %d %p): returning %d,%d\n",
-                 hdc, count, str, count, size, size->cx, size->cy );
+    dprintf_font(stddeb,"GetTextExtentPoint(%08x %s %d %p): returning %d,%d\n",
+                 hdc, debugstr_an (str, count), count,
+		 size, size->cx, size->cy );
     return TRUE;
 }
 
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index 6504676be1e..dd49530ac43 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -738,13 +738,18 @@ INT32 WINAPI EnumObjects32( HDC32 hdc, INT32 nObjType,
  */
 BOOL16 WINAPI IsGDIObject( HGDIOBJ16 handle )
 {
-    GDIOBJHDR *object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
-    if (object)
+    if (handle >= FIRST_STOCK_HANDLE ) 
+	return TRUE;
+    else
     {
-        UINT16 magic = object->wMagic;
-        GDI_HEAP_UNLOCK( handle );
-        if (magic >= PEN_MAGIC && magic <= METAFILE_DC_MAGIC)
-            return magic - PEN_MAGIC + 1;
+	GDIOBJHDR *object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
+	if (object)
+	{
+	    UINT16 magic = object->wMagic;
+	    GDI_HEAP_UNLOCK( handle );
+	    if (magic >= PEN_MAGIC && magic <= METAFILE_DC_MAGIC)
+		return magic - PEN_MAGIC + 1;
+	}
     }
     return FALSE;
 }
diff --git a/objects/oembitmap.c b/objects/oembitmap.c
index ba13b822629..3a7bcaa6400 100644
--- a/objects/oembitmap.c
+++ b/objects/oembitmap.c
@@ -56,6 +56,7 @@
 #include "bitmaps/obm_size"
 #include "bitmaps/obm_old_close"
 #include "bitmaps/obm_trtype"
+#include "bitmaps/obm_radiocheck"
 
 #include "bitmaps/obm_zoomd"
 #include "bitmaps/obm_reduced"
@@ -70,7 +71,7 @@
 #include "bitmaps/obm_closed_95"
 
 
-#define OBM_FIRST  OBM_TRTYPE	   /* First OEM bitmap */
+#define OBM_FIRST  OBM_RADIOCHECK  /* First OEM bitmap */
 #define OBM_LAST   OBM_OLD_CLOSE   /* Last OEM bitmap */
 
 static struct
@@ -78,6 +79,7 @@ static struct
     char** data;   /* Pointer to bitmap data */
     BOOL32 color;  /* Is it a color bitmap?  */
 } OBM_Pixmaps_Data[OBM_LAST-OBM_FIRST+1] = {
+    { obm_radiocheck, FALSE },	/* OBM_RADIOCHECK */
     { obm_trtype, TRUE },	/* OBM_TRTYPE */    
     { obm_cdrom, TRUE },        /* OBM_CDROM    */
     { obm_harddisk, TRUE },     /* OBM_HARDDISK */
diff --git a/objects/region.c b/objects/region.c
index fd0bbb53db7..65951eaf2e4 100644
--- a/objects/region.c
+++ b/objects/region.c
@@ -39,16 +39,22 @@ INT16 WINAPI OffsetRgn16( HRGN16 hrgn, INT16 x, INT16 y )
 INT32 WINAPI OffsetRgn32( HRGN32 hrgn, INT32 x, INT32 y )
 {
     RGNOBJ * obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC );
-    if (!obj) return ERROR;
-    dprintf_region(stddeb, "OffsetRgn: %04x %d,%d\n", hrgn, x, y );
-    if (!obj->xrgn) 
+
+    if (obj)
     {
-      GDI_HEAP_UNLOCK( hrgn );
-      return NULLREGION;
+	INT32 ret;
+	dprintf_region(stddeb, "OffsetRgn: %04x %d,%d\n", hrgn, x, y );
+	if (obj->xrgn) 
+	{
+	    XOffsetRegion( obj->xrgn, x, y );
+	    ret = COMPLEXREGION;
+	}
+	else
+	    ret = NULLREGION;
+	GDI_HEAP_UNLOCK( hrgn );
+	return ret;
     }
-    XOffsetRegion( obj->xrgn, x, y );
-    GDI_HEAP_UNLOCK( hrgn );
-    return COMPLEXREGION;
+    return ERROR;
 }
 
 
@@ -58,23 +64,27 @@ INT32 WINAPI OffsetRgn32( HRGN32 hrgn, INT32 x, INT32 y )
 INT16 WINAPI GetRgnBox16( HRGN16 hrgn, LPRECT16 rect )
 {
     RGNOBJ * obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC );
-    if (!obj) return ERROR;
-    dprintf_region(stddeb, "GetRgnBox: %04x\n", hrgn );
-    if (!obj->xrgn)
-    {
-        SetRectEmpty16( rect );
-	GDI_HEAP_UNLOCK( hrgn );
-        return NULLREGION;
-    }
-    else
+    if (obj)
     {
-        XRectangle xrect;
-        XClipBox( obj->xrgn, &xrect );
+	INT16 ret;
+	dprintf_region(stddeb, "GetRgnBox: %04x\n", hrgn );
+	if (obj->xrgn)
+	{
+	    XRectangle xrect;
+	    XClipBox( obj->xrgn, &xrect );
+	    SetRect16( rect, xrect.x, xrect.y,
+		       xrect.x + xrect.width, xrect.y + xrect.height);
+	    ret = COMPLEXREGION;
+	}
+	else
+	{
+	    SetRectEmpty16( rect );
+	    ret = NULLREGION;
+	}
 	GDI_HEAP_UNLOCK(hrgn);
-        SetRect16( rect, xrect.x, xrect.y,
-                   xrect.x + xrect.width, xrect.y + xrect.height);
-        return COMPLEXREGION;
+        return ret;
     }
+    return ERROR;
 }
 
 
@@ -469,13 +479,18 @@ BOOL16 WINAPI PtInRegion16( HRGN16 hrgn, INT16 x, INT16 y )
 BOOL32 WINAPI PtInRegion32( HRGN32 hrgn, INT32 x, INT32 y )
 {
     RGNOBJ * obj;
-    BOOL32 result;
     
-    if (!(obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC ))) return FALSE;
-    if (!obj->xrgn) result = FALSE;
-    else result = XPointInRegion( obj->xrgn, x, y );
-    GDI_HEAP_UNLOCK( hrgn );
-    return result;
+    if ((obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC )))
+    {
+	BOOL32 ret;
+	if (obj->xrgn)
+	    ret = XPointInRegion( obj->xrgn, x, y );
+	else
+	    ret = FALSE;
+	GDI_HEAP_UNLOCK( hrgn );
+	return ret;
+    }
+    return FALSE;
 }
 
 
@@ -485,15 +500,19 @@ BOOL32 WINAPI PtInRegion32( HRGN32 hrgn, INT32 x, INT32 y )
 BOOL16 WINAPI RectInRegion16( HRGN16 hrgn, const RECT16 *rect )
 {
     RGNOBJ * obj;
-    BOOL16 result;
 
-    if (!(obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC ))) return FALSE;
-    if (!obj->xrgn) result = FALSE;
-    else result = (XRectInRegion( obj->xrgn, rect->left, rect->top,
-                           rect->right-rect->left,
-                           rect->bottom-rect->top ) != RectangleOut);
-    GDI_HEAP_UNLOCK( hrgn );
-    return result;
+    if ((obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC )))
+    {
+	BOOL16 ret;
+	if (obj->xrgn)
+	    ret = (XRectInRegion( obj->xrgn, rect->left, rect->top,
+                   rect->right-rect->left, rect->bottom-rect->top ) != RectangleOut);
+	else
+	    ret = FALSE;
+	GDI_HEAP_UNLOCK( hrgn );
+	return ret;
+    }
+    return FALSE;
 }
 
 
@@ -503,15 +522,19 @@ BOOL16 WINAPI RectInRegion16( HRGN16 hrgn, const RECT16 *rect )
 BOOL32 WINAPI RectInRegion32( HRGN32 hrgn, const RECT32 *rect )
 {
     RGNOBJ * obj;
-    BOOL32 result;
     
-    if (!(obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC ))) return FALSE;
-    if (!obj->xrgn) result = FALSE;
-    else result = (XRectInRegion( obj->xrgn, rect->left, rect->top,
-                           rect->right-rect->left,
-                           rect->bottom-rect->top ) != RectangleOut);
-    GDI_HEAP_UNLOCK( hrgn );
-    return result;
+    if ((obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC )))
+    {
+	BOOL32 ret;
+	if (obj->xrgn)
+	    ret = (XRectInRegion( obj->xrgn, rect->left, rect->top,
+                   rect->right-rect->left, rect->bottom-rect->top ) != RectangleOut);
+	else
+	    ret = FALSE;
+	GDI_HEAP_UNLOCK( hrgn );
+	return ret;
+    }
+    return FALSE;
 }
 
 
@@ -530,19 +553,21 @@ BOOL16 WINAPI EqualRgn16( HRGN16 rgn1, HRGN16 rgn2 )
 BOOL32 WINAPI EqualRgn32( HRGN32 rgn1, HRGN32 rgn2 )
 {
     RGNOBJ *obj1, *obj2;
-    BOOL32 result;
+    BOOL32 ret = FALSE;
 
-    if (!(obj1 = (RGNOBJ *) GDI_GetObjPtr( rgn1, REGION_MAGIC ))) return FALSE;
-    if (!(obj2 = (RGNOBJ *) GDI_GetObjPtr( rgn2, REGION_MAGIC ))) 
+    if ((obj1 = (RGNOBJ *) GDI_GetObjPtr( rgn1, REGION_MAGIC ))) 
     {
-      GDI_HEAP_UNLOCK( rgn1 );
-      return FALSE;
+	if ((obj2 = (RGNOBJ *) GDI_GetObjPtr( rgn2, REGION_MAGIC ))) 
+	{
+	    if (!obj1->xrgn || !obj2->xrgn) 
+		ret = (!obj1->xrgn && !obj2->xrgn);
+	    else 
+		ret = XEqualRegion( obj1->xrgn, obj2->xrgn );
+	    GDI_HEAP_UNLOCK( rgn2 );
+	}
+	GDI_HEAP_UNLOCK( rgn1 );
     }
-    if (!obj1->xrgn || !obj2->xrgn) result = (!obj1->xrgn && !obj2->xrgn);
-    else result = XEqualRegion( obj1->xrgn, obj2->xrgn );
-    GDI_HEAP_UNLOCK( rgn1 );
-    GDI_HEAP_UNLOCK( rgn2 );
-    return result;
+    return ret;
 }
 
 
diff --git a/objects/text.c b/objects/text.c
index aab82fa0556..7844d8af96d 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -80,10 +80,11 @@ static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
 	    break;
 	    
 	case PREFIX:
-	    if (!(format & DT_NOPREFIX))
-	    {
-                if (str[++i] != PREFIX)
+	    if (!(format & DT_NOPREFIX) && *count > 1)
                 {
+                if (str[++i] == PREFIX)
+		    (*count)--;
+		else {
                     prefix_offset = j;
                     break;
                 }
diff --git a/programs/progman/Makefile.in b/programs/progman/Makefile.in
index a09f86d1ade..c1948d63b45 100644
--- a/programs/progman/Makefile.in
+++ b/programs/progman/Makefile.in
@@ -1,3 +1,4 @@
+DEFS      = -DWINELIB
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
@@ -5,7 +6,6 @@ VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = progman
 ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LDLIBS)
-DEFS      = -I$(SRCDIR)
 RCFLAGS   = -w32 -h
 
 LANGUAGES   = En Da De Fr Fi Ko Hu It Va
diff --git a/programs/progman/main.c b/programs/progman/main.c
index bc9b8436fc8..6f0e985e5ae 100644
--- a/programs/progman/main.c
+++ b/programs/progman/main.c
@@ -357,14 +357,9 @@ static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
       WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
       break;
 
-#ifdef WINELIB
     case PM_ABOUT_WINE:
-      {
-	extern const char people[];
-	ShellAbout(hWnd, "WINE", people, 0);
-      }
+      ShellAbout(hWnd, "WINE", "Program Manager", 0);
       break;
-#endif
 
     default:
       if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
diff --git a/programs/winhelp/Makefile.in b/programs/winhelp/Makefile.in
index 22b605add85..322bb0b1454 100644
--- a/programs/winhelp/Makefile.in
+++ b/programs/winhelp/Makefile.in
@@ -1,3 +1,4 @@
+DEFS      = -DWINELIB
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
diff --git a/programs/winhelp/winhelp.c b/programs/winhelp/winhelp.c
index 8b530553189..cd8a22b98d7 100644
--- a/programs/winhelp/winhelp.c
+++ b/programs/winhelp/winhelp.c
@@ -10,7 +10,6 @@
 #include "resource.h"
 #include "options.h"
 #include "shell.h"
-extern const char people[];
 #endif
 #include "winhelp.h"
 
@@ -421,11 +420,10 @@ static LRESULT WINHELP_MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM l
 
 	  /* Menu Info */
 	case WH_ABOUT:           MACRO_About();          break;
-#ifdef WINELIB
+
 	case WH_ABOUT_WINE: 
-	  ShellAbout(hWnd, "WINE", people, 0);
+	  ShellAbout(hWnd, "WINE", "Help", 0);
 	  break;
-#endif
 
 	default:
 	  /* Buttons */
diff --git a/resources/Makefile.in b/resources/Makefile.in
index 43012e53de1..a99b60527b3 100644
--- a/resources/Makefile.in
+++ b/resources/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/resources/sysres_Cz.rc b/resources/sysres_Cz.rc
index db196b00ba0..7718edaa3a5 100644
--- a/resources/sysres_Cz.rc
+++ b/resources/sysres_Cz.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "&Ne", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "O aplikaci %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Otevøení souboru"
diff --git a/resources/sysres_Da.rc b/resources/sysres_Da.rc
index 5c60ad8630c..ec99cd61e57 100644
--- a/resources/sysres_Da.rc
+++ b/resources/sysres_Da.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "&Nej", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Om %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "Ok", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Tekst", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Åbn"
diff --git a/resources/sysres_De.rc b/resources/sysres_De.rc
index a9208ccdd82..b866fd4411c 100644
--- a/resources/sysres_De.rc
+++ b/resources/sysres_De.rc
@@ -42,15 +42,16 @@ BEGIN
         PUSHBUTTON "&Nein", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Info über %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
 
diff --git a/resources/sysres_En.rc b/resources/sysres_En.rc
index b7b6adeeab0..95015802330 100644
--- a/resources/sysres_En.rc
+++ b/resources/sysres_En.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "&No", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "About %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Open"
diff --git a/resources/sysres_Eo.rc b/resources/sysres_Eo.rc
index a5d5b31e4da..2fa6e802945 100644
--- a/resources/sysres_Eo.rc
+++ b/resources/sysres_Eo.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "N&e", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Pri %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "Enorde", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "Enorde", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Malfermu dosieron"
diff --git a/resources/sysres_Es.rc b/resources/sysres_Es.rc
index d7b048e8ab7..387d8bb10ef 100644
--- a/resources/sysres_Es.rc
+++ b/resources/sysres_Es.rc
@@ -43,18 +43,18 @@ BEGIN
         PUSHBUTTON "&No", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Acerca de %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "Aceptar", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "Aceptar", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Abrir"
diff --git a/resources/sysres_Fi.rc b/resources/sysres_Fi.rc
index 59fa1715afb..369873c428c 100644
--- a/resources/sysres_Fi.rc
+++ b/resources/sysres_Fi.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "&Ei", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Tietoja: %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Teksti", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Avaa"
diff --git a/resources/sysres_Fr.rc b/resources/sysres_Fr.rc
index c58bbc90dba..4fa953525df 100644
--- a/resources/sysres_Fr.rc
+++ b/resources/sysres_Fr.rc
@@ -43,18 +43,18 @@ BEGIN
         PUSHBUTTON "&Non", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "A propos de %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 185, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Ouvrir"
diff --git a/resources/sysres_Hu.rc b/resources/sysres_Hu.rc
index c6ae6c2545e..66cf2812c22 100644
--- a/resources/sysres_Hu.rc
+++ b/resources/sysres_Hu.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "&Nem", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "A %s-rõl"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Megnyitás"
diff --git a/resources/sysres_It.rc b/resources/sysres_It.rc
index d32bb8b9fff..bd78672541a 100644
--- a/resources/sysres_It.rc
+++ b/resources/sysres_It.rc
@@ -42,15 +42,16 @@ BEGIN
         PUSHBUTTON "&No", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Informazioni su %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
diff --git a/resources/sysres_Ko.rc b/resources/sysres_Ko.rc
index 646c8c304df..7810c12087a 100644
--- a/resources/sysres_Ko.rc
+++ b/resources/sysres_Ko.rc
@@ -42,18 +42,18 @@ BEGIN
 	PUSHBUTTON "¾Æ´Ï¿À(&N)", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "%s¿¡ °üÇÏ¿©"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "È®ÀÎ", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "È®ÀÎ", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "¿­±â"
diff --git a/resources/sysres_No.rc b/resources/sysres_No.rc
index eed7dfe5f31..5850bf13da1 100644
--- a/resources/sysres_No.rc
+++ b/resources/sysres_No.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "&Nei", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Om %s"
 FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Tekst", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Åpne"
diff --git a/resources/sysres_Pl.rc b/resources/sysres_Pl.rc
index 1e821f82c4a..80260bc7c47 100644
--- a/resources/sysres_Pl.rc
+++ b/resources/sysres_Pl.rc
@@ -41,16 +41,19 @@ BEGIN
 	PUSHBUTTON "&Tak", 6, 263, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 	PUSHBUTTON "&Nie", 7, 311, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
-SHELL_ABOUT_MSGBOX DIALOG 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "O %s"
 FONT 10, "System"
 {
-	DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
-	CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
-	CONTROL "Text", 100, "STATIC", SS_NOPREFIX | WS_GROUP, 11, 40, 200, 200
-	ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
+
 /* LTEXT "Wyswietl pliki &typu:", 1089, 6, 104, 90, 9 */
 OPEN_FILE DIALOG 36, 24, 279, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
diff --git a/resources/sysres_Po.rc b/resources/sysres_Po.rc
index 0fca2511ff9..200b8d24eb5 100644
--- a/resources/sysres_Po.rc
+++ b/resources/sysres_Po.rc
@@ -42,18 +42,18 @@ BEGIN
         PUSHBUTTON "&Não", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
 END
 
-SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 270
-STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 15, 40, 210, 152
+STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Sobre %s"
-FONT 10, "Sistema"
+FONT 10, "System"
 {
- DEFPUSHBUTTON "OK", 1, 91, 250, 40, 14
- CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 210
- LTEXT "Text", 100, 11, 40, 200, 200, SS_NOPREFIX | WS_GROUP
- ICON "", 1088, 195, 10, 18, 20
+ DEFPUSHBUTTON "OK", 1, 153, 130, 50, 12
+ LISTBOX 99, 8, 65, 137, 82, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
+ ICON "", 1088, 189, 10, 14, 16
+ LTEXT "", 100, 8, 10, 137, 33
+ LTEXT "Wine was brought to you by:", 98, 8, 55, 137, 10
 }
 
-
 OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Abrir"
diff --git a/scheduler/Makefile.in b/scheduler/Makefile.in
index f6327b1d029..75ff0803bab 100644
--- a/scheduler/Makefile.in
+++ b/scheduler/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/scheduler/thread.c b/scheduler/thread.c
index 91131b5a623..97400861782 100644
--- a/scheduler/thread.c
+++ b/scheduler/thread.c
@@ -58,6 +58,7 @@ THDB *THREAD_Create( PDB32 *pdb, DWORD stack_size,
                      LPTHREAD_START_ROUTINE start_addr )
 {
     DWORD old_prot;
+    WORD cs, ds;
     THDB *thdb = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(THDB) );
     if (!thdb) return NULL;
     thdb->header.type     = K32OBJ_THREAD;
@@ -92,13 +93,15 @@ THDB *THREAD_Create( PDB32 *pdb, DWORD stack_size,
 
     /* Initialize the thread context */
 
+    GET_CS(cs);
+    GET_DS(ds);
     thdb->pcontext        = &thdb->context;
-    thdb->context.SegCs   = WINE_CODE_SELECTOR;
-    thdb->context.SegDs   = WINE_DATA_SELECTOR;
-    thdb->context.SegEs   = WINE_DATA_SELECTOR;
+    thdb->context.SegCs   = cs;
+    thdb->context.SegDs   = ds;
+    thdb->context.SegEs   = ds;
+    thdb->context.SegGs   = ds;
+    thdb->context.SegSs   = ds;
     thdb->context.SegFs   = thdb->teb_sel;
-    thdb->context.SegGs   = WINE_DATA_SELECTOR;
-    thdb->context.SegSs   = WINE_DATA_SELECTOR;
     thdb->context.Eip     = (DWORD)start_addr;
     thdb->context.Esp     = (DWORD)thdb->teb.stack_top;
 
@@ -135,8 +138,12 @@ void THREAD_Destroy( K32OBJ *ptr )
     {
         /* Check if we are deleting the current thread */
         WORD fs;
-        __asm__("movw %%fs,%w0":"=r" (fs));
-        if (fs == thdb->teb_sel) __asm__ __volatile__("pushw %ds\n\tpopw %fs");
+        GET_FS( fs );
+        if (fs == thdb->teb_sel)
+        {
+            GET_DS( fs );
+            SET_FS( fs );
+        }
     }
 #endif
     SELECTOR_FreeBlock( thdb->teb_sel, 1 );
diff --git a/tools/build.c b/tools/build.c
index 253bb45b069..952bb9f9cd0 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -137,11 +137,12 @@ static ORDDEF OrdinalDefinitions[MAX_ORDINALS];
 static SPEC_TYPE SpecType = SPEC_INVALID;
 static char DLLName[80];
 static char DLLFileName[80];
-int Limit = 0;
-int Base = MAX_ORDINALS;
-int DLLHeapSize = 0;
-char *SpecName;
-FILE *SpecFp;
+static int Limit = 0;
+static int Base = MAX_ORDINALS;
+static int DLLHeapSize = 0;
+static char *SpecName;
+static FILE *SpecFp;
+static WORD Code_Selector, Data_Selector;
 
 char *ParseBuffer = NULL;
 char *ParseNext;
@@ -1084,7 +1085,7 @@ static int BuildSpec32File( char * specfile, FILE *outfile )
                 if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
                 if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
 	    }
-	fprintf( outfile, "\t.long %ld\n",mask);
+	fprintf( outfile, "\t.long %d\n",mask);
     }
 
     /* Output the DLL ordinals table */
@@ -1233,10 +1234,8 @@ static int BuildSpec16File( char * specfile, FILE *outfile )
                      (odp->type == TYPE_REGISTER) ? "regs" :
                      (odp->type == TYPE_PASCAL) ? "long" : "word",
                      odp->u.func.arg_types );
-            fprintf( outfile,"\t.byte 0x%02x,0x%02x\n", /* Some asms don't have .word */
-                     LOBYTE(WINE_CODE_SELECTOR), HIBYTE(WINE_CODE_SELECTOR) );
-            fprintf( outfile, "\tnop\n" );
-            fprintf( outfile, "\tnop\n\n" );
+            fprintf( outfile, "\t.long 0x%08lx\n",
+                     MAKELONG( Code_Selector, 0x9090 /* nop ; nop */ ) );
             odp->offset = code_offset;
             code_offset += 16;  /* Assembly code is 16 bytes long */
             break;
@@ -1571,8 +1570,7 @@ static void BuildCallFrom16Func( FILE *outfile, char *profile )
 
     /* Restore 32-bit ds and es */
 
-    fprintf( outfile, "\tpushl $0x%04x%04x\n",
-             WINE_DATA_SELECTOR, WINE_DATA_SELECTOR );
+    fprintf( outfile, "\tpushl $0x%04x%04x\n", Data_Selector, Data_Selector );
     fprintf( outfile, "\tpopw %%ds\n" );
     fprintf( outfile, "\tpopw %%es\n" );
 
@@ -1966,10 +1964,10 @@ static void BuildRet16Func( FILE *outfile )
     fprintf( outfile, "\tmovw %%ax,%%dx\n" );
     fprintf( outfile, "\tmovl %%edx,%%eax\n" );
 
-    /* Restore 32-bit segment registers and stack*/
+    /* Restore 32-bit segment registers */
 
     fprintf( outfile, "\tpopl %%ecx\n" );  /* Get the saved %%esp */
-    fprintf( outfile, "\tmovw $0x%04x,%%bx\n", WINE_DATA_SELECTOR );
+    fprintf( outfile, "\tmovw $0x%04x,%%bx\n", Data_Selector );
 #ifdef __svr4__
     fprintf( outfile, "\tdata16\n");
 #endif
@@ -2422,6 +2420,13 @@ int main(int argc, char **argv)
         }
     }
 
+    /* Retrieve the selector values; this assumes that we are building
+     * the asm files on the platform that will also run them. Probably
+     * a safe assumption to make.
+     */
+    GET_CS( Code_Selector );
+    GET_DS( Data_Selector );
+
     if (!strcmp( argv[1], "-spec" ))
         res = BuildSpec( outfile, argc, argv );
     else if (!strcmp( argv[1], "-callfrom16" ))
diff --git a/tools/examine-relay b/tools/examine-relay
new file mode 100755
index 00000000000..6030f08e4bf
--- /dev/null
+++ b/tools/examine-relay
@@ -0,0 +1,61 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+my $srcfile = $ARGV[0];
+my @callstack = ();
+
+open (IN, "<$srcfile") || die "Cannot open $srcfile for reading: $!\n";
+LINE:
+while (<IN>) {
+    if (/^Call ([A-Za-z0-9]+\.[0-9]+): .*\)/) {
+	my $func = $1;
+	if (/ ret=(........)$/ ||
+	    / ret=(....:....) ds=....$/) {
+	    my $retaddr = $1;
+	    push @callstack, [$func,$retaddr];
+	    next;
+	} else {
+	    # Assume a line got cut by a line feed in a string.
+	    $_ .= scalar (<IN>);
+	    print "[$_]";
+	    redo;
+	}
+    }
+
+
+    if (/^Ret  ([A-Za-z0-9]+\.[0-9]+): .* ret=(........)$/ ||
+	/^Ret  ([A-Za-z0-9]+\.[0-9]+): .* ret=(....:....) ds=....$/) {
+	my $func = $1;
+	my $retaddr = $2;
+	my ($topfunc,$topaddr);
+
+      POP:
+	while (1) {
+	    if ($#callstack == -1) {
+		print "Error: Return from $func to $retaddr with empty stack.\n";
+		next LINE;
+	    }
+
+	    ($topfunc,$topaddr) = @{pop @callstack};
+
+	    if ($topfunc ne $func) {
+		print "Error: Return from $topfunc, but call from $func.\n";
+		next POP 
+	    }
+	    last POP;
+	}
+
+	if ($topaddr eq $retaddr) {
+	    print "OK: $func from $retaddr.\n";
+	} else {
+	    print "Error: Return from $func is to $retaddr, not $topaddr.\n";
+	}    
+    }
+}
+
+while ($#callstack != -1) {
+    my ($topfunc,$topaddr) = @{pop @callstack};
+    print "Error: leftover call to $topfunc from $topaddr.\n";
+}
+
+close (IN);
diff --git a/win32/Makefile.in b/win32/Makefile.in
index b83223cc48b..fb594a85983 100644
--- a/win32/Makefile.in
+++ b/win32/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/win32/code_page.c b/win32/code_page.c
index 82caf721306..ed6ea82291d 100644
--- a/win32/code_page.c
+++ b/win32/code_page.c
@@ -90,11 +90,11 @@ int WINAPI MultiByteToWideChar(UINT32 page, DWORD flags, char *src, int srclen,
 {
     if (srclen == -1)
    	 srclen = lstrlen32A(src)+1;
-    if (!dst)
-         return srclen*2;
+    if (!dstlen || !dst)
+         return srclen;
 
     lstrcpynAtoW(dst,src,srclen); /* FIXME */
-    return srclen*2-2;
+    return srclen-1;
 }
 
 int WINAPI WideCharToMultiByte(UINT32 page, DWORD flags, WCHAR *src, int srclen,
diff --git a/windows/Makefile.in b/windows/Makefile.in
index 70cbec2240a..c18a4702ed2 100644
--- a/windows/Makefile.in
+++ b/windows/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__
+DEFS      = @DLLFLAGS@ -D__WINE__
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/windows/clipboard.c b/windows/clipboard.c
index d51dbd4a486..7a262bdd22d 100644
--- a/windows/clipboard.c
+++ b/windows/clipboard.c
@@ -1,5 +1,5 @@
 /*
- * 'Wine' Clipboard function handling
+ * WINE clipboard function handling
  *
  * Copyright 1994 Martin Ayotte
  *	     1996 Alex Korobka
@@ -41,11 +41,13 @@ typedef struct tagCLIPFORMAT {
  *			internal variables
  */
 
+static HQUEUE16 hqClipLock   = 0;
+static BOOL32 bCBHasChanged  = FALSE;
+
 static HWND32 hWndClipOwner  = 0;   /* current clipboard owner */
 static HWND32 hWndClipWindow = 0;   /* window that opened clipboard */
 static HWND32 hWndViewer     = 0;   /* start of viewers chain */
 
-static BOOL32 bClipChanged  = FALSE;
 static WORD LastRegFormat = CF_REGFORMATBASE;
 
 static Bool   selectionWait = False;
@@ -72,70 +74,104 @@ static CLIPFORMAT ClipFormats[16]  = {
     { CF_DSPBITMAP, 1, 0, "DSPBitmap", (HANDLE16)NULL, 0, &ClipFormats[14], NULL }
     };
 
+static LPCLIPFORMAT __lookup_format( LPCLIPFORMAT lpFormat, WORD wID )
+{
+    while(TRUE)
+    {
+	if (lpFormat == NULL ||
+	    lpFormat->wFormatID == wID) break;
+	lpFormat = lpFormat->NextFormat;
+    }
+    return lpFormat;
+}
+
 /**************************************************************************
  *                      CLIPBOARD_CheckSelection
+ *
+ * Prevent X selection from being lost when a top level window is
+ * destroyed.
  */
 static void CLIPBOARD_CheckSelection(WND* pWnd)
 {
-  dprintf_clipboard(stddeb,"\tchecking %08x\n", (unsigned)pWnd->window);
+    dprintf_clipboard(stddeb,"\tchecking %08x\n", (unsigned)pWnd->window);
 
-  if( selectionAcquired && selectionWindow != None &&
-      pWnd->window == selectionWindow )
-  {
-    selectionPrevWindow = selectionWindow;
-    selectionWindow = None;
+    if( selectionAcquired && selectionWindow != None &&
+        pWnd->window == selectionWindow )
+    {
+	selectionPrevWindow = selectionWindow;
+	selectionWindow = None;
 
-    if( pWnd->next ) 
-         selectionWindow = pWnd->next->window;
-    else if( pWnd->parent )
+	if( pWnd->next ) 
+	    selectionWindow = pWnd->next->window;
+	else if( pWnd->parent )
              if( pWnd->parent->child != pWnd ) 
                  selectionWindow = pWnd->parent->child->window;
 
-    dprintf_clipboard(stddeb,"\tswitching selection from %08x to %08x\n", 
+	dprintf_clipboard(stddeb,"\tswitching selection from %08x to %08x\n", 
                     (unsigned)selectionPrevWindow, (unsigned)selectionWindow);
 
-    if( selectionWindow != None )
+	if( selectionWindow != None )
+	{
+	    XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
+	    if( XGetSelectionOwner(display, XA_PRIMARY) != selectionWindow )
+		selectionWindow = None;
+	}
+    }
+}
+
+/**************************************************************************
+ *                      CLIPBOARD_ResetLock
+ */
+void CLIPBOARD_ResetLock( HQUEUE16 hqCurrent, HQUEUE16 hqNew )
+{
+    if( hqClipLock == hqCurrent )
     {
-        XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
-        if( XGetSelectionOwner(display, XA_PRIMARY) != selectionWindow )
-            selectionWindow = None;
+	if( hqNew )
+	    hqClipLock = hqNew;
+	else
+	{
+ 	    hWndClipOwner = 0;
+	    hWndClipWindow = 0;
+	    EmptyClipboard32();
+	    hqClipLock = 0;
+	}
     }
-  }
 }
 
 /**************************************************************************
- *			CLIPBOARD_DisOwn
+ *			CLIPBOARD_ResetOwner
  *
  * Called from DestroyWindow().
  */
-void CLIPBOARD_DisOwn(WND* pWnd)
+void CLIPBOARD_ResetOwner(WND* pWnd)
 {
-  LPCLIPFORMAT lpFormat = ClipFormats;
+    LPCLIPFORMAT lpFormat = ClipFormats;
 
-  dprintf_clipboard(stddeb,"DisOwn: clipboard owner = %04x, selection = %08x\n", 
+    dprintf_clipboard(stddeb,"DisOwn: clipboard owner = %04x, selection = %08x\n", 
 				hWndClipOwner, (unsigned)selectionWindow);
 
-  if( pWnd->hwndSelf == hWndClipOwner)
-  {
-      SendMessage16(hWndClipOwner,WM_RENDERALLFORMATS,0,0L);
+    if( pWnd->hwndSelf == hWndClipOwner)
+    {
+	SendMessage16(hWndClipOwner,WM_RENDERALLFORMATS,0,0L);
 
-      /* check if all formats were rendered */
+	/* check if all formats were rendered */
 
-      while(lpFormat)
-      { 
-         if( lpFormat->wDataPresent && !lpFormat->hData )
-	 {
-	   dprintf_clipboard(stddeb,"\tdata missing for clipboard format %i\n", lpFormat->wFormatID); 
-	   lpFormat->wDataPresent = 0;
-	 }
-         lpFormat = lpFormat->NextFormat;
-      }
-      hWndClipOwner = 0;
-  }
+	while(lpFormat)
+	{
+	    if( lpFormat->wDataPresent && !lpFormat->hData )
+	    {
+		dprintf_clipboard( stddeb,"\tdata missing for clipboard format %i\n", 
+				   lpFormat->wFormatID); 
+		lpFormat->wDataPresent = 0;
+	    }
+	    lpFormat = lpFormat->NextFormat;
+	}
+	hWndClipOwner = 0;
+    }
 
-  /* now try to salvage current selection from being destroyed by X */
+    /* now try to salvage current selection from being destroyed by X */
 
-  if( pWnd->window ) CLIPBOARD_CheckSelection(pWnd);
+    if( pWnd->window ) CLIPBOARD_CheckSelection(pWnd);
 }
 
 /**************************************************************************
@@ -143,16 +179,16 @@ void CLIPBOARD_DisOwn(WND* pWnd)
  */
 static void CLIPBOARD_DeleteRecord(LPCLIPFORMAT lpFormat, BOOL32 bChange)
 {
-  if( lpFormat->wFormatID >= CF_GDIOBJFIRST &&
-      lpFormat->wFormatID <= CF_GDIOBJLAST )
-      DeleteObject32(lpFormat->hData);
-  else if( lpFormat->hData )
-           GlobalFree16(lpFormat->hData);
+    if( lpFormat->wFormatID >= CF_GDIOBJFIRST &&
+	lpFormat->wFormatID <= CF_GDIOBJLAST )
+	DeleteObject32(lpFormat->hData);
+    else if( lpFormat->hData )
+	GlobalFree16(lpFormat->hData);
 
-  lpFormat->wDataPresent = 0; 
-  lpFormat->hData = 0;
+    lpFormat->wDataPresent = 0; 
+    lpFormat->hData = 0;
 
-  if( bChange ) bClipChanged = TRUE;
+    if( bChange ) bCBHasChanged = TRUE;
 }
 
 /**************************************************************************
@@ -160,31 +196,34 @@ static void CLIPBOARD_DeleteRecord(LPCLIPFORMAT lpFormat, BOOL32 bChange)
  */
 static BOOL32 CLIPBOARD_RequestXSelection()
 {
-  HWND32 hWnd = (hWndClipWindow) ? hWndClipWindow : GetActiveWindow32();
+    HWND32 hWnd = (hWndClipWindow) ? hWndClipWindow : GetActiveWindow32();
 
-  if( !hWnd ) return FALSE;
+    if( !hWnd ) return FALSE;
 
-  dprintf_clipboard(stddeb,"Requesting selection...\n");
+    dprintf_clipboard(stddeb,"Requesting selection...\n");
 
   /* request data type XA_STRING, later
    * CLIPBOARD_ReadSelection() will be invoked 
    * from the SelectionNotify event handler */
 
-  XConvertSelection(display,XA_PRIMARY,XA_STRING,
-                    XInternAtom(display,"PRIMARY_TEXT",False),
-                    WIN_GetXWindow(hWnd),CurrentTime);
+    XConvertSelection(display,XA_PRIMARY,XA_STRING,
+                      XInternAtom(display,"PRIMARY_TEXT",False),
+                      WIN_GetXWindow(hWnd),CurrentTime);
 
-  /* wait until SelectionNotify is processed */
+  /* wait until SelectionNotify is processed 
+   *
+   * FIXME: Use XCheckTypedWindowEvent() instead ( same in the 
+   *	    CLIPBOARD_CheckSelection() ). 
+   */
 
-  selectionWait=True;
-  while(selectionWait) 
-        EVENT_WaitNetEvent( TRUE, FALSE );
+    selectionWait=True;
+    while(selectionWait) EVENT_WaitNetEvent( TRUE, FALSE );
 
   /* we treat Unix text as CF_OEMTEXT */
-  dprintf_clipboard(stddeb,"\tgot CF_OEMTEXT = %i\n", 
-		    ClipFormats[CF_OEMTEXT-1].wDataPresent);
+    dprintf_clipboard(stddeb,"\tgot CF_OEMTEXT = %i\n", 
+		      ClipFormats[CF_OEMTEXT-1].wDataPresent);
 
-  return (BOOL32)ClipFormats[CF_OEMTEXT-1].wDataPresent;
+    return (BOOL32)ClipFormats[CF_OEMTEXT-1].wDataPresent;
 }
 
 /**************************************************************************
@@ -192,21 +231,17 @@ static BOOL32 CLIPBOARD_RequestXSelection()
  */
 BOOL32 CLIPBOARD_IsPresent(WORD wFormat)
 {
-    LPCLIPFORMAT lpFormat = ClipFormats; 
-
     /* special case */
 
     if( wFormat == CF_TEXT || wFormat == CF_OEMTEXT )
-        return lpFormat[CF_TEXT-1].wDataPresent ||
-               lpFormat[CF_OEMTEXT-1].wDataPresent;
-
-    while(TRUE) {
-        if (lpFormat == NULL) return FALSE;
-        if (lpFormat->wFormatID == wFormat) break;
-        lpFormat = lpFormat->NextFormat;
-        }
-
-    return (lpFormat->wDataPresent);
+        return ClipFormats[CF_TEXT-1].wDataPresent ||
+               ClipFormats[CF_OEMTEXT-1].wDataPresent;
+    else
+    {
+	LPCLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat );
+	if( lpFormat ) return (lpFormat->wDataPresent);
+    }
+    return FALSE;
 }
 
 /**************************************************************************
@@ -220,18 +255,23 @@ BOOL16 WINAPI OpenClipboard16( HWND16 hWnd )
 
 /**************************************************************************
  *            OpenClipboard32   (USER32.406)
+ *
+ * Note: Netscape uses NULL hWnd to open the clipboard.
  */
 BOOL32 WINAPI OpenClipboard32( HWND32 hWnd )
 {
-    BOOL32 bRet = FALSE;
+    BOOL32 bRet;
+
     dprintf_clipboard(stddeb,"OpenClipboard(%04x) = ", hWnd);
 
-    if (!hWndClipWindow)
-       {
+    if (!hqClipLock)
+    {
+	 hqClipLock = GetTaskQueue(0);
     	 hWndClipWindow = hWnd;
+	 bCBHasChanged = FALSE;
 	 bRet = TRUE;
-       }
-    bClipChanged = FALSE;
+    }
+    else bRet = FALSE;
 
     dprintf_clipboard(stddeb,"%i\n", bRet);
     return bRet;
@@ -254,11 +294,14 @@ BOOL32 WINAPI CloseClipboard32(void)
 {
     dprintf_clipboard(stddeb,"CloseClipboard(); !\n");
 
-    if (hWndClipWindow == 0) return FALSE;
-    hWndClipWindow = 0;
-
-    if (bClipChanged && hWndViewer) SendMessage16(hWndViewer,WM_DRAWCLIPBOARD,0,0L);
+    if (hqClipLock == GetTaskQueue(0))
+    {
+	hWndClipWindow = 0;
 
+        if (bCBHasChanged && hWndViewer) 
+	    SendMessage16(hWndViewer, WM_DRAWCLIPBOARD, 0, 0L);
+	hqClipLock = 0;
+    }
     return TRUE;
 }
 
@@ -281,20 +324,20 @@ BOOL32 WINAPI EmptyClipboard32(void)
 
     dprintf_clipboard(stddeb,"EmptyClipboard()\n");
 
-    if (hWndClipWindow == 0) return FALSE;
+    if (hqClipLock != GetTaskQueue(0)) return FALSE;
 
     /* destroy private objects */
 
     if (hWndClipOwner)
-	SendMessage16(hWndClipOwner,WM_DESTROYCLIPBOARD,0,0L);
+	SendMessage16(hWndClipOwner, WM_DESTROYCLIPBOARD, 0, 0L);
   
     while(lpFormat) 
-      {
+    {
 	if ( lpFormat->wDataPresent || lpFormat->hData )
 	     CLIPBOARD_DeleteRecord( lpFormat, TRUE );
 
 	lpFormat = lpFormat->NextFormat;
-      }
+    }
 
     hWndClipOwner = hWndClipWindow;
 
@@ -307,7 +350,7 @@ BOOL32 WINAPI EmptyClipboard32(void)
 	dprintf_clipboard(stddeb, "\tgiving up selection (spw = %08x)\n", 
 				 	(unsigned)selectionPrevWindow);
 
-	XSetSelectionOwner(display,XA_PRIMARY,None,CurrentTime);
+	XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
     }
     return TRUE;
 }
@@ -336,34 +379,37 @@ HWND32 WINAPI GetClipboardOwner32(void)
  */
 HANDLE16 WINAPI SetClipboardData16( UINT16 wFormat, HANDLE16 hData )
 {
-    LPCLIPFORMAT lpFormat = ClipFormats; 
+    LPCLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat );
     Window       owner;
 
     dprintf_clipboard(stddeb,
 		"SetClipboardData(%04X, %04x) !\n", wFormat, hData);
 
-    while(TRUE) 
-      {
-	if (lpFormat == NULL) return 0;
-	if (lpFormat->wFormatID == wFormat) break;
-	lpFormat = lpFormat->NextFormat;
-      }
+    /* NOTE: If the hData is zero and current owner doesn't match
+     * the window that opened the clipboard then this application
+     * is screwed because WM_RENDERFORMAT will go to the owner
+     * (to become the owner it must call EmptyClipboard() before
+     *  adding new data).
+     */
+
+    if( (hqClipLock != GetTaskQueue(0)) || !lpFormat ||
+	(!hData && (!hWndClipOwner || (hWndClipOwner != hWndClipWindow))) ) return 0; 
 
     /* Acquire X selection if text format */
 
     if( !selectionAcquired && 
 	(wFormat == CF_TEXT || wFormat == CF_OEMTEXT) )
     {
-      owner = WIN_GetXWindow(hWndClipWindow);
-      XSetSelectionOwner(display,XA_PRIMARY,owner,CurrentTime);
-      if( XGetSelectionOwner(display,XA_PRIMARY) == owner )
-      {
-        selectionAcquired = True;
-	selectionWindow = owner;
-
-        dprintf_clipboard(stddeb,"Grabbed X selection, owner=(%08x)\n", 
+	owner = WIN_GetXWindow( hWndClipWindow ? hWndClipWindow : AnyPopup32() );
+	XSetSelectionOwner(display,XA_PRIMARY,owner,CurrentTime);
+	if( XGetSelectionOwner(display,XA_PRIMARY) == owner )
+	{
+	    selectionAcquired = True;
+	    selectionWindow = owner;
+
+	    dprintf_clipboard(stddeb,"Grabbed X selection, owner=(%08x)\n", 
 						(unsigned) owner);
-      }
+	}
     }
 
     if ( lpFormat->wDataPresent || lpFormat->hData ) 
@@ -380,7 +426,7 @@ HANDLE16 WINAPI SetClipboardData16( UINT16 wFormat, HANDLE16 hData )
 	    CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE);
     }
 
-    bClipChanged = TRUE;
+    bCBHasChanged = TRUE;
     lpFormat->wDataPresent = 1;
     lpFormat->hData = hData;          /* 0 is legal, see WM_RENDERFORMAT */
 
@@ -403,7 +449,7 @@ HANDLE32 WINAPI SetClipboardData32( UINT32 wFormat, HANDLE32 hData )
  */
 static BOOL32 CLIPBOARD_RenderFormat(LPCLIPFORMAT lpFormat)
 {
- if( lpFormat->wDataPresent && !lpFormat->hData )
+   if( lpFormat->wDataPresent && !lpFormat->hData )
    if( IsWindow32(hWndClipOwner) )
        SendMessage16(hWndClipOwner,WM_RENDERFORMAT,
                      (WPARAM16)lpFormat->wFormatID,0L);
@@ -414,37 +460,39 @@ static BOOL32 CLIPBOARD_RenderFormat(LPCLIPFORMAT lpFormat)
        hWndClipOwner = 0; lpFormat->wDataPresent = 0;
        return FALSE;
    }
- return (lpFormat->hData) ? TRUE : FALSE;
+   return (lpFormat->hData) ? TRUE : FALSE;
 }
 
 /**************************************************************************
  *                      CLIPBOARD_RenderText
+ *
+ * Convert text between UNIX and DOS formats.
  */
 static BOOL32 CLIPBOARD_RenderText(LPCLIPFORMAT lpTarget, LPCLIPFORMAT lpSource)
 {
-  UINT16 size = GlobalSize16( lpSource->hData );
-  LPCSTR	lpstrS = (LPSTR)GlobalLock16(lpSource->hData);
-  LPSTR		lpstrT;
+    UINT16 size = GlobalSize16( lpSource->hData );
+    LPCSTR lpstrS = (LPSTR)GlobalLock16(lpSource->hData);
+    LPSTR  lpstrT;
 
-  if( !lpstrS ) return FALSE;
-  dprintf_clipboard(stddeb,"\tconverting from '%s' to '%s', %i chars\n",
+    if( !lpstrS ) return FALSE;
+    dprintf_clipboard(stddeb,"\tconverting from '%s' to '%s', %i chars\n",
 			   	      lpSource->Name, lpTarget->Name, size);
 
-  lpTarget->hData = GlobalAlloc16(GMEM_ZEROINIT, size); 
-  lpstrT = (LPSTR)GlobalLock16(lpTarget->hData);
+    lpTarget->hData = GlobalAlloc16(GMEM_ZEROINIT, size); 
+    lpstrT = (LPSTR)GlobalLock16(lpTarget->hData);
 
-  if( lpstrT )
-  {
-    if( lpSource->wFormatID == CF_TEXT )
-	CharToOemBuff32A(lpstrS, lpstrT, size);
-    else
-	OemToCharBuff32A(lpstrS, lpstrT, size);
-    dprintf_clipboard(stddeb,"\tgot %s\n", lpstrT);
-    return TRUE;
-  }
+    if( lpstrT )
+    {
+	if( lpSource->wFormatID == CF_TEXT )
+	    CharToOemBuff32A(lpstrS, lpstrT, size);
+	else
+	    OemToCharBuff32A(lpstrS, lpstrT, size);
+	dprintf_clipboard(stddeb,"\tgot %s\n", lpstrT);
+	return TRUE;
+    }
 
-  lpTarget->hData = 0;
-  return FALSE;
+    lpTarget->hData = 0;
+    return FALSE;
 }
 
 /**************************************************************************
@@ -455,7 +503,7 @@ HANDLE16 WINAPI GetClipboardData16( UINT16 wFormat )
     LPCLIPFORMAT lpRender = ClipFormats; 
     LPCLIPFORMAT lpUpdate = NULL;
 
-    if (!hWndClipWindow) return 0;
+    if (hqClipLock != GetTaskQueue(0)) return 0;
 
     dprintf_clipboard(stddeb,"GetClipboardData(%04X)\n", wFormat);
 
@@ -477,18 +525,13 @@ HANDLE16 WINAPI GetClipboardData16( UINT16 wFormat )
     }
     else
     {
-      while(TRUE) 
-      {
-	if (lpRender == NULL) return 0;
-	if (lpRender->wFormatID == wFormat) break;
-	lpRender = lpRender->NextFormat;
-      }
-      lpUpdate = lpRender;
+	lpRender = __lookup_format( ClipFormats, wFormat );
+	lpUpdate = lpRender;
     }
    
-    if( !CLIPBOARD_RenderFormat(lpRender) ) return 0; 
-    if( lpUpdate != lpRender &&
-	!lpUpdate->hData ) CLIPBOARD_RenderText(lpUpdate, lpRender);
+    if( !lpRender || !CLIPBOARD_RenderFormat(lpRender) ) return 0; 
+    if( lpUpdate != lpRender && !lpUpdate->hData ) 
+	CLIPBOARD_RenderText(lpUpdate, lpRender);
 
     dprintf_clipboard(stddeb,"\treturning %04x (type %i)\n", 
 			      lpUpdate->hData, lpUpdate->wFormatID);
@@ -529,16 +572,16 @@ INT32 WINAPI CountClipboardFormats32(void)
     FormatCount += abs(lpFormat[CF_TEXT-1].wDataPresent -
 		       lpFormat[CF_OEMTEXT-1].wDataPresent); 
 
-    while(TRUE) {
+    while(TRUE) 
+    {
 	if (lpFormat == NULL) break;
 	if (lpFormat->wDataPresent) 
-	    {
-               dprintf_clipboard(stddeb, "\tdata found for format %i\n", lpFormat->wFormatID);
-
-	       FormatCount++;
-	    }
-	lpFormat = lpFormat->NextFormat;
+	{
+            dprintf_clipboard(stddeb, "\tdata found for format %i\n", lpFormat->wFormatID);
+	    FormatCount++;
 	}
+	lpFormat = lpFormat->NextFormat;
+    }
 
     dprintf_clipboard(stddeb,"\ttotal %d\n", FormatCount);
     return FormatCount;
@@ -563,7 +606,7 @@ UINT32 WINAPI EnumClipboardFormats32( UINT32 wFormat )
 
     dprintf_clipboard(stddeb,"EnumClipboardFormats(%04X)\n", wFormat);
 
-    if( !hWndClipWindow ) return 0;
+    if( hqClipLock != GetTaskQueue(0) ) return 0;
 
     if( (!wFormat || wFormat == CF_TEXT || wFormat == CF_OEMTEXT) 
 	 && !selectionAcquired) CLIPBOARD_RequestXSelection();
@@ -576,22 +619,19 @@ UINT32 WINAPI EnumClipboardFormats32( UINT32 wFormat )
 
     /* walk up to the specified format record */
 
-    while(TRUE) {
-	if (lpFormat == NULL) return 0;
-	if (lpFormat->wFormatID == wFormat) break;
-	lpFormat = lpFormat->NextFormat;
-	}
+    if( !(lpFormat = __lookup_format( lpFormat, wFormat )) ) return 0;
 
     /* find next format with available data */
 
     lpFormat = lpFormat->NextFormat;
-    while(TRUE) {
+    while(TRUE) 
+    {
 	if (lpFormat == NULL) return 0;
-	if (lpFormat->wDataPresent ||
-	       (lpFormat->wFormatID == CF_OEMTEXT &&
-		ClipFormats[CF_TEXT-1].wDataPresent)) break;
+	if (lpFormat->wDataPresent || (lpFormat->wFormatID == CF_OEMTEXT && 
+				       ClipFormats[CF_TEXT-1].wDataPresent)) 
+	    break;
 	lpFormat = lpFormat->NextFormat;
-	}
+    }
 
     return lpFormat->wFormatID;
 }
@@ -611,17 +651,18 @@ UINT16 WINAPI RegisterClipboardFormat16( LPCSTR FormatName )
 
     /* walk format chain to see if it's already registered */
 
-    while(TRUE) {
+    while(TRUE) 
+    {
 	if ( !strcmp(lpFormat->Name,FormatName) )
-	   {
+	{
 	     lpFormat->wRefCount++;
 	     return lpFormat->wFormatID;
-	   }
+	}
  
 	if ( lpFormat->NextFormat == NULL ) break;
 
 	lpFormat = lpFormat->NextFormat;
-	}
+    }
 
     /* allocate storage for new format entry */
 
@@ -677,18 +718,12 @@ INT16 WINAPI GetClipboardFormatName16( UINT16 wFormat, LPSTR retStr, INT16 maxle
  */
 INT32 WINAPI GetClipboardFormatName32A( UINT32 wFormat, LPSTR retStr, INT32 maxlen )
 {
-    LPCLIPFORMAT lpFormat = ClipFormats; 
+    LPCLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat );
 
     dprintf_clipboard(stddeb,
 	"GetClipboardFormatName(%04X, %p, %d) !\n", wFormat, retStr, maxlen);
 
-    while(TRUE) {
-	if (lpFormat == NULL) return 0;
-	if (lpFormat->wFormatID == wFormat) break;
-	lpFormat = lpFormat->NextFormat;
-	}
-
-    if (lpFormat->Name == NULL || 
+    if (lpFormat == NULL || lpFormat->Name == NULL || 
 	lpFormat->wFormatID < CF_REGFORMATBASE) return 0;
 
     dprintf_clipboard(stddeb,
@@ -758,7 +793,7 @@ HWND32 WINAPI GetClipboardViewer32(void)
  */
 BOOL16 WINAPI ChangeClipboardChain16(HWND16 hWnd, HWND16 hWndNext)
 {
-    return ChangeClipboardChain32(hWnd,hWndNext);
+    return ChangeClipboardChain32(hWnd, hWndNext);
 }
 
 /**************************************************************************
@@ -771,10 +806,10 @@ BOOL32 WINAPI ChangeClipboardChain32(HWND32 hWnd, HWND32 hWndNext)
     dprintf_clipboard(stdnimp, "ChangeClipboardChain(%04x, %04x)\n", hWnd, hWndNext);
 
     if( hWndViewer )
-      bRet = !SendMessage16( hWndViewer, WM_CHANGECBCHAIN,
+	bRet = !SendMessage16( hWndViewer, WM_CHANGECBCHAIN,
                              (WPARAM16)hWnd, (LPARAM)hWndNext);   
     else
-      dprintf_clipboard(stddeb,"ChangeClipboardChain: hWndViewer is lost\n");
+	dprintf_clipboard(stddeb,"ChangeClipboardChain: hWndViewer is lost\n");
 
     if( hWnd == hWndViewer ) hWndViewer = hWndNext;
 
@@ -929,32 +964,31 @@ void CLIPBOARD_ReadSelection(Window w,Atom prop)
  */
 void CLIPBOARD_ReleaseSelection(Window w, HWND32 hwnd)
 {
-  /* w is the window that lost selection,
-   * 
-   * selectionPrevWindow is nonzero if CheckSelection() was called. 
-   */
+    /* w is the window that lost selection,
+     * 
+     * selectionPrevWindow is nonzero if CheckSelection() was called. 
+     */
 
-  dprintf_clipboard(stddeb,"\tevent->window = %08x (sw = %08x, spw=%08x)\n", 
+    dprintf_clipboard(stddeb,"\tevent->window = %08x (sw = %08x, spw=%08x)\n", 
 	  (unsigned)w, (unsigned)selectionWindow, (unsigned)selectionPrevWindow );
 
-  if( selectionAcquired )
-    if( w == selectionWindow || selectionPrevWindow == None)
-    {
-      /* alright, we really lost it */
-
-      selectionAcquired = False;
-      selectionWindow = None; 
+    if( selectionAcquired )
+	if( w == selectionWindow || selectionPrevWindow == None)
+	{
+	    /* alright, we really lost it */
 
-      /* but we'll keep existing data for internal use */
-    }
-    else if( w == selectionPrevWindow )
-    {
-      w =  XGetSelectionOwner(display, XA_PRIMARY);
+	    selectionAcquired = False;
+	    selectionWindow = None; 
 
-      if( w == None )
-        XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
-    }
+	    /* but we'll keep existing data for internal use */
+	}
+	else if( w == selectionPrevWindow )
+	{
+	    w = XGetSelectionOwner(display, XA_PRIMARY);
+	    if( w == None )
+		XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
+	}
 
-  selectionPrevWindow = None;
+    selectionPrevWindow = None;
 }
 
diff --git a/windows/dce.c b/windows/dce.c
index 85761904f2b..df98a119d41 100644
--- a/windows/dce.c
+++ b/windows/dce.c
@@ -40,7 +40,7 @@ static INT32 DCE_ReleaseDC( DCE* );
 /***********************************************************************
  *           DCE_DumpCache
  */
-static void DCE_DumpCache()
+static void DCE_DumpCache(void)
 {
     DCE* dce = firstDCE;
     
@@ -206,7 +206,7 @@ static INT32 DCE_ReleaseDC( DCE* dce )
  * rectangle. wndScope is the immediate parent of the window(s) that 
  * was(were) moved and(or) resized.
  */
-BOOL32 DCE_InvalidateDCE(WND* wndScope, RECT32* pRectUpdate)
+BOOL32 DCE_InvalidateDCE(WND* wndScope, const RECT32* pRectUpdate)
 {
     BOOL32 bRet = FALSE;
 
@@ -219,8 +219,6 @@ BOOL32 DCE_InvalidateDCE(WND* wndScope, RECT32* pRectUpdate)
 				        pRectUpdate->right,pRectUpdate->bottom);
 	if( debugging_dc ) DCE_DumpCache();
 
-	if( !Options.desktopGeometry && wndScope == WIN_GetDesktop() ) return TRUE;
-
  	/* walk all DCEs and fixup non-empty entries */
 
 	for (dce = firstDCE; (dce); dce = dce->next)
@@ -234,8 +232,7 @@ BOOL32 DCE_InvalidateDCE(WND* wndScope, RECT32* pRectUpdate)
 		    WND* wnd = wndCurrent;
 		    INT32 xoffset = 0, yoffset = 0;
 
-		    if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) )
-			continue;
+		    if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) ) continue;
 
 		    /* check if DCE window is within the z-order scope */
 
@@ -288,7 +285,7 @@ BOOL32 DCE_InvalidateDCE(WND* wndScope, RECT32* pRectUpdate)
 /***********************************************************************
  *           DCE_Init
  */
-void DCE_Init()
+void DCE_Init(void)
 {
     int i;
     DCE * dce;
@@ -448,13 +445,20 @@ HRGN32 DCE_GetVisRgn( HWND32 hwnd, WORD flags )
 		    DCE_AddClipRects( wndPtr->parent->child,
 				      wndPtr, hrgnClip, &rect, xoffset, yoffset );
 
+		/* Clip siblings of all ancestors that have the
+                 * WS_CLIPSIBLINGS style
+		 */
+
 		while (wndPtr->dwStyle & WS_CHILD)
 		{
 		    wndPtr = wndPtr->parent;
 		    xoffset -= wndPtr->rectClient.left;
 		    yoffset -= wndPtr->rectClient.top;
-		    DCE_AddClipRects( wndPtr->parent->child, wndPtr,
-					hrgnClip, &rect, xoffset, yoffset );
+		    if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
+		    {
+			DCE_AddClipRects( wndPtr->parent->child, wndPtr,
+					  hrgnClip, &rect, xoffset, yoffset );
+		    }
 		}
 
 		/* Now once we've got a jumbo clip region we have
@@ -665,13 +669,9 @@ HDC32 WINAPI GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
 		   ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
 				      DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
 		{
-		    dprintf_dc(stddeb,"\tfound valid %08x dce [%04x]\n", (unsigned)dce, hwnd );
-
-/* Eventually, this won't be commented out but at this time
- * there are still some problems with DC reuse.
- * 
-		    bUpdateVisRgn = TRUE; 
- */
+		    dprintf_dc(stddeb,"\tfound valid %08x dce [%04x], flags %08x\n", 
+					(unsigned)dce, hwnd, (unsigned)dcxFlags );
+		    bUpdateVisRgn = FALSE; 
 		    bUpdateClipOrigin = TRUE;
 		    break;
 		}
@@ -718,7 +718,7 @@ HDC32 WINAPI GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
     DCE_SetDrawable( wndPtr, dc, flags, bUpdateClipOrigin );
     if( bUpdateVisRgn )
     {
-	dprintf_dc(stddeb,"updating %08x dce, visrgn [%04x]\n", (unsigned)dce, hwnd);
+	dprintf_dc(stddeb,"updating visrgn for %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
 
 	if (flags & DCX_PARENTCLIP)
         {
@@ -772,6 +772,8 @@ HDC32 WINAPI GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
 	dc->w.flags &= ~DC_DIRTY;
 	SelectVisRgn( hdc, hrgnVisible );
     }
+    else
+	dprintf_dc(stddeb,"no visrgn update %08x dce, hwnd [%04x]\n", (unsigned)dce, hwnd);
 
     /* apply additional region operation (if any) */
 
diff --git a/windows/defdlg.c b/windows/defdlg.c
index 1285d735257..36c146a0c4b 100644
--- a/windows/defdlg.c
+++ b/windows/defdlg.c
@@ -54,7 +54,8 @@ static BOOL32 DEFDLG_RestoreFocus( HWND32 hwnd, DIALOGINFO *infoPtr )
     if (!infoPtr->hwndFocus || IsIconic32(hwnd)) return FALSE;
     if (!IsWindow32( infoPtr->hwndFocus )) return FALSE;
     DEFDLG_SetFocus( hwnd, infoPtr->hwndFocus );
-    infoPtr->hwndFocus = 0;
+    /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
+       sometimes losing focus when receiving WM_SETFOCUS messages. */
     return TRUE;
 }
 
diff --git a/windows/defwnd.c b/windows/defwnd.c
index 8a2a7b338b5..80a8d92e91a 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -71,6 +71,25 @@ void DEFWND_SetText( WND *wndPtr, LPCSTR text )
     }
 }
 
+/***********************************************************************
+ *           DEFWND_ControlColor
+ *
+ * Default colors for control painting.
+ */
+HBRUSH32 DEFWND_ControlColor( HDC32 hDC, UINT16 ctlType )
+{
+    if( ctlType == CTLCOLOR_SCROLLBAR)
+    {
+	SetBkColor32( hDC, RGB(255, 255, 255) );
+	SetTextColor32( hDC, RGB(0, 0, 0) );
+	UnrealizeObject32( sysColorObjects.hbrushScrollbar );
+        return sysColorObjects.hbrushScrollbar;
+    }
+
+    SetBkColor32( hDC, GetSysColor32(COLOR_WINDOW) );
+    SetTextColor32( hDC, GetSysColor32(COLOR_WINDOWTEXT));
+    return sysColorObjects.hbrushWindow;
+}
 
 /***********************************************************************
  *           DEFWND_DefWinProc
@@ -89,7 +108,7 @@ static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT32 msg, WPARAM32 wParam,
         return NC_HandleNCHitTest( wndPtr->hwndSelf, MAKEPOINT16(lParam) );
 
     case WM_NCLBUTTONDOWN:
-	return NC_HandleNCLButtonDown( wndPtr->hwndSelf, wParam, lParam );
+	return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
 
     case WM_LBUTTONDBLCLK:
     case WM_NCLBUTTONDBLCLK:
@@ -206,32 +225,11 @@ static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT32 msg, WPARAM32 wParam,
     case WM_CTLCOLORBTN:
     case WM_CTLCOLORDLG:
     case WM_CTLCOLORSTATIC:
-        SetBkColor32( (HDC32)wParam, GetSysColor32(COLOR_WINDOW) );
-        SetTextColor32( (HDC32)wParam, GetSysColor32(COLOR_WINDOWTEXT) );
-        return (LRESULT)sysColorObjects.hbrushWindow;
-
     case WM_CTLCOLORSCROLLBAR:
-        SetBkColor32( (HDC32)wParam, RGB(255, 255, 255) );
-        SetTextColor32( (HDC32)wParam, RGB(0, 0, 0) );
-        UnrealizeObject32( sysColorObjects.hbrushScrollbar );
-        return (LRESULT)sysColorObjects.hbrushScrollbar;
+	return (LRESULT)DEFWND_ControlColor( (HDC32)wParam, msg - WM_CTLCOLORMSGBOX );
 
     case WM_CTLCOLOR:
-	{
-	    if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
-	    {
-		SetBkColor32( (HDC32)wParam, RGB(255, 255, 255) );
-		SetTextColor32( (HDC32)wParam, RGB(0, 0, 0) );
-		UnrealizeObject32( sysColorObjects.hbrushScrollbar );
-		return (LRESULT)sysColorObjects.hbrushScrollbar;
-	    }
-	    else
-	    {
-		SetBkColor32( (HDC32)wParam, GetSysColor32(COLOR_WINDOW) );
-		SetTextColor32((HDC32)wParam, GetSysColor32(COLOR_WINDOWTEXT));
-		return (LRESULT)sysColorObjects.hbrushWindow;
-	    }
-	}
+	return (LRESULT)DEFWND_ControlColor( (HDC32)wParam, HIWORD(lParam) );
 	
     case WM_GETTEXTLENGTH:
         if (wndPtr->text) return (LRESULT)strlen(wndPtr->text);
diff --git a/windows/event.c b/windows/event.c
index b54769a0d0f..69c40ecb615 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -5,6 +5,7 @@
  * 
  */
 
+#include <assert.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -27,6 +28,7 @@
 #include "win.h"
 #include "class.h"
 #include "clipboard.h"
+#include "dce.h"
 #include "message.h"
 #include "module.h"
 #include "options.h"
@@ -86,7 +88,7 @@ static const char * const event_names[] =
 };
 
   /* Event handlers */
-static void EVENT_Key( XKeyEvent *event );
+static void EVENT_Key( WND *pWnd, XKeyEvent *event );
 static void EVENT_ButtonPress( WND *pWnd, XButtonEvent *event );
 static void EVENT_ButtonRelease( WND *pWnd, XButtonEvent *event );
 static void EVENT_MotionNotify( WND *pWnd, XMotionEvent *event );
@@ -94,7 +96,7 @@ static void EVENT_FocusIn( WND *pWnd, XFocusChangeEvent *event );
 static void EVENT_FocusOut( WND *pWnd, XFocusChangeEvent *event );
 static void EVENT_Expose( WND *pWnd, XExposeEvent *event );
 static void EVENT_GraphicsExpose( WND *pWnd, XGraphicsExposeEvent *event );
-static void EVENT_ConfigureNotify( HWND32 hwnd, XConfigureEvent *event );
+static void EVENT_ConfigureNotify( WND *pWnd, XConfigureEvent *event );
 static void EVENT_SelectionRequest( WND *pWnd, XSelectionRequestEvent *event);
 static void EVENT_SelectionNotify( XSelectionEvent *event);
 static void EVENT_SelectionClear( WND *pWnd, XSelectionClearEvent *event);
@@ -160,8 +162,7 @@ void EVENT_ProcessEvent( XEvent *event )
     {
     case KeyPress:
     case KeyRelease:
-        if (InputEnabled)
-            EVENT_Key( (XKeyEvent*)event );
+        if (InputEnabled) EVENT_Key( pWnd, (XKeyEvent*)event );
 	break;
 	
     case ButtonPress:
@@ -208,7 +209,7 @@ void EVENT_ProcessEvent( XEvent *event )
         break;
 
     case ConfigureNotify:
-	EVENT_ConfigureNotify( pWnd->hwndSelf, (XConfigureEvent*)event );
+	EVENT_ConfigureNotify( pWnd, (XConfigureEvent*)event );
 	break;
 
     case SelectionRequest:
@@ -414,6 +415,7 @@ BOOL32 EVENT_WaitNetEvent( BOOL32 sleep, BOOL32 peek )
 	  }
 
 	  if( pWnd )
+          {
             if( (pQ = (MESSAGEQUEUE*)GlobalLock16(pWnd->hmemTaskQ)) )
             {
               pQ->flags |= QUEUE_FLAG_XEVENT;
@@ -421,9 +423,9 @@ BOOL32 EVENT_WaitNetEvent( BOOL32 sleep, BOOL32 peek )
 	      XPutBackEvent(display, &event);
               break;
 	    }
+          }
         }
-        else
-          EVENT_ProcessEvent( &event );
+        else EVENT_ProcessEvent( &event );
     }
     while (XPending( display ));
     return TRUE;
@@ -615,9 +617,9 @@ static void EVENT_GraphicsExpose( WND *pWnd, XGraphicsExposeEvent *event )
  *
  * Handle a X key event
  */
-static void EVENT_Key( XKeyEvent *event )
+static void EVENT_Key( WND *pWnd, XKeyEvent *event )
 {
-    KEYBOARD_HandleEvent( event );
+    KEYBOARD_HandleEvent( pWnd, event );
 }
 
 
@@ -627,8 +629,9 @@ static void EVENT_Key( XKeyEvent *event )
 static void EVENT_MotionNotify( WND *pWnd, XMotionEvent *event )
 {
     hardware_event( WM_MOUSEMOVE, EVENT_XStateToKeyState( event->state ), 0L,
-		    event->x_root - desktopX, event->y_root - desktopY,
-		    event->time - MSG_WineStartTicks, (DWORD)pWnd->hwndSelf );
+                    pWnd->rectWindow.left + event->x,
+                    pWnd->rectWindow.top + event->y,
+                    event->time - MSG_WineStartTicks, pWnd->hwndSelf );
 }
 
 
@@ -640,14 +643,14 @@ static void EVENT_MotionNotify( WND *pWnd, XMotionEvent *event )
 void EVENT_DummyMotionNotify(void)
 {
     Window root, child;
-    int rootX, rootY, childX, childY;
+    int rootX, rootY, winX, winY;
     unsigned int state;
 
     if (XQueryPointer( display, rootWindow, &root, &child,
-                       &rootX, &rootY, &childX, &childY, &state ))
+                       &rootX, &rootY, &winX, &winY, &state ))
     {
-        hardware_event(WM_MOUSEMOVE, EVENT_XStateToKeyState( state ), 0L,
-                       rootX - desktopX, rootY - desktopY, GetTickCount(), 0 );
+        hardware_event( WM_MOUSEMOVE, EVENT_XStateToKeyState( state ), 0L,
+                        winX, winY, GetTickCount(), 0 );
     }
 }
 
@@ -667,8 +670,9 @@ static void EVENT_ButtonPress( WND *pWnd, XButtonEvent *event )
     AsyncMouseButtonsStates[buttonNum] = 0x8000;
     hardware_event( messages[buttonNum],
 		    EVENT_XStateToKeyState( event->state ), 0L,
-		    event->x_root - desktopX, event->y_root - desktopY,
-		    event->time - MSG_WineStartTicks, (DWORD)pWnd->hwndSelf );
+                    pWnd->rectWindow.left + event->x,
+                    pWnd->rectWindow.top + event->y,
+		    event->time - MSG_WineStartTicks, pWnd->hwndSelf );
 }
 
 
@@ -683,11 +687,12 @@ static void EVENT_ButtonRelease( WND *pWnd, XButtonEvent *event )
 
     if (buttonNum >= NB_BUTTONS) return;    
     if (SwappedButtons) buttonNum = NB_BUTTONS - 1 - buttonNum;
-    MouseButtonsStates[buttonNum] = FALSE;
+    MouseButtonsStates[buttonNum] = 0;
     hardware_event( messages[buttonNum],
 		    EVENT_XStateToKeyState( event->state ), 0L,
-		    event->x_root - desktopX, event->y_root - desktopY,
-		    event->time - MSG_WineStartTicks, (DWORD)pWnd->hwndSelf );
+                    pWnd->rectWindow.left + event->x,
+                    pWnd->rectWindow.top + event->y,
+		    event->time - MSG_WineStartTicks, pWnd->hwndSelf );
 }
 
 
@@ -744,83 +749,118 @@ BOOL32 EVENT_CheckFocus(void)
     return TRUE;
 }
 
+
 /**********************************************************************
- *              EVENT_ConfigureNotify
+ *              EVENT_GetGeometry
  *
- * The ConfigureNotify event is only selected on the desktop window
- * and on top-level windows when the -managed flag is used.
+ * Helper function for ConfigureNotify handling.
+ * Get the new geometry of a window relative to the root window.
  */
-static void EVENT_ConfigureNotify( HWND32 hwnd, XConfigureEvent *event )
+static void EVENT_GetGeometry( Window win, int *px, int *py,
+                               unsigned int *pwidth, unsigned int *pheight )
 {
-    /* FIXME: with -desktop xxx we get this event _before_ desktop 
-     * window structure is created. WIN_GetDesktop() check is a hack.
-     */
+    Window root, parent, *children;
+    int xpos, ypos;
+    unsigned int width, height, border, depth, nb_children;
 
-    if ( !WIN_GetDesktop() || hwnd == GetDesktopWindow32())
+    if (!XGetGeometry( display, win, &root, px, py, pwidth, pheight,
+                       &border, &depth )) return;
+    if (win == rootWindow)
     {
-        desktopX = event->x;
-	desktopY = event->y;
+        *px = *py = 0;
+        return;
     }
+
+    for (;;)
+    {
+        if (!XQueryTree(display, win, &root, &parent, &children, &nb_children))
+            return;
+        XFree( children );
+        if (parent == rootWindow) break;
+        win = parent;
+        if (!XGetGeometry( display, win, &root, &xpos, &ypos,
+                           &width, &height, &border, &depth )) return;
+        *px += xpos;
+        *py += ypos;
+    }
+}
+
+
+/**********************************************************************
+ *              EVENT_ConfigureNotify
+ *
+ * The ConfigureNotify event is only selected on top-level windows
+ * when the -managed flag is used.
+ */
+static void EVENT_ConfigureNotify( WND *pWnd, XConfigureEvent *event )
+{
+    WINDOWPOS32 winpos;
+    RECT32 newWindowRect, newClientRect;
+    HRGN32 hrgnOldPos, hrgnNewPos;
+    Window above = event->above;
+    int x, y;
+    unsigned int width, height;
+
+    assert (pWnd->flags & WIN_MANAGED);
+
+    /* We don't rely on the event geometry info, because it is relative
+     * to parent and not to root, and it may be wrong (XFree sets x,y to 0,0
+     * if the window hasn't moved).
+     */
+    EVENT_GetGeometry( event->window, &x, &y, &width, &height );
+
+    /* Fill WINDOWPOS struct */
+    winpos.flags = SWP_NOACTIVATE | SWP_NOZORDER;
+    winpos.hwnd = pWnd->hwndSelf;
+    winpos.x = x;
+    winpos.y = y;
+    winpos.cx = width;
+    winpos.cy = height;
+
+    /* Check for unchanged attributes */
+    if (winpos.x == pWnd->rectWindow.left && winpos.y == pWnd->rectWindow.top)
+        winpos.flags |= SWP_NOMOVE;
+    if ((winpos.cx == pWnd->rectWindow.right - pWnd->rectWindow.left) &&
+        (winpos.cy == pWnd->rectWindow.bottom - pWnd->rectWindow.top))
+        winpos.flags |= SWP_NOSIZE;
     else
     {
-        WND *wndPtr = WIN_FindWndPtr( hwnd );
-	WINDOWPOS32 winpos;
-	RECT32 newWindowRect, newClientRect;
-	HRGN32 hrgnOldPos, hrgnNewPos;
-	Window above = event->above;
-
-	if (!wndPtr || !(wndPtr->flags & WIN_MANAGED)) return;
-
-	/* Fill WINDOWPOS struct */
-	winpos.flags = SWP_NOACTIVATE | SWP_NOZORDER;
-	winpos.hwnd = hwnd;
-        /* FIXME: position should be relative to root window */
-	winpos.x = event->x;
-	winpos.y = event->y;
-	winpos.cx = event->width;
-	winpos.cy = event->height;
-
-	/* Check for unchanged attributes */
-	if(winpos.x == wndPtr->rectWindow.left &&
-	   winpos.y == wndPtr->rectWindow.top)
-	    winpos.flags |= SWP_NOMOVE;
-	if(winpos.cx == wndPtr->rectWindow.right - wndPtr->rectWindow.left &&
-	   winpos.cy == wndPtr->rectWindow.bottom - wndPtr->rectWindow.top)
-	    winpos.flags |= SWP_NOSIZE;
-
-	/* Send WM_WINDOWPOSCHANGING */
-	SendMessage32A( hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)&winpos );
-
-	/* Calculate new position and size */
-	newWindowRect.left = event->x;
-	newWindowRect.right = event->x + event->width;
-	newWindowRect.top = event->y;
-	newWindowRect.bottom = event->y + event->height;
-
-	WINPOS_SendNCCalcSize( winpos.hwnd, TRUE, &newWindowRect,
-                               &wndPtr->rectWindow, &wndPtr->rectClient,
-                               &winpos, &newClientRect );
-
-        hrgnOldPos = CreateRectRgnIndirect32( &wndPtr->rectWindow );
-        hrgnNewPos = CreateRectRgnIndirect32( &newWindowRect );
-        CombineRgn32( hrgnOldPos, hrgnOldPos, hrgnNewPos, RGN_DIFF );
- 
-	/* Set new size and position */
-	wndPtr->rectWindow = newWindowRect;
-	wndPtr->rectClient = newClientRect;
-	SendMessage32A( hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos );
+        RECT32 rect = { 0, 0, pWnd->rectWindow.right - pWnd->rectWindow.left,
+                        pWnd->rectWindow.bottom - pWnd->rectWindow.top };
+        DCE_InvalidateDCE( pWnd, &rect );
+    }
 
-	if( IsWindow32( hwnd ) )
-	    if( above == None )			/* absolute bottom */
-	    {
-        	WIN_UnlinkWindow( hwnd );
-        	WIN_LinkWindow( hwnd, HWND_BOTTOM);
-	    }
-	    else EVENT_QueryZOrder( wndPtr );	/* try to outsmart window manager */
+    /* Send WM_WINDOWPOSCHANGING */
+    SendMessage32A( winpos.hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)&winpos );
+
+    /* Calculate new position and size */
+    newWindowRect.left = x;
+    newWindowRect.right = x + width;
+    newWindowRect.top = y;
+    newWindowRect.bottom = y + height;
+
+    WINPOS_SendNCCalcSize( winpos.hwnd, TRUE, &newWindowRect,
+                           &pWnd->rectWindow, &pWnd->rectClient,
+                           &winpos, &newClientRect );
 
-        DeleteObject32(hrgnOldPos);
-        DeleteObject32(hrgnNewPos);
+    hrgnOldPos = CreateRectRgnIndirect32( &pWnd->rectWindow );
+    hrgnNewPos = CreateRectRgnIndirect32( &newWindowRect );
+    CombineRgn32( hrgnOldPos, hrgnOldPos, hrgnNewPos, RGN_DIFF );
+    DeleteObject32(hrgnOldPos);
+    DeleteObject32(hrgnNewPos);
+ 
+    /* Set new size and position */
+    pWnd->rectWindow = newWindowRect;
+    pWnd->rectClient = newClientRect;
+    SendMessage32A( winpos.hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos );
+
+    if (!IsWindow32( winpos.hwnd )) return;
+    if( above == None )			/* absolute bottom */
+    {
+        WIN_UnlinkWindow( winpos.hwnd );
+        WIN_LinkWindow( winpos.hwnd, HWND_BOTTOM);
     }
+    else EVENT_QueryZOrder( pWnd );	/* try to outsmart window manager */
 }
 
 
@@ -1185,7 +1225,7 @@ void WINAPI Mouse_Event( CONTEXT *context )
      * SI = mouse event flags (?)
      */
     Window root, child;
-    int rootX, rootY, childX, childY;
+    int rootX, rootY, winX, winY;
     unsigned int state;
 
     if (AX_reg(context) & ME_MOVE)
@@ -1196,19 +1236,19 @@ void WINAPI Mouse_Event( CONTEXT *context )
         return;
     }
     if (!XQueryPointer( display, rootWindow, &root, &child,
-                        &rootX, &rootY, &childX, &childY, &state )) return;
+                        &rootX, &rootY, &winX, &winY, &state )) return;
     if (AX_reg(context) & ME_LDOWN)
-        hardware_event( WM_LBUTTONDOWN, EVENT_XStateToKeyState( state ), 0L,
-                        rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
+        hardware_event( WM_LBUTTONDOWN, EVENT_XStateToKeyState( state ),
+                        0L, winX, winY, GetTickCount(), 0 );
     if (AX_reg(context) & ME_LUP)
-        hardware_event( WM_LBUTTONUP, EVENT_XStateToKeyState( state ), 0L,
-                        rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
+        hardware_event( WM_LBUTTONUP, EVENT_XStateToKeyState( state ),
+                        0L, winX, winY, GetTickCount(), 0 );
     if (AX_reg(context) & ME_RDOWN)
-        hardware_event( WM_RBUTTONDOWN, EVENT_XStateToKeyState( state ), 0L,
-                        rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
+        hardware_event( WM_RBUTTONDOWN, EVENT_XStateToKeyState( state ),
+                        0L, winX, winY, GetTickCount(), 0 );
     if (AX_reg(context) & ME_RUP)
-        hardware_event( WM_RBUTTONUP, EVENT_XStateToKeyState( state ), 0L,
-                        rootX - desktopX, rootY - desktopY, GetTickCount(), 0);
+        hardware_event( WM_RBUTTONUP, EVENT_XStateToKeyState( state ),
+                        0L, winX, winY, GetTickCount(), 0 );
 }
 
 
diff --git a/windows/focus.c b/windows/focus.c
index 28aa8471ffe..9f7bb9ba674 100644
--- a/windows/focus.c
+++ b/windows/focus.c
@@ -69,12 +69,15 @@ void FOCUS_SwitchFocus( HWND32 hFocusFrom, HWND32 hFocusTo )
     if( !hFocusTo || hFocusTo != hwndFocus )
 	return;
 
+    /* According to API docs, the WM_SETFOCUS message is sent AFTER the window
+       has received the keyboard focus. */
+    FOCUS_SetXFocus( hFocusTo );
+
 #if 0
     SendMessage32A( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 );
 #else
     SendMessage16( hFocusTo, WM_SETFOCUS, hFocusFrom, 0 );
 #endif
-    FOCUS_SetXFocus( hFocusTo );
 }
 
 
diff --git a/windows/keyboard.c b/windows/keyboard.c
index 60c8cd648b5..83010946c72 100644
--- a/windows/keyboard.c
+++ b/windows/keyboard.c
@@ -26,7 +26,6 @@
 #include "stddebug.h"
 /* #define DEBUG_KEYBOARD */
 #include "debug.h"
-#include "accel.h"
 #include "struct32.h"
 
 BOOL32 MouseButtonsStates[3];
@@ -309,7 +308,8 @@ BOOL32 KEYBOARD_Init(void)
 
 static BOOL32 NumState=FALSE, CapsState=FALSE;
 
-void KEYBOARD_GenerateMsg( WORD vkey, int Evtype, XKeyEvent * event, KEYLP localkeylp )
+void KEYBOARD_GenerateMsg( WORD vkey, int Evtype, INT32 event_x, INT32 event_y,
+                           DWORD event_time, KEYLP localkeylp )
 {
   BOOL32 * State = (vkey==VK_NUMLOCK? &NumState : &CapsState);
 
@@ -328,10 +328,10 @@ void KEYBOARD_GenerateMsg( WORD vkey, int Evtype, XKeyEvent * event, KEYLP local
 		dprintf_keyboard(stddeb,"ON + KeyRelease => generating DOWN and UP messages.\n");
 		localkeylp.lp1.previous = 0; /* ? */
 		localkeylp.lp1.transition = 0;
-		hardware_event( WM_KEYDOWN, vkey, localkeylp.lp2, event->x_root - desktopX,
-				event->y_root - desktopY, event->time - MSG_WineStartTicks, 0);
-		hardware_event( WM_KEYUP, vkey, localkeylp.lp2, event->x_root - desktopX,
-				event->y_root - desktopY, event->time - MSG_WineStartTicks, 0);
+		hardware_event( WM_KEYDOWN, vkey, localkeylp.lp2,
+                                event_x, event_y, event_time, 0 );
+		hardware_event( WM_KEYUP, vkey, localkeylp.lp2,
+                                event_x, event_y, event_time, 0 );
 		*State=FALSE;
 		InputKeyStateTable[vkey] &= ~0x01; /* Toggle state to off. */ 
 	      } 
@@ -340,12 +340,12 @@ void KEYBOARD_GenerateMsg( WORD vkey, int Evtype, XKeyEvent * event, KEYLP local
 	  if (Evtype==KeyPress)
 	    {
 	      dprintf_keyboard(stddeb,"OFF + Keypress => generating DOWN and UP messages.\n");
-	      hardware_event( WM_KEYDOWN, vkey, localkeylp.lp2, event->x_root - desktopX,
-			      event->y_root - desktopY, event->time - MSG_WineStartTicks, 0);
+	      hardware_event( WM_KEYDOWN, vkey, localkeylp.lp2,
+                              event_x, event_y, event_time, 0 );
 	      localkeylp.lp1.previous = 1;
 	      localkeylp.lp1.transition = 1;
-	      hardware_event( WM_KEYUP, vkey, localkeylp.lp2, event->x_root - desktopX,
-			      event->y_root - desktopY, event->time - MSG_WineStartTicks, 0);
+	      hardware_event( WM_KEYUP, vkey, localkeylp.lp2,
+                              event_x, event_y, event_time, 0 );
 	      *State=TRUE; /* Goes to intermediary state before going to ON */
 	      InputKeyStateTable[vkey] |= 0x01; /* Toggle state to on. */
 	    }
@@ -357,7 +357,7 @@ void KEYBOARD_GenerateMsg( WORD vkey, int Evtype, XKeyEvent * event, KEYLP local
  *
  * Handle a X key event
  */
-void KEYBOARD_HandleEvent( XKeyEvent *event )
+void KEYBOARD_HandleEvent( WND *pWnd, XKeyEvent *event )
 {
     char Str[24]; 
     XComposeStatus cs; 
@@ -368,17 +368,21 @@ void KEYBOARD_HandleEvent( XKeyEvent *event )
 
     int ascii_chars = XLookupString(event, Str, 1, &keysym, &cs);
 
+    INT32 event_x = pWnd->rectWindow.left + event->x;
+    INT32 event_y = pWnd->rectWindow.top + event->y;
+    DWORD event_time = event->time - MSG_WineStartTicks;
+
     dprintf_key(stddeb, "EVENT_key : state = %X\n", event->state);
     if (keysym == XK_Mode_switch)
 	{
 	dprintf_key(stddeb, "Alt Gr key event received\n");
 	event->keycode = XKeysymToKeycode(event->display, XK_Control_L);
 	dprintf_key(stddeb, "Control_L is keycode 0x%x\n", event->keycode);
-	KEYBOARD_HandleEvent(event);
+	KEYBOARD_HandleEvent( pWnd, event );
 	event->keycode = XKeysymToKeycode(event->display, XK_Alt_L);
 	dprintf_key(stddeb, "Alt_L is keycode 0x%x\n", event->keycode);
 	force_extended = TRUE;
-	KEYBOARD_HandleEvent(event);
+	KEYBOARD_HandleEvent( pWnd, event );
 	force_extended = FALSE;
 	return;
 	}
@@ -416,10 +420,13 @@ void KEYBOARD_HandleEvent( XKeyEvent *event )
     switch(vkey)
     {
     case VK_NUMLOCK:    
-      KEYBOARD_GenerateMsg(VK_NUMLOCK,event->type,event,keylp); break;
+      KEYBOARD_GenerateMsg( VK_NUMLOCK, event->type, event_x, event_y,
+                            event_time, keylp);
+      break;
     case VK_CAPITAL:
       dprintf_keyboard(stddeb,"Caps Lock event. (type %d). State before : %#.2x\n",event->type,InputKeyStateTable[vkey]);
-      KEYBOARD_GenerateMsg(VK_CAPITAL,event->type,event,keylp); 
+      KEYBOARD_GenerateMsg( VK_CAPITAL, event->type, event_x, event_y,
+                            event_time, keylp ); 
       dprintf_keyboard(stddeb,"State after : %#.2x\n",InputKeyStateTable[vkey]);
       break;
     default:
@@ -452,14 +459,18 @@ void KEYBOARD_HandleEvent( XKeyEvent *event )
 	if (!(InputKeyStateTable[VK_NUMLOCK] & 0x01) != !(event->state & NumLockMask))
 	  { 
 	    dprintf_keyboard(stddeb,"Adjusting NumLock state. \n");
-	    KEYBOARD_GenerateMsg(VK_NUMLOCK,KeyPress,event,keylp);
-	    KEYBOARD_GenerateMsg(VK_NUMLOCK,KeyRelease,event,keylp);
+	    KEYBOARD_GenerateMsg( VK_NUMLOCK, KeyPress, event_x, event_y,
+                                  event_time, keylp );
+	    KEYBOARD_GenerateMsg( VK_NUMLOCK, KeyRelease, event_x, event_y,
+                                  event_time, keylp );
 	  }
 	if (!(InputKeyStateTable[VK_CAPITAL] & 0x01) != !(event->state & LockMask))
 	  {
 	    dprintf_keyboard(stddeb,"Adjusting Caps Lock state. State before %#.2x \n",InputKeyStateTable[VK_CAPITAL]);
-	    KEYBOARD_GenerateMsg(VK_CAPITAL,KeyPress,event,keylp);
-	    KEYBOARD_GenerateMsg(VK_CAPITAL,KeyRelease,event,keylp);
+	    KEYBOARD_GenerateMsg( VK_CAPITAL, KeyPress, event_x, event_y,
+                                  event_time, keylp );
+	    KEYBOARD_GenerateMsg( VK_CAPITAL, KeyRelease, event_x, event_y,
+                                  event_time, keylp );
 	    dprintf_keyboard(stddeb,"State after %#.2x \n",InputKeyStateTable[VK_CAPITAL]);
 	  }
 	/* End of intermediary states. */
@@ -471,8 +482,8 @@ void KEYBOARD_HandleEvent( XKeyEvent *event )
 	dprintf_key(stddeb,"            InputKeyState=%X\n",
 		    InputKeyStateTable[vkey]);
 
-	hardware_event( message, vkey, keylp.lp2, event->x_root - desktopX,
-			event->y_root - desktopY, event->time - MSG_WineStartTicks, 0 );
+	hardware_event( message, vkey, keylp.lp2,
+                        event_x, event_y, event_time, 0 );
       }
     }
    }
@@ -831,7 +842,7 @@ WORD WINAPI VkKeyScan32A(CHAR cChar)
 	      index : 1     adds 0x0100 (shift)
 	      index : ?     adds 0x0200 (ctrl)
 	      index : 2     adds 0x0600 (ctrl+alt)
-	      index : ?     adds 0x0700 (ctrl+alt+shit (used?))
+	      index : ?     adds 0x0700 (ctrl+alt+shift (used?))
 	     */
 	  }
 	dprintf_keyboard(stddeb," ... returning %#.2x\n", keyc2vkey[keycode]+highbyte);
diff --git a/windows/mdi.c b/windows/mdi.c
index ccc4bcf201b..54babe0edbc 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -37,58 +37,38 @@ static HBITMAP16 hBmpRestore = 0;
 DWORD SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
 
 /* ----------------- declarations ----------------- */
-static void MDI_UpdateFrameText(WND *, HWND16, BOOL32, LPCSTR);
-static BOOL32 MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND16);
-static BOOL32 MDI_RestoreFrameMenu(WND *, HWND16);
+static void MDI_UpdateFrameText(WND *, HWND32, BOOL32, LPCSTR);
+static BOOL32 MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND32);
+static BOOL32 MDI_RestoreFrameMenu(WND *, HWND32);
 
-static LONG MDI_ChildActivate(WND* ,HWND16 );
+static LONG MDI_ChildActivate( WND*, HWND32 );
 
 /* -------- Miscellaneous service functions ----------
  *
  *			MDI_GetChildByID
  */
 
-static HWND16 MDI_GetChildByID(WND* wndPtr,int id)
+static HWND32 MDI_GetChildByID(WND* wndPtr, INT32 id)
 {
     for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
         if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
     return 0;
 }
 
-static void MDI_PostUpdate(HWND16 hwnd, MDICLIENTINFO* ci, WORD recalc)
+static void MDI_PostUpdate(HWND32 hwnd, MDICLIENTINFO* ci, WORD recalc)
 {
     if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
     {
 	ci->mdiFlags |= MDIF_NEEDUPDATE;
-	PostMessage16( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
+	PostMessage32A( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
     }
     ci->sbRecalc = recalc;
 }
 
-/**********************************************************************
- *			MDI_MenuAppendItem
- */
-#ifdef SUPERFLUOUS_FUNCTIONS
-static BOOL32 MDI_MenuAppendItem(WND *clientWnd, HWND16 hWndChild)
-{
- char buffer[128];
- MDICLIENTINFO  *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
- WND		*wndPtr     = WIN_FindWndPtr(hWndChild);
- int 		 n          = sprintf(buffer, "%d ", 
-				      clientInfo->nActiveChildren);
-
- if( !clientInfo->hWindowMenu ) return 0; 
-    
- if (wndPtr->text) strncpy(buffer + n, wndPtr->text, sizeof(buffer) - n - 1);
- return AppendMenu32A( clientInfo->hWindowMenu, MF_STRING,
-                       wndPtr->wIDmenu, buffer );
-}
-#endif
-
 /**********************************************************************
  *			MDI_MenuModifyItem
  */
-static BOOL32 MDI_MenuModifyItem(WND* clientWnd, HWND16 hWndChild )
+static BOOL32 MDI_MenuModifyItem(WND* clientWnd, HWND32 hWndChild )
 {
     char            buffer[128];
     MDICLIENTINFO  *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
@@ -111,7 +91,7 @@ static BOOL32 MDI_MenuModifyItem(WND* clientWnd, HWND16 hWndChild )
 /**********************************************************************
  *			MDI_MenuDeleteItem
  */
-static BOOL32 MDI_MenuDeleteItem(WND* clientWnd, HWND16 hWndChild )
+static BOOL32 MDI_MenuDeleteItem(WND* clientWnd, HWND32 hWndChild )
 {
     char    	 buffer[128];
     MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
@@ -156,7 +136,8 @@ static BOOL32 MDI_MenuDeleteItem(WND* clientWnd, HWND16 hWndChild )
  *
  * returns "activateable" child different from the current or zero
  */
-static HWND16 MDI_GetWindow(WND *clientWnd, HWND16 hWnd, BOOL16 bNext, DWORD dwStyleMask )
+static HWND32 MDI_GetWindow(WND *clientWnd, HWND32 hWnd, BOOL32 bNext,
+                            DWORD dwStyleMask )
 {
     MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
     WND *wndPtr, *pWnd, *pWndLast = NULL;
@@ -186,7 +167,7 @@ static HWND16 MDI_GetWindow(WND *clientWnd, HWND16 hWnd, BOOL16 bNext, DWORD dwS
  *
  *  It seems that the default height is about 2/3 of the client rect
  */
-static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT16 lpPos,
+static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT32 lpPos,
                                      INT32 delta)
 {
     INT32  nstagger;
@@ -206,84 +187,68 @@ static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT16 lpPos,
 /**********************************************************************
  *            MDISetMenu
  */
-static HMENU16 MDISetMenu(HWND16 hwnd, BOOL32 fRefresh, HMENU16 hmenuFrame,
-                          HMENU16 hmenuWindow)
+static LRESULT MDISetMenu( HWND32 hwnd, HMENU32 hmenuFrame,
+                           HMENU32 hmenuWindow)
 {
-    WND           *w         = WIN_FindWndPtr(hwnd);
+    WND *w = WIN_FindWndPtr(hwnd);
     MDICLIENTINFO *ci;
+    HWND32 hwndFrame = GetParent32(hwnd);
+    HMENU32 oldFrameMenu = GetMenu32(hwndFrame);
 
-    dprintf_mdi(stddeb, "WM_MDISETMENU: %04x %04x %04x %04x\n",
-                hwnd, fRefresh, hmenuFrame, hmenuWindow);
+    dprintf_mdi(stddeb, "WM_MDISETMENU: %04x %04x %04x\n",
+                hwnd, hmenuFrame, hmenuWindow);
 
     ci = (MDICLIENTINFO *) w->wExtra;
 
-    if (!fRefresh) 
-    {
-	HWND16 hwndFrame = GetParent16(hwnd);
-	HMENU32 oldFrameMenu = GetMenu32(hwndFrame);
-        
-	if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
-	    MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
+    if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
+        MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
 
-	if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
-	{
-	    /* delete menu items from ci->hWindowMenu 
-	     * and add them to hmenuWindow */
+    if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
+    {
+        /* delete menu items from ci->hWindowMenu 
+         * and add them to hmenuWindow */
 
-            INT32 i = GetMenuItemCount32(ci->hWindowMenu) - 1;
-	    INT32 pos = GetMenuItemCount32(hmenuWindow) + 1;
+        INT32 i = GetMenuItemCount32(ci->hWindowMenu) - 1;
+        INT32 pos = GetMenuItemCount32(hmenuWindow) + 1;
 
-            AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
+        AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
 
-	    if( ci->nActiveChildren )
-	    {
-	        INT32 j = i - ci->nActiveChildren + 1;
-		char buffer[100];
-		UINT32 id,state;
+        if( ci->nActiveChildren )
+        {
+            INT32 j = i - ci->nActiveChildren + 1;
+            char buffer[100];
+            UINT32 id,state;
 
-		for( ; i >= j ; i-- )
-		{
-		     id = GetMenuItemID32(ci->hWindowMenu,i );
-		     state = GetMenuState32(ci->hWindowMenu,i,MF_BYPOSITION); 
+            for( ; i >= j ; i-- )
+            {
+                id = GetMenuItemID32(ci->hWindowMenu,i );
+                state = GetMenuState32(ci->hWindowMenu,i,MF_BYPOSITION); 
 
-		     GetMenuString32A(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
+                GetMenuString32A(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
 
-		     DeleteMenu32(ci->hWindowMenu, i , MF_BYPOSITION);
-		     InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
-					     id, buffer);
-		     CheckMenuItem32(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
-		}
-	    }
+                DeleteMenu32(ci->hWindowMenu, i , MF_BYPOSITION);
+                InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
+                              id, buffer);
+                CheckMenuItem32(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
+            }
+        }
 
-	    /* remove separator */
-	    DeleteMenu32(ci->hWindowMenu, i, MF_BYPOSITION); 
+        /* remove separator */
+        DeleteMenu32(ci->hWindowMenu, i, MF_BYPOSITION); 
 
-	    ci->hWindowMenu = hmenuWindow;
-	} 
-
-	if( hmenuFrame && hmenuFrame!=oldFrameMenu)
-	{
-	    SetMenu32(hwndFrame, hmenuFrame);
-	    if( ci->hwndChildMaximized )
-	        MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
-	    return oldFrameMenu;
-	}
+        ci->hWindowMenu = hmenuWindow;
+    } 
 
+    if( hmenuFrame && hmenuFrame!=oldFrameMenu)
+    {
+        SetMenu32(hwndFrame, hmenuFrame);
+        if( ci->hwndChildMaximized )
+            MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
+        return oldFrameMenu;
     }
     return 0;
 }
 
-/**********************************************************************
- *            MDIIconArrange
- */
-static WORD MDIIconArrange(HWND16 parent)
-{
-  return ArrangeIconicWindows16(parent);	/* Any reason why the    */
-						/* existing icon arrange */
-						/* can't be used here?	 */
-						/* -DRP			 */
-}
-
 
 /* ------------------ MDI child window functions ---------------------- */
 
@@ -291,26 +256,24 @@ static WORD MDIIconArrange(HWND16 parent)
 /**********************************************************************
  *					MDICreateChild
  */
-static HWND16 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND16 parent, 
-                              LPMDICREATESTRUCT16 cs, LPARAM lParam )
+static HWND32 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND32 parent, 
+                              LPMDICREATESTRUCT32A cs )
 {
-    POINT16          pos[2]; 
+    POINT32          pos[2]; 
     DWORD	     style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
-    HWND16 	     hwnd, hwndMax = 0;
+    HWND32 	     hwnd, hwndMax = 0;
     WORD	     wIDmenu = ci->idFirstChild + ci->nActiveChildren;
     char	     lpstrDef[]="junk!";
 
     dprintf_mdi(stdnimp,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n", 
-					 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);    
+                cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);    
     /* calculate placement */
     MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
 
-    if( cs->cx == CW_USEDEFAULT16 || !cs->cx )
-        cs->cx = pos[1].x;
-    if( cs->cy == CW_USEDEFAULT16 || !cs->cy )
-        cs->cy = pos[1].y;
+    if (cs->cx == CW_USEDEFAULT32 || !cs->cx) cs->cx = pos[1].x;
+    if (cs->cy == CW_USEDEFAULT32 || !cs->cy) cs->cy = pos[1].y;
 
-    if( cs->x == CW_USEDEFAULT16 )
+    if( cs->x == CW_USEDEFAULT32 )
     {
  	cs->x = pos[0].x;
 	cs->y = pos[0].y;
@@ -320,11 +283,11 @@ static HWND16 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND16 parent,
     if( style & WS_VISIBLE && ci->hwndChildMaximized )
     {
 	if( style & WS_MAXIMIZE )
-	    SendMessage16(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
+	    SendMessage32A(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
 	hwndMax = ci->hwndChildMaximized;
-	ShowWindow16( hwndMax, SW_SHOWNOACTIVATE );
+	ShowWindow32( hwndMax, SW_SHOWNOACTIVATE );
 	if( style & WS_MAXIMIZE )
-	    SendMessage16(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
+	    SendMessage32A(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
     }
 
     /* this menu is needed to set a check mark in MDI_ChildActivate */
@@ -342,24 +305,30 @@ static HWND16 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND16 parent,
 
     if( w->flags & WIN_ISWIN32 )
     {
-    	MDICREATESTRUCT32A cs32a;
-
-	STRUCT32_MDICREATESTRUCT16to32A(cs,&cs32a);
-	cs32a.szTitle = (LPCSTR)PTR_SEG_TO_LIN(cs->szTitle);
-	cs32a.szClass = (LPCSTR)PTR_SEG_TO_LIN(cs->szClass);
-
-	hwnd = CreateWindow32A(cs32a.szClass,cs32a.szTitle, style, 
-			       cs->x, cs->y, cs->cx, cs->cy, parent, 
-			       (HMENU16)wIDmenu, cs->hOwner,
-			       (LPVOID)&cs32a);
-	STRUCT32_MDICREATESTRUCT32Ato16(&cs32a,cs);
+	hwnd = CreateWindow32A( cs->szClass, cs->szTitle, style, 
+                                cs->x, cs->y, cs->cx, cs->cy, parent, 
+                                (HMENU16)wIDmenu, cs->hOwner, cs );
     }
     else
-	hwnd = CreateWindow16( (LPCSTR)PTR_SEG_TO_LIN(cs->szClass),
-			       (LPCSTR)PTR_SEG_TO_LIN(cs->szTitle), style, 
-			       cs->x, cs->y, cs->cx, cs->cy, parent, 
-			       (HMENU32)wIDmenu, cs->hOwner,
-			       (LPVOID)lParam);
+    {
+    	MDICREATESTRUCT16 *cs16;
+        LPSTR title, cls;
+
+        cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
+        STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
+        title = SEGPTR_STRDUP( cs->szTitle );
+        cls   = SEGPTR_STRDUP( cs->szClass );
+        cs16->szTitle = SEGPTR_GET(title);
+        cs16->szClass = SEGPTR_GET(cls);
+
+	hwnd = CreateWindow16( cs->szClass, cs->szTitle, style, 
+			       cs16->x, cs16->y, cs16->cx, cs16->cy, parent, 
+			       (HMENU32)wIDmenu, cs16->hOwner,
+                               (LPVOID)SEGPTR_GET(cs16) );
+        SEGPTR_FREE( title );
+        SEGPTR_FREE( cls );
+        SEGPTR_FREE( cs16 );
+    }
 
     /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
 
@@ -369,7 +338,7 @@ static HWND16 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND16 parent,
 
 	MDI_MenuModifyItem(w ,hwnd); 
 	if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
-	    ShowWindow16( hwnd, SW_SHOWMINNOACTIVE );
+	    ShowWindow32( hwnd, SW_SHOWMINNOACTIVE );
 	else
 	{
 	    SetWindowPos32( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
@@ -404,7 +373,7 @@ static HWND16 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND16 parent,
  * Note: The rule here is that client rect of the maximized MDI child 
  *	 is equal to the client rect of the MDI client window.
  */
-static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND16 hwnd,
+static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND32 hwnd,
                                     MINMAXINFO16* lpMinMax )
 {
     WND*	childWnd = WIN_FindWndPtr(hwnd);
@@ -430,12 +399,12 @@ static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND16 hwnd,
  * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
  *       being activated 
  */
-static void MDI_SwitchActiveChild( HWND16 clientHwnd, HWND16 childHwnd,
+static void MDI_SwitchActiveChild( HWND32 clientHwnd, HWND32 childHwnd,
                                    BOOL32 bNextWindow )
 {
     WND		  *w	     = WIN_FindWndPtr(clientHwnd);
-    HWND16	   hwndTo    = 0;
-    HWND16	   hwndPrev  = 0;
+    HWND32	   hwndTo    = 0;
+    HWND32	   hwndPrev  = 0;
     MDICLIENTINFO *ci;
 
     hwndTo = MDI_GetWindow(w, childHwnd, bNextWindow, 0);
@@ -465,7 +434,7 @@ static void MDI_SwitchActiveChild( HWND16 clientHwnd, HWND16 childHwnd,
 	    SetWindowPos32( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0, 
 		  	    SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
 	if( bOptimize )
-	    ShowWindow16( clientHwnd, SW_SHOW );
+	    ShowWindow32( clientHwnd, SW_SHOW );
     }
 }
 
@@ -473,8 +442,9 @@ static void MDI_SwitchActiveChild( HWND16 clientHwnd, HWND16 childHwnd,
 /**********************************************************************
  *                                      MDIDestroyChild
  */
-static HWND16 MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci, HWND16 parent,
-                               HWND16 child, BOOL32 flagDestroy )
+static LRESULT MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci,
+                                HWND32 parent, HWND32 child,
+                                BOOL32 flagDestroy )
 {
     WND         *childPtr = WIN_FindWndPtr(child);
 
@@ -486,7 +456,7 @@ static HWND16 MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci, HWND16 parent,
 
 	    if( child == ci->hwndActiveChild )
 	    {
-		ShowWindow16( child, SW_HIDE);
+		ShowWindow32( child, SW_HIDE);
 		if( child == ci->hwndChildMaximized )
 		{
 		    MDI_RestoreFrameMenu(w_parent->parent, child);
@@ -505,7 +475,7 @@ static HWND16 MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci, HWND16 parent,
 
         if (flagDestroy)
 	{
-	    MDI_PostUpdate(GetParent16(child), ci, SB_BOTH+1);
+	    MDI_PostUpdate(GetParent32(child), ci, SB_BOTH+1);
             DestroyWindow32(child);
 	}
     }
@@ -519,10 +489,10 @@ static HWND16 MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci, HWND16 parent,
  *
  * Note: hWndChild is NULL when last child is being destroyed
  */
-static LONG MDI_ChildActivate( WND *clientPtr, HWND16 hWndChild )
+static LONG MDI_ChildActivate( WND *clientPtr, HWND32 hWndChild )
 {
     MDICLIENTINFO       *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra; 
-    HWND16                 prevActiveWnd = clientInfo->hwndActiveChild;
+    HWND32               prevActiveWnd = clientInfo->hwndActiveChild;
     WND                 *wndPtr = WIN_FindWndPtr( hWndChild );
     WND			*wndPrev = WIN_FindWndPtr( prevActiveWnd );
     BOOL32		 isActiveFrameWnd = 0;	 
@@ -542,7 +512,7 @@ static LONG MDI_ChildActivate( WND *clientPtr, HWND16 hWndChild )
     {
 	wndPrev->dwStyle |= WS_SYSMENU;
 	SendMessage32A( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
-        SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd, 
+        SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd,
                         (LPARAM)hWndChild);
         /* uncheck menu item */
        	if( clientInfo->hWindowMenu )
@@ -556,11 +526,10 @@ static LONG MDI_ChildActivate( WND *clientPtr, HWND16 hWndChild )
         if( hWndChild )
 	{
 		  clientInfo->hwndActiveChild = hWndChild;
-		  ShowWindow16( hWndChild, SW_SHOWMAXIMIZED);
+		  ShowWindow32( hWndChild, SW_SHOWMAXIMIZED);
 	}
 	else
-		ShowWindow16( clientInfo->hwndActiveChild, 
-			    SW_SHOWNORMAL );
+		ShowWindow32( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
 
     clientInfo->hwndActiveChild = hWndChild;
 
@@ -582,10 +551,10 @@ static LONG MDI_ChildActivate( WND *clientPtr, HWND16 hWndChild )
 
     if( isActiveFrameWnd )
     {
-	    SendMessage16( hWndChild, WM_NCACTIVATE, TRUE, 0L);
+	    SendMessage32A( hWndChild, WM_NCACTIVATE, TRUE, 0L);
 	    if( GetFocus32() == clientInfo->self )
-		SendMessage16( clientInfo->self, WM_SETFOCUS, 
-			    (WPARAM16)clientInfo->self, 0L );
+		SendMessage32A( clientInfo->self, WM_SETFOCUS, 
+                                (WPARAM32)clientInfo->self, 0L );
 	    else
 		SetFocus32( clientInfo->self );
     }
@@ -649,8 +618,8 @@ static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
 	WND**	heapPtr = ppWnd;
 	if( total )
 	{
-	    INT16	delta = 0, n = 0;
-	    POINT16	pos[2];
+	    INT32	delta = 0, n = 0;
+	    POINT32	pos[2];
 	    if( total < ci->nActiveChildren )
 		delta = SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
 
@@ -661,30 +630,32 @@ static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
                             (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
 
 		MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
-		SetWindowPos32((*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
-					      SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
+		SetWindowPos32( (*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y,
+                                pos[1].x, pos[1].y,
+                                SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
 		ppWnd++;
 	    }
 	}
 	HeapFree( SystemHeap, 0, heapPtr );
     }
 
-    if( total < ci->nActiveChildren ) ArrangeIconicWindows32( clientWnd->hwndSelf );
+    if( total < ci->nActiveChildren )
+        ArrangeIconicWindows32( clientWnd->hwndSelf );
     return 0;
 }
 
 /**********************************************************************
  *					MDITile
  */
-static LONG MDITile(WND* wndClient, MDICLIENTINFO *ci,WORD wParam)
+static void MDITile( WND* wndClient, MDICLIENTINFO *ci, WPARAM32 wParam )
 {
     WND**	ppWnd;
     UINT32	total = 0;
 
     if (ci->hwndChildMaximized)
-	ShowWindow16(ci->hwndChildMaximized, SW_NORMAL);
+	ShowWindow32(ci->hwndChildMaximized, SW_NORMAL);
 
-    if (ci->nActiveChildren == 0) return 0;
+    if (ci->nActiveChildren == 0) return;
 
     ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
 	    ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
@@ -744,7 +715,6 @@ static LONG MDITile(WND* wndClient, MDICLIENTINFO *ci,WORD wParam)
     }
   
     if( total < ci->nActiveChildren ) ArrangeIconicWindows32( wndClient->hwndSelf );
-    return 0;
 }
 
 /* ----------------------- Frame window ---------------------------- */
@@ -754,10 +724,10 @@ static LONG MDITile(WND* wndClient, MDICLIENTINFO *ci,WORD wParam)
  *					MDI_AugmentFrameMenu
  */
 static BOOL32 MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
-                                    HWND16 hChild )
+                                    HWND32 hChild )
 {
     WND*	child = WIN_FindWndPtr(hChild);
-    HMENU16  	hSysPopup = 0;
+    HMENU32  	hSysPopup = 0;
 
     dprintf_mdi(stddeb,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame,hChild);
 
@@ -797,7 +767,7 @@ static BOOL32 MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
 /**********************************************************************
  *					MDI_RestoreFrameMenu
  */
-static BOOL32 MDI_RestoreFrameMenu( WND *frameWnd, HWND16 hChild )
+static BOOL32 MDI_RestoreFrameMenu( WND *frameWnd, HWND32 hChild )
 {
     INT32 nItems = GetMenuItemCount32(frameWnd->wIDmenu) - 1;
 
@@ -821,7 +791,7 @@ static BOOL32 MDI_RestoreFrameMenu( WND *frameWnd, HWND16 hChild )
  *
  * Note: lpTitle can be NULL
  */
-static void MDI_UpdateFrameText( WND *frameWnd, HWND16 hClient,
+static void MDI_UpdateFrameText( WND *frameWnd, HWND32 hClient,
                                  BOOL32 repaint, LPCSTR lpTitle )
 {
     char   lpBuffer[MDI_MAXTITLELENGTH+1];
@@ -830,6 +800,12 @@ static void MDI_UpdateFrameText( WND *frameWnd, HWND16 hClient,
 
     dprintf_mdi(stddeb, "MDI: repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
 
+    if (!clientWnd)
+           return;
+
+    if (!ci)
+           return;
+
     /* store new "default" title if lpTitle is not NULL */
     if (lpTitle) 
     {
@@ -892,10 +868,10 @@ static void MDI_UpdateFrameText( WND *frameWnd, HWND16 hClient,
  *
  * This function handles all MDI requests.
  */
-LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam,
-                                LPARAM lParam)
+LRESULT WINAPI MDIClientWndProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
+                                 LPARAM lParam )
 {
-    LPCREATESTRUCT16     cs;
+    LPCREATESTRUCT32A    cs;
     MDICLIENTINFO       *ci;
     RECT32		 rect;
     WND                 *w 	  = WIN_FindWndPtr(hwnd);
@@ -908,7 +884,7 @@ LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam,
     {
       case WM_CREATE:
 
-	cs = (LPCREATESTRUCT16) PTR_SEG_TO_LIN(lParam);
+	cs = (LPCREATESTRUCT32A)lParam;
 
 	/* Translation layer doesn't know what's in the cs->lpCreateParams
 	 * so we have to keep track of what environment we're in. */
@@ -966,52 +942,46 @@ LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam,
 	return 0;
 
       case WM_MDIACTIVATE:
-        if( ci->hwndActiveChild != (HWND16)wParam )
-	    SetWindowPos32((HWND32)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE ); 
+        if( ci->hwndActiveChild != (HWND32)wParam )
+	    SetWindowPos32((HWND32)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
 	return 0;
 
       case WM_MDICASCADE:
 	return MDICascade(w, ci);
 
       case WM_MDICREATE:
-        if( lParam )
-	{
-	    MDICREATESTRUCT16* cs = (MDICREATESTRUCT16*) PTR_SEG_TO_LIN(lParam);
-	    return (LONG)MDICreateChild(w, ci, hwnd, cs, lParam );
-	}
+        if (lParam) return MDICreateChild( w, ci, hwnd,
+                                           (MDICREATESTRUCT32A*)lParam );
 	return 0;
 
       case WM_MDIDESTROY:
-	return (LONG)MDIDestroyChild(w, ci, hwnd, (HWND32)wParam, TRUE);
+	return MDIDestroyChild( w, ci, hwnd, (HWND32)wParam, TRUE );
 
       case WM_MDIGETACTIVE:
-	return ((LONG) ci->hwndActiveChild | 
-		((LONG) (ci->hwndChildMaximized>0) << 16));
+          if (lParam) *(BOOL32 *)lParam = (ci->hwndChildMaximized > 0);
+          return ci->hwndActiveChild;
 
       case WM_MDIICONARRANGE:
 	ci->mdiFlags |= MDIF_NEEDUPDATE;
-	MDIIconArrange(hwnd);
+        ArrangeIconicWindows32(hwnd);
 	ci->sbRecalc = SB_BOTH+1;
-	SendMessage16(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
+	SendMessage32A(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
 	return 0;
 	
       case WM_MDIMAXIMIZE:
-	ShowWindow16((HWND16)wParam, SW_MAXIMIZE);
+	ShowWindow32( (HWND32)wParam, SW_MAXIMIZE );
 	return 0;
 
       case WM_MDINEXT: /* lParam != 0 means previous window */
-	MDI_SwitchActiveChild(hwnd, (HWND16)wParam, (lParam)? FALSE : TRUE );
+	MDI_SwitchActiveChild(hwnd, (HWND32)wParam, (lParam)? FALSE : TRUE );
 	break;
 	
       case WM_MDIRESTORE:
-	ShowWindow16( (HWND16)wParam, SW_NORMAL);
+	ShowWindow32( (HWND32)wParam, SW_NORMAL);
 	return 0;
 
       case WM_MDISETMENU:
-          /* if Winelib32:
-           * return (LRESULT)MDISetMenu(hwnd, FALSE, (HMENU16)wParam, (HMENU16)lParam);
-           */
-          return (LRESULT)MDISetMenu(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
+          return MDISetMenu( hwnd, (HMENU32)wParam, (HMENU32)lParam );
 	
       case WM_MDITILE:
 	ci->mdiFlags |= MDIF_NEEDUPDATE;
@@ -1038,19 +1008,18 @@ LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam,
 	
       case WM_NCACTIVATE:
         if( ci->hwndActiveChild )
-	     SendMessage16(ci->hwndActiveChild, message, wParam, lParam);
+	     SendMessage32A(ci->hwndActiveChild, message, wParam, lParam);
 	break;
 	
       case WM_PARENTNOTIFY:
-        if( wParam == WM_LBUTTONDOWN )
+        if (LOWORD(wParam) == WM_LBUTTONDOWN)
         {
             POINT16  pt = MAKEPOINT16(lParam);
             HWND16 child = ChildWindowFromPoint16(hwnd, pt);
 
 	    dprintf_mdi(stddeb,"MDIClient: notification from %04x (%i,%i)\n",child,pt.x,pt.y);
 
-            if( child && child != hwnd &&
-			 child != ci->hwndActiveChild )
+            if( child && child != hwnd && child != ci->hwndActiveChild )
                 SetWindowPos32(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
         }
         return 0;
@@ -1059,10 +1028,10 @@ LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam,
         if( ci->hwndChildMaximized )
 	{
 	    WND*	child = WIN_FindWndPtr(ci->hwndChildMaximized);
-	    RECT16	rect  = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
+	    RECT32	rect  = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
 
-	    AdjustWindowRectEx16(&rect, child->dwStyle, 0, child->dwExStyle);
-	    MoveWindow16(ci->hwndChildMaximized, rect.left, rect.top,
+	    AdjustWindowRectEx32(&rect, child->dwStyle, 0, child->dwExStyle);
+	    MoveWindow32(ci->hwndChildMaximized, rect.left, rect.top,
 			 rect.right - rect.left, rect.bottom - rect.top, 1);
 	}
 	else
@@ -1080,7 +1049,7 @@ LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam,
 	return 0;
     }
     
-    return DefWindowProc16(hwnd, message, wParam, lParam);
+    return DefWindowProc32A( hwnd, message, wParam, lParam );
 }
 
 
diff --git a/windows/nonclient.c b/windows/nonclient.c
index 3638ebc22ff..923583621d3 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -5,6 +5,7 @@
  *
  */
 
+#include "version.h"
 #include "win.h"
 #include "message.h"
 #include "sysmetrics.h"
@@ -1331,22 +1332,6 @@ BOOL32 NC_GetSysPopupPos( WND* wndPtr, RECT32* rect )
   return FALSE;
 }
 
-/***********************************************************************
- *           NC_TrackSysMenu
- *
- * Track a mouse button press on the system menu.
- * TODO: Unify with NC_TrackMinMaxBox() (and without InternalGetMessage() calls).
- */
-static void NC_TrackSysMenu( HWND32 hwnd, POINT16 pt )
-{
-    WND*	wndPtr = WIN_FindWndPtr( hwnd );
-    
-    if (wndPtr->dwStyle & WS_SYSMENU)
-	SendMessage16( hwnd, WM_SYSCOMMAND, 
-		SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt));
-}
-
-
 /***********************************************************************
  *           NC_StartSizeMove
  *
@@ -1450,7 +1435,7 @@ static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
     WND *     wndPtr = WIN_FindWndPtr( hwnd );
     BOOL32    thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
     BOOL32    iconic = wndPtr->dwStyle & WS_MINIMIZE;
-    int       moved = 0;
+    BOOL32    moved = FALSE;
 
     if (IsZoomed32(hwnd) || !IsWindowVisible32(hwnd) ||
         (wndPtr->flags & WIN_MANAGED)) return;
@@ -1521,19 +1506,12 @@ static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
 	if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
     }
 
-    if( iconic )
+    if( iconic ) /* create a cursor for dragging */
     {
-	HICON16 hIcon = (wndPtr->class->hIcon)
-                      ? wndPtr->class->hIcon
+	HICON16 hIcon = (wndPtr->class->hIcon) ? wndPtr->class->hIcon
                       : (HICON16)SendMessage16( hwnd, WM_QUERYDRAGICON, 0, 0L);
-	if( hIcon )
-	{
-	    hDragCursor =  CURSORICON_IconToCursor( hIcon, TRUE );
-	    hOldCursor = SetCursor32(hDragCursor);
-	    ShowCursor32( TRUE );
-	} 
-	else iconic = FALSE;
-	WINPOS_ShowIconTitle( wndPtr, FALSE );
+	if( hIcon ) hDragCursor =  CURSORICON_IconToCursor( hIcon, TRUE );
+	if( !hDragCursor ) iconic = FALSE;
     }
 
     if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
@@ -1574,7 +1552,17 @@ static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
 
 	if (dx || dy)
 	{
-            moved = 1;
+	    if( !moved )
+	    {
+		moved = TRUE;
+        	if( iconic ) /* ok, no system popup tracking */
+		{
+		    hOldCursor = SetCursor32(hDragCursor);
+		    ShowCursor32( TRUE );
+		    WINPOS_ShowIconTitle( wndPtr, FALSE );
+		}
+	    }
+
 	    if (msg.message == WM_KEYDOWN) SetCursorPos32( pt.x, pt.y );
 	    else
 	    {
@@ -1599,9 +1587,12 @@ static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
     ReleaseCapture();
     if( iconic )
     {
-	ShowCursor32( FALSE );
-	SetCursor32(hOldCursor);
-	if( hDragCursor ) DestroyCursor32( hDragCursor );
+	if( moved ) /* restore cursors, show icon title later on */
+	{
+	    ShowCursor32( FALSE );
+	    SetCursor32( hOldCursor );
+	}
+        DestroyCursor32( hDragCursor );
     }
     else
 	NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
@@ -1616,40 +1607,43 @@ static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
 
     if (HOOK_IsHooked( WH_CBT ))
     {
-       RECT16* pr = SEGPTR_NEW(RECT16);
-       if( pr )
-       {
-           CONV_RECT32TO16( &sizingRect, pr );
-	  if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
+	RECT16* pr = SEGPTR_NEW(RECT16);
+	if( pr )
+	{
+            CONV_RECT32TO16( &sizingRect, pr );
+	    if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
 			        (LPARAM)SEGPTR_GET(pr)) )
-	      sizingRect = wndPtr->rectWindow;
-	  else
-	      CONV_RECT16TO32( pr, &sizingRect );
-	  SEGPTR_FREE(pr);
-       }
+		sizingRect = wndPtr->rectWindow;
+	    else
+		CONV_RECT16TO32( pr, &sizingRect );
+	    SEGPTR_FREE(pr);
+	}
     }
     SendMessage16( hwnd, WM_EXITSIZEMOVE, 0, 0 );
     SendMessage16( hwnd, WM_SETVISIBLE, !IsIconic16(hwnd), 0L);
 
-    /* Single click brings up the system menu when iconized */
-
-    if( moved )
+    if( moved && !((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
     {
-	if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
-
 	/* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
 	SetWindowPos32( hwnd, 0, sizingRect.left, sizingRect.top,
 			sizingRect.right - sizingRect.left,
 			sizingRect.bottom - sizingRect.top,
 		      ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
     }
-    if( wndPtr->dwStyle & WS_MINIMIZE )
-    {
-	WINPOS_ShowIconTitle( wndPtr, TRUE );
-	if (!moved && (wndPtr->dwStyle & WS_SYSMENU))
-            SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU,
-                           MAKELPARAM( pt.x, pt.y ) );
-    }
+
+    if( IsWindow32(hwnd) )
+	if( wndPtr->dwStyle & WS_MINIMIZE )
+	{
+	    /* Single click brings up the system menu when iconized */
+
+	    if( !moved ) 
+	    {
+		 if( wndPtr->dwStyle & WS_SYSMENU ) 
+		     SendMessage16( hwnd, WM_SYSCOMMAND,
+				    SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt));
+	    }
+	    else WINPOS_ShowIconTitle( wndPtr, TRUE );
+	}
 }
 
 
@@ -1663,18 +1657,15 @@ static void NC_TrackMinMaxBox( HWND32 hwnd, WORD wParam )
     MSG16 msg;
     HDC32 hdc = GetWindowDC32( hwnd );
     BOOL32 pressed = TRUE;
+    void  (*paintButton)(HWND32, HDC16, BOOL32);
 
     SetCapture32( hwnd );
     if (wParam == HTMINBUTTON)
-	if(TWEAK_Win95Look)
-	    NC_DrawMinButton95( hwnd, hdc, TRUE );
-	else
-	    NC_DrawMinButton( hwnd, hdc, TRUE );
+	paintButton = (TWEAK_Win95Look) ? &NC_DrawMinButton95 : &NC_DrawMinButton;
     else
-	if(TWEAK_Win95Look)
-	    NC_DrawMaxButton95( hwnd, hdc, TRUE );
-	else
-	    NC_DrawMaxButton( hwnd, hdc, TRUE );
+	paintButton = (TWEAK_Win95Look) ? &NC_DrawMaxButton95 : &NC_DrawMaxButton;
+
+    (*paintButton)( hwnd, hdc, TRUE );
 
     do
     {
@@ -1683,30 +1674,10 @@ static void NC_TrackMinMaxBox( HWND32 hwnd, WORD wParam )
 
 	pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
 	if (pressed != oldstate)
-	{
-	    if (wParam == HTMINBUTTON)
-		if(TWEAK_Win95Look)
-		    NC_DrawMinButton95( hwnd, hdc, pressed );
-		else
-		    NC_DrawMinButton( hwnd, hdc, pressed );
-	    else
-		if(TWEAK_Win95Look)
-		    NC_DrawMaxButton95( hwnd, hdc, pressed );
-		else
-		    NC_DrawMaxButton( hwnd, hdc, pressed );
-	}
+	   (*paintButton)( hwnd, hdc, pressed );
     } while (msg.message != WM_LBUTTONUP);
 
-    if (wParam == HTMINBUTTON)
-	if(TWEAK_Win95Look)
-	    NC_DrawMinButton95( hwnd, hdc, FALSE );
-	else
-	    NC_DrawMinButton( hwnd, hdc, FALSE );
-    else
-	if(TWEAK_Win95Look)
-	    NC_DrawMaxButton95( hwnd, hdc, FALSE );
-	else
-	    NC_DrawMaxButton( hwnd, hdc, FALSE );
+    (*paintButton)( hwnd, hdc, FALSE );
 
     ReleaseCapture();
     ReleaseDC32( hwnd, hdc );
@@ -1781,20 +1752,34 @@ static void NC_TrackScrollBar( HWND32 hwnd, WPARAM32 wParam, POINT32 pt )
  *
  * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
  */
-LONG NC_HandleNCLButtonDown( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
+LONG NC_HandleNCLButtonDown( WND* pWnd, WPARAM16 wParam, LPARAM lParam )
 {
+    HWND32 hwnd = pWnd->hwndSelf;
+
     switch(wParam)  /* Hit test */
     {
     case HTCAPTION:
+	 hwnd = WIN_GetTopParent(hwnd);
 
-	if( WINPOS_SetActiveWindow(WIN_GetTopParent(hwnd), TRUE, TRUE)
-	    || (GetActiveWindow32() == WIN_GetTopParent(hwnd)) )
-		SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
-	break;
+	 if( WINPOS_SetActiveWindow(hwnd, TRUE, TRUE) || (GetActiveWindow32() == hwnd) )
+		SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
+	 break;
 
     case HTSYSMENU:
-	SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU, lParam );
-	break;
+	 if( pWnd->dwStyle & WS_SYSMENU )
+	 {
+	     if( !(pWnd->dwStyle & WS_MINIMIZE) )
+	     {
+		HDC32 hDC = GetWindowDC32(hwnd);
+		if( TWEAK_Win95Look)
+		    NC_DrawSysButton95( hwnd, hDC, TRUE );
+		else
+		    NC_DrawSysButton( hwnd, hDC, TRUE );
+		ReleaseDC32( hwnd, hDC );
+	     }
+	     SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU, lParam );
+	 }
+	 break;
 
     case HTMENU:
 	SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
@@ -1866,12 +1851,12 @@ LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam )
 
     case HTHSCROLL:
 	SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL,
-            lParam );
+		       lParam );
 	break;
 
     case HTVSCROLL:
 	SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL,
-            lParam );
+		       lParam );
 	break;
     }
     return 0;
@@ -1938,10 +1923,7 @@ LONG NC_HandleSysCommand( HWND32 hwnd, WPARAM16 wParam, POINT16 pt )
 
     case SC_SCREENSAVE:
 	if (wParam == SC_ABOUTWINE)
-	{   
-            extern const char people[];
-            ShellAbout32A(hwnd,"Wine",people,0);
-        }
+            ShellAbout32A(hwnd,"Wine", WINE_RELEASE_INFO, 0);
 	break;
   
     case SC_HOTKEY:
diff --git a/windows/painting.c b/windows/painting.c
index 77a37480ca5..8699c2edbff 100644
--- a/windows/painting.c
+++ b/windows/painting.c
@@ -207,32 +207,51 @@ void WINAPI FillWindow( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbru
 }
 
 
+/***********************************************************************
+ *	     PAINT_GetControlBrush
+ */
+static HBRUSH16 PAINT_GetControlBrush( HWND32 hParent, HWND32 hWnd, HDC16 hDC, UINT16 ctlType )
+{
+    HBRUSH16 bkgBrush = (HBRUSH16)SendMessage32A( hParent, WM_CTLCOLORMSGBOX + ctlType, 
+							     (WPARAM32)hDC, (LPARAM)hWnd );
+    if( !IsGDIObject(bkgBrush) )
+	bkgBrush = DEFWND_ControlColor( hDC, ctlType );
+    return bkgBrush;
+}
+
+
 /***********************************************************************
  *           PaintRect    (USER.325)
  */
 void WINAPI PaintRect( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
                        HBRUSH16 hbrush, const RECT16 *rect)
 {
-      /* Send WM_CTLCOLOR message if needed */
-
-    if ((UINT32)hbrush <= CTLCOLOR_MAX)
-    {
-	if (!hwndParent) return;
-	hbrush = (HBRUSH16)SendMessage32A( hwndParent, 
-                                           WM_CTLCOLORMSGBOX + (UINT32)hbrush,
-                                           (WPARAM32)hdc, (LPARAM)hwnd );
-    }
-    if (hbrush) FillRect16( hdc, rect, hbrush );
+    if( hbrush <= CTLCOLOR_MAX ) 
+	if( hwndParent )
+	    hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
+	else 
+	    return;
+    if( hbrush ) 
+	FillRect16( hdc, rect, hbrush );
 }
 
 
 /***********************************************************************
  *           GetControlBrush    (USER.326)
  */
-HBRUSH16 WINAPI GetControlBrush( HWND16 hwnd, HDC16 hdc, UINT16 control )
+HBRUSH16 WINAPI GetControlBrush( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
 {
-    return (HBRUSH16)SendMessage32A( GetParent32(hwnd), WM_CTLCOLOR+control,
-                                     (WPARAM32)hdc, (LPARAM)hwnd );
+    WND* wndPtr = WIN_FindWndPtr( hwnd );
+
+    if((ctlType <= CTLCOLOR_MAX) && wndPtr )
+    {
+	WND* parent;
+	if( wndPtr->dwStyle & WS_POPUP ) parent = wndPtr->owner;
+	else parent = wndPtr->parent;
+	if( !parent ) parent = wndPtr;
+	return (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
+    }
+    return (HBRUSH16)0;
 }
 
 
@@ -240,7 +259,9 @@ HBRUSH16 WINAPI GetControlBrush( HWND16 hwnd, HDC16 hdc, UINT16 control )
  *           PAINT_RedrawWindow
  *
  * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
- * SendMessage() calls. From SDK:
+ * SendMessage() calls. This is a comment inside DefWindowProc() source 
+ * from 16-bit SDK:
+ *
  *   This message avoids lots of inter-app message traffic
  *   by switching to the other task and continuing the
  *   recursion there.
diff --git a/windows/queue.c b/windows/queue.c
index f9534cd35c4..ecc6f30b647 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -11,6 +11,7 @@
 #include "queue.h"
 #include "task.h"
 #include "win.h"
+#include "clipboard.h"
 #include "hook.h"
 #include "thread.h"
 #include "process.h"
@@ -762,6 +763,7 @@ BOOL32 WINAPI SetMessageQueue32( INT32 size )
        if( WIN_GetDesktop()->hmemTaskQ == hQueue )
 	   WIN_GetDesktop()->hmemTaskQ = hNewQueue;
        WIN_ResetQueueWindows( WIN_GetDesktop(), hQueue, hNewQueue );
+       CLIPBOARD_ResetLock( hQueue, hNewQueue );
        QUEUE_DeleteMsgQueue( hQueue );
     }
 
diff --git a/windows/user.c b/windows/user.c
index dda1a28c867..f791b00cd26 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -15,6 +15,7 @@
 #include "task.h"
 #include "queue.h"
 #include "win.h"
+#include "clipboard.h"
 #include "hook.h"
 #include "debug.h"
 #include "toolhelp.h"
@@ -181,6 +182,7 @@ static void USER_AppExit( HTASK16 hTask, HINSTANCE16 hInstance, HQUEUE16 hQueue
 
     QUEUE_SetExitingQueue( hQueue );
     WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
+    CLIPBOARD_ResetLock( hQueue, 0 );
     QUEUE_SetExitingQueue( 0 );
 
     /* Free the message queue */
diff --git a/windows/win.c b/windows/win.c
index 58566067c70..11c45b817aa 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -330,6 +330,7 @@ static WND* WIN_DestroyWindow( WND* wndPtr )
 	    }
 	    QUEUE_RemoveMsg(msgQ, pos);
 	}
+	/* repost WM_QUIT to make sure this app exits its message loop */
 	if( bPostQuit ) PostQuitMessage32(wQuitParam);
 	wndPtr->hmemTaskQ = 0;
     }
@@ -653,7 +654,7 @@ static HWND32 WIN_CreateWindowEx( CREATESTRUCT32A *cs, ATOM classAtom,
 	    win_attr.event_mask = ExposureMask | KeyPressMask |
 	                          KeyReleaseMask | PointerMotionMask |
 	                          ButtonPressMask | ButtonReleaseMask |
-	                          FocusChangeMask | StructureNotifyMask;
+	                          FocusChangeMask;
             win_attr.override_redirect = TRUE;
 	}
         win_attr.colormap      = COLOR_GetColormap();
@@ -936,8 +937,8 @@ HWND32 WINAPI CreateWindowEx32W( DWORD exStyle, LPCWSTR className,
  */
 static void WIN_CheckFocus( WND* pWnd )
 {
-  if( GetFocus16() == pWnd->hwndSelf )
-      SetFocus16( (pWnd->dwStyle & WS_CHILD) ? pWnd->parent->hwndSelf : 0 ); 
+    if( GetFocus16() == pWnd->hwndSelf )
+	SetFocus16( (pWnd->dwStyle & WS_CHILD) ? pWnd->parent->hwndSelf : 0 ); 
 }
 
 /***********************************************************************
@@ -945,28 +946,25 @@ static void WIN_CheckFocus( WND* pWnd )
  */
 static void WIN_SendDestroyMsg( WND* pWnd )
 {
-  WND*	pChild;
-
-  WIN_CheckFocus(pWnd);
+    WIN_CheckFocus(pWnd);
 
-  if( CARET_GetHwnd() == pWnd->hwndSelf ) DestroyCaret32();
-  if( !pWnd->window ) CLIPBOARD_DisOwn( pWnd ); 
+    if( CARET_GetHwnd() == pWnd->hwndSelf ) DestroyCaret32();
+    if( !pWnd->window ) CLIPBOARD_ResetOwner( pWnd ); 
   
-  SendMessage32A( pWnd->hwndSelf, WM_DESTROY, 0, 0);
+    SendMessage32A( pWnd->hwndSelf, WM_DESTROY, 0, 0);
 
-  if( !IsWindow32(pWnd->hwndSelf) )
-  {
-    dprintf_win(stddeb,"\tdestroyed itself while in WM_DESTROY!\n");
-    return;
-  }
-
-  pChild = pWnd->child;
-  while( pChild )
-  { 
-    WIN_SendDestroyMsg( pChild );
-    pChild = pChild->next;
-  }
-  WIN_CheckFocus(pWnd);
+    if( IsWindow32(pWnd->hwndSelf) )
+    {
+	WND* pChild = pWnd->child;
+	while( pChild )
+	{
+	    WIN_SendDestroyMsg( pChild );
+	    pChild = pChild->next;
+	}
+	WIN_CheckFocus(pWnd);
+    }
+    else
+	dprintf_win(stddeb,"\tdestroyed itself while in WM_DESTROY!\n");
 }
 
 
@@ -1013,7 +1011,7 @@ BOOL32 WINAPI DestroyWindow32( HWND32 hwnd )
 	    if( !IsWindow32(hwnd) ) return TRUE;
 	}
 
-    if( wndPtr->window ) CLIPBOARD_DisOwn( wndPtr ); /* before window is unmapped */
+    if( wndPtr->window ) CLIPBOARD_ResetOwner( wndPtr ); /* before the window is unmapped */
 
       /* Hide the window */
 
diff --git a/windows/winpos.c b/windows/winpos.c
index b916d90c48d..1f28f5f3385 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -226,7 +226,7 @@ void WINAPI GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
 
 
 /***********************************************************************
- *           GetWindowRect32   (USER.32)
+ *           GetWindowRect32   (USER32.308)
  */
 void WINAPI GetWindowRect32( HWND32 hwnd, LPRECT32 rect ) 
 {
@@ -2202,7 +2202,9 @@ BOOL32 WINAPI SetWindowPos32( HWND32 hwnd, HWND32 hwndInsertAfter,
 				    newClientRect.top != wndPtr->rectClient.top) )
 	    winpos.flags &= ~SWP_NOCLIENTMOVE;
 
-    /* Update active DCEs */
+    /* Update active DCEs 
+     * TODO: Optimize conditions that trigger DCE update.
+     */
 
     if( (((winpos.flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && 
 					 wndPtr->dwStyle & WS_VISIBLE) || 
@@ -2211,7 +2213,7 @@ BOOL32 WINAPI SetWindowPos32( HWND32 hwnd, HWND32 hwndInsertAfter,
         RECT32 rect;
 
         UnionRect32(&rect, &newWindowRect, &wndPtr->rectWindow);
-        DCE_InvalidateDCE(wndPtr->parent, &rect);
+	DCE_InvalidateDCE(wndPtr->parent, &rect);
     }
 
     /* change geometry */
diff --git a/windows/winproc.c b/windows/winproc.c
index e5960bb527e..259b384071d 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -89,8 +89,6 @@ static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND32 hwnd,
                                                UINT32 msg, WPARAM32 wParam,
                                                LPARAM lParam );
 
-extern void CallFrom16_long_wwwll(void);
-
 static HANDLE32 WinProcHeap;
 
 
@@ -211,8 +209,8 @@ static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
                                            (void(*)())WINPROC_CallProc16To32A :
                                            (void(*)())WINPROC_CallProc16To32W;
             proc->thunk.t_from16.lcall       = 0x9a;   /* lcall cs:relay */
-            proc->thunk.t_from16.relay       = CallFrom16_long_wwwll;
-            proc->thunk.t_from16.cs          = WINE_CODE_SELECTOR;
+            proc->thunk.t_from16.relay       = Callbacks->CallFrom16WndProc;
+            GET_CS(proc->thunk.t_from16.cs);
             proc->jmp.jmp  = 0xe9;
             /* Fixup relative jump */
             proc->jmp.proc = (WNDPROC32)((DWORD)func -
-- 
GitLab