Group commit for recovery after disk crash.
See Changelog for changes WRT release 990110.

diff --git a/ChangeLog b/ChangeLog
index feec784..cfeaa8b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,175 @@
+Sun Jan 17 17:48:48 1999  Alexandre Julliard  <julliard@winehq.com>
+
+	* ChangeLog:
+	Recovered log entries from CVS mailing list.
+
+	* relay32/ntdll.spec, dlls/ntdll/rtl.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Implemented _alloca_probe and _chkstk (mostly done by Ulrich Weigand).
+
+	* files/file.c
+	Marcus Meissner <marcus@jet.franken.de>
+	Handle ERROR_WRITE_PROTECT too in readonly fallback open.
+
+	* dlls/advapi32/security.c, relay32/advapi32.spec:
+	Marcus Meissner <marcus@jet.franken.de>
+	Added GetSecurityDescriptorLength stub for regedt32.exe.
+
+	* debugger/Makefile.in, files/Makefile.in:
+	Marcus Meissner <marcus@jet.franken.de>
+	Add "" around -D defines for paths with spaces in them.
+
+	* graphics/d3dtexture.c, graphics/ddraw.c, include/ddraw.h:
+	Lionel Ulmer <ulmer@directprovider.net>
+	Cleaned up ColorKey handling.
+
+	* objects/metafile.c:
+	Paul Quinn <paulq@COREL.CA>
+	METARECORD member rdParam should be rdParm (in win32 sdk)
+	lots of changes in this source file to reflect this change.
+
+	* graphics/escape.c, graphics/painting.c, graphics/metafiledrv/init.c, include/commctrl.h, include/commdlg.h, include/gdi.h, include/tchar.h, include/windows.h, include/wingdi.h, include/wintypes.h, include/winuser.h, misc/spooler.c, objects/gdiobj.c,
+	relay32/gdi32.spec:
+	Paul Quinn <paulq@COREL.CA>
+	Fixed bad defines, added a few types 'n defines.
+
+	* windows/dinput.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Disable broken callbacks which lead to crashes.
+
+	* multimedia/mcistring.c:
+	Eric Pouech <Eric.Pouech@wanadoo.fr>
+	Fixed ID usage (and rely less heavily on multimedia/mmsystem.c
+	internal structures).
+
+	* misc/toolhelp.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	debug.h needs to be included last since it #undefs ERR for Solaris.
+
+	* debugger/debug.l, debugger/memory.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Added /u format to debugger display for UNICODE strings.
+
+	* loader/pe_image.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Remove irritating FIXME line no longer needed.
+
+	* msdos/int2f.c:
+	Eric Pouech <Eric.Pouech@wanadoo.fr>
+	Added missing '\n' in FIXME message.
+
+	* graphics/ddraw.c:
+	Robert Riggs <rriggs@tesser.com>
+	objbase.h needed for WINE_StringFromCLSID(), fix C function
+	declarations, install a colormap if we are not managed, release
+	backbuffers in DGA mode, fix video mode switching logic to avoid
+	possible NULL pointer dereference.
+
+	* msdos/dpmi.c:
+	Andreas Mohr <mohr@elektron.ikp.physik.tu-darmstadt.de>
+	Small fix.
+
+	* files/file.c, include/file.h, include/process.h, loader/resource.c, loader/dos/module.c, loader/ne/segment.c, misc/lzexpand.c, msdos/int21.c vxd.c, multimedia/mmio.c, win32/kernel32.c:
+	Better DOS file handle management.
+
+	* documentation/common_controls:
+	Francis Beaudet <francis@macadamian.com>
+	This should help prevent duplicate work.
+
+	* if1632/gdi.spec, include/wingdi.h, objects/dc.c:
+	Andreas Mohr <mohr@elektron.ikp.physik.tu-darmstadt.de>
+	Implemented Death() and Resurrection(), two functions needed by some
+	TPWin (?) command line tool.
+
+	* windows/winproc.c:
+	Juergen Schmied <juergen.schmied@metronet.de>
+	Added 32->16 translation for WM_ACTIVATEAPP.
+
+	* dlls/shell32/pidl.c, dlls/shell32/shellord.c, dlls/shell32/shellpath.c, dlls/shell32/shlfolder.c, relay32/shell32.spec:
+	Juergen Schmied <juergen.schmied@metronet.de>
+	New stubs: ShellMessageBoxW, RunDLL_CallEntry16.
+	Implementation for SHGetSpecialFolderPath32[A|W].
+	Many bugfixes.
+
+	* console/xterm.c, misc/port.c, win32/console.c:
+	Joseph Pranevich <jpranevich@lycos.com>
+	Change all Wine openpty() implementations to match the "standard" and
+	then make them both call the same code leaving the option to change
+	that code to call the "standard" openpty() at a later date.
+
+	* relay32/kernel32.spec, scheduler/process.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Added SetProcessAffinityMask stub.
+
+	* graphics/ddraw.c, include/ddraw.h:
+	Marcus Meissner <marcus@jet.franken.de>
+	Fixed the other union misuse too (one less mem corruption)
+	Re-added XInstallColormap (or non managed does not change palette)
+
+	* if1632/kernel.spec, scheduler/synchro.c:
+	Ulrich Weigand <weigand@informatik.uni-erlangen.de>
+	Added an implementation for KERNEL.495.
+
+	* documentation/status, documentation/direct3D, graphics/d3d_private.h, graphics/d3dcommon.c, graphics/d3ddevices.c, graphics/d3dexecutebuffer.c, graphics/d3dtexture.c, graphics/d3dviewport.c, graphics/ddraw.c, include/d3d.h, include/ddraw.h:
+	Lionel Ulmer <ulmer@directprovider.net>
+	- added bitmask to store which ColorKey structures are valid
+	- handle many new rendering states, some optimizations in state changes
+	- 8bit palettized textures now support ColorKeying
+	- some miscellaneous bug fixes and code rewrite
+
+	* controls/menu.c:
+	Noomen Hamza <noomen@macadamian.com>
+	Fixed the look of the menu so it would be compliant with Win95: modified
+	the mouse tracking code so it would change the selection every time the
+	mouse moved over a menu item.
+
+	* documentation/how-to-port:
+	Mike Castle <dalgoda@shell.rt66.com>
+	Small fix.
+
+	* dlls/comctl32/updown.c:
+	Noel Borthwick <noel@macadamian.com>
+	Fixed bugs:
+	- When an edit control buddy was used single digit values were not
+	being displayed.
+	- Comma values were not displayed correctly when thousands separation
+	was requested.
+
+	* win32/newfns.c:
+	Tom Bech <tomb@ii.uib.no>
+	While the debug event messages are not implemented, WaitForDebugEvent
+	should return FALSE.
+
+	* if1632/user.spec, objects/bitmap.c:
+	Andreas Mohr <mohr@elektron.ikp.physik.tu-darmstadt.de>
+	Implemented CopyImage16.
+
+	* documentation/bugreports 
+	Andreas Mohr <mohr@elektron.ikp.physik.tu-darmstadt.de>
+	Small fix.
+
+	* console/generic.c, msdos/int21.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Changed 0x01 to use generic console, fixed 0x0b.
+	Fixed CONSOLE_GetCharacter (two args swapped).
+
+	* include/module.h, loader/main.c, loader/module.c, loader/dos/module.c:
+	Ulrich Weigand <weigand@informatik.uni-erlangen.de>
+	Allow specifying module name for NE dummy module.
+
+	* loader/pe_image.c 
+	Ulrich Weigand <weigand@informatik.uni-erlangen.de>
+	Set module name of dummy module equal to module name of PE module.
+
+	* controls/scroll.c, controls/uitools.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Missing include wine/winuser16.h added.
+
+	* graphics/vga.c:
+	Marcus Meissner <marcus@jet.franken.de>
+	Create an actual primary surface for screenbuffer.
+
+----------------------------------------------------------------
 Sun Jan 10 14:40:34 1999  Alexandre Julliard  <julliard@winehq.com>
 
 	* include/miscemu.h, include/msdos.h, loader/main.c, msdos/Makefile.in, msdos/dosconf.c, msdos/int21.c:
diff --git a/console/generic.c b/console/generic.c
index 8bdff1d..8502b27 100644
--- a/console/generic.c
+++ b/console/generic.c
@@ -129,7 +129,7 @@
    
    while (!ch)
    {
-      CONSOLE_GetKeystroke(&ch, &scan);
+      CONSOLE_GetKeystroke(&scan, &ch);
    }
    return ch;
 }
diff --git a/console/xterm.c b/console/xterm.c
index fa2cf79..b3c2afd 100644
--- a/console/xterm.c
+++ b/console/xterm.c
@@ -2,11 +2,11 @@
 
 /* This "driver" is designed to go on top of an existing driver
    to provide support for features only present if using an
-   xterm or compatible program for your console output. It should
-   inlcude such features as resizing, separation of output from the
-   standard wine console, and a configurable title bar for
-   Win32 console. */
-/* Right now, it doesn't have any "special" features */
+   xterm or compatible program for your console output. 
+   Currently, it supports resizing and separating debug messages from
+   program output.
+   It does not currently support changing the title bar.
+*/
 
 #include <signal.h>
 #include <sys/ioctl.h>
@@ -99,67 +99,26 @@
    CONSOLE_NotifyResizeScreen(x, y);
 }
 
-/**
- *  It looks like the openpty that comes with glibc in RedHat 5.0
- *  is buggy (second call returns what looks like a dup of 0 and 1
- *  instead of a new pty), this is a generic replacement.
- */
-/** Can't we determine this using autoconf?
- */
-
-static FILE *wine_openpty(FILE **master, FILE **slave, char *name,
-                        struct termios *term, struct winsize *winsize)
-{
-        FILE *fdm, *fds;
-        char *ptr1, *ptr2;
-        char pts_name[512];
-
-        strcpy (pts_name, "/dev/ptyXY");
-        for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
-                pts_name[8] = *ptr1;
-                for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
-                        pts_name[9] = *ptr2;
-
-                        if ((fdm = fopen(pts_name, "r+")) == NULL) {
-                                if (errno == ENOENT)
-                                        return (FILE *) -1;
-                                else
-                                        continue;
-                        }
-                        pts_name[5] = 't';
-                        if ((fds = fopen(pts_name, "r+")) == NULL) {
-                                pts_name[5] = 'p';
-                                continue;
-                        }
-                        *master = fdm;
-                        *slave = fds;
-
-                        if (term != NULL)
-                                tcsetattr(fileno(*slave), TCSANOW, term);
-                        if (winsize != NULL)
-                                ioctl(fileno(*slave), TIOCSWINSZ, winsize);
-
-                        if (name != NULL)
-                                strcpy(name, pts_name);
-                        return fds;
-                }
-        }
-        return (FILE *) -1;
-}
 
 static BOOL32 wine_create_console(FILE **master, FILE **slave, int *pid)
 {
+        /* There is definately a bug in this routine that causes a lot
+           of garbage to be written to the screen, but I can't find it...
+        */
         struct termios term;
         char buf[1024];
         char c = '\0';
         int status = 0;
         int i;
+        int tmaster, tslave;
 
         if (tcgetattr(0, &term) < 0) return FALSE;
         term.c_lflag |= ICANON;
         term.c_lflag &= ~ECHO;
-        if (wine_openpty(master, slave, NULL, &term, NULL) < 0)
+        if (wine_openpty(&tmaster, &tslave, NULL, &term, NULL) < 0)
            return FALSE;
+        *master = fdopen(tmaster, "r+");
+        *slave = fdopen(tslave, "r+");
 
         if ((*pid=fork()) == 0) {
                 tcsetattr(fileno(*slave), TCSADRAIN, &term);
diff --git a/controls/menu.c b/controls/menu.c
index 1a131bc..e8b4798 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -2339,11 +2339,15 @@
 		    break;
 		
 		case WM_MOUSEMOVE:
-		    if ((msg.wParam & MK_LBUTTON) || ((wFlags & TPM_RIGHTBUTTON) 
-						  && (msg.wParam & MK_RBUTTON)))
-		    {
+                    /* In win95 winelook, the selected menu item must be changed every time the
+                       mouse moves. In Win31 winelook, the mouse button has to be held down */
+                     
+                    if ( (TWEAK_WineLook > WIN31_LOOK) ||
+                         ( (msg.wParam & MK_LBUTTON) ||
+                           ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
+
 			fEndMenu |= !MENU_MouseMove( &mt, hmenu );
-		    }
+
 	    } /* switch(msg.message) - mouse */
 	}
 	else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
diff --git a/controls/scroll.c b/controls/scroll.c
index 2cf2314..099b123 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -6,6 +6,7 @@
  */
 
 #include "windows.h"
+#include "wine/winuser16.h"
 #include "sysmetrics.h"
 #include "scroll.h"
 #include "heap.h"
diff --git a/controls/uitools.c b/controls/uitools.c
index 0169b00..08a6396 100644
--- a/controls/uitools.c
+++ b/controls/uitools.c
@@ -6,6 +6,7 @@
  */
 
 #include "windows.h"
+#include "wine/winuser16.h"
 #include "debug.h"
 
 static const WORD wPattern_AA55[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555,
diff --git a/debugger/Makefile.in b/debugger/Makefile.in
index 350c219..1aaaca1 100644
--- a/debugger/Makefile.in
+++ b/debugger/Makefile.in
@@ -1,4 +1,4 @@
-DEFS      = -D__WINE__ -DLIBDIR=\"$(libdir)\"
+DEFS      = -D__WINE__ -DLIBDIR="\"$(libdir)\""
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ..
 SRCDIR    = @srcdir@
diff --git a/debugger/debug.l b/debugger/debug.l
index 0c4bc8a..7dd2cb2 100644
--- a/debugger/debug.l
+++ b/debugger/debug.l
@@ -33,7 +33,7 @@
 
 DIGIT	   [0-9]
 HEXDIGIT   [0-9a-fA-F]
-FORMAT     [bcdiswx]
+FORMAT     [ubcdiswx]
 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~@]*
 PATHNAME   [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
 STRING     \"[^\n"]+\"
diff --git a/debugger/memory.c b/debugger/memory.c
index aa1dd71..4d30b87 100644
--- a/debugger/memory.c
+++ b/debugger/memory.c
@@ -223,6 +223,19 @@
 
     switch(format)
     {
+	case 'u': {
+		WCHAR *ptr = (WCHAR*)pnt;
+		if (count == 1) count = 256;
+                while (count--)
+                {
+                    if (!DBG_CHECK_READ_PTR( &addr, sizeof(WCHAR) )) return;
+                    if (!*ptr) break;
+                    addr.off++;
+                    fputc( (char)*ptr++, stderr );
+                }
+		fprintf(stderr,"\n");
+		return;
+	    }
 	case 's':
 		if (count == 1) count = 256;
                 while (count--)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 6916ed3..b49c8ad 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -269,6 +269,16 @@
     return TRUE;
 }
 
+/***********************************************************************
+ *           GetSecurityDescriptorLength  (ADVAPI.55)
+ */
+DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
+{
+    FIXME(security, "(%p), stub\n", pDescr);
+    return 0;
+}
+
+
 
 /***********************************************************************
  *           InitializeSid  (ADVAPI.74)
diff --git a/dlls/comctl32/updown.c b/dlls/comctl32/updown.c
index f8a3368..1f39352 100644
--- a/dlls/comctl32/updown.c
+++ b/dlls/comctl32/updown.c
@@ -18,7 +18,10 @@
  *     - acceleration
  *     - base 16
  *     - UDS_ALIGNLEFT, ~UDS_WRAP
+ *       (tested - they work)
  *     - integers with thousand separators.
+ *       (fixed bugs. <noel@macadamian.com>)
+ *
  *   Even though the above list seems rather large, the control seems to
  *   behave very well so I am confident it does work in most (all) of the
  *   untested cases.
@@ -243,14 +246,15 @@
 
     sep = UPDOWN_GetThousandSep(); 
 
-    if (!(wndPtr->dwStyle & UDS_NOTHOUSANDS)) {
+    /* Do thousands seperation if necessary */
+    if (!(wndPtr->dwStyle & UDS_NOTHOUSANDS) && (len > 3)) {
       char txt2[20], *src = txt1, *dst = txt2;
       if(len%3 > 0){
-	lstrcpyn32A (dst, src, len%3);
+	lstrcpyn32A (dst, src, len%3 + 1);      /* need to include the null */ 
 	dst += len%3;
 	src += len%3;
       }
-      for(len=0; *src; len++,src++){
+      for(len=0; *src; len++){
 	if(len%3==0)
 	  *dst++ = sep;
 	*dst++ = *src++;
diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c
index e35464d..51e000c 100644
--- a/dlls/ntdll/rtl.c
+++ b/dlls/ntdll/rtl.c
@@ -588,11 +588,16 @@
 
 /**************************************************************************
  *                 NTDLL_chkstk				[NTDLL.862]
+ *                 NTDLL_alloca_probe				[NTDLL.861]
+ * Glorified "enter xxxx".
  */
 REGS_ENTRYPOINT(NTDLL_chkstk)
 {
-	/* FIXME: should subtract %eax bytes from stack pointer */
-	FIXME(ntdll, "(eax=%ld): stub\n",EAX_reg(context));
+    ESP_reg(context) -= EAX_reg(context);
+}
+REGS_ENTRYPOINT(NTDLL_alloca_probe)
+{
+    ESP_reg(context) -= EAX_reg(context);
 }
 
 /******************************************************************************
diff --git a/dlls/shell32/pidl.c b/dlls/shell32/pidl.c
index 0f014b3..225491b 100644
--- a/dlls/shell32/pidl.c
+++ b/dlls/shell32/pidl.c
@@ -631,23 +631,27 @@
 }
 
 BOOL32 WINAPI _ILIsMyComputer(LPCITEMIDLIST pidl)
-{	TRACE(pidl,"(%p)\n",pidl);
-	return (pidl && PT_MYCOMP == _ILGetDataPointer(pidl)->type);
+{	LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
+	TRACE(pidl,"(%p)\n",pidl);
+	return (pidl && lpPData && PT_MYCOMP == lpPData->type);
 }
 
 BOOL32 WINAPI _ILIsDrive(LPCITEMIDLIST pidl)
-{	TRACE(pidl,"(%p)\n",pidl);
-	return (pidl && PT_DRIVE == _ILGetDataPointer(pidl)->type);
+{	LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
+	TRACE(pidl,"(%p)\n",pidl);
+	return (pidl && lpPData && PT_DRIVE == lpPData->type);
 }
 
 BOOL32 WINAPI _ILIsFolder(LPCITEMIDLIST pidl)
-{	TRACE(pidl,"(%p)\n",pidl);
-	return (pidl && PT_FOLDER == _ILGetDataPointer(pidl)->type);
+{	LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
+	TRACE(pidl,"(%p)\n",pidl);
+	return (pidl && lpPData && PT_FOLDER == lpPData->type);
 }
 
 BOOL32 WINAPI _ILIsValue(LPCITEMIDLIST pidl)
-{	TRACE(pidl,"(%p)\n",pidl);
-	return (pidl && PT_VALUE == _ILGetDataPointer(pidl)->type);
+{	LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
+	TRACE(pidl,"(%p)\n",pidl);
+	return (pidl && lpPData && PT_VALUE == lpPData->type);
 }
 
 /**************************************************************************
@@ -661,6 +665,7 @@
  */
 DWORD WINAPI _ILGetFolderText(LPCITEMIDLIST pidl,LPSTR lpszPath, DWORD dwSize)
 {	LPITEMIDLIST	pidlTemp;
+	LPPIDLDATA	pData;
 	DWORD		dwCopied = 0;
 	LPSTR		pText;
  
@@ -680,29 +685,34 @@
 	if(lpszPath)
 	  *lpszPath = 0;
 
-	while(pidlTemp->mkid.cb)
-	{ LPPIDLDATA  pData = _ILGetDataPointer(pidlTemp);
+	pData = _ILGetDataPointer(pidlTemp);
 
-	  /*if this item is a value, then skip it and finish */
-	  if(PT_VALUE == pData->type)
-	  { break;
-	  }
-
-	  pText = _ILGetTextPointer(pData->type,pData);
-	  pidlTemp = ILGetNext(pidlTemp);
+	while(pidlTemp->mkid.cb && !(PT_VALUE == pData->type))
+	{ 
+	  if (!(pText = _ILGetTextPointer(pData->type,pData)))
+	    return 0;				/* foreign pidl */
+	    	  
 	  dwCopied += strlen(pText);
 
+	  pidlTemp = ILGetNext(pidlTemp);
+	  pData = _ILGetDataPointer(pidlTemp);
+
 	  if (lpszPath)
 	  { strcat(lpszPath, pText);
-	    if (pidlTemp && lpszPath[dwCopied-1]!='\\')
+
+	    if (pidlTemp->mkid.cb 		/* last element ? */
+	    	&& (pText[2] != '\\')	 	/* drive has own '\' */
+		&& (PT_VALUE != pData->type))	/* next element is value */
 	    { lpszPath[dwCopied] = '\\';
 	      lpszPath[dwCopied+1] = '\0';
 	      dwCopied++;
 	    }
 	  }
 	  else						/* only length */
-	  { if (pidlTemp && !_ILIsDrive (pidlTemp))	/* backslash between elements */
-	      dwCopied++;
+	  { if (pidlTemp->mkid.cb 
+	        && (pText[2] != '\\')
+		&& (PT_VALUE != pData->type))
+	      dwCopied++;				/* backslash between elements */
 	  }
 	}
 
@@ -754,8 +764,9 @@
  *  strlen(lpszOut)
  */
 DWORD WINAPI _ILGetPidlPath( LPCITEMIDLIST pidl, LPSTR lpszOut, DWORD dwOutSize)
-{	WORD  len = 0;
-
+{	int	len = 0;
+	LPSTR	lpszTemp = lpszOut;
+	
 	TRACE(pidl,"(%p,%lu)\n",lpszOut,dwOutSize);
 
 	if(!lpszOut)
@@ -768,19 +779,17 @@
 
 	lpszOut += len;
 	strcpy (lpszOut,"\\");
-	lpszOut++;
-
-	dwOutSize -= len+1;;
+	len++; lpszOut++; dwOutSize -= len;
 
 	len += _ILGetValueText(pidl, lpszOut, dwOutSize );
 
 	/*remove the last backslash if necessary */
-	if( lpszOut[len-1]=='\\')
-	{ lpszOut[len-1] = 0;
+	if( lpszTemp[len-1]=='\\')
+	{ lpszTemp[len-1] = 0;
 	  len--;
 	}
 
-	TRACE(pidl,"-- (%p=%s,%lu)\n",lpszOut,lpszOut,dwOutSize);
+	TRACE(pidl,"-- (%p=%s,%u)\n",lpszTemp,lpszTemp,len);
 
 	return len;
 }
@@ -800,7 +809,7 @@
 	LPPIDLDATA     pData;
 	LPSTR	pszDest;
 	
-	TRACE(pidl,"(%x %p %x)\n",type,pIn,uInSize);
+	TRACE(pidl,"(0x%02x %p %i)\n",type,pIn,uInSize);
 
 	if ( type == PT_DESKTOP)
 	{ pidlOut = SHAlloc(2);
@@ -812,7 +821,7 @@
 	{ return NULL;
 	}	
 
-	/* the sizes of: cb(2), pidldata-1, szText+1, next cb(2) */
+	/* the sizes of: cb(2), pidldata-1(26), szText+1, next cb(2) */
 	switch (type)
 	{ case PT_DRIVE:
 	    uSize = 4 + 9;
@@ -911,11 +920,9 @@
  *  _ILGetDataPointer()
  */
 LPPIDLDATA WINAPI _ILGetDataPointer(LPITEMIDLIST pidl)
-{	if(!pidl)
-	{ return NULL;
-	}
-/*	TRACE(pidl,"(%p)\n",  pidl);*/
-	return (LPPIDLDATA)(&pidl->mkid.abID);
+{	if(pidl && pidl->mkid.cb != 0x00)
+	  return (LPPIDLDATA)(&pidl->mkid.abID);
+	return NULL;
 }
 /**************************************************************************
  *  _ILGetTextPointer()
diff --git a/dlls/shell32/shellord.c b/dlls/shell32/shellord.c
index 2edd0df..e7e0733 100644
--- a/dlls/shell32/shellord.c
+++ b/dlls/shell32/shellord.c
@@ -188,19 +188,6 @@
     return MultiByteToWideChar (0, 0, lpMulti, nMulti, lpWide, nWide);
 }
 
-
-/*************************************************************************
- * SHGetSpecialFolderPath [SHELL32.175]
- * 
- * NOTES
- *     exported by ordinal
- */
-void WINAPI SHGetSpecialFolderPath(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
-    FIXME(shell,"(0x%04lx,0x%04lx,csidl=0x%04lx,0x%04lx):stub.\n",
-      x1,x2,x3,x4
-    );
-}
-
 /*************************************************************************
  * RegisterShellHook [SHELL32.181]
  *
@@ -214,6 +201,24 @@
 void WINAPI RegisterShellHook32(HWND32 hwnd, DWORD y) {
     FIXME(shell,"(0x%08x,0x%08lx):stub.\n",hwnd,y);
 }
+/*************************************************************************
+ * ShellMessageBoxW [SHELL32.182]
+ *
+ * Format and output errormessage.
+ *
+ * NOTES
+ *     exported by ordinal
+ */
+void __cdecl
+ShellMessageBoxW(HMODULE32 hmod,HWND32 hwnd,DWORD id,DWORD x,DWORD type,LPVOID arglist) {
+	WCHAR	buf[100];
+
+	if (!LoadString32W(hmod,x,buf,100))
+		lstrcpyAtoW (buf,"Desktop");
+
+	FIXME(shell,"(%08lx,%08lx,%08lx,%08lx(%s),%08lx,%p):stub.\n",
+		(DWORD)hmod,(DWORD)hwnd,id,x,debugstr_w(buf),type,arglist);
+}
 
 /*************************************************************************
  * ShellMessageBoxA [SHELL32.183]
@@ -1243,3 +1248,11 @@
 {	FIXME(shell,"0x%04x 0x%04x 0x%04lx 0x%04lx stub\n",hWnd, hModule,w,x);
 	return 0;
 }
+/*************************************************************************
+ * RunDLL_CallEntry16 [SHELL32.122]
+ * the name is propably wrong
+ */
+HRESULT WINAPI RunDLL_CallEntry16(DWORD v, DWORD w, DWORD x, DWORD y, DWORD z)
+{	FIXME(shell,"0x%04lx 0x%04lx 0x%04lx 0x%04lx 0x%04lx stub\n",v,w,x,y,z);
+	return 0;
+}
diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c
index f6c49f6..53d948f 100644
--- a/dlls/shell32/shellpath.c
+++ b/dlls/shell32/shellpath.c
@@ -724,3 +724,35 @@
 {	FIXME(shell,"0x%04lx 0x%04lx 0x%04lx 0x%04lx stub\n",u,v,w,x);
 	return 0;
 }
+
+/*************************************************************************
+ * SHGetSpecialFolderPath [SHELL32.175]
+ * 
+ * converts csidl to path
+ * 
+ */
+BOOL32 WINAPI SHGetSpecialFolderPath32A (DWORD x1,LPSTR szPath,DWORD csidl,DWORD x4) 
+{	LPITEMIDLIST pidl;
+
+	WARN(shell,"(0x%04lx,%p,csidl=%lu,0x%04lx) semi-stub\n", x1,szPath,csidl,x4);
+
+	SHGetSpecialFolderLocation(0, csidl, &pidl);
+	SHGetPathFromIDList32A (pidl, szPath);
+	SHFree (pidl);
+	return TRUE;
+}
+BOOL32 WINAPI SHGetSpecialFolderPath32W (DWORD x1,LPWSTR szPath, DWORD csidl,DWORD x4) 
+{	LPITEMIDLIST pidl;
+
+	WARN(shell,"(0x%04lx,%p,csidl=%lu,0x%04lx) semi-stub\n", x1,szPath,csidl,x4);
+
+	SHGetSpecialFolderLocation(0, csidl, &pidl);
+	SHGetPathFromIDList32W (pidl, szPath);
+	SHFree (pidl);
+	return TRUE;
+}
+BOOL32 WINAPI SHGetSpecialFolderPath32 (DWORD x1,LPVOID szPath,DWORD csidl,DWORD x4) 
+{	if (VERSION_OsIsUnicode())
+	  return SHGetSpecialFolderPath32W ( x1, szPath, csidl, x4);
+	return SHGetSpecialFolderPath32A ( x1, szPath, csidl, x4);
+}
diff --git a/dlls/shell32/shlfolder.c b/dlls/shell32/shlfolder.c
index 3fff67d..30b21e8 100644
--- a/dlls/shell32/shlfolder.c
+++ b/dlls/shell32/shlfolder.c
@@ -107,27 +107,31 @@
 	sf->mpSFParent=pParent;	/* parrent shellfolder */
 
 	TRACE(shell,"(%p)->(parent=%p, pidl=%p)\n",sf,pParent, pidl);
-	
+	pdump(pidl);
+		
 	/* keep a copy of the pidl in the instance*/
 	sf->mpidl = ILClone(pidl);
 	
-	if(sf->mpidl)        /* do we have a pidl? */
+	if(sf->mpidl)        				/* do we have a pidl? */
 	{ dwSize = 0;
-	  if(sf->mpSFParent->sMyPath)		/* get the size of the parents path */
+	  if(sf->mpSFParent->sMyPath)			/* get the size of the parents path */
 	  { dwSize += strlen(sf->mpSFParent->sMyPath) ;
 	    TRACE(shell,"-- (%p)->(parent's path=%s)\n",sf, debugstr_a(sf->mpSFParent->sMyPath));
 	  }   
 	  dwSize += _ILGetFolderText(sf->mpidl,NULL,0); /* add the size of the foldername*/
-	  sf->sMyPath = SHAlloc(dwSize+1);
+	  sf->sMyPath = SHAlloc(dwSize+2);		/* '\0' and backslash */
 	  if(sf->sMyPath)
-	  { *(sf->sMyPath)=0x00;
-	    if(sf->mpSFParent->sMyPath)		/* if the parent has a path, get it*/
+	  { int len;
+	    *(sf->sMyPath)=0x00;
+	    if(sf->mpSFParent->sMyPath)			/* if the parent has a path, get it*/
 	    {  strcpy(sf->sMyPath, sf->mpSFParent->sMyPath);
 	       PathAddBackslash32A (sf->sMyPath);
 	    }
-	    sf->pMyPidl = ILCombine(sf->pMyPidl, pidl);
-	    _ILGetFolderText(sf->mpidl, sf->sMyPath+strlen(sf->sMyPath), dwSize-strlen(sf->sMyPath));
-	    TRACE(shell,"-- (%p)->(my path=%s)\n",sf, debugstr_a(sf->sMyPath));
+	    sf->pMyPidl = ILCombine(sf->mpSFParent->pMyPidl, pidl);
+	    len = strlen(sf->sMyPath);
+	    _ILGetFolderText(sf->mpidl, sf->sMyPath+len, dwSize-len);
+	    TRACE(shell,"-- (%p)->(my pidl=%p, my path=%s)\n",sf, sf->pMyPidl,debugstr_a(sf->sMyPath));
+	    pdump (sf->pMyPidl);
 	  }
 	}
 	return sf;
@@ -344,8 +348,6 @@
 	if(!pShellFolder)
 	  return E_OUTOFMEMORY;
 
-	IShellFolder_Initialize(pShellFolder, this->pMyPidl);
-
 	hr = pShellFolder->lpvtbl->fnQueryInterface(pShellFolder, riid, ppvOut);
  	pShellFolder->lpvtbl->fnRelease(pShellFolder);
 	TRACE(shell,"-- (%p)->(interface=%p)\n",this, ppvOut);
@@ -614,7 +616,8 @@
 	BOOL32	bSimplePidl=FALSE;
 		
 	TRACE(shell,"(%p)->(pidl=%p,0x%08lx,%p)\n",this,pidl,dwFlags,lpName);
-
+	pdump(pidl);
+	
 	szSpecial[0]=0x00; 
 	szDrive[0]=0x00;
 	szText[0]=0x00;
@@ -624,7 +627,6 @@
 	if (pidlTemp && pidlTemp->mkid.cb==0x00)
 	{ bSimplePidl = TRUE;
 	  TRACE(shell,"-- simple pidl\n");
-
 	}
 
 	if (_ILIsDesktop( pidl))
diff --git a/documentation/bugreports b/documentation/bugreports
index b20be06..df849d4 100644
--- a/documentation/bugreports
+++ b/documentation/bugreports
@@ -39,7 +39,7 @@
 
 	bash and other sh-like shells:
 
-	    wine -debugmsg +relay [other_options] program_name 2>&1 | tee filename.out
+	    wine -debugmsg +relay,+snoop [other_options] program_name 2>&1 | tee filename.out
 	    tail -100 filename.out > report_file
 
 	'report_file' will now contain the last hundred lines of the debugging
diff --git a/documentation/common_controls b/documentation/common_controls
index 7ee3b3f..d908d26 100644
--- a/documentation/common_controls
+++ b/documentation/common_controls
@@ -183,12 +183,14 @@
   Author:
       Dummy written by Eric Kohl. <ekohl@abo.rhein-zeitung.de>
       Ben Williams <biwillia@shrug.isdn.uiuc.edu>
+      Luc Tourangeau <luc@macadamian.com>
 
   Status:
       Under construction.
 
   Notes:
-      Author needed!! Any volunteers??
+      Basic data structure with related messages are supported.
+      No painting supported yet.
 
 
 3.11 Month Calendar Control
diff --git a/documentation/how-to-port b/documentation/how-to-port
index 4a89821..812e23d 100644
--- a/documentation/how-to-port
+++ b/documentation/how-to-port
@@ -72,7 +72,7 @@
   #ifdef HAVE_FOO_H
   #include <foo.h>
   #elif defined (HAVE_BAR_H)
-  #include <bat.h>
+  #include <bar.h>
   #endif
 
 If your system doesn't have a corresponding header file even
diff --git a/documentation/status/direct3D b/documentation/status/direct3D
index b73d30d..308889c 100644
--- a/documentation/status/direct3D
+++ b/documentation/status/direct3D
@@ -28,18 +28,24 @@
 Status
 ------
 
-I tested this code with two programs (all using Direct3D 5.0) :
+Some programs with which I tested the code :
 
- * BOIDS.EXE that comes with the 5.2 DirectX SDK : works great. Only
-   thing missing is the texturing and transparency on the spinning
-   gobes. Lighting seems to be a bit different than the Real One.
+ * BOIDS.EXE (DX5.0) that comes with the 5.2 DirectX SDK : works
+   great. Only thing missing is the texturing and transparency on the
+   spinning gobes. Lighting seems to be a bit different than the Real
+   One.
 
- * Tomb Raider II : works quite well (without texturing).
+ * Tomb Raider II (DX5.0) : works perfectly (but slowly). All the
+   calls needed to make TR2 work have been written.
+
+ * Jedi Knight (DX3.0) : does not start
+
+ * Shadow of the Empire demo (DX3.0) : runs but does not display
+   anything
 
 TODO
 ----
  * finish working on Execute Buffers (i.e. Direct3D 3.0)
- * texture mapping / blending effects
  * real GLX implementation (will need a complete rewrite of DirectDraw
    also) to have 3DFx support
  * restructuration of all the DDRAW.DLL (put that in the dll
@@ -52,4 +58,4 @@
 
 -- 
 Lionel Ulmer - ulmer@directprovider.net
-Last updated : Sun Jan 03 1999
+Last updated : Sun Jan 10 1999
diff --git a/files/Makefile.in b/files/Makefile.in
index b1937e1..a9033cf 100644
--- a/files/Makefile.in
+++ b/files/Makefile.in
@@ -1,6 +1,6 @@
 prefix     = @prefix@
 sysconfdir = @sysconfdir@
-DEFS       = @DLLFLAGS@ -D__WINE__ -DETCDIR=\"$(sysconfdir)\"
+DEFS       = @DLLFLAGS@ -D__WINE__ -DETCDIR="\"$(sysconfdir)\""
 TOPSRCDIR  = @top_srcdir@
 TOPOBJDIR  = ..
 SRCDIR     = @srcdir@
diff --git a/files/file.c b/files/file.c
index fddb304..2cfe9e2 100644
--- a/files/file.c
+++ b/files/file.c
@@ -67,6 +67,8 @@
 static DOS_FILE_LOCK *locks = NULL;
 static void DOS_RemoveFileLocks(FILE_OBJECT *file);
 
+/* Size of per-process table of DOS handles */
+#define DOS_TABLE_SIZE 256
 
 
 /***********************************************************************
@@ -421,13 +423,18 @@
     /* If write access failed, retry without GENERIC_WRITE */
 
     if ((reply.handle == -1) && !Options.failReadOnly &&
-        (access & GENERIC_WRITE) && (GetLastError() == ERROR_ACCESS_DENIED))
+        (access & GENERIC_WRITE)) 
     {
-        req.access &= ~GENERIC_WRITE;
-        CLIENT_SendRequest( REQ_CREATE_FILE, -1, 2,
-                            &req, sizeof(req),
-                            filename, strlen(filename) + 1 );
-        CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
+    	DWORD lasterror = GetLastError();
+	if ((lasterror == ERROR_ACCESS_DENIED) || 
+	    (lasterror == ERROR_WRITE_PROTECT))
+        {
+	    req.access &= ~GENERIC_WRITE;
+	    CLIENT_SendRequest( REQ_CREATE_FILE, -1, 2,
+				&req, sizeof(req),
+				filename, strlen(filename) + 1 );
+	    CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
+	}
     }
     if (reply.handle == -1) return INVALID_HANDLE_VALUE32;
 
@@ -730,25 +737,6 @@
 
 
 /***********************************************************************
- *           FILE_Dup2
- *
- * dup2() function for DOS handles.
- */
-HFILE32 FILE_Dup2( HFILE32 hFile1, HFILE32 hFile2 )
-{
-    FILE_OBJECT *file;
-
-    TRACE(file, "FILE_Dup2 for handle %d\n", hFile1 );
-    /* FIXME: should use DuplicateHandle */
-    if (!(file = FILE_GetFile( hFile1, 0, NULL ))) return HFILE_ERROR32;
-    if (!HANDLE_SetObjPtr( PROCESS_Current(), hFile2, &file->header, 0 ))
-        hFile2 = HFILE_ERROR32;
-    FILE_ReleaseFile( file );
-    return hFile2;
-}
-
-
-/***********************************************************************
  *           GetTempFileName16   (KERNEL.97)
  */
 UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
@@ -1014,7 +1002,7 @@
 HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
 {
     TRACE(file,"OpenFile16(%s,%i)\n", name, mode);
-    return HFILE32_TO_HFILE16(FILE_DoOpenFile( name, ofs, mode, FALSE ));
+    return FILE_AllocDosHandle( FILE_DoOpenFile( name, ofs, mode, FALSE ) );
 }
 
 
@@ -1028,12 +1016,117 @@
 
 
 /***********************************************************************
+ *           FILE_AllocDosHandle
+ *
+ * Allocate a DOS handle for a Win32 handle. The Win32 handle is no
+ * longer valid after this function (even on failure).
+ */
+HFILE16 FILE_AllocDosHandle( HANDLE32 handle )
+{
+    int i;
+    HANDLE32 *ptr = PROCESS_Current()->dos_handles;
+
+    if (!handle || (handle == INVALID_HANDLE_VALUE32))
+        return INVALID_HANDLE_VALUE16;
+
+    if (!ptr)
+    {
+        if (!(ptr = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY,
+                               sizeof(*ptr) * DOS_TABLE_SIZE )))
+            goto error;
+        PROCESS_Current()->dos_handles = ptr;
+        ptr[0] = GetStdHandle(STD_INPUT_HANDLE);
+        ptr[1] = GetStdHandle(STD_OUTPUT_HANDLE);
+        ptr[2] = GetStdHandle(STD_ERROR_HANDLE);
+        ptr[3] = GetStdHandle(STD_ERROR_HANDLE);
+        ptr[4] = GetStdHandle(STD_ERROR_HANDLE);
+    }
+
+    for (i = 0; i < DOS_TABLE_SIZE; i++, ptr++)
+        if (!*ptr)
+        {
+            *ptr = handle;
+            TRACE( file, "Got %d for h32 %d\n", i, handle );
+            return i;
+        }
+error:
+    DOS_ERROR( ER_TooManyOpenFiles, EC_ProgramError, SA_Abort, EL_Disk );
+    CloseHandle( handle );
+    return INVALID_HANDLE_VALUE16;
+}
+
+
+/***********************************************************************
+ *           FILE_GetHandle32
+ *
+ * Return the Win32 handle for a DOS handle.
+ */
+HANDLE32 FILE_GetHandle32( HFILE16 hfile )
+{
+    HANDLE32 *table = PROCESS_Current()->dos_handles;
+    if ((hfile >= DOS_TABLE_SIZE) || !table || !table[hfile])
+    {
+        DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
+        return INVALID_HANDLE_VALUE32;
+    }
+    return table[hfile];
+}
+
+
+/***********************************************************************
+ *           FILE_Dup2
+ *
+ * dup2() function for DOS handles.
+ */
+HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 )
+{
+    HANDLE32 *table = PROCESS_Current()->dos_handles;
+    HANDLE32 new_handle;
+
+    if ((hFile1 >= DOS_TABLE_SIZE) || (hFile2 >= DOS_TABLE_SIZE) ||
+        !table || !table[hFile1])
+    {
+        DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
+        return HFILE_ERROR16;
+    }
+    if (hFile2 < 5)
+    {
+        FIXME( file, "stdio handle closed, need proper conversion\n" );
+        DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
+        return HFILE_ERROR16;
+    }
+    if (!DuplicateHandle( GetCurrentProcess(), table[hFile1],
+                          GetCurrentProcess(), &new_handle,
+                          0, FALSE, DUPLICATE_SAME_ACCESS ))
+        return HFILE_ERROR16;
+    if (table[hFile2]) CloseHandle( table[hFile2] );
+    table[hFile2] = new_handle;
+    return hFile2;
+}
+
+
+/***********************************************************************
  *           _lclose16   (KERNEL.81)
  */
 HFILE16 WINAPI _lclose16( HFILE16 hFile )
 {
-    TRACE(file, "handle %d\n", hFile );
-    return CloseHandle( HFILE16_TO_HFILE32( hFile )  ) ? 0 : HFILE_ERROR16;
+    HANDLE32 *table = PROCESS_Current()->dos_handles;
+
+    if (hFile < 5)
+    {
+        FIXME( file, "stdio handle closed, need proper conversion\n" );
+        DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
+        return HFILE_ERROR16;
+    }
+    if ((hFile >= DOS_TABLE_SIZE) || !table || !table[hFile])
+    {
+        DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
+        return HFILE_ERROR16;
+    }
+    TRACE( file, "%d (handle32=%d)\n", hFile, table[hFile] );
+    CloseHandle( table[hFile] );
+    table[hFile] = 0;
+    return 0;
 }
 
 
@@ -1126,7 +1219,7 @@
     /* Some programs pass a count larger than the allocated buffer */
     maxlen = GetSelectorLimit( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
     if (count > maxlen) count = maxlen;
-    return _lread32(HFILE16_TO_HFILE32(hFile), PTR_SEG_TO_LIN(buffer), count );
+    return _lread32(FILE_GetHandle32(hFile), PTR_SEG_TO_LIN(buffer), count );
 }
 
 
@@ -1155,7 +1248,7 @@
  */
 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
 {
-    return (UINT16)_lread32(HFILE16_TO_HFILE32(hFile), buffer, (LONG)count );
+    return (UINT16)_lread32(FILE_GetHandle32(hFile), buffer, (LONG)count );
 }
 
 
@@ -1165,7 +1258,7 @@
 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
 {
     TRACE(file, "%s %02x\n", path, attr );
-    return (HFILE16) HFILE32_TO_HFILE16(_lcreat32( path, attr ));
+    return FILE_AllocDosHandle( _lcreat32( path, attr ) );
 }
 
 
@@ -1182,14 +1275,14 @@
 
 
 /***********************************************************************
- *           _lcreat_uniq   (Not a Windows API)
+ *           _lcreat16_uniq   (Not a Windows API)
  */
-HFILE32 _lcreat_uniq( LPCSTR path, INT32 attr )
+HFILE16 _lcreat16_uniq( LPCSTR path, INT32 attr )
 {
     TRACE(file, "%s %02x\n", path, attr );
-    return CreateFile32A( path, GENERIC_READ | GENERIC_WRITE,
-                          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
-                          CREATE_NEW, attr, -1 );
+    return FILE_AllocDosHandle( CreateFile32A( path, GENERIC_READ | GENERIC_WRITE,
+                                               FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+                                               CREATE_NEW, attr, -1 ));
 }
 
 
@@ -1236,7 +1329,7 @@
  */
 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
 {
-    return SetFilePointer( HFILE16_TO_HFILE32(hFile), lOffset, NULL, nOrigin );
+    return SetFilePointer( FILE_GetHandle32(hFile), lOffset, NULL, nOrigin );
 }
 
 
@@ -1254,7 +1347,7 @@
  */
 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
 {
-    return HFILE32_TO_HFILE16(_lopen32( path, mode ));
+    return FILE_AllocDosHandle( _lopen32( path, mode ) );
 }
 
 
@@ -1276,7 +1369,7 @@
  */
 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
 {
-    return (UINT16)_hwrite32( HFILE16_TO_HFILE32(hFile), buffer, (LONG)count );
+    return (UINT16)_hwrite32( FILE_GetHandle32(hFile), buffer, (LONG)count );
 }
 
 /***********************************************************************
@@ -1293,7 +1386,7 @@
  */
 LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
 {
-    return _lread32( HFILE16_TO_HFILE32(hFile), buffer, count );
+    return _lread32( FILE_GetHandle32(hFile), buffer, count );
 }
 
 
@@ -1311,7 +1404,7 @@
  */
 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
 {
-    return _hwrite32( HFILE16_TO_HFILE32(hFile), buffer, count );
+    return _hwrite32( FILE_GetHandle32(hFile), buffer, count );
 }
 
 
diff --git a/graphics/d3d_private.h b/graphics/d3d_private.h
index c5f81ae..6d1fd70 100644
--- a/graphics/d3d_private.h
+++ b/graphics/d3d_private.h
@@ -53,6 +53,13 @@
   TRACE(ddraw, "%f %f %f %f\n", (mat)->_31, (mat)->_32, (mat)->_33, (mat)->_34); \
   TRACE(ddraw, "%f %f %f %f\n", (mat)->_41, (mat)->_42, (mat)->_43, (mat)->_44);
 
+typedef struct render_state {
+  /* This is used for the device mode */
+  GLenum src, dst;
+  /* This is used for textures */
+  GLenum mag, min;
+} RenderState;
+
 typedef struct OpenGL_IDirect3DDevice2 {
   IDirect3DDevice2 common;
   
@@ -60,6 +67,12 @@
   OSMesaContext ctx;
   unsigned char *buffer;
   
+  /* The current render state */
+  RenderState rs;
+
+  /* The last type of vertex drawn */
+  D3DVERTEXTYPE vt;
+  
   float world_mat[16];
   float view_mat[16];
   float proj_mat[16];
@@ -72,6 +85,9 @@
   OSMesaContext ctx;
   unsigned char *buffer;
   
+  /* The current render state */
+  RenderState rs;
+  
   D3DMATRIX *world_mat;
   D3DMATRIX *view_mat;
   D3DMATRIX *proj_mat;
@@ -81,11 +97,11 @@
   TRACE(ddraw, " " s " : %f %f %f %f\n",           \
 	(v).r.r, (v).g.g, (v).b.b, (v).a.a);
 
-#endif /* HAVE_MESAGL */
-
 /* Common functions defined in d3dcommon.c */
 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
-		      DWORD dwRenderState) ;
+		      DWORD dwRenderState, RenderState *rs) ;
+
+#endif /* HAVE_MESAGL */
 
 /* All non-static functions 'exported' by various sub-objects */
 extern LPDIRECT3DTEXTURE2 d3dtexture2_create(LPDIRECTDRAWSURFACE3 surf) ;
diff --git a/graphics/d3dcommon.c b/graphics/d3dcommon.c
index b71351a..e6e86ba 100644
--- a/graphics/d3dcommon.c
+++ b/graphics/d3dcommon.c
@@ -61,6 +61,7 @@
     "D3DRENDERSTATE_STIPPLEENABLE",
     "D3DRENDERSTATE_EDGEANTIALIAS",
     "D3DRENDERSTATE_COLORKEYENABLE",
+    "ERR",
     "D3DRENDERSTATE_BORDERCOLOR",
     "D3DRENDERSTATE_TEXTUREADDRESSU",
     "D3DRENDERSTATE_TEXTUREADDRESSV",
@@ -69,6 +70,8 @@
     "D3DRENDERSTATE_RANGEFOGENABLE",
     "D3DRENDERSTATE_ANISOTROPY",
     "D3DRENDERSTATE_FLUSHBATCH",
+    "ERR", "ERR", "ERR", "ERR", "ERR", "ERR", "ERR",
+    "ERR", "ERR", "ERR", "ERR", "ERR", "ERR",
     "D3DRENDERSTATE_STIPPLEPATTERN00",
     "D3DRENDERSTATE_STIPPLEPATTERN01",
     "D3DRENDERSTATE_STIPPLEPATTERN02",
@@ -108,7 +111,7 @@
 
 
 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
-		      DWORD dwRenderState)
+		      DWORD dwRenderState, RenderState *rs)
 {
 
   if (TRACE_ON(ddraw))
@@ -116,13 +119,13 @@
 
   /* First, all the stipple patterns */
   if ((dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00) && 
-      (dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN31)) {
-
+      (dwRenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)) {
+    ERR(ddraw, "Unhandled stipple !\n");
   } else {
     /* All others state variables */
     switch (dwRenderStateType) {
 
-    case D3DRENDERSTATE_TEXTUREHANDLE: {
+    case D3DRENDERSTATE_TEXTUREHANDLE: {    /*  1 */
       LPDIRECT3DTEXTURE2 tex = (LPDIRECT3DTEXTURE2) dwRenderState;
       
       if (tex == NULL) {
@@ -131,13 +134,21 @@
       } else {
 	TRACE(ddraw, "setting OpenGL texture handle : %d\n", tex->tex_name);
 	glEnable(GL_TEXTURE_2D);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+	/* Default parameters */
 	glBindTexture(GL_TEXTURE_2D, tex->tex_name);
+	/* To prevent state change, we could test here what are the parameters
+	   stored in the texture */
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
       }
     } break;
 
+    case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
+      if (dwRenderState)
+	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+      else
+	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
+      break;
       
     case D3DRENDERSTATE_ZENABLE:          /*  7 */
       if (dwRenderState)
@@ -146,6 +157,31 @@
 	glDisable(GL_DEPTH_TEST);
       break;
       
+    case D3DRENDERSTATE_FILLMODE:           /*  8 */
+      switch ((D3DFILLMODE) dwRenderState) {
+      case D3DFILL_SOLID:
+	break;
+
+      default:
+	ERR(ddraw, "Unhandled fill mode !\n");
+      }
+      break;
+
+    case D3DRENDERSTATE_SHADEMODE:          /*  9 */
+      switch ((D3DSHADEMODE) dwRenderState) {
+      case D3DSHADE_FLAT:
+	glShadeModel(GL_FLAT);
+	break;
+
+      case D3DSHADE_GOURAUD:
+	glShadeModel(GL_SMOOTH);
+	break;
+
+      default:
+	ERR(ddraw, "Unhandled shade mode !\n");
+      }
+      break;
+      
     case D3DRENDERSTATE_ZWRITEENABLE:     /* 14 */
       if (dwRenderState)
 	glDepthMask(GL_TRUE);
@@ -153,6 +189,95 @@
 	glDepthMask(GL_FALSE);
       break;
       
+    case D3DRENDERSTATE_TEXTUREMAG:         /* 17 */
+      switch ((D3DTEXTUREFILTER) dwRenderState) {
+      case D3DFILTER_NEAREST:
+	rs->mag = GL_NEAREST;
+	break;
+	
+      case D3DFILTER_LINEAR:
+	rs->mag = GL_LINEAR;
+	break;
+	
+      default:
+	ERR(ddraw, "Unhandled texture mag !\n");
+      }
+      break;
+
+    case D3DRENDERSTATE_TEXTUREMIN:         /* 18 */
+      switch ((D3DTEXTUREFILTER) dwRenderState) {
+      case D3DFILTER_NEAREST:
+	rs->min = GL_NEAREST;
+	break;
+	
+      case D3DFILTER_LINEAR:
+	rs->mag = GL_LINEAR;
+	break;
+	
+      default:
+	ERR(ddraw, "Unhandled texture min !\n");
+      }
+      break;
+      
+    case D3DRENDERSTATE_SRCBLEND:           /* 19 */
+      switch ((D3DBLEND) dwRenderState) {
+      case D3DBLEND_SRCALPHA:
+	rs->src = GL_SRC_ALPHA;
+	break;
+
+      default:
+	ERR(ddraw, "Unhandled blend mode !\n");
+      }
+      
+      glBlendFunc(rs->src, rs->dst);
+      break;
+      
+    case D3DRENDERSTATE_DESTBLEND:          /* 20 */
+      switch ((D3DBLEND) dwRenderState) {
+      case D3DBLEND_INVSRCALPHA:
+	rs->dst = GL_ONE_MINUS_SRC_ALPHA;
+	break;
+	
+      default:
+	ERR(ddraw, "Unhandled blend mode !\n");
+      }
+      
+      glBlendFunc(rs->src, rs->dst);
+      break;
+
+    case D3DRENDERSTATE_TEXTUREMAPBLEND:    /* 21 */
+      switch ((D3DTEXTUREBLEND) dwRenderState) {
+      case D3DTBLEND_MODULATE:
+      case D3DTBLEND_MODULATEALPHA:
+	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+	break;
+
+      default:
+	ERR(ddraw, "Unhandled texture environment !\n");
+      }
+      break;
+      
+    case D3DRENDERSTATE_CULLMODE:           /* 22 */
+      switch ((D3DCULL) dwRenderState) {
+      case D3DCULL_NONE:
+	glDisable(GL_CULL_FACE);
+	break;
+	
+      case D3DCULL_CW:
+	glEnable(GL_CULL_FACE);
+	glFrontFace(GL_CW);
+	break;
+	
+      case D3DCULL_CCW:
+	glEnable(GL_CULL_FACE);
+	glFrontFace(GL_CCW);
+	break;
+	
+      default:
+	ERR(ddraw, "Unhandled cull mode !\n");
+      }
+      break;
+      
     case D3DRENDERSTATE_ZFUNC:            /* 23 */
       switch ((D3DCMPFUNC) dwRenderState) {
       case D3DCMP_NEVER:
@@ -192,8 +317,25 @@
 	glDisable(GL_DITHER);
       break;
       
+    case D3DRENDERSTATE_ALPHABLENDENABLE:   /* 27 */
+      if (dwRenderState)
+	glEnable(GL_BLEND);
+      else
+	glDisable(GL_BLEND);
+      break;
+
+    case D3DRENDERSTATE_COLORKEYENABLE:     /* 41 */
+      if (dwRenderState)
+	glEnable(GL_BLEND);
+      else
+	glDisable(GL_BLEND);
+      break;
+
+    case D3DRENDERSTATE_FLUSHBATCH:         /* 50 */
+      break;
+      
     default:
-      FIXME(ddraw, "Unhandled Render State\n");
+      ERR(ddraw, "Unhandled Render State\n");
       break;
     }
   }
diff --git a/graphics/d3ddevices.c b/graphics/d3ddevices.c
index a53f6db..e6cf395 100644
--- a/graphics/d3ddevices.c
+++ b/graphics/d3ddevices.c
@@ -96,7 +96,7 @@
   d1->dlcLightingCaps.dwSize = sizeof(D3DLIGHTINGCAPS);
   d1->dlcLightingCaps.dwCaps = D3DLIGHTCAPS_DIRECTIONAL | D3DLIGHTCAPS_PARALLELPOINT | D3DLIGHTCAPS_POINT | D3DLIGHTCAPS_SPOT;
   d1->dlcLightingCaps.dwLightingModel = D3DLIGHTINGMODEL_RGB;
-  glGetIntegerv(GL_MAX_LIGHTS, &maxlight); d1->dlcLightingCaps.dwNumLights = maxlight;
+  d1->dlcLightingCaps.dwNumLights = 16; /* glGetIntegerv(GL_MAX_LIGHTS, &maxlight); d1->dlcLightingCaps.dwNumLights = maxlight; */
   fill_opengl_primcaps(&(d1->dpcLineCaps));
   fill_opengl_primcaps(&(d1->dpcTriCaps));  
   d1->dwDeviceRenderBitDepth  = DDBD_16;
@@ -160,6 +160,11 @@
     odev->ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
     odev->buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
 			     surface->s.surface_desc.dwWidth * surface->s.surface_desc.dwHeight * 4);
+    odev->rs.src = GL_ONE;
+    odev->rs.dst = GL_ZERO;
+    odev->rs.mag = GL_NEAREST;
+    odev->rs.min = GL_NEAREST;
+    odev->vt     = 0;
     
     memcpy(odev->world_mat, id_mat, 16 * sizeof(float));
     memcpy(odev->view_mat , id_mat, 16 * sizeof(float));
@@ -594,10 +599,12 @@
 						      D3DRENDERSTATETYPE dwRenderStateType,
 						      DWORD dwRenderState)
 {
+  OpenGL_IDirect3DDevice2 *odev = (OpenGL_IDirect3DDevice2 *) this;
+
   TRACE(ddraw, "(%p)->(%d,%ld)\n", this, dwRenderStateType, dwRenderState);
   
   /* Call the render state functions */
-  set_render_state(dwRenderStateType, dwRenderState);
+  set_render_state(dwRenderStateType, dwRenderState, &(odev->rs));
   
   return DD_OK;
 }
@@ -756,6 +763,165 @@
   return DD_OK;
 }
 
+#define DRAW_PRIMITIVE(MAXVERT,INDEX)						\
+  /* Puts GL in the correct lighting mode */					\
+  if (odev->vt != d3dv) {							\
+    if (odev->vt == D3DVT_TLVERTEX) {						\
+      /* Need to put the correct transformation again */			\
+      glMatrixMode(GL_MODELVIEW);						\
+      glLoadMatrixf((float *) &(odev->world_mat));				\
+      glMatrixMode(GL_PROJECTION);						\
+      glLoadMatrixf((float *) &(odev->proj_mat));				\
+      glMultMatrixf((float *) &(odev->view_mat));				\
+    }										\
+										\
+    switch (d3dv) {								\
+    case D3DVT_VERTEX:								\
+      TRACE(ddraw, "Standard Vertex\n");					\
+      glEnable(GL_LIGHTING);							\
+      break;									\
+										\
+    case D3DVT_LVERTEX:								\
+      TRACE(ddraw, "Lighted Vertex\n");						\
+      glDisable(GL_LIGHTING);							\
+      break;									\
+										\
+    case D3DVT_TLVERTEX: {							\
+      GLdouble height, width, minZ, maxZ;					\
+										\
+      TRACE(ddraw, "Transformed - Lighted Vertex\n");				\
+      /* First, disable lighting */						\
+      glDisable(GL_LIGHTING);							\
+										\
+      /* Then do not put any transformation matrixes */				\
+      glMatrixMode(GL_MODELVIEW);						\
+      glLoadIdentity();								\
+      glMatrixMode(GL_PROJECTION);						\
+      glLoadIdentity();								\
+										\
+      if (this->current_viewport == NULL) {					\
+	ERR(ddraw, "No current viewport !\n");					\
+	/* Using standard values */						\
+	height = 640.0;								\
+	width = 480.0;								\
+	minZ = -10.0;								\
+	maxZ = 10.0;								\
+      } else {									\
+	if (this->current_viewport->use_vp2) {					\
+	  height = (GLdouble) this->current_viewport->viewport.vp2.dwHeight;	\
+	  width  = (GLdouble) this->current_viewport->viewport.vp2.dwWidth;	\
+	  minZ   = (GLdouble) this->current_viewport->viewport.vp2.dvMinZ;	\
+	  maxZ   = (GLdouble) this->current_viewport->viewport.vp2.dvMaxZ;	\
+	} else {								\
+	  height = (GLdouble) this->current_viewport->viewport.vp1.dwHeight;	\
+	  width  = (GLdouble) this->current_viewport->viewport.vp1.dwWidth;	\
+	  minZ   = (GLdouble) this->current_viewport->viewport.vp1.dvMinZ;	\
+	  maxZ   = (GLdouble) this->current_viewport->viewport.vp1.dvMaxZ;	\
+	}									\
+      }										\
+										\
+      glOrtho(0.0, width, height, 0.0, -minZ, -maxZ);				\
+    } break;									\
+										\
+    default:									\
+      ERR(ddraw, "Unhandled vertex type\n");					\
+      break;									\
+    }										\
+										\
+    odev->vt = d3dv;								\
+  }										\
+										\
+  switch (d3dp) {								\
+  case D3DPT_POINTLIST:								\
+    TRACE(ddraw, "Start POINTS\n");						\
+    glBegin(GL_POINTS);								\
+    break;									\
+										\
+  case D3DPT_LINELIST:								\
+    TRACE(ddraw, "Start LINES\n");						\
+    glBegin(GL_LINES);								\
+    break;									\
+										\
+  case D3DPT_LINESTRIP:								\
+    TRACE(ddraw, "Start LINE_STRIP\n");						\
+    glBegin(GL_LINE_STRIP);							\
+    break;									\
+										\
+  case D3DPT_TRIANGLELIST:							\
+    TRACE(ddraw, "Start TRIANGLES\n");						\
+    glBegin(GL_TRIANGLES);							\
+    break;									\
+										\
+  case D3DPT_TRIANGLESTRIP:							\
+    TRACE(ddraw, "Start TRIANGLE_STRIP\n");					\
+    glBegin(GL_TRIANGLE_STRIP);							\
+    break;									\
+										\
+  case D3DPT_TRIANGLEFAN:							\
+    TRACE(ddraw, "Start TRIANGLE_FAN\n");					\
+    glBegin(GL_TRIANGLE_FAN);							\
+    break;									\
+										\
+  default:									\
+    TRACE(ddraw, "Unhandled primitive\n");					\
+    break;									\
+  }										\
+										\
+  /* Draw the primitives */							\
+  for (vx_index = 0; vx_index < MAXVERT; vx_index++) {				\
+    switch (d3dv) {								\
+    case D3DVT_VERTEX: {							\
+      D3DVERTEX *vx = ((D3DVERTEX *) lpvertex) + INDEX;				\
+										\
+      glNormal3f(vx->nx.nx, vx->ny.ny, vx->nz.nz);				\
+      glVertex3f(vx->x.x, vx->y.y, vx->z.z);					\
+      TRACE(ddraw, "   V: %f %f %f\n", vx->x.x, vx->y.y, vx->z.z);		\
+    } break;									\
+										\
+    case D3DVT_LVERTEX: {							\
+      D3DLVERTEX *vx = ((D3DLVERTEX *) lpvertex) + INDEX;			\
+      DWORD col = vx->c.color;							\
+										\
+      glColor3f(((col >> 16) & 0xFF) / 255.0,					\
+		((col >>  8) & 0xFF) / 255.0,					\
+		((col >>  0) & 0xFF) / 255.0);					\
+      glVertex3f(vx->x.x, vx->y.y, vx->z.z);					\
+      TRACE(ddraw, "  LV: %f %f %f (%02lx %02lx %02lx)\n",			\
+	    vx->x.x, vx->y.y, vx->z.z,						\
+	    ((col >> 16) & 0xFF), ((col >>  8) & 0xFF), ((col >>  0) & 0xFF));	\
+    } break;									\
+										\
+    case D3DVT_TLVERTEX: {							\
+      D3DTLVERTEX *vx = ((D3DTLVERTEX *) lpvertex) + INDEX;			\
+      DWORD col = vx->c.color;							\
+										\
+      glColor3f(((col >> 16) & 0xFF) / 255.0,					\
+		((col >>  8) & 0xFF) / 255.0,					\
+		((col >>  0) & 0xFF) / 255.0);					\
+      glTexCoord2f(vx->u.tu, vx->v.tv);						\
+      if (vx->r.rhw < 0.01)							\
+	glVertex3f(vx->x.sx,							\
+		   vx->y.sy,							\
+		   vx->z.sz);							\
+      else									\
+	glVertex4f(vx->x.sx / vx->r.rhw,					\
+		   vx->y.sy / vx->r.rhw,					\
+		   vx->z.sz / vx->r.rhw,					\
+		   1.0 / vx->r.rhw);						\
+      TRACE(ddraw, " TLV: %f %f %f (%02lx %02lx %02lx) (%f %f) (%f)\n",		\
+	    vx->x.sx, vx->y.sy, vx->z.sz,					\
+	    ((col >> 16) & 0xFF), ((col >>  8) & 0xFF), ((col >>  0) & 0xFF),	\
+	    vx->u.tu, vx->v.tv, vx->r.rhw);					\
+    } break;									\
+										\
+    default:									\
+      TRACE(ddraw, "Unhandled vertex type\n");					\
+      break;									\
+    }										\
+  }										\
+										\
+  glEnd();									\
+  TRACE(ddraw, "End\n");
 
 
 static HRESULT WINAPI IDirect3DDevice2_DrawPrimitive(LPDIRECT3DDEVICE2 this,
@@ -765,147 +931,18 @@
 						     DWORD vertcount,
 						     DWORD dwFlags)
 {
+  OpenGL_IDirect3DDevice2 *odev = (OpenGL_IDirect3DDevice2 *) this;
   int vx_index;
   
   TRACE(ddraw, "(%p)->(%d,%d,%p,%ld,%08lx): stub\n", this, d3dp, d3dv, lpvertex, vertcount, dwFlags);
 
-  /* Puts GL in the correct lighting mode */
-  switch (d3dv) {
-  case D3DVT_VERTEX:
-    TRACE(ddraw, "Standard Vertex\n");
-    glEnable(GL_LIGHTING);
-    break;
+  DRAW_PRIMITIVE(vertcount, vx_index);
     
-  case D3DVT_LVERTEX:
-    TRACE(ddraw, "Lighted Vertex\n");
-    glDisable(GL_LIGHTING);
-    break;
-    
-  case D3DVT_TLVERTEX: {
-    GLdouble height, width;
-    
-    TRACE(ddraw, "Transformed - Lighted Vertex\n");
-    /* First, disable lighting */
-    glDisable(GL_LIGHTING);
-
-    /* Then do not put any transformation matrixes */
-    glMatrixMode(GL_MODELVIEW);
-    glLoadIdentity();
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-
-    if (this->current_viewport == NULL) {
-      ERR(ddraw, "No current viewport !\n");
-      /* Using standard values */
-      height = 640.0;
-      width = 480.0;
-    } else {
-      if (this->current_viewport->use_vp2) {
-	height = (GLdouble) this->current_viewport->viewport.vp2.dwHeight;
-	width  = (GLdouble) this->current_viewport->viewport.vp2.dwWidth;
-      } else {
-	height = (GLdouble) this->current_viewport->viewport.vp1.dwHeight;
-	width  = (GLdouble) this->current_viewport->viewport.vp1.dwWidth;
+  return D3D_OK;
       }
-    }
-
-    glOrtho(0.0, width, height, 0.0, 1.5, -1.5);
-  } break;
     
-  default:
-    TRACE(ddraw, "Unhandled vertex type\n");
-    break;
-  }
 
-  switch (d3dp) {
-  case D3DPT_POINTLIST:
-    TRACE(ddraw, "Start POINTS\n");
-    glBegin(GL_POINTS);
-    break;
-
-  case D3DPT_LINELIST:
-    TRACE(ddraw, "Start LINES\n");
-    glBegin(GL_LINES);
-    break;
-    
-  case D3DPT_LINESTRIP:
-    TRACE(ddraw, "Start LINE_STRIP\n");
-    glBegin(GL_LINE_STRIP);
-    break;
-    
-  case D3DPT_TRIANGLELIST:
-    TRACE(ddraw, "Start TRIANGLES\n");
-    glBegin(GL_TRIANGLES);
-    break;
-
-  case D3DPT_TRIANGLESTRIP:
-    TRACE(ddraw, "Start TRIANGLE_STRIP\n");
-    glBegin(GL_TRIANGLE_STRIP);
-    break;
-
-  case D3DPT_TRIANGLEFAN:
-    TRACE(ddraw, "Start TRIANGLE_FAN\n");
-    glBegin(GL_TRIANGLE_FAN);
-    break;
-    
-  default:
-    TRACE(ddraw, "Unhandled primitive\n");
-    break;
-  }
-  
-  /* Draw the primitives */
-  for (vx_index = 0; vx_index < vertcount; vx_index++) {
-    switch (d3dv) {
-    case D3DVT_VERTEX: {
-      D3DVERTEX *vx = ((D3DVERTEX *) lpvertex) + vx_index;
       
-      glNormal3f(vx->nx.nx, vx->ny.ny, vx->nz.nz);
-      glVertex3f(vx->x.x, vx->y.y, vx->z.z);
-      TRACE(ddraw, "   V: %f %f %f\n", vx->x.x, vx->y.y, vx->z.z);
-    } break;
-      
-    case D3DVT_LVERTEX: {
-      D3DLVERTEX *vx = ((D3DLVERTEX *) lpvertex) + vx_index;
-      DWORD col = vx->c.color;
-      
-      glColor3f(((col >> 16) & 0xFF) / 255.0,
-		((col >>  8) & 0xFF) / 255.0,
-		((col >>  0) & 0xFF) / 255.0);
-      glVertex3f(vx->x.x, vx->y.y, vx->z.z);
-      TRACE(ddraw, "  LV: %f %f %f (%02lx %02lx %02lx)\n",
-	    vx->x.x, vx->y.y, vx->z.z,
-	    ((col >> 16) & 0xFF), ((col >>  8) & 0xFF), ((col >>  0) & 0xFF));
-    } break;
-
-    case D3DVT_TLVERTEX: {
-      D3DTLVERTEX *vx = ((D3DTLVERTEX *) lpvertex) + vx_index;
-      DWORD col = vx->c.color;
-      
-      glColor3f(((col >> 16) & 0xFF) / 255.0,
-		((col >>  8) & 0xFF) / 255.0,
-		((col >>  0) & 0xFF) / 255.0);
-      glTexCoord2f(vx->u.tu, vx->v.tv);
-      glVertex3f(vx->x.sx, vx->y.sy, vx->z.sz);
-      TRACE(ddraw, " TLV: %f %f %f (%02lx %02lx %02lx) (%f %f)\n",
-	    vx->x.sx, vx->y.sy, vx->z.sz,
-	    ((col >> 16) & 0xFF), ((col >>  8) & 0xFF), ((col >>  0) & 0xFF),
-	    vx->u.tu, vx->v.tv);
-    } break;
-      
-    default:
-      TRACE(ddraw, "Unhandled vertex type\n");
-      break;
-    }
-  }
-  
-  glEnd();
-  TRACE(ddraw, "End\n");
-   
-  return DD_OK;
-}
-
-
-
 static HRESULT WINAPI IDirect3DDevice2_DrawIndexedPrimitive(LPDIRECT3DDEVICE2 this,
 							    D3DPRIMITIVETYPE d3dp,
 							    D3DVERTEXTYPE d3dv,
@@ -915,73 +952,14 @@
 							    DWORD indexcount,
 							    DWORD dwFlags)
 {
+  OpenGL_IDirect3DDevice2 *odev = (OpenGL_IDirect3DDevice2 *) this;
   int vx_index;
   
   TRACE(ddraw, "(%p)->(%d,%d,%p,%ld,%p,%ld,%08lx): stub\n", this, d3dp, d3dv, lpvertex, vertcount, lpindexes, indexcount, dwFlags);
   
-  /* Puts GL in the correct lighting mode */
-  switch (d3dv) {
-  case D3DVT_VERTEX:
-    glEnable(GL_LIGHTING);
-    break;
-    
-  case D3DVT_LVERTEX:
-  case D3DVT_TLVERTEX:
-    glDisable(GL_LIGHTING);
-    break;
-    
-  default:
-    break;
-  }
+  DRAW_PRIMITIVE(indexcount, lpindexes[vx_index]);
   
-  switch (d3dp) {
-  case D3DPT_LINESTRIP:
-    TRACE(ddraw, "Start LINE_STRIP\n");
-    glBegin(GL_LINE_STRIP);
-    break;
-    
-  case D3DPT_TRIANGLELIST:
-    TRACE(ddraw, "Start TRIANGLES\n");
-    glBegin(GL_TRIANGLES);
-    break;
-    
-  default:
-    break;
-  }
-  
-  /* Draw the primitives */
-  for (vx_index = 0; vx_index < indexcount; vx_index++) {
-    switch (d3dv) {
-    case D3DVT_VERTEX: {
-      D3DVERTEX *vx = ((D3DVERTEX *) lpvertex) + lpindexes[vx_index];
-      
-      glNormal3f(vx->nx.nx, vx->ny.ny, vx->nz.nz);
-      glVertex3f(vx->x.x, vx->y.y, vx->z.z);
-      TRACE(ddraw, "   V: %f %f %f\n", vx->x.x, vx->y.y, vx->z.z);
-    } break;
-      
-    case D3DVT_LVERTEX: {
-      D3DLVERTEX *vx = ((D3DLVERTEX *) lpvertex) + lpindexes[vx_index];
-      DWORD col = vx->c.color;
-      
-      glColor3f(((col >> 16) & 0xFF) / 255.0,
-		((col >>  8) & 0xFF) / 255.0,
-		((col >>  0) & 0xFF) / 255.0);
-      glVertex3f(vx->x.x, vx->y.y, vx->z.z);
-      TRACE(ddraw, "  LV: %f %f %f (%02lx %02lx %02lx)\n",
-	    vx->x.x, vx->y.y, vx->z.z,
-	    ((col >> 16) & 0xFF), ((col >>  8) & 0xFF), ((col >>  0) & 0xFF));
-    } break;
-      
-    default:
-      break;
-    }
-  }
-  
-  glEnd();
-  TRACE(ddraw, "End\n");
-  
-  return DD_OK;
+  return D3D_OK;
 }
 
 
@@ -1101,6 +1079,10 @@
     odev->ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
     odev->buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
 			     surface->s.surface_desc.dwWidth * surface->s.surface_desc.dwHeight * 4);
+    odev->rs.src = GL_ONE;
+    odev->rs.dst = GL_ZERO;
+    odev->rs.mag = GL_NEAREST;
+    odev->rs.min = GL_NEAREST;
 
     odev->world_mat = (LPD3DMATRIX) &id_mat;
     odev->view_mat  = (LPD3DMATRIX) &id_mat;
diff --git a/graphics/d3dexecutebuffer.c b/graphics/d3dexecutebuffer.c
index 4fe4f04..5152300 100644
--- a/graphics/d3dexecutebuffer.c
+++ b/graphics/d3dexecutebuffer.c
@@ -275,7 +275,7 @@
 	LPD3DSTATE ci = (LPD3DSTATE) instr;
 	
 	/* Handle the state transform */
-	set_render_state(ci->t.drstRenderStateType, ci->v.dwArg[0]);
+	set_render_state(ci->t.drstRenderStateType, ci->v.dwArg[0], &(odev->rs));
 
 	instr += size;
       }
diff --git a/graphics/d3dtexture.c b/graphics/d3dtexture.c
index 14bc4c4..0344c9c 100644
--- a/graphics/d3dtexture.c
+++ b/graphics/d3dtexture.c
@@ -84,6 +84,12 @@
   FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
   
   if (!--(this->ref)) {
+    /* Delete texture from OpenGL */
+    glDeleteTextures(1, &(this->tex_name));
+    
+    /* Release surface */
+    this->surface->lpvtbl->fnRelease(this->surface);
+    
     HeapFree(GetProcessHeap(),0,this);
     return 0;
   }
@@ -168,17 +174,19 @@
     ERR(ddraw, "Error in surface sizes\n");
     return D3DERR_TEXTURE_LOAD_FAILED;
   } else {
-    LPDIRECT3DDEVICE2 d3dd = (LPDIRECT3DDEVICE2) this->D3Ddevice;
+    /* LPDIRECT3DDEVICE2 d3dd = (LPDIRECT3DDEVICE2) this->D3Ddevice; */
     /* I should put a macro for the calculus of bpp */
     int bpp = (src_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8 ?
 	       1 /* 8 bit of palette index */:
 	       src_d->ddpfPixelFormat.x.dwRGBBitCount / 8 /* RGB bits for each colors */ );
+    GLuint current_texture;
 
     /* Not sure if this is usefull ! */
     memcpy(dst_d->y.lpSurface, src_d->y.lpSurface, src_d->dwWidth * src_d->dwHeight * bpp);
 
     /* Now, load the texture */
-    d3dd->set_context(d3dd);
+    /* d3dd->set_context(d3dd); We need to set the context somehow.... */
+    glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
     glBindTexture(GL_TEXTURE_2D, this->tex_name);
 
     if (src_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
@@ -186,14 +194,45 @@
       BYTE table[256][4];
       int i;
       
+      if (pal == NULL) {
+	ERR(ddraw, "Palettized texture Loading with a NULL palette !\n");
+	return D3DERR_TEXTURE_LOAD_FAILED;
+      }
+
       /* Get the surface's palette */
       for (i = 0; i < 256; i++) {
 	table[i][0] = pal->palents[i].peRed;
 	table[i][1] = pal->palents[i].peGreen;
 	table[i][2] = pal->palents[i].peBlue;
+	if ((this->surface->s.surface_desc.dwFlags & DDSD_CKSRCBLT) &&
+	    (i >= this->surface->s.surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue) &&
+	    (i <= this->surface->s.surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue))
+	  table[i][3] = 0x00;
+	else
 	table[i][3] = 0xFF;
       }
       
+#if 0
+      /* If you want to see how the game manages its textures :-) */
+      {
+	FILE *f;
+	char buf[32];
+	int x, y;
+	
+	sprintf(buf, "%d.pnm", this->tex_name);
+	f = fopen(buf, "wb");
+	fprintf(f, "P6\n%d %d\n255\n", src_d->dwWidth, src_d->dwHeight);
+	for (y = 0; y < src_d->dwHeight; y++) {
+	  for (x = 0; x < src_d->dwWidth; x++) {
+	    unsigned char c = ((unsigned char *) src_d->y.lpSurface)[y * src_d->dwWidth + x];
+	    fputc(table[c][0], f);
+	    fputc(table[c][1], f);
+	    fputc(table[c][2], f);
+	  }
+	}
+	fclose(f);
+      }
+#endif 
       /* Use Paletted Texture Extension */
       glColorTableEXT(GL_TEXTURE_2D,    /* target */
 		      GL_RGBA,          /* internal format */
@@ -213,9 +252,11 @@
     } else {
       ERR(ddraw, "Unhandled texture format\n");
     }
+
+    glBindTexture(GL_TEXTURE_2D, current_texture);
   }
   
-  return DD_OK;
+  return D3D_OK;
 }
 
 
diff --git a/graphics/d3dviewport.c b/graphics/d3dviewport.c
index 754d410..c593e34 100644
--- a/graphics/d3dviewport.c
+++ b/graphics/d3dviewport.c
@@ -210,6 +210,7 @@
 					       LPD3DRECT lpRects,
 					       DWORD dwFlags)
 {
+  GLboolean ztest;
   FIXME(ddraw, "(%p)->(%8ld,%p,%08lx): stub\n", this, dwCount, lpRects, dwFlags);
 
   /* For the moment, ignore the rectangles */
@@ -221,8 +222,10 @@
       this->device.active_device1->set_context(this->device.active_device1);
 
     /* Clears the screen */
+    glGetBooleanv(GL_DEPTH_TEST, &ztest);
     glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glDepthMask(ztest);
   }
   
   return DD_OK;
diff --git a/graphics/ddraw.c b/graphics/ddraw.c
index f297b9f..49f570d 100644
--- a/graphics/ddraw.c
+++ b/graphics/ddraw.c
@@ -46,6 +46,7 @@
 #include "message.h"
 #include "x11drv.h"
 #include "options.h"
+#include "objbase.h"
 
 #ifdef HAVE_LIBXXF86DGA
 #include "ts_xf86dga.h"
@@ -100,7 +101,7 @@
 #endif
 
 BOOL32
-DDRAW_DGA_Available()
+DDRAW_DGA_Available(void)
 {
 #ifdef HAVE_LIBXXF86DGA
 	int evbase, evret, fd;
@@ -415,7 +416,7 @@
 {
 	TRACE(ddraw,"(%p)->Unlock(%p)\n",this,surface);
 
-	if (!this->s.ddraw->e.xlib.paintable)
+	if (!this->s.ddraw->d.paintable)
 		return DD_OK;
 
   /* Only redraw the screen when unlocking the buffer that is on screen */
@@ -488,7 +489,7 @@
 	LPDIRECTDRAWSURFACE3 this,LPDIRECTDRAWSURFACE3 flipto,DWORD dwFlags
 ) {
 	TRACE(ddraw,"(%p)->Flip(%p,%08lx)\n",this,flipto,dwFlags);
-	if (!this->s.ddraw->e.xlib.paintable)
+	if (!this->s.ddraw->d.paintable)
 		return DD_OK;
 
 	if (!flipto) {
@@ -557,6 +558,9 @@
 	{
 		pal->cm = TSXCreateColormap(display,this->s.ddraw->d.drawable,DefaultVisualOfScreen(screen),AllocAll);
 
+    	    	if (!Options.managed)
+			TSXInstallColormap(display,pal->cm);
+
 		for (i=0;i<256;i++) {
 			XColor xc;
 
@@ -567,6 +571,7 @@
 			xc.pixel = i;
 			TSXStoreColor(display,pal->cm,&xc);
 		}
+		TSXInstallColormap(display,pal->cm);
         }
 
         /* According to spec, we are only supposed to 
@@ -863,6 +868,11 @@
 		} else {
 			this->s.ddraw->e.dga.vpmask &= ~(1<<(this->t.dga.fb_height/this->s.ddraw->e.dga.fb_height));
 		}
+
+		/* Free the backbuffer */
+		if (this->s.backbuffer)
+			this->s.backbuffer->lpvtbl->fnRelease(this->s.backbuffer);
+
 		HeapFree(GetProcessHeap(),0,this);
 		return 0;
 	}
@@ -1074,24 +1084,29 @@
         if( dwFlags & DDCKEY_SRCBLT )
         {
            dwFlags &= ~DDCKEY_SRCBLT;
-           memcpy( &(this->s.ckSrcBlt), ckey, sizeof( *ckey ) );
+	   this->s.surface_desc.dwFlags |= DDSD_CKSRCBLT;
+           memcpy( &(this->s.surface_desc.ddckCKSrcBlt), ckey, sizeof( *ckey ) );
         }
 
         if( dwFlags & DDCKEY_DESTBLT )
         {
            dwFlags &= ~DDCKEY_DESTBLT;
-           memcpy( &(this->s.ckDestBlt), ckey, sizeof( *ckey ) );
+	   this->s.surface_desc.dwFlags |= DDSD_CKDESTBLT;
+           memcpy( &(this->s.surface_desc.ddckCKDestBlt), ckey, sizeof( *ckey ) );
         }
 
         if( dwFlags & DDCKEY_SRCOVERLAY )
         {
            dwFlags &= ~DDCKEY_SRCOVERLAY;
-           memcpy( &(this->s.ckSrcOverlay), ckey, sizeof( *ckey ) );
+	   this->s.surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
+           memcpy( &(this->s.surface_desc.ddckCKSrcOverlay), ckey, sizeof( *ckey ) );	   
         }
+	
         if( dwFlags & DDCKEY_DESTOVERLAY )
         {
            dwFlags &= ~DDCKEY_DESTOVERLAY;
-           memcpy( &(this->s.ckDestOverlay), ckey, sizeof( *ckey ) );
+	   this->s.surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
+           memcpy( &(this->s.surface_desc.ddckCKDestOverlay), ckey, sizeof( *ckey ) );	   
         }
 
         if( dwFlags )
@@ -1152,25 +1167,25 @@
 
   if( dwFlags & DDCKEY_SRCBLT )  {
      dwFlags &= ~DDCKEY_SRCBLT;
-     memcpy( lpDDColorKey, &(this->s.ckSrcBlt), sizeof( *lpDDColorKey ) );
+     memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKSrcBlt), sizeof( *lpDDColorKey ) );
   }
 
   if( dwFlags & DDCKEY_DESTBLT )
   {
     dwFlags &= ~DDCKEY_DESTBLT;
-    memcpy( lpDDColorKey, &(this->s.ckDestBlt), sizeof( *lpDDColorKey ) );
+    memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKDestBlt), sizeof( *lpDDColorKey ) );
   }
 
   if( dwFlags & DDCKEY_SRCOVERLAY )
   {
     dwFlags &= ~DDCKEY_SRCOVERLAY;
-    memcpy( lpDDColorKey, &(this->s.ckSrcOverlay), sizeof( *lpDDColorKey ) );
+    memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKSrcOverlay), sizeof( *lpDDColorKey ) );
   }
 
   if( dwFlags & DDCKEY_DESTOVERLAY )
   {
     dwFlags &= ~DDCKEY_DESTOVERLAY;
-    memcpy( lpDDColorKey, &(this->s.ckDestOverlay), sizeof( *lpDDColorKey ) );
+    memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKDestOverlay), sizeof( *lpDDColorKey ) );
   }
 
   if( dwFlags )
@@ -2427,7 +2442,7 @@
 
 	_common_IDirectDraw_SetDisplayMode(this);
 
-	this->e.xlib.paintable = 1;
+	this->d.paintable = 1;
         this->d.drawable  = ((X11DRV_WND_DATA *) WIN_FindWndPtr(this->d.window)->pDriverData)->window;  
         /* We don't have a context for this window. Host off the desktop */
         if( !this->d.drawable )
@@ -2633,12 +2648,16 @@
 		TSXF86DGADirectVideo(display,DefaultScreen(display),0);
 
 #ifdef HAVE_LIBXXF86VM
-		if (orig_mode)
-		  TSXF86VidModeSwitchToMode(display, DefaultScreen(display), orig_mode);
-		if (orig_mode->privsize)
-		  TSXFree(orig_mode->private);		
-		free(orig_mode);
-		orig_mode = NULL;
+		if (orig_mode) {
+			TSXF86VidModeSwitchToMode(
+				display,
+				DefaultScreen(display),
+				orig_mode);
+			if (orig_mode->privsize)
+				TSXFree(orig_mode->private);		
+			free(orig_mode);
+			orig_mode = NULL;
+		}
 #endif
 		
 #ifdef RESTORE_SIGNALS
@@ -3135,7 +3154,7 @@
    {
       /* Perform any special direct draw functions */
       if (msg==WM_PAINT)
-        ddraw->e.xlib.paintable = 1;
+        ddraw->d.paintable = 1;
 
       /* Now let the application deal with the rest of this */
       if( ddraw->d.mainWindow )
@@ -3232,7 +3251,7 @@
 }
 
 BOOL32
-DDRAW_XSHM_Available()
+DDRAW_XSHM_Available(void)
    {
 #ifdef HAVE_LIBXXSHM
   if (TSXShmQueryExtension(display))
diff --git a/graphics/escape.c b/graphics/escape.c
index da8f35f..8b4a9c4 100644
--- a/graphics/escape.c
+++ b/graphics/escape.c
@@ -138,7 +138,7 @@
 }
 
 /******************************************************************************
- *		ExtEscape32	[GDI32.95]
+ *		ExtEscape	[GDI32.95]
  *
  * PARAMS
  *    hdc         [I] Handle to device context
@@ -153,8 +153,8 @@
  *    Not implemented: 0
  *    Failure: <0
  */
-INT32 WINAPI ExtEscape32( HDC32 hdc, INT32 nEscape, INT32 cbInput, 
-                          LPCSTR lpszInData, INT32 cbOutput, LPSTR lpszOutData )
+INT32 WINAPI ExtEscape( HDC32 hdc, INT32 nEscape, INT32 cbInput, 
+                        LPCSTR lpszInData, INT32 cbOutput, LPSTR lpszOutData )
 {
     FIXME(driver,"(0x%04x,0x%x,%d,%s,%d,%p):stub\n",
           hdc,nEscape,cbInput,debugstr_a(lpszInData),cbOutput,lpszOutData);
@@ -166,7 +166,7 @@
  *
  *
  */
-INT32 WINAPI DrawEscape32(HDC32 hdc, INT32 nEscape, INT32 cbInput, LPCSTR lpszInData)
+INT32 WINAPI DrawEscape(HDC32 hdc, INT32 nEscape, INT32 cbInput, LPCSTR lpszInData)
 {
     FIXME(gdi, "DrawEscape, stub\n");
     return 0;
diff --git a/graphics/metafiledrv/init.c b/graphics/metafiledrv/init.c
index 4dd562a..392037a 100644
--- a/graphics/metafiledrv/init.c
+++ b/graphics/metafiledrv/init.c
@@ -407,7 +407,7 @@
     return hReturnDC;
 }
 
-HENHMETAFILE32 WINAPI CloseEnhMetaFile32( HDC32 hdc /* metafile DC */ )
+HENHMETAFILE32 WINAPI CloseEnhMetaFile( HDC32 hdc /* metafile DC */ )
 {
   /* write EMR_EOF(0x0, 0x10, 0x14) */
   return 0;
diff --git a/graphics/painting.c b/graphics/painting.c
index 423853f..bc64708 100644
--- a/graphics/painting.c
+++ b/graphics/painting.c
@@ -127,13 +127,13 @@
 }
 
 /***********************************************************************
- *           ArcTo32    (GDI32.8)
+ *           ArcTo    (GDI32.8)
  */
-BOOL32 WINAPI ArcTo32( HDC32 hdc, 
-                       INT32 left,   INT32 top, 
-                       INT32 right,  INT32 bottom,
-                       INT32 xstart, INT32 ystart,
-                       INT32 xend,   INT32 yend )
+BOOL32 WINAPI ArcTo( HDC32 hdc, 
+                     INT32 left,   INT32 top, 
+                     INT32 right,  INT32 bottom,
+                     INT32 xstart, INT32 ystart,
+                     INT32 xend,   INT32 yend )
 {
     BOOL32 result;
 
@@ -819,10 +819,10 @@
 }
 
 /**********************************************************************
- *          PolyPolyline32  (GDI32.272)
+ *          PolyPolyline  (GDI32.272)
  */
-BOOL32 WINAPI PolyPolyline32( HDC32 hdc, const POINT32* pt, const DWORD* counts,
-                             DWORD polylines )
+BOOL32 WINAPI PolyPolyline( HDC32 hdc, const POINT32* pt, const DWORD* counts,
+                            DWORD polylines )
 {
     DC * dc = DC_GetDCPtr( hdc );
 
@@ -1206,11 +1206,11 @@
 }
 
 /***************************************************************
- *      AngleArc32 (GDI32.5)
+ *      AngleArc (GDI32.5)
  *
  */
-BOOL32 WINAPI AngleArc32(HDC32 hdc, INT32 x, INT32 y, DWORD dwRadius,
-                         FLOAT eStartAngle, FLOAT eSweepAngle)
+BOOL32 WINAPI AngleArc(HDC32 hdc, INT32 x, INT32 y, DWORD dwRadius,
+                       FLOAT eStartAngle, FLOAT eSweepAngle)
 {
         FIXME(gdi,"AngleArc, stub\n");
         return 0;
diff --git a/graphics/vga.c b/graphics/vga.c
index 490074d..a194af9 100644
--- a/graphics/vga.c
+++ b/graphics/vga.c
@@ -39,6 +39,8 @@
         lpddraw->lpvtbl->fnCreatePalette(lpddraw,0,NULL,&lpddpal,NULL);
         memset(&sdesc,0,sizeof(sdesc));
         sdesc.dwSize=sizeof(sdesc);
+	sdesc.dwFlags = DDSD_CAPS;
+	sdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
         if (lpddraw->lpvtbl->fnCreateSurface(lpddraw,&sdesc,&lpddsurf,NULL)||(!lpddsurf)) {
             ERR(ddraw,"DirectDraw surface is not available\n");
             lpddraw->lpvtbl->fnRelease(lpddraw);
@@ -119,6 +121,9 @@
     lpddsurf->lpvtbl->fnUnlock(lpddsurf,sdesc.y.lpSurface);
 }
 
+/* We are called from SIGALRM, aren't we? We should _NOT_ do synchronization
+ * stuff!
+ */
 void VGA_Poll( WORD timer )
 {
     char *dat;
@@ -138,7 +143,7 @@
         /* copy from virtual VGA frame buffer to DirectDraw surface */
         for (Y=0; Y<Height; Y++,surf+=Pitch,dat+=Width) {
             memcpy(surf,dat,Width);
-            for (X=0; X<Width; X++) if (dat[X]) TRACE(ddraw,"data(%d) at (%d,%d)\n",dat[X],X,Y);
+            /*for (X=0; X<Width; X++) if (dat[X]) TRACE(ddraw,"data(%d) at (%d,%d)\n",dat[X],X,Y);*/
         }
         VGA_Unlock();
         vga_refresh=1;
diff --git a/if1632/gdi.spec b/if1632/gdi.spec
index bc0b52c..ff1cc15 100644
--- a/if1632/gdi.spec
+++ b/if1632/gdi.spec
@@ -117,8 +117,8 @@
 106 pascal SetBitmapBits(word long ptr) SetBitmapBits16
 117 pascal SetDCOrg(word s_word s_word) SetDCOrg
 119 pascal16 AddFontResource(str) AddFontResource16
-121 stub Death
-122 stub ReSurRection
+121 pascal16 Death(word) Death
+122 pascal16 Resurrection(word word word word word word word) Resurrection
 123 pascal16 PlayMetaFile(word word) PlayMetaFile16
 124 pascal16 GetMetaFile(str) GetMetaFile16
 125 pascal16 CreateMetaFile(str) CreateMetaFile16
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index cf01ca1..5b7adc1 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -400,6 +400,8 @@
 493 stub UTInit
 494 stub KERNEL_494
 
+# 495 is present only in Win98
+495 pascal WaitForMultipleObjectsEx(long ptr long long long) WIN16_WaitForMultipleObjectsEx
 
 # 500-544 are WinNT extensions; some are also available in Win95
 
diff --git a/if1632/user.spec b/if1632/user.spec
index ffb96f3..2113bb2 100644
--- a/if1632/user.spec
+++ b/if1632/user.spec
@@ -360,7 +360,7 @@
 384 pascal16 SetMenuContextHelpId(word word) SetMenuContextHelpId16
 385 pascal16 GetMenuContextHelpId(word) GetMenuContextHelpId16
 389 pascal LoadImage(word segstr word word word word) LoadImage16
-390 stub CopyImage
+390 pascal16 CopyImage(word word word word word) CopyImage16
 391 stub SignalProc32
 394 pascal16 DrawIconEx(word word word word word word word word word) DrawIconEx16
 395 stub GetIconInfo
diff --git a/include/commctrl.h b/include/commctrl.h
index 49c888b..7ecd9ce 100644
--- a/include/commctrl.h
+++ b/include/commctrl.h
@@ -616,6 +616,7 @@
 
 #define HDITEM   WINELIB_NAME_AW(HDITEM)
 #define LPHDITEM WINELIB_NAME_AW(LPHDITEM)
+#define HD_ITEM  HDITEM
 
 #define HDITEM_V1_SIZE32A CCSIZEOF_STRUCT(HDITEM32A, lParam)
 #define HDITEM_V1_SIZE32W CCSIZEOF_STRUCT(HDITEM32W, lParam)
@@ -2211,8 +2212,8 @@
     INT32  iIndent;	/* (_WIN32_IE >= 0x0300) */
 } LVITEM32W, *LPLVITEM32W;
 
-#define LVITEM32   WINELIB_NAME_AW(LVITEM)
-#define LPLVITEM32 WINELIB_NAME_AW(LPLVITEM)
+#define LVITEM   WINELIB_NAME_AW(LVITEM)
+#define LPLVITEM WINELIB_NAME_AW(LPLVITEM)
 
 #define LVITEM_V1_SIZE32A CCSIZEOF_STRUCT(LVITEM32A, lParam)
 #define LVITEM_V1_SIZE32W CCSIZEOF_STRUCT(LVITEM32W, lParam)
@@ -2454,7 +2455,7 @@
 
 #define TCITEM   WINELIB_NAME_AW(TCITEM)
 #define LPTCITEM WINELIB_NAME_AW(LPTCITEM)
-
+#define TC_ITEM  TCITEM
 
 #define TCN_FIRST               (0U-550U)
 #define TCN_LAST                (0U-580U)
diff --git a/include/commdlg.h b/include/commdlg.h
index 1ff9625..34ce9e0 100644
--- a/include/commdlg.h
+++ b/include/commdlg.h
@@ -671,7 +671,7 @@
 LRESULT WINAPI FormatCharDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
 LRESULT WINAPI FormatCharDlgProc32A(HWND32,UINT32,WPARAM32,LPARAM);
 LRESULT WINAPI FormatCharDlgProc32W(HWND32,UINT32,WPARAM32,LPARAM);
-#define FormatCharDlgProc LIBWINE_NAME_AW(FormatCharDlgProc)
+#define FormatCharDlgProc WINELIB_NAME_AW(FormatCharDlgProc)
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/d3d.h b/include/d3d.h
index 34e0cac..1496950 100644
--- a/include/d3d.h
+++ b/include/d3d.h
@@ -111,7 +111,7 @@
   D3DLIGHT_SPOT           = 2,
   D3DLIGHT_DIRECTIONAL    = 3,
   D3DLIGHT_PARALLELPOINT  = 4,
-  D3DLIGHT_FORCE_DWORD    = 0x7fffffff, /* force 32-bit size enum */
+  D3DLIGHT_FORCE_DWORD    = 0x7fffffff
 } D3DLIGHTTYPE;
 
 typedef enum {
@@ -121,9 +121,69 @@
   D3DPT_TRIANGLELIST  = 4,
   D3DPT_TRIANGLESTRIP = 5,
   D3DPT_TRIANGLEFAN   = 6,
-  D3DPT_FORCE_DWORD   = 0x7fffffff, /* force 32-bit size enum */
+  D3DPT_FORCE_DWORD   = 0x7fffffff
 } D3DPRIMITIVETYPE;
 
+typedef enum { 
+  D3DFILL_POINT         = 1, 
+  D3DFILL_WIREFRAME     = 2, 
+  D3DFILL_SOLID         = 3,
+  D3DFILL_FORCE_DWORD   = 0x7fffffff
+} D3DFILLMODE; 
+
+typedef enum { 
+  D3DSHADE_FLAT         = 1, 
+  D3DSHADE_GOURAUD      = 2, 
+  D3DSHADE_PHONG        = 3, 
+  D3DSHADE_FORCE_DWORD  = 0x7fffffff
+} D3DSHADEMODE;
+
+typedef enum { 
+  D3DCULL_NONE        = 1, 
+  D3DCULL_CW          = 2, 
+  D3DCULL_CCW         = 3, 
+  D3DCULL_FORCE_DWORD = 0x7fffffff 
+} D3DCULL; 
+
+typedef enum { 
+  D3DBLEND_ZERO            = 1, 
+  D3DBLEND_ONE             = 2, 
+  D3DBLEND_SRCCOLOR        = 3, 
+  D3DBLEND_INVSRCCOLOR     = 4, 
+  D3DBLEND_SRCALPHA        = 5, 
+  D3DBLEND_INVSRCALPHA     = 6, 
+  D3DBLEND_DESTALPHA       = 7, 
+  D3DBLEND_INVDESTALPHA    = 8, 
+  D3DBLEND_DESTCOLOR       = 9, 
+  D3DBLEND_INVDESTCOLOR    = 10, 
+  D3DBLEND_SRCALPHASAT     = 11, 
+  D3DBLEND_BOTHSRCALPHA    = 12, 
+  D3DBLEND_BOTHINVSRCALPHA = 13, 
+  D3DBLEND_FORCE_DWORD     = 0x7fffffff
+} D3DBLEND; 
+
+typedef enum { 
+  D3DTBLEND_DECAL         = 1, 
+  D3DTBLEND_MODULATE      = 2, 
+  D3DTBLEND_DECALALPHA    = 3, 
+  D3DTBLEND_MODULATEALPHA = 4, 
+  D3DTBLEND_DECALMASK     = 5, 
+  D3DTBLEND_MODULATEMASK  = 6, 
+  D3DTBLEND_COPY          = 7, 
+  D3DTBLEND_ADD           = 8, 
+  D3DTBLEND_FORCE_DWORD   = 0x7fffffff
+} D3DTEXTUREBLEND;
+
+typedef enum { 
+  D3DFILTER_NEAREST          = 1, 
+  D3DFILTER_LINEAR           = 2, 
+  D3DFILTER_MIPNEAREST       = 3, 
+  D3DFILTER_MIPLINEAR        = 4, 
+  D3DFILTER_LINEARMIPNEAREST = 5, 
+  D3DFILTER_LINEARMIPLINEAR  = 6, 
+  D3DFILTER_FORCE_DWORD      = 0x7fffffff
+} D3DTEXTUREFILTER;
+
 typedef enum {
   D3DRENDERSTATE_TEXTUREHANDLE      = 1,    /* Texture handle */
   D3DRENDERSTATE_ANTIALIAS          = 2,    /* D3DANTIALIASMODE */
diff --git a/include/ddraw.h b/include/ddraw.h
index fdb74dc..cc6ec07 100644
--- a/include/ddraw.h
+++ b/include/ddraw.h
@@ -903,6 +903,7 @@
     HWND32		window;
     Window		drawable;
     PAINTSTRUCT32	ps;
+    int			paintable;
 };
 
 struct _dga_directdrawdata {
@@ -912,8 +913,6 @@
 };
 
 struct _xlib_directdrawdata {
-    int			paintable;
-
 #ifdef HAVE_LIBXXSHM
     int xshm_active;
 #endif
@@ -999,9 +998,6 @@
     LPDIRECTDRAWSURFACE3	backbuffer;
 
     DDSURFACEDESC               surface_desc;
-
-    DDCOLORKEY                  ckDestOverlay, ckSrcOverlay;
-    DDCOLORKEY                  ckDestBlt, ckSrcBlt;
 };
 
 struct _dga_directdrawsurface {
diff --git a/include/file.h b/include/file.h
index 0bc6023..e6192b5 100644
--- a/include/file.h
+++ b/include/file.h
@@ -37,22 +37,6 @@
     int flags;
 } DOS_DEVICE;
 
-/* Macros to convert 16 bit to 32 bit file handles and back */
-/* LZW handles are exempt as if not, could go below 0x400 */
-#define HFILE16_TO_HFILE32(handle) \
-(((handle)==0) ? GetStdHandle(STD_INPUT_HANDLE) : \
- ((handle)==1) ? GetStdHandle(STD_OUTPUT_HANDLE) : \
- ((handle)==2) ? GetStdHandle(STD_ERROR_HANDLE) : \
- ((handle)==3) ? GetStdHandle(STD_ERROR_HANDLE) : \
- ((handle)==4) ? GetStdHandle(STD_ERROR_HANDLE) : \
- ((handle)>=0x400) ? handle : \
- (handle)-5)
-
-#define HFILE32_TO_HFILE16(handle) ({ HFILE32 hnd=handle; \
-      ((hnd==HFILE_ERROR32) ? HFILE_ERROR16 : \
-      ((hnd)>=0x400) ? hnd : \
-       (HFILE16)hnd+5); })
-
 
 /* files/file.c */
 extern FILE_OBJECT *FILE_GetFile( HFILE32 handle, DWORD access,
@@ -61,7 +45,7 @@
 extern void FILE_SetDosError(void);
 extern HFILE32 FILE_DupUnixHandle( int fd, DWORD access );
 extern BOOL32 FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info );
-extern HFILE32 FILE_Dup2( HFILE32 hFile1, HFILE32 hFile2 );
+extern HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 );
 extern HFILE32 FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
                                 LPSECURITY_ATTRIBUTES sa, DWORD creation,
                                 DWORD attributes, HANDLE32 template );
@@ -70,7 +54,9 @@
                            DWORD offset_high, DWORD offset_low,
                            int prot, int flags );
 extern int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low );
-extern HFILE32 _lcreat_uniq( LPCSTR path, INT32 attr );
+extern HFILE16 FILE_AllocDosHandle( HANDLE32 handle );
+extern HANDLE32 FILE_GetHandle32( HFILE16 hfile );
+extern HFILE16 _lcreat16_uniq( LPCSTR path, INT32 attr );
 
 /* files/directory.c */
 extern int DIR_Init(void);
diff --git a/include/gdi.h b/include/gdi.h
index b3b10cd..8b2c379 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -35,21 +35,6 @@
 } GDIOBJHDR;
 
 
-#define OBJ_PEN             1 
-#define OBJ_BRUSH           2 
-#define OBJ_DC              3 
-#define OBJ_METADC          4 
-#define OBJ_PAL             5 
-#define OBJ_FONT            6 
-#define OBJ_BITMAP          7 
-#define OBJ_REGION          8 
-#define OBJ_METAFILE        9 
-#define OBJ_MEMDC           10 
-#define OBJ_EXTPEN          11 
-#define OBJ_ENHMETADC       12 
-#define OBJ_ENHMETAFILE     13 
-
-
 typedef struct tagDeviceCaps
 {
     WORD   version;       /*   0: driver version */
diff --git a/include/module.h b/include/module.h
index ba02b90..30e45e7 100644
--- a/include/module.h
+++ b/include/module.h
@@ -147,7 +147,7 @@
 extern WINE_MODREF *MODULE32_LookupHMODULE( struct _PDB32 *process, HMODULE32 hModule );
 extern void MODULE_InitializeDLLs( struct _PDB32 *process, HMODULE32 root, DWORD type, LPVOID lpReserved );
 extern HMODULE32 MODULE_FindModule32( struct _PDB32 *process, LPCSTR path );
-extern HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs );
+extern HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName );
 extern FARPROC16 MODULE_GetWndProcEntry16( const char *name );
 extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE32 hmodule, LPCSTR name );
 extern SEGPTR WINAPI HasGPHandler( SEGPTR address );
diff --git a/include/process.h b/include/process.h
index 9de4073..e5969a6 100644
--- a/include/process.h
+++ b/include/process.h
@@ -108,6 +108,7 @@
     LCID             locale;           /* c4 Locale to be queried by GetThreadLocale (NT) */
     /* The following are Wine-specific fields */
     void            *server_pid;       /*    Server id for this process */
+    HANDLE32        *dos_handles;      /*    Handles mapping DOS -> Win32 */
     struct _PDB32   *list_next;        /*    List reference - list of PDB's */
     struct _PDB32   *list_prev;        /*    List reference - list of PDB's */
 } PDB32;
diff --git a/include/tchar.h b/include/tchar.h
index 443c1cc..3a01e32 100644
--- a/include/tchar.h
+++ b/include/tchar.h
@@ -237,4 +237,15 @@
 #define _vstprintf    WINE_tchar_routine(vsprintf,        vsprintf,    vswprintf)
 #define _vtprintf     WINE_tchar_routine(vprintf,         vprintf,     vwprintf)
 
+#define _T(x) __T(x)
+#define _TEXT(x) __T(x)
+#define __T(x) x
+
+typedef CHAR  _TCHAR32A;
+typedef WCHAR _TCHAR32W;
+DECL_WINELIB_TYPE_AW (_TCHAR)
+typedef UCHAR  _TUCHAR32A;
+typedef WCHAR _TUCHAR32W;
+DECL_WINELIB_TYPE_AW (_TUCHAR)
+				 
 #endif /* __WINE_TCHAR_H */
diff --git a/include/windows.h b/include/windows.h
index 3b602c4..e3885f8 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -3172,6 +3172,11 @@
 #define DM_PROMPT	4
 #define DM_MODIFY	8
 
+#define DM_IN_BUFFER      DM_MODIFY
+#define DM_IN_PROMPT      DM_PROMPT
+#define DM_OUT_BUFFER     DM_COPY
+#define DM_OUT_DEFAULT    DM_UPDATE
+
 #define DM_ORIENTATION		0x00000001L
 #define DM_PAPERSIZE		0x00000002L
 #define DM_PAPERLENGTH		0x00000004L
diff --git a/include/wingdi.h b/include/wingdi.h
index fea4b22..844b10d 100644
--- a/include/wingdi.h
+++ b/include/wingdi.h
@@ -429,6 +429,22 @@
 #define MWT_LEFTMULTIPLY  2
 #define MWT_RIGHTMULTIPLY 3
 
+/* Object Definitions for EnumObjects() */
+#define OBJ_PEN             1
+#define OBJ_BRUSH           2
+#define OBJ_DC              3
+#define OBJ_METADC          4
+#define OBJ_PAL             5
+#define OBJ_FONT            6
+#define OBJ_BITMAP          7
+#define OBJ_REGION          8
+#define OBJ_METAFILE        9
+#define OBJ_MEMDC           10
+#define OBJ_EXTPEN          11
+#define OBJ_ENHMETADC       12
+#define OBJ_ENHMETAFILE     13
+
+ 
 typedef struct
 {
     FLOAT  eM11;
@@ -1453,6 +1469,8 @@
 #define SYSTEM_FIXED_FONT   16
 #define DEFAULT_GUI_FONT    17
 
+#define STOCK_LAST          17
+
 /* Metafile header structure */
 typedef struct
 {
@@ -1470,7 +1488,7 @@
 {
     DWORD      rdSize;
     WORD       rdFunction;
-    WORD       rdParam[1];
+    WORD       rdParm[1];
 } METARECORD;
 typedef METARECORD *PMETARECORD;
 typedef METARECORD *LPMETARECORD;
@@ -1951,24 +1969,26 @@
 
 #pragma pack(4)
 
+/* Declarations for functions that exist only in Win16 */
+
+VOID        WINAPI Death(HDC16);
+VOID        WINAPI Resurrection(HDC16,WORD,WORD,WORD,WORD,WORD,WORD);
+
 /* Declarations for functions that exist only in Win32 */
 
-BOOL32      WINAPI AngleArc32(HDC32, INT32, INT32, DWORD, FLOAT, FLOAT);
-#define     AngleArc WINELIB_NAME(AngleArc)
-BOOL32      WINAPI ArcTo32(HDC32, INT32, INT32, INT32, INT32, INT32, INT32, INT32, INT32); 
-HENHMETAFILE32 WINAPI CloseEnhMetaFile32(HDC32);
-#define     CloseEnhMetaFile WINELIB_NAME(CloseEnhMetaFile)
+BOOL32      WINAPI AngleArc(HDC32, INT32, INT32, DWORD, FLOAT, FLOAT);
+BOOL32      WINAPI ArcTo(HDC32, INT32, INT32, INT32, INT32, INT32, INT32, INT32, INT32); 
+HENHMETAFILE32 WINAPI CloseEnhMetaFile(HDC32);
 HBRUSH32    WINAPI CreateDIBPatternBrushPt(const void*,UINT32);
 HDC32       WINAPI CreateEnhMetaFile32A(HDC32,LPCSTR,const RECT32*,LPCSTR);
 HDC32       WINAPI CreateEnhMetaFile32W(HDC32,LPCWSTR,const RECT32*,LPCWSTR);
 #define     CreateEnhMetaFile WINELIB_NAME_AW(CreateEnhMetaFile)
-INT32       WINAPI DrawEscape32(HDC32,INT32,INT32,LPCSTR);
+INT32       WINAPI DrawEscape(HDC32,INT32,INT32,LPCSTR);
 INT16       WINAPI ExcludeVisRect(HDC16,INT16,INT16,INT16,INT16);
 BOOL16      WINAPI FastWindowFrame(HDC16,const RECT16*,INT16,INT16,DWORD);
 UINT16      WINAPI GDIRealizePalette(HDC16);
 HPALETTE16  WINAPI GDISelectPalette(HDC16,HPALETTE16,WORD);
-BOOL32      WINAPI GdiComment32(HDC32,UINT32,const BYTE *);
-#define     GdiComment WINELIB_NAME(GdiComment)
+BOOL32      WINAPI GdiComment(HDC32,UINT32,const BYTE *);
 DWORD       WINAPI GetBitmapDimension(HBITMAP16);
 DWORD       WINAPI GetBrushOrg(HDC16);
 BOOL32      WINAPI GetCharABCWidthsFloat32A(HDC32,UINT32,UINT32,LPABCFLOAT);
@@ -1977,8 +1997,7 @@
 BOOL32      WINAPI GetCharWidthFloat32A(HDC32,UINT32,UINT32,PFLOAT);
 BOOL32      WINAPI GetCharWidthFloat32W(HDC32,UINT32,UINT32,PFLOAT);
 #define     GetCharWidthFloat WINELIB_NAME_AW(GetCharWidthFloat)
-BOOL32      WINAPI GetColorAdjustment32(HDC32, LPCOLORADJUSTMENT);
-#define     GetColorAdjustment WINELIB_NAME(GetColorAdjustment)
+BOOL32      WINAPI GetColorAdjustment(HDC32, LPCOLORADJUSTMENT);
 HFONT16     WINAPI GetCurLogFont(HDC16);
 DWORD       WINAPI GetCurrentPosition(HDC16);
 DWORD       WINAPI GetDCHook(HDC16,FARPROC16*);
@@ -2032,7 +2051,7 @@
 BOOL32      WINAPI DeleteEnhMetaFile(HENHMETAFILE32);
 INT32       WINAPI ExtSelectClipRgn(HDC32,HRGN32,INT32);
 HRGN32      WINAPI ExtCreateRegion(const XFORM*,DWORD,const RGNDATA*);
-INT32       WINAPI ExtEscape32(HDC32,INT32,INT32,LPCSTR,INT32,LPSTR);
+INT32       WINAPI ExtEscape(HDC32,INT32,INT32,LPCSTR,INT32,LPSTR);
 BOOL32      WINAPI FixBrushOrgEx(HDC32,INT32,INT32,LPPOINT32);
 HANDLE32    WINAPI GetCurrentObject(HDC32,UINT32);
 BOOL32      WINAPI GetDCOrgEx(HDC32,LPPOINT32);
@@ -2055,7 +2074,7 @@
 BOOL32      WINAPI ModifyWorldTransform(HDC32,const XFORM *, DWORD);
 BOOL32      WINAPI PlayEnhMetaFile(HDC32,HENHMETAFILE32,const RECT32*);
 BOOL32      WINAPI PlayEnhMetaFileRecord(HDC32,LPHANDLETABLE32,const ENHMETARECORD*,UINT32);
-BOOL32      WINAPI PolyPolyline32(HDC32,const POINT32*,const DWORD*,DWORD);
+BOOL32      WINAPI PolyPolyline(HDC32,const POINT32*,const DWORD*,DWORD);
 BOOL32      WINAPI SetBrushOrgEx(HDC32,INT32,INT32,LPPOINT32);
 HENHMETAFILE32 WINAPI SetEnhMetaFileBits(UINT32,const BYTE *);
 INT32       WINAPI SetGraphicsMode(HDC32,INT32);
@@ -2580,7 +2599,7 @@
 HPALETTE32  WINAPI SelectPalette32(HDC32,HPALETTE32,BOOL32);
 #define     SelectPalette WINELIB_NAME(SelectPalette)
 INT16       WINAPI SetAbortProc16(HDC16,SEGPTR);
-INT32       WINAPI SetAbortProc32(HDC32,FARPROC32);
+INT32       WINAPI SetAbortProc32(HDC32,ABORTPROC32);
 #define     SetAbortProc WINELIB_NAME(SetAbortProc)
 INT16       WINAPI SetArcDirection16(HDC16,INT16);
 INT32       WINAPI SetArcDirection32(HDC32,INT32);
diff --git a/include/wintypes.h b/include/wintypes.h
index 538f4cb..e64868c 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -413,6 +413,9 @@
 #define max(a,b)   MAX(a,b)
 #define min(a,b)   MIN(a,b)
 
+#define _MAX_PATH  260
+#define _MAX_FNAME 255
+
 /* Winelib run-time flag */
 
 #ifdef __WINE__
diff --git a/include/winuser.h b/include/winuser.h
index 21be626..71cabc0 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -228,6 +228,7 @@
 #define SBS_SIZEBOXTOPLEFTALIGN     0x0002L
 #define SBS_SIZEBOXBOTTOMRIGHTALIGN 0x0004L
 #define SBS_SIZEBOX                 0x0008L
+#define SBS_SIZEGRIP                0x0010L
 
 /* EnableScrollBar() flags */
 #define ESB_ENABLE_BOTH     0x0000
@@ -923,6 +924,8 @@
 INT32       WINAPI DlgDirListComboBox32A(HWND32,LPSTR,INT32,INT32,UINT32);
 INT32       WINAPI DlgDirListComboBox32W(HWND32,LPWSTR,INT32,INT32,UINT32);
 #define     DlgDirListComboBox WINELIB_NAME_AW(DlgDirListComboBox)
+BOOL32      WINAPI DlgDirSelectComboBoxEx32A(HWND32,LPSTR,INT32,INT32);
+BOOL32      WINAPI DlgDirSelectComboBoxEx32W(HWND32,LPWSTR,INT32,INT32);
 #define     DlgDirSelectComboBoxEx WINELIB_NAME_AW(DlgDirSelectComboBoxEx)
 BOOL32      WINAPI DlgDirSelectEx32A(HWND32,LPSTR,INT32,INT32);
 BOOL32      WINAPI DlgDirSelectEx32W(HWND32,LPWSTR,INT32,INT32);
diff --git a/loader/dos/module.c b/loader/dos/module.c
index dc01307..6a11fdc 100644
--- a/loader/dos/module.c
+++ b/loader/dos/module.c
@@ -228,7 +228,7 @@
 #endif
   old_com=1; /* assume .COM file */
   image_start=0;
-  image_size=GetFileSize(HFILE16_TO_HFILE32(hFile),NULL);
+  image_size=GetFileSize(FILE_GetHandle32(hFile),NULL);
   min_size=0x10000; max_size=0x100000;
   mz_header.e_crlc=0;
   mz_header.e_ss=0; mz_header.e_sp=0xFFFE;
@@ -432,7 +432,7 @@
 
  if ((!env)&&pdb) env = pdb->env_db->environ;
  if (alloc) {
-  if ((hModule = MODULE_CreateDummyModule(&ofs)) < 32)
+  if ((hModule = MODULE_CreateDummyModule(&ofs, NULL)) < 32)
    return hModule;
 
   lpDosTask->hModule = hModule;
diff --git a/loader/main.c b/loader/main.c
index bbbadac37..278c0e9 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -291,7 +291,7 @@
     PROCESS_Current()->exe_modref = wm;
 
     strcpy( ofs.szPathName, wm->modname );
-    if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return 0;
+    if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
     pModule = (NE_MODULE *)GlobalLock16( hModule );
     pModule->flags = NE_FFLAGS_WIN32;
     pModule->module32 = wm->module;
diff --git a/loader/module.c b/loader/module.c
index 735b7a7..d4b67dc 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -177,7 +177,7 @@
  *
  * Create a dummy NE module for Win32 or Winelib.
  */
-HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs )
+HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName )
 {
     HMODULE32 hModule;
     NE_MODULE *pModule;
@@ -240,9 +240,14 @@
     /* Module name */
     pStr = (char *)pSegment;
     pModule->name_table = (int)pStr - (int)pModule;
-    basename = strrchr(ofs->szPathName,'\\');
-    if (!basename) basename = ofs->szPathName;
-    else basename++;
+    if ( modName )
+        basename = modName;
+    else
+    {
+        basename = strrchr(ofs->szPathName,'\\');
+        if (!basename) basename = ofs->szPathName;
+        else basename++;
+    }
     len = strlen(basename);
     if ((s = strchr(basename,'.'))) len = s - basename;
     if (len > 8) len = 8;
diff --git a/loader/ne/segment.c b/loader/ne/segment.c
index a40ee19..b452266 100644
--- a/loader/ne/segment.c
+++ b/loader/ne/segment.c
@@ -93,6 +93,8 @@
         DWORD oldstack;
  	WORD old_hSeg, new_hSeg;
         THDB *thdb = THREAD_Current();
+        HFILE32 hFile32;
+        HFILE16 hFile16;
 
  	selfloadheader = (SELFLOADHEADER *)
  		PTR_SEG_OFF_TO_LIN(SEL(pSegTable->hSeg),0);
@@ -111,12 +113,14 @@
         stack16Top->cs = 0;
 	TRACE(dll,"CallLoadAppSegProc(hmodule=0x%04x,hf=0x%04x,segnum=%d\n",
 		pModule->self,hf,segnum );
+        DuplicateHandle( GetCurrentProcess(), hf, GetCurrentProcess(), &hFile32,
+                         0, FALSE, DUPLICATE_SAME_ACCESS );
+        hFile16 = FILE_AllocDosHandle( hFile32 );
  	new_hSeg = Callbacks->CallLoadAppSegProc(selfloadheader->LoadAppSeg,
-                                                    pModule->self,
-                                                    HFILE32_TO_HFILE16(hf),
+                                                    pModule->self, hFile16,
                                                     segnum );
 	TRACE(dll,"Ret CallLoadAppSegProc: hSeg = 0x%04x\n",new_hSeg);
-        _lclose32( hf );
+        _lclose16( hFile16 );
  	if (SEL(new_hSeg) != SEL(old_hSeg)) {
  	  /* Self loaders like creating their own selectors; 
  	   * they love asking for trouble to Wine developers
@@ -390,6 +394,7 @@
     if (pModule->flags & NE_FFLAGS_SELFLOAD)
     {
         HFILE32 hf;
+        HFILE16 hFile16;
         /* Handle self loading modules */
         SELFLOADHEADER *selfloadheader;
         STACK16FRAME *stack16Top;
@@ -422,13 +427,14 @@
         stack16Top->ip = 0;
         stack16Top->cs = 0;
 
-        hf = NE_OpenFile( pModule );
-        TRACE(dll,"CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n",pModule->self,
-              HFILE32_TO_HFILE16(hf));
-        Callbacks->CallBootAppProc(selfloadheader->BootApp, pModule->self,
-                                   HFILE32_TO_HFILE16(hf));
+        DuplicateHandle( GetCurrentProcess(), NE_OpenFile(pModule),
+                         GetCurrentProcess(), &hf, 0, FALSE, DUPLICATE_SAME_ACCESS );
+        hFile16 = FILE_AllocDosHandle( hf );
+        TRACE(dll,"CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n",
+              pModule->self,hFile16);
+        Callbacks->CallBootAppProc(selfloadheader->BootApp, pModule->self,hFile16);
 	TRACE(dll,"Return from CallBootAppProc\n");
-        _lclose32(hf);
+        _lclose16(hf);
         /* some BootApp procs overwrite the segment handle of dgroup */
         pSegTable[pModule->dgroup - 1].hSeg = saved_hSeg;
         thdb->cur_stack = oldstack;
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 0e7d7df..46f9fb9 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -456,7 +456,7 @@
  * BUT we have to map the whole image anyway, for Win32 programs sometimes
  * want to access them. (HMODULE32 point to the start of it)
  */
-static HMODULE32 PE_LoadImage( LPCSTR name, OFSTRUCT *ofs )
+static HMODULE32 PE_LoadImage( LPCSTR name, OFSTRUCT *ofs, LPCSTR *modName )
 {
     HMODULE32	hModule;
     HFILE32	hFile;
@@ -464,6 +464,7 @@
 
     IMAGE_NT_HEADERS *nt;
     IMAGE_SECTION_HEADER *pe_sec;
+    IMAGE_DATA_DIRECTORY *dir;
     BY_HANDLE_FILE_INFORMATION bhfi;
     int	i, rawsize, lowest_va, lowest_fa, vma_size, file_size = 0;
     DWORD load_addr, aoep, reloc = 0;
@@ -574,7 +575,6 @@
     if (load_addr == 0) 
     {
         /* We need to perform base relocations */
-        IMAGE_DATA_DIRECTORY *dir;
 	dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_BASERELOC;
         if (dir->Size)
             reloc = dir->VirtualAddress;
@@ -635,6 +635,11 @@
     if ( reloc )
         do_relocations( load_addr, (IMAGE_BASE_RELOCATION *)RVA(reloc) );
 
+    /* Get module name */
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
+    if (dir->Size)
+        *modName = (LPCSTR)RVA(((PIMAGE_EXPORT_DIRECTORY)RVA(dir->VirtualAddress))->Name);
+
     /* We don't need the orignal mapping any more */
     UnmapViewOfFile( (LPVOID)hModule );
     return (HMODULE32)load_addr;
@@ -799,6 +804,7 @@
 HMODULE32 PE_LoadLibraryEx32A (LPCSTR name, PDB32 *process,
                                HFILE32 hFile, DWORD flags)
 {
+    LPCSTR	modName = NULL;
     OFSTRUCT	ofs;
     HMODULE32	hModule32;
     HMODULE16	hModule16;
@@ -814,7 +820,7 @@
     if ((hModule32 = BUILTIN32_LoadImage( name, &ofs, FALSE )))
         builtin = TRUE;
     /* try to load the specified dll/exe */
-    else if ((hModule32 = PE_LoadImage( name, &ofs )) >= 32)
+    else if ((hModule32 = PE_LoadImage( name, &ofs, &modName )) >= 32)
         builtin = FALSE;
     /* Now try the built-in even if disabled */
     else if ((hModule32 = BUILTIN32_LoadImage( name, &ofs, TRUE ))) 
@@ -826,7 +832,7 @@
         return 0;
 
     /* Create 16-bit dummy module */
-    if ((hModule16 = MODULE_CreateDummyModule( &ofs )) < 32) return hModule16;
+    if ((hModule16 = MODULE_CreateDummyModule( &ofs, modName )) < 32) return hModule16;
     pModule = (NE_MODULE *)GlobalLock16( hModule16 );
     pModule->flags    = NE_FFLAGS_LIBMODULE | NE_FFLAGS_SINGLEDATA |
                         NE_FFLAGS_WIN32 | (builtin? NE_FFLAGS_BUILTIN : 0);
@@ -855,6 +861,7 @@
                               LPCSTR env, BOOL32 inherit, LPSTARTUPINFO32A startup,
                               LPPROCESS_INFORMATION info )
 {
+    LPCSTR modName = NULL;
     HMODULE16 hModule16;
     HMODULE32 hModule32;
     HINSTANCE16 hInstance;
@@ -865,13 +872,13 @@
     WINE_MODREF	*wm;
 
     /* Load file */
-    if ((hModule32 = PE_LoadImage( name, &ofs )) < 32)
+    if ((hModule32 = PE_LoadImage( name, &ofs, &modName )) < 32)
         return hModule32;
     if (PE_HEADER(hModule32)->FileHeader.Characteristics & IMAGE_FILE_DLL)
         return 20;  /* FIXME: not the right error code */
 
     /* Create 16-bit dummy module */
-    if ((hModule16 = MODULE_CreateDummyModule( &ofs )) < 32) return hModule16;
+    if ((hModule16 = MODULE_CreateDummyModule( &ofs, modName )) < 32) return hModule16;
     pModule = (NE_MODULE *)GlobalLock16( hModule16 );
     pModule->flags    = NE_FFLAGS_WIN32;
     pModule->module32 = hModule32;
@@ -969,7 +976,6 @@
 		delta = wm->module - peh->OptionalHeader.ImageBase;
 		if (!peh->OptionalHeader.DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress)
 			continue;
-		FIXME(win32,"%s has TLS directory.\n",wm->longname);
 		pdir = (LPVOID)(wm->module + peh->OptionalHeader.
 			DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress);
 		
diff --git a/loader/resource.c b/loader/resource.c
index fe281b1..96e5017 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -331,7 +331,7 @@
     {
         HANDLE32 hRsrc32 = MapHRsrc16To32( pModule, hRsrc );
         HFILE32 hFile32 = AccessResource32( pModule->module32, hRsrc32 );
-        return HFILE32_TO_HFILE16( hFile32 );
+        return FILE_AllocDosHandle( hFile32 );
     }
 
     return NE_AccessResource( pModule, hRsrc );
diff --git a/misc/lzexpand.c b/misc/lzexpand.c
index 2046ff8..243607d 100644
--- a/misc/lzexpand.c
+++ b/misc/lzexpand.c
@@ -30,8 +30,7 @@
 };
 static BYTE LZMagic[8]={'S','Z','D','D',0x88,0xf0,0x27,0x33};
 
-static struct lzstate {
-	HFILE32	lzfd;		/* the handle used by the program */
+struct lzstate {
 	HFILE32	realfd;		/* the real filedescriptor */
 	CHAR	lastchar;	/* the last char of the filename */
 
@@ -51,8 +50,13 @@
 	BYTE	*get;		/* GETLEN bytes */
 	DWORD	getcur;		/* current read */
 	DWORD	getlen;		/* length last got */
-} *lzstates=NULL;
-static int nroflzstates=0;
+};
+
+#define MAX_LZSTATES 16
+static struct lzstate *lzstates[MAX_LZSTATES];
+
+#define IS_LZ_HANDLE(h) (((h) >= 0x400) && ((h) < 0x400+MAX_LZSTATES))
+#define GET_LZ_STATE(h) (IS_LZ_HANDLE(h) ? lzstates[(h)] : NULL)
 
 /* reads one compressed byte, including buffering */
 #define GET(lzs,b)	_lzget(lzs,&b)
@@ -132,7 +136,7 @@
  */
 HFILE16 WINAPI LZInit16( HFILE16 hfSrc )
 {
-    return HFILE32_TO_HFILE16( LZInit32( HFILE16_TO_HFILE32(hfSrc) ) );
+    return LZInit32( FILE_GetHandle32(hfSrc) );
 }
 
 
@@ -143,7 +147,6 @@
  * (return value the same as hfSrc, if hfSrc is not compressed)
  * on failure, returns error code <0
  * lzfiledescriptors range from 0x400 to 0x410 (only 16 open files per process)
- * we use as much as we need, we just OR 0x400 to the passed HFILE.
  *
  * since _llseek uses the same types as libc.lseek, we just use the macros of 
  *  libc
@@ -154,6 +157,7 @@
 	struct	lzfileheader	head;
 	struct	lzstate		*lzs;
 	DWORD	ret;
+        int i;
 
 	TRACE(file,"(%d)\n",hfSrc);
 	ret=read_header(hfSrc,&head);
@@ -161,13 +165,12 @@
 		_llseek32(hfSrc,0,SEEK_SET);
 		return ret?ret:hfSrc;
 	}
-	lzstates = HeapReAlloc( SystemHeap, 0, lzstates,
-                                (++nroflzstates)*sizeof(struct lzstate) );
-	lzs		= lzstates+(nroflzstates-1);
+        for (i = 0; i < MAX_LZSTATES; i++) if (!lzstates[i]) break;
+        if (i == MAX_LZSTATES) return LZERROR_GLOBALLOC;
+	lzstates[i] = lzs = HeapAlloc( SystemHeap, 0, sizeof(struct lzstate) );
 
 	memset(lzs,'\0',sizeof(*lzs));
 	lzs->realfd	= hfSrc;
-	lzs->lzfd	= hfSrc | 0x400;
 	lzs->lastchar	= head.lastchar;
 	lzs->reallength = head.reallength;
 
@@ -179,7 +182,7 @@
 	memset(lzs->table,' ',0x1000);
 	/* Yes, start 16 byte from the END of the table */
 	lzs->curtabent	= 0xff0; 
-	return lzs->lzfd;
+	return 0x400 + i;
 }
 
 
@@ -302,7 +305,8 @@
  */
 INT16 WINAPI LZRead16( HFILE16 fd, LPVOID buf, UINT16 toread )
 {
-    return LZRead32(HFILE16_TO_HFILE32(fd),buf,toread);
+    if (IS_LZ_HANDLE(fd)) return LZRead32( fd, buf, toread );
+    return _lread16( fd, buf, toread );
 }
 
 
@@ -311,19 +315,14 @@
  */
 INT32 WINAPI LZRead32( HFILE32 fd, LPVOID vbuf, UINT32 toread )
 {
-	int	i,howmuch;
+	int	howmuch;
 	BYTE	b,*buf;
 	struct	lzstate	*lzs;
 
 	buf=(LPBYTE)vbuf;
 	TRACE(file,"(%d,%p,%d)\n",fd,buf,toread);
 	howmuch=toread;
-	for (i=0;i<nroflzstates;i++)
-		if (lzstates[i].lzfd==fd)
-			break;
-	if (i==nroflzstates)
-		return _lread32(fd,buf,toread);
-	lzs=lzstates+i;
+	if (!(lzs = GET_LZ_STATE(fd))) return _lread32(fd,buf,toread);
 
 /* The decompressor itself is in a define, cause we need it twice
  * in this function. (the decompressed byte will be in b)
@@ -407,7 +406,8 @@
  */
 LONG WINAPI LZSeek16( HFILE16 fd, LONG off, INT16 type )
 {
-    return LZSeek32( HFILE16_TO_HFILE32(fd), off, type );
+    if (IS_LZ_HANDLE(fd)) return LZSeek32( fd, off, type );
+    return _llseek16( fd, off, type );
 }
 
 
@@ -416,19 +416,13 @@
  */
 LONG WINAPI LZSeek32( HFILE32 fd, LONG off, INT32 type )
 {
-	int	i;
 	struct	lzstate	*lzs;
 	LONG	newwanted;
 
 	TRACE(file,"(%d,%ld,%d)\n",fd,off,type);
-	for (i=0;i<nroflzstates;i++)
-		if (lzstates[i].lzfd==fd)
-			break;
 	/* not compressed? just use normal _llseek() */
-	if (i==nroflzstates)
-		return _llseek32(fd,off,type);
-	lzs		= lzstates+i;
-	newwanted	= lzs->realwanted;
+        if (!(lzs = GET_LZ_STATE(fd))) return _llseek32(fd,off,type);
+	newwanted = lzs->realwanted;
 	switch (type) {
 	case 1:	/* SEEK_CUR */
 		newwanted      += off;
@@ -455,7 +449,19 @@
  */
 LONG WINAPI LZCopy16( HFILE16 src, HFILE16 dest )
 {
-    return LZCopy32( HFILE16_TO_HFILE32(src), HFILE16_TO_HFILE32(dest) );
+    HFILE32 oldsrc = src;
+    int usedlzinit = 0;
+    LONG ret;
+
+    if (!IS_LZ_HANDLE(src))
+    {
+        src = LZInit16(src);
+        if (src!=oldsrc) usedlzinit=1;
+        if (src>0xfff0) return 0;
+    }
+    ret = LZCopy32( src, FILE_GetHandle32(dest) );
+    if (usedlzinit) LZClose32(src);
+    return ret;
 }
 
 
@@ -468,7 +474,7 @@
  */
 LONG WINAPI LZCopy32( HFILE32 src, HFILE32 dest )
 {
-	int	usedlzinit=0,i,ret,wret;
+	int	usedlzinit=0,ret,wret;
 	LONG	len;
 	HFILE32	oldsrc = src;
 #define BUFLEN	1000
@@ -476,7 +482,7 @@
 	INT32	WINAPI (*xread)(HFILE32,LPVOID,UINT32);
 
 	TRACE(file,"(%d,%d)\n",src,dest);
-	if (src<0x400) {
+	if (!IS_LZ_HANDLE(src)) {
 		src = LZInit32(src);
 		if (src!=oldsrc)
 			usedlzinit=1;
@@ -484,11 +490,8 @@
 			return 0;
 	}
 
-	for (i=0;i<nroflzstates;i++)
-		if (src==lzstates[i].lzfd)
-			break;
 	/* not compressed? just copy */
-	if (i==nroflzstates)
+        if (!IS_LZ_HANDLE(src))
 		xread=(INT32(*)(HFILE32,LPVOID,UINT32))_lread32;
 	else
 		xread=LZRead32;
@@ -537,7 +540,7 @@
  */
 HFILE16 WINAPI LZOpenFile16( LPCSTR fn, LPOFSTRUCT ofs, UINT16 mode )
 {
-    return HFILE32_TO_HFILE16 ( LZOpenFile32A( fn, ofs, mode ) );
+    return LZOpenFile32A( fn, ofs, mode );
 }
 
 
@@ -597,7 +600,8 @@
  */
 void WINAPI LZClose16( HFILE16 fd )
 {
-    return LZClose32( HFILE16_TO_HFILE32 (fd) );
+    if (IS_LZ_HANDLE(fd)) LZClose32( fd );
+    else _lclose16( fd );
 }
 
 
@@ -606,24 +610,17 @@
  */
 void WINAPI LZClose32( HFILE32 fd )
 {
-	int	i;
+	struct lzstate *lzs;
 
 	TRACE(file,"(%d)\n",fd);
-	for (i=0;i<nroflzstates;i++)
-		if (lzstates[i].lzfd==fd)
-			break;
-	if (i==nroflzstates) {
-		_lclose32(fd);
-		return;
-	}
-	if (lzstates[i].get)
-		HeapFree( GetProcessHeap(), 0, lzstates[i].get );
-	_lclose32(lzstates[i].realfd);
-	memmove(lzstates+i,lzstates+i+1,
-                sizeof(struct lzstate)*(nroflzstates-i-1));
-	nroflzstates--;
-	lzstates = HeapReAlloc( SystemHeap, 0, lzstates,
-                                sizeof(struct lzstate)*nroflzstates );
+        if (!(lzs = GET_LZ_STATE(fd))) _lclose32(fd);
+        else
+        {
+            if (lzs->get) HeapFree( GetProcessHeap(), 0, lzs->get );
+            CloseHandle(lzs->realfd);
+            lzstates[fd - 0x400] = NULL;
+            HeapFree( SystemHeap, 0, lzs );
+        }
 }
 
 /***********************************************************************
@@ -632,7 +629,7 @@
 LONG WINAPI CopyLZFile16( HFILE16 src, HFILE16 dest )
 {
     TRACE(file,"(%d,%d)\n",src,dest);
-    return LZCopy32(HFILE16_TO_HFILE32(src),HFILE16_TO_HFILE32(dest));
+    return LZCopy16(src,dest);
 }
 
 
diff --git a/misc/port.c b/misc/port.c
index 657450e..aba2d0a 100644
--- a/misc/port.c
+++ b/misc/port.c
@@ -7,6 +7,12 @@
 #include "config.h"
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <libio.h>
 
 #ifndef HAVE_USLEEP
 #ifdef __EMX__
@@ -90,3 +96,49 @@
 #endif  /* __i386__ */
 }
 #endif  /* !HAVE_CLONE && __linux__ */
+
+
+/** 
+ *  It looks like the openpty that comes with glibc in RedHat 5.0
+ *  is buggy (second call returns what looks like a dup of 0 and 1
+ *  instead of a new pty), this is a generic replacement.
+ */
+/** We will have an autoconf check for this soon... */
+
+int wine_openpty(int *master, int *slave, char *name, 
+			struct termios *term, struct winsize *winsize)
+{
+    char *ptr1, *ptr2;
+    char pts_name[512];
+
+    strcpy (pts_name, "/dev/ptyXY");
+
+    for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
+        pts_name[8] = *ptr1;
+        for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
+            pts_name[9] = *ptr2;
+
+            if ((*master = open(pts_name, O_RDWR)) < 0) {
+                if (errno == ENOENT)
+                    return -1;
+                else
+                    continue;
+            }
+            pts_name[5] = 't';
+            if ((*slave = open(pts_name, O_RDWR)) < 0) {
+                pts_name[5] = 'p';
+                continue;
+            }
+
+            if (term != NULL)
+	        tcsetattr(*slave, TCSANOW, term);
+	    if (winsize != NULL)
+	        ioctl(*slave, TIOCSWINSZ, winsize);
+	    if (name != NULL)
+	        strcpy(name, pts_name);
+            return *slave;
+        }
+    }
+    return -1;
+}
+
diff --git a/misc/spooler.c b/misc/spooler.c
index b5d4e87..71e0153 100644
--- a/misc/spooler.c
+++ b/misc/spooler.c
@@ -52,7 +52,7 @@
  *           SetAbortProc32   (GDI32.301)
  *
  */
-INT32 WINAPI SetAbortProc32(HDC32 hdc, FARPROC32 abrtprc)
+INT32 WINAPI SetAbortProc32(HDC32 hdc, ABORTPROC32 abrtprc)
 {
     FIXME(print, "stub\n");
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
diff --git a/misc/toolhelp.c b/misc/toolhelp.c
index 751b620..926fd61 100644
--- a/misc/toolhelp.c
+++ b/misc/toolhelp.c
@@ -14,10 +14,10 @@
 #include "winerror.h"
 #include "tlhelp32.h"
 #include "toolhelp.h"
-#include "debug.h"
 #include "heap.h"
 #include "process.h"
 #include "k32obj.h"
+#include "debug.h"
 
 /*
  * Support for toolhelp's snapshots.  They
diff --git a/msdos/dpmi.c b/msdos/dpmi.c
index d49bc54..1d0c223 100644
--- a/msdos/dpmi.c
+++ b/msdos/dpmi.c
@@ -291,8 +291,8 @@
         CurrRMCB = CurrRMCB->next;
 
 #ifdef MZ_SUPPORTED
-    FIXME(int31,"DPMI real-mode call using DOS VM task system, not fully tested!\n");
     if (!(CurrRMCB || pModule->lpDosTask)) {
+        FIXME(int31,"DPMI real-mode call using DOS VM task system, not fully tested!\n");
         TRACE(int31,"creating VM86 task\n");
         if (MZ_InitTask( MZ_AllocDPMITask( pModule->self ) ) < 32) {
             ERR(int31,"could not setup VM86 task\n");
diff --git a/msdos/int21.c b/msdos/int21.c
index 8315d74..2b01169 100644
--- a/msdos/int21.c
+++ b/msdos/int21.c
@@ -225,7 +225,7 @@
     RESET_CFLAG(context);
 
     /* DOS device ? */
-    if ((file = FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context)), 0, NULL )))
+    if ((file = FILE_GetFile( FILE_GetHandle32(BX_reg(context)), 0, NULL )))
     {
         const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
         FILE_ReleaseFile( file );
@@ -725,7 +725,7 @@
         sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
         counter = (counter + 1) % 1000;
 
-        if ((AX_reg(context) = HFILE32_TO_HFILE16(_lcreat_uniq( name, 0 ))) != (WORD)HFILE_ERROR16)
+        if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
         {
             TRACE(int21, "created %s\n", name );
             return TRUE;
@@ -919,7 +919,7 @@
 		BX_reg(context),
 		MAKELONG(DX_reg(context),CX_reg(context)),
 		MAKELONG(DI_reg(context),SI_reg(context))) ;
-          if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context)),
+          if (!LockFile(FILE_GetHandle32(BX_reg(context)),
                         MAKELONG(DX_reg(context),CX_reg(context)), 0,
                         MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
 	    AX_reg(context) = DOS_ExtendedError;
@@ -932,7 +932,7 @@
 		BX_reg(context),
 		MAKELONG(DX_reg(context),CX_reg(context)),
 		MAKELONG(DI_reg(context),SI_reg(context))) ;
-          if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context)),
+          if (!UnlockFile(FILE_GetHandle32(BX_reg(context)),
                           MAKELONG(DX_reg(context),CX_reg(context)), 0,
                           MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
 	    AX_reg(context) = DOS_ExtendedError;
@@ -1127,8 +1127,10 @@
         break;
 
     case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
-                _lread16(1, (BYTE *)&context->Eax, 1);
-                break;
+        TRACE(int21,"DIRECT CHARACTER INPUT WITH ECHO\n");
+	AL_reg(context) = CONSOLE_GetCharacter();
+	/* FIXME: no echo */
+	break;
 
     case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
         TRACE(int21, "Write Character to Standard Output\n");
@@ -1177,13 +1179,15 @@
 	break;
       }
 
-    case 0x0b: /* GET STDIN STATUS */
-	{
-	    CHAR dummy;
+    case 0x0b: {/* GET STDIN STATUS */
+    		char x1,x2;
 
-	    AL_reg(context) = CONSOLE_CheckForKeystroke(&dummy, &dummy);
+		if (CONSOLE_CheckForKeystroke(&x1,&x2))
+		    AL_reg(context) = 0xff; 
+		else
+		    AL_reg(context) = 0; 
+		break;
 	}
-        break;
     case 0x2e: /* SET VERIFY FLAG */
         TRACE(int21,"SET VERIFY FLAG ignored\n");
     	/* we cannot change the behaviour anyway, so just ignore it */
@@ -1457,16 +1461,6 @@
 
     case 0x3e: /* "CLOSE" - CLOSE FILE */
         TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
-	if ((BX_reg(context)<5)||
-	    /* FIXME: need to improve on those handle conversion macros */
-	    (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE)))||
-	    (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE)))||
-	    (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE)))) {
-	    /* hack to make sure stdio isn't closed */
-	    FIXME(int21, "stdio handle closed, need proper conversion\n");
-	    DOS_ExtendedError = 0x06;
-	    bSetDOSExtendedError = TRUE;
-	} else
         bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
         break;
 
@@ -1566,7 +1560,7 @@
             break;
         case 0x02:{
            FILE_OBJECT *file;
-           file = FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context)),0,NULL);
+           file = FILE_GetFile(FILE_GetHandle32(BX_reg(context)),0,NULL);
            if (!strcasecmp(file->unix_name, "SCSIMGR$"))
                         ASPI_DOS_HandleInt(context);
            FILE_ReleaseFile( file );
@@ -1685,19 +1679,19 @@
             HANDLE32 handle;
             TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
             if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
-                                                          HFILE16_TO_HFILE32(BX_reg(context)),
+                                                          FILE_GetHandle32(BX_reg(context)),
                                                           GetCurrentProcess(), &handle,
                                                           0, TRUE, DUPLICATE_SAME_ACCESS )))
                 AX_reg(context) = HFILE_ERROR16;
             else
-                AX_reg(context) = HFILE32_TO_HFILE16(handle);
+                AX_reg(context) = FILE_AllocDosHandle(handle);
             break;
         }
 
     case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
         TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
 	      BX_reg(context),CX_reg(context));
-        bSetDOSExtendedError = (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context)), HFILE16_TO_HFILE32(CX_reg(context)) ) == HFILE_ERROR32);
+        bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
         break;
 
     case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
@@ -1848,7 +1842,7 @@
                 FILETIME filetime;
                 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
 		      BX_reg(context));
-                if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context)), NULL, NULL, &filetime ))
+                if (!GetFileTime( FILE_GetHandle32(BX_reg(context)), NULL, NULL, &filetime ))
 		     bSetDOSExtendedError = TRUE;
                 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
                                             &CX_reg(context) );
@@ -1863,7 +1857,7 @@
                 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
                                        &filetime );
                 bSetDOSExtendedError = 
-			(!SetFileTime( HFILE16_TO_HFILE32(BX_reg(context)),
+			(!SetFileTime( FILE_GetHandle32(BX_reg(context)),
                                       NULL, NULL, &filetime ));
             }
             break;
@@ -1897,7 +1891,7 @@
         TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
 	      (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  DS_reg(context), EDX_reg(context)));
         bSetDOSExtendedError = ((AX_reg(context) = 
-               HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)), 0 )))
+               _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)), 0 ))
 								== (WORD)HFILE_ERROR16);
         break;
 
@@ -2022,7 +2016,7 @@
     case 0x68: /* "FFLUSH" - COMMIT FILE */
     case 0x6a: /* COMMIT FILE */
         TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
-        bSetDOSExtendedError = (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context)) ));
+        bSetDOSExtendedError = (!FlushFileBuffers( FILE_GetHandle32(BX_reg(context)) ));
         break;		
 	
     case 0x69: /* DISK SERIAL NUMBER */
diff --git a/msdos/int2f.c b/msdos/int2f.c
index ac8bf4b..6374a2e 100644
--- a/msdos/int2f.c
+++ b/msdos/int2f.c
@@ -382,7 +382,7 @@
         /* FIXME: why a new linux-only CDROM drive access, for crying out loud?
          * There are pretty complete routines in multimedia/mcicda.c already! */
 	case 0x10: /* direct driver acces */
-            FIXME(cdaudio,"mscdex should use multimedia/mcicda.c");
+            FIXME(cdaudio,"mscdex should use multimedia/mcicda.c\n");
 	    do_mscdex_dd(context,ISV86(context));
 	    break;
 
diff --git a/msdos/vxd.c b/msdos/vxd.c
index 62cc284..420bb50 100644
--- a/msdos/vxd.c
+++ b/msdos/vxd.c
@@ -1009,7 +1009,7 @@
         LARGE_INTEGER *size = (LARGE_INTEGER *)W32S_APP2WINE(stack[3], W32S_OFFSET);
         DWORD  protect  = stack[4];
         DWORD  flags2   = stack[5];
-        HFILE32 hFile   = HFILE16_TO_HFILE32(stack[6]);
+        HFILE32 hFile   = FILE_GetHandle32(stack[6]);
         DWORD  psp      = stack[7];
 
         HANDLE32 result = INVALID_HANDLE_VALUE32;
diff --git a/multimedia/mcistring.c b/multimedia/mcistring.c
index 76580dd..8b82b68 100644
--- a/multimedia/mcistring.c
+++ b/multimedia/mcistring.c
@@ -29,40 +29,41 @@
 #include "debug.h"
 #include "xmalloc.h"
 
+/* FIXME the following definitions must be moved to mmsystem.c */
 extern struct WINE_MCIDRIVER mciDrv[MAXMCIDRIVERS];
 
 #define MCI_GetDrv(wDevID) 	(&mciDrv[MCI_DevIDToIndex(wDevID)])
 #define MCI_GetOpenDrv(wDevID) 	(&(MCI_GetDrv(wDevID)->mop))
-
-LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
-                             DWORD dwParam1, DWORD dwParam2);
+/* end of FIXME */
 
 /* The reason why I just don't lowercase the keywords array in 
  * mciSendString is left as an exercise to the reader.
  */
 #define STRCMP(x,y) lstrcmpi32A(x,y)
 
-/* standard functionparameters for all functions */
-#define _MCISTR_PROTO_ \
-	WORD wDevID,WORD uDevTyp,LPSTR lpstrReturnString,UINT16 uReturnLength,\
-	LPCSTR dev,LPSTR *keywords,UINT16 nrofkeywords,DWORD dwFlags,\
-        HWND16 hwndCallback
+/* standard function parameters for all functions */
+#define _MCISTR_PROTO_ 				       		\
+	WORD wDevID, WORD uDevTyp, LPSTR lpstrReturnString,	\
+        UINT16 uReturnLength, LPCSTR dev, LPSTR *keywords,	\
+	UINT16 nrofkeywords, DWORD dwFlags, HWND16 hwndCallback
 
 /* copy string to return pointer including necessary checks 
  * for use in mciSendString()
  */
-#define _MCI_STR(s) do {\
-	TRACE(mci,"->returns '%s'\n",s);\
-	if (lpstrReturnString) {\
-	    lstrcpyn32A(lpstrReturnString,s,uReturnLength);\
-	    TRACE(mci,"-->'%s'\n",lpstrReturnString);\
-	}\
+#define _MCI_STR(s) 						\
+do {								\
+    TRACE(mci, "->returns '%s'\n", s);				\
+    if (lpstrReturnString) {					\
+	lstrcpyn32A(lpstrReturnString, s, uReturnLength);	\
+	TRACE(mci, "-->'%s'\n", lpstrReturnString);		\
+    }								\
 } while(0)
 
 /* print a DWORD in the specified timeformat */
 static void
-_MCISTR_printtf(char *buf,UINT16 uDevType,DWORD timef,DWORD val) {
-    *buf='\0';
+_MCISTR_printtf(char *buf,UINT16 uDevType,DWORD timef,DWORD val) 
+{
+    *buf = '\0';
     switch (timef) {
     case MCI_FORMAT_MILLISECONDS:
     case MCI_FORMAT_FRAMES:
@@ -70,25 +71,23 @@
     case MCI_FORMAT_SAMPLES:
     case MCI_VD_FORMAT_TRACK:
 	/*case MCI_SEQ_FORMAT_SONGPTR: sameas MCI_VD_FORMAT_TRACK */
-	sprintf(buf,"%ld",val);
+	sprintf(buf, "%ld",val);
 	break;
     case MCI_FORMAT_HMS:
 	/* well, the macros have the same content*/
 	/*FALLTRHOUGH*/
     case MCI_FORMAT_MSF:
-	sprintf(buf,"%d:%d:%d",
+	sprintf(buf, "%d:%d:%d", 
 		MCI_HMS_HOUR(val),
 		MCI_HMS_MINUTE(val),
-		MCI_HMS_SECOND(val)
-		);
+		MCI_HMS_SECOND(val));
 	break;
     case MCI_FORMAT_TMSF:
-	sprintf(buf,"%d:%d:%d:%d",
+	sprintf(buf, "%d:%d:%d:%d",
 		MCI_TMSF_TRACK(val),
 		MCI_TMSF_MINUTE(val),
 		MCI_TMSF_SECOND(val),
-		MCI_TMSF_FRAME(val)
-		);
+		MCI_TMSF_FRAME(val)		);
 	break;
     default:
 	FIXME(mci, "missing timeformat for %ld, report.\n",timef);
@@ -110,35 +109,35 @@
 
 static void
 _MCISTR_convreturn(int type,DWORD dwReturn,LPSTR lpstrReturnString,
-		   WORD uReturnLength,WORD uDevTyp,int timef
-		   ) {
+		   WORD uReturnLength,WORD uDevTyp,int timef) 
+{
     switch (type) {
     case _MCISTR_vdmtype:
 	switch (dwReturn) {
-	case MCI_VD_MEDIA_CLV:_MCI_STR("CLV");break;
-	case MCI_VD_MEDIA_CAV:_MCI_STR("CAV");break;
+	case MCI_VD_MEDIA_CLV:	_MCI_STR("CLV");	break;
+	case MCI_VD_MEDIA_CAV:	_MCI_STR("CAV");	break;
 	default:
-	case MCI_VD_MEDIA_OTHER:_MCI_STR("other");break;
+	case MCI_VD_MEDIA_OTHER:_MCI_STR("other");	break;
 	}
 	break;
     case _MCISTR_seqtype:
 	switch (dwReturn) {
-	case MCI_SEQ_NONE:_MCI_STR("none");break;
-	case MCI_SEQ_SMPTE:_MCI_STR("smpte");break;
-	case MCI_SEQ_FILE:_MCI_STR("file");break;
-	case MCI_SEQ_MIDI:_MCI_STR("midi");break;
+	case MCI_SEQ_NONE:	_MCI_STR("none");	break;
+	case MCI_SEQ_SMPTE:	_MCI_STR("smpte");	break;
+	case MCI_SEQ_FILE:	_MCI_STR("file");	break;
+	case MCI_SEQ_MIDI:	_MCI_STR("midi");	break;
 	default:FIXME(mci,"missing sequencer mode %ld\n",dwReturn);
 	}
 	break;
     case _MCISTR_mode:
 	switch (dwReturn) {
-	case MCI_MODE_NOT_READY:_MCI_STR("not ready");break;
-	case MCI_MODE_STOP:_MCI_STR("stopped");break;
-	case MCI_MODE_PLAY:_MCI_STR("playing");break;
-	case MCI_MODE_RECORD:_MCI_STR("recording");break;
-	case MCI_MODE_SEEK:_MCI_STR("seeking");break;
-	case MCI_MODE_PAUSE:_MCI_STR("paused");break;
-	case MCI_MODE_OPEN:_MCI_STR("open");break;
+	case MCI_MODE_NOT_READY:_MCI_STR("not ready");	break;
+	case MCI_MODE_STOP:	_MCI_STR("stopped");	break;
+	case MCI_MODE_PLAY:	_MCI_STR("playing");	break;
+	case MCI_MODE_RECORD:	_MCI_STR("recording");	break;
+	case MCI_MODE_SEEK:	_MCI_STR("seeking");	break;
+	case MCI_MODE_PAUSE:	_MCI_STR("paused");	break;
+	case MCI_MODE_OPEN:	_MCI_STR("open");	break;
 	default:break;
 	}
 	break;
@@ -162,13 +161,13 @@
     }
     case _MCISTR_tfname:
 	switch (timef) {
-	case MCI_FORMAT_MILLISECONDS:_MCI_STR("milliseconds");break;
-	case MCI_FORMAT_FRAMES:_MCI_STR("frames");break;
-	case MCI_FORMAT_BYTES:_MCI_STR("bytes");break;
-	case MCI_FORMAT_SAMPLES:_MCI_STR("samples");break;
-	case MCI_FORMAT_HMS:_MCI_STR("hms");break;
-	case MCI_FORMAT_MSF:_MCI_STR("msf");break;
-	case MCI_FORMAT_TMSF:_MCI_STR("tmsf");break;
+	case MCI_FORMAT_MILLISECONDS:	_MCI_STR("milliseconds");	break;
+	case MCI_FORMAT_FRAMES:		_MCI_STR("frames");		break;
+	case MCI_FORMAT_BYTES:		_MCI_STR("bytes");		break;
+	case MCI_FORMAT_SAMPLES:	_MCI_STR("samples");		break;
+	case MCI_FORMAT_HMS:		_MCI_STR("hms");		break;
+	case MCI_FORMAT_MSF:		_MCI_STR("msf");		break;
+	case MCI_FORMAT_TMSF:		_MCI_STR("tmsf");		break;
 	default:
 	    FIXME(mci,"missing timefmt for %d, report.\n",timef);
 	    break;
@@ -176,25 +175,25 @@
 	break;
     case _MCISTR_divtype:
 	switch (dwReturn) {
-	case MCI_SEQ_DIV_PPQN:_MCI_STR("PPQN");break;
-	case MCI_SEQ_DIV_SMPTE_24:_MCI_STR("SMPTE 24 frame");break;
-	case MCI_SEQ_DIV_SMPTE_25:_MCI_STR("SMPTE 25 frame");break;
-	case MCI_SEQ_DIV_SMPTE_30:_MCI_STR("SMPTE 30 frame");break;
-	case MCI_SEQ_DIV_SMPTE_30DROP:_MCI_STR("SMPTE 30 frame drop");break;
+	case MCI_SEQ_DIV_PPQN:		_MCI_STR("PPQN");		break;
+	case MCI_SEQ_DIV_SMPTE_24:	_MCI_STR("SMPTE 24 frame");	break;
+	case MCI_SEQ_DIV_SMPTE_25:	_MCI_STR("SMPTE 25 frame");	break;
+	case MCI_SEQ_DIV_SMPTE_30:	_MCI_STR("SMPTE 30 frame");	break;
+	case MCI_SEQ_DIV_SMPTE_30DROP:	_MCI_STR("SMPTE 30 frame drop");break;
 	}
     case _MCISTR_devtype:
 	switch (dwReturn) {
-	case MCI_DEVTYPE_VCR:_MCI_STR("vcr");break;
-	case MCI_DEVTYPE_VIDEODISC:_MCI_STR("videodisc");break;
-	case MCI_DEVTYPE_CD_AUDIO:_MCI_STR("cd audio");break;
-	case MCI_DEVTYPE_OVERLAY:_MCI_STR("overlay");break;
-	case MCI_DEVTYPE_DAT:_MCI_STR("dat");break;
-	case MCI_DEVTYPE_SCANNER:_MCI_STR("scanner");break;
-	case MCI_DEVTYPE_ANIMATION:_MCI_STR("animation");break;
-	case MCI_DEVTYPE_DIGITAL_VIDEO:_MCI_STR("digital video");break;
-	case MCI_DEVTYPE_OTHER:_MCI_STR("other");break;
-	case MCI_DEVTYPE_WAVEFORM_AUDIO:_MCI_STR("waveform audio");break;
-	case MCI_DEVTYPE_SEQUENCER:_MCI_STR("sequencer");break;
+	case MCI_DEVTYPE_VCR:		_MCI_STR("vcr");		break;
+	case MCI_DEVTYPE_VIDEODISC:	_MCI_STR("videodisc");		break;
+	case MCI_DEVTYPE_CD_AUDIO:	_MCI_STR("cd audio");		break;
+	case MCI_DEVTYPE_OVERLAY:	_MCI_STR("overlay");		break;
+	case MCI_DEVTYPE_DAT:		_MCI_STR("dat");		break;
+	case MCI_DEVTYPE_SCANNER:	_MCI_STR("scanner");		break;
+	case MCI_DEVTYPE_ANIMATION:	_MCI_STR("animation");		break;
+	case MCI_DEVTYPE_DIGITAL_VIDEO:	_MCI_STR("digital video");	break;
+	case MCI_DEVTYPE_OTHER:		_MCI_STR("other");		break;
+	case MCI_DEVTYPE_WAVEFORM_AUDIO:_MCI_STR("waveform audio");	break;
+	case MCI_DEVTYPE_SEQUENCER:	_MCI_STR("sequencer");		break;
 	default:FIXME(mci,"unknown device type %ld, report.\n",
 		      dwReturn);break;
 	}
@@ -205,17 +204,20 @@
     }
 }
 
-#define FLAG1(str,flag) \
-	if (!STRCMP(keywords[i],str)) {\
-		dwFlags |= flag;\
-		i++;\
-		continue;\
+#define FLAG1(str,flag) 			\
+	if (!STRCMP(keywords[i],str)) {		\
+		dwFlags |= flag;		\
+		i++;				\
+		continue;			\
 	}
-#define FLAG2(str1,str2,flag) \
-	if (!STRCMP(keywords[i],str1) && (i+1<nrofkeywords) && !STRCMP(keywords[i+1],str2)) {\
-		dwFlags |= flag;\
-		i+=2;\
-		continue;\
+
+#define FLAG2(str1,str2,flag) 			\
+	if (!STRCMP(keywords[i],str1) &&	\
+	    (i+1<nrofkeywords) && 		\
+            !STRCMP(keywords[i+1],str2)) {	\
+		dwFlags |= flag;		\
+		i+=2;				\
+		continue;			\
 	}
 
 /* All known subcommands are implemented in single functions to avoid
@@ -261,7 +263,8 @@
  * Returns nothing.
  */
 static DWORD
-MCISTR_Open(_MCISTR_PROTO_) {
+MCISTR_Open(_MCISTR_PROTO_) 
+{
     int			res,i;
     char		*s;
     union U {
@@ -273,10 +276,10 @@
     union U *pU = xmalloc(sizeof(union U));
     
     pU->openParams.lpstrElementName = NULL;
-    s=strchr(dev,'!');
-    if (s!=NULL) {
-	*s++='\0';
-	pU->openParams.lpstrElementName=strdup(s);
+    s = strchr(dev,'!');
+    if (s != NULL) {
+	*s++ = '\0';
+	pU->openParams.lpstrElementName = strdup(s);
 	dwFlags |= MCI_OPEN_ELEMENT;
     }
     uDevTyp = MCI_GetDevType(dev);
@@ -285,19 +288,8 @@
 	free(pU);
 	return MCIERR_INVALID_DEVICE_NAME;
     }
-    wDevID=MCI_FirstDevID();
-    while(MCI_GetDrv(wDevID)->modp.wType) {
-	wDevID = MCI_NextDevID(wDevID);
-	if (!MCI_DevIDValid(wDevID)) {
-	    TRACE(mci, "MAXMCIDRIVERS reached (%x) !\n", wDevID);
-	    free(pU->openParams.lpstrElementName);
-	    free(pU);
-	    return MCIERR_INTERNAL;
-	}
-    }
-    MCI_GetDrv(wDevID)->modp.wType	= uDevTyp;
-    MCI_GetDrv(wDevID)->modp.wDeviceID	= 0;  /* FIXME? for multiple devices */
-    pU->openParams.dwCallback	= hwndCallback ;
+
+    pU->openParams.dwCallback	= hwndCallback;
     pU->openParams.wDeviceID	= wDevID;
     pU->openParams.wReserved0   = 0;
     pU->ovlyopenParams.dwStyle	= 0; 
@@ -305,18 +297,18 @@
     pU->openParams.lpstrDeviceType	= strdup(dev);
     pU->openParams.lpstrAlias	= NULL;
     dwFlags |= MCI_OPEN_TYPE;
-    i=0;
-    while (i<nrofkeywords) {
+    i = 0;
+    while (i < nrofkeywords) {
 	FLAG1("shareable",MCI_OPEN_SHAREABLE);
-	if (!STRCMP(keywords[i],"alias") && (i+1<nrofkeywords)) {
+	if (!STRCMP(keywords[i],"alias") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_OPEN_ALIAS;
-	    pU->openParams.lpstrAlias=strdup(keywords[i+1]);
+	    pU->openParams.lpstrAlias = strdup(keywords[i+1]);
 	    i+=2;
 	    continue;
 	}
 	if (!STRCMP(keywords[i],"element") && (i+1<nrofkeywords)) {
 	    dwFlags |= MCI_OPEN_ELEMENT;
-	    pU->openParams.lpstrElementName=strdup(keywords[i+1]);
+	    pU->openParams.lpstrElementName = strdup(keywords[i+1]);
 	    i+=2;
 	    continue;
 	}
@@ -324,13 +316,13 @@
 	case MCI_DEVTYPE_ANIMATION:
 	case MCI_DEVTYPE_DIGITAL_VIDEO:
 	    FLAG1("nostatic",MCI_ANIM_OPEN_NOSTATIC);
-	    if (!STRCMP(keywords[i],"parent") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"parent") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_ANIM_OPEN_PARENT;
-		sscanf(keywords[i+1],"%hu",&(pU->animopenParams.hWndParent));
+		sscanf(keywords[i+1], "%hu", &(pU->animopenParams.hWndParent));
 		i+=2;
 		continue;
 	    }
-	    if (!STRCMP(keywords[i],"style") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i], "style") && (i+1 < nrofkeywords)) {
 		DWORD	st;
 		
 		dwFlags |= MCI_ANIM_OPEN_WS;
@@ -343,26 +335,26 @@
 		} else if (sscanf(keywords[i+1],"%ld",&st)) {
 		    pU->animopenParams.dwStyle |= st; 
 		} else
-		    FIXME(mci,"unknown 'style' keyword %s, please report.\n",keywords[i+1]);
+		    FIXME(mci, "unknown 'style' keyword %s, please report.\n", keywords[i+1]);
 		i+=2;
 		continue;
 	    }
 	    break;
 	case MCI_DEVTYPE_WAVEFORM_AUDIO:
-	    if (!STRCMP(keywords[i],"buffer") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"buffer") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_WAVE_OPEN_BUFFER;
-		sscanf(keywords[i+1],"%ld",&(pU->waveopenParams.dwBufferSeconds));
+		sscanf(keywords[i+1], "%ld", &(pU->waveopenParams.dwBufferSeconds));
 	    }
 	    break;
 	case MCI_DEVTYPE_OVERLAY:
 	    /* looks just like anim, but without NOSTATIC */
-	    if (!STRCMP(keywords[i],"parent") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i], "parent") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_OVLY_OPEN_PARENT;
-		sscanf(keywords[i+1],"%hd",&(pU->ovlyopenParams.hWndParent));
+		sscanf(keywords[i+1], "%hd", &(pU->ovlyopenParams.hWndParent));
 		i+=2;
 		continue;
 	    }
-	    if (!STRCMP(keywords[i],"style") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"style") && (i+1 < nrofkeywords)) {
 		DWORD	st;
 		
 		dwFlags |= MCI_OVLY_OPEN_WS;
@@ -385,15 +377,11 @@
 	      keywords[i]);
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_OPEN, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(0, MCI_OPEN, dwFlags, (DWORD)pU);
 
-    if (res==0)
-	memcpy(MCI_GetOpenDrv(wDevID),&pU->openParams,sizeof(MCI_OPEN_PARMS16));
-    else {
- 	free(pU->openParams.lpstrElementName);
-	free(pU->openParams.lpstrDeviceType);
-	free(pU->openParams.lpstrAlias);
-    }
+    free(pU->openParams.lpstrElementName);
+    free(pU->openParams.lpstrDeviceType);
+    free(pU->openParams.lpstrAlias);
     free(pU);
     return res;
 }
@@ -411,7 +399,7 @@
     if (!statusParams) return 0;
     statusParams->dwItem	= MCI_STATUS_TIME_FORMAT;
     statusParams->dwReturn	= 0;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_STATUS, dwFlags, (DWORD)statusParams);
+    res = mciSendCommand32A(wDevID, MCI_STATUS, dwFlags, (DWORD)statusParams);
 
     if (res==0) *timef = statusParams->dwReturn;
     free(statusParams);
@@ -471,34 +459,33 @@
  *	"level"			- return level?
  */
 
-#define ITEM1(str,item,xtype) \
-	if (!STRCMP(keywords[i],str)) {\
-		statusParams->dwItem = item;\
-		type = xtype;\
-		i++;\
-		continue;\
+#define ITEM1(str,item,xtype) 			\
+	if (!STRCMP(keywords[i],str)) {		\
+		statusParams->dwItem = item;	\
+		type = xtype;			\
+		i++;				\
+		continue;			\
 	}
-#define ITEM2(str1,str2,item,xtype) \
-	if (	!STRCMP(keywords[i],str1) &&\
-		(i+1<nrofkeywords) &&\
-		!STRCMP(keywords[i+1],str2)\
-	) {\
-		statusParams->dwItem = item;\
-		type = xtype;\
-		i+=2;\
-		continue;\
+#define ITEM2(str1,str2,item,xtype) 		\
+	if (	!STRCMP(keywords[i],str1) &&	\
+		(i+1 < nrofkeywords) &&		\
+		!STRCMP(keywords[i+1],str2)) {	\
+		statusParams->dwItem = item;	\
+		type = xtype;			\
+		i+=2;				\
+		continue;			\
 	}
-#define ITEM3(str1,str2,str3,item,xtype) \
-	if (	!STRCMP(keywords[i],str1) &&\
-		(i+2<nrofkeywords) &&\
-		!STRCMP(keywords[i+1],str2) &&\
-		!STRCMP(keywords[i+2],str3)\
-	) {\
-		statusParams->dwItem = item;\
-		type = xtype;\
-		i+=3;\
-		continue;\
+#define ITEM3(str1,str2,str3,item,xtype) 	\
+	if (	!STRCMP(keywords[i],str1) &&	\
+		(i+2 < nrofkeywords) &&		\
+		!STRCMP(keywords[i+1],str2) &&	\
+		!STRCMP(keywords[i+2],str3)) {	\
+		statusParams->dwItem = item;	\
+		type = xtype;			\
+		i+=3;				\
+		continue;			\
 	}
+
 static DWORD
 MCISTR_Status(_MCISTR_PROTO_) {
     MCI_STATUS_PARMS	*statusParams = xmalloc(sizeof(MCI_STATUS_PARMS));
@@ -513,8 +500,8 @@
     statusParams->dwItem	= 0;
     i = 0;
     
-    while (i<nrofkeywords) {
-	if (!STRCMP(keywords[i],"track") && (i+1<nrofkeywords)) {
+    while (i < nrofkeywords) {
+	if (!STRCMP(keywords[i],"track") && (i+1 < nrofkeywords)) {
 	    sscanf(keywords[i+1],"%ld",&(statusParams->dwTrack));
 	    dwFlags |= MCI_TRACK;
 	    i+=2;
@@ -583,7 +570,7 @@
     if (!statusParams->dwItem) 
 	return MCIERR_MISSING_STRING_ARGUMENT;
     
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_STATUS, dwFlags, (DWORD)statusParams);
+    res = mciSendCommand32A(wDevID, MCI_STATUS, dwFlags, (DWORD)statusParams);
 
     if (res==0)
 	_MCISTR_convreturn(type,statusParams->dwReturn,lpstrReturnString,uReturnLength,uDevTyp,timef);
@@ -636,12 +623,12 @@
     
     pU->setParams.dwCallback = hwndCallback;
     i = 0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	FLAG2("door","open",MCI_SET_DOOR_OPEN);
 	FLAG2("door","closed",MCI_SET_DOOR_CLOSED);
 	
 	if (	!STRCMP(keywords[i],"time") && 
-		(i+2<nrofkeywords) &&
+		(i+2 < nrofkeywords) &&
 		!STRCMP(keywords[i+1],"format")
 		) {
 	    dwFlags |= MCI_SET_TIME_FORMAT;
@@ -668,18 +655,18 @@
 	    if (!STRCMP(keywords[i+2],"tmsf"))
 		pU->setParams.dwTimeFormat = MCI_FORMAT_TMSF;
 	    if (	!STRCMP(keywords[i+2],"song") && 
-			(i+3<nrofkeywords) &&
+			(i+3 < nrofkeywords) &&
 			!STRCMP(keywords[i+3],"pointer")
 			)
 		pU->setParams.dwTimeFormat = MCI_SEQ_FORMAT_SONGPTR;
-	    if (!STRCMP(keywords[i+2],"smpte") && (i+3<nrofkeywords)) {
+	    if (!STRCMP(keywords[i+2],"smpte") && (i+3 < nrofkeywords)) {
 		if (!STRCMP(keywords[i+3],"24"))
 		    pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_24;
 		if (!STRCMP(keywords[i+3],"25"))
 		    pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_25;
 		if (!STRCMP(keywords[i+3],"30"))
 		    pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30;
-		if (!STRCMP(keywords[i+3],"drop") && (i+4<nrofkeywords) && !STRCMP(keywords[i+4],"30")) {
+		if (!STRCMP(keywords[i+3],"drop") && (i+4 < nrofkeywords) && !STRCMP(keywords[i+4],"30")) {
 		    pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30DROP;
 		    i++;
 		}
@@ -689,7 +676,7 @@
 	    i+=3;
 	    continue;
 	}
-	if (!STRCMP(keywords[i],"audio") && (i+1<nrofkeywords)) {
+	if (!STRCMP(keywords[i],"audio") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_SET_AUDIO;
 	    if (!STRCMP(keywords[i+1],"all"))
 		pU->setParams.dwAudio = MCI_SET_AUDIO_ALL;
@@ -709,7 +696,7 @@
 	    FLAG2("any","output",MCI_WAVE_SET_ANYOUTPUT);
 	    
 	    if (	!STRCMP(keywords[i],"formattag") && 
-			(i+1<nrofkeywords) &&
+			(i+1 < nrofkeywords) &&
 			!STRCMP(keywords[i+1],"pcm")
 			) {
 		dwFlags |= MCI_WAVE_SET_FORMATTAG;
@@ -719,13 +706,15 @@
 	    }
 	    
 	    /* <keyword> <integer> */
-#define WII(str,flag,fmt,element) \
-			if (!STRCMP(keywords[i],str) && (i+1<nrofkeywords)) {\
-				sscanf(keywords[i+1],fmt,&(pU->wavesetParams. element ));\
-				dwFlags |= flag;\
-				i+=2;\
-				continue;\
-			}
+#define WII(str,flag,fmt,element) 		\
+    if (!STRCMP(keywords[i],str) &&		\
+	(i+1 < nrofkeywords)) {			\
+        sscanf(keywords[i+1], fmt,		\
+	       &(pU->wavesetParams. element));	\
+	dwFlags |= flag;			\
+	i+=2;					\
+	continue;				\
+    }
 	    WII("formattag",MCI_WAVE_SET_FORMATTAG,"%hu",wFormatTag);
 	    WII("channels",MCI_WAVE_SET_CHANNELS,"%hu",nChannels);
 	    WII("bytespersec",MCI_WAVE_SET_AVGBYTESPERSEC,"%lu",nAvgBytesPerSec);
@@ -737,7 +726,7 @@
 #undef WII
 	    break;
 	case MCI_DEVTYPE_SEQUENCER:
-	    if (!STRCMP(keywords[i],"master") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"master") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_SEQ_SET_MASTER;
 		if (!STRCMP(keywords[i+1],"midi"))
 		    pU->seqsetParams.dwMaster = MCI_SEQ_MIDI;
@@ -750,7 +739,7 @@
 		i+=2;
 		continue;
 	    }
-	    if (!STRCMP(keywords[i],"slave") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"slave") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_SEQ_SET_SLAVE;
 		if (!STRCMP(keywords[i+1],"midi"))
 		    pU->seqsetParams.dwMaster = MCI_SEQ_MIDI;
@@ -764,7 +753,7 @@
 		continue;
 	    }
 	    if (	!STRCMP(keywords[i],"port") && 
-			(i+1<nrofkeywords) &&
+			(i+1 < nrofkeywords) &&
 			!STRCMP(keywords[i+1],"mapper")
 			) {
 		pU->seqsetParams.dwPort=-1;/* FIXME:not sure*/
@@ -773,12 +762,12 @@
 		continue;
 	    }
 #define SII(str,flag,element) \
-			if (!STRCMP(keywords[i],str) && (i+1<nrofkeywords)) {\
-				sscanf(keywords[i+1],"%ld",&(pU->seqsetParams. element ));\
-				dwFlags |= flag;\
-				i+=2;\
-				continue;\
-			}
+	if (!STRCMP(keywords[i],str) && (i+1 < nrofkeywords)) {\
+		sscanf(keywords[i+1],"%ld",&(pU->seqsetParams. element));\
+		dwFlags |= flag;\
+		i+=2;\
+		continue;\
+	}
 	    SII("tempo",MCI_SEQ_SET_TEMPO,dwTempo);
 	    SII("port",MCI_SEQ_SET_PORT,dwPort);
 	    SII("offset",MCI_SEQ_SET_PORT,dwOffset);
@@ -787,7 +776,7 @@
     }
     if (!dwFlags)
 	return MCIERR_MISSING_STRING_ARGUMENT;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_SET, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_SET, dwFlags, (DWORD)pU);
     free(pU);
     return res;
 }
@@ -819,39 +808,38 @@
 	    continue;
 	}
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_BREAK, dwFlags, (DWORD)breakParams);
+    res = mciSendCommand32A(wDevID, MCI_BREAK, dwFlags, (DWORD)breakParams);
     free(breakParams);
     return res;
 }
 
-#define ITEM1(str,item,xtype) \
-	if (!STRCMP(keywords[i],str)) {\
-		gdcParams->dwItem = item;\
-		type = xtype;\
-		i++;\
-		continue;\
+#define ITEM1(str,item,xtype) 			\
+	if (!STRCMP(keywords[i],str)) {		\
+		gdcParams->dwItem = item;	\
+		type = xtype;			\
+		i++;				\
+		continue;			\
 	}
-#define ITEM2(str1,str2,item,xtype) \
-	if (	!STRCMP(keywords[i],str1) &&\
-		(i+1<nrofkeywords) &&\
-		!STRCMP(keywords[i+1],str2)\
-	) {\
-		gdcParams->dwItem = item;\
-		type = xtype;\
-		i+=2;\
-		continue;\
+#define ITEM2(str1,str2,item,xtype) 		\
+	if (	!STRCMP(keywords[i],str1) &&	\
+		(i+1 < nrofkeywords) &&		\
+		!STRCMP(keywords[i+1],str2)) {	\
+		gdcParams->dwItem = item;	\
+		type = xtype;			\
+		i+=2;				\
+		continue;			\
 	}
-#define ITEM3(str1,str2,str3,item,xtype) \
-	if (	!STRCMP(keywords[i],str1) &&\
-		(i+2<nrofkeywords) &&\
-		!STRCMP(keywords[i+1],str2) &&\
-		!STRCMP(keywords[i+2],str3)\
-	) {\
-		gdcParams->dwItem = item;\
-		type = xtype;\
-		i+=3;\
-		continue;\
+#define ITEM3(str1,str2,str3,item,xtype) 	\
+	if (	!STRCMP(keywords[i],str1) &&	\
+		(i+2 < nrofkeywords) &&		\
+		!STRCMP(keywords[i+1],str2) &&	\
+		!STRCMP(keywords[i+2],str3)) {	\
+		gdcParams->dwItem = item;	\
+		type = xtype;			\
+		i+=3;				\
+		continue;			\
 	}
+
 /* get device capabilities of MCI drivers
  * Arguments:
  * Generic:
@@ -899,7 +887,7 @@
     dwFlags |= MCI_GETDEVCAPS_ITEM;
     gdcParams->dwItem = 0;
     i=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	ITEM2("device","type",MCI_GETDEVCAPS_DEVICE_TYPE,_MCISTR_devtype);
 	ITEM2("has","audio",MCI_GETDEVCAPS_HAS_AUDIO,_MCISTR_bool);
 	ITEM2("has","video",MCI_GETDEVCAPS_HAS_VIDEO,_MCISTR_bool);
@@ -939,12 +927,12 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_GETDEVCAPS, dwFlags, (DWORD)gdcParams);
+    res = mciSendCommand32A(wDevID, MCI_GETDEVCAPS, dwFlags, (DWORD)gdcParams);
 
     /* no timeformat needed */
     if (res==0)
-	_MCISTR_convreturn( type, gdcParams->dwReturn, lpstrReturnString,
-			    uReturnLength, uDevTyp, 0 );
+	_MCISTR_convreturn(type, gdcParams->dwReturn, lpstrReturnString,
+			    uReturnLength, uDevTyp, 0);
     free(gdcParams);
     return res;
 }
@@ -958,7 +946,7 @@
     MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
     int	res;
     genParams->dwCallback = hwndCallback;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_RESUME, dwFlags, (DWORD)genParams);
+    res = mciSendCommand32A(wDevID, MCI_RESUME, dwFlags, (DWORD)genParams);
     free(genParams);
     return res;
 }
@@ -970,7 +958,7 @@
     MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
     int res;
     genParams->dwCallback = hwndCallback;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_PAUSE, dwFlags, (DWORD)genParams);
+    res = mciSendCommand32A(wDevID, MCI_PAUSE, dwFlags, (DWORD)genParams);
     free(genParams);
     return res;
 }
@@ -982,7 +970,7 @@
     MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
     int res;
     genParams->dwCallback = hwndCallback;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_STOP, dwFlags, (DWORD)genParams);
+    res = mciSendCommand32A(wDevID, MCI_STOP, dwFlags, (DWORD)genParams);
     free(genParams);
     return res;
 }
@@ -1027,8 +1015,8 @@
     }
     recordParams->dwCallback = hwndCallback;
     i = 0;
-    while (i<nrofkeywords) {
-	if (!strcmp(keywords[i],"to") && (i+1<nrofkeywords)) {
+    while (i < nrofkeywords) {
+	if (!strcmp(keywords[i],"to") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_TO;
 	    a[0]=a[1]=a[2]=a[3]=0;
 	    j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
@@ -1037,18 +1025,18 @@
 	     * mmsystem.h, right).
 	     */
 	    recordParams->dwTo=0;
-	    for (k=0;k<j;k++)
-		recordParams->dwTo+=a[k]<<(8*(nrargs-k));
+	    for (k=0;k < j;k++)
+		recordParams->dwTo+=a[k] << (8*(nrargs-k));
 	    i+=2;
 	    continue;
 	}
-	if (!strcmp(keywords[i],"from") && (i+1<nrofkeywords)) {
+	if (!strcmp(keywords[i],"from") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_FROM;
 	    a[0]=a[1]=a[2]=a[3]=0;
 	    j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
 	    /* dito. */
 	    recordParams->dwFrom=0;
-	    for (k=0;k<j;k++)
+	    for (k=0;k < j;k++)
 		recordParams->dwFrom+=a[k]<<(8*(nrargs-k));
 	    i+=2;
 	    continue;
@@ -1057,7 +1045,7 @@
 	FLAG1("overwrite",MCI_RECORD_OVERWRITE);
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_RECORD, dwFlags, (DWORD)recordParams);
+    res = mciSendCommand32A(wDevID, MCI_RECORD, dwFlags, (DWORD)recordParams);
     free(recordParams);
     return res;
 }
@@ -1116,8 +1104,8 @@
     }
     pU->playParams.dwCallback=hwndCallback;
     i=0;
-    while (i<nrofkeywords) {
-	if (!strcmp(keywords[i],"to") && (i+1<nrofkeywords)) {
+    while (i < nrofkeywords) {
+	if (!strcmp(keywords[i],"to") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_TO;
 	    a[0]=a[1]=a[2]=a[3]=0;
 	    j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
@@ -1126,18 +1114,18 @@
 	     * mmsystem.h, right).
 	     */
 	    pU->playParams.dwTo=0;
-	    for (k=0;k<j;k++)
-		pU->playParams.dwTo+=a[k]<<(8*(nrargs-k));
+	    for (k=0;k < j;k++)
+		pU->playParams.dwTo+=a[k] << (8*(nrargs-k));
 	    i+=2;
 	    continue;
 	}
-	if (!strcmp(keywords[i],"from") && (i+1<nrofkeywords)) {
+	if (!strcmp(keywords[i],"from") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_FROM;
 	    a[0]=a[1]=a[2]=a[3]=0;
 	    j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
 	    /* dito. */
 	    pU->playParams.dwFrom=0;
-	    for (k=0;k<j;k++)
+	    for (k=0;k < j;k++)
 		pU->playParams.dwFrom+=a[k]<<(8*(nrargs-k));
 	    i+=2;
 	    continue;
@@ -1148,7 +1136,7 @@
 	    FLAG1("fast",MCI_VD_PLAY_FAST);
 	    FLAG1("scan",MCI_VD_PLAY_SCAN);
 	    FLAG1("reverse",MCI_VD_PLAY_REVERSE);
-	    if (!STRCMP(keywords[i],"speed") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"speed") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_VD_PLAY_SPEED;
 		sscanf(keywords[i+1],"%ld",&(pU->vdplayParams.dwSpeed));
 		i+=2;
@@ -1160,7 +1148,7 @@
 	    FLAG1("fast",MCI_ANIM_PLAY_FAST);
 	    FLAG1("scan",MCI_ANIM_PLAY_SCAN);
 	    FLAG1("reverse",MCI_ANIM_PLAY_REVERSE);
-	    if (!STRCMP(keywords[i],"speed") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"speed") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_ANIM_PLAY_SPEED;
 		sscanf(keywords[i+1],"%ld",&(pU->animplayParams.dwSpeed));
 		i+=2;
@@ -1170,7 +1158,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_PLAY, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_PLAY, dwFlags, (DWORD)pU);
     free(pU);
     return res;
 }
@@ -1213,8 +1201,8 @@
     }
     seekParams->dwCallback=hwndCallback;
     i=0;
-    while (i<nrofkeywords) {
-	if (	!STRCMP(keywords[i],"to") && (i+1<nrofkeywords)) {
+    while (i < nrofkeywords) {
+	if (	!STRCMP(keywords[i],"to") && (i+1 < nrofkeywords)) {
 	    if (!STRCMP(keywords[i+1],"start")) {
 		dwFlags|=MCI_SEEK_TO_START;
 		seekParams->dwTo=0;
@@ -1232,8 +1220,8 @@
 	    a[0]=a[1]=a[2]=a[3]=0;
 	    j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
 	    seekParams->dwTo=0;
-	    for (k=0;k<j;k++)
-		seekParams->dwTo+=a[k]<<(8*(nrargs-k));
+	    for (k=0;k < j;k++)
+		seekParams->dwTo+=a[k] << (8*(nrargs-k));
 	    continue;
 	}
 	switch (uDevTyp) {
@@ -1243,7 +1231,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_SEEK, dwFlags, (DWORD)seekParams);
+    res = mciSendCommand32A(wDevID, MCI_SEEK, dwFlags, (DWORD)seekParams);
     free(seekParams);
     return res;
 }
@@ -1252,10 +1240,10 @@
 static DWORD
 MCISTR_Close(_MCISTR_PROTO_)
 {
-    MCI_GENERIC_PARMS *closeParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
+    MCI_GENERIC_PARMS*	closeParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
     int res;
     
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_CLOSE, dwFlags, (DWORD)closeParams);
+    res = mciSendCommand32A(wDevID, MCI_CLOSE, dwFlags, (DWORD)closeParams);
     free(closeParams);
     return res;
 }
@@ -1272,13 +1260,13 @@
 static DWORD
 MCISTR_Info(_MCISTR_PROTO_)
 {
-    MCI_INFO_PARMS16 *infoParams = xmalloc(sizeof(MCI_INFO_PARMS16));
+    MCI_INFO_PARMS16*	infoParams = xmalloc(sizeof(MCI_INFO_PARMS16));
     DWORD		sflags;
     int		i,res;
     
     sflags = dwFlags;
     i=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	FLAG1("product",MCI_INFO_PRODUCT);
 	FLAG1("file",MCI_INFO_FILE);
 	switch (uDevTyp) {
@@ -1296,7 +1284,7 @@
     /* MCI driver will fill in lpstrReturn, dwRetSize.
      * FIXME: I don't know if this is correct behaviour
      */
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_INFO, dwFlags, (DWORD)infoParams);
+    res = mciSendCommand32A(wDevID, MCI_INFO, dwFlags, (DWORD)infoParams);
     if (res==0)
 	_MCI_STR(infoParams->lpstrReturn);
     free(infoParams);
@@ -1326,7 +1314,7 @@
 	FLAG1("installname",MCI_SYSINFO_INSTALLNAME);
 	FLAG1("quantity",MCI_SYSINFO_INSTALLNAME);
 	FLAG1("open",MCI_SYSINFO_OPEN);
-	if (!strcmp(keywords[i],"name") && (i+1<nrofkeywords)) {
+	if (!strcmp(keywords[i],"name") && (i+1 < nrofkeywords)) {
 	    sscanf(keywords[i+1],"%ld",&(sysinfoParams.dwNumber));
 	    dwFlags |= MCI_SYSINFO_NAME;
 	    i++;
@@ -1354,15 +1342,15 @@
 	MCI_LOAD_PARMS16	loadParams;
 	MCI_OVLY_LOAD_PARMS16	ovlyloadParams;
     };
-    union U *pU = xmalloc(sizeof(union U));
+    union 	U *pU = xmalloc(sizeof(union U));
     int		i,len,res;
-    char		*s;
+    char	*s;
     
     i=len=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	switch (uDevTyp) {
 	case MCI_DEVTYPE_OVERLAY:
-	    if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"at") && (i+4 < nrofkeywords)) {
 		dwFlags |= MCI_OVLY_RECT;
 		sscanf(keywords[i+1],"%hd",&(pU->ovlyloadParams.rc.left));
 		sscanf(keywords[i+2],"%hd",&(pU->ovlyloadParams.rc.top));
@@ -1378,14 +1366,14 @@
     }
     s=(char*)xmalloc(len);
     *s='\0';
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	strcat(s,keywords[i]);
 	i++;
-	if (i<nrofkeywords) strcat(s," ");
+	if (i < nrofkeywords) strcat(s," ");
     }
     pU->loadParams.lpfilename=s;
     dwFlags |= MCI_LOAD_FILE;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_LOAD, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_LOAD, dwFlags, (DWORD)pU);
     free(s);
     free(pU);
     return res;
@@ -1406,10 +1394,10 @@
     char		*s;
     
     i=0;len=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	switch (uDevTyp) {
 	case MCI_DEVTYPE_OVERLAY:
-	    if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"at") && (i+4 < nrofkeywords)) {
 		dwFlags |= MCI_OVLY_RECT;
 		sscanf(keywords[i+1],"%hd",&(pU->ovlysaveParams.rc.left));
 		sscanf(keywords[i+2],"%hd",&(pU->ovlysaveParams.rc.top));
@@ -1425,14 +1413,14 @@
     }
     s=(char*)xmalloc(len);
     *s='\0';
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	strcat(s,keywords[i]);
 	i++;
-	if (i<nrofkeywords) strcat(s," ");
+	if (i < nrofkeywords) strcat(s," ");
     }
     pU->saveParams.lpfilename=s;
     dwFlags |= MCI_LOAD_FILE;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_SAVE, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_SAVE, dwFlags, (DWORD)pU);
     free(s);
     free(pU);
     return res;
@@ -1449,12 +1437,12 @@
     for (i = 0; i < nrofkeywords; i++) {
 	switch (uDevTyp) {
 	case MCI_DEVTYPE_WAVEFORM_AUDIO:
-	    FLAG1("input",MCI_WAVE_INPUT);
-	    FLAG1("output",MCI_WAVE_OUTPUT);
+	    FLAG1("input", MCI_WAVE_INPUT);
+	    FLAG1("output", MCI_WAVE_OUTPUT);
 	    break;
 	}
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_CUE, dwFlags, (DWORD)cueParams);
+    res = mciSendCommand32A(wDevID, MCI_CUE, dwFlags, (DWORD)cueParams);
     free(cueParams);
     return res;
 }
@@ -1494,8 +1482,8 @@
 	break;
     }
     i=0;
-    while (i<nrofkeywords) {
-	if (!strcmp(keywords[i],"to") && (i+1<nrofkeywords)) {
+    while (i < nrofkeywords) {
+	if (!strcmp(keywords[i],"to") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_TO;
 	    a[0]=a[1]=a[2]=a[3]=0;
 	    j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
@@ -1504,25 +1492,25 @@
 	     * mmsystem.h, right).
 	     */
 	    deleteParams->dwTo=0;
-	    for (k=0;k<j;k++)
+	    for (k=0;k < j;k++)
 		deleteParams->dwTo+=a[k]<<(8*(nrargs-k));
 	    i+=2;
 	    continue;
 	}
-	if (!strcmp(keywords[i],"from") && (i+1<nrofkeywords)) {
+	if (!strcmp(keywords[i],"from") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_FROM;
 	    a[0]=a[1]=a[2]=a[3]=0;
 	    j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
 	    /* dito. */
 	    deleteParams->dwFrom=0;
-	    for (k=0;k<j;k++)
+	    for (k=0;k < j;k++)
 		deleteParams->dwFrom+=a[k]<<(8*(nrargs-k));
 	    i+=2;
 	    continue;
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_DELETE, dwFlags, (DWORD)deleteParams);
+    res = mciSendCommand32A(wDevID, MCI_DELETE, dwFlags, (DWORD)deleteParams);
     free(deleteParams);
     return res;
 }
@@ -1538,20 +1526,20 @@
     if (uDevTyp != MCI_DEVTYPE_VIDEODISC)
 	return MCIERR_UNSUPPORTED_FUNCTION;
     i=0;len=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	len+=strlen(keywords[i])+1;
 	i++;
     }
     s=(char*)malloc(len);
     *s='\0';
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	strcat(s,keywords[i]);
 	i++;
-	if (i<nrofkeywords) strcat(s," ");
+	if (i < nrofkeywords) strcat(s," ");
     }
     escapeParams->lpstrCommand = s;
     dwFlags |= MCI_VD_ESCAPE_STRING;
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_ESCAPE, dwFlags, (DWORD)escapeParams);
+    res = mciSendCommand32A(wDevID, MCI_ESCAPE, dwFlags, (DWORD)escapeParams);
     free(s);
     free(escapeParams);
     return res;
@@ -1568,8 +1556,8 @@
     
     if (uDevTyp != MCI_DEVTYPE_OVERLAY)
 	return MCIERR_UNSUPPORTED_FUNCTION;
-    i=0;while (i<nrofkeywords) {
-	if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
+    i=0;while (i < nrofkeywords) {
+	if (!STRCMP(keywords[i],"at") && (i+4 < nrofkeywords)) {
 	    sscanf(keywords[i+1],"%hd",&(unfreezeParams->rc.left));
 	    sscanf(keywords[i+2],"%hd",&(unfreezeParams->rc.top));
 	    sscanf(keywords[i+3],"%hd",&(unfreezeParams->rc.right));
@@ -1580,7 +1568,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_UNFREEZE, dwFlags, (DWORD)unfreezeParams);
+    res = mciSendCommand32A(wDevID, MCI_UNFREEZE, dwFlags, (DWORD)unfreezeParams);
     free(unfreezeParams);
     return res;
 }
@@ -1595,8 +1583,8 @@
     
     if (uDevTyp != MCI_DEVTYPE_OVERLAY)
 	return MCIERR_UNSUPPORTED_FUNCTION;
-    i=0;while (i<nrofkeywords) {
-	if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
+    i=0;while (i < nrofkeywords) {
+	if (!STRCMP(keywords[i],"at") && (i+4 < nrofkeywords)) {
 	    sscanf(keywords[i+1],"%hd",&(freezeParams->rc.left));
 	    sscanf(keywords[i+2],"%hd",&(freezeParams->rc.top));
 	    sscanf(keywords[i+3],"%hd",&(freezeParams->rc.right));
@@ -1607,7 +1595,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_FREEZE, dwFlags, (DWORD)freezeParams);
+    res = mciSendCommand32A(wDevID, MCI_FREEZE, dwFlags, (DWORD)freezeParams);
     free(freezeParams);
     return res;
 }
@@ -1634,12 +1622,12 @@
     };
     union U *pU = xmalloc(sizeof(union U));
     int	i,res;
-    i=0;while (i<nrofkeywords) {
+    i=0;while (i < nrofkeywords) {
 	switch (uDevTyp) {
 	case MCI_DEVTYPE_ANIMATION:
 	    FLAG1("source",MCI_ANIM_PUT_SOURCE);
 	    FLAG1("destination",MCI_ANIM_PUT_DESTINATION);
-	    if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"at") && (i+4 < nrofkeywords)) {
 		sscanf(keywords[i+1],"%hd",&(pU->animputParams.rc.left));
 		sscanf(keywords[i+2],"%hd",&(pU->animputParams.rc.top));
 		sscanf(keywords[i+3],"%hd",&(pU->animputParams.rc.right));
@@ -1654,7 +1642,7 @@
 	    FLAG1("destination",MCI_OVLY_PUT_DESTINATION);
 	    FLAG1("video",MCI_OVLY_PUT_VIDEO);
 	    FLAG1("frame",MCI_OVLY_PUT_FRAME);
-	    if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"at") && (i+4 < nrofkeywords)) {
 		sscanf(keywords[i+1],"%hd",&(pU->ovlyputParams.rc.left));
 		sscanf(keywords[i+2],"%hd",&(pU->ovlyputParams.rc.top));
 		sscanf(keywords[i+3],"%hd",&(pU->ovlyputParams.rc.right));
@@ -1667,7 +1655,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_PUT, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_PUT, dwFlags, (DWORD)pU);
     free(pU);
     return res;
 }
@@ -1686,12 +1674,12 @@
     if (uDevTyp != MCI_DEVTYPE_ANIMATION)
 	return MCIERR_UNSUPPORTED_FUNCTION;
     i=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	FLAG1("background",MCI_ANIM_REALIZE_BKGD);
 	FLAG1("normal",MCI_ANIM_REALIZE_NORM);
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_REALIZE, dwFlags, (DWORD)realizeParams);
+    res = mciSendCommand32A(wDevID, MCI_REALIZE, dwFlags, (DWORD)realizeParams);
     free(realizeParams);
     return res;
 }
@@ -1709,12 +1697,12 @@
     if (uDevTyp != MCI_DEVTYPE_VIDEODISC)
 	return MCIERR_UNSUPPORTED_FUNCTION;
     i=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	FLAG1("up",MCI_VD_SPIN_UP);
 	FLAG1("down",MCI_VD_SPIN_UP);
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_SPIN, dwFlags, (DWORD)spinParams);
+    res = mciSendCommand32A(wDevID, MCI_SPIN, dwFlags, (DWORD)spinParams);
     free(spinParams);
     return res;
 }
@@ -1733,11 +1721,11 @@
     int	i,res;
     
     i=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	switch (uDevTyp) {
 	case MCI_DEVTYPE_ANIMATION:
 	    FLAG1("reverse",MCI_ANIM_STEP_REVERSE);
-	    if (!STRCMP(keywords[i],"by") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"by") && (i+1 < nrofkeywords)) {
 		sscanf(keywords[i+1],"%ld",&(pU->animstepParams.dwFrames));
 		dwFlags |= MCI_ANIM_STEP_FRAMES;
 		i+=2;
@@ -1746,7 +1734,7 @@
 	    break;
 	case MCI_DEVTYPE_VIDEODISC:
 	    FLAG1("reverse",MCI_VD_STEP_REVERSE);
-	    if (!STRCMP(keywords[i],"by") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"by") && (i+1 < nrofkeywords)) {
 		sscanf(keywords[i+1],"%ld",&(pU->vdstepParams.dwFrames));
 		dwFlags |= MCI_VD_STEP_FRAMES;
 		i+=2;
@@ -1756,7 +1744,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_STEP, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_STEP, dwFlags, (DWORD)pU);
     free(pU);
     return res;
 }
@@ -1773,7 +1761,7 @@
     
     i=0;
     while (i<nrofkeywords) {
-	if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
+	if (!STRCMP(keywords[i],"at") && (i+4 < nrofkeywords)) {
 	    sscanf(keywords[i+1],"%hd",&(updateParams->rc.left));
 	    sscanf(keywords[i+2],"%hd",&(updateParams->rc.top));
 	    sscanf(keywords[i+3],"%hd",&(updateParams->rc.right));
@@ -1782,7 +1770,7 @@
 	    i+=5;
 	    continue;
 	}
-	if (!STRCMP(keywords[i],"hdc") && (i+1<nrofkeywords)) {
+	if (!STRCMP(keywords[i],"hdc") && (i+1 < nrofkeywords)) {
 	    dwFlags |= MCI_ANIM_UPDATE_HDC;
 	    sscanf(keywords[i+1],"%hd",&(updateParams->hDC));
 	    i+=2;
@@ -1790,7 +1778,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_UPDATE, dwFlags, (DWORD)updateParams);
+    res = mciSendCommand32A(wDevID, MCI_UPDATE, dwFlags, (DWORD)updateParams);
     free(updateParams);
     return res;
 }
@@ -1814,7 +1802,7 @@
     int	i,res;
     
     i=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	switch (uDevTyp) {
 	case MCI_DEVTYPE_ANIMATION:
 	    FLAG1("source",MCI_ANIM_WHERE_SOURCE);
@@ -1829,7 +1817,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_WHERE, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_WHERE, dwFlags, (DWORD)pU);
     if (res==0) {
 	char	buf[100];
 	switch (uDevTyp) {
@@ -1839,7 +1827,7 @@
 		    pU->animwhereParams.rc.top,
 		    pU->animwhereParams.rc.right,
 		    pU->animwhereParams.rc.bottom
-		    );
+		   );
 	    break;
 	case MCI_DEVTYPE_OVERLAY:
 	    sprintf(buf,"%d %d %d %d",
@@ -1847,7 +1835,7 @@
 		    pU->ovlywhereParams.rc.top,
 		    pU->ovlywhereParams.rc.right,
 		    pU->ovlywhereParams.rc.bottom
-		    );
+		   );
 	    break;
 	default:strcpy(buf,"0 0 0 0");break;
 	}
@@ -1869,10 +1857,10 @@
     
     s=NULL;
     i=0;
-    while (i<nrofkeywords) {
+    while (i < nrofkeywords) {
 	switch (uDevTyp) {
 	case MCI_DEVTYPE_ANIMATION:
-	    if (!STRCMP(keywords[i],"handle") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"handle") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_ANIM_WINDOW_HWND;
 		if (!STRCMP(keywords[i+1],"default")) 
 		    pU->animwindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT;
@@ -1881,7 +1869,7 @@
 		i+=2;
 		continue;
 	    }
-	    if (!STRCMP(keywords[i],"state") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"state") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_ANIM_WINDOW_STATE;
 		if (!STRCMP(keywords[i+1],"hide"))
 		    pU->animwindowParams.nCmdShow = SW_HIDE;
@@ -1897,7 +1885,7 @@
 		    pU->animwindowParams.nCmdShow = SW_NORMAL;
 		if (!STRCMP(keywords[i+1],"show"))
 		    pU->animwindowParams.nCmdShow = SW_SHOW;
-		if (!STRCMP(keywords[i+1],"no") && (i+2<nrofkeywords)) {
+		if (!STRCMP(keywords[i+1],"no") && (i+2 < nrofkeywords)) {
 		    if (!STRCMP(keywords[i+2],"active"))
 			pU->animwindowParams.nCmdShow = SW_SHOWNOACTIVATE;
 		    if (!STRCMP(keywords[i+2],"action"))
@@ -1919,7 +1907,7 @@
 		dwFlags |= MCI_ANIM_WINDOW_TEXT;
 		len	= strlen(keywords[i+1])+1;
 		j	= i+2;
-		while (j<nrofkeywords) {
+		while (j < nrofkeywords) {
 		    len += strlen(keywords[j])+1;
 		    if (strchr(keywords[j],'"'))
 			break;
@@ -1928,7 +1916,7 @@
 		s=(char*)xmalloc(len);
 		strcpy(s,keywords[i+1]+1);
 		k=j;j=i+2;
-		while (j<=k) {
+		while (j <= k) {
 		    strcat(s," ");
 		    strcat(s,keywords[j]);
 		}
@@ -1941,7 +1929,7 @@
 	    FLAG1("stretch",MCI_ANIM_WINDOW_ENABLE_STRETCH);
 	    break;
 	case MCI_DEVTYPE_OVERLAY:
-	    if (!STRCMP(keywords[i],"handle") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"handle") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_OVLY_WINDOW_HWND;
 		if (!STRCMP(keywords[i+1],"default")) 
 		    pU->ovlywindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT;
@@ -1950,7 +1938,7 @@
 		i+=2;
 		continue;
 	    }
-	    if (!STRCMP(keywords[i],"state") && (i+1<nrofkeywords)) {
+	    if (!STRCMP(keywords[i],"state") && (i+1 < nrofkeywords)) {
 		dwFlags |= MCI_OVLY_WINDOW_STATE;
 		if (!STRCMP(keywords[i+1],"hide"))
 		    pU->ovlywindowParams.nCmdShow = SW_HIDE;
@@ -1966,7 +1954,7 @@
 		    pU->ovlywindowParams.nCmdShow = SW_NORMAL;
 		if (!STRCMP(keywords[i+1],"show"))
 		    pU->ovlywindowParams.nCmdShow = SW_SHOW;
-		if (!STRCMP(keywords[i+1],"no") && (i+2<nrofkeywords)) {
+		if (!STRCMP(keywords[i+1],"no") && (i+2 < nrofkeywords)) {
 		    if (!STRCMP(keywords[i+2],"active"))
 			pU->ovlywindowParams.nCmdShow = SW_SHOWNOACTIVATE;
 		    if (!STRCMP(keywords[i+2],"action"))
@@ -1988,7 +1976,7 @@
 		dwFlags |= MCI_OVLY_WINDOW_TEXT;
 		len	= strlen(keywords[i+1])+1;
 		j	= i+2;
-		while (j<nrofkeywords) {
+		while (j < nrofkeywords) {
 		    len += strlen(keywords[j])+1;
 		    if (strchr(keywords[j],'"'))
 			break;
@@ -2012,7 +2000,7 @@
 	}
 	i++;
     }
-    res = MCI_SendCommand32(MCI_GetDrv(wDevID)->modp.wDeviceID, MCI_WINDOW, dwFlags, (DWORD)pU);
+    res = mciSendCommand32A(wDevID, MCI_WINDOW, dwFlags, (DWORD)pU);
     if (s) free(s);
     free(pU);
     return res;
@@ -2094,7 +2082,7 @@
 	keywords=(char**)xmalloc(sizeof(char*)*(i+2));
 	nrofkeywords=i;
 	s=args;i=0;
-	while (s && i<nrofkeywords) {
+	while (s && i < nrofkeywords) {
 	    keywords[i++]=s;
 	    s=strchr(s,' ');
 	    if (s) *s++='\0';
@@ -2105,9 +2093,9 @@
 	keywords=(char**)xmalloc(sizeof(char*));
     }
     dwFlags = 0; /* default flags */
-    for (i=0;i<nrofkeywords;) {
+    for (i=0;i < nrofkeywords;) {
 	/* take care, there is also a "device type" capability */
-	if ((!STRCMP(keywords[i],"type")) && (i<nrofkeywords-1)) {
+	if ((!STRCMP(keywords[i],"type")) && (i < nrofkeywords-1)) {
 	    filename = dev;
 	    dev = keywords[i+1];
 	    memcpy(keywords+i,keywords+(i+2),(nrofkeywords-i-2)*sizeof(char *));
@@ -2128,7 +2116,8 @@
 	}
 	i++;
     }
-    
+
+    /* FIXME: this code should be moved to mmsystem.c */
     /* determine wDevID and uDevTyp for all commands except "open" */
     if (STRCMP(cmd,"open")!=0) {
 	wDevID = MCI_FirstDevID();
@@ -2149,7 +2138,8 @@
 	}
 	uDevTyp=MCI_GetDrv(wDevID)->modp.wType;
     }
-    
+    /* end of FIXME */
+
     for (i=0;MCISTR_cmdtable[i].cmd!=NULL;i++) {
 	if (!STRCMP(MCISTR_cmdtable[i].cmd,cmd)) {
 	    res=MCISTR_cmdtable[i].fun(
diff --git a/multimedia/mmio.c b/multimedia/mmio.c
index 35a3a70..2c37428 100644
--- a/multimedia/mmio.c
+++ b/multimedia/mmio.c
@@ -46,7 +46,7 @@
 			/* if filename NULL, assume open file handle in adwInfo[0] */
 			if (!szFileName) {
 				if (lParam2) lpmmioinfo->adwInfo[0] =
-					HFILE16_TO_HFILE32(lpmmioinfo->adwInfo[0]);
+					FILE_GetHandle32(lpmmioinfo->adwInfo[0]);
 				return 0;
 			}
 
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 9c276410..335b449 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -527,6 +527,16 @@
     return res;
 }
 
+/******************************************************************************
+ * CopyImage16 [USER.390]  Creates new image and copies attributes to it
+ *
+ */
+HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
+                             INT16 desiredy, UINT16 flags )
+{
+    return (HICON16)CopyImage32((HANDLE32)hnd, (UINT32)type, (INT32)desiredx,
+                                (INT32)desiredy, (UINT32)flags);
+}
 
 /******************************************************************************
  * CopyImage32 [USER32.61]  Creates new image and copies attributes to it
diff --git a/objects/dc.c b/objects/dc.c
index 981d5d3..53d64ba 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -1269,3 +1269,25 @@
     return DCB_DISABLE;   /* bounding rectangle always empty */
 }
 
+/***********************************************************************
+ *           Death    (GDI.121)
+ *
+ * Disables GDI, switches back to text mode.
+ * We don't have to do anything here,
+ * just let console support handle everything
+ */
+void WINAPI Death(HDC16 hDC)
+{
+    MSG("Death(%04x) called. Application enters text mode...\n", hDC);
+}
+
+/***********************************************************************
+ *           Resurrection    (GDI.122)
+ *
+ * Restores GDI functionality
+ */
+void WINAPI Resurrection(HDC16 hDC,
+                           WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6)
+{
+    MSG("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC, w1, w2, w3, w4, w5, w6);
+}
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index fd22bdf..dbcd5e4 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -996,7 +996,7 @@
  *
  *
  */
-BOOL32 WINAPI GetColorAdjustment32(HDC32 hdc, LPCOLORADJUSTMENT lpca)
+BOOL32 WINAPI GetColorAdjustment(HDC32 hdc, LPCOLORADJUSTMENT lpca)
 {
         FIXME(gdi, "GetColorAdjustment, stub\n");
         return 0;
@@ -1029,7 +1029,7 @@
  *
  *
  */
-BOOL32 WINAPI GdiComment32(HDC32 hdc, UINT32 cbSize, const BYTE *lpData)
+BOOL32 WINAPI GdiComment(HDC32 hdc, UINT32 cbSize, const BYTE *lpData)
 {
         FIXME(gdi, "GdiComment, stub\n");
         return 0;
diff --git a/objects/metafile.c b/objects/metafile.c
index bbd95c5..c608879 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -526,133 +526,133 @@
       break;
 
     case META_DELETEOBJECT:
-      DeleteObject32(*(ht->objectHandle + *(mr->rdParam)));
-      *(ht->objectHandle + *(mr->rdParam)) = 0;
+      DeleteObject32(*(ht->objectHandle + *(mr->rdParm)));
+      *(ht->objectHandle + *(mr->rdParm)) = 0;
       break;
 
     case META_SETBKCOLOR:
-	SetBkColor16(hdc, MAKELONG(*(mr->rdParam), *(mr->rdParam + 1)));
+	SetBkColor16(hdc, MAKELONG(*(mr->rdParm), *(mr->rdParm + 1)));
 	break;
 
     case META_SETBKMODE:
-	SetBkMode16(hdc, *(mr->rdParam));
+	SetBkMode16(hdc, *(mr->rdParm));
 	break;
 
     case META_SETMAPMODE:
-	SetMapMode16(hdc, *(mr->rdParam));
+	SetMapMode16(hdc, *(mr->rdParm));
 	break;
 
     case META_SETROP2:
-	SetROP216(hdc, *(mr->rdParam));
+	SetROP216(hdc, *(mr->rdParm));
 	break;
 
     case META_SETRELABS:
-	SetRelAbs16(hdc, *(mr->rdParam));
+	SetRelAbs16(hdc, *(mr->rdParm));
 	break;
 
     case META_SETPOLYFILLMODE:
-	SetPolyFillMode16(hdc, *(mr->rdParam));
+	SetPolyFillMode16(hdc, *(mr->rdParm));
 	break;
 
     case META_SETSTRETCHBLTMODE:
-	SetStretchBltMode16(hdc, *(mr->rdParam));
+	SetStretchBltMode16(hdc, *(mr->rdParm));
 	break;
 
     case META_SETTEXTCOLOR:
-	SetTextColor16(hdc, MAKELONG(*(mr->rdParam), *(mr->rdParam + 1)));
+	SetTextColor16(hdc, MAKELONG(*(mr->rdParm), *(mr->rdParm + 1)));
 	break;
 
     case META_SETWINDOWORG:
-	SetWindowOrg(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+	SetWindowOrg(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_SETWINDOWEXT:
-	SetWindowExt(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+	SetWindowExt(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_SETVIEWPORTORG:
-	SetViewportOrg(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+	SetViewportOrg(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_SETVIEWPORTEXT:
-	SetViewportExt(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+	SetViewportExt(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_OFFSETWINDOWORG:
-	OffsetWindowOrg(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+	OffsetWindowOrg(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_SCALEWINDOWEXT:
-	ScaleWindowExt(hdc, *(mr->rdParam + 3), *(mr->rdParam + 2),
-		       *(mr->rdParam + 1), *(mr->rdParam));
+	ScaleWindowExt(hdc, *(mr->rdParm + 3), *(mr->rdParm + 2),
+		       *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_OFFSETVIEWPORTORG:
-	OffsetViewportOrg(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+	OffsetViewportOrg(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_SCALEVIEWPORTEXT:
-	ScaleViewportExt(hdc, *(mr->rdParam + 3), *(mr->rdParam + 2),
-			 *(mr->rdParam + 1), *(mr->rdParam));
+	ScaleViewportExt(hdc, *(mr->rdParm + 3), *(mr->rdParm + 2),
+			 *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_LINETO:
-	LineTo32(hdc, (INT16)*(mr->rdParam + 1), (INT16)*(mr->rdParam));
+	LineTo32(hdc, (INT16)*(mr->rdParm + 1), (INT16)*(mr->rdParm));
 	break;
 
     case META_MOVETO:
-	MoveTo(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+	MoveTo(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_EXCLUDECLIPRECT:
-	ExcludeClipRect16( hdc, *(mr->rdParam + 3), *(mr->rdParam + 2),
-                           *(mr->rdParam + 1), *(mr->rdParam) );
+	ExcludeClipRect16( hdc, *(mr->rdParm + 3), *(mr->rdParm + 2),
+                           *(mr->rdParm + 1), *(mr->rdParm) );
 	break;
 
     case META_INTERSECTCLIPRECT:
-	IntersectClipRect16( hdc, *(mr->rdParam + 3), *(mr->rdParam + 2),
-                             *(mr->rdParam + 1), *(mr->rdParam) );
+	IntersectClipRect16( hdc, *(mr->rdParm + 3), *(mr->rdParm + 2),
+                             *(mr->rdParm + 1), *(mr->rdParm) );
 	break;
 
     case META_ARC:
-	Arc32(hdc, (INT16)*(mr->rdParam + 7), (INT16)*(mr->rdParam + 6),
-	      (INT16)*(mr->rdParam + 5), (INT16)*(mr->rdParam + 4),
-	      (INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-             (INT16)*(mr->rdParam + 1), (INT16)*(mr->rdParam));
+	Arc32(hdc, (INT16)*(mr->rdParm + 7), (INT16)*(mr->rdParm + 6),
+	      (INT16)*(mr->rdParm + 5), (INT16)*(mr->rdParm + 4),
+	      (INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+             (INT16)*(mr->rdParm + 1), (INT16)*(mr->rdParm));
 	break;
 
     case META_ELLIPSE:
-	Ellipse32(hdc, (INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-                  (INT16)*(mr->rdParam + 1), (INT16)*(mr->rdParam));
+	Ellipse32(hdc, (INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+                  (INT16)*(mr->rdParm + 1), (INT16)*(mr->rdParm));
 	break;
 
     case META_FLOODFILL:
-	FloodFill32(hdc, (INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-                    MAKELONG(*(mr->rdParam), *(mr->rdParam + 1)));
+	FloodFill32(hdc, (INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+                    MAKELONG(*(mr->rdParm), *(mr->rdParm + 1)));
 	break;
 
     case META_PIE:
-	Pie32(hdc, (INT16)*(mr->rdParam + 7), (INT16)*(mr->rdParam + 6),
-	      (INT16)*(mr->rdParam + 5), (INT16)*(mr->rdParam + 4),
-	      (INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-             (INT16)*(mr->rdParam + 1), (INT16)*(mr->rdParam));
+	Pie32(hdc, (INT16)*(mr->rdParm + 7), (INT16)*(mr->rdParm + 6),
+	      (INT16)*(mr->rdParm + 5), (INT16)*(mr->rdParm + 4),
+	      (INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+             (INT16)*(mr->rdParm + 1), (INT16)*(mr->rdParm));
 	break;
 
     case META_RECTANGLE:
-	Rectangle32(hdc, (INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-                    (INT16)*(mr->rdParam + 1), (INT16)*(mr->rdParam));
+	Rectangle32(hdc, (INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+                    (INT16)*(mr->rdParm + 1), (INT16)*(mr->rdParm));
 	break;
 
     case META_ROUNDRECT:
-	RoundRect32(hdc, (INT16)*(mr->rdParam + 5), (INT16)*(mr->rdParam + 4),
-                    (INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-                    (INT16)*(mr->rdParam + 1), (INT16)*(mr->rdParam));
+	RoundRect32(hdc, (INT16)*(mr->rdParm + 5), (INT16)*(mr->rdParm + 4),
+                    (INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+                    (INT16)*(mr->rdParm + 1), (INT16)*(mr->rdParm));
 	break;
 
     case META_PATBLT:
-	PatBlt16(hdc, *(mr->rdParam + 5), *(mr->rdParam + 4),
-                 *(mr->rdParam + 3), *(mr->rdParam + 2),
-                 MAKELONG(*(mr->rdParam), *(mr->rdParam + 1)));
+	PatBlt16(hdc, *(mr->rdParm + 5), *(mr->rdParm + 4),
+                 *(mr->rdParm + 3), *(mr->rdParm + 2),
+                 MAKELONG(*(mr->rdParm), *(mr->rdParm + 1)));
 	break;
 
     case META_SAVEDC:
@@ -660,60 +660,60 @@
 	break;
 
     case META_SETPIXEL:
-	SetPixel32(hdc, (INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-                   MAKELONG(*(mr->rdParam), *(mr->rdParam + 1)));
+	SetPixel32(hdc, (INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+                   MAKELONG(*(mr->rdParm), *(mr->rdParm + 1)));
 	break;
 
     case META_OFFSETCLIPRGN:
-	OffsetClipRgn16( hdc, *(mr->rdParam + 1), *(mr->rdParam) );
+	OffsetClipRgn16( hdc, *(mr->rdParm + 1), *(mr->rdParm) );
 	break;
 
     case META_TEXTOUT:
-	s1 = *(mr->rdParam);
-	TextOut16(hdc, *(mr->rdParam + ((s1 + 1) >> 1) + 2),
-                  *(mr->rdParam + ((s1 + 1) >> 1) + 1), 
-                  (char *)(mr->rdParam + 1), s1);
+	s1 = *(mr->rdParm);
+	TextOut16(hdc, *(mr->rdParm + ((s1 + 1) >> 1) + 2),
+                  *(mr->rdParm + ((s1 + 1) >> 1) + 1), 
+                  (char *)(mr->rdParm + 1), s1);
 	break;
 
     case META_POLYGON:
-	Polygon16(hdc, (LPPOINT16)(mr->rdParam + 1), *(mr->rdParam));
+	Polygon16(hdc, (LPPOINT16)(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_POLYPOLYGON:
-      PolyPolygon16(hdc, (LPPOINT16)(mr->rdParam + *(mr->rdParam) + 1),
-                    (LPINT16)(mr->rdParam + 1), *(mr->rdParam)); 
+      PolyPolygon16(hdc, (LPPOINT16)(mr->rdParm + *(mr->rdParm) + 1),
+                    (LPINT16)(mr->rdParm + 1), *(mr->rdParm)); 
       break;
 
     case META_POLYLINE:
-	Polyline16(hdc, (LPPOINT16)(mr->rdParam + 1), *(mr->rdParam));
+	Polyline16(hdc, (LPPOINT16)(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
     case META_RESTOREDC:
-	RestoreDC32(hdc, (INT16)*(mr->rdParam));
+	RestoreDC32(hdc, (INT16)*(mr->rdParm));
 	break;
 
     case META_SELECTOBJECT:
-	SelectObject32(hdc, *(ht->objectHandle + *(mr->rdParam)));
+	SelectObject32(hdc, *(ht->objectHandle + *(mr->rdParm)));
 	break;
 
     case META_CHORD:
-	Chord32(hdc, (INT16)*(mr->rdParam + 7), (INT16)*(mr->rdParam + 6),
-		(INT16)*(mr->rdParam+5), (INT16)*(mr->rdParam + 4),
-		(INT16)*(mr->rdParam + 3), (INT16)*(mr->rdParam + 2),
-               (INT16)*(mr->rdParam + 1), (INT16)*(mr->rdParam));
+	Chord32(hdc, (INT16)*(mr->rdParm + 7), (INT16)*(mr->rdParm + 6),
+		(INT16)*(mr->rdParm+5), (INT16)*(mr->rdParm + 4),
+		(INT16)*(mr->rdParm + 3), (INT16)*(mr->rdParm + 2),
+               (INT16)*(mr->rdParm + 1), (INT16)*(mr->rdParm));
 	break;
 
     case META_CREATEPATTERNBRUSH:
-	switch (*(mr->rdParam))
+	switch (*(mr->rdParm))
 	{
 	case BS_PATTERN:
-	    infohdr = (BITMAPINFOHEADER *)(mr->rdParam + 2);
+	    infohdr = (BITMAPINFOHEADER *)(mr->rdParm + 2);
 	    MF_AddHandle(ht, nHandles,
 			 CreatePatternBrush32(CreateBitmap32(infohdr->biWidth, 
 				      infohdr->biHeight, 
 				      infohdr->biPlanes, 
 				      infohdr->biBitCount,
-				      (LPSTR)(mr->rdParam + 
+				      (LPSTR)(mr->rdParm + 
 				      (sizeof(BITMAPINFOHEADER) / 2) + 4))));
 	    break;
 
@@ -721,45 +721,45 @@
 	    s1 = mr->rdSize * 2 - sizeof(METARECORD) - 2;
 	    hndl = GlobalAlloc16(GMEM_MOVEABLE, s1);
 	    ptr = GlobalLock16(hndl);
-	    memcpy(ptr, mr->rdParam + 2, s1);
+	    memcpy(ptr, mr->rdParm + 2, s1);
 	    GlobalUnlock16(hndl);
 	    MF_AddHandle(ht, nHandles,
-			 CreateDIBPatternBrush32(hndl, *(mr->rdParam + 1)));
+			 CreateDIBPatternBrush32(hndl, *(mr->rdParm + 1)));
 	    GlobalFree16(hndl);
 	}
 	break;
 	
     case META_CREATEPENINDIRECT:
 	MF_AddHandle(ht, nHandles, 
-		     CreatePenIndirect16((LOGPEN16 *)(&(mr->rdParam))));
+		     CreatePenIndirect16((LOGPEN16 *)(&(mr->rdParm))));
 	break;
 
     case META_CREATEFONTINDIRECT:
 	MF_AddHandle(ht, nHandles, 
-		     CreateFontIndirect16((LOGFONT16 *)(&(mr->rdParam))));
+		     CreateFontIndirect16((LOGFONT16 *)(&(mr->rdParm))));
 	break;
 
     case META_CREATEBRUSHINDIRECT:
 	MF_AddHandle(ht, nHandles, 
-		     CreateBrushIndirect16((LOGBRUSH16 *)(&(mr->rdParam))));
+		     CreateBrushIndirect16((LOGBRUSH16 *)(&(mr->rdParm))));
 	break;
 
     /* W. Magro: Some new metafile operations.  Not all debugged. */
     case META_CREATEPALETTE:
 	MF_AddHandle(ht, nHandles, 
-		     CreatePalette16((LPLOGPALETTE)mr->rdParam));
+		     CreatePalette16((LPLOGPALETTE)mr->rdParm));
 	break;
 
     case META_SETTEXTALIGN:
-       	SetTextAlign16(hdc, *(mr->rdParam));
+       	SetTextAlign16(hdc, *(mr->rdParm));
 	break;
 
     case META_SELECTPALETTE:
-	SelectPalette16(hdc, *(ht->objectHandle + *(mr->rdParam+1)),*(mr->rdParam));
+	SelectPalette16(hdc, *(ht->objectHandle + *(mr->rdParm+1)),*(mr->rdParm));
 	break;
 
     case META_SETMAPPERFLAGS:
-	SetMapperFlags16(hdc, *(mr->rdParam));
+	SetMapperFlags16(hdc, *(mr->rdParm));
 	break;
 
     case META_REALIZEPALETTE:
@@ -777,12 +777,12 @@
 	LPSTR sot; 
         DWORD len;
 
-        s1 = mr->rdParam[2];                              /* String length */
+        s1 = mr->rdParm[2];                              /* String length */
         len = sizeof(METARECORD) + (((s1 + 1) >> 1) * 2) + 2 * sizeof(short)
-	 + sizeof(UINT16) +  (mr->rdParam[3] ? sizeof(RECT16) : 0);  /* rec len without dx array */
+	 + sizeof(UINT16) +  (mr->rdParm[3] ? sizeof(RECT16) : 0);  /* rec len without dx array */
 
-	sot= (LPSTR)&mr->rdParam[4];			/* start_of_text */
-	if (mr->rdParam[3])
+	sot= (LPSTR)&mr->rdParm[4];			/* start_of_text */
+	if (mr->rdParm[3])
 	   sot+=sizeof(RECT16);				/* there is a rectangle, so add offset */
 	 
 	if (mr->rdSize == len / 2)
@@ -796,13 +796,13 @@
              sot,mr->rdSize);
            WARN(metafile,
 	     "Please report: PlayMetaFile/ExtTextOut len=%ld slen=%d rdSize=%ld opt=%04x\n",
-		   len,s1,mr->rdSize,mr->rdParam[3]);
+		   len,s1,mr->rdSize,mr->rdParm[3]);
            dxx = NULL; /* should't happen -- but if, we continue with NULL [for workaround] */
           }
-        ExtTextOut16( hdc, mr->rdParam[1],              /* X position */
-	                   mr->rdParam[0],              /* Y position */
-	                   mr->rdParam[3],              /* options */
-		     	   mr->rdParam[3] ? (LPRECT16) &mr->rdParam[4]:NULL,  /* rectangle */
+        ExtTextOut16( hdc, mr->rdParm[1],              /* X position */
+	                   mr->rdParm[0],              /* Y position */
+	                   mr->rdParm[3],              /* options */
+		     	   mr->rdParm[3] ? (LPRECT16) &mr->rdParm[4]:NULL,  /* rectangle */
 		           sot,				/* string */
                            s1, dxx);                    /* length, dx array */
         if (dxx)                      
@@ -813,40 +813,40 @@
     
     case META_STRETCHDIB:
       {
-       LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParam[11]);
-       LPSTR bits = (LPSTR)info + DIB_BitmapInfoSize( info, mr->rdParam[2] );
-       StretchDIBits16(hdc,mr->rdParam[10],mr->rdParam[9],mr->rdParam[8],
-                       mr->rdParam[7],mr->rdParam[6],mr->rdParam[5],
-                       mr->rdParam[4],mr->rdParam[3],bits,info,
-                       mr->rdParam[2],MAKELONG(mr->rdParam[0],mr->rdParam[1]));
+       LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParm[11]);
+       LPSTR bits = (LPSTR)info + DIB_BitmapInfoSize( info, mr->rdParm[2] );
+       StretchDIBits16(hdc,mr->rdParm[10],mr->rdParm[9],mr->rdParm[8],
+                       mr->rdParm[7],mr->rdParm[6],mr->rdParm[5],
+                       mr->rdParm[4],mr->rdParm[3],bits,info,
+                       mr->rdParm[2],MAKELONG(mr->rdParm[0],mr->rdParm[1]));
       }
       break;
 
     case META_DIBSTRETCHBLT:
       {
-       LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParam[10]); 
-       LPSTR bits = (LPSTR)info + DIB_BitmapInfoSize( info, mr->rdParam[2] );
-       StretchDIBits16(hdc,mr->rdParam[9],mr->rdParam[8],mr->rdParam[7],
-                       mr->rdParam[6],mr->rdParam[5],mr->rdParam[4],
-                       mr->rdParam[3],mr->rdParam[2],bits,info,
-                       DIB_RGB_COLORS,MAKELONG(mr->rdParam[0],mr->rdParam[1]));
+       LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParm[10]); 
+       LPSTR bits = (LPSTR)info + DIB_BitmapInfoSize( info, mr->rdParm[2] );
+       StretchDIBits16(hdc,mr->rdParm[9],mr->rdParm[8],mr->rdParm[7],
+                       mr->rdParm[6],mr->rdParm[5],mr->rdParm[4],
+                       mr->rdParm[3],mr->rdParm[2],bits,info,
+                       DIB_RGB_COLORS,MAKELONG(mr->rdParm[0],mr->rdParm[1]));
       }
       break;		  
 
     case META_STRETCHBLT:
       {
        HDC16 hdcSrc=CreateCompatibleDC16(hdc);
-       HBITMAP32 hbitmap=CreateBitmap32(mr->rdParam[10], /*Width */
-                                        mr->rdParam[11], /*Height*/
-                                        mr->rdParam[13], /*Planes*/
-                                        mr->rdParam[14], /*BitsPixel*/
-                                        (LPSTR)&mr->rdParam[15]);  /*bits*/
+       HBITMAP32 hbitmap=CreateBitmap32(mr->rdParm[10], /*Width */
+                                        mr->rdParm[11], /*Height*/
+                                        mr->rdParm[13], /*Planes*/
+                                        mr->rdParm[14], /*BitsPixel*/
+                                        (LPSTR)&mr->rdParm[15]);  /*bits*/
        SelectObject32(hdcSrc,hbitmap);
-       StretchBlt16(hdc,mr->rdParam[9],mr->rdParam[8],
-                    mr->rdParam[7],mr->rdParam[6],
-		    hdcSrc,mr->rdParam[5],mr->rdParam[4],
-		    mr->rdParam[3],mr->rdParam[2],
-		    MAKELONG(mr->rdParam[0],mr->rdParam[1]));
+       StretchBlt16(hdc,mr->rdParm[9],mr->rdParm[8],
+                    mr->rdParm[7],mr->rdParm[6],
+		    hdcSrc,mr->rdParm[5],mr->rdParm[4],
+		    mr->rdParm[3],mr->rdParm[2],
+		    MAKELONG(mr->rdParm[0],mr->rdParm[1]));
        DeleteDC32(hdcSrc);		    
       }
       break;
@@ -854,16 +854,16 @@
     case META_BITBLT:            /* <-- not yet debugged */
       {
        HDC16 hdcSrc=CreateCompatibleDC16(hdc);
-       HBITMAP32 hbitmap=CreateBitmap32(mr->rdParam[7]/*Width */,
-                                        mr->rdParam[8]/*Height*/,
-                                        mr->rdParam[10]/*Planes*/,
-                                        mr->rdParam[11]/*BitsPixel*/,
-                                        (LPSTR)&mr->rdParam[12]/*bits*/);
+       HBITMAP32 hbitmap=CreateBitmap32(mr->rdParm[7]/*Width */,
+                                        mr->rdParm[8]/*Height*/,
+                                        mr->rdParm[10]/*Planes*/,
+                                        mr->rdParm[11]/*BitsPixel*/,
+                                        (LPSTR)&mr->rdParm[12]/*bits*/);
        SelectObject32(hdcSrc,hbitmap);
-       BitBlt32(hdc,(INT16)mr->rdParam[6],(INT16)mr->rdParam[5],
-                (INT16)mr->rdParam[4],(INT16)mr->rdParam[3],
-                hdcSrc, (INT16)mr->rdParam[2],(INT16)mr->rdParam[1],
-                MAKELONG(0,mr->rdParam[0]));
+       BitBlt32(hdc,(INT16)mr->rdParm[6],(INT16)mr->rdParm[5],
+                (INT16)mr->rdParm[4],(INT16)mr->rdParm[3],
+                hdcSrc, (INT16)mr->rdParm[2],(INT16)mr->rdParm[1],
+                MAKELONG(0,mr->rdParm[0]));
        DeleteDC32(hdcSrc);		    
       }
       break;
@@ -879,51 +879,51 @@
       break;
 
      case META_FILLREGION:
-        FillRgn16(hdc, *(ht->objectHandle + *(mr->rdParam)),
-		       *(ht->objectHandle + *(mr->rdParam+1)));
+        FillRgn16(hdc, *(ht->objectHandle + *(mr->rdParm)),
+		       *(ht->objectHandle + *(mr->rdParm+1)));
         break;
 
      case META_INVERTREGION:
-        InvertRgn16(hdc, *(ht->objectHandle + *(mr->rdParam)));
+        InvertRgn16(hdc, *(ht->objectHandle + *(mr->rdParm)));
         break; 
 
      case META_PAINTREGION:
-        PaintRgn16(hdc, *(ht->objectHandle + *(mr->rdParam)));
+        PaintRgn16(hdc, *(ht->objectHandle + *(mr->rdParm)));
         break;
 
      case META_SELECTCLIPREGION:
-       	SelectClipRgn32(hdc, *(ht->objectHandle + *(mr->rdParam)));
+       	SelectClipRgn32(hdc, *(ht->objectHandle + *(mr->rdParm)));
 	break;
 
      case META_DIBCREATEPATTERNBRUSH:
-	/*  *(mr->rdParam) may be BS_PATTERN or BS_DIBPATTERN: but there's no difference */
-        TRACE(metafile,"%d\n",*(mr->rdParam));
+	/*  *(mr->rdParm) may be BS_PATTERN or BS_DIBPATTERN: but there's no difference */
+        TRACE(metafile,"%d\n",*(mr->rdParm));
 	s1 = mr->rdSize * 2 - sizeof(METARECORD) - 2;
 	hndl = GlobalAlloc16(GMEM_MOVEABLE, s1);
 	ptr = GlobalLock16(hndl);
-	memcpy(ptr, mr->rdParam + 2, s1);
+	memcpy(ptr, mr->rdParm + 2, s1);
 	GlobalUnlock16(hndl);
-	MF_AddHandle(ht, nHandles,CreateDIBPatternBrush16(hndl, *(mr->rdParam + 1)));
+	MF_AddHandle(ht, nHandles,CreateDIBPatternBrush16(hndl, *(mr->rdParm + 1)));
 	GlobalFree16(hndl);
 	break;
 
      case META_DIBBITBLT:
         {
-         LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParam[8]);
-         LPSTR bits = (LPSTR)info + DIB_BitmapInfoSize( info, mr->rdParam[0] );
-         StretchDIBits16(hdc,mr->rdParam[7],mr->rdParam[6],mr->rdParam[5],
-                       mr->rdParam[4],mr->rdParam[3],mr->rdParam[2],
-                       mr->rdParam[5],mr->rdParam[4],bits,info,
-                       DIB_RGB_COLORS,MAKELONG(mr->rdParam[0],mr->rdParam[1]));
+         LPBITMAPINFO info = (LPBITMAPINFO) &(mr->rdParm[8]);
+         LPSTR bits = (LPSTR)info + DIB_BitmapInfoSize( info, mr->rdParm[0] );
+         StretchDIBits16(hdc,mr->rdParm[7],mr->rdParm[6],mr->rdParm[5],
+                       mr->rdParm[4],mr->rdParm[3],mr->rdParm[2],
+                       mr->rdParm[5],mr->rdParm[4],bits,info,
+                       DIB_RGB_COLORS,MAKELONG(mr->rdParm[0],mr->rdParm[1]));
         }
         break;	
        
      case META_SETTEXTCHAREXTRA:
-	    SetTextCharacterExtra16(hdc, (INT16)*(mr->rdParam));
+	    SetTextCharacterExtra16(hdc, (INT16)*(mr->rdParm));
 	    break;
 
      case META_SETTEXTJUSTIFICATION:
-       	SetTextJustification32(hdc, *(mr->rdParam + 1), *(mr->rdParam));
+       	SetTextJustification32(hdc, *(mr->rdParm + 1), *(mr->rdParm));
 	break;
 
 #define META_UNIMP(x) case x: FIXME(metafile, "PlayMetaFileRecord:record type "#x" not implemented.\n");break;
@@ -1089,7 +1089,7 @@
 /*
  *	The layout of the record looks something like this:
  *	 
- *	 rdParam	meaning
+ *	 rdParm	meaning
  *	 0		Always 0?
  *	 1		Always 6?
  *	 2		Looks like a handle? - not constant
@@ -1104,7 +1104,7 @@
  *	 y-direction. Each band consists of pairs of on/off x-coords and is
  *	 written as
  *		m y0 y1 x1 x2 x3 ... xm m
- *	 into successive rdParam[]s.
+ *	 into successive rdParm[]s.
  *
  *	 This is probably just a dump of the internal RGNOBJ?
  *
@@ -1119,7 +1119,7 @@
     INT16 y0, y1;
     HRGN32 hrgn2 = CreateRectRgn32( 0, 0, 0, 0 );
 
-    for(band  = 0, start = &(mr->rdParam[11]); band < mr->rdParam[5];
+    for(band  = 0, start = &(mr->rdParm[11]); band < mr->rdParm[5];
  					        band++, start = end + 1) {
         if(*start / 2 != (*start + 1) / 2) {
  	    WARN(metafile, "Delimiter not even.\n");
@@ -1215,7 +1215,7 @@
     
     mr->rdSize = 4;
     mr->rdFunction = func;
-    *(mr->rdParam) = param1;
+    *(mr->rdParm) = param1;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1230,8 +1230,8 @@
     
     mr->rdSize = 5;
     mr->rdFunction = func;
-    *(mr->rdParam) = param2;
-    *(mr->rdParam + 1) = param1;
+    *(mr->rdParm) = param2;
+    *(mr->rdParm + 1) = param1;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1248,10 +1248,10 @@
     
     mr->rdSize = 7;
     mr->rdFunction = func;
-    *(mr->rdParam) = param4;
-    *(mr->rdParam + 1) = param3;
-    *(mr->rdParam + 2) = param2;
-    *(mr->rdParam + 3) = param1;
+    *(mr->rdParm) = param4;
+    *(mr->rdParm + 1) = param3;
+    *(mr->rdParm + 2) = param2;
+    *(mr->rdParm + 3) = param1;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1268,12 +1268,12 @@
     
     mr->rdSize = 9;
     mr->rdFunction = func;
-    *(mr->rdParam) = param6;
-    *(mr->rdParam + 1) = param5;
-    *(mr->rdParam + 2) = param4;
-    *(mr->rdParam + 3) = param3;
-    *(mr->rdParam + 4) = param2;
-    *(mr->rdParam + 5) = param1;
+    *(mr->rdParm) = param6;
+    *(mr->rdParm + 1) = param5;
+    *(mr->rdParm + 2) = param4;
+    *(mr->rdParm + 3) = param3;
+    *(mr->rdParm + 4) = param2;
+    *(mr->rdParm + 5) = param1;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1290,14 +1290,14 @@
     
     mr->rdSize = 11;
     mr->rdFunction = func;
-    *(mr->rdParam) = param8;
-    *(mr->rdParam + 1) = param7;
-    *(mr->rdParam + 2) = param6;
-    *(mr->rdParam + 3) = param5;
-    *(mr->rdParam + 4) = param4;
-    *(mr->rdParam + 5) = param3;
-    *(mr->rdParam + 6) = param2;
-    *(mr->rdParam + 7) = param1;
+    *(mr->rdParm) = param8;
+    *(mr->rdParm + 1) = param7;
+    *(mr->rdParm + 2) = param6;
+    *(mr->rdParm + 3) = param5;
+    *(mr->rdParm + 4) = param4;
+    *(mr->rdParm + 5) = param3;
+    *(mr->rdParm + 6) = param2;
+    *(mr->rdParm + 7) = param1;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1314,14 +1314,14 @@
 
     mr->rdSize = (sizeof(METARECORD) + sizeof(*logbrush) - 2) / 2;
     mr->rdFunction = META_CREATEBRUSHINDIRECT;
-    memcpy(&(mr->rdParam), logbrush, sizeof(*logbrush));
+    memcpy(&(mr->rdParm), logbrush, sizeof(*logbrush));
     if (!(MF_WriteRecord( dc, mr, mr->rdSize * 2))) return FALSE;
 
     mr->rdSize = sizeof(METARECORD) / 2;
     mr->rdFunction = META_SELECTOBJECT;
 
     if ((index = MF_AddHandleDC( dc )) == -1) return FALSE;
-    *(mr->rdParam) = index;
+    *(mr->rdParm) = index;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1357,15 +1357,15 @@
 	memset(mr, 0, len);
 	mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
 	mr->rdSize = len / 2;
-	*(mr->rdParam) = logbrush->lbStyle;
-	*(mr->rdParam + 1) = DIB_RGB_COLORS;
-	infohdr = (BITMAPINFOHEADER *)(mr->rdParam + 2);
+	*(mr->rdParm) = logbrush->lbStyle;
+	*(mr->rdParm + 1) = DIB_RGB_COLORS;
+	infohdr = (BITMAPINFOHEADER *)(mr->rdParm + 2);
 	infohdr->biSize = sizeof(BITMAPINFOHEADER);
 	infohdr->biWidth = bmp->bitmap.bmWidth;
 	infohdr->biHeight = bmp->bitmap.bmHeight;
 	infohdr->biPlanes = bmp->bitmap.bmPlanes;
 	infohdr->biBitCount = bmp->bitmap.bmBitsPixel;
-	memcpy(mr->rdParam + (sizeof(BITMAPINFOHEADER) / 2) + 4,
+	memcpy(mr->rdParm + (sizeof(BITMAPINFOHEADER) / 2) + 4,
 	       PTR_SEG_TO_LIN(bmp->bitmap.bmBits),
 	       bmp->bitmap.bmHeight * bmp->bitmap.bmWidthBytes);
 	GDI_HEAP_UNLOCK(logbrush->lbHatch);
@@ -1386,9 +1386,9 @@
 	memset(mr, 0, len);
 	mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
 	mr->rdSize = len / 2;
-	*(mr->rdParam) = logbrush->lbStyle;
-	*(mr->rdParam + 1) = LOWORD(logbrush->lbColor);
-	memcpy(mr->rdParam + 2, info, biSize + bmSize);
+	*(mr->rdParm) = logbrush->lbStyle;
+	*(mr->rdParm + 1) = LOWORD(logbrush->lbColor);
+	memcpy(mr->rdParm + 2, info, biSize + bmSize);
 	break;
     default:
         return FALSE;
@@ -1406,7 +1406,7 @@
     mr->rdFunction = META_SELECTOBJECT;
 
     if ((index = MF_AddHandleDC( dc )) == -1) return FALSE;
-    *(mr->rdParam) = index;
+    *(mr->rdParm) = index;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1423,14 +1423,14 @@
 
     mr->rdSize = (sizeof(METARECORD) + sizeof(*logpen) - 2) / 2;
     mr->rdFunction = META_CREATEPENINDIRECT;
-    memcpy(&(mr->rdParam), logpen, sizeof(*logpen));
+    memcpy(&(mr->rdParm), logpen, sizeof(*logpen));
     if (!(MF_WriteRecord( dc, mr, mr->rdSize * 2))) return FALSE;
 
     mr->rdSize = sizeof(METARECORD) / 2;
     mr->rdFunction = META_SELECTOBJECT;
 
     if ((index = MF_AddHandleDC( dc )) == -1) return FALSE;
-    *(mr->rdParam) = index;
+    *(mr->rdParm) = index;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1447,14 +1447,14 @@
 
     mr->rdSize = (sizeof(METARECORD) + sizeof(LOGFONT16) - 2) / 2;
     mr->rdFunction = META_CREATEFONTINDIRECT;
-    memcpy(&(mr->rdParam), logfont, sizeof(LOGFONT16));
+    memcpy(&(mr->rdParm), logfont, sizeof(LOGFONT16));
     if (!(MF_WriteRecord( dc, mr, mr->rdSize * 2))) return FALSE;
 
     mr->rdSize = sizeof(METARECORD) / 2;
     mr->rdFunction = META_SELECTOBJECT;
 
     if ((index = MF_AddHandleDC( dc )) == -1) return FALSE;
-    *(mr->rdParam) = index;
+    *(mr->rdParm) = index;
     return MF_WriteRecord( dc, mr, mr->rdSize * 2);
 }
 
@@ -1477,10 +1477,10 @@
 
     mr->rdSize = len / 2;
     mr->rdFunction = META_TEXTOUT;
-    *(mr->rdParam) = count;
-    memcpy(mr->rdParam + 1, str, count);
-    *(mr->rdParam + ((count + 1) >> 1) + 1) = y;
-    *(mr->rdParam + ((count + 1) >> 1) + 2) = x;
+    *(mr->rdParm) = count;
+    memcpy(mr->rdParm + 1, str, count);
+    *(mr->rdParm + ((count + 1) >> 1) + 1) = y;
+    *(mr->rdParm + ((count + 1) >> 1) + 2) = x;
     ret = MF_WriteRecord( dc, mr, mr->rdSize * 2);
     GlobalFree16(hmr);
     return ret;
@@ -1512,14 +1512,14 @@
 
     mr->rdSize = len / 2;
     mr->rdFunction = META_EXTTEXTOUT;
-    *(mr->rdParam) = y;
-    *(mr->rdParam + 1) = x;
-    *(mr->rdParam + 2) = count;
-    *(mr->rdParam + 3) = flags;
-    if (rect) memcpy(mr->rdParam + 4, rect, sizeof(RECT16));
-    memcpy(mr->rdParam + (rect ? 8 : 4), str, count);
+    *(mr->rdParm) = y;
+    *(mr->rdParm + 1) = x;
+    *(mr->rdParm + 2) = count;
+    *(mr->rdParm + 3) = flags;
+    if (rect) memcpy(mr->rdParm + 4, rect, sizeof(RECT16));
+    memcpy(mr->rdParm + (rect ? 8 : 4), str, count);
     if (lpDx)
-     memcpy(mr->rdParam + (rect ? 8 : 4) + ((count + 1) >> 1),lpDx,
+     memcpy(mr->rdParm + (rect ? 8 : 4) + ((count + 1) >> 1),lpDx,
       count*sizeof(INT16));
     ret = MF_WriteRecord( dc, mr, mr->rdSize * 2);
     GlobalFree16(hmr);
@@ -1544,8 +1544,8 @@
 
     mr->rdSize = len / 2;
     mr->rdFunction = func;
-    *(mr->rdParam) = count;
-    memcpy(mr->rdParam + 1, pt, count * 4);
+    *(mr->rdParm) = count;
+    memcpy(mr->rdParm + 1, pt, count * 4);
     ret = MF_WriteRecord( dc, mr, mr->rdSize * 2);
     GlobalFree16(hmr);
     return ret;
@@ -1570,23 +1570,23 @@
 	return FALSE;
     mr = (METARECORD *)GlobalLock16(hmr);
     mr->rdFunction = META_BITBLT;
-    *(mr->rdParam + 7) = BM.bmWidth;
-    *(mr->rdParam + 8) = BM.bmHeight;
-    *(mr->rdParam + 9) = BM.bmWidthBytes;
-    *(mr->rdParam +10) = BM.bmPlanes;
-    *(mr->rdParam +11) = BM.bmBitsPixel;
+    *(mr->rdParm + 7) = BM.bmWidth;
+    *(mr->rdParm + 8) = BM.bmHeight;
+    *(mr->rdParm + 9) = BM.bmWidthBytes;
+    *(mr->rdParm +10) = BM.bmPlanes;
+    *(mr->rdParm +11) = BM.bmBitsPixel;
     TRACE(metafile,"MF_StretchBlt->len = %ld  rop=%lx  \n",len,rop);
     if (GetBitmapBits32(dcSrc->w.hBitmap,BM.bmWidthBytes * BM.bmHeight,
-                        mr->rdParam +12))
+                        mr->rdParm +12))
     {
       mr->rdSize = len / sizeof(INT16);
-      *(mr->rdParam) = HIWORD(rop);
-      *(mr->rdParam + 1) = ySrc;
-      *(mr->rdParam + 2) = xSrc;
-      *(mr->rdParam + 3) = height;
-      *(mr->rdParam + 4) = width;
-      *(mr->rdParam + 5) = yDest;
-      *(mr->rdParam + 6) = xDest;
+      *(mr->rdParm) = HIWORD(rop);
+      *(mr->rdParm + 1) = ySrc;
+      *(mr->rdParm + 2) = xSrc;
+      *(mr->rdParm + 3) = height;
+      *(mr->rdParm + 4) = width;
+      *(mr->rdParm + 5) = yDest;
+      *(mr->rdParm + 6) = xDest;
       ret = MF_WriteRecord( dcDest, mr, mr->rdSize * 2);
     }  
     else
@@ -1627,7 +1627,7 @@
 	return FALSE;
     mr = (METARECORD *)GlobalLock16(hmr);
     mr->rdFunction = META_DIBSTRETCHBLT;
-    lpBMI=(LPBITMAPINFOHEADER)(mr->rdParam+10);
+    lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
     lpBMI->biSize      = sizeof(BITMAPINFOHEADER);
     lpBMI->biWidth     = BM.bmWidth;
     lpBMI->biHeight    = BM.bmHeight;
@@ -1652,27 +1652,27 @@
 	return FALSE;
     mr = (METARECORD *)GlobalLock16(hmr);
     mr->rdFunction = META_STRETCHBLT;
-    *(mr->rdParam +10) = BM.bmWidth;
-    *(mr->rdParam +11) = BM.bmHeight;
-    *(mr->rdParam +12) = BM.bmWidthBytes;
-    *(mr->rdParam +13) = BM.bmPlanes;
-    *(mr->rdParam +14) = BM.bmBitsPixel;
+    *(mr->rdParm +10) = BM.bmWidth;
+    *(mr->rdParm +11) = BM.bmHeight;
+    *(mr->rdParm +12) = BM.bmWidthBytes;
+    *(mr->rdParm +13) = BM.bmPlanes;
+    *(mr->rdParm +14) = BM.bmBitsPixel;
     TRACE(metafile,"MF_StretchBlt->len = %ld  rop=%lx  \n",len,rop);
     if (GetBitmapBits32( dcSrc->w.hBitmap, BM.bmWidthBytes * BM.bmHeight,
-                         mr->rdParam +15))
+                         mr->rdParm +15))
 #endif    
     {
       mr->rdSize = len / sizeof(INT16);
-      *(mr->rdParam) = LOWORD(rop);
-      *(mr->rdParam + 1) = HIWORD(rop);
-      *(mr->rdParam + 2) = heightSrc;
-      *(mr->rdParam + 3) = widthSrc;
-      *(mr->rdParam + 4) = ySrc;
-      *(mr->rdParam + 5) = xSrc;
-      *(mr->rdParam + 6) = heightDest;
-      *(mr->rdParam + 7) = widthDest;
-      *(mr->rdParam + 8) = yDest;
-      *(mr->rdParam + 9) = xDest;
+      *(mr->rdParm) = LOWORD(rop);
+      *(mr->rdParm + 1) = HIWORD(rop);
+      *(mr->rdParm + 2) = heightSrc;
+      *(mr->rdParm + 3) = widthSrc;
+      *(mr->rdParm + 4) = ySrc;
+      *(mr->rdParm + 5) = xSrc;
+      *(mr->rdParm + 6) = heightDest;
+      *(mr->rdParm + 7) = widthDest;
+      *(mr->rdParm + 8) = yDest;
+      *(mr->rdParm + 9) = xDest;
       ret = MF_WriteRecord( dcDest, mr, mr->rdSize * 2);
     }  
     else
@@ -1714,7 +1714,7 @@
 
     memset(mr, 0, len);
         
-    Param = mr->rdParam + 11;
+    Param = mr->rdParm + 11;
     StartBand = NULL;
 
     pEndRect = (RECT32 *)rgndata->Buffer + rgndata->rdh.nCount;
@@ -1744,17 +1744,17 @@
     }
     len = Param - (WORD *)mr;
     
-    mr->rdParam[0] = 0;
-    mr->rdParam[1] = 6;
-    mr->rdParam[2] = 0x1234;
-    mr->rdParam[3] = 0;
-    mr->rdParam[4] = len * 2;
-    mr->rdParam[5] = Bands;
-    mr->rdParam[6] = MaxBands;
-    mr->rdParam[7] = rgndata->rdh.rcBound.left;
-    mr->rdParam[8] = rgndata->rdh.rcBound.top;
-    mr->rdParam[9] = rgndata->rdh.rcBound.right;
-    mr->rdParam[10] = rgndata->rdh.rcBound.bottom;
+    mr->rdParm[0] = 0;
+    mr->rdParm[1] = 6;
+    mr->rdParm[2] = 0x1234;
+    mr->rdParm[3] = 0;
+    mr->rdParm[4] = len * 2;
+    mr->rdParm[5] = Bands;
+    mr->rdParm[6] = MaxBands;
+    mr->rdParm[7] = rgndata->rdh.rcBound.left;
+    mr->rdParm[8] = rgndata->rdh.rcBound.top;
+    mr->rdParm[9] = rgndata->rdh.rcBound.right;
+    mr->rdParm[10] = rgndata->rdh.rcBound.bottom;
     mr->rdFunction = META_CREATEREGION;
     mr->rdSize = len / 2;
     ret = MF_WriteRecord( dc, mr, mr->rdSize * 2 );	
diff --git a/relay32/advapi32.spec b/relay32/advapi32.spec
index f83c156..ec3f7f3 100644
--- a/relay32/advapi32.spec
+++ b/relay32/advapi32.spec
@@ -56,7 +56,7 @@
 0052 stub GetSecurityDescriptorControl
 0053 stub GetSecurityDescriptorDacl
 0054 stub GetSecurityDescriptorGroup
-0055 stub GetSecurityDescriptorLength
+0055 stdcall GetSecurityDescriptorLength(ptr) GetSecurityDescriptorLength
 0056 stub GetSecurityDescriptorOwner
 0057 stub GetSecurityDescriptorSacl
 0058 stub GetServiceDisplayNameA
diff --git a/relay32/gdi32.spec b/relay32/gdi32.spec
index b58f73e..e929737 100644
--- a/relay32/gdi32.spec
+++ b/relay32/gdi32.spec
@@ -7,17 +7,17 @@
   2 stdcall AddFontResourceA(str) AddFontResource32A
   3 stub AddFontResourceTracking
   4 stdcall AddFontResourceW(wstr) AddFontResource32W
-  5 stdcall AngleArc(long long long long long long) AngleArc32
+  5 stdcall AngleArc(long long long long long long) AngleArc
   6 stdcall AnimatePalette(long long long ptr) AnimatePalette32
   7 stdcall Arc(long long long long long long long long long) Arc32
-  8 stdcall ArcTo(long long long long long long long long long) ArcTo32
+  8 stdcall ArcTo(long long long long long long long long long) ArcTo
   9 stdcall BeginPath(long) BeginPath32
  10 stdcall BitBlt(long long long long long long long long long) BitBlt32
  11 stub CancelDC
  12 stub CheckColorsInGamut
  13 stdcall ChoosePixelFormat(long ptr) ChoosePixelFormat
  14 stdcall Chord(long long long long long long long long long) Chord32
- 15 stdcall CloseEnhMetaFile(long) CloseEnhMetaFile32
+ 15 stdcall CloseEnhMetaFile(long) CloseEnhMetaFile
  16 stdcall CloseFigure(long) CloseFigure32
  17 stdcall CloseMetaFile(long) CloseMetaFile32
  18 stub ColorMatchToTarget
@@ -76,7 +76,7 @@
  71 stdcall DescribePixelFormat(long long long ptr) DescribePixelFormat
  72 stub DeviceCapabilitiesExA
  73 stub DeviceCapabilitiesExW
- 74 stdcall DrawEscape(long long long ptr) DrawEscape32
+ 74 stdcall DrawEscape(long long long ptr) DrawEscape
  75 stdcall Ellipse(long long long long long) Ellipse32
  76 stdcall EndDoc(long) EndDoc32
  77 stdcall EndPage(long) EndPage32
@@ -97,7 +97,7 @@
  92 stdcall ExcludeClipRect(long long long long long) ExcludeClipRect32
  93 stdcall ExtCreatePen(long long ptr long ptr) ExtCreatePen32
  94 stdcall ExtCreateRegion(ptr long ptr) ExtCreateRegion
- 95 stdcall ExtEscape(long long long ptr long ptr) ExtEscape32
+ 95 stdcall ExtEscape(long long long ptr long ptr) ExtEscape
  96 stdcall ExtFloodFill(long long long long long) ExtFloodFill32
  97 stdcall ExtSelectClipRgn(long long long) ExtSelectClipRgn
  98 stdcall ExtTextOutA(long long long long ptr str long ptr) ExtTextOut32A
@@ -111,7 +111,7 @@
 106 stub FreeImageColorMatcher
 107 stub GdiAssociateObject
 108 stub GdiCleanCacheDC
-109 stdcall GdiComment(long long ptr) GdiComment32
+109 stdcall GdiComment(long long ptr) GdiComment
 110 stub GdiConvertAndCheckDC
 111 stub GdiConvertBitmap
 112 stub GdiConvertBrush
@@ -166,7 +166,7 @@
 161 stdcall GetCharacterPlacementW(long wstr long long ptr long) GetCharacterPlacement32W
 162 stdcall GetClipBox(long ptr) GetClipBox32
 163 stdcall GetClipRgn(long long) GetClipRgn32
-164 stdcall GetColorAdjustment(long ptr) GetColorAdjustment32
+164 stdcall GetColorAdjustment(long ptr) GetColorAdjustment
 165 stdcall GetColorSpace(long) GetColorSpace
 166 stdcall GetCurrentObject(long long) GetCurrentObject
 167 stdcall GetCurrentPositionEx(long ptr) GetCurrentPositionEx32
@@ -274,7 +274,7 @@
 269 stdcall PolyBezierTo(long ptr long) PolyBezierTo32
 270 stdcall PolyDraw(long ptr ptr long) PolyDraw
 271 stdcall PolyPolygon(long ptr ptr long) PolyPolygon32
-272 stdcall PolyPolyline(long ptr ptr long) PolyPolyline32
+272 stdcall PolyPolyline(long ptr ptr long) PolyPolyline
 273 stub PolyTextOutA
 274 stub PolyTextOutW
 275 stdcall Polygon(long ptr long) Polygon32
diff --git a/relay32/kernel32.spec b/relay32/kernel32.spec
index b2c1333..b82cb20 100644
--- a/relay32/kernel32.spec
+++ b/relay32/kernel32.spec
@@ -906,7 +906,7 @@
 887 stub SetConsoleIcon
 888 stub SetConsoleInputExeNameA
 889 stub SetConsoleInputExeNameW
-890 stub SetProcessAffinityMask
+890 stdcall SetProcessAffinityMask(long long) SetProcessAffinityMask
 891 stdcall SetProcessPriorityBoost(long long) SetProcessPriorityBoost
 892 stub SetThreadIdealProcessor
 893 stub SetThreadPriorityBoost
diff --git a/relay32/ntdll.spec b/relay32/ntdll.spec
index c7b0681..fa09454 100644
--- a/relay32/ntdll.spec
+++ b/relay32/ntdll.spec
@@ -866,7 +866,7 @@
 858 stub __eFYL2X
 859 stub __eFYL2XP1
 860 stub __eGetStatusWord
-861 stub _alloca_probe
+861 register _alloca_probe() NTDLL_alloca_probe
 862 register _chkstk() NTDLL_chkstk
 863 stub _fltused
 864 cdecl _ftol(double) CRTDLL__ftol
diff --git a/relay32/shell32.spec b/relay32/shell32.spec
index 6d1f01a..1091a3e 100644
--- a/relay32/shell32.spec
+++ b/relay32/shell32.spec
@@ -127,7 +127,7 @@
  119 stdcall IsLFNDrive(str) IsLFNDrive32A
  120 stub FileMenu_AbortInitMenu
  121 stdcall SHFlushClipboard () SHFlushClipboard
- 122 stub RunDLL_CallEntry16
+ 122 stdcall RunDLL_CallEntry16 (long long long long long) RunDLL_CallEntry16 #name wrong?
  123 stdcall SHFreeUnusedLibraries () SHFreeUnusedLibraries
  124 stub FileMenu_AppendFilesForPidl
  125 stub FileMenu_AddFilesForPidl
@@ -180,14 +180,14 @@
  172 stub SHCreateLinks
  173 stub SHValidateUNC
  174 stdcall SHCreateShellFolderViewEx (ptr ptr) SHCreateShellFolderViewEx32
- 175 stdcall SHGetSpecialFolderPath(long long long long) SHGetSpecialFolderPath
+ 175 stdcall SHGetSpecialFolderPath(long long long long) SHGetSpecialFolderPath32
  176 stdcall SHSetInstanceExplorer (long) SHSetInstanceExplorer
  177 stub DAD_SetDragImageFromListView
  178 stub SHObjectProperties
  179 stub SHGetNewLinkInfoA
  180 stub SHGetNewLinkInfoW
  181 stdcall RegisterShellHook(long long) RegisterShellHook32
- 182 stub ShellMessageBoxW
+ 182 cdecl ShellMessageBoxW(long long long str long long) ShellMessageBoxW
  183 cdecl ShellMessageBoxA(long long long str long long) ShellMessageBoxA
  184 stdcall ArrangeWindows(long long long long long) ArrangeWindows
  185 stub SHHandleDiskFull
@@ -375,5 +375,5 @@
 1217 stub FOOBAR1217   # no joke! This is the real name!!
 
 # later additions ... FIXME: incorrect ordinals
-1218 stdcall SHGetSpecialFolderPathA(long long long long) SHGetSpecialFolderPath
+1218 stdcall SHGetSpecialFolderPathA(long ptr long long) SHGetSpecialFolderPath32A
 1219 stub DoEnvironmentSubstW
diff --git a/scheduler/process.c b/scheduler/process.c
index ee1155d..b49c00a 100644
--- a/scheduler/process.c
+++ b/scheduler/process.c
@@ -721,6 +721,15 @@
 }
 
 /***********************************************************************
+ *		SetProcessAffinityMask	[KERNEL32.662]
+ */
+BOOL32 WINAPI SetProcessAffinityMask(HANDLE32 hProcess,DWORD affmask)
+{
+    FIXME(process,"(0x%08x,%ld), stub - harmless\n",hProcess,affmask);
+    return TRUE;
+}
+
+/***********************************************************************
  *		SetProcessWorkingSetSize	[KERNEL32.662]
  * Sets the min/max working set sizes for a specified process.
  *
diff --git a/scheduler/synchro.c b/scheduler/synchro.c
index c102c41..9f0dbce 100644
--- a/scheduler/synchro.c
+++ b/scheduler/synchro.c
@@ -186,3 +186,22 @@
 
     return retval;
 }
+
+/***********************************************************************
+ *           WIN16_WaitForMultipleObjectsEx   (KERNEL.495)
+ */
+DWORD WINAPI WIN16_WaitForMultipleObjectsEx( DWORD count, 
+                                             const HANDLE32 *handles,
+                                             BOOL32 wait_all, DWORD timeout,
+                                             BOOL32 alertable )
+{
+    DWORD retval;
+
+    SYSLEVEL_ReleaseWin16Lock();
+    retval = WaitForMultipleObjectsEx( count, handles, 
+                                       wait_all, timeout, alertable );
+    SYSLEVEL_RestoreWin16Lock();
+
+    return retval;
+}
+
diff --git a/win32/console.c b/win32/console.c
index f82afc4..e2bc622 100644
--- a/win32/console.c
+++ b/win32/console.c
@@ -506,48 +506,23 @@
 static int CONSOLE_openpty(CONSOLE *console, char *name, 
 			struct termios *term, struct winsize *winsize)
 {
-        int fdm, fds;
-        char *ptr1, *ptr2;
-        char pts_name[512];
+        int temp, slave;
         struct set_console_fd_request req;
 
-        strcpy (pts_name, "/dev/ptyXY");
+        temp = wine_openpty(&console->master, &slave, name, term,
+           winsize);
+        console->infd = console->outfd = slave;
 
-        for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
-                pts_name[8] = *ptr1;
-                for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
-                        pts_name[9] = *ptr2;
+        req.handle = console->hread;
+        CLIENT_SendRequest(REQ_SET_CONSOLE_FD, dup(slave), 1,
+           &req, sizeof(req));
+        CLIENT_WaitReply( NULL, NULL, 0);
+        req.handle = console->hwrite;
+        CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(slave), 1,
+           &req, sizeof(req));
+        CLIENT_WaitReply( NULL, NULL, 0);
 
-                        if ((fdm = open(pts_name, O_RDWR)) < 0) {
-                                if (errno == ENOENT)
-                                        return -1;
-                                else
-                                        continue;
-                        }
-                        pts_name[5] = 't';
-                        if ((fds = open(pts_name, O_RDWR)) < 0) {
-                                pts_name[5] = 'p';
-                                continue;
-                        }
-                        console->master = fdm;
-                        console->infd = console->outfd = fds;
-                        req.handle = console->hread;
-			CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(fds), 1, &req, sizeof(req) );
-                        CLIENT_WaitReply( NULL, NULL, 0 );
-                        req.handle = console->hwrite;
-			CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(fds), 1, &req, sizeof(req) );
-                        CLIENT_WaitReply( NULL, NULL, 0 );
-
-			if (term != NULL)
-				tcsetattr(console->infd, TCSANOW, term);
-			if (winsize != NULL)
-				ioctl(console->outfd, TIOCSWINSZ, winsize);
-			if (name != NULL)
-				strcpy(name, pts_name);
-                        return fds;
-                }
-        }
-	return -1;
+        return temp;  /* The same result as the openpty call */
 }
 
 /*************************************************************************
diff --git a/win32/kernel32.c b/win32/kernel32.c
index 2417b96..d4d7251 100644
--- a/win32/kernel32.c
+++ b/win32/kernel32.c
@@ -969,7 +969,7 @@
 	HFILE16 hf16	/* [in] open file, if filename is NULL */
 ) {
 	IMAGE_DOS_HEADER	mzh;
-        HFILE32                 hf=HFILE16_TO_HFILE32(hf16);
+        HFILE32                 hf=FILE_GetHandle32(hf16);
 	OFSTRUCT		ofs;
 	DWORD			xmagic;
 
diff --git a/win32/newfns.c b/win32/newfns.c
index fc57c2e..47e41af 100644
--- a/win32/newfns.c
+++ b/win32/newfns.c
@@ -300,7 +300,7 @@
                                  DWORD dwMilliseconds )
 {
     FIXME(win32, "(%p,%ld): stub\n", lpDebugEvent, dwMilliseconds);
-    return TRUE;
+    return FALSE;
 }
 
 
diff --git a/windows/dinput.c b/windows/dinput.c
index 7e504ff..dd3f4d1 100644
--- a/windows/dinput.c
+++ b/windows/dinput.c
@@ -443,8 +443,10 @@
 	DWORD dwFlags)
 {
 	FIXME(dinput, "stub!\n");
+#if 0
 	if (lpCallback)
 		lpCallback(NULL, lpvRef);
+#endif
 	return DI_OK;
 }
 	
diff --git a/windows/winproc.c b/windows/winproc.c
index 59a2675..925b173 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -1777,6 +1777,10 @@
         return 0;
 
     case WM_ACTIVATEAPP:
+	if (*plparam) {
+	*plparam = (LPARAM) THREAD_ID_TO_THDB((DWORD) *plparam)->teb.htask16;
+	}
+	return 1;
     case WM_ASKCBFORMATNAME:
     case WM_DEVMODECHANGE:
     case WM_PAINTCLIPBOARD: