Release 951003

Sun Oct  1 15:48:34 1995  Alexandre Julliard  <julliard@sunsite.unc>

	* [controls/menu.c]
	Fixed GetMenuString() for non-string items.

	* [debugger/*.c]
	First attempt to check validity of pointers before memory
	accesses. For now only segmented pointers are checked.

	* [debugger/dbg.y] [memory/ldt.c]
	Added possibility to dump only one segment with 'info segment'.

	* [include/bitmaps/ocr_*]
	Added all OEM cursors as XPM bitmaps.

	* [include/cursoricon.h] [objects/cursoricon.c]
	Rewrote all cursor and icon management to use the same memory
 	layout as Windows, and to factor common code between icons and
	cursors. Implemented icon directory lookup to find the best
	matching icon (i.e. the color one).
  	Implemented CopyCursor() and DumpIcon().

	* [loader/module.c]
	For disabled built-in modules, we now try to load the Windows DLL
	first, and if this fails we fall back to using the built-in module
	anyway.

	* [memory/global.c]
	Fixed GlobalHandle() to return the correct selector in the high
	word even if we are passed a handle in the first place.

	* [miscemu/instr.c]
	Take into account the size of the operand and of the stack segment
	when incrementing the stack pointer.
	Avoid referencing FS_reg and GS_reg on *BSD.

	* [objects/dib.c]
	All DIB functions now accept a BITMAPCOREHEADER format bitmap.
	Monochrome DIBs are created as monochrome bitmap iff they are
	black and white.

	* [objects/oembitmap.c]
	Added support for OEM cursors, changed OBM_LoadIcon to use the new
	icon memory layout.

	* [rc/sysres_Fr.rc]
	Added French [Fr] language support.

	* [win32/environment.c]
	Fixed GetCommandLineA() to use current PDB.

	* [windows/event.c] [windows/winpos.c]
	Simulate a mouse motion event upon SetWindowPos() to force the
	cursor to be set correctly.

Sat Sep 30 17:49:32  Cameron Heide  (heide@ee.ualberta.ca)

	* [win32/*]
        New Win32 kernel functions: GetACP, GetCPInfo,
 	GetEnvironmentVariableA, GetFileType, GetLastError, GetOEMCP,
 	GetStartupInfoA, GetTimeZoneInformation, SetEnvironmentVariable,
 	SetFilePointer, SetLastError, VirtualAlloc, VirtualFree,
 	WriteFile.  Completed implementations of GetCommandLineA.

	* [include/kernel32.h]
        New file.

	* [loader/main.c]
        Call initialization function for Win32 data (doesn't currently do
 	anything).

	* [misc/main.c]
	Implemented GetEnvironmentVariableA, SetEnvironmentVariableA.

Sat Sep 30 00:26:56 1995  Niels de Carpentier  <niels@cindy.et.tudelft.nl>

	* [windows/winpos.c][miscemu/emulate.c][loader/module.c]
	  [misc/commdlg.c]
	Misc. bug fixes

Fri Sep 29 16:16:13 1995  Jim Peterson <jspeter@birch.ee.vt.edu>

	* [*/*]
	For Winelib, explicit casts have been placed where warnings were
 	usually generated.
	printf formats which give the format for printing a handle as
 	"%04x" or something similar have been changed to use the NPFMT
 	macro defined in include/wintypes.h.  Some times, explicit casts
 	were also necessary.
     	Parameter, field, and variable declarations have been made more
 	exact, such as converting 'WORD wParam' to 'WPARAM wParam' or
 	'WORD hFont' to 'HFONT hFont'.
     	Any call of the form GetWindowWord(hwnd,GWW_HINSTANCE) has been
 	replaced with a call to WIN_GetWindowInstance(hwnd).

	* [controls/combo.c]
	Added WINELIB32 support in CLBoxGetCombo().

	* [include/dialog.h]
	Commented out the '#ifndef WINELIB' around the '#pragma pack(1)'.
	winelib needs the packing as well (e.g. when accessing resources
	like sysres_DIALOG_SHELL_ABOUT_MSGBOX).

	* [include/windows.h]
	Got rid of the F[a-k] macros, which were cluttering up the global
	namespace.

	* [include/windows.h] [windows/defwnd.c]
	Added Win32 messages WM_CTLCOLOR*.

	* [include/wintypes.h]
	Put in preprocessor '#define WINELIB32' if appropriate and changed
	the types of some typedefs (WPARAM, HANDLE) based on this.
	
	* [loader/module.c] [toolkit/miscstubs.c]
	Added #ifdef'd portion in LoadModule to handle loading a WINElib
	module (already loaded, just init values).  '#ifdef'ed out the
	definition for GetWndProcEntry16 and added a new version to
	toolkit/miscstubs.c.

	* [misc/shell.c]
	Adjusted the lengths of AppName and AppMisc from 512,512 to 128,906.
	Same amount of total storage, but much more reasonable.  Also, changed
	calls to strcpy() in ShellAbout() to calls to strncpy() instead.
	This was a difficult bug to track down, but the AppMisc field was
	being initialized with the contributers text, which was much larger
	than 512 characters.

	* [toolkit/atom.c]
	New file for atom-handling functions.  Copied from memory/atom.c and
	then heavily modified.  Right now, it's just a linked list of atoms.
	Consider it as a hash table with just one entry.  It's easily changed
	later.

	* [toolkit/heap.c]
	Commented out the heap functions with a "#ifdef WINELIB16" and put in
	a Win32 version (which is basically a modified copy).

	* [toolkit/sup.c] [toolkit/miscstubs.c]
	Moved the stuff I put in toolkit/sup.c into toolkit/miscstubs.c and
	added quite a few more stubs.

	* [toolkit/winmain.c]
	Rearranged startup code in _WinMain.  I think this will work.

	* [toolkit/Makefile.in]
	Added targets for 'hello' and 'hello2' in case anyone cares to try
	out the sample programs.

Wed Sep 27 23:13:43 1995  Anand Kumria <akumria@ozemail.com.au>
	
	* [miscemu/int2f.c] [miscemu/vxd.c] [if1632/winprocs.spec]
	First attempt at support for some VxDs. Comm, Shell and Pagefile.

Tue Sep 26 21:34:45 1995  Hans de Graaff  <graaff@twi72.twi.tudelft.nl>

	* [misc/dos_fs.c]
	DOS_SimplifyPath: Also remove "/./" from path. (Happens when
 	starting applications like 'wine ./excel.exe')

Sat Sep 23 23:32:40 1995  Morten Welinder  <terra@diku.dk>

	* [configure.in]
	Avoid relative path for wine.ini.

	* [rc/sysres_Da.rc]
	Support for Danish [Da] language.

	* [misc/main.c] [miscemu/cpu.c]
	Return the processor we're running on correctly.

	* [miscemu/int2f.c]
	Minor stuff in int 0x2f, function 0x16.

Sat Sep 23 1995 17:58:04  Marcus Meissner  <msmeissn@faui01.informatik.uni-erlangen.de>

	* [misc/shell.c] [misc/main.c]
	Implement saving and loading of the registry database (needed for
	OLE). Very experimental. Fixed ShellExecute().
	
	* [miscemu/int21.c]
	EEXIST is not a critical error condition for mkdir().

Fri Sep 22 01:33:34 1995  Alex Korobka  <alex@phm6.pharm.sunysb.edu>

	* [include/shell.h] [misc/shell.c]
	Implemented 4 drag/drop functions with documented functionality.

        * [multimedia/time.c]
        "Fixed" MMSysTimeCallback kludge so Excel5 loads up without crashing.

	* [*/*] 
        Added new files, more message definitions, structures, debug info,
 	etc.  Rewrote message logging functions to produce output similar
 	to WinSight.  Check out -debugmsg +message option.

	* [misc/file.c]
        Fixed GetDriveType return value.  

        * [windows/message.c] 
        Hooks are invoked in normal order.

        * [miscemu/*]
        Added some functions and interrupts.

        * [misc/shell.c]
        Implemented Drag... functions.

Thu Sep 21 23:50:12 1995  Jukka Iivonen <iivonen@cc.helsinki.fi>

	* [rc/sysres_Fi.rc] [rc/sysres.rc]
	First attempt at Finnish [Fi] language support.
diff --git a/ANNOUNCE b/ANNOUNCE
index 04036c4..5a10f8b 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,15 +1,15 @@
-This is release 950918 of Wine the MS Windows emulator.  This is still a
+This is release 951003 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.
 
 Patches should be submitted to "wine-new@amscons.com".  Please don't forget
 to include a ChangeLog entry.  I'll make a new release every other week.
 
-WHAT'S NEW with Wine-950918: (see ChangeLog for details)
-	- Support for self-loading modules.
-	- Win32 support should begin to work again.
-	- Cursor fixes.
-	- New configure script should be useable now.
+WHAT'S NEW with Wine-951003: (see ChangeLog for details)
+	- New cursor handling.
+	- French, Danish and Finnish language support.
+	- Lots of Winelib improvements.
+	- Preliminary VxD support.
 	- Lots of bug fixes.
 
 See the README file in the distribution for installation instructions.
@@ -18,11 +18,11 @@
 the release is available at the ftp sites.  The sources will be available
 from the following locations:
 
-    sunsite.unc.edu:/pub/Linux/ALPHA/wine/Wine-950918.tar.gz
-    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-950918.tar.gz
-    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-950918.tar.gz
-    ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-950918.tar.gz
-    aris.com:/pub/linux/ALPHA/Wine/development/Wine-950918.tar.gz
+    sunsite.unc.edu:/pub/Linux/ALPHA/wine/Wine-951003.tar.gz
+    tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-951003.tar.gz
+    ftp.infomagic.com:/pub/mirrors/linux/wine/development/Wine-951003.tar.gz
+    ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-951003.tar.gz
+    aris.com:/pub/linux/ALPHA/Wine/development/Wine-951003.tar.gz
 
 It should also be available from any site that mirrors tsx-11 or sunsite.
 
@@ -36,7 +36,7 @@
 Wine is available thanks to the work of Bob Amstadt, Dag Asheim,
 Martin Ayotte, Ross Biro, Erik Bos, Fons Botman, John Brezak,
 Andrew Bulhak, John Burton, Paul Falstad, Olaf Flebbe, Peter Galbavy,
-Ramon Garcia, Hans de Graaf, Charles M. Hannum, Cameron Heide,
+Ramon Garcia, Hans de Graaff, Charles M. Hannum, Cameron Heide,
 Jochen Hoenicke, Jeffrey Hsu, Miguel de Icaza, Alexandre Julliard,
 Jon Konrath, Scott A. Laird, Martin von Loewis, Kenneth MacDonald,
 Peter MacDonald, William Magro, Marcus Meissner, Graham Menhennitt,
diff --git a/BUGS b/BUGS
index 5ec13e3..d0f6e47 100644
--- a/BUGS
+++ b/BUGS
@@ -1,4 +1,5 @@
 - EBP and ESP are sometimes corrupted while running 16-bit code.
+- Message flow is not correct for multiple tasks, some messages are not supported.
 - Dialog Boxes created by WM_CREATE handler aren't visible
 - MDI does not send WM_GETMINMAX message.
 - InitializeLoadedDLLs() can't init LZEXPAND.DLL. (cs:ip => 0:0)
diff --git a/ChangeLog b/ChangeLog
index 13a6e9e..3ddda8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,218 @@
 ----------------------------------------------------------------------
+Sun Oct  1 15:48:34 1995  Alexandre Julliard  <julliard@sunsite.unc>
+
+	* [controls/menu.c]
+	Fixed GetMenuString() for non-string items.
+
+	* [debugger/*.c]
+	First attempt to check validity of pointers before memory
+	accesses. For now only segmented pointers are checked.
+
+	* [debugger/dbg.y] [memory/ldt.c]
+	Added possibility to dump only one segment with 'info segment'.
+
+	* [include/bitmaps/ocr_*]
+	Added all OEM cursors as XPM bitmaps.
+
+	* [include/cursoricon.h] [objects/cursoricon.c]
+	Rewrote all cursor and icon management to use the same memory
+ 	layout as Windows, and to factor common code between icons and
+	cursors. Implemented icon directory lookup to find the best
+	matching icon (i.e. the color one).
+  	Implemented CopyCursor() and DumpIcon().
+
+	* [loader/module.c]
+	For disabled built-in modules, we now try to load the Windows DLL
+	first, and if this fails we fall back to using the built-in module
+	anyway.
+
+	* [memory/global.c]
+	Fixed GlobalHandle() to return the correct selector in the high
+	word even if we are passed a handle in the first place.
+
+	* [miscemu/instr.c]
+	Take into account the size of the operand and of the stack segment
+	when incrementing the stack pointer.
+	Avoid referencing FS_reg and GS_reg on *BSD.
+
+	* [objects/dib.c]
+	All DIB functions now accept a BITMAPCOREHEADER format bitmap.
+	Monochrome DIBs are created as monochrome bitmap iff they are
+	black and white.
+
+	* [objects/oembitmap.c]
+	Added support for OEM cursors, changed OBM_LoadIcon to use the new
+	icon memory layout.
+
+	* [rc/sysres_Fr.rc]
+	Added French [Fr] language support.
+
+	* [win32/environment.c]
+	Fixed GetCommandLineA() to use current PDB.
+
+	* [windows/event.c] [windows/winpos.c]
+	Simulate a mouse motion event upon SetWindowPos() to force the
+	cursor to be set correctly.
+
+Sat Sep 30 17:49:32  Cameron Heide  (heide@ee.ualberta.ca)
+
+	* [win32/*]
+        New Win32 kernel functions: GetACP, GetCPInfo,
+ 	GetEnvironmentVariableA, GetFileType, GetLastError, GetOEMCP,
+ 	GetStartupInfoA, GetTimeZoneInformation, SetEnvironmentVariable,
+ 	SetFilePointer, SetLastError, VirtualAlloc, VirtualFree,
+ 	WriteFile.  Completed implementations of GetCommandLineA.
+
+	* [include/kernel32.h]
+        New file.
+
+	* [loader/main.c]
+        Call initialization function for Win32 data (doesn't currently do
+ 	anything).
+
+	* [misc/main.c]
+	Implemented GetEnvironmentVariableA, SetEnvironmentVariableA.
+
+Sat Sep 30 00:26:56 1995  Niels de Carpentier  <niels@cindy.et.tudelft.nl>
+
+	* [windows/winpos.c][miscemu/emulate.c][loader/module.c]
+	  [misc/commdlg.c]
+	Misc. bug fixes
+
+Fri Sep 29 16:16:13 1995  Jim Peterson <jspeter@birch.ee.vt.edu>
+
+	* [*/*]
+	For Winelib, explicit casts have been placed where warnings were
+ 	usually generated.
+	printf formats which give the format for printing a handle as
+ 	"%04x" or something similar have been changed to use the NPFMT
+ 	macro defined in include/wintypes.h.  Some times, explicit casts
+ 	were also necessary.
+     	Parameter, field, and variable declarations have been made more
+ 	exact, such as converting 'WORD wParam' to 'WPARAM wParam' or
+ 	'WORD hFont' to 'HFONT hFont'.
+     	Any call of the form GetWindowWord(hwnd,GWW_HINSTANCE) has been
+ 	replaced with a call to WIN_GetWindowInstance(hwnd).
+
+	* [controls/combo.c]
+	Added WINELIB32 support in CLBoxGetCombo().
+
+	* [include/dialog.h]
+	Commented out the '#ifndef WINELIB' around the '#pragma pack(1)'.
+	winelib needs the packing as well (e.g. when accessing resources
+	like sysres_DIALOG_SHELL_ABOUT_MSGBOX).
+
+	* [include/windows.h]
+	Got rid of the F[a-k] macros, which were cluttering up the global
+	namespace.
+
+	* [include/windows.h] [windows/defwnd.c]
+	Added Win32 messages WM_CTLCOLOR*.
+
+	* [include/wintypes.h]
+	Put in preprocessor '#define WINELIB32' if appropriate and changed
+	the types of some typedefs (WPARAM, HANDLE) based on this.
+	
+	* [loader/module.c] [toolkit/miscstubs.c]
+	Added #ifdef'd portion in LoadModule to handle loading a WINElib
+	module (already loaded, just init values).  '#ifdef'ed out the
+	definition for GetWndProcEntry16 and added a new version to
+	toolkit/miscstubs.c.
+
+	* [misc/shell.c]
+	Adjusted the lengths of AppName and AppMisc from 512,512 to 128,906.
+	Same amount of total storage, but much more reasonable.  Also, changed
+	calls to strcpy() in ShellAbout() to calls to strncpy() instead.
+	This was a difficult bug to track down, but the AppMisc field was
+	being initialized with the contributers text, which was much larger
+	than 512 characters.
+
+	* [toolkit/atom.c]
+	New file for atom-handling functions.  Copied from memory/atom.c and
+	then heavily modified.  Right now, it's just a linked list of atoms.
+	Consider it as a hash table with just one entry.  It's easily changed
+	later.
+
+	* [toolkit/heap.c]
+	Commented out the heap functions with a "#ifdef WINELIB16" and put in
+	a Win32 version (which is basically a modified copy).
+
+	* [toolkit/sup.c] [toolkit/miscstubs.c]
+	Moved the stuff I put in toolkit/sup.c into toolkit/miscstubs.c and
+	added quite a few more stubs.
+
+	* [toolkit/winmain.c]
+	Rearranged startup code in _WinMain.  I think this will work.
+
+	* [toolkit/Makefile.in]
+	Added targets for 'hello' and 'hello2' in case anyone cares to try
+	out the sample programs.
+
+Wed Sep 27 23:13:43 1995  Anand Kumria <akumria@ozemail.com.au>
+	
+	* [miscemu/int2f.c] [miscemu/vxd.c] [if1632/winprocs.spec]
+	First attempt at support for some VxDs. Comm, Shell and Pagefile.
+
+Tue Sep 26 21:34:45 1995  Hans de Graaff  <graaff@twi72.twi.tudelft.nl>
+
+	* [misc/dos_fs.c]
+	DOS_SimplifyPath: Also remove "/./" from path. (Happens when
+ 	starting applications like 'wine ./excel.exe')
+
+Sat Sep 23 23:32:40 1995  Morten Welinder  <terra@diku.dk>
+
+	* [configure.in]
+	Avoid relative path for wine.ini.
+
+	* [rc/sysres_Da.rc]
+	Support for Danish [Da] language.
+
+	* [misc/main.c] [miscemu/cpu.c]
+	Return the processor we're running on correctly.
+
+	* [miscemu/int2f.c]
+	Minor stuff in int 0x2f, function 0x16.
+
+Sat Sep 23 1995 17:58:04  Marcus Meissner  <msmeissn@faui01.informatik.uni-erlangen.de>
+
+	* [misc/shell.c] [misc/main.c]
+	Implement saving and loading of the registry database (needed for
+	OLE). Very experimental. Fixed ShellExecute().
+	
+	* [miscemu/int21.c]
+	EEXIST is not a critical error condition for mkdir().
+
+Fri Sep 22 01:33:34 1995  Alex Korobka  <alex@phm6.pharm.sunysb.edu>
+
+	* [include/shell.h] [misc/shell.c]
+	Implemented 4 drag/drop functions with documented functionality.
+
+        * [multimedia/time.c]
+        "Fixed" MMSysTimeCallback kludge so Excel5 loads up without crashing.
+
+	* [*/*] 
+        Added new files, more message definitions, structures, debug info,
+ 	etc.  Rewrote message logging functions to produce output similar
+ 	to WinSight.  Check out -debugmsg +message option.
+
+	* [misc/file.c]
+        Fixed GetDriveType return value.  
+
+        * [windows/message.c] 
+        Hooks are invoked in normal order.
+
+        * [miscemu/*]
+        Added some functions and interrupts.
+
+        * [misc/shell.c]
+        Implemented Drag... functions.
+
+Thu Sep 21 23:50:12 1995  Jukka Iivonen <iivonen@cc.helsinki.fi>
+
+	* [rc/sysres_Fi.rc] [rc/sysres.rc]
+	First attempt at Finnish [Fi] language support.
+
+----------------------------------------------------------------------------
 Sun Sep 17 16:47:49 1995  Alexandre Julliard  <julliard@sunsite.unc.edu>
 
 	* [configure.in] [*/Makefile.in] [Make.rules.in]
diff --git a/Configure.old b/Configure.old
deleted file mode 100644
index 7e7f4a0..0000000
--- a/Configure.old
+++ /dev/null
@@ -1,221 +0,0 @@
-#! /bin/sh
-#
-# Configure script for wine
-
-: ${EDITOR:=vi}
-: ${PAGER:=more}
-
-WINELIB=''
-LANGUAGE=not_matching
-ALLDEFINES=''
-
-# Ask question 'str' and set 'var' to reply (defaulting to 'def' on CR)
-prompt ()
-{
-	str="$1"
-	var="$2"
-	def="$3"
-
-	eval $var='$def'
-	echo
-	echo -n "$str [$def]? "
-	input=`head -1`  #  When using read, user must double all backslashes
-	if [ -n "$input" ]
-	then
-		eval $var='$input'
-	fi
-}
-
-echo
-echo Read the RELEASE-NOTES for an explanation of the various flags
-echo
-
-echo -n 'Build Wine as emulator or library (E/L) [E]? '
-read input
-if [ "$input" = 'l' -o "$input" = 'L' ]
-then
-	WINELIB='#define WINELIB -DWINELIB'
-	ALLDEFINES="$ALLDEFINES -DWINELIB"
-fi
-
-LANGS=`echo En rc/sysres_*.rc | sed -e 's/rc\/sysres_//g' -e 's/\.rc//g' -e 's/ /\//g;'`
-while	expr "$LANGS" : ".*$LANGUAGE" = 0 > /dev/null
-do
-	prompt "Language ($LANGS)" LANGUAGE En
-	if	expr "$LANGS" : ".*$LANGUAGE" = 0 > /dev/null
-	then
-		echo "\"$LANGUAGE\" is not a supported language."
-	fi
-done
-ALLDEFINES="$ALLDEFINES -ALANG\($LANGUAGE\)"
-
-prompt "Inter-process communication" CONFIG_IPC N
-if [ CONFIG_IPC = 'Y' -o $CONFIG_IPC = 'y' ]
-then
-       ALLDEFINES="$ALLDEFINES -DCONFIG_IPC"
-fi
-
-prompt "Malloc debugging" MALLOC_DEBUGGING N
-if [ MALLOC_DEBUGGING = 'Y' -o $MALLOC_DEBUGGING = 'y' ]
-then
-       MALLOC_DEBUGGING="#define MALLOC_DEBUGGING"
-       ALLDEFINES="$ALLDEFINES -DMALLOC_DEBUGGING"
-else
-       MALLOC_DEBUGGING=''
-fi
-
-prompt "Global configfile name" WINE_CONFIGFILE /usr/local/etc/wine.conf
-
-if [ -r $WINE_CONFIGFILE ]
-then
-	DEFAULT_ANS=N
-else
-	DEFAULT_ANS=Y
-fi
-
-echo
-echo -n "Do you want to make a config file now (Y/N) [$DEFAULT_ANS]? "
-read input
-if [ "$input" = '' ]
-then
-	input="$DEFAULT_ANS"
-fi
-if [ "$input" = 'y' -o "$input" = 'Y' ]
-then
-	if [ -r $WINE_CONFIGFILE ]
-	then
-		echo "Backing up the old file to ${WINE_CONFIGFILE}.old."
-		if cp $WINE_CONFIGFILE ${WINE_CONFIGFILE}.old
-		then	:
-		else
-			echo "Error while creating backup file.  Fix it and run Configure again"
-			exit 1
-		fi
-	fi
-
-	CF_A=`mount | awk '/^\/dev\/fd/ {print $3;exit} END {print "/a"}'`
-	prompt "Which directory do you want to use as A:" CF_A $CF_A
-	CF_C=`awk '{if ($3=="msdos") {print $2;exit}} END {print "/c"}' /etc/fstab`
-	prompt "Which directory do you want to use as C:" CF_C $CF_C
-	prompt "Where is the Windows directory" CF_Windows 'c:\windows'
-	prompt "Where is the System directory" CF_System 'c:\windows\system'
-	if [ -r "$CF_C/autoexec.bat" ]
-	then
-		CF_Temp=`tr A-Z a-z < "$CF_C/autoexec.batX" | sed -n 's/^ *set *temp= *\(c:.*[a-z]\).*/\1/p'`
-	fi
-	if [ -z "$CF_Temp" ]
-	then
-		CF_Temp='c:\temp'
-	fi
-	prompt "Where should Windows apps store temp files" CF_Temp $CF_Temp
-	prompt "Which path should be used to find progs/DLL's" CF_Path "$CF_Windows;$CF_System"
-	prompt "Where is COM1" CF_Com1 '/dev/cua0'
-	prompt "Where is COM2" CF_Com2 '/dev/cua1'
-	prompt "Where is LPT1" CF_Lpt1 '/dev/lp0'
-
-	echo
-	sed -n -e 's/^ *\"\(WM_[A-Z0-9]*\)\".*/\1/p' < misc/spy.c | \
-		sort | pr -ta4w83 | sed '1 i\
-Here is the list of messages:\
-\
-' | $PAGER
-
-	prompt "Exclude which messages from the log" CF_Exclude 'WM_SIZE;WM_TIMER'
-
-	cat >  $WINE_CONFIGFILE << EOF
-[drives]
-A=$CF_A
-C=$CF_C
-
-[wine]
-Windows=$CF_Windows
-System=$CF_System
-Temp=$CF_Temp
-Path=$CF_Path
-SystemResources=$CF_SystemResources
-
-[fonts]
-system=*-helvetica
-mssansserif=*-helvetica
-msserif=*-times
-fixedsys=*-fixed
-arial=*-helvetica
-helv=*-helvetica
-roman=*-times
-default=*-*
-
-[serialports]
-Com1=$CF_Com1
-Com2=$CF_Com2
-
-[parallelports]
-Lpt1=$CF_Lpt1
-
-[spy]
-Exclude=$CF_Exclude
-EOF
-
-	echo
-	sed '1 i\
-The config file '"$WINE_CONFIGFILE"' now looks like this:\
-\
-' < $WINE_CONFIGFILE | $PAGER
-
-	echo
-	echo -n "Do you want to edit it using $EDITOR (Y/N) [N]? "
-	read input
-	if [ "$input" = 'y' -o "$input" = 'Y' ]
-	then
-		$EDITOR $WINE_CONFIGFILE
-	fi
-else
-	if [ ! -r $WINE_CONFIGFILE ]
-	then
-		echo 'Ok, remember to make it yourself later.'
-	fi
-fi
-
-cat > autoconf.h << EOF
-/* autoconf.h generated automatically.  Run Configure. */
-$WINELIB
-$MALLOC_DEBUGGING
-#define WINE_INI_GLOBAL "$WINE_CONFIGFILE"
-#define AutoDefines $ALLDEFINES
-EOF
-
-echo
-echo "Creating Makefiles.  This may take a while."
-if xmkmf -a
-then :
-else	cat << EOF
-
-WARNING:  The exit status of the command 'xmkmf -a' indicates an error.
-Maybe the Wine directory is incomplete, or Imake (see 'man xmkmf imake')
-is incorrectly configured?  In the latter case, it might be easiest to
-reinstall X11 to get a new copy of Imake.
-EOF
-fi
-
-if [ 0 -lt `find . -name "*.rej" -print | wc -l` ]
-then
-	cat << EOF
-
-WARNING:  You have some files named '*.rej', which usually indicates
-rejected patch files.  Maybe you tried to upgrade Wine with 'patch',
-and that some of the patches failed?  If something doesn't work, this
-might be the reason.  See 'man patch' (especially the '-p' option).
-
-List of "*.rej" files:
-
-EOF
-	find . -name "*.rej" -print
-fi
-
-if [ -f ./Makefile ]
-then
-	echo
-	echo "Configure finished.  Do 'make' to compile Wine."
-else
-	echo
-	echo "*** There was a problem with 'imake': the main Makefile has not be created."
-fi
diff --git a/DEVELOPERS-HINTS b/DEVELOPERS-HINTS
index 96e1713..a661276 100644
--- a/DEVELOPERS-HINTS
+++ b/DEVELOPERS-HINTS
@@ -57,13 +57,6 @@
 control to the proper handler.  The format of the *.spec files is
 documented in the file "tools/build-spec.txt".
 
-REGISTER FUNCTIONS:
-
-Some functions are defined as type "register" in the DLL specification files.
-In order to return values in the registers to the WIN16 program, the handler
-function must exit by calling ReturnFromRegisterFunc().  Look at the function
-DOS3Call() for an example of how this works.
-
 DEBUG MESSAGES:
 
 To display a message only during debugging, you normally write something
diff --git a/Imakefile b/Imakefile
deleted file mode 100644
index 47ffac6..0000000
--- a/Imakefile
+++ /dev/null
@@ -1,119 +0,0 @@
-#include "autoconf.h"
-#include "Wine.tmpl"
-
-#if defined(i386FreeBsd) || defined(FreeBSDArchitecture)
-MAKE = gmake
-#endif
-
-DEFINES = AutoDefines -DUSE_READLINE
-
-/*
- * This is the second try at using Imakefiles. There are probably many
- * problems and things I haven't even considered. I do not have a fixed
- * Linux system to test them on, but thanks to Thomas Michlmayr
- * <tmichl@cosy.sbg.ac.at> for use of one of his boxes. 
- *
- * SEE BELOW ABOUT DEBUGGING AND LINUX
- *
- * Peter Galbavy, 31st Jan 1994: peter@wonderland.org
- */
-
-#define IHaveSubdirs
-#define	PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)' 'CC=$(CC)' 'MAKE=$(MAKE)'\
-			'DEFINES=$(DEFINES)' 'LD=$(LD)' 'ASFLAGS=$(ASFLAGS)'
-
-COMMONSUBDIRS = \
-	controls \
-	rc \
-	ipc \
-	loader \
-	misc \
-	multimedia \
-	objects \
-	windows
-
-EMUSUBDIRS = \
-	tools \
-	debugger \
-	if1632 \
-	memory \
-	miscemu
-
-LIBSUBDIRS = \
-	toolkit
-
-WINEDIR = $(LIBDIR)/wine
-
-COMMONOBJS = \
-	controls/controls.o \
-	ipc/ipc.o \
-	loader/loader.o \
-	misc/misc.o \
-	multimedia/multimedia.o \
-	objects/objects.o \
-	rc/rc.o \
-	windows/windows.o
-
-EMUOBJS = \
-	debugger/debugger.o \
-	if1632/if1632.o \
-	memory/memory.o \
-	miscemu/miscemu.o
-
-LIBOBJS = \
-	toolkit/toolkit.o
-
-#ifndef WINELIB
-SUBDIRS = $(COMMONSUBDIRS) $(EMUSUBDIRS)
-OBJS = $(EMUOBJS) $(COMMONOBJS)
-#else
-SUBDIRS = $(COMMONSUBDIRS) $(LIBSUBDIRS)
-OBJS = $(LIBOBJS) $(COMMONOBJS)
-#endif
-
-#ifdef i386BsdArchitecture
-SYSLIBS = -ll -lm -li386 -lgnumalloc
-#endif
-#if defined(i386FreeBsd) || defined(FreeBSDArchitecture)
-SYSLIBS = -ll -lm -lgnumalloc
-#endif
-#ifdef LinuxArchitecture
-SYSLIBS = -lm -lg
-#endif
-
-/* You may need to add the full path of your libXpm here */
-XPM_LIB = -lXpm
-
-#ifdef MALLOC_DEBUGGING
-MALLOCLIB = -lmcheck
-#else
-MALLOCLIB =
-#endif
-
-MakeSubdirs($(SUBDIRS))
-DependSubdirs($(SUBDIRS))
-
-#ifndef WINELIB
-NormalProgramTarget(wine,$(OBJS),$(DEPXLIB),$(XPM_LIB) $(XLIB),$(MALLOCLIB) $(SYSLIBS))
-AllTarget(wine.sym)
-#else
-NormalLibraryTarget(wine,$(OBJS))
-#endif
-
-wine.sym: wine
-	nm wine|grep -v _compiled|sort >wine.sym
-
-clean::
-	$(RM) wine.sym
-
-depend::
-
-install::
-
-etags::
-	etags `find . -name '*.[chS]' -print`
-
-distclean: clean
-	echo "/* autoconf.h generated automatically.  Run Configure */" >autoconf.h
-	echo "#error You must run Configure before you can build the makefiles." >>autoconf.h
-	$(RM) config.* `find . -name Makefile -print`
diff --git a/Make.rules.in b/Make.rules.in
index c618c50..7894d2b 100644
--- a/Make.rules.in
+++ b/Make.rules.in
@@ -10,7 +10,7 @@
 LEX       = @LEX@
 LEXLIB    = @LEXLIB@
 DIVINCL   = -I$(TOPSRC)/include
-ALLCFLAGS = $(CFLAGS) $(DEFS) $(LANG) $(X_CFLAGS) $(DIVINCL) $(EXTRA_DEFS)
+ALLCFLAGS = $(CFLAGS) $(DEFS) -ALANG\($(LANG)\) $(X_CFLAGS) $(DIVINCL) $(EXTRA_DEFS)
 LDCOMBINE = ld -r
 RM        = rm -f
 @SET_MAKE@
diff --git a/Makefile.in b/Makefile.in
index 5559dd9..130f12f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -28,12 +28,12 @@
 
 MAIN_TARGET = @MAIN_TARGET@
 
-COMMONSUBDIRS = rc controls ipc loader misc multimedia objects windows
+COMMONSUBDIRS = rc controls ipc loader misc multimedia objects win32 windows
 
 EMUSUBDIRS = tools debugger debugger/readline if1632 memory miscemu
 
 LIBSUBDIRS = toolkit
- 
+
 ALLSUBDIRS = $(COMMONSUBDIRS) $(EMUSUBDIRS) $(LIBSUBDIRS)
 
 COMMONOBJS = \
@@ -44,6 +44,7 @@
 	multimedia/multimedia.o \
 	objects/objects.o \
 	rc/rc.o \
+	win32/win32.o \
 	windows/windows.o
 
 EMUOBJS = \
@@ -90,5 +91,5 @@
 langclean:
 	for i in $(ALLSUBDIRS); do (cd $$i; $(MAKE) langclean); done
 	$(RM) wine wine.sym winelib.a
-	
+
 dummy:
diff --git a/README b/README
index 6dc6d64..e00a177 100644
--- a/README
+++ b/README
@@ -22,7 +22,7 @@
 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
+The executable "wine" will be built.  "wine" will load and run 16-bit
 Windows executables.
 
 To upgrade to a new release by using a patch file, first cd to the
@@ -104,20 +104,15 @@
 
 * [spy]
 
-format: file = <filename or CON when logging to stdout>
+format: exclude = <message names and/or EXCLUDEALL separated by commas >
 default: none
 
-used to specify the file which will be used as logfile.
+Used to specify which messages will be excluded from the message logging.
 
-format: exclude = <message names separated by semicolons>
+format: include = <message names and/or INCLUDEALL separated by commas >
 default: none
 
-Used to specify which messages will be excluded from the logfile.
-
-format: include = <message names separated by semicolons>
-default: none
-
-Used to specify which messages will be included in the logfile.
+Used to specify which messages will be included in the message logging.
 
 
 4. RUNNING PROGRAMS
diff --git a/Wine.man b/Wine.man
index aeb1463..789a503 100644
--- a/Wine.man
+++ b/Wine.man
@@ -319,8 +319,8 @@
 Changes in Wine, since the beginning (most recent changes first)
 .TP
 .I configure
-Shell script to automatically generate Makefiles.  Usually followed by make 
-(or gmake on *BSD systems) to compile wine.
+Shell script to automatically generate Makefiles.  Usually followed by
+make to compile wine.
 .TP
 .I Wine newsgroup
 Subscribe to comp.emulators.ms-windows.wine
diff --git a/configure b/configure
index e3760c8..73944bc 100755
--- a/configure
+++ b/configure
@@ -15,7 +15,7 @@
 ac_help="$ac_help
   --with-library          build Wine as a library instead of an emulator"
 ac_help="$ac_help
-  --with-language=LANG    change the default language (LANG=En/De/No/Es)"
+  --with-language=LANG    change the language (LANG=En/De/Fr/Es/No/Fi/Da)"
 ac_help="$ac_help
   --with-ipc              use inter-process communication for DDE"
 ac_help="$ac_help
@@ -431,9 +431,9 @@
 # Check whether --with-language or --without-language was given.
 withval="$with_language"
 if test -n "$withval"; then
-  LANG="-ALANG\($withval\)"
+  LANG="$withval"
 else
-  LANG="-ALANG\(En\)"
+  LANG=En
 fi
 
 
@@ -1556,7 +1556,7 @@
 
 
 if test -z "${top_srcdir}"; then
-TOP_SRCDIR="."
+TOP_SRCDIR=`pwd`
 else
 TOP_SRCDIR="${top_srcdir}"
 fi
@@ -1689,7 +1689,7 @@
 
 ac_given_srcdir=$srcdir
 
-trap 'rm -fr `echo "Make.rules controls/Makefile ipc/Makefile loader/Makefile memory/Makefile misc/Makefile miscemu/Makefile multimedia/Makefile objects/Makefile windows/Makefile rc/Makefile debugger/Makefile debugger/readline/Makefile tools/Makefile if1632/Makefile toolkit/Makefile Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
+trap 'rm -fr `echo "Make.rules controls/Makefile ipc/Makefile loader/Makefile memory/Makefile misc/Makefile miscemu/Makefile multimedia/Makefile objects/Makefile win32/Makefile windows/Makefile rc/Makefile debugger/Makefile debugger/readline/Makefile tools/Makefile if1632/Makefile toolkit/Makefile Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
 
 # Protect against being on the right side of a sed subst in config.status. 
 sed 's/%@/@@/; s/@%/@@/; s/%g$/@g/; /@g$/s/[\\\\&%]/\\\\&/g; 
@@ -1726,7 +1726,7 @@
 EOF
 cat >> $CONFIG_STATUS <<EOF
 
-CONFIG_FILES=\${CONFIG_FILES-"Make.rules controls/Makefile ipc/Makefile loader/Makefile memory/Makefile misc/Makefile miscemu/Makefile multimedia/Makefile objects/Makefile windows/Makefile rc/Makefile debugger/Makefile debugger/readline/Makefile tools/Makefile if1632/Makefile toolkit/Makefile Makefile"}
+CONFIG_FILES=\${CONFIG_FILES-"Make.rules controls/Makefile ipc/Makefile loader/Makefile memory/Makefile misc/Makefile miscemu/Makefile multimedia/Makefile objects/Makefile win32/Makefile windows/Makefile rc/Makefile debugger/Makefile debugger/readline/Makefile tools/Makefile if1632/Makefile toolkit/Makefile Makefile"}
 EOF
 cat >> $CONFIG_STATUS <<\EOF
 for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
diff --git a/configure.in b/configure.in
index 5154cd7..8460d1d 100644
--- a/configure.in
+++ b/configure.in
@@ -16,9 +16,9 @@
 AC_SUBST(MAIN_TARGET)
 
 AC_ARG_WITH(language,
-[  --with-language=LANG    change the default language (LANG=En/De/No/Es)],
-[LANG="-ALANG\($withval\)"],
-[LANG="-ALANG\(En\)"],)
+[  --with-language=LANG    change the language (LANG=En/De/Fr/Es/No/Fi/Da)],
+[LANG="$withval"],
+[LANG=En],)
 AC_SUBST(LANG)
 
 AC_ARG_WITH(ipc,
@@ -45,7 +45,7 @@
 AC_TYPE_SIZE_T()
 
 if test -z "${top_srcdir}"; then
-TOP_SRCDIR="."
+TOP_SRCDIR=`pwd`
 else
 TOP_SRCDIR="${top_srcdir}"
 fi
@@ -77,7 +77,7 @@
 MAKE_RULES=$TOP_SRCDIR/Make.rules
 AC_SUBST_FILE(MAKE_RULES)
 
-AC_OUTPUT(Make.rules controls/Makefile ipc/Makefile loader/Makefile memory/Makefile misc/Makefile miscemu/Makefile multimedia/Makefile objects/Makefile windows/Makefile rc/Makefile debugger/Makefile debugger/readline/Makefile tools/Makefile if1632/Makefile toolkit/Makefile Makefile)
+AC_OUTPUT(Make.rules controls/Makefile ipc/Makefile loader/Makefile memory/Makefile misc/Makefile miscemu/Makefile multimedia/Makefile objects/Makefile win32/Makefile windows/Makefile rc/Makefile debugger/Makefile debugger/readline/Makefile tools/Makefile if1632/Makefile toolkit/Makefile Makefile)
 
 echo
 echo "Configure finished.  Do 'make depend; make' to compile Wine."
diff --git a/controls/Imakefile b/controls/Imakefile
deleted file mode 100644
index 582965b..0000000
--- a/controls/Imakefile
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = controls
-
-SRCS = \
-	button.c \
-	combo.c \
-	desktop.c \
-	edit.c \
-	listbox.c \
-	menu.c \
-	scroll.c \
-	static.c \
-	widgets.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/controls/button.c b/controls/button.c
index b33900a..087a7d7 100644
--- a/controls/button.c
+++ b/controls/button.c
@@ -68,7 +68,7 @@
 static WORD checkBoxWidth = 0, checkBoxHeight = 0;
 
 
-LONG ButtonWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam)
+LRESULT ButtonWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
         RECT rect;
 	LONG lResult = 0;
@@ -156,8 +156,14 @@
                                      ((infoPtr->state & 3) + 1), 0 );
                         break;
                     }
+#ifdef WINELIB32
+                    SendMessage( GetParent(hWnd), WM_COMMAND,
+                                 MAKEWPARAM(wndPtr->wIDmenu,BN_CLICKED),
+				 (LPARAM) hWnd );
+#else
                     SendMessage( GetParent(hWnd), WM_COMMAND,
                                  wndPtr->wIDmenu, MAKELPARAM(hWnd,BN_CLICKED));
+#endif
                 }
 		break;
 
@@ -182,13 +188,13 @@
 		return 0;
 
         case WM_SETFONT:
-                infoPtr->hFont = wParam;
+                infoPtr->hFont = (HFONT) wParam;
                 if (lParam)
                     PAINT_BUTTON( hWnd, style, ODA_DRAWENTIRE );
                 break;
 
         case WM_GETFONT:
-                return infoPtr->hFont;
+                return (LONG) infoPtr->hFont;
 
 	case WM_SETFOCUS:
                 infoPtr->state |= BUTTON_HASFOCUS;
@@ -269,8 +275,13 @@
 
       /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
     if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
+#ifdef WINELIB32
+    SendMessage( GetParent(hButton), WM_CTLCOLORBTN,
+		 (WPARAM)hDC, (LPARAM)hButton );
+#else
     SendMessage( GetParent(hButton), WM_CTLCOLOR, (WORD)hDC,
                  MAKELPARAM(hButton, CTLCOLOR_BTN) );
+#endif
     hOldPen = (HPEN)SelectObject(hDC, sysColorObjects.hpenWindowFrame);
     hOldBrush = (HBRUSH)SelectObject(hDC, sysColorObjects.hbrushBtnFace);
     SetBkMode(hDC, TRANSPARENT);
@@ -302,7 +313,7 @@
     else GRAPH_DrawReliefRect( hDC, &rc, 2, 2, FALSE );
     
     /* draw button label, if any: */
-    text = USER_HEAP_LIN_ADDR( wndPtr->hText );
+    text = (char*) USER_HEAP_LIN_ADDR( wndPtr->hText );
     if (text[0])
     {
         SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
@@ -347,13 +358,18 @@
     GetClientRect(hWnd, &rc);
 
     if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
+#ifdef WINELIB32 /* JBP: Different in Win32 */
+    hBrush = (HBRUSH) SendMessage(GetParent(hWnd), WM_CTLCOLORBTN, (WPARAM)hDC,
+				  (LPARAM)hWnd);
+#else
     hBrush = SendMessage(GetParent(hWnd), WM_CTLCOLOR, (WORD)hDC,
 			 MAKELPARAM(hWnd, CTLCOLOR_BTN));
+#endif
     if (action == ODA_DRAWENTIRE) FillRect(hDC, &rc, hBrush);
 
     GetTextMetrics(hDC, &tm);
     delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
-    text = USER_HEAP_LIN_ADDR( wndPtr->hText );
+    text = (char*) USER_HEAP_LIN_ADDR( wndPtr->hText );
     textlen = strlen( text );
 
       /* Draw the check-box bitmap */
@@ -421,8 +437,12 @@
     if (action != ODA_DRAWENTIRE) return;
 
     if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
+#ifdef WINELIB32
+    SendMessage( GetParent(hWnd), WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hWnd );
+#else
     SendMessage( GetParent(hWnd), WM_CTLCOLOR, (WORD)hDC,
 		 MAKELPARAM(hWnd, CTLCOLOR_BTN));
+#endif
     SelectObject( hDC, sysColorObjects.hpenWindowFrame );
 
     GetClientRect(hWnd, &rc);
@@ -433,7 +453,7 @@
     LineTo( hDC, rc.left, rc.bottom-1 );
     LineTo( hDC, rc.left, rc.top+2 );
 
-    text = USER_HEAP_LIN_ADDR( wndPtr->hText );
+    text = (char*) USER_HEAP_LIN_ADDR( wndPtr->hText );
     GetTextExtentPoint(hDC, text, strlen(text), &size);
     rc.left  += 10;
     rc.right  = rc.left + size.cx + 1;
@@ -460,8 +480,13 @@
     GetClientRect(hWnd, &rc);
 
     if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
+#ifdef WINELIB32
+    hBrush = (HBRUSH) SendMessage(GetParent(hWnd), WM_CTLCOLORBTN, (WPARAM)hDC,
+				  (LPARAM)hWnd);
+#else
     hBrush = SendMessage(GetParent(hWnd), WM_CTLCOLOR, (WORD)hDC,
 			 MAKELPARAM(hWnd, CTLCOLOR_BTN));
+#endif
     FillRect(hDC, &rc, hBrush);
 
     if ((action == ODA_FOCUS) ||
@@ -491,5 +516,5 @@
     dis.hDC        = hDC;
     GetClientRect( hWnd, &dis.rcItem );
     dis.itemData   = 0;
-    SendMessage(GetParent(hWnd), WM_DRAWITEM, 1, MAKE_SEGPTR(&dis) );
+    SendMessage(GetParent(hWnd), WM_DRAWITEM, 1, (LPARAM) MAKE_SEGPTR(&dis) );
 }
diff --git a/controls/combo.c b/controls/combo.c
index 77374cd..aab97f5 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -131,7 +131,7 @@
     lphc->hWndEdit = CreateWindow(MAKE_SEGPTR(editName), (SEGPTR)0, 
 				  WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | SS_LEFT,
 				  0, 0, rect.right, lphl->StdItemHeight,
-				  hwnd, 1, GetWindowWord(hwnd,GWW_HINSTANCE), 0L);
+				  hwnd, (HMENU)1, WIN_GetWindowInstance(hwnd), 0L);
     break;
    case CBS_DROPDOWN:          /* edit control, dropdown listbox     */
     dprintf_combo(stddeb,"CBS_DROPDOWN\n");
@@ -145,7 +145,7 @@
     lphc->hWndEdit = CreateWindow(MAKE_SEGPTR(editName), (SEGPTR)0,
 				  WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | SS_LEFT,
 				  0, 0, lphc->RectButton.left, lphl->StdItemHeight,
-				  hwnd, 1, GetWindowWord(hwnd,GWW_HINSTANCE), 0L);
+				  hwnd, (HMENU)1, WIN_GetWindowInstance(hwnd), 0L);
     break;
    case CBS_DROPDOWNLIST:      /* static control, downdown listbox   */
     dprintf_combo(stddeb,"CBS_DROPDOWNLIST\n");
@@ -167,10 +167,10 @@
 				lboxrect.left, lboxrect.top,
 				lboxrect.right - lboxrect.left, 
 				lboxrect.bottom - lboxrect.top,
-				0, 0, GetWindowWord(hwnd,GWW_HINSTANCE),
-				(SEGPTR)MAKELONG(hwnd, hwnd));
+				0, 0, WIN_GetWindowInstance(hwnd),
+				(SEGPTR)hwnd );
   ShowWindow(lphc->hWndLBox, SW_HIDE);
-  dprintf_combo(stddeb,"Combo Creation LBox=%X!\n", lphc->hWndLBox);
+  dprintf_combo(stddeb,"Combo Creation LBox="NPFMT"!\n", lphc->hWndLBox);
   return 0;
 }
 
@@ -220,8 +220,13 @@
 
   hOldFont = SelectObject(hdc, lphl->hFont);
 
+#ifdef WINELIB32
+  hBrush = (HBRUSH) SendMessage(lphl->hParent, WM_CTLCOLORLISTBOX, (WPARAM)hdc,
+				(LPARAM)hwnd);
+#else
   hBrush = SendMessage(lphl->hParent, WM_CTLCOLOR, hdc,
 		       MAKELONG(hwnd, CTLCOLOR_LISTBOX));
+#endif
   if (hBrush == 0) hBrush = GetStockObject(WHITE_BRUSH);
 
   GetClientRect(hwnd, &rect);
@@ -512,14 +517,14 @@
 /***********************************************************************
  *           CBSetFont
  */
-static LONG CBSetFont(HWND hwnd, WORD wParam, LONG lParam)
+static LONG CBSetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
   LPHEADLIST  lphl = ComboGetListHeader(hwnd);
 
   if (wParam == 0)
     lphl->hFont = GetStockObject(SYSTEM_FONT);
   else
-    lphl->hFont = wParam;
+    lphl->hFont = (HFONT)wParam;
 
   return 0;
 }
@@ -588,7 +593,7 @@
 /***********************************************************************
  *           ComboWndProc
  */
-LONG ComboBoxWndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+LRESULT ComboBoxWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     switch(message) {	
      case WM_NCCREATE: return CBNCCreate(hwnd, wParam, lParam);
@@ -629,7 +634,11 @@
 
 HWND CLBoxGetCombo(HWND hwnd)
 {
-  return GetWindowWord(hwnd,0);
+#ifdef WINELIB32
+  return (HWND)GetWindowLong(hwnd,0);
+#else
+  return (HWND)GetWindowWord(hwnd,0);
+#endif
 }
 
 LPHEADLIST CLBoxGetListHeader(HWND hwnd)
@@ -735,8 +744,13 @@
   }
 
   hOldFont = SelectObject(hdc, lphl->hFont);
+#ifdef WINELIB32
+  hBrush = (HBRUSH) SendMessage(lphl->hParent, WM_CTLCOLORLISTBOX, (WPARAM)hdc,
+				(LPARAM)hwnd);
+#else
   hBrush = SendMessage(lphl->hParent, WM_CTLCOLOR, hdc,
 		       MAKELONG(hwnd, CTLCOLOR_LISTBOX));
+#endif
 
   if (hBrush == 0) hBrush = GetStockObject(WHITE_BRUSH);
 
@@ -835,10 +849,16 @@
 
   if (GetCapture() == hwnd) ReleaseCapture();
 
-  if (lphl->PrevFocused != lphl->ItemFocused) {
-    SendMessage(CLBoxGetCombo(hwnd),CB_SETCURSEL,lphl->ItemFocused,0);
-    ListBoxSendNotification(lphl, CLBoxGetCombo(hwnd), CBN_SELCHANGE);
-  }
+  if(!lphl)
+     {
+      fprintf(stdnimp,"CBLLButtonUp: CLBoxGetListHeader returned NULL!\n");
+     }
+  else if (lphl->PrevFocused != lphl->ItemFocused) 
+          {
+      		SendMessage(CLBoxGetCombo(hwnd),CB_SETCURSEL,lphl->ItemFocused,0);
+      		ListBoxSendNotification(lphl, CLBoxGetCombo(hwnd), CBN_SELCHANGE);
+     	  }
+
   SendMessage(CLBoxGetCombo(hwnd),CB_SHOWDROPDOWN,0,0);
 
   return 0;
@@ -938,7 +958,7 @@
 /***********************************************************************
  *           ComboLBoxWndProc
  */
-LONG ComboLBoxWndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+LRESULT ComboLBoxWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     switch(message) {	
      case WM_CREATE: return CBLCreate(hwnd, wParam, lParam);
@@ -961,7 +981,7 @@
  */
 BOOL DlgDirSelectComboBox(HWND hDlg, LPSTR lpStr, int nIDLBox)
 {
-	fprintf(stdnimp,"DlgDirSelectComboBox(%04X, '%s', %d) \n",	
+	fprintf(stdnimp,"DlgDirSelectComboBox("NPFMT", '%s', %d) \n",
 				hDlg, lpStr, nIDLBox);
 	return TRUE;
 }
@@ -976,8 +996,8 @@
   HWND	hWnd;
   int ret;
   LPSTR lpPathSpec = PTR_SEG_TO_LIN(PathSpec);
-  
-  dprintf_combo(stddeb,"DlgDirListComboBox(%04X, '%s', %d, %d, %04X) \n",
+
+  dprintf_combo(stddeb,"DlgDirListComboBox("NPFMT", '%s', %d, %d, %04X) \n",
 		  hDlg, lpPathSpec, nIDLBox, nIDStat, wType);
   if (nIDLBox) {
     LPHEADLIST lphl;
@@ -1003,13 +1023,13 @@
 	temp[1] = 'A'+drive;
 	temp[2] = ':';
 	SendDlgItemMessage( hDlg, nIDStat, WM_SETTEXT, 0,
-                            USER_HEAP_SEG_ADDR(hTemp) + 1 );
+                            (LPARAM)(USER_HEAP_SEG_ADDR(hTemp) + 1) );
       } else {
 	temp[0] = 'A'+drive;
 	temp[1] = ':';
 	temp[2] = '\\';
 	SendDlgItemMessage( hDlg, nIDStat, WM_SETTEXT, 0,
-                            USER_HEAP_SEG_ADDR(hTemp) );
+                            (LPARAM)USER_HEAP_SEG_ADDR(hTemp) );
       }
       USER_HEAP_FREE( hTemp );
   } 
diff --git a/controls/desktop.c b/controls/desktop.c
index 096092e..ef9377b 100644
--- a/controls/desktop.c
+++ b/controls/desktop.c
@@ -118,7 +118,7 @@
  *
  * Window procedure for the desktop window.
  */
-LONG DesktopWndProc ( HWND hwnd, WORD message, WORD wParam, LONG lParam )
+LRESULT DesktopWndProc ( HWND hwnd, WORD message, WPARAM wParam, LPARAM lParam )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
     DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
diff --git a/controls/edit.c b/controls/edit.c
index 943321f..957c870 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -20,9 +20,16 @@
 #include "debug.h"
 
 
+#ifdef WINELIB32
+#define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
+	SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
+		    MAKEWPARAM(GetDlgCtrlID(hWndCntrl),wNotifyCode), \
+		    (LPARAM)hWndCntrl );
+#else
 #define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
 	SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
 		 GetDlgCtrlID(hWndCntrl), MAKELPARAM(hWndCntrl, wNotifyCode));
+#endif
 
 #define MAXTEXTLEN 30000   /* maximum text buffer length */
 #define EDITLEN     1024   /* starting length for multi-line control */
@@ -95,12 +102,12 @@
  *
  *  Allocate the specified number of bytes on the specified local heap.
  */
-static unsigned int EDIT_HeapAlloc(HWND hwnd, int bytes, WORD flags)
+static HLOCAL EDIT_HeapAlloc(HWND hwnd, int bytes, WORD flags)
 {
-    unsigned int ret;
+    HLOCAL ret;
 
-    ret = LOCAL_Alloc( GetWindowWord(hwnd,GWW_HINSTANCE), flags, bytes );
-    if (ret == 0)
+    ret = LOCAL_Alloc( WIN_GetWindowInstance(hwnd), flags, bytes );
+    if (!ret)
         printf("EDIT_HeapAlloc: Out of heap-memory\n");
     return ret;
 }
@@ -110,10 +117,10 @@
  *
  *  Return the address of the memory pointed to by the handle.
  */
-static void *EDIT_HeapLock(HWND hwnd, unsigned int handle)
+static void *EDIT_HeapLock(HWND hwnd, HANDLE handle)
 {
-    WORD hinstance = GetWindowWord( hwnd, GWW_HINSTANCE );
-    WORD offs;
+    HINSTANCE hinstance = WIN_GetWindowInstance( hwnd );
+    HANDLE offs;
     
     if (handle == 0) return 0;
     offs = LOCAL_Lock( hinstance, handle );
@@ -123,10 +130,10 @@
 /*********************************************************************
  *  EDIT_HeapUnlock
  */
-static void EDIT_HeapUnlock(HWND hwnd, unsigned int handle)
+static void EDIT_HeapUnlock(HWND hwnd, HANDLE handle)
 {
     if (handle == 0) return;
-    LOCAL_Unlock( GetWindowWord( hwnd, GWW_HINSTANCE ), handle );
+    LOCAL_Unlock( WIN_GetWindowInstance( hwnd ), handle );
 }
 
 /*********************************************************************
@@ -134,9 +141,9 @@
  *
  *  Reallocate the memory pointed to by the handle.
  */
-static unsigned int EDIT_HeapReAlloc(HWND hwnd, unsigned int handle, int bytes)
+static HLOCAL EDIT_HeapReAlloc(HWND hwnd, HANDLE handle, int bytes)
 {
-    return LOCAL_ReAlloc( GetWindowWord(hwnd,GWW_HINSTANCE), handle, bytes, 
+    return LOCAL_ReAlloc( WIN_GetWindowInstance(hwnd), handle, bytes, 
 			  LMEM_FIXED );
 }
 
@@ -146,9 +153,9 @@
  *
  *  Frees the memory pointed to by the handle.
  */
-static void EDIT_HeapFree(HWND hwnd, unsigned int handle)
+static void EDIT_HeapFree(HWND hwnd, HANDLE handle)
 {
-    LOCAL_Free( GetWindowWord(hwnd,GWW_HINSTANCE), handle );
+    LOCAL_Free( WIN_GetWindowInstance(hwnd), handle );
 }
 
 
@@ -157,9 +164,9 @@
  *
  *  Return the size of the given object on the local heap.
  */
-static unsigned int EDIT_HeapSize(HWND hwnd, unsigned int handle)
+static unsigned int EDIT_HeapSize(HWND hwnd, HANDLE handle)
 {
-    return LOCAL_Size( GetWindowWord(hwnd,GWW_HINSTANCE), handle );
+    return LOCAL_Size( WIN_GetWindowInstance(hwnd), handle );
 }
 
 /********************************************************************
@@ -470,8 +477,12 @@
     else
         oldfont = 0;		/* -Wall does not see the use of if */
 
-    SendMessage(GetParent(hwnd), WM_CTLCOLOR, (WORD)hdc,
+#ifdef WINELIB32
+    SendMessage(GetParent(hwnd), WM_CTLCOLOREDIT, (WPARAM)hdc, (LPARAM)hwnd);
+#else
+    SendMessage(GetParent(hwnd), WM_CTLCOLOR, (WPARAM)hdc,
 		MAKELPARAM(hwnd, CTLCOLOR_EDIT));
+#endif
 
     if (reverse)
     {
@@ -1840,13 +1851,13 @@
 /*********************************************************************
  *  EM_SETHANDLE message function
  */
-static void EDIT_SetHandleMsg(HWND hwnd, WORD wParam)
+static void EDIT_SetHandleMsg(HWND hwnd, WPARAM wParam)
 {
     EDITSTATE *es = EDIT_GetEditState(hwnd);
 
     if (IsMultiLine(hwnd))
     {
-	es->hText = wParam;
+	es->hText = (HANDLE)wParam;
 	es->textlen = EDIT_HeapSize(hwnd, es->hText);
 	es->wlines = 0;
 	es->wtop = es->wleft = 0;
@@ -1856,8 +1867,8 @@
 	es->textwidth = 0;
 	es->SelBegLine = es->SelBegCol = 0;
 	es->SelEndLine = es->SelEndCol = 0;
-	dprintf_edit(stddeb, "EDIT_SetHandleMsg: handle %04x, textlen=%d\n",
-		     wParam, es->textlen);
+	dprintf_edit(stddeb, "EDIT_SetHandleMsg: handle %04lx, textlen=%d\n",
+		     (DWORD)wParam, es->textlen);
 
 	EDIT_BuildTextPointers(hwnd);
 	es->PaintBkgd = TRUE;
@@ -2107,14 +2118,14 @@
 /*********************************************************************
  *  WM_SETFONT
  */
-static void EDIT_WM_SetFont(HWND hwnd, WORD wParam, LONG lParam)
+static void EDIT_WM_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
     HDC hdc;
     TEXTMETRIC tm;
     HFONT oldfont;
     EDITSTATE *es = EDIT_GetEditState(hwnd);
 
-    es->hFont = wParam;
+    es->hFont = (HANDLE)wParam;
     hdc = GetDC(hwnd);
     oldfont = (HFONT)SelectObject(hdc, (HANDLE)es->hFont);
     GetCharWidth(hdc, 0, 255, es->CharWidths);
@@ -2174,7 +2185,7 @@
 	   rc.right, rc.bottom);
 
     if (es->PaintBkgd)
-	FillWindow(GetParent(hwnd), hwnd, hdc, CTLCOLOR_EDIT);
+	FillWindow(GetParent(hwnd), hwnd, hdc, (HBRUSH)CTLCOLOR_EDIT);
 
     for (y = (rc.top / es->txtht); y <= (rc.bottom / es->txtht); y++)
     {
@@ -2607,7 +2618,7 @@
 /*********************************************************************
  * EditWndProc()
  */
-LONG EditWndProc(HWND hwnd, WORD uMsg, WORD wParam, LONG lParam)
+LRESULT EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
     LONG lResult = 0;
     char *textPtr;
@@ -2616,7 +2627,7 @@
 
     switch (uMsg) {
     case EM_CANUNDO:
-	lResult = es->hDeletedText;
+	lResult = (LONG)es->hDeletedText;
 	break;
 	
     case EM_EMPTYUNDOBUFFER:
@@ -2636,7 +2647,7 @@
 	break;
 
     case EM_GETHANDLE:
-	lResult = es->hText;
+	lResult = (LONG)es->hText;
 	break;
 
     case EM_GETLINE:
diff --git a/controls/listbox.c b/controls/listbox.c
index 1a081f0..393f497 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -118,8 +118,13 @@
 void ListBoxSendNotification(LPHEADLIST lphl, HWND hwnd, WORD code)
 {
   if (lphl->dwStyle & LBS_NOTIFY)
+#ifdef WINELIB32
+    SendMessage(lphl->hParent, WM_COMMAND,
+		MAKEWPARAM(lphl->CtlID,code), (LPARAM)hwnd);
+#else
     SendMessage(lphl->hParent, WM_COMMAND,
 		lphl->CtlID, MAKELONG(hwnd, code));
+#endif
 }
 
 
@@ -274,7 +279,7 @@
  
   *lpmeasure = lpls->mis;
   lpmeasure->itemHeight = lphl->StdItemHeight;
-  SendMessage(lphl->hParent, WM_MEASUREITEM, 0, USER_HEAP_SEG_ADDR(hTemp));
+  SendMessage(lphl->hParent, WM_MEASUREITEM, 0, (LPARAM)USER_HEAP_SEG_ADDR(hTemp));
 
   if (lphl->dwStyle & LBS_OWNERDRAWFIXED) {
     lphl->StdItemHeight = lpmeasure->itemHeight;
@@ -898,8 +903,14 @@
 {
   LPHEADLIST lphl = ListBoxGetStorageHeader(hwnd);
 
+#ifdef WINELIB32
+  SendMessage(lphl->hParent, WM_COMMAND, 
+	      MAKEWPARAM(GetWindowWord(hwnd,GWW_ID),LBN_DBLCLK),
+	      (LPARAM)hwnd);
+#else
   SendMessage(lphl->hParent, WM_COMMAND, GetWindowWord(hwnd,GWW_ID),
 		MAKELONG(hwnd, LBN_DBLCLK));
+#endif
 
   return 0;
 }
@@ -1060,7 +1071,8 @@
 {
   LPHEADLIST  lphl = ListBoxGetStorageHeader(hwnd);
 
-  dprintf_listbox(stddeb,"ListBox WM_SETREDRAW hWnd=%04X w=%04X !\n", hwnd, wParam);
+  dprintf_listbox(stddeb,"ListBox WM_SETREDRAW hWnd="NPFMT" w=%04X !\n",
+		  hwnd, wParam);
   lphl->bRedrawFlag = wParam;
 
   return 0;
@@ -1069,14 +1081,14 @@
 /***********************************************************************
  *           LBSetFont
  */
-static LONG LBSetFont(HWND hwnd, WORD wParam, LONG lParam)
+static LONG LBSetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
   LPHEADLIST  lphl = ListBoxGetStorageHeader(hwnd);
 
   if (wParam == 0)
     lphl->hFont = GetStockObject(SYSTEM_FONT);
   else
-    lphl->hFont = wParam;
+    lphl->hFont = (HFONT) wParam;
 
   return 0;
 }
@@ -1105,8 +1117,13 @@
 
   hOldFont = SelectObject(hdc, lphl->hFont);
 
+#ifdef WINELIB32
+  hBrush = (HBRUSH) SendMessage(lphl->hParent, WM_CTLCOLORLISTBOX, (WPARAM)hdc,
+				(LPARAM)hwnd);
+#else
   hBrush = SendMessage(lphl->hParent, WM_CTLCOLOR, hdc,
 		       MAKELONG(hwnd, CTLCOLOR_LISTBOX));
+#endif
 
   if (hBrush == 0) hBrush = GetStockObject(WHITE_BRUSH);
 
@@ -1638,7 +1655,7 @@
 /***********************************************************************
  *           ListBoxWndProc 
  */
-LONG ListBoxWndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+LRESULT ListBoxWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 { 
     switch (message) {
      case WM_CREATE: return LBCreate(hwnd, wParam, lParam);
@@ -1702,7 +1719,7 @@
   LPHEADLIST lphl;
   char s[130];
 
-  dprintf_listbox( stddeb, "DlgDirSelect(%04X, '%s', %d) \n", hDlg, lpStr, 
+  dprintf_listbox( stddeb, "DlgDirSelect("NPFMT", '%s', %d) \n", hDlg, lpStr, 
 		  nIDLBox );
 
   hwnd = GetDlgItem(hDlg, nIDLBox);
@@ -1743,7 +1760,7 @@
   HWND	hWnd;
   int ret;
   
-  dprintf_listbox(stddeb,"DlgDirList(%04X, '%s', %d, %d, %04X) \n",
+  dprintf_listbox(stddeb,"DlgDirList("NPFMT", '%s', %d, %d, %04X) \n",
 		  hDlg, lpPathSpec, nIDLBox, nIDStat, wType);
   if (nIDLBox)  {
     LPHEADLIST lphl;
@@ -1767,13 +1784,13 @@
 	temp[1] = 'A'+drive;
 	temp[2] = ':';
 	SendDlgItemMessage( hDlg, nIDStat, WM_SETTEXT, 0,
-                            USER_HEAP_SEG_ADDR(hTemp) + 1 );
+                            (LPARAM)(USER_HEAP_SEG_ADDR(hTemp) + 1) );
       } else {
 	temp[0] = 'A'+drive;
 	temp[1] = ':';
 	temp[2] = '\\';
 	SendDlgItemMessage( hDlg, nIDStat, WM_SETTEXT, 0,
-                            USER_HEAP_SEG_ADDR(hTemp) );
+                            (LPARAM)USER_HEAP_SEG_ADDR(hTemp) );
       }
       USER_HEAP_FREE( hTemp );
   } 
diff --git a/controls/menu.c b/controls/menu.c
index 250f424..90db99c 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -225,8 +225,13 @@
 	    if (p && (p[1] != '&') && (toupper(p[1]) == key)) return i;
 	}
     }
+#ifdef WINELIB32
+    menuchar = SendMessage( hwndOwner, WM_MENUCHAR, 
+			    MAKEWPARAM(key,menu->wFlags), (LPARAM)hmenu );
+#else
     menuchar = SendMessage( hwndOwner, WM_MENUCHAR, key,
 			    MAKELONG( menu->wFlags, hmenu ) );
+#endif
     if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
     if (HIWORD(menuchar) == 1) return -2;
     return -1;
@@ -252,7 +257,7 @@
       static LPMEASUREITEMSTRUCT mistruct=NULL;
       if (mistruct == NULL)  {
 	mistrh = GlobalAlloc(0,sizeof(MEASUREITEMSTRUCT));
-	mistrsegp = WIN16_GlobalLock(mistrh);
+	mistrsegp = (SEGPTR)WIN16_GlobalLock(mistrh);
 	mistruct = PTR_SEG_TO_LIN(mistrsegp);
       }
       mistruct->CtlType = ODT_MENU;
@@ -455,7 +460,7 @@
       static LPDRAWITEMSTRUCT distruct=NULL;
       if (distruct == NULL)  {
 	distrh = GlobalAlloc(0,sizeof(DRAWITEMSTRUCT));
-	distrsegp = WIN16_GlobalLock(distrh);
+	distrsegp = (SEGPTR)WIN16_GlobalLock(distrh);
 	distruct = PTR_SEG_TO_LIN(distrsegp);
       }
       dprintf_menu(stddeb,"DrawMenuItem: Ownerdraw!\n");
@@ -630,7 +635,7 @@
     
     lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR( wndPtr->wIDmenu );
     if (lppop == NULL || lprect == NULL) return SYSMETRICS_CYMENU;
-    dprintf_menu(stddeb,"MENU_DrawMenuBar(%04X, %p, %p); !\n", 
+    dprintf_menu(stddeb,"MENU_DrawMenuBar("NPFMT", %p, %p); !\n", 
 		 hDC, lprect, lppop);
     if (lppop->Height == 0) MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
     lprect->bottom = lprect->top + lppop->Height;
@@ -667,7 +672,7 @@
 	item[menu->FocusedItem].item_flags &= ~(MF_HILITE | MF_MOUSESELECT);
 	menu->FocusedItem = NO_SELECTED_ITEM;
     }
-    SendMessage( hwndOwner, WM_INITMENUPOPUP, hmenu,
+    SendMessage( hwndOwner, WM_INITMENUPOPUP, (WPARAM)hmenu,
 		 MAKELONG( id, (menu->wFlags & MF_SYSMENU) ? 1 : 0 ));
     MENU_PopupMenuCalcSize( menu, hwndOwner );
     if (!menu->hWnd)
@@ -735,22 +740,43 @@
 	if (lppop->FocusedItem == SYSMENU_SELECTED)
         {
 	    NC_DrawSysButton( lppop->hWnd, hdc, TRUE );
+#ifdef WINELIB32
+            SendMessage( hwndOwner, WM_MENUSELECT,
+                         MAKEWPARAM( GetSystemMenu( lppop->hWnd, FALSE ),
+				     lppop->wFlags | MF_MOUSESELECT ),
+			 (LPARAM)hmenu );
+#else
             SendMessage( hwndOwner, WM_MENUSELECT,
                          GetSystemMenu( lppop->hWnd, FALSE ),
                          MAKELONG( lppop->wFlags | MF_MOUSESELECT, hmenu ) );
+#endif
         }
 	else
 	{
 	    items[lppop->FocusedItem].item_flags |= MF_HILITE;
 	    MENU_DrawMenuItem( lppop->hWnd, hdc, &items[lppop->FocusedItem], lppop->Height,
 			       !(lppop->wFlags & MF_POPUP) );
+#ifdef WINELIB32
+	    SendMessage( hwndOwner, WM_MENUSELECT,
+                         MAKEWPARAM( items[lppop->FocusedItem].item_id,
+				     items[lppop->FocusedItem].item_flags | 
+				     MF_MOUSESELECT ),
+			 (LPARAM) hmenu );
+#else
 	    SendMessage( hwndOwner, WM_MENUSELECT,
                          items[lppop->FocusedItem].item_id,
 		         MAKELONG( items[lppop->FocusedItem].item_flags | MF_MOUSESELECT, hmenu));
+#endif
 	}
     }
+#ifdef WINELIB32
+    else SendMessage( hwndOwner, WM_MENUSELECT, 
+		      MAKEWPARAM( hmenu, lppop->wFlags | MF_MOUSESELECT),
+		      (LPARAM)hmenu );
+#else
     else SendMessage( hwndOwner, WM_MENUSELECT, hmenu,
                       MAKELONG( lppop->wFlags | MF_MOUSESELECT, hmenu ) );
+#endif
 
     ReleaseDC( lppop->hWnd, hdc );
 }
@@ -858,7 +884,7 @@
     item = ((MENUITEM *)USER_HEAP_LIN_ADDR(menu->hItems)) + menu->FocusedItem;
     if (!(item->item_flags & MF_POPUP) || !(item->item_flags & MF_MOUSESELECT))
 	return 0;
-    return item->item_id;
+    return (HMENU)item->item_id;
 }
 
 
@@ -885,7 +911,7 @@
 	if (!(item->item_flags & MF_POPUP) ||
 	    !(item->item_flags & MF_MOUSESELECT)) return;
 	item->item_flags &= ~MF_MOUSESELECT;
-	hsubmenu = item->item_id;
+	hsubmenu = (HMENU)item->item_id;
     }
     submenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hsubmenu );
     MENU_HideSubPopups( hwndOwner, hsubmenu );
@@ -1089,7 +1115,7 @@
 	{
 	    return MENU_ExecFocusedItem( hwndOwner, hmenu, hmenuCurrent );
 	}
-	hsubmenu = item->item_id;
+	hsubmenu = (HMENU)item->item_id;
     }
       /* Select first item of sub-popup */
     MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM );
@@ -1448,15 +1474,20 @@
 /***********************************************************************
  *           PopupMenuWndProc
  */
-LONG PopupMenuWndProc( HWND hwnd, WORD message, WORD wParam, LONG lParam )
+LRESULT PopupMenuWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
 {    
     switch(message)
     {
     case WM_CREATE:
 	{
 	    CREATESTRUCT *createStruct = (CREATESTRUCT*)PTR_SEG_TO_LIN(lParam);
+#ifdef WINELIB32
+	    HMENU hmenu = (HMENU) (createStruct->lpCreateParams);
+	    SetWindowLong( hwnd, 0, hmenu );
+#else
 	    HMENU hmenu = (HMENU) ((int)createStruct->lpCreateParams & 0xffff);
 	    SetWindowWord( hwnd, 0, hmenu );
+#endif
 	    return 0;
 	}
 
@@ -1468,7 +1499,12 @@
 	    PAINTSTRUCT ps;
 	    BeginPaint( hwnd, &ps );
 	    MENU_DrawPopupMenu( hwnd, ps.hdc,
-			        (HMENU)GetWindowWord( hwnd, 0 ) );
+#ifdef WINELIB32
+			        (HMENU)GetWindowLong( hwnd, 0 )
+#else
+			        (HMENU)GetWindowWord( hwnd, 0 )
+#endif
+ 			       );
 	    EndPaint( hwnd, &ps );
 	    return 0;
 	}
@@ -1508,7 +1544,7 @@
 BOOL ChangeMenu(HMENU hMenu, WORD nPos, LPSTR lpNewItem, 
 			WORD wItemID, WORD wFlags)
 {
-  dprintf_menu(stddeb,"ChangeMenu(%04X, %X, '%s', %X, %X)\n",
+  dprintf_menu(stddeb,"ChangeMenu: menu="NPFMT" pos=%d ptr=%p item=%04x flags=%04x\n",
 	       hMenu, nPos, lpNewItem, wItemID, wFlags);
   if (wFlags & MF_APPEND)  {
     return AppendMenu(hMenu, wFlags & ~MF_APPEND, wItemID, lpNewItem);
@@ -1535,7 +1571,7 @@
 BOOL CheckMenuItem(HMENU hMenu, WORD wItemID, WORD wFlags)
 {
 	LPMENUITEM 	lpitem;
-	dprintf_menu(stddeb,"CheckMenuItem (%04X, %04X, %04X) !\n", 
+	dprintf_menu(stddeb,"CheckMenuItem ("NPFMT", %04X, %04X) !\n", 
 		     hMenu, wItemID, wFlags);
 	if (!(lpitem = MENU_FindItem(&hMenu, &wItemID, wFlags))) return FALSE;
 	if (wFlags & MF_CHECKED) lpitem->item_flags |= MF_CHECKED;
@@ -1550,7 +1586,7 @@
 BOOL EnableMenuItem(HMENU hMenu, WORD wItemID, WORD wFlags)
 {
     LPMENUITEM 	lpitem;
-    dprintf_menu(stddeb,"EnableMenuItem (%04X, %04X, %04X) !\n", 
+    dprintf_menu(stddeb,"EnableMenuItem ("NPFMT", %04X, %04X) !\n", 
 		 hMenu, wItemID, wFlags);
     if (!(lpitem = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return FALSE;
 
@@ -1571,29 +1607,25 @@
 }
 
 
-/**********************************************************************
- *			GetMenuString		[USER.161]
+/*******************************************************************
+ *         GetMenuString    (USER.161)
  */
-int GetMenuString(HMENU hMenu, WORD wItemID, 
-		  LPSTR str, short nMaxSiz, WORD wFlags)
+int GetMenuString( HMENU hMenu, WORD wItemID,
+                   LPSTR str, short nMaxSiz, WORD wFlags )
 {
-	LPMENUITEM 	lpitem;
-	int		maxsiz;
-	dprintf_menu(stddeb,"GetMenuString(%04X, %04X, %p, %d, %04X);\n",
-					hMenu, wItemID, str, nMaxSiz, wFlags);
-	if (str == NULL) return FALSE;
-	lpitem = MENU_FindItem( &hMenu, &wItemID, wFlags );
-	if (lpitem != NULL) {
-		if (lpitem->item_text != NULL) {
-			maxsiz = min(nMaxSiz - 1, strlen(lpitem->item_text));
-			strncpy(str, lpitem->item_text, maxsiz + 1);
-			}
-		else
-			maxsiz = 0;
-		dprintf_menu(stddeb,"GetMenuString // Found !\n");
-		return maxsiz;
-		}
-	return 0;
+    LPMENUITEM lpitem;
+
+    dprintf_menu( stddeb, "GetMenuString: menu="NPFMT" item=%04x ptr=%p len=%d flags=%04x\n",
+                 hMenu, wItemID, str, nMaxSiz, wFlags );
+    if (!str || !nMaxSiz) return 0;
+    str[0] = '\0';
+    if (!(lpitem = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
+    if (!lpitem->item_text || !IS_STRING_ITEM(lpitem->item_flags)) return 0;
+    nMaxSiz = min( nMaxSiz-1, strlen(lpitem->item_text) );
+    strncpy( str, lpitem->item_text, nMaxSiz );
+    str[nMaxSiz] = '\0';
+    dprintf_menu( stddeb, "GetMenuString: returning '%s'\n", str );
+    return nMaxSiz;
 }
 
 
@@ -1604,7 +1636,7 @@
 {
     LPPOPUPMENU menu;
     LPMENUITEM  lpitem;
-    dprintf_menu(stddeb,"HiliteMenuItem(%04X, %04X, %04X, %04X);\n", 
+    dprintf_menu(stddeb,"HiliteMenuItem("NPFMT", "NPFMT", %04X, %04X);\n", 
 						hWnd, hMenu, wItemID, wHilite);
     if (!(lpitem = MENU_FindItem( &hMenu, &wItemID, wHilite ))) return FALSE;
     if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
@@ -1621,7 +1653,7 @@
 WORD GetMenuState(HMENU hMenu, WORD wItemID, WORD wFlags)
 {
     LPMENUITEM lpitem;
-    dprintf_menu(stddeb,"GetMenuState(%04X, %04X, %04X);\n", 
+    dprintf_menu(stddeb,"GetMenuState("NPFMT", %04X, %04X);\n", 
 		 hMenu, wItemID, wFlags);
     if (!(lpitem = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
     if (lpitem->item_flags & MF_POPUP)
@@ -1640,10 +1672,10 @@
 WORD GetMenuItemCount(HMENU hMenu)
 {
 	LPPOPUPMENU	menu;
-	dprintf_menu(stddeb,"GetMenuItemCount(%04X);\n", hMenu);
+	dprintf_menu(stddeb,"GetMenuItemCount("NPFMT");\n", hMenu);
 	menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
 	if (menu == NULL) return (WORD)-1;
-	dprintf_menu(stddeb,"GetMenuItemCount(%04X) return %d \n", 
+	dprintf_menu(stddeb,"GetMenuItemCount("NPFMT") return %d \n", 
 		     hMenu, menu->nItems);
 	return menu->nItems;
 }
@@ -1657,7 +1689,7 @@
     LPPOPUPMENU	menu;
     MENUITEM *item;
 
-    dprintf_menu(stddeb,"GetMenuItemID(%04X, %d);\n", hMenu, nPos);
+    dprintf_menu(stddeb,"GetMenuItemID("NPFMT", %d);\n", hMenu, nPos);
     if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return -1;
     if ((nPos < 0) || (nPos >= menu->nItems)) return -1;
     item = (MENUITEM *) USER_HEAP_LIN_ADDR( menu->hItems );
@@ -1677,13 +1709,13 @@
 
     if (IS_STRING_ITEM(wFlags))
     {
-        dprintf_menu(stddeb,"InsertMenu (%04X, %04X, %04X, %04X, '%s') !\n",
+        dprintf_menu(stddeb,"InsertMenu ("NPFMT", %04X, %04X, %04X, '%s') !\n",
                      hMenu, nPos, wFlags, wItemID,
                      lpNewItem ? lpNewItem : "(null)");
         if (!lpNewItem) return FALSE;
     }
     else
-        dprintf_menu(stddeb,"InsertMenu (%04X, %04X, %04X, %04X, %p) !\n",
+        dprintf_menu(stddeb,"InsertMenu ("NPFMT", %04X, %04X, %04X, %p) !\n",
                      hMenu, nPos, wFlags, wItemID, lpNewItem);
 
       /* Find where to insert new item */
@@ -1695,7 +1727,7 @@
              Some programs specify the menu length to do that */
         if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) 
         {
-            dprintf_menu(stddeb,"InsertMenu: %04X not a menu handle\n", hMenu);
+            dprintf_menu(stddeb,"InsertMenu: "NPFMT" not a menu handle\n", hMenu);
             return FALSE;
         }
         nPos = menu->nItems;
@@ -1709,7 +1741,7 @@
         }
         if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
         {
-            dprintf_menu(stddeb,"InsertMenu: %04X not a menu handle\n", hMenu);
+            dprintf_menu(stddeb,"InsertMenu: "NPFMT" not a menu handle\n", hMenu);
             return FALSE;
         }
     }
@@ -1783,7 +1815,7 @@
 {
     LPPOPUPMENU	menu;
     LPMENUITEM 	lpitem;
-	dprintf_menu(stddeb,"RemoveMenu (%04X, %04X, %04X) !\n", 
+	dprintf_menu(stddeb,"RemoveMenu ("NPFMT", %04X, %04X) !\n", 
 		     hMenu, nPos, wFlags);
     if (!(lpitem = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
     if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
@@ -1833,12 +1865,12 @@
     LPMENUITEM 	lpitem;
     if (IS_STRING_ITEM(wFlags))
     {
-	dprintf_menu(stddeb,"ModifyMenu (%04X, %04X, %04X, %04X, '%s') !\n",
+	dprintf_menu(stddeb,"ModifyMenu ("NPFMT", %04X, %04X, %04X, '%s') !\n",
 	       hMenu, nPos, wFlags, wItemID, lpNewItem ? lpNewItem : "(null)");
         if (!lpNewItem) return FALSE;
     }
     else
-	dprintf_menu(stddeb,"ModifyMenu (%04X, %04X, %04X, %04X, %p) !\n",
+	dprintf_menu(stddeb,"ModifyMenu ("NPFMT", %04X, %04X, %04X, %p) !\n",
 	       hMenu, nPos, wFlags, wItemID, lpNewItem);
     if (!(lpitem = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
     
@@ -1890,8 +1922,8 @@
 		HBITMAP hNewCheck, HBITMAP hNewUnCheck)
 {
     LPMENUITEM lpitem;
-   dprintf_menu(stddeb,"SetMenuItemBitmaps (%04X, %04X, %04X, %04X, %08X) !\n",
-	    hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
+   dprintf_menu(stddeb,"SetMenuItemBitmaps ("NPFMT", %04X, %04X, "NPFMT", %08lX) !\n",
+	    hMenu, nPos, wFlags, hNewCheck, (DWORD)hNewUnCheck);
     if (!(lpitem = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
 
     if (!hNewCheck && !hNewUnCheck)
@@ -1932,7 +1964,7 @@
     menu->hWnd   = 0;
     menu->hItems = 0;
     menu->FocusedItem = NO_SELECTED_ITEM;
-    dprintf_menu(stddeb,"CreateMenu // return %04X\n", hMenu);
+    dprintf_menu(stddeb,"CreateMenu // return "NPFMT"\n", hMenu);
     return hMenu;
 }
 
@@ -1943,7 +1975,7 @@
 BOOL DestroyMenu(HMENU hMenu)
 {
     LPPOPUPMENU lppop;
-    dprintf_menu(stddeb,"DestroyMenu (%04X) !\n", hMenu);
+    dprintf_menu(stddeb,"DestroyMenu ("NPFMT") !\n", hMenu);
     if (hMenu == 0) return FALSE;
     lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
     if (!lppop || (lppop->wMagic != MENU_MAGIC)) return FALSE;
@@ -1963,7 +1995,7 @@
         USER_HEAP_FREE( lppop->hItems );
     }
     USER_HEAP_FREE( hMenu );
-    dprintf_menu(stddeb,"DestroyMenu (%04X) // End !\n", hMenu);
+    dprintf_menu(stddeb,"DestroyMenu ("NPFMT") // End !\n", hMenu);
     return TRUE;
 }
 
@@ -2012,18 +2044,18 @@
 	LPPOPUPMENU lpmenu;
 	WND * wndPtr = WIN_FindWndPtr(hWnd);
 	if (wndPtr == NULL) {
-		fprintf(stderr,"SetMenu(%04X, %04X) // Bad window handle !\n",
+		fprintf(stderr,"SetMenu("NPFMT", "NPFMT") // Bad window handle !\n",
 			hWnd, hMenu);
 		return FALSE;
 		}
-	dprintf_menu(stddeb,"SetMenu(%04X, %04X);\n", hWnd, hMenu);
+	dprintf_menu(stddeb,"SetMenu("NPFMT", "NPFMT");\n", hWnd, hMenu);
 	if (GetCapture() == hWnd) ReleaseCapture();
 	wndPtr->wIDmenu = hMenu;
 	if (hMenu != 0)
 	{
 	    lpmenu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
 	    if (lpmenu == NULL) {
-		fprintf(stderr,"SetMenu(%04X, %04X) // Bad menu handle !\n", 
+		fprintf(stderr,"SetMenu("NPFMT", "NPFMT") // Bad menu handle !\n", 
 			hWnd, hMenu);
 		return FALSE;
 		}
@@ -2045,7 +2077,7 @@
 {
     LPPOPUPMENU lppop;
     LPMENUITEM 	lpitem;
-    dprintf_menu(stddeb,"GetSubMenu (%04X, %04X) !\n", hMenu, nPos);
+    dprintf_menu(stddeb,"GetSubMenu ("NPFMT", %04X) !\n", hMenu, nPos);
     if (!(lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return 0;
     if ((WORD)nPos >= lppop->nItems) return 0;
     lpitem = (MENUITEM *) USER_HEAP_LIN_ADDR( lppop->hItems );
@@ -2061,7 +2093,7 @@
 {
 	WND		*wndPtr;
 	LPPOPUPMENU lppop;
-	dprintf_menu(stddeb,"DrawMenuBar (%04X)\n", hWnd);
+	dprintf_menu(stddeb,"DrawMenuBar ("NPFMT")\n", hWnd);
 	wndPtr = WIN_FindWndPtr(hWnd);
 	if (wndPtr != NULL && (wndPtr->dwStyle & WS_CHILD) == 0 && 
 		wndPtr->wIDmenu != 0) {
@@ -2109,11 +2141,11 @@
     if (HIWORD(name))
     {
         char *str = (char *)PTR_SEG_TO_LIN( name );
-        dprintf_menu( stddeb, "LoadMenu(%04x,'%s')\n", instance, str );
+        dprintf_menu( stddeb, "LoadMenu("NPFMT",'%s')\n", instance, str );
         if (str[0] == '#') name = (SEGPTR)atoi( str + 1 );
     }
     else
-        dprintf_resource(stddeb,"LoadMenu(%04x,%04x)\n",instance,LOWORD(name));
+        dprintf_resource(stddeb,"LoadMenu("NPFMT",%04x)\n",instance,LOWORD(name));
 
     if (!name) return 0;
 
@@ -2157,7 +2189,7 @@
     }
     menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hMenu);
     menu->wFlags |= MF_SYSMENU|MF_POPUP;
-    dprintf_menu(stddeb,"CopySysMenu hMenu=%04X !\n", hMenu);
+    dprintf_menu(stddeb,"CopySysMenu hMenu="NPFMT" !\n", hMenu);
     return hMenu;
 }
 
diff --git a/controls/scroll.c b/controls/scroll.c
index 230b7b4..507c897 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -353,8 +353,14 @@
     {
         if (nBar == SB_CTL)  /* Only scrollbar controls send WM_CTLCOLOR */
         {
+#ifdef WINELIB32
+            HBRUSH hbrush = (HBRUSH)SendMessage( GetParent(hwnd), 
+						 WM_CTLCOLORSCROLLBAR,
+						 (WPARAM)hdc, (LPARAM)hwnd );
+#else
             HBRUSH hbrush = SendMessage( GetParent(hwnd), WM_CTLCOLOR, hdc,
                                          MAKELONG(hwnd, CTLCOLOR_SCROLLBAR) );
+#endif
             SelectObject( hdc, hbrush );
         }
         else SelectObject( hdc, sysColorObjects.hbrushScrollbar );
@@ -506,9 +512,15 @@
     default:
         return;
     }
+#ifdef WINELIB32
+    SendMessage( GetParent(hwnd),
+                 (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
+                 (WPARAM)msg, (LPARAM)hwnd );
+#else
     SendMessage( GetParent(hwnd),
                  (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
                  msg, MAKELONG( 0, hwnd ));
+#endif
 }
 
 
@@ -580,7 +592,7 @@
           return;  /* Should never happen */
     }
 
-    dprintf_scroll( stddeb, "ScrollBar Event: hwnd=%x bar=%d msg=%x pt=%d,%d hit=%d\n",
+    dprintf_scroll( stddeb, "ScrollBar Event: hwnd="NPFMT" bar=%d msg=%x pt=%d,%d hit=%d\n",
                     hwnd, nBar, msg, pt.x, pt.y, hittest );
 
     switch(trackHitTest)
@@ -598,8 +610,13 @@
                 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
                                 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
                                 (FARPROC)0 );
+#ifdef WINELIB32
+                SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
+                             (WPARAM)SB_LINEUP, (LPARAM)hwndCtl );
+#else
                 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
                              SB_LINEUP, MAKELONG( 0, hwndCtl ));
+#endif
             }
         }
         else KillSystemTimer( hwnd, SCROLL_TIMER );
@@ -616,8 +633,13 @@
                 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
                                 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
                                 (FARPROC)0 );
+#ifdef WINELIB32
+                SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
+                             (WPARAM)SB_PAGEUP, (LPARAM)hwndCtl );
+#else
                 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
                              SB_PAGEUP, MAKELONG( 0, hwndCtl ));
+#endif
             }
         }
         else KillSystemTimer( hwnd, SCROLL_TIMER );
@@ -645,8 +667,13 @@
                 lastMousePos = pos;
                 val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
                                  trackThumbPos + lastMousePos - lastClickPos );
+#ifdef WINELIB32
+                SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
+                             MAKEWPARAM(SB_THUMBTRACK,val), (LPARAM)hwndCtl );
+#else
                 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
                              SB_THUMBTRACK, MAKELONG( val, hwndCtl ));
+#endif
             }
         }
         break;
@@ -662,8 +689,13 @@
                 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
                                 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
                                 (FARPROC)0 );
+#ifdef WINELIB32
+                SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
+                             (WPARAM)SB_PAGEDOWN, (LPARAM)hwndCtl );
+#else
                 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
                              SB_PAGEDOWN, MAKELONG( 0, hwndCtl ));
+#endif
             }
         }
         else KillSystemTimer( hwnd, SCROLL_TIMER );
@@ -679,8 +711,13 @@
                 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
                                 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
                                 (FARPROC)0 );
+#ifdef WINELIB32
+                SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
+                             (WPARAM)SB_LINEDOWN, (LPARAM)hwndCtl );
+#else
                 SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
                              SB_LINEDOWN, MAKELONG( 0, hwndCtl ));
+#endif
             }
         }
         else KillSystemTimer( hwnd, SCROLL_TIMER );
@@ -693,12 +730,22 @@
         {
             UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
                                  trackThumbPos + lastMousePos - lastClickPos );
+#ifdef WINELIB32
+            SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
+                         MAKEWPARAM(SB_THUMBPOSITION,val), (LPARAM)hwndCtl );
+#else
             SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
                          SB_THUMBPOSITION, MAKELONG( val, hwndCtl ) );
+#endif
         }
         else
+#ifdef WINELIB32
+            SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
+                         (WPARAM)SB_ENDSCROLL, (LPARAM)hwndCtl );
+#else
             SendMessage( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
                          SB_ENDSCROLL, MAKELONG( 0, hwndCtl ) );
+#endif
         trackHitTest = SCROLL_NOWHERE;  /* Terminate tracking */
     }
 
@@ -746,7 +793,7 @@
             }
         }
         if (!hUpArrow) SCROLL_LoadBitmaps();
-        dprintf_scroll( stddeb, "ScrollBar creation, hwnd=%d\n", hwnd );
+        dprintf_scroll( stddeb, "ScrollBar creation, hwnd="NPFMT"\n", hwnd );
         return 0;
 	
     case WM_LBUTTONDOWN:
@@ -822,7 +869,7 @@
 
     if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return;
 
-    dprintf_scroll( stddeb,"SetScrollRange hwnd=%x bar=%d min=%d max=%d\n",
+    dprintf_scroll( stddeb,"SetScrollRange hwnd="NPFMT" bar=%d min=%d max=%d\n",
                     hwnd, nBar, MinVal, MaxVal );
 
       /* Invalid range -> range is set to (0,0) */
@@ -860,7 +907,7 @@
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
     if (!wndPtr) return;
-    dprintf_scroll( stddeb, "ShowScrollBar: hwnd=%x bar=%d on=%d\n", hwnd, wBar, fShow );
+    dprintf_scroll( stddeb, "ShowScrollBar: hwnd="NPFMT" bar=%d on=%d\n", hwnd, wBar, fShow );
 
     switch(wBar)
     {
@@ -926,7 +973,7 @@
     HDC hdc;
 
     if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
-    dprintf_scroll( stddeb, "EnableScrollBar: %x %d %d\n", hwnd, nBar, flags );
+    dprintf_scroll( stddeb, "EnableScrollBar: "NPFMT" %d %d\n", hwnd, nBar, flags );
     flags &= ESB_DISABLE_BOTH;
     if (infoPtr->flags == flags) return FALSE;
     infoPtr->flags = flags;
diff --git a/controls/static.c b/controls/static.c
index b0c37ec..b88dd2f 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -11,7 +11,6 @@
 #include "win.h"
 #include "user.h"
 #include "static.h"
-#include "icon.h"
 
 extern void DEFWND_SetText( HWND hwnd, LPSTR text );  /* windows/defwnd.c */
 
@@ -60,9 +59,8 @@
     infoPtr->hIcon = hicon;
     if (hicon)
     {
-        ICONALLOC *icon = (ICONALLOC *) GlobalLock( hicon );
-        SetWindowPos( hwnd, 0, 0, 0,
-                     icon->descriptor.Width, icon->descriptor.Height,
+        CURSORICONINFO *info = (CURSORICONINFO *) GlobalLock( hicon );
+        SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
                      SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
         GlobalUnlock( hicon );
     }
@@ -72,7 +70,7 @@
 /***********************************************************************
  *           StaticWndProc
  */
-LONG StaticWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam)
+LONG StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
 	LONG lResult = 0;
 	WND *wndPtr = WIN_FindWndPtr(hWnd);
@@ -144,7 +142,7 @@
 
         case WM_SETFONT:
             if (style == SS_ICON) return 0;
-            infoPtr->hFont = wParam;
+            infoPtr->hFont = (HFONT)wParam;
             if (LOWORD(lParam))
             {
                 InvalidateRect( hWnd, NULL, FALSE );
@@ -153,7 +151,7 @@
             break;
 
         case WM_GETFONT:
-            return infoPtr->hFont;
+            return (LONG)infoPtr->hFont;
 
 	case WM_NCHITTEST:
 	    return HTTRANSPARENT;
@@ -162,10 +160,10 @@
             return DLGC_STATIC;
 
 	case STM_GETICON:
-	    return infoPtr->hIcon;
+	    return (LONG)infoPtr->hIcon;
 
 	case STM_SETICON:
-            STATIC_SetIcon( hWnd, wParam );
+            STATIC_SetIcon( hWnd, (HICON)wParam );
             InvalidateRect( hWnd, NULL, FALSE );
             UpdateWindow( hWnd );
 	    return 0;
@@ -223,8 +221,13 @@
 	wFormat |= DT_NOPREFIX;
 
     if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
+#ifdef WINELIB32
+    hBrush = (HBRUSH)SendMessage( wndPtr->hwndParent, WM_CTLCOLORSTATIC,
+				  (WPARAM)hdc, (LPARAM)hwnd );
+#else
     hBrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, (WORD)hdc,
                           MAKELONG(hwnd, CTLCOLOR_STATIC));
+#endif
     if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
     FillRect(hdc, &rc, hBrush);
     if (text)
@@ -281,8 +284,13 @@
     STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
 
     GetClientRect(hwnd, &rc);
+#ifdef WINELIB32
+    hbrush = (HBRUSH)SendMessage( wndPtr->hwndParent, WM_CTLCOLORSTATIC, 
+				  (WPARAM)hdc, (LPARAM)hwnd );
+#else
     hbrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, hdc,
                           MAKELONG(hwnd, CTLCOLOR_STATIC));
+#endif
     FillRect( hdc, &rc, hbrush );
     if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
 }
diff --git a/controls/widgets.c b/controls/widgets.c
index 34d678a..5559dd1 100644
--- a/controls/widgets.c
+++ b/controls/widgets.c
@@ -63,7 +63,7 @@
         DWORD WineProc,Win16Proc,Win32Proc;
         /* currently, there is no way to get the 'real' pointer at run time */
         WineProc=0;
-        Win16Proc = GetWndProcEntry16( (char *)class->lpfnWndProc );
+        Win16Proc = (DWORD)GetWndProcEntry16( (char *)class->lpfnWndProc );
         Win32Proc = (DWORD)RELAY32_GetEntryPoint(
              "WINPROCS32",(char *)class->lpfnWndProc, 0);
         /* Register the alias so we don't pass Win16 pointers to Win32 apps */
diff --git a/debugger/Imakefile b/debugger/Imakefile
deleted file mode 100644
index 766a9c7..0000000
--- a/debugger/Imakefile
+++ /dev/null
@@ -1,54 +0,0 @@
-#include "../Wine.tmpl"
-
-#define IHaveSubdirs
-#define	PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)' 'CC=$(CC)' 'MAKE=$(MAKE)'\
-			'LD=$(LD)'
-
-MODULE = debugger
-
-SUBDIRS = readline
-
-DEFINES = -DUSE_READLINE
-
-SRCS = \
-	break.c \
-	db_disasm.c \
-	dbg.tab.c \
-	hash.c \
-	info.c \
-	lex.yy.c \
-	memory.c \
-	registers.c \
-	stack.c
-
-SUBDIRS_OBJS = readline/readline.o
-
-OBJS = $(SRCS:.c=.o) $(SUBDIRS_OBJS)
-
-/*
- * All the SUBDIR stuff
- */
-MakeSubdirs($(SUBDIRS))
-DependSubdirs($(SUBDIRS))
-
-/*
- * The main act
- */
-WineRelocatableTarget($(MODULE),,$(OBJS))
-
-depend:: dbg.tab.c dbg.tab.h lex.yy.c
-
-DependTarget()
-
-includes::
-
-install::
-
-clean::
-	$(RM) lex.yy.c dbg.tab* y.tab.c
-
-dbg.tab.c dbg.tab.h: dbg.y
-	$(YACC) -b dbg -d dbg.y
-
-lex.yy.c: debug.l
-	$(LEX) -I debug.l
diff --git a/debugger/break.c b/debugger/break.c
index 4406b2f..8e9fbb8 100644
--- a/debugger/break.c
+++ b/debugger/break.c
@@ -142,8 +142,15 @@
     for (i = 0; i < MAX_BREAKPOINTS; i++)
     {
         if (breakpoints[i].in_use && breakpoints[i].enabled)
-            DEBUG_SetOpcode( &breakpoints[i].addr,
-                             set ? INT3 : breakpoints[i].opcode );
+        {
+            if (DEBUG_IsBadWritePtr( &breakpoints[i].addr, 1 ))
+            {
+                fprintf( stderr, "Invalid address for breakpoint %d, disabling it\n", i );
+                breakpoints[i].enabled = FALSE;
+            }
+            else DEBUG_SetOpcode( &breakpoints[i].addr,
+                                  set ? INT3 : breakpoints[i].opcode );
+        }
     }
 }
 
@@ -193,6 +200,7 @@
             return;
         }
     }
+    if (!DBG_CHECK_READ_PTR( &addr, 1 )) return;
     p = DBG_ADDR_TO_LIN( &addr );
     breakpoints[num].addr    = addr;
     breakpoints[num].addrlen = !addr.seg ? 32 :
diff --git a/debugger/dbg.y b/debugger/dbg.y
index 5aa6780..7eb5a58 100644
--- a/debugger/dbg.y
+++ b/debugger/dbg.y
@@ -51,7 +51,6 @@
 	| input line  { issue_prompt(); }
 
  line:		'\n'
-	| infocmd '\n'
 	| error '\n'       { yyerrok; }
 	| QUIT  '\n'       { exit(0); }
 	| HELP  '\n'       { DEBUG_Help(); }
@@ -72,6 +71,7 @@
                                 }
         | DELETE BREAK NUM '\n' { DEBUG_DelBreakpoint( $3 ); }
 	| BACKTRACE '\n'        { DEBUG_BackTrace(); }
+	| infocmd
 	| x_command
 	| print_command
 	| deposit_command
@@ -113,10 +113,11 @@
 	| '(' expr ')'		{ $$ = $2; }
 	| '*' addr		{ $$ = DEBUG_ReadMemory( &$2 ); }
 	
- infocmd: INFO REGS     { DEBUG_InfoRegisters(); }
-	| INFO STACK    { DEBUG_InfoStack(); }
-	| INFO BREAK    { DEBUG_InfoBreakpoints(); }
-	| INFO SEGMENTS { LDT_Print(); }
+ infocmd: INFO REGS '\n'          { DEBUG_InfoRegisters(); }
+	| INFO STACK '\n'         { DEBUG_InfoStack(); }
+	| INFO BREAK '\n'         { DEBUG_InfoBreakpoints(); }
+	| INFO SEGMENTS '\n'      { LDT_Print( 0, -1 ); }
+        | INFO SEGMENTS expr '\n' { LDT_Print( SELECTOR_TO_ENTRY($3), 1 ); }
 
 
 %%
@@ -162,9 +163,9 @@
     {
         DBG_ADDR addr;
 
-        addr.seg = (CS_reg(DEBUG_context) == WINE_CODE_SELECTOR) ?
-                    0 : CS_reg(DEBUG_context);
+        addr.seg = CS_reg(DEBUG_context);
         addr.off = EIP_reg(DEBUG_context);
+        DBG_FIX_ADDR_SEG( &addr, 0 );
 
         if (!addr.seg) newmode = 32;
         else newmode = (GET_SEL_FLAGS(addr.seg) & LDT_FLAGS_32BIT) ? 32 : 16;
@@ -175,13 +176,22 @@
         /* Show where we crashed */
         DEBUG_PrintAddress( &addr, dbg_mode );
         fprintf(stderr,":  ");
-        DEBUG_Disasm( &addr );
-        fprintf(stderr,"\n");
-        instr_len = addr.off - EIP_reg(DEBUG_context);
-        
-        issue_prompt();
-        yyparse();
-        flush_symbols();
+        if (DBG_CHECK_READ_PTR( &addr, 1 ))
+        {
+            DEBUG_Disasm( &addr );
+            fprintf(stderr,"\n");
+            instr_len = addr.off - EIP_reg(DEBUG_context);
+        }
+
+        do
+        {
+            issue_prompt();
+            yyparse();
+            flush_symbols();
+            addr.seg = CS_reg(DEBUG_context);
+            addr.off = EIP_reg(DEBUG_context);
+            DBG_FIX_ADDR_SEG( &addr, 0 );
+        } while (!DBG_CHECK_READ_PTR( &addr, 1 ));
     }
 
     DEBUG_RestartExecution( regs, dbg_exec_mode, instr_len );
diff --git a/debugger/debug.l b/debugger/debug.l
index 29321e7..ef142ed 100644
--- a/debugger/debug.l
+++ b/debugger/debug.l
@@ -73,7 +73,7 @@
 $ss     { yylval.reg = REG_SS;  return REG; }
 
 info|inf|in		      { return INFO; }
-segments|segm                 { return SEGMENTS; }
+segments|segment|segm|seg|se  { return SEGMENTS; }
 break|brea|bre|br|b           { return BREAK; }
 enable|enabl|enab|ena         { return ENABLE;}
 disable|disabl|disab|disa|dis { return DISABLE; }
diff --git a/debugger/memory.c b/debugger/memory.c
index 206e587..49108c2 100644
--- a/debugger/memory.c
+++ b/debugger/memory.c
@@ -11,6 +11,40 @@
 
 
 /***********************************************************************
+ *           DEBUG_IsBadReadPtr
+ *
+ * Check if we are allowed to read memory at 'address'.
+ */
+BOOL DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size )
+{
+    if (address->seg)  /* segmented addr */
+        return IsBadReadPtr( (SEGPTR)MAKELONG( (WORD)address->off,
+                                               (WORD)address->seg ), size );
+        /* FIXME: should check if resulting linear addr is readable */
+    else  /* linear address */
+        return FALSE;  /* FIXME: should do some checks here */
+}
+
+
+/***********************************************************************
+ *           DEBUG_IsBadWritePtr
+ *
+ * Check if we are allowed to write memory at 'address'.
+ */
+BOOL DEBUG_IsBadWritePtr( const DBG_ADDR *address, int size )
+{
+    if (address->seg)  /* segmented addr */
+        /* Note: we use IsBadReadPtr here because we are */
+        /* always allowed to write to read-only segments */
+        return IsBadReadPtr( (SEGPTR)MAKELONG( (WORD)address->off,
+                                               (WORD)address->seg ), size );
+        /* FIXME: should check if resulting linear addr is writable */
+    else  /* linear address */
+        return FALSE;  /* FIXME: should do some checks here */
+}
+
+
+/***********************************************************************
  *           DEBUG_ReadMemory
  *
  * Read a memory value.
@@ -20,6 +54,7 @@
     DBG_ADDR addr = *address;
 
     DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
+    if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return 0;
     return *(int *)DBG_ADDR_TO_LIN( &addr );
 }
 
@@ -34,6 +69,7 @@
     DBG_ADDR addr = *address;
 
     DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
+    if (!DBG_CHECK_WRITE_PTR( &addr, sizeof(int) )) return;
     *(int *)DBG_ADDR_TO_LIN( &addr ) = value;
 }
 
@@ -57,7 +93,7 @@
     if (format != 'i' && count > 1)
     {
         DEBUG_PrintAddress( &addr, dbg_mode );
-        fprintf(stderr,":  ");
+        fprintf(stderr,": ");
     }
 
     pnt = DBG_ADDR_TO_LIN( &addr );
@@ -66,7 +102,13 @@
     {
 	case 's':
 		if (count == 1) count = 256;
-	        while(*pnt && count--) fputc( *pnt++, stderr );
+                while (count--)
+                {
+                    if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
+                    if (!*pnt) break;
+                    addr.off++;
+                    fputc( *pnt++, stderr );
+                }
 		fprintf(stderr,"\n");
 		return;
 
@@ -74,7 +116,8 @@
 		while (count--)
                 {
                     DEBUG_PrintAddress( &addr, dbg_mode );
-                    fprintf(stderr,":  ");
+                    fprintf(stderr,": ");
+                    if (!DBG_CHECK_READ_PTR( &addr, 1 )) return;
                     DEBUG_Disasm( &addr );
                     fprintf(stderr,"\n");
 		}
@@ -83,13 +126,15 @@
 		dump = (unsigned int *)pnt;
 		for(i=0; i<count; i++) 
 		{
-			fprintf(stderr," %8.8x", *dump++);
-                        addr.off += 4;
-			if ((i % 8) == 7) {
-				fprintf(stderr,"\n");
-				DEBUG_PrintAddress( &addr, dbg_mode );
-				fprintf(stderr,":  ");
-			};
+                    if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return;
+                    fprintf(stderr," %8.8x", *dump++);
+                    addr.off += sizeof(int);
+                    if ((i % 8) == 7)
+                    {
+                        fprintf(stderr,"\n");
+                        DEBUG_PrintAddress( &addr, dbg_mode );
+                        fprintf(stderr,": ");
+                    }
 		}
 		fprintf(stderr,"\n");
 		return;
@@ -98,13 +143,15 @@
 		dump = (unsigned int *)pnt;
 		for(i=0; i<count; i++) 
 		{
-			fprintf(stderr," %d", *dump++);
-                        addr.off += 4;
-			if ((i % 8) == 7) {
-				fprintf(stderr,"\n");
-				DEBUG_PrintAddress( &addr, dbg_mode );
-				fprintf(stderr,":  ");
-			};
+                    if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return;
+                    fprintf(stderr," %d", *dump++);
+                    addr.off += sizeof(int);
+                    if ((i % 8) == 7)
+                    {
+                        fprintf(stderr,"\n");
+                        DEBUG_PrintAddress( &addr, dbg_mode );
+                        fprintf(stderr,": ");
+                    }
 		}
 		fprintf(stderr,"\n");
 		return;
@@ -113,13 +160,15 @@
 		wdump = (unsigned short *)pnt;
 		for(i=0; i<count; i++) 
 		{
-			fprintf(stderr," %04x", *wdump++);
-                        addr.off += 2;
-			if ((i % 8) == 7) {
-				fprintf(stderr,"\n");
-				DEBUG_PrintAddress( &addr, dbg_mode );
-				fprintf(stderr,":  ");
-			};
+                    if (!DBG_CHECK_READ_PTR( &addr, sizeof(short) )) return;
+                    fprintf(stderr," %04x", *wdump++);
+                    addr.off += sizeof(short);
+                    if ((i % 8) == 7)
+                    {
+                        fprintf(stderr,"\n");
+                        DEBUG_PrintAddress( &addr, dbg_mode );
+                        fprintf(stderr,": ");
+                    }
 		}
 		fprintf(stderr,"\n");
 		return;
@@ -127,17 +176,20 @@
 	case 'c':
 		for(i=0; i<count; i++) 
 		{
-			if(*pnt < 0x20) {
-				fprintf(stderr,"  ");
-				pnt++;
-			} else
-				fprintf(stderr," %c", *pnt++);
-                        addr.off++;
-			if ((i % 32) == 31) {
-				fprintf(stderr,"\n");
-				DEBUG_PrintAddress( &addr, dbg_mode );
-				fprintf(stderr,":  ");
-			};
+                    if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
+                    if(*pnt < 0x20)
+                    {
+                        fprintf(stderr,"  ");
+                        pnt++;
+                    }
+                    else fprintf(stderr," %c", *pnt++);
+                    addr.off++;
+                    if ((i % 32) == 31)
+                    {
+                        fprintf(stderr,"\n");
+                        DEBUG_PrintAddress( &addr, dbg_mode );
+                        fprintf(stderr,": ");
+                    }
 		}
 		fprintf(stderr,"\n");
 		return;
@@ -145,13 +197,15 @@
 	case 'b':
 		for(i=0; i<count; i++) 
 		{
-			fprintf(stderr," %02x", (*pnt++) & 0xff);
-                        addr.off++;
-			if ((i % 16) == 15) {
-				fprintf(stderr,"\n");
-				DEBUG_PrintAddress( &addr, dbg_mode );
-				fprintf(stderr,":  ");
-			};
+                    if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
+                    fprintf(stderr," %02x", (*pnt++) & 0xff);
+                    addr.off++;
+                    if ((i % 16) == 15)
+                    {
+                        fprintf(stderr,"\n");
+                        DEBUG_PrintAddress( &addr, dbg_mode );
+                        fprintf(stderr,": ");
+                    }
 		}
 		fprintf(stderr,"\n");
 		return;
diff --git a/debugger/readline/Imakefile b/debugger/readline/Imakefile
deleted file mode 100644
index 6678bcb..0000000
--- a/debugger/readline/Imakefile
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "../../Wine.tmpl"
-
-MODULE = readline
-
-EXTRA_DEFINES= -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE
-
-SRCS = \
-	editline.c \
-	sysunix.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/debugger/stack.c b/debugger/stack.c
index 73fcacf..be7fb9b 100644
--- a/debugger/stack.c
+++ b/debugger/stack.c
@@ -62,40 +62,46 @@
     DBG_ADDR addr;
     int frameno = 0;
 
-  fprintf(stderr,"Backtrace:\n");
-  if (SS_reg(DEBUG_context) == WINE_DATA_SELECTOR)  /* 32-bit mode */
-  {
-      FRAME32 *frame = (FRAME32 *)EBP_reg(DEBUG_context);
-      addr.seg = 0;
-      while (frame->ip)
-      {
-          fprintf(stderr,"%d ",frameno++);
-          addr.off = frame->ip;
-          DEBUG_PrintAddress( &addr, 32 );
-          fprintf( stderr, "\n" );
-          frame = (FRAME32 *)frame->bp;
-      }
-  }
-  else  /* 16-bit mode */
-  {
-      FRAME16 *frame = (FRAME16 *)PTR_SEG_OFF_TO_LIN( SS_reg(DEBUG_context),
-                                                  BP_reg(DEBUG_context) & ~1 );
-      WORD cs = CS_reg(DEBUG_context);
-      if (GET_SEL_FLAGS(SS_reg(DEBUG_context)) & LDT_FLAGS_32BIT)
+    fprintf(stderr,"Backtrace:\n");
+    if (SS_reg(DEBUG_context) == WINE_DATA_SELECTOR)  /* 32-bit mode */
+    {
+        addr.seg = 0;
+        addr.off = EBP_reg(DEBUG_context);
+        for (;;)
+        {
+            FRAME32 *frame = (FRAME32 *)addr.off;
+            if (!DBG_CHECK_READ_PTR( &addr, sizeof(FRAME32) )) return;
+            if (!frame->ip) break;
+            fprintf(stderr,"%d ",frameno++);
+            addr.off = frame->ip;
+            DEBUG_PrintAddress( &addr, 32 );
+            fprintf( stderr, "\n" );
+            addr.off = frame->bp;
+        }
+    }
+    else  /* 16-bit mode */
+    {
+      WORD ss = SS_reg(DEBUG_context), cs = CS_reg(DEBUG_context);
+      if (GET_SEL_FLAGS(ss) & LDT_FLAGS_32BIT)
       {
           fprintf( stderr, "Not implemented: 32-bit backtrace on a different stack segment.\n" );
           return;
       }
-      while (frame->bp)
+      addr.seg = SS_reg(DEBUG_context);
+      addr.off = BP_reg(DEBUG_context) & ~1;
+      for (;;)
       {
+          FRAME16 *frame = (FRAME16 *)DBG_ADDR_TO_LIN(&addr);
+          if (!DBG_CHECK_READ_PTR( &addr, sizeof(FRAME16) )) return;
+          if (!frame->bp) break;
           if (frame->bp & 1) cs = frame->cs;
           fprintf( stderr,"%d ", frameno++ );
           addr.seg = cs;
           addr.off = frame->ip;
           DEBUG_PrintAddress( &addr, 16 );
           fprintf( stderr, "\n" );
-          frame = (FRAME16 *)PTR_SEG_OFF_TO_LIN( SS_reg(DEBUG_context),
-                                                 frame->bp & ~1 );
+          addr.seg = ss;
+          addr.off = frame->bp & ~1;
       }
   }
   fprintf( stderr, "\n" );
diff --git a/if1632/Imakefile b/if1632/Imakefile
deleted file mode 100644
index 8eb6c1e..0000000
--- a/if1632/Imakefile
+++ /dev/null
@@ -1,120 +0,0 @@
-#include "../autoconf.h"
-#include "../Wine.tmpl"
-
-MODULE = if1632
-
-SRCS = \
-	callback.c \
-	relay.c \
-	relay32.c
-
-#ifdef WINELIB
-CALLOBJS =
-DLLS16 =
-DLLS32 =
-#else
-CALLOBJS = \
-	call16.o \
-	call32.o
-DLLS16 = \
-	commdlg.spec \
-	compobj.spec \
-	ddeml.spec \
-	gdi.spec \
-	kernel.spec \
-	keyboard.spec \
-	mmsystem.spec \
-	mouse.spec \
-	ole2.spec \
-	ole2conv.spec \
-	ole2disp.spec \
-	ole2nls.spec \
-	ole2prox.spec \
-	olecli.spec \
-	olesvr.spec \
-	shell.spec \
-	sound.spec \
-	storage.spec \
-	stress.spec \
-	system.spec \
-	toolhelp.spec \
-	user.spec \
-	win87em.spec \
-	winprocs.spec \
-	winsock.spec
-DLLS32 = \
-	advapi32.spec \
-	comdlg32.spec \
-	gdi32.spec \
-	kernel32.spec \
-	shell32.spec \
-	user32.spec \
-	winprocs32.spec
-#endif
-
-OBJS = $(SRCS:.c=.o) $(CALLOBJS) $(DLLS16:.spec=.o) $(DLLS32:.spec=.o)
-
-BUILD = $(TOP)/tools/build
-
-#define MakeDll16FromSpec(name)			@@\
-name.S : name.spec $(BUILD)			@@\
-	$(BUILD) -spec16 name.spec > name.S	@@\
-
-#define MakeDll32FromSpec(name)			@@\
-name.c : name.spec $(BUILD)			@@\
-	$(BUILD) -spec32 name.spec > name.c	@@\
-
-/*
- * If you add a new spec file, copy one of these lines
- */
-MakeDll16FromSpec(commdlg)
-MakeDll16FromSpec(compobj)
-MakeDll16FromSpec(ddeml)
-MakeDll16FromSpec(gdi)
-MakeDll16FromSpec(kernel)
-MakeDll16FromSpec(keyboard)
-MakeDll16FromSpec(shell)
-MakeDll16FromSpec(mmsystem)
-MakeDll16FromSpec(mouse)
-MakeDll16FromSpec(ole2)
-MakeDll16FromSpec(ole2conv)
-MakeDll16FromSpec(ole2disp)
-MakeDll16FromSpec(ole2nls)
-MakeDll16FromSpec(ole2prox)
-MakeDll16FromSpec(olecli)
-MakeDll16FromSpec(olesvr)
-MakeDll16FromSpec(sound)
-MakeDll16FromSpec(storage)
-MakeDll16FromSpec(stress)
-MakeDll16FromSpec(system)
-MakeDll16FromSpec(toolhelp)
-MakeDll16FromSpec(user)
-MakeDll16FromSpec(win87em)
-MakeDll16FromSpec(winprocs)
-MakeDll16FromSpec(winsock)
-
-MakeDll32FromSpec(gdi32)
-MakeDll32FromSpec(kernel32)
-MakeDll32FromSpec(shell32)
-MakeDll32FromSpec(user32)
-MakeDll32FromSpec(winprocs32)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-#ifndef WINELIB
-
-call32.S: $(BUILD) $(DLLS16:.spec=.S)
-	$(BUILD) -call32 `cat $(DLLS16:.spec=.S) | grep CallTo32_ | sed 's/.*CallTo32_\(.*\)/\1/' | sort | uniq` > call32.S
-
-call16.S: $(BUILD) $(TOP)/include/callback.h
-	$(BUILD) -call16 `cat $(TOP)/include/callback.h | grep "extern.*CallTo16_" | sed 's/.*CallTo16_\(.*\)(.*/\1/' | sort | uniq` > call16.S
-
-#endif  /* WINELIB */
-
-includes::
-
-install::
-
-clean::
-	$(RM) $(DLLS16:.spec=.S) $(DLLS32:.spec=.c) call32.S call16.S
diff --git a/if1632/callback.c b/if1632/callback.c
index 1cc1fde..2d6a742 100644
--- a/if1632/callback.c
+++ b/if1632/callback.c
@@ -26,7 +26,6 @@
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
     if (!wndPtr) return 0;
-    SpyMessage(hwnd, message, wParam, lParam);
 
     /* check if we have something better than 16 bit relays */
     if(!ALIAS_UseAliases || !(a=ALIAS_LookupAlias((DWORD)func)) ||
diff --git a/if1632/gdi.spec b/if1632/gdi.spec
index 2ea33f1..f960007 100644
--- a/if1632/gdi.spec
+++ b/if1632/gdi.spec
@@ -254,7 +254,7 @@
 374 pascal16 GetSystemPaletteUse(word) GetSystemPaletteUse
 375 pascal16 GetSystemPaletteEntries(word word word ptr)
              GetSystemPaletteEntries
-376 stub ResetDC
+376 pascal16 ResetDC(word ptr) ResetDC
 377 stub STARTDOC
 378 stub ENDDOC
 379 stub STARTPAGE
diff --git a/if1632/kernel32.spec b/if1632/kernel32.spec
index 9f0ceee..1987061 100644
--- a/if1632/kernel32.spec
+++ b/if1632/kernel32.spec
@@ -149,13 +149,13 @@
 0145 stub FreeResource
 0146 stub FreeVirtualBuffer
 0147 stub GenerateConsoleCtrlEvent
-0148 stub GetACP
+0148    stdcall GetACP() GetACP
 0149 stub GetAtomNameA
 0150 stub GetAtomNameW
 0151 stub GetBinaryType
 0152 stub GetBinaryTypeA
 0153 stub GetBinaryTypeW
-0154 stub GetCPInfo
+0154    stdcall GetCPInfo(long ptr) GetCPInfo
 0155 stub GetCommConfig
 0156 stub GetCommMask
 0157 stub GetCommModemStatus
@@ -214,7 +214,7 @@
 0210	stdcall GetEnvironmentStrings()	GetEnvironmentStrings
 0211 stub GetEnvironmentStringsA
 0212 stub GetEnvironmentStringsW
-0213 stub GetEnvironmentVariableA
+0213    stdcall GetEnvironmentVariableA(ptr ptr long) GetEnvironmentVariableA
 0214 stub GetEnvironmentVariableW
 0215 stub GetExitCodeProcess
 0216 stub GetExitCodeThread
@@ -223,12 +223,12 @@
 0219 stub GetFileInformationByHandle
 0220 stub GetFileSize
 0221 stub GetFileTime
-0222 stub GetFileType
+0222    stdcall GetFileType(long) GetFileType
 0223 stub GetFullPathNameA
 0224 stub GetFullPathNameW
 0225 stub GetHandleInformation
 0226 stub GetLargestConsoleWindowSize
-0227 stub GetLastError
+0227    stdcall GetLastError() GetLastError
 0228 stub GetLocalTime
 0229 stub GetLocaleInfoA
 0230 stub GetLocaleInfoW
@@ -236,7 +236,7 @@
 0232 stub GetLogicalDriveStringsW
 0233 stub GetLogicalDrives
 0234 stub GetMailslotInfo
-0235	return GetModuleFileNameA 12 0
+0235	stdcall GetModuleFileNameA(long ptr long) GetModuleFileNameA
 0236 stub GetModuleFileNameW
 0237	stdcall GetModuleHandleA(ptr)	GetModuleHandle
 0238 stub GetModuleHandleW
@@ -249,7 +249,7 @@
 0245 stub GetNumberOfConsoleFonts
 0246 stub GetNumberOfConsoleInputEvents
 0247 stub GetNumberOfConsoleMouseButtons
-0248 stub GetOEMCP
+0248    stdcall GetOEMCP() GetOEMCP
 0249 stub GetOverlappedResult
 0250 stub GetPriorityClass
 0251 stub GetPrivateProfileIntA
@@ -274,7 +274,7 @@
 0270 stub GetQueuedCompletionStatus
 0271 stub GetShortPathNameA
 0272 stub GetShortPathNameW
-0273	return GetStartupInfoA 4 0
+0273	stdcall GetStartupInfoA(ptr) GetStartupInfoA
 0274 stub GetStartupInfoW
 0275	stdcall GetStdHandle(long)	GetStdHandle
 0276 stub GetStringTypeA
@@ -300,10 +300,10 @@
 0296 stub GetThreadPriority
 0297 stub GetThreadSelectorEntry
 0298 stub GetThreadTimes
-0299 stub GetTickCount
+0299    stdcall GetTickCount() GetTickCount
 0300 stub GetTimeFormatA
 0301 stub GetTimeFormatW
-0302 stub GetTimeZoneInformation
+0302    stdcall GetTimeZoneInformation(ptr) GetTimeZoneInformation
 0303 stub GetUserDefaultLCID
 0304 stub GetUserDefaultLangID
 0305 stub GetVDMCurrentDirectories
@@ -486,7 +486,7 @@
 0481 stub SetDefaultCommConfigA
 0482 stub SetDefaultCommConfigW
 0483 stub SetEndOfFile
-0484 stub SetEnvironmentVariableA
+0484    stdcall SetEnvironmentVariableA(ptr ptr) SetEnvironmentVariableA
 0485 stub SetEnvironmentVariableW
 0486 stub SetErrorMode
 0487 stub SetEvent
@@ -494,12 +494,12 @@
 0489 stub SetFileApisToOEM
 0490 stub SetFileAttributesA
 0491 stub SetFileAttributesW
-0492 stub SetFilePointer
+0492    stdcall SetFilePointer(long long ptr long) SetFilePointer
 0493 stub SetFileTime
 0494 stub SetHandleCount
 0495 stub SetHandleInformation
 0496 stub SetLastConsoleEventActive
-0497 stub SetLastError
+0497    stdcall SetLastError(long) SetLastError
 0498 stub SetLocalTime
 0499 stub SetLocaleInfoA
 0500 stub SetLocaleInfoW
@@ -550,9 +550,9 @@
 0545 stub VerLanguageNameA
 0546 stub VerLanguageNameW
 0547 stub VerifyConsoleIoHandle
-0548 stub VirtualAlloc
+0548    stdcall VirtualAlloc(ptr long long long) VirtualAlloc
 0549 stub VirtualBufferExceptionHandler
-0550 stub VirtualFree
+0550    stdcall VirtualFree(ptr long long) VirtualFree
 0551 stub VirtualLock
 0552 stub VirtualProtect
 0553 stub VirtualProtectEx
@@ -580,7 +580,7 @@
 0575 stub WriteConsoleOutputCharacterW
 0576 stub WriteConsoleOutputW
 0577 stub WriteConsoleW
-0578 stub WriteFile
+0578    stdcall WriteFile(long ptr long ptr ptr) WriteFile
 0579 stub WriteFileEx
 0580 stub WritePrivateProfileSectionA
 0581 stub WritePrivateProfileSectionW
diff --git a/if1632/mmsystem.spec b/if1632/mmsystem.spec
index d4e0b28..14171d4 100644
--- a/if1632/mmsystem.spec
+++ b/if1632/mmsystem.spec
@@ -31,6 +31,8 @@
 210    pascal  MIDIOUTRESET(word) midiOutReset
 211    pascal  MIDIOUTGETVOLUME(word segptr) midiOutGetVolume
 212    pascal  MIDIOUTSETVOLUME(word long) midiOutSetVolume
+213    pascal  MIDIOUTCACHEPATCHES(word word segptr word) midiOutCachePatches
+214    pascal  MIDIOUTCACHEDRUMPATCHES(word word segptr word) midiOutCacheDrumPatches
 215    pascal  MIDIOUTGETID(word ptr) midiOutGetID
 216    pascal  MIDIOUTMESSAGE(word word long long) midiOutMessage
 301    pascal  MIDIINGETNUMDEVS() midiInGetNumDevs
@@ -86,7 +88,7 @@
 513    pascal  WAVEINGETID(word ptr) waveInGetID
 514    pascal  WAVEINMESSAGE(word word long long) waveInMessage
 601    pascal  timeGetSystemTime(ptr word) timeGetSystemTime
-602    pascal  timeSetEvent(word word ptr long word) timeSetEvent
+602    pascal  timeSetEvent(word word segptr long word) timeSetEvent
 603    pascal  timeKillEvent(word) timeKillEvent
 604    pascal  timeGetDevCaps(ptr word) timeGetDevCaps
 605    pascal  timeBeginPeriod(word) timeBeginPeriod
diff --git a/if1632/relay.c b/if1632/relay.c
index d325ce8..df41747 100644
--- a/if1632/relay.c
+++ b/if1632/relay.c
@@ -31,8 +31,8 @@
     DLL_ENTRY(KERNEL),
     DLL_ENTRY(USER),
     DLL_ENTRY(GDI),
-    DLL_ENTRY(WIN87EM),
-    DLL_ENTRY(SHELL),
+    DLL_ENTRY_NOTUSED(WIN87EM),
+    DLL_ENTRY_NOTUSED(SHELL),
     DLL_ENTRY(SOUND),
     DLL_ENTRY(KEYBOARD),
     DLL_ENTRY(WINSOCK),
@@ -41,7 +41,7 @@
     DLL_ENTRY(SYSTEM),
     DLL_ENTRY(TOOLHELP),
     DLL_ENTRY(MOUSE),
-    DLL_ENTRY(COMMDLG),
+    DLL_ENTRY_NOTUSED(COMMDLG),
     DLL_ENTRY_NOTUSED(OLE2),
     DLL_ENTRY_NOTUSED(OLE2CONV),
     DLL_ENTRY_NOTUSED(OLE2DISP),
diff --git a/if1632/relay32.c b/if1632/relay32.c
index 0d0630d..0d906d4 100644
--- a/if1632/relay32.c
+++ b/if1632/relay32.c
@@ -13,6 +13,7 @@
 #include "windows.h"
 #include "dlls.h"
 #include "pe_image.h"
+#include "relay32.h"
 #include "stddebug.h"
 /* #define DEBUG_RELAY */
 #include "debug.h"
@@ -110,8 +111,7 @@
              int wParam, int lParam )
 {
 	int ret;
-	SpyMessage(hwnd, message, wParam, lParam);
-	__asm__ (
+__asm__ (
 		"push %1;"
 		"push %2;"
 		"push %3;"
diff --git a/if1632/user.spec b/if1632/user.spec
index dd82aee..63b7a9d 100644
--- a/if1632/user.spec
+++ b/if1632/user.spec
@@ -329,7 +329,7 @@
 362 stub DCHook
 364 stub LookupIconIDFromDirectoryEx
 368 pascal16 CopyIcon(word word) CopyIcon
-369 stub CopyCursor
+369 pascal16 CopyCursor(word word) CopyCursor
 370 pascal16 GetWindowPlacement(word ptr) GetWindowPlacement
 371 pascal16 SetWindowPlacement(word ptr) SetWindowPlacement
 372 stub GetInternalIconHeader
@@ -358,7 +358,7 @@
 403 pascal16 UnregisterClass(segptr word) UnregisterClass
 404 pascal16 GetClassInfo(word segptr ptr) GetClassInfo
 406 pascal16 CreateCursor(word word word word word ptr ptr) CreateCursor
-407 pascal16 CreateIcon(word word word byte byte ptr ptr) CreateIcon
+407 pascal16 CreateIcon(word word word word word ptr ptr) CreateIcon
 408 pascal16 CreateCursorIconIndirect(word ptr ptr ptr)
 	     CreateCursorIconIndirect
 409 stub InitThreadInput
@@ -401,7 +401,7 @@
 452 pascal16 CreateWindowEx(long segptr segptr long s_word s_word s_word s_word
                             word word word segptr) CreateWindowEx
 454 pascal16 AdjustWindowRectEx(ptr long word long) AdjustWindowRectEx
-455 stub GetIconId
+455 pascal16 GetIconID(word long) GetIconID
 456 pascal16 LoadIconHandler(word word) LoadIconHandler
 457 pascal16 DestroyIcon(word) DestroyIcon
 458 pascal16 DestroyCursor(word) DestroyCursor
@@ -410,7 +410,7 @@
 461 pascal16 SetInternalWindowPos(word word ptr ptr) SetInternalWindowPos
 462 pascal16 CalcChildScroll(word word) CalcChildScroll
 463 stub ScrollChildren
-464 stub DragObject
+464 pascal16 DragObject(word word word word word word) DragObject
 465 stub DragDetect
 466 pascal16 DrawFocusRect(word ptr) DrawFocusRect
 470 stub StringFunc
diff --git a/if1632/winprocs.spec b/if1632/winprocs.spec
index 27fd50f..b770e4d 100644
--- a/if1632/winprocs.spec
+++ b/if1632/winprocs.spec
@@ -108,7 +108,7 @@
 172 register INT_Int48Handler(word) INT_DummyHandler
 173 register INT_Int49Handler(word) INT_DummyHandler
 174 register INT_Int4aHandler(word) INT_DummyHandler
-175 register INT_Int4bHandler(word) INT_DummyHandler
+175 register INT_Int4bHandler(word) INT_Int4bHandler
 176 register INT_Int4cHandler(word) INT_DummyHandler
 177 register INT_Int4dHandler(word) INT_DummyHandler
 178 register INT_Int4eHandler(word) INT_DummyHandler
@@ -289,3 +289,12 @@
 353 register INT_IntfdHandler(word) INT_DummyHandler
 354 register INT_IntfeHandler(word) INT_DummyHandler
 355 register INT_IntffHandler(word) INT_DummyHandler
+
+# VxDs. The first Vxd is at 400
+#
+#400+VXD_ID register <VxD handler>(word) <VxD handler>
+#
+414 register VXD_Comm(word) VXD_Comm
+#415 register VXD_Printer(word) VXD_Printer
+423 register VXD_Shell(word) VXD_Shell
+433 register VXD_PageFile(word) VXD_PageFile
diff --git a/include/bitmap.h b/include/bitmap.h
index dda2d55..c236cdc 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -45,6 +45,6 @@
 
   /* objects/oembitmap.c */
 extern HBITMAP OBM_LoadBitmap( WORD id );
-extern HICON OBM_LoadIcon( WORD id );
+extern HANDLE OBM_LoadCursorIcon( WORD id, BOOL fCursor );
 
 #endif  /* __WINE_BITMAP_H */
diff --git a/include/bitmaps/ocr_cross b/include/bitmaps/ocr_cross
new file mode 100644
index 0000000..c13793f
--- /dev/null
+++ b/include/bitmaps/ocr_cross
@@ -0,0 +1,37 @@
+/* XPM */
+static char * ocr_cross[] = {
+"32 32 2 1 9 9",
+" 	s None	c None",
+".	s black c black",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"...................             ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"         .                      ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                "};
diff --git a/include/bitmaps/ocr_ibeam b/include/bitmaps/ocr_ibeam
new file mode 100644
index 0000000..e372a1e
--- /dev/null
+++ b/include/bitmaps/ocr_ibeam
@@ -0,0 +1,37 @@
+/* XPM */
+static char * ocr_ibeam[] = {
+"32 32 2 1 3 8",
+" 	s black c black",
+".	s None	c None",
+"   .   .........................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"... ............................",
+"   .   .........................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................"};
diff --git a/include/bitmaps/ocr_icon b/include/bitmaps/ocr_icon
new file mode 100644
index 0000000..351f744
--- /dev/null
+++ b/include/bitmaps/ocr_icon
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_icon[] = {
+"32 32 3 1 8 6",
+" 	s black c black",
+".	s None	c None",
+"X	s white c white",
+"                 ...............",
+"                 ...............",
+"   XXXXXXXXXXX   ...............",
+"   XX       XX   ...............",
+"   XX       XX   ...............",
+"   XX       XX   ...............",
+"   XX       XX   ...............",
+"   XX       XX   ...............",
+"   XX       XX   ...............",
+"   XX       XX   ...............",
+"   XXXXXXXXXXX   ...............",
+"                 ...............",
+"                 ...............",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................"};
diff --git a/include/bitmaps/ocr_normal b/include/bitmaps/ocr_normal
new file mode 100644
index 0000000..47e7409
--- /dev/null
+++ b/include/bitmaps/ocr_normal
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_normal[] = {
+"32 32 3 1 0 0",
+" 	s black c black",
+".	s None	c None",
+"X	s white c white",
+"  ..............................",
+" X .............................",
+" XX ............................",
+" XXX ...........................",
+" XXXX ..........................",
+" XXXXX .........................",
+" XXXXXX ........................",
+" XXXXXXX .......................",
+" XXXXXXXX ......................",
+" XXXXXXXXX .....................",
+" XXXXXX     ....................",
+" XXX XX ........................",
+" XX  XX ........................",
+" X .  XX .......................",
+"  ... XX .......................",
+" ..... XX ......................",
+"...... XX ......................",
+"....... XX .....................",
+"....... XX .....................",
+"........  ......................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................"};
diff --git a/include/bitmaps/ocr_size b/include/bitmaps/ocr_size
new file mode 100644
index 0000000..f33f604
--- /dev/null
+++ b/include/bitmaps/ocr_size
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_size[] = {
+"32 32 3 1 11 11",
+" 	s None	c None",
+".	s black c black",
+"X	s white c white",
+"           ..                   ",
+"          .XX.                  ",
+"         .XXXX.                 ",
+"        .XXXXXX.                ",
+"       .XXXXXXXX.               ",
+"       ....XX....               ",
+"          .XX.                  ",
+"    ..    .XX.    ..            ",
+"   .X.    .XX.    .X.           ",
+"  .XX.    .XX.    .XX.          ",
+" .XXX......XX......XXX.         ",
+".XXXXXXXXXXXXXXXXXXXXXX.        ",
+".XXXXXXXXXXXXXXXXXXXXXX.        ",
+" .XXX......XX......XXX.         ",
+"  .XX.    .XX.    .XX.          ",
+"   .X.    .XX.    .X.           ",
+"    ..    .XX.    ..            ",
+"          .XX.                  ",
+"       ....XX....               ",
+"       .XXXXXXXX.               ",
+"        .XXXXXX.                ",
+"         .XXXX.                 ",
+"          .XX.                  ",
+"           ..                   ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                "};
diff --git a/include/bitmaps/ocr_sizenesw b/include/bitmaps/ocr_sizenesw
new file mode 100644
index 0000000..4159a7f
--- /dev/null
+++ b/include/bitmaps/ocr_sizenesw
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_sizenesw[] = {
+"32 32 3 1 6 6",
+" 	s None	c None",
+".	s black c black",
+"X	s white c white",
+"     .......                    ",
+"     .XXXXXX.                   ",
+"      .XXXXX.                   ",
+"       .XXXX.                   ",
+"      .XXXXX.                   ",
+"..   .XXX.XX.                   ",
+".X. .XXX. .X.                   ",
+".XX.XXX.   ..                   ",
+".XXXXX.                         ",
+".XXXX.                          ",
+".XXXXX.                         ",
+".XXXXXX.                        ",
+" .......                        ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                "};
diff --git a/include/bitmaps/ocr_sizens b/include/bitmaps/ocr_sizens
new file mode 100644
index 0000000..39fc680
--- /dev/null
+++ b/include/bitmaps/ocr_sizens
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_sizens[] = {
+"32 32 3 1 4 7",
+" 	s None	c None",
+".	s black c black",
+"X	s white c white",
+"    ..                          ",
+"   .XX.                         ",
+"  .XXXX.                        ",
+" .XXXXXX.                       ",
+".XXXXXXXX.                      ",
+"....XX....                      ",
+"   .XX.                         ",
+"   .XX.                         ",
+"   .XX.                         ",
+"   .XX.                         ",
+"....XX....                      ",
+".XXXXXXXX.                      ",
+" .XXXXXX.                       ",
+"  .XXXX.                        ",
+"   .XX.                         ",
+"    ..                          ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                "};
diff --git a/include/bitmaps/ocr_sizenwse b/include/bitmaps/ocr_sizenwse
new file mode 100644
index 0000000..6f6491f
--- /dev/null
+++ b/include/bitmaps/ocr_sizenwse
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_sizenwse[] = {
+"32 32 3 1 6 6",
+" 	s None	c None",
+".	s black c black",
+"X	s white c white",
+" .......                        ",
+".XXXXXX.                        ",
+".XXXXX.                         ",
+".XXXX.                          ",
+".XXXXX.                         ",
+".XX.XXX.   ..                   ",
+".X. .XXX. .X.                   ",
+"..   .XXX.XX.                   ",
+"      .XXXXX.                   ",
+"       .XXXX.                   ",
+"      .XXXXX.                   ",
+"     .XXXXXX.                   ",
+"     .......                    ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                "};
diff --git a/include/bitmaps/ocr_sizewe b/include/bitmaps/ocr_sizewe
new file mode 100644
index 0000000..281a9a0
--- /dev/null
+++ b/include/bitmaps/ocr_sizewe
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_sizewe[] = {
+"32 32 3 1 7 4",
+" 	s None	c None",
+".	s black c black",
+"X	s white c white",
+"    ..    ..                    ",
+"   .X.    .X.                   ",
+"  .XX.    .XX.                  ",
+" .XXX......XXX.                 ",
+".XXXXXXXXXXXXXX.                ",
+".XXXXXXXXXXXXXX.                ",
+" .XXX......XXX.                 ",
+"  .XX.    .XX.                  ",
+"   .X.    .X.                   ",
+"    ..    ..                    ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                ",
+"                                "};
diff --git a/include/bitmaps/ocr_up b/include/bitmaps/ocr_up
new file mode 100644
index 0000000..ee5726f
--- /dev/null
+++ b/include/bitmaps/ocr_up
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_up[] = {
+"32 32 3 1 6 0",
+" 	s None	c None",
+".	s black c black",
+"X	s white c white",
+"      ..                        ",
+"      ..                        ",
+"     ....                       ",
+"     ....                       ",
+"    ..XX..                      ",
+"    ..XX..                      ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"  ..XXXXXX..                    ",
+"  ..XXXXXX..                    ",
+" ..XXXXXXXX..                   ",
+" ..XXXXXXXX..                   ",
+"..XXXXXXXXXX..                  ",
+"..XXXXXXXXXX..                  ",
+".....XXXX.....                  ",
+".....XXXX.....                  ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ..XXXX..                     ",
+"   ........                     ",
+"   ........                     ",
+"                                ",
+"                                ",
+"                                ",
+"                                "};
diff --git a/include/bitmaps/ocr_wait b/include/bitmaps/ocr_wait
new file mode 100644
index 0000000..4c9d73d
--- /dev/null
+++ b/include/bitmaps/ocr_wait
@@ -0,0 +1,38 @@
+/* XPM */
+static char * ocr_wait[] = {
+"32 32 3 1 7 13",
+" 	s black c black",
+".	s None	c None",
+"X	s white c white",
+"               .................",
+"               .................",
+"  XXXXXXXXXXX  .................",
+".             ..................",
+".  XXXXXXXXX  ..................",
+".  XXXXXXXXX  ..................",
+".  XXXXXX XX  ..................",
+".  X X X X X  ..................",
+".  XX X X XX  ..................",
+"..  XX X XX  ...................",
+"...  XX XX  ....................",
+"....  XXX  .....................",
+".....  X  ......................",
+".....  X  ......................",
+".....  X  ......................",
+"....  XXX  .....................",
+"...  XXXXX  ....................",
+"..  XXX XXX  ...................",
+".  XXXXXXXXX  ..................",
+".  XXXX XXXX  ..................",
+".  XXX X XXX  ..................",
+".  XX X X XX  ..................",
+".  X X X X X  ..................",
+".             ..................",
+"  XXXXXXXXXXX  .................",
+"               .................",
+"               .................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................"};
diff --git a/include/button.h b/include/button.h
index b9b0565..28fdd82 100644
--- a/include/button.h
+++ b/include/button.h
@@ -28,6 +28,7 @@
 
 #define BUTTON_STATE(hwnd)     ((WIN_FindWndPtr(hwnd))->wExtra[0])
 
-extern LONG ButtonWndProc( HWND hWnd, WORD uMsg, WORD wParam, LONG lParam );
+extern LRESULT ButtonWndProc( HWND hWnd, UINT uMsg,
+                              WPARAM wParam, LPARAM lParam );
 
 #endif  /* BUTTON_H */
diff --git a/include/callback.h b/include/callback.h
index b1a0e58..1e5649c 100644
--- a/include/callback.h
+++ b/include/callback.h
@@ -12,8 +12,6 @@
 
 #include "stackframe.h"
 
-#ifndef WINELIB
-
 extern int CallTo32_LargeStack( int (*func)(), int nbargs, ... );
 
 
@@ -22,6 +20,9 @@
 
                                /* func     ds    parameters */
 extern WORD CallTo16_word_     ( FARPROC, WORD );
+
+#ifndef WINELIB
+
 extern WORD CallTo16_word_ww   ( FARPROC, WORD, WORD, WORD );
 extern WORD CallTo16_word_wl   ( FARPROC, WORD, WORD, LONG );
 extern WORD CallTo16_word_ll   ( FARPROC, WORD, LONG, LONG );
diff --git a/include/class.h b/include/class.h
index 8e27cd3..90c3a3c 100644
--- a/include/class.h
+++ b/include/class.h
@@ -32,7 +32,7 @@
 #endif
 
 
-HCLASS CLASS_FindClassByName( SEGPTR name, WORD hinstance, CLASS **ptr );
+HCLASS CLASS_FindClassByName( SEGPTR name, HINSTANCE hinstance, CLASS **ptr );
 CLASS * CLASS_FindClassPtr( HCLASS hclass );
 
 
diff --git a/include/combo.h b/include/combo.h
index cf301f0..d89bd6e 100644
--- a/include/combo.h
+++ b/include/combo.h
@@ -15,3 +15,6 @@
   RECT  RectButton;
   BOOL  bRedrawFlag;
 } HEADCOMBO,*LPHEADCOMBO;
+
+LRESULT ComboBoxWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+LRESULT ComboLBoxWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
diff --git a/include/commdlg.h b/include/commdlg.h
index 2161a6c..dcc96b9 100644
--- a/include/commdlg.h
+++ b/include/commdlg.h
@@ -290,7 +290,13 @@
 #define FINDDLG		       		9
 #define REPLACEDLG	       		10
 
-
+LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
+LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
+LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
+LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
+LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
+LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
+LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
 
 #endif 		/* #ifdef COMMDLG_H */
 
diff --git a/include/cursor.h b/include/cursor.h
deleted file mode 100644
index 85c5c8c..0000000
--- a/include/cursor.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * structure definitions for CURSOR
- *
- * Copyright  Martin Ayotte, 1993
- *
- */
-#ifndef __WINE_CURSOR_H
-#define __WINE_CURSOR_H
-
-
-typedef struct {
-        POINT           pntHotSpot;     /* cursor hot spot */
-        WORD            nWidth;         /* width of bitmap in pixels */
-        WORD            nHeight;
-        WORD            nWidthBytes;
-        BYTE            byPlanes;       /* number of bit planes */
-        BYTE            byBitsPix;      /* bits per pixel */
-        } CURSORICONINFO, FAR *LPCURSORICONINFO;
-
-typedef struct  {
-	WORD	cdReserved;
-	WORD	cdType;
-	WORD	cdCount;
-        } CURSORDIR;
- 
-typedef struct {
-	WORD	Width;
-	WORD	Height;
-	WORD	Planes;
-	WORD	BitCount;
-	DWORD	curDIBSize;
-	WORD	curDIBOffset;
-	} CURSORDESCRIP;
-
-typedef struct  {
-	Cursor	xcursor;
-	} CURSORALLOC;
-
-extern void CURSOR_SetWinCursor( HWND hwnd, HCURSOR hcursor );   /* cursor.c */
-
-#endif /* __WINE_CURSOR_H */
diff --git a/include/cursoricon.h b/include/cursoricon.h
new file mode 100644
index 0000000..214ddbf
--- /dev/null
+++ b/include/cursoricon.h
@@ -0,0 +1,59 @@
+/*
+ * Cursor and icon definitions
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+
+#ifndef __WINE_CURSORICON_H
+#define __WINE_CURSORICON_H
+
+#include <X11/Xlib.h>
+#include "windows.h"
+
+#ifndef WINELIB
+#pragma pack(1)
+#endif
+
+typedef struct
+{
+    BYTE   bWidth;
+    BYTE   bHeight;
+    BYTE   bColorCount;
+    BYTE   bReserved;
+    WORD   wPlanes;
+    WORD   wBitCount;
+    DWORD  dwBytesInRes;
+    WORD   wResId;
+} ICONDIRENTRY;
+
+typedef struct
+{
+    WORD   wWidth;
+    WORD   wHeight;
+    WORD   wPlanes;
+    WORD   wBitCount;
+    DWORD  dwBytesInRes;
+    WORD   wResId;
+} CURSORDIRENTRY;
+
+typedef union
+{
+    ICONDIRENTRY    icon;
+    CURSORDIRENTRY  cursor;
+} CURSORICONDIRENTRY;
+
+typedef struct
+{
+    WORD                idReserved;
+    WORD                idType;
+    WORD                idCount;
+    CURSORICONDIRENTRY  idEntries[1] WINE_PACKED;
+} CURSORICONDIR;
+
+#ifndef WINELIB
+#pragma pack(4)
+#endif
+
+extern Cursor CURSORICON_XCursor;  /* Current X cursor */
+
+#endif /* __WINE_CURSORICON_H */
diff --git a/include/debug.h b/include/debug.h
index 8d74615..a67f722 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -78,10 +78,8 @@
 #undef DEBUG_RESOURCE
 #undef DEBUG_SCROLL
 #undef DEBUG_SELECTOR
-#undef DEBUG_SELECTORS
 #undef DEBUG_SEM
 #undef DEBUG_SHM
-#undef DEBUG_SPY
 #undef DEBUG_STRESS
 #undef DEBUG_SYSCOLOR
 #undef DEBUG_TASK
@@ -89,6 +87,7 @@
 #undef DEBUG_TIMER
 #undef DEBUG_TOOLHELP
 #undef DEBUG_UTILITY
+#undef DEBUG_VXD
 #undef DEBUG_WIN
 #undef DEBUG_WINSOCK
 #endif
@@ -156,10 +155,8 @@
 #define DEBUG_RESOURCE
 #define DEBUG_SCROLL
 #define DEBUG_SELECTOR
-#define DEBUG_SELECTORS
 #define DEBUG_SEM
 #define DEBUG_SHM
-#define DEBUG_SPY
 #define DEBUG_STRESS
 #define DEBUG_SYSCOLOR
 #define DEBUG_TASK
@@ -167,6 +164,7 @@
 #define DEBUG_TIMER
 #define DEBUG_TOOLHELP
 #define DEBUG_UTILITY
+#define DEBUG_VXD
 #define DEBUG_WIN
 #define DEBUG_WINSOCK
 #endif
@@ -484,11 +482,6 @@
 #else
     0,
 #endif
-#ifdef DEBUG_SELECTORS
-    1,
-#else
-    0,
-#endif
 #ifdef DEBUG_SEM
     1,
 #else
@@ -499,11 +492,6 @@
 #else
     0,
 #endif
-#ifdef DEBUG_SPY
-    1,
-#else
-    0,
-#endif
 #ifdef DEBUG_STRESS
     1,
 #else
@@ -539,6 +527,11 @@
 #else
     0,
 #endif
+#ifdef DEBUG_VXD
+    1,
+#else
+    0,
+#endif
 #ifdef DEBUG_WIN
     1,
 #else
@@ -1363,21 +1356,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_selectors if(!debug_msg_enabled[62]) ; else fprintf
-#define debugging_selectors debug_msg_enabled[62]
-#else
-#ifdef DEBUG_SELECTORS
-#define dprintf_selectors fprintf
-#define debugging_selectors 1
-#else
-#define dprintf_selectors while(0) fprintf
-#define debugging_selectors 0
-#endif
-#endif
-
-#ifdef DEBUG_RUNTIME
-#define dprintf_sem if(!debug_msg_enabled[63]) ; else fprintf
-#define debugging_sem debug_msg_enabled[63]
+#define dprintf_sem if(!debug_msg_enabled[62]) ; else fprintf
+#define debugging_sem debug_msg_enabled[62]
 #else
 #ifdef DEBUG_SEM
 #define dprintf_sem fprintf
@@ -1389,8 +1369,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_shm if(!debug_msg_enabled[64]) ; else fprintf
-#define debugging_shm debug_msg_enabled[64]
+#define dprintf_shm if(!debug_msg_enabled[63]) ; else fprintf
+#define debugging_shm debug_msg_enabled[63]
 #else
 #ifdef DEBUG_SHM
 #define dprintf_shm fprintf
@@ -1402,21 +1382,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_spy if(!debug_msg_enabled[65]) ; else fprintf
-#define debugging_spy debug_msg_enabled[65]
-#else
-#ifdef DEBUG_SPY
-#define dprintf_spy fprintf
-#define debugging_spy 1
-#else
-#define dprintf_spy while(0) fprintf
-#define debugging_spy 0
-#endif
-#endif
-
-#ifdef DEBUG_RUNTIME
-#define dprintf_stress if(!debug_msg_enabled[66]) ; else fprintf
-#define debugging_stress debug_msg_enabled[66]
+#define dprintf_stress if(!debug_msg_enabled[64]) ; else fprintf
+#define debugging_stress debug_msg_enabled[64]
 #else
 #ifdef DEBUG_STRESS
 #define dprintf_stress fprintf
@@ -1428,8 +1395,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_syscolor if(!debug_msg_enabled[67]) ; else fprintf
-#define debugging_syscolor debug_msg_enabled[67]
+#define dprintf_syscolor if(!debug_msg_enabled[65]) ; else fprintf
+#define debugging_syscolor debug_msg_enabled[65]
 #else
 #ifdef DEBUG_SYSCOLOR
 #define dprintf_syscolor fprintf
@@ -1441,8 +1408,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_task if(!debug_msg_enabled[68]) ; else fprintf
-#define debugging_task debug_msg_enabled[68]
+#define dprintf_task if(!debug_msg_enabled[66]) ; else fprintf
+#define debugging_task debug_msg_enabled[66]
 #else
 #ifdef DEBUG_TASK
 #define dprintf_task fprintf
@@ -1454,8 +1421,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_text if(!debug_msg_enabled[69]) ; else fprintf
-#define debugging_text debug_msg_enabled[69]
+#define dprintf_text if(!debug_msg_enabled[67]) ; else fprintf
+#define debugging_text debug_msg_enabled[67]
 #else
 #ifdef DEBUG_TEXT
 #define dprintf_text fprintf
@@ -1467,8 +1434,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_timer if(!debug_msg_enabled[70]) ; else fprintf
-#define debugging_timer debug_msg_enabled[70]
+#define dprintf_timer if(!debug_msg_enabled[68]) ; else fprintf
+#define debugging_timer debug_msg_enabled[68]
 #else
 #ifdef DEBUG_TIMER
 #define dprintf_timer fprintf
@@ -1480,8 +1447,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_toolhelp if(!debug_msg_enabled[71]) ; else fprintf
-#define debugging_toolhelp debug_msg_enabled[71]
+#define dprintf_toolhelp if(!debug_msg_enabled[69]) ; else fprintf
+#define debugging_toolhelp debug_msg_enabled[69]
 #else
 #ifdef DEBUG_TOOLHELP
 #define dprintf_toolhelp fprintf
@@ -1493,8 +1460,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_utility if(!debug_msg_enabled[72]) ; else fprintf
-#define debugging_utility debug_msg_enabled[72]
+#define dprintf_utility if(!debug_msg_enabled[70]) ; else fprintf
+#define debugging_utility debug_msg_enabled[70]
 #else
 #ifdef DEBUG_UTILITY
 #define dprintf_utility fprintf
@@ -1506,8 +1473,21 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win if(!debug_msg_enabled[73]) ; else fprintf
-#define debugging_win debug_msg_enabled[73]
+#define dprintf_vxd if(!debug_msg_enabled[71]) ; else fprintf
+#define debugging_vxd debug_msg_enabled[71]
+#else
+#ifdef DEBUG_VXD
+#define dprintf_vxd fprintf
+#define debugging_vxd 1
+#else
+#define dprintf_vxd while(0) fprintf
+#define debugging_vxd 0
+#endif
+#endif
+
+#ifdef DEBUG_RUNTIME
+#define dprintf_win if(!debug_msg_enabled[72]) ; else fprintf
+#define debugging_win debug_msg_enabled[72]
 #else
 #ifdef DEBUG_WIN
 #define dprintf_win fprintf
@@ -1519,8 +1499,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_winsock if(!debug_msg_enabled[74]) ; else fprintf
-#define debugging_winsock debug_msg_enabled[74]
+#define dprintf_winsock if(!debug_msg_enabled[73]) ; else fprintf
+#define debugging_winsock debug_msg_enabled[73]
 #else
 #ifdef DEBUG_WINSOCK
 #define dprintf_winsock fprintf
@@ -1597,10 +1577,8 @@
     "resource",
     "scroll",
     "selector",
-    "selectors",
     "sem",
     "shm",
-    "spy",
     "stress",
     "syscolor",
     "task",
@@ -1608,6 +1586,7 @@
     "timer",
     "toolhelp",
     "utility",
+    "vxd",
     "win",
     "winsock",
     ""
diff --git a/include/debugger.h b/include/debugger.h
index 3311825..9190ff1 100644
--- a/include/debugger.h
+++ b/include/debugger.h
@@ -26,6 +26,18 @@
     ((addr)->seg ? (char *)PTR_SEG_OFF_TO_LIN((addr)->seg,(addr)->off) \
                  : (char *)(addr)->off)
 
+#define DBG_CHECK_READ_PTR(addr,len) \
+    (!DEBUG_IsBadReadPtr((addr),(len)) || \
+     (fprintf(stderr,"*** Invalid address "), \
+      DEBUG_PrintAddress((addr),dbg_mode), \
+      fprintf(stderr,"\n"),0))
+
+#define DBG_CHECK_WRITE_PTR(addr,len) \
+    (!DEBUG_IsBadWritePtr((addr),(len)) || \
+     (fprintf(stderr,"*** Invalid address "), \
+      DEBUG_PrintAddress(addr,dbg_mode), \
+      fprintf(stderr,"\n"),0))
+
 enum debug_regs
 {
     REG_EAX, REG_EBX, REG_ECX, REG_EDX, REG_ESI,
@@ -76,6 +88,8 @@
 extern void DEBUG_Help(void);
 
   /* debugger/memory.c */
+extern BOOL DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size );
+extern BOOL DEBUG_IsBadWritePtr( const DBG_ADDR *address, int size );
 extern int DEBUG_ReadMemory( const DBG_ADDR *address );
 extern void DEBUG_WriteMemory( const DBG_ADDR *address, int value );
 extern void DEBUG_ExamineMemory( const DBG_ADDR *addr, int count, char format);
diff --git a/include/desktop.h b/include/desktop.h
index 024dfb4..ba9876c 100644
--- a/include/desktop.h
+++ b/include/desktop.h
@@ -20,4 +20,6 @@
 extern BOOL DESKTOP_Init();
 extern BOOL DESKTOP_SetPattern(char *pattern );
 
+extern LRESULT DesktopWndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
+
 #endif  /* DESKTOP_H */
diff --git a/include/dialog.h b/include/dialog.h
index aca9adc..772074e 100644
--- a/include/dialog.h
+++ b/include/dialog.h
@@ -12,9 +12,7 @@
 extern BOOL DIALOG_Init(void);
 extern HWND DIALOG_GetFirstTabItem( HWND hwndDlg );
 
-#ifndef WINELIB
 #pragma pack(1)
-#endif
 
   /* Dialog info structure.
    * This structure is stored into the window extra bytes (cbWndExtra).
@@ -70,8 +68,6 @@
     SEGPTR             faceName;
 } DLGTEMPLATE;
 
-#ifndef WINELIB
 #pragma pack(4)
-#endif
 
 #endif  /* DIALOG_H */
diff --git a/include/dos_fs.h b/include/dos_fs.h
index a6a91a3..1200dfd 100644
--- a/include/dos_fs.h
+++ b/include/dos_fs.h
@@ -22,7 +22,7 @@
 extern char *DOS_GetVolumeLabel(int drive);
 extern int DOS_SetVolumeLabel(int drive, char *label);
 extern int DOS_GetFreeSpace(int drive, long *size, long *available);
-extern char *DOS_FindFile(char *buffer, int buflen, char *rootname, char **extensions, char *path);
+extern char *DOS_FindFile(char *buffer, int buflen, const char *rootname, char **extensions, char *path);
 extern char *WineIniFileName(void);
 extern char *WinIniFileName(void); 
 extern struct dosdirent *DOS_opendir(char *dosdirname); 
@@ -30,6 +30,7 @@
 extern void DOS_closedir(struct dosdirent *de);
 extern char *DOS_GetRedirectedDir(int drive);
 extern void errno_to_doserr(void);
+extern int DOS_Error(int extended, int class, int locus);
 
 extern char WindowsPath[256];
 
diff --git a/include/event.h b/include/event.h
index 0d1689f..4019f1d 100644
--- a/include/event.h
+++ b/include/event.h
@@ -3,5 +3,6 @@
 
 extern void EVENT_ProcessEvent( XEvent *event );  /* event.c */
 extern void EVENT_RegisterWindow( Window w, HWND hwnd );  /* event.c */
+extern void EVENT_DummyMotionNotify(void);  /* event.c */
 
 #endif /* __WINE_EVENT_H */
diff --git a/include/gdi.h b/include/gdi.h
index 04a2185..a8f1899 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -197,37 +197,42 @@
 #define DC_SAVED      2   /* It is a saved DC */
 
   /* Last 32 bytes are reserved for stock object handles */
+#ifdef WINELIB32
+/* Stupid overloading (see DefWindowProc, case WM_ERASEBKGND) */
+#define GDI_HEAP_SIZE               (COLOR_BTNHIGHLIGHT+1)
+#else
 #define GDI_HEAP_SIZE               0xffe0  
+#endif
 
   /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
 #define FIRST_STOCK_HANDLE          GDI_HEAP_SIZE
 
   /* Stock objects handles */
 
-#define STOCK_WHITE_BRUSH	    (FIRST_STOCK_HANDLE + WHITE_BRUSH)
-#define STOCK_LTGRAY_BRUSH	    (FIRST_STOCK_HANDLE + LTGRAY_BRUSH)
-#define STOCK_GRAY_BRUSH	    (FIRST_STOCK_HANDLE + GRAY_BRUSH)
-#define STOCK_DKGRAY_BRUSH	    (FIRST_STOCK_HANDLE + DKGRAY_BRUSH)
-#define STOCK_BLACK_BRUSH	    (FIRST_STOCK_HANDLE + BLACK_BRUSH)
-#define STOCK_NULL_BRUSH	    (FIRST_STOCK_HANDLE + NULL_BRUSH)
-#define STOCK_HOLLOW_BRUSH	    (FIRST_STOCK_HANDLE + HOLLOW_BRUSH)
-#define STOCK_WHITE_PEN	            (FIRST_STOCK_HANDLE + WHITE_PEN)
-#define STOCK_BLACK_PEN	            (FIRST_STOCK_HANDLE + BLACK_PEN)
-#define STOCK_NULL_PEN	            (FIRST_STOCK_HANDLE + NULL_PEN)
-#define STOCK_OEM_FIXED_FONT	    (FIRST_STOCK_HANDLE + OEM_FIXED_FONT)
-#define STOCK_ANSI_FIXED_FONT       (FIRST_STOCK_HANDLE + ANSI_FIXED_FONT)
-#define STOCK_ANSI_VAR_FONT	    (FIRST_STOCK_HANDLE + ANSI_VAR_FONT)
-#define STOCK_SYSTEM_FONT	    (FIRST_STOCK_HANDLE + SYSTEM_FONT)
-#define STOCK_DEVICE_DEFAULT_FONT   (FIRST_STOCK_HANDLE + DEVICE_DEFAULT_FONT)
-#define STOCK_DEFAULT_PALETTE       (FIRST_STOCK_HANDLE + DEFAULT_PALETTE)
-#define STOCK_SYSTEM_FIXED_FONT     (FIRST_STOCK_HANDLE + SYSTEM_FIXED_FONT)
+#define NB_STOCK_OBJECTS          (SYSTEM_FIXED_FONT + 1)
 
-#define NB_STOCK_OBJECTS            (SYSTEM_FIXED_FONT + 1)
+#define STOCK_WHITE_BRUSH         ((HBRUSH)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
+#define STOCK_LTGRAY_BRUSH        ((HBRUSH)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
+#define STOCK_GRAY_BRUSH          ((HBRUSH)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
+#define STOCK_DKGRAY_BRUSH        ((HBRUSH)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
+#define STOCK_BLACK_BRUSH         ((HBRUSH)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
+#define STOCK_NULL_BRUSH          ((HBRUSH)(FIRST_STOCK_HANDLE+NULL_BRUSH))
+#define STOCK_HOLLOW_BRUSH        ((HBRUSH)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
+#define STOCK_WHITE_PEN	          ((HPEN)(FIRST_STOCK_HANDLE+WHITE_PEN))
+#define STOCK_BLACK_PEN	          ((HPEN)(FIRST_STOCK_HANDLE+BLACK_PEN))
+#define STOCK_NULL_PEN	          ((HPEN)(FIRST_STOCK_HANDLE+NULL_PEN))
+#define STOCK_OEM_FIXED_FONT      ((HFONT)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
+#define STOCK_ANSI_FIXED_FONT     ((HFONT)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
+#define STOCK_ANSI_VAR_FONT       ((HFONT)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
+#define STOCK_SYSTEM_FONT         ((HFONT)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
+#define STOCK_DEVICE_DEFAULT_FONT ((HFONT)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
+#define STOCK_DEFAULT_PALETTE     ((HPALETTE)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
+#define STOCK_SYSTEM_FIXED_FONT   ((HFONT)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
 
-#define FIRST_STOCK_FONT            STOCK_OEM_FIXED_FONT
-#define LAST_STOCK_FONT             STOCK_SYSTEM_FIXED_FONT
+#define FIRST_STOCK_FONT          STOCK_OEM_FIXED_FONT
+#define LAST_STOCK_FONT           STOCK_SYSTEM_FIXED_FONT
 
-
+#define LAST_STOCK_HANDLE         ((DWORD)STOCK_SYSTEM_FIXED_FONT)
 
   /* Device <-> logical coords conversion */
 
diff --git a/include/icon.h b/include/icon.h
deleted file mode 100644
index 4a38a60..0000000
--- a/include/icon.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * structure definitions for ICON
- *
- * Copyright  Martin Ayotte, 1993
- *
- */
-
-
-typedef struct {
-	BYTE	Width;
-	BYTE	Height;
-	BYTE	ColorCount;
-	BYTE	Reserved1;
-	WORD	Reserved2;
-	WORD	Reserved3;
-	DWORD	icoDIBSize;
-	DWORD	icoDIBOffset;
-	} ICONDESCRIP;
-
-typedef struct {
-	ICONDESCRIP	descriptor;
-	HBITMAP		hBitmap;
-	HBITMAP		hBitMask;
-	} ICONALLOC;
-
-
diff --git a/include/kernel32.h b/include/kernel32.h
new file mode 100644
index 0000000..5fb595f
--- /dev/null
+++ b/include/kernel32.h
@@ -0,0 +1,80 @@
+/* kernel32.h - 95-09-14  Cameron Heide
+ *
+ * Win32 functions, structures, and types related to kernel functions
+ */
+#include <stddef.h>
+
+int KERN32_Init(void);
+void SetLastError(DWORD error);
+DWORD ErrnoToLastError(int errno_num);
+
+/* Linux's wchar_t is unsigned long but Win32 wants unsigned short
+ */
+typedef unsigned short WCHAR;
+
+/* Code page information.
+ */
+typedef struct {
+        DWORD MaxCharSize;
+        BYTE DefaultChar[2];
+        BYTE LeadBytes[5];
+} CPINFO, *LPCPINFO;
+
+/* The 'overlapped' data structure used by async I/O functions.
+ */
+typedef struct {
+        DWORD Internal;
+        DWORD InternalHigh;
+        DWORD Offset;
+        DWORD OffsetHigh;
+        HANDLE hEvent;
+} OVERLAPPED, *LPOVERLAPPED;
+
+/* Process startup information.
+ */
+typedef struct {
+        DWORD cb;
+        LPSTR lpReserved;
+        LPSTR lpDesktop;
+        LPSTR lpTitle;
+        DWORD dwX;
+        DWORD dwY;
+        DWORD dwXSize;
+        DWORD dwYSize;
+        DWORD dwXCountChars;
+        DWORD dwYCountChars;
+        DWORD dwFillAttribute;
+        DWORD dwFlags;
+        WORD wShowWindow;
+        WORD cbReserved2;
+        BYTE *lpReserved2;
+        HANDLE hStdInput;
+        HANDLE hStdOutput;
+        HANDLE hStdError;
+} STARTUPINFO, *LPSTARTUPINFO;
+
+typedef struct {
+        WORD wYear;
+        WORD wMonth;
+        WORD wDayOfWeek;
+        WORD wDay;
+        WORD wHour;
+        WORD wMinute;
+        WORD wSecond;
+        WORD wMilliseconds;
+} SYSTEMTIME, *LPSYSTEMTIME;
+
+typedef struct {
+        LONG Bias;
+        WCHAR StandardName[32];
+        SYSTEMTIME StandardDate;
+        LONG StandardBias;
+        WCHAR DaylightName[32];
+        SYSTEMTIME DaylightDate;
+        LONG DaylightBias;
+} TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
+
+#define TIME_ZONE_ID_UNKNOWN    0
+#define TIME_ZONE_ID_STANDARD   1
+#define TIME_ZONE_ID_DAYLIGHT   2
+
diff --git a/include/ldt.h b/include/ldt.h
index 76f9ca0..b02b2cd 100644
--- a/include/ldt.h
+++ b/include/ldt.h
@@ -30,7 +30,7 @@
 extern void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content);
 extern int LDT_GetEntry( int entry, ldt_entry *content );
 extern int LDT_SetEntry( int entry, const ldt_entry *content );
-extern void LDT_Print();
+extern void LDT_Print( int start, int length );
 
 
   /* This structure is used to build the local copy of the LDT. */
@@ -73,7 +73,7 @@
            ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
 #else
 #define PTR_SEG_TO_LIN(ptr)	((void*)(ptr))
-#define PTR_SEG_OFF_TO_LIN(seg,off)	((void*)(off))
+#define PTR_SEG_OFF_TO_LIN(seg,off)	((void*)((char*)(seg)+(int)(off)))
 #endif
 
 
diff --git a/include/listbox.h b/include/listbox.h
index 491ed20..405a110 100644
--- a/include/listbox.h
+++ b/include/listbox.h
@@ -67,3 +67,5 @@
 			     WORD itemState);
 extern int ListBoxFindMouse(LPHEADLIST lphl, int X, int Y);
 extern void ListBoxAskMeasure(LPHEADLIST lphl, LPLISTSTRUCT lpls);
+
+extern LRESULT ListBoxWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
diff --git a/include/local.h b/include/local.h
index de58d4f..93b4cbe 100644
--- a/include/local.h
+++ b/include/local.h
@@ -13,14 +13,14 @@
   /* excepted that they need DS as the first parameter. This    */
   /* allows managing several heaps from the emulation library.  */
 
-extern HLOCAL LOCAL_Alloc( WORD ds, WORD flags, WORD size );
-extern HLOCAL LOCAL_ReAlloc( WORD ds, HLOCAL handle, WORD size, WORD flags );
-extern HLOCAL LOCAL_Free( WORD ds, HLOCAL handle );
-extern HLOCAL LOCAL_Handle( WORD ds, WORD addr );
-extern WORD LOCAL_Size( WORD ds, HLOCAL handle );
-extern WORD LOCAL_Flags( WORD ds, HLOCAL handle );
-extern WORD LOCAL_HeapSize( WORD ds );
-extern WORD LOCAL_Lock( WORD ds, HLOCAL handle );
-extern BOOL LOCAL_Unlock( WORD ds, HLOCAL handle );
+extern HLOCAL LOCAL_Alloc( HANDLE ds, WORD flags, WORD size );
+extern HLOCAL LOCAL_ReAlloc( HANDLE ds, HLOCAL handle, WORD size, WORD flags );
+extern HLOCAL LOCAL_Free( HANDLE ds, HLOCAL handle );
+extern HLOCAL LOCAL_Handle( HANDLE ds, WORD addr );
+extern WORD LOCAL_Size( HANDLE ds, HLOCAL handle );
+extern WORD LOCAL_Flags( HANDLE ds, HLOCAL handle );
+extern WORD LOCAL_HeapSize( HANDLE ds );
+extern NPVOID LOCAL_Lock( HANDLE ds, HLOCAL handle );
+extern BOOL LOCAL_Unlock( HANDLE ds, HLOCAL handle );
 
 #endif  /* __WINE_LOCAL_H */
diff --git a/include/mdi.h b/include/mdi.h
index 6891c3d..d2d1434 100644
--- a/include/mdi.h
+++ b/include/mdi.h
@@ -11,8 +11,8 @@
 #include "windows.h"
 
 #define MDI_MAXLISTLENGTH	64
-extern LONG MDIClientWndProc(HWND hwnd, WORD message, 
-			     WORD wParam, LONG lParam); /* mdi.c */
+extern LRESULT MDIClientWndProc(HWND hwnd, UINT message, 
+				WPARAM wParam, LPARAM lParam); /* mdi.c */
 
 
 typedef struct
diff --git a/include/menu.h b/include/menu.h
index d471eec..d2fae7c 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -17,6 +17,7 @@
 			      HWND hwnd, BOOL suppress_draw );   /* menu.c */
 extern HMENU CopySysMenu(); /* menu.c */
 
+extern LRESULT PopupMenuWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam );
 
 typedef struct tagMENUITEM
 {
diff --git a/include/message.h b/include/message.h
index c8a1429..10832ef 100644
--- a/include/message.h
+++ b/include/message.h
@@ -20,7 +20,7 @@
 typedef struct tagMESSAGEQUEUE
 {
   WORD      next;
-  WORD      hTask;                  /* hTask owning the queue                */
+  HTASK     hTask;                  /* hTask owning the queue                */
   WORD      msgSize;                /* Size of messages in the queue         */
   WORD      msgCount;               /* Number of waiting messages            */
   WORD      nextMessage;            /* Next message to be retrieved          */
@@ -29,10 +29,10 @@
   DWORD     GetMessageTimeVal;      /* Value returned by GetMessageTime      */
   DWORD     GetMessagePosVal;       /* Value returned by GetMessagePos       */
   DWORD     GetMessageExtraInfoVal; /* Value returned by GetMessageExtraInfo */
-  DWORD     lParam;                 /* Next four values set by SendMessage   */
-  WORD      wParam;
-  WORD      msg;
-  WORD      hWnd;
+  LPARAM    lParam;                 /* Next four values set by SendMessage   */
+  WPARAM    wParam;
+  UINT      msg;
+  HWND      hWnd;
   WORD      wPostQMsg;              /* PostQuitMessage flag                  */
   WORD      wExitCode;              /* PostQuitMessage exit code             */
   WORD      InSendMessageHandle;    /* Handle of task that sent a message    */
diff --git a/include/miscemu.h b/include/miscemu.h
index bf2b007..99186e7 100644
--- a/include/miscemu.h
+++ b/include/miscemu.h
@@ -10,7 +10,6 @@
 #include "wintypes.h"
 #include "registers.h"
 
-
   /* miscemu/dosmem.c */
 extern BOOL DOSMEM_Init(void);
 extern void DOSMEM_FillBiosSegment(void);
diff --git a/include/module.h b/include/module.h
index 5ca5a59..5ab729f 100644
--- a/include/module.h
+++ b/include/module.h
@@ -19,7 +19,7 @@
     WORD    magic;            /* 'NE' signature */
     WORD    count;            /* Usage count */
     WORD    entry_table;      /* Near ptr to entry table */
-    WORD    next;             /* Selector to next module */
+    HMODULE next;             /* Selector to next module */
     WORD    dgroup_entry;     /* Near ptr to segment entry for DGROUP */
     WORD    fileinfo;         /* Near ptr to file info (LOADEDFILEINFO) */
     WORD    flags;            /* Module flags */
@@ -69,7 +69,7 @@
     WORD    size;      /* Segment size on disk */
     WORD    flags;     /* Segment flags */
     WORD    minsize;   /* Min. size of segment in memory */
-    WORD    selector;  /* Selector of segment in memory */
+    HANDLE  selector;  /* Selector of segment in memory */
 } SEGTABLEENTRY;
 
   /* Self-loading modules contain this structure in their first segment */
diff --git a/include/msdos.h b/include/msdos.h
index 2922d13..6861971 100644
--- a/include/msdos.h
+++ b/include/msdos.h
@@ -39,6 +39,7 @@
 #define MAX_DOS_DRIVES	26
 
 extern WORD ExtendedError;
+extern BYTE ErrorClass, Action, ErrorLocus;
 extern struct DosDeviceStruct COM[MAX_PORTS];
 extern struct DosDeviceStruct LPT[MAX_PORTS];
 
diff --git a/include/neexe.h b/include/neexe.h
index c24f2f6..e8c460c 100644
--- a/include/neexe.h
+++ b/include/neexe.h
@@ -68,6 +68,7 @@
  */
 #define NE_FFLAGS_SINGLEDATA	0x0001
 #define NE_FFLAGS_MULTIPLEDATA	0x0002
+#define NE_FFLAGS_BUILTIN       0x0010  /* Wine built-in module */
 #define NE_FFLAGS_SELFLOAD	0x0800
 #define NE_FFLAGS_LINKERROR	0x2000
 #define NE_FFLAGS_LIBMODULE	0x8000
@@ -196,7 +197,7 @@
     unsigned short length;
     unsigned short flags;
     unsigned short id;
-    unsigned short handle;
+            HANDLE handle;
     unsigned short usage;
 };
 
diff --git a/include/nonclient.h b/include/nonclient.h
index 0a34d90..d2ca8ab 100644
--- a/include/nonclient.h
+++ b/include/nonclient.h
@@ -14,12 +14,12 @@
                               POINT *minTrack, POINT *maxTrack );
 extern void NC_DoNCPaint( HWND hwnd, BOOL active, BOOL suppress_menupaint );
 extern LONG NC_HandleNCPaint( HWND hwnd );
-extern LONG NC_HandleNCActivate( HWND hwnd, WORD wParam );
+extern LONG NC_HandleNCActivate( HWND hwnd, WPARAM wParam );
 extern LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params );
 extern LONG NC_HandleNCHitTest( HWND hwnd, POINT pt );
-extern LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam );
-extern LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam );
-extern LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt );
-extern LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam );
+extern LONG NC_HandleNCLButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam );
+extern LONG NC_HandleNCLButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam );
+extern LONG NC_HandleSysCommand( HWND hwnd, WPARAM wParam, POINT pt );
+extern LONG NC_HandleSetCursor( HWND hwnd, WPARAM wParam, LPARAM lParam );
 
 #endif /* __WINE_NONCLIENT_H */
diff --git a/include/pe_image.h b/include/pe_image.h
index cdadb66..a65c756 100644
--- a/include/pe_image.h
+++ b/include/pe_image.h
@@ -19,8 +19,8 @@
     char * filename; /* Actual name of the unix file that satisfies this */
     int type;        /* DLL or EXE */
     int fd;
-    unsigned short hinstance;
-    HANDLE hModule;
+    HINSTANCE hinstance;
+    HMODULE hModule;
     int initialised;
     struct mz_header_s *mz_header;
     struct pe_data *pe;
diff --git a/include/registers.h b/include/registers.h
index 7e2e4e4..777522d 100644
--- a/include/registers.h
+++ b/include/registers.h
@@ -40,13 +40,11 @@
 #define ES_reg(context)      ((context)->sc_es)
 #define SS_reg(context)      ((context)->sc_ss)
                             
-#ifdef linux                
+#ifdef linux
+/* fs and gs are not supported on *BSD. Hopefully we won't need them. */
 #define FS_reg(context)      ((context)->sc_fs)
 #define GS_reg(context)      ((context)->sc_gs)
-#else  /* FIXME: are fs and gs supported under *BSD? */
-#define FS_reg(context)      0
-#define GS_reg(context)      0
-#endif                      
+#endif
                             
 #ifndef __FreeBSD__         
 #define EFL_reg(context)     ((context)->sc_eflags)
diff --git a/include/relay32.h b/include/relay32.h
index 7ebf688..2736089 100644
--- a/include/relay32.h
+++ b/include/relay32.h
@@ -4,8 +4,10 @@
  * Copyright 1995 Martin von Loewis
  */
 
+void RELAY32_Unimplemented(char *dll, int item);
 void *RELAY32_GetEntryPoint(char *dll_name, char *item, int hint);
 LONG RELAY32_CallWindowProc(WNDPROC,int,int,int,int);
+void RELAY32_DebugEnter(char *dll,char *name);
 
 typedef struct tagWNDCLASSA{
 	UINT	style;
diff --git a/include/resource.h b/include/resource.h
index 6a5eeb2..d389ce4 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -17,9 +17,6 @@
 extern HGLOBAL NE_AllocResource( HMODULE hModule, HRSRC hRsrc, DWORD size );
 extern HGLOBAL NE_LoadResource( HMODULE hModule,  HRSRC hRsrc );
 
-extern HBITMAP ConvertCoreBitmap( HDC hdc, BITMAPCOREHEADER * image );
-extern HBITMAP ConvertInfoBitmap( HDC hdc, BITMAPINFO * image );
-
 struct ResourceTable
 {
         int id,type;
diff --git a/include/shell.h b/include/shell.h
index b222e7e..5a546ec 100644
--- a/include/shell.h
+++ b/include/shell.h
@@ -18,7 +18,11 @@
 
 #define HKEY_CLASSES_ROOT       1
 
+#ifdef WINELIB32
+typedef void* HKEY;
+#else
 typedef DWORD HKEY;
+#endif
 typedef HKEY FAR* LPHKEY;
 
 typedef struct tagKEYSTRUCT {
@@ -32,6 +36,13 @@
 	} KEYSTRUCT;
 typedef KEYSTRUCT *LPKEYSTRUCT;
 
+typedef struct tagDROPFILESTRUCT { 	   /* structure for dropped files */ 
+	WORD		wSize;
+	POINT		ptMousePos;   
+	BOOL		fInNonClientArea;
+	/* memory block with filenames follows */     
+        } DROPFILESTRUCT,FAR *LPDROPFILESTRUCT; 
+
 #define SE_ERR_SHARE            26
 #define SE_ERR_ASSOCINCOMPLETE  27
 #define SE_ERR_DDETIMEOUT       28
@@ -39,4 +50,5 @@
 #define SE_ERR_DDEBUSY          30
 #define SE_ERR_NOASSOC          31
 
+LRESULT AboutDlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
 
diff --git a/include/spy.h b/include/spy.h
new file mode 100644
index 0000000..7fa75fb
--- /dev/null
+++ b/include/spy.h
@@ -0,0 +1,19 @@
+/*
+ * 			     Message Logging functions
+ */
+
+#ifndef __WINE_SPY_H
+#define __WINE_SPY_H
+
+#define SPY_DISPATCHMESSAGE     0x0099
+#define SPY_SENDMESSAGE         0x0100
+#define SPY_DEFWNDPROC          0x0101
+
+#define SPY_RESULT_OK           0x0000
+#define SPY_RESULT_INVALIDHWND  0x0001
+
+extern void EnterSpyMessage( int, HWND, WORD, WORD, LONG);
+extern void  ExitSpyMessage( int, HWND, WORD, LONG);
+extern void         SpyInit( void);
+
+#endif /* __WINE_SPY_H */
diff --git a/include/stackframe.h b/include/stackframe.h
index 81fcf8e..cf4358b 100644
--- a/include/stackframe.h
+++ b/include/stackframe.h
@@ -72,7 +72,7 @@
 #else
 #define CURRENT_STACK16	error.error
 #define CURRENT_DS		0
-#define MAKE_SEGPTR(ptr)	(ptr)
+#define MAKE_SEGPTR(ptr)	((SEGPTR)ptr)
 #endif
 
 #endif /* WINE_STACKFRAME_H */
diff --git a/include/static.h b/include/static.h
index 8dcd000..dfe7148 100644
--- a/include/static.h
+++ b/include/static.h
@@ -17,6 +17,6 @@
     HICON  hIcon;   /* Icon handle for SS_ICON controls */ 
 } STATICINFO;
 
-extern LONG StaticWndProc( HWND hWnd, WORD uMsg, WORD wParam, LONG lParam );
+extern LRESULT StaticWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam );
 
 #endif  /* STATIC_H */
diff --git a/include/stddebug.h b/include/stddebug.h
index b262020..0b5a5c4 100644
--- a/include/stddebug.h
+++ b/include/stddebug.h
@@ -138,10 +138,8 @@
 #undef DEBUG_RESOURCE
 #undef DEBUG_SCROLL
 #undef DEBUG_SELECTOR
-#undef DEBUG_SELECTORS
 #undef DEBUG_SEM
 #undef DEBUG_SHM
-#undef DEBUG_SPY
 #undef DEBUG_STRESS
 #undef DEBUG_SYSCOLOR
 #undef DEBUG_TASK
@@ -149,6 +147,7 @@
 #undef DEBUG_TIMER
 #undef DEBUG_TOOLHELP
 #undef DEBUG_UTILITY
+#undef DEBUG_VXD
 #undef DEBUG_WIN
 #undef DEBUG_WINSOCK
 #endif
@@ -216,10 +215,8 @@
 #define DEBUG_RESOURCE
 #define DEBUG_SCROLL
 #define DEBUG_SELECTOR
-#define DEBUG_SELECTORS
 #define DEBUG_SEM
 #define DEBUG_SHM
-#define DEBUG_SPY
 #define DEBUG_STRESS
 #define DEBUG_SYSCOLOR
 #define DEBUG_TASK
@@ -227,6 +224,7 @@
 #define DEBUG_TIMER
 #define DEBUG_TOOLHELP
 #define DEBUG_UTILITY
+#define DEBUG_VXD
 #define DEBUG_WIN
 #define DEBUG_WINSOCK
 #endif
diff --git a/include/task.h b/include/task.h
index dd7e9e8..fd5604d 100644
--- a/include/task.h
+++ b/include/task.h
@@ -61,7 +61,7 @@
     char    priority;                   /* Task priority, between -32 and 15 */
     BYTE    unused1;
     HGLOBAL hStack32;                   /* Handle to 32-bit stack */
-    WORD    hSelf;                      /* Selector of this TDB */
+    HTASK   hSelf;                      /* Selector of this TDB */
     HANDLE  hPrevInstance;              /* Previous instance of the module */
     DWORD   esp;                        /* 32-bit stack pointer */
     WORD    ctrlword8087;               /* 80x87 control word */
diff --git a/include/toolhelp.h b/include/toolhelp.h
index ba1a05a..5ffb1b4 100644
--- a/include/toolhelp.h
+++ b/include/toolhelp.h
@@ -166,14 +166,14 @@
     HMODULE hModule;
     WORD wcUsage;
     char szExePath[MAX_PATH + 1];
-    WORD wNext;
+    HANDLE wNext;
 } MODULEENTRY;
 typedef MODULEENTRY *LPMODULEENTRY;
 
 BOOL	ModuleFirst(MODULEENTRY *lpModule);
 BOOL	ModuleNext(MODULEENTRY *lpModule);
-HMODULE ModuleFindName(MODULEENTRY *lpModule, LPCSTR lpstrName);
-HMODULE ModuleFindHandle(MODULEENTRY *lpModule, HMODULE hModule);
+BOOL    ModuleFindName(MODULEENTRY *lpModule, LPCSTR lpstrName);
+BOOL    ModuleFindHandle(MODULEENTRY *lpModule, HMODULE hModule);
 
 /* tasks */
 
@@ -240,7 +240,7 @@
     DWORD     dwSize;
     HMODULE   hInst;              /* This is really an hModule */
     char      szClassName[MAX_CLASSNAME + 1];
-    WORD      wNext;
+    HANDLE    wNext;
 } CLASSENTRY;
 
 BOOL ClassFirst( CLASSENTRY *pClassEntry );
diff --git a/include/win.h b/include/win.h
index 6b614aa..f40937d 100644
--- a/include/win.h
+++ b/include/win.h
@@ -78,9 +78,11 @@
 extern BOOL WIN_UnlinkWindow( HWND hwnd );
 extern BOOL WIN_LinkWindow( HWND hwnd, HWND hwndInsertAfter );
 extern HWND WIN_FindWinToRepaint( HWND hwnd );
-extern void WIN_SendParentNotify( HWND hwnd, WORD event, LONG lParam );
+extern void WIN_SendParentNotify( HWND hwnd, WORD event,
+                                  WORD idChild, LONG lValue );
 extern BOOL WIN_CreateDesktopWindow(void);
 extern HWND WIN_GetTopParent( HWND hwnd );
+extern HINSTANCE WIN_GetWindowInstance( HWND hwnd );
 
 extern Display * display;
 extern Screen * screen;
diff --git a/include/windows.h b/include/windows.h
index 7f65748..e151ebf 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -25,6 +25,11 @@
 
 #define MAKEPOINT(l) (*((POINT *)&(l)))
 
+#ifdef WINELIB32
+#define MAKEWPARAM(low, high) ((LONG)(((WORD)(low)) | \
+			      (((DWORD)((WORD)(high))) << 16)))
+#endif
+
 #define MAKELPARAM(low, high) ((LONG)(((WORD)(low)) | \
 			      (((DWORD)((WORD)(high))) << 16)))
 
@@ -89,7 +94,7 @@
   /* Windows */
 
 typedef struct {
-    void *    lpCreateParams;
+    LPVOID    lpCreateParams;
     HINSTANCE hInstance;
     HMENU     hMenu;
     HWND      hwndParent;
@@ -542,7 +547,11 @@
 { 
     WORD       lbStyle; 
     COLORREF   lbColor WINE_PACKED;
+#ifdef WINELIB32
+    LONG       lbHatch; 
+#else
     INT      lbHatch; 
+#endif
 } LOGBRUSH, *PLOGBRUSH, *NPLOGBRUSH, *LPLOGBRUSH;
 
   /* Brush styles */
@@ -990,7 +999,7 @@
 typedef BITMAPINFO *NPBITMAPINFO;
 typedef BITMAPINFO *PBITMAPINFO;
 
-typedef struct tagBITMAPCOREHEADER
+typedef struct
 {
     unsigned long bcSize;
     UINT bcWidth;
@@ -999,10 +1008,31 @@
     UINT bcBitCount;
 } BITMAPCOREHEADER;
 
+typedef struct
+{
+    BITMAPCOREHEADER bmciHeader;
+    RGBTRIPLE        bmciColors[1];
+} BITMAPCOREINFO, *LPBITMAPCOREINFO;
+
 #define DIB_RGB_COLORS   0
 #define DIB_PAL_COLORS   1
 #define CBM_INIT         4
 
+
+  /* Cursors / Icons */
+
+typedef struct
+{
+    POINT   ptHotSpot;
+    WORD    nWidth;
+    WORD    nHeight;
+    WORD    nWidthBytes;
+    BYTE    bPlanes;
+    BYTE    bBitsPerPixel;
+} CURSORICONINFO;
+
+
+
 typedef struct {
 	BYTE i;  /* much more .... */
 } KANJISTRUCT;
@@ -1284,12 +1314,12 @@
 #define IDC_WAIT         MAKEINTRESOURCE(32514)
 #define IDC_CROSS        MAKEINTRESOURCE(32515)
 #define IDC_UPARROW      MAKEINTRESOURCE(32516)
-#define IDC_SIZE         MAKEINTRESOURCE(32540)
-#define IDC_ICON         MAKEINTRESOURCE(32541)
-#define IDC_SIZENWSE     MAKEINTRESOURCE(32542)
-#define IDC_SIZENESW     MAKEINTRESOURCE(32543)
-#define IDC_SIZEWE       MAKEINTRESOURCE(32544)
-#define IDC_SIZENS       MAKEINTRESOURCE(32545)
+#define IDC_SIZE         MAKEINTRESOURCE(32640)
+#define IDC_ICON         MAKEINTRESOURCE(32641)
+#define IDC_SIZENWSE     MAKEINTRESOURCE(32642)
+#define IDC_SIZENESW     MAKEINTRESOURCE(32643)
+#define IDC_SIZEWE       MAKEINTRESOURCE(32644)
+#define IDC_SIZENS       MAKEINTRESOURCE(32645)
 
 /* OEM Resource Ordinal Numbers */
 #define OBM_CLOSE           32754
@@ -1378,11 +1408,11 @@
 #define SYSTEM_FIXED_FONT   16
 
 
-enum { WM_NULL, WM_CREATE, WM_DESTROY, WM_MOVE, WM_UNUSED0, WM_SIZE, WM_ACTIVATE,
-	WM_SETFOCUS, WM_KILLFOCUS, WM_UNUSED1, WM_ENABLE, WM_SETREDRAW, 
+enum {  WM_NULL, WM_CREATE, WM_DESTROY, WM_MOVE, WM_UNUSED0, WM_SIZE, WM_ACTIVATE,
+	WM_SETFOCUS, WM_KILLFOCUS, WM_SETVISIBLE, WM_ENABLE, WM_SETREDRAW, 
 	WM_SETTEXT, WM_GETTEXT, WM_GETTEXTLENGTH, WM_PAINT, WM_CLOSE, 
 	WM_QUERYENDSESSION, WM_QUIT, WM_QUERYOPEN, WM_ERASEBKGND, 
-	WM_SYSCOLORCHANGE, WM_ENDSESSION, WM_UNUSED2,
+	WM_SYSCOLORCHANGE, WM_ENDSESSION, WM_SYSTEMERROR,
 	WM_SHOWWINDOW, WM_CTLCOLOR, WM_WININICHANGE, WM_DEVMODECHANGE,
 	WM_ACTIVATEAPP, WM_FONTCHANGE, WM_TIMECHANGE, WM_CANCELMODE, WM_SETCURSOR,
 	WM_MOUSEACTIVATE, WM_CHILDACTIVATE, WM_QUEUESYNC, WM_GETMINMAXINFO,
@@ -1391,8 +1421,16 @@
 	WM_DELETEITEM, WM_VKEYTOITEM,
 	WM_CHARTOITEM, WM_SETFONT, WM_GETFONT };
 
+#define WM_QUERYDRAGICON    0x0037
+
+#define WM_COMPAREITEM	    0x0039
+
+#define WM_COMPACTING	    0x0041
+
+#define WM_COMMNOTIFY	    0x0044
 #define WM_WINDOWPOSCHANGING 0x0046
-#define WM_WINDOWPOSCHANGED 0x0047
+#define WM_WINDOWPOSCHANGED  0x0047
+#define WM_POWER	    0x0048
 
 #define WM_NCCREATE         0x0081
 #define WM_NCDESTROY        0x0082
@@ -1402,6 +1440,7 @@
 #define WM_NCACTIVATE       0x0086
 
 #define WM_GETDLGCODE	    0x0087
+#define WM_SYNCPAINT	    0x0088
 
   /* Non-client mouse messages */
 #define WM_NCMOUSEMOVE      0x00a0
@@ -1437,8 +1476,25 @@
 #define WM_HSCROLL          0x0114
 #define WM_VSCROLL          0x0115
 
+/* Menu messages */
+#define WM_INITMENU         0x0116
+#define WM_INITMENUPOPUP    0x0117
+
+#define WM_MENUSELECT       0x011F
+#define WM_MENUCHAR         0x0120
 #define WM_ENTERIDLE        0x0121
 
+#define WM_LBTRACKPOINT     0x0131
+
+  /* Win32 CTLCOLOR messages */
+#define WM_CTLCOLORMSGBOX    0x0132
+#define WM_CTLCOLOREDIT      0x0133
+#define WM_CTLCOLORLISTBOX   0x0134
+#define WM_CTLCOLORBTN       0x0135
+#define WM_CTLCOLORDLG       0x0136
+#define WM_CTLCOLORSCROLLBAR 0x0137
+#define WM_CTLCOLORSTATIC    0x0138
+
   /* Mouse messages */
 #define WM_MOUSEMOVE	    0x0200
 #define WM_LBUTTONDOWN	    0x0201
@@ -1467,15 +1523,44 @@
 #define WM_MDICASCADE	    0x0227
 #define WM_MDIICONARRANGE   0x0228
 #define WM_MDIGETACTIVE     0x0229
+#define WM_DROPOBJECT	    0x022A
+#define WM_QUERYDROPOBJECT  0x022B
+#define WM_DRAGLOOP	    0x022D
+#define WM_DRAGSELECT	    0x022E
+#define WM_DRAGMOVE	    0x022F
 #define WM_MDISETMENU	    0x0230
 
 #define WM_ENTERSIZEMOVE    0x0231
 #define WM_EXITSIZEMOVE     0x0232
+#define WM_DROPFILES	    0x0233
+
+#define WM_CUT               0x0300
+#define WM_COPY              0x0301
+#define WM_PASTE             0x0302
+#define WM_CLEAR             0x0303
+#define WM_UNDO              0x0304
+#define WM_RENDERFORMAT      0x0305
+#define WM_RENDERALLFORMATS  0x0306
+#define WM_DESTROYCLIPBOARD  0x0307
+#define WM_DRAWCLIPBOARD     0x0308
+#define WM_PAINTCLIPBOARD    0x0309
+#define WM_VSCROLLCLIPBOARD  0x030A
+#define WM_SIZECLIPBOARD     0x030B
+#define WM_ASKCBFORMATNAME   0x030C
+#define WM_CHANGECBCHAIN     0x030D
+#define WM_HSCROLLCLIPBOARD  0x030E
+#define WM_QUERYNEWPALETTE   0x030F
+#define WM_PALETTEISCHANGING 0x0310
+#define WM_PALETTECHANGED    0x0311
+
+#define WM_COALESCE_FIRST    0x0390
+#define WM_COALESCE_LAST     0x039F
 
   /* misc messages */
 #define WM_NULL             0x0000
 #define WM_USER             0x0400
-
+#define WM_CPL_LAUNCH       (WM_USER + 1000)
+#define WM_CPL_LAUNCHED     (WM_USER + 1001)
 
   /* Key status flags for mouse events */
 #define MK_LBUTTON	    0x0001
@@ -1560,13 +1645,6 @@
 #define TPM_CENTERALIGN 0x0004
 #define TPM_RIGHTALIGN  0x0008
 
-/* Menu messages */
-#define WM_INITMENU         0x0116
-#define WM_INITMENUPOPUP    0x0117
-
-#define WM_MENUSELECT       0x011F
-#define WM_MENUCHAR         0x0120
-
 #define MF_INSERT 0
 #define MF_CHANGE 0x0080
 #define MF_APPEND 0x0100
@@ -2372,694 +2450,677 @@
 #pragma pack(4)
 #endif
 
-
-#define F(ret,name) ret name(void);
-#define Fa(ret,name,t1,a1) ret name(t1);
-#define Fb(ret,name,t1,a1,t2,a2) ret name(t1,t2);
-#define Fc(ret,name,t1,a1,t2,a2,t3,a3) ret name(t1,t2,t3);
-#define Fd(ret,name,t1,a1,t2,a2,t3,a3,t4,a4) ret name(t1,t2,t3,t4);
-#define Fe(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5) ret name(t1,t2,t3,t4,t5);
-#define Ff(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6) ret name(t1,t2,t3,t4,t5,t6);
-#define Fg(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7) ret name(t1,t2,t3,t4,t5,t6,t7);
-#define Fh(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7,t8,a8) ret name(t1,t2,t3,t4,t5,t6,t7,t8);
-#define Fi(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7,t8,a8,t9,a9) ret name(t1,t2,t3,t4,t5,t6,t7,t8,t9);
-#define Fj(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7,t8,a8,t9,a9,t10,a10) ret name(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10);
-#define Fk(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7,t8,a8,t9,a9,t10,a10,t11,a11) ret name(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11);
-#define Fl(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7,t8,a8,t9,a9,t10,a10,t11,a11,t12,a12) ret name(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12);
-#define Fm(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7,t8,a8,t9,a9,t10,a10,t11,a11,t12,a12,t13,a13) ret name(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13);
-#define Fn(ret,name,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7,t8,a8,t9,a9,t10,a10,t11,a11,t12,a12,t13,a13,t14,a14) ret name(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14);
-
-int wsprintf(LPSTR a,LPSTR b,...);
-
-/* Implemented functions */
-
-F(BOOL,AnyPopup)
-F(BOOL,CloseClipboard)
-F(BOOL,EmptyClipboard)
-F(BOOL,GetInputState)
-F(BOOL,InSendMessage)
-F(BOOL,SetDeskPattern)
-F(DWORD,GetCurrentTime)
-F(DWORD,GetDialogBaseUnits)
-F(DWORD,GetMenuCheckMarkDimensions)
-F(DWORD,GetMessagePos)
-F(DWORD,GetTickCount)
-F(HANDLE,GetCurrentTask)
-F(HMENU,CreateMenu)
-F(HMENU,CreatePopupMenu)
-F(HWND,GetActiveWindow)
-F(HWND,GetCapture)
-F(HWND,GetClipboardOwner)
-F(HWND,GetClipboardViewer)
-F(HWND,GetDesktopHwnd)
-F(HWND,GetDesktopWindow)
-F(HWND,GetFocus)
-F(HWND,GetOpenClipboardWindow)
-F(HWND,GetSysModalWindow)
-F(LONG,GetMessageExtraInfo)
-F(LONG,GetMessageTime)
-F(LONG,GetVersion)
-F(LONG,GetWinFlags)
-F(LPINT,GetThresholdEvent)
-F(LPSTR,ValidateFreeSpaces)
-F(SEGPTR,GetDOSEnvironment)
-F(WORD,GetCaretBlinkTime)
-F(WORD,GetCurrentPDB)
-F(WORD,GetDoubleClickTime)
-F(WORD,GetNumTasks)
-F(WORD,GetTaskDS)
-F(int,CountClipboardFormats)
-F(int,GetKBCodePage)
-F(int,GetThresholdStatus)
-F(int,OpenSound)
-F(int,ProfInsChk)
-F(int,StartSound)
-F(int,StopSound)
-F(int,SyncAllVoices)
-F(void,CloseSound)
-F(void,DebugBreak)
-F(void,DestroyCaret)
-F(void,ProfClear)
-F(void,ProfFinish)
-F(void,ProfFlush)
-F(void,ProfStart)
-F(void,ProfStop)
-F(void,ReleaseCapture)
-F(void,SwitchStackBack)
-F(void,ValidateCodeSegments)
-F(void,WaitMessage)
-F(void,Yield)
-Fa(ATOM,AddAtom,SEGPTR,a)
-Fa(ATOM,DeleteAtom,ATOM,a)
-Fa(ATOM,FindAtom,SEGPTR,a)
-Fa(ATOM,GlobalAddAtom,SEGPTR,a)
-Fa(ATOM,GlobalDeleteAtom,ATOM,a)
-Fa(ATOM,GlobalFindAtom,SEGPTR,a)
-Fa(ATOM,RegisterClass,LPWNDCLASS,a) 
-Fa(BOOL,BringWindowToTop,HWND,a)
-Fa(BOOL,DeleteDC,HDC,a)
-Fa(BOOL,DeleteMetaFile,HMETAFILE,a)
-Fa(BOOL,DeleteObject,HANDLE,a)
-Fa(BOOL,DestroyCursor,HCURSOR,a)
-Fa(BOOL,DestroyIcon,HICON,a)
-Fa(BOOL,DestroyMenu,HMENU,a)
-Fa(BOOL,DestroyWindow,HWND,a)
-Fa(BOOL,EnableHardwareInput,BOOL,a)
-Fa(BOOL,EndDeferWindowPos,HDWP,hWinPosInfo)
-Fa(BOOL,FreeModule,HANDLE,a)
-Fa(BOOL,FreeResource,HANDLE,a)
-Fa(BOOL,GlobalUnWire,HGLOBAL,a)
-Fa(BOOL,GlobalUnlock,HGLOBAL,a)
-Fa(BOOL,IsBadCodePtr,SEGPTR,a)
-Fa(BOOL,IsCharAlpha,char,ch)
-Fa(BOOL,IsCharAlphaNumeric,char,ch)
-Fa(BOOL,IsCharLower,char,ch)
-Fa(BOOL,IsCharUpper,char,ch)
-Fa(BOOL,IsClipboardFormatAvailable,WORD,a)
-Fa(BOOL,IsIconic,HWND,a)
-Fa(BOOL,IsRectEmpty,LPRECT,a)
-Fa(BOOL,IsTwoByteCharPrefix,char,a)
-Fa(BOOL,IsWindow,HWND,a)
-Fa(BOOL,IsWindowEnabled,HWND,a)
-Fa(BOOL,IsWindowVisible,HWND,a)
-Fa(BOOL,IsZoomed,HWND,a)
-Fa(BOOL,LocalUnlock,HANDLE,a)
-Fa(BOOL,OpenClipboard,HWND,a)
-Fa(BOOL,OpenIcon,HWND,a)
-Fa(BOOL,RemoveFontResource,LPSTR,a)
-Fa(BOOL,SetDeskWallPaper,LPSTR,a)
-Fa(BOOL,SetErrorMode,WORD,a)
-Fa(BOOL,SetMessageQueue,int,a)
-Fa(BOOL,SetWinDebugInfo,LPWINDEBUGINFO,a)
-Fa(BOOL,SwapMouseButton,BOOL,a)
-Fa(BOOL,TranslateMessage,LPMSG,a)
-Fa(BOOL,UnhookWindowsHookEx,HHOOK,a)
-Fa(BOOL,UnrealizeObject,HBRUSH,a)
-Fa(BYTE,GetTempDrive,BYTE,a)
-Fa(COLORREF,GetBkColor,HDC,a)
-Fa(COLORREF,GetSysColor,short,a)
-Fa(COLORREF,GetTextColor,HDC,a)
-Fa(DWORD,GetAspectRatioFilter,HDC,a)
-Fa(DWORD,GetBitmapDimension,HBITMAP,a)
-Fa(DWORD,GetBrushOrg,HDC,a)
-Fa(DWORD,GetCurrentPosition,HDC,a)
-Fa(DWORD,GetDCOrg,HDC,a)
-Fa(DWORD,GetFreeSpace,WORD,a)
-Fa(DWORD,GetHeapSpaces,HMODULE,a)
-Fa(DWORD,GetSelectorBase,WORD,a)
-Fa(DWORD,GetSelectorLimit,WORD,a)
-Fa(DWORD,GetViewportExt,HDC,a)
-Fa(DWORD,GetViewportOrg,HDC,a)
-Fa(DWORD,GetWindowExt,HDC,a)
-Fa(DWORD,GetWindowOrg,HDC,a)
-Fa(DWORD,GlobalCompact,DWORD,a)
-Fa(DWORD,GlobalDOSAlloc,DWORD,a)
-Fa(DWORD,GlobalHandle,WORD,a)
-Fa(DWORD,GlobalSize,HGLOBAL,a)
-Fa(DWORD,OemKeyScan,WORD,a)
-Fa(FARPROC,LocalNotify,FARPROC,a)
-Fa(HANDLE,CreateMetaFile,LPSTR,a)
-Fa(HANDLE,GetAtomHandle,ATOM,a)
-Fa(HANDLE,GetClipboardData,WORD,a)
-Fa(HANDLE,GetCodeHandle,FARPROC,a)
-Fa(HANDLE,GetMetaFile,LPSTR,a)
-Fa(HANDLE,GetMetaFileBits,HANDLE,a)
-Fa(HANDLE,GetModuleHandle,LPCSTR,a)
-Fa(HANDLE,GetStockObject,int,a)
-Fa(HANDLE,GetWindowTask,HWND,a)
-Fa(HANDLE,LoadLibrary,LPCSTR,a)
-Fa(HANDLE,LocalFree,HANDLE,a)
-Fa(HANDLE,LocalHandle,WORD,a)
-Fa(HANDLE,SetMetaFileBits,HANDLE,a)
-Fa(HBITMAP,CreateBitmapIndirect,BITMAP FAR*,a)
-Fa(HBRUSH,CreateBrushIndirect,LOGBRUSH FAR*,a)
-Fa(HBRUSH,CreatePatternBrush,HBITMAP,a)
-Fa(HBRUSH,CreateSolidBrush,DWORD,a)
-Fa(HCURSOR,SetCursor,HCURSOR,a)
-Fa(HDC,CreateCompatibleDC,HDC,a)
-Fa(HDC,GetDC,HWND,a)
-Fa(HDC,GetDCState,HDC,a)
-Fa(HDC,GetWindowDC,HWND,a)
-Fa(HDWP,BeginDeferWindowPos,INT,nNumWindows)
-Fa(HFONT,CreateFontIndirect,LOGFONT FAR*,a)
-Fa(HGLOBAL,GetTaskQueue,HTASK,a)
-Fa(HGLOBAL,GlobalFree,HGLOBAL,a)
-Fa(HGLOBAL,GlobalLRUNewest,HGLOBAL,a)
-Fa(HGLOBAL,GlobalLRUOldest,HGLOBAL,a)
-Fa(HGLOBAL,LockSegment,HGLOBAL,a)
-Fa(HMENU,GetMenu,HWND,a)
-Fa(HMENU,LoadMenuIndirect,LPSTR,a)
-Fa(HMETAFILE,CloseMetaFile,HANDLE,a)
-Fa(HMODULE, GetExePtr,HANDLE,a)
-Fa(HPALETTE,CreatePalette,LPLOGPALETTE,a)
-Fa(HPEN,CreatePenIndirect,LOGPEN FAR*,a)
-Fa(HRGN,CreateEllipticRgnIndirect,LPRECT,a)
-Fa(HRGN,CreateRectRgnIndirect,LPRECT,a)
-Fa(HRGN,GetClipRgn,HDC,a)
-Fa(HRGN,InquireVisRgn,HDC,a)
-Fa(HRGN,SaveVisRgn,HDC,a)
-Fa(HWND,GetLastActivePopup,HWND,a)
-Fa(HWND,GetParent,HWND,a)
-Fa(HWND,GetTopWindow,HWND,a)
-Fa(HWND,SetActiveWindow,HWND,a)
-Fa(HWND,SetCapture,HWND,a)
-Fa(HWND,SetClipboardViewer,HWND,a)
-Fa(HWND,SetFocus,HWND,a)
-Fa(HWND,SetSysModalWindow,HWND,a)
-Fa(HWND,WindowFromPoint,POINT,a)
-Fa(INT,_lclose,INT,a)
-Fa(INT,lstrlen,LPCSTR,a)
-Fa(LONG,DispatchMessage,LPMSG,msg)
-Fa(LONG,SetSwapAreaSize,WORD,a)
-Fa(LPSTR,AnsiLower,LPSTR,a)
-Fa(LPSTR,AnsiUpper,LPSTR,a)
-Fa(LPSTR,GlobalLock,HGLOBAL,a)
-Fa(LPSTR,LockResource,HANDLE,a)
-Fa(SEGPTR,AnsiNext,SEGPTR,a)
-Fa(SEGPTR,GlobalWire,HGLOBAL,a)
-Fa(SEGPTR,WIN16_GlobalLock,HGLOBAL,a)
-Fa(SEGPTR,WIN16_LockResource,HANDLE,a)
-Fa(UINT,GDIRealizePalette,HDC,a)
-Fa(UINT,RealizePalette,HDC,a)
-Fa(WORD,AllocCStoDSAlias,WORD,a)
-Fa(WORD,AllocDStoCSAlias,WORD,a)
-Fa(WORD,AllocSelector,WORD,a)
-Fa(WORD,AllocSelectorArray,WORD,a)
-Fa(WORD,ArrangeIconicWindows,HWND,a)
-Fa(WORD,EnumClipboardFormats,WORD,a)
-Fa(WORD,FarGetOwner,HANDLE,a)
-Fa(WORD,FreeSelector,WORD,a)
-Fa(WORD,GetBkMode,HDC,a)
-Fa(WORD,GetDriveType,INT,a)
-Fa(WORD,GetMapMode,HDC,a)
-Fa(WORD,GetMenuItemCount,HMENU,a)
-Fa(WORD,GetPolyFillMode,HDC,a)
-Fa(WORD,GetROP2,HDC,a)
-Fa(WORD,GetRelAbs,HDC,a)
-Fa(WORD,GetStretchBltMode,HDC,a)
-Fa(WORD,GetSystemPaletteUse,HDC,a)
-Fa(WORD,GetTextAlign,HDC,a)
-Fa(WORD,GlobalDOSFree,WORD,a)
-Fa(WORD,GlobalFlags,HGLOBAL,a)
-Fa(WORD,GlobalPageLock,HGLOBAL,a)
-Fa(WORD,GlobalPageUnlock,HGLOBAL,a)
-Fa(WORD,InitAtomTable,WORD,a)
-Fa(WORD,LocalCompact,WORD,a)
-Fa(WORD,LocalFlags,HLOCAL,a)
-Fa(WORD,LocalLock,HLOCAL,a)
-Fa(WORD,LocalSize,HLOCAL,a)
-Fa(WORD,RealizeDefaultPalette,HDC,a)
-Fa(WORD,RegisterClipboardFormat,LPCSTR,a)
-Fa(WORD,RegisterWindowMessage,SEGPTR,a)
-Fa(WORD,SetHandleCount,WORD,a)
-Fa(WORD,VkKeyScan,WORD,a)
-Fa(int,AddFontResource,LPSTR,a)
-Fa(int,Catch,LPCATCHBUF,a)
-Fa(int,ClearCommBreak,int,a)
-Fa(int,CloseComm,int,a)
-Fa(int,CountVoiceNotes,int,a)
-Fa(int,GetAsyncKeyState,int,a)
-Fa(int,GetDlgCtrlID,HWND,a)
-Fa(int,GetKeyState,int,a)
-Fa(int,GetKeyboardType,int,a)
-Fa(int,GetModuleUsage,HANDLE,a)
-Fa(int,GetSystemMetrics,WORD,a)
-Fa(int,GetWindowTextLength,HWND,a)
-Fa(int,RestoreVisRgn,HDC,a)
-Fa(int,SaveDC,HDC,a)
-Fa(int,SetCommBreak,int,a)
-Fa(int,SetCommState,DCB*,a)
-Fa(int,ShowCursor,BOOL,a)
-Fa(int,UpdateColors,HDC,a)
-Fa(int,WaitSoundState,int,a)
-Fa(short,GetTextCharacterExtra,HDC,a)
-Fa(void,ClipCursor,LPRECT,a)
-Fa(void,CloseWindow,HWND,a)
-Fa(void,DrawMenuBar,HWND,a)
-Fa(void,FatalExit,int,a)
-Fa(void,FreeLibrary,HANDLE,a)
-Fa(void,FreeProcInstance,FARPROC,a)
-Fa(void,GetCaretPos,LPPOINT,a)
-Fa(void,GetCursorPos,LPPOINT,a)
-Fa(void,GetKeyboardState,BYTE FAR*,a)
-Fa(void,GlobalFix,HGLOBAL,a)
-Fa(void,GlobalFreeAll,HANDLE,a)
-Fa(void,GlobalNotify,FARPROC,a)
-Fa(void,GlobalUnfix,HGLOBAL,a)
-Fa(void,HideCaret,HWND,a)
-Fa(void,LimitEmsPages,DWORD,a)
-Fa(void,MessageBeep,WORD,a)
-Fa(void,OutputDebugString,LPSTR,a)
-Fa(void,PostQuitMessage,int,a)
-Fa(void,ReplyMessage,LONG,a)
-Fa(void,SetCaretBlinkTime,WORD,a)
-Fa(void,SetConvertHook,BOOL,a)
-Fa(void,SetDoubleClickTime,WORD,a)
-Fa(void,SetKeyboardState,BYTE FAR*,a)
-Fa(void,SetRectEmpty,LPRECT,a)
-Fa(void,ShowCaret,HWND,a)
-Fa(void,SwapRecording,WORD,a)
-Fa(void,UnlockSegment,HGLOBAL,a)
-Fa(void,UpdateWindow,HWND,a)
-Fb(BOOL,CallMsgFilter,SEGPTR,a,short,b)
-Fb(BOOL,ChangeClipboardChain,HWND,a,HWND,b)
-Fb(BOOL,EnableWindow,HWND,a,BOOL,b)
-Fb(BOOL,EnumWindows,FARPROC,a,LONG,b)
-Fb(BOOL,EqualRect,LPRECT,a,LPRECT,b)
-Fb(BOOL,EqualRgn,HRGN,a,HRGN,b)
-Fb(BOOL,ExitWindows,DWORD,dwReserved,WORD,wReturnCode)
-Fb(BOOL,FlashWindow,HWND,a,BOOL,b)
-Fb(BOOL,GetBitmapDimensionEx,HBITMAP,a,LPSIZE,b)
-Fb(BOOL,GetBrushOrgEx,HDC,a,LPPOINT,b)
-Fb(BOOL,GetCurrentPositionEx,HDC,a,LPPOINT,b)
-Fb(BOOL,GetTextMetrics,HDC,a,LPTEXTMETRIC,b)
-Fb(BOOL,GetViewportExtEx,HDC,a,LPPOINT,b)
-Fb(BOOL,GetViewportOrgEx,HDC,a,LPPOINT,b)
-Fb(BOOL,GetWinDebugInfo,LPWINDEBUGINFO,a,UINT,b)
-Fb(BOOL,GetWindowExtEx,HDC,a,LPPOINT,b)
-Fb(BOOL,GetWindowOrgEx,HDC,a,LPPOINT,b)
-Fb(BOOL,GetWindowPlacement,HWND,a,LPWINDOWPLACEMENT,b)
-Fb(BOOL,InvertRgn,HDC,a,HRGN,b)
-Fb(BOOL,IsBadHugeReadPtr,SEGPTR,a,DWORD,b)
-Fb(BOOL,IsBadHugeWritePtr,SEGPTR,a,DWORD,b)
-Fb(BOOL,IsBadReadPtr,SEGPTR,a,WORD,b)
-Fb(BOOL,IsBadStringPtr,SEGPTR,a,WORD,b)
-Fb(BOOL,IsBadWritePtr,SEGPTR,a,WORD,b)
-Fb(BOOL,IsChild,HWND,a,HWND,b)
-Fb(BOOL,IsDialogMessage,HWND,a,LPMSG,b)
-Fb(BOOL,KillSystemTimer,HWND,a,WORD,b)
-Fb(BOOL,KillTimer,HWND,a,WORD,b)
-Fb(BOOL,OemToAnsi,LPSTR,a,LPSTR,b)
-Fb(BOOL,PaintRgn,HDC,a,HRGN,b)
-Fb(BOOL,PlayMetaFile,HDC,a,HANDLE,b)
-Fb(BOOL,PtInRect,LPRECT,a,POINT,b)
-Fb(BOOL,RectInRegion,HRGN,a,LPRECT,b)
-Fb(BOOL,RectVisible,HDC,a,LPRECT,b)
-Fb(BOOL,ResizePalette,HPALETTE,a,WORD,b)
-Fb(BOOL,RestoreDC,HDC,a,short,b)
-Fb(BOOL,SetConvertParams,int,a,int,b)
-Fb(BOOL,SetMenu,HWND,a,HMENU,b)
-Fb(BOOL,SetWindowPlacement,HWND,a,LPWINDOWPLACEMENT,b)
-Fb(BOOL,ShowWindow,HWND,a,int,b) 
-Fb(BOOL,TranslateMDISysAccel,HWND,a,LPMSG,b)
-Fb(BOOL,UnhookWindowsHook,short,a,FARPROC,b)
-Fb(BOOL,UnregisterClass,SEGPTR,a,HANDLE,b)
-Fb(DWORD,GetNearestColor,HDC,a,DWORD,b)
-Fb(DWORD,SetBkColor,HDC,a,COLORREF,b)
-Fb(DWORD,SetMapperFlags,HDC,a,DWORD,b)
-Fb(DWORD,SetTextColor,HDC,a,DWORD,b)
-Fb(DWORD,SizeofResource,HANDLE,a,HRSRC,b)
-Fb(FARPROC,GetProcAddress,HANDLE,a,SEGPTR,b)
-Fb(FARPROC,MakeProcInstance,FARPROC,a,HANDLE,b)
-Fb(FARPROC,SetWindowsHook,short,a,FARPROC,b)
-Fb(HANDLE,CopyMetaFile,HANDLE,a,LPSTR,b)
-Fb(HANDLE,GetProp,HWND,a,SEGPTR,b)
-Fb(HANDLE,LoadAccelerators,HANDLE,a,SEGPTR,b)
-Fb(HANDLE,LoadModule,LPCSTR,a,LPVOID,b)
-Fb(HANDLE,LoadResource,HANDLE,a,HANDLE,b)
-Fb(HANDLE,LocalAlloc,WORD,a,WORD,b)
-Fb(HANDLE,RemoveProp,HWND,a,SEGPTR,b)
-Fb(HANDLE,SelectObject,HDC,a,HANDLE,b)
-Fb(HANDLE,SetClipboardData,WORD,a,HANDLE,b)
-Fb(HBITMAP,LoadBitmap,HANDLE,a,SEGPTR,b)
-Fb(HBRUSH,CreateDIBPatternBrush,HANDLE,a,WORD,b)
-Fb(HBRUSH,CreateHatchBrush,short,a,COLORREF,b)
-Fb(HCURSOR,LoadCursor,HANDLE,a,SEGPTR,b)
-Fb(HDC,BeginPaint,HWND,a,LPPAINTSTRUCT,b) 
-Fb(HGLOBAL,GlobalAlloc,WORD,a,DWORD,b)
-Fb(HGLOBAL,SetTaskQueue,HTASK,a,HGLOBAL,b)
-Fb(HICON,LoadIcon,HANDLE,a,SEGPTR,b)
-Fb(HMENU,GetSubMenu,HMENU,a,short,b)
-Fb(HMENU,GetSystemMenu,HWND,a,BOOL,b)
-Fb(HMENU,LoadMenu,HANDLE,a,SEGPTR,b)
-Fb(HMENU,LookupMenuHandle,HMENU,a,INT,b)
-Fb(HPALETTE,GDISelectPalette,HDC,a,HPALETTE,b)
-Fb(HWND,ChildWindowFromPoint,HWND,a,POINT,b)
-Fb(HWND,FindWindow,SEGPTR,a,LPSTR,b)
-Fb(HWND,GetDlgItem,HWND,a,WORD,b)
-Fb(HWND,GetNextWindow,HWND,a,WORD,b)
-Fb(HWND,GetWindow,HWND,a,WORD,b)
-Fb(HWND,SetParent,HWND,a,HWND,b)
-Fb(INT,AnsiToOem,LPSTR,a,LPSTR,b)
-Fb(INT,_lcreat,LPSTR,a,INT,b)
-Fb(INT,_lopen,LPSTR,a,INT,b)
-Fb(INT,lstrcmp,LPCSTR,a,LPCSTR,b )
-Fb(INT,lstrcmpi,LPCSTR,a,LPCSTR,b )
-Fb(LONG,EscapeCommFunction,int,a,int,b)
-Fb(LONG,GetClassLong,HWND,a,short,b)
-Fb(LONG,GetWindowLong,HWND,a,short,b)
-Fb(SEGPTR,AnsiPrev,SEGPTR,a,SEGPTR,b)
-Fb(SEGPTR,lstrcat,SEGPTR,a,SEGPTR,b)
-Fb(SEGPTR,lstrcpy,SEGPTR,a,SEGPTR,b)
-Fb(WORD FAR*,SetCommEventMask,int,a,WORD,b)
-Fb(WORD,AnsiLowerBuff,LPSTR,a,WORD,b)
-Fb(WORD,AnsiUpperBuff,LPSTR,a,WORD,b)
-Fb(WORD,ChangeSelector,WORD,a,WORD,b)
-Fb(WORD,GetClassWord,HWND,a,short,b)
-Fb(WORD,GetCommEventMask,int,a,int,b)
-Fb(WORD,GetMenuItemID,HMENU,a,int,b)
-Fb(WORD,GetNearestPaletteIndex,HPALETTE,a,DWORD,b)
-Fb(WORD,GetSystemDirectory,LPSTR,a,WORD,b)
-Fb(WORD,GetWindowWord,HWND,a,short,b)
-Fb(WORD,GetWindowsDirectory,LPSTR,a,WORD,b)
-Fb(WORD,IsDlgButtonChecked,HWND,a,WORD,b)
-Fb(WORD,LocalShrink,HANDLE,a,WORD,b)
-Fb(WORD,MapVirtualKey,WORD,a,WORD,b)
-Fb(WORD,PrestoChangoSelector,WORD,a,WORD,b)
-Fb(WORD,SetBkMode,HDC,a,WORD,b)
-Fb(WORD,SetMapMode,HDC,a,WORD,b)
-Fb(WORD,SetPolyFillMode,HDC,a,WORD,b)
-Fb(WORD,SetROP2,HDC,a,WORD,b)
-Fb(WORD,SetRelAbs,HDC,a,WORD,b)
-Fb(WORD,SetSelectorBase,WORD,a,DWORD,b)
-Fb(WORD,SetSelectorLimit,WORD,a,DWORD,b)
-Fb(WORD,SetStretchBltMode,HDC,a,WORD,b)
-Fb(WORD,SetSystemPaletteUse,HDC,a,WORD,b)
-Fb(WORD,SetTextAlign,HDC,a,WORD,b)
-Fb(WORD,WinExec,LPSTR,a,WORD,b)
-Fb(int,AccessResource,HANDLE,a,HANDLE,b)
-Fb(int,BuildCommDCB,LPSTR,a,DCB*,b)
-Fb(int,ConvertRequest,HWND,a,LPKANJISTRUCT,b)
-Fb(int,EnumProps,HWND,a,FARPROC,b)
-Fb(int,ExcludeUpdateRgn,HDC,a,HWND,b)
-Fb(int,FlushComm,int,a,int,b)
-Fb(int,GetClipBox,HDC,a,LPRECT,b)
-Fb(int,GetCommError,int,a,COMSTAT*,b)
-Fb(int,GetCommState,int,a,DCB*,b)
-Fb(int,GetDeviceCaps,HDC,a,WORD,b)
-Fb(int,GetPriorityClipboardFormat,WORD FAR*,a,short,b)
-Fb(int,GetRgnBox,HRGN,a,LPRECT,b)
-Fb(int,GetScrollPos,HWND,a,int,b)
-Fb(int,ReleaseDC,HWND,a,HDC,b)
-Fb(int,SelectClipRgn,HDC,a,HRGN,b)
-Fb(int,SelectVisRgn,HDC,a,HRGN,b)
-Fb(int,SetSoundNoise,int,a,int,b)
-Fb(int,SetVoiceQueueSize,int,a,int,b)
-Fb(int,SetVoiceThreshold,int,a,int,b)
-Fb(int,Throw,LPCATCHBUF,a,int,b)
-Fb(int,TransmitCommChar,int,a,char,b)
-Fb(int,UngetCommChar,int,a,char,b)
-Fb(short,SetTextCharacterExtra,HDC,a,short,b)
-Fb(void,ClientToScreen,HWND,a,LPPOINT,b)
-Fb(void,CopyRect,LPRECT,a,LPRECT,b)
-Fb(void,DrawFocusRect,HDC,a,LPRECT,b)
-Fb(void,EndDialog,HWND,a,short,b)
-Fb(void,EndPaint,HWND,a,LPPAINTSTRUCT,b)
-Fb(void,FarSetOwner,HANDLE,a,WORD,b)
-Fb(void,GetClientRect,HWND,a,LPRECT,b)
-Fb(void,GetCodeInfo,FARPROC,lpProc,LPVOID,lpSegInfo)
-Fb(void,GetWindowRect,HWND,a,LPRECT,b)
-Fb(void,InvertRect,HDC,a,LPRECT,b)
-Fb(void,MapDialogRect,HWND,a,LPRECT,b)
-Fb(void,ProfSampRate,int,a,int,b)
-Fb(void,ProfSetup,int,a,int,b)
-Fb(void,ScreenToClient,HWND,a,LPPOINT,b)
-Fb(void,SetCaretPos,short,a,short,b)
-Fb(void,SetCursorPos,short,a,short,b)
-Fb(void,SetDCState,HDC,a,HDC,b)
-Fb(void,SetWindowText,HWND,a,LPSTR,b)
-Fb(void,ShowOwnedPopups,HWND,a,BOOL,b)
-Fb(void,ValidateRect,HWND,a,LPRECT,b)
-Fb(void,ValidateRgn,HWND,a,HRGN,b)
-Fc(BOOL,CheckMenuItem,HMENU,a,WORD,b,WORD,c)
-Fc(BOOL,DPtoLP,HDC,a,LPPOINT,b,int,c)
-Fc(BOOL,DeleteMenu,HMENU,a,WORD,b,WORD,c)
-Fc(BOOL,DlgDirSelect,HWND,a,LPSTR,b,int,c)
-Fc(BOOL,DlgDirSelectComboBox,HWND,a,LPSTR,b,int,c)
-Fc(BOOL,EnableMenuItem,HMENU,a,WORD,b,WORD,c)
-Fc(BOOL,EnableScrollBar,HWND,a,INT,b,UINT,c)
-Fc(BOOL,EnumChildWindows,HWND,a,FARPROC,b,LONG,c)
-Fc(BOOL,EnumTaskWindows,HANDLE,a,FARPROC,b,LONG,c)
-Fc(BOOL,FillRgn,HDC,a,HRGN,b,HBRUSH,c)
-Fc(BOOL,GetClassInfo,HANDLE,a,SEGPTR,b,LPWNDCLASS,c)
-Fc(BOOL,GetUpdateRect,HWND,a,LPRECT,b,BOOL,c)
-Fc(BOOL,IntersectRect,LPRECT,a,LPRECT,b,LPRECT,c)
-Fc(BOOL,LPtoDP,HDC,a,LPPOINT,b,int,c)
-Fc(BOOL,LineTo,HDC,a,short,b,short,c)
-Fc(BOOL,LocalInit,WORD,a,WORD,b,WORD,c)
-Fc(BOOL,Polygon,HDC,a,LPPOINT,b,int,c)
-Fc(BOOL,Polyline,HDC,a,LPPOINT,b,int,c)
-Fc(BOOL,PtInRegion,HRGN,a,short,b,short,c)
-Fc(BOOL,PtVisible,HDC,a,short,b,short,c)
-Fc(BOOL,RemoveMenu,HMENU,a,WORD,b,WORD,c)
-Fc(BOOL,SetProp,HWND,a,SEGPTR,b,HANDLE,c)
-Fc(BOOL,SubtractRect,LPRECT,a,LPRECT,b,LPRECT,c)
-Fc(BOOL,UnionRect,LPRECT,a,LPRECT,b,LPRECT,c)
-Fc(BOOL,WriteProfileString,LPSTR,a,LPSTR,b,LPSTR,c)
-Fc(DWORD,GetPixel,HDC,a,short,b,short,c)
-Fc(DWORD,GetTextExtent,HDC,a,LPSTR,b,short,c)
-Fc(DWORD,MoveTo,HDC,a,short,b,short,c)
-Fc(DWORD,OffsetViewportOrg,HDC,a,short,b,short,c)
-Fc(DWORD,OffsetWindowOrg,HDC,a,short,b,short,c)
-Fc(DWORD,SetBitmapDimension,HBITMAP,a,short,b,short,c)
-Fc(DWORD,SetBrushOrg,HDC,a,short,b,short,c)
-Fc(DWORD,SetViewportExt,HDC,a,short,b,short,c)
-Fc(DWORD,SetViewportOrg,HDC,a,short,b,short,c)
-Fc(DWORD,SetWindowExt,HDC,a,short,b,short,c)
-Fc(DWORD,SetWindowOrg,HDC,a,short,b,short,c)
-Fc(FARPROC,SetResourceHandler,HANDLE,a,LPSTR,b,FARPROC,c)
-Fc(HANDLE,AllocResource,HANDLE,a,HANDLE,b,DWORD,c)
-Fc(HANDLE,FindResource,HANDLE,a,SEGPTR,b,SEGPTR,c)
-Fc(HANDLE,LocalReAlloc,HANDLE,a,WORD,b,WORD,c)
-Fc(HBITMAP,CreateCompatibleBitmap,HDC,a,short,b,short,c)
-Fc(HBITMAP,CreateDiscardableBitmap,HDC,a,short,b,short,c)
-Fc(HBRUSH,GetControlBrush,HWND,a,HDC,b,WORD,c)
-Fc(HDC,GetDCEx,HWND,a,HRGN,b,DWORD,c)
-Fc(HGLOBAL,GlobalReAlloc,HGLOBAL,a,DWORD,b,WORD,c)
-Fc(HPALETTE,SelectPalette,HDC,a,HPALETTE,b,BOOL,c)
-Fc(HPEN,CreatePen,short,a,short,b,COLORREF,c)
-Fc(HRGN,CreatePolygonRgn,LPPOINT,a,short,b,short,c)
-Fc(HWND,GetNextDlgGroupItem,HWND,a,HWND,b,BOOL,c)
-Fc(HWND,GetNextDlgTabItem,HWND,a,HWND,b,BOOL,c)
-Fc(INT,GetTextFace,HDC,a,INT,b,LPSTR,c)
-Fc(INT,OpenFile,LPSTR,a,LPOFSTRUCT,b,WORD,c)
-Fc(INT,_lread,INT,a,LPSTR,b,WORD,c)
-Fc(INT,_lwrite,INT,a,LPCSTR,b,WORD,c)
-Fc(LONG,GetBitmapBits,HBITMAP,a,LONG,b,LPSTR,c)
-Fc(LONG,SetBitmapBits,HBITMAP,a,LONG,b,LPSTR,c)
-Fc(LONG,SetClassLong,HWND,a,short,b,LONG,c)
-Fc(LONG,SetWindowLong,HWND,a,short,b,LONG,c)
-Fc(LONG,_hread,INT,a,LPSTR,b,LONG,c)
-Fc(LONG,_hwrite,INT,a,LPCSTR,b,LONG,c)
-Fc(LONG,_llseek,INT,a,LONG,b,INT,c)
-Fc(SEGPTR,lstrcpyn,SEGPTR,a,SEGPTR,b,WORD,c)
-Fc(WORD,GetAtomName,ATOM,a,LPSTR,b,short,c)
-Fc(WORD,GetInternalWindowPos,HWND,a,LPRECT,b,LPPOINT,c)
-Fc(WORD,GetMenuState,HMENU,a,WORD,b,WORD,c)
-Fc(WORD,GetProfileInt,LPSTR,a,LPSTR,b,int,c)
-Fc(WORD,GlobalGetAtomName,ATOM,a,LPSTR,b,short,c)
-Fc(WORD,SelectorAccessRights,WORD,a,WORD,b,WORD,c)
-Fc(WORD,SetClassWord,HWND,a,short,b,WORD,c)
-Fc(WORD,SetWindowWord,HWND,a,short,b,WORD,c)
-Fc(int,FillRect,HDC,a,LPRECT,b,HBRUSH,c)
-Fc(int,FrameRect,HDC,a,LPRECT,b,HBRUSH,c)
-Fc(int,GetClassName,HWND,a,LPSTR,b,short,c)
-Fc(int,GetClipboardFormatName,WORD,a,LPSTR,b,short,c)
-Fc(int,GetEnvironment,LPSTR,a,LPSTR,b,WORD,c)
-Fc(int,GetInstanceData,HANDLE,a,WORD,b,int,c)
-Fc(int,GetKeyNameText,LONG,a,LPSTR,b,int,c)
-Fc(int,GetModuleFileName,HANDLE,a,LPSTR,b,short,c)
-Fc(int,GetObject,HANDLE,a,int,b,LPSTR,c)
-Fc(int,GetUpdateRgn,HWND,a,HRGN,b,BOOL,c)
-Fc(int,GetWindowText,HWND,a,LPSTR,b,int,c)
-Fc(int,MulDiv,int,a,int,b,int,c)
-Fc(int,OffsetClipRgn,HDC,a,short,b,short,c)
-Fc(int,OffsetRgn,HRGN,a,short,b,short,c)
-Fc(int,OpenComm,LPSTR,a,WORD,b,WORD,c)
-Fc(int,ReadComm,int,a,LPSTR,b,int,c)
-Fc(int,SetEnvironment,LPSTR,a,LPSTR,b,WORD,c)
-Fc(int,SetVoiceEnvelope,int,a,int,b,int,c)
-Fc(int,SetVoiceSound,int,a,LONG,b,int,c)
-Fc(int,TranslateAccelerator,HWND,a,HANDLE,b,LPMSG,c)
-Fc(int,WriteComm,int,a,LPSTR,b,int,c)
-Fc(int,wvsprintf,LPSTR,a,LPSTR,b,LPSTR,c)
-Fc(short,SetTextJustification,HDC,a,short,b,short,c)
-Fc(void,AdjustWindowRect,LPRECT,a,DWORD,b,BOOL,c)
-Fc(void,AnsiToOemBuff,LPSTR,a,LPSTR,b,INT,c)
-Fc(void,CheckDlgButton,HWND,a,WORD,b,WORD,c)
-Fc(void,InflateRect,LPRECT,a,short,b,short,c)
-Fc(void,InvalidateRect,HWND,a,LPRECT,b,BOOL,c)
-Fc(void,InvalidateRgn,HWND,a,HRGN,b,BOOL,c)
-Fc(void,OemToAnsiBuff,LPSTR,a,LPSTR,b,INT,c)
-Fc(void,OffsetRect,LPRECT,a,short,b,short,c)
-Fc(void,SetDlgItemText,HWND,a,WORD,b,SEGPTR,c)
-Fc(void,SetSysColors,int,a,LPINT,b,COLORREF*,c)
-Fc(void,ShowScrollBar,HWND,a,WORD,b,BOOL,c)
-Fc(void,SwitchStackTo,WORD,a,WORD,b,WORD,c)
-Fd(BOOL,AppendMenu,HMENU,a,WORD,b,WORD,c,LPSTR,d)
-Fd(BOOL,DrawIcon,HDC,a,short,b,short,c,HICON,d)
-Fd(BOOL,EnumMetaFile,HDC,a,LOCALHANDLE,b,FARPROC,c,BYTE FAR*,d)
-Fd(BOOL,FloodFill,HDC,a,INT,b,INT,c,COLORREF,d)
-Fd(BOOL,GetCharWidth,HDC,a,WORD,b,WORD,c,LPINT,d)
-Fd(BOOL,GetMessage,SEGPTR,msg,HWND,b,WORD,c,WORD,d)
-Fd(BOOL,GetTextExtentPoint,HDC,a,LPSTR,b,short,c,LPSIZE,d)
-Fd(BOOL,HiliteMenuItem,HWND,a,HMENU,b,WORD,c,WORD,d)
-Fd(BOOL,MoveToEx,HDC,a,short,b,short,c,LPPOINT,d)
-Fd(BOOL,OffsetViewportOrgEx,HDC,a,short,b,short,c,LPPOINT,d)
-Fd(BOOL,OffsetWindowOrgEx,HDC,a,short,b,short,c,LPPOINT,d)
-Fd(BOOL,PolyPolygon,HDC,a,LPPOINT,b,LPINT,c,WORD,d)
-Fd(BOOL,PostAppMessage,HANDLE,a,WORD,b,WORD,c,LONG,d)
-Fd(BOOL,PostMessage,HWND,a,WORD,b,WORD,c,LONG,d)
-Fd(BOOL,RedrawWindow,HWND,a,LPRECT,b,HRGN,c,UINT,d)
-Fd(BOOL,SetBitmapDimensionEx,HBITMAP,a,short,b,short,c,LPSIZE,d)
-Fd(BOOL,SetViewportExtEx,HDC,a,short,b,short,c,LPSIZE,d)
-Fd(BOOL,SetViewportOrgEx,HDC,a,short,b,short,c,LPPOINT,d)
-Fd(BOOL,SetWindowExtEx,HDC,a,short,b,short,c,LPSIZE,d)
-Fd(BOOL,SetWindowOrgEx,HDC,a,short,b,short,c,LPPOINT,d)
-Fd(BOOL,WinHelp,HWND,hwndMain,LPSTR,lpszHelp,WORD,usCommand,DWORD,ulData)
-Fd(BOOL,WritePrivateProfileString,LPSTR,a,LPSTR,b,LPSTR,c,LPSTR,d)
-Fd(COLORREF,SetPixel,HDC,a,short,b,short,c,COLORREF,d)
-Fd(DWORD,CallNextHookEx,HHOOK,a,short,b,WPARAM,c,LPARAM,d)
-Fd(DWORD,DefHookProc,short,a,WORD,b,DWORD,c,HHOOK FAR*,d)
-Fd(HDC,CreateDC,LPSTR,a,LPSTR,b,LPSTR,c,LPSTR,d)
-Fd(HDC,CreateIC,LPSTR,a,LPSTR,b,LPSTR,c,LPSTR,d)
-Fd(HHOOK,SetWindowsHookEx,short,a,HOOKPROC,b,HINSTANCE,c,HTASK,d)
-Fd(HRGN,CreateEllipticRgn,short,a,short,b,short,c,short,d)
-Fd(HRGN,CreatePolyPolygonRgn,LPPOINT,a,LPINT,b,short,c,short,d)
-Fd(HRGN,CreateRectRgn,short,a,short,b,short,c,short,d)
-Fd(HWND,CreateDialog,HANDLE,a,SEGPTR,b,HWND,c,WNDPROC,d)
-Fd(HWND,CreateDialogIndirect,HANDLE,a,SEGPTR,b,HWND,c,WNDPROC,d)
-Fd(INT,GetTempFileName,BYTE,a,LPCSTR,b,UINT,c,LPSTR,d)
-Fd(LONG,DefDlgProc,HWND,a,WORD,b,WORD,c,LONG,d)
-Fd(LONG,DefMDIChildProc,HWND,a,WORD,b,WORD,c,LONG,d)
-Fd(LONG,DefWindowProc,HWND,a,WORD,b,WORD,c,LONG,d)
-Fd(LONG,SendMessage,HWND,a,WORD,b,WORD,c,LONG,d)
-Fd(WORD,GetDlgItemInt,HWND,a,WORD,b,BOOL FAR*,c,BOOL,d)
-Fd(WORD,GetPaletteEntries,HPALETTE,a,WORD,b,WORD,c,LPPALETTEENTRY,d)
-Fd(WORD,GetPrivateProfileInt,LPSTR,a,LPSTR,b,short,c,LPSTR,d)
-Fd(WORD,GetSystemPaletteEntries,HDC,a,WORD,b,WORD,c,LPPALETTEENTRY,d)
-Fd(WORD,SetPaletteEntries,HPALETTE,a,WORD,b,WORD,c,LPPALETTEENTRY,d)
-Fd(WORD,SetSystemTimer,HWND,a,WORD,d,WORD,b,FARPROC,c)
-Fd(WORD,SetTimer,HWND,a,WORD,d,WORD,b,FARPROC,c)
-Fd(int,CombineRgn,HRGN,a,HRGN,b,HRGN,c,short,d)
-Fd(int,DialogBox,HINSTANCE,a,SEGPTR,b,HWND,c,WNDPROC,d)
-Fd(int,DialogBoxIndirect,HANDLE,a,HANDLE,b,HWND,c,WNDPROC,d)
-Fd(int,EnumFonts,HDC,a,LPSTR,b,FARPROC,c,LPSTR,d)
-Fd(int,EnumObjects,HDC,a,int,b,FARPROC,c,LPSTR,d)
-Fd(int,GetDlgItemText,HWND,a,WORD,b,SEGPTR,c,WORD,d)
-Fd(int,LoadString,HANDLE,a,WORD,b,LPSTR,c,int,d)
-Fd(int,MessageBox,HWND,a,LPSTR,b,LPSTR,c,WORD,d)
-Fd(int,SetScrollPos,HWND,a,int,b,int,c,BOOL,d)
-Fd(int,SetVoiceNote,int,a,int,b,int,c,int,d)
-Fd(void,AdjustWindowRectEx,LPRECT,a,DWORD,b,BOOL,c,DWORD,d)
-Fd(void,AnimatePalette,HPALETTE,a,WORD,b,WORD,c,LPPALETTEENTRY,d)
-Fd(void,CheckRadioButton,HWND,a,WORD,b,WORD,c,WORD,d)
-Fd(void,CreateCaret,HWND,a,HBITMAP,b,short,c,short,d)
-Fd(void,FillWindow,HWND,a,HWND,b,HDC,c,HBRUSH,d)
-Fd(void,GetScrollRange,HWND,a,int,b,LPINT,c,LPINT,d)
-Fd(void,MapWindowPoints,HWND,a,HWND,b,LPPOINT,c,WORD,d)
-Fd(void,PlayMetaFileRecord,HDC,a,LPHANDLETABLE,b,LPMETARECORD,c,WORD,d)
-Fd(void,SetDlgItemInt,HWND,a,WORD,b,WORD,c,BOOL,d)
-Fd(void,SetInternalWindowPos,HWND,a,WORD,b,LPRECT,c,LPPOINT,d)
-Fe(BOOL,ChangeMenu,HMENU,a,WORD,b,LPSTR,c,WORD,d,WORD,e)
-Fe(BOOL,Ellipse,HDC,a,int,b,int,c,int,d,int,e)
-Fe(BOOL,ExtFloodFill,HDC,a,INT,b,INT,c,COLORREF,d,WORD,e)
-Fe(BOOL,FrameRgn,HDC,a,HRGN,b,HBRUSH,e,int,c,int,d)
-Fe(BOOL,InsertMenu,HMENU,a,WORD,b,WORD,c,WORD,d,LPSTR,e)
-Fe(BOOL,ModifyMenu,HMENU,a,WORD,b,WORD,c,WORD,d,LPSTR,e)
-Fe(BOOL,PeekMessage,LPMSG,a,HWND,b,WORD,c,WORD,d,WORD,e)
-Fe(BOOL,Rectangle,HDC,a,int,xLeft,int,yTop,int,xRight,int,yBottom)
-Fe(BOOL,SetMenuItemBitmaps,HMENU,a,WORD,b,WORD,c,HBITMAP,d,HBITMAP,e)
-Fe(BOOL,TextOut,HDC,a,short,b,short,c,LPSTR,d,short,e)
-Fe(DWORD,GetTabbedTextExtent,HDC,a,LPSTR,b,int,c,int,d,LPINT,e)
-Fe(DWORD,ScaleViewportExt,HDC,a,short,b,short,c,short,d,short,e)
-Fe(DWORD,ScaleWindowExt,HDC,a,short,b,short,c,short,d,short,e)
-Fe(HBITMAP,CreateBitmap,short,a,short,b,BYTE,c,BYTE,d,LPSTR,e)
-Fe(HWND,CreateDialogIndirectParam,HANDLE,a,SEGPTR,b,HWND,c,WNDPROC,d,LPARAM,e)
-Fe(HWND,CreateDialogParam,HANDLE,a,SEGPTR,b,HWND,c,WNDPROC,d,LPARAM,e)
-Fe(LONG,CallWindowProc,WNDPROC,a,HWND,b,WORD,c,WORD,d,LONG,e)
-Fe(LONG,DefFrameProc,HWND,a,HWND,b,WORD,c,WORD,d,LONG,e)
-Fe(LONG,SendDlgItemMessage,HWND,a,WORD,b,WORD,c,WORD,d,LONG,e)
-Fe(int,DialogBoxIndirectParam,HANDLE,a,HANDLE,b,HWND,c,WNDPROC,d,LONG,e)
-Fe(int,DialogBoxParam,HANDLE,a,SEGPTR,b,HWND,c,WNDPROC,d,LONG,e)
-Fe(int,DlgDirList,HWND,a,LPSTR,b,int,c,int,d,WORD,e)
-Fe(int,DlgDirListComboBox,HWND,a,SEGPTR,b,int,c,int,d,WORD,e)
-Fe(int,DrawText,HDC,a,LPSTR,str,int,c,LPRECT,d,WORD,flag)
-Fe(int,Escape,HDC,a,int,b,int,c,LPSTR,d,LPSTR,e)
-Fe(int,ExcludeClipRect,HDC,a,short,b,short,c,short,d,short,e)
-Fe(int,ExcludeVisRect,HDC,a,short,b,short,c,short,d,short,e)
-Fe(int,GetMenuString,HMENU,a,WORD,b,LPSTR,c,short,d,WORD,e)
-Fe(int,GetProfileString,LPSTR,a,LPSTR,b,LPSTR,c,LPSTR,d,int,e)
-Fe(int,IntersectClipRect,HDC,a,short,b,short,c,short,d,short,e)
-Fe(int,IntersectVisRect,HDC,a,short,b,short,c,short,d,short,e)
-Fe(int,SetVoiceAccent,int,a,int,b,int,c,int,d,int,e)
-Fe(int,ToAscii,WORD,wVirtKey,WORD,wScanCode,LPSTR,lpKeyState,LPVOID,lpChar,WORD,wFlags)
-Fe(void,PaintRect,HWND,a,HWND,b,HDC,c,HBRUSH,d,LPRECT,e)
-Fe(void,ScrollWindow,HWND,a,short,b,short,c,LPRECT,d,LPRECT,e)
-Fe(void,SetRect,LPRECT,a,short,b,short,c,short,d,short,e)
-Fe(void,SetRectRgn,HRGN,a,short,b,short,c,short,d,short,e)
-Fe(void,SetScrollRange,HWND,a,int,b,int,c,int,d,BOOL,e)
-Ff(BOOL,MoveWindow,HWND,a,short,b,short,c,short,d,short,e,BOOL,f)
-Ff(BOOL,PatBlt,HDC,a,short,b,short,c,short,d,short,e,DWORD,f)
-Ff(BOOL,ScaleViewportExtEx,HDC,a,short,b,short,c,short,d,short,e,LPSIZE,f)
-Ff(BOOL,ScaleWindowExtEx,HDC,a,short,b,short,c,short,d,short,e,LPSIZE,f)
-Ff(HBITMAP,CreateDIBitmap,HDC,a,LPBITMAPINFOHEADER,b,DWORD,c,LPSTR,d,LPBITMAPINFO,e,WORD,f)
-Ff(HRGN,CreateRoundRectRgn,short,a,short,b,short,c,short,d,short,e,short,f)
-Ff(short,GetPrivateProfileString,LPSTR,a,LPSTR,b,LPSTR,c,LPSTR,d,short,e,LPSTR,f)
-Ff(void,LineDDA,short,a,short,b,short,c,short,d,FARPROC,e,long,f)
-Fg(BOOL,RoundRect,HDC,a,short,b,short,c,short,d,short,e,short,f,short,g)
-Fg(BOOL,ScrollDC,HDC,a,short,b,short,c,LPRECT,d,LPRECT,e,HRGN,f,LPRECT,g)
-Fg(BOOL,SetWindowPos,HWND,a,HWND,b,short,c,short,d,short,e,short,f,WORD,g)
-Fg(BOOL,TrackPopupMenu,HMENU,a,WORD,b,short,c,short,d,short,e,HWND,f,LPRECT,g)
-Fg(HCURSOR,CreateCursor,HANDLE,a,short,b,short,c,short,d,short,e,LPSTR,f,LPSTR,g)
-Fg(HICON,CreateIcon,HANDLE,a,int,b,int,c,BYTE,d,BYTE,e,LPSTR,f,LPSTR,g)
-Fg(int,GetDIBits,HDC,a,HANDLE,a2,WORD,b,WORD,c,LPSTR,d,LPBITMAPINFO,e,WORD,f)
-Fg(int,SetDIBits,HDC,a,HANDLE,a2,WORD,b,WORD,c,LPSTR,d,LPBITMAPINFO,e,WORD,f)
-Fh(BOOL,ExtTextOut,HDC,a,short,b,short,c,WORD,d,LPRECT,e,LPSTR,f,WORD,g,LPINT,h)
-Fh(HDWP,DeferWindowPos,HDWP,hWinPosInfo,HWND,hWnd,HWND,hWndInsertAfter,INT,x,INT,y,INT,cx,INT,cy,WORD,wFlags)
-Fh(LONG,TabbedTextOut,HDC,a,short,b,short,c,LPSTR,d,short,e,short,f,LPINT,g,short,h)
-Fh(int,ScrollWindowEx,HWND,a,short,b,short,c,LPRECT,d,LPRECT,e,HRGN,f,LPRECT,g,WORD,h)
-Fi(BOOL,Arc,HDC,a,int,xLeft,int,yTop,int,xRight,int,yBottom,int,xStart,int,yStart,int,xEnd,int,yEnd)
-Fi(BOOL,BitBlt,HDC,a,short,b,short,c,short,d,short,e,HDC,f,short,g,short,h,DWORD,i)
-Fi(BOOL,Chord,HDC,a,int,xLeft,int,yTop,int,xRight,int,yBottom,int,xStart,int,yStart,int,xEnd,int,yEnd)
-Fi(BOOL,GrayString,HDC,a,HBRUSH,b,FARPROC,gsprc,LPARAM,lParam,INT,cch,INT,x,INT,y,INT,cx,INT,cy)
-Fi(BOOL,Pie,HDC,a,int,xLeft,int,yTop,int,xRight,int,yBottom,int,xStart,int,yStart,int,xEnd,int,yEnd)
-Fk(BOOL,StretchBlt,HDC,a,short,b,short,c,short,d,short,e,HDC,f,short,g,short,h,short,i,short,j,DWORD,k)
-Fk(HWND,CreateWindow,SEGPTR,a,SEGPTR,b,DWORD,c,short,d,short,e,short,f,short,g,HWND,h,HMENU,i,HANDLE,j,SEGPTR,k)
-Fl(HWND,CreateWindowEx,DWORD,a,SEGPTR,b,SEGPTR,c,DWORD,d,short,e,short,f,short,g,short,h,HWND,i,HMENU,j,HANDLE,k,SEGPTR,l)
-Fl(int,SetDIBitsToDevice,HDC,a,short,b,short,c,WORD,d,WORD,e,WORD,f,WORD,g,WORD,h,WORD,i,LPSTR,j,LPBITMAPINFO,k,WORD,l)
-Fm(int,StretchDIBits,HDC,a,WORD,b,WORD,c,WORD,d,WORD,e,WORD,f,WORD,g,WORD,h,WORD,i,LPSTR,j,LPBITMAPINFO,k,WORD,l,DWORD,m)
-Fn(HFONT,CreateFont,int,a,int,b,int,c,int,d,int,e,BYTE,f,BYTE,g,BYTE,h,BYTE,i,BYTE,j,BYTE,k,BYTE,l,BYTE,m,LPSTR,n)
+ATOM AddAtom(SEGPTR);
+ATOM DeleteAtom(ATOM);
+ATOM FindAtom(SEGPTR);
+ATOM GlobalAddAtom(SEGPTR);
+ATOM GlobalDeleteAtom(ATOM);
+ATOM GlobalFindAtom(SEGPTR);
+ATOM RegisterClass(LPWNDCLASS);
+BOOL AnyPopup(void);
+BOOL AppendMenu(HMENU,WORD,WORD,LPSTR);
+BOOL Arc(HDC,int,int,int,int,int,int,int,int);
+BOOL BitBlt(HDC,short,short,short,short,HDC,short,short,DWORD);
+BOOL BringWindowToTop(HWND);
+BOOL CallMsgFilter(SEGPTR,short);
+BOOL ChangeClipboardChain(HWND,HWND);
+BOOL ChangeMenu(HMENU,WORD,LPSTR,WORD,WORD);
+BOOL CheckMenuItem(HMENU,WORD,WORD);
+BOOL Chord(HDC,int,int,int,int,int,int,int,int);
+BOOL CloseClipboard(void);
+BOOL DPtoLP(HDC,LPPOINT,int);
+BOOL DeleteDC(HDC);
+BOOL DeleteMenu(HMENU,WORD,WORD);
+BOOL DeleteMetaFile(HMETAFILE);
+BOOL DeleteObject(HANDLE);
+BOOL DestroyCursor(HCURSOR);
+BOOL DestroyIcon(HICON);
+BOOL DestroyMenu(HMENU);
+BOOL DestroyWindow(HWND);
+BOOL DlgDirSelect(HWND,LPSTR,int);
+BOOL DlgDirSelectComboBox(HWND,LPSTR,int);
+BOOL DrawIcon(HDC,short,short,HICON);
+BOOL Ellipse(HDC,int,int,int,int);
+BOOL EmptyClipboard(void);
+BOOL EnableHardwareInput(BOOL);
+BOOL EnableMenuItem(HMENU,WORD,WORD);
+BOOL EnableScrollBar(HWND,INT,UINT);
+BOOL EnableWindow(HWND,BOOL);
+BOOL EndDeferWindowPos(HDWP);
+BOOL EnumChildWindows(HWND,FARPROC,LONG);
+BOOL EnumMetaFile(HDC,LOCALHANDLE,FARPROC,BYTE*);
+BOOL EnumTaskWindows(HANDLE,FARPROC,LONG);
+BOOL EnumWindows(FARPROC,LONG);
+BOOL EqualRect(LPRECT,LPRECT);
+BOOL EqualRgn(HRGN,HRGN);
+BOOL ExitWindows(DWORD,WORD);
+BOOL ExtFloodFill(HDC,INT,INT,COLORREF,WORD);
+BOOL ExtTextOut(HDC,short,short,WORD,LPRECT,LPSTR,WORD,LPINT);
+BOOL FillRgn(HDC,HRGN,HBRUSH);
+BOOL FlashWindow(HWND,BOOL);
+BOOL FloodFill(HDC,INT,INT,COLORREF);
+BOOL FrameRgn(HDC,HRGN,HBRUSH,int,int);
+BOOL FreeModule(HANDLE);
+BOOL FreeResource(HANDLE);
+BOOL GetBitmapDimensionEx(HBITMAP,LPSIZE);
+BOOL GetBrushOrgEx(HDC,LPPOINT);
+BOOL GetCharWidth(HDC,WORD,WORD,LPINT);
+BOOL GetClassInfo(HANDLE,SEGPTR,LPWNDCLASS);
+BOOL GetCurrentPositionEx(HDC,LPPOINT);
+BOOL GetInputState(void);
+BOOL GetMessage(SEGPTR,HWND,UINT,UINT);
+BOOL GetTextExtentPoint(HDC,LPSTR,short,LPSIZE);
+BOOL GetTextMetrics(HDC,LPTEXTMETRIC);
+BOOL GetUpdateRect(HWND,LPRECT,BOOL);
+BOOL GetViewportExtEx(HDC,LPPOINT);
+BOOL GetViewportOrgEx(HDC,LPPOINT);
+BOOL GetWinDebugInfo(LPWINDEBUGINFO,UINT);
+BOOL GetWindowExtEx(HDC,LPPOINT);
+BOOL GetWindowOrgEx(HDC,LPPOINT);
+BOOL GetWindowPlacement(HWND,LPWINDOWPLACEMENT);
+BOOL GlobalUnWire(HGLOBAL);
+BOOL GlobalUnlock(HGLOBAL);
+BOOL GrayString(HDC,HBRUSH,FARPROC,LPARAM,INT,INT,INT,INT,INT);
+BOOL HiliteMenuItem(HWND,HMENU,WORD,WORD);
+BOOL InSendMessage(void);
+BOOL InsertMenu(HMENU,WORD,WORD,WORD,LPSTR);
+BOOL IntersectRect(LPRECT,LPRECT,LPRECT);
+BOOL InvertRgn(HDC,HRGN);
+BOOL IsBadCodePtr(SEGPTR);
+BOOL IsBadHugeReadPtr(SEGPTR,DWORD);
+BOOL IsBadHugeWritePtr(SEGPTR,DWORD);
+BOOL IsBadReadPtr(SEGPTR,WORD);
+BOOL IsBadStringPtr(SEGPTR,WORD);
+BOOL IsBadWritePtr(SEGPTR,WORD);
+BOOL IsCharAlpha(char);
+BOOL IsCharAlphaNumeric(char);
+BOOL IsCharLower(char);
+BOOL IsCharUpper(char);
+BOOL IsChild(HWND,HWND);
+BOOL IsClipboardFormatAvailable(WORD);
+BOOL IsDialogMessage(HWND,LPMSG);
+BOOL IsIconic(HWND);
+BOOL IsRectEmpty(LPRECT);
+BOOL IsTwoByteCharPrefix(char);
+BOOL IsWindow(HWND);
+BOOL IsWindowEnabled(HWND);
+BOOL IsWindowVisible(HWND);
+BOOL IsZoomed(HWND);
+BOOL KillSystemTimer(HWND,WORD);
+BOOL KillTimer(HWND,WORD);
+BOOL LPtoDP(HDC,LPPOINT,int);
+BOOL LineTo(HDC,short,short);
+BOOL LocalInit(HANDLE,WORD,WORD);
+BOOL LocalUnlock(HANDLE);
+BOOL ModifyMenu(HMENU,WORD,WORD,WORD,LPSTR);
+BOOL MoveToEx(HDC,short,short,LPPOINT);
+BOOL MoveWindow(HWND,short,short,short,short,BOOL);
+BOOL OemToAnsi(LPSTR,LPSTR);
+BOOL OffsetViewportOrgEx(HDC,short,short,LPPOINT);
+BOOL OffsetWindowOrgEx(HDC,short,short,LPPOINT);
+BOOL OpenClipboard(HWND);
+BOOL OpenIcon(HWND);
+BOOL PaintRgn(HDC,HRGN);
+BOOL PatBlt(HDC,short,short,short,short,DWORD);
+BOOL PeekMessage(LPMSG,HWND,WORD,WORD,WORD);
+BOOL Pie(HDC,int,int,int,int,int,int,int,int);
+BOOL PlayMetaFile(HDC,HANDLE);
+BOOL PolyPolygon(HDC,LPPOINT,LPINT,WORD);
+BOOL Polygon(HDC,LPPOINT,int);
+BOOL Polyline(HDC,LPPOINT,int);
+BOOL PostAppMessage(HANDLE,WORD,WORD,LONG);
+BOOL PostMessage(HWND,WORD,WORD,LONG);
+BOOL PtInRect(LPRECT,POINT);
+BOOL PtInRegion(HRGN,short,short);
+BOOL PtVisible(HDC,short,short);
+BOOL RectInRegion(HRGN,LPRECT);
+BOOL RectVisible(HDC,LPRECT);
+BOOL Rectangle(HDC,int,int,int,int);
+BOOL RedrawWindow(HWND,LPRECT,HRGN,UINT);
+BOOL RemoveFontResource(LPSTR);
+BOOL RemoveMenu(HMENU,WORD,WORD);
+BOOL ResizePalette(HPALETTE,WORD);
+BOOL RestoreDC(HDC,short);
+BOOL RoundRect(HDC,short,short,short,short,short,short);
+BOOL ScaleViewportExtEx(HDC,short,short,short,short,LPSIZE);
+BOOL ScaleWindowExtEx(HDC,short,short,short,short,LPSIZE);
+BOOL ScrollDC(HDC,short,short,LPRECT,LPRECT,HRGN,LPRECT);
+BOOL SetBitmapDimensionEx(HBITMAP,short,short,LPSIZE);
+BOOL SetConvertParams(int,int);
+BOOL SetDeskPattern(void);
+BOOL SetDeskWallPaper(LPSTR);
+BOOL SetErrorMode(WORD);
+BOOL SetMenu(HWND,HMENU);
+BOOL SetMenuItemBitmaps(HMENU,WORD,WORD,HBITMAP,HBITMAP);
+BOOL SetMessageQueue(int);
+BOOL SetProp(HWND,SEGPTR,HANDLE);
+BOOL SetViewportExtEx(HDC,short,short,LPSIZE);
+BOOL SetViewportOrgEx(HDC,short,short,LPPOINT);
+BOOL SetWinDebugInfo(LPWINDEBUGINFO);
+BOOL SetWindowExtEx(HDC,short,short,LPSIZE);
+BOOL SetWindowOrgEx(HDC,short,short,LPPOINT);
+BOOL SetWindowPlacement(HWND,LPWINDOWPLACEMENT);
+BOOL SetWindowPos(HWND,HWND,short,short,short,short,WORD);
+BOOL ShowWindow(HWND,int);
+BOOL StretchBlt(HDC,short,short,short,short,HDC,short,short,short,short,DWORD);
+BOOL SubtractRect(LPRECT,LPRECT,LPRECT);
+BOOL SwapMouseButton(BOOL);
+BOOL TextOut(HDC,short,short,LPSTR,short);
+BOOL TrackPopupMenu(HMENU,WORD,short,short,short,HWND,LPRECT);
+BOOL TranslateMDISysAccel(HWND,LPMSG);
+BOOL TranslateMessage(LPMSG);
+BOOL UnhookWindowsHook(short,FARPROC);
+BOOL UnhookWindowsHookEx(HHOOK);
+BOOL UnionRect(LPRECT,LPRECT,LPRECT);
+BOOL UnrealizeObject(HBRUSH);
+BOOL UnregisterClass(SEGPTR,HANDLE);
+BOOL WinHelp(HWND,LPSTR,WORD,DWORD);
+BOOL WritePrivateProfileString(LPSTR,LPSTR,LPSTR,LPSTR);
+BOOL WriteProfileString(LPSTR,LPSTR,LPSTR);
+BYTE GetTempDrive(BYTE);
+COLORREF GetBkColor(HDC);
+COLORREF GetSysColor(short);
+COLORREF GetTextColor(HDC);
+COLORREF SetPixel(HDC,short,short,COLORREF);
+DWORD CallNextHookEx(HHOOK,short,WPARAM,LPARAM);
+DWORD DefHookProc(short,WORD,DWORD,HHOOK*);
+DWORD GetAspectRatioFilter(HDC);
+DWORD GetBitmapDimension(HBITMAP);
+DWORD GetBrushOrg(HDC);
+DWORD GetCurrentPosition(HDC);
+DWORD GetCurrentTime(void);
+DWORD GetDCOrg(HDC);
+DWORD GetDialogBaseUnits(void);
+DWORD GetFreeSpace(WORD);
+DWORD GetHeapSpaces(HMODULE);
+DWORD GetMenuCheckMarkDimensions(void);
+DWORD GetMessagePos(void);
+DWORD GetNearestColor(HDC,DWORD);
+DWORD GetPixel(HDC,short,short);
+DWORD GetSelectorBase(WORD);
+DWORD GetSelectorLimit(WORD);
+DWORD GetTabbedTextExtent(HDC,LPSTR,int,int,LPINT);
+DWORD GetTextExtent(HDC,LPSTR,short);
+DWORD GetTickCount(void);
+DWORD GetViewportExt(HDC);
+DWORD GetViewportOrg(HDC);
+DWORD GetWindowExt(HDC);
+DWORD GetWindowOrg(HDC);
+DWORD GlobalCompact(DWORD);
+DWORD GlobalDOSAlloc(DWORD);
+DWORD GlobalHandle(WORD);
+DWORD GlobalSize(HGLOBAL);
+DWORD MoveTo(HDC,short,short);
+DWORD OemKeyScan(WORD);
+DWORD OffsetViewportOrg(HDC,short,short);
+DWORD OffsetWindowOrg(HDC,short,short);
+DWORD ScaleViewportExt(HDC,short,short,short,short);
+DWORD ScaleWindowExt(HDC,short,short,short,short);
+DWORD SetBitmapDimension(HBITMAP,short,short);
+DWORD SetBkColor(HDC,COLORREF);
+DWORD SetBrushOrg(HDC,short,short);
+DWORD SetMapperFlags(HDC,DWORD);
+DWORD SetTextColor(HDC,DWORD);
+DWORD SetViewportExt(HDC,short,short);
+DWORD SetViewportOrg(HDC,short,short);
+DWORD SetWindowExt(HDC,short,short);
+DWORD SetWindowOrg(HDC,short,short);
+DWORD SizeofResource(HANDLE,HRSRC);
+FARPROC GetProcAddress(HANDLE,SEGPTR);
+FARPROC LocalNotify(FARPROC);
+FARPROC MakeProcInstance(FARPROC,HANDLE);
+FARPROC SetResourceHandler(HANDLE,LPSTR,FARPROC);
+FARPROC SetWindowsHook(short,FARPROC);
+HANDLE CopyMetaFile(HANDLE,LPSTR);
+HANDLE CreateCursorIconIndirect(HANDLE,CURSORICONINFO*,LPSTR,LPSTR);
+HANDLE CreateMetaFile(LPSTR);
+HANDLE DirectResAlloc(HANDLE,WORD,WORD);
+HANDLE FindResource(HANDLE,SEGPTR,SEGPTR);
+HANDLE GetAtomHandle(ATOM);
+HANDLE GetClipboardData(WORD);
+HANDLE GetCodeHandle(FARPROC);
+HANDLE GetCurrentPDB(void);
+HANDLE GetCurrentTask(void);
+HANDLE GetMetaFile(LPSTR);
+HANDLE GetMetaFileBits(HANDLE);
+HANDLE GetModuleHandle(LPCSTR);
+HANDLE GetProp(HWND,SEGPTR);
+HANDLE GetStockObject(int);
+HANDLE GetWindowTask(HWND);
+HANDLE LoadAccelerators(HANDLE,SEGPTR);
+HANDLE LoadLibrary(LPCSTR);
+HANDLE LoadModule(LPCSTR,LPVOID);
+HANDLE LoadResource(HANDLE,HANDLE);
+HANDLE LocalAlloc(WORD,WORD);
+HANDLE LocalFree(HANDLE);
+HANDLE LocalHandle(WORD);
+HANDLE LocalReAlloc(HANDLE,WORD,WORD);
+HANDLE RemoveProp(HWND,SEGPTR);
+HANDLE SelectObject(HDC,HANDLE);
+HANDLE SetClipboardData(WORD,HANDLE);
+HANDLE SetMetaFileBits(HANDLE);
+HANDLE WinExec(LPSTR,WORD);
+HBITMAP CreateBitmap(short,short,BYTE,BYTE,LPSTR);
+HBITMAP CreateBitmapIndirect(BITMAP*);
+HBITMAP CreateCompatibleBitmap(HDC,short,short);
+HBITMAP CreateDIBitmap(HDC,LPBITMAPINFOHEADER,DWORD,LPSTR,LPBITMAPINFO,WORD);
+HBITMAP CreateDiscardableBitmap(HDC,short,short);
+HBITMAP LoadBitmap(HANDLE,SEGPTR);
+HBRUSH CreateBrushIndirect(LOGBRUSH*);
+HBRUSH CreateDIBPatternBrush(HANDLE,WORD);
+HBRUSH CreateHatchBrush(short,COLORREF);
+HBRUSH CreatePatternBrush(HBITMAP);
+HBRUSH CreateSolidBrush(DWORD);
+HBRUSH GetControlBrush(HWND,HDC,WORD);
+HCURSOR CreateCursor(HANDLE,INT,INT,INT,INT,LPSTR,LPSTR);
+HCURSOR GetCursor(void);
+HCURSOR LoadCursor(HANDLE,SEGPTR);
+HCURSOR SetCursor(HCURSOR);
+HDC BeginPaint(HWND,LPPAINTSTRUCT);
+HDC CreateCompatibleDC(HDC);
+HDC CreateDC(LPSTR,LPSTR,LPSTR,LPSTR);
+HDC CreateIC(LPSTR,LPSTR,LPSTR,LPSTR);
+HDC GetDC(HWND);
+HDC GetDCEx(HWND,HRGN,DWORD);
+HDC GetDCState(HDC);
+HDC GetWindowDC(HWND);
+HDWP BeginDeferWindowPos(INT);
+HDWP DeferWindowPos(HDWP,HWND,HWND,INT,INT,INT,INT,WORD);
+HFONT CreateFont(int,int,int,int,int,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,LPSTR);
+HFONT CreateFontIndirect(LOGFONT*);
+HGLOBAL AllocResource(HINSTANCE,HRSRC,DWORD);
+HGLOBAL GetTaskQueue(HTASK);
+HGLOBAL GlobalAlloc(WORD,DWORD);
+HGLOBAL GlobalFree(HGLOBAL);
+HGLOBAL GlobalLRUNewest(HGLOBAL);
+HGLOBAL GlobalLRUOldest(HGLOBAL);
+HGLOBAL GlobalReAlloc(HGLOBAL,DWORD,WORD);
+HGLOBAL LockSegment(HGLOBAL);
+HGLOBAL SetTaskQueue(HTASK,HGLOBAL);
+HHOOK SetWindowsHookEx(short,HOOKPROC,HINSTANCE,HTASK);
+HICON CreateIcon(HANDLE,INT,INT,BYTE,BYTE,LPSTR,LPSTR);
+HICON LoadIcon(HANDLE,SEGPTR);
+HINSTANCE GetTaskDS(void);
+HMENU CreateMenu(void);
+HMENU CreatePopupMenu(void);
+HMENU GetMenu(HWND);
+HMENU GetSubMenu(HMENU,short);
+HMENU GetSystemMenu(HWND,BOOL);
+HMENU LoadMenu(HANDLE,SEGPTR);
+HMENU LoadMenuIndirect(LPSTR);
+HMENU LookupMenuHandle(HMENU,INT);
+HMETAFILE CloseMetaFile(HANDLE);
+HMODULE GetExePtr(HANDLE);
+HPALETTE CreatePalette(LPLOGPALETTE);
+HPALETTE GDISelectPalette(HDC,HPALETTE);
+HPALETTE SelectPalette(HDC,HPALETTE,BOOL);
+HPEN CreatePen(short,short,COLORREF);
+HPEN CreatePenIndirect(LOGPEN*);
+HRGN CreateEllipticRgn(short,short,short,short);
+HRGN CreateEllipticRgnIndirect(LPRECT);
+HRGN CreatePolyPolygonRgn(LPPOINT,LPINT,short,short);
+HRGN CreatePolygonRgn(LPPOINT,short,short);
+HRGN CreateRectRgn(short,short,short,short);
+HRGN CreateRectRgnIndirect(LPRECT);
+HRGN CreateRoundRectRgn(short,short,short,short,short,short);
+HRGN GetClipRgn(HDC);
+HRGN InquireVisRgn(HDC);
+HRGN SaveVisRgn(HDC);
+HWND ChildWindowFromPoint(HWND,POINT);
+HWND CreateDialog(HANDLE,SEGPTR,HWND,WNDPROC);
+HWND CreateDialogIndirect(HANDLE,SEGPTR,HWND,WNDPROC);
+HWND CreateDialogIndirectParam(HANDLE,SEGPTR,HWND,WNDPROC,LPARAM);
+HWND CreateDialogParam(HANDLE,SEGPTR,HWND,WNDPROC,LPARAM);
+HWND CreateWindow(SEGPTR,SEGPTR,DWORD,INT,INT,INT,INT,HWND,HMENU,HINSTANCE,SEGPTR);
+HWND CreateWindowEx(DWORD,SEGPTR,SEGPTR,DWORD,INT,INT,INT,INT,HWND,HMENU,HINSTANCE,SEGPTR);
+HWND FindWindow(SEGPTR,LPSTR);
+HWND GetActiveWindow(void);
+HWND GetCapture(void);
+HWND GetClipboardOwner(void);
+HWND GetClipboardViewer(void);
+HWND GetDesktopHwnd(void);
+HWND GetDesktopWindow(void);
+HWND GetDlgItem(HWND,WORD);
+HWND GetFocus(void);
+HWND GetLastActivePopup(HWND);
+HWND GetNextDlgGroupItem(HWND,HWND,BOOL);
+HWND GetNextDlgTabItem(HWND,HWND,BOOL);
+HWND GetNextWindow(HWND,WORD);
+HWND GetOpenClipboardWindow(void);
+HWND GetParent(HWND);
+HWND GetSysModalWindow(void);
+HWND GetTopWindow(HWND);
+HWND GetWindow(HWND,WORD);
+HWND SetActiveWindow(HWND);
+HWND SetCapture(HWND);
+HWND SetClipboardViewer(HWND);
+HWND SetFocus(HWND);
+HWND SetParent(HWND,HWND);
+HWND SetSysModalWindow(HWND);
+HWND WindowFromPoint(POINT);
+INT AccessResource(HINSTANCE,HRSRC);
+INT AddFontResource(LPCSTR);
+INT AnsiToOem(LPSTR,LPSTR);
+INT GetTempFileName(BYTE,LPCSTR,UINT,LPSTR);
+INT GetTextFace(HDC,INT,LPSTR);
+INT OpenFile(LPCSTR,LPOFSTRUCT,UINT);
+INT _lclose(INT);
+INT _lcreat(LPSTR,INT);
+INT _lopen(LPSTR,INT);
+INT _lread(INT,LPSTR,WORD);
+INT _lwrite(INT,LPCSTR,WORD);
+INT lstrcmp(LPCSTR,LPCSTR);
+INT lstrcmpi(LPCSTR,LPCSTR);
+INT lstrlen(LPCSTR);
+LONG CallWindowProc(WNDPROC,HWND,UINT,WPARAM,LPARAM);
+LONG DefDlgProc(HWND,UINT,WPARAM,LPARAM);
+LONG DefFrameProc(HWND,HWND,UINT,WPARAM,LPARAM);
+LONG DefMDIChildProc(HWND,UINT,WPARAM,LPARAM);
+LONG DispatchMessage(LPMSG);
+LONG EscapeCommFunction(int,int);
+LONG GetBitmapBits(HBITMAP,LONG,LPSTR);
+LONG GetClassLong(HWND,short);
+LONG GetMessageExtraInfo(void);
+LONG GetMessageTime(void);
+LONG GetVersion(void);
+LONG GetWinFlags(void);
+LONG GetWindowLong(HWND,short);
+LONG SendDlgItemMessage(HWND,INT,UINT,WPARAM,LPARAM);
+LONG SetBitmapBits(HBITMAP,LONG,LPSTR);
+LONG SetClassLong(HWND,short,LONG);
+LONG SetSwapAreaSize(WORD);
+LONG SetWindowLong(HWND,short,LONG);
+LONG TabbedTextOut(HDC,short,short,LPSTR,short,short,LPINT,short);
+LONG _hread(INT,LPSTR,LONG);
+LONG _hwrite(INT,LPCSTR,LONG);
+LONG _llseek(INT,LONG,INT);
+LPINT GetThresholdEvent(void);
+LPSTR AnsiLower(LPSTR);
+LPSTR AnsiUpper(LPSTR);
+LPSTR LockResource(HANDLE);
+LPSTR ValidateFreeSpaces(void);
+LPVOID GlobalLock(HGLOBAL);
+LRESULT DefWindowProc(HWND,UINT,WPARAM,LPARAM);
+LRESULT SendMessage(HWND,UINT,WPARAM,LPARAM);
+NPVOID LocalLock(HLOCAL);
+SEGPTR AnsiNext(SEGPTR);
+SEGPTR AnsiPrev(SEGPTR,SEGPTR);
+SEGPTR GetDOSEnvironment(void);
+SEGPTR GlobalWire(HGLOBAL);
+SEGPTR WIN16_GlobalLock(HGLOBAL);
+SEGPTR WIN16_LockResource(HANDLE);
+SEGPTR lstrcat(SEGPTR,SEGPTR);
+SEGPTR lstrcpy(SEGPTR,SEGPTR);
+SEGPTR lstrcpyn(SEGPTR,SEGPTR,WORD);
+UINT AnsiLowerBuff(LPSTR,UINT);
+UINT AnsiUpperBuff(LPSTR,UINT);
+UINT GDIRealizePalette(HDC);
+UINT RealizePalette(HDC);
+WORD AllocCStoDSAlias(WORD);
+WORD AllocDStoCSAlias(WORD);
+WORD AllocSelector(WORD);
+WORD AllocSelectorArray(WORD);
+WORD ArrangeIconicWindows(HWND);
+WORD ChangeSelector(WORD,WORD);
+WORD EnumClipboardFormats(WORD);
+WORD FarGetOwner(HANDLE);
+WORD FreeSelector(WORD);
+WORD GetAtomName(ATOM,LPSTR,short);
+WORD GetBkMode(HDC);
+WORD GetCaretBlinkTime(void);
+WORD GetClassWord(HWND,short);
+WORD GetCommEventMask(int,int);
+WORD GetDlgItemInt(HWND,WORD,BOOL*,BOOL);
+WORD GetDoubleClickTime(void);
+WORD GetDriveType(INT);
+WORD GetInternalWindowPos(HWND,LPRECT,LPPOINT);
+WORD GetMapMode(HDC);
+WORD GetMenuItemCount(HMENU);
+WORD GetMenuItemID(HMENU,int);
+WORD GetMenuState(HMENU,WORD,WORD);
+WORD GetNearestPaletteIndex(HPALETTE,DWORD);
+WORD GetNumTasks(void);
+WORD GetPaletteEntries(HPALETTE,WORD,WORD,LPPALETTEENTRY);
+WORD GetPolyFillMode(HDC);
+WORD GetPrivateProfileInt(LPSTR,LPSTR,short,LPSTR);
+WORD GetProfileInt(LPSTR,LPSTR,int);
+WORD GetROP2(HDC);
+WORD GetRelAbs(HDC);
+WORD GetStretchBltMode(HDC);
+WORD GetSystemDirectory(LPSTR,WORD);
+WORD GetSystemPaletteEntries(HDC,WORD,WORD,LPPALETTEENTRY);
+WORD GetSystemPaletteUse(HDC);
+WORD GetTextAlign(HDC);
+WORD GetWindowWord(HWND,short);
+WORD GetWindowsDirectory(LPSTR,WORD);
+WORD GlobalDOSFree(WORD);
+WORD GlobalFlags(HGLOBAL);
+WORD GlobalGetAtomName(ATOM,LPSTR,short);
+WORD GlobalPageLock(HGLOBAL);
+WORD GlobalPageUnlock(HGLOBAL);
+WORD InitAtomTable(WORD);
+WORD IsDlgButtonChecked(HWND,WORD);
+WORD LocalCompact(WORD);
+WORD LocalFlags(HLOCAL);
+WORD LocalShrink(HANDLE,WORD);
+WORD LocalSize(HLOCAL);
+WORD MapVirtualKey(WORD,WORD);
+WORD PrestoChangoSelector(WORD,WORD);
+WORD RealizeDefaultPalette(HDC);
+WORD RegisterClipboardFormat(LPCSTR);
+WORD RegisterWindowMessage(SEGPTR);
+WORD SelectorAccessRights(WORD,WORD,WORD);
+WORD SetBkMode(HDC,WORD);
+WORD SetClassWord(HWND,short,WORD);
+WORD SetHandleCount(WORD);
+WORD SetMapMode(HDC,WORD);
+WORD SetPaletteEntries(HPALETTE,WORD,WORD,LPPALETTEENTRY);
+WORD SetPolyFillMode(HDC,WORD);
+WORD SetROP2(HDC,WORD);
+WORD SetRelAbs(HDC,WORD);
+WORD SetSelectorBase(WORD,DWORD);
+WORD SetSelectorLimit(WORD,DWORD);
+WORD SetStretchBltMode(HDC,WORD);
+WORD SetSystemPaletteUse(HDC,WORD);
+WORD SetSystemTimer(HWND,WORD,WORD,FARPROC);
+WORD SetTextAlign(HDC,WORD);
+WORD SetTimer(HWND,WORD,WORD,FARPROC);
+WORD SetWindowWord(HWND,short,WORD);
+WORD VkKeyScan(WORD);
+WORD* SetCommEventMask(int,WORD);
+int BuildCommDCB(LPSTR,DCB*);
+int Catch(LPCATCHBUF);
+int ClearCommBreak(int);
+int CloseComm(int);
+int CombineRgn(HRGN,HRGN,HRGN,short);
+int ConvertRequest(HWND,LPKANJISTRUCT);
+int CountClipboardFormats(void);
+int CountVoiceNotes(int);
+int DialogBox(HINSTANCE,SEGPTR,HWND,WNDPROC);
+int DialogBoxIndirect(HANDLE,HANDLE,HWND,WNDPROC);
+int DialogBoxIndirectParam(HANDLE,HANDLE,HWND,WNDPROC,LONG);
+int DialogBoxParam(HANDLE,SEGPTR,HWND,WNDPROC,LONG);
+int DlgDirList(HWND,LPSTR,int,int,WORD);
+int DlgDirListComboBox(HWND,SEGPTR,int,int,WORD);
+int DrawText(HDC,LPSTR,int,LPRECT,WORD);
+int EnumFonts(HDC,LPSTR,FARPROC,LPSTR);
+int EnumObjects(HDC,int,FARPROC,LPSTR);
+int EnumProps(HWND,FARPROC);
+int Escape(HDC,int,int,LPSTR,LPSTR);
+int ExcludeClipRect(HDC,short,short,short,short);
+int ExcludeUpdateRgn(HDC,HWND);
+int ExcludeVisRect(HDC,short,short,short,short);
+int FillRect(HDC,LPRECT,HBRUSH);
+int FlushComm(int,int);
+int FrameRect(HDC,LPRECT,HBRUSH);
+int GetAsyncKeyState(int);
+int GetClassName(HWND,LPSTR,short);
+int GetClipBox(HDC,LPRECT);
+int GetClipboardFormatName(WORD,LPSTR,short);
+int GetCommError(int,COMSTAT*);
+int GetCommState(int,DCB*);
+int GetDIBits(HDC,HANDLE,WORD,WORD,LPSTR,LPBITMAPINFO,WORD);
+int GetDeviceCaps(HDC,WORD);
+int GetDlgCtrlID(HWND);
+int GetDlgItemText(HWND,WORD,SEGPTR,WORD);
+int GetEnvironment(LPSTR,LPSTR,WORD);
+int GetInstanceData(HANDLE,WORD,int);
+int GetKBCodePage(void);
+int GetKeyNameText(LONG,LPSTR,int);
+int GetKeyState(int);
+int GetKeyboardType(int);
+int GetMenuString(HMENU,WORD,LPSTR,short,WORD);
+int GetModuleFileName(HANDLE,LPSTR,short);
+int GetModuleUsage(HANDLE);
+int GetObject(HANDLE,int,LPSTR);
+int GetPriorityClipboardFormat(WORD*,short);
+int GetProfileString(LPSTR,LPSTR,LPSTR,LPSTR,int);
+int GetRgnBox(HRGN,LPRECT);
+int GetScrollPos(HWND,int);
+int GetSystemMetrics(WORD);
+int GetThresholdStatus(void);
+int GetUpdateRgn(HWND,HRGN,BOOL);
+int GetWindowText(HWND,LPSTR,int);
+int GetWindowTextLength(HWND);
+int IntersectClipRect(HDC,short,short,short,short);
+int IntersectVisRect(HDC,short,short,short,short);
+int LoadString(HANDLE,WORD,LPSTR,int);
+int MessageBox(HWND,LPSTR,LPSTR,WORD);
+int MulDiv(int,int,int);
+int OffsetClipRgn(HDC,short,short);
+int OffsetRgn(HRGN,short,short);
+int OpenComm(LPSTR,WORD,WORD);
+int OpenSound(void);
+int ProfInsChk(void);
+int ReadComm(int,LPSTR,int);
+int ReleaseDC(HWND,HDC);
+int RestoreVisRgn(HDC);
+int SaveDC(HDC);
+int ScrollWindowEx(HWND,short,short,LPRECT,LPRECT,HRGN,LPRECT,WORD);
+int SelectClipRgn(HDC,HRGN);
+int SelectVisRgn(HDC,HRGN);
+int SetCommBreak(int);
+int SetCommState(DCB*);
+int SetDIBits(HDC,HANDLE,WORD,WORD,LPSTR,LPBITMAPINFO,WORD);
+int SetDIBitsToDevice(HDC,short,short,WORD,WORD,WORD,WORD,WORD,WORD,LPSTR,LPBITMAPINFO,WORD);
+int SetEnvironment(LPSTR,LPSTR,WORD);
+int SetScrollPos(HWND,int,int,BOOL);
+int SetSoundNoise(int,int);
+int SetVoiceAccent(int,int,int,int,int);
+int SetVoiceEnvelope(int,int,int);
+int SetVoiceNote(int,int,int,int);
+int SetVoiceQueueSize(int,int);
+int SetVoiceSound(int,LONG,int);
+int SetVoiceThreshold(int,int);
+int ShowCursor(BOOL);
+int StartSound(void);
+int StopSound(void);
+int StretchDIBits(HDC,WORD,WORD,WORD,WORD,WORD,WORD,WORD,WORD,LPSTR,LPBITMAPINFO,WORD,DWORD);
+int SyncAllVoices(void);
+int Throw(LPCATCHBUF,int);
+int ToAscii(WORD,WORD,LPSTR,LPVOID,WORD);
+int TranslateAccelerator(HWND,HANDLE,LPMSG);
+int TransmitCommChar(int,char);
+int UngetCommChar(int,char);
+int UpdateColors(HDC);
+int WaitSoundState(int);
+int WriteComm(int,LPSTR,int);
+int wvsprintf(LPSTR,LPSTR,LPSTR);
+short GetPrivateProfileString(LPSTR,LPSTR,LPSTR,LPSTR,short,LPSTR);
+short GetTextCharacterExtra(HDC);
+short SetTextCharacterExtra(HDC,short);
+short SetTextJustification(HDC,short,short);
+void AdjustWindowRect(LPRECT,DWORD,BOOL);
+void AdjustWindowRectEx(LPRECT,DWORD,BOOL,DWORD);
+void AnimatePalette(HPALETTE,UINT,UINT,LPPALETTEENTRY);
+void AnsiToOemBuff(LPSTR,LPSTR,INT);
+void CheckDlgButton(HWND,WORD,WORD);
+void CheckRadioButton(HWND,WORD,WORD,WORD);
+void ClientToScreen(HWND,LPPOINT);
+void ClipCursor(LPRECT);
+void CloseSound(void);
+void CloseWindow(HWND);
+void CopyRect(LPRECT,LPRECT);
+void CreateCaret(HWND,HBITMAP,short,short);
+void DebugBreak(void);
+void DestroyCaret(void);
+void DirectedYield(HTASK);
+void DrawFocusRect(HDC,LPRECT);
+void DrawMenuBar(HWND);
+void EndDialog(HWND,short);
+void EndPaint(HWND,LPPAINTSTRUCT);
+void FarSetOwner(HANDLE,WORD);
+void FatalExit(int);
+void FillWindow(HWND,HWND,HDC,HBRUSH);
+void FreeLibrary(HANDLE);
+void FreeProcInstance(FARPROC);
+void GetCaretPos(LPPOINT);
+void GetClientRect(HWND,LPRECT);
+void GetCodeInfo(FARPROC,LPVOID);
+void GetCursorPos(LPPOINT);
+void GetKeyboardState(BYTE*);
+void GetScrollRange(HWND,int,LPINT,LPINT);
+void GetWindowRect(HWND,LPRECT);
+void GlobalFix(HGLOBAL);
+void GlobalFreeAll(HANDLE);
+void GlobalNotify(FARPROC);
+void GlobalUnfix(HGLOBAL);
+void HideCaret(HWND);
+void InflateRect(LPRECT,short,short);
+void InvalidateRect(HWND,LPRECT,BOOL);
+void InvalidateRgn(HWND,HRGN,BOOL);
+void InvertRect(HDC,LPRECT);
+void LimitEmsPages(DWORD);
+void LineDDA(short,short,short,short,FARPROC,long);
+void MapDialogRect(HWND,LPRECT);
+void MapWindowPoints(HWND,HWND,LPPOINT,WORD);
+void MessageBeep(WORD);
+void OemToAnsiBuff(LPSTR,LPSTR,INT);
+void OffsetRect(LPRECT,short,short);
+void OutputDebugString(LPSTR);
+void PaintRect(HWND,HWND,HDC,HBRUSH,LPRECT);
+void PlayMetaFileRecord(HDC,LPHANDLETABLE,LPMETARECORD,WORD);
+void PostQuitMessage(int);
+void ProfClear(void);
+void ProfFinish(void);
+void ProfFlush(void);
+void ProfSampRate(int,int);
+void ProfSetup(int,int);
+void ProfStart(void);
+void ProfStop(void);
+void ReleaseCapture(void);
+void ReplyMessage(LONG);
+void ScreenToClient(HWND,LPPOINT);
+void ScrollWindow(HWND,short,short,LPRECT,LPRECT);
+void SetCaretBlinkTime(WORD);
+void SetCaretPos(short,short);
+void SetConvertHook(BOOL);
+void SetCursorPos(short,short);
+void SetDCState(HDC,HDC);
+void SetDlgItemInt(HWND,WORD,WORD,BOOL);
+void SetDlgItemText(HWND,WORD,SEGPTR);
+void SetDoubleClickTime(WORD);
+void SetInternalWindowPos(HWND,WORD,LPRECT,LPPOINT);
+void SetKeyboardState(BYTE*);
+void SetRect(LPRECT,short,short,short,short);
+void SetRectEmpty(LPRECT);
+void SetRectRgn(HRGN,short,short,short,short);
+void SetScrollRange(HWND,int,int,int,BOOL);
+void SetSysColors(int,LPINT,COLORREF*);
+void SetWindowText(HWND,LPSTR);
+void ShowCaret(HWND);
+void ShowOwnedPopups(HWND,BOOL);
+void ShowScrollBar(HWND,WORD,BOOL);
+void SwapRecording(WORD);
+void SwitchStackBack(void);
+void SwitchStackTo(WORD,WORD,WORD);
+void UnlockSegment(HGLOBAL);
+void UpdateWindow(HWND);
+void ValidateCodeSegments(void);
+void ValidateRect(HWND,LPRECT);
+void ValidateRgn(HWND,HRGN);
+void WaitMessage(void);
+void Yield(void);
 
 #ifdef WINELIB
 #define WINELIB_UNIMP(x) fprintf (stderr, "WineLib: Unimplemented %s\n", x)
diff --git a/include/wine.h b/include/wine.h
index 5dee98a..f6748e0 100644
--- a/include/wine.h
+++ b/include/wine.h
@@ -7,7 +7,19 @@
 #define WINE_INI WineIniFileName()
 #define WIN_INI WinIniFileName()
 
-#ifdef linux
+#ifdef i386
+extern int runtime_cpu (void);
+#else
+static inline int runtime_cpu(void) { return 3; }
+#endif
+
+
+#if defined ( linux) || defined(__svr4__)
+/*
+ * SVR4 NOTE:
+ * This is not correct but gets it through the compiler
+ * Must come back and look at this again
+ */
 struct sigcontext_struct {
 	unsigned short sc_gs, __gsh;
 	unsigned short sc_fs, __fsh;
@@ -32,8 +44,14 @@
 	unsigned long oldmask;
 	unsigned long cr2;
 };
+#ifdef linux
 #define WINE_DATA_SELECTOR 0x2b
 #define WINE_CODE_SELECTOR 0x23
+#endif
+#ifdef __svr4__
+#define WINE_DATA_SELECTOR 0x1f
+#define WINE_CODE_SELECTOR 0x17
+#endif
 #endif  /* linux */
 
 #ifdef __NetBSD__
diff --git a/include/winsock.h b/include/winsock.h
index 63e92bb..46471ac 100644
--- a/include/winsock.h
+++ b/include/winsock.h
@@ -64,6 +64,7 @@
 
 #ifndef _SYS_SOCKET_H_
 #ifndef _sys_socket_h
+#ifndef _NET_TRANSPORT_SOCKET_H
 /*
  * Structure used by kernel to pass protocol
  * information in raw sockets.
@@ -74,10 +75,14 @@
 };
 #endif
 #endif
+#endif
 
 /*
  * Maximum queue length specifiable by listen.
  */
+#ifdef SOMAXCONN
+#undef SOMAXCONN
+#endif
 #define SOMAXCONN       5
 
 #ifndef MSG_DONTROUTE
diff --git a/include/wintypes.h b/include/wintypes.h
index 74e3feb..348af36 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -1,17 +1,40 @@
 #ifndef __WINE_WINTYPES_H
 #define __WINE_WINTYPES_H
 
+#ifdef WINELIB
+# ifdef WINELIB16
+#  undef WINELIB32
+# else
+#  ifndef WINELIB32
+#   define WINELIB32
+#  endif
+# endif
+#endif
+
 typedef short	INT;
 typedef unsigned short UINT;
+#define UIFMT "%hu"
 typedef unsigned short WORD;
 typedef unsigned long DWORD;
 typedef unsigned short BOOL;
 typedef unsigned char BYTE;
 typedef long LONG;
+#ifdef WINELIB32
+typedef LONG WPARAM;
+#else
 typedef UINT WPARAM;
+#endif
 typedef LONG LPARAM;
 typedef LONG LRESULT;
+#ifdef WINELIB32
+typedef void* HANDLE;
+typedef void* NPVOID;
+#define NPFMT "%p"
+#else
 typedef WORD HANDLE;
+typedef WORD NPVOID;
+#define NPFMT "%04X"
+#endif
 typedef DWORD HHOOK;
 typedef DWORD SEGPTR;
 typedef char *LPSTR;
@@ -23,17 +46,8 @@
 typedef DWORD *LPDWORD;
 typedef LONG *LPLONG;
 typedef void *LPVOID;
-#ifdef WINELIB
-typedef long (*FARPROC)();
-typedef LONG (*WNDPROC)(WORD,WORD,WORD,LONG);
-#else
-typedef SEGPTR FARPROC;
-typedef SEGPTR WNDPROC;
-#endif
-typedef FARPROC DLGPROC;
 typedef WORD CATCHBUF[9];
 typedef WORD *LPCATCHBUF;
-typedef FARPROC HOOKPROC;
 
 #define DECLARE_HANDLE(a) typedef HANDLE a;
 
@@ -61,6 +75,16 @@
 DECLARE_HANDLE(HWND);
 DECLARE_HANDLE(LOCALHANDLE);
 
+#ifdef WINELIB
+typedef long (*FARPROC)();
+typedef LRESULT (*WNDPROC)(HWND,UINT,WPARAM,LPARAM);
+#else
+typedef SEGPTR FARPROC;
+typedef SEGPTR WNDPROC;
+#endif
+typedef FARPROC DLGPROC;
+typedef FARPROC HOOKPROC;
+
 #define TRUE 1
 #define FALSE 0
 #define CW_USEDEFAULT ((INT)0x8000)
diff --git a/ipc/Imakefile b/ipc/Imakefile
deleted file mode 100644
index e9e82a1..0000000
--- a/ipc/Imakefile
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = ipc
-
-SRCS =    bit_array.c \
-          dde_proc.c  \
-          shm_main_blk.c \
-	  dde_atom.c  \
-          shm_semaph.c \
-	  dde_mem.c \
-          shm_block.c \
-          shm_fragment.c
-
-OBJS = $(SRCS:.c=.o)
-
-SHM_OBJ=shm_block.o shm_semaph.o shm_main_blk.o dde_proc.o \
-               	   dde_mem.o bit_array.o shm_fragment.o wine_test_stub.o
-
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-
-DependTarget()
-
-tests:: dde_mem_test dde_proc_test dde_atom_test shm_fragment_test \
-        shm_semaph_test
-
-NormalProgramTarget(bit_array_test, bit_array.o bit_array_test.o,,,)
-NormalProgramTarget(shm_semaph_test, shm_semaph_test.o shm_semaph.o,,,)
-NormalProgramTarget(shm_fragment_test, shm_fragment_test.o shm_fragment.o,,,)
-NormalProgramTarget(dde_atom_test, dde_atom_test.o dde_atom.o $(SHM_OBJ),,,)
-NormalProgramTarget(dde_mem_test, dde_mem_test.o $(SHM_OBJ),,,)
-NormalProgramTarget(dde_proc_test, dde_proc_test.o $(SHM_OBJ) ,,,)
-
-
-includes::
-
-install::
diff --git a/loader/Imakefile b/loader/Imakefile
deleted file mode 100644
index 848d137..0000000
--- a/loader/Imakefile
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = loader
-
-SRCS = \
-	main.c \
-	module.c \
-	ne_image.c \
-	ne_resource.c \
-	pe_image.c \
-	pe_resource.c \
-	signal.c \
-	resource.c \
-	task.c 
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/loader/main.c b/loader/main.c
index 9bb0185..de7df1e 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -17,6 +17,7 @@
 #include "comm.h"
 #include "user.h"
 #include "menu.h"
+#include "kernel32.h"
 #include "atom.h"
 #include "dialog.h"
 #include "message.h"
@@ -29,12 +30,15 @@
 #include "miscemu.h"
 #include "neexe.h"
 #include "options.h"
+#include "spy.h"
 #include "task.h"
 #include "dce.h"
 #include "pe_image.h"
 #include "stddebug.h"
 #include "debug.h"
 
+void init_wine_signals(void);
+
 
 /***********************************************************************
  *           Main initialisation routine
@@ -48,11 +52,13 @@
 
     SpyInit();
 
+#ifndef WINELIB
       /* Initialize relay code */
     if (!RELAY_Init()) return 0;
 
       /* Initialize Win32 relay code */
     if (!RELAY32_Init()) return 0;
+#endif
 
       /* Create built-in modules */
     if (!MODULE_Init()) return 0;
@@ -63,6 +69,7 @@
       /* Initialize tasks */
     if (!TASK_Init()) return 0;
 
+#ifndef WINELIB
       /* Initialize interrupt vectors */
     if (!INT_Init()) return 0;
 
@@ -71,6 +78,7 @@
 
       /* Initialize signal handling */
     init_wine_signals();
+#endif
 
       /* Initialize communications */
     COMM_Init();
@@ -102,6 +110,9 @@
       /* Initialize menus */
     if (!MENU_Init()) return 0;
 
+      /* Initialize Win32 data structures */
+    if (!KERN32_Init()) return 0;
+
       /* Create system message queue */
     queueSize = GetProfileInt( "windows", "TypeAhead", 120 );
     if (!MSG_CreateSysMsgQueue( queueSize )) return 0;
diff --git a/loader/module.c b/loader/module.c
index 928b647..e48ed03 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -30,62 +30,89 @@
 
 
 /***********************************************************************
+ *           MODULE_LoadBuiltin
+ *
+ * Load a built-in module. If the 'force' parameter is FALSE, we only
+ * load the module if it has not been disabled via the -dll option.
+ */
+static HMODULE MODULE_LoadBuiltin( LPCSTR name, BOOL force )
+{
+#ifndef WINELIB /* JBP: Not really allowed in libwine.a (FIXME:?) */
+    HMODULE hModule;
+    NE_MODULE *pModule;
+    SEGTABLEENTRY *pSegTable;
+    struct dll_table_s *table;
+    int i;
+    char dllname[16], *p;
+
+    /* Fix the name in case we have a full path and extension */
+
+    if ((p = strrchr( name, '\\' ))) name = p + 1;
+    strncpy( dllname, name, 15 );
+    dllname[15] = '\0';
+    if ((p = strrchr( dllname, '.' ))) *p = '\0';
+
+    for (i = 0, table = dll_builtin_table; i < N_BUILTINS; i++, table++)
+        if (!strcasecmp( table->name, dllname )) break;
+    if (i >= N_BUILTINS) return 0;
+    if (!table->used && !force) return 0;
+
+    hModule = GLOBAL_CreateBlock( GMEM_MOVEABLE, table->module_start,
+                                  table->module_end - table->module_start,
+                                  0, FALSE, FALSE, FALSE, NULL );
+    if (!hModule) return 0;
+    FarSetOwner( hModule, hModule );
+
+    table->hModule = hModule;
+
+    dprintf_module( stddeb, "Built-in %s: hmodule=%04x\n",
+                    table->name, hModule );
+
+    /* Allocate the code segment */
+
+    pModule = (NE_MODULE *)GlobalLock( hModule );
+    pSegTable = NE_SEG_TABLE( pModule );
+
+    pSegTable->selector = GLOBAL_CreateBlock( GMEM_FIXED, table->code_start,
+                                              pSegTable->minsize, hModule,
+                                              TRUE, TRUE, FALSE, NULL );
+    if (!pSegTable->selector) return 0;
+    pSegTable++;
+
+    /* Allocate the data segment */
+
+    pSegTable->selector = GLOBAL_Alloc( GMEM_FIXED, pSegTable->minsize,
+                                        hModule, FALSE, FALSE, FALSE );
+    if (!pSegTable->selector) return 0;
+    memcpy( GlobalLock( pSegTable->selector ),
+            table->data_start, pSegTable->minsize );
+
+    pModule->next = hFirstModule;
+    hFirstModule = hModule;
+    return hModule;
+}
+
+
+/***********************************************************************
  *           MODULE_Init
  *
  * Create the built-in modules.
  */
 BOOL MODULE_Init(void)
 {
-    HMODULE hModule;
-    NE_MODULE *pModule;
-    SEGTABLEENTRY *pSegTable;
-    struct dll_table_s *table;
-    int i;
+    /* For these, built-in modules are always used */
 
-      /* Create the built-in modules */
+    if (!MODULE_LoadBuiltin( "KERNEL", TRUE ) ||
+        !MODULE_LoadBuiltin( "GDI", TRUE ) ||
+        !MODULE_LoadBuiltin( "USER", TRUE ) ||
+        !MODULE_LoadBuiltin( "WINPROCS", TRUE )) return FALSE;
 
-    for (i = 0, table = dll_builtin_table; i < N_BUILTINS; i++, table++)
-    {
-        if (!table->used) continue;
-
-        hModule = GLOBAL_CreateBlock( GMEM_MOVEABLE, table->module_start,
-                                      table->module_end - table->module_start,
-                                      0, FALSE, FALSE, FALSE, NULL );
-        if (!hModule) return FALSE;
-        FarSetOwner( hModule, hModule );
-
-        table->hModule = hModule;
-
-        dprintf_module( stddeb, "Built-in %s: hmodule=%04x\n",
-                        table->name, hModule );
-
-          /* Allocate the code segment */
-
-        pModule = (NE_MODULE *)GlobalLock( hModule );
-        pSegTable = NE_SEG_TABLE( pModule );
-
-        pSegTable->selector = GLOBAL_CreateBlock(GMEM_FIXED, table->code_start,
-                                                 pSegTable->minsize, hModule,
-                                                 TRUE, TRUE, FALSE, NULL );
-        if (!pSegTable->selector) return FALSE;
-        pSegTable++;
-
-          /* Allocate the data segment */
-
-        pSegTable->selector = GLOBAL_Alloc( GMEM_FIXED, pSegTable->minsize,
-                                            hModule, FALSE, FALSE, FALSE );
-        if (!pSegTable->selector) return FALSE;
-        memcpy( GlobalLock( pSegTable->selector ), table->data_start,
-                pSegTable->minsize );
-
-        pModule->next = hFirstModule;
-        hFirstModule = hModule;
-    }
-
+#else
+    fprintf(stderr, "JBP: MODULE_Init() ignored.\n");
+#endif
     /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
 
     MODULE_SetEntryPoint( GetModuleHandle( "KERNEL" ), 178, GetWinFlags() );
-
     return TRUE;
 }
 
@@ -103,7 +130,7 @@
 
       /* Dump the module info */
 
-    printf( "Module %04x:\n", hmodule );
+    printf( "Module "NPFMT":\n", hmodule );
     printf( "count=%d flags=%04x heap=%d stack=%d\n",
             pModule->count, pModule->flags,
             pModule->heap_size, pModule->stack_size );
@@ -124,7 +151,7 @@
     printf( "\nSegment table:\n" );
     pSeg = NE_SEG_TABLE( pModule );
     for (i = 0; i < pModule->seg_count; i++, pSeg++)
-        printf( "%02x: pos=%d size=%d flags=%04x minsize=%d sel=%04x\n",
+        printf( "%02x: pos=%d size=%d flags=%04x minsize=%d sel="NPFMT"\n",
                 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
                 pSeg->minsize, pSeg->selector );
 
@@ -233,7 +260,7 @@
     static int cachedfd = -1;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
-    dprintf_module( stddeb, "MODULE_OpenFile(%04x) cache: mod=%04x fd=%d\n",
+    dprintf_module( stddeb, "MODULE_OpenFile("NPFMT") cache: mod="NPFMT" fd=%d\n",
                     hModule, hCachedModule, cachedfd );
     if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return -1;
     if (hCachedModule == hModule) return cachedfd;
@@ -278,9 +305,13 @@
 DWORD MODULE_AllocateSegment(WORD wFlags, WORD wSize, WORD wElem)
 {
     WORD size = wSize << wElem;
-    WORD hMem = GlobalAlloc( MODULE_Ne2MemFlags(wFlags), size);
+    HANDLE hMem = GlobalAlloc( MODULE_Ne2MemFlags(wFlags), size);
+#ifdef WINELIB32
+    return (DWORD)GlobalLock(hMem);
+#else
     WORD selector = HIWORD(GlobalLock(hMem));
     return MAKELONG(hMem, selector);
+#endif
 }
 
 /***********************************************************************
@@ -389,14 +420,14 @@
 
     lseek( fd, 0, SEEK_SET );
     if ((read( fd, &mz_header, sizeof(mz_header) ) != sizeof(mz_header)) ||
-        (mz_header.mz_magic != MZ_SIGNATURE)) return 11;  /* invalid exe */
+        (mz_header.mz_magic != MZ_SIGNATURE)) return (HMODULE)11;  /* invalid exe */
 
     lseek( fd, mz_header.ne_offset, SEEK_SET );
     if (read( fd, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
-        return 11;  /* invalid exe */
+        return (HMODULE)11;  /* invalid exe */
 
-    if (ne_header.ne_magic == PE_SIGNATURE) return 21;  /* win32 exe */
-    if (ne_header.ne_magic != NE_SIGNATURE) return 11;  /* invalid exe */
+    if (ne_header.ne_magic == PE_SIGNATURE) return (HMODULE)21;  /* win32 exe */
+    if (ne_header.ne_magic != NE_SIGNATURE) return (HMODULE)11;  /* invalid exe */
 
     /* We now have a valid NE header */
 
@@ -417,7 +448,7 @@
            ne_header.entry_tab_length;
 
     hModule = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
-    if (!hModule) return 11;  /* invalid exe */
+    if (!hModule) return (HMODULE)11;  /* invalid exe */
     FarSetOwner( hModule, hModule );
     pModule = (NE_MODULE *)GlobalLock( hModule );
     memcpy( pModule, &ne_header, sizeof(NE_MODULE) );
@@ -465,7 +496,7 @@
 
         if (!READ( ne_header.segment_tab_offset,
              ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
-             buffer )) return 11;  /* invalid exe */
+             buffer )) return (HMODULE)11;  /* invalid exe */
         pSeg = (struct ne_segment_table_entry_s *)buffer;
         for (i = ne_header.n_segment_tab; i > 0; i--, pSeg++)
         {
@@ -474,7 +505,7 @@
         }
         free( buffer );
     }
-    else return 11;  /* invalid exe */
+    else return (HMODULE)11;  /* invalid exe */
 
     /* Get the resource table */
 
@@ -483,7 +514,7 @@
         pModule->res_table = (int)pData - (int)pModule;
         if (!READ(ne_header.resource_tab_offset,
                   ne_header.rname_tab_offset - ne_header.resource_tab_offset,
-                  pData )) return 11;  /* invalid exe */
+                  pData )) return (HMODULE)11;  /* invalid exe */
         pData += ne_header.rname_tab_offset - ne_header.resource_tab_offset;
     }
     else pModule->res_table = 0;  /* No resource table */
@@ -493,7 +524,7 @@
     pModule->name_table = (int)pData - (int)pModule;
     if (!READ( ne_header.rname_tab_offset,
                ne_header.moduleref_tab_offset - ne_header.rname_tab_offset,
-               pData )) return 11;  /* invalid exe */
+               pData )) return (HMODULE)11;  /* invalid exe */
     pData += ne_header.moduleref_tab_offset - ne_header.rname_tab_offset;
 
     /* Get the module references table */
@@ -503,7 +534,7 @@
         pModule->modref_table = (int)pData - (int)pModule;
         if (!READ( ne_header.moduleref_tab_offset,
                   ne_header.n_mod_ref_tab * sizeof(WORD),
-                  pData )) return 11;  /* invalid exe */
+                  pData )) return (HMODULE)11;  /* invalid exe */
         pData += ne_header.n_mod_ref_tab * sizeof(WORD);
     }
     else pModule->modref_table = 0;  /* No module references */
@@ -513,7 +544,7 @@
     pModule->import_table = (int)pData - (int)pModule;
     if (!READ( ne_header.iname_tab_offset, 
                ne_header.entry_tab_offset - ne_header.iname_tab_offset,
-               pData )) return 11;  /* invalid exe */
+               pData )) return (HMODULE)11;  /* invalid exe */
     pData += ne_header.entry_tab_offset - ne_header.iname_tab_offset;
 
     /* Get the entry table */
@@ -521,7 +552,7 @@
     pModule->entry_table = (int)pData - (int)pModule;
     if (!READ( ne_header.entry_tab_offset,
                ne_header.entry_tab_length,
-               pData )) return 11;  /* invalid exe */
+               pData )) return (HMODULE)11;  /* invalid exe */
     pData += ne_header.entry_tab_length;
 
     /* Get the non-resident names table */
@@ -530,11 +561,11 @@
     {
         pModule->nrname_handle = GLOBAL_Alloc( 0, ne_header.nrname_tab_length,
                                                hModule, FALSE, FALSE, FALSE );
-        if (!pModule->nrname_handle) return 11;  /* invalid exe */
+        if (!pModule->nrname_handle) return (HMODULE)11;  /* invalid exe */
         buffer = GlobalLock( pModule->nrname_handle );
         lseek( fd, ne_header.nrname_tab_offset, SEEK_SET );
         if (read( fd, buffer, ne_header.nrname_tab_length )
-              != ne_header.nrname_tab_length) return 11;  /* invalid exe */
+              != ne_header.nrname_tab_length) return (HMODULE)11;  /* invalid exe */
     }
     else pModule->nrname_handle = 0;
 
@@ -545,7 +576,7 @@
         pModule->dlls_to_init = GLOBAL_Alloc(GMEM_ZEROINIT,
                                     (pModule->modref_count+1)*sizeof(HMODULE),
                                     hModule, FALSE, FALSE, FALSE );
-        if (!pModule->dlls_to_init) return 11;  /* invalid exe */
+        if (!pModule->dlls_to_init) return (HMODULE)11;  /* invalid exe */
     }
     else pModule->dlls_to_init = 0;
 
@@ -569,7 +600,7 @@
 
     if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
 
-    dprintf_module( stddeb, "MODULE_GetOrdinal(%04x,'%s')\n",
+    dprintf_module( stddeb, "MODULE_GetOrdinal("NPFMT",'%s')\n",
                     hModule, name );
 
       /* First handle names of the form '#xxxx' */
@@ -817,10 +848,12 @@
     HMODULE *hPrevModule;
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegment;
-    WORD *pModRef;
+    HMODULE *pModRef;
     int i;
 
     if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return;
+    if (pModule->flags & NE_FFLAGS_BUILTIN)
+        return;  /* Can't free built-in module */
 
     /* FIXME: should call the exit code for the library here */
 
@@ -861,6 +894,8 @@
 }
 
 
+HINSTANCE PE_LoadModule(int fd, OFSTRUCT *ofs, LOADPARAMS* params);
+
 /**********************************************************************
  *	    LoadModule    (KERNEL.45)
  */
@@ -870,16 +905,30 @@
     HANDLE hInstance, hPrevInstance;
     NE_MODULE *pModule;
     LOADPARAMS *params = (LOADPARAMS *)paramBlock;
+#ifndef WINELIB /* JBP: Disabled for now in winelib.a */
     WORD *pModRef, *pDLLs;
     int i, fd;
 
     hModule = MODULE_FindModule( name );
+
     if (!hModule)  /* We have to load the module */
     {
         OFSTRUCT ofs;
+
+        /* Try to load the built-in first if not disabled */
+        if ((hModule = MODULE_LoadBuiltin( name, FALSE ))) return hModule;
+
         if (strchr( name, '/' )) name = DOS_GetDosFileName( name );
         if ((fd = OpenFile( name, &ofs, OF_READ )) == -1)
+        {
+            /* Now try the built-in even if disabled */
+            if ((hModule = MODULE_LoadBuiltin( name, TRUE )))
+            {
+                fprintf( stderr, "Warning: could not load Windows DLL '%s', using built-in module.\n", name );
+                return hModule;
+            }
             return 2;  /* File not found */
+        }
 
           /* Create the module structure */
 
@@ -996,6 +1045,10 @@
           /* the module, even if it contains circular DLL references */
 
         pModule->count = 1;
+
+          /* Clear built-in flag in case it was set in the EXE file */
+
+        pModule->flags &= ~NE_FFLAGS_BUILTIN;
     }
     else
     {
@@ -1006,6 +1059,14 @@
             NE_LoadSegment( hModule, pModule->dgroup );
         pModule->count++;
     }
+#else
+    hModule = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(NE_MODULE) );
+    pModule = (NE_MODULE *)GlobalLock( hModule );
+    pModule->count = 1;
+    pModule->magic = 0x454e;
+    hPrevInstance = 0;
+    hInstance = MODULE_CreateInstance( hModule, (LOADPARAMS*)paramBlock );
+#endif /* WINELIB */
 
       /* Create a task for this instance */
 
@@ -1043,7 +1104,11 @@
  */
 HMODULE WIN16_GetModuleHandle( SEGPTR name )
 {
+#ifdef WINELIB32
+    if (HIWORD(name) == 0) return GetExePtr( name );
+#else
     if (HIWORD(name) == 0) return GetExePtr( LOWORD(name) );
+#endif
     return MODULE_FindModule( PTR_SEG_TO_LIN(name) );
 }
 
@@ -1062,7 +1127,7 @@
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
-    dprintf_module( stddeb, "GetModuleUsage(%04x): returning %d\n",
+    dprintf_module( stddeb, "GetModuleUsage("NPFMT"): returning %d\n",
                     hModule, pModule->count );
     return pModule->count;
 }
@@ -1099,14 +1164,14 @@
     if ((handle = MODULE_FindModule( libname )) != 0) return handle;
      */
     handle = LoadModule( libname, (LPVOID)-1 );
-    if (handle == 2)  /* file not found */
+    if (handle == (HANDLE)2)  /* file not found */
     {
         char buffer[256];
         strcpy( buffer, libname );
         strcat( buffer, ".dll" );
         handle = LoadModule( buffer, (LPVOID)-1 );
     }
-    if (handle >= 32) NE_InitializeDLLs( GetExePtr(handle) );
+    if (handle >= (HANDLE)32) NE_InitializeDLLs( GetExePtr(handle) );
     return handle;
 }
 
@@ -1116,7 +1181,7 @@
  */
 void FreeLibrary( HANDLE handle )
 {
-    dprintf_module( stddeb,"FreeLibrary: %04x\n", handle );
+    dprintf_module( stddeb,"FreeLibrary: "NPFMT"\n", handle );
     FreeModule( handle );
 }
 
@@ -1157,12 +1222,12 @@
 
       /* Now load the executable file */
 
-    params.hEnvironment = SELECTOROF( GetDOSEnvironment() );
-    params.cmdLine  = WIN16_GlobalLock( cmdLineHandle );
-    params.showCmd  = WIN16_GlobalLock( cmdShowHandle );
+    params.hEnvironment = (HANDLE)SELECTOROF( GetDOSEnvironment() );
+    params.cmdLine  = (SEGPTR)WIN16_GlobalLock( cmdLineHandle );
+    params.showCmd  = (SEGPTR)WIN16_GlobalLock( cmdShowHandle );
     params.reserved = 0;
     handle = LoadModule( filename, &params );
-    if (handle == 2)  /* file not found */
+    if (handle == (HANDLE)2)  /* file not found */
     {
         strcat( filename, ".exe" );
         handle = LoadModule( filename, &params );
@@ -1170,6 +1235,7 @@
 
     GlobalFree( cmdShowHandle );
     GlobalFree( cmdLineHandle );
+    Yield();	/* program is executed immediatly ....needed for word */
     return handle;
 }
 
@@ -1188,13 +1254,13 @@
     if (HIWORD(name) != 0)
     {
         ordinal = MODULE_GetOrdinal( hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
-        dprintf_module( stddeb, "GetProcAddress: %04x '%s'\n",
+        dprintf_module( stddeb, "GetProcAddress: "NPFMT" '%s'\n",
                         hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
     }
     else
     {
         ordinal = LOWORD(name);
-        dprintf_module( stddeb, "GetProcAddress: %04x %04x\n",
+        dprintf_module( stddeb, "GetProcAddress: "NPFMT" %04x\n",
                         hModule, ordinal );
     }
     if (!ordinal) return (FARPROC)0;
@@ -1206,6 +1272,7 @@
 }
 
 
+#ifndef WINELIB
 /***********************************************************************
  *           GetWndProcEntry16 (not a Windows API function)
  *
@@ -1220,6 +1287,7 @@
     ordinal = MODULE_GetOrdinal( hModule, name );
     return MODULE_GetEntryPoint( hModule, ordinal );
 }
+#endif
 
 
 /**********************************************************************
diff --git a/loader/ne_image.c b/loader/ne_image.c
index b05e65e..9167a99 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -34,7 +34,8 @@
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable, *pSeg;
     WORD *pModuleTable;
-    WORD count, i, module, offset;
+    WORD count, i, offset;
+    HMODULE module;
     DWORD address;
     int fd;
     struct relocation_entry_s *rep, *reloc_entries;
@@ -54,12 +55,13 @@
     if (!pSeg->filepos) return TRUE;  /* No file image, just return */
 	
     fd = MODULE_OpenFile( hModule );
-    dprintf_module( stddeb, "Loading segment %d, selector=%04x\n",
+    dprintf_module( stddeb, "Loading segment %d, selector="NPFMT"\n",
                     segnum, pSeg->selector );
     lseek( fd, pSeg->filepos << pModule->alignment, SEEK_SET );
     size = pSeg->size ? pSeg->size : 0x10000;
     mem = GlobalLock(pSeg->selector);
     if (pModule->flags & NE_FFLAGS_SELFLOAD && segnum > 1) {	
+#ifndef WINELIB
  	/* Implement self loading segments */
  	SELFLOADHEADER *selfloadheader;
  	WORD oldss, oldsp, oldselector, newselector;
@@ -92,6 +94,9 @@
  	
  	IF1632_Saved16_ss = oldss;
  	IF1632_Saved16_sp = oldsp;
+#else
+	fprintf(stderr,"JBP: Ignoring self loading segments in NE_LoadSegment.\n");
+#endif
      }
     else if (!(pSeg->flags & NE_SEGFLAGS_ITERATED))
       read(fd, mem, size);
@@ -126,7 +131,7 @@
     read( fd, &count, sizeof(count) );
     if (!count) return TRUE;
 
-    dprintf_fixup( stddeb, "Fixups for %*.*s, segment %d, selector %04x\n",
+    dprintf_fixup( stddeb, "Fixups for %*.*s, segment %d, selector "NPFMT"\n",
                    *((BYTE *)pModule + pModule->name_table),
                    *((BYTE *)pModule + pModule->name_table),
                    (char *)pModule + pModule->name_table + 1,
@@ -165,7 +170,7 @@
             {
                 NE_MODULE *pTarget = (NE_MODULE *)GlobalLock( module );
                 if (!pTarget)
-                    fprintf( stderr, "Module not found: %04x, reference %d of module %*.*s\n",
+                    fprintf( stderr, "Module not found: "NPFMT", reference %d of module %*.*s\n",
                              module, rep->target1, 
                              *((BYTE *)pModule + pModule->name_table),
                              *((BYTE *)pModule + pModule->name_table),
@@ -266,7 +271,7 @@
 	  case NE_RADDR_LOWBYTE:
             do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-                dprintf_fixup(stddeb,"    %04x:%04x:%04x BYTE%s\n",
+                dprintf_fixup(stddeb,"    "NPFMT":%04x:%04x BYTE%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive":"");
                 offset = *sp;
 		if(additive)
@@ -280,7 +285,7 @@
 	  case NE_RADDR_OFFSET16:
 	    do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x OFFSET16%s\n",
+		dprintf_fixup(stddeb,"    "NPFMT":%04x:%04x OFFSET16%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive" : "" );
 		offset = *sp;
 		*sp = LOWORD(address);
@@ -292,7 +297,7 @@
 	  case NE_RADDR_POINTER32:
 	    do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x POINTER32%s\n",
+		dprintf_fixup(stddeb,"    "NPFMT":%04x:%04x POINTER32%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive" : "" );
 		offset = *sp;
 		*sp    = LOWORD(address);
@@ -305,7 +310,7 @@
 	  case NE_RADDR_SELECTOR:
 	    do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x SELECTOR%s\n",
+		dprintf_fixup(stddeb,"    "NPFMT":%04x:%04x SELECTOR%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive" : "" );
 		offset = *sp;
 		*sp    = HIWORD(address);
@@ -434,6 +439,7 @@
  */
 static BOOL NE_InitDLL( HMODULE hModule )
 {
+#ifndef WINELIB
     int cs_reg, ds_reg, ip_reg, cx_reg, di_reg, bp_reg;
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
@@ -482,6 +488,10 @@
     return CallTo16_regs_( (FARPROC)(cs_reg << 16 | ip_reg), ds_reg,
                            0 /*es*/, 0 /*bp*/, 0 /*ax*/, 0 /*bx*/,
                            cx_reg, 0 /*dx*/, 0 /*si*/, di_reg );
+#else
+    fprintf( stderr,"JBP: Ignoring call to LibMain\n" );
+    return FALSE;
+#endif
 }
 
 
@@ -493,14 +503,14 @@
 void NE_InitializeDLLs( HMODULE hModule )
 {
     NE_MODULE *pModule;
-    WORD *pDLL;
+    HMODULE *pDLL;
 
     pModule = (NE_MODULE *)GlobalLock( hModule );
     if (pModule->dlls_to_init)
     {
 	HANDLE to_init = pModule->dlls_to_init;
 	pModule->dlls_to_init = 0;
-        for (pDLL = (WORD *)GlobalLock( to_init ); *pDLL; pDLL++)
+        for (pDLL = (HMODULE *)GlobalLock( to_init ); *pDLL; pDLL++)
         {
             NE_InitializeDLLs( *pDLL );
             NE_InitDLL( *pDLL );
diff --git a/loader/ne_resource.c b/loader/ne_resource.c
index ab9b089..a83f639 100644
--- a/loader/ne_resource.c
+++ b/loader/ne_resource.c
@@ -54,7 +54,8 @@
         {
             dprintf_resource( stddeb, "NameTable entry: type=%04x id=%04x\n",
                               pTypeInfo->type_id, pNameInfo->id );
-            handle = LoadResource( hModule, (int)pNameInfo - (int)pModule );
+            handle = LoadResource( hModule, 
+				   (HANDLE)((int)pNameInfo - (int)pModule) );
             for(p = (WORD*)LockResource(handle); *p; p = (WORD *)((char*)p+*p))
             {
                 dprintf_resource( stddeb,"  type=%04x '%s' id=%04x '%s'\n",
@@ -118,14 +119,15 @@
             if (pNameInfo->id & 0x8000) continue;
             p = (BYTE *)pModule + pModule->res_table + pNameInfo->id;
             if ((*p == len) && !strncasecmp( p+1, str, len ))
-                return (int)pNameInfo - (int)pModule;
+                return (HRSRC)((int)pNameInfo - (int)pModule);
         }
     }
     else  /* Numeric resource id */
     {
         WORD id = LOWORD(resId) | 0x8000;
         for (count = pTypeInfo->count; count > 0; count--, pNameInfo++)
-            if (pNameInfo->id == id) return (int)pNameInfo - (int)pModule;
+            if (pNameInfo->id == id) 
+	      return (HRSRC)((int)pNameInfo - (int)pModule);
     }
     return 0;
 }
@@ -219,13 +221,15 @@
 HGLOBAL NE_AllocResource( HMODULE hModule, HRSRC hRsrc, DWORD size )
 {
     NE_MODULE *pModule;
-    NE_NAMEINFO *pNameInfo;
+    NE_NAMEINFO *pNameInfo=NULL;
     WORD sizeShift;
 
     pModule = (NE_MODULE *)GlobalLock( hModule );
     if (!pModule || !pModule->res_table) return 0;
     sizeShift = *(WORD *)((char *)pModule + pModule->res_table);
+#ifndef WINELIB
     pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
+#endif
     if (size < (DWORD)pNameInfo->length << sizeShift)
         size = (DWORD)pNameInfo->length << sizeShift;
     return GLOBAL_Alloc( GMEM_FIXED, size, hModule, FALSE, FALSE, FALSE );
@@ -238,14 +242,16 @@
 int NE_AccessResource( HMODULE hModule, HRSRC hRsrc )
 {
     NE_MODULE *pModule;
-    NE_NAMEINFO *pNameInfo;
+    NE_NAMEINFO *pNameInfo=NULL;
     WORD sizeShift;
     char *name;
     int fd;
 
     pModule = (NE_MODULE *)GlobalLock( hModule );
     if (!pModule || !pModule->res_table) return 0;
+#ifndef WINELIB
     pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
+#endif
 
     name = ((LOADEDFILEINFO*)((char*)pModule + pModule->fileinfo))->filename;
     fd = open( DOS_GetUnixFileName(name), O_RDONLY );
@@ -261,13 +267,15 @@
 DWORD NE_SizeofResource( HMODULE hModule, HRSRC hRsrc )
 {
     NE_MODULE *pModule;
-    NE_NAMEINFO *pNameInfo;
+    NE_NAMEINFO *pNameInfo=NULL;
     WORD sizeShift;
 
     pModule = (NE_MODULE *)GlobalLock( hModule );
     if (!pModule || !pModule->res_table) return 0;
     sizeShift = *(WORD *)((char *)pModule + pModule->res_table);
+#ifndef WINELIB
     pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
+#endif
     return (DWORD)pNameInfo->length << sizeShift;
 }
 
@@ -278,13 +286,15 @@
 HGLOBAL NE_LoadResource( HMODULE hModule,  HRSRC hRsrc )
 {
     NE_MODULE *pModule;
-    NE_NAMEINFO *pNameInfo;
+    NE_NAMEINFO *pNameInfo=NULL;
     WORD sizeShift;
     int fd;
 
     pModule = (NE_MODULE *)GlobalLock( hModule );
     if (!pModule || !pModule->res_table) return 0;
+#ifndef WINELIB
     pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
+#endif
     if (pNameInfo->handle)
     {
         pNameInfo->usage++;
@@ -313,7 +323,7 @@
 {
     /* May need to reload the resource if discarded */
 
-    return WIN16_GlobalLock( handle );
+    return (SEGPTR)WIN16_GlobalLock( handle );
 }
 
 
@@ -349,6 +359,6 @@
         }
         pTypeInfo = (NE_TYPEINFO *)pNameInfo;
     }
-    fprintf( stderr, "FreeResource: %04x %04x not found!\n", hModule, handle );
+    fprintf( stderr, "FreeResource: "NPFMT" "NPFMT" not found!\n", hModule, handle );
     return FALSE;
 }
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 493de0f..18117cd 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -25,7 +25,7 @@
 #include "task.h"
 #include "ldt.h"
 #include "registers.h"
-
+#include "selectors.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -54,7 +54,11 @@
   if(r_size)
     v_size=r_size;
   else
+#ifdef __svr4__
+    fprintf(stderr,"xmmap: %s line %d doesn't support MAP_ANON\n",__FILE__, __LINE__);
+#else
     flags |= MAP_ANON;
+#endif
   result = mmap(vaddr, v_size, prot, flags, fd, file_offset);
   if((unsigned int) result != 0xffffffff) return result;
 
@@ -131,7 +135,11 @@
 		exit(0);
 	  }
 	  printf("--- %s %s.%d\n", pe_name->Name, Module, pe_name->Hint);
-	  *thunk_list=RELAY32_GetEntryPoint(Module,pe_name->Name,pe_name->Hint);
+#ifndef WINELIB /* FIXME: JBP: Should this happen in libwine.a? */
+	  *thunk_list=(unsigned int)RELAY32_GetEntryPoint(Module,pe_name->Name,pe_name->Hint);
+#else
+	  fprintf(stderr,"JBP: Call to RELAY32_GetEntryPoint being ignored.\n");
+#endif
 	  if(!*thunk_list)
 	  {
 	  	fprintf(stderr,"No implementation for %s.%d\n",Module, pe_name->Hint);
@@ -197,12 +205,12 @@
 	for(i=0; i < wpnt->pe->pe_header->coff.NumberOfSections; i++)
 	{
 	if(!load_addr) {
-		result = xmmap((char *)0, wpnt->pe->pe_seg[i].Virtual_Size,
+		result = (int)xmmap((char *)0, wpnt->pe->pe_seg[i].Virtual_Size,
 			wpnt->pe->pe_seg[i].Size_Of_Raw_Data, 7,
 			MAP_PRIVATE, wpnt->fd, wpnt->pe->pe_seg[i].PointerToRawData);
 		load_addr = (unsigned int) result -  wpnt->pe->pe_seg[i].Virtual_Address;
 	} else {
-		result = xmmap((char *) load_addr + wpnt->pe->pe_seg[i].Virtual_Address, 
+		result = (int)xmmap((char *) load_addr + wpnt->pe->pe_seg[i].Virtual_Address, 
 			  wpnt->pe->pe_seg[i].Virtual_Size,
 		      wpnt->pe->pe_seg[i].Size_Of_Raw_Data, 7, MAP_PRIVATE | MAP_FIXED, 
 		      wpnt->fd, wpnt->pe->pe_seg[i].PointerToRawData);
@@ -232,10 +240,13 @@
 	if(wpnt->pe->pe_import) fixup_imports(wpnt->pe->pe_import);
 	if(wpnt->pe->pe_export) dump_exports(wpnt->pe->pe_export);
   
-	wpnt->hinstance = 0x8000;
+	wpnt->hinstance = (HINSTANCE)0x8000;
 	return (wpnt->hinstance);
 }
 
+HINSTANCE MODULE_CreateInstance(HMODULE hModule,LOADPARAMS *params);
+void InitTask(struct sigcontext_struct context);
+
 HINSTANCE PE_LoadModule(int fd, OFSTRUCT *ofs, LOADPARAMS* params)
 {
 	struct w_files *wpnt;
@@ -275,11 +286,11 @@
 
 	hModule = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
 	wpnt->hModule=hModule;
-	if (!hModule) return 11;  /* invalid exe */
+	if (!hModule) return (HINSTANCE)11;  /* invalid exe */
 
 	FarSetOwner( hModule, hModule );
 	
-	pModule = GlobalLock(hModule);
+	pModule = (NE_MODULE*)GlobalLock(hModule);
 
 	/* Set all used entries */
 	pModule->magic=NE_SIGNATURE;
@@ -312,9 +323,14 @@
 	pSegment->minsize=0x1000;
 	pSegment++;
 
-	cts=GetWndProcEntry16("Win32CallToStart");
+	cts=(DWORD)GetWndProcEntry16("Win32CallToStart");
+#ifdef WINELIB32
+	pSegment->selector=(void*)cts;
+	pModule->ip=0;
+#else
 	pSegment->selector=cts>>16;
 	pModule->ip=cts & 0xFFFF;
+#endif
 	pSegment++;
 
 	pStr=(char*)pSegment;
@@ -332,7 +348,7 @@
 	pModule->stack_size=0xE000;
 
 	/* CreateInstance allocates now 64KB */
-	hInstance=MODULE_CreateInstance(hModule);
+	hInstance=MODULE_CreateInstance(hModule,NULL /* FIX: NULL? really? */);
 	wpnt->hinstance=hInstance;
 
 	TASK_CreateTask(hModule,hInstance,0,
@@ -342,11 +358,13 @@
 	return hInstance;
 }
 
+int USER_InitApp(HINSTANCE hInstance);
+
 void PE_Win32CallToStart(struct sigcontext_struct context)
 {
 	int fs;
 	struct w_files *wpnt=wine_files;
-	fs=GlobalAlloc(GHND,0x10000);
+	fs=(int)GlobalAlloc(GHND,0x10000);
 	fprintf(stddeb,"Going to start Win32 program\n");	
 	InitTask(context);
 	USER_InitApp(wpnt->hModule);
diff --git a/loader/resource.c b/loader/resource.c
index 90e9216..7a5b4b1 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -15,10 +15,8 @@
 #include "arch.h"
 #include "windows.h"
 #include "gdi.h"
-#include "bitmap.h"
 #include "global.h"
 #include "neexe.h"
-#include "icon.h"
 #include "accel.h"
 #include "dlls.h"
 #include "module.h"
@@ -34,15 +32,6 @@
 
 
 /**********************************************************************
- *	    LoadIconHandler    (USER.456)
- */
-HICON LoadIconHandler( HANDLE hResource, BOOL bNew )
-{
-  return 0;
-}
-
-
-/**********************************************************************
  *	    FindResource    (KERNEL.60)
  */
 HRSRC FindResource( HMODULE hModule, SEGPTR name, SEGPTR type )
@@ -50,7 +39,7 @@
     WORD *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
-    dprintf_resource(stddeb, "FindResource: module=%04x type=", hModule );
+    dprintf_resource(stddeb, "FindResource: module="NPFMT" type=", hModule );
     PrintId( type );
     dprintf_resource( stddeb, " name=" );
     PrintId( name );
@@ -76,7 +65,7 @@
     WORD *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
-    dprintf_resource(stddeb, "LoadResource: module=%04x res=%04x\n",
+    dprintf_resource(stddeb, "LoadResource: module="NPFMT" res="NPFMT"\n",
                      hModule, hRsrc );
     if (!hRsrc) return 0;
     if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
@@ -101,7 +90,7 @@
     HMODULE hModule;
     WORD *pModule;
 
-    dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
+    dprintf_resource(stddeb, "LockResource: handle="NPFMT"\n", handle );
     if (!handle) return (SEGPTR)0;
     hModule = GetExePtr( handle );
     if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
@@ -122,7 +111,7 @@
     HMODULE hModule;
     WORD *pModule;
 
-    dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
+    dprintf_resource(stddeb, "LockResource: handle="NPFMT"\n", handle );
     if (!handle) return NULL;
     hModule = GetExePtr( handle );
     if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
@@ -146,7 +135,7 @@
     HMODULE hModule;
     WORD *pModule;
 
-    dprintf_resource(stddeb, "FreeResource: handle=%04x\n", handle );
+    dprintf_resource(stddeb, "FreeResource: handle="NPFMT"\n", handle );
     if (!handle) return FALSE;
     hModule = GetExePtr( handle );
     if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
@@ -165,12 +154,12 @@
 /**********************************************************************
  *	    AccessResource    (KERNEL.64)
  */
-int AccessResource( HMODULE hModule, HRSRC hRsrc )
+INT AccessResource( HINSTANCE hModule, HRSRC hRsrc )
 {
     WORD *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
-    dprintf_resource(stddeb, "AccessResource: module=%04x res=%04x\n",
+    dprintf_resource(stddeb, "AccessResource: module="NPFMT" res="NPFMT"\n",
                      hModule, hRsrc );
     if (!hRsrc) return 0;
     if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
@@ -194,7 +183,7 @@
     WORD *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
-    dprintf_resource(stddeb, "SizeofResource: module=%04x res=%04x\n",
+    dprintf_resource(stddeb, "SizeofResource: module="NPFMT" res="NPFMT"\n",
                      hModule, hRsrc );
     if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
     switch(*pModule)
@@ -217,7 +206,7 @@
     WORD *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
-    dprintf_resource(stddeb, "AllocResource: module=%04x res=%04x size=%ld\n",
+    dprintf_resource(stddeb, "AllocResource: module="NPFMT" res="NPFMT" size=%ld\n",
                      hModule, hRsrc, size );
     if (!hRsrc) return 0;
     if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
@@ -234,264 +223,22 @@
 
 /**********************************************************************
  *      DirectResAlloc    (KERNEL.168)
+ *
  * Check Schulman, p. 232 for details
  */
 HANDLE DirectResAlloc(HANDLE hInstance, WORD wType, WORD wSize)
 {
-	HANDLE hModule;
-	dprintf_resource(stddeb,"DirectResAlloc(%x,%x,%x)\n",hInstance,wType,wSize);
-	hModule = GetExePtr(hInstance);
-	if(!hModule)return 0;
-	if(wType != 0x10)	/* 0x10 is the only observed value, passed from
+    dprintf_resource(stddeb,"DirectResAlloc("NPFMT",%x,%x)\n",hInstance,wType,wSize);
+    hInstance = GetExePtr(hInstance);
+    if(!hInstance)return 0;
+    if(wType != 0x10)	/* 0x10 is the only observed value, passed from
                            CreateCursorIndirect. */
-		fprintf(stderr, "DirectResAlloc: wType = %x\n", wType);
-	/* This hopefully does per-module allocation rather than per-instance */
-	return GLOBAL_Alloc(GMEM_FIXED, wSize, hModule, FALSE, FALSE, FALSE);
+        fprintf(stderr, "DirectResAlloc: wType = %x\n", wType);
+    return GLOBAL_Alloc(GMEM_MOVEABLE, wSize, hInstance, FALSE, FALSE, FALSE);
 }
 
 
 /**********************************************************************
- *			ConvertCoreBitmap
- */
-HBITMAP ConvertCoreBitmap( HDC hdc, BITMAPCOREHEADER * image )
-{
-    BITMAPINFO * bmpInfo;
-    HBITMAP hbitmap;
-    char * bits;
-    int i, size, n_colors;
-   
-    n_colors = 1 << image->bcBitCount;
-    if (image->bcBitCount < 24)
-    {
-	size = sizeof(BITMAPINFOHEADER) + n_colors * sizeof(RGBQUAD);	
-	bits = (char *) (image + 1) + (n_colors * sizeof(RGBTRIPLE));
-    }
-    else
-    {
-	size = sizeof(BITMAPINFOHEADER);
-	bits = (char *) (image + 1);
-    }
-    bmpInfo = (BITMAPINFO *) malloc( size );
-
-    bmpInfo->bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
-    bmpInfo->bmiHeader.biWidth         = image->bcWidth;
-    bmpInfo->bmiHeader.biHeight        = image->bcHeight;
-    bmpInfo->bmiHeader.biPlanes        = image->bcPlanes;
-    bmpInfo->bmiHeader.biBitCount      = image->bcBitCount;
-    bmpInfo->bmiHeader.biCompression   = 0;
-    bmpInfo->bmiHeader.biSizeImage     = 0;
-    bmpInfo->bmiHeader.biXPelsPerMeter = 0;
-    bmpInfo->bmiHeader.biYPelsPerMeter = 0;
-    bmpInfo->bmiHeader.biClrUsed       = 0;
-    bmpInfo->bmiHeader.biClrImportant  = 0;
-
-    if (image->bcBitCount < 24)
-    {
-	RGBTRIPLE * oldMap = (RGBTRIPLE *)(image + 1);
-	RGBQUAD * newMap = bmpInfo->bmiColors;
-	for (i = 0; i < n_colors; i++, oldMap++, newMap++)
-	{
-	    newMap->rgbRed      = oldMap->rgbtRed;
-	    newMap->rgbGreen    = oldMap->rgbtGreen;
-	    newMap->rgbBlue     = oldMap->rgbtBlue;
-	    newMap->rgbReserved = 0;
-	}
-    }
-
-    hbitmap = CreateDIBitmap( hdc, &bmpInfo->bmiHeader, CBM_INIT,
-			      bits, bmpInfo, DIB_RGB_COLORS );
-    free( bmpInfo );
-    return hbitmap;
-}
-
-/**********************************************************************
- *			ConvertInfoBitmap
- */
-HBITMAP	ConvertInfoBitmap( HDC hdc, BITMAPINFO * image )
-{
-    char * bits = ((char *)image) + DIB_BitmapInfoSize(image, DIB_RGB_COLORS);
-    return CreateDIBitmap( hdc, &image->bmiHeader, CBM_INIT,
-			   bits, image, DIB_RGB_COLORS );
-} 
-
-
-/**********************************************************************
- *			LoadIcon [USER.174]
- */
-HICON LoadIcon( HANDLE instance, SEGPTR icon_name )
-{
-    HICON 	hIcon;
-    HRSRC       hRsrc;
-    HANDLE 	rsc_mem;
-    WORD 	*lp;
-    ICONDESCRIP *lpicodesc;
-    ICONALLOC	*lpico;
-    int		width, height;
-    BITMAPINFO 	*bmi;
-    BITMAPINFOHEADER 	*bih;
-    RGBQUAD	*rgbq;
-    HDC 	hdc;
-    BITMAPINFO *pInfo;
-    char *bits;
-    int size;
-
-    if (HIWORD(icon_name))
-        dprintf_resource( stddeb, "LoadIcon: %04x '%s'\n",
-                          instance, (char *)PTR_SEG_TO_LIN( icon_name ) );
-    else
-        dprintf_resource( stddeb, "LoadIcon: %04x %04x\n",
-                          instance, LOWORD(icon_name) );
-    
-    if (!instance)
-    {
-        if (HIWORD((int)icon_name)) return 0; /* FIXME: should handle '#xxx' */
-        return OBM_LoadIcon( LOWORD((int)icon_name) );
-    }
-
-    if (!(hRsrc = FindResource( instance, icon_name, RT_GROUP_ICON))) return 0;
-    rsc_mem = LoadResource( instance, hRsrc );
-    if (rsc_mem == (HANDLE)NULL) {
-	printf("LoadIcon / Icon %08x not Found !\n", (int) icon_name);
-	return 0;
-    }
-    lp = (WORD *)LockResource(rsc_mem);
-    lpicodesc = (ICONDESCRIP *)(lp + 3);
-    hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
-    if (hIcon == (HICON)NULL) {
-        FreeResource( rsc_mem );
-	return 0;
-    }
-    lpico = (ICONALLOC *)GlobalLock(hIcon);
-    lpico->descriptor = *lpicodesc;
-    width = lpicodesc->Width;
-    height = lpicodesc->Height;
-    FreeResource( rsc_mem );
-    if (!(hRsrc = FindResource( instance,
-                              MAKEINTRESOURCE(lpico->descriptor.icoDIBOffset), 
-                              RT_ICON ))) return 0;
-    if (!(rsc_mem = LoadResource( instance, hRsrc ))) return 0;
-
-    bmi = (BITMAPINFO *)LockResource(rsc_mem);
-    size = DIB_BitmapInfoSize( bmi, DIB_RGB_COLORS );
-    pInfo = (BITMAPINFO *)malloc( size );
-    memcpy( pInfo, bmi, size );
-    bih = &pInfo->bmiHeader;
-    bih->biHeight /= 2;
-
-    if (!(hdc = GetDC( 0 ))) return 0;
-    if (bih->biSize != sizeof(BITMAPINFOHEADER)) return 0;
-    lpico->hBitmap = CreateDIBitmap( hdc, &pInfo->bmiHeader, CBM_INIT,
-                                    (char*)bmi + size, pInfo, DIB_RGB_COLORS );
-
-    if (bih->biCompression != BI_RGB)
-    {
-	fprintf(stderr,"Unknown size for compressed Icon bitmap.\n");
-	FreeResource( rsc_mem );
-	ReleaseDC( 0, hdc); 
-	return 0;
-    }
-    bits = (char *)bmi + size +
-      DIB_GetImageWidthBytes(bih->biWidth,bih->biBitCount) * bih->biHeight;
-    bih->biBitCount = 1;
-    bih->biClrUsed = bih->biClrImportant = 2;
-    rgbq = &pInfo->bmiColors[0];
-    rgbq[0].rgbBlue = rgbq[0].rgbGreen = rgbq[0].rgbRed = 0x00;
-    rgbq[1].rgbBlue = rgbq[1].rgbGreen = rgbq[1].rgbRed = 0xff;
-    rgbq[0].rgbReserved = rgbq[1].rgbReserved = 0;
-    lpico->hBitMask = CreateDIBitmap(hdc, &pInfo->bmiHeader, CBM_INIT,
-                                     bits, pInfo, DIB_RGB_COLORS );
-    FreeResource( rsc_mem );
-    ReleaseDC( 0, hdc);
-    free( pInfo );
-    GlobalUnlock(hIcon);
-    dprintf_resource(stddeb,"LoadIcon Alloc hIcon=%X\n", hIcon);
-    return hIcon;
-}
-
-
-/**********************************************************************
- *			CreateIcon [USER.407]
- */
-HICON CreateIcon(HANDLE hInstance, int nWidth, int nHeight, 
-                 BYTE nPlanes, BYTE nBitsPixel, LPSTR lpANDbits, 
-                 LPSTR lpXORbits)
-{
-    HICON 	hIcon;
-    ICONALLOC	*lpico;
-
-    dprintf_resource(stddeb, "CreateIcon: hInstance = %04x, nWidth = %08x, nHeight = %08x \n",
-	    hInstance, nWidth, nHeight);
-    dprintf_resource(stddeb, "  nPlanes = %04x, nBitsPixel = %04x,",nPlanes, nBitsPixel);
-    dprintf_resource(stddeb, " lpANDbits= %04x, lpXORbits = %04x, \n", (int)lpANDbits,
-    		(int)lpXORbits);
-
-    if (hInstance == (HANDLE)NULL) { 
-        printf("CreateIcon / hInstance %04x not Found!\n",hInstance);
-        return 0;
-	}
-    hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
-    if (hIcon == (HICON)NULL) {
-	printf("Can't allocate memory for Icon in CreateIcon\n");
-	return 0;
-	}
-    lpico= (ICONALLOC *)GlobalLock(hIcon);
-
-    lpico->descriptor.Width=nWidth;
-    lpico->descriptor.Height=nHeight;
-    lpico->descriptor.ColorCount=16; /* Dummy Value */ 
-    lpico->descriptor.Reserved1=0;
-    lpico->descriptor.Reserved2=nPlanes;
-    lpico->descriptor.Reserved3=nWidth*nHeight;
-
-    /* either nPlanes and/or nBitCount is set to one */
-    lpico->descriptor.icoDIBSize=nWidth*nHeight*nPlanes*nBitsPixel; 
-    lpico->descriptor.icoDIBOffset=0; 
-
-    if( !(lpico->hBitmap=CreateBitmap(nWidth, nHeight, nPlanes, nBitsPixel, 
-                                 lpXORbits)) ) {
-      printf("CreateIcon: couldn't create the XOR bitmap\n");
-      return(0);
-    }
-    
-    /* the AND BitMask is always monochrome */
-    if( !(lpico->hBitMask=CreateBitmap(nWidth, nHeight, 1, 1, lpANDbits)) ) {
-      printf("CreateIcon: couldn't create the AND bitmap\n");
-      return(0);
-    }
-
-    GlobalUnlock(hIcon);
-    dprintf_resource(stddeb, "CreateIcon Alloc hIcon=%X\n", hIcon);
-    return hIcon;
-}
-
-/**********************************************************************
- *			DestroyIcon [USER.457]
- */
-BOOL DestroyIcon(HICON hIcon)
-{
-    ICONALLOC	*lpico;
-    
-    if (hIcon == (HICON)NULL)
-    	return FALSE;
-    lpico = (ICONALLOC *)GlobalLock(hIcon);
-    if (lpico->hBitmap != (HBITMAP)NULL) 
-    	DeleteObject(lpico->hBitmap);
-    GlobalFree(hIcon);
-    return TRUE;
-}
-
-/**********************************************************************
- *          DumpIcon [USER.459]
- */
-DWORD DumpIcon(void* cursorIconInfo, WORD FAR *lpLen, LPSTR FAR *lpXorBits,
-	LPSTR FAR *lpAndMask)
-{
-	dprintf_resource(stdnimp,"DumpIcon: Empty Stub!!!\n");
-	return 0;
-}
-
-
-/**********************************************************************
  *			LoadAccelerators	[USER.177]
  */
 HANDLE LoadAccelerators(HANDLE instance, SEGPTR lpTableName)
@@ -504,10 +251,10 @@
     int 	i, n;
 
     if (HIWORD(lpTableName))
-        dprintf_accel( stddeb, "LoadAccelerators: %04x '%s'\n",
+        dprintf_accel( stddeb, "LoadAccelerators: "NPFMT" '%s'\n",
                       instance, (char *)PTR_SEG_TO_LIN( lpTableName ) );
     else
-        dprintf_accel( stddeb, "LoadAccelerators: %04x %04x\n",
+        dprintf_accel( stddeb, "LoadAccelerators: "NPFMT" %04x\n",
                        instance, LOWORD(lpTableName) );
 
     if (!(hRsrc = FindResource( instance, lpTableName, RT_ACCELERATOR )))
@@ -553,7 +300,7 @@
 	msg->message != WM_SYSKEYUP &&
     	msg->message != WM_CHAR) return 0;
 
-    dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04X !\n", hAccel);
+    dprintf_accel(stddeb, "TranslateAccelerators hAccel="NPFMT" !\n", hAccel);
 
     lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
     for (i = 0; i < lpAccelTbl->wCount; i++) {
@@ -600,7 +347,7 @@
     int string_num;
     int i;
 
-    dprintf_resource(stddeb, "LoadString: instance = %04x, id = %d, buffer = %08x, "
+    dprintf_resource(stddeb, "LoadString: instance = "NPFMT", id = %04x, buffer = %08x, "
 	   "length = %d\n", instance, resource_id, (int) buffer, buflen);
 
     hrsrc = FindResource( instance, (SEGPTR)((resource_id>>4)+1), RT_STRING );
diff --git a/loader/signal.c b/loader/signal.c
index d943bc5..3a560c5 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -7,7 +7,7 @@
 #include <time.h>
 #include <setjmp.h>
 
-#if defined(__NetBSD__) || defined(__FreeBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__svr4__)
 #include <sys/syscall.h>
 #include <sys/param.h>
 #else
@@ -45,7 +45,7 @@
 #endif
 
 
-#ifdef linux
+#if defined(linux) || defined(__svr4__)
 static void win_fault(int signal, struct sigcontext_struct context_struct)
 {
     struct sigcontext_struct *context = &context_struct;
diff --git a/loader/task.c b/loader/task.c
index b2180f4..ae8e2d5 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -42,12 +42,15 @@
   /* TASK_Reschedule() 16-bit entry point */
 static FARPROC TASK_RescheduleProc;
 
+#ifdef WINELIB
+#define TASK_SCHEDULE()  TASK_Reschedule();
+#else
 #define TASK_SCHEDULE()  CallTo16_word_(TASK_RescheduleProc,0)
+#endif
 
 
 static HANDLE TASK_CreateDOSEnvironment(void);
 
-
 /***********************************************************************
  *           TASK_Init
  */
@@ -328,6 +331,10 @@
     cs_reg = pSegTable[pModule->cs - 1].selector;
     ip_reg = pModule->ip;
     ds_reg = pSegTable[pModule->dgroup - 1].selector;
+#ifndef WINELIB
+/* JBP: I doubt a CallTo16_regs_ is possible in libwine.a, and IF1632 is not
+ *      allowed.
+ */
     IF1632_Saved16_ss = pTask->ss;
     IF1632_Saved16_sp = pTask->sp;
     dprintf_task( stddeb, "Starting main program: cs:ip=%04x:%04x ds=%04x ss:sp=%04x:%04x\n",
@@ -338,6 +345,11 @@
                    pTask->hPDB /*es*/, 0 /*bp*/, 0 /*ax*/,
                    pModule->stack_size /*bx*/, pModule->heap_size /*cx*/,
                    0 /*dx*/, 0 /*si*/, ds_reg /*di*/ );
+#else
+    fprintf(stderr, "JBP: Ignoring main program: cs:ip=%04x:%04x ds=%04x ss:sp=%04x:%04x\n",
+                 cs_reg, ip_reg, ds_reg,
+                 pTask->ss, pTask->sp);
+#endif
     /* This should never return */
     fprintf( stderr, "TASK_CallToStart: Main program returned!\n" );
     TASK_KillCurrentTask( 1 );
@@ -356,11 +368,13 @@
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
     LPSTR name;
+    char filename[256];
+#ifndef WINELIB32
     char *stack16Top, *stack32Top;
     STACK16FRAME *frame16;
     STACK32FRAME *frame32;
     extern DWORD CALL16_RetAddr_word;
-    char filename[256];
+#endif
     
     if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
     pSegTable = NE_SEG_TABLE( pModule );
@@ -424,9 +438,11 @@
     pTask->pdb.int20 = 0x20cd;
     pTask->pdb.dispatcher[0] = 0x9a;  /* ljmp */
     *(DWORD *)&pTask->pdb.dispatcher[1] = MODULE_GetEntryPoint( GetModuleHandle("KERNEL"), 102 );  /* KERNEL.102 is DOS3Call() */
+#ifndef WINELIB
     pTask->pdb.savedint22 = INT_GetHandler( 0x22 );
     pTask->pdb.savedint23 = INT_GetHandler( 0x23 );
     pTask->pdb.savedint24 = INT_GetHandler( 0x24 );
+#endif
     pTask->pdb.environment = hEnvironment;
     strncpy( pTask->pdb.cmdLine + 1, cmdLine, 126 );
     pTask->pdb.cmdLine[127] = '\0';
@@ -458,6 +474,7 @@
 
       /* Allocate the 32-bit stack */
 
+#ifndef WINELIB
     pTask->hStack32 = GLOBAL_Alloc( GMEM_FIXED, STACK32_SIZE, pTask->hPDB,
                                     FALSE, FALSE, FALSE );
 
@@ -513,12 +530,13 @@
         fprintf( stderr, "Task '%s': ", name );
         DEBUG_AddBreakpoint( &addr );
     }
+#endif
 
       /* Add the task to the linked list */
 
     TASK_LinkTask( hTask );
 
-    dprintf_task( stddeb, "CreateTask: module='%s' cmdline='%s' task=%04x\n",
+    dprintf_task( stddeb, "CreateTask: module='%s' cmdline='%s' task="NPFMT"\n",
                   name, cmdLine, hTask );
 
     return hTask;
@@ -646,11 +664,12 @@
     if (!hTask) return;  /* Do nothing */
 
     pNewTask = (TDB *)GlobalLock( hTask );
-    dprintf_task( stddeb, "Switching to task %04x (%.8s)\n",
+    dprintf_task( stddeb, "Switching to task "NPFMT" (%.8s)\n",
                   hTask, pNewTask->module_name );
 
       /* Save the stacks of the previous task (if any) */
 
+#ifndef WINELIB /* FIXME: JBP: IF1632 not allowed in libwine.a */
     if (pOldTask)
     {
         pOldTask->ss  = IF1632_Saved16_ss;
@@ -658,6 +677,7 @@
         pOldTask->esp = IF1632_Saved32_esp;
     }
     else IF1632_Original32_esp = IF1632_Saved32_esp;
+#endif
 
      /* Make the task the last in the linked list (round-robin scheduling) */
 
@@ -669,10 +689,12 @@
       /* Switch to the new stack */
 
     hCurrentTask = hTask;
+#ifndef WINELIB /* FIXME: JBP: IF1632 not allowed in libwine.a */
     IF1632_Saved16_ss   = pNewTask->ss;
     IF1632_Saved16_sp   = pNewTask->sp;
     IF1632_Saved32_esp  = pNewTask->esp;
     IF1632_Stack32_base = WIN16_GlobalLock( pNewTask->hStack32 );
+#endif
 }
 
 
@@ -722,9 +744,9 @@
     context.sc_ebx = 0x81;
     context.sc_ecx = pModule->stack_size;
     context.sc_edx = pTask->nCmdShow;
-    context.sc_esi = pTask->hPrevInstance;
-    context.sc_edi = pTask->hInstance;
-    context.sc_es  = pTask->hPDB;
+    context.sc_esi = (DWORD)pTask->hPrevInstance;
+    context.sc_edi = (DWORD)pTask->hInstance;
+    context.sc_es  = (WORD)pTask->hPDB;
 
     /* Initialize the local heap */
     if ( pModule->heap_size )
@@ -741,7 +763,9 @@
     pinstance = (INSTANCEDATA *)PTR_SEG_OFF_TO_LIN(CURRENT_DS, 0);
     pinstance->stackbottom = stackhi; /* yup, that's right. Confused me too. */
     pinstance->stacktop    = stacklow; 
+#ifndef WINELIB /* FIXME: JBP: IF1632 not allowed in libwine.a */
     pinstance->stackmin    = IF1632_Saved16_sp;
+#endif
 }
 
 
@@ -869,12 +893,14 @@
     if (!thunkaddr) return (FARPROC)0;
     thunk = PTR_SEG_TO_LIN( thunkaddr );
 
-    dprintf_task( stddeb, "MakeProcInstance(%08lx,%04x): got thunk %08lx\n",
+    dprintf_task( stddeb, "MakeProcInstance(%08lx,"NPFMT"): got thunk %08lx\n",
                   (SEGPTR)func, hInstance, (SEGPTR)thunkaddr );
     
     *thunk++ = 0xb8;    /* movw instance, %ax */
+#ifndef WINELIB
     *thunk++ = (BYTE)(hInstance & 0xff);
     *thunk++ = (BYTE)(hInstance >> 8);
+#endif
     *thunk++ = 0xea;    /* ljmp func */
     *(DWORD *)thunk = (DWORD)func;
     return (FARPROC)thunkaddr;
@@ -908,7 +934,7 @@
     else
         handle = GlobalHandle( HIWORD(proc) );
 
-    printf( "STUB: GetCodeHandle(%08lx) returning %04x\n",
+    printf( "STUB: GetCodeHandle(%08lx) returning "NPFMT"\n",
             (DWORD)proc, handle );
     return handle;
 }
@@ -949,14 +975,18 @@
 HTASK GetCurrentTask(void)
 {
       /* Undocumented: first task is returned in high word */
+#ifdef WINELIB32
+    return hCurrentTask;
+#else
     return MAKELONG( hCurrentTask, hFirstTask );
+#endif
 }
 
 
 /***********************************************************************
  *           GetCurrentPDB   (KERNEL.37)
  */
-WORD GetCurrentPDB(void)
+HANDLE GetCurrentPDB(void)
 {
     TDB *pTask;
 
@@ -986,7 +1016,7 @@
     TDB *pTask;
 
     if (!(pTask = (TDB *)GlobalLock( hCurrentTask ))) return 0;
-    return WIN16_GlobalLock( pTask->pdb.environment );
+    return (SEGPTR)WIN16_GlobalLock( pTask->pdb.environment );
 }
 
 
@@ -1002,7 +1032,7 @@
 /***********************************************************************
  *           GetTaskDS   (KERNEL.155)
  */
-WORD GetTaskDS(void)
+HINSTANCE GetTaskDS(void)
 {
     TDB *pTask;
 
@@ -1040,7 +1070,12 @@
 
       /* Check the owner for module handle */
 
+#ifndef WINELIB
     owner = FarGetOwner( handle );
+#else
+    owner = NULL;
+    fprintf(stderr,"JBP: FarGetOwner() ignored.\n");
+#endif
     if (!(ptr = GlobalLock( owner ))) return 0;
     if (((NE_MODULE *)ptr)->magic == NE_SIGNATURE) return owner;
 
@@ -1082,7 +1117,7 @@
     TDB *pTask;
     INSTANCEDATA *pInstData;
 
-    dprintf_toolhelp( stddeb, "TaskNext(%p): task=%04x\n", lpte, lpte->hNext );
+    dprintf_toolhelp( stddeb, "TaskNext(%p): task="NPFMT"\n", lpte, lpte->hNext );
     if (!lpte->hNext) return FALSE;
     pTask = (TDB *)GlobalLock( lpte->hNext );
     if (!pTask || pTask->magic != TDB_MAGIC) return FALSE;
diff --git a/memory/Imakefile b/memory/Imakefile
deleted file mode 100644
index 5d738d1..0000000
--- a/memory/Imakefile
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = memory
-
-SRCS = \
-	atom.c \
-	global.c \
-	ldt.c \
-	local.c \
-	selector.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/memory/global.c b/memory/global.c
index 83f0dda..0689c88 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -409,7 +409,7 @@
  *
  * This is the GlobalLock() function used by 32-bit code.
  */
-LPSTR GlobalLock( HGLOBAL handle )
+LPVOID GlobalLock( HGLOBAL handle )
 {
     if (!handle) return 0;
 #ifdef CONFIG_IPC
@@ -446,7 +446,7 @@
 DWORD GlobalHandle( WORD sel )
 {
     dprintf_global( stddeb, "GlobalHandle: %04x\n", sel );
-    return MAKELONG( GET_ARENA_PTR(sel)->handle, sel );
+    return MAKELONG( GET_ARENA_PTR(sel)->handle, GlobalHandleToSel(sel) );
 }
 
 
diff --git a/memory/ldt.c b/memory/ldt.c
index 2b07893..9500f2b 100644
--- a/memory/ldt.c
+++ b/memory/ldt.c
@@ -7,7 +7,11 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#ifdef __svr4__
+#include <string.h>
+#else
 #include <strings.h>
+#endif
 #include <errno.h>
 #include "ldt.h"
 #include "stddebug.h"
@@ -22,6 +26,10 @@
 
 _syscall3(int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount)
 #endif  /* linux */
+#ifdef __svr4__
+#include <sys/sysi86.h>
+#include <sys/seg.h>
+#endif
 
 #if defined(__NetBSD__) || defined(__FreeBSD__)
 #include <machine/segments.h>
@@ -148,6 +156,35 @@
         }
     }
 #endif  /* __NetBSD__ || __FreeBSD__ */
+#ifdef __svr4__
+{
+    struct ssd ldt_mod;
+    int i;
+    ldt_mod.sel = ENTRY_TO_SELECTOR(entry) | 4;
+    ldt_mod.bo = content->base;
+    ldt_mod.ls = content->limit;
+    i =   (content->limit & 0xf0000) |
+        (content->type << 10) |
+            (((content->read_only != 0) ^ 1) << 9) |
+                ((content->seg_32bit != 0) << 22) |
+                    ((content->limit_in_pages != 0)<< 23) |
+                        (1<<15) |
+                            0x7000;
+
+    ldt_mod.acc1 = (i & 0xff00) >> 8;
+    ldt_mod.acc2 = (i & 0xf00000) >> 20;
+    
+    
+    if (content->base == 0)
+    {
+        ldt_mod.acc1 =  0;
+        ldt_mod.acc2 = 0;
+    }    
+    if ((i = sysi86(SI86DSCR, &ldt_mod)) == -1)
+        perror("sysi86");
+    
+}    
+#endif
 #endif  /* ifndef WINELIB */
 
     if (ret < 0) return ret;
@@ -168,12 +205,13 @@
  *
  * Print the content of the LDT on stdout.
  */
-void LDT_Print()
+void LDT_Print( int start, int length )
 {
     int i;
     char flags[3];
 
-    for (i = 0; i < LDT_SIZE; i++)
+    if (length == -1) length = LDT_SIZE - start;
+    for (i = start; i < start + length; i++)
     {
         if (!ldt_copy[i].base && !ldt_copy[i].limit) continue; /* Free entry */
         if ((ldt_flags_copy[i] & LDT_FLAGS_TYPE) == SEGMENT_CODE)
diff --git a/memory/local.c b/memory/local.c
index fa5845b..9f215af 100644
--- a/memory/local.c
+++ b/memory/local.c
@@ -285,7 +285,7 @@
 /***********************************************************************
  *           LocalInit   (KERNEL.4)
  */
-HLOCAL LocalInit( WORD selector, WORD start, WORD end )
+BOOL LocalInit( HANDLE selector, WORD start, WORD end )
 {
     char *ptr;
     WORD heapInfoArena, freeArena, lastArena;
@@ -672,7 +672,7 @@
  *
  * Implementation of LocalFree().
  */
-HLOCAL LOCAL_Free( WORD ds, HLOCAL handle )
+HLOCAL LOCAL_Free( HANDLE ds, HLOCAL handle )
 {
     char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
     WORD arena;
@@ -696,7 +696,7 @@
  *
  * Implementation of LocalAlloc().
  */
-HLOCAL LOCAL_Alloc( WORD ds, WORD flags, WORD size )
+HLOCAL LOCAL_Alloc( HANDLE ds, WORD flags, WORD size )
 {
     char *ptr;
     HLOCAL handle;
@@ -732,7 +732,7 @@
  *
  * Implementation of LocalReAlloc().
  */
-HLOCAL LOCAL_ReAlloc( WORD ds, HLOCAL handle, WORD size, WORD flags )
+HLOCAL LOCAL_ReAlloc( HANDLE ds, HLOCAL handle, WORD size, WORD flags )
 {
     char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
     LOCALHEAPINFO *pInfo;
@@ -820,7 +820,7 @@
 /***********************************************************************
  *           LOCAL_Lock
  */
-WORD LOCAL_Lock( WORD ds, HLOCAL handle )
+HANDLE LOCAL_Lock( HANDLE ds, HLOCAL handle )
 {
     char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
 
@@ -922,7 +922,7 @@
 /***********************************************************************
  *           LocalLock   (KERNEL.8)
  */
-WORD LocalLock( HLOCAL handle )
+NPVOID LocalLock( HLOCAL handle )
 {
     return LOCAL_Lock( CURRENT_DS, handle );
 }
diff --git a/memory/selector.c b/memory/selector.c
index fed873d..8ca361a 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -358,7 +358,7 @@
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
     if ((entry.type == SEGMENT_CODE) && entry.read_only) return TRUE;
     if (strlen(PTR_SEG_TO_LIN(ptr)) < size) size = strlen(PTR_SEG_TO_LIN(ptr));
-    if (OFFSETOF(ptr) + size > entry.limit) return TRUE;
+    if (OFFSETOF(ptr) + size - 1 > entry.limit) return TRUE;
     return FALSE;
 }
 
@@ -376,7 +376,7 @@
     if (IS_SELECTOR_FREE(sel)) return TRUE;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
     if ((entry.type == SEGMENT_CODE) && entry.read_only) return TRUE;
-    if (OFFSETOF(ptr) + size > entry.limit) return TRUE;
+    if (OFFSETOF(ptr) + size - 1 > entry.limit) return TRUE;
     return FALSE;
 }
 
@@ -394,7 +394,7 @@
     if (IS_SELECTOR_FREE(sel)) return TRUE;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
     if ((entry.type == SEGMENT_CODE) || entry.read_only) return TRUE;
-    if (OFFSETOF(ptr) + size > entry.limit) return TRUE;
+    if (OFFSETOF(ptr) + size - 1 > entry.limit) return TRUE;
     return FALSE;
 }
 
diff --git a/misc/Imakefile b/misc/Imakefile
deleted file mode 100644
index 2b89bd7..0000000
--- a/misc/Imakefile
+++ /dev/null
@@ -1,42 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = misc
-
-SRCS = \
-	clipboard.c \
-	comm.c \
-	commdlg.c \
-	compobj.c \
-	dos_fs.c \
-	driver.c \
-	exec.c \
-	escape.c \
-	file.c \
-	keyboard.c \
-	kernel32.c \
-	lstr.c \
-	main.c \
-	ole2.c \
-	ole2disp.c \
-	ole2nls.c \
-	olecli.c \
-	olesvr.c \
-	network.c \
-	profile.c \
-	rect.c \
-	shell.c \
-	sound.c \
-	spy.c \
-	stress.c \
-	user.c \
-	user32.c \
-	winsocket.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/misc/Makefile.in b/misc/Makefile.in
index c606b94..778e331 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -12,7 +12,6 @@
 	escape.c \
 	file.c \
 	keyboard.c \
-	kernel32.c \
 	lstr.c \
 	main.c \
 	ole2.c \
diff --git a/misc/clipboard.c b/misc/clipboard.c
index fef309d..d3df59d 100644
--- a/misc/clipboard.c
+++ b/misc/clipboard.c
@@ -59,7 +59,7 @@
 {
     if (hWndClipboardOwner != 0) return FALSE;
     hWndClipboardOwner = hWnd;
-    dprintf_clipboard(stddeb,"OpenClipboard(%04X); !\n", hWnd);
+    dprintf_clipboard(stddeb,"OpenClipboard("NPFMT"); !\n", hWnd);
     return TRUE;
 }
 
@@ -107,7 +107,7 @@
 HWND GetClipboardOwner()
 {
     dprintf_clipboard(stddeb,
-		"GetClipboardOwner() = %04X !\n", hWndClipboardOwner);
+		"GetClipboardOwner() = "NPFMT" !\n", hWndClipboardOwner);
     return hWndClipboardOwner;
 }
 
@@ -119,7 +119,7 @@
 {
     LPCLIPFORMAT lpFormat = ClipFormats; 
     dprintf_clipboard(stddeb,
-		"SetClipboardDate(%04X, %04X) !\n", wFormat, hData);
+		"SetClipboardDate(%04X, "NPFMT") !\n", wFormat, hData);
     while(TRUE) {
 	if (lpFormat == NULL) return 0;
 	if (lpFormat->wFormatID == wFormat) break;
@@ -173,7 +173,7 @@
 	if (lpFormat == NULL) break;
 	if (lpFormat->hData != 0) {
         dprintf_clipboard(stddeb,
-		"CountClipboardFormats // Find Not Empty (%04X) !\n",
+		"CountClipboardFormats // Find Not Empty ("NPFMT") !\n",
 					lpFormat->hData);
 	    FormatCount++;
 	    }
@@ -211,7 +211,7 @@
 	lpFormat = lpFormat->NextFormat;
 	}
     dprintf_clipboard(stddeb,
-		"EnumClipboardFormats // Find Not Empty Id=%04X hData=%04X !\n",
+		"EnumClipboardFormats // Find Not Empty Id=%04X hData="NPFMT" !\n",
 				lpFormat->wFormatID, lpFormat->hData);
     return lpFormat->wFormatID;
 }
@@ -279,7 +279,7 @@
 HWND SetClipboardViewer(HWND hWnd)
 {
     HWND hwndPrev = hWndViewer;
-    dprintf_clipboard(stddeb,"SetClipboardViewer(%04X) !\n", hWnd);
+    dprintf_clipboard(stddeb,"SetClipboardViewer("NPFMT") !\n", hWnd);
     hWndViewer = hWnd;
     return hwndPrev;
 }
@@ -290,7 +290,7 @@
  */
 HWND GetClipboardViewer()
 {
-    dprintf_clipboard(stddeb,"GetClipboardFormat() = %04X !\n", hWndViewer);
+    dprintf_clipboard(stddeb,"GetClipboardFormat() = "NPFMT" !\n", hWndViewer);
     return hWndViewer;
 }
 
@@ -301,7 +301,7 @@
 BOOL ChangeClipboardChain(HWND hWnd, HWND hWndNext)
 {
     dprintf_clipboard(stdnimp,
-		"ChangeClipboardChain(%04X, %04X) !\n", hWnd, hWndNext);
+		"ChangeClipboardChain("NPFMT", "NPFMT") !\n", hWnd, hWndNext);
 
      return 0;
 }
@@ -331,7 +331,7 @@
 HWND GetOpenClipboardWindow()
 {
     dprintf_clipboard(stddeb,
-		"GetOpenClipboardWindow() = %04X !\n", hWndClipboardOwner);
+		"GetOpenClipboardWindow() = "NPFMT" !\n", hWndClipboardOwner);
     return hWndClipboardOwner;
 }
 
diff --git a/misc/comm.c b/misc/comm.c
index 4da7e7e..bce491c 100644
--- a/misc/comm.c
+++ b/misc/comm.c
@@ -358,6 +358,7 @@
 			port.c_cflag &= TIOCM_RTS;
 			break;
 	
+#ifndef __svr4__
 		case SETDTR:
 			port.c_cflag |= CRTSCTS;
 			break;
@@ -365,6 +366,7 @@
 		case SETRTS:
 			port.c_cflag |= CRTSCTS;
 			break;
+#endif
 
 		case SETXOFF:
 			port.c_iflag |= IXOFF;
@@ -618,11 +620,13 @@
 			commerror = IE_BYTESIZE;
 			return -1;
 	}
+#ifndef __svr4__
 
 	if (lpdcb->fDtrflow || lpdcb->fRtsflow || lpdcb->fOutxCtsFlow)
 		port.c_cflag |= CRTSCTS;
 
 	if (lpdcb->fDtrDisable) 
+#endif
 		port.c_cflag &= ~CRTSCTS;
 	
 	if (lpdcb->fInX)
@@ -724,12 +728,14 @@
 	lpdcb->fChEvt = 0;
 	lpdcb->fBinary = 1;
 
+#ifndef __svr4__
 	lpdcb->fDtrDisable = 0;
 	if (port.c_cflag & CRTSCTS) {
 		lpdcb->fDtrflow = 1;
 		lpdcb->fRtsflow = 1;
 		lpdcb->fOutxCtsFlow = 1;
 		lpdcb->fOutxDsrFlow = 1;
+#endif
 	} else 
 		lpdcb->fDtrDisable = 1;
 
diff --git a/misc/commdlg.c b/misc/commdlg.c
index 774cc84..f85624f 100644
--- a/misc/commdlg.c
+++ b/misc/commdlg.c
@@ -83,7 +83,7 @@
         return FALSE;
     }
 
-    hInst = GetWindowWord( lpofn->hwndOwner, GWW_HINSTANCE );
+    hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
     bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
                                    GetWndProcEntry16("FileOpenDlgProc"),
                                    (DWORD)lpofn );
@@ -130,7 +130,7 @@
                                         TRUE, NULL );
 
 
-    hInst = GetWindowWord( lpofn->hwndOwner, GWW_HINSTANCE );
+    hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
     bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
                                    GetWndProcEntry16("FileSaveDlgProc"),
                                    (DWORD)lpofn); 
@@ -513,7 +513,13 @@
 	strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
       }
       lpofn->nFileOffset = 0;
-      lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
+      lpofn->nFileExtension = 0;
+      while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
+        lpofn->nFileExtension++;
+      if (lpofn->nFileExtension == '\0')
+	lpofn->nFileExtension = 0;
+      else
+	lpofn->nFileExtension++;
       if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) 
 	{
 	  lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
@@ -534,7 +540,7 @@
 /***********************************************************************
  *           FileOpenDlgProc   (COMMDLG.6)
  */
-BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
+LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {  
   switch (wMsg)
     {
@@ -568,7 +574,7 @@
 /***********************************************************************
  *           FileSaveDlgProc   (COMMDLG.7)
  */
-BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
+LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {
   switch (wMsg) {
    case WM_INITDIALOG:
@@ -614,7 +620,7 @@
     hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_CHOOSE_COLOR.bytes,
                                   sysres_DIALOG_CHOOSE_COLOR.size,
                                   GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
-    hInst = GetWindowWord( lpChCol->hwndOwner, GWW_HINSTANCE );
+    hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
     bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
                                    GetWndProcEntry16("ColorDlgProc"), 
                                    (DWORD)lpChCol );
@@ -626,7 +632,7 @@
 /***********************************************************************
  *           ColorDlgProc   (COMMDLG.8)
  */
-BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
+LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {
   switch (wMsg) 
     {
@@ -661,7 +667,7 @@
     hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_FIND_TEXT.bytes,
                                   sysres_DIALOG_FIND_TEXT.size,
                                   GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
-    hInst = GetWindowWord( lpFind->hwndOwner, GWW_HINSTANCE );
+    hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
     bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
                                    GetWndProcEntry16("FindTextDlgProc"), 
                                    (DWORD)lpFind );
@@ -681,7 +687,7 @@
     hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_REPLACE_TEXT.bytes,
                                   sysres_DIALOG_REPLACE_TEXT.size,
                                   GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
-    hInst = GetWindowWord( lpFind->hwndOwner, GWW_HINSTANCE );
+    hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
     bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
                                    GetWndProcEntry16("ReplaceTextDlgProc"), 
                                    (DWORD)lpFind );
@@ -693,7 +699,7 @@
 /***********************************************************************
  *           FindTextDlgProc   (COMMDLG.13)
  */
-BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
+LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {
   switch (wMsg)
     {
@@ -720,7 +726,7 @@
 /***********************************************************************
  *           ReplaceTextDlgProc   (COMMDLG.14)
  */
-BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
+LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {
   switch (wMsg)
     {
@@ -754,6 +760,10 @@
 
     printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
 
+    if (lpPrint->Flags & PD_RETURNDEFAULT)
+        /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
+        return TRUE;
+
     if (lpPrint->Flags & PD_PRINTSETUP)
         hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED,
                                        sysres_DIALOG_PRINT_SETUP.bytes,
@@ -766,7 +776,7 @@
                                        GetCurrentPDB(), FALSE,
                                        FALSE, TRUE, NULL );
 
-    hInst = GetWindowWord( lpPrint->hwndOwner, GWW_HINSTANCE );
+    hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
     bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
                                    (lpPrint->Flags & PD_PRINTSETUP) ?
                                        GetWndProcEntry16("PrintSetupDlgProc") :
@@ -780,7 +790,7 @@
 /***********************************************************************
  *           PrintDlgProc   (COMMDLG.21)
  */
-BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
+LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {
   switch (wMsg)
     {
@@ -807,7 +817,7 @@
 /***********************************************************************
  *           PrintSetupDlgProc   (COMMDLG.22)
  */
-BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
+LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {
   switch (wMsg)
     {
diff --git a/misc/dos_fs.c b/misc/dos_fs.c
index a141798..6667058 100644
--- a/misc/dos_fs.c
+++ b/misc/dos_fs.c
@@ -24,7 +24,9 @@
 #include <sys/param.h>
 #include <sys/mount.h>
 #endif
-
+#ifdef __svr4__
+#include <sys/statfs.h>
+#endif
 #include "wine.h"
 #include "windows.h"
 #include "msdos.h"
@@ -60,6 +62,60 @@
 static struct DosDriveStruct DosDrives[MAX_DOS_DRIVES];
 static struct dosdirent *DosDirs=NULL;
 
+WORD ExtendedError;
+BYTE ErrorClass, Action, ErrorLocus;
+
+int DOS_Error(int e, int class, int el)
+{
+	ErrorClass = class;
+	Action = SA_Ask4Retry;
+	ErrorLocus = el;
+	ExtendedError = e;
+
+	return e;
+}
+
+void errno_to_doserr(void)
+{
+	switch (errno) {
+		case EAGAIN:
+			DOS_Error (ShareViolation, EC_Temporary, EL_Unknown);
+			break;
+		case EBADF:
+			DOS_Error (InvalidHandle, EC_AppError, EL_Unknown);
+			break;
+		case ENOSPC:
+			DOS_Error (DiskFull, EC_MediaError, EL_Disk);
+			break;				
+		case EACCES:
+		case EPERM:
+		case EROFS:
+			DOS_Error (WriteProtected, EC_AccessDenied, EL_Unknown);
+			break;
+		case EBUSY:
+			DOS_Error (LockViolation, EC_AccessDenied, EL_Unknown);
+			break;		
+		case ENOENT:
+			DOS_Error (FileNotFound, EC_NotFound, EL_Unknown);
+			break;				
+		case EISDIR:
+			DOS_Error (CanNotMakeDir, EC_AccessDenied, EL_Unknown);
+			break;
+		case ENFILE:
+		case EMFILE:
+			DOS_Error (NoMoreFiles, EC_MediaError, EL_Unknown);
+			break;
+		case EEXIST:
+			DOS_Error (FileExists, EC_Exists, EL_Disk);
+			break;				
+		default:
+			dprintf_int(stddeb, "int21: unknown errno %d!\n", errno);
+			DOS_Error (GeneralFailure, EC_SystemFailure, EL_Unknown);
+			break;
+	}
+}
+
+
 static void ExpandTildeString(char *s)
 {
     struct passwd *entry;
@@ -88,7 +144,7 @@
     *s = 0;
 }
 
-/* Simplify the path in "name" by removing  "//"'s and
+/* Simplify the path in "name" by removing  "//"'s, "/./"'s, and
    ".."'s in names like "/usr/bin/../lib/test" */
 static void DOS_SimplifyPath(char *name)
 {
@@ -108,6 +164,9 @@
       strcpy(p,l+3);
       changed = TRUE;
     }
+    while ((l = strstr(name, "/./"))) {
+      strcpy(l, l+2); changed = TRUE;
+    }
   } while (changed);
   dprintf_dosfs(stddeb,"SimplifyPath: After %s\n",name);
 }
@@ -569,19 +628,27 @@
 	if (!DOS_ValidDrive(drive))
 		return 0;
 
+#ifdef __svr4__
+	if (statfs(DosDrives[drive].rootdir, &info, 0, 0) < 0) {
+#else
 	if (statfs(DosDrives[drive].rootdir, &info) < 0) {
+#endif
 		fprintf(stderr,"dosfs: cannot do statfs(%s)\n",
 			DosDrives[drive].rootdir);
 		return 0;
 	}
 
 	*size = info.f_bsize * info.f_blocks;
+#ifdef __svr4__
+	*available = info.f_bfree * info.f_bsize;
+#else
 	*available = info.f_bavail * info.f_bsize;
+#endif
 
 	return 1;
 }
 
-char *DOS_FindFile(char *buffer, int buflen, char *filename, char **extensions, 
+char *DOS_FindFile(char *buffer, int buflen, const char *filename, char **extensions, 
 		char *path)
 {
     char *workingpath, *dirname, *rootname, **e;
diff --git a/misc/driver.c b/misc/driver.c
index e9f5f40..7da4990 100644
--- a/misc/driver.c
+++ b/misc/driver.c
@@ -33,7 +33,7 @@
         	dprintf_driver(stddeb,"LoadStartupDrivers // str='%s'\n", ptr);
 		hDrv = OpenDriver(ptr, "drivers", 0L);
         	dprintf_driver(stddeb,
-			"LoadStartupDrivers // hDrv=%04X\n", hDrv);
+			"LoadStartupDrivers // hDrv="NPFMT"\n", hDrv);
 		ptr += strlen(ptr) + 1;
 		}
     	dprintf_driver(stddeb,"LoadStartupDrivers // end of list !\n");
@@ -44,7 +44,7 @@
  */
 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, WORD msg, LPARAM lParam1, LPARAM lParam2)
 {
-	dprintf_driver(stdnimp,"SendDriverMessage(%04X, %04X, %08lX, %08lX);\n",
+	dprintf_driver(stdnimp,"SendDriverMessage("NPFMT", %04X, %08lX, %08lX);\n",
 						hDriver, msg, lParam1, lParam2);
         return 0;
 }
@@ -93,7 +93,7 @@
 		lpnewdrv->lpPrevItem = lpdrv;
 		}
 	lpnewdrv->lpDrvProc = NULL;
-    	dprintf_driver(stddeb,"OpenDriver // hDrvr=%04X loaded !\n", hDrvr);
+    	dprintf_driver(stddeb,"OpenDriver // hDrvr="NPFMT" loaded !\n", hDrvr);
 	return hDrvr;
 }
 
@@ -104,7 +104,7 @@
 {
 	LPDRIVERITEM	lpdrv;
     	dprintf_driver(stddeb,
-		"CloseDriver(%04X, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
+		"CloseDriver("NPFMT", %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
 	lpdrv = (LPDRIVERITEM) GlobalLock(hDrvr);
 	if (lpdrv != NULL && lpdrv->dis.hDriver == hDrvr) {
 		if (lpdrv->lpPrevItem)
@@ -113,7 +113,7 @@
 			((LPDRIVERITEM)lpdrv->lpNextItem)->lpPrevItem = lpdrv->lpPrevItem;
 		GlobalUnlock(hDrvr);
 		GlobalFree(hDrvr);
-        dprintf_driver(stddeb,"CloseDriver // hDrvr=%04X closed !\n", hDrvr);
+        dprintf_driver(stddeb,"CloseDriver // hDrvr="NPFMT" closed !\n", hDrvr);
 		return TRUE;
 		}
 	return FALSE;
@@ -126,7 +126,7 @@
 {
 	LPDRIVERITEM	lpdrv;
 	HANDLE			hModule = 0;
-    	dprintf_driver(stddeb,"GetDriverModuleHandle(%04X);\n", hDrvr);
+    	dprintf_driver(stddeb,"GetDriverModuleHandle("NPFMT");\n", hDrvr);
 	lpdrv = (LPDRIVERITEM) GlobalLock(hDrvr);
 	if (lpdrv != NULL) {
 		hModule = lpdrv->dis.hModule;
@@ -175,7 +175,7 @@
 BOOL GetDriverInfo(HDRVR hDrvr, LPDRIVERINFOSTRUCT lpDrvInfo)
 {
 	LPDRIVERITEM	lpdrv;
-    	dprintf_driver(stddeb,"GetDriverInfo(%04X, %p);\n", hDrvr, lpDrvInfo);
+    	dprintf_driver(stddeb,"GetDriverInfo("NPFMT", %p);\n", hDrvr, lpDrvInfo);
 	if (lpDrvInfo == NULL) return FALSE;
 	lpdrv = (LPDRIVERITEM) GlobalLock(hDrvr);
 	if (lpdrv == NULL) return FALSE;
@@ -191,7 +191,7 @@
 {
 	LPDRIVERITEM	lpdrv;
 	HDRVR			hRetDrv = 0;
-    	dprintf_driver(stddeb,"GetNextDriver(%04X, %08lX);\n", hDrvr, dwFlags);
+    	dprintf_driver(stddeb,"GetNextDriver("NPFMT", %08lX);\n", hDrvr, dwFlags);
 	if (hDrvr == 0) {
 		if (lpDrvItemList == NULL) {
             		dprintf_driver(stddeb,
@@ -199,7 +199,7 @@
 			LoadStartupDrivers();
 			if (lpDrvItemList == NULL) return 0;
 			}
-        	dprintf_driver(stddeb,"GetNextDriver // return first %04X !\n",
+        	dprintf_driver(stddeb,"GetNextDriver // return first "NPFMT" !\n",
 					lpDrvItemList->dis.hDriver);
 		return lpDrvItemList->dis.hDriver;
 		}
@@ -215,7 +215,7 @@
 			}
 		GlobalUnlock(hDrvr);
 		}
-    	dprintf_driver(stddeb,"GetNextDriver // return %04X !\n", hRetDrv);
+    	dprintf_driver(stddeb,"GetNextDriver // return "NPFMT" !\n", hRetDrv);
 	return hRetDrv;
 }
 
diff --git a/misc/file.c b/misc/file.c
index 2488c63..b9bcc06 100644
--- a/misc/file.c
+++ b/misc/file.c
@@ -139,7 +139,7 @@
 /**************************************************************************
  OpenFile
  **************************************************************************/
-INT OpenFile (LPSTR lpFileName, LPOFSTRUCT ofs, WORD wStyle)
+INT OpenFile (LPCSTR lpFileName, LPOFSTRUCT ofs, UINT wStyle)
 {
     char         filename[MAX_PATH+1];
     int          action;
@@ -149,10 +149,9 @@
     int          verify_time = 0;
   
     dprintf_file(stddeb,"Openfile(%s,<struct>,%d)\n",lpFileName,wStyle);
-  
+ 
     action = wStyle & 0xff00;
   
-  
     /* OF_CREATE is completly different from all other options, so
        handle it first */
 
@@ -251,7 +250,7 @@
     
 
     if (action & OF_PARSE)
-      return 0;
+        return 0;
 
     if (action & OF_DELETE)
       return unlink(ofs->szPathName);
@@ -355,9 +354,13 @@
 {
 
     	dprintf_file(stddeb,"GetDriveType %c:\n",'A'+drive);
+ 
+        /* File Damager thinks that only return code 0 is bad enough 
+	 * -Al K
+	 */
 
 	if (!DOS_ValidDrive(drive))
-		return DRIVE_DOESNOTEXIST;
+		return DRIVE_CANNOTDETERMINE;
 
 	if (drive == 0 || drive == 1)
 		return DRIVE_REMOVABLE;
diff --git a/misc/kernel32.c b/misc/kernel32.c
deleted file mode 100644
index df6a5ba..0000000
--- a/misc/kernel32.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Win32 kernel functions
- *
- * Copyright 1995 Martin von Loewis
- */
-
-/* This file contains only wrappers to existing Wine functions or trivial
-   stubs. 'Real' implementations go into context specific files */
-
-#include "windows.h"
-#include "winerror.h"
-#include <unistd.h>
-
-int WIN32_LastError;
-
-/***********************************************************************
- *           GetCommandLineA      (KERNEL32.161)
- */
-LPSTR GetCommandLineA(void)
-{
-	return 0;
-}
-
-/***********************************************************************
- *           GetCurrentThreadId   (KERNEL32.200)
- */
-
-int GetCurrentThreadId(void)
-{
-	return getpid();
-}
-
-
-/***********************************************************************
- *           GetEnvironmentStrings    (KERNEL32.210)
- */
-LPSTR GetEnvironmentStrings(void)
-{
-	return 0;
-}
-
-/***********************************************************************
- *           GetStdHandle             (KERNEL32.276)
- */
-HANDLE GetStdHandle(DWORD nStdHandle)
-{
-	switch(nStdHandle)
-	{
-		case -10/*STD_INPUT_HANDLE*/:return 0;
-		case -11/*STD_OUTPUT_HANDLE*/:return 1;
-		case -12/*STD_ERROR_HANDLE*/:return 2;
-	}
-	return -1;
-}
-
-/***********************************************************************
- *           GetThreadContext         (KERNEL32.294)
- */
-BOOL GetThreadContext(HANDLE hThread, void *lpContext)
-{
-	return FALSE;
-}
diff --git a/misc/main.c b/misc/main.c
index 2a70dc4..d8876a1 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -31,7 +31,7 @@
 const char people[] = "Wine is available thanks to the work of "
 "Bob Amstadt, Dag Asheim, Martin Ayotte, Ross Biro, Erik Bos, "
 "Fons Botman, John Brezak, Andrew Bulhak, John Burton, Paul Falstad, "
-"Olaf Flebbe, Peter Galbavy, Ramon Garcia, Hans de Graaf, "
+"Olaf Flebbe, Peter Galbavy, Ramon Garcia, Hans de Graaff, "
 "Charles M. Hannum, Cameron Heide, Jochen Hoenicke, Jeffrey Hsu, "
 "Miguel de Icaza, Alexandre Julliard, Jon Konrath, Scott A. Laird, "
 "Martin von Loewis, Kenneth MacDonald, Peter MacDonald, William Magro, "
@@ -114,7 +114,7 @@
   "    -fixedmap       Use a \"standard\" color map\n" \
   "    -synchronous    Turn on synchronous display mode\n" \
   "    -backingstore   Turn on backing store\n" \
-  "    -spy file       Obsolete. Use -debugmsg +spy for Spy messages\n" \
+  "    -spy file       Obsolete. Use -debugmsg +message for messages\n" \
   "    -debugmsg name  Turn debugging-messages on or off\n" \
   "    -dll name       Enable or disable built-in DLLs\n" \
   "    -allowreadonly  Read only files may be opened in write mode\n" \
@@ -483,10 +483,12 @@
 static void called_at_exit(void)
 {
     extern void sync_profiles(void);
+    extern void SHELL_SaveRegistry(void);
 
     sync_profiles();
     MAIN_RestoreSetup();
     WSACleanup();
+    SHELL_SaveRegistry();
 }
 
 /***********************************************************************
@@ -499,6 +501,7 @@
     int *depth_list;
 
     extern int _WinMain(int argc, char **argv);
+    extern void SHELL_LoadRegistry(void);
 
     setbuf(stdout,NULL);
     setbuf(stderr,NULL);
@@ -525,6 +528,8 @@
     }
 #endif
 
+    SHELL_LoadRegistry();
+
     screen       = DefaultScreenOfDisplay( display );
     screenWidth  = WidthOfScreen( screen );
     screenHeight = HeightOfScreen( screen );
@@ -579,10 +584,16 @@
  */
 LONG GetWinFlags(void)
 {
+  static const long cpuflags[5] =
+    { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
+
+  /* There doesn't seem to be any Pentium flag.  */
+  long cpuflag = cpuflags[min (runtime_cpu (), 4)];
+
   if (Options.enhanced)
-    return (WF_ENHANCED | WF_CPU386 | WF_PMODE | WF_80x87 | WF_PAGING);
+    return (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
   else
-    return (WF_STANDARD | WF_CPU386 | WF_PMODE | WF_80x87);
+    return (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
 }
 
 /***********************************************************************
@@ -653,6 +664,17 @@
 }
 
 /***********************************************************************
+ *      SetEnvironmentVariableA (KERNEL32.484)
+ */
+BOOL SetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue)
+{
+    int rc;
+
+    rc = SetEnvironment(lpName, lpValue, strlen(lpValue) + 1);
+    return (rc > 0) ? 1 : 0;
+}
+
+/***********************************************************************
  *	GetEnvironment (GDI.134)
  */
 int GetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nMaxSiz)
@@ -675,6 +697,59 @@
 }
 
 /***********************************************************************
+ *      GetEnvironmentVariableA (KERNEL32.213)
+ */
+DWORD GetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue, DWORD size)
+{
+    return GetEnvironment(lpName, lpValue, size);
+}
+
+/***********************************************************************
+ *      GetEnvironmentStrings (KERNEL32.210)
+ */
+LPVOID GetEnvironmentStrings(void)
+{
+    int count;
+    LPENVENTRY lpEnv;
+    char *envtable, *envptr;
+
+    /* Count the total number of bytes we'll need for the string
+     * table.  Include the trailing nuls and the final double nul.
+     */
+    count = 1;
+    lpEnv = lpEnvList;
+    while(lpEnv != NULL)
+    {
+        if(lpEnv->Name != NULL)
+        {
+            count += strlen(lpEnv->Name) + 1;
+            count += strlen(lpEnv->Value) + 1;
+        }
+        lpEnv = lpEnv->Next;
+    }
+
+    envtable = malloc(count);
+    if(envtable)
+    {
+        lpEnv = lpEnvList;
+        envptr = envtable;
+
+        while(lpEnv != NULL)
+        {
+            if(lpEnv->Name != NULL)
+            {
+                count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
+                envptr += count + 1;
+            }
+            lpEnv = lpEnv->Next;
+        }
+        *envptr = '\0';
+    }
+
+    return envtable;
+}
+
+/***********************************************************************
  *	GetTimerResolution (USER.14)
  */
 LONG GetTimerResolution(void)
diff --git a/misc/network.c b/misc/network.c
index abf7e1b..b798a5e 100644
--- a/misc/network.c
+++ b/misc/network.c
@@ -119,7 +119,7 @@
  */
 int WNetWatchQueue(HWND hWnd,LPSTR szLocal,LPSTR szUser,WORD nQueue)
 {
-	printf("EMPTY STUB !!! WNetWatchQueue(%x,'%s','%s',%x)\n",
+	printf("EMPTY STUB !!! WNetWatchQueue("NPFMT",'%s','%s',%x)\n",
 		hWnd,szLocal,szUser,nQueue);
 	return WN_NET_ERROR;
 }
@@ -196,7 +196,7 @@
  */
 int WNetDeviceMode(HWND hWndOwner)
 {
-	printf("EMPTY STUB !!! WNetDeviceMode(%x)\n",hWndOwner);
+	printf("EMPTY STUB !!! WNetDeviceMode("NPFMT")\n",hWndOwner);
 	return WN_NET_ERROR;
 }
 
@@ -205,7 +205,7 @@
  */
 int WNetBrowseDialog(HWND hParent,WORD nType,LPSTR szPath)
 {
-	printf("EMPTY STUB !!! WNetBrowseDialog(%x,%x,'%s')\n",
+	printf("EMPTY STUB !!! WNetBrowseDialog("NPFMT",%x,'%s')\n",
 		hParent,nType,szPath);
 	return WN_NET_ERROR;
 }
@@ -265,7 +265,7 @@
  */
 int WNetRestoreConnection(HWND hwndOwner,LPSTR lpszDevice)
 {
-	printf("EMPTY STUB !!! WNetRestoreConnection(%x,'%s')\n",
+	printf("EMPTY STUB !!! WNetRestoreConnection("NPFMT",'%s')\n",
 		hwndOwner,lpszDevice);
 	return WN_NET_ERROR;
 }
@@ -273,9 +273,9 @@
 /**************************************************************************
  *              WNetWriteJob       [USER.524]
  */
-int WNetWriteJob(WORD hJob,void *lpData,LPWORD lpcbData)
+int WNetWriteJob(HANDLE hJob,void *lpData,LPWORD lpcbData)
 {
-	printf("EMPTY STUB !!! WNetWriteJob(%x,%p,%p)\n",
+	printf("EMPTY STUB !!! WNetWriteJob("NPFMT",%p,%p)\n",
 		hJob,lpData,lpcbData);
 	return WN_NET_ERROR;
 }
@@ -285,7 +285,7 @@
  */
 UINT WNetConnectDialog(HWND hWndParent, WORD iType)
 {
-	printf("EMPTY STUB !!! WNetConnectDialog(%4X, %4X)\n", hWndParent, iType);
+	printf("EMPTY STUB !!! WNetConnectDialog("NPFMT", %4X)\n", hWndParent, iType);
 	return WN_SUCCESS;
 }
 
@@ -294,7 +294,7 @@
  */
 int WNetDisconnectDialog(HWND hwndOwner, WORD iType)
 {
-	printf("EMPTY STUB !!! WNetDisconnectDialog(%x,%x)\n",
+	printf("EMPTY STUB !!! WNetDisconnectDialog("NPFMT",%x)\n",
 		hwndOwner,iType);
 	return WN_NET_ERROR;
 }
@@ -304,7 +304,7 @@
  */
 UINT WNetConnectionDialog(HWND hWndParent, WORD iType)
 {
-	printf("EMPTY STUB !!! WNetConnectionDialog(%4X, %4X)\n", 
+	printf("EMPTY STUB !!! WNetConnectionDialog("NPFMT", %4X)\n", 
 		hWndParent, iType);
 	return WN_SUCCESS;
 }
@@ -314,7 +314,7 @@
  */
 int WNetViewQueueDialog(HWND hwndOwner,LPSTR lpszQueue)
 {
-	printf("EMPTY STUB !!! WNetViewQueueDialog(%x,'%s')\n",
+	printf("EMPTY STUB !!! WNetViewQueueDialog("NPFMT",'%s')\n",
 		hwndOwner,lpszQueue);
 	return WN_NET_ERROR;
 }
@@ -325,7 +325,7 @@
 int WNetPropertyDialog(HWND hwndParent,WORD iButton,
 	WORD nPropSel,LPSTR lpszName,WORD nType)
 {
-	printf("EMPTY STUB !!! WNetPropertyDialog(%x,%x,%x,'%s',%x)\n",
+	printf("EMPTY STUB !!! WNetPropertyDialog("NPFMT",%x,%x,'%s',%x)\n",
 		hwndParent,iButton,nPropSel,lpszName,nType);
 	return WN_NET_ERROR;
 }
@@ -345,7 +345,7 @@
  */
 int WNetDirectoryNotify(HWND hwndOwner,void *lpDir,WORD wOper)
 {
-	printf("EMPTY STUB !!! WNetDirectoryNotify(%x,%p,%x)\n",
+	printf("EMPTY STUB !!! WNetDirectoryNotify("NPFMT",%p,%x)\n",
 		hwndOwner,lpDir,wOper);
 	return WN_NET_ERROR;
 }
@@ -356,7 +356,7 @@
 int WNetGetPropertyText(HWND hwndParent,WORD iButton,WORD nPropSel,
 	LPSTR lpszName,WORD nType)
 {
-	printf("EMPTY STUB !!! WNetGetPropertyText(%x,%x,%x,'%s',%x)\n",
+	printf("EMPTY STUB !!! WNetGetPropertyText("NPFMT",%x,%x,'%s',%x)\n",
 		hwndParent,iButton,nPropSel,lpszName,nType);
 	return WN_NET_ERROR;
 }
@@ -377,7 +377,7 @@
  */
 UINT WNetCloseEnum(HANDLE hEnum)
 {
-	printf("EMPTY STUB !!! WNetCloseEnum(%04X);\n", hEnum);
+	printf("EMPTY STUB !!! WNetCloseEnum("NPFMT");\n", hEnum);
 	return WN_NET_ERROR;
 }
 
@@ -387,7 +387,7 @@
 UINT WNetEnumResource(HANDLE hEnum, DWORD cRequ, 
 				DWORD *lpCount, LPVOID lpBuf)
 {
-	printf("EMPTY STUB !!! WNetEnumResource(%04X, %08lX, %p, %p);\n", 
+	printf("EMPTY STUB !!! WNetEnumResource("NPFMT", %08lX, %p, %p);\n", 
 							hEnum, cRequ, lpCount, lpBuf);
 	return WN_NET_ERROR;
 }
diff --git a/misc/ole2disp.c b/misc/ole2disp.c
index 92dba48..edb461c 100644
--- a/misc/ole2disp.c
+++ b/misc/ole2disp.c
@@ -31,12 +31,20 @@
 	if(!BSTRheapsel)
 		return 0;
 	mem=LOCAL_Alloc(BSTRheapsel,LMEM_FIXED,n);
+#ifdef WINELIB32
+	return (BSTR)mem;
+#else
 	return mem ? MAKELONG(mem,BSTRheapsel) : 0;
+#endif
 }
 
 static void BSTR_Free(BSTR in)
 {
+#ifdef WINELIB32
+	LOCAL_Free(BSTRheapsel, (HANDLE)in);
+#else
 	LOCAL_Free(BSTRheapsel, LOWORD(in));
+#endif
 }
 
 static void* BSTR_GetAddr(BSTR in)
diff --git a/misc/ole2nls.c b/misc/ole2nls.c
index fbec3d7..5915ce8 100644
--- a/misc/ole2nls.c
+++ b/misc/ole2nls.c
@@ -26,6 +26,8 @@
 	return 7;
 #elif #LANG(Es)
 	return 7; /* Just a Guess :-) */
+#elif #LANG(Fr)
+	return 7; /* ditto :-) */
 #elif #LANG(No)
 	return 0x14;
 #else
diff --git a/misc/olecli.c b/misc/olecli.c
index 0dadd1a..ca5ca9d 100644
--- a/misc/olecli.c
+++ b/misc/olecli.c
@@ -52,6 +52,6 @@
  */
 BOOL WINAPI OleIsDcMeta(HDC hdc)
 {
-	dprintf_ole(stddeb,"OleIsDCMeta(%04X)\n",hdc);
+	dprintf_ole(stddeb,"OleIsDCMeta("NPFMT")\n",hdc);
 	return GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ) != 0;
 }
diff --git a/misc/shell.c b/misc/shell.c
index 7588a57..12822f1 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -15,6 +15,7 @@
 #include "relay32.h"
 #include "../rc/sysres.h"
 #include "dlgs.h"
+#include "win.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -36,7 +37,7 @@
         printf("SHELL_RegCheckForRoot: Couldn't allocate root key!\n");
         return ERROR_OUTOFMEMORY;
       }
-      lphRootKey->hKey = 1;
+      lphRootKey->hKey = (HKEY)1;
       lphRootKey->lpSubKey = RootKeyName;
       lphRootKey->dwType = 0;
       lphRootKey->lpValue = NULL;
@@ -60,6 +61,157 @@
     return ERROR_SUCCESS;
 }
 
+/* FIXME: the loading and saving of the registry database is rather messy.
+ * bad input (while reading) may crash wine.
+ */
+void
+_DumpLevel(FILE *f,LPKEYSTRUCT lpTKey,int tabs) {
+	LPKEYSTRUCT	lpKey;
+
+	lpKey=lpTKey->lpSubLvl;
+	while (lpKey) {
+		int	i;
+		for (i=0;i<tabs;i++) fprintf(f,"\t");
+		/* implement different dwTypes ... */
+		if (lpKey->lpValue)
+			fprintf(f,"%s=%s\n",lpKey->lpSubKey,lpKey->lpValue);
+		else
+			fprintf(f,"%s\n",lpKey->lpSubKey);
+
+		if (lpKey->lpSubLvl)
+			_DumpLevel(f,lpKey,tabs+1);
+		lpKey=lpKey->lpNextKey;
+	}
+}
+
+static void
+_SaveKey(HKEY hKey,char *where) {
+	FILE		*f;
+	LPKEYSTRUCT	lpKey;
+
+	f=fopen(where,"w");
+	if (f==NULL) {
+		perror("registry-fopen");
+		return;
+	}
+	switch ((DWORD)hKey) {
+	case HKEY_CLASSES_ROOT:
+		lpKey=lphRootKey;
+		break;
+	default:return;
+	}
+	_DumpLevel(f,lpKey,0);
+	fclose(f);
+}
+
+void
+SHELL_SaveRegistry(void) {
+	/* FIXME: 
+	 * -implement win95 additional keytypes here
+	 * (HKEY_LOCAL_MACHINE,HKEY_CURRENT_USER or whatever)
+	 * -choose better filename(s)
+	 */
+	_SaveKey(HKEY_CLASSES_ROOT,"/tmp/winereg");
+}
+
+#define BUFSIZE	256
+void
+_LoadLevel(FILE *f,LPKEYSTRUCT lpKey,int tabsexp,char *buf) {
+	int		i;
+	char		*s,*t;
+	HKEY		hNewKey;
+	LPKEYSTRUCT	lpNewKey;
+
+	while (1) {
+		if (NULL==fgets(buf,BUFSIZE,f)) {
+			buf[0]=0;
+			return;
+		}
+		for (i=0;buf[i]=='\t';i++) /*empty*/;
+		s=buf+i;
+		if (NULL!=(t=strchr(s,'\n'))) *t='\0';
+		if (NULL!=(t=strchr(s,'\r'))) *t='\0';
+
+		if (i<tabsexp) return;
+
+		if (i>tabsexp) {
+			hNewKey=GlobalAlloc(GMEM_MOVEABLE,sizeof(KEYSTRUCT));
+			lpNewKey=lpKey->lpSubLvl=(LPKEYSTRUCT)GlobalLock(hNewKey);
+			lpNewKey->hKey		= hNewKey;
+			lpNewKey->dwType	= 0;
+			lpNewKey->lpSubKey	=
+			lpNewKey->lpValue	=
+			lpNewKey->lpSubLvl	=
+			lpNewKey->lpNextKey	=
+			lpNewKey->lpPrevKey	= NULL;
+			if (NULL!=(t=strchr(s,'='))) {
+				*t='\0';t++;
+				lpNewKey->dwType	= REG_SZ;
+				lpNewKey->lpSubKey	= strdup(s);
+				lpNewKey->lpValue	= strdup(t);
+			} else {
+				lpNewKey->dwType	= REG_SZ;
+				lpNewKey->lpSubKey	= strdup(s);
+			}
+			_LoadLevel(f,lpNewKey,tabsexp+1,buf);
+		}
+		for (i=0;buf[i]=='\t';i++) /*empty*/;
+		s=buf+i;
+		if (i<tabsexp) return;
+		if (buf[0]=='\0') break; /* marks end of file */
+		/* we have a buf now. even when returning from _LoadLevel */
+		hNewKey		= GlobalAlloc(GMEM_MOVEABLE,sizeof(KEYSTRUCT));
+		lpNewKey	= lpKey->lpNextKey=(LPKEYSTRUCT)GlobalLock(hNewKey);
+		lpNewKey->lpPrevKey	= lpKey;
+		lpNewKey->hKey		= hNewKey;
+		lpNewKey->dwType	= 0;
+		lpNewKey->lpSubKey	=
+		lpNewKey->lpValue	=
+		lpNewKey->lpSubLvl	=
+		lpNewKey->lpNextKey	= NULL;
+		if (NULL!=(t=strchr(s,'='))) {
+			*t='\0';t++;
+			lpNewKey->dwType	= REG_SZ;
+			lpNewKey->lpSubKey	= strdup(s);
+			lpNewKey->lpValue	= strdup(t);
+		} else {
+			lpNewKey->dwType	= REG_SZ;
+			lpNewKey->lpSubKey	= strdup(s);
+		}
+		lpKey=lpNewKey;
+	}
+}
+
+void
+_LoadKey(HKEY hKey,char *from) {
+	FILE		*f;
+	LPKEYSTRUCT	lpKey;
+	char		buf[BUFSIZE]; /* FIXME: long enough? */
+
+	f=fopen(from,"r");
+	if (f==NULL) {
+		perror("fopen-registry-read");
+		return;
+	}
+	switch ((DWORD)hKey) {
+	case HKEY_CLASSES_ROOT:
+		lpKey=lphRootKey;
+		break;
+	default:return;
+	}
+	_LoadLevel(f,lpKey,-1,buf);
+}
+
+void
+SHELL_LoadRegistry(void) {
+	DWORD	dwRet;
+
+	dwRet=SHELL_RegCheckForRoot();
+	if (dwRet!=ERROR_SUCCESS) 
+		return;/*very bad magic, if we can't even allocate the rootkeys*/
+	_LoadKey(HKEY_CLASSES_ROOT,"/tmp/winereg");
+}
+
 /*************************************************************************
  *				RegOpenKey		[SHELL.1]
  */
@@ -73,16 +225,16 @@
         dwRet = SHELL_RegCheckForRoot();
         if (dwRet != ERROR_SUCCESS) return dwRet;
 	dprintf_reg(stddeb, "RegOpenKey(%08lX, %p='%s', %p)\n",
-						hKey, lpSubKey, lpSubKey, lphKey);
+				       (DWORD)hKey, lpSubKey, lpSubKey, lphKey);
 	if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
-        switch(hKey) {
+        switch((DWORD)hKey) {
 	case 0: 
 	  lpKey = lphTopKey; break;
         case HKEY_CLASSES_ROOT: /* == 1 */
         case 0x80000000:
           lpKey = lphRootKey; break;
         default: 
-	  dprintf_reg(stddeb,"RegOpenKey // specific key = %08lX !\n", hKey);
+	  dprintf_reg(stddeb,"RegOpenKey // specific key = %08lX !\n", (DWORD)hKey);
 	  lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
         }
 	if (lpSubKey == NULL || !*lpSubKey)  { 
@@ -127,16 +279,16 @@
 
 	dwRet = SHELL_RegCheckForRoot();
         if (dwRet != ERROR_SUCCESS) return dwRet;
-	dprintf_reg(stddeb, "RegCreateKey(%08lX, '%s', %p)\n",	hKey, lpSubKey, lphKey);
+	dprintf_reg(stddeb, "RegCreateKey(%08lX, '%s', %p)\n",	(DWORD)hKey, lpSubKey, lphKey);
 	if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
-        switch(hKey) {
+        switch((DWORD)hKey) {
 	case 0: 
 	  lpKey = lphTopKey; break;
         case HKEY_CLASSES_ROOT: /* == 1 */
         case 0x80000000:
           lpKey = lphRootKey; break;
         default: 
-	  dprintf_reg(stddeb,"RegCreateKey // specific key = %08lX !\n", hKey);
+	  dprintf_reg(stddeb,"RegCreateKey // specific key = %08lX !\n", (DWORD)hKey);
 	  lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
         }
 	if (lpSubKey == NULL || !*lpSubKey)  { 
@@ -179,11 +331,11 @@
 	    lpNewKey->lpValue = NULL;
 	    lpNewKey->lpSubLvl = NULL;
 	    *lphKey = hNewKey;
-	    dprintf_reg(stddeb,"RegCreateKey // successful '%s' key=%08lX !\n", str, hNewKey);
+	    dprintf_reg(stddeb,"RegCreateKey // successful '%s' key=%08lX !\n", str, (DWORD)hNewKey);
 	    lpKey = lpNewKey;
 	  } else {
             *lphKey = lpKey->hKey;
-	    dprintf_reg(stddeb,"RegCreateKey // found '%s', key=%08lX\n", str, *lphKey);
+	    dprintf_reg(stddeb,"RegCreateKey // found '%s', key=%08lX\n", str, (DWORD)*lphKey);
 	  }
 	}
 	return ERROR_SUCCESS;
@@ -195,7 +347,7 @@
  */
 LONG RegCloseKey(HKEY hKey)
 {
-	dprintf_reg(stdnimp, "EMPTY STUB !!! RegCloseKey(%08lX);\n", hKey);
+	dprintf_reg(stdnimp, "EMPTY STUB !!! RegCloseKey(%08lX);\n", (DWORD)hKey);
 	return ERROR_SUCCESS;
 }
 
@@ -205,8 +357,8 @@
  */
 LONG RegDeleteKey(HKEY hKey, LPCSTR lpSubKey)
 {
-	dprintf_reg(stdnimp, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n", 
-												hKey, lpSubKey);
+	dprintf_reg(stdnimp, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n",
+                     (DWORD)hKey, lpSubKey);
 	return ERROR_SUCCESS;
 }
 
@@ -221,7 +373,7 @@
     LPKEYSTRUCT	lpKey;
     LONG       	dwRet;
     dprintf_reg(stddeb, "RegSetValue(%08lX, '%s', %08lX, '%s', %08lX);\n",
-		hKey, lpSubKey, dwType, lpVal, dwIgnored);
+		(DWORD)hKey, lpSubKey, dwType, lpVal, dwIgnored);
     /*if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;*/
     if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
     if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
@@ -251,7 +403,7 @@
 	LONG		dwRet;
 	int			size;
 	dprintf_reg(stddeb, "RegQueryValue(%08lX, '%s', %p, %p);\n",
-							hKey, lpSubKey, lpVal, lpcb);
+                    (DWORD)hKey, lpSubKey, lpVal, lpcb);
 	/*if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;*/
 	if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
 	if (lpcb == NULL) return ERROR_INVALID_PARAMETER;
@@ -291,16 +443,16 @@
 
 	dwRet = SHELL_RegCheckForRoot();
         if (dwRet != ERROR_SUCCESS) return dwRet;
-	dprintf_reg(stddeb, "RegEnumKey(%08lX, %ld)\n", hKey, dwSubKey);
+	dprintf_reg(stddeb, "RegEnumKey(%08lX, %ld)\n", (DWORD)hKey, dwSubKey);
 	if (lpBuf == NULL) return ERROR_INVALID_PARAMETER;
-        switch(hKey) {
+        switch((DWORD)hKey) {
 	case 0: 
 	  lpKey = lphTopKey; break;
         case HKEY_CLASSES_ROOT: /* == 1 */
         case 0x80000000:
           lpKey = lphRootKey; break;
         default: 
-	  dprintf_reg(stddeb,"RegEnumKey // specific key = %08lX !\n", hKey);
+	  dprintf_reg(stddeb,"RegEnumKey // specific key = %08lX !\n", (DWORD)hKey);
 	  lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
         }
         lpKey = lpKey->lpSubLvl;
@@ -319,22 +471,61 @@
 	return ERROR_INVALID_PARAMETER;
 }
 
+
 /*************************************************************************
  *				DragAcceptFiles		[SHELL.9]
  */
 void DragAcceptFiles(HWND hWnd, BOOL b)
 {
-	fprintf(stdnimp, "DragAcceptFiles : Empty Stub !!!\n");
+ /* flips WS_EX_ACCEPTFILES bit according to the value of b (TRUE or FALSE) */
+
+ dprintf_reg(stddeb,"DragAcceptFiles(%04x, %u) old exStyle %08lx\n",hWnd,b,GetWindowLong(hWnd,GWL_EXSTYLE));
+
+ SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE) | b*(LONG)WS_EX_ACCEPTFILES); 
 }
 
 
 /*************************************************************************
  *				DragQueryFile		[SHELL.11]
  */
-void DragQueryFile(HDROP h, UINT u, LPSTR u2, UINT u3)
+UINT DragQueryFile(HDROP hDrop, WORD wFile, LPSTR lpszFile, WORD wLength)
 {
-	fprintf(stdnimp, "DragQueryFile : Empty Stub !!!\n");
+ /* hDrop is a global memory block allocated with GMEM_SHARE 
+    with DROPFILESTRUCT as a header and filenames following
+    it, zero length filename is in the end */       
 
+ LPDROPFILESTRUCT lpDropFileStruct;
+ LPSTR		  lpCurrent;
+ WORD		  i;
+
+ dprintf_reg(stddeb,"DragQueryFile(%04x, %i, %p, %u)\n",
+                           hDrop,wFile,lpszFile,wLength);
+
+ lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
+ if(!lpDropFileStruct)
+    {
+       dprintf_reg(stddeb,"DragQueryFile: unable to lock handle!\n");
+       return 0;
+    } 
+ lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize;
+
+ i = 0;
+ while(i++ < wFile)
+    {
+       while(*lpCurrent++);  /* skip filename */
+       if(!*lpCurrent) 
+          return (wFile == 0xFFFF)? i : 0;  
+    }
+
+ i = strlen(lpCurrent); 
+ if(!lpszFile) return i+1;   /* needed buffer size */
+
+ i = ( wLength > i)? i : wLength-1;
+ strncpy(lpszFile,lpCurrent,i);
+ lpszFile[i]='\0';
+
+ GlobalUnlock(hDrop);
+ return i;
 }
 
 
@@ -343,17 +534,25 @@
  */
 void DragFinish(HDROP h)
 {
-	fprintf(stdnimp, "DragFinish : Empty Stub !!!\n");
+ GlobalFree((HGLOBAL)h);
 }
 
 
 /*************************************************************************
  *				DragQueryPoint		[SHELL.13]
  */
-BOOL DragQueryPoint(HDROP h, POINT FAR *p)
+BOOL DragQueryPoint(HDROP hDrop, POINT FAR *p)
 {
-	fprintf(stdnimp, "DragQueryPoint : Empty Stub !!!\n");
-        return FALSE;
+ LPDROPFILESTRUCT lpDropFileStruct;  
+ BOOL             bRet;
+
+ lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop);
+
+ memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT));
+ bRet = lpDropFileStruct->fInNonClientArea;
+
+ GlobalUnlock(hDrop);
+ return bRet; 
 }
 
 
@@ -371,7 +570,7 @@
      * we have to pass the parameters. If an instance is already running,
      * we might have to send DDE commands.
      */
-    dprintf_exec(stddeb, "ShellExecute(%4X,'%s','%s','%s','%s',%x)\n",
+    dprintf_exec(stddeb, "ShellExecute("NPFMT",'%s','%s','%s','%s',%x)\n",
 		hWnd, lpOperation ? lpOperation:"<null>", lpFile ? lpFile:"<null>",
 		lpParameters ? lpParameters : "<null>", 
 		lpDirectory ? lpDirectory : "<null>", iShowCmd);
@@ -392,7 +591,7 @@
       }
     } else {
       len=200;
-      if (RegQueryValue(HKEY_CLASSES_ROOT,p,subclass,&len)==ERROR_SUCCESS) {
+      if (RegQueryValue((HKEY)HKEY_CLASSES_ROOT,p,subclass,&len)==ERROR_SUCCESS) {
 	if (len>20)
 	  fprintf(stddeb,"ShellExecute:subclass with len %ld? (%s), please report.\n",len,subclass);
 	subclass[len]='\0';
@@ -401,7 +600,7 @@
 	strcat(subclass,"\\command");
 	dprintf_exec(stddeb,"ShellExecute:looking for %s.\n",subclass);
 	len=400;
-	if (RegQueryValue(HKEY_CLASSES_ROOT,subclass,cmd,&len)==ERROR_SUCCESS) {
+	if (RegQueryValue((HKEY)HKEY_CLASSES_ROOT,subclass,cmd,&len)==ERROR_SUCCESS) {
 	  char *t;
 	  dprintf_exec(stddeb,"ShellExecute:...got %s\n",cmd);
 	  cmd[len]='\0';
@@ -413,6 +612,7 @@
 	    char *s;
 	    s=malloc(len+strlen(lpFile)+10);
 	    strncpy(s,cmd,t-cmd);
+	    s[t-cmd]='\0';
 	    strcat(s,lpFile);
 	    strcat(s,t+2);
 	    strcpy(cmd,s);
@@ -425,13 +625,14 @@
 	  }
 	} else {
 	  fprintf(stddeb,"ShellExecute: No %s\\shell\\%s\\command found for \"%s\" suffix.\n",subclass,lpOperation,p);
-	  return 14; /* unknown type */
+	  return (HINSTANCE)14; /* unknown type */
 	}
       } else {
 	fprintf(stddeb,"ShellExecute: No operation found for \"%s\" suffix.\n",p);
-	return 14; /* file not found */
+	return (HINSTANCE)14; /* file not found */
       }
     }
+    dprintf_exec(stddeb,"ShellExecute:starting %s\n",cmd);
     return WinExec(cmd,iShowCmd);
 }
 
@@ -445,18 +646,22 @@
         return 0;
 }
 
-static char AppName[512], AppMisc[512];
+static char AppName[128], AppMisc[906];
 
 /*************************************************************************
  *				AboutDlgProc		[SHELL.33]
  */
-INT AboutDlgProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
+LRESULT AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
   char Template[512], AppTitle[512];
  
   switch(msg) {
    case WM_INITDIALOG:
+#ifdef WINELIB32
+    SendDlgItemMessage(hWnd,stc1,STM_SETICON,lParam,0);
+#else
     SendDlgItemMessage(hWnd,stc1,STM_SETICON,LOWORD(lParam),0);
+#endif
     GetWindowText(hWnd, Template, 511);
     sprintf(AppTitle, Template, AppName);
     SetWindowText(hWnd, AppTitle);
@@ -484,11 +689,13 @@
     DWORD WineProc,Win16Proc,Win32Proc;
     static int initialized=0;
 
-    if (szApp) strcpy(AppName, szApp);
+    if (szApp) strncpy(AppName, szApp, sizeof(AppName));
     else *AppName = 0;
+    AppName[sizeof(AppName)-1]=0;
 
-    if (szOtherStuff) strcpy(AppMisc, szOtherStuff);
+    if (szOtherStuff) strncpy(AppMisc, szOtherStuff, sizeof(AppMisc));
     else *AppMisc = 0;
+    AppMisc[sizeof(AppMisc)-1]=0;
 
     if (!hIcon) hIcon = LoadIcon(0,MAKEINTRESOURCE(OIC_WINEICON));
     
@@ -507,9 +714,10 @@
                                  GetCurrentPDB(), FALSE, FALSE,
                                  TRUE, NULL );
     if (!handle) return FALSE;
-    bRet = DialogBoxIndirectParam( GetWindowWord( hWnd, GWW_HINSTANCE ),
+    bRet = DialogBoxIndirectParam( WIN_GetWindowInstance( hWnd ),
                                    handle, hWnd,
-                                   GetWndProcEntry16("AboutDlgProc"), hIcon );
+                                   GetWndProcEntry16("AboutDlgProc"), 
+				   (LONG)hIcon );
     GLOBAL_FreeBlock( handle );
     return bRet;
 }
@@ -521,7 +729,7 @@
 {
 	HICON	hIcon = 0;
 	HINSTANCE hInst2 = hInst;
-	dprintf_reg(stddeb, "ExtractIcon(%04X, '%s', %d\n", 
+	dprintf_reg(stddeb, "ExtractIcon("NPFMT", '%s', %d\n", 
 			hInst, lpszExeFileName, nIconIndex);
         return 0;
 	if (lpszExeFileName != NULL) {
diff --git a/misc/spy.c b/misc/spy.c
index 835f8c6..eba14fe 100644
--- a/misc/spy.c
+++ b/misc/spy.c
@@ -1,6 +1,7 @@
 /* SPY.C
  *
  * Copyright 1994, Bob Amstadt
+ *           1995, Alex Korobka  
  */
 
 #include <stdlib.h>
@@ -13,8 +14,10 @@
 #include "options.h"
 #include "stddebug.h"
 #include "debug.h"
+#include "spy.h"
 
-#define SPY_MAX_MSGNUM		0x03e8
+#define SPY_MAX_MSGNUM		WM_USER
+#define SPY_MAX_INDENTLEVEL     64
 
 const char *MessageTypeNames[SPY_MAX_MSGNUM + 1] =
 {
@@ -27,7 +30,7 @@
     "WM_ACTIVATE",
     "WM_SETFOCUS",
     "WM_KILLFOCUS",
-    "WM_UNUSED1",
+    "WM_SETVISIBLE",
     "WM_ENABLE",
     "WM_SETREDRAW",
     "WM_SETTEXT",
@@ -41,7 +44,7 @@
     "WM_ERASEBKGND",
     "WM_SYSCOLORCHANGE",
     "WM_ENDSESSION",
-    "WM_UNUSED2",
+    "WM_SYSTEMERROR",
     "WM_SHOWWINDOW",
     "WM_CTLCOLOR",
     "WM_WININICHANGE",
@@ -67,17 +70,19 @@
     "WM_VKEYTOITEM",
     "WM_CHARTOITEM",
     "WM_SETFONT",		/* 0x30 */
-    "WM_GETFONT", NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "WM_GETFONT", NULL, NULL, NULL, NULL, NULL, 
+    "WM_QUERYDRAGICON", NULL, 
+    "WM_COMPAREITEM", NULL, NULL, NULL, NULL, NULL, NULL,
 
-    /* 0x40 */
-    NULL, NULL, NULL, NULL, NULL, NULL,
+    NULL, 		        /* 0x40 */
+    "WM_COMPACTING", NULL, NULL, 
+    "WM_COMMNOTIFY", NULL, 
     "WM_WINDOWPOSCHANGING",	/* 0x0046 */
     "WM_WINDOWPOSCHANGED",	/* 0x0047 */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "WM_POWER", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
-    /* 0x0050 */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    NULL, 		        /* 0x0050 */
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
     /* 0x0060 */
@@ -96,7 +101,7 @@
     "WM_NCPAINT",          	/* 0x0085 */
     "WM_NCACTIVATE",       	/* 0x0086 */
     "WM_GETDLGCODE",		/* 0x0087 */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "WM_SYNCPAINT", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
     /* 0x0090 */
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -164,7 +169,9 @@
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
     /* 0x0130 */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    NULL, 
+    "WM_LBTRACKPOINT", 
+    NULL, NULL, NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
     /* 0x0140 */
@@ -244,12 +251,19 @@
     "WM_MDIICONARRANGE",        /* 0x0228 */
     "WM_MDIGETACTIVE",          /* 0x0229 */
 
-    NULL, NULL, NULL, NULL, NULL, NULL,
+    "WM_DROPOBJECT", 
+    "WM_QUERYDROPOBJECT", 
+    NULL,
+    "WM_DRAGLOOP",
+    "WM_DRAGSELECT",
+    "WM_DRAGMOVE",
+     
     /* 0x0230*/
     "WM_MDISETMENU",            /* 0x0230 */
     "WM_ENTERSIZEMOVE",		/* 0x0231 */
     "WM_EXITSIZEMOVE",		/* 0x0232 */
-    NULL, NULL, NULL, NULL, NULL, 
+    "WM_DROPFILES", 		/* 0x0233 */
+    NULL, NULL, NULL, NULL, 
     /* 0x0238*/
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
     
@@ -289,11 +303,27 @@
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
-    /* 0x0300 */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "WM_CUT", 			/* 0x0300 */
+    "WM_COPY", 
+    "WM_PASTE", 
+    "WM_CLEAR", 
+    "WM_UNDO", 
+    "WM_RENDERFORMAT", 
+    "WM_RENDERALLFORMATS", 
+    "WM_DESTROYCLIPBOARD",
+    "WM_DRAWCLIPBOARD", 
+    "WM_PAINTCLIPBOARD", 
+    "WM_VSCROLLCLIPBOARD", 
+    "WM_SIZECLIPBOARD", 
+    "WM_ASKCBFORMATNAME", 
+    "WM_CHANGECBCHAIN",
+    "WM_HSCROLLCLIPBOARD",
+    "WM_QUERYNEWPALETTE",	/* 0x030f*/
+
+    "WM_PALETTEISCHANGING",
+    "WM_PALETTECHANGED", 	/* 0x0311 */
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
 
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -314,7 +344,9 @@
     /* 0x0380 */
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "WM_COALESCE_FIRST", 
+    "WM_COALESCE_LAST", 
+                NULL, NULL, NULL, NULL, NULL, NULL,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -337,35 +369,138 @@
     "WM_DDE_DATA",	/* 0x3E5 */
     "WM_DDE_REQUEST",	/* 0x3E6 */
     "WM_DDE_POKE",	/* 0x3E7 */
-    "WM_DDE_EXECUTE"	/* 0x3E8 */
+    "WM_DDE_EXECUTE",	/* 0x3E8 */
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+
+    
+    /* 0x03f0 */
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+
+    "WM_USER"
 };
 
-char SpyFilters[256+1];
-char SpyIncludes[256+1];
+static BOOL  	SpyFilters [SPY_MAX_MSGNUM+1];
+static BOOL 	SpyIncludes[SPY_MAX_MSGNUM+1];
+
+static int      iSpyMessageIndentLevel  = 0;
+static char     lpstrSpyMessageIndent[SPY_MAX_INDENTLEVEL];
+static char    *lpstrSpyMessageFromWine = "Wine";
+static char     lpstrSpyMessageFromTask[10]; 
+static char    *lpstrSpyMessageFromSelf = "self";
+static char    *lpstrSpyMessageFrom     =  NULL;
+
 
 /**********************************************************************
- *					SpyMessage
+ *			      EnterSpyMessage
  */
-void SpyMessage(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
+void EnterSpyMessage(int iFlag, HWND hWnd, WORD msg, WORD wParam, LONG lParam)
 {
-    char msg_name[80];
-    
-	if(!debugging_spy)
-		return;
+  HTASK	hTask     = GetWindowTask(hWnd);
+  WORD 	wCheckMsg = (msg > WM_USER)? WM_USER: msg;
 
-    if (msg > SPY_MAX_MSGNUM || MessageTypeNames[msg] == NULL)
-	sprintf(msg_name, "%04x", msg);
-    else
-	strcpy(msg_name, MessageTypeNames[msg]);
-    
-    strcat(msg_name, ";");
-    
-    if ((strlen(SpyIncludes) == 0 || strstr(SpyIncludes, msg_name) != NULL) &&
-	strstr(SpyFilters, msg_name) == NULL)
+  if( !SpyIncludes[wCheckMsg] || SpyFilters[wCheckMsg]) return;
+
+  /* each SPY_SENDMESSAGE must be complemented by call to ExitSpyMessage */
+  switch(iFlag)
+   {
+	case SPY_DISPATCHMESSAGE:
+		    if(msg <= WM_USER)
+		      {
+		       if(MessageTypeNames[msg])
+		          dprintf_message(stddeb,"(%04x) message [%04x] %s dispatched  wp=%04x lp=%08lx\n",
+		                          hWnd, msg, MessageTypeNames[msg], wParam, lParam);
+		       else
+		          dprintf_message(stddeb,"(%04x) message [%04x] dispatched  wp=%04x lp=%08lx\n",
+		                          hWnd, msg, wParam, lParam);
+		      }
+		    else
+		          dprintf_message(stddeb,"(%04x) message [%04x] WM_USER+%04d dispatched  wp=%04x lp=%08lx\n",
+		                          hWnd, msg, msg-WM_USER ,wParam ,lParam);
+		    break;
+	case SPY_SENDMESSAGE:
+		    if(hTask == GetCurrentTask())
+ 		      lpstrSpyMessageFrom = lpstrSpyMessageFromSelf;
+		    else if(hTask == NULL)
+  		      	   lpstrSpyMessageFrom = lpstrSpyMessageFromWine;
+  		    	 else
+  				{
+  				   sprintf(lpstrSpyMessageFromTask, "task %04x", hTask);	
+  				   lpstrSpyMessageFrom = lpstrSpyMessageFromTask;
+  				}
+		     
+	            if(msg <= WM_USER)
+	                {
+	                  if(MessageTypeNames[msg])
+			      dprintf_message(stddeb,"%s(%04x) message [%04x] %s sent from %s wp=%04x lp=%08lx\n",
+                                   	      lpstrSpyMessageIndent,
+                                   	      hWnd, msg, MessageTypeNames[msg],
+                                   	      lpstrSpyMessageFrom,
+                                   	      wParam, lParam);
+	                  else
+	                      dprintf_message(stddeb,"%s(%04x) message [%04x] sent from %s wp=%04x lp=%08lx\n",
+                                   	      lpstrSpyMessageIndent,
+                                   	      hWnd, msg,
+                                   	      lpstrSpyMessageFrom,
+                                   	      wParam, lParam);
+          		}
+        	    else
+             		  dprintf_message(stddeb,"%s(%04x) message [%04x] WM_USER+%04x sent from %s wp=%04x lp=%08lx\n",
+                               		  lpstrSpyMessageIndent,
+                               		  hWnd, msg, msg-WM_USER,
+                               		  lpstrSpyMessageFrom,
+                             		  wParam, lParam);
+
+	            if(SPY_MAX_INDENTLEVEL > iSpyMessageIndentLevel ) 
+		    	{
+			  iSpyMessageIndentLevel++;
+			  lpstrSpyMessageIndent[iSpyMessageIndentLevel]='\0';
+			  lpstrSpyMessageIndent[iSpyMessageIndentLevel-1]  ='\t';
+		      	}
+		    break;   
+	case SPY_DEFWNDPROC:
+		    if(msg <= WM_USER)
+		        if(MessageTypeNames[msg])
+		           dprintf_message(stddeb, "%s(%04x) DefWindowProc: %s [%04x]  wp=%04x lp=%08lx\n",
+		                           lpstrSpyMessageIndent,
+		                           hWnd, MessageTypeNames[msg], msg, wParam, lParam );
+		        else
+		           dprintf_message(stddeb, "%s(%04x) DefWindowProc: [%04x]  wp=%04x lp=%08lx\n",
+		                           lpstrSpyMessageIndent,
+		                           hWnd, msg, wParam, lParam );
+		    else
+		        dprintf_message(stddeb, "%s(%04x) DefWindowProc: WM_USER+%d [%04x] wp=%04x lp=%08lx\n",
+		                        lpstrSpyMessageIndent,
+		                        hWnd, msg - WM_USER, msg, wParam, lParam );
+		    break;
+	default:		    
+   }  
+
+}
+
+/**********************************************************************
+ *			      ExitSpyMessage
+ */
+void ExitSpyMessage(int iFlag, HWND hWnd, WORD msg, LONG lReturn)
+{
+  WORD wCheckMsg = (msg > WM_USER)? WM_USER: msg;
+
+  if( !SpyIncludes[wCheckMsg] || SpyFilters[wCheckMsg]) return;
+
+  iSpyMessageIndentLevel--;
+  lpstrSpyMessageIndent[iSpyMessageIndentLevel]='\0';
+
+  switch(iFlag)
     {
-	msg_name[strlen(msg_name) - 1] = '\0';
-	dprintf_spy(stddeb, "%04x  %20.20s  %04x  %04x  %08lx\n",
-		hwnd, msg_name, msg, wParam, lParam);
+	case SPY_RESULT_INVALIDHWND: 
+		dprintf_message(stddeb,"%s(%04x) message [%04x] HAS INVALID HWND\n",
+                                lpstrSpyMessageIndent, hWnd, msg);
+	        break;
+	case SPY_RESULT_OK:
+		dprintf_message(stddeb,"%s(%04x) message [%04x] returned %08lx\n",
+	                        lpstrSpyMessageIndent, hWnd, msg, lReturn);
+		break;
+	default:
     }
 }
 
@@ -374,15 +509,30 @@
  */
 void SpyInit(void)
 {
-    GetPrivateProfileString("spy", "exclude", "", SpyFilters, 
-			    sizeof(SpyFilters)-1, WINE_INI);
-    GetPrivateProfileString("spy", "include", "", SpyIncludes, 
-			    sizeof(SpyIncludes)-1, WINE_INI);
+    int      i;
+    char     lpstrBuffer[512];
 
-    if (*SpyIncludes != 0) {
-      strcat(SpyIncludes, ";");
-    }
-    if (*SpyFilters != 0) {
-      strcat(SpyFilters, ";");
-    }
+    for(i=0; i <= SPY_MAX_MSGNUM; i++) SpyFilters[i] = SpyIncludes[i] = FALSE;
+
+    GetPrivateProfileString("spy", "Exclude", "",lpstrBuffer ,511 , WINE_INI);
+    dprintf_message(stddeb,"SpyInit: Exclude=%s\n",lpstrBuffer);
+    if( *lpstrBuffer != 0 )
+      if(strstr(lpstrBuffer,"EXCLUDEALL"))
+	for(i=0; i <= SPY_MAX_MSGNUM; i++) SpyFilters[i] = TRUE;
+      else
+        for(i=0; i <= SPY_MAX_MSGNUM; i++)
+	    if(MessageTypeNames[i])
+	       if(strstr(lpstrBuffer,MessageTypeNames[i])) SpyFilters[i] = TRUE; 
+
+    GetPrivateProfileString("spy", "Include", "",lpstrBuffer ,511 , WINE_INI);
+    dprintf_message(stddeb,"SpyInit: Include=%s\n",lpstrBuffer);
+    if( *lpstrBuffer != 0 )
+      if(strstr(lpstrBuffer,"INCLUDEALL"))
+        for(i=0; i <= SPY_MAX_MSGNUM; i++) SpyIncludes[i] = TRUE;
+      else 
+        for(i=0; i <= SPY_MAX_MSGNUM; i++)
+            if(MessageTypeNames[i])
+               if(strstr(lpstrBuffer,MessageTypeNames[i])) SpyIncludes[i] = TRUE;
+
 }
+
diff --git a/misc/user.c b/misc/user.c
index 98b7b1b..1005ffd 100644
--- a/misc/user.c
+++ b/misc/user.c
@@ -89,7 +89,7 @@
 /**********************************************************************
  *					USER_InitApp
  */
-int USER_InitApp(int hInstance)
+int USER_InitApp(HINSTANCE hInstance)
 {
     int queueSize;
 
diff --git a/misc/user32.c b/misc/user32.c
index f5b280f..5a4c02f 100644
--- a/misc/user32.c
+++ b/misc/user32.c
@@ -17,7 +17,7 @@
 /* Structure copy functions */
 static void MSG16to32(MSG *msg16,struct WIN32_MSG *msg32)
 {
-	msg32->hwnd=msg16->hwnd;
+	msg32->hwnd=(DWORD)msg16->hwnd;
 	msg32->message=msg16->message;
 	msg32->wParam=msg16->wParam;
 	msg32->lParam=msg16->lParam;
@@ -28,7 +28,7 @@
 
 static void MSG32to16(struct WIN32_MSG *msg32,MSG *msg16)
 {
-	msg16->hwnd=msg32->hwnd;
+	msg16->hwnd=(HWND)msg32->hwnd;
 	msg16->message=msg32->message;
 	msg16->wParam=msg32->wParam;
 	msg16->lParam=msg32->lParam;
@@ -45,14 +45,14 @@
 	WNDCLASS copy;
 	char *s1,*s2;
 	copy.style=wndclass->style;
-	ALIAS_RegisterAlias(0,0,wndclass->lpfnWndProc);
+	ALIAS_RegisterAlias(0,0,(DWORD)wndclass->lpfnWndProc);
 	copy.lpfnWndProc=wndclass->lpfnWndProc;
 	copy.cbClsExtra=wndclass->cbClsExtra;
 	copy.cbWndExtra=wndclass->cbWndExtra;
-	copy.hInstance=wndclass->hInstance;
-	copy.hIcon=wndclass->hIcon;
-	copy.hCursor=wndclass->hCursor;
-	copy.hbrBackground=wndclass->hbrBackground;
+	copy.hInstance=(HINSTANCE)wndclass->hInstance;
+	copy.hIcon=(HICON)wndclass->hIcon;
+	copy.hCursor=(HCURSOR)wndclass->hCursor;
+	copy.hbrBackground=(HBRUSH)wndclass->hbrBackground;
 	if(wndclass->lpszMenuName)
 	{
 		s1=alloca(strlen(wndclass->lpszMenuName)+1);
@@ -75,7 +75,7 @@
 LRESULT USER32_DefWindowProcA(DWORD hwnd,DWORD msg,DWORD wParam,DWORD lParam)
 {
 	/* some messages certainly need special casing. We come to that later */
-	return DefWindowProc(hwnd,msg,wParam,lParam);
+	return DefWindowProc((HWND)hwnd,msg,wParam,lParam);
 }
 
 /***********************************************************************
@@ -85,7 +85,7 @@
 {
 	BOOL ret;
 	MSG msg;
-	ret=GetMessage(MAKE_SEGPTR(&msg),hwnd,min,max);
+	ret=GetMessage(MAKE_SEGPTR(&msg),(HWND)hwnd,min,max);
 	MSG16to32(&msg,lpmsg);
 	return ret;
 }
@@ -97,8 +97,8 @@
 {
 	PAINTSTRUCT ps;
 	HDC ret;
-	ret=BeginPaint(hwnd,&ps);
-	lpps->hdc=ps.hdc;
+	ret=BeginPaint((HWND)hwnd,&ps);
+	lpps->hdc=(DWORD)ps.hdc;
 	lpps->fErase=ps.fErase;
 	lpps->rcPaint.top=ps.rcPaint.top;
 	lpps->rcPaint.left=ps.rcPaint.left;
@@ -123,7 +123,7 @@
 	ps.rcPaint.bottom=lpps->rcPaint.bottom;
 	ps.fRestore=lpps->fRestore;
 	ps.fIncUpdate=lpps->fIncUpdate;
-	EndPaint(hwnd,&ps);
+	EndPaint((HWND)hwnd,&ps);
 	return TRUE;
 }
 
diff --git a/misc/winsocket.c b/misc/winsocket.c
index 2fdd5a6..23675a1 100644
--- a/misc/winsocket.c
+++ b/misc/winsocket.c
@@ -90,14 +90,14 @@
 	char scratch[8192];
 };
 static struct WinSockHeap *Heap;
-static int HeapHandle;
+static HANDLE HeapHandle;
 static int ScratchPtr;
 
 #ifndef WINELIB
 #define GET_SEG_PTR(x)	MAKELONG((int)((char*)(x)-(char*)Heap),	\
 							GlobalHandleToSel(HeapHandle))
 #else
-#define GET_SEG_PTR(x)	(x)
+#define GET_SEG_PTR(x)	((SEGPTR)x)
 #endif
 
 #ifndef WINELIB
@@ -196,7 +196,9 @@
 	case ESTALE:		return WSAESTALE;
 	case EREMOTE:		return WSAEREMOTE;
 
+#ifdef EDQUOT
         default:
+#endif
 		fprintf(stderr, "winsock: unknown errorno %d!\n", errno);
 		return WSAEOPNOTSUPP;
 	}
@@ -283,7 +285,7 @@
 	for(i=0;host->h_addr_list[i];i++)
 		;
 	addr_list=scratch_alloc(sizeof(SEGPTR)*(i+1));
-	heapent->h_addr_list = GET_SEG_PTR(addr_list);
+	heapent->h_addr_list = (char**)GET_SEG_PTR(addr_list);
 	for(i=0;host->h_addr_list[i];i++)
 	{
 		void *addr=scratch_alloc(host->h_length);
@@ -740,17 +742,18 @@
 {
 	struct ipc_packet message;
 
-	if (msgrcv(wine_key, &message, IPC_PACKET_SIZE, MTYPE, IPC_NOWAIT) == -1)
+	if (msgrcv(wine_key, (struct msgbuf*)&message, 
+		   IPC_PACKET_SIZE, MTYPE, IPC_NOWAIT) == -1)
 		perror("wine: msgrcv");
 
 	fprintf(stderr, 
-		"WSA: PostMessage (hwnd %d, wMsg %d, wParam %d, lParam %ld)\n",
+		"WSA: PostMessage (hwnd "NPFMT", wMsg %d, wParam "NPFMT", lParam %ld)\n",
 		message.hWnd,
 		message.wMsg,
 		message.handle,
 		message.lParam);
 
-	PostMessage(message.hWnd, message.wMsg, message.handle, message.lParam);
+	PostMessage(message.hWnd, message.wMsg, (WPARAM)message.handle, message.lParam);
 		
 	signal(SIGUSR1, recv_message);
 }
@@ -767,10 +770,11 @@
 	message.lParam = lParam;
 
 	fprintf(stderr, 
-		"WSA: send (hwnd %d, wMsg %d, handle %d, lParam %ld)\n",
+		"WSA: send (hwnd "NPFMT", wMsg %d, handle "NPFMT", lParam %ld)\n",
 		hWnd, wMsg, handle, lParam);
 	
-	if (msgsnd(wine_key, &message,  IPC_PACKET_SIZE, IPC_NOWAIT) == -1)
+	if (msgsnd(wine_key, (struct msgbuf*)&message,  
+		   IPC_PACKET_SIZE, IPC_NOWAIT) == -1)
 		perror("wine: msgsnd");
 		
 	kill(getppid(), SIGUSR1);
@@ -913,7 +917,7 @@
 	long event;
 	fd_set read_fds, write_fds, except_fds;
 
-	dprintf_winsock(stddeb, "WSA_AsyncSelect: socket %d, HWND %d, wMsg %d, event %ld\n", s, hWnd, wMsg, lEvent);
+	dprintf_winsock(stddeb, "WSA_AsyncSelect: socket %d, HWND "NPFMT", wMsg %d, event %ld\n", s, hWnd, wMsg, lEvent);
 
 	/* remove outstanding asyncselect() processes */
 	/* kill */
@@ -955,7 +959,7 @@
 
 INT WSACancelAsyncRequest(HANDLE hAsyncTaskHandle)
 {
-	dprintf_winsock(stddeb, "WSA_AsyncRequest: handle %d\n", hAsyncTaskHandle);
+	dprintf_winsock(stddeb, "WSA_AsyncRequest: handle "NPFMT"\n", hAsyncTaskHandle);
 
 	return 0;
 }
diff --git a/miscemu/Imakefile b/miscemu/Imakefile
deleted file mode 100644
index 60adb1a..0000000
--- a/miscemu/Imakefile
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = miscemu
-
-SRCS = \
-	dosmem.c \
-	dpmi.c \
-	emulate.c \
-	instr.c \
-	int10.c \
-	int13.c \
-	int1a.c \
-	int21.c \
-	int25.c \
-	int26.c \
-	int2a.c \
-	int2f.c \
-	int5c.c \
-	interrupts.c \
-	ioports.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/miscemu/Makefile.in b/miscemu/Makefile.in
index 6df68b0..f1f67ea 100644
--- a/miscemu/Makefile.in
+++ b/miscemu/Makefile.in
@@ -2,6 +2,7 @@
 MODULE = miscemu
 
 C_SRCS = \
+	cpu.c \
 	dosmem.c \
 	dpmi.c \
 	emulate.c \
@@ -14,9 +15,11 @@
 	int26.c \
 	int2a.c \
 	int2f.c \
+	int4b.c \
 	int5c.c \
 	interrupts.c \
-	ioports.c
+	ioports.c \
+	vxd.c
 
 all: $(MODULE).o
 
diff --git a/miscemu/cpu.c b/miscemu/cpu.c
new file mode 100644
index 0000000..436c35b
--- /dev/null
+++ b/miscemu/cpu.c
@@ -0,0 +1,43 @@
+/*
+ * What processor?
+ *
+ * Copyright 1995 Morten Welinder
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+int runtime_cpu (void)
+{
+  static int cache = 0;
+
+#ifdef linux
+  if (!cache)
+    {
+      FILE *f = fopen ("/proc/cpuinfo", "r");
+
+      cache = 3;  /* Default.  */
+
+      if (f)
+	{
+	  char info[5], value[5];
+	  while (fscanf (f, " %4s%*s : %4s%*s", info, value) == 2)
+	    if (!strcasecmp (info, "cpu"))
+	      {
+		if (isdigit (value[0]) && value[1] == '8'
+		    && value[2] == '6' && value[3] == 0)
+		  {
+		    cache = value[0] - '0';
+		    break;
+		  }
+	      }
+	  fclose (f);
+	}
+    }
+  return cache;
+#else
+  /* FIXME: how do we do this on other systems? */
+  return 3;
+#endif
+}
diff --git a/miscemu/dpmi.c b/miscemu/dpmi.c
index 1c787e9..7389396 100644
--- a/miscemu/dpmi.c
+++ b/miscemu/dpmi.c
@@ -127,10 +127,24 @@
                        (SEGPTR)MAKELONG( DX_reg(&context), CX_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.
+        */
+        ptr = (BYTE *)PTR_SEG_OFF_TO_LIN( ES_reg(&context), DI_reg(&context) );
+        fprintf(stdnimp,
+               "RealModeInt %02x: AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x DS=%04x\n",
+                BL_reg(&context),
+              *(WORD*)(ptr+0x1c),*(WORD*)(ptr+0x10),*(WORD*)(ptr+0x18),*(WORD*)(ptr+0x14),
+              *(WORD*)(ptr+0x04),*(WORD*)(ptr+0x00),*(WORD*)(ptr+0x22),*(WORD*)(ptr+0x24));
+        SET_CFLAG(&context);
+        break;
+
     case 0x0400:  /* Get DPMI version */
         AX_reg(&context) = 0x005a;  /* DPMI version 0.90 */
         BX_reg(&context) = 0x0005;  /* Flags: 32-bit, virtual memory */
-        CL_reg(&context) = 3;       /* CPU type: 386 */
+        CL_reg(&context) = runtime_cpu ();
         DX_reg(&context) = 0x0102;  /* Master/slave interrupt controller base*/
         break;
 
diff --git a/miscemu/emulate.c b/miscemu/emulate.c
index afa61e7..d31ccb7 100644
--- a/miscemu/emulate.c
+++ b/miscemu/emulate.c
@@ -72,7 +72,7 @@
         /* IN: AX&0x0C00 rounding protocol */
         /* OUT: DX:AX variable popped */
         {
-            DWORD dw;
+            DWORD dw=0;
             /* I don't know much about asm() programming. This could be 
              * wrong. 
              */
@@ -91,6 +91,7 @@
         break;
 
     case 10: /* dunno. but looks like returning nr. of things on stack in AX */
+	AX_reg(&context) = 0;
         break;
 
     case 11: /* just returns the installed flag in DX:AX */
diff --git a/miscemu/instr.c b/miscemu/instr.c
index e5d89d8..83f7cef 100644
--- a/miscemu/instr.c
+++ b/miscemu/instr.c
@@ -11,10 +11,12 @@
 #include "registers.h"
 
 
+#define STACK_reg(context) \
+   ((GET_SEL_FLAGS(SS_reg(context)) & LDT_FLAGS_32BIT) ? \
+                   ESP_reg(context) : SP_reg(context))
+
 #define STACK_PTR(context) \
-    (PTR_SEG_OFF_TO_LIN( SS_reg(context), \
-        ((GET_SEL_FLAGS(SS_reg(context)) & LDT_FLAGS_32BIT) ? \
-            ESP_reg(context) : SP_reg(context))))
+    (PTR_SEG_OFF_TO_LIN(SS_reg(context),STACK_reg(context)))
 
 /***********************************************************************
  *           INSTR_ReplaceSelector
@@ -250,8 +252,12 @@
     case 0x0f: switch(instr[1])
                {
                case 0xb2: SS_reg(context) = seg; break;  /* lss */
+#ifdef FS_reg
                case 0xb4: FS_reg(context) = seg; break;  /* lfs */
+#endif
+#ifdef GS_reg
                case 0xb5: GS_reg(context) = seg; break;  /* lgs */
+#endif
                }
                break;
     }
@@ -298,12 +304,16 @@
         case 0x26:
             segprefix = ES_reg(context);
             break;
+#ifdef FS_reg
         case 0x64:
             segprefix = FS_reg(context);
             break;
+#endif
+#ifdef GS_reg
         case 0x65:
             segprefix = GS_reg(context);
             break;
+#endif
         case 0x66:
             long_op = !long_op;  /* opcode size prefix */
             break;
@@ -346,7 +356,7 @@
                     case 0x17: SS_reg(context) = seg; break;
                     case 0x1f: DS_reg(context) = seg; break;
                     }
-                    SP_reg(context) += sizeof(WORD);
+                    STACK_reg(context) += long_op ? 4 : 2;
                     EIP_reg(context) += prefixlen + 1;
                     return TRUE;
                 }
@@ -356,27 +366,43 @@
         case 0x0f: /* extended instruction */
             switch(instr[1])
             {
+#ifdef FS_reg
             case 0xa1: /* pop fs */
-            case 0xa9: /* pop gs */
                 {
                     WORD seg = *(WORD *)STACK_PTR( context );
                     if ((seg = INSTR_ReplaceSelector( context, seg )) != 0)
                     {
-                        switch(instr[1])
-                        {
-                        case 0xa1: FS_reg(context) = seg; break;
-                        case 0xa9: GS_reg(context) = seg; break;
-                        }
-                        SP_reg(context) += sizeof(WORD);
+                        FS_reg(context) = seg;
+                        STACK_reg(context) += long_op ? 4 : 2;
                         EIP_reg(context) += prefixlen + 2;
                         return TRUE;
                     }
                 }
                 break;
+#endif  /* FS_reg */
+
+#ifdef GS_reg
+            case 0xa9: /* pop gs */
+                {
+                    WORD seg = *(WORD *)STACK_PTR( context );
+                    if ((seg = INSTR_ReplaceSelector( context, seg )) != 0)
+                    {
+                        GS_reg(context) = seg;
+                        STACK_reg(context) += long_op ? 4 : 2;
+                        EIP_reg(context) += prefixlen + 2;
+                        return TRUE;
+                    }
+                }
+                break;
+#endif  /* GS_reg */
 
             case 0xb2: /* lss addr,reg */
+#ifdef FS_reg
             case 0xb4: /* lfs addr,reg */
+#endif
+#ifdef GS_reg
             case 0xb5: /* lgs addr,reg */
+#endif
                 if (INSTR_EmulateLDS( context, instr, long_op,
                                       long_addr, segprefix, &len ))
                 {
@@ -458,7 +484,7 @@
 	    }
             return TRUE;
 
-        case 0x8e: /* mov reg,segment_reg */
+        case 0x8e: /* mov XX,segment_reg */
             {
                 WORD seg = *(WORD *)INSTR_GetOperandAddr( context, instr + 1,
                                                   long_addr, segprefix, &len );
@@ -482,13 +508,17 @@
                     EIP_reg(context) += prefixlen + len + 1;
                     return TRUE;
                 case 4:
+#ifdef FS_reg
                     FS_reg(context) = seg;
                     EIP_reg(context) += prefixlen + len + 1;
                     return TRUE;
+#endif
                 case 5:
+#ifdef GS_reg
                     GS_reg(context) = seg;
                     EIP_reg(context) += prefixlen + len + 1;
                     return TRUE;
+#endif
                 case 6:  /* unused */
                 case 7:  /* unused */
                     break;
@@ -520,7 +550,7 @@
                 *(--stack) = FL_reg(context);
                 *(--stack) = CS_reg(context);
                 *(--stack) = IP_reg(context) + prefixlen + 2;
-                SP_reg(context) -= 3 * sizeof(WORD);
+                STACK_reg(context) -= 3 * sizeof(WORD);
                 /* Jump to the interrupt handler */
                 CS_reg(context)  = HIWORD(addr);
                 EIP_reg(context) = LOWORD(addr);
@@ -534,7 +564,7 @@
                 EIP_reg(context) = *stack++;
                 CS_reg(context)  = *stack++;
                 EFL_reg(context) = *stack;
-                SP_reg(context) += 3*sizeof(DWORD);  /* Pop the return address and flags */
+                STACK_reg(context) += 3*sizeof(DWORD);  /* Pop the return address and flags */
             }
             else
             {
@@ -542,7 +572,7 @@
                 EIP_reg(context) = *stack++;
                 CS_reg(context)  = *stack++;
                 FL_reg(context)  = *stack;
-                SP_reg(context) += 3*sizeof(WORD);  /* Pop the return address and flags */
+                STACK_reg(context) += 3*sizeof(WORD);  /* Pop the return address and flags */
             }
             return TRUE;
 
diff --git a/miscemu/int1a.c b/miscemu/int1a.c
index 69386c0..738029c 100644
--- a/miscemu/int1a.c
+++ b/miscemu/int1a.c
@@ -23,12 +23,14 @@
 {
     struct tm *bdtime;
     struct timeval tvs;
+    time_t seconds;
 
     /* This should give us the (approximately) correct
      * 18.206 clock ticks per second since midnight.
      */
     gettimeofday( &tvs, NULL );
-    bdtime = localtime( &tvs.tv_sec );
+    seconds = tvs.tv_sec;
+    bdtime = localtime( &seconds );
     return (((bdtime->tm_hour * 3600 + bdtime->tm_min * 60 +
               bdtime->tm_sec) * 18206) / 1000) +
                   (tvs.tv_usec / 54927);
diff --git a/miscemu/int21.c b/miscemu/int21.c
index d580ec5..30862a6 100644
--- a/miscemu/int21.c
+++ b/miscemu/int21.c
@@ -25,7 +25,12 @@
 #include "miscemu.h"
 #include "stddebug.h"
 #include "debug.h"
-
+#ifdef __svr4__
+/* SVR4 DOESNTdo locking the same way must implement properly */
+#define LOCK_EX 0
+#define LOCK_SH  1
+#define LOCK_NB  8
+#endif
 /* Define the drive parameter block, as used by int21/1F
  * and int21/32.  This table can be accessed through the
  * global 'dpb' pointer, which points into the local dos
@@ -53,8 +58,7 @@
     WORD free_clusters;     /* Number of free clusters (0xFFFF=unknown) */
 };
 
-WORD ExtendedError, CodePage = 437;
-BYTE ErrorClass, Action, ErrorLocus;
+WORD CodePage = 437;
 struct DPB *dpb;
 DWORD dpbsegptr;
 
@@ -74,53 +78,9 @@
 
 static int Error(int e, int class, int el)
 {
-	ErrorClass = class;
-	Action = SA_Ask4Retry;
-	ErrorLocus = el;
-	ExtendedError = e;
-
-	return e;
+  return DOS_Error(e,class,el);
 }
 
-void errno_to_doserr(void)
-{
-	switch (errno) {
-		case EAGAIN:
-			Error (ShareViolation, EC_Temporary, EL_Unknown);
-			break;
-		case EBADF:
-			Error (InvalidHandle, EC_AppError, EL_Unknown);
-			break;
-		case ENOSPC:
-			Error (DiskFull, EC_MediaError, EL_Disk);
-			break;				
-		case EACCES:
-		case EPERM:
-		case EROFS:
-			Error (WriteProtected, EC_AccessDenied, EL_Unknown);
-			break;
-		case EBUSY:
-			Error (LockViolation, EC_AccessDenied, EL_Unknown);
-			break;		
-		case ENOENT:
-			Error (FileNotFound, EC_NotFound, EL_Unknown);
-			break;				
-		case EISDIR:
-			Error (CanNotMakeDir, EC_AccessDenied, EL_Unknown);
-			break;
-		case ENFILE:
-		case EMFILE:
-			Error (NoMoreFiles, EC_MediaError, EL_Unknown);
-			break;
-		case EEXIST:
-			Error (FileExists, EC_Exists, EL_Disk);
-			break;				
-		default:
-			dprintf_int(stddeb, "int21: unknown errno %d!\n", errno);
-			Error (GeneralFailure, EC_SystemFailure, EL_Unknown);
-			break;
-	}
-}
 
 BYTE *GetCurrentDTA(void)
 {
@@ -488,9 +448,11 @@
 {
 	struct tm *now;
 	struct timeval tv;
+	time_t seconds;
 
 	gettimeofday(&tv,NULL);		/* Note use of gettimeofday(), instead of time() */
-	now = localtime(&tv.tv_sec);
+	seconds = tv.tv_sec;
+	now = localtime(&seconds);
 	 
 	CX_reg(context) = (now->tm_hour<<8) | now->tm_min;
 	DX_reg(context) = (now->tm_sec<<8) | tv.tv_usec/10000;
@@ -591,7 +553,11 @@
 
 	  int result,retries=sharing_retries;
 	  {
+#ifdef __svr4__
+              printf("Should call flock and needs porting to lockf\n");
+#else
 	    result = flock(handle, lock | LOCK_NB);
+#endif
 	    if ( retries && (!result) )
 	    {
               int i;
@@ -668,8 +634,7 @@
             return;
 	}
 
-	if (mkdir(dirname,0) == -1)
-        {
+	if ((mkdir(dirname,0) == -1)  && errno!=EEXIST) {
             Error( CanNotMakeDir, EC_AccessDenied, EL_Disk );
             AX_reg(context) = CanNotMakeDir;
             SET_CFLAG(context);
@@ -1553,6 +1518,7 @@
               case 0x0F:   /* Set logical drive mapping */
                 /* FIXME: Not implemented at the moment, always returns error
                  */
+		fprintf(stdnimp,"Attempt to map drive %02x\n",BL_reg(&context));
                 AX_reg(&context) = 0x0001; /* invalid function */
                 SET_CFLAG(&context);
                 break;
@@ -1763,8 +1729,8 @@
 	    }
 	    break;
     
-      case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
-        break;
+          case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
+            break;
 
 	  case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
 	    break;
diff --git a/miscemu/int2f.c b/miscemu/int2f.c
index 66a7a01..779f6b7 100644
--- a/miscemu/int2f.c
+++ b/miscemu/int2f.c
@@ -1,14 +1,19 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include "registers.h"
 #include "wine.h"
 #include "msdos.h"
 #include "miscemu.h"
+#include "module.h"
 #include "options.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
 #include "debug.h"
 
+  /* base WINPROC module number for VxDs */
+#define VXD_BASE 400
+
 static void do_int2f_16(struct sigcontext_struct *context);
 
 /**********************************************************************
@@ -20,25 +25,41 @@
 {
     switch(AH_reg(&context))
     {
-	case 0x10:
-                AL_reg(&context) = 0xff; /* share is installed */
-		break;
+    case 0x10:
+        AL_reg(&context) = 0xff; /* share is installed */
+        break;
 
-	case 0x15: /* mscdex */
-		/* ignore requests */
-		break;
+    case 0x15: /* mscdex */
+        /* ignore requests */
+        break;
 
-	case 0x16:
-		do_int2f_16( &context );
-                break;
-	default:
-		INT_BARF( &context, 0x2f );
-            }
+    case 0x16:
+        do_int2f_16( &context );
+        break;
+
+    case 0x4a:
+        switch(AL_reg(&context))
+        {
+        case 0x12:  /* realtime compression interface */
+            break;  /* not installed */
+        default:
+            INT_BARF( &context, 0x2f );
+        }
+        break;
+    default:
+        INT_BARF( &context, 0x2f );
+        break;
+    }
 }
 
 
+/**********************************************************************
+ *	    do_int2f_16
+ */
 static void do_int2f_16(struct sigcontext_struct *context)
 {
+    DWORD addr;
+
     switch(AL_reg(context))
     {
     case 0x00:  /* Windows enhanced mode installation check */
@@ -52,34 +73,56 @@
         break;
 
     case 0x80:  /* Release time-slice */
-        break;  /* nothing to do */
+	AL_reg(context) = 0;
+	/* FIXME: We need to do something that lets some other process run
+	   here.  */
+	sleep(0);
+        break;
 
-	case 0x84:  /* Get device API entry point */
-	    fprintf(stderr,"Application attempted to access VxD %4X\n",
-			BX_reg(context));
-		fprintf(stderr,"This device is not known to Wine.");
-		fprintf(stderr,"Expect a failure now\n");
-		ES_reg(context)=0;
-		DI_reg(context)=0;
-		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.
+         * According to Ralf Brown's Interrupt List, never return 0. But it
+         * seems to work okay (returning 0), just to be sure we return 1.
+         */
+	BX_reg(context) = 1; /* VM 1 is probably the System VM */
+	break;
+
+    case 0x84:  /* Get device API entry point */
+        addr = MODULE_GetEntryPoint( GetModuleHandle("WINPROCS"),
+                                     VXD_BASE + BX_reg(context) );
+        if (!addr)  /* not supported */
+        {
+	    fprintf( stderr,"Application attempted to access VxD %04x\n",
+                     BX_reg(context) );
+	    fprintf( stderr,"This device is not known to Wine.");
+	    fprintf( stderr,"Expect a failure now\n");
+        }
+	ES_reg(context) = SELECTOROF(addr);
+	DI_reg(context) = OFFSETOF(addr);
+	break;
 
     case 0x86:  /* DPMI detect mode */
         AX_reg(context) = 0;  /* Running under DPMI */
         break;
 
+    /* FIXME: is this right?  Specs say that this should only be callable
+       in real (v86) mode which we never enter.  */
     case 0x87:  /* DPMI installation check */
         AX_reg(context) = 0x0000; /* DPMI Installed */
         BX_reg(context) = 0x0001; /* 32bits available */
-        CL_reg(context) = 0x03;   /* processor 386 */
+        CL_reg(context) = runtime_cpu();
         DX_reg(context) = 0x005a; /* DPMI major/minor 0.90 */
         SI_reg(context) = 0;      /* # of para. of DOS extended private data */
         ES_reg(context) = 0;      /* ES:DI is DPMI switch entry point */
         DI_reg(context) = 0;
         break;
 
+    case 0x8a:  /* DPMI get vendor-specific API entry point. */
+	/* The 1.0 specs say this should work with all 0.9 hosts.  */
+	break;
+
     default:
         INT_BARF( context, 0x2f );
     }
 }
-
-
diff --git a/miscemu/int4b.c b/miscemu/int4b.c
new file mode 100644
index 0000000..16cf0b6
--- /dev/null
+++ b/miscemu/int4b.c
@@ -0,0 +1,34 @@
+/*
+ * Int 4B handling
+ *
+ */
+
+#include "wine.h"
+#include "miscemu.h"
+#include "stddebug.h"
+/* #define DEBUG_INT */
+#include "debug.h"
+#include "registers.h"
+
+
+/***********************************************************************
+ *           INT_Int4bHandler
+ *
+ */
+void INT_Int4bHandler( struct sigcontext_struct context )
+{
+
+  switch(AH_reg(&context))
+   {
+	case 0x81: /* Virtual DMA Spec (IBM SCSI interface) */   
+             if(AL_reg(&context) != 0x02) /* if not install check */
+		{
+		 SET_CFLAG(&context);		 
+		 AL_reg(&context) = 0x0f; /* function is not implemented */
+		}
+	     break;
+        default:
+	     INT_BARF(&context, 0x4b);
+    }
+}
+
diff --git a/miscemu/int5c.c b/miscemu/int5c.c
index f2794b7..28540f2 100644
--- a/miscemu/int5c.c
+++ b/miscemu/int5c.c
@@ -1,9 +1,10 @@
 /*
  * NetBIOS interrupt handling
  *
- * Copyright 1995 Alexandre Julliard
+ * Copyright 1995 Alexandre Julliard, Alex Korobka
  */
 
+#include "ldt.h"
 #include "wine.h"
 #include "miscemu.h"
 #include "stddebug.h"
@@ -15,9 +16,16 @@
 /***********************************************************************
  *           NetBIOSCall  (KERNEL.103)
  *
- * Also handler for interrupt 5c.
+ * Also handler for interrupt 5c. 
  */
 void NetBIOSCall( struct sigcontext_struct context )
 {
-    INT_BARF( &context, 0x5c );
+  BYTE* ptr;
+
+  ptr = (BYTE*) PTR_SEG_OFF_TO_LIN(ES_reg(&context),BX_reg(&context));
+
+  fprintf(stdnimp,"NetBIOSCall: command code %02x (ignored)\n",*ptr);
+  
+  AL_reg(&context) = *(ptr+0x01) = 0xFB; /* NetBIOS emulator not found */
 }
+
diff --git a/miscemu/vxd.c b/miscemu/vxd.c
new file mode 100644
index 0000000..95712f4
--- /dev/null
+++ b/miscemu/vxd.c
@@ -0,0 +1,141 @@
+/*
+ * VxD emulation
+ *
+ * Copyright 1995 Anand Kumria
+ */
+
+#include <stdio.h>
+#include "windows.h"
+#include "msdos.h"
+#include "miscemu.h"
+#include "wine.h"
+#include "stddebug.h"
+/* #define DEBUG_VXD */
+#include "debug.h"
+
+
+/***********************************************************************
+ *           VXD_PageFile
+ */
+void VXD_PageFile( struct sigcontext_struct context )
+{
+    /* taken from Ralf Brown's Interrupt List */
+
+    dprintf_vxd(stddeb,"VxD PageFile called ...\n");
+
+    switch(AX_reg(&context)) 
+    {
+    case 0x00: /* get version, is this windows version? */
+	dprintf_vxd(stddeb,"VxD PageFile: returning version\n");
+        AX_reg(&context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+	RESET_CFLAG(&context);
+	break;
+
+    case 0x01: /* get swap file info */
+	dprintf_vxd(stddeb,"VxD PageFile: returning swap file info\n");
+	AX_reg(&context) = 0x00; /* paging disabled */
+	ECX_reg(&context) = 0;   /* maximum size of paging file */	
+	/* FIXME: do I touch DS:SI or DS:DI? */
+	RESET_CFLAG(&context);
+	break;
+
+    case 0x02: /* delete permanent swap on exit */
+	dprintf_vxd(stddeb,"VxD PageFile: supposed to delete swap\n");
+	RESET_CFLAG(&context);
+	break;
+
+    case 0x03: /* current temporary swap file size */
+	dprintf_vxd(stddeb,"VxD PageFile: what is current temp. swap size\n");
+	RESET_CFLAG(&context);
+	break;
+
+    case 0x04: /* read or write?? INTERRUP.D */
+    case 0x05: /* cancel?? INTERRUP.D */
+    case 0x06: /* test I/O valid INTERRUP.D */
+    default:
+	INT_BARF( &context, 0x2f);
+	break;
+    }
+}
+
+
+/***********************************************************************
+ *           VXD_Shell
+ */
+void VXD_Shell( struct sigcontext_struct context )
+{
+    dprintf_vxd(stddeb,"VxD Shell called ...\n");
+
+    switch (DX_reg(&context)) /* Ralf Brown says EDX, but I use DX instead */
+    {
+    case 0x0000:
+	dprintf_vxd(stddeb,"VxD Shell: returning version\n");
+        AX_reg(&context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+	EBX_reg(&context) = 1; /* system VM Handle */
+	break;
+
+    case 0x0001:
+    case 0x0002:
+    case 0x0003:
+    case 0x0004:
+    case 0x0005:
+	dprintf_vxd(stddeb,"VxD Shell: EDX = %08lx\n",EDX_reg(&context));
+	INT_BARF( &context, 0x2f);
+	break;
+
+    case 0x0006: /* SHELL_Get_VM_State */
+	dprintf_vxd(stddeb,"VxD Shell: returning VM state\n");
+	/* Actually we don't, not yet. We have to return a structure
+         * and I am not to sure how to set it up and return it yet,
+         * so for now let's do nothing. I can (hopefully) get this
+         * by the next release
+         */
+	/* RESET_CFLAG(&context); */
+	break;
+
+    case 0x0007:
+    case 0x0008:
+    case 0x0009:
+    case 0x000A:
+    case 0x000B:
+    case 0x000C:
+    case 0x000D:
+    case 0x000E:
+    case 0x000F:
+    case 0x0010:
+    case 0x0011:
+    case 0x0012:
+    case 0x0013:
+    case 0x0014:
+    case 0x0015:
+    case 0x0016:
+    default:
+ 	dprintf_vxd(stddeb,"VxD Shell: EDX = %08lx\n",EDX_reg(&context)); 
+	INT_BARF( &context, 0x2f);
+	break;
+    }
+}
+
+
+/***********************************************************************
+ *           VXD_Comm
+ */
+void VXD_Comm( struct sigcontext_struct context )
+{
+    dprintf_vxd(stddeb,"VxD Comm called ...\n");
+
+    switch (AX_reg(&context))
+    {
+    case 0x0000: /* get version */
+	dprintf_vxd(stddeb,"VxD Comm: returning version\n");
+        AX_reg(&context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+	RESET_CFLAG(&context);
+	break;
+
+    case 0x0001: /* set port global */
+    case 0x0002: /* get focus */
+    case 0x0003: /* virtualise port */
+    default:
+        INT_BARF( &context, 0x2f);
+    }
+}
diff --git a/multimedia/Imakefile b/multimedia/Imakefile
deleted file mode 100644
index 51ea94f..0000000
--- a/multimedia/Imakefile
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = multimedia
-
-SRCS = \
-	audio.c \
-	joystick.c \
-	mcianim.c \
-	mcicda.c \
-	mcistring.c \
-	midi.c \
-	mmaux.c \
-	mmsystem.c \
-	time.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/multimedia/mcistring.c b/multimedia/mcistring.c
index f860563..79fe669 100644
--- a/multimedia/mcistring.c
+++ b/multimedia/mcistring.c
@@ -753,21 +753,21 @@
 			}
 
 			/* <keyword> <integer> */
-#define WII(str,flag,element) \
+#define WII(str,flag,fmt,element) \
 			if (!STRCMP(keywords[i],str) && (i+1<nrofkeywords)) {\
-				sscanf(keywords[i+1],"%d",&(U.wavesetParams. element ));\
+				sscanf(keywords[i+1],fmt,&(U.wavesetParams. element ));\
 				dwFlags |= flag;\
 				i+=2;\
 				continue;\
 			}
-			WII("formattag",MCI_WAVE_SET_FORMATTAG,wFormatTag);
-			WII("channels",MCI_WAVE_SET_CHANNELS,nChannels);
-			WII("bytespersec",MCI_WAVE_SET_AVGBYTESPERSEC,nAvgBytesPerSec);
-			WII("samplespersec",MCI_WAVE_SET_SAMPLESPERSEC,nSamplesPerSec);
-			WII("alignment",MCI_WAVE_SET_BLOCKALIGN,nBlockAlign);
-			WII("bitspersample",MCI_WAVE_SET_BITSPERSAMPLE,wBitsPerSample);
-			WII("input",MCI_WAVE_INPUT,wInput);
-			WII("output",MCI_WAVE_OUTPUT,wOutput);
+			WII("formattag",MCI_WAVE_SET_FORMATTAG,UIFMT,wFormatTag);
+			WII("channels",MCI_WAVE_SET_CHANNELS,UIFMT,nChannels);
+			WII("bytespersec",MCI_WAVE_SET_AVGBYTESPERSEC,"%lu",nAvgBytesPerSec);
+			WII("samplespersec",MCI_WAVE_SET_SAMPLESPERSEC,"%lu",nSamplesPerSec);
+			WII("alignment",MCI_WAVE_SET_BLOCKALIGN,UIFMT,nBlockAlign);
+			WII("bitspersample",MCI_WAVE_SET_BITSPERSAMPLE,UIFMT,wBitsPerSample);
+			WII("input",MCI_WAVE_INPUT,UIFMT,wInput);
+			WII("output",MCI_WAVE_OUTPUT,UIFMT,wOutput);
 #undef WII
 			break;
 		case MCI_DEVTYPE_SEQUENCER:
@@ -921,7 +921,7 @@
 static DWORD
 MCISTR_Capability(_MCISTR_PROTO_) {
 	MCI_GETDEVCAPS_PARMS	gdcParams;
-	int	type,i,res;
+	int	type=0,i,res;
 
 	gdcParams.dwCallback = 0;
 	if (!nrofkeywords)
@@ -1317,6 +1317,8 @@
 	return res;
 }
 
+DWORD mciSysInfo(DWORD dwFlags,LPMCI_SYSINFO_PARMS lpParms);
+
 /* query MCI driver itself for information
  * Arguments:
  *	"installname"	return install name of <device> (system.ini)
@@ -2080,9 +2082,9 @@
 	UINT uReturnLength, HWND hwndCallback)
 {
 	char	*cmd,*dev,*args,**keywords;
-	WORD	uDevTyp,wDevID;
+	WORD	uDevTyp=0,wDevID=0;
 	DWORD	dwFlags;
-	int	res,i,nrofkeywords;
+	int	res=0,i,nrofkeywords;
 
 	dprintf_mci(stdnimp,"mciSendString('%s', %p, %d, %X)\n", lpstrCommand, 
 		lpstrReturnString, uReturnLength, hwndCallback
diff --git a/multimedia/mmsystem.c b/multimedia/mmsystem.c
index b2bc0e1..db3e707 100644
--- a/multimedia/mmsystem.c
+++ b/multimedia/mmsystem.c
@@ -1051,8 +1051,9 @@
 UINT midiOutCachePatches(HMIDIOUT hMidiOut,
     UINT uBank, WORD FAR* lpwPatchArray, UINT uFlags)
 {
-	dprintf_mmsys(stddeb, "midiOutCachePatches\n");
-	return 0;
+        /* not really necessary to support this */
+	fprintf(stdnimp, "midiOutCachePatches: not supported yet\n");
+	return MMSYSERR_NOTSUPPORTED;
 }
 
 /**************************************************************************
@@ -1061,8 +1062,8 @@
 UINT midiOutCacheDrumPatches(HMIDIOUT hMidiOut,
     UINT uPatch, WORD FAR* lpwKeyArray, UINT uFlags)
 {
-	dprintf_mmsys(stddeb, "midiOutCacheDrumPatches\n");
-	return 0;
+	fprintf(stdnimp, "midiOutCacheDrumPatchesi: not supported yet\n");
+	return MMSYSERR_NOTSUPPORTED;
 }
 
 /**************************************************************************
diff --git a/multimedia/time.c b/multimedia/time.c
index 00bffc4..5193abd 100644
--- a/multimedia/time.c
+++ b/multimedia/time.c
@@ -45,7 +45,6 @@
  */
 WORD MMSysTimeCallback(HWND hWnd, WORD wMsg, INT nID, DWORD dwTime)
 {
-    FARPROC	lpFunc;
     LPTIMERENTRY lpTimer = lpTimerList;
     mmSysTimeMS.u.ms += 33;
     mmSysTimeSMPTE.u.smpte.frame++;
@@ -58,23 +57,25 @@
 		dprintf_mmtime(stddeb, "MMSysTimeCallback // lpFunc=%08lx wTimerID=%04X dwUser=%08lX !\n",
 			lpTimer->lpFunc, lpTimer->wTimerID, lpTimer->dwUser);
 		dprintf_mmtime(stddeb, "MMSysTimeCallback // hInstance=%04X !\n", lpTimer->hInstance);
-/*
-		lpFunc = MakeProcInstance(lpTimer->hInstance, lpTimer->lpFunc);
-		dprintf_mmtime(stddeb, "MMSysTimeCallback // MakeProcInstance(lpFunc)=%p %p !\n", 
-			lpFunc, PTR_SEG_TO_LIN(lpFunc));
-*/
-		lpFunc = MODULE_GetEntryPoint( lpTimer->hInstance,
-                      MODULE_GetOrdinal(lpTimer->hInstance,"TimerCallBack" ));
+
+/* This is wrong (lpFunc is NULL all the time)
+
+   	        lpFunc = MODULE_GetEntryPoint( lpTimer->hInstance,
+                         MODULE_GetOrdinal(lpTimer->hInstance,"TimerCallBack" ));
 		dprintf_mmtime(stddeb, "MMSysTimeCallback // lpFunc=%08lx !\n", lpFunc);
-		
+*/
+
+
+/*        - TimeProc callback that is called here is something strange, under Windows 3.1x it is called 
+ *          during interrupt time,  is allowed to execute very limited number of API calls (like
+ *	    PostMessage), and must reside in DLL (therefore uses stack of active application). So I 
+ *          guess current implementation via SetTimer has to be improved upon.		
+ */
+
 		CallTo16_word_wwlll(lpTimer->lpFunc,
 			lpTimer->hInstance, lpTimer->wTimerID, 
 			0, lpTimer->dwUser, 0, 0);
 
-/*
-		CallTimeFuncProc(lpTimer->lpFunc, lpTimer->wTimerID, 
-				0, lpTimer->dwUser, 0, 0);
-*/
 		dprintf_mmtime(stddeb, "MMSysTimeCallback // after CallBack16 !\n");
 		fflush(stdout);
 	    }
diff --git a/objects/Imakefile b/objects/Imakefile
deleted file mode 100644
index 6ba4f82..0000000
--- a/objects/Imakefile
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = objects
-
-SRCS = \
-	bitblt.c \
-	bitmap.c \
-	brush.c \
-	clipping.c \
-	color.c \
-	dc.c \
-	dcvalues.c \
-	dib.c \
-	font.c \
-	gdiobj.c \
-	linedda.c \
-	metafile.c \
-	oembitmap.c \
-	palette.c \
-	pen.c \
-	region.c \
-	text.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/objects/Makefile.in b/objects/Makefile.in
index f88bb21..eb31162 100644
--- a/objects/Makefile.in
+++ b/objects/Makefile.in
@@ -7,6 +7,7 @@
 	brush.c \
 	clipping.c \
 	color.c \
+	cursoricon.c \
 	dc.c \
 	dcvalues.c \
 	dib.c \
diff --git a/objects/bitblt.c b/objects/bitblt.c
index ab8daf9..ae7dd30 100644
--- a/objects/bitblt.c
+++ b/objects/bitblt.c
@@ -1236,7 +1236,7 @@
 	return TRUE;
     }
 
-    dprintf_bitblt(stddeb, "PatBlt: %d %d,%d %dx%d %06lx\n",
+    dprintf_bitblt(stddeb, "PatBlt: "NPFMT" %d,%d %dx%d %06lx\n",
 	    hdc, left, top, width, height, rop );
 
     return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
@@ -1263,7 +1263,7 @@
     dcSrc = (DC *) GDI_GetObjPtr( hdcSrc, DC_MAGIC );
 
     dprintf_bitblt(stddeb,
-                "BitBlt: %04x %d,%d %d bpp -> %04x %d,%d %dx%dx%d rop=%06lx\n",
+                "BitBlt: "NPFMT" %d,%d %d bpp -> "NPFMT" %d,%d %dx%dx%d rop=%06lx\n",
                 hdcSrc, xSrc, ySrc, dcSrc ? dcSrc->w.bitsPerPixel : 0,
                 hdcDst, xDst, yDst, width, height, dcDst->w.bitsPerPixel, rop);
 
@@ -1293,7 +1293,7 @@
 
     dcSrc = (DC *) GDI_GetObjPtr( hdcSrc, DC_MAGIC );
     dprintf_bitblt(stddeb,
-          "StretchBlt: %04x %d,%d %dx%dx%d -> %04x %d,%d %dx%dx%d rop=%06lx\n",
+          "StretchBlt: "NPFMT" %d,%d %dx%dx%d -> "NPFMT" %d,%d %dx%dx%d rop=%06lx\n",
                    hdcSrc, xSrc, ySrc, widthSrc, heightSrc,
                    dcSrc ? dcSrc->w.bitsPerPixel : 0, hdcDst, xDst, yDst,
                    widthDst, heightDst, dcDst->w.bitsPerPixel, rop );
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 179d16d..dde4d94 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -8,11 +8,9 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include "gdi.h"
-#include "arch.h"
 #include "callback.h"
 #include "dc.h"
 #include "bitmap.h"
-#include "resource.h"  /* for ConvertCore/InfoBitmap */
 #include "stddebug.h"
 /* #define DEBUG_GDI    */
 /* #define DEBUG_BITMAP */
@@ -126,7 +124,7 @@
 HBITMAP CreateCompatibleBitmap( HDC hdc, short width, short height )
 {
     DC * dc;
-    dprintf_gdi(stddeb, "CreateCompatibleBitmap: %d %dx%d\n", 
+    dprintf_gdi(stddeb, "CreateCompatibleBitmap: "NPFMT" %dx%d\n", 
 		hdc, width, height );
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
     return CreateBitmap( width, height, 1, dc->w.bitsPerPixel, NULL );
@@ -213,17 +211,17 @@
     HDC hdc;
     HRSRC hRsrc;
     HGLOBAL handle;
-    int size;
-    long *lp;
+    BITMAPINFO *info;
 
     if (HIWORD(name))
     {
         char *str = (char *)PTR_SEG_TO_LIN( name );
-        dprintf_bitmap( stddeb, "LoadBitmap(%04x,'%s')\n", instance, str );
-        if (str[0] == '#') name = (SEGPTR)atoi( str + 1 );
+        dprintf_bitmap( stddeb, "LoadBitmap("NPFMT",'%s')\n", instance, str );
+        if (str[0] == '#') name = (SEGPTR)(WORD)atoi( str + 1 );
     }
     else
-        dprintf_bitmap(stddeb,"LoadBitmap(%04x,%04x)\n",instance,LOWORD(name));
+        dprintf_bitmap( stddeb, "LoadBitmap("NPFMT",%04x)\n",
+                        instance, LOWORD(name) );
 
     if (!instance)  /* OEM bitmap */
     {
@@ -234,14 +232,12 @@
     if (!(hRsrc = FindResource( instance, name, RT_BITMAP ))) return 0;
     if (!(handle = LoadResource( instance, hRsrc ))) return 0;
 
-    lp = (long *)LockResource( handle );
-    size = CONV_LONG(*lp);
+    info = (BITMAPINFO *)LockResource( handle );
     if ((hdc = GetDC(0)) != 0)
     {
-        if (size == sizeof(BITMAPCOREHEADER))
-            hbitmap = ConvertCoreBitmap( hdc, (BITMAPCOREHEADER *) lp );
-        else if (size == sizeof(BITMAPINFOHEADER))
-            hbitmap = ConvertInfoBitmap( hdc, (BITMAPINFO *) lp );
+        char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
+        hbitmap = CreateDIBitmap( hdc, &info->bmiHeader, CBM_INIT,
+                                  bits, info, DIB_RGB_COLORS );
         ReleaseDC( 0, hdc );
     }
     FreeResource( handle );
@@ -306,7 +302,7 @@
  */
 HBITMAP CreateDiscardableBitmap(HDC hdc, short width, short height)
 {
-    dprintf_bitmap(stddeb,"CreateDiscardableBitmap(%04X, %d, %d); "
+    dprintf_bitmap(stddeb,"CreateDiscardableBitmap("NPFMT", %d, %d); "
 	   "// call CreateCompatibleBitmap() for now!\n",
 	   hdc, width, height);
     return CreateCompatibleBitmap(hdc, width, height);
diff --git a/objects/brush.c b/objects/brush.c
index de64274..982920a 100644
--- a/objects/brush.c
+++ b/objects/brush.c
@@ -171,14 +171,18 @@
     LOGBRUSH logbrush = { BS_PATTERN, 0, 0 };
     BITMAPOBJ *bmp, *newbmp;
 
-    dprintf_gdi(stddeb, "CreatePatternBrush: %d\n", hbitmap );
+    dprintf_gdi(stddeb, "CreatePatternBrush: "NPFMT"\n", hbitmap );
 
       /* Make a copy of the bitmap */
 
     if (!(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
 	return 0;
-    logbrush.lbHatch = CreateBitmapIndirect( &bmp->bitmap );
-    newbmp = (BITMAPOBJ *) GDI_GetObjPtr( logbrush.lbHatch, BITMAP_MAGIC );
+#ifdef WINELIB32
+    logbrush.lbHatch = (LONG)CreateBitmapIndirect( &bmp->bitmap );
+#else
+    logbrush.lbHatch = (INT)CreateBitmapIndirect( &bmp->bitmap );
+#endif
+    newbmp = (BITMAPOBJ *) GDI_GetObjPtr( (HANDLE)logbrush.lbHatch, BITMAP_MAGIC );
     if (!newbmp) return 0;
     XCopyArea( display, bmp->pixmap, newbmp->pixmap, BITMAP_GC(bmp),
 	       0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 0, 0 );
@@ -195,7 +199,7 @@
     BITMAPINFO *info, *newInfo;
     int size;
     
-    dprintf_gdi(stddeb, "CreateDIBPatternBrush: %d\n", hbitmap );
+    dprintf_gdi(stddeb, "CreateDIBPatternBrush: "NPFMT"\n", hbitmap );
 
       /* Make a copy of the bitmap */
 
@@ -207,14 +211,18 @@
 	         * 8 * info->bmiHeader.biHeight;
     size += DIB_BitmapInfoSize( info, coloruse );
 
-    if (!(logbrush.lbHatch = GlobalAlloc( GMEM_MOVEABLE, size )))
+#ifdef WINELIB32
+    if (!(logbrush.lbHatch = (LONG)GlobalAlloc( GMEM_MOVEABLE, size )))
+#else
+    if (!(logbrush.lbHatch = (INT)GlobalAlloc( GMEM_MOVEABLE, size )))
+#endif
     {
 	GlobalUnlock( hbitmap );
 	return 0;
     }
-    newInfo = (BITMAPINFO *) GlobalLock( logbrush.lbHatch );
+    newInfo = (BITMAPINFO *) GlobalLock( (HANDLE)logbrush.lbHatch );
     memcpy( newInfo, info, size );
-    GlobalUnlock( logbrush.lbHatch );
+    GlobalUnlock( (HANDLE)logbrush.lbHatch );
     GlobalUnlock( hbitmap );
     return CreateBrushIndirect( &logbrush );
 }
@@ -248,7 +256,7 @@
 /***********************************************************************
  *           GetSysColorBrush    (USER.281)
  */
-WORD GetSysColorBrush(WORD x)
+HBRUSH GetSysColorBrush(WORD x)
 {
 	return GetStockObject(GRAY_BRUSH);
 }
@@ -261,10 +269,10 @@
     switch(brush->logbrush.lbStyle)
     {
       case BS_PATTERN:
-	  DeleteObject( brush->logbrush.lbHatch );
+	  DeleteObject( (HANDLE)brush->logbrush.lbHatch );
 	  break;
       case BS_DIBPATTERN:
-	  GlobalFree( brush->logbrush.lbHatch );
+	  GlobalFree( (HANDLE)brush->logbrush.lbHatch );
 	  break;
     }
     return GDI_FreeObject( hbrush );
@@ -339,7 +347,7 @@
     BITMAPINFO * bmpInfo;
     HBRUSH prevHandle = dc->w.hBrush;
 
-    dprintf_gdi(stddeb, "Brush_SelectObject   hdc=%04x  hbrush=%04x\n",
+    dprintf_gdi(stddeb, "Brush_SelectObject   hdc="NPFMT"  hbrush="NPFMT"\n",
 		hdc,hbrush);
     if (dc->header.wMagic == METAFILE_DC_MAGIC)
     {
@@ -349,16 +357,16 @@
 	case BS_HATCHED:
 	case BS_HOLLOW:
 	    if (!MF_CreateBrushIndirect(dc, hbrush, &(brush->logbrush)))
-		return 0;
+		return (HBRUSH)0;
 	    break;
 
 	case BS_PATTERN:
 	case BS_DIBPATTERN:
 	    if (!MF_CreatePatternBrush(dc, hbrush, &(brush->logbrush)))
-		return 0;
+		return (HBRUSH)0;
 	    break;
 	}
-	return 1;
+	return (HBRUSH)1;
     }
     
     dc->w.hBrush = hbrush;
@@ -391,12 +399,12 @@
 	
       case BS_PATTERN:
 	dprintf_gdi( stddeb, "BS_PATTERN\n");
-	BRUSH_SelectPatternBrush( dc, brush->logbrush.lbHatch );
+	BRUSH_SelectPatternBrush( dc, (HBRUSH)brush->logbrush.lbHatch );
 	break;
 
       case BS_DIBPATTERN:
 	dprintf_gdi( stddeb, "BS_DIBPATTERN\n");
-	if ((bmpInfo = (BITMAPINFO *) GlobalLock( brush->logbrush.lbHatch )))
+	if ((bmpInfo = (BITMAPINFO *) GlobalLock( (HANDLE)brush->logbrush.lbHatch )))
 	{
 	    int size = DIB_BitmapInfoSize( bmpInfo, brush->logbrush.lbColor );
 	    hBitmap = CreateDIBitmap( hdc, &bmpInfo->bmiHeader, CBM_INIT,
@@ -404,7 +412,7 @@
 				      (WORD) brush->logbrush.lbColor );
 	    BRUSH_SelectPatternBrush( dc, hBitmap );
 	    DeleteObject( hBitmap );
-	    GlobalUnlock( brush->logbrush.lbHatch );	    
+	    GlobalUnlock( (HANDLE)brush->logbrush.lbHatch );	    
 	}
 	
 	break;
diff --git a/objects/clipping.c b/objects/clipping.c
index 003a6ae..e6a3335 100644
--- a/objects/clipping.c
+++ b/objects/clipping.c
@@ -67,7 +67,7 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;
 
-    dprintf_clipping(stddeb, "SelectClipRgn: %x %x\n", hdc, hrgn );
+    dprintf_clipping(stddeb, "SelectClipRgn: "NPFMT" "NPFMT"\n", hdc, hrgn );
 
     if (hrgn)
     {
@@ -94,7 +94,7 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc || !hrgn) return ERROR;
 
-    dprintf_clipping(stddeb, "SelectVisRgn: %x %x\n", hdc, hrgn );
+    dprintf_clipping(stddeb, "SelectVisRgn: "NPFMT" "NPFMT"\n", hdc, hrgn );
 
     retval = CombineRgn( dc->w.hVisRgn, hrgn, 0, RGN_COPY );
     CLIPPING_UpdateGCRegion( dc );
@@ -116,7 +116,7 @@
 	return NULLREGION;   /* ?? */
     }
 
-    dprintf_clipping(stddeb, "OffsetClipRgn: %x %d,%d\n", hdc, x, y );
+    dprintf_clipping(stddeb, "OffsetClipRgn: "NPFMT" %d,%d\n", hdc, x, y );
 
     if (dc->w.hClipRgn)
     {
@@ -136,7 +136,7 @@
     int retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
-    dprintf_clipping(stddeb, "OffsetVisRgn: %x %d,%d\n", hdc, x, y );
+    dprintf_clipping(stddeb, "OffsetVisRgn: "NPFMT" %d,%d\n", hdc, x, y );
     retval = OffsetRgn( dc->w.hVisRgn, x, y );
     CLIPPING_UpdateGCRegion( dc );
     return retval;
@@ -195,7 +195,7 @@
 	return NULLREGION;   /* ?? */
     }
 
-    dprintf_clipping(stddeb, "ExcludeClipRect: %x %dx%d,%dx%d\n",
+    dprintf_clipping(stddeb, "ExcludeClipRect: "NPFMT" %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
     return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, TRUE );
 }
@@ -216,7 +216,7 @@
 	return NULLREGION;   /* ?? */
     }
 
-    dprintf_clipping(stddeb, "IntersectClipRect: %x %dx%d,%dx%d\n",
+    dprintf_clipping(stddeb, "IntersectClipRect: "NPFMT" %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
     return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, FALSE );
 }
@@ -269,7 +269,7 @@
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
-    dprintf_clipping(stddeb, "ExcludeVisRect: %x %dx%d,%dx%d\n",
+    dprintf_clipping(stddeb, "ExcludeVisRect: "NPFMT" %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
     return CLIPPING_IntersectVisRect( dc, left, top, right, bottom, TRUE );
 }
@@ -283,7 +283,7 @@
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
-    dprintf_clipping(stddeb, "IntersectVisRect: %x %dx%d,%dx%d\n",
+    dprintf_clipping(stddeb, "IntersectVisRect: "NPFMT" %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
     return CLIPPING_IntersectVisRect( dc, left, top, right, bottom, FALSE );
 }
@@ -297,7 +297,7 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
 
-    dprintf_clipping(stddeb, "PtVisible: %x %d,%d\n", hdc, x, y );
+    dprintf_clipping(stddeb, "PtVisible: "NPFMT" %d,%d\n", hdc, x, y );
     if (!dc->w.hGCClipRgn) return FALSE;
     return PtInRegion( dc->w.hGCClipRgn, XLPTODP(dc,x), YLPTODP(dc,y) );
 }
@@ -311,7 +311,7 @@
     RECT tmpRect;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
-    dprintf_clipping(stddeb,"RectVisible: %x %d,%dx%d,%d\n",
+    dprintf_clipping(stddeb,"RectVisible: "NPFMT" %d,%dx%d,%d\n",
                      hdc, rect->left, rect->top, rect->right, rect->bottom );
     if (!dc->w.hGCClipRgn) return FALSE;
     /* copy rectangle to avoid overwriting by LPtoDP */
@@ -329,7 +329,7 @@
     int ret;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
-    dprintf_clipping(stddeb, "GetClipBox: %x %p\n", hdc, rect );
+    dprintf_clipping(stddeb, "GetClipBox: "NPFMT" %p\n", hdc, rect );
     ret = GetRgnBox( dc->w.hGCClipRgn, rect );
     DPtoLP( hdc, (LPPOINT)rect, 2 );
     return ret;
@@ -345,7 +345,7 @@
     RGNOBJ *obj, *copyObj;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return 0;
-    dprintf_clipping(stddeb, "SaveVisRgn: %x\n", hdc );
+    dprintf_clipping(stddeb, "SaveVisRgn: "NPFMT"\n", hdc );
     if (!dc->w.hVisRgn)
     {
         fprintf( stderr, "SaveVisRgn: hVisRgn is zero. Please report this.\n" );
@@ -372,7 +372,7 @@
     RGNOBJ *obj, *savedObj;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc || !dc->w.hVisRgn) return ERROR;    
-    dprintf_clipping(stddeb, "RestoreVisRgn: %x\n", hdc );
+    dprintf_clipping(stddeb, "RestoreVisRgn: "NPFMT"\n", hdc );
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC )))
 	return ERROR;
     if (!(saved = obj->header.hNext)) return ERROR;
diff --git a/objects/color.c b/objects/color.c
index bde033b..5941340 100644
--- a/objects/color.c
+++ b/objects/color.c
@@ -2,9 +2,8 @@
  * Color functions
  *
  * Copyright 1993 Alexandre Julliard
- *
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993";
-*/
+ */
+
 #include <stdlib.h>
 #include <X11/Xlib.h>
 #include <stdio.h>
@@ -243,7 +242,6 @@
 	}
 	COLOR_WinColormap = DefaultColormapOfScreen( screen );
         break;
-	/* Fall through */
     case StaticGray:
 	COLOR_WinColormap = DefaultColormapOfScreen( screen );
 	COLOR_FixedMap = 1;
@@ -303,8 +301,6 @@
     WORD index = 0;
     WORD *mapping;
 
-    /* if (screenDepth > 8) return color; */
-
     if (dc && (dc->w.bitsPerPixel == 1) && ((color >> 24) == 0))
     {
 	/* monochrome */
@@ -314,53 +310,52 @@
         else return 0;  /* black */
     }
 
-    if(COLOR_FixedMap) {
-
+    if (COLOR_FixedMap)
+    {
         /* there is no colormap possible; we are going to have to compute
            the pixel value from the visual information stored earlier */
 
-	unsigned long which = color >> 24;
-
 	unsigned long red, green, blue;
 	unsigned idx;
 	PALETTEOBJ * palPtr;
 
-	switch(which) {
-		case 0: /* RGB */
-		case 2: /* PALETTERGB -- needs some work, but why bother; we've got a REALLY LARGE number of colors...? */
-		default:
+	switch(color >> 24)
+        {
+        case 0: /* RGB */
+        case 2: /* PALETTERGB -- needs some work, but why bother; we've got a REALLY LARGE number of colors...? */
+        default:
+            red = GetRValue(color);
+            green = GetGValue(color);
+            blue = GetBValue(color);
+            break;
 
-		red = GetRValue(color);
-		green = GetGValue(color);
-		blue = GetBValue(color);
-		break;
-
-		case 1: /* PALETTEIDX -- hmm, get the real color from the stock palette */
-		palPtr = (PALETTEOBJ *) GDI_GetObjPtr( STOCK_DEFAULT_PALETTE, PALETTE_MAGIC);
-		idx = color & 0xffff;
-		if(idx >= palPtr->logpalette.palNumEntries) {
-			/* out of bounds */
-			red = green = blue = 0;
-		}
-		else {
-			red = palPtr->logpalette.palPalEntry[idx].peRed;
-			green = palPtr->logpalette.palPalEntry[idx].peGreen;
-			blue = palPtr->logpalette.palPalEntry[idx].peBlue;
-		}
+        case 1: /* PALETTEIDX -- hmm, get the real color from the stock palette */
+            palPtr = (PALETTEOBJ *) GDI_GetObjPtr( STOCK_DEFAULT_PALETTE, PALETTE_MAGIC);
+            idx = color & 0xffff;
+            if (idx >= palPtr->logpalette.palNumEntries)
+            {
+                /* out of bounds */
+                red = green = blue = 0;
+            }
+            else
+            {
+                red = palPtr->logpalette.palPalEntry[idx].peRed;
+                green = palPtr->logpalette.palPalEntry[idx].peGreen;
+                blue = palPtr->logpalette.palPalEntry[idx].peBlue;
+            }
 	}
 
-	if(COLOR_Graymax) {
+	if (COLOR_Graymax)
+        {
 	    /* grayscale only; return scaled value */
             return ( (red * 30 + green * 69 + blue * 11) * COLOR_Graymax) / 25500;
 	}
-	else {
+	else
+        {
 	    /* scale each individually and construct the TrueColor pixel value */
-	    if(COLOR_Redmax != 255)
-                red = (red * COLOR_Redmax) / 255;
-	    if(COLOR_Greenmax != 255)
-                green = (green * COLOR_Greenmax) / 255;
-	    if(COLOR_Bluemax != 255)
-                blue = (blue * COLOR_Bluemax) / 255;
+	    if (COLOR_Redmax != 255) red = (red * COLOR_Redmax) / 255;
+            if (COLOR_Greenmax != 255) green = (green * COLOR_Greenmax) / 255;
+	    if (COLOR_Bluemax != 255) blue = (blue * COLOR_Bluemax) / 255;
 
 	    return (red << COLOR_Redshift) | (green << COLOR_Greenshift) | (blue << COLOR_Blueshift);
         }
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
new file mode 100644
index 0000000..6cc3f2a
--- /dev/null
+++ b/objects/cursoricon.c
@@ -0,0 +1,853 @@
+/*
+ * Cursor and icon support
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+
+/*
+ * Theory:
+ *
+ * Cursors and icons are stored in a global heap block, with the
+ * following layout:
+ *
+ * CURSORICONINFO info;
+ * BYTE[]         ANDbits;
+ * BYTE[]         XORbits;
+ *
+ * The bits structures are in the format of a device-dependent bitmap.
+ *
+ * This layout is very sub-optimal, as the bitmap bits are stored in
+ * the X client instead of in the server like other bitmaps; however,
+ * some programs (notably Paint Brush) expect to be able to manipulate
+ * the bits directly :-(
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include "windows.h"
+#include "bitmap.h"
+#include "callback.h"
+#include "cursoricon.h"
+#include "sysmetrics.h"
+#include "win.h"
+#include "stddebug.h"
+#include "debug.h"
+
+
+Cursor CURSORICON_XCursor = None;  /* Current X cursor */
+static HCURSOR hActiveCursor = 0;  /* Active cursor */
+static int CURSOR_ShowCount = 0;   /* Cursor display count */
+static RECT CURSOR_ClipRect;       /* Cursor clipping rect */
+
+/**********************************************************************
+ *	    CURSORICON_FindBestIcon
+ *
+ * Find the icon closest to the requested size and number of colors.
+ */
+static ICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
+                                              int height, int colors )
+{
+    int i, maxcolors, maxwidth, maxheight;
+    ICONDIRENTRY *entry, *bestEntry = NULL;
+
+    if (dir->idCount < 1)
+    {
+        fprintf( stderr, "Icon: empty directory!\n" );
+        return NULL;
+    }
+    if (dir->idCount == 1) return &dir->idEntries[0].icon;  /* No choice... */
+
+    /* First find the exact size with less colors */
+
+    maxcolors = 0;
+    for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++)
+        if ((entry->bWidth == width) && (entry->bHeight == height) &&
+            (entry->bColorCount <= colors) && (entry->bColorCount > maxcolors))
+        {
+            bestEntry = entry;
+            maxcolors = entry->bColorCount;
+        }
+    if (bestEntry) return bestEntry;
+
+    /* First find the exact size with more colors */
+
+    maxcolors = 255;
+    for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++)
+        if ((entry->bWidth == width) && (entry->bHeight == height) &&
+            (entry->bColorCount > colors) && (entry->bColorCount <= maxcolors))
+        {
+            bestEntry = entry;
+            maxcolors = entry->bColorCount;
+        }
+    if (bestEntry) return bestEntry;
+
+    /* Now find a smaller one with less colors */
+
+    maxcolors = maxwidth = maxheight = 0;
+    for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++)
+        if ((entry->bWidth <= width) && (entry->bHeight <= height) &&
+            (entry->bWidth >= maxwidth) && (entry->bHeight >= maxheight) &&
+            (entry->bColorCount <= colors) && (entry->bColorCount > maxcolors))
+        {
+            bestEntry = entry;
+            maxwidth  = entry->bWidth;
+            maxheight = entry->bHeight;
+            maxcolors = entry->bColorCount;
+        }
+    if (bestEntry) return bestEntry;
+
+    /* Now find a smaller one with more colors */
+
+    maxcolors = 255;
+    maxwidth = maxheight = 0;
+    for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++)
+        if ((entry->bWidth <= width) && (entry->bHeight <= height) &&
+            (entry->bWidth >= maxwidth) && (entry->bHeight >= maxheight) &&
+            (entry->bColorCount > colors) && (entry->bColorCount <= maxcolors))
+        {
+            bestEntry = entry;
+            maxwidth  = entry->bWidth;
+            maxheight = entry->bHeight;
+            maxcolors = entry->bColorCount;
+        }
+    if (bestEntry) return bestEntry;
+
+    /* Now find a larger one with less colors */
+
+    maxcolors = 0;
+    maxwidth = maxheight = 255;
+    for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++)
+        if ((entry->bWidth <= maxwidth) && (entry->bHeight <= maxheight) &&
+            (entry->bColorCount <= colors) && (entry->bColorCount > maxcolors))
+        {
+            bestEntry = entry;
+            maxwidth  = entry->bWidth;
+            maxheight = entry->bHeight;
+            maxcolors = entry->bColorCount;
+        }
+    if (bestEntry) return bestEntry;
+
+    /* Now find a larger one with more colors */
+
+    maxcolors = maxwidth = maxheight = 255;
+    for (i = 0, entry = &dir->idEntries[0].icon; i < dir->idCount; i++,entry++)
+        if ((entry->bWidth <= maxwidth) && (entry->bHeight <= maxheight) &&
+            (entry->bColorCount > colors) && (entry->bColorCount <= maxcolors))
+        {
+            bestEntry = entry;
+            maxwidth  = entry->bWidth;
+            maxheight = entry->bHeight;
+            maxcolors = entry->bColorCount;
+        }
+
+    return bestEntry;
+}
+
+
+/**********************************************************************
+ *	    CURSORICON_FindBestCursor
+ *
+ * Find the cursor closest to the requested size.
+ */
+static CURSORDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir,
+                                                  int width, int height )
+{
+    int i, maxwidth, maxheight;
+    CURSORDIRENTRY *entry, *bestEntry = NULL;
+
+    if (dir->idCount < 1)
+    {
+        fprintf( stderr, "Cursor: empty directory!\n" );
+        return NULL;
+    }
+    if (dir->idCount == 1) return &dir->idEntries[0].cursor; /* No choice... */
+
+    /* First find the largest one smaller than or equal to the requested size*/
+
+    maxwidth = maxheight = 0;
+    for(i = 0,entry = &dir->idEntries[0].cursor; i < dir->idCount; i++,entry++)
+        if ((entry->wWidth <= width) && (entry->wHeight <= height) &&
+            (entry->wWidth > maxwidth) && (entry->wHeight > maxheight))
+        {
+            bestEntry = entry;
+            maxwidth  = entry->wWidth;
+            maxheight = entry->wHeight;
+        }
+    if (bestEntry) return bestEntry;
+
+    /* Now find the smallest one larger than the requested size */
+
+    maxwidth = maxheight = 255;
+    for(i = 0,entry = &dir->idEntries[0].cursor; i < dir->idCount; i++,entry++)
+        if ((entry->wWidth < maxwidth) && (entry->wHeight < maxheight))
+        {
+            bestEntry = entry;
+            maxwidth  = entry->wWidth;
+            maxheight = entry->wHeight;
+        }
+
+    return bestEntry;
+}
+
+
+/**********************************************************************
+ *	    CURSORICON_LoadDirEntry
+ *
+ * Load the icon/cursor directory for a given resource name and find the
+ * best matching entry.
+ */
+static BOOL CURSORICON_LoadDirEntry(HANDLE hInstance, SEGPTR name,
+                                    int width, int height, int colors,
+                                    BOOL fCursor, CURSORICONDIRENTRY *dirEntry)
+{
+    HRSRC hRsrc;
+    HANDLE hMem;
+    CURSORICONDIR *dir;
+    CURSORICONDIRENTRY *entry = NULL;
+
+    if (!(hRsrc = FindResource( hInstance, name,
+                                fCursor ? RT_GROUP_CURSOR : RT_GROUP_ICON )))
+        return FALSE;
+    if (!(hMem = LoadResource( hInstance, hRsrc ))) return FALSE;
+    if ((dir = (CURSORICONDIR *)LockResource( hMem )))
+    {
+        if (fCursor)
+            entry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor( dir,
+                                                               width, height );
+        else
+            entry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon( dir,
+                                                       width, height, colors );
+        if (entry) *dirEntry = *entry;
+    }
+    FreeResource( hMem );
+    return (entry != NULL);
+}
+
+
+/**********************************************************************
+ *	    CURSORICON_Load
+ *
+ * Load a cursor or icon.
+ */
+static HANDLE CURSORICON_Load( HANDLE hInstance, SEGPTR name, int width,
+                               int height, int colors, BOOL fCursor )
+{
+    HANDLE handle, hAndBits, hXorBits;
+    HRSRC hRsrc;
+    HDC hdc;
+    int size, sizeAnd, sizeXor;
+    POINT hotspot = { 0 ,0 };
+    BITMAPOBJ *bmpXor, *bmpAnd;
+    BITMAPINFO *bmi, *pInfo;
+    CURSORICONINFO *info;
+    CURSORICONDIRENTRY dirEntry;
+    char *bits;
+
+    if (!hInstance)  /* OEM cursor/icon */
+    {
+        if (HIWORD(name))  /* Check for '#xxx' name */
+        {
+            char *ptr = PTR_SEG_TO_LIN( name );
+            if (ptr[0] != '#') return 0;
+            if (!(name = (SEGPTR)atoi( ptr + 1 ))) return 0;
+        }
+        return OBM_LoadCursorIcon( LOWORD(name), fCursor );
+    }
+
+    /* Find the best entry in the directory */
+
+    if (!CURSORICON_LoadDirEntry( hInstance, name, width, height,
+                                  colors, fCursor, &dirEntry )) return 0;
+
+    /* Load the resource */
+
+    if (!(hRsrc = FindResource( hInstance,
+                                MAKEINTRESOURCE( dirEntry.icon.wResId ),
+                                fCursor ? RT_CURSOR : RT_ICON ))) return 0;
+    if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
+
+    if (fCursor)  /* If cursor, get the hotspot */
+    {
+        POINT *pt = (POINT *)LockResource( handle );
+        hotspot = *pt;
+        bmi = (BITMAPINFO *)(pt + 1);
+    }
+    else bmi = (BITMAPINFO *)LockResource( handle );
+
+    /* Create a copy of the bitmap header */
+
+    size = DIB_BitmapInfoSize( bmi, DIB_RGB_COLORS );
+    /* Make sure we have room for the monochrome bitmap later on */
+    size = max( size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD) );
+    pInfo = (BITMAPINFO *)malloc( size );
+    memcpy( pInfo, bmi, size );
+
+    if (pInfo->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
+    {
+        if (pInfo->bmiHeader.biCompression != BI_RGB)
+        {
+            fprintf(stderr,"Unknown size for compressed icon bitmap.\n");
+            FreeResource( handle );
+            free( pInfo );
+            return 0;
+        }
+        pInfo->bmiHeader.biHeight /= 2;
+    }
+    else if (pInfo->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
+    {
+        BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)pInfo;
+        core->bcHeight /= 2;
+    }
+    else
+    {
+        fprintf( stderr, "CURSORICON_Load: Unknown bitmap length %ld!\n",
+                 pInfo->bmiHeader.biSize );
+        FreeResource( handle );
+        free( pInfo );
+        return 0;
+    }
+
+    /* Create the XOR bitmap */
+
+    if (!(hdc = GetDC( 0 )))
+    {
+        FreeResource( handle );
+        free( pInfo );
+        return 0;
+    }
+
+    hXorBits = CreateDIBitmap( hdc, &pInfo->bmiHeader, CBM_INIT,
+                               (char*)bmi + size, pInfo, DIB_RGB_COLORS );
+
+    /* Fix the bitmap header to load the monochrome mask */
+
+    if (pInfo->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
+    {
+        BITMAPINFOHEADER *bih = &pInfo->bmiHeader;
+        RGBQUAD *rgb = pInfo->bmiColors;
+        bits = (char *)bmi + size +
+            DIB_GetImageWidthBytes(bih->biWidth,bih->biBitCount)*bih->biHeight;
+        bih->biBitCount = 1;
+        bih->biClrUsed = bih->biClrImportant = 2;
+        rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
+        rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
+        rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
+    }
+    else
+    {
+        BITMAPCOREHEADER *bch = (BITMAPCOREHEADER *)pInfo;
+        RGBTRIPLE *rgb = (RGBTRIPLE *)(bch + 1);
+        bits = (char *)bmi + size +
+            DIB_GetImageWidthBytes(bch->bcWidth,bch->bcBitCount)*bch->bcHeight;
+        bch->bcBitCount = 1;
+        rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
+        rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
+    }
+
+    /* Create the AND bitmap */
+
+    hAndBits = CreateDIBitmap( hdc, &pInfo->bmiHeader, CBM_INIT,
+                               bits, pInfo, DIB_RGB_COLORS );
+    ReleaseDC( 0, hdc );
+    FreeResource( handle );
+
+    /* Now create the CURSORICONINFO structure */
+
+    bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( hXorBits, BITMAP_MAGIC );
+    bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( hAndBits, BITMAP_MAGIC );
+    sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes;
+    sizeAnd = bmpAnd->bitmap.bmHeight * bmpAnd->bitmap.bmWidthBytes;
+
+    if (!(handle = GlobalAlloc( GMEM_MOVEABLE,
+                                sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
+    {
+        DeleteObject( hXorBits );
+        DeleteObject( hAndBits );
+        return 0;
+    }
+    /* Make it owned by the module */
+    FarSetOwner( handle, GetExePtr( hInstance ) );
+    info = (CURSORICONINFO *)GlobalLock( handle );
+    info->ptHotSpot.x   = hotspot.x;
+    info->ptHotSpot.y   = hotspot.y;
+    info->nWidth        = bmpXor->bitmap.bmWidth;
+    info->nHeight       = bmpXor->bitmap.bmHeight;
+    info->nWidthBytes   = bmpXor->bitmap.bmWidthBytes;
+    info->bPlanes       = bmpXor->bitmap.bmPlanes;
+    info->bBitsPerPixel = bmpXor->bitmap.bmBitsPixel;
+
+    /* Transfer the bitmap bits to the CURSORICONINFO structure */
+
+    GetBitmapBits( hAndBits, sizeAnd, (char *)(info + 1) );
+    GetBitmapBits( hXorBits, sizeXor, (char *)(info + 1) + sizeAnd );
+    DeleteObject( hXorBits );
+    DeleteObject( hAndBits );
+    GlobalUnlock( handle );
+    return handle;
+}
+
+
+/***********************************************************************
+ *           CURSORICON_Copy
+ *
+ * Make a copy of a cursor or icon.
+ */
+static HANDLE CURSORICON_Copy( HANDLE hInstance, HANDLE handle )
+{
+    char *ptrOld, *ptrNew;
+    int size;
+    HANDLE hNew;
+
+    if (!(ptrOld = (char *)GlobalLock( handle ))) return 0;
+    if (!(hInstance = GetExePtr( hInstance ))) return 0;
+    size = GlobalSize( handle );
+    hNew = GlobalAlloc( GMEM_MOVEABLE, size );
+    FarSetOwner( hNew, hInstance );
+    ptrNew = (char *)GlobalLock( hNew );
+    memcpy( ptrNew, ptrOld, size );
+    GlobalUnlock( handle );
+    GlobalUnlock( hNew );
+    return hNew;
+}
+
+
+/***********************************************************************
+ *           LoadCursor    (USER.173)
+ */
+HCURSOR LoadCursor( HANDLE hInstance, SEGPTR name )
+{
+    if (HIWORD(name))
+        dprintf_cursor( stddeb, "LoadCursor: "NPFMT" '%s'\n",
+                        hInstance, (char *)PTR_SEG_TO_LIN( name ) );
+    else
+        dprintf_cursor( stddeb, "LoadCursor: "NPFMT" %04x\n",
+                        hInstance, LOWORD(name) );
+
+    return CURSORICON_Load( hInstance, name,
+                            SYSMETRICS_CXCURSOR, SYSMETRICS_CYCURSOR, 1, TRUE);
+}
+
+
+/***********************************************************************
+ *           LoadIcon    (USER.174)
+ */
+HICON LoadIcon( HANDLE hInstance, SEGPTR name )
+{
+    if (HIWORD(name))
+        dprintf_icon( stddeb, "LoadIcon: "NPFMT" '%s'\n",
+                      hInstance, (char *)PTR_SEG_TO_LIN( name ) );
+    else
+        dprintf_icon( stddeb, "LoadIcon: "NPFMT" %04x\n",
+                      hInstance, LOWORD(name) );
+
+    return CURSORICON_Load( hInstance, name,
+                            SYSMETRICS_CXICON, SYSMETRICS_CYICON,
+                            min( 16, 1 << screenDepth ), FALSE );
+}
+
+
+/***********************************************************************
+ *           CreateCursor    (USER.406)
+ */
+HICON CreateCursor( HANDLE hInstance, INT xHotSpot, INT yHotSpot,
+                    INT nWidth, INT nHeight, LPSTR lpANDbits, LPSTR lpXORbits)
+{
+    CURSORICONINFO info = { { xHotSpot, yHotSpot }, nWidth, nHeight, 1, 1 };
+
+    dprintf_cursor( stddeb, "CreateCursor: %dx%d spot=%d,%d xor=%p and=%p\n",
+                    nWidth, nHeight, xHotSpot, yHotSpot, lpXORbits, lpANDbits);
+    return CreateCursorIconIndirect( hInstance, &info, lpANDbits, lpXORbits );
+}
+
+
+/***********************************************************************
+ *           CreateIcon    (USER.407)
+ */
+HICON CreateIcon( HANDLE hInstance, INT nWidth, INT nHeight, BYTE bPlanes,
+                  BYTE bBitsPixel, LPSTR lpANDbits, LPSTR lpXORbits)
+{
+    CURSORICONINFO info = { { 0, 0 }, nWidth, nHeight, bPlanes, bBitsPixel };
+
+    dprintf_icon( stddeb, "CreateIcon: %dx%dx%d, xor=%p, and=%p\n",
+                  nWidth, nHeight, bPlanes * bBitsPixel, lpXORbits, lpANDbits);
+    return CreateCursorIconIndirect( hInstance, &info, lpANDbits, lpXORbits );
+}
+
+
+/***********************************************************************
+ *           CreateCursorIconIndirect    (USER.408)
+ */
+HANDLE CreateCursorIconIndirect( HANDLE hInstance, CURSORICONINFO *info,
+                                 LPSTR lpANDbits, LPSTR lpXORbits )
+{
+    HANDLE handle;
+    char *ptr;
+    int sizeAnd, sizeXor;
+
+    hInstance = GetExePtr( hInstance );  /* Make it a module handle */
+    if (!hInstance || !lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
+    info->nWidthBytes = (info->nWidth * info->bBitsPerPixel + 15) / 16 * 2;
+    sizeXor = info->nHeight * info->nWidthBytes;
+    sizeAnd = info->nHeight * ((info->nWidth + 15) / 16 * 2);
+    if (!(handle = DirectResAlloc(hInstance, 0x10,
+                                  sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
+        return 0;
+    ptr = (char *)GlobalLock( handle );
+    memcpy( ptr, info, sizeof(*info) );
+    memcpy( ptr + sizeof(CURSORICONINFO), lpANDbits, sizeAnd );
+    memcpy( ptr + sizeof(CURSORICONINFO) + sizeAnd, lpXORbits, sizeXor );
+    GlobalUnlock( handle );
+    return handle;
+}
+
+
+/***********************************************************************
+ *           CopyIcon    (USER.368)
+ */
+HICON CopyIcon( HANDLE hInstance, HICON hIcon )
+{
+    dprintf_icon( stddeb, "CopyIcon: %04x %04x\n", hInstance, hIcon );
+    return CURSORICON_Copy( hInstance, hIcon );
+}
+
+
+/***********************************************************************
+ *           CopyCursor    (USER.369)
+ */
+HCURSOR CopyCursor( HANDLE hInstance, HCURSOR hCursor )
+{
+    dprintf_cursor( stddeb, "CopyCursor: %04x %04x\n", hInstance, hCursor );
+    return CURSORICON_Copy( hInstance, hCursor );
+}
+
+
+/***********************************************************************
+ *           DestroyIcon    (USER.457)
+ */
+BOOL DestroyIcon( HICON hIcon )
+{
+    dprintf_icon( stddeb, "DestroyIcon: %04x\n", hIcon );
+    return GlobalFree( hIcon );
+}
+
+
+/***********************************************************************
+ *           DestroyCursor    (USER.458)
+ */
+BOOL DestroyCursor( HCURSOR hCursor )
+{
+    dprintf_cursor( stddeb, "DestroyCursor: %04x\n", hCursor );
+    return GlobalFree( hCursor );
+}
+
+
+/***********************************************************************
+ *           DrawIcon    (USER.84)
+ */
+BOOL DrawIcon( HDC hdc, short x, short y, HICON hIcon )
+{
+    CURSORICONINFO *ptr;
+    HDC hMemDC;
+    HBITMAP hXorBits, hAndBits;
+    COLORREF oldFg, oldBg;
+
+    if (!(ptr = (CURSORICONINFO *)GlobalLock( hIcon ))) return FALSE;
+    if (!(hMemDC = CreateCompatibleDC( hdc ))) return FALSE;
+    hAndBits = CreateBitmap( ptr->nWidth, ptr->nHeight, 1, 1, (char *)(ptr+1));
+    hXorBits = CreateBitmap( ptr->nWidth, ptr->nHeight, ptr->bPlanes,
+                             ptr->bBitsPerPixel, (char *)(ptr + 1)
+                              + ptr->nHeight * ((ptr->nWidth + 15) / 16 * 2) );
+    oldFg = SetTextColor( hdc, RGB(0,0,0) );
+    oldBg = SetBkColor( hdc, RGB(255,255,255) );
+
+    if (hXorBits && hAndBits)
+    {
+        HBITMAP hBitTemp = SelectObject( hMemDC, hAndBits );
+        BitBlt( hdc, x, y, ptr->nWidth, ptr->nHeight, hMemDC, 0, 0, SRCAND );
+        SelectObject( hMemDC, hXorBits );
+        BitBlt( hdc, x, y, ptr->nWidth, ptr->nHeight, hMemDC, 0, 0, SRCINVERT);
+        SelectObject( hMemDC, hBitTemp );
+    }
+    DeleteDC( hMemDC );
+    if (hXorBits) DeleteObject( hXorBits );
+    if (hAndBits) DeleteObject( hAndBits );
+    GlobalUnlock( hIcon );
+    SetTextColor( hdc, oldFg );
+    SetBkColor( hdc, oldBg );
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           DumpIcon    (USER.459)
+ */
+DWORD DumpIcon( CURSORICONINFO *info, WORD *lpLen,
+                LPSTR *lpXorBits, LPSTR *lpAndBits )
+{
+    int sizeAnd, sizeXor;
+
+    if (!info) return 0;
+    sizeXor = info->nHeight * info->nWidthBytes;
+    sizeAnd = info->nHeight * ((info->nWidth + 15) / 16 * 2);
+    if (lpAndBits) *lpAndBits = (LPSTR)(info + 1);
+    if (lpXorBits) *lpXorBits = (LPSTR)(info + 1) + sizeAnd;
+    if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor;
+    return MAKELONG( sizeXor, sizeXor );
+}
+
+
+/***********************************************************************
+ *           CURSORICON_SetCursor
+ *
+ * Change the X cursor. Helper function for SetCursor() and ShowCursor().
+ */
+static BOOL CURSORICON_SetCursor( HCURSOR hCursor )
+{
+    Pixmap pixmapBits, pixmapMask, pixmapAll;
+    XColor fg, bg;
+    Cursor cursor = None;
+
+    if (!hCursor)  /* Create an empty cursor */
+    {
+        static const char data[] = { 0 };
+
+        bg.red = bg.green = bg.blue = 0x0000;
+        pixmapBits = XCreateBitmapFromData( display, rootWindow, data, 1, 1 );
+        if (pixmapBits)
+        {
+            cursor = XCreatePixmapCursor( display, pixmapBits, pixmapBits,
+                                          &bg, &bg, 0, 0 );
+            XFreePixmap( display, pixmapBits );
+        }
+    }
+    else  /* Create the X cursor from the bits */
+    {
+        CURSORICONINFO *ptr;
+        XImage *image;
+
+        if (!(ptr = (CURSORICONINFO*)GlobalLock( hCursor ))) return FALSE;
+        if (ptr->bPlanes * ptr->bBitsPerPixel != 1)
+        {
+            fprintf( stderr, "Cursor %04x has more than 1 bpp!\n", hCursor );
+            return FALSE;
+        }
+
+        /* Create a pixmap and transfer all the bits to it */
+
+        pixmapAll = XCreatePixmap( display, rootWindow,
+                                   ptr->nWidth, ptr->nHeight * 2, 1 );
+        image = XCreateImage( display, DefaultVisualOfScreen(screen),
+                              1, ZPixmap, 0, (char *)(ptr + 1), ptr->nWidth,
+                              ptr->nHeight * 2, 16, ptr->nWidthBytes);
+        if (image)
+        {
+            extern void _XInitImageFuncPtrs( XImage* );
+            image->byte_order = MSBFirst;
+            image->bitmap_bit_order = MSBFirst;
+            image->bitmap_unit = 16;
+            _XInitImageFuncPtrs(image);
+            if (pixmapAll)
+                CallTo32_LargeStack( XPutImage, 10,
+                                     display, pixmapAll, BITMAP_monoGC, image,
+                                     0, 0, 0, 0, ptr->nWidth, ptr->nHeight*2 );
+            image->data = NULL;
+            XDestroyImage( image );
+        }
+
+        /* Now create the 2 pixmaps for bits and mask */
+
+        pixmapBits = XCreatePixmap( display, rootWindow,
+                                    ptr->nWidth, ptr->nHeight, 1 );
+        pixmapMask = XCreatePixmap( display, rootWindow,
+                                    ptr->nWidth, ptr->nHeight, 1 );
+
+        /* Make sure everything went OK so far */
+
+        if (pixmapBits && pixmapMask && pixmapAll)
+        {
+            /* We have to do some magic here, as cursors are not fully
+             * compatible between Windows and X11. Under X11, there
+             * are only 3 possible color cursor: black, white and
+             * masked. So we map the 4th Windows color (invert the
+             * bits on the screen) to black. This require some boolean
+             * arithmetic:
+             *
+             *   Windows                        X11
+             * Xor    And      Result      Bits     Mask
+             *  0      0     black          0        1
+             *  0      1     no change      X        0
+             *  1      0     white          1        1
+             *  1      1     inverted       0        1  (=black)
+             *
+             * which gives:
+             *  Bits = 'Xor' xor 'And'
+             *  Mask = 'Xor' or not 'And'
+             */
+            XCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
+                       0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
+            XCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
+                       0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
+            XSetFunction( display, BITMAP_monoGC, GXxor );
+            XCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
+                       0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
+            XSetFunction( display, BITMAP_monoGC, GXorReverse );
+            XCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
+                       0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
+            XSetFunction( display, BITMAP_monoGC, GXcopy );
+            fg.red = fg.green = fg.blue = 0xffff;
+            bg.red = bg.green = bg.blue = 0x0000;
+            cursor = XCreatePixmapCursor( display, pixmapBits, pixmapMask,
+                                &fg, &bg, ptr->ptHotSpot.x, ptr->ptHotSpot.y );
+        }
+
+        /* Now free everything */
+
+        if (pixmapAll) XFreePixmap( display, pixmapAll );
+        if (pixmapBits) XFreePixmap( display, pixmapBits );
+        if (pixmapMask) XFreePixmap( display, pixmapMask );
+        GlobalUnlock( hCursor );
+    }
+
+    if (cursor == None) return FALSE;
+    if (CURSORICON_XCursor != None) XFreeCursor( display, CURSORICON_XCursor );
+    CURSORICON_XCursor = cursor;
+
+    if (rootWindow != DefaultRootWindow(display))
+    {
+        /* Set the cursor on the desktop window */
+        XDefineCursor( display, rootWindow, cursor );
+    }
+    else
+    {
+        /* Set the same cursor for all top-level windows */
+        HWND hwnd = GetWindow( GetDesktopWindow(), GW_CHILD );
+        while(hwnd)
+        {
+            Window win = WIN_GetXWindow( hwnd );
+            if (win) XDefineCursor( display, win, cursor );
+            hwnd = GetWindow( hwnd, GW_HWNDNEXT );
+        }
+    }
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           SetCursor    (USER.69)
+ */
+HCURSOR SetCursor( HCURSOR hCursor )
+{
+    HCURSOR hOldCursor;
+
+    if (hCursor == hActiveCursor) return hActiveCursor;  /* No change */
+    dprintf_cursor( stddeb, "SetCursor: %04x\n", hCursor );
+    hOldCursor = hActiveCursor;
+    hActiveCursor = hCursor;
+    /* Change the cursor shape only if it is visible */
+    if (CURSOR_ShowCount >= 0) CURSORICON_SetCursor( hActiveCursor );
+    return hOldCursor;
+}
+
+
+/***********************************************************************
+ *           SetCursorPos    (USER.70)
+ */
+void SetCursorPos( short x, short y )
+{
+    dprintf_cursor( stddeb, "SetCursorPos: x=%d y=%d\n", x, y );
+    XWarpPointer( display, None, rootWindow, 0, 0, 0, 0, x, y );
+}
+
+
+/***********************************************************************
+ *           ShowCursor    (USER.71)
+ */
+int ShowCursor( BOOL bShow )
+{
+    dprintf_cursor( stddeb, "ShowCursor: %d, count=%d\n",
+                    bShow, CURSOR_ShowCount );
+
+    if (bShow)
+    {
+        if (++CURSOR_ShowCount == 0)
+            CURSORICON_SetCursor( hActiveCursor );  /* Show it */
+    }
+    else
+    {
+        if (--CURSOR_ShowCount == -1)
+            CURSORICON_SetCursor( 0 );  /* Hide it */
+    }
+    return CURSOR_ShowCount;
+}
+
+
+/***********************************************************************
+ *           GetCursor    (USER.247)
+ */
+HCURSOR GetCursor(void)
+{
+    return hActiveCursor;
+}
+
+
+/***********************************************************************
+ *           ClipCursor    (USER.16)
+ */
+void ClipCursor( RECT *rect )
+{
+    if (!rect) SetRectEmpty( &CURSOR_ClipRect );
+    else CopyRect( &CURSOR_ClipRect, rect );
+}
+
+
+/***********************************************************************
+ *           GetCursorPos    (USER.17)
+ */
+void GetCursorPos( POINT *pt )
+{
+    Window root, child;
+    int rootX, rootY, childX, childY;
+    unsigned int mousebut;
+
+    if (!pt) return;
+    if (!XQueryPointer( display, rootWindow, &root, &child,
+		        &rootX, &rootY, &childX, &childY, &mousebut ))
+	pt->x = pt->y = 0;
+    else
+    {
+	pt->x = rootX + desktopX;
+	pt->y = rootY + desktopY;
+    }
+    dprintf_cursor(stddeb, "GetCursorPos: ret=%d,%d\n", pt->x, pt->y );
+}
+
+
+/***********************************************************************
+ *           GetClipCursor    (USER.309)
+ */
+void GetClipCursor( RECT *rect )
+{
+    if (rect) CopyRect( rect, &CURSOR_ClipRect );
+}
+
+
+/**********************************************************************
+ *	    GetIconID    (USER.455)
+ */
+WORD GetIconID( HANDLE hResource, DWORD resType )
+{
+    fprintf( stderr, "GetIconId(%04x,%ld): empty stub!\n",
+             hResource, resType );
+    return 0;
+}
+
+
+/**********************************************************************
+ *	    LoadIconHandler    (USER.456)
+ */
+HICON LoadIconHandler( HANDLE hResource, BOOL bNew )
+{
+    fprintf( stderr, "LoadIconHandle(%04x,%d): empty stub!\n",
+             hResource, bNew );
+    return 0;
+}
diff --git a/objects/dc.c b/objects/dc.c
index 5a74ad2..7dbd68e 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -332,7 +332,7 @@
     if (!(handle = GDI_AllocObject( sizeof(DC), DC_MAGIC ))) return 0;
     newdc = (DC *) GDI_HEAP_LIN_ADDR( handle );
 
-    dprintf_dc(stddeb, "GetDCState(%d): returning %d\n", hdc, handle );
+    dprintf_dc(stddeb, "GetDCState("NPFMT"): returning "NPFMT"\n", hdc, handle );
 
     memset( &newdc->u.x, 0, sizeof(newdc->u.x) );
     memcpy( &newdc->w, &dc->w, sizeof(dc->w) );
@@ -365,7 +365,7 @@
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
     if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return;
     if (!dcs->w.flags & DC_SAVED) return;
-    dprintf_dc(stddeb, "SetDCState: %d %d\n", hdc, hdcs );
+    dprintf_dc(stddeb, "SetDCState: "NPFMT" "NPFMT"\n", hdc, hdcs );
 
       /* Save the regions before overwriting everything */
     hVisRgn    = dc->w.hVisRgn;
@@ -409,7 +409,7 @@
     dcs = (DC *) GDI_HEAP_LIN_ADDR( hdcs );
     dcs->header.hNext = dc->header.hNext;
     dc->header.hNext = hdcs;
-    dprintf_dc(stddeb, "SaveDC(%d): returning %d\n", hdc, dc->saveLevel+1 );
+    dprintf_dc(stddeb, "SaveDC("NPFMT"): returning %d\n", hdc, dc->saveLevel+1 );
     return ++dc->saveLevel;
 }
 
@@ -421,7 +421,7 @@
 {
     DC * dc, * dcs;
 
-    dprintf_dc(stddeb, "RestoreDC: %d %d\n", hdc, level );
+    dprintf_dc(stddeb, "RestoreDC: "NPFMT" %d\n", hdc, level );
     dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) 
     {
@@ -458,7 +458,7 @@
     if (!handle) return 0;
     dc = (DC *) GDI_HEAP_LIN_ADDR( handle );
 
-    dprintf_dc(stddeb, "CreateDC(%s %s %s): returning %d\n", 
+    dprintf_dc(stddeb, "CreateDC(%s %s %s): returning "NPFMT"\n",
 	    driver, device, output, handle );
 
     if (!displayDevCaps)
@@ -514,7 +514,7 @@
     if (!handle) return 0;
     dc = (DC *) GDI_HEAP_LIN_ADDR( handle );
 
-    dprintf_dc(stddeb, "CreateCompatibleDC(%d): returning %d\n", hdc, handle );
+    dprintf_dc(stddeb, "CreateCompatibleDC("NPFMT"): returning "NPFMT"\n", hdc, handle );
 
       /* Create default bitmap */
     if (!(hbitmap = CreateBitmap( 1, 1, 1, 1, NULL )))
@@ -558,7 +558,7 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
 
-    dprintf_dc(stddeb, "DeleteDC: %d\n", hdc );
+    dprintf_dc(stddeb, "DeleteDC: "NPFMT"\n", hdc );
 
     while (dc->saveLevel)
     {
@@ -588,6 +588,16 @@
 
 
 /***********************************************************************
+ *           ResetDC    (GDI.376)
+ */
+HDC ResetDC( HDC hdc, /* DEVMODE */ void *devmode )
+{
+    fprintf( stderr, "ResetDC: empty stub!\n" );
+    return hdc;
+}
+
+
+/***********************************************************************
  *           GetDeviceCaps    (GDI.80)
  */
 int GetDeviceCaps( HDC hdc, WORD cap )
@@ -597,7 +607,7 @@
 
     if (cap > sizeof(DeviceCaps)-sizeof(WORD)) return 0;
     
-    dprintf_dc(stddeb, "GetDeviceCaps(%d,%d): returning %d\n",
+    dprintf_dc(stddeb, "GetDeviceCaps("NPFMT",%d): returning %d\n",
 	    hdc, cap, *(WORD *)(((char *)dc->w.devCaps) + cap) );
     return *(WORD *)(((char *)dc->w.devCaps) + cap);
 }
diff --git a/objects/dib.c b/objects/dib.c
index c976180..1082b74 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -12,7 +12,6 @@
 #include "bitmap.h"
 #include "callback.h"
 #include "palette.h"
-#include "icon.h"
 #include "stackframe.h"
 #include "stddebug.h"
 #include "color.h"
@@ -51,14 +50,23 @@
  */
 int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse )
 {
-    int size = info->bmiHeader.biClrUsed;
-    if (!size && (info->bmiHeader.biBitCount != 24))
-	size = 1 << info->bmiHeader.biBitCount;
-    if (coloruse == DIB_RGB_COLORS) 
-	size = info->bmiHeader.biSize + size * sizeof(RGBQUAD);
-    else
-	size = info->bmiHeader.biSize + size * sizeof(WORD);
-    return size;
+    int colors;
+
+    if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
+    {
+        BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)info;
+        colors = (core->bcBitCount != 24) ? 1 << core->bcBitCount : 0;
+        return sizeof(BITMAPCOREHEADER) + colors *
+             ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
+    }
+    else  /* assume BITMAPINFOHEADER */
+    {
+        colors = info->bmiHeader.biClrUsed;
+        if (!colors && (info->bmiHeader.biBitCount != 24))
+            colors = 1 << info->bmiHeader.biBitCount;
+        return sizeof(BITMAPINFOHEADER) + colors *
+               ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
+    }
 }
 
 
@@ -86,6 +94,103 @@
 
 
 /***********************************************************************
+ *           DIB_GetBitmapInfo
+ *
+ * Get the info from a bitmap header.
+ * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
+ */
+static int DIB_GetBitmapInfo( BITMAPINFOHEADER *header, DWORD *width,
+                              DWORD *height, WORD *bpp )
+{
+    if (header->biSize == sizeof(BITMAPINFOHEADER))
+    {
+        *width  = header->biWidth;
+        *height = header->biHeight;
+        *bpp    = header->biBitCount;
+        return 1;
+    }
+    if (header->biSize == sizeof(BITMAPCOREHEADER))
+    {
+        BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)header;
+        *width  = core->bcWidth;
+        *height = core->bcHeight;
+        *bpp    = core->bcBitCount;
+        return 0;
+    }
+    fprintf( stderr, "DIB_GetBitmapInfo: wrong size (%ld) for header\n",
+             header->biSize );
+    return -1;
+}
+
+
+/***********************************************************************
+ *           DIB_BuildColorMap
+ *
+ * Build the color map from the bitmap palette. Should not be called
+ * for a 24-bit deep bitmap.
+ */
+static int *DIB_BuildColorMap( DC *dc, WORD coloruse, WORD depth,
+                               BITMAPINFO *info )
+{
+    int i, colors;
+    BOOL isInfo;
+    WORD *colorPtr;
+    int *colorMapping;
+
+    if ((isInfo = (info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))))
+    {
+        colors = info->bmiHeader.biClrUsed;
+        if (!colors) colors = 1 << info->bmiHeader.biBitCount;
+        colorPtr = (WORD *)info->bmiColors;
+    }
+    else  /* assume BITMAPCOREINFO */
+    {
+        colors = 1 << ((BITMAPCOREHEADER *)&info->bmiHeader)->bcBitCount;
+        colorPtr = (WORD *)((BITMAPCOREINFO *)info)->bmciColors;
+    }
+    if (!(colorMapping = (int *)malloc( colors * sizeof(int) ))) return NULL;
+
+    if (coloruse == DIB_RGB_COLORS)
+    {
+        if (isInfo)
+        {
+            RGBQUAD * rgb = (RGBQUAD *)colorPtr;
+        
+            if (depth == 1)  /* Monochrome */
+                for (i = 0; i < colors; i++, rgb++)
+                    colorMapping[i] = (rgb->rgbRed + rgb->rgbGreen + 
+                                       rgb->rgbBlue > 255*3/2);
+            else
+                for (i = 0; i < colors; i++, rgb++)
+                    colorMapping[i] = COLOR_ToPhysical( dc, RGB(rgb->rgbRed,
+                                                                rgb->rgbGreen,
+                                                                rgb->rgbBlue));
+        }
+        else
+        {
+            RGBTRIPLE * rgb = (RGBTRIPLE *)colorPtr;
+        
+            if (depth == 1)  /* Monochrome */
+                for (i = 0; i < colors; i++, rgb++)
+                    colorMapping[i] = (rgb->rgbtRed + rgb->rgbtGreen + 
+                                       rgb->rgbtBlue > 255*3/2);
+            else
+                for (i = 0; i < colors; i++, rgb++)
+                    colorMapping[i] = COLOR_ToPhysical( dc, RGB(rgb->rgbtRed,
+                                                               rgb->rgbtGreen,
+                                                               rgb->rgbtBlue));
+        }
+    }
+    else  /* DIB_PAL_COLORS */
+    {
+        for (i = 0; i < colors; i++, colorPtr++)
+            colorMapping[i] = COLOR_ToPhysical( dc, PALETTEINDEX(*colorPtr) );
+    }
+    return colorMapping;
+}
+
+
+/***********************************************************************
  *           DIB_SetImageBits_1
  *
  * SetDIBits for a 1-bit deep DIB.
@@ -454,68 +559,48 @@
  * Helper function for SetDIBits() and SetDIBitsToDevice().
  */
 static int DIB_SetImageBits( DC *dc, WORD lines, WORD depth, LPSTR bits,
-			     BITMAPINFO *info, WORD coloruse,
+                             DWORD infoWidth, WORD infoBpp, DWORD compression,
+                             BITMAPINFO *info, WORD coloruse,
 			     Drawable drawable, GC gc, int xSrc, int ySrc,
 			     int xDest, int yDest, int width, int height )
 {
     int *colorMapping;
     XImage *bmpImage;
-    int i, colors;
 
       /* Build the color mapping table */
 
-    if (info->bmiHeader.biBitCount == 24) colorMapping = NULL;
+    if (infoBpp == 24) colorMapping = NULL;
     else
-    {
-	colors = info->bmiHeader.biClrUsed;
-	if (!colors) colors = 1 << info->bmiHeader.biBitCount;
-	if (!(colorMapping = (int *)malloc( colors * sizeof(int) )))
-	    return 0;
-	if (coloruse == DIB_RGB_COLORS)
-	{
-	    RGBQUAD * rgbPtr = info->bmiColors;
-            for (i = 0; i < colors; i++, rgbPtr++)
-                colorMapping[i] = COLOR_ToPhysical( dc, RGB(rgbPtr->rgbRed,
-							    rgbPtr->rgbGreen,
-							    rgbPtr->rgbBlue) );
-	}
-	else
-	{
-	    WORD * index = (WORD *)info->bmiColors;
-	    for (i = 0; i < colors; i++, index++)
-		colorMapping[i] = COLOR_ToPhysical( dc, PALETTEINDEX(*index) );
-	}
-    }
+        if (!(colorMapping = DIB_BuildColorMap( dc, coloruse, depth, info )))
+            return 0;
 
       /* Transfer the pixels */
-    XCREATEIMAGE(bmpImage, info->bmiHeader.biWidth, lines, depth );
+    XCREATEIMAGE(bmpImage, infoWidth, lines, depth );
 
-    switch(info->bmiHeader.biBitCount)
+    switch(infoBpp)
     {
     case 1:
-	DIB_SetImageBits_1( lines, bits, info->bmiHeader.biWidth,
+	DIB_SetImageBits_1( lines, bits, infoWidth,
 			    colorMapping, bmpImage );
 	break;
     case 4:
-	if (info->bmiHeader.biCompression)
-		DIB_SetImageBits_RLE4( lines, bits, info->bmiHeader.biWidth,
-			    colorMapping, bmpImage );
-	else	
-		DIB_SetImageBits_4( lines, bits, info->bmiHeader.biWidth,
-			    colorMapping, bmpImage );
+	if (compression) DIB_SetImageBits_RLE4( lines, bits, infoWidth,
+                                                colorMapping, bmpImage );
+	else DIB_SetImageBits_4( lines, bits, infoWidth,
+                                 colorMapping, bmpImage );
 	break;
     case 8:
-	if (info->bmiHeader.biCompression)
-		DIB_SetImageBits_RLE8( lines, bits, info->bmiHeader.biWidth,
-			    colorMapping, bmpImage );
-	else
-		DIB_SetImageBits_8( lines, bits, info->bmiHeader.biWidth,
-			    colorMapping, bmpImage );
+	if (compression) DIB_SetImageBits_RLE8( lines, bits, infoWidth,
+                                                colorMapping, bmpImage );
+	else DIB_SetImageBits_8( lines, bits, infoWidth,
+                                 colorMapping, bmpImage );
 	break;
     case 24:
-	DIB_SetImageBits_24( lines, bits, info->bmiHeader.biWidth,
-			     dc, bmpImage );
+	DIB_SetImageBits_24( lines, bits, infoWidth, dc, bmpImage );
 	break;
+    default:
+        fprintf( stderr, "Invalid depth %d for SetDIBits!\n", infoBpp );
+        break;
     }
     if (colorMapping) free(colorMapping);
     XPutImage( display, drawable, gc, bmpImage, xSrc, ySrc,
@@ -548,6 +633,7 @@
     return wSrcHeight;
 }
 
+
 /***********************************************************************
  *           SetDIBits    (GDI.440)
  */
@@ -556,21 +642,26 @@
 {
     DC * dc;
     BITMAPOBJ * bmp;
+    DWORD width, height, compression = 0;
+    WORD bpp;
 
       /* Check parameters */
 
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
     if (!(bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
 	return 0;
-    if (!lines || (startscan >= (WORD)info->bmiHeader.biHeight)) return 0;
-    if (startscan+lines > info->bmiHeader.biHeight)
-	lines = info->bmiHeader.biHeight - startscan;
+    if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, &bpp ) == -1)
+        return 0;
+    if (info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
+        compression = info->bmiHeader.biCompression;
+    if (!lines || (startscan >= (WORD)height)) return 0;
+    if (startscan + lines > height) lines = height - startscan;
 
-    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 14,
+    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 17,
                                 dc, lines, bmp->bitmap.bmBitsPixel,
-                                bits, info, coloruse, bmp->pixmap,
-                                BITMAP_GC(bmp), 0, 0, 0, startscan,
-                                bmp->bitmap.bmWidth, lines );
+                                bits, width, bpp, compression, info,
+                                coloruse, bmp->pixmap, BITMAP_GC(bmp), 0, 0, 0,
+                                startscan, bmp->bitmap.bmWidth, lines );
 }
 
 
@@ -582,25 +673,31 @@
 		       LPSTR bits, BITMAPINFO * info, WORD coloruse )
 {
     DC * dc;
+    DWORD width, height, compression = 0;
+    WORD bpp;
 
       /* Check parameters */
 
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
-    if (!lines || (startscan >= info->bmiHeader.biHeight)) return 0;
-    if (startscan+lines > info->bmiHeader.biHeight)
-	lines = info->bmiHeader.biHeight - startscan;
+    if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, &bpp ) == -1)
+        return 0;
+    if (info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
+        compression = info->bmiHeader.biCompression;
+    if (!lines || (startscan >= height)) return 0;
+    if (startscan + lines > height) lines = height - startscan;
     if (ySrc < startscan) ySrc = startscan;
-    else if (ySrc >= startscan+lines) return 0;
-    if (xSrc >= info->bmiHeader.biWidth) return 0;
-    if (ySrc+cy >= startscan+lines) cy = startscan + lines - ySrc;
-    if (xSrc+cx >= info->bmiHeader.biWidth) cx = info->bmiHeader.biWidth-xSrc;
+    else if (ySrc >= startscan + lines) return 0;
+    if (xSrc >= width) return 0;
+    if (ySrc + cy >= startscan + lines) cy = startscan + lines - ySrc;
+    if (xSrc + cx >= width) cx = width - xSrc;
     if (!cx || !cy) return 0;
 
     DC_SetupGCForText( dc );  /* To have the correct colors */
     XSetFunction( display, dc->u.x.gc, DC_XROPfunction[dc->w.ROPmode-1] );
-    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 14,
-                                dc, lines, dc->w.bitsPerPixel, bits, info,
-                                coloruse, dc->u.x.drawable, dc->u.x.gc,
+    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 17,
+                                dc, lines, dc->w.bitsPerPixel, bits, width,
+                                bpp, compression, info, coloruse,
+                                dc->u.x.drawable, dc->u.x.gc,
                                 xSrc, ySrc - startscan,
                                 dc->w.DCOrgX + XLPTODP( dc, xDest ),
                                 dc->w.DCOrgY + YLPTODP( dc, yDest ),
@@ -679,65 +776,61 @@
 		        LPSTR bits, BITMAPINFO * data, WORD coloruse )
 {
     HBITMAP handle;
-    
-	if(header->biSize!=sizeof(BITMAPINFOHEADER))
-	{
-		fprintf(stderr,"CreateDIBitmap: wrong size (%ld) for header\n",
-			header->biSize);
-		return 0;
-	}
-    handle = CreateCompatibleBitmap( hdc, header->biWidth, header->biHeight );
-/*    handle = CreateBitmap( header->biWidth, header->biHeight,
-                           1, header->biBitCount, NULL );
-*/
+    BOOL fColor;
+    DWORD width, height;
+    WORD bpp;
+
+    if (DIB_GetBitmapInfo( header, &width, &height, &bpp ) == -1) return 0;
+
+    /* Check if we should create a monochrome or color bitmap. */
+    /* We create a monochrome bitmap only if it has exactly 2  */
+    /* colors, which are either black or white, nothing else.  */
+    /* In all other cases, we create a color bitmap.           */
+
+    if (bpp != 1) fColor = TRUE;
+    else if ((coloruse != DIB_RGB_COLORS) ||
+             (init != CBM_INIT) || !data) fColor = FALSE;
+    else
+    {
+        if (data->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
+        {
+            RGBQUAD *rgb = data->bmiColors;
+            DWORD col = RGB( rgb->rgbRed, rgb->rgbGreen, rgb->rgbBlue );
+            if ((col == RGB(0,0,0)) || (col == RGB(0xff,0xff,0xff)))
+            {
+                rgb++;
+                col = RGB( rgb->rgbRed, rgb->rgbGreen, rgb->rgbBlue );
+                fColor = ((col != RGB(0,0,0)) && (col != RGB(0xff,0xff,0xff)));
+            }
+            else fColor = TRUE;
+        }
+        else if (data->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
+        {
+            RGBTRIPLE *rgb = ((BITMAPCOREINFO *)data)->bmciColors;
+            DWORD col = RGB( rgb->rgbtRed, rgb->rgbtGreen, rgb->rgbtBlue );
+            if ((col == RGB(0,0,0)) || (col == RGB(0xff,0xff,0xff)))
+            {
+                rgb++;
+                col = RGB( rgb->rgbtRed, rgb->rgbtGreen, rgb->rgbtBlue );
+                fColor = ((col != RGB(0,0,0)) && (col != RGB(0xff,0xff,0xff)));
+            }
+            else fColor = TRUE;
+        }
+        else
+        {
+            fprintf( stderr, "CreateDIBitmap: wrong size (%ld) for data\n",
+                     data->bmiHeader.biSize );
+            return 0;
+        }
+    }
+
+    /* Now create the bitmap */
+
+    handle = fColor ? CreateCompatibleBitmap( hdc, width, height ) :
+                      CreateBitmap( width, height, 1, 1, NULL );
     if (!handle) return 0;
-    if (init == CBM_INIT) SetDIBits( hdc, handle, 0, header->biHeight,
-				    bits, data, coloruse );
+
+    if (init == CBM_INIT)
+        SetDIBits( hdc, handle, 0, height, bits, data, coloruse );
     return handle;
 }
-
-/***********************************************************************
- *           DrawIcon    (USER.84)
- */
-BOOL DrawIcon(HDC hDC, short x, short y, HICON hIcon)
-{
-    ICONALLOC	*lpico;
-    BITMAP	bm;
-    HBITMAP	hBitTemp;
-    HDC		hMemDC;
-    COLORREF    oldFg, oldBg;
-
-    oldFg = SetTextColor( hDC, RGB(0,0,0) );
-    oldBg = SetBkColor( hDC, RGB(255,255,255) );
-    dprintf_icon(stddeb,"DrawIcon(%04X, %d, %d, %04X) \n", hDC, x, y, hIcon);
-    if (hIcon == (HICON)NULL) return FALSE;
-    lpico = (ICONALLOC *)GlobalLock(hIcon);
-    GetObject(lpico->hBitmap, sizeof(BITMAP), (LPSTR)&bm);
-    hMemDC = CreateCompatibleDC(hDC);
-    if (lpico->hBitMask)
-    {
-        hBitTemp = SelectObject(hMemDC, lpico->hBitMask);
-        BitBlt(hDC, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCAND);
-        SelectObject(hMemDC, lpico->hBitmap);
-        BitBlt(hDC, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCINVERT);
-    }
-    else  /* no mask -> everything is masked; so use SRCCOPY as it's faster */
-    {
-        hBitTemp = SelectObject(hMemDC, lpico->hBitmap);
-        BitBlt(hDC, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
-    }
-    SelectObject( hMemDC, hBitTemp );
-    DeleteDC(hMemDC);
-    GlobalUnlock( hIcon );
-    SetTextColor( hDC, oldFg );
-    SetBkColor( hDC, oldBg );
-    return TRUE;
-}
-/***********************************************************************
- *           CopyIcon    (USER.368)
- */
-BOOL CopyIcon(HANDLE handle, HICON hIcon)
-{
-    printf("STUB !!! CopyIcon: %x %x\n",handle,hIcon);
-    return TRUE;
-}
diff --git a/objects/font.c b/objects/font.c
index bbeb634..b1a89a8 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -265,7 +265,7 @@
 DWORD GetGlyphOutLine(HDC hdc, UINT uChar, UINT fuFormat, LPGLYPHMETRICS lpgm, 
                       DWORD cbBuffer, LPSTR lpBuffer, LPMAT2 lpmat2) 
 {
-    fprintf( stdnimp,"GetGlyphOutLine(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
+    fprintf( stdnimp,"GetGlyphOutLine("NPFMT", '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
              hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
     return (DWORD)-1; /* failure */
 }
@@ -298,7 +298,7 @@
     fontPtr = (FONTOBJ *) GDI_HEAP_LIN_ADDR( hfont );
     memcpy( &fontPtr->logfont, font, sizeof(LOGFONT) );
     AnsiLower( fontPtr->logfont.lfFaceName );
-    dprintf_font(stddeb,"CreateFontIndirect(%p); return %04x\n",font,hfont);
+    dprintf_font(stddeb,"CreateFontIndirect(%p); return "NPFMT"\n",font,hfont);
     return hfont;
 }
 
@@ -339,7 +339,7 @@
     X_PHYSFONT * stockPtr;
     HFONT prevHandle = dc->w.hFont;
     XFontStruct * fontStruct;
-    dprintf_font(stddeb,"FONT_SelectObject(%p, %04x, %p)\n", 
+    dprintf_font(stddeb,"FONT_SelectObject(%p, "NPFMT", %p)\n", 
 		     dc, hfont, font);
       /* Load font if necessary */
 
@@ -354,10 +354,14 @@
     }
 
     if (dc->header.wMagic == METAFILE_DC_MAGIC)
-	return MF_CreateFontIndirect(dc, hfont, &(font->logfont));
+      if (MF_CreateFontIndirect(dc, hfont, &(font->logfont)))
+	return prevHandle;
+      else
+	return 0;
 
+      /*  Must be DWORD for WINELIB32 support  */
     if ((hfont >= FIRST_STOCK_FONT) && (hfont <= LAST_STOCK_FONT))
-	stockPtr = &stockFonts[hfont - FIRST_STOCK_FONT];
+	stockPtr = &stockFonts[(DWORD)hfont - (DWORD)FIRST_STOCK_FONT];
     else 
 	stockPtr = NULL;
     
@@ -368,7 +372,7 @@
               /* If it is not a stock font, we can simply return 0 */
             if (!stockPtr) return 0;
               /* Otherwise we must try to find a substitute */
-            dprintf_font(stddeb,"Loading font 'fixed' for %x\n", hfont );
+            dprintf_font(stddeb,"Loading font 'fixed' for "NPFMT"\n", hfont );
             font->logfont.lfPitchAndFamily &= ~VARIABLE_PITCH;
             font->logfont.lfPitchAndFamily |= FIXED_PITCH;
             fontStruct = XLoadQueryFont( display, "fixed" );
@@ -383,7 +387,7 @@
     {
 	fontStruct = stockPtr->fstruct;
 	dprintf_font(stddeb,
-                     "FONT_SelectObject: Loaded font from cache %x %p\n",
+                     "FONT_SelectObject: Loaded font from cache "NPFMT" %p\n",
 		     hfont, fontStruct );
     }	
 
@@ -514,7 +518,7 @@
     size->cy = abs((dc->u.x.font.fstruct->ascent+dc->u.x.font.fstruct->descent)
 		    * dc->w.WndExtY / dc->w.VportExtY);
 
-    dprintf_font(stddeb,"GetTextExtentPoint(%d '%*.*s' %d %p): returning %d,%d\n",
+    dprintf_font(stddeb,"GetTextExtentPoint("NPFMT" '%*.*s' %d %p): returning %d,%d\n",
 	    hdc, count, count, str, count, size, size->cx, size->cy );
     return TRUE;
 }
@@ -551,7 +555,7 @@
  */
 DWORD SetMapperFlags(HDC hDC, DWORD dwFlag)
 {
-    dprintf_font(stdnimp,"SetmapperFlags(%04X, %08lX) // Empty Stub !\n", 
+    dprintf_font(stdnimp,"SetmapperFlags("NPFMT", %08lX) // Empty Stub !\n", 
 		 hDC, dwFlag); 
     return 0L;
 }
@@ -597,7 +601,7 @@
 /***********************************************************************
  *           AddFontResource    (GDI.119)
  */
-int AddFontResource( LPSTR str )
+INT AddFontResource( LPCSTR str )
 {
     fprintf( stdnimp, "STUB: AddFontResource('%s')\n", str );
     return 1;
@@ -740,7 +744,7 @@
   int          nRet = 0;
   int          i;
   
-  dprintf_font(stddeb,"EnumFonts(%04X, %p='%s', %08lx, %p)\n", 
+  dprintf_font(stddeb,"EnumFonts("NPFMT", %p='%s', %08lx, %p)\n", 
 	       hDC, lpFaceName, lpFaceName, (LONG)lpEnumFunc, lpData);
   if (lpEnumFunc == 0) return 0;
   hLog = GDI_HEAP_ALLOC( sizeof(LOGFONT) + LF_FACESIZE );
@@ -810,8 +814,8 @@
   int	       	nRet = 0;
   int	       	i;
   
-  dprintf_font(stddeb,"EnumFontFamilies(%04X, %p, %08lx, %p)\n",
-	       hDC, lpszFamily, lpEnumFunc, lpData);
+  dprintf_font(stddeb,"EnumFontFamilies("NPFMT", %p, %08lx, %p)\n",
+	       hDC, lpszFamily, (DWORD)lpEnumFunc, lpData);
   if (lpEnumFunc == 0) return 0;
   hLog = GDI_HEAP_ALLOC( sizeof(ENUMLOGFONT) );
   lpEnumLogFont = (LPENUMLOGFONT) GDI_HEAP_LIN_ADDR(hLog);
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index af7cccc..b2434125 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -208,7 +208,7 @@
 		if (*lphObj == 0) {
 			*lphObj = hNewObj;
 			*(lphObj + 1) = 0;
-			dprintf_gdi(stddeb,"GDI_AppendToPenBrushList(%04X) appended (count=%d)\n", hNewObj, i);
+			dprintf_gdi(stddeb,"GDI_AppendToPenBrushList("NPFMT") appended (count=%d)\n", hNewObj, i);
 			return TRUE;
 		}
 		lphObj++;
@@ -245,7 +245,8 @@
     GDIOBJHDR * object;
 
       /* Can't free stock objects */
-    if (handle >= FIRST_STOCK_HANDLE) return TRUE;
+    if ((DWORD)handle >= FIRST_STOCK_HANDLE &&
+	(DWORD)handle <= LAST_STOCK_HANDLE   ) return TRUE;
     
     object = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
     if (!object) return FALSE;
@@ -267,12 +268,11 @@
 {
     GDIOBJHDR * ptr = NULL;
 
-    if (handle >= FIRST_STOCK_HANDLE)
-    {
-	if (handle < FIRST_STOCK_HANDLE + NB_STOCK_OBJECTS)
-	    ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
-    }
-    else ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+    if ((DWORD)handle >= FIRST_STOCK_HANDLE &&
+	(DWORD)handle <= LAST_STOCK_HANDLE   )
+      ptr = StockObjects[(DWORD)handle - FIRST_STOCK_HANDLE];
+    else 
+      ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
     if (!ptr) return NULL;
     if (ptr->wMagic != magic) return NULL;
     return ptr;
@@ -289,7 +289,7 @@
     GDIOBJHDR * header = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( obj );
     if (!header) return FALSE;
 
-    dprintf_gdi(stddeb, "DeleteObject: %d\n", obj );
+    dprintf_gdi(stddeb, "DeleteObject: "NPFMT"\n", obj );
 
       /* Delete object */
 
@@ -313,9 +313,9 @@
 {
     if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
     if (!StockObjects[obj]) return 0;
-    dprintf_gdi(stddeb, "GetStockObject: returning %04x\n", 
-		FIRST_STOCK_HANDLE + obj );
-    return FIRST_STOCK_HANDLE + obj;
+    dprintf_gdi(stddeb, "GetStockObject: returning %ld\n",
+		(DWORD)FIRST_STOCK_HANDLE + obj );
+    return (HANDLE)((DWORD)FIRST_STOCK_HANDLE + obj);
 }
 
 
@@ -325,15 +325,14 @@
 int GetObject( HANDLE handle, int count, LPSTR buffer )
 {
     GDIOBJHDR * ptr = NULL;
-    dprintf_gdi(stddeb, "GetObject: %04x %d %p\n", handle, count, buffer );
+    dprintf_gdi(stddeb, "GetObject: "NPFMT" %d %p\n", handle, count, buffer );
     if (!count) return 0;
 
-    if (handle >= FIRST_STOCK_HANDLE)
-    {
-	if (handle < FIRST_STOCK_HANDLE + NB_STOCK_OBJECTS)
-	    ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
-    }
-    else ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+    if ((DWORD)handle >= FIRST_STOCK_HANDLE &&
+	(DWORD)handle <= LAST_STOCK_HANDLE   )
+      ptr = StockObjects[(DWORD)handle - FIRST_STOCK_HANDLE];
+    else
+      ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
     if (!ptr) return 0;
     
     switch(ptr->wMagic)
@@ -361,13 +360,12 @@
     GDIOBJHDR * ptr = NULL;
     DC * dc;
     
-    dprintf_gdi(stddeb, "SelectObject: %d %04x\n", hdc, handle );
-    if (handle >= FIRST_STOCK_HANDLE)
-    {
-	if (handle < FIRST_STOCK_HANDLE + NB_STOCK_OBJECTS)
-	    ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
-    }
-    else ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+    dprintf_gdi(stddeb, "SelectObject: "NPFMT" "NPFMT"\n", hdc, handle );
+    if ((DWORD)handle >= FIRST_STOCK_HANDLE &&
+	(DWORD)handle <= LAST_STOCK_HANDLE   )
+      ptr = StockObjects[(DWORD)handle - FIRST_STOCK_HANDLE];
+    else 
+      ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
     if (!ptr) return 0;
     
     dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -388,7 +386,7 @@
       case FONT_MAGIC:
 	  return FONT_SelectObject( dc, handle, (FONTOBJ *)ptr );	  
       case REGION_MAGIC:
-	  return SelectClipRgn( hdc, handle );
+	  return (HANDLE)SelectClipRgn( hdc, handle );
     }
     return 0;
 }
@@ -399,7 +397,7 @@
  */
 BOOL UnrealizeObject( HANDLE handle )
 {
-    dprintf_gdi(stdnimp, "UnrealizeObject: %04x\n", handle );
+    dprintf_gdi(stdnimp, "UnrealizeObject: "NPFMT"\n", handle );
     return TRUE;
 }
 
@@ -425,7 +423,7 @@
   switch (nObjType) {
    case OBJ_PEN:
     wMagic = PEN_MAGIC;
-    dprintf_gdi(stddeb,"EnumObjects(%04X, OBJ_PEN, %08lx, %p);\n",
+    dprintf_gdi(stddeb,"EnumObjects("NPFMT", OBJ_PEN, %08lx, %p);\n",
 		hDC, (LONG)lpEnumFunc, lpData);
     hLog = GDI_HEAP_ALLOC( sizeof(LOGPEN) );
     lpLog = (LPSTR) GDI_HEAP_LIN_ADDR(hLog);
@@ -436,7 +434,7 @@
     break;
    case OBJ_BRUSH:
     wMagic = BRUSH_MAGIC;
-    dprintf_gdi(stddeb,"EnumObjects(%04X, OBJ_BRUSH, %08lx, %p);\n",
+    dprintf_gdi(stddeb,"EnumObjects("NPFMT", OBJ_BRUSH, %08lx, %p);\n",
 		hDC, (LONG)lpEnumFunc, lpData);
     hLog = GDI_HEAP_ALLOC( sizeof(LOGBRUSH) );
     lpLog = (LPSTR) GDI_HEAP_LIN_ADDR(hLog);
@@ -446,7 +444,7 @@
     }
     break;
    default:
-    fprintf(stderr,"EnumObjects(%04X, %04X, %08lx, %p); // Unknown OBJ type !\n", 
+    fprintf(stderr,"EnumObjects("NPFMT", %04X, %08lx, %p); // Unknown OBJ type !\n", 
 	    hDC, nObjType, (LONG)lpEnumFunc, lpData);
     return 0;
   }
@@ -484,7 +482,7 @@
   
   if (lpPenBrushList == NULL) return 0;
   for (lphObj = lpPenBrushList; *lphObj != 0; ) {
-    dprintf_gdi(stddeb,"EnumObjects // *lphObj=%04X\n", *lphObj);
+    dprintf_gdi(stddeb,"EnumObjects // *lphObj="NPFMT"\n", *lphObj);
     header = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR(*lphObj++);
     if (header->wMagic == wMagic) {
       dprintf_gdi(stddeb,"EnumObjects // DC_Obj lpLog=%p lpData=%p\n", lpLog, lpData);
@@ -492,7 +490,7 @@
 	BRUSH_GetObject( (BRUSHOBJ *)header, sizeof(LOGBRUSH), lpLog);
 	dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbStyle=%04X\n", ((LPLOGBRUSH)lpLog)->lbStyle);
 	dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbColor=%08lX\n", ((LPLOGBRUSH)lpLog)->lbColor);
-	dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbHatch=%04X\n", ((LPLOGBRUSH)lpLog)->lbHatch);
+	dprintf_gdi(stddeb,"EnumObjects // DC_Brush lbHatch=%04lX\n", (LONG)((LPLOGBRUSH)lpLog)->lbHatch);
       }
       if (header->wMagic == PEN_MAGIC) {
 	PEN_GetObject( (PENOBJ *)header, sizeof(LOGPEN), lpLog);
diff --git a/objects/metafile.c b/objects/metafile.c
index 846964e..9628e99 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -759,7 +759,7 @@
     switch (logbrush->lbStyle)
     {
     case BS_PATTERN:
-	bmp = (BITMAPOBJ *)GDI_GetObjPtr(logbrush->lbHatch, BITMAP_MAGIC);
+	bmp = (BITMAPOBJ *)GDI_GetObjPtr((HANDLE)logbrush->lbHatch, BITMAP_MAGIC);
 	if (!bmp) return FALSE;
 	len = sizeof(METARECORD) + sizeof(BITMAPINFOHEADER) + 
 	      (bmp->bitmap.bmHeight * bmp->bitmap.bmWidthBytes) + 6;
@@ -783,7 +783,7 @@
 	break;
 
     case BS_DIBPATTERN:
-	info = (BITMAPINFO *)GlobalLock(logbrush->lbHatch);
+	info = (BITMAPINFO *)GlobalLock((HANDLE)logbrush->lbHatch);
 	bmSize = info->bmiHeader.biSizeImage;
 	if (!bmSize)
 	    bmSize = (info->bmiHeader.biWidth * info->bmiHeader.biBitCount 
diff --git a/objects/oembitmap.c b/objects/oembitmap.c
index ecd40b4..c850994 100644
--- a/objects/oembitmap.c
+++ b/objects/oembitmap.c
@@ -6,6 +6,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/xpm.h>
@@ -13,7 +14,7 @@
 #include "bitmap.h"
 #include "callback.h"
 #include "color.h"
-#include "icon.h"
+#include "cursoricon.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -154,6 +155,51 @@
 };
 
 
+  /* Include OEM cursors */
+#include "bitmaps/ocr_normal"
+#include "bitmaps/ocr_ibeam"
+#include "bitmaps/ocr_wait"
+#include "bitmaps/ocr_cross"
+#include "bitmaps/ocr_up"
+#include "bitmaps/ocr_size"
+#include "bitmaps/ocr_icon"
+#include "bitmaps/ocr_sizenwse"
+#include "bitmaps/ocr_sizenesw"
+#include "bitmaps/ocr_sizewe"
+#include "bitmaps/ocr_sizens"
+#if 0
+#include "bitmaps/ocr_sizeall"
+#include "bitmaps/ocr_icocur"
+#endif
+
+/* Cursor are not all contiguous (go figure...) */
+#define OCR_FIRST1 OCR_NORMAL
+#define OCR_LAST1  OCR_UP
+#define OCR_FIRST2 OCR_SIZE
+#define OCR_LAST2  OCR_SIZENS  /* OCR_ICOCUR */
+#define NB_CURSORS (OCR_LAST2 - OCR_FIRST2 + 1 + OCR_LAST1 - OCR_FIRST1 + 1)
+static char **OBM_Cursors_Data[NB_CURSORS] = 
+{
+    ocr_normal,    /* OCR_NORMAL */
+    ocr_ibeam,     /* OCR_IBEAM */
+    ocr_wait,      /* OCR_WAIT */
+    ocr_cross,     /* OCR_CROSS */
+    ocr_up,        /* OCR_UP */
+    ocr_size,      /* OCR_SIZE */
+    ocr_icon,      /* OCR_ICON */
+    ocr_sizenwse,  /* OCR_SIZENWSE */
+    ocr_sizenesw,  /* OCR_SIZENESW */
+    ocr_sizewe,    /* OCR_SIZEWE */
+    ocr_sizens     /* OCR_SIZENS */
+#if 0
+    ocr_sizeall,   /* OCR_SIZEALL */
+    ocr_icocur     /* OCR_ICOCUR */
+#endif
+};
+
+static HCURSOR OBM_Cursors[NB_CURSORS] = { 0, };
+
+
   /* All the colors used in the xpm files must be included in this   */
   /* list, to make sure that the loaded bitmaps only use colors from */
   /* the Windows colormap. Note: the PALETTEINDEX() are not really   */
@@ -166,7 +212,6 @@
     COLORREF color;
 } OBM_SymbolicColors[] =
 {
-      /* Black & white must always be the first 2 colors */
     { "black",            RGB(0,0,0) },
     { "white",            RGB(255,255,255) },
     { "red",              RGB(255,0,0) },
@@ -190,6 +235,16 @@
 #define NB_COLOR_SYMBOLS \
             (sizeof(OBM_SymbolicColors)/sizeof(OBM_SymbolicColors[0]))
 
+  /* These are the symbolic colors for monochrome bitmaps   */
+  /* This is needed to make sure that black is always 0 and */
+  /* white always 1, as required by Windows.                */
+
+static XpmColorSymbol OBM_BlackAndWhite[2] =
+{
+    { "black", NULL, 0 },
+    { "white", NULL, 0xffffffff }
+};
+
 static XpmColorSymbol *OBM_Colors = NULL;
 
 
@@ -243,7 +298,7 @@
     bmpObjPtr->bitmap.bmType       = 0;
     bmpObjPtr->bitmap.bmWidth      = width;
     bmpObjPtr->bitmap.bmHeight     = height;
-    bmpObjPtr->bitmap.bmWidthBytes = (width + 15) / 16 * 2;
+    bmpObjPtr->bitmap.bmWidthBytes = (width * bpp + 15) / 16 * 2;
     bmpObjPtr->bitmap.bmPlanes     = 1;
     bmpObjPtr->bitmap.bmBitsPixel  = bpp;
     bmpObjPtr->bitmap.bmBits       = NULL;
@@ -257,22 +312,28 @@
  * Create the 2 bitmaps from XPM data.
  */
 static BOOL OBM_CreateBitmaps( char **data, BOOL color, BOOL mask,
-                               HBITMAP *hBitmap, HBITMAP *hBitmapMask )
+                               HBITMAP *hBitmap, HBITMAP *hBitmapMask,
+                               POINT *hotspot )
 {
     Pixmap pixmap, pixmask;
     XpmAttributes attrs;
     int err;
 
-    attrs.valuemask    = XpmColormap | XpmDepth | XpmColorSymbols;
+    attrs.valuemask    = XpmColormap | XpmDepth | XpmColorSymbols | XpmHotspot;
     attrs.colormap     = COLOR_WinColormap;
     attrs.depth        = color ? screenDepth : 1;
-    attrs.colorsymbols = OBM_Colors;
+    attrs.colorsymbols = (attrs.depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
     attrs.numsymbols   = (attrs.depth > 1) ? NB_COLOR_SYMBOLS : 2;
         
     err = XpmCreatePixmapFromData( display, rootWindow, data,
                                    &pixmap, &pixmask, &attrs );
 
     if (err != XpmSuccess) return FALSE;
+    if (hotspot)
+    {
+        hotspot->x = attrs.x_hotspot;
+        hotspot->y = attrs.y_hotspot;
+    }
     *hBitmap = OBM_MakeBitmap( attrs.width, attrs.height,
                                attrs.depth, pixmap );
     if (mask) *hBitmapMask = OBM_MakeBitmap( attrs.width, attrs.height,
@@ -301,10 +362,10 @@
 
     if (!OBM_InitColorSymbols()) return 0;
     
-    if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 5,
+    if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 6,
                               OBM_Pixmaps_Data[id].data,
                               OBM_Pixmaps_Data[id].color,
-                              FALSE, &hbitmap, &hbitmask ))
+                              FALSE, &hbitmap, &hbitmask, NULL, NULL ))
     {
         fprintf( stderr, "Error creating OEM bitmap %d\n", OBM_FIRST+id );
         return 0;
@@ -314,60 +375,95 @@
 
 
 /***********************************************************************
- *           OBM_LoadIcon
+ *           OBM_LoadCursorIcon
  */
-HICON OBM_LoadIcon( WORD id )
+HANDLE OBM_LoadCursorIcon( WORD id, BOOL fCursor )
 {
-    HICON hicon;
-    ICONALLOC *pIcon;
-    BITMAPOBJ *bmp;
+    HANDLE handle;
+    CURSORICONINFO *pInfo;
+    BITMAPOBJ *bmpXor, *bmpAnd;
+    HBITMAP hXorBits, hAndBits;
+    POINT hotspot;
+    int sizeXor, sizeAnd;
 
-    if ((id < OIC_FIRST) || (id > OIC_LAST)) return 0;
-    id -= OIC_FIRST;
+    if (fCursor)
+    {
+        if ((id >= OCR_FIRST1) && (id <= OCR_LAST1))
+            id -= OCR_FIRST1;
+        else if ((id >= OCR_FIRST2) && (id <= OCR_LAST2))
+            id += (OCR_LAST1 - OCR_FIRST1 + 1) - OCR_FIRST2;
+        else return 0;
+        if (OBM_Cursors[id]) return OBM_Cursors[id];
+    }
+    else
+    {
+        if ((id < OIC_FIRST) || (id > OIC_LAST)) return 0;
+        id -= OIC_FIRST;
+    }
 
     if (!OBM_InitColorSymbols()) return 0;
     
-    if (!(hicon = GlobalAlloc( GMEM_MOVEABLE, sizeof(ICONALLOC) ))) return 0;
-    pIcon = (ICONALLOC *)GlobalLock( hicon );
-
-    if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 5,
-                              OBM_Icons_Data[id], TRUE, TRUE,
-                              &pIcon->hBitmap, &pIcon->hBitMask ))
+    if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 6,
+                           fCursor ? OBM_Cursors_Data[id] : OBM_Icons_Data[id],
+                           !fCursor, TRUE, &hXorBits, &hAndBits, &hotspot ))
     {
-        fprintf( stderr, "Error creating OEM icon %d\n", OIC_FIRST+id );
-        GlobalFree( hicon );
+        fprintf( stderr, "Error creating OEM cursor/icon %d\n", id );
         return 0;
     }
 
-    bmp = (BITMAPOBJ *) GDI_GetObjPtr( pIcon->hBitmap, BITMAP_MAGIC );
-    pIcon->descriptor.Width = bmp->bitmap.bmWidth;
-    pIcon->descriptor.Height = bmp->bitmap.bmHeight;
-    pIcon->descriptor.ColorCount = bmp->bitmap.bmBitsPixel;
+    bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( hXorBits, BITMAP_MAGIC );
+    bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( hAndBits, BITMAP_MAGIC );
+    sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes;
+    sizeAnd = bmpXor->bitmap.bmHeight * ((bmpXor->bitmap.bmWidth+15) / 16 * 2);
 
-    if (pIcon->hBitMask)
+    if (!(handle = GlobalAlloc( GMEM_MOVEABLE,
+                                sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
     {
-        BITMAPOBJ *bmpMask;
+        DeleteObject( hXorBits );
+        DeleteObject( hAndBits );
+        return 0;
+    }
 
+    pInfo = (CURSORICONINFO *)GlobalLock( handle );
+    pInfo->ptHotSpot.x   = hotspot.x;
+    pInfo->ptHotSpot.y   = hotspot.y;
+    pInfo->nWidth        = bmpXor->bitmap.bmWidth;
+    pInfo->nHeight       = bmpXor->bitmap.bmHeight;
+    pInfo->nWidthBytes   = bmpXor->bitmap.bmWidthBytes;
+    pInfo->bPlanes       = bmpXor->bitmap.bmPlanes;
+    pInfo->bBitsPerPixel = bmpXor->bitmap.bmBitsPixel;
+
+    if (hAndBits)
+    {
           /* Invert the mask */
-        bmpMask = (BITMAPOBJ *) GDI_GetObjPtr( pIcon->hBitMask, BITMAP_MAGIC );
+
         XSetFunction( display, BITMAP_monoGC, GXinvert );
-        XFillRectangle( display, bmpMask->pixmap, BITMAP_monoGC, 0, 0,
-                        bmpMask->bitmap.bmWidth, bmpMask->bitmap.bmHeight );
+        XFillRectangle( display, bmpAnd->pixmap, BITMAP_monoGC, 0, 0,
+                        bmpAnd->bitmap.bmWidth, bmpAnd->bitmap.bmHeight );
+        XSetFunction( display, BITMAP_monoGC, GXcopy );
 
           /* Set the masked pixels to black */
-        if (bmp->bitmap.bmBitsPixel != 1)
+
+        if (bmpXor->bitmap.bmBitsPixel != 1)
         {
             XSetForeground( display, BITMAP_colorGC,
                             COLOR_ToPhysical( NULL, RGB(0,0,0) ));
             XSetBackground( display, BITMAP_colorGC, 0 );
             XSetFunction( display, BITMAP_colorGC, GXor );
-            XCopyPlane( display, bmpMask->pixmap, bmp->pixmap, BITMAP_colorGC,
-                        0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
-                        0, 0, 1 );
+            XCopyPlane(display, bmpAnd->pixmap, bmpXor->pixmap, BITMAP_colorGC,
+                       0, 0, bmpXor->bitmap.bmWidth, bmpXor->bitmap.bmHeight,
+                       0, 0, 1 );
             XSetFunction( display, BITMAP_colorGC, GXcopy );
         }
-        XSetFunction( display, BITMAP_monoGC, GXcopy );
     }
 
-    return hicon;
+    if (hAndBits) GetBitmapBits( hAndBits, sizeAnd, (char *)(pInfo + 1) );
+    else memset( (char *)(pInfo + 1), 0xff, sizeAnd );
+    GetBitmapBits( hXorBits, sizeXor, (char *)(pInfo + 1) + sizeAnd );
+
+    DeleteObject( hXorBits );
+    DeleteObject( hAndBits );
+
+    if (fCursor) OBM_Cursors[id] = handle;
+    return handle;
 }
diff --git a/objects/palette.c b/objects/palette.c
index dd925ce..7fa2cfe 100644
--- a/objects/palette.c
+++ b/objects/palette.c
@@ -80,6 +80,14 @@
     return count;
 }
 
+/***********************************************************************
+ *           ResizePalette          (GDI.368)
+ */
+BOOL ResizePalette(HPALETTE hPal, UINT cEntries)
+{
+ fprintf(stdnimp,"ResizePalette: empty stub! \n");
+ return FALSE;
+}
 
 /***********************************************************************
  *           SetSystemPaletteUse    (GDI.373)
@@ -90,7 +98,7 @@
 WORD SetSystemPaletteUse( HDC hdc, WORD use)
 {
 	 WORD old=SystemPaletteUse;
-	 printf("SetSystemPaletteUse(%04X,%04X) // empty stub !!!\n", hdc, use);
+	 printf("SetSystemPaletteUse("NPFMT",%04X) // empty stub !!!\n", hdc, use);
 	 SystemPaletteUse=use;
 	 return old;
 }
@@ -100,7 +108,7 @@
  */
 WORD GetSystemPaletteUse( HDC hdc )
 {
-	printf("GetSystemPaletteUse(%04X) // empty stub !!!\n", hdc);
+	printf("GetSystemPaletteUse("NPFMT") // empty stub !!!\n", hdc);
 	return SystemPaletteUse;
 }
 
@@ -175,7 +183,7 @@
 	}
 	entry++;
     }
-    dprintf_palette(stddeb,"GetNearestPaletteIndex(%x,%06lx): returning %d\n", 
+    dprintf_palette(stddeb,"GetNearestPaletteIndex("NPFMT",%06lx): returning %d\n", 
 	     hpalette, color, index );
     return index;
 }
@@ -200,7 +208,7 @@
     HPALETTE prev;
     DC *dc;
 
-    dprintf_palette(stddeb, "GDISelectPalette: %d %d\n", hdc, hpal );
+    dprintf_palette(stddeb, "GDISelectPalette: "NPFMT" "NPFMT"\n", hdc, hpal );
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
     prev = dc->w.hPalette;
     dc->w.hPalette = hpal;
@@ -215,7 +223,7 @@
  */
 UINT GDIRealizePalette( HDC hdc )
 {
-    dprintf_palette(stdnimp, "GDIRealizePalette: %d\n", hdc );
+    dprintf_palette(stdnimp, "GDIRealizePalette: "NPFMT"\n", hdc );
     return 0;
 }
 
diff --git a/objects/pen.c b/objects/pen.c
index 131667a..adf02e6 100644
--- a/objects/pen.c
+++ b/objects/pen.c
@@ -61,7 +61,10 @@
     HPEN prevHandle = dc->w.hPen;
 
     if (dc->header.wMagic == METAFILE_DC_MAGIC)
-	return MF_CreatePenIndirect(dc, hpen, &(pen->logpen));
+      if (MF_CreatePenIndirect(dc, hpen, &(pen->logpen)))
+	return prevHandle;
+      else
+	return 0;
 
     dc->w.hPen = hpen;
 
diff --git a/objects/region.c b/objects/region.c
index 02a10d7..5be23ff 100644
--- a/objects/region.c
+++ b/objects/region.c
@@ -19,7 +19,7 @@
  */
 BOOL REGION_DeleteObject( HRGN hrgn, RGNOBJ * obj )
 {
-    dprintf_region(stddeb, "DeleteRegion: %x\n", hrgn );
+    dprintf_region(stddeb, "DeleteRegion: "NPFMT"\n", hrgn );
     if (obj->xrgn) XDestroyRegion( obj->xrgn );
     return GDI_FreeObject( hrgn );
 }
@@ -32,7 +32,7 @@
 {
     RGNOBJ * obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC );
     if (!obj) return ERROR;
-    dprintf_region(stddeb, "OffsetRgn: %d %d,%d\n", hrgn, x, y );
+    dprintf_region(stddeb, "OffsetRgn: "NPFMT" %d,%d\n", hrgn, x, y );
     if (!obj->xrgn) return NULLREGION;
     XOffsetRegion( obj->xrgn, x, y );
     return COMPLEXREGION;
@@ -46,7 +46,7 @@
 {
     RGNOBJ * obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC );
     if (!obj) return ERROR;
-    dprintf_region(stddeb, "GetRgnBox: %d\n", hrgn );
+    dprintf_region(stddeb, "GetRgnBox: "NPFMT"\n", hrgn );
     if (!obj->xrgn)
     {
         SetRectEmpty( rect );
@@ -84,7 +84,7 @@
         XUnionRectWithRegion( &rect, obj->xrgn, obj->xrgn );
     }
     else obj->xrgn = 0;
-    dprintf_region( stddeb, "CreateRectRgn(%d,%d-%d,%d): returning %x\n",
+    dprintf_region( stddeb, "CreateRectRgn(%d,%d-%d,%d): returning "NPFMT"\n",
                     left, top, right, bottom, hrgn );
     return hrgn;
 }
@@ -106,7 +106,7 @@
 {
     RGNOBJ * obj;
 
-    dprintf_region(stddeb, "SetRectRgn: %x %d,%d-%d,%d\n", 
+    dprintf_region(stddeb, "SetRectRgn: "NPFMT" %d,%d-%d,%d\n", 
 		   hrgn, left, top, right, bottom );
     
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC ))) return;
@@ -143,7 +143,7 @@
     if (!(hrgn = GDI_AllocObject( sizeof(RGNOBJ), REGION_MAGIC ))) return 0;
     obj = (RGNOBJ *) GDI_HEAP_LIN_ADDR( hrgn );
     obj->xrgn = XCreateRegion();
-    dprintf_region(stddeb,"CreateRoundRectRgn(%d,%d-%d,%d %dx%d): return=%x\n",
+    dprintf_region(stddeb,"CreateRoundRectRgn(%d,%d-%d,%d %dx%d): return="NPFMT"\n",
                left, top, right, bottom, ellipse_width, ellipse_height, hrgn );
 
       /* Check parameters */
@@ -276,7 +276,7 @@
     }
     obj = (RGNOBJ *) GDI_HEAP_LIN_ADDR( hrgn );
     obj->xrgn = 0;
-    dprintf_region(stddeb, "CreatePolyPolygonRgn: %d polygons, returning %x\n",
+    dprintf_region(stddeb, "CreatePolyPolygonRgn: %d polygons, returning "NPFMT"\n",
                    nbpolygons, hrgn );
 
       /* Create X region */
@@ -406,7 +406,7 @@
 {
     RGNOBJ *destObj, *src1Obj, *src2Obj;
     
-    dprintf_region(stddeb, "CombineRgn: %x,%x -> %x mode=%x\n", 
+    dprintf_region(stddeb, "CombineRgn: "NPFMT","NPFMT" -> "NPFMT" mode=%x\n", 
 		   hSrc1, hSrc2, hDest, mode );
     
     if (!(destObj = (RGNOBJ *) GDI_GetObjPtr( hDest, REGION_MAGIC )))
diff --git a/objects/text.c b/objects/text.c
index 1ee64d0..fd94b10 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -571,7 +571,7 @@
 LONG TabbedTextOut( HDC hdc, short x, short y, LPSTR lpstr, short count, 
                     short cTabStops, LPINT lpTabPos, short nTabOrg )
 {
-    dprintf_text( stddeb, "TabbedTextOut: %x %d,%d '%*.*s' %d\n",
+    dprintf_text( stddeb, "TabbedTextOut: "NPFMT" %d,%d '%*.*s' %d\n",
                   hdc, x, y, count, count, lpstr, count );
     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
                                lpTabPos, nTabOrg, TRUE );
@@ -584,7 +584,7 @@
 DWORD GetTabbedTextExtent( HDC hdc, LPSTR lpstr, int count, 
                           int cTabStops, LPINT lpTabPos )
 {
-    dprintf_text( stddeb, "GetTabbedTextExtent: %x '%*.*s' %d\n",
+    dprintf_text( stddeb, "GetTabbedTextExtent: "NPFMT" '%*.*s' %d\n",
                   hdc, count, count, lpstr, count );
     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
                                lpTabPos, 0, FALSE );
diff --git a/rc/Imakefile b/rc/Imakefile
deleted file mode 100644
index 571cb8f..0000000
--- a/rc/Imakefile
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = rc
-
-.SUFFIXES: .rc
-
-.rc.c:
-	echo "#include \"windows.h\"" >$*.rct
-	echo WINDOWS_H_ENDS_HERE >>$*.rct
-	cat $< >>$*.rct
-	$(CC) -E -x c -P $(CFLAGS) $*.rct | sed -e '1,/^WINDOWS_H_ENDS_HERE/d' | ./winerc -o $* -v -p $*
-	$(RM) $*.rct
-
-XCOMM This would be nicer, but it breaks gcc (2.5.8 on Linux)  --AJ
-XCOMM gcc -E -x c -P $(CFLAGS) -imacros ../include/windows.h $*.rc | ./winerc -o $* -v -p $*
-
-RCSRCS = sysres.rc
-
-RCOBJS = $(RCSRCS:.rc=.o)
-
-WineRelocatableTarget($(MODULE),,$(RCOBJS))
-
-$(RCOBJS): winerc $(TOP)/include/windows.h
-
-includes::
-	touch $(RCSRCS:.rc=.h)
-
-clean::
-	$(RM) $(RCSRCS:.rc=.c) $(RCSRCS:.rc=.h) $(RCSRCS:.rc=.rct)
-
-
-XCOMM Rules to build the winerc program
-
-SRCS = \
-	lex.yy.c \
-	winerc.c \
-	y.tab.c
-
-OBJS = $(SRCS:.c=.o)
-
-#ifdef SunArchitecture
-YACC=bison -y
-LEX=flex
-LOCAL_LIBRARIES = -ly -ll
-#endif
-#if defined(i386BsdArchitecture) || defined(i386FreeBsd) || defined(FreeBSDArchitecture)
-LOCAL_LIBRARIES = -ll
-#endif
-
-NormalProgramTarget(winerc,$(OBJS),$(DEPLIBS),$(LOCAL_LIBRARIES),)
-
-depend:: y.tab.c y.tab.h lex.yy.c
-
-DependTarget()
-
-clean::
-	$(RM) lex.yy.c y.tab.*
-
-y.tab.c y.tab.h: parser.y
-	$(YACC) -d -t parser.y
-
-lex.yy.c: parser.l y.tab.h
-	$(LEX) -8 -I parser.l
- 
-
diff --git a/rc/Makefile.in b/rc/Makefile.in
index aec8d02..0f558c6 100644
--- a/rc/Makefile.in
+++ b/rc/Makefile.in
@@ -4,6 +4,8 @@
 
 C_SRCS = sysres.c
 
+LANGUAGES = En Es De No Fr Fi Da
+
 all: $(MODULE).o
 
 @MAKE_RULES@
@@ -17,7 +19,7 @@
 winerc: lex.yy.o winerc.o y.tab.o
 	$(CC) $(ALLCFLAGS) lex.yy.o winerc.o y.tab.o -o winerc $(LEXLIB)
 
-sysres.rct: sysres.rc sysres_En.rc sysres_Es.rc sysres_De.rc sysres_No.rc
+sysres.rct: sysres.rc $(LANGUAGES:%=sysres_%.rc)
 	echo "#include \"windows.h\"" >sysres.rct
 	echo WINDOWS_H_ENDS_HERE >>sysres.rct
 	cat sysres.rc >>sysres.rct
diff --git a/rc/parser.h b/rc/parser.h
index 5064c60..dc667ba 100644
--- a/rc/parser.h
+++ b/rc/parser.h
@@ -77,6 +77,9 @@
 gen_res* make_dialog(gen_res*,int,int,int,int,gen_res*);
 
 gen_res *hex_to_raw(char*,gen_res*);
+gen_res *int_to_raw(int,gen_res*);
+gen_res *make_font(gen_res*);
+gen_res *make_raw(gen_res*);
 gen_res *make_bitmap(gen_res*);
 gen_res *make_icon(gen_res*);
 gen_res *make_cursor(gen_res*);
diff --git a/rc/parser.y b/rc/parser.y
index d8d7004..121c508 100644
--- a/rc/parser.y
+++ b/rc/parser.y
@@ -204,5 +204,6 @@
 int yyerror(char *s)
 {
 	puts(s);
+	return 0;
 }
 
diff --git a/rc/sysres.rc b/rc/sysres.rc
index 4cd2efd..52e3749 100644
--- a/rc/sysres.rc
+++ b/rc/sysres.rc
@@ -6,6 +6,12 @@
 #include "sysres_No.rc"
 #elif #LANG(Es)
 #include "sysres_Es.rc"
+#elif #LANG(Fr)
+#include "sysres_Fr.rc"
+#elif #LANG(Fi)
+#include "sysres_Fi.rc"
+#elif #LANG(Da)
+#include "sysres_Da.rc"
 #else
 #error LANG not set to an implemented language.
 #endif
diff --git a/rc/sysres_Da.rc b/rc/sysres_Da.rc
new file mode 100644
index 0000000..df9c11f
--- /dev/null
+++ b/rc/sysres_Da.rc
@@ -0,0 +1,200 @@
+SYSMENU MENU LOADONCALL MOVEABLE DISCARDABLE
+{
+ MENUITEM "&Genopret", 61728
+ MENUITEM "&Flyt", 61456
+ MENUITEM "&Størrelse", 61440
+ MENUITEM "Mi&nimer", 61472
+ MENUITEM "Ma&ximer", 61488
+ MENUITEM SEPARATOR
+ MENUITEM "&Luk\tAlt-F4", 61536
+ MENUITEM SEPARATOR
+ MENUITEM "&Skift til ...\tCtrl-Esc", 61744
+ MENUITEM SEPARATOR
+ MENUITEM "&Om WINE ...", 61761
+}
+
+MSGBOX DIALOG 100, 80, 216, 168
+STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+BEGIN
+        ICON "", 1088, 8, 20, 16, 16, WS_CHILD | WS_VISIBLE
+        LTEXT "", 100, 32, 4, 176, 48, WS_CHILD | WS_VISIBLE | WS_GROUP
+        PUSHBUTTON "&Ok", 1, 16, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Annuller", 2, 64, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Afbryd", 3, 112, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Gentag", 4, 160, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Ignorer", 5, 208, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Ja", 6, 256, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Nej", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+END
+
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 200
+STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+CAPTION "Om %s"
+FONT 10, "System"
+{
+ DEFPUSHBUTTON "Ok", 1, 91, 180, 40, 14
+ CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 140
+ LTEXT "Tekst", 100, 11, 40, 200, 130, SS_NOPREFIX | WS_GROUP
+ ICON "", 1088, 195, 10, 18, 20
+}
+
+
+OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Åbn"
+FONT 8, "Helv"
+{
+ LTEXT "&Filnavn:", 1090, 6, 6, 76, 9
+ EDITTEXT 1152, 6, 16, 90, 12, ES_AUTOHSCROLL | ES_OEMCONVERT | WS_BORDER | WS_TABSTOP
+ LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Kataloger:", -1, 110, 6, 92, 9
+ LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
+ LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Oversigt over filer af type:", 1089, 6, 104, 90, 9
+ COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ LTEXT "&Drev:", 1091, 110, 104, 92, 9
+ COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "Å&bn", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Hjælp", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ CHECKBOX "&Skrivebeskyttet", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+SAVE_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Gem som ..."
+FONT 8, "Helv"
+{
+ LTEXT "&Filnavn:", 1090, 6, 6, 76, 9
+ EDITTEXT 1152, 6, 16, 90, 12, ES_AUTOHSCROLL | ES_OEMCONVERT | WS_BORDER | WS_TABSTOP
+ LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Kataloger:", -1, 110, 6, 92, 9
+ LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
+ LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Oversigt over filer af type:", 1089, 6, 104, 90, 9
+ COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ LTEXT "&Drev:", 1091, 110, 104, 92, 9
+ COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "&Gem som", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuller", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Hjælp", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ CHECKBOX "&Skrivebeskyttet", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+PRINT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Udskriv"
+FONT 8, "Helv"
+{
+ LTEXT "Printer:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ GROUPBOX "Udskriv område", 1072, 6, 30, 160, 65, BS_GROUPBOX
+ RADIOBUTTON "&Alt", 1056, 16, 45, 60, 12
+ RADIOBUTTON "&Markeret", 1057, 16, 60, 60, 12
+ RADIOBUTTON "&Sider", 1058, 16, 75, 60, 12
+ DEFPUSHBUTTON "Udskriv", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuller", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Indstilling", 1024, 206, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ LTEXT "&Fra:", 1090, 60, 80, 30, 9
+ LTEXT "&Til:", 1091, 120, 80, 30, 9
+ LTEXT "Udskrifts&kvalitet:", 1092, 6, 100, 76, 9
+ COMBOBOX 1136, 80, 100, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ CHECKBOX "Udskriv til fi&l", 1040, 20, 100, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Sammentrykket", 1041, 160, 100, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+PRINT_SETUP DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Udskriftsindstilling"
+FONT 8, "Helv"
+{
+ GROUPBOX "Printer", 1072, 6, 10, 180, 65, BS_GROUPBOX
+ RADIOBUTTON "&Standardprinter", 1056, 16, 20, 80, 12
+ LTEXT "[none]", 1088, 35, 35, 120, 9
+ RADIOBUTTON "Specifik &printer", 1057, 16, 50, 80, 12
+ COMBOBOX 1136, 35, 65, 149, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "Ok", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuller", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Indstilling", 1024, 206, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ GROUPBOX "Orientering", 1073, 6, 85, 100, 50, BS_GROUPBOX
+ RADIOBUTTON "Po&rtræt", 1058, 50, 100, 40, 12
+ RADIOBUTTON "&Landskab", 1059, 50, 115, 40, 12
+ ICON "LANDSCAP", 1097, 10, 95, 32, 32
+ ICON "PORTRAIT", 1098, 10, 95, 32, 32
+ GROUPBOX "Papir", 1074, 120, 85, 180, 50, BS_GROUPBOX
+ LTEXT "Størrelse", 1089, 130, 95, 30, 9
+ LTEXT "&Kilde", 1090, 130, 110, 30, 9
+ COMBOBOX 1137, 155, 95, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX 1138, 155, 110, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+}
+
+
+CHOOSE_FONT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Skriftsnit"
+FONT 8, "Helv"
+{
+ LTEXT "Skriftsnit:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ DEFPUSHBUTTON "Ok", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuller", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+CHOOSE_COLOR DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 200
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Farve"
+FONT 8, "Helv"
+{
+ LTEXT "&Grundlæggende farver:", 1088, 6, 6, 40, 9
+ LTEXT "&Selvvalgte farver:", 1089, 6, 126, 40, 9
+ LTEXT "&Ensfarvet", 1090, 100, 146, 40, 9
+ LTEXT "&Intensitet:", 1091, 150, 126, 40, 9
+ LTEXT "&Farvemætning:", 1092, 150, 146, 40, 9
+ LTEXT "&Lysstyrke:", 1093, 150, 166, 40, 9
+ LTEXT "&Rød:", 1094, 150, 126, 40, 9
+ LTEXT "&Grøn:", 1095, 150, 146, 40, 9
+ LTEXT "&Blå:", 1096, 150, 166, 40, 9
+ DEFPUSHBUTTON "Ok", 1, 6, 182, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Tilføj til selvvalgte farver", 1024, 120, 182, 100, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Slet selvvalgte farver", 1025, 6, 164, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuller", 2, 76, 182, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+FIND_TEXT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 84
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Find"
+FONT 8, "Helv"
+{
+ LTEXT "&Find hvad:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ CHECKBOX "Kun &hele ord", 1040, 20, 30, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Forskel på store/små &bogstaver", 1041, 20, 50, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ GROUPBOX "Retning", 1072, 90, 40, 80, 40, BS_GROUPBOX
+ RADIOBUTTON "&Op", 1056, 100, 50, 50, 12
+ RADIOBUTTON "&Ned", 1057, 150, 50, 50, 12
+ DEFPUSHBUTTON "&Find næste", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuller", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+REPLACE_TEXT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 114
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Erstat"
+FONT 8, "Helv"
+{
+ LTEXT "&Find hvad:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ LTEXT "&Erstat med:", 1090, 6, 26, 40, 9
+ LTEXT "", 1091, 60, 26, 150, 9
+ CHECKBOX "Kun &hele ord", 1040, 20, 40, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Forskel på store/små &bogstaver", 1041, 20, 60, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ DEFPUSHBUTTON "&Find næste", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Erstat", 1024, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Erstat &alle", 1025, 206, 44, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Afbryd", 2, 206, 64, 56, 14, WS_GROUP | WS_TABSTOP
+}
diff --git a/rc/sysres_Fi.rc b/rc/sysres_Fi.rc
new file mode 100644
index 0000000..9a9f7a2
--- /dev/null
+++ b/rc/sysres_Fi.rc
@@ -0,0 +1,200 @@
+SYSMENU MENU LOADONCALL MOVEABLE DISCARDABLE
+{
+ MENUITEM "&Palauta", 61728
+ MENUITEM "Sii&rrä", 61456
+ MENUITEM "&Muuta kokoa", 61440
+ MENUITEM "P&ienennä", 61472
+ MENUITEM "S&uurenna", 61488
+ MENUITEM SEPARATOR
+ MENUITEM "&Sulje\tAlt+F4", 61536
+ MENUITEM SEPARATOR
+ MENUITEM "&Vaihda...\tCtrl+Esc", 61744
+ MENUITEM SEPARATOR
+ MENUITEM "&Tietoja WINEista...", 61761
+}
+
+MSGBOX DIALOG 100, 80, 216, 168
+STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+BEGIN
+        ICON "", 1088, 8, 20, 16, 16, WS_CHILD | WS_VISIBLE
+        LTEXT "", 100, 32, 4, 176, 48, WS_CHILD | WS_VISIBLE | WS_GROUP
+        PUSHBUTTON "&OK", 1, 16, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Peruuta", 2, 64, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Keskeytä", 3, 112, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Yritä uudelleen", 4, 160, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Hylkää", 5, 208, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Kyllä", 6, 256, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Ei", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+END
+
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 223, 200
+STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+CAPTION "Tietoja: %s"
+FONT 10, "System"
+{
+ DEFPUSHBUTTON "OK", 1, 91, 180, 40, 14
+ CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 215, 140
+ LTEXT "Teksti", 100, 11, 40, 200, 130, SS_NOPREFIX | WS_GROUP
+ ICON "", 1088, 195, 10, 18, 20
+}
+
+
+OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Avaa"
+FONT 8, "Helv"
+{
+ LTEXT "Tiedosto&nimi:", 1090, 6, 6, 76, 9
+ EDITTEXT 1152, 6, 16, 90, 12, ES_AUTOHSCROLL | ES_OEMCONVERT | WS_BORDER | WS_TABSTOP
+ LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Hakemistot:", -1, 110, 6, 92, 9
+ LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
+ LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Luettele tiedostot tyypeittäin:", 1089, 6, 104, 90, 9
+ COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ LTEXT "&Asemat:", 1091, 110, 104, 92, 9
+ COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "Avaa", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Peruuta", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Ohje", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ CHECKBOX "&Vain luku", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+SAVE_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Tallenna nimellä"
+FONT 8, "Helv"
+{
+ LTEXT "Tiedosto&nimi:", 1090, 6, 6, 76, 9
+ EDITTEXT 1152, 6, 16, 90, 12, ES_AUTOHSCROLL | ES_OEMCONVERT | WS_BORDER | WS_TABSTOP
+ LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Hakemistot:", -1, 110, 6, 92, 9
+ LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
+ LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "Tallenna tiedosto &muodossa:", 1089, 6, 104, 90, 9
+ COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ LTEXT "&Asemat:", 1091, 110, 104, 92, 9
+ COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "Tallenna", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Peruuta", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Ohje", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ CHECKBOX "&Vain luku", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+PRINT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Tulosta"
+FONT 8, "Helv"
+{
+ LTEXT "Kirjoitin:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ GROUPBOX "Tulostusalue", 1072, 6, 30, 160, 65, BS_GROUPBOX
+ RADIOBUTTON "&Kaikki", 1056, 16, 45, 60, 12
+ RADIOBUTTON "&Valinta", 1057, 16, 60, 60, 12
+ RADIOBUTTON "&Sivut", 1058, 16, 75, 60, 12
+ DEFPUSHBUTTON "Tulosta", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Peruuta", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Asetukset", 1024, 206, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ LTEXT "&Mistä:", 1090, 60, 80, 30, 9
+ LTEXT "Mi&hin:", 1091, 120, 80, 30, 9
+ LTEXT "&Tulostustarkkuus:", 1092, 6, 100, 76, 9
+ COMBOBOX 1136, 80, 100, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ CHECKBOX "Tulosta t&iedostoon", 1040, 20, 100, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Tiivistetty", 1041, 160, 100, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+PRINT_SETUP DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Kirjoittimen asetukset"
+FONT 8, "Helv"
+{
+ GROUPBOX "Kirjoitin", 1072, 6, 10, 180, 65, BS_GROUPBOX
+ RADIOBUTTON "O&letuskirjoitin", 1056, 16, 20, 80, 12
+ LTEXT "[ei valittu]", 1088, 35, 35, 120, 9
+ RADIOBUTTON "&Erityinen kirjoitin", 1057, 16, 50, 80, 12
+ COMBOBOX 1136, 35, 65, 149, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "OK", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Peruuta", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Asetukset...", 1024, 206, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ GROUPBOX "Suunta", 1073, 6, 85, 100, 50, BS_GROUPBOX
+ RADIOBUTTON "&Pysty", 1058, 50, 100, 40, 12
+ RADIOBUTTON "&Vaaka", 1059, 50, 115, 40, 12
+ ICON "LANDSCAP", 1097, 10, 95, 32, 32
+ ICON "PORTRAIT", 1098, 10, 95, 32, 32
+ GROUPBOX "Paperi", 1074, 120, 85, 180, 50, BS_GROUPBOX
+ LTEXT "&Koko:", 1089, 130, 95, 30, 9
+ LTEXT "Lä&hde:", 1090, 130, 110, 30, 9
+ COMBOBOX 1137, 155, 95, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX 1138, 155, 110, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+}
+
+
+CHOOSE_FONT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Fontit"
+FONT 8, "Helv"
+{
+ LTEXT "Fontti:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ DEFPUSHBUTTON "OK", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Peruuta", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+CHOOSE_COLOR DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 200
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Väri"
+FONT 8, "Helv"
+{
+ LTEXT "Pe&rusvärit:", 1088, 6, 6, 40, 9
+ LTEXT "&Muokatut värit:", 1089, 6, 126, 40, 9
+ LTEXT "Väri|&Tasainen", 1090, 100, 146, 40, 9
+ LTEXT "&Sävy:", 1091, 150, 126, 40, 9
+ LTEXT "&Kyll:", 1092, 150, 146, 40, 9
+ LTEXT "K&irkk:", 1093, 150, 166, 40, 9
+ LTEXT "&Pun:", 1094, 150, 126, 40, 9
+ LTEXT "&Vihr:", 1095, 150, 146, 40, 9
+ LTEXT "Si&n:", 1096, 150, 166, 40, 9
+ DEFPUSHBUTTON "OK", 1, 6, 182, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Lisää väri", 1024, 120, 182, 100, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Pois&ta väri", 1025, 6, 164, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "S&ulje", 2, 76, 182, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+FIND_TEXT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 84
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Etsi"
+FONT 8, "Helv"
+{
+ LTEXT "&Etsittävä:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ CHECKBOX "&Koko sana", 1040, 20, 30, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Kirjaink&oko", 1041, 20, 50, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ GROUPBOX "Suunta", 1072, 90, 40, 80, 40, BS_GROUPBOX
+ RADIOBUTTON "&Ylös", 1056, 100, 50, 50, 12
+ RADIOBUTTON "&Alas", 1057, 150, 50, 50, 12
+ DEFPUSHBUTTON "Etsi &seuraava", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Peruuta", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+REPLACE_TEXT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 114
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Korvaa"
+FONT 8, "Helv"
+{
+ LTEXT "&Etsittävä:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ LTEXT "Ko&rvattava:", 1090, 6, 26, 40, 9
+ LTEXT "", 1091, 60, 26, 150, 9
+ CHECKBOX "&Koko sana", 1040, 20, 40, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Kirjaink&oko", 1041, 20, 60, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ DEFPUSHBUTTON "Etsi &seuraava", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Korv&aa", 1024, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Korvaa ka&ikki", 1025, 206, 44, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "S&ulje", 2, 206, 64, 56, 14, WS_GROUP | WS_TABSTOP
+}
diff --git a/rc/sysres_Fr.rc b/rc/sysres_Fr.rc
new file mode 100644
index 0000000..723ea2d
--- /dev/null
+++ b/rc/sysres_Fr.rc
@@ -0,0 +1,201 @@
+
+SYSMENU MENU LOADONCALL MOVEABLE DISCARDABLE
+{
+ MENUITEM "&Restauration", 61728
+ MENUITEM "&Déplacement", 61456
+ MENUITEM "Di&mension", 61440
+ MENUITEM "Réduct&ion", 61472
+ MENUITEM "&Agrandissement", 61488
+ MENUITEM SEPARATOR
+ MENUITEM "&Fermeture\tAlt-F4", 61536
+ MENUITEM SEPARATOR
+ MENUITEM "&Basculer vers ...\tCtrl-Echap", 61744
+ MENUITEM SEPARATOR
+ MENUITEM "A propos de &Wine ...", 61761
+}
+
+MSGBOX DIALOG 100, 80, 216, 168
+STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+BEGIN
+        ICON "", 1088, 8, 20, 16, 16, WS_CHILD | WS_VISIBLE
+        LTEXT "", 100, 32, 4, 176, 48, WS_CHILD | WS_VISIBLE | WS_GROUP
+        PUSHBUTTON "&Ok", 1, 16, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Annuler", 2, 64, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Annuler", 3, 112, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Répéter", 4, 160, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Ignorer", 5, 208, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Oui", 6, 256, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+        PUSHBUTTON "&Non", 7, 304, 56, 40, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
+END
+
+SHELL_ABOUT_MSGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 50, 44, 213, 179
+STYLE DS_LOCALEDIT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+CAPTION "A propos de %s"
+FONT 10, "System"
+{
+ DEFPUSHBUTTON "OK", 1, 86, 160, 40, 14
+ CONTROL "", -1, "STATIC", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE | WS_DISABLED, 4, 35, 205, 120
+ LTEXT "Text", 100, 11, 40, 190, 110, SS_NOPREFIX | WS_GROUP
+ ICON "", 1088, 185, 10, 18, 20
+}
+
+
+OPEN_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Ouvrir"
+FONT 8, "Helv"
+{
+ LTEXT "&Nom de fichier:", 1090, 6, 6, 76, 9
+ EDITTEXT 1152, 6, 16, 90, 12, ES_AUTOHSCROLL | ES_OEMCONVERT | WS_BORDER | WS_TABSTOP
+ LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Répertoires", -1, 110, 6, 92, 9
+ LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
+ LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "Liste des fichiers de &type:", 1089, 6, 104, 90, 9
+ COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ LTEXT "&Lecteurs:", 1091, 110, 104, 92, 9
+ COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "OK", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Aide", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ CHECKBOX "Lecture seule", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+SAVE_FILE DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 275, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Enregistrer sous ..."
+FONT 8, "Helv"
+{
+ LTEXT "&Nom de fichier:", 1090, 6, 6, 76, 9
+ EDITTEXT 1152, 6, 16, 90, 12, ES_AUTOHSCROLL | ES_OEMCONVERT | WS_BORDER | WS_TABSTOP
+ LISTBOX 1120, 6, 32, 90, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "&Répertoires:", -1, 110, 6, 92, 9
+ LTEXT "", 1088, 110, 18, 92, 9, SS_NOPREFIX | WS_GROUP
+ LISTBOX 1121, 110, 32, 92, 68, LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | WS_TABSTOP
+ LTEXT "Liste des fichiers de &type:", 1089, 6, 104, 90, 9
+ COMBOBOX 1136, 6, 114, 90, 36, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ LTEXT "&Lecteurs:", 1091, 110, 104, 92, 9
+ COMBOBOX 1137, 110, 114, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "OK", 1, 208, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 208, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Aide", 1038, 208, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ CHECKBOX "Lecture seule", 1040, 208, 68, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+PRINT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Imprimer"
+FONT 8, "Helv"
+{
+ LTEXT "Imprimante:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ GROUPBOX "Etendue", 1072, 6, 30, 160, 65, BS_GROUPBOX
+ RADIOBUTTON "&Tout", 1056, 16, 45, 60, 12
+ RADIOBUTTON "&Sélection", 1057, 16, 60, 60, 12
+ RADIOBUTTON "&Pages", 1058, 16, 75, 60, 12
+ DEFPUSHBUTTON "OK", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Configurer...", 1024, 206, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ LTEXT "&De:", 1090, 60, 80, 30, 9
+ LTEXT "&A:", 1091, 120, 80, 30, 9
+ LTEXT "&Qualité d'impression:", 1092, 6, 100, 76, 9
+ COMBOBOX 1136, 80, 100, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ CHECKBOX "&Fichier d'impression", 1040, 20, 100, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Copies t&riées", 1041, 160, 100, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+}
+
+
+PRINT_SETUP DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Configuration de l'impression"
+FONT 8, "Helv"
+{
+ GROUPBOX "Imprimante", 1072, 6, 10, 180, 65, BS_GROUPBOX
+ RADIOBUTTON "&Imprimante par défaut", 1056, 16, 20, 80, 12
+ LTEXT "[aucune]", 1088, 35, 35, 120, 9
+ RADIOBUTTON "Imprimante &spécifique", 1057, 16, 50, 80, 12
+ COMBOBOX 1136, 35, 65, 149, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ DEFPUSHBUTTON "OK", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Options...", 1024, 206, 46, 56, 14, WS_GROUP | WS_TABSTOP
+ GROUPBOX "Orientation", 1073, 6, 85, 100, 50, BS_GROUPBOX
+ RADIOBUTTON "&Portrait", 1058, 50, 100, 40, 12
+ RADIOBUTTON "Paysag&e", 1059, 50, 115, 40, 12
+ ICON "LANDSCAP", 1097, 10, 95, 32, 32
+ ICON "PORTRAIT", 1098, 10, 95, 32, 32
+ GROUPBOX "Papier", 1074, 120, 85, 180, 50, BS_GROUPBOX
+ LTEXT "&Taille :", 1089, 130, 95, 30, 9
+ LTEXT "&Ali&mentation :", 1090, 130, 110, 30, 9
+ COMBOBOX 1137, 155, 95, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX 1138, 155, 110, 92, 68, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP
+}
+
+
+CHOOSE_FONT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 134
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Polices"
+FONT 8, "Helv"
+{
+ LTEXT "&Police:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ DEFPUSHBUTTON "OK", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+CHOOSE_COLOR DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 200
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Couleurs"
+FONT 8, "Helv"
+{
+ LTEXT "Couleurs de &base:", 1088, 6, 6, 40, 9
+ LTEXT "%Couleurs personnalisées:", 1089, 6, 126, 40, 9
+ LTEXT "Couleur|&Uni", 1090, 100, 146, 40, 9
+ LTEXT "&Couleur:", 1091, 150, 126, 40, 9
+ LTEXT "&Sat. :", 1092, 150, 146, 40, 9
+ LTEXT "&Lum. :", 1093, 150, 166, 40, 9
+ LTEXT "&Rouge:", 1094, 150, 126, 40, 9
+ LTEXT "&Vert:", 1095, 150, 146, 40, 9
+ LTEXT "&Bleu:", 1096, 150, 166, 40, 9
+ DEFPUSHBUTTON "OK", 1, 6, 182, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Ajouter la couleur", 1024, 120, 182, 100, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Supprimer la couleur", 1025, 6, 164, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 76, 182, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+FIND_TEXT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 84
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Rechercher"
+FONT 8, "Helv"
+{
+ LTEXT "&Rechercher:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ CHECKBOX "M&ot seulement", 1040, 20, 30, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Respect des &majuscules/minuscules", 1041, 20, 50, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ GROUPBOX "Direction", 1072, 90, 40, 80, 40, BS_GROUPBOX
+ RADIOBUTTON "&Haut", 1056, 100, 50, 50, 12
+ RADIOBUTTON "&Bas", 1057, 150, 50, 50, 12
+ DEFPUSHBUTTON "&Poursuivre", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Annuler", 2, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+}
+
+
+REPLACE_TEXT DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 264, 114
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Remplacer"
+FONT 8, "Helv"
+{
+ LTEXT "&Rechercher:", 1088, 6, 6, 40, 9
+ LTEXT "", 1089, 60, 6, 150, 9
+ LTEXT "R&emplacer par:", 1090, 6, 26, 40, 9
+ LTEXT "", 1091, 60, 26, 150, 9
+ CHECKBOX "M&ot seulement", 1040, 20, 40, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ CHECKBOX "Respect des &majuscules/minuscules", 1041, 20, 60, 50, 12, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
+ DEFPUSHBUTTON "&Poursuivre", 1, 206, 6, 56, 14, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Rempla&cer", 1024, 206, 24, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "Remplacer &tout", 1025, 206, 44, 56, 14, WS_GROUP | WS_TABSTOP
+ PUSHBUTTON "&Fermer", 2, 206, 64, 56, 14, WS_GROUP | WS_TABSTOP
+}
diff --git a/rc/winerc.c b/rc/winerc.c
index 14b0c85..afdd89e 100644
--- a/rc/winerc.c
+++ b/rc/winerc.c
@@ -31,6 +31,9 @@
 FILE *header,*code;
 char hname[256],sname[256];
 
+int transform_binary_file(void);
+int yyparse(void);
+
 int main(int argc,char *argv[])
 {  
 	extern int yydebug;
@@ -88,6 +91,7 @@
 		fprintf(code,"%3d,",c);
 	}
 	fprintf(code,"\n0}\nint _Aplication_resources_size=%d;\n",i);
+	return 0;
 }
 
 /* SunOS' memcpy is wrong for overlapping arrays */
@@ -592,19 +596,22 @@
     fprintf( code, "  0\n};\n" );
 }
 
-void make_font()
+gen_res* make_font(gen_res* res)
 {
 	fprintf(stderr,"Fonts not supported\n");
+	return NULL;
 }
 
-void make_raw()
+gen_res* make_raw(gen_res* res)
 {
 	fprintf(stderr,"RCData not supported\n");
+	return NULL;
 }
 
-void int_to_raw()
+gen_res* int_to_raw(int i,gen_res* res)
 {
 	fprintf(stderr,"IntToRaw not supported\n");
+	return NULL;
 }
 
 /* translate "Hello,\\tworld!\\10" to "Hello,\tworld!\n" */
diff --git a/toolkit/Imakefile b/toolkit/Imakefile
deleted file mode 100644
index 28bf583..0000000
--- a/toolkit/Imakefile
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = toolkit
-
-SRCS = \
-	arch.c \
-	heap.c \
-	sup.c \
-	winmain.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/toolkit/Makefile.in b/toolkit/Makefile.in
index d09cb11..73f8746 100644
--- a/toolkit/Makefile.in
+++ b/toolkit/Makefile.in
@@ -1,14 +1,27 @@
 TOPSRC = @top_srcdir@
+X_LIBS = @X_LIBS@
+XLIB   = @X_PRE_LIBS@ -lXext -lX11 @X_EXTRA_LIBS@
 MODULE = toolkit
 
 C_SRCS = \
+	atom.c \
 	arch.c \
 	heap.c \
+	miscstubs.c \
 	sup.c \
 	winmain.c
 
 all: $(MODULE).o
 
+hello: hello.o ../winelib.a
+	gcc -g -o hello hello.o ../winelib.a -lm $(X_LIBS) -lXpm $(XLIB)
+
+hello2: hello2.o ../winelib.a
+	gcc -g -o hello2 hello2.o ../winelib.a -lm $(X_LIBS) -lXpm $(XLIB)
+
 @MAKE_RULES@
 
+clean::
+	$(RM) hello hello2
+
 ### Dependencies:
diff --git a/toolkit/atom.c b/toolkit/atom.c
new file mode 100644
index 0000000..26ae445
--- /dev/null
+++ b/toolkit/atom.c
@@ -0,0 +1,340 @@
+/*
+ * Atom table functions
+ *
+ * Copyright 1993, 1994, 1995 Alexandre Julliard
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "windows.h"
+
+#ifdef CONFIG_IPC
+#include "dde_atom.h"
+#include "options.h"
+#endif
+
+#define MIN_STR_ATOM              0xc000
+
+typedef struct
+{
+  WORD  refCount;
+  BYTE  length;
+  char* str;
+} ATOMDATA;
+
+typedef struct
+{
+  void* next;
+  ATOMDATA a2h[16];
+} ATOMtoHANDLEtable;
+
+static ATOMtoHANDLEtable* GlobalAtomTable = NULL;
+static ATOMtoHANDLEtable*  LocalAtomTable = NULL;
+
+
+/***********************************************************************
+ *           ATOM_Init
+ *
+ * Global table initialisation.
+ */
+BOOL ATOM_Init(void)
+{
+  return TRUE;
+}
+
+
+/***********************************************************************
+ *           ATOM_AddAtom
+ */
+static ATOM ATOM_AddAtom( ATOMtoHANDLEtable** tableptr, SEGPTR name )
+{
+    ATOMDATA* FirstUnused;
+    ATOM FirstUnusedIndex;
+    ATOM Index;
+    ATOMtoHANDLEtable* table;
+    int i,len;
+    char *str;
+
+    /* Check for integer atom */
+
+    if (!HIWORD(name)) return (ATOM)LOWORD(name);
+    str = (char*)name;
+    if (str[0] == '#') return atoi( &str[1] );
+
+    if ((len = strlen( str )) > 255) len = 255;
+    table = *tableptr;
+    FirstUnused = NULL;
+    FirstUnusedIndex = 0;
+    Index = MIN_STR_ATOM;
+    while (table)
+    {
+      for(i=0; i<16; i++, Index++)
+      {
+	if (!table->a2h[i].refCount)
+	{
+	  FirstUnused=&table->a2h[i];
+	  FirstUnusedIndex=Index;
+	}
+	else if ((table->a2h[i].length == len) && 
+		 (!strncasecmp( table->a2h[i].str, str, len )))
+	{
+	    table->a2h[i].refCount++;
+	    return Index;
+	}
+      }
+      tableptr = (ATOMtoHANDLEtable**)&table->next;
+      table = table->next;
+    }
+    if(!FirstUnused)
+    {
+      *tableptr = malloc(sizeof(ATOMtoHANDLEtable));
+      (*tableptr)->next = NULL;
+      for(i=0; i<16; i++)
+      {
+	(*tableptr)->a2h[i].str = NULL;
+	(*tableptr)->a2h[i].refCount = 0;
+      }
+      FirstUnused = (*tableptr)->a2h;
+      FirstUnusedIndex = Index;
+    }
+    if((FirstUnused->str = malloc(len+1)))
+    {
+      memcpy( FirstUnused->str, str, len );
+      FirstUnused->str[len] = 0;
+    }
+    else
+      return 0;
+    FirstUnused->refCount = 1;
+    FirstUnused->length = len;
+    return FirstUnusedIndex;
+}
+
+
+/***********************************************************************
+ *           ATOM_DeleteAtom
+ */
+static ATOM ATOM_DeleteAtom( ATOMtoHANDLEtable** tableptr, ATOM atom )
+{    
+    ATOMtoHANDLEtable* table;
+    int i;
+    ATOM Index;
+
+    if (atom < MIN_STR_ATOM) return 0;  /* Integer atom */
+
+    Index = MIN_STR_ATOM;
+    table = *tableptr;
+    while (table)
+    {
+      if(atom-Index < 16)
+      {
+	i=atom-Index;
+
+	/* Delete atom */
+	if (--table->a2h[i].refCount == 0)
+	{
+	  free(table->a2h[i].str);
+	  table->a2h[i].str=NULL;
+	}    
+	return 0;
+      }
+      else
+      {
+	Index+=16;
+	table = table->next;
+      }
+    }
+    return atom;
+}
+
+
+/***********************************************************************
+ *           ATOM_FindAtom
+ */
+static ATOM ATOM_FindAtom( ATOMtoHANDLEtable** tableptr, SEGPTR name )
+{
+    ATOM Index;
+    ATOMtoHANDLEtable* table;
+    int i,len;
+    char *str;
+
+    /* Check for integer atom */
+
+    if (!HIWORD(name)) return (ATOM)LOWORD(name);
+    str = (char*)name;
+    if (str[0] == '#') return atoi( &str[1] );
+
+    if ((len = strlen( str )) > 255) len = 255;
+    table=*tableptr;
+    Index=MIN_STR_ATOM;
+    while (table)
+    {
+      for(i=0; i<16; i++, Index++)
+      {
+	if ((table->a2h[i].refCount != 0) &&
+	    (table->a2h[i].length == len) && 
+	    (!strncasecmp( table->a2h[i].str, str, len )))
+	  return Index;
+      }
+      table=table->next;
+    }
+    return 0;
+}
+
+
+/***********************************************************************
+ *           ATOM_GetAtomName
+ */
+static WORD ATOM_GetAtomName( ATOMtoHANDLEtable** tableptr, ATOM atom,
+                              LPSTR buffer, short count )
+{
+    ATOMtoHANDLEtable* table;
+    ATOM Index;
+    char * strPtr=NULL;
+    int i,len=0;
+    char text[8];
+    
+    if (!count) return 0;
+    if (atom < MIN_STR_ATOM)
+    {
+	sprintf( text, "#%d", atom );
+	len = strlen(text);
+	strPtr = text;
+    }
+    else
+    {
+      Index = MIN_STR_ATOM;
+      table = *tableptr;
+      while (table)
+      {
+	if(atom-Index < 16)
+	{
+	  i=atom-Index;
+	  
+	  if (table->a2h[i].refCount == 0)
+	    table=NULL;
+	  else
+	  {
+	    len = table->a2h[i].length;
+	    strPtr = table->a2h[i].str;
+	  }
+	  break;
+	}
+	else
+	{
+	  Index+=16;
+	  table = table->next;
+	}
+      }
+      if(!table)return 0;
+    }
+    if (len >= count) len = count-1;
+    memcpy( buffer, strPtr, len );
+    buffer[len] = '\0';
+    return len;
+}
+
+
+/***********************************************************************
+ *           InitAtomTable   (KERNEL.68)
+ */
+WORD InitAtomTable( WORD entries )
+{
+    return entries;
+}
+
+
+/***********************************************************************
+ *           GetAtomHandle   (KERNEL.73)
+ */
+HANDLE GetAtomHandle( ATOM atom )
+{
+  fprintf(stderr,"JBP: GetAtomHandle() called (obsolete).\n");
+  return 0;
+}
+
+
+/***********************************************************************
+ *           AddAtom   (KERNEL.70)
+ */
+ATOM AddAtom( SEGPTR str )
+{
+    return ATOM_AddAtom( &LocalAtomTable, (SEGPTR)str );
+}
+
+
+/***********************************************************************
+ *           DeleteAtom   (KERNEL.71)
+ */
+ATOM DeleteAtom( ATOM atom )
+{
+    return ATOM_DeleteAtom( &LocalAtomTable, atom );
+}
+
+
+/***********************************************************************
+ *           FindAtom   (KERNEL.69)
+ */
+ATOM FindAtom( SEGPTR str )
+{
+    return ATOM_FindAtom( &LocalAtomTable, str );
+}
+
+
+/***********************************************************************
+ *           GetAtomName   (KERNEL.72)
+ */
+WORD GetAtomName( ATOM atom, LPSTR buffer, short count )
+{
+    return ATOM_GetAtomName( &LocalAtomTable, atom, buffer, count );
+}
+
+
+/***********************************************************************
+ *           GlobalAddAtom   (USER.268)
+ */
+ATOM GlobalAddAtom( SEGPTR str )
+{
+#ifdef CONFIG_IPC
+    if (Options.ipc) return DDE_GlobalAddAtom( str );
+#endif
+    return ATOM_AddAtom( &GlobalAtomTable, str );
+}
+
+
+/***********************************************************************
+ *           GlobalDeleteAtom   (USER.269)
+ */
+ATOM GlobalDeleteAtom( ATOM atom )
+{
+#ifdef CONFIG_IPC
+    if (Options.ipc) return DDE_GlobalDeleteAtom( atom );
+#endif
+    return ATOM_DeleteAtom( &GlobalAtomTable, atom );
+}
+
+
+/***********************************************************************
+ *           GlobalFindAtom   (USER.270)
+ */
+ATOM GlobalFindAtom( SEGPTR str )
+{
+#ifdef CONFIG_IPC
+    if (Options.ipc) return DDE_GlobalFindAtom( str );
+#endif
+    return ATOM_FindAtom( &GlobalAtomTable, str );
+}
+
+
+/***********************************************************************
+ *           GlobalGetAtomName   (USER.271)
+ */
+WORD GlobalGetAtomName( ATOM atom, LPSTR buffer, short count )
+{
+#ifdef CONFIG_IPC
+    if (Options.ipc) return DDE_GlobalGetAtomName( atom, buffer, count );
+#endif
+    return ATOM_GetAtomName( &GlobalAtomTable, atom, buffer, count );
+}
diff --git a/toolkit/heap.c b/toolkit/heap.c
index c1584c7..370f7c6 100644
--- a/toolkit/heap.c
+++ b/toolkit/heap.c
@@ -6,11 +6,14 @@
  * All the memory management is being done by the libc malloc and friends.
  */
 
-#ifndef __STDC__
+/* #ifndef __STDC__ */
 #include <malloc.h>
-#endif
+#include <string.h>
+/* #endif */
 #include "windows.h"
 
+#ifdef WINELIB16
+
 /* Controls the blocks per handle table */
 #define MAXBLOCKS 1024
 
@@ -203,3 +206,111 @@
 }
 
 #endif
+
+#else /* WINELIB16 */
+HANDLE LocalAlloc (WORD flags, WORD bytes)
+{
+    HANDLE m;
+
+    if (flags & LMEM_WINE_ALIGN)
+	m = memalign (4, bytes);
+    else
+	m = malloc (bytes);
+    if (m){
+	if (flags & LMEM_ZEROINIT)
+	    bzero (m, bytes);
+    }
+    return m;
+}
+
+WORD LocalCompact (WORD min_free)
+{
+    return min_free;
+}
+
+WORD LocalFlags (HANDLE hMem)
+{
+    return 0;
+}
+
+HANDLE LocalFree (HANDLE hMem)
+{
+    free(hMem);
+    return 0;
+}
+
+BOOL LocalInit (HANDLE segment, WORD start, WORD end)
+{
+    return TRUE;
+}
+
+LPVOID LocalLock (HANDLE hMem)
+{
+    return hMem;
+}
+
+HANDLE LocalReAlloc (HANDLE hMem, WORD flags, WORD bytes)
+{
+    realloc(hMem, bytes);
+    return hMem;
+}
+
+WORD LocalSize (HANDLE hMem)
+{
+    /* Not implemented yet */
+  return 0;
+}
+
+
+BOOL LocalUnLock (HANDLE hMem)
+{
+    return 0;
+}
+
+HANDLE GlobalAlloc (WORD flags, DWORD size)
+{
+    return LocalAlloc (flags, size);
+}
+
+HANDLE GlobalFree (HANDLE hMem)
+{
+    return LocalFree (hMem);
+}
+
+LPVOID GlobalLock (HGLOBAL hMem)
+{
+    return LocalLock (hMem);
+}
+
+BOOL GlobalUnlock (HANDLE hMem)
+{
+    return LocalUnLock (hMem);
+}
+
+WORD GlobalFlags (HANDLE hMem)
+{
+    return LocalFlags (hMem);
+}
+
+DWORD GlobalSize (HANDLE hMem)
+{
+    return LocalSize (hMem);
+}
+
+DWORD GlobalCompact(DWORD desired)
+{
+    if (desired)
+	return desired;
+    else
+	return 0x01000000;	/* Should check the available core. */
+}
+
+HANDLE GlobalReAlloc(HANDLE hMem, DWORD new_size, WORD flags)
+{
+    if (!(flags & GMEM_MODIFY))
+      return LocalReAlloc (hMem, new_size, flags);
+    else
+      return hMem;
+}
+
+#endif
diff --git a/toolkit/hello.c b/toolkit/hello.c
index 604f18b..4285ac1 100644
--- a/toolkit/hello.c
+++ b/toolkit/hello.c
@@ -5,7 +5,7 @@
     TextOut (dc, x, y, s, strlen (s));
 }
 
-LONG WndProc (HANDLE wnd, UINT msg, WORD w, LONG l)
+LRESULT WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l)
 {
     static short xChar, yChar;
     HDC dc;
@@ -53,7 +53,7 @@
 	class.hCursor    = LoadCursor (0, IDC_ARROW);
 	class.hbrBackground = GetStockObject (WHITE_BRUSH);
 	class.lpszMenuName = NULL;
-	class.lpszClassName = "class";
+	class.lpszClassName = (SEGPTR)"class";
     }
     if (!RegisterClass (&class))
 	return FALSE;
@@ -68,4 +68,5 @@
 	TranslateMessage (&msg);
 	DispatchMessage (&msg);
     }
+    return 0;
 }
diff --git a/toolkit/hello2.c b/toolkit/hello2.c
new file mode 100644
index 0000000..589f131
--- /dev/null
+++ b/toolkit/hello2.c
@@ -0,0 +1,9 @@
+#include "windows.h"
+
+int PASCAL WinMain (HANDLE inst, HANDLE prev, LPSTR cmdline, int show)
+{
+  return MessageBox((HWND)0,
+		    (LPSTR)"Hello, hello!",
+		    (LPSTR)"Hello Wine Application",
+		    (MB_OK | MB_ICONEXCLAMATION));
+}
diff --git a/toolkit/miscstubs.c b/toolkit/miscstubs.c
new file mode 100644
index 0000000..5db9016
--- /dev/null
+++ b/toolkit/miscstubs.c
@@ -0,0 +1,324 @@
+/*
+ * JBP (Jim Peterson <jspeter@birch.ee.vt.edu>): Lots of stubs needed for
+ *      libwine.a.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "dde_mem.h"
+#include "windows.h"
+#include "global.h"
+#include "debug.h"
+
+int CallTo32_LargeStack( int (*func)(), int nbargs, ...)
+{
+  va_list arglist;
+  int i,a[32];
+
+  va_start(arglist,nbargs);
+
+  for(i=0; i<nbargs; i++) a[i]=va_arg(arglist,int);
+
+  switch(nbargs) /* Ewww... Icky.  But what can I do? */
+  {
+  case 5: return func(a[0],a[1],a[2],a[3],a[4]);
+  case 6: return func(a[0],a[1],a[2],a[3],a[4],a[5]);
+  case 8: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
+  case 10: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],
+                a[7],a[8],a[9]);
+  case 11: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],
+                a[7],a[8],a[9],a[10]);
+  case 14: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],
+                a[7],a[8],a[9],a[10],a[11],a[12],a[13]);
+  default: fprintf(stderr,"JBP: CallTo32_LargeStack called with unsupported "
+                          "number of arguments (%d).  Ignored.\n",nbargs);
+           return 0;
+  }
+}
+
+WORD CallTo16_word_ ( FARPROC func, WORD arg ) { return func(arg); }
+
+/* typedef void* ATOM; */
+/* ATOM GlobalAddAtom(char *n) */
+/* { */
+/*   return strdup(n); */
+/* } */
+/* GlobalDeleteAtom(ATOM n) */
+/* { */
+/*   free(n); */
+/* } */
+/* GlobalFindAtom(char*n) */
+/* { */
+/*   fprintf(stderr,"JBP: GlobalFindAtom() ignored.\n"); */
+/*   return 0; */
+/* } */
+/* char *GlobalGetAtomName(ATOM a) */
+/* { */
+/*   return a; */
+/* } */
+
+void GlobalFreeAll(HANDLE owner)
+{
+  fprintf(stderr,"JBP: GlobalFreeAll() ignored.\n");
+}
+
+SEGPTR WIN16_GlobalLock(HGLOBAL h)
+{
+  return (SEGPTR)h;
+}
+
+
+
+#if 0
+typedef WORD* HLOCAL;
+
+int IsValidHLOCAL(HLOCAL handle)
+{
+  return *(handle-1) + *(handle-2) == 0; /* Valid HLOCAL's sum to 0 */
+}
+
+/***********************************************************************
+ *           LOCAL_Free
+ *
+ */
+HLOCAL LOCAL_Free( WORD ds, HLOCAL handle )
+{
+  if (!IsValidHLOCAL(handle)) return handle; /* couldn't free it */
+  free(handle-2);
+  return 0;
+}
+
+
+/***********************************************************************
+ *           LOCAL_Alloc
+ *
+ */
+HLOCAL LOCAL_Alloc( WORD ds, WORD flags, WORD size )
+{
+  HLOCAL handle;
+    
+  handle = malloc(size + 2*sizeof(WORD));
+  handle += 2;
+  *(handle-2) = size;
+  *(handle-1) = -size;
+  return handle;
+}
+
+
+/***********************************************************************
+ *           LOCAL_ReAlloc
+ *
+ */
+HLOCAL LOCAL_ReAlloc( WORD ds, HLOCAL handle, WORD size, WORD flags )
+{
+  HLOCAL newhandle;
+
+  if(!IsValidHLOCAL(handle))return 0;
+  newhandle = realloc(handle-2, size+2*sizeof(WORD));
+  newhandle += 2;
+  *(newhandle-2) = size;
+  *(newhandle-1) = -size;
+  return newhandle;
+}
+
+
+/***********************************************************************
+ *           LOCAL_Lock
+ */
+WORD LOCAL_Lock( WORD ds, HLOCAL handle )
+{
+  if(!IsValidHLOCAL(handle))return 0;
+  return handle;
+}
+
+
+/***********************************************************************
+ *           LOCAL_Unlock
+ */
+BOOL LOCAL_Unlock( WORD ds, HLOCAL handle )
+{
+  return TRUE;
+}
+
+
+/***********************************************************************
+ *           LOCAL_Size
+ *
+ */
+WORD LOCAL_Size( WORD ds, HLOCAL handle )
+{
+  return *(handle-2);
+}
+#endif
+
+HLOCAL LOCAL_Free( WORD ds, HLOCAL handle )
+{
+  fprintf(stderr,"JBP: LOCAL_*() ignored.\n");
+  return 0;
+}
+
+HLOCAL LOCAL_Alloc( WORD ds, WORD flags, WORD size )
+{
+  fprintf(stderr,"JBP: LOCAL_*() ignored.\n");
+  return 0;
+}
+
+HLOCAL LOCAL_ReAlloc( WORD ds, HLOCAL handle, WORD size, WORD flags )
+{
+  fprintf(stderr,"JBP: LOCAL_*() ignored.\n");
+  return 0;
+}
+
+WORD LOCAL_Lock( WORD ds, HLOCAL handle )
+{
+  fprintf(stderr,"JBP: LOCAL_*() ignored.\n");
+  return 0;
+}
+
+BOOL LOCAL_Unlock( WORD ds, HLOCAL handle )
+{
+  fprintf(stderr,"JBP: LOCAL_*() ignored.\n");
+  return 1;
+}
+
+WORD LOCAL_Size( WORD ds, HLOCAL handle )
+{
+  fprintf(stderr,"JBP: LOCAL_*() ignored.\n");
+  return 0;
+}
+
+void FarSetOwner(HANDLE a, WORD b)
+{
+  fprintf(stderr,"JBP: FarSetOwner() ignored.\n");
+}
+
+#define GLOBAL_MAX_ALLOC_SIZE 0x00ff0000  /* Largest allocation is 16M - 64K */
+
+HGLOBAL GLOBAL_Alloc( WORD flags, DWORD size, HGLOBAL hOwner,
+                      BOOL isCode, BOOL is32Bit, BOOL isReadOnly )
+{
+    void *ptr;
+    HGLOBAL handle;
+    SHMDATA shmdata;
+
+    dprintf_global( stddeb, "GLOBAL_Alloc: %ld flags=%04x\n", size, flags );
+
+      /* Fixup the size */
+
+    if (size >= GLOBAL_MAX_ALLOC_SIZE - 0x1f) return 0;
+    if (size == 0) size = 0x20;
+    else size = (size + 0x1f) & ~0x1f;
+
+      /* Allocate the linear memory */
+
+#ifdef CONFIG_IPC
+    if ((flags & GMEM_DDESHARE) && Options.ipc)
+        ptr = DDE_malloc(flags, size, &shmdata);
+    else 
+#endif  /* CONFIG_IPC */
+	ptr = malloc( size );
+    if (!ptr) return 0;
+
+      /* Allocate the selector(s) */
+
+    handle = GLOBAL_CreateBlock( flags, ptr, size, hOwner,
+				isCode, is32Bit, isReadOnly, &shmdata);
+    if (!handle)
+    {
+        free( ptr );
+        return 0;
+    }
+
+    if (flags & GMEM_ZEROINIT) memset( ptr, 0, size );
+    return handle;
+}
+
+HGLOBAL GLOBAL_CreateBlock( WORD flags, void *ptr, DWORD size,
+			    HGLOBAL hOwner, BOOL isCode,
+			    BOOL is32Bit, BOOL isReadOnly,
+			    SHMDATA *shmdata)
+{
+  fprintf(stderr,"JBP: GLOBAL_CreateBlock() faked.\n");
+  return ptr;
+}
+
+BOOL GLOBAL_FreeBlock( HGLOBAL handle )
+{
+  fprintf(stderr,"JBP: GLOBAL_FreeBlock() ignored.\n");
+  return 1;
+}
+
+DWORD GlobalHandle(WORD a)
+{
+  fprintf(stderr,"JBP: GlobalHandle() ignored.\n");
+  return 0;
+}
+
+void *RELAY32_GetEntryPoint(char *dll_name, char *item, int hint)
+{
+  fprintf(stderr,"JBP: RELAY32_GetEntryPoint() ignored.\n");
+  return NULL;
+}
+
+extern LRESULT AboutDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT ButtonWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT CARET_Callback(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT ColorDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT ComboBoxWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT ComboLBoxWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT DesktopWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT EditWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT FileOpenDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT FileSaveDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT FindTextDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT ListBoxWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT MDIClientWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT PopupMenuWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT PrintDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT PrintSetupDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT ReplaceTextDlgProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT ScrollBarWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT StaticWndProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT SystemMessageBoxProc(HWND,UINT,WPARAM,LPARAM);
+extern LRESULT TASK_Reschedule(HWND,UINT,WPARAM,LPARAM);
+
+LRESULT ErrorProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
+{
+  fprintf(stderr,"ERROR: ErrorProc() called!\n");
+  return 0;
+}
+
+/***********************************************************************
+ *           GetWndProcEntry16 (not a Windows API function)
+ *
+ * Return an entry point from the WINPROCS dll.
+ */
+WNDPROC GetWndProcEntry16( char *name )
+{
+#define MAP_STR_TO_PROC(str,proc) if(!strcmp(name,str))return proc
+  MAP_STR_TO_PROC("AboutDlgProc",AboutDlgProc);
+  MAP_STR_TO_PROC("ButtonWndProc",ButtonWndProc);
+  MAP_STR_TO_PROC("CARET_Callback",CARET_Callback);
+  MAP_STR_TO_PROC("ColorDlgProc",ColorDlgProc);
+  MAP_STR_TO_PROC("ComboBoxWndProc",ComboBoxWndProc);
+  MAP_STR_TO_PROC("ComboLBoxWndProc",ComboLBoxWndProc);
+  MAP_STR_TO_PROC("DefDlgProc",DefDlgProc);
+  MAP_STR_TO_PROC("DesktopWndProc",DesktopWndProc);
+  MAP_STR_TO_PROC("EditWndProc",EditWndProc);
+  MAP_STR_TO_PROC("FileOpenDlgProc",FileOpenDlgProc);
+  MAP_STR_TO_PROC("FileSaveDlgProc",FileSaveDlgProc);
+  MAP_STR_TO_PROC("FindTextDlgProc",FindTextDlgProc);
+  MAP_STR_TO_PROC("ListBoxWndProc",ListBoxWndProc);
+  MAP_STR_TO_PROC("MDIClientWndProc",MDIClientWndProc);
+  MAP_STR_TO_PROC("PopupMenuWndProc",PopupMenuWndProc);
+  MAP_STR_TO_PROC("PrintDlgProc",PrintDlgProc);
+  MAP_STR_TO_PROC("PrintSetupDlgProc",PrintSetupDlgProc);
+  MAP_STR_TO_PROC("ReplaceTextDlgProc",ReplaceTextDlgProc);
+  MAP_STR_TO_PROC("ScrollBarWndProc",ScrollBarWndProc);
+  MAP_STR_TO_PROC("StaticWndProc",StaticWndProc);
+  MAP_STR_TO_PROC("SystemMessageBoxProc",SystemMessageBoxProc);
+  MAP_STR_TO_PROC("TASK_Reschedule",TASK_Reschedule);
+  return ErrorProc;
+}
diff --git a/toolkit/sup.c b/toolkit/sup.c
index 9a66e74..421a097 100644
--- a/toolkit/sup.c
+++ b/toolkit/sup.c
@@ -1,12 +1,13 @@
 #include <stdio.h>
+#include <unistd.h>
 #include "windows.h"
 #include "callback.h"
 #include "wine.h"
 #include "arch.h"
 #include "neexe.h"
 
-LONG CallWindowProc (WNDPROC func, HWND hwnd, WORD message,
-		     WORD wParam, LONG lParam)
+LRESULT CallWindowProc (WNDPROC func, HWND hwnd, UINT message,
+			WPARAM wParam, LPARAM lParam)
 {
     return (*func)(hwnd, message, wParam, lParam);
 }
@@ -91,4 +92,5 @@
     LOADSHORT (id);
     LOADSHORT (handle);
     LOADSHORT (usage);
+    return 0;
 }
diff --git a/toolkit/winmain.c b/toolkit/winmain.c
index f5bd227..1982f6b 100644
--- a/toolkit/winmain.c
+++ b/toolkit/winmain.c
@@ -4,33 +4,27 @@
 #include "windows.h"
 #include "wine.h"
 
-_WinMain (int argc, char *argv [])
+extern int MAIN_Init(void);
+extern BOOL WIDGETS_Init(void);
+extern BOOL WIN_CreateDesktopWindow(void);
+extern int PASCAL WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
+extern void TASK_Reschedule(void);
+extern int USER_InitApp(HINSTANCE);
+
+int _WinMain (int argc, char *argv [])
 {
-    int ret_val;
-    char filename [4096], *module_name, *resource_file;
-    HANDLE hTaskMain, hInstance;
-    
-	/* The libwine resource DLL is temporarily disabled */
-#if 0
-    if ((module_name = strchr (argv [0], '/')) == NULL){
-	printf ("Error: Can't determine base name for resource loading\n");
-	return 0;
-    }
+  HINSTANCE hInstance;
 
-    resource_file = malloc (strlen (++module_name) + 5);
-    strcpy (resource_file, module_name);
-    strcat (resource_file, ".dll");
+  if(!MAIN_Init()) return 0; /* JBP: Needed for DosDrives[] structure, etc. */
+  hInstance = WinExec( *argv, SW_SHOWNORMAL );
+  TASK_Reschedule();
+  USER_InitApp( hInstance );
+  /* Perform global initialisations that need a task context */
+  if (!WIDGETS_Init()) return -1;
+  if (!WIN_CreateDesktopWindow()) return -1;
 
-    hInstance = LoadImage (resource_file, 0, 0);
-#endif
-    
-    USER_InitApp( hInstance );
-#if 0
-    hTaskMain = CreateNewTask (1); /* This is not correct */
-#endif
-    ret_val = WinMain (hInstance,	/* hInstance */
-		       0,		/* hPrevInstance */
-		       "",		/* lpszCmdParam */
-		       SW_NORMAL); 	/* nCmdShow */
-    return ret_val;
+  return WinMain (hInstance,    /* hInstance */
+		  0,	        /* hPrevInstance */
+		  "",	        /* lpszCmdParam */
+		  SW_NORMAL);   /* nCmdShow */
 }
diff --git a/tools/Imakefile b/tools/Imakefile
deleted file mode 100644
index e5abd7b..0000000
--- a/tools/Imakefile
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "../Wine.tmpl"
-
-SRCS = build.c
-
-OBJS = $(SRCS:.c=.o)
-
-AllTarget(build)
-
-NormalProgramTarget(build,build.o,$(DEPLIBS),,)
-
-DependTarget()
-
-includes::
-
-install::
diff --git a/tools/build.c b/tools/build.c
index 0221c49..5958875 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -13,7 +13,7 @@
 #include "neexe.h"
 
 /* ELF symbols do not have an underscore in front */
-#ifdef __ELF__
+#if defined (__ELF__) || defined (__svr4__)
 #define PREFIX
 #else
 #define PREFIX "_"
@@ -539,7 +539,7 @@
     pModule->magic = NE_SIGNATURE;
     pModule->count = 1;
     pModule->next = 0;
-    pModule->flags = NE_FFLAGS_SINGLEDATA | NE_FFLAGS_LIBMODULE;
+    pModule->flags = NE_FFLAGS_SINGLEDATA | NE_FFLAGS_BUILTIN | NE_FFLAGS_LIBMODULE;
     pModule->dgroup = 2;
     pModule->heap_size = 0xffff;
     pModule->stack_size = 0;
@@ -718,14 +718,13 @@
 
     printf( "/* File generated automatically, do not edit! */\n" );
     printf( "#include <sys/types.h>\n");
-	printf( "#include \"windows.h\"\n");
+    printf( "#include \"windows.h\"\n");
     printf( "#include \"dlls.h\"\n");
     printf( "#include \"pe_image.h\"\n");
     printf( "#include \"winerror.h\"\n");
-	printf( "#include \"relay32.h\"\n");
+    printf( "#include \"relay32.h\"\n");
     printf( "#include \"stddebug.h\"\n");
     printf( "#include \"debug.h\"\n");
-    printf( "\nextern int RELAY32_Unimplemented();\n\n" );
 
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
@@ -760,8 +759,13 @@
                 if (argno!=argc-1) putchar( ',' );
             }
             printf( ")\n{\n" );
-            printf( "\tdprintf_relay(stddeb,\"Entering %%s.%%s(");
-            for (argno=0;argno<argc;argno++) printf( "%%x ");
+            printf( "\tdprintf_relay(stddeb,\"Call %%s.%%s(");
+            for (argno=0;argno<argc;argno++)
+            {
+                putchar( '%' );
+                putchar( (fdp->arg_types[argno] == 'p') ? 'p' : 'x' );
+                if (argno < argc-1) putchar( ',' );
+            }
             printf( ")\\n\", \"%s\", \"%s\"", UpperDLLName, odp->export_name);
             for(argno=0;argno<argc;argno++) printf( ",%c", 'a'+argno);
             printf( ");\n\t%s(", fdp->internal_name );
@@ -847,7 +851,11 @@
     printf( "\t.data\n" );
     printf( "\t.globl " PREFIX "%s_Data_Start\n", UpperDLLName );
     printf( PREFIX "%s_Data_Start:\n", UpperDLLName );
+#ifdef __svr4__
+    printf( "\t.4byte 0,0,0,0,0,0,0,0\n" );
+#else
     printf( "\t.word 0,0,0,0,0,0,0,0\n" );
+#endif
     data_offset = 16;
     printf( "\t.text\n" );
     printf( "\t.globl " PREFIX "%s_Code_Start\n", UpperDLLName );
@@ -879,7 +887,11 @@
           case TYPE_WORD:
             printf( "/* %s.%d */\n", UpperDLLName, i);
             odp->offset = data_offset;
+#ifdef __svr4__
+            data_offset += 2 * OutputVariableCode( ".4byte", odp);
+#else
             data_offset += 2 * OutputVariableCode( ".word", odp);
+#endif
             break;
 
           case TYPE_LONG:
diff --git a/win32/Makefile.in b/win32/Makefile.in
new file mode 100644
index 0000000..bfabcb6
--- /dev/null
+++ b/win32/Makefile.in
@@ -0,0 +1,18 @@
+TOPSRC = @top_srcdir@
+MODULE = win32
+
+C_SRCS = \
+	code_page.c \
+	environment.c \
+	error.c \
+	file.c \
+	init.c \
+	memory.c \
+	thread.c \
+	time.c
+
+all: $(MODULE).o
+
+@MAKE_RULES@
+
+### Dependencies:
diff --git a/win32/code_page.c b/win32/code_page.c
new file mode 100644
index 0000000..1338ea4
--- /dev/null
+++ b/win32/code_page.c
@@ -0,0 +1,38 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis and Cameron Heide
+ */
+
+#include <stdio.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+
+/***********************************************************************
+ *           GetACP               (KERNEL32.148)
+ */
+UINT GetACP(void)
+{
+    return 1252;    /* Windows 3.1 ISO Latin */
+}
+
+/***********************************************************************
+ *           GetCPInfo            (KERNEL32.154)
+ */
+BOOL GetCPInfo(UINT codepage, LPCPINFO cpinfo)
+{
+    cpinfo->MaxCharSize = 1;
+    cpinfo->DefaultChar[0] = '?';
+
+    return 1;
+}
+
+/***********************************************************************
+ *              GetOEMCP                (KERNEL32.248)
+ */
+UINT GetOEMCP(void)
+{
+    return 437;    /* MS-DOS United States */
+}
+
diff --git a/win32/environment.c b/win32/environment.c
new file mode 100644
index 0000000..a37c57f
--- /dev/null
+++ b/win32/environment.c
@@ -0,0 +1,26 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis and Cameron Heide
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+#include "task.h"
+
+
+/***********************************************************************
+ *           GetCommandLineA      (KERNEL32.161)
+ */
+LPSTR GetCommandLineA(void)
+{
+    static char buffer[256];
+    PDB *pdb = (PDB *)GlobalLock( GetCurrentPDB() );
+    memcpy( buffer, &pdb->cmdLine[1], pdb->cmdLine[0] );
+    printf("CommandLine = %s\n", buffer );
+    return buffer;
+}
+
diff --git a/win32/error.c b/win32/error.c
new file mode 100644
index 0000000..5bbe1f8
--- /dev/null
+++ b/win32/error.c
@@ -0,0 +1,36 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis and Cameron Heide
+ */
+
+#include <stdio.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+
+static int WIN32_LastError;
+
+/**********************************************************************
+ *              GetLastError            (KERNEL32.227)
+ */
+DWORD GetLastError(void)
+{
+    return WIN32_LastError;
+}
+
+/**********************************************************************
+ *              SetLastError            (KERNEL32.497)
+ *
+ * This is probably not used by apps too much, but it's useful for
+ * our own internal use.
+ */
+void SetLastError(DWORD error)
+{
+    WIN32_LastError = error;
+}
+
+DWORD ErrnoToLastError(int errno_num)
+{
+    return errno_num;   /* Obviously not finished yet. :-) */
+}
diff --git a/win32/file.c b/win32/file.c
new file mode 100644
index 0000000..61b4a09
--- /dev/null
+++ b/win32/file.c
@@ -0,0 +1,96 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis and Cameron Heide
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+
+/***********************************************************************
+ *           GetFileType              (KERNEL32.222)
+ *
+ * GetFileType currently only supports stdin, stdout, and stderr, which
+ * are considered to be of type FILE_TYPE_CHAR.
+ */
+DWORD GetFileType(HANDLE hFile)
+{
+    DWORD file_type;
+
+    if(hFile < 3)
+    {
+        file_type = 2;        /* FILE_TYPE_CHAR */
+    }
+    else
+    {
+        file_type = 0;        /* FILE_TYPE_UNKNOWN */
+    }
+
+    return file_type;
+}
+
+/***********************************************************************
+ *           GetStdHandle             (KERNEL32.276)
+ */
+HANDLE GetStdHandle(DWORD nStdHandle)
+{
+        switch(nStdHandle)
+        {
+                case -10/*STD_INPUT_HANDLE*/:return (HANDLE)0;
+                case -11/*STD_OUTPUT_HANDLE*/:return (HANDLE)1;
+                case -12/*STD_ERROR_HANDLE*/:return (HANDLE)2;
+        }
+        return (HANDLE)-1;
+}
+
+/***********************************************************************
+ *              SetFilePointer          (KERNEL32.492)
+ *
+ * Luckily enough, this function maps almost directly into an lseek
+ * call, the exception being the use of 64-bit offsets.
+ */
+DWORD SetFilePointer(HANDLE hFile, LONG distance, LONG *highword,
+                     DWORD method)
+{
+    int rc;
+
+    if(highword != NULL)
+    {
+        if(*highword != 0)
+        {
+            printf("SetFilePointer: 64-bit offsets not yet supported.\n");
+            return -1;
+        }
+    }
+
+    rc = lseek(hFile, distance, method);
+    if(rc == -1)
+        SetLastError(ErrnoToLastError(errno));
+    return rc;
+}
+
+/***********************************************************************
+ *             WriteFile               (KERNEL32.578)
+ *
+ * WriteFile isn't very useful at this point since only standard
+ * handles are permitted, but it lets us see runtime errors at least.
+ */
+BOOL WriteFile(HANDLE hFile, LPVOID lpBuffer, DWORD numberOfBytesToWrite,
+              LPDWORD numberOfBytesWritten, LPOVERLAPPED lpOverlapped)
+{
+    int written;
+
+    if(hFile < 3)
+    {
+        written = write(hFile, lpBuffer, numberOfBytesToWrite);
+        if(numberOfBytesWritten)
+            *numberOfBytesWritten = written;
+    }
+
+    return 1;
+}
+
diff --git a/win32/init.c b/win32/init.c
new file mode 100644
index 0000000..8000edc
--- /dev/null
+++ b/win32/init.c
@@ -0,0 +1,44 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis and Cameron Heide
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+
+int WIN32_LastError;
+
+/***********************************************************************
+ *              GetModuleFileNameA      (KERNEL32.235)
+ */
+DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
+{
+    strcpy(lpFilename, "c:\\dummy");
+    return 8;
+}
+
+/***********************************************************************
+ *              GetStartupInfoA         (KERNEL32.273)
+ */
+VOID GetStartupInfoA(LPSTARTUPINFO lpStartupInfo)
+{
+    lpStartupInfo->cb = sizeof(STARTUPINFO);
+    lpStartupInfo->lpReserved = NULL;
+    lpStartupInfo->lpDesktop = "Desktop";
+    lpStartupInfo->lpTitle = "Title";
+
+    lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
+    lpStartupInfo->hStdInput = 0;
+    lpStartupInfo->hStdOutput = 1;
+    lpStartupInfo->hStdError = 2;
+}
+
+int KERN32_Init(void)
+{
+    return 1;
+}
diff --git a/win32/memory.c b/win32/memory.c
new file mode 100644
index 0000000..a654510
--- /dev/null
+++ b/win32/memory.c
@@ -0,0 +1,46 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis and Cameron Heide
+ */
+
+#include <malloc.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+
+/***********************************************************************
+ *           VirtualAlloc             (KERNEL32.548)
+ */
+LPVOID VirtualAlloc(LPVOID lpvAddress, DWORD cbSize,
+                   DWORD fdwAllocationType, DWORD fdwProtect)
+{
+    char *ptr;
+
+    printf("VirtualAlloc: size = %ld, address=%p\n", cbSize, lpvAddress);
+    ptr = malloc(cbSize + 65536);
+    if(ptr)
+    {
+        /* Round it up to the next 64K boundary and zero it.
+         */
+        ptr = (void *)(((unsigned long)ptr & 0xFFFF0000L) + 0x00010000L);
+        memset(ptr, 0, cbSize);
+    }
+    printf("VirtualAlloc: got pointer %p\n", ptr);
+    return ptr;
+}
+
+/***********************************************************************
+ *           VirtualFree               (KERNEL32.550)
+ */
+BOOL VirtualFree(LPVOID lpvAddress, DWORD cbSize, DWORD fdwFreeType)
+{
+    if(lpvAddress)
+        free(lpvAddress);
+    return 1;
+}
+
diff --git a/win32/thread.c b/win32/thread.c
new file mode 100644
index 0000000..e6b9e2c
--- /dev/null
+++ b/win32/thread.c
@@ -0,0 +1,29 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+
+/***********************************************************************
+ *           GetCurrentThreadId   (KERNEL32.200)
+ */
+
+int GetCurrentThreadId(void)
+{
+        return getpid();
+}
+
+/***********************************************************************
+ *           GetThreadContext         (KERNEL32.294)
+ */
+BOOL GetThreadContext(HANDLE hThread, void *lpContext)
+{
+        return FALSE;
+}
+
diff --git a/win32/time.c b/win32/time.c
new file mode 100644
index 0000000..58f9703
--- /dev/null
+++ b/win32/time.c
@@ -0,0 +1,31 @@
+/*
+ * Win32 kernel functions
+ *
+ * Copyright 1995 Martin von Loewis and Cameron Heide
+ */
+
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include "windows.h"
+#include "winerror.h"
+#include "kernel32.h"
+
+/***********************************************************************
+ *              GetTimeZoneInformation  (KERNEL32.302)
+ */
+DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
+{
+    time_t gmt, lt;
+
+    memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));
+
+    gmt = time(NULL);
+    lt = mktime(localtime(&gmt));
+    tzinfo->Bias = (gmt - lt) / 60;
+    tzinfo->StandardBias = 0;
+    tzinfo->DaylightBias = -60;
+
+    return TIME_ZONE_ID_UNKNOWN;
+}
+
diff --git a/windows/Imakefile b/windows/Imakefile
deleted file mode 100644
index 54c0f27..0000000
--- a/windows/Imakefile
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "../Wine.tmpl"
-
-MODULE = windows
-
-SRCS = \
-	alias.c \
-	caret.c \
-	class.c \
-	cursor.c \
-	dce.c \
-	defdlg.c \
-	defwnd.c \
-	dialog.c \
-	event.c \
-	focus.c \
-	graphics.c \
-	hook.c \
-	keyboard.c \
-	mapping.c \
-	mdi.c \
-	message.c \
-	msgbox.c \
-	nonclient.c \
-	painting.c \
-	property.c \
-	scroll.c \
-	syscolor.c \
-	sysmetrics.c \
-	timer.c \
-	utility.c \
-	win.c \
-	winpos.c
-
-OBJS = $(SRCS:.c=.o)
-
-WineRelocatableTarget($(MODULE),,$(OBJS))
-DependTarget()
-
-includes::
-
-install::
diff --git a/windows/Makefile.in b/windows/Makefile.in
index 4eef8a0..d04102b 100644
--- a/windows/Makefile.in
+++ b/windows/Makefile.in
@@ -5,7 +5,6 @@
 	alias.c \
 	caret.c \
 	class.c \
-	cursor.c \
 	dce.c \
 	defdlg.c \
 	defwnd.c \
diff --git a/windows/caret.c b/windows/caret.c
index a85a47c..8cf00ca 100644
--- a/windows/caret.c
+++ b/windows/caret.c
@@ -2,13 +2,12 @@
  * Caret functions
  *
  * Copyright 1993 David Metcalfe
- *
-static char Copyright[] = "Copyright  David Metcalfe, 1993";
-*/
+ */
 
 #include "windows.h"
 #include "selectors.h"
 #include "alias.h"
+#include "relay32.h"
 #include "stddebug.h"
 /* #define DEBUG_CARET */
 #include "debug.h"
@@ -50,7 +49,7 @@
     {
 	Caret.on = (Caret.on ? FALSE : TRUE);
 	hdc = GetDC(Caret.hwnd);
-	if (Caret.bitmap == 0 || Caret.bitmap == 1)
+	if (Caret.bitmap == (HBITMAP)0 || Caret.bitmap == (HBITMAP)1)
 	    hBrush = CreateSolidBrush(Caret.color);
 	else
 	    hBrush = CreatePatternBrush(Caret.bitmap);
@@ -80,7 +79,7 @@
 
     Caret.on = FALSE;
     hdc = GetDC(Caret.hwnd);
-    if (Caret.bitmap == 0 || Caret.bitmap == 1)
+    if (Caret.bitmap == (HBITMAP)0 || Caret.bitmap == (HBITMAP)1)
 	hBrush = CreateSolidBrush(Caret.color);
     else
 	hBrush = CreatePatternBrush(Caret.bitmap);
@@ -126,7 +125,7 @@
 /*    if (Caret.hwnd)
 	DestroyCaret();
 */
-    if (bitmap && bitmap != 1)
+    if (bitmap && bitmap != (HBITMAP)1)
 	Caret.bitmap = bitmap;
 
     if (width)
@@ -144,7 +143,7 @@
     Caret.on = FALSE;
     Caret.x = 0;
     Caret.y = 0;
-    if (bitmap == 1)
+    if (bitmap == (HBITMAP)1)
 	Caret.color = GetSysColor(COLOR_GRAYTEXT);
     else
 	Caret.color = GetSysColor(COLOR_WINDOWTEXT);
@@ -156,7 +155,7 @@
     Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
                                 (FARPROC)GetWndProcEntry16("CARET_Callback"));
 
-    dprintf_caret(stddeb,"CreateCaret: hwnd=%d, timerid=%d\n", 
+    dprintf_caret(stddeb,"CreateCaret: hwnd="NPFMT", timerid=%d\n", 
 		  hwnd, Caret.timerid);
 }
    
diff --git a/windows/class.c b/windows/class.c
index 4ce07ed..f148b38 100644
--- a/windows/class.c
+++ b/windows/class.c
@@ -28,7 +28,7 @@
  * Return a handle and a pointer to the class.
  * 'ptr' can be NULL if the pointer is not needed.
  */
-HCLASS CLASS_FindClassByName( SEGPTR name, WORD hinstance, CLASS **ptr )
+HCLASS CLASS_FindClassByName( SEGPTR name, HINSTANCE hinstance, CLASS **ptr )
 {
     ATOM atom;
     HCLASS class;
@@ -43,7 +43,8 @@
         classPtr = (CLASS *) USER_HEAP_LIN_ADDR(class);
         if (classPtr->wc.style & CS_GLOBALCLASS) continue;
         if ((classPtr->atomName == atom) && 
-            ((hinstance==0xffff )|| (hinstance == classPtr->wc.hInstance)))
+            ( (hinstance==(HINSTANCE)0xffff) ||
+	      (hinstance == classPtr->wc.hInstance) ) )
         {
             if (ptr) *ptr = classPtr;
             return class;
@@ -92,7 +93,7 @@
     HCLASS handle, prevClass;
     int classExtra;
 
-    dprintf_class( stddeb, "RegisterClass: wndproc=%08lx hinst=%04x name='%s' background %04x\n",
+    dprintf_class( stddeb, "RegisterClass: wndproc=%08lx hinst="NPFMT" name='%s' background "NPFMT"\n",
                  (DWORD)class->lpfnWndProc, class->hInstance,
                  HIWORD(class->lpszClassName) ?
                   (char *)PTR_SEG_TO_LIN(class->lpszClassName) : "(int)",
@@ -143,7 +144,7 @@
 	HANDLE hname = USER_HEAP_ALLOC( strlen(menuname)+1 );
 	if (hname)
 	{
-	    newClass->wc.lpszMenuName = USER_HEAP_SEG_ADDR( hname );
+	    newClass->wc.lpszMenuName = (SEGPTR)USER_HEAP_SEG_ADDR( hname );
 	    strcpy( USER_HEAP_LIN_ADDR( hname ), menuname );
 	}
     }
@@ -191,7 +192,11 @@
     if (classPtr->wc.hbrBackground) DeleteObject( classPtr->wc.hbrBackground );
     GlobalDeleteAtom( classPtr->atomName );
     if (HIWORD(classPtr->wc.lpszMenuName))
+#ifdef WINELIB32
+	USER_HEAP_FREE( (HANDLE)classPtr->wc.lpszMenuName );
+#else
 	USER_HEAP_FREE( LOWORD(classPtr->wc.lpszMenuName) );
+#endif
     USER_HEAP_FREE( class );
     return TRUE;
 }
@@ -265,7 +270,7 @@
     CLASS *classPtr;
 
     /* FIXME: We have the find the correct hInstance */
-    dprintf_class(stddeb,"GetClassName(%x,%p,%d)\n",hwnd,lpClassName,maxCount);
+    dprintf_class(stddeb,"GetClassName("NPFMT",%p,%d)\n",hwnd,lpClassName,maxCount);
     if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
     if (!(classPtr = CLASS_FindClassPtr(wndPtr->hClass))) return 0;
     
@@ -280,7 +285,7 @@
 {
     CLASS *classPtr;
 
-    dprintf_class( stddeb, "GetClassInfo: hInstance=%04x className=%s\n",
+    dprintf_class( stddeb, "GetClassInfo: hInstance="NPFMT" className=%s\n",
 		   hInstance,
                    HIWORD(name) ? (char *)PTR_SEG_TO_LIN(name) : "(int)" );
 
diff --git a/windows/cursor.c b/windows/cursor.c
deleted file mode 100644
index 9875df1..0000000
--- a/windows/cursor.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- *    WINE
-static char Copyright[] = "Copyright  Martin Ayotte, 1993";
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <X11/cursorfont.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include "windows.h"
-#include "win.h"
-#include "gdi.h"
-#include "neexe.h"
-#include "wine.h"
-#include "callback.h"
-#include "cursor.h"
-#include "resource.h"
-#include "stddebug.h"
-#include "debug.h"
-#include "arch.h"
-#include "bitmap.h"
-
-static int ShowCursCount = 0;
-static HCURSOR hActiveCursor;
-static HCURSOR hEmptyCursor = 0;
-RECT	ClipCursorRect;
-
-static struct { 
-   SEGPTR name; HCURSOR cursor; unsigned int shape;
-} system_cursor[] =
-{
-    { IDC_ARROW,    0, XC_top_left_arrow},
-    { IDC_IBEAM,    0, XC_xterm },
-    { IDC_WAIT,     0, XC_watch },
-    { IDC_CROSS,    0, XC_crosshair },
-    { IDC_UPARROW,  0, XC_based_arrow_up },
-    { IDC_SIZE,     0, XC_bottom_right_corner },
-    { IDC_ICON,     0, XC_icon },
-    { IDC_SIZENWSE, 0, XC_fleur },
-    { IDC_SIZENESW, 0, XC_fleur },
-    { IDC_SIZEWE,   0, XC_sb_h_double_arrow },
-    { IDC_SIZENS,   0, XC_sb_v_double_arrow }
-};
-
-#define NB_SYS_CURSORS  (sizeof(system_cursor)/sizeof(system_cursor[0]))
-
-
-/**********************************************************************
- *			LoadCursor [USER.173]
- */
-HCURSOR LoadCursor(HANDLE instance, SEGPTR cursor_name)
-{
-    HCURSOR 	hCursor;
-    HRSRC       hRsrc;
-    HANDLE 	rsc_mem;
-    char        *lpbits;
-    LONG        *lpl,size;
-    CURSORALLOC *lpcur;
-    CURSORDIR   *lpcurdir;
-    CURSORDESCRIP curdesc;
-    POINT       hotspot;
-    int i;
-    dprintf_resource(stddeb,"LoadCursor: instance = %04x, name = %08lx\n",
-	   instance, cursor_name);
-    if (!instance)
-    {
-	for (i = 0; i < NB_SYS_CURSORS; i++)
-	    if (system_cursor[i].name == cursor_name)
-	    {
-	        if (!system_cursor[i].cursor) 
-	        {
-		    hCursor = GlobalAlloc (GMEM_MOVEABLE, sizeof (Cursor));
-		    dprintf_cursor(stddeb,"LoadCursor Alloc hCursor=%X\n", hCursor);
-		    system_cursor[i].cursor = hCursor;
-		    lpcur = (CURSORALLOC *) GlobalLock(hCursor);
-		    lpcur->xcursor = XCreateFontCursor(display, system_cursor[i].shape);
-		    GlobalUnlock(hCursor);
-	        }
-	       	return system_cursor[i].cursor;
-	    }
-	return 0;
-    }
-
-    if (!(hRsrc = FindResource( instance, cursor_name, RT_GROUP_CURSOR )))
-	return 0;
-    rsc_mem = LoadResource(instance, hRsrc );
-    if (rsc_mem == (HANDLE)NULL) {
-        fprintf(stderr,"LoadCursor / Cursor %08lx not Found !\n", cursor_name);
-	return 0;
-    }
-    lpcurdir = (CURSORDIR *)LockResource(rsc_mem);
-    if (lpcurdir == NULL) {
-        FreeResource( rsc_mem );
-	return 0;
-    }
-    curdesc = *(CURSORDESCRIP *)(lpcurdir + 1);  /* CONV_CURDESC ? */
-#if 0
-    dprintf_cursor(stddeb,"LoadCursor / curReserved=%X\n", lpcurdir->cdReserved);
-    dprintf_cursor(stddeb,"LoadCursor / curResourceType=%X\n", lpcurdir->cdType);
-    dprintf_cursor(stddeb,"LoadCursor / curResourceCount=%X\n", lpcurdir->cdCount);
-    dprintf_cursor(stddeb,"LoadCursor / cursor Width=%d\n", 
-		(int)curdesc.Width);
-    dprintf_cursor(stddeb,"LoadCursor / cursor Height=%d\n", 
-		(int)curdesc.Height);
-    dprintf_cursor(stddeb,"LoadCursor / cursor curDIBSize=%lX\n", 
-		(DWORD)curdesc.curDIBSize);
-    dprintf_cursor(stddeb,"LoadCursor / cursor curDIBOffset=%lX\n",
-		(DWORD)curdesc.curDIBOffset);
-#endif
-    FreeResource( rsc_mem );
-    if (!(hRsrc = FindResource( instance,
-                                MAKEINTRESOURCE(curdesc.curDIBOffset), 
-                                RT_CURSOR )))
-	return 0;
-    rsc_mem = LoadResource(instance, hRsrc );
-    if (rsc_mem == (HANDLE)NULL) {
-    	fprintf(stderr,
-		"LoadCursor / Cursor %08lx Bitmap not Found !\n", cursor_name);
-	return 0;
-    }
-    lpl = (LONG *) LockResource(rsc_mem);
-    if (lpl == NULL) {
-        FreeResource( rsc_mem );
-	return 0;
-	}
-    hotspot = *(POINT *) lpl++;  /* CONV_POINT ? */
-    size = CONV_LONG (*lpl);
-#if 0
-    if (!(hdc = GetDC(0))) {
-       FreeResource( rsc_mem );
-       return 0;
-    }
-    if (size == sizeof(BITMAPCOREHEADER)){
-	CONV_BITMAPCOREHEADER (lpl);
-        ((BITMAPINFOHEADER *)lpl)->biHeight /= 2;
-	lpcur->hBitmap = ConvertCoreBitmap( hdc, (BITMAPCOREHEADER *) lpl );
-    } else if (size == sizeof(BITMAPINFOHEADER)){
-	CONV_BITMAPINFO (lpl);
-        ((BITMAPINFOHEADER *)lpl)->biHeight /= 2;
-	lpcur->hBitmap = ConvertInfoBitmap( hdc, (BITMAPINFO *) lpl );
-    } else  {
-      fprintf(stderr,"No bitmap for cursor?\n");
-      lpcur->hBitmap = 0;
-    }
-    ReleaseDC(0,hdc);
-#endif
-    if (size == sizeof(BITMAPCOREHEADER))
-	lpbits = (char *)lpl + sizeof(BITMAPCOREHEADER) + 2*sizeof(RGBTRIPLE);
-    else if (size == sizeof(BITMAPINFOHEADER))
-	lpbits = (char *)lpl + sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD);
-    else  {
-      fprintf(stderr,"Invalid bitmap in cursor resource\n");
-      FreeResource(rsc_mem);
-      return 0;
-    }
-    /* The height of the cursor is the height of the XOR-Bitmap
-     * plus the height of the AND-Bitmap, so divide it by two.
-     */
-    size = curdesc.Height/2 * ((curdesc.Width+31)/32 * 4);
-#if 0
-    dprintf_cursor(stddeb,"Bitmap:\n");
-    for(i=0;i<2*size;i++)  {
-      dprintf_cursor(stddeb,"%02x ",(unsigned char) lpc[i]);
-      if ((i & 7) == 7) dprintf_cursor(stddeb,"\n");
-    }
-#endif
-    hCursor = CreateCursor(instance, hotspot.x, hotspot.y, 
-			   curdesc.Width, curdesc.Height / 2,
-			   lpbits+size, lpbits);
-    FreeResource( rsc_mem );
-    return hCursor;
-}
-
-
-
-/***********************************************************************
- *           CreateCursorIconIndirect           (USER.408)
- *
- * Returns handle to either an icon or a cursor. Used by CreateCursor
- * and CreateIcon in  Windoze, but will use same in this version.
- */
-HANDLE CreateCursorIconIndirect(HANDLE hInstance, LPCURSORICONINFO lpInfo,
-                                LPSTR lpANDBits, /* bitmap data */
-                                LPSTR lpXORBits /* masking data */)
-{
-        return CreateIcon(hInstance,
-                lpInfo->nWidth, lpInfo->nHeight,
-                lpInfo->byPlanes, lpInfo->byBitsPix,
-                lpANDBits, lpXORBits);
-}
-
-
-/**********************************************************************
- *			CreateCursor [USER.406]
- */
-HCURSOR CreateCursor(HANDLE instance, short nXhotspot, short nYhotspot, 
-	short nWidth, short nHeight, LPSTR lpANDbitPlane, LPSTR lpXORbitPlane)
-{
-    HCURSOR	hCursor;
-    CURSORALLOC *lpcur;
-    int		bpl = (nWidth + 31)/32 * 4;
-    char	*tmpbits = malloc(bpl * nHeight);
-    char	*src, *dst;
-    int		i;
-    XImage	*image;
-    Pixmap	pixshape, pixmask;
-    extern void _XInitImageFuncPtrs( XImage* );
-  
-    XColor bkcolor,fgcolor;
-    Colormap cmap = XDefaultColormap(display,XDefaultScreen(display));
-    
-    dprintf_resource(stddeb, "CreateCursor: inst=%04x nXhotspot=%d  nYhotspot=%d nWidth=%d nHeight=%d\n",  
-       instance, nXhotspot, nYhotspot, nWidth, nHeight);
-    dprintf_resource(stddeb,"CreateCursor: inst=%04x lpANDbitPlane=%p lpXORbitPlane=%p\n",
-	instance, lpANDbitPlane, lpXORbitPlane);
-
-    image = XCreateImage( display, DefaultVisualOfScreen(screen),
-                          1, ZPixmap, 0, tmpbits,
-                          nWidth, nHeight, 32, bpl );
-    if (!image) {
-	free (tmpbits);
-	return 0;
-    }
-    image->byte_order = MSBFirst;
-    image->bitmap_bit_order = MSBFirst;
-    image->bitmap_unit = 16;
-    _XInitImageFuncPtrs(image);
-
-    hCursor = GlobalAlloc(GMEM_MOVEABLE, sizeof(Cursor)); 
-    if (hCursor == (HCURSOR)NULL) {
-	XDestroyImage(image);
-	return 0;
-    }
-    dprintf_cursor(stddeb,"CreateCursor Alloc hCursor=%X\n", hCursor);
-    lpcur = (CURSORALLOC *)GlobalLock(hCursor);
-
-    for(src=lpANDbitPlane, dst=tmpbits+(nHeight-1)*bpl; 
-	dst>=tmpbits; src+=bpl, dst-=bpl)
-        for(i=0; i<bpl; i++) 
-            dst[i] = ~src[i];
-    pixmask = XCreatePixmap(display, DefaultRootWindow(display), 
-			    nWidth, nHeight, 1);
-    CallTo32_LargeStack(XPutImage, 10,
-			display, pixmask, BITMAP_monoGC, image, 
-			0, 0, 0, 0, nWidth, nHeight );
-
-    for(src=lpXORbitPlane, dst=tmpbits+(nHeight-1)*bpl; 
-	dst>=tmpbits; src+=bpl, dst-=bpl)
-        for(i=0; i<bpl; i++) 
-            dst[i] = ~src[i];
-    pixshape = XCreatePixmap(display, DefaultRootWindow(display), 
-			     nWidth, nHeight, 1);
-    CallTo32_LargeStack(XPutImage, 10,
-			display, pixshape, BITMAP_monoGC, image, 
-			0, 0, 0, 0, nWidth, nHeight );
-    XParseColor(display,cmap,"#000000",&fgcolor);
-    XParseColor(display,cmap,"#ffffff",&bkcolor);
-    lpcur->xcursor = XCreatePixmapCursor(display, pixshape, pixmask,
-			                 &fgcolor, &bkcolor, nXhotspot, nYhotspot);
-    XFreePixmap(display, pixshape);
-    XFreePixmap(display, pixmask);
-    GlobalUnlock(hCursor);
-    XDestroyImage(image);
-    return hCursor;
-}
-
-
-
-/**********************************************************************
- *			DestroyCursor [USER.458]
- */
-BOOL DestroyCursor(HCURSOR hCursor)
-{
-    int i;
-    CURSORALLOC	*lpcur;
-    
-    if (hCursor == 0) return FALSE;
-    for (i = 0; i < NB_SYS_CURSORS; i++) {
-	if (system_cursor[i].cursor == hCursor) return TRUE;
-    }
-    lpcur = (CURSORALLOC *)GlobalLock(hCursor);
-    XFreeCursor (display, lpcur->xcursor);
-    GlobalUnlock(hCursor);
-    GlobalFree(hCursor);
-    return TRUE;
-}
-
-
-/**********************************************************************
- *         CURSOR_SetCursor
- *
- * Internal helper function for SetCursor() and ShowCursor().
- */
-static void CURSOR_SetCursor( HCURSOR hCursor )
-{
-    CURSORALLOC	*lpcur;
-
-    if (!(lpcur = (CURSORALLOC *)GlobalLock(hCursor))) return;
-    if (rootWindow != DefaultRootWindow(display))
-    {
-        XDefineCursor( display, rootWindow, lpcur->xcursor );
-    }
-    else
-    {
-        HWND hwnd = GetWindow( GetDesktopWindow(), GW_CHILD );
-        while(hwnd)
-        {
-            Window win = WIN_GetXWindow( hwnd );
-            if (win) XDefineCursor( display, win, lpcur->xcursor );
-            hwnd = GetWindow( hwnd, GW_HWNDNEXT );
-        }
-    }
-    GlobalUnlock( hCursor );
-}
-
-/**********************************************************************
- *			SetCursor [USER.69]
- */
-HCURSOR SetCursor(HCURSOR hCursor)
-{
-    HCURSOR hOldCursor;
-
-    dprintf_cursor(stddeb,"SetCursor / hCursor=%04X !\n", hCursor);
-    hOldCursor = hActiveCursor;
-    hActiveCursor = hCursor;
-    if ((hCursor != hOldCursor) || (ShowCursCount < 0))
-    {
-        CURSOR_SetCursor( hCursor );
-    }
-    ShowCursCount = 0;
-    return hOldCursor;
-}
-
-
-/**********************************************************************
- *			GetCursor [USER.247]
- */
-HCURSOR GetCursor(void)
-{
-    return hActiveCursor;
-}
-
-
-/**********************************************************************
- *                        SetCursorPos [USER.70]
- */
-void SetCursorPos(short x, short y)
-{
-    dprintf_cursor(stddeb,"SetCursorPos // x=%d y=%d\n", x, y);
-    XWarpPointer( display, None, rootWindow, 0, 0, 0, 0, x, y );
-}
-
-
-/**********************************************************************
- *                        GetCursorPos [USER.17]
- */
-void GetCursorPos(LPPOINT lpRetPoint)
-{
-    Window 	root, child;
-    int		rootX, rootY;
-    int		childX, childY;
-    unsigned int mousebut;
-
-    if (!lpRetPoint) return;
-    if (!XQueryPointer( display, rootWindow, &root, &child,
-		        &rootX, &rootY, &childX, &childY, &mousebut ))
-	lpRetPoint->x = lpRetPoint->y = 0;
-    else
-    {
-	lpRetPoint->x = rootX + desktopX;
-	lpRetPoint->y = rootY + desktopY;
-    }
-    dprintf_cursor(stddeb,
-		"GetCursorPos // x=%d y=%d\n", lpRetPoint->x, lpRetPoint->y);
-}
-
-
-/**********************************************************************
- *			ShowCursor [USER.71]
- */
-int ShowCursor(BOOL bShow)
-{
-    dprintf_cursor(stddeb, "ShowCursor(%d), count=%d\n", bShow, ShowCursCount);
-
-    if (bShow)
-    {
-        if (++ShowCursCount == 0)  /* Time to show it */
-            CURSOR_SetCursor( hActiveCursor );
-    }
-    else  /* Hide it */
-    {
-        if (--ShowCursCount == -1)  /* Time to hide it */
-        {
-            if (!hEmptyCursor)
-                hEmptyCursor = CreateCursor( 0, 1, 1, 1, 1,
-					    "\xFF\xFF\xFF\xFF", "\xFF\xFF\xFF\xFF" );
-            CURSOR_SetCursor( hEmptyCursor );
-        }
-    }
-    return 0;
-}
-
-
-/**********************************************************************
- *                        ClipCursor [USER.16]
- */
-void ClipCursor(LPRECT lpNewClipRect)
-{
-    if (!lpNewClipRect) SetRectEmpty( &ClipCursorRect );
-    else CopyRect( &ClipCursorRect, lpNewClipRect );
-}
-
-
-/**********************************************************************
- *                        GetClipCursor [USER.309]
- */
-void GetClipCursor(LPRECT lpRetClipRect)
-{
-    if (lpRetClipRect != NULL)
-	CopyRect(lpRetClipRect, &ClipCursorRect);
-}
diff --git a/windows/dce.c b/windows/dce.c
index cbd6cf4..7cb9df3 100644
--- a/windows/dce.c
+++ b/windows/dce.c
@@ -392,7 +392,7 @@
     SelectVisRgn( hdc, hrgnVisible );
     DeleteObject( hrgnVisible );
 
-    dprintf_dc(stddeb, "GetDCEx(%d,%d,0x%lx): returning %d\n", 
+    dprintf_dc(stddeb, "GetDCEx("NPFMT","NPFMT",0x%lx): returning "NPFMT"\n", 
 	       hwnd, hrgnClip, flags, hdc);
     return hdc;
 }
@@ -432,7 +432,7 @@
     HANDLE hdce;
     DCE * dce = NULL;
     
-    dprintf_dc(stddeb, "ReleaseDC: %d %d\n", hwnd, hdc );
+    dprintf_dc(stddeb, "ReleaseDC: "NPFMT" "NPFMT"\n", hwnd, hdc );
         
     for (hdce = firstDCE; (hdce); hdce = dce->hNext)
     {
diff --git a/windows/defdlg.c b/windows/defdlg.c
index a3fb464..9f30af1 100644
--- a/windows/defdlg.c
+++ b/windows/defdlg.c
@@ -111,7 +111,7 @@
 /***********************************************************************
  *           DefDlgProc   (USER.308)
  */
-LONG DefDlgProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
+LRESULT DefDlgProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
     DIALOGINFO * dlgInfo;
     BOOL result = FALSE;
@@ -120,8 +120,8 @@
     if (!wndPtr) return 0;
     dlgInfo = (DIALOGINFO *)&wndPtr->wExtra;
 
-    dprintf_dialog(stddeb, "DefDlgProc: %d %04x %d %08lx\n", 
-		   hwnd, msg, wParam, lParam );
+    dprintf_dialog(stddeb, "DefDlgProc: "NPFMT" %04x %ld %08lx\n", 
+		   hwnd, msg, (DWORD)wParam, lParam );
 
     dlgInfo->msgResult = 0;
     if (dlgInfo->dlgProc)
@@ -197,7 +197,7 @@
 
 	case WM_NEXTDLGCTL:
 	    {
-                HWND hwndDest = wParam;
+                HWND hwndDest = (HWND)wParam;
                 if (!lParam)
                 {
                     HWND hwndPrev = GetFocus();
diff --git a/windows/defwnd.c b/windows/defwnd.c
index 6263dd5..1479b68 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -15,10 +15,12 @@
 #include "stddebug.h"
 /* #define DEBUG_MESSAGE */
 #include "debug.h"
+#include "spy.h"
 
   /* Last COLOR id */
 #define COLOR_MAX   COLOR_BTNHIGHLIGHT
 
+
 /***********************************************************************
  *           DEFWND_SetText
  *
@@ -40,15 +42,14 @@
 /***********************************************************************
  *           DefWindowProc   (USER.107)
  */
-LONG DefWindowProc( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
+LRESULT DefWindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
     CLASS * classPtr;
     LPSTR textPtr;
     int len;
     WND * wndPtr = WIN_FindWndPtr( hwnd );
-    
-    dprintf_message(stddeb, "DefWindowProc: %d %d %d %08lx\n", 
-		    hwnd, msg, wParam, lParam );
+
+    EnterSpyMessage(SPY_DEFWNDPROC,hwnd,msg,wParam,lParam);
 
     switch(msg)
     {
@@ -120,7 +121,8 @@
 	return MA_ACTIVATE;
 
     case WM_ACTIVATE:
-	if (wParam) SetFocus( hwnd );
+      /* LOWORD() needed for WINELIB32 implementation.  Should be fine. */
+	if (LOWORD(wParam)!=WA_INACTIVE) SetFocus( hwnd );
 	break;
 
     case WM_WINDOWPOSCHANGING:
@@ -145,11 +147,11 @@
 	{
 	    if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
 	    if (!classPtr->wc.hbrBackground) return 0;
-            if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
+            if (classPtr->wc.hbrBackground <= (HBRUSH)(COLOR_MAX+1))
             {
                  HBRUSH hbrush;
                  hbrush = CreateSolidBrush(
-                     GetSysColor(classPtr->wc.hbrBackground-1));
+                     GetSysColor(((DWORD)classPtr->wc.hbrBackground)-1));
                  FillWindow( GetParent(hwnd), hwnd, (HDC)wParam, hbrush);
                  DeleteObject (hbrush);
             }
@@ -162,6 +164,22 @@
     case WM_GETDLGCODE:
 	return 0;
 
+    case WM_CTLCOLORMSGBOX:
+    case WM_CTLCOLOREDIT:
+    case WM_CTLCOLORLISTBOX:
+    case WM_CTLCOLORBTN:
+    case WM_CTLCOLORDLG:
+    case WM_CTLCOLORSTATIC:
+        SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
+        SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
+        return (LONG)sysColorObjects.hbrushWindow;
+
+    case WM_CTLCOLORSCROLLBAR:
+        SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
+        SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
+        UnrealizeObject( sysColorObjects.hbrushScrollbar );
+        return (LONG)sysColorObjects.hbrushScrollbar;
+
     case WM_CTLCOLOR:
 	{
 	    if (HIWORD(lParam) == CTLCOLOR_SCROLLBAR)
@@ -169,13 +187,13 @@
 		SetBkColor( (HDC)wParam, RGB(255, 255, 255) );
 		SetTextColor( (HDC)wParam, RGB(0, 0, 0) );
 		UnrealizeObject( sysColorObjects.hbrushScrollbar );
-		return sysColorObjects.hbrushScrollbar;
+		return (LONG)sysColorObjects.hbrushScrollbar;
 	    }
 	    else
 	    {
 		SetBkColor( (HDC)wParam, GetSysColor(COLOR_WINDOW) );
 		SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
-		return sysColorObjects.hbrushWindow;
+		return (LONG)sysColorObjects.hbrushWindow;
 	    }
 	}
 	
diff --git a/windows/dialog.c b/windows/dialog.c
index b6a3d31..8dc29c4 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -218,7 +218,7 @@
     HGLOBAL hmem;
     SEGPTR data;
 
-    dprintf_dialog(stddeb, "CreateDialogParam: %d,%08lx,%d,%08lx,%ld\n",
+    dprintf_dialog(stddeb, "CreateDialogParam: "NPFMT",%08lx,"NPFMT",%08lx,%ld\n",
 	    hInst, dlgTemplate, owner, (DWORD)dlgProc, param );
      
     if (!(hRsrc = FindResource( hInst, dlgTemplate, RT_DIALOG ))) return 0;
@@ -303,7 +303,8 @@
     rect.right = template.header.cx * xUnit / 4;
     rect.bottom = template.header.cy * yUnit / 8;
     if (template.header.style & DS_MODALFRAME) exStyle |= WS_EX_DLGMODALFRAME;
-    AdjustWindowRectEx( &rect, template.header.style, hMenu, exStyle );
+    AdjustWindowRectEx( &rect, template.header.style, 
+			hMenu ? TRUE : FALSE , exStyle );
     rect.right -= rect.left;
     rect.bottom -= rect.top;
 
@@ -393,8 +394,8 @@
                                       header->y * yUnit / 8,
                                       header->cx * xUnit / 4,
                                       header->cy * yUnit / 8,
-                                      hwnd, header->id, dlgInfo->hDialogHeap,
-                                      (SEGPTR)0 );
+                                      hwnd, (HMENU)header->id,
+                                      dlgInfo->hDialogHeap, (SEGPTR)0 );
 	}
 	else
         {
@@ -404,7 +405,8 @@
                                       header->y * yUnit / 8,
                                       header->cx * xUnit / 4,
                                       header->cy * yUnit / 8,
-                                      hwnd, header->id, hInst, (SEGPTR)0 );
+                                      hwnd, (HMENU)header->id,
+                                      hInst, (SEGPTR)0 );
 	}
 
         /* Make the control last one in Z-order, so that controls remain
@@ -413,7 +415,7 @@
                       SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
 
             /* Send initialisation messages to the control */
-        if (hFont) SendMessage( hwndCtrl, WM_SETFONT, hFont, 0 );
+        if (hFont) SendMessage( hwndCtrl, WM_SETFONT, (WPARAM)hFont, 0 );
         if (SendMessage( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
         {
               /* If there's already a default push-button, set it back */
@@ -439,8 +441,8 @@
       /* Send initialisation messages and set focus */
 
     if (dlgInfo->hUserFont)
-	SendMessage( hwnd, WM_SETFONT, dlgInfo->hUserFont, 0 );
-    if (SendMessage( hwnd, WM_INITDIALOG, dlgInfo->hwndFocus, param ))
+	SendMessage( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
+    if (SendMessage( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
 	SetFocus( dlgInfo->hwndFocus );
     if (template.header.style & WS_VISIBLE) ShowWindow(hwnd, SW_SHOW);
     return hwnd;
@@ -504,7 +506,7 @@
 {
     HWND hwnd;
     
-    dprintf_dialog(stddeb, "DialogBoxParam: %d,%08lx,%d,%08lx,%ld\n",
+    dprintf_dialog(stddeb, "DialogBoxParam: "NPFMT",%08lx,"NPFMT",%08lx,%ld\n",
 	    hInst, dlgTemplate, owner, (DWORD)dlgProc, param );
     hwnd = CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, param );
     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
@@ -531,7 +533,7 @@
     HWND hwnd;
     SEGPTR ptr;
 
-    if (!(ptr = WIN16_GlobalLock( dlgTemplate ))) return -1;
+    if (!(ptr = (SEGPTR)WIN16_GlobalLock( dlgTemplate ))) return -1;
     hwnd = CreateDialogIndirectParam( hInst, ptr, owner, dlgProc, param );
     GlobalUnlock( dlgTemplate );
     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
@@ -548,7 +550,7 @@
     DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
     dlgInfo->msgResult = retval;
     dlgInfo->fEnd = TRUE;
-    dprintf_dialog(stddeb, "EndDialog: %d %d\n", hwnd, retval );
+    dprintf_dialog(stddeb, "EndDialog: "NPFMT" %d\n", hwnd, retval );
 }
 
 
@@ -610,20 +612,36 @@
             break;
 
         case VK_ESCAPE:
+#ifdef WINELIB32
+            SendMessage( hwndDlg, WM_COMMAND, 
+			 MAKEWPARAM( IDCANCEL, 0 ),
+                         (LPARAM)GetDlgItem(hwndDlg,IDCANCEL) );
+#else
             SendMessage( hwndDlg, WM_COMMAND, IDCANCEL,
                          MAKELPARAM( GetDlgItem(hwndDlg,IDCANCEL), 0 ));
+#endif
             break;
 
         case VK_RETURN:
             {
                 DWORD dw = SendMessage( hwndDlg, DM_GETDEFID, 0, 0 );
                 if (HIWORD(dw) == DC_HASDEFID)
+#ifdef WINELIB32
+                    SendMessage( hwndDlg, WM_COMMAND, 
+				 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
+                                 (LPARAM)GetDlgItem( hwndDlg, LOWORD(dw) ) );
+                else
+                    SendMessage( hwndDlg, WM_COMMAND, 
+				 MAKEWPARAM( IDOK, 0 ),
+                                 (LPARAM)GetDlgItem(hwndDlg,IDOK) );
+#else
                     SendMessage( hwndDlg, WM_COMMAND, LOWORD(dw),
                                  MAKELPARAM( GetDlgItem( hwndDlg, LOWORD(dw) ),
                                              BN_CLICKED ));
                 else
                     SendMessage( hwndDlg, WM_COMMAND, IDOK,
                                  MAKELPARAM( GetDlgItem(hwndDlg,IDOK), 0 ));
+#endif
             }
             break;
         }
@@ -681,7 +699,7 @@
 /*******************************************************************
  *           SendDlgItemMessage   (USER.101)
  */
-LONG SendDlgItemMessage(HWND hwnd, WORD id, UINT msg, WORD wParam, LONG lParam)
+LRESULT SendDlgItemMessage(HWND hwnd, INT id, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     HWND hwndCtrl = GetDlgItem( hwnd, id );
     if (hwndCtrl) return SendMessage( hwndCtrl, msg, wParam, lParam );
diff --git a/windows/event.c b/windows/event.c
index 837d284..a91d248 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -118,8 +118,7 @@
 
 static BOOL KeyDown = FALSE;
 
-
-static char *event_names[] =
+static const char *event_names[] =
 {
     "", "", "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease",
     "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut",
@@ -157,7 +156,7 @@
     XFindContext( display, ((XAnyEvent *)event)->window, winContext, &ptr );
     hwnd = (HWND) (int)ptr;
 
-    dprintf_event(stddeb, "Got event %s for hwnd %d\n", 
+    dprintf_event(stddeb, "Got event %s for hwnd "NPFMT"\n",
 		  event_names[event->type], hwnd );
 
     switch(event->type)
@@ -214,7 +213,7 @@
 	break;
 
     default:    
-	dprintf_event(stddeb, "Unprocessed event %s for hwnd %d\n",
+	dprintf_event(stddeb, "Unprocessed event %s for hwnd "NPFMT"\n",
 	        event_names[event->type], hwnd );
 	break;
     }
@@ -397,6 +396,26 @@
 
 
 /***********************************************************************
+ *           EVENT_DummyMotionNotify
+ *
+ * Generate a dummy MotionNotify event. Used to force a WM_SETCURSOR message.
+ */
+void EVENT_DummyMotionNotify(void)
+{
+    Window root, child;
+    int rootX, rootY, childX, childY;
+    unsigned int state;
+
+    if (XQueryPointer( display, rootWindow, &root, &child,
+                       &rootX, &rootY, &childX, &childY, &state ))
+    {
+        hardware_event(WM_MOUSEMOVE, EVENT_XStateToKeyState( state ), 0L,
+                       rootX - desktopX, rootY - desktopY, GetTickCount(), 0 );
+    }
+}
+
+
+/***********************************************************************
  *           EVENT_ButtonPress
  */
 static void EVENT_ButtonPress( XButtonEvent *event )
@@ -539,7 +558,7 @@
                      GrabModeAsync, GrabModeAsync,
                      None, None, CurrentTime ) == GrabSuccess)
     {
-	dprintf_win(stddeb, "SetCapture: %04x\n", hwnd);
+	dprintf_win(stddeb, "SetCapture: "NPFMT"\n", hwnd);
 	captureWnd   = hwnd;
 	return old_capture_wnd;
     }
diff --git a/windows/focus.c b/windows/focus.c
index 7dc8897..141bede 100644
--- a/windows/focus.c
+++ b/windows/focus.c
@@ -83,10 +83,12 @@
 
     hWndPrevFocus = hWndFocus;
     hWndFocus = hwnd;    
-    if (hWndPrevFocus) SendMessage( hWndPrevFocus, WM_KILLFOCUS, hwnd, 0 );
+    if (hWndPrevFocus) SendMessage( hWndPrevFocus, WM_KILLFOCUS, 
+				    (WPARAM)hwnd, 0 );
     if (hwnd == hWndFocus)  /* Maybe already changed during WM_KILLFOCUS */
     {
-	if (hwnd) SendMessage( hWndFocus, WM_SETFOCUS, hWndPrevFocus, 0 );
+	if (hwnd) SendMessage( hWndFocus, WM_SETFOCUS, 
+			       (WPARAM)hWndPrevFocus, 0 );
 	FOCUS_SetXFocus( hwnd );
     }
     return hWndPrevFocus;
diff --git a/windows/graphics.c b/windows/graphics.c
index d623752..608fbea 100644
--- a/windows/graphics.c
+++ b/windows/graphics.c
@@ -693,19 +693,17 @@
 BOOL GRAPH_DrawBitmap( HDC hdc, HBITMAP hbitmap, int xdest, int ydest,
 		       int xsrc, int ysrc, int width, int height )
 {
-    XGCValues val;
     BITMAPOBJ *bmp;
     DC *dc;
     
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
     if (!(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
 	return FALSE;
-    val.function   = GXcopy;
-    val.foreground = dc->w.textPixel;
-    val.background = dc->w.backgroundPixel;
-    XChangeGC(display, dc->u.x.gc, GCFunction|GCForeground|GCBackground, &val);
+    XSetFunction( display, dc->u.x.gc, GXcopy );
     if (bmp->bitmap.bmBitsPixel == 1)
     {
+        XSetForeground( display, dc->u.x.gc, dc->w.backgroundPixel );
+        XSetBackground( display, dc->u.x.gc, dc->w.textPixel );
 	XCopyPlane( display, bmp->pixmap, dc->u.x.drawable, dc->u.x.gc,
 		    xsrc, ysrc, width, height,
 		    dc->w.DCOrgX + xdest, dc->w.DCOrgY + ydest, 1 );
@@ -980,7 +978,7 @@
     RECT rect;
     DC *dc;
 
-    dprintf_graphics( stddeb, "ExtFloodFill %x %d,%d %06lx %d\n",
+    dprintf_graphics( stddeb, "ExtFloodFill "NPFMT" %d,%d %06lx %d\n",
                       hdc, x, y, color, fillType );
     dc = (DC *) GDI_GetObjPtr(hdc, DC_MAGIC);
     if (!dc) 
diff --git a/windows/hook.c b/windows/hook.c
index d4fe2eb..08472af 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -52,7 +52,11 @@
     if (data->proc == hproc) {
       hhook = *prevHook;
       *prevHook = data->next;
+#ifdef WINELIB32
+      USER_HEAP_FREE((HANDLE)hhook);
+#else
       USER_HEAP_FREE(LOWORD(hhook));
+#endif
       return TRUE;
     }
   }
@@ -62,7 +66,11 @@
     if (data->proc == hproc) {
       hhook = *prevHook;
       *prevHook = data->next;
+#ifdef WINELIB32
+      USER_HEAP_FREE((HANDLE)hhook);
+#else
       USER_HEAP_FREE(LOWORD(hhook));
+#endif
       return TRUE;
     }
   }
@@ -84,8 +92,9 @@
  */
 BOOL CallMsgFilter( SEGPTR msg, short code )
 {
-    if (CALL_SYSTEM_HOOK( WH_SYSMSGFILTER, code, 0, (LPARAM)msg )) return TRUE;
-    else return CALL_TASK_HOOK( WH_MSGFILTER, code, 0, (LPARAM)msg );
+    if (CALL_TASK_HOOK( WH_MSGFILTER, code, 0, (LPARAM)msg )) 
+	return TRUE;
+    return CALL_SYSTEM_HOOK( WH_SYSMSGFILTER, code, 0, (LPARAM)msg );
 }
 
 
@@ -100,7 +109,8 @@
 
     if ((id < FIRST_HOOK) || (id > LAST_HOOK)) return 0;
     if (id != WH_GETMESSAGE && id != WH_CALLWNDPROC) {
-	fprintf( stdnimp, "Unimplemented hook set: %d!\n", id );
+	fprintf( stdnimp, "Unimplemented hook set: (%d,%08lx,%04x,%04x)!\n",
+                 id, (DWORD)proc, hinst, htask );
     }
     if (htask)  /* Task-specific hook */
     {
@@ -121,7 +131,7 @@
     data->proc  = proc;
     data->id    = id;
     data->htask = htask;
-    *prevHook   = USER_HEAP_SEG_ADDR(handle);
+    *prevHook   = (HHOOK)USER_HEAP_SEG_ADDR(handle);
     return *prevHook;
 }
 
@@ -141,7 +151,11 @@
     }
     if (!*prevHook) return FALSE;
     *prevHook = data->next;
+#ifdef WINELIB32
+    USER_HEAP_FREE( (HANDLE)hhook );
+#else
     USER_HEAP_FREE( hhook & 0xffff );
+#endif
     return TRUE;
 }
 
diff --git a/windows/mapping.c b/windows/mapping.c
index 74b91f3..5e66819 100644
--- a/windows/mapping.c
+++ b/windows/mapping.c
@@ -86,7 +86,7 @@
 	return 1;
     }
 
-    dprintf_gdi(stddeb, "SetMapMode: %d %d\n", hdc, mode );
+    dprintf_gdi(stddeb, "SetMapMode: "NPFMT" %d\n", hdc, mode );
     
     prevMode = dc->w.MapMode;
     switch(mode)
diff --git a/windows/mdi.c b/windows/mdi.c
index de7ded7..76f6d87 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -27,7 +27,7 @@
     char buffer[128];
     int id, n, index;
 
-    dprintf_mdi(stddeb, "MDIRecreateMenuList: hWindowMenu %0x\n", 
+    dprintf_mdi(stddeb, "MDIRecreateMenuList: hWindowMenu "NPFMT"\n", 
 	    ci->hWindowMenu);
     
     id = ci->idFirstChild; 
@@ -66,7 +66,7 @@
  */
 HMENU MDISetMenu(HWND hwnd, BOOL fRefresh, HMENU hmenuFrame, HMENU hmenuWindow)
 {
-    dprintf_mdi(stddeb, "WM_MDISETMENU: %04x %04x %04x %04x\n", hwnd, fRefresh, hmenuFrame, hmenuWindow);
+    dprintf_mdi(stddeb, "WM_MDISETMENU: "NPFMT" %04x "NPFMT" "NPFMT"\n", hwnd, fRefresh, hmenuFrame, hmenuWindow);
     if (!fRefresh) {
 	HWND hwndFrame = GetParent(hwnd);
 	HMENU oldFrameMenu = GetMenu(hwndFrame);
@@ -112,7 +112,7 @@
 			  WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU |
 			  WS_THICKFRAME | WS_VISIBLE | cs->style,
 			  cs->x, cs->y, cs->cx, cs->cy, parent, (HMENU) 0,
-			  w->hInstance, lParam);
+			  w->hInstance, (SEGPTR)lParam);
 
     if (hwnd)
     {
@@ -215,7 +215,7 @@
 	{
 	    while (hinfo != 0) {
 		chi = (MDICHILDINFO *)USER_HEAP_LIN_ADDR(hinfo);
-		if (chi->hwnd == id) break;
+		if (chi->hwnd == (HWND)id) break;
 	        hinfo = chi->next;
 	    }
 	}
@@ -223,7 +223,7 @@
 	if (hinfo == 0)
 	    return;
 
-	dprintf_mdi(stddeb, "MDIBringToTop: child %04x\n", chi->hwnd);
+	dprintf_mdi(stddeb, "MDIBringToTop: child "NPFMT"\n", chi->hwnd);
 	if (hinfo != ci->infoActiveChildren)
 	{
 	    if (ci->flagChildMaximized)
@@ -285,7 +285,7 @@
 	    SendMessage(parent, WM_CHILDACTIVATE, 0, 0);
 	}
 	
-	dprintf_mdi(stddeb, "MDIBringToTop: pos %04x, hwnd %04x\n", 
+	dprintf_mdi(stddeb, "MDIBringToTop: pos %04x, hwnd "NPFMT"\n", 
 		id, chi->hwnd);
     }
 }
@@ -354,17 +354,17 @@
     HWND          act_hwnd;
     LONG          lParam;
 
-    dprintf_mdi(stddeb, "MDIChildActivate: top %04x\n", w->hwndChild);
+    dprintf_mdi(stddeb, "MDIChildActivate: top "NPFMT"\n", w->hwndChild);
 
     hinfo = ci->infoActiveChildren;
     if (hinfo)
     {
 	chi = (MDICHILDINFO *)USER_HEAP_LIN_ADDR(hinfo);
 	deact_hwnd = ci->hwndActiveChild;
-	act_hwnd   = chi->hwnd;
-	lParam     = ((LONG) deact_hwnd << 16) | act_hwnd;
+	act_hwnd   = chi->hwnd;                /* FIX: Hack */
+	lParam     = ((LONG) deact_hwnd << 16) | (LONG)act_hwnd;
 
-	dprintf_mdi(stddeb, "MDIChildActivate: deact %04x, act %04x\n",
+	dprintf_mdi(stddeb, "MDIChildActivate: deact "NPFMT", act "NPFMT"\n",
 	       deact_hwnd, act_hwnd);
 
 	ci->hwndActiveChild = act_hwnd;
@@ -424,13 +424,13 @@
 	hinfo = chi->next;
     }
     
-    dprintf_mdi(stddeb, "MDICascade: last child is %04x\n", chi->hwnd);
+    dprintf_mdi(stddeb, "MDICascade: last child is "NPFMT"\n", chi->hwnd);
     x = 0;
     y = 0;
     while (hinfo != 0)
     {
 	chi = USER_HEAP_LIN_ADDR(hinfo);
-	dprintf_mdi(stddeb, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n", 
+	dprintf_mdi(stddeb, "MDICascade: move "NPFMT" to (%d,%d) size [%d,%d]\n", 
 		chi->hwnd, x, y, xsize, ysize);
         if (IsIconic(chi->hwnd)) continue;
 	SetWindowPos(chi->hwnd, 0, x, y, xsize, ysize, 
@@ -556,7 +556,7 @@
     w  = WIN_FindWndPtr(hwndClient);
     ci = (MDICLIENTINFO *) w->wExtra;
 
-    dprintf_mdi(stddeb, "MDIPaintMaximized: frame %04x,  client %04x"
+    dprintf_mdi(stddeb, "MDIPaintMaximized: frame "NPFMT",  client "NPFMT
 		",  max flag %d,  menu %04x\n", hwndFrame, hwndClient, 
 		ci->flagChildMaximized, wndPtr ? wndPtr->wIDmenu : 0);
 
@@ -576,8 +576,8 @@
 	}
 
 	dprintf_mdi(stddeb, 
-		    "MDIPaintMaximized: hdcMem %04x, close bitmap %04x, "
-		    "maximized bitmap %04x\n",
+		    "MDIPaintMaximized: hdcMem "NPFMT", close bitmap "NPFMT", "
+		    "maximized bitmap "NPFMT"\n",
 		    hdcMem, hbitmapClose, hbitmapMaximized);
 
 	NC_GetInsideRect(hwndFrame, &rect);
@@ -617,7 +617,7 @@
  *
  * This function is the handler for all MDI requests.
  */
-LONG MDIClientWndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+LRESULT MDIClientWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     LPCREATESTRUCT       cs;
     LPCLIENTCREATESTRUCT ccs;
@@ -656,7 +656,7 @@
 	return MDICascade(hwnd, ci);
 
       case WM_MDICREATE:
-	return MDICreateChild(w, ci, hwnd, lParam );
+	return (LONG)MDICreateChild(w, ci, hwnd, lParam );
 
       case WM_MDIDESTROY:
 	return MDIDestroyChild(w, ci, hwnd, wParam, TRUE);
@@ -690,7 +690,11 @@
 	
       case WM_PARENTNOTIFY:
 	if (wParam == WM_DESTROY)
+#ifdef WINELIB32
+	    return MDIDestroyChild(w, ci, hwnd, lParam, FALSE);
+#else
 	    return MDIDestroyChild(w, ci, hwnd, LOWORD(lParam), FALSE);
+#endif
 	else if (wParam == WM_LBUTTONDOWN)
 	    MDIBringChildToTop(hwnd, ci->hwndHitTest, FALSE, FALSE);
 	break;
@@ -708,8 +712,8 @@
  *					DefFrameProc (USER.445)
  *
  */
-LONG DefFrameProc(HWND hwnd, HWND hwndMDIClient, WORD message, 
-		  WORD wParam, LONG lParam)
+LRESULT DefFrameProc(HWND hwnd, HWND hwndMDIClient, UINT message, 
+		     WPARAM wParam, LPARAM lParam)
 {
     if (hwndMDIClient)
     {
@@ -751,7 +755,11 @@
  *					DefMDIChildProc (USER.447)
  *
  */
+#ifdef WINELIB32
+LONG DefMDIChildProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+#else
 LONG DefMDIChildProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+#endif
 {
     MDICLIENTINFO       *ci;
     WND                 *w;
@@ -773,10 +781,10 @@
 	switch (wParam)
 	{
 	  case SC_MAXIMIZE:
-	    return SendMessage(GetParent(hwnd), WM_MDIMAXIMIZE, hwnd, 0);
+	    return SendMessage(GetParent(hwnd), WM_MDIMAXIMIZE, (WPARAM)hwnd, 0);
 
 	  case SC_RESTORE:
-	    return SendMessage(GetParent(hwnd), WM_MDIRESTORE, hwnd, 0);
+	    return SendMessage(GetParent(hwnd), WM_MDIRESTORE, (WPARAM)hwnd, 0);
 	}
 	break;
 	
diff --git a/windows/message.c b/windows/message.c
index 72cb9ab..adefb14 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -15,6 +15,7 @@
 #include "sysmetrics.h"
 #include "hook.h"
 #include "event.h"
+#include "spy.h"
 #include "winpos.h"
 #include "atom.h"
 #include "dde.h"
@@ -137,7 +138,7 @@
 {
     int i, pos = msgQueue->nextMessage;
 
-    dprintf_msg(stddeb,"MSG_FindMsg: hwnd=0x%04x\n\n", hwnd );
+    dprintf_msg(stddeb,"MSG_FindMsg: hwnd=0x"NPFMT"\n\n", hwnd );
 
     if (!msgQueue->msgCount) return -1;
     if (!hwnd && !first && !last) return pos;
@@ -310,7 +311,7 @@
 
         /* Send the WM_PARENTNOTIFY message */
 
-        if (mouseClick) WIN_SendParentNotify( msg->hwnd, msg->message,
+        if (mouseClick) WIN_SendParentNotify( msg->hwnd, msg->message, 0,
                                             MAKELONG( msg->pt.x, msg->pt.y ) );
 
         /* Activate the window if needed */
@@ -320,7 +321,8 @@
             HWND hwndTop = WIN_GetTopParent( msg->hwnd );
             if (hwndTop != GetActiveWindow())
             {
-                LONG ret = SendMessage( msg->hwnd, WM_MOUSEACTIVATE, hwndTop,
+                LONG ret = SendMessage( msg->hwnd, WM_MOUSEACTIVATE,
+					(WPARAM)hwndTop,
                                         MAKELONG( hittest, msg->message ) );
                 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
                     eatMsg = TRUE;
@@ -336,7 +338,7 @@
 
       /* Send the WM_SETCURSOR message */
 
-    SendMessage( msg->hwnd, WM_SETCURSOR, msg->hwnd,
+    SendMessage( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
                  MAKELONG( hittest, msg->message ));
     if (eatMsg) return FALSE;
 
@@ -954,8 +956,8 @@
 {
     MSG_PeekMessage( (MSG *)PTR_SEG_TO_LIN(msg),
                      hwnd, first, last, PM_REMOVE, FALSE );
-    CALL_SYSTEM_HOOK( WH_GETMESSAGE, 0, 0, (LPARAM)msg );
     CALL_TASK_HOOK( WH_GETMESSAGE, 0, 0, (LPARAM)msg );
+    CALL_SYSTEM_HOOK( WH_GETMESSAGE, 0, 0, (LPARAM)msg );
     return (((MSG *)PTR_SEG_TO_LIN(msg))->message != WM_QUIT);
 }
 
@@ -988,7 +990,7 @@
       while (hwnd) {
 	if (!(wndPtr = WIN_FindWndPtr(hwnd))) break;
 	if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION) {
-	  dprintf_msg(stddeb,"BROADCAST Message to hWnd=%04X m=%04X w=%04X l=%08lX !\n",
+	  dprintf_msg(stddeb,"BROADCAST Message to hWnd="NPFMT" m=%04X w=%04X l=%08lX !\n",
 		      hwnd, message, wParam, lParam);
 	  PostMessage(hwnd, message, wParam, lParam);
 	}
@@ -1027,16 +1029,16 @@
 /***********************************************************************
  *           SendMessage   (USER.111)
  */
-LONG SendMessage( HWND hwnd, WORD msg, WORD wParam, LONG lParam )
+LRESULT SendMessage( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
     WND * wndPtr;
     LONG ret;
     struct
     {
-	LONG lParam;
-	WORD wParam;
-	WORD wMsg;
-	WORD hWnd;
+	LPARAM lParam;
+	WPARAM wParam;
+	UINT wMsg;
+	HWND hWnd;
     } msgstruct = { lParam, wParam, msg, hwnd };
 
 #ifdef CONFIG_IPC
@@ -1053,8 +1055,8 @@
             if (!(wndPtr = WIN_FindWndPtr(hwnd))) break;
             if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
             {
-                dprintf_msg(stddeb,"BROADCAST Message to hWnd=%04X m=%04X w=%04X l=%08lX !\n",
-                            hwnd, msg, wParam, lParam);
+                dprintf_msg(stddeb,"BROADCAST Message to hWnd="NPFMT" m=%04X w=%04lX l=%08lX !\n",
+                            hwnd, msg, (DWORD)wParam, lParam);
                  ret |= SendMessage( hwnd, msg, wParam, lParam );
 	    }
             hwnd = wndPtr->hwndNext;
@@ -1063,13 +1065,18 @@
         return TRUE;
     }
 
-    CALL_SYSTEM_HOOK( WH_CALLWNDPROC, 0, 0, MAKE_SEGPTR(&msgstruct) );
-    CALL_TASK_HOOK( WH_CALLWNDPROC, 0, 0, MAKE_SEGPTR(&msgstruct) );
-    if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
+    EnterSpyMessage(SPY_SENDMESSAGE, hwnd, msg, wParam, lParam);
+
+    CALL_TASK_HOOK( WH_CALLWNDPROC, HC_ACTION, 1, MAKE_SEGPTR(&msgstruct) );
+    CALL_SYSTEM_HOOK( WH_CALLWNDPROC, HC_ACTION, 1, MAKE_SEGPTR(&msgstruct) );
+    if (!(wndPtr = WIN_FindWndPtr( hwnd ))) 
+    {
+        ExitSpyMessage(SPY_RESULT_INVALIDHWND,hwnd,msg,0);
+        return 0;
+    }
     ret = CallWindowProc( wndPtr->lpfnWndProc, msgstruct.hWnd, msgstruct.wMsg,
                           msgstruct.wParam, msgstruct.lParam );
-    dprintf_msg( stddeb,"SendMessage(%4.4x,%x,%x,%lx) -> %lx\n",
-                 hwnd, msg, wParam, lParam, ret );
+    ExitSpyMessage(SPY_RESULT_OK,hwnd,msg,ret);
     return ret;
 }
 
@@ -1126,17 +1133,16 @@
     LONG retval;
     int painting;
     
-    dprintf_msg(stddeb, "Dispatch message hwnd=%04x msg=0x%x w=%d l=%ld time=%lu pt=%d,%d\n",
-	    msg->hwnd, msg->message, msg->wParam, msg->lParam, 
-	    msg->time, msg->pt.x, msg->pt.y );
+    EnterSpyMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
+                     msg->wParam, msg->lParam );
 
       /* Process timer messages */
     if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
     {
 	if (msg->lParam)
         {
-            WORD ds = msg->hwnd ? GetWindowWord( msg->hwnd, GWW_HINSTANCE )
-                                : CURRENT_DS;
+            HINSTANCE ds = msg->hwnd ? WIN_GetWindowInstance( msg->hwnd )
+                                     : (HINSTANCE)CURRENT_DS;
 	    return CallWndProc( (WNDPROC)msg->lParam, ds, msg->hwnd,
                                 msg->message, msg->wParam, GetTickCount() );
         }
@@ -1152,7 +1158,7 @@
     if (painting && IsWindow(msg->hwnd) &&
         (wndPtr->flags & WIN_NEEDS_BEGINPAINT))
     {
-	fprintf(stderr, "BeginPaint not called on WM_PAINT for hwnd %d!\n", 
+	fprintf(stderr, "BeginPaint not called on WM_PAINT for hwnd "NPFMT"!\n", 
 		msg->hwnd);
 	wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
     }
@@ -1207,7 +1213,7 @@
 
 
 /***********************************************************************
- *           GetTickCount    (USER.13)
+ *           GetTickCount    (USER.13) (KERNEL32.299)
  */
 DWORD GetTickCount(void)
 {
diff --git a/windows/msgbox.c b/windows/msgbox.c
index 05bc09c..e0cd46c 100644
--- a/windows/msgbox.c
+++ b/windows/msgbox.c
@@ -11,6 +11,7 @@
 #include "selectors.h"
 #include "alias.h"
 #include "relay32.h"
+#include "win.h"
 #include "../rc/sysres.h"
 #include "task.h"
 
@@ -20,7 +21,7 @@
   WORD  type;
 } MSGBOX, *LPMSGBOX;
 
-LONG SystemMessageBoxProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
+LRESULT SystemMessageBoxProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
 {
   LPMSGBOX lpmb;
   RECT rect, textrect;
@@ -68,17 +69,21 @@
     /* Set the icon */
     switch(lpmb->type & MB_ICONMASK) {
      case MB_ICONEXCLAMATION:
-      SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_EXCLAMATION), 0);
+      SendDlgItemMessage(hwnd, stc1, STM_SETICON, 
+			 (WPARAM)LoadIcon(0, IDI_EXCLAMATION), 0);
       break;
      case MB_ICONQUESTION:
-      SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_QUESTION), 0);
+      SendDlgItemMessage(hwnd, stc1, STM_SETICON, 
+			 (WPARAM)LoadIcon(0, IDI_QUESTION), 0);
       break;
      case MB_ICONASTERISK:
-      SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_ASTERISK), 0);
+      SendDlgItemMessage(hwnd, stc1, STM_SETICON, 
+			 (WPARAM)LoadIcon(0, IDI_ASTERISK), 0);
       break;
      case MB_ICONHAND:
      default:
-      SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_HAND), 0);
+      SendDlgItemMessage(hwnd, stc1, STM_SETICON, 
+			 (WPARAM)LoadIcon(0, IDI_HAND), 0);
       break;
     }
     
@@ -200,7 +205,7 @@
                                  sysres_DIALOG_MSGBOX.size, GetCurrentPDB(),
                                  FALSE, FALSE, TRUE, NULL );
     if (!handle) return 0;
-    ret = DialogBoxIndirectParam( GetWindowWord(hWnd, GWW_HINSTANCE),
+    ret = DialogBoxIndirectParam( WIN_GetWindowInstance(hWnd),
                                   handle, hWnd,
                                   GetWndProcEntry16("SystemMessageBoxProc"),
                                   (LONG)&mbox );
diff --git a/windows/nonclient.c b/windows/nonclient.c
index a192262..aa77bef 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -170,7 +170,7 @@
 	pMinMax = (MINMAXINFO *) USER_HEAP_LIN_ADDR( minmaxHandle );
 	memcpy( pMinMax, &MinMax, sizeof(MinMax) );	
 	SendMessage( hwnd, WM_GETMINMAXINFO, 0,
-                     USER_HEAP_SEG_ADDR(minmaxHandle) );
+                     (LPARAM)USER_HEAP_SEG_ADDR(minmaxHandle) );
     }
     else pMinMax = &MinMax;
 
@@ -260,7 +260,7 @@
     WND *wndPtr = WIN_FindWndPtr( hwnd );
     if (!wndPtr) return HTERROR;
 
-    dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd=%x pt=%d,%d\n", 
+    dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd="NPFMT" pt=%d,%d\n",
 		      hwnd, pt.x, pt.y );
 
     GetWindowRect( hwnd, &rect );
@@ -624,7 +624,7 @@
 
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
-    dprintf_nonclient(stddeb, "NC_DoNCPaint: %x %d\n", hwnd, active );
+    dprintf_nonclient(stddeb, "NC_DoNCPaint: "NPFMT" %d\n", hwnd, active );
     if (!wndPtr || !(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
 
     if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
@@ -639,7 +639,7 @@
         HICON hIcon = WIN_CLASS_INFO(wndPtr).hIcon;
         if (hIcon)  
         {
-            SendMessage(hwnd, WM_ICONERASEBKGND, hdc, 0);
+            SendMessage(hwnd, WM_ICONERASEBKGND, (WPARAM)hdc, 0);
             DrawIcon(hdc, 0, 0, hIcon);
         }
         ReleaseDC(hwnd, hdc);
@@ -730,9 +730,9 @@
  *
  * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
  */
-LONG NC_HandleNCActivate( HWND hwnd, WORD wParam )
+LONG NC_HandleNCActivate( HWND hwnd, WPARAM wParam )
 {
-    NC_DoNCPaint( hwnd, wParam, FALSE );
+    NC_DoNCPaint( hwnd, (wParam != 0), FALSE );
     return TRUE;
 }
 
@@ -742,9 +742,9 @@
  *
  * Handle a WM_SETCURSOR message. Called from DefWindowProc().
  */
-LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam )
+LONG NC_HandleSetCursor( HWND hwnd, WPARAM wParam, LPARAM lParam )
 {
-    if (hwnd != wParam) return 0;  /* Don't set the cursor for child windows */
+    if (hwnd != (HWND)wParam) return 0;  /* Don't set the cursor for child windows */
 
     switch(LOWORD(lParam))
     {
@@ -773,23 +773,23 @@
 
     case HTLEFT:
     case HTRIGHT:
-	return SetCursor( LoadCursor( 0, IDC_SIZEWE ) );
+	return (LONG)SetCursor( LoadCursor( 0, IDC_SIZEWE ) );
 
     case HTTOP:
     case HTBOTTOM:
-	return SetCursor( LoadCursor( 0, IDC_SIZENS ) );
+	return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENS ) );
 
     case HTTOPLEFT:
     case HTBOTTOMRIGHT:	
-	return SetCursor( LoadCursor( 0, IDC_SIZENWSE ) );
+	return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENWSE ) );
 
     case HTTOPRIGHT:
     case HTBOTTOMLEFT:
-	return SetCursor( LoadCursor( 0, IDC_SIZENESW ) );
+	return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENESW ) );
     }
 
     /* Default cursor: arrow */
-    return SetCursor( LoadCursor( 0, IDC_ARROW ) );
+    return (LONG)SetCursor( LoadCursor( 0, IDC_ARROW ) );
 }
 
 
@@ -799,7 +799,7 @@
  * Initialisation of a move or resize, when initiatied from a menu choice.
  * Return hit test code for caption or sizing border.
  */
-static LONG NC_StartSizeMove( HWND hwnd, WORD wParam, POINT *capturePoint )
+static LONG NC_StartSizeMove( HWND hwnd, WPARAM wParam, POINT *capturePoint )
 {
     LONG hittest = 0;
     POINT pt;
@@ -1114,7 +1114,7 @@
 
     do
     {
-        GetMessage( USER_HEAP_SEG_ADDR(hMsg), 0, 0, 0 );
+        GetMessage( (SEGPTR)USER_HEAP_SEG_ADDR(hMsg), 0, 0, 0 );
 	switch(msg->message)
 	{
 	case WM_LBUTTONUP:
@@ -1174,7 +1174,7 @@
  *
  * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
  */
-LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam )
+LONG NC_HandleNCLButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam )
 {
     HDC hdc = GetWindowDC( hwnd );
 
@@ -1230,7 +1230,7 @@
  *
  * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
  */
-LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam )
+LONG NC_HandleNCLButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam )
 {
     /*
      * if this is an icon, send a restore since we are handling
@@ -1262,12 +1262,12 @@
  *
  * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
  */
-LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt )
+LONG NC_HandleSysCommand( HWND hwnd, WPARAM wParam, POINT pt )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
-    dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n", 
-		      wParam, pt.x, pt.y );
+    dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %lx %d,%d\n", 
+		      (DWORD)wParam, pt.x, pt.y );
 
     if (wndPtr->dwStyle & WS_CHILD) ScreenToClient( wndPtr->hwndParent, &pt );
 
diff --git a/windows/painting.c b/windows/painting.c
index b188ac3..7e16632 100644
--- a/windows/painting.c
+++ b/windows/painting.c
@@ -47,7 +47,7 @@
     DeleteObject( hrgnUpdate );
     if (!lps->hdc)
     {
-        fprintf( stderr, "GetDCEx() failed in BeginPaint(), hwnd=%x\n", hwnd );
+        fprintf( stderr, "GetDCEx() failed in BeginPaint(), hwnd="NPFMT"\n", hwnd );
         return 0;
     }
 
@@ -57,7 +57,7 @@
     if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
     {
         wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
-        lps->fErase = !SendMessage( hwnd, WM_ERASEBKGND, lps->hdc, 0 );
+        lps->fErase = !SendMessage( hwnd, WM_ERASEBKGND, (WPARAM)lps->hdc, 0 );
     }
     else lps->fErase = TRUE;
 
@@ -93,11 +93,17 @@
 {
       /* Send WM_CTLCOLOR message if needed */
 
-    if (hbrush <= CTLCOLOR_MAX)
+    if ((DWORD)hbrush <= CTLCOLOR_MAX)
     {
 	if (!hwndParent) return;
+#ifdef WINELIB32
+	hbrush = (HBRUSH)SendMessage( hwndParent, 
+				      WM_CTLCOLORMSGBOX+(DWORD)hbrush,
+				      (WPARAM)hdc, (LPARAM)hwnd );
+#else
 	hbrush = (HBRUSH)SendMessage( hwndParent, WM_CTLCOLOR,
 				      hdc, MAKELONG( hwnd, hbrush ) );
+#endif
     }
     if (hbrush) FillRect( hdc, rect, hbrush );
 }
@@ -108,8 +114,13 @@
  */
 HBRUSH GetControlBrush( HWND hwnd, HDC hdc, WORD control )
 {
+#ifdef WINELIB32
+    return (HBRUSH)SendMessage( GetParent(hwnd), WM_CTLCOLOR+control,
+                                (WPARAM)hdc, (LPARAM)hwnd );
+#else
     return (HBRUSH)SendMessage( GetParent(hwnd), WM_CTLCOLOR,
                                 hdc, MAKELONG( hwnd, control ) );
+#endif
 }
 
 
@@ -129,13 +140,13 @@
 
     if (rectUpdate)
     {
-        dprintf_win( stddeb, "RedrawWindow: %x %d,%d-%d,%d %x flags=%04x\n",
+        dprintf_win( stddeb, "RedrawWindow: "NPFMT" %d,%d-%d,%d "NPFMT" flags=%04x\n",
                      hwnd, rectUpdate->left, rectUpdate->top,
                      rectUpdate->right, rectUpdate->bottom, hrgnUpdate, flags);
     }
     else
     {
-        dprintf_win( stddeb, "RedrawWindow: %x NULL %x flags=%04x\n",
+        dprintf_win( stddeb, "RedrawWindow: "NPFMT" NULL "NPFMT" flags=%04x\n",
                      hwnd, hrgnUpdate, flags);
     }
     GetClientRect( hwnd, &rectClient );
@@ -239,7 +250,7 @@
                 if (!(wndPtr->dwStyle & WS_MINIMIZE)
                     || !WIN_CLASS_INFO(wndPtr).hIcon)
                 {
-                    if (SendMessage( hwnd, WM_ERASEBKGND, hdc, 0 ))
+                    if (SendMessage( hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0 ))
                         wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
                 }
                 ReleaseDC( hwnd, hdc );
diff --git a/windows/property.c b/windows/property.c
index f3e88ba..601615f 100644
--- a/windows/property.c
+++ b/windows/property.c
@@ -31,7 +31,7 @@
     PROPERTY *prop;
     WND *wndPtr;
 
-    dprintf_prop( stddeb, "SetProp: %04x %08lx %04x\n", hwnd, str, hData );
+    dprintf_prop( stddeb, "SetProp: "NPFMT" %08lx "NPFMT"\n", hwnd, str, hData );
     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
     hProp = USER_HEAP_ALLOC( sizeof(PROPERTY) + 
                              (HIWORD(str) ? strlen(PTR_SEG_TO_LIN(str)) : 0 ));
@@ -62,7 +62,7 @@
     HANDLE hProp;
     WND *wndPtr;
 
-    dprintf_prop( stddeb, "GetProp: %04x %08lx\n", hwnd, str );
+    dprintf_prop( stddeb, "GetProp: "NPFMT" %08lx\n", hwnd, str );
     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
     hProp = wndPtr->hProp;
     while (hProp)
@@ -88,7 +88,7 @@
     HANDLE *hProp;
     WND *wndPtr;
 
-    dprintf_prop( stddeb, "RemoveProp: %04x %08lx\n", hwnd, str );
+    dprintf_prop( stddeb, "RemoveProp: "NPFMT" %08lx\n", hwnd, str );
     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
     hProp = &wndPtr->hProp;
     while (*hProp)
@@ -119,23 +119,25 @@
     HANDLE hProp;
     WND *wndPtr;
 
-    dprintf_prop( stddeb, "EnumProps: %04x %08lx\n", hwnd, (LONG)func );
+    dprintf_prop( stddeb, "EnumProps: "NPFMT" %08lx\n", hwnd, (LONG)func );
     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
     hProp = wndPtr->hProp;
     while (hProp)
     {
         PROPERTY *prop = (PROPERTY *)USER_HEAP_LIN_ADDR(hProp);
         
-        dprintf_prop( stddeb, "  Callback: atom=%04x data=%04x str='%s'\n",
+        dprintf_prop( stddeb, "  Callback: atom=%04x data="NPFMT" str='%s'\n",
                       prop->atom, prop->hData, prop->string );
 
           /* Already get the next in case the callback */
           /* function removes the current property.    */
         hProp = prop->next;
         ret = CallEnumPropProc( func, hwnd,
-                                prop->atom ? MAKELONG( prop->atom, 0 ) :
-                                USER_HEAP_SEG_ADDR(hProp) +
-                                ((int)prop->string - (int)prop),
+                                prop->atom ? 
+				  (LONG)MAKELONG( prop->atom, 0 )
+				:
+                                  (LONG)(USER_HEAP_SEG_ADDR(hProp) +
+                                         ((int)prop->string - (int)prop)),
                                 prop->hData );
         if (!ret) break;
     }
diff --git a/windows/timer.c b/windows/timer.c
index 88b7073..797f66e 100644
--- a/windows/timer.c
+++ b/windows/timer.c
@@ -114,8 +114,8 @@
 	TIMER_RestartTimer( pTimer, curTime );
     }
 
-    dprintf_timer(stddeb, "Timer expired: %p, %04x, %04x, %04x, %08lx\n", 
-		  pTimer, pTimer->hwnd, pTimer->msg, pTimer->id, pTimer->proc);
+    dprintf_timer(stddeb, "Timer expired: %p, "NPFMT", %04x, %04x, %08lx\n", 
+		  pTimer, pTimer->hwnd, pTimer->msg, pTimer->id, (DWORD)pTimer->proc);
       /* Build the message */
     msg->hwnd    = pTimer->hwnd;
     msg->message = pTimer->msg;
@@ -170,8 +170,8 @@
     pTimer->timeout = timeout;
     pTimer->expires = GetTickCount() + timeout;
     pTimer->proc    = proc;
-    dprintf_timer(stddeb, "Timer added: %p, %04x, %04x, %04x, %08lx\n", 
-		  pTimer, pTimer->hwnd, pTimer->msg, pTimer->id, pTimer->proc);
+    dprintf_timer(stddeb, "Timer added: %p, "NPFMT", %04x, %04x, %08lx\n", 
+		  pTimer, pTimer->hwnd, pTimer->msg, pTimer->id, (DWORD)pTimer->proc);
     TIMER_InsertTimer( pTimer );
     MSG_IncTimerCount( GetTaskQueue(0) );
     if (!id)
@@ -217,7 +217,7 @@
  */
 WORD SetTimer( HWND hwnd, WORD id, WORD timeout, FARPROC proc )
 {
-    dprintf_timer(stddeb, "SetTimer: %d %d %d %08lx\n", hwnd, id, timeout, (LONG)proc );
+    dprintf_timer(stddeb, "SetTimer: "NPFMT" %d %d %08lx\n", hwnd, id, timeout, (LONG)proc );
     return TIMER_SetTimer( hwnd, id, timeout, proc, FALSE );
 }
 
@@ -227,7 +227,7 @@
  */
 WORD SetSystemTimer( HWND hwnd, WORD id, WORD timeout, FARPROC proc )
 {
-    dprintf_timer(stddeb, "SetSystemTimer: %d %d %d %08lx\n", 
+    dprintf_timer(stddeb, "SetSystemTimer: "NPFMT" %d %d %08lx\n", 
 		  hwnd, id, timeout, (LONG)proc );
     return TIMER_SetTimer( hwnd, id, timeout, proc, TRUE );
 }
@@ -238,7 +238,7 @@
  */
 BOOL KillTimer( HWND hwnd, WORD id )
 {
-    dprintf_timer(stddeb, "KillTimer: %d %d\n", hwnd, id );
+    dprintf_timer(stddeb, "KillTimer: "NPFMT" %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, FALSE );
 }
 
@@ -248,6 +248,6 @@
  */
 BOOL KillSystemTimer( HWND hwnd, WORD id )
 {
-    dprintf_timer(stddeb, "KillSystemTimer: %d %d\n", hwnd, id );
+    dprintf_timer(stddeb, "KillSystemTimer: "NPFMT" %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, TRUE );
 }
diff --git a/windows/utility.c b/windows/utility.c
index 61df0cb..8838394 100644
--- a/windows/utility.c
+++ b/windows/utility.c
@@ -423,3 +423,25 @@
 	free(newargs);
 	return result;
 };
+
+/******************************************************************************
+ *                              DragDetect ( USER.465 )
+ *
+ * Hardly ever called at all
+ */
+
+
+/******************************************************************************
+ *                              DragObject ( USER.464 )
+ *
+ * responsible for generation of WM_QUERYDROPOBJECT, WM_DRAGLOOP, 
+ *                               WM_DRAGMOVE,        WM_DROPOBJECT
+ */
+LONG DragObject(HWND hDesktop, HWND hWnd, UINT Unknown1, WORD Unknown2, WORD Unknown3, HCURSOR hCursor)
+{
+
+ fprintf(stdnimp,"DragObject: EmptyStub!!!\n");
+ return 0;
+}
+ 
+
diff --git a/windows/win.c b/windows/win.c
index d7e2d2d..164b563 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -14,8 +14,7 @@
 #include "dce.h"
 #include "sysmetrics.h"
 #include "menu.h"
-#include "icon.h"
-#include "cursor.h"
+#include "cursoricon.h"
 #include "event.h"
 #include "message.h"
 #include "nonclient.h"
@@ -140,7 +139,7 @@
     for ( ; hwnd != 0; hwnd = wndPtr->hwndNext )
     {
 	if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
-	dprintf_win( stddeb, "WIN_FindWinToRepaint: %04x, style %08lx\n",
+	dprintf_win( stddeb, "WIN_FindWinToRepaint: "NPFMT", style %08lx\n",
 		     hwnd, wndPtr->dwStyle );
         if (!(wndPtr->dwStyle & WS_VISIBLE) || (wndPtr->flags & WIN_NO_REDRAW))
             continue;
@@ -165,16 +164,22 @@
  * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
  * the window has the WS_EX_NOPARENTNOTIFY style.
  */
-void WIN_SendParentNotify( HWND hwnd, WORD event, LONG lParam )
+void WIN_SendParentNotify( HWND hwnd, WORD event, WORD idChild, LONG lValue )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
     
     while (wndPtr && (wndPtr->dwStyle & WS_CHILD))
     {
         if (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY) break;
-	SendMessage( wndPtr->hwndParent, WM_PARENTNOTIFY, event, lParam );
+#ifdef WINELIB32
+	SendMessage( wndPtr->hwndParent, WM_PARENTNOTIFY, 
+		     MAKEWPARAM(event,idChild),
+		     (LPARAM)lValue );
+#else
+	SendMessage( wndPtr->hwndParent, WM_PARENTNOTIFY, event,
+		     MAKELPARAM(LOWORD(lValue), idChild) );
+#endif
         wndPtr = WIN_FindWndPtr( wndPtr->hwndParent );
-
     }
 }
 
@@ -269,7 +274,7 @@
     SendMessage( hwndDesktop, WM_NCCREATE, 0, 0 );
     if ((hdc = GetDC( hwndDesktop )) != 0)
     {
-        SendMessage( hwndDesktop, WM_ERASEBKGND, hdc, 0 );
+        SendMessage( hwndDesktop, WM_ERASEBKGND, (WPARAM)hdc, 0 );
         ReleaseDC( hwndDesktop, hdc );
     }
     return TRUE;
@@ -315,9 +320,9 @@
     else
         dprintf_win( stddeb, "%04x ", LOWORD(className) );
 
-    dprintf_win(stddeb, "%08lx %08lx %d,%d %dx%d %04x %04x %04x %08lx\n",
+    dprintf_win(stddeb, "%08lx %08lx %d,%d %dx%d "NPFMT" "NPFMT" "NPFMT" %08lx\n",
 		exStyle, style, x, y, width, height,
-		parent, menu, instance, data);
+		parent, menu, instance, (DWORD)data);
 
     if (x == CW_USEDEFAULT) x = y = 0;
     if (width == CW_USEDEFAULT)
@@ -332,7 +337,7 @@
     {
 	/* Make sure parent is valid */
         if (!IsWindow( parent )) {
-	    dprintf_win(stddeb,"CreateWindowEx: Parent %x is not a window\n", parent);
+	    dprintf_win(stddeb,"CreateWindowEx: Parent "NPFMT" is not a window\n", parent);
 	    return 0;
 	}
     }
@@ -436,11 +441,6 @@
 
     if (!(style & WS_CHILD) && (rootWindow == DefaultRootWindow(display)))
     {
-        CURSORALLOC *cursor;
-        HCURSOR hCursor = classPtr->wc.hCursor;
-        if (!hCursor) hCursor = LoadCursor( 0, IDC_ARROW );
-        cursor = (CURSORALLOC *) GlobalLock(hCursor);
-
         win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
                               PointerMotionMask | ButtonPressMask |
                               ButtonReleaseMask | FocusChangeMask;
@@ -448,7 +448,7 @@
         win_attr.colormap      = COLOR_WinColormap;
         win_attr.backing_store = Options.backingstore ? WhenMapped : NotUseful;
         win_attr.save_under    = ((classPtr->wc.style & CS_SAVEBITS) != 0);
-        win_attr.cursor        = cursor ? cursor->xcursor : None;
+        win_attr.cursor        = CURSORICON_XCursor;
         wndPtr->window = XCreateWindow( display, rootWindow, x, y,
                                         width, height, 0, CopyFromParent,
                                         InputOutput, CopyFromParent,
@@ -457,7 +457,6 @@
                                         CWBackingStore, &win_attr );
         XStoreName( display, wndPtr->window, PTR_SEG_TO_LIN(windowName) );
         EVENT_RegisterWindow( wndPtr->window, hwnd );
-        GlobalUnlock( hCursor );
     }
     
     if ((style & WS_CAPTION) && !(style & WS_CHILD))
@@ -507,7 +506,7 @@
       /* Create a copy of SysMenu */
     if (style & WS_SYSMENU) wndPtr->hSysMenu = CopySysMenu();
 
-    WIN_SendParentNotify( hwnd, WM_CREATE, MAKELONG( hwnd, wndPtr->wIDmenu ) );
+    WIN_SendParentNotify( hwnd, WM_CREATE, wndPtr->wIDmenu, (LONG)hwnd );
 
     /* Show the window, maximizing or minimizing if needed */
 
@@ -528,7 +527,7 @@
     }
     else if (style & WS_VISIBLE) ShowWindow( hwnd, SW_SHOW );
 
-    dprintf_win(stddeb, "CreateWindowEx: return %04X \n", hwnd);
+    dprintf_win(stddeb, "CreateWindowEx: return "NPFMT" \n", hwnd);
     return hwnd;
 }
 
@@ -541,7 +540,7 @@
     WND * wndPtr;
     CLASS * classPtr;
 
-    dprintf_win(stddeb, "DestroyWindow (%04x)\n", hwnd);
+    dprintf_win(stddeb, "DestroyWindow ("NPFMT")\n", hwnd);
     
       /* Initialisation */
 
@@ -556,7 +555,7 @@
 		      SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE );
     if ((hwnd == GetCapture()) || IsChild( hwnd, GetCapture() ))
 	ReleaseCapture();
-    WIN_SendParentNotify( hwnd, WM_DESTROY, MAKELONG(hwnd, wndPtr->wIDmenu) );
+    WIN_SendParentNotify( hwnd, WM_DESTROY, wndPtr->wIDmenu, (LONG)hwnd );
 
       /* Recursively destroy owned windows */
 
@@ -620,7 +619,8 @@
 
     if (ClassMatch)
     {
-	hclass = CLASS_FindClassByName( ClassMatch, 0xffff, &classPtr );
+	hclass = CLASS_FindClassByName( ClassMatch, (HINSTANCE)0xffff,
+                                        &classPtr );
 	if (!hclass) return 0;
     }
     else hclass = 0;
@@ -708,14 +708,32 @@
     switch(offset)
     {
 	case GWW_ID:         return wndPtr->wIDmenu;
-	case GWW_HWNDPARENT: return wndPtr->hwndParent;
-	case GWW_HINSTANCE:  return wndPtr->hInstance;
+#ifdef WINELIB32
+        case GWW_HWNDPARENT:
+        case GWW_HINSTANCE: 
+            fprintf(stderr,"GetWindowWord called with offset %d.\n",offset);
+            return 0;
+#else
+	case GWW_HWNDPARENT: return (WORD)wndPtr->hwndParent;
+	case GWW_HINSTANCE:  return (WORD)wndPtr->hInstance;
+#endif
     }
     return 0;
 }
 
 
 /**********************************************************************
+ *	     WIN_GetWindowInstance
+ */
+HINSTANCE WIN_GetWindowInstance(HWND hwnd)
+{
+    WND * wndPtr = WIN_FindWndPtr( hwnd );
+    if (!wndPtr) return (HINSTANCE)0;
+    return wndPtr->hInstance;
+}
+
+
+/**********************************************************************
  *	     SetWindowWord    (USER.134)
  */
 WORD SetWindowWord( HWND hwnd, short offset, WORD newval )
@@ -727,7 +745,13 @@
     else switch(offset)
     {
 	case GWW_ID:        ptr = &wndPtr->wIDmenu;   break;
-	case GWW_HINSTANCE: ptr = &wndPtr->hInstance; break;
+#ifdef WINELIB32
+	case GWW_HINSTANCE:
+            fprintf(stderr,"SetWindowWord called with offset %d.\n",offset);
+            return 0;
+#else
+	case GWW_HINSTANCE: ptr = (WORD*)&wndPtr->hInstance; break;
+#endif
 	default: return 0;
     }
     retval = *ptr;
@@ -749,6 +773,10 @@
 	case GWL_STYLE:   return wndPtr->dwStyle;
         case GWL_EXSTYLE: return wndPtr->dwExStyle;
 	case GWL_WNDPROC: return (LONG)wndPtr->lpfnWndProc;
+#ifdef WINELIB32
+	case GWW_HWNDPARENT: return (LONG)wndPtr->hwndParent;
+	case GWW_HINSTANCE:  return (LONG)wndPtr->hInstance;
+#endif
     }
     return 0;
 }
@@ -793,8 +821,8 @@
       /* We have to allocate a buffer on the USER heap */
       /* to be able to pass its address to 16-bit code */
     if (!(handle = USER_HEAP_ALLOC( nMaxCount ))) return 0;
-    len = (int)SendMessage( hwnd, WM_GETTEXT, (WORD)nMaxCount, 
-                            USER_HEAP_SEG_ADDR(handle) );
+    len = (int)SendMessage( hwnd, WM_GETTEXT, (WPARAM)nMaxCount, 
+                            (LPARAM)USER_HEAP_SEG_ADDR(handle) );
     strncpy( lpString, USER_HEAP_LIN_ADDR(handle), nMaxCount );
     USER_HEAP_FREE( handle );
     return len;
@@ -817,7 +845,7 @@
       /* to be able to pass its address to 16-bit code */
     if (!(handle = USER_HEAP_ALLOC( strlen(lpString)+1 ))) return;
     strcpy( USER_HEAP_LIN_ADDR(handle), lpString );
-    SendMessage( hwnd, WM_SETTEXT, 0, USER_HEAP_SEG_ADDR(handle) );
+    SendMessage( hwnd, WM_SETTEXT, 0, (LPARAM)USER_HEAP_SEG_ADDR(handle) );
     USER_HEAP_FREE( handle );
 }
 
@@ -1197,7 +1225,7 @@
 {
 	HWND hWndOldModal = hWndSysModal;
 	hWndSysModal = hWnd;
-	dprintf_win(stdnimp,"EMPTY STUB !! SetSysModalWindow(%04X) !\n", hWnd);
+	dprintf_win(stdnimp,"EMPTY STUB !! SetSysModalWindow("NPFMT") !\n", hWnd);
 	return hWndOldModal;
 }
 
diff --git a/windows/winpos.c b/windows/winpos.c
index 5ef9e45..32ca21c6 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -7,6 +7,7 @@
 #include "sysmetrics.h"
 #include "user.h"
 #include "win.h"
+#include "event.h"
 #include "message.h"
 #include "stackframe.h"
 #include "winpos.h"
@@ -309,7 +310,7 @@
 {    
     int flags = SWP_NOZORDER | SWP_NOACTIVATE;
     if (!repaint) flags |= SWP_NOREDRAW;
-    dprintf_win(stddeb, "MoveWindow: %d %d,%d %dx%d %d\n", 
+    dprintf_win(stddeb, "MoveWindow: "NPFMT" %d,%d %dx%d %d\n", 
 	    hwnd, x, y, cx, cy, repaint );
     return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
 }
@@ -328,7 +329,7 @@
 
     if (!wndPtr) return FALSE;
 
-    dprintf_win(stddeb,"ShowWindow: hwnd=%04X, cmd=%d\n", hwnd, cmd);
+    dprintf_win(stddeb,"ShowWindow: hwnd="NPFMT", cmd=%d\n", hwnd, cmd);
 
     wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
 
@@ -542,8 +543,14 @@
     if (hwndActive)
     {
 	if (!SendMessage( hwndActive, WM_NCACTIVATE, FALSE, 0 )) return 0;
+#ifdef WINELIB32
+	SendMessage( hwndActive, WM_ACTIVATE,
+		     MAKEWPARAM( WA_INACTIVE, IsIconic(hwndActive) ),
+		     (LPARAM)hwnd );
+#else
 	SendMessage( hwndActive, WM_ACTIVATE, WA_INACTIVE,
 		     MAKELONG( IsIconic(hwndActive), hwnd ) );
+#endif
 	/* Send WM_ACTIVATEAPP here */
     }
 
@@ -555,8 +562,15 @@
 
 	/* Send WM_ACTIVATEAPP here */
 	SendMessage( hwnd, WM_NCACTIVATE, TRUE, 0 );
+#ifdef WINELIB32
+	SendMessage( hwnd, WM_ACTIVATE,
+		     MAKEWPARAM( mouseMsg ? WA_CLICKACTIVE : WA_ACTIVE, 
+				 IsIconic(hwnd) )
+		     , (LPARAM)prevActive );
+#else
 	SendMessage( hwnd, WM_ACTIVATE, mouseMsg ? WA_CLICKACTIVE : WA_ACTIVE,
 		     MAKELONG( IsIconic(hwnd), prevActive ) );
+#endif
     }
     return prevActive;
 }
@@ -919,6 +933,7 @@
       /* Repaint the window */
 
     if (wndPtr->window) MSG_Synchronize();  /* Wait for all expose events */
+    EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
     if ((flags & SWP_FRAMECHANGED) && !(flags & SWP_NOREDRAW))
         RedrawWindow( winpos.hwnd, NULL, 0,
                       RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
@@ -928,6 +943,8 @@
 
       /* And last, send the WM_WINDOWPOSCHANGED message */
 
+    winpos.flags |= SWP_NOMOVE; /* prevent looping.. window is already moved ??? (FIXME)*/
+
     if (!(winpos.flags & SWP_NOSENDCHANGING))
         SendMessage( winpos.hwnd, WM_WINDOWPOSCHANGED,
                      0, MAKE_SEGPTR(&winpos) );
@@ -1057,7 +1074,7 @@
  */
 void TileChildWindows( HWND parent, WORD action )
 {
-    printf("STUB TileChildWindows(%04X, %d)\n", parent, action);
+    printf("STUB TileChildWindows("NPFMT", %d)\n", parent, action);
 }
 
 /***********************************************************************
@@ -1065,5 +1082,5 @@
  */
 void CascadeChildWindows( HWND parent, WORD action )
 {
-    printf("STUB CascadeChildWindows(%04X, %d)\n", parent, action);
+    printf("STUB CascadeChildWindows("NPFMT", %d)\n", parent, action);
 }