Release 980104

Sat Jan  3 17:15:56 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [debugger/db_disasm.c]
	Added cpuid and cmpxchg instructions.

	* [if1632/builtin.c] [relay32/builtin32.c]
	Fixed broken -dll option with Win32 DLLs.

	* [include/heap.h]
	Added SYSTEM_LOCK/SYSTEM_UNLOCK macros.

	* [configure.in] [misc/lstr.c]
	Added check for wctype.h.
	Commented out --enable-ipc option (IPC code has been broken for a
	long time anyway).

	* [scheduler/critsection.c] [scheduler/event.c]
	  [scheduler/mutex.c] [scheduler/semaphore.c]
	Implemented Win32 synchronization objects.

	* [scheduler/synchro.c]
	Implemented WaitForMultipleObjects and related functions.

	* [scheduler/thread.c]
	If possible, use clone() in CreateThread().

	* [scheduler/thread.c] [scheduler/process.c]
	Made thread and process waitable objects.
	Thread and process id values are now different from the pointers
	they represent.

	* [win32/k32obj.c]
	Moved to scheduler directory.
	Added function table for waiting operations on objects.

	* [files/file.c] [memory/virtual.c]
	Added new K32OBJ function table.

Sun Jan  1 16:48:23 1997  Andreas Mohr <100.30936@germany.net>

	* [files/file.c]
	Fixed my patch for GetTempFileName16() as needed.
	It was ...Name32A() that didn't work properly, not ...Name16().

	* [graphics/x11drv/brush.c]
	Fixed a BadMatch error.

	* [msdos/int21.c]
	Fixed INT21_FindNextFCB() to get correct volume labels e.g.
	in "file open" dialog.

	* [multimedia/joystick.c] [relay32/winmm.spec]
	Stub JoyGetPosEx().

	* [scheduler/process.c] [relay32/kernel32.spec]
	Implemented RegisterServiceProcess().

Wed Dec 31 11:14:43 1997  Lawson Whitney  <lawson_whitney@juno.com>

	* [if1632/kernel.spec] [if1632/relay.c]
	Define CallProcEx32w - Thanks to Marcus Meissner for his excellent
	CallProc32W.

	* [loader/module.c]
	Take a shot at defining FreeLibrary32W.

Sun Dec 28 12:44:04 1997  Kai Morich <kai.morich@rhein-neckar.netsurf.de>

	* [controls/menu.c]
	Menu modification from WM_INITMENUPOPUP message fixed.
	Menu items now can have different wID and hSubMenu (Win95 behavior).

	* [misc/cpu.c]
	Improved IsProcessorFeaturePresent.

Sun Dec 28 03:21:08 1997  Ove Kaaven <ovek@main.arcticnet.no>

	* [include/winsock.h] [misc/winsock.c]
	Fixed WS_SOL_SOCKET for setsockopt(), and made select() return
	empty fd_sets if timeout.

	* [objects/palette.c]
	AnimatePalette() bailed out if entire palette is animated. Fixed.

	* [objects/dib.c]
	Added some code to SetDIBitsToDevice() and its helpers to fix
	some offseting problems.

	* [objects/cursoricon.c]
	Made CreateCursor32() convert the instance handle properly. Made
	DestroyCursor() return correct success status.

Wed Dec 24 17:56:34 1997  Dimitrie O. Paun  <dimi@cs.toronto.edu>

	* [windows/syscolor.c]
	Added definition of GetSysColorPen16/32. This function does not
	exist in the Win32 API but is a very close (and natural) relative
	to GetSysColorBrush function. Moreover, it is *very* much used 
	within Wine since there are a lot of places where we need to draw
	lines with the standard colors.

	* [controls/button.c] [controls/combo.c] [controls/icontitle.c]
	  [controls/menu.c] [controls/progress.c] [controls/scroll.c]
	  [controls/updown.c] [graphics/painting.c] [misc/tweak.c]
	  [windows/defwnd.c] [windows/graphics.c] [windows/nonclient.c]
	Replaced references to sysColorObjects with the appropriate
	call to GetSysColorBrush32/GetSysColorPen32. There is no need to
	expose the implementation of these functions, even within Wine.
	This makes the code easier to understand, debug, maintain.

	* [controls/uitools.c]
	Modified most of the functions in this file to use the now
	standard pens (i.e. GetSysColorPen32). These functions made
	*heavy* use of standard pens so I expect a lot less
	CreatePen/DeleteObject calls can do only good...:)
	Plus some minor modifications (*no* functional changes though).

	* [controls/updown.c]
	Used the new DrawFrameControl32 function to paint the control.
	I also deleted UDDOWN_DrawArrow since it was no longer required.

Tue Dec 23 00:03:33 1997  Steinar Hamre  <steinarh@stud.fim.ntnu.no>

	* [configure.in]
	Added check for -lw.

	* [include/wintypes.h] [tools/build.c]
	Changes to make the assembly understandable for even sun as.
	".ascii" -> ".string", "call %foo" -> "call *%foo",
	"pushw/popw %[cdes]s" written out to ".byte 0x66\npushl/popl %[cdes]s".

	* [memory/ldt.c]
	#ifdef added so <sys/seg.h> will not be included on Solaris.

Mon Dec 22 18:55:19 1997  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [configure.in]
	Added XF86DGA check.

	* [multimedia/dsound.c][relay32/dsound.spec][include/dsound.h]
	Started DirectSound. Only stubs for now.

	* [graphics/ddraw.c][include/ddraw.h][relay32/ddraw.spec]
	Started to implement DirectDraw. Mostly stubs, some
	testcases work. Requires the XF86DGA extension to XFree86.
	(check demo/blizdemo.exe from the Diablo CD-ROM).

	* [files/drive.c]
	Return correct "CDFS" fsname so Diablo is a bit happier.

Sun Dec 21 21:45:48 1997  Kevin Cozens <kcozens@interlog.com>

	* [misc/registry.c]
	Fixed bugs in the routines which read the Windows '95 registry
	files. Added extra information regarding the format of the Windows
	'95 registry files.
diff --git a/include/builtin32.h b/include/builtin32.h
index 56532a3..4d3dd3b 100644
--- a/include/builtin32.h
+++ b/include/builtin32.h
@@ -27,5 +27,7 @@
                                              unsigned int *typemask );
 extern void BUILTIN32_Unimplemented( const BUILTIN32_DESCRIPTOR *descr,
                                      int ordinal );
+extern void BUILTIN32_PrintDLLs(void);
+extern int BUILTIN32_EnableDLL( const char *name, int len, int enable );
 
 #endif /* __WINE_BUILTIN32_H */
diff --git a/include/config.h.in b/include/config.h.in
index 2d301c7..40d489b 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -18,6 +18,9 @@
 /* Define if symbols declared in assembly code need an underscore prefix */
 #undef NEED_UNDERSCORE_PREFIX
 
+/* Define if you have the clone function.  */
+#undef HAVE_CLONE
+
 /* Define if you have the memmove function.  */
 #undef HAVE_MEMMOVE
 
@@ -35,3 +38,15 @@
 
 /* Define if you have the waitpid function.  */
 #undef HAVE_WAITPID
+
+/* Define if you have the <wctype.h> header file.  */
+#undef HAVE_WCTYPE_H
+
+/* Define if you have the Xxf86dga library (-lXxf86dga).  */
+#undef HAVE_LIBXXF86DGA
+
+/* Define if you have the i386 library (-li386).  */
+#undef HAVE_LIBI386
+
+/* Define if you have the w library (-lw).  */
+#undef HAVE_LIBW
diff --git a/include/ddraw.h b/include/ddraw.h
new file mode 100644
index 0000000..3197b85
--- /dev/null
+++ b/include/ddraw.h
@@ -0,0 +1,898 @@
+#ifndef __WINE_DDRAW_H
+#define __WINE_DDRAW_H
+
+#include <X11/Xlib.h>
+
+
+DEFINE_GUID( CLSID_DirectDraw,		0xD7B70EE0,0x4340,0x11CF,0xB0,0x63,0x00,0x20,0xAF,0xC2,0xCD,0x35 );
+DEFINE_GUID( CLSID_DirectDrawClipper,	0x593817A0,0x7DB3,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xb9,0x33,0x56 );
+DEFINE_GUID( IID_IDirectDraw,		0x6C14DB80,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
+DEFINE_GUID( IID_IDirectDraw2,		0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
+DEFINE_GUID( IID_IDirectDrawSurface,	0x6C14DB81,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
+DEFINE_GUID( IID_IDirectDrawSurface2,	0x57805885,0x6eec,0x11cf,0x94,0x41,0xa8,0x23,0x03,0xc1,0x0e,0x27 );
+DEFINE_GUID( IID_IDirectDrawPalette,	0x6C14DB84,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
+DEFINE_GUID( IID_IDirectDrawClipper,	0x6C14DB85,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 );
+
+typedef struct IDirectDraw IDirectDraw,*LPDIRECTDRAW;
+typedef struct IDirectDraw2 IDirectDraw2,*LPDIRECTDRAW2;
+typedef struct IDirectDrawClipper IDirectDrawClipper,*LPDIRECTDRAWCLIPPER;
+typedef struct IDirectDrawPalette IDirectDrawPalette,*LPDIRECTDRAWPALETTE;
+typedef struct IDirectDrawSurface IDirectDrawSurface,*LPDIRECTDRAWSURFACE;
+typedef struct IDirectDrawSurface2 IDirectDrawSurface2,*LPDIRECTDRAWSURFACE2;
+
+#define _FACDD		0x876
+#define MAKE_DDHRESULT( code )  MAKE_HRESULT( 1, _FACDD, code )
+
+#define DDERR_ALREADYINITIALIZED		MAKE_DDHRESULT( 5 )
+#define DDERR_CANNOTATTACHSURFACE		MAKE_DDHRESULT( 10 )
+#define DDERR_CANNOTDETACHSURFACE		MAKE_DDHRESULT( 20 )
+#define DDERR_CURRENTLYNOTAVAIL			MAKE_DDHRESULT( 40 )
+#define DDERR_EXCEPTION				MAKE_DDHRESULT( 55 )
+#define DDERR_GENERIC				E_FAIL
+#define DDERR_HEIGHTALIGN			MAKE_DDHRESULT( 90 )
+#define DDERR_INCOMPATIBLEPRIMARY		MAKE_DDHRESULT( 95 )
+#define DDERR_INVALIDCAPS			MAKE_DDHRESULT( 100 )
+#define DDERR_INVALIDCLIPLIST			MAKE_DDHRESULT( 110 )
+#define DDERR_INVALIDMODE			MAKE_DDHRESULT( 120 )
+#define DDERR_INVALIDOBJECT			MAKE_DDHRESULT( 130 )
+#define DDERR_INVALIDPARAMS			E_INVALIDARG
+#define DDERR_INVALIDPIXELFORMAT		MAKE_DDHRESULT( 145 )
+#define DDERR_INVALIDRECT			MAKE_DDHRESULT( 150 )
+#define DDERR_LOCKEDSURFACES			MAKE_DDHRESULT( 160 )
+#define DDERR_NO3D				MAKE_DDHRESULT( 170 )
+#define DDERR_NOALPHAHW				MAKE_DDHRESULT( 180 )
+#define DDERR_NOCLIPLIST			MAKE_DDHRESULT( 205 )
+#define DDERR_NOCOLORCONVHW			MAKE_DDHRESULT( 210 )
+#define DDERR_NOCOOPERATIVELEVELSET		MAKE_DDHRESULT( 212 )
+#define DDERR_NOCOLORKEY			MAKE_DDHRESULT( 215 )
+#define DDERR_NOCOLORKEYHW			MAKE_DDHRESULT( 220 )
+#define DDERR_NODIRECTDRAWSUPPORT		MAKE_DDHRESULT( 222 )
+#define DDERR_NOEXCLUSIVEMODE			MAKE_DDHRESULT( 225 )
+#define DDERR_NOFLIPHW				MAKE_DDHRESULT( 230 )
+#define DDERR_NOGDI				MAKE_DDHRESULT( 240 )
+#define DDERR_NOMIRRORHW			MAKE_DDHRESULT( 250 )
+#define DDERR_NOTFOUND				MAKE_DDHRESULT( 255 )
+#define DDERR_NOOVERLAYHW			MAKE_DDHRESULT( 260 )
+#define DDERR_NORASTEROPHW			MAKE_DDHRESULT( 280 )
+#define DDERR_NOROTATIONHW			MAKE_DDHRESULT( 290 )
+#define DDERR_NOSTRETCHHW			MAKE_DDHRESULT( 310 )
+#define DDERR_NOT4BITCOLOR			MAKE_DDHRESULT( 316 )
+#define DDERR_NOT4BITCOLORINDEX			MAKE_DDHRESULT( 317 )
+#define DDERR_NOT8BITCOLOR			MAKE_DDHRESULT( 320 )
+#define DDERR_NOTEXTUREHW			MAKE_DDHRESULT( 330 )
+#define DDERR_NOVSYNCHW				MAKE_DDHRESULT( 335 )
+#define DDERR_NOZBUFFERHW			MAKE_DDHRESULT( 340 )
+#define DDERR_NOZOVERLAYHW			MAKE_DDHRESULT( 350 )
+#define DDERR_OUTOFCAPS				MAKE_DDHRESULT( 360 )
+#define DDERR_OUTOFMEMORY			E_OUTOFMEMORY
+#define DDERR_OUTOFVIDEOMEMORY			MAKE_DDHRESULT( 380 )
+#define DDERR_OVERLAYCANTCLIP			MAKE_DDHRESULT( 382 )
+#define DDERR_OVERLAYCOLORKEYONLYONEACTIVE	MAKE_DDHRESULT( 384 )
+#define DDERR_PALETTEBUSY			MAKE_DDHRESULT( 387 )
+#define DDERR_COLORKEYNOTSET			MAKE_DDHRESULT( 400 )
+#define DDERR_SURFACEALREADYATTACHED		MAKE_DDHRESULT( 410 )
+#define DDERR_SURFACEALREADYDEPENDENT		MAKE_DDHRESULT( 420 )
+#define DDERR_SURFACEBUSY			MAKE_DDHRESULT( 430 )
+#define DDERR_CANTLOCKSURFACE			MAKE_DDHRESULT( 435 )
+#define DDERR_SURFACEISOBSCURED			MAKE_DDHRESULT( 440 )
+#define DDERR_SURFACELOST			MAKE_DDHRESULT( 450 )
+#define DDERR_SURFACENOTATTACHED		MAKE_DDHRESULT( 460 )
+#define DDERR_TOOBIGHEIGHT			MAKE_DDHRESULT( 470 )
+#define DDERR_TOOBIGSIZE			MAKE_DDHRESULT( 480 )
+#define DDERR_TOOBIGWIDTH			MAKE_DDHRESULT( 490 )
+#define DDERR_UNSUPPORTED			E_NOTIMPL
+#define DDERR_UNSUPPORTEDFORMAT			MAKE_DDHRESULT( 510 )
+#define DDERR_UNSUPPORTEDMASK			MAKE_DDHRESULT( 520 )
+#define DDERR_VERTICALBLANKINPROGRESS		MAKE_DDHRESULT( 537 )
+#define DDERR_WASSTILLDRAWING			MAKE_DDHRESULT( 540 )
+#define DDERR_XALIGN				MAKE_DDHRESULT( 560 )
+#define DDERR_INVALIDDIRECTDRAWGUID		MAKE_DDHRESULT( 561 )
+#define DDERR_DIRECTDRAWALREADYCREATED		MAKE_DDHRESULT( 562 )
+#define DDERR_NODIRECTDRAWHW			MAKE_DDHRESULT( 563 )
+#define DDERR_PRIMARYSURFACEALREADYEXISTS	MAKE_DDHRESULT( 564 )
+#define DDERR_NOEMULATION			MAKE_DDHRESULT( 565 )
+#define DDERR_REGIONTOOSMALL			MAKE_DDHRESULT( 566 )
+#define DDERR_CLIPPERISUSINGHWND		MAKE_DDHRESULT( 567 )
+#define DDERR_NOCLIPPERATTACHED			MAKE_DDHRESULT( 568 )
+#define DDERR_NOHWND				MAKE_DDHRESULT( 569 )
+#define DDERR_HWNDSUBCLASSED			MAKE_DDHRESULT( 570 )
+#define DDERR_HWNDALREADYSET			MAKE_DDHRESULT( 571 )
+#define DDERR_NOPALETTEATTACHED			MAKE_DDHRESULT( 572 )
+#define DDERR_NOPALETTEHW			MAKE_DDHRESULT( 573 )
+#define DDERR_BLTFASTCANTCLIP			MAKE_DDHRESULT( 574 )
+#define DDERR_NOBLTHW				MAKE_DDHRESULT( 575 )
+#define DDERR_NODDROPSHW			MAKE_DDHRESULT( 576 )
+#define DDERR_OVERLAYNOTVISIBLE			MAKE_DDHRESULT( 577 )
+#define DDERR_NOOVERLAYDEST			MAKE_DDHRESULT( 578 )
+#define DDERR_INVALIDPOSITION			MAKE_DDHRESULT( 579 )
+#define DDERR_NOTAOVERLAYSURFACE		MAKE_DDHRESULT( 580 )
+#define DDERR_EXCLUSIVEMODEALREADYSET		MAKE_DDHRESULT( 581 )
+#define DDERR_NOTFLIPPABLE			MAKE_DDHRESULT( 582 )
+#define DDERR_CANTDUPLICATE			MAKE_DDHRESULT( 583 )
+#define DDERR_NOTLOCKED				MAKE_DDHRESULT( 584 )
+#define DDERR_CANTCREATEDC			MAKE_DDHRESULT( 585 )
+#define DDERR_NODC				MAKE_DDHRESULT( 586 )
+#define DDERR_WRONGMODE				MAKE_DDHRESULT( 587 )
+#define DDERR_IMPLICITLYCREATED			MAKE_DDHRESULT( 588 )
+#define DDERR_NOTPALETTIZED			MAKE_DDHRESULT( 589 )
+#define DDERR_UNSUPPORTEDMODE			MAKE_DDHRESULT( 590 )
+#define DDERR_NOMIPMAPHW			MAKE_DDHRESULT( 591 )
+#define DDERR_INVALIDSURFACETYPE		MAKE_DDHRESULT( 592 )
+#define DDERR_DCALREADYCREATED			MAKE_DDHRESULT( 620 )
+#define DDERR_CANTPAGELOCK			MAKE_DDHRESULT( 640 )
+#define DDERR_CANTPAGEUNLOCK			MAKE_DDHRESULT( 660 )
+#define DDERR_NOTPAGELOCKED			MAKE_DDHRESULT( 680 )
+#define DDERR_NOTINITIALIZED			CO_E_NOTINITIALIZED
+
+/* dwFlags for Blt* */
+#define DDBLT_ALPHADEST				0x00000001
+#define DDBLT_ALPHADESTCONSTOVERRIDE		0x00000002
+#define DDBLT_ALPHADESTNEG			0x00000004
+#define DDBLT_ALPHADESTSURFACEOVERRIDE		0x00000008
+#define DDBLT_ALPHAEDGEBLEND			0x00000010
+#define DDBLT_ALPHASRC				0x00000020
+#define DDBLT_ALPHASRCCONSTOVERRIDE		0x00000040
+#define DDBLT_ALPHASRCNEG			0x00000080
+#define DDBLT_ALPHASRCSURFACEOVERRIDE		0x00000100
+#define DDBLT_ASYNC				0x00000200
+#define DDBLT_COLORFILL				0x00000400
+#define DDBLT_DDFX				0x00000800
+#define DDBLT_DDROPS				0x00001000
+#define DDBLT_KEYDEST				0x00002000
+#define DDBLT_KEYDESTOVERRIDE			0x00004000
+#define DDBLT_KEYSRC				0x00008000
+#define DDBLT_KEYSRCOVERRIDE			0x00010000
+#define DDBLT_ROP				0x00020000
+#define DDBLT_ROTATIONANGLE			0x00040000
+#define DDBLT_ZBUFFER				0x00080000
+#define DDBLT_ZBUFFERDESTCONSTOVERRIDE		0x00100000
+#define DDBLT_ZBUFFERDESTOVERRIDE		0x00200000
+#define DDBLT_ZBUFFERSRCCONSTOVERRIDE		0x00400000
+#define DDBLT_ZBUFFERSRCOVERRIDE		0x00800000
+#define DDBLT_WAIT				0x01000000
+#define DDBLT_DEPTHFILL				0x02000000
+
+/* dwTrans for BltFast */
+#define DDBLTFAST_NOCOLORKEY			0x00000000
+#define DDBLTFAST_SRCCOLORKEY			0x00000001
+#define DDBLTFAST_DESTCOLORKEY			0x00000002
+#define DDBLTFAST_WAIT				0x00000010
+
+/* dwFlags for Flip */
+#define DDFLIP_WAIT				0x00000001
+
+/* dwFlags for GetBltStatus */
+#define DDGBS_CANBLT				0x00000001
+#define DDGBS_ISBLTDONE				0x00000002
+
+/* 3d capable (no meaning?) */
+#define DDSCAPS_3D			0x00000001
+/* surface contains alpha information */
+#define DDSCAPS_ALPHA			0x00000002
+/* this surface is a backbuffer */
+#define DDSCAPS_BACKBUFFER		0x00000004
+/* complex surface structure */
+#define DDSCAPS_COMPLEX			0x00000008
+/* part of surface flipping structure */
+#define DDSCAPS_FLIP			0x00000010
+/* this surface is the frontbuffer surface */
+#define DDSCAPS_FRONTBUFFER		0x00000020
+/* this is a plain offscreen surface */
+#define DDSCAPS_OFFSCREENPLAIN		0x00000040
+/* overlay */
+#define DDSCAPS_OVERLAY			0x00000080
+/* palette objects can be created and attached to us */
+#define DDSCAPS_PALETTE			0x00000100
+/* primary surface (the one the user looks at currently)(right eye)*/
+#define DDSCAPS_PRIMARYSURFACE		0x00000200
+/* primary surface for left eye */
+#define DDSCAPS_PRIMARYSURFACELEFT	0x00000400
+/* surface exists in systemmemory */
+#define DDSCAPS_SYSTEMMEMORY		0x00000800
+/* surface can be used as a texture */
+#define DDSCAPS_TEXTURE		        0x00001000
+/* surface may be destination for 3d rendering */
+#define DDSCAPS_3DDEVICE		0x00002000
+/* surface exists in videomemory */
+#define DDSCAPS_VIDEOMEMORY		0x00004000
+/* surface changes immediately visible */
+#define DDSCAPS_VISIBLE			0x00008000
+/* write only surface */
+#define DDSCAPS_WRITEONLY		0x00010000
+/* zbuffer surface */
+#define DDSCAPS_ZBUFFER			0x00020000
+/* has its own DC */
+#define DDSCAPS_OWNDC			0x00040000
+/* surface should be able to receive live video */
+#define DDSCAPS_LIVEVIDEO		0x00080000
+/* should be able to have a hw codec decompress stuff into it */
+#define DDSCAPS_HWCODEC			0x00100000
+/* mode X (320x200 or 320x240) surface */
+#define DDSCAPS_MODEX			0x00200000
+/* one mipmap surface (1 level) */
+#define DDSCAPS_MIPMAP			0x00400000
+/* memory allocation delayed until Load() */
+#define DDSCAPS_ALLOCONLOAD		0x04000000
+
+typedef struct _DDSCAPS {
+	DWORD	dwCaps;	/* capabilities of surface wanted */
+} DDSCAPS,*LPDDSCAPS;
+
+#define	DD_ROP_SPACE	(256/32)	/* space required to store ROP array */
+
+typedef struct _DDCAPS
+{
+    DWORD	dwSize;                 /* size of the DDDRIVERCAPS structure */
+    DWORD	dwCaps;                 /* driver specific capabilities */
+    DWORD	dwCaps2;                /* more driver specific capabilites */
+    DWORD	dwCKeyCaps;             /* color key capabilities of the surface */
+    DWORD	dwFXCaps;               /* driver specific stretching and effects capabilites */
+    DWORD	dwFXAlphaCaps;          /* alpha driver specific capabilities */
+    DWORD	dwPalCaps;              /* palette capabilities */
+    DWORD	dwSVCaps;               /* stereo vision capabilities */
+    DWORD	dwAlphaBltConstBitDepths;       /* DDBD_2,4,8 */
+    DWORD	dwAlphaBltPixelBitDepths;       /* DDBD_1,2,4,8 */
+    DWORD	dwAlphaBltSurfaceBitDepths;     /* DDBD_1,2,4,8 */
+    DWORD	dwAlphaOverlayConstBitDepths;   /* DDBD_2,4,8 */
+    DWORD	dwAlphaOverlayPixelBitDepths;   /* DDBD_1,2,4,8 */
+    DWORD	dwAlphaOverlaySurfaceBitDepths; /* DDBD_1,2,4,8 */
+    DWORD	dwZBufferBitDepths;             /* DDBD_8,16,24,32 */
+    DWORD	dwVidMemTotal;          /* total amount of video memory */
+    DWORD	dwVidMemFree;           /* amount of free video memory */
+    DWORD	dwMaxVisibleOverlays;   /* maximum number of visible overlays */
+    DWORD	dwCurrVisibleOverlays;  /* current number of visible overlays */
+    DWORD	dwNumFourCCCodes;       /* number of four cc codes */
+    DWORD	dwAlignBoundarySrc;     /* source rectangle alignment */
+    DWORD	dwAlignSizeSrc;         /* source rectangle byte size */
+    DWORD	dwAlignBoundaryDest;    /* dest rectangle alignment */
+    DWORD	dwAlignSizeDest;        /* dest rectangle byte size */
+    DWORD	dwAlignStrideAlign;     /* stride alignment */
+    DWORD	dwRops[DD_ROP_SPACE];   /* ROPS supported */
+    DDSCAPS	ddsCaps;                /* DDSCAPS structure has all the general capabilities */
+    DWORD	dwMinOverlayStretch;    /* minimum overlay stretch factor multiplied by 1000, eg 1000 == 1.0, 1300 == 1.3 */
+    DWORD	dwMaxOverlayStretch;    /* maximum overlay stretch factor multiplied by 1000, eg 1000 == 1.0, 1300 == 1.3 */
+    DWORD	dwMinLiveVideoStretch;  /* minimum live video stretch factor multiplied by 1000, eg 1000 == 1.0, 1300 == 1.3 */
+    DWORD	dwMaxLiveVideoStretch;  /* maximum live video stretch factor multiplied by 1000, eg 1000 == 1.0, 1300 == 1.3 */
+    DWORD	dwMinHwCodecStretch;    /* minimum hardware codec stretch factor multiplied by 1000, eg 1000 == 1.0, 1300 == 1.3 */
+    DWORD	dwMaxHwCodecStretch;    /* maximum hardware codec stretch factor multiplied by 1000, eg 1000 == 1.0, 1300 == 1.3 */
+    DWORD	dwReserved1;
+    DWORD	dwReserved2;
+    DWORD	dwReserved3;
+    DWORD	dwSVBCaps;              /* driver specific capabilities for System->Vmem blts */
+    DWORD	dwSVBCKeyCaps;          /* driver color key capabilities for System->Vmem blts */
+    DWORD	dwSVBFXCaps;            /* driver FX capabilities for System->Vmem blts */
+    DWORD	dwSVBRops[DD_ROP_SPACE];/* ROPS supported for System->Vmem blts */
+    DWORD	dwVSBCaps;              /* driver specific capabilities for Vmem->System blts */
+    DWORD	dwVSBCKeyCaps;          /* driver color key capabilities for Vmem->System blts */
+    DWORD	dwVSBFXCaps;            /* driver FX capabilities for Vmem->System blts */
+    DWORD	dwVSBRops[DD_ROP_SPACE];/* ROPS supported for Vmem->System blts */
+    DWORD	dwSSBCaps;              /* driver specific capabilities for System->System blts */
+    DWORD	dwSSBCKeyCaps;          /* driver color key capabilities for System->System blts */
+    DWORD	dwSSBFXCaps;            /* driver FX capabilities for System->System blts */
+    DWORD	dwSSBRops[DD_ROP_SPACE];/* ROPS supported for System->System blts */
+    DWORD	dwReserved4;
+    DWORD	dwReserved5;
+    DWORD	dwReserved6;
+} DDCAPS,*LPDDCAPS;
+
+/* hw has 3d accel */
+#define DDCAPS_3D			0x00000001
+/* supports only boundary aligned rectangles */
+#define DDCAPS_ALIGNBOUNDARYDEST	0x00000002
+#define DDCAPS_ALIGNSIZEDEST		0x00000004
+#define DDCAPS_ALIGNBOUNDARYSRC		0x00000008
+#define DDCAPS_ALIGNSIZESRC		0x00000010
+#define DDCAPS_ALIGNSTRIDE		0x00000020
+#define DDCAPS_BLT			0x00000040
+#define DDCAPS_BLTQUEUE			0x00000080
+#define DDCAPS_BLTFOURCC		0x00000100
+#define DDCAPS_BLTSTRETCH		0x00000200
+#define DDCAPS_GDI			0x00000400
+#define DDCAPS_OVERLAY			0x00000800
+#define DDCAPS_OVERLAYCANTCLIP		0x00001000
+#define DDCAPS_OVERLAYFOURCC		0x00002000
+#define DDCAPS_OVERLAYSTRETCH		0x00004000
+#define DDCAPS_PALETTE			0x00008000
+#define DDCAPS_PALETTEVSYNC		0x00010000
+#define DDCAPS_READSCANLINE		0x00020000
+#define DDCAPS_STEREOVIEW		0x00040000
+#define DDCAPS_VBI			0x00080000
+#define DDCAPS_ZBLTS			0x00100000
+#define DDCAPS_ZOVERLAYS		0x00200000
+#define DDCAPS_COLORKEY			0x00400000
+#define DDCAPS_ALPHA			0x00800000
+#define DDCAPS_COLORKEYHWASSIST		0x01000000
+#define DDCAPS_NOHARDWARE		0x02000000
+#define DDCAPS_BLTCOLORFILL		0x04000000
+#define DDCAPS_BANKSWITCHED		0x08000000
+#define DDCAPS_BLTDEPTHFILL		0x10000000
+#define DDCAPS_CANCLIP			0x20000000
+#define DDCAPS_CANCLIPSTRETCHED		0x40000000
+#define DDCAPS_CANBLTSYSMEM		0x80000000
+
+/* dwCaps2 */
+/* driver is certified */
+#define DDCAPS2_CERTIFIED		0x00000001
+/* no 2d operations in 3d mode */
+#define DDCAPS2_NO2DDURING3DSCENE       0x00000002
+
+typedef struct _DDCOLORKEY
+{
+	DWORD	dwColorSpaceLowValue;/* low boundary of color space that is to
+                                      * be treated as Color Key, inclusive
+				      */
+	DWORD	dwColorSpaceHighValue;/* high boundary of color space that is
+                                       * to be treated as Color Key, inclusive
+				       */
+} DDCOLORKEY,*LPDDCOLORKEY;
+
+/* ddCKEYCAPS bits */
+#define DDCKEYCAPS_DESTBLT			0x00000001
+#define DDCKEYCAPS_DESTBLTCLRSPACE		0x00000002
+#define DDCKEYCAPS_DESTBLTCLRSPACEYUV		0x00000004
+#define DDCKEYCAPS_DESTBLTYUV			0x00000008
+#define DDCKEYCAPS_DESTOVERLAY			0x00000010
+#define DDCKEYCAPS_DESTOVERLAYCLRSPACE		0x00000020
+#define DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV	0x00000040
+#define DDCKEYCAPS_DESTOVERLAYONEACTIVE		0x00000080
+#define DDCKEYCAPS_DESTOVERLAYYUV		0x00000100
+#define DDCKEYCAPS_SRCBLT			0x00000200
+#define DDCKEYCAPS_SRCBLTCLRSPACE		0x00000400
+#define DDCKEYCAPS_SRCBLTCLRSPACEYUV		0x00000800
+#define DDCKEYCAPS_SRCBLTYUV			0x00001000
+#define DDCKEYCAPS_SRCOVERLAY			0x00002000
+#define DDCKEYCAPS_SRCOVERLAYCLRSPACE		0x00004000
+#define DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV	0x00008000
+#define DDCKEYCAPS_SRCOVERLAYONEACTIVE		0x00010000
+#define DDCKEYCAPS_SRCOVERLAYYUV		0x00020000
+#define DDCKEYCAPS_NOCOSTOVERLAY		0x00040000
+
+typedef struct _DDPIXELFORMAT {
+    DWORD	dwSize;                 /* size of structure */
+    DWORD	dwFlags;                /* pixel format flags */
+    DWORD	dwFourCC;               /* (FOURCC code) */
+    union {
+	DWORD	dwRGBBitCount;          /* how many bits per pixel (BD_4,8,16,24,32)*/
+	DWORD	dwYUVBitCount;          /* how many bits per pixel (BD_4,8,16,24,32)*/
+	DWORD	dwZBufferBitDepth;      /* how many bits for z buffers (BD_8,16,24,32)*/
+	DWORD	dwAlphaBitDepth;        /* how many bits for alpha channels (BD_1,2,4,8)*/
+    } x;
+    union {
+	DWORD	dwRBitMask;             /* mask for red bit*/
+	DWORD	dwYBitMask;             /* mask for Y bits*/
+    } y;
+    union {
+	DWORD	dwGBitMask;             /* mask for green bits*/
+	DWORD	dwUBitMask;             /* mask for U bits*/
+    } z;
+    union {
+	DWORD   dwBBitMask;             /* mask for blue bits*/
+	DWORD   dwVBitMask;             /* mask for V bits*/
+    } xx;
+    union {
+    	DWORD	dwRGBAlphaBitMask;	/* mask for alpha channel */
+    	DWORD	dwYUVAlphaBitMask;	/* mask for alpha channel */
+
+    } xy;
+} DDPIXELFORMAT,*LPDDPIXELFORMAT;
+
+/* DDCAPS.dwFXCaps */
+#define DDFXCAPS_BLTARITHSTRETCHY	0x00000020
+#define DDFXCAPS_BLTARITHSTRETCHYN	0x00000010
+#define DDFXCAPS_BLTMIRRORLEFTRIGHT	0x00000040
+#define DDFXCAPS_BLTMIRRORUPDOWN	0x00000080
+#define DDFXCAPS_BLTROTATION		0x00000100
+#define DDFXCAPS_BLTROTATION90		0x00000200
+#define DDFXCAPS_BLTSHRINKX		0x00000400
+#define DDFXCAPS_BLTSHRINKXN		0x00000800
+#define DDFXCAPS_BLTSHRINKY		0x00001000
+#define DDFXCAPS_BLTSHRINKYN		0x00002000
+#define DDFXCAPS_BLTSTRETCHX		0x00004000
+#define DDFXCAPS_BLTSTRETCHXN		0x00008000
+#define DDFXCAPS_BLTSTRETCHY		0x00010000
+#define DDFXCAPS_BLTSTRETCHYN		0x00020000
+#define DDFXCAPS_OVERLAYARITHSTRETCHY	0x00040000
+#define DDFXCAPS_OVERLAYARITHSTRETCHYN	0x00000008
+#define DDFXCAPS_OVERLAYSHRINKX		0x00080000
+#define DDFXCAPS_OVERLAYSHRINKXN	0x00100000
+#define DDFXCAPS_OVERLAYSHRINKY		0x00200000
+#define DDFXCAPS_OVERLAYSHRINKYN	0x00400000
+#define DDFXCAPS_OVERLAYSTRETCHX	0x00800000
+#define DDFXCAPS_OVERLAYSTRETCHXN	0x01000000
+#define DDFXCAPS_OVERLAYSTRETCHY	0x02000000
+#define DDFXCAPS_OVERLAYSTRETCHYN	0x04000000
+#define DDFXCAPS_OVERLAYMIRRORLEFTRIGHT	0x08000000
+#define DDFXCAPS_OVERLAYMIRRORUPDOWN	0x10000000
+
+/* DDCAPS.dwFXAlphaCaps */
+#define DDFXALPHACAPS_BLTALPHAEDGEBLEND		0x00000001
+#define DDFXALPHACAPS_BLTALPHAPIXELS		0x00000002
+#define DDFXALPHACAPS_BLTALPHAPIXELSNEG		0x00000004
+#define DDFXALPHACAPS_BLTALPHASURFACES		0x00000008
+#define DDFXALPHACAPS_BLTALPHASURFACESNEG	0x00000010
+#define DDFXALPHACAPS_OVERLAYALPHAEDGEBLEND	0x00000020
+#define DDFXALPHACAPS_OVERLAYALPHAPIXELS	0x00000040
+#define DDFXALPHACAPS_OVERLAYALPHAPIXELSNEG	0x00000080
+#define DDFXALPHACAPS_OVERLAYALPHASURFACES	0x00000100
+#define DDFXALPHACAPS_OVERLAYALPHASURFACESNEG	0x00000200
+
+/* DDCAPS.dwPalCaps */
+#define DDPCAPS_4BIT			0x00000001
+#define DDPCAPS_8BITENTRIES		0x00000002
+#define DDPCAPS_8BIT			0x00000004
+#define DDPCAPS_INITIALIZE		0x00000008
+#define DDPCAPS_PRIMARYSURFACE		0x00000010
+#define DDPCAPS_PRIMARYSURFACELEFT	0x00000020
+#define DDPCAPS_ALLOW256		0x00000040
+#define DDPCAPS_VSYNC			0x00000080
+#define DDPCAPS_1BIT			0x00000100
+#define DDPCAPS_2BIT			0x00000200
+
+/* DDCAPS.dwSVCaps */
+#define DDSVCAPS_ENIGMA			0x00000001l
+#define DDSVCAPS_FLICKER		0x00000002l
+#define DDSVCAPS_REDBLUE		0x00000004l
+#define DDSVCAPS_SPLIT			0x00000008l
+
+/* BitDepths */
+#define DDBD_1				0x00004000
+#define DDBD_2				0x00002000
+#define DDBD_4				0x00001000
+#define DDBD_8				0x00000800
+#define DDBD_16				0x00000400
+#define DDBD_24				0x00000200
+#define DDBD_32				0x00000100
+
+/* DDOVERLAYFX.dwDDFX */
+#define DDOVERFX_ARITHSTRETCHY		0x00000001
+#define DDOVERFX_MIRRORLEFTRIGHT	0x00000002
+#define DDOVERFX_MIRRORUPDOWN		0x00000004
+
+/* DDCOLORKEY.dwFlags */
+#define DDPF_ALPHAPIXELS		0x00000001
+#define DDPF_ALPHA			0x00000002
+#define DDPF_FOURCC			0x00000004
+#define DDPF_PALETTEINDEXED4		0x00000008
+#define DDPF_PALETTEINDEXEDTO8		0x00000010
+#define DDPF_PALETTEINDEXED8		0x00000020
+#define DDPF_RGB			0x00000040
+#define DDPF_COMPRESSED			0x00000080
+#define DDPF_RGBTOYUV			0x00000100
+#define DDPF_YUV			0x00000200
+#define DDPF_ZBUFFER			0x00000400
+#define DDPF_PALETTEINDEXED1		0x00000800
+#define DDPF_PALETTEINDEXED2		0x00001000
+
+/* SetCooperativeLevel dwFlags */
+#define DDSCL_FULLSCREEN		0x00000001
+#define DDSCL_ALLOWREBOOT		0x00000002
+#define DDSCL_NOWINDOWCHANGES		0x00000004
+#define DDSCL_NORMAL			0x00000008
+#define DDSCL_EXCLUSIVE			0x00000010
+#define DDSCL_ALLOWMODEX		0x00000040
+
+typedef struct _DDSURFACEDESC
+{
+	DWORD	dwSize;	/* size of the DDSURFACEDESC structure*/
+	DWORD	dwFlags;/* determines what fields are valid*/
+	DWORD	dwHeight;/* height of surface to be created*/
+	DWORD	dwWidth;/* width of input surface*/
+	LONG	lPitch;	/* distance to start of next line (return value only)*/
+	DWORD	dwBackBufferCount;	/* number of back buffers requested*/
+	union {
+		DWORD	dwMipMapCount;	/* number of mip-map levels requested*/
+		DWORD	dwZBufferBitDepth;/* depth of Z buffer requested*/
+		DWORD	dwRefreshRate;	/* refresh rate (used when display mode is described)*/
+	} x;
+	DWORD	dwAlphaBitDepth;        /* depth of alpha buffer requested*/
+	DWORD	dwReserved;             /* reserved*/
+	LPVOID	lpSurface;              /* pointer to the associated surface memory*/
+	DDCOLORKEY	ddckCKDestOverlay;/* color key for destination overlay use*/
+	DDCOLORKEY	ddckCKDestBlt;/* color key for destination blt use*/
+	DDCOLORKEY	ddckCKSrcOverlay;/* color key for source overlay use*/
+	DDCOLORKEY	ddckCKSrcBlt;/* color key for source blt use*/
+	DDPIXELFORMAT	ddpfPixelFormat;/* pixel format description of the surface*/
+	DDSCAPS		ddsCaps;/* direct draw surface capabilities*/
+} DDSURFACEDESC,*LPDDSURFACEDESC;
+
+typedef BOOL32 (CALLBACK * LPDDENUMCALLBACK32A)(GUID *, LPSTR, LPSTR, LPVOID);
+typedef BOOL32 (CALLBACK * LPDDENUMCALLBACK32W)(GUID *, LPWSTR, LPWSTR, LPVOID);
+DECL_WINELIB_TYPE_AW(LPDDENUMCALLBACK)
+
+typedef HRESULT (CALLBACK * LPDDENUMMODESCALLBACK)(LPDDSURFACEDESC, LPVOID);
+typedef HRESULT (CALLBACK * LPDDENUMSURFACESCALLBACK)(LPDIRECTDRAWSURFACE, LPDDSURFACEDESC, LPVOID);
+
+/* dwFlags field... which are valid */
+
+#define	DDSD_CAPS		0x00000001
+#define	DDSD_HEIGHT		0x00000002
+#define	DDSD_WIDTH		0x00000004
+#define	DDSD_PITCH		0x00000008
+#define	DDSD_BACKBUFFERCOUNT	0x00000020
+#define	DDSD_ZBUFFERBITDEPTH	0x00000040
+#define	DDSD_ALPHABITDEPTH	0x00000080
+#define	DDSD_PIXELFORMAT	0x00001000
+#define	DDSD_CKDESTOVERLAY	0x00002000
+#define	DDSD_CKDESTBLT		0x00004000
+#define	DDSD_CKSRCOVERLAY	0x00008000
+#define	DDSD_CKSRCBLT		0x00010000
+#define	DDSD_MIPMAPCOUNT	0x00020000
+#define	DDSD_REFRESHRATE	0x00040000
+#define	DDSD_ALL		0x0007f9ee
+
+typedef struct _DDBLTFX
+{
+    DWORD       dwSize;                         /* size of structure */
+    DWORD       dwDDFX;                         /* FX operations */
+    DWORD       dwROP;                          /* Win32 raster operations */
+    DWORD       dwDDROP;                        /* Raster operations new for DirectDraw */
+    DWORD       dwRotationAngle;                /* Rotation angle for blt */
+    DWORD       dwZBufferOpCode;                /* ZBuffer compares */
+    DWORD       dwZBufferLow;                   /* Low limit of Z buffer */
+    DWORD       dwZBufferHigh;                  /* High limit of Z buffer */
+    DWORD       dwZBufferBaseDest;              /* Destination base value */
+    DWORD       dwZDestConstBitDepth;           /* Bit depth used to specify Z constant for destination */
+    union
+    {
+        DWORD   dwZDestConst;                   /* Constant to use as Z buffer for dest */
+        LPDIRECTDRAWSURFACE lpDDSZBufferDest;   /* Surface to use as Z buffer for dest */
+    } x;
+    DWORD       dwZSrcConstBitDepth;            /* Bit depth used to specify Z constant for source */
+    union
+    {
+        DWORD   dwZSrcConst;                    /* Constant to use as Z buffer for src */
+        LPDIRECTDRAWSURFACE lpDDSZBufferSrc;    /* Surface to use as Z buffer for src */
+    } y;
+    DWORD       dwAlphaEdgeBlendBitDepth;       /* Bit depth used to specify constant for alpha edge blend */
+    DWORD       dwAlphaEdgeBlend;               /* Alpha for edge blending */
+    DWORD       dwReserved;
+    DWORD       dwAlphaDestConstBitDepth;       /* Bit depth used to specify alpha constant for destination */
+    union
+    {
+        DWORD   dwAlphaDestConst;               /* Constant to use as Alpha Channel */
+        LPDIRECTDRAWSURFACE lpDDSAlphaDest;     /* Surface to use as Alpha Channel */
+    } z;
+    DWORD       dwAlphaSrcConstBitDepth;        /* Bit depth used to specify alpha constant for source */
+    union
+    {
+        DWORD   dwAlphaSrcConst;                /* Constant to use as Alpha Channel */
+        LPDIRECTDRAWSURFACE lpDDSAlphaSrc;      /* Surface to use as Alpha Channel */
+    } a;
+    union
+    {
+        DWORD   dwFillColor;                    /* color in RGB or Palettized */
+        DWORD   dwFillDepth;                    /* depth value for z-buffer */
+        LPDIRECTDRAWSURFACE lpDDSPattern;       /* Surface to use as pattern */
+    } b;
+    DDCOLORKEY  ddckDestColorkey;               /* DestColorkey override */
+    DDCOLORKEY  ddckSrcColorkey;                /* SrcColorkey override */
+} DDBLTFX,*LPDDBLTFX;
+
+/* dwDDFX */
+/* arithmetic stretching along y axis */
+#define DDBLTFX_ARITHSTRETCHY			0x00000001
+/* mirror on y axis */
+#define DDBLTFX_MIRRORLEFTRIGHT			0x00000002
+/* mirror on x axis */
+#define DDBLTFX_MIRRORUPDOWN			0x00000004
+/* do not tear */
+#define DDBLTFX_NOTEARING			0x00000008
+/* 180 degrees clockwise rotation */
+#define DDBLTFX_ROTATE180			0x00000010
+/* 270 degrees clockwise rotation */
+#define DDBLTFX_ROTATE270			0x00000020
+/* 90 degrees clockwise rotation */
+#define DDBLTFX_ROTATE90			0x00000040
+/* dwZBufferLow and dwZBufferHigh specify limits to the copied Z values */
+#define DDBLTFX_ZBUFFERRANGE			0x00000080
+/* add dwZBufferBaseDest to every source z value before compare */
+#define DDBLTFX_ZBUFFERBASEDEST			0x00000100
+
+typedef struct _DDOVERLAYFX
+{
+    DWORD       dwSize;                         /* size of structure */
+    DWORD       dwAlphaEdgeBlendBitDepth;       /* Bit depth used to specify constant for alpha edge blend */
+    DWORD       dwAlphaEdgeBlend;               /* Constant to use as alpha for edge blend */
+    DWORD       dwReserved;
+    DWORD       dwAlphaDestConstBitDepth;       /* Bit depth used to specify alpha constant for destination */
+    union
+    {
+        DWORD   dwAlphaDestConst;               /* Constant to use as alpha channel for dest */
+        LPDIRECTDRAWSURFACE lpDDSAlphaDest;     /* Surface to use as alpha channel for dest */
+    } x;
+    DWORD       dwAlphaSrcConstBitDepth;        /* Bit depth used to specify alpha constant for source */
+    union
+    {
+        DWORD   dwAlphaSrcConst;                /* Constant to use as alpha channel for src */
+        LPDIRECTDRAWSURFACE lpDDSAlphaSrc;      /* Surface to use as alpha channel for src */
+    } y;
+    DDCOLORKEY  dckDestColorkey;                /* DestColorkey override */
+    DDCOLORKEY  dckSrcColorkey;                 /* DestColorkey override */
+    DWORD       dwDDFX;                         /* Overlay FX */
+    DWORD       dwFlags;                        /* flags */
+} DDOVERLAYFX,*LPDDOVERLAYFX;
+
+typedef struct _DDBLTBATCH
+{
+    LPRECT32		lprDest;
+    LPDIRECTDRAWSURFACE	lpDDSSrc;
+    LPRECT32		lprSrc;
+    DWORD		dwFlags;
+    LPDDBLTFX		lpDDBltFx;
+} DDBLTBATCH,*LPDDBLTBATCH;
+
+#define STDMETHOD(xfn) HRESULT (CALLBACK *fn##xfn)
+#define STDMETHOD_(ret,xfn) ret (CALLBACK *fn##xfn)
+#define PURE
+#define FAR
+#define ULONG DWORD
+#define THIS_ THIS ,
+
+#define THIS LPDIRECTDRAWPALETTE this
+
+typedef struct IDirectDrawPalette_VTable {
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectDrawPalette methods ***/
+    STDMETHOD(GetCaps)(THIS_ LPDWORD) PURE;
+    STDMETHOD(GetEntries)(THIS_ DWORD,DWORD,DWORD,LPPALETTEENTRY) PURE;
+    STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, DWORD, LPPALETTEENTRY) PURE;
+    STDMETHOD(SetEntries)(THIS_ DWORD,DWORD,DWORD,LPPALETTEENTRY) PURE;
+} *LPDIRECTDRAWPALETTE_VTABLE,IDirectDrawPalette_VTable;
+
+struct IDirectDrawPalette {
+    LPDIRECTDRAWPALETTE_VTABLE	lpvtbl;
+    DWORD			ref;
+    LPDIRECTDRAW		ddraw;
+    Colormap			cm;
+};
+#undef THIS
+
+#define THIS LPDIRECTDRAWCLIPPER this
+typedef struct IDirectDrawClipper_VTable {
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectDrawClipper methods ***/
+    STDMETHOD(GetClipList)(THIS_ LPRECT32, LPRGNDATA, LPDWORD) PURE;
+    STDMETHOD(GetHWnd)(THIS_ HWND32 FAR *) PURE;
+    STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, DWORD) PURE;
+    STDMETHOD(IsClipListChanged)(THIS_ BOOL32 FAR *) PURE;
+    STDMETHOD(SetClipList)(THIS_ LPRGNDATA,DWORD) PURE;
+    STDMETHOD(SetHWnd)(THIS_ DWORD, HWND32 ) PURE;
+} *LPDIRECTDRAWCLIPPER_VTABLE,IDirectDrawClipper_VTable;
+
+struct IDirectDrawClipper {
+   LPDIRECTDRAWCLIPPER_VTABLE lpvtbl;
+   DWORD ref;
+};
+#undef THIS
+
+#define THIS LPDIRECTDRAW this
+typedef struct IDirectDraw_VTable {
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectDraw methods ***/
+    STDMETHOD(Compact)(THIS) PURE;
+    STDMETHOD(CreateClipper)(THIS_ DWORD, LPDIRECTDRAWCLIPPER FAR*, IUnknown FAR * ) PURE;
+    STDMETHOD(CreatePalette)(THIS_ DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR*, IUnknown FAR * ) PURE;
+    STDMETHOD(CreateSurface)(THIS_  LPDDSURFACEDESC *lpddsd, LPDIRECTDRAWSURFACE FAR *,
+IUnknown FAR *) PURE;
+    STDMETHOD(DuplicateSurface)( THIS_ LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE
+FAR * ) PURE;
+    STDMETHOD(EnumDisplayModes)( THIS_ DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK ) PURE;
+    STDMETHOD(EnumSurfaces)(THIS_ DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK ) PURE;
+    STDMETHOD(FlipToGDISurface)(THIS) PURE;
+    STDMETHOD(GetCaps)( THIS_ LPDDCAPS, LPDDCAPS) PURE;
+    STDMETHOD(GetDisplayMode)( THIS_ LPDDSURFACEDESC) PURE;
+    STDMETHOD(GetFourCCCodes)(THIS_  LPDWORD, LPDWORD ) PURE;
+    STDMETHOD(GetGDISurface)(THIS_ LPDIRECTDRAWSURFACE FAR *) PURE;
+    STDMETHOD(GetMonitorFrequency)(THIS_ LPDWORD) PURE;
+    STDMETHOD(GetScanLine)(THIS_ LPDWORD) PURE;
+    STDMETHOD(GetVerticalBlankStatus)(THIS_ BOOL32* ) PURE;
+    STDMETHOD(Initialize)(THIS_ GUID FAR *) PURE;
+    STDMETHOD(RestoreDisplayMode)(THIS) PURE;
+    STDMETHOD(SetCooperativeLevel)(THIS_ HWND32, DWORD) PURE;
+    STDMETHOD(SetDisplayMode)(THIS_ DWORD width, DWORD height,DWORD depth) PURE;
+    STDMETHOD(WaitForVerticalBlank)(THIS_ DWORD, HANDLE32 ) PURE;
+} *LPDIRECTDRAW_VTABLE,IDirectDraw_VTable;
+
+struct _directdrawdata {
+    DWORD			depth;
+    DWORD			vp_width,vp_height; /* viewport dimension */
+    DWORD			height,width;	/* SetDisplayMode */
+    DWORD			current_height,fb_width,fb_height,fb_banksize,fb_memsize;
+    HWND32			mainwindow;
+    void			*fb_addr;
+};
+
+
+struct IDirectDraw {
+	LPDIRECTDRAW_VTABLE	lpvtbl;
+	DWORD			ref;
+	struct _directdrawdata	d;
+};
+
+/* flags for Lock() */
+/* The default.  Set to indicate that Lock should return a valid memory pointer
+ * to the top of the specified rectangle.  If no rectangle is specified then a
+ * pointer to the top of the surface is returned.
+ */
+#define DDLOCK_SURFACEMEMORYPTR	0x00000000L
+/* Set to indicate that Lock should wait until it can obtain a valid memory
+ * pointer before returning.  If this bit is set, Lock will never return
+ * DDERR_WASSTILLDRAWING.
+ */
+#define DDLOCK_WAIT		0x00000001L
+/* Set if an event handle is being passed to Lock.  Lock will trigger the event
+ * when it can return the surface memory pointer requested.
+ */
+#define DDLOCK_EVENT		0x00000002L
+/* Indicates that the surface being locked will only be read from.  */
+#define DDLOCK_READONLY		0x00000010L
+/* Indicates that the surface being locked will only be written to */
+#define DDLOCK_WRITEONLY	0x00000020L
+
+#undef THIS
+
+#define THIS LPDIRECTDRAW2 this
+typedef struct IDirectDraw2_VTable
+{
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectDraw methods ***/
+    STDMETHOD(Compact)(THIS) PURE;
+    STDMETHOD(CreateClipper)(THIS_ DWORD, LPDIRECTDRAWCLIPPER FAR*, IUnknown FAR * ) PURE;
+    STDMETHOD(CreatePalette)(THIS_ DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR*, IUnknown FAR * ) PURE;
+    STDMETHOD(CreateSurface)(THIS_  LPDDSURFACEDESC, LPDIRECTDRAWSURFACE FAR *,
+IUnknown FAR *) PURE;
+    STDMETHOD(DuplicateSurface)( THIS_ LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE
+FAR * ) PURE;
+    STDMETHOD(EnumDisplayModes)( THIS_ DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK ) PURE;
+    STDMETHOD(EnumSurfaces)(THIS_ DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK ) PURE;
+    STDMETHOD(FlipToGDISurface)(THIS) PURE;
+    STDMETHOD(GetCaps)( THIS_ LPDDCAPS, LPDDCAPS) PURE;
+    STDMETHOD(GetDisplayMode)( THIS_ LPDDSURFACEDESC) PURE;
+    STDMETHOD(GetFourCCCodes)(THIS_  LPDWORD, LPDWORD ) PURE;
+    STDMETHOD(GetGDISurface)(THIS_ LPDIRECTDRAWSURFACE FAR *) PURE;
+    STDMETHOD(GetMonitorFrequency)(THIS_ LPDWORD) PURE;
+    STDMETHOD(GetScanLine)(THIS_ LPDWORD) PURE;
+    STDMETHOD(GetVerticalBlankStatus)(THIS_ BOOL32* ) PURE;
+    STDMETHOD(Initialize)(THIS_ GUID FAR *) PURE;
+    STDMETHOD(RestoreDisplayMode)(THIS) PURE;
+    STDMETHOD(SetCooperativeLevel)(THIS_ HWND32, DWORD) PURE;
+    STDMETHOD(SetDisplayMode)(THIS_ DWORD, DWORD,DWORD, DWORD, DWORD) PURE;
+    STDMETHOD(WaitForVerticalBlank)(THIS_ DWORD, HANDLE32 ) PURE;
+    /*** Added in the v2 interface ***/
+    STDMETHOD(GetAvailableVidMem)(THIS_ LPDDSCAPS, LPDWORD, LPDWORD) PURE;
+} IDirectDraw2_VTable,*LPDIRECTDRAW2_VTABLE;
+/* MUST HAVE THE SAME LAYOUT AS struct IDirectDraw */
+
+struct IDirectDraw2 {
+    LPDIRECTDRAW2_VTABLE	lpvtbl;
+    DWORD			ref;
+    struct _directdrawdata	d;
+};
+#undef THIS
+
+#define THIS LPDIRECTDRAWSURFACE this
+typedef struct IDirectDrawSurface_VTable {
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectDrawSurface methods ***/
+    STDMETHOD(AddAttachedSurface)(THIS_ LPDIRECTDRAWSURFACE) PURE;
+    STDMETHOD(AddOverlayDirtyRect)(THIS_ LPRECT32) PURE;
+    STDMETHOD(Blt)(THIS_ LPRECT32,LPDIRECTDRAWSURFACE, LPRECT32,DWORD, LPDDBLTFX) PURE;
+    STDMETHOD(BltBatch)(THIS_ LPDDBLTBATCH, DWORD, DWORD ) PURE;
+    STDMETHOD(BltFast)(THIS_ DWORD,DWORD,LPDIRECTDRAWSURFACE, LPRECT32,DWORD) PURE;
+    STDMETHOD(DeleteAttachedSurface)(THIS_ DWORD,LPDIRECTDRAWSURFACE) PURE;
+    STDMETHOD(EnumAttachedSurfaces)(THIS_ LPVOID,LPDDENUMSURFACESCALLBACK) PURE;    STDMETHOD(EnumOverlayZOrders)(THIS_ DWORD,LPVOID,LPDDENUMSURFACESCALLBACK) PURE;
+    STDMETHOD(Flip)(THIS_ LPDIRECTDRAWSURFACE, DWORD) PURE;
+    STDMETHOD(GetAttachedSurface)(THIS_ LPDDSCAPS, LPDIRECTDRAWSURFACE FAR *) PURE;
+    STDMETHOD(GetBltStatus)(THIS_ DWORD) PURE;
+    STDMETHOD(GetCaps)(THIS_ LPDDSCAPS) PURE;
+    STDMETHOD(GetClipper)(THIS_ LPDIRECTDRAWCLIPPER FAR*) PURE;
+    STDMETHOD(GetColorKey)(THIS_ DWORD, LPDDCOLORKEY) PURE;
+    STDMETHOD(GetDC)(THIS_ HDC32 FAR *) PURE;
+    STDMETHOD(GetFlipStatus)(THIS_ DWORD) PURE;
+    STDMETHOD(GetOverlayPosition)(THIS_ LPLONG, LPLONG ) PURE;
+    STDMETHOD(GetPalette)(THIS_ LPDIRECTDRAWPALETTE FAR*) PURE;
+    STDMETHOD(GetPixelFormat)(THIS_ LPDDPIXELFORMAT) PURE;
+    STDMETHOD(GetSurfaceDesc)(THIS_ LPDDSURFACEDESC) PURE;
+    STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, LPDDSURFACEDESC) PURE;
+    STDMETHOD(IsLost)(THIS) PURE;
+    STDMETHOD(Lock)(THIS_ LPRECT32,LPDDSURFACEDESC,DWORD flags,HANDLE32) PURE;
+    STDMETHOD(ReleaseDC)(THIS_ HDC32) PURE;
+    STDMETHOD(Restore)(THIS) PURE;
+    STDMETHOD(SetClipper)(THIS_ LPDIRECTDRAWCLIPPER) PURE;
+    STDMETHOD(SetColorKey)(THIS_ DWORD, LPDDCOLORKEY) PURE;
+    STDMETHOD(SetOverlayPosition)(THIS_ LONG, LONG ) PURE;
+    STDMETHOD(SetPalette)(THIS_ LPDIRECTDRAWPALETTE) PURE;
+    STDMETHOD(Unlock)(THIS_ LPVOID) PURE;
+    STDMETHOD(UpdateOverlay)(THIS_ LPRECT32, LPDIRECTDRAWSURFACE,LPRECT32,DWORD, LPDDOVERLAYFX) PURE;
+    STDMETHOD(UpdateOverlayDisplay)(THIS_ DWORD) PURE;
+    STDMETHOD(UpdateOverlayZOrder)(THIS_ DWORD, LPDIRECTDRAWSURFACE) PURE;
+} *LPDIRECTDRAWSURFACE_VTABLE,IDirectDrawSurface_VTable;
+
+struct IDirectDrawSurface {
+    LPDIRECTDRAWSURFACE_VTABLE lpvtbl;
+    DWORD		ref;
+    LPVOID		surface;
+    LPDIRECTDRAWPALETTE	palette;
+    DWORD		fb_height,lpitch,width,height;
+    LPDIRECTDRAW	ddraw;
+};
+#undef THIS
+#define THIS LPDIRECTDRAWSURFACE2 this
+
+typedef struct IDirectDrawSurface2_VTable {
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectDrawSurface methods ***/
+    STDMETHOD(AddAttachedSurface)(THIS_ LPDIRECTDRAWSURFACE2) PURE;
+    STDMETHOD(AddOverlayDirtyRect)(THIS_ LPRECT32) PURE;
+    STDMETHOD(Blt)(THIS_ LPRECT32,LPDIRECTDRAWSURFACE2, LPRECT32,DWORD, LPDDBLTFX) PURE;
+    STDMETHOD(BltBatch)(THIS_ LPDDBLTBATCH, DWORD, DWORD ) PURE;
+    STDMETHOD(BltFast)(THIS_ DWORD,DWORD,LPDIRECTDRAWSURFACE2, LPRECT32,DWORD) PURE;
+    STDMETHOD(DeleteAttachedSurface)(THIS_ DWORD,LPDIRECTDRAWSURFACE2) PURE;
+    STDMETHOD(EnumAttachedSurfaces)(THIS_ LPVOID,LPDDENUMSURFACESCALLBACK) PURE;    STDMETHOD(EnumOverlayZOrders)(THIS_ DWORD,LPVOID,LPDDENUMSURFACESCALLBACK) PURE;
+    STDMETHOD(Flip)(THIS_ LPDIRECTDRAWSURFACE2, DWORD) PURE;
+    STDMETHOD(GetAttachedSurface)(THIS_ LPDDSCAPS, LPDIRECTDRAWSURFACE2 FAR *) PURE;
+    STDMETHOD(GetBltStatus)(THIS_ DWORD) PURE;
+    STDMETHOD(GetCaps)(THIS_ LPDDSCAPS) PURE;
+    STDMETHOD(GetClipper)(THIS_ LPDIRECTDRAWCLIPPER FAR*) PURE;
+    STDMETHOD(GetColorKey)(THIS_ DWORD, LPDDCOLORKEY) PURE;
+    STDMETHOD(GetDC)(THIS_ HDC32 FAR *) PURE;
+    STDMETHOD(GetFlipStatus)(THIS_ DWORD) PURE;
+    STDMETHOD(GetOverlayPosition)(THIS_ LPLONG, LPLONG ) PURE;
+    STDMETHOD(GetPalette)(THIS_ LPDIRECTDRAWPALETTE FAR*) PURE;
+    STDMETHOD(GetPixelFormat)(THIS_ LPDDPIXELFORMAT) PURE;
+    STDMETHOD(GetSurfaceDesc)(THIS_ LPDDSURFACEDESC) PURE;
+    STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, LPDDSURFACEDESC) PURE;
+    STDMETHOD(IsLost)(THIS) PURE;
+    STDMETHOD(Lock)(THIS_ LPRECT32,LPDDSURFACEDESC,DWORD,HANDLE32) PURE;
+    STDMETHOD(ReleaseDC)(THIS_ HDC32) PURE;
+    STDMETHOD(Restore)(THIS) PURE;
+    STDMETHOD(SetClipper)(THIS_ LPDIRECTDRAWCLIPPER) PURE;
+    STDMETHOD(SetColorKey)(THIS_ DWORD, LPDDCOLORKEY) PURE;
+    STDMETHOD(SetOverlayPosition)(THIS_ LONG, LONG ) PURE;
+    STDMETHOD(SetPalette)(THIS_ LPDIRECTDRAWPALETTE) PURE;
+    STDMETHOD(Unlock)(THIS_ LPVOID) PURE;
+    STDMETHOD(UpdateOverlay)(THIS_ LPRECT32, LPDIRECTDRAWSURFACE2,LPRECT32,DWORD, LPDDOVERLAYFX) PURE;
+    STDMETHOD(UpdateOverlayDisplay)(THIS_ DWORD) PURE;
+    STDMETHOD(UpdateOverlayZOrder)(THIS_ DWORD, LPDIRECTDRAWSURFACE2) PURE;
+    /*** Added in the v2 interface ***/
+    STDMETHOD(GetDDInterface)(THIS_ LPVOID FAR *) PURE;
+    STDMETHOD(PageLock)(THIS_ DWORD) PURE;
+    STDMETHOD(PageUnlock)(THIS_ DWORD) PURE;
+} *LPDIRECTDRAWSURFACE2_VTABLE,IDirectDrawSurface2_VTable;
+
+struct IDirectDrawSurface2 {
+    LPDIRECTDRAWSURFACE2_VTABLE	lpvtbl;
+    DWORD		ref;
+    LPVOID		surface;
+    LPDIRECTDRAWPALETTE	palette;
+    DWORD		fb_height,lpitch,width,height;
+    LPDIRECTDRAW	ddraw;
+};
+#undef THIS
+
+#undef THIS_
+#undef PURE
+#undef FAR
+#undef STDMETHOD
+#undef STDMETHOD_
+
+extern HRESULT WINAPI DirectDrawCreate( LPGUID lpGUID,LPDIRECTDRAW *lplpDD,LPUNKNOWN pUnkOuter );
+#endif
diff --git a/include/dsound.h b/include/dsound.h
new file mode 100644
index 0000000..61d042b
--- /dev/null
+++ b/include/dsound.h
@@ -0,0 +1,187 @@
+#ifndef __WINE_DSOUND_H
+#define __WINE_DSOUND_H
+
+#include "mmsystem.h"
+
+/* Direct Sound Component GUID    {47D4D946-62E8-11cf-93BC-444553540000} */
+DEFINE_GUID(CLSID_DirectSound,0x47d4d946, 0x62e8, 0x11cf, 0x93, 0xbc, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
+
+/* DirectSound 279afa83-4981-11ce-a521-0020af0be560 */
+DEFINE_GUID(IID_IDirectSound,0x279AFA83,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
+/* DirectSoundBuffer 279afa85-4981-11ce-a521-0020af0be560 */
+DEFINE_GUID(IID_IDirectSoundBuffer,0x279AFA85,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60); 
+
+typedef struct IDirectSound IDirectSound,*LPDIRECTSOUND;
+typedef struct IDirectSoundBuffer IDirectSoundBuffer,*LPDIRECTSOUNDBUFFER,**LPLPDIRECTSOUNDBUFFER;
+
+#define DSCAPS_PRIMARYMONO          0x00000001
+#define DSCAPS_PRIMARYSTEREO        0x00000002
+#define DSCAPS_PRIMARY8BIT          0x00000004
+#define DSCAPS_PRIMARY16BIT         0x00000008
+#define DSCAPS_CONTINUOUSRATE       0x00000010
+#define DSCAPS_EMULDRIVER           0x00000020
+#define DSCAPS_CERTIFIED            0x00000040
+#define DSCAPS_SECONDARYMONO        0x00000100
+#define DSCAPS_SECONDARYSTEREO      0x00000200
+#define DSCAPS_SECONDARY8BIT        0x00000400
+#define DSCAPS_SECONDARY16BIT       0x00000800
+
+typedef struct _DSCAPS
+{
+    DWORD	dwSize;
+    DWORD	dwFlags;
+    DWORD	dwMinSecondarySampleRate;
+    DWORD	dwMaxSecondarySampleRate;
+    DWORD	dwPrimaryBuffers;
+    DWORD	dwMaxHwMixingAllBuffers;
+    DWORD	dwMaxHwMixingStaticBuffers;
+    DWORD	dwMaxHwMixingStreamingBuffers;
+    DWORD	dwFreeHwMixingAllBuffers;
+    DWORD	dwFreeHwMixingStaticBuffers;
+    DWORD	dwFreeHwMixingStreamingBuffers;
+    DWORD	dwMaxHw3DAllBuffers;
+    DWORD	dwMaxHw3DStaticBuffers;
+    DWORD	dwMaxHw3DStreamingBuffers;
+    DWORD	dwFreeHw3DAllBuffers;
+    DWORD	dwFreeHw3DStaticBuffers;
+    DWORD	dwFreeHw3DStreamingBuffers;
+    DWORD	dwTotalHwMemBytes;
+    DWORD	dwFreeHwMemBytes;
+    DWORD	dwMaxContigFreeHwMemBytes;
+    DWORD	dwUnlockTransferRateHwBuffers;
+    DWORD	dwPlayCpuOverheadSwBuffers;
+    DWORD	dwReserved1;
+    DWORD	dwReserved2;
+} DSCAPS,*LPDSCAPS;
+
+#define DSBPLAY_LOOPING         0x00000001
+
+#define DSBSTATUS_PLAYING           0x00000001
+#define DSBSTATUS_BUFFERLOST        0x00000002
+#define DSBSTATUS_LOOPING           0x00000004
+
+
+#define DSBLOCK_FROMWRITECURSOR         0x00000001
+
+#define DSBCAPS_PRIMARYBUFFER       0x00000001
+#define DSBCAPS_STATIC              0x00000002
+#define DSBCAPS_LOCHARDWARE         0x00000004
+#define DSBCAPS_LOCSOFTWARE         0x00000008
+#define DSBCAPS_CTRLFREQUENCY       0x00000020
+#define DSBCAPS_CTRLPAN             0x00000040
+#define DSBCAPS_CTRLVOLUME          0x00000080
+#define DSBCAPS_CTRLDEFAULT         0x000000E0  /* Pan + volume + frequency. */
+#define DSBCAPS_CTRLALL             0x000000E0  /* All control capabilities */
+#define DSBCAPS_STICKYFOCUS         0x00004000
+#define DSBCAPS_GETCURRENTPOSITION2 0x00010000  /* More accurate play cursor under emulation*/
+
+typedef struct _DSBCAPS
+{
+    DWORD	dwSize;
+    DWORD	dwFlags;
+    DWORD	dwBufferBytes;
+    DWORD	dwUnlockTransferRate;
+    DWORD	dwPlayCpuOverhead;
+} DSBCAPS,*LPDSBCAPS;
+
+#define DSSCL_NORMAL                1
+#define DSSCL_PRIORITY              2
+#define DSSCL_EXCLUSIVE             3
+#define DSSCL_WRITEPRIMARY          4
+
+typedef struct _DSBUFFERDESC
+{
+    DWORD		dwSize;
+    DWORD		dwFlags;
+    DWORD		dwBufferBytes;
+    DWORD		dwReserved;
+    LPWAVEFORMATEX	lpwfxFormat;
+} DSBUFFERDESC,*LPDSBUFFERDESC;
+
+
+
+#define DSSPEAKER_HEADPHONE     1
+#define DSSPEAKER_MONO          2
+#define DSSPEAKER_QUAD          3
+#define DSSPEAKER_STEREO        4
+#define DSSPEAKER_SURROUND      5
+
+
+
+typedef LPVOID* LPLPVOID;
+
+typedef BOOL32 (CALLBACK *LPDSENUMCALLBACK32W)(LPGUID,LPWSTR,LPWSTR,LPVOID);
+typedef BOOL32 (CALLBACK *LPDSENUMCALLBACK32A)(LPGUID,LPSTR,LPSTR,LPVOID);
+
+extern HRESULT WINAPI DirectSoundCreate(LPGUID lpGUID,LPDIRECTSOUND * ppDS,IUnknown *pUnkOuter );
+
+#define STDMETHOD(xfn) HRESULT (CALLBACK *fn##xfn)
+#define STDMETHOD_(ret,xfn) ret (CALLBACK *fn##xfn)
+#define PURE
+#define FAR
+#define ULONG DWORD
+
+#define THIS LPDIRECTSOUND this
+#define THIS_ LPDIRECTSOUND this,
+
+typedef struct tagLPDIRECTSOUND_VTABLE
+{
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectSound methods ***/
+
+    STDMETHOD( CreateSoundBuffer)(THIS_ LPDSBUFFERDESC, LPLPDIRECTSOUNDBUFFER, IUnknown FAR *) PURE;
+    STDMETHOD( GetCaps)(THIS_ LPDSCAPS ) PURE;
+    STDMETHOD( DuplicateSoundBuffer)(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER ) PURE;
+    STDMETHOD( SetCooperativeLevel)(THIS_ HWND32, DWORD ) PURE;
+    STDMETHOD( Compact)(THIS ) PURE;
+    STDMETHOD( GetSpeakerConfig)(THIS_ LPDWORD ) PURE;
+    STDMETHOD( SetSpeakerConfig)(THIS_ DWORD ) PURE;
+    STDMETHOD( Initialize)(THIS_ GUID FAR * ) PURE;
+} *LPDIRECTSOUND_VTABLE;
+
+struct IDirectSound {
+	LPDIRECTSOUND_VTABLE	lpvtbl;
+	DWORD			ref;
+};
+
+#undef THIS
+#undef THIS_
+#define THIS LPDIRECTSOUNDBUFFER this
+#define THIS_ LPDIRECTSOUNDBUFFER this,
+typedef struct tagLPDIRECTSOUNDBUFFER_VTABLE
+{
+    /*** IUnknown methods ***/
+    STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
+    STDMETHOD_(ULONG,Release) (THIS) PURE;
+    /*** IDirectSoundBuffer methods ***/
+
+    STDMETHOD(           GetCaps)(THIS_ LPDSBCAPS ) PURE;
+    STDMETHOD(GetCurrentPosition)(THIS_ LPDWORD,LPDWORD ) PURE;
+    STDMETHOD(         GetFormat)(THIS_ LPWAVEFORMATEX, DWORD, LPDWORD ) PURE;
+    STDMETHOD(         GetVolume)(THIS_ LPLONG ) PURE;
+    STDMETHOD(            GetPan)(THIS_ LPLONG ) PURE;
+    STDMETHOD(      GetFrequency)(THIS_ LPDWORD ) PURE;
+    STDMETHOD(         GetStatus)(THIS_ LPDWORD ) PURE;
+    STDMETHOD(        Initialize)(THIS_ LPDIRECTSOUND, LPDSBUFFERDESC ) PURE;
+    STDMETHOD(              Lock)(THIS_ DWORD,DWORD,LPVOID,LPDWORD,LPVOID,LPDWORD,DWORD ) PURE;
+    STDMETHOD(              Play)(THIS_ DWORD,DWORD,DWORD ) PURE;
+    STDMETHOD(SetCurrentPosition)(THIS_ DWORD ) PURE;
+    STDMETHOD(         SetFormat)(THIS_ LPWAVEFORMATEX ) PURE;
+    STDMETHOD(         SetVolume)(THIS_ LONG ) PURE;
+    STDMETHOD(            SetPan)(THIS_ LONG ) PURE;
+    STDMETHOD(      SetFrequency)(THIS_ DWORD ) PURE;
+    STDMETHOD(              Stop)(THIS  ) PURE;
+    STDMETHOD(            Unlock)(THIS_ LPVOID,DWORD,LPVOID,DWORD ) PURE;
+    STDMETHOD(           Restore)(THIS  ) PURE;
+} *LPDIRECTSOUNDBUFFER_VTABLE;
+
+struct IDirectSoundBuffer {
+	LPDIRECTSOUNDBUFFER_VTABLE	lpvtbl;
+	DWORD				ref;
+};
+
+#endif
diff --git a/include/file.h b/include/file.h
index badc67a..de43e1b 100644
--- a/include/file.h
+++ b/include/file.h
@@ -9,7 +9,7 @@
 
 #include <time.h>
 #include "windows.h"
-#include "handle32.h"
+#include "k32obj.h"
 
 #define MAX_PATHNAME_LEN   1024
 
@@ -35,7 +35,6 @@
 
 
 /* files/file.c */
-extern void FILE_Destroy( K32OBJ *ptr );
 extern void FILE_SetDosError(void);
 extern HFILE32 FILE_DupUnixHandle( int fd );
 extern BOOL32 FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info );
diff --git a/include/handle32.h b/include/handle32.h
deleted file mode 100644
index 9e5fca0..0000000
--- a/include/handle32.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * KERNEL32 objects
- *
- * Copyright 1996 Alexandre Julliard
- */
-
-#ifndef __WINE_HANDLE32_H
-#define __WINE_HANDLE32_H
-
-#include "wintypes.h"
-
-/* Object types */
-typedef enum
-{
-    K32OBJ_UNKNOWN = 0,
-    K32OBJ_SEMAPHORE,
-    K32OBJ_EVENT,
-    K32OBJ_MUTEX,
-    K32OBJ_CRITICAL_SECTION,
-    K32OBJ_PROCESS,
-    K32OBJ_THREAD,
-    K32OBJ_FILE,
-    K32OBJ_CHANGE,
-    K32OBJ_CONSOLE,
-    K32OBJ_SCREEN_BUFFER,
-    K32OBJ_MEM_MAPPED_FILE,
-    K32OBJ_SERIAL,
-    K32OBJ_DEVICE_IOCTL,
-    K32OBJ_PIPE,
-    K32OBJ_MAILSLOT,
-    K32OBJ_TOOLHELP_SNAPSHOT,
-    K32OBJ_SOCKET,
-    K32OBJ_NBOBJECTS
-} K32OBJ_TYPE;
-
-/* Kernel object */
-typedef struct
-{
-    K32OBJ_TYPE   type;
-    DWORD         refcount;
-} K32OBJ;
-
-/* Kernel object list entry */
-typedef struct _K32OBJ_ENTRY
-{
-    K32OBJ               *obj;
-    struct _K32OBJ_ENTRY *next;
-    struct _K32OBJ_ENTRY *prev;
-} K32OBJ_ENTRY;
-
-/* Kernel object list */
-typedef struct
-{
-    K32OBJ_ENTRY *head;
-    K32OBJ_ENTRY *tail;
-} K32OBJ_LIST;
-
-extern void K32OBJ_IncCount( K32OBJ *ptr );
-extern void K32OBJ_DecCount( K32OBJ *ptr );
-extern void K32OBJ_AddHead( K32OBJ_LIST *list, K32OBJ *ptr );
-extern void K32OBJ_AddTail( K32OBJ_LIST *list, K32OBJ *ptr );
-extern void K32OBJ_Remove( K32OBJ_LIST *list, K32OBJ *ptr );
-extern K32OBJ *K32OBJ_RemoveHead( K32OBJ_LIST *list );
-extern BOOL32 K32OBJ_AddName( K32OBJ *obj, LPCSTR name );
-extern K32OBJ *K32OBJ_FindName( LPCSTR name );
-extern K32OBJ *K32OBJ_FindNameType( LPCSTR name, K32OBJ_TYPE type );
-
-#endif /* __WINE_HANDLE32_H */
diff --git a/include/heap.h b/include/heap.h
index 8459eba..82f26e2 100644
--- a/include/heap.h
+++ b/include/heap.h
@@ -12,6 +12,7 @@
 
 extern HANDLE32 SystemHeap;
 extern HANDLE32 SegptrHeap;
+extern CRITICAL_SECTION *HEAP_SystemLock;
 
 extern int HEAP_IsInsideHeap( HANDLE32 heap, DWORD flags, LPCVOID ptr );
 extern SEGPTR HEAP_GetSegptr( HANDLE32 heap, DWORD flags, LPCVOID ptr );
@@ -36,4 +37,11 @@
 #define SEGPTR_FREE(ptr) \
          (HIWORD(ptr) ? HeapFree( SegptrHeap, 0, (ptr) ) : 0)
 
+/* System heap locking macros */
+
+#define SYSTEM_LOCK()       (EnterCriticalSection(HEAP_SystemLock))
+#define SYSTEM_UNLOCK()     (LeaveCriticalSection(HEAP_SystemLock))
+/* Use this one only when you own the lock! */
+#define SYSTEM_LOCK_COUNT() (HEAP_SystemLock->RecursionCount)
+
 #endif  /* __WINE_HEAP_H */
diff --git a/include/k32obj.h b/include/k32obj.h
new file mode 100644
index 0000000..afe3c94
--- /dev/null
+++ b/include/k32obj.h
@@ -0,0 +1,66 @@
+/*
+ * KERNEL32 objects
+ *
+ * Copyright 1996, 1998 Alexandre Julliard
+ */
+
+#ifndef __WINE_K32OBJ_H
+#define __WINE_K32OBJ_H
+
+#include "wintypes.h"
+
+/* Object types */
+typedef enum
+{
+    K32OBJ_UNKNOWN = 0,
+    K32OBJ_SEMAPHORE,
+    K32OBJ_EVENT,
+    K32OBJ_MUTEX,
+    K32OBJ_CRITICAL_SECTION,
+    K32OBJ_PROCESS,
+    K32OBJ_THREAD,
+    K32OBJ_FILE,
+    K32OBJ_CHANGE,
+    K32OBJ_CONSOLE,
+    K32OBJ_SCREEN_BUFFER,
+    K32OBJ_MEM_MAPPED_FILE,
+    K32OBJ_SERIAL,
+    K32OBJ_DEVICE_IOCTL,
+    K32OBJ_PIPE,
+    K32OBJ_MAILSLOT,
+    K32OBJ_TOOLHELP_SNAPSHOT,
+    K32OBJ_SOCKET,
+    K32OBJ_NBOBJECTS
+} K32OBJ_TYPE;
+
+/* Kernel object */
+typedef struct
+{
+    K32OBJ_TYPE   type;
+    LONG          refcount;
+} K32OBJ;
+
+/* Kernel object operations */
+typedef struct
+{
+    BOOL32 (*signaled)(K32OBJ*,DWORD);    /* Is object signaled? */
+    void   (*satisfied)(K32OBJ*,DWORD);   /* Wait on object is satisfied */
+    void   (*add_wait)(K32OBJ*,DWORD);    /* Add thread to wait queue */
+    void   (*remove_wait)(K32OBJ*,DWORD); /* Remove thread from wait queue */
+    void   (*destroy)(K32OBJ *);          /* Destroy object on refcount==0 */
+} K32OBJ_OPS;
+
+extern const K32OBJ_OPS * const K32OBJ_Ops[K32OBJ_NBOBJECTS];
+
+#define K32OBJ_OPS(obj) (K32OBJ_Ops[(obj)->type])
+
+extern void K32OBJ_IncCount( K32OBJ *ptr );
+extern void K32OBJ_DecCount( K32OBJ *ptr );
+extern BOOL32 K32OBJ_IsValid( K32OBJ *ptr, K32OBJ_TYPE type );
+extern BOOL32 K32OBJ_AddName( K32OBJ *obj, LPCSTR name );
+extern K32OBJ *K32OBJ_Create( K32OBJ_TYPE type, DWORD size, LPCSTR name,
+                              HANDLE32 *handle );
+extern K32OBJ *K32OBJ_FindName( LPCSTR name );
+extern K32OBJ *K32OBJ_FindNameType( LPCSTR name, K32OBJ_TYPE type );
+
+#endif /* __WINE_K32OBJ_H */
diff --git a/include/mmsystem.h b/include/mmsystem.h
index 6845f35..493b7ac 100644
--- a/include/mmsystem.h
+++ b/include/mmsystem.h
@@ -875,8 +875,8 @@
     WCHAR szRegKey[MAXPNAMELEN];
     WCHAR szOEMVxD[MAX_JOYSTICKOEMVXDNAME];
 } JOYCAPS32W, *LPJOYCAPS32W;
-DECL_WINELIB_TYPE_AW(JOYCAPS)
-DECL_WINELIB_TYPE_AW(LPJOYCAPS)
+DECL_WINELIB_TYPE_AW(JOYCAPS);
+DECL_WINELIB_TYPE_AW(LPJOYCAPS);
 
 typedef struct {
     UINT16 wXpos;                 /* x position */
@@ -892,8 +892,8 @@
     UINT32 wButtons;
 } JOYINFO32, *LPJOYINFO32;
 
-DECL_WINELIB_TYPE(JOYINFO)
-DECL_WINELIB_TYPE(LPJOYINFO)
+DECL_WINELIB_TYPE(JOYINFO);
+DECL_WINELIB_TYPE(LPJOYINFO);
 
 MMRESULT16 WINAPI joyGetDevCaps16 (UINT16,LPJOYCAPS16 ,UINT16);
 MMRESULT32 WINAPI joyGetDevCaps32A(UINT32,LPJOYCAPS32A,UINT32);
diff --git a/include/process.h b/include/process.h
index 3cbd14c..ca0014f 100644
--- a/include/process.h
+++ b/include/process.h
@@ -10,7 +10,7 @@
 #include "windows.h"
 #include "winbase.h"
 #include "winnt.h"
-#include "handle32.h"
+#include "k32obj.h"
 #include "pe_image.h"
 #include "task.h"
 
@@ -98,13 +98,20 @@
     LCID             locale;           /* c4 Locale to be queried by GetThreadLocale (NT) */
 } PDB32;
 
+/* PDB <-> Process id conversion macros */
+#define PROCESS_OBFUSCATOR     ((DWORD)0xdeadbeef)
+#define PROCESS_ID_TO_PDB(id)  ((PDB32 *)((id) ^ PROCESS_OBFUSCATOR))
+#define PDB_TO_PROCESS_ID(pdb) ((DWORD)(pdb) ^ PROCESS_OBFUSCATOR)
+
+/* scheduler/process.c */
 extern HANDLE32 PROCESS_AllocHandle( K32OBJ *ptr, DWORD flags);
 extern K32OBJ *PROCESS_GetObjPtr( HANDLE32 handle, K32OBJ_TYPE type );
 extern BOOL32 PROCESS_SetObjPtr( HANDLE32 handle, K32OBJ *ptr, DWORD flags );
-
 extern PDB32 *PROCESS_Create( TDB *pTask, LPCSTR cmd_line );
-extern void PROCESS_Destroy( K32OBJ *ptr );
-
 extern PDB32 *pCurrentProcess;
 
+/* scheduler/event.c */
+extern void EVENT_Set( K32OBJ *obj );
+extern K32OBJ *EVENT_Create( BOOL32 manual_reset, BOOL32 initial_state );
+
 #endif  /* __WINE_PROCESS_H */
diff --git a/include/shlobj.h b/include/shlobj.h
index d51a190..35b23cc 100644
--- a/include/shlobj.h
+++ b/include/shlobj.h
@@ -197,7 +197,7 @@
 typedef struct IShellLink IShellLink,*LPSHELLLINK;
 typedef struct IShellLink_VTable
 {
-    // *** IUnknown methods ***
+    /* *** IUnknown methods *** */
     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
     STDMETHOD_(ULONG,Release) (THIS) PURE;
diff --git a/include/struct32.h b/include/struct32.h
index 70875bf..79f1b5f 100644
--- a/include/struct32.h
+++ b/include/struct32.h
@@ -1,7 +1,7 @@
 /* Structure definitions for Win32 -- used only internally */
 #ifndef __WINE__STRUCT32_H
 #define __WINE__STRUCT32_H
-#include "handle32.h"
+#include "windows.h"
 
 extern void STRUCT32_MINMAXINFO32to16( const MINMAXINFO32*, MINMAXINFO16* );
 extern void STRUCT32_MINMAXINFO16to32( const MINMAXINFO16*, MINMAXINFO32* );
diff --git a/include/syscolor.h b/include/syscolor.h
deleted file mode 100644
index 7845858..0000000
--- a/include/syscolor.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * System color objects
- *
- * Copyright  Alexandre Julliard, 1994
- */
-
-#ifndef __WINE_SYSCOLOR_H
-#define __WINE_SYSCOLOR_H
-
-#include "windows.h"
-
-struct SysColorObjects
-{
-    HBRUSH32 hbrushScrollbar;        /* COLOR_SCROLLBAR           */
-    HBRUSH32 hbrushBackground;       /* COLOR_BACKGROUND          */
-    HBRUSH32 hbrushActiveCaption;    /* COLOR_ACTIVECAPTION       */
-    HBRUSH32 hbrushInactiveCaption;  /* COLOR_INACTIVECAPTION     */
-    HBRUSH32 hbrushMenu;             /* COLOR_MENU                */
-    HBRUSH32 hbrushWindow;           /* COLOR_WINDOW              */
-    HBRUSH32 hbrushWindowFrame;      /* COLOR_WINDOWFRAME         */
-    HBRUSH32 hbrushMenuText;         /* COLOR_MENUTEXT            */
-    HBRUSH32 hbrushWindowText;       /* COLOR_WINDOWTEXT          */
-    HBRUSH32 hbrushCaptionText;      /* COLOR_CAPTIONTEXT         */
-    HBRUSH32 hbrushActiveBorder;     /* COLOR_ACTIVEBORDER        */
-    HBRUSH32 hbrushInactiveBorder;   /* COLOR_INACTIVEBORDER      */
-    HBRUSH32 hbrushAppWorkspace;     /* COLOR_APPWORKSPACE        */
-    HBRUSH32 hbrushHighlight;        /* COLOR_HIGHLIGHT           */
-    HBRUSH32 hbrushHighlightText;    /* COLOR_HIGHLIGHTTEXT       */
-    HBRUSH32 hbrushBtnFace;          /* COLOR_BTNFACE             */
-    HBRUSH32 hbrushBtnShadow;        /* COLOR_BTNSHADOW           */
-    HBRUSH32 hbrushGrayText;         /* COLOR_GRAYTEXT            */
-    HBRUSH32 hbrushBtnText;          /* COLOR_BTNTEXT             */
-    HBRUSH32 hbrushInactiveCaptionText; /* COLOR_INACTIVECAPTIONTEXT */
-    HBRUSH32 hbrushBtnHighlight;     /* COLOR_BTNHIGHLIGHT        */
-    HBRUSH32 hbrush3DDkShadow;       /* COLOR_3DDKSHADOW          */
-    HBRUSH32 hbrush3DLight;          /* COLOR_3DLIGHT             */
-    HBRUSH32 hbrushInfoText;         /* COLOR_INFOTEXT            */
-    HBRUSH32 hbrushInfoBk;           /* COLOR_INFOBK              */
-
-    HPEN32   hpenWindowFrame;        /* COLOR_WINDOWFRAME         */
-    HPEN32   hpenWindowText;         /* COLOR_WINDOWTEXT          */
-};
-
-extern void SYSCOLOR_Init(void);
-extern struct SysColorObjects sysColorObjects;
-
-#endif  /* __WINE_SYSCOLOR_H */
diff --git a/include/sysmetrics.h b/include/sysmetrics.h
index b2f7e35..a398235 100644
--- a/include/sysmetrics.h
+++ b/include/sysmetrics.h
@@ -129,7 +129,9 @@
 #define SYSMETRICS_MIDEASTENABLED       sysMetrics[SM_MIDEASTENABLED]       /* 74 */
 #define SYSMETRICS_MOUSEWHEELPRESENT    sysMetrics[SM_MOUSEWHEELPRESENT]    /* 75 */
 
-extern void SYSMETRICS_Init(void);
+extern void SYSMETRICS_Init(void);  /* sysmetrics.c */
 extern short sysMetrics[SM_CMETRICS+1];
 
+extern void SYSCOLOR_Init(void);  /* syscolor.c */
+
 #endif  /* __WINE_SYSMETRICS_H */
diff --git a/include/thread.h b/include/thread.h
index 347019e..4e9b61f 100644
--- a/include/thread.h
+++ b/include/thread.h
@@ -7,8 +7,10 @@
 #ifndef __WINE_THREAD_H
 #define __WINE_THREAD_H
 
-#include "process.h"
+#include "k32obj.h"
+#include "windows.h"
 #include "winnt.h"
+#include "selectors.h"  /* for SET_FS */
 
 /* Thread exception block */
 typedef struct _TEB
@@ -30,58 +32,100 @@
     LPVOID      *tls_ptr;        /* 2c Pointer to TLS array */
 } TEB;
 
+/* Event waiting structure */
+typedef struct
+{
+    DWORD         count;     /* Count of valid objects */
+    DWORD         signaled;  /* Index of signaled object (or WAIT_FAILED)*/
+    BOOL32        wait_all;  /* Wait for all objects flag */
+    K32OBJ       *objs[MAXIMUM_WAIT_OBJECTS];  /* Object pointers */
+} WAIT_STRUCT;
+
+struct _PDB32;
+
 /* Thread database */
 typedef struct _THDB
 {
-    K32OBJ       header;         /*  00 Kernel object header */
-    PDB32       *process;        /*  08 Process owning this thread */
-    K32OBJ      *event;          /*  0c Thread event */
-    TEB          teb;            /*  10 Thread exception block */
-    PDB32       *process2;       /*  40 Same as offset 08 (?) */
-    DWORD        flags;          /*  44 Flags */
-    DWORD        exit_code;      /*  48 Termination status */
-    WORD         teb_sel;        /*  4c Selector to TEB */
-    WORD         emu_sel;        /*  4e 80387 emulator selector */
-    DWORD        unknown1;       /*  50 Unknown */
-    void        *wait_list;      /*  54 Event waiting list */
-    DWORD        unknown2;       /*  58 Unknown */
-    void        *ring0_thread;   /*  5c Pointer to ring 0 thread */
-    void        *ptdbx;          /*  60 Pointer to TDBX structure */
-    void        *stack_base;     /*  64 Base of the stack */
-    void        *exit_stack;     /*  68 Stack pointer on thread exit */
-    void        *emu_data;       /*  6c Related to 80387 emulation */
-    DWORD        last_error;     /*  70 Last error code */
-    void        *debugger_CB;    /*  74 Debugger context block */
-    DWORD        debug_thread;   /*  78 Thread debugging this one (?) */
-    void        *pcontext;       /*  7c Thread register context */
-    DWORD        unknown3[3];    /*  80 Unknown */
-    WORD         current_ss;     /*  8c Another 16-bit stack selector */
-    WORD         pad2;           /*  8e */
-    void        *ss_table;       /*  90 Pointer to info about 16-bit stack */
-    WORD         thunk_ss;       /*  94 Yet another 16-bit stack selector */
-    WORD         pad3;           /*  96 */
-    LPVOID       tls_array[64];  /*  98 Thread local storage */
-    DWORD        delta_priority; /* 198 Priority delta */
-    DWORD        unknown4[7];    /* 19c Unknown */
-    void        *create_data;    /* 1b8 Pointer to creation structure */
-    DWORD        suspend_count;  /* 1bc SuspendThread() counter */
-    DWORD        unknown5[9];    /* 1c0 Unknown */
-    K32OBJ      *crit_section;   /* 1e4 Some critical section */
-    K32OBJ      *win16_mutex;    /* 1e8 Pointer to Win16 mutex */
-    K32OBJ      *win32_mutex;    /* 1ec Pointer to KERNEL32 mutex */
-    K32OBJ      *crit_section2;  /* 1f0 Another critical section */
-    DWORD        unknown6[3];    /* 1f4 Unknown */
+    K32OBJ         header;         /*  00 Kernel object header */
+    struct _PDB32 *process;        /*  08 Process owning this thread */
+    K32OBJ        *event;          /*  0c Thread event */
+    TEB            teb;            /*  10 Thread exception block */
+    struct _PDB32 *process2;       /*  40 Same as offset 08 (?) */
+    DWORD          flags;          /*  44 Flags */
+    DWORD          exit_code;      /*  48 Termination status */
+    WORD           teb_sel;        /*  4c Selector to TEB */
+    WORD           emu_sel;        /*  4e 80387 emulator selector */
+    DWORD          unknown1;       /*  50 Unknown */
+    WAIT_STRUCT   *wait_list;      /*  54 Event waiting list */
+    DWORD          unknown2;       /*  58 Unknown */
+    void          *ring0_thread;   /*  5c Pointer to ring 0 thread */
+    void          *ptdbx;          /*  60 Pointer to TDBX structure */
+    void          *stack_base;     /*  64 Base of the stack */
+    void          *exit_stack;     /*  68 Stack pointer on thread exit */
+    void          *emu_data;       /*  6c Related to 80387 emulation */
+    DWORD          last_error;     /*  70 Last error code */
+    void          *debugger_CB;    /*  74 Debugger context block */
+    DWORD          debug_thread;   /*  78 Thread debugging this one (?) */
+    void          *pcontext;       /*  7c Thread register context */
+    DWORD          unknown3[3];    /*  80 Unknown */
+    WORD           current_ss;     /*  8c Another 16-bit stack selector */
+    WORD           pad2;           /*  8e */
+    void          *ss_table;       /*  90 Pointer to info about 16-bit stack */
+    WORD           thunk_ss;       /*  94 Yet another 16-bit stack selector */
+    WORD           pad3;           /*  96 */
+    LPVOID         tls_array[64];  /*  98 Thread local storage */
+    DWORD          delta_priority; /* 198 Priority delta */
+    DWORD          unknown4[7];    /* 19c Unknown */
+    void          *create_data;    /* 1b8 Pointer to creation structure */
+    DWORD          suspend_count;  /* 1bc SuspendThread() counter */
+    void          *entry_point;    /* 1c0 Thread entry point (was: unknown) */
+    void          *entry_arg;      /* 1c4 Entry point arg (was: unknown) */
+    int            unix_pid;       /* 1c8 Unix thread pid (was: unknown) */
+    DWORD          unknown5[6];    /* 1cc Unknown */
+    K32OBJ        *crit_section;   /* 1e4 Some critical section */
+    K32OBJ        *win16_mutex;    /* 1e8 Pointer to Win16 mutex */
+    K32OBJ        *win32_mutex;    /* 1ec Pointer to KERNEL32 mutex */
+    K32OBJ        *crit_section2;  /* 1f0 Another critical section */
+    DWORD          unknown6[3];    /* 1f4 Unknown */
     /* The following are Wine-specific fields */
-    CONTEXT      context;        /* 200 Thread context */
+    CONTEXT        context;        /* 200 Thread context */
+    WAIT_STRUCT    wait_struct;    /*     Event wait structure */
 } THDB;
 
+/* Thread queue entry */
+typedef struct _THREAD_ENTRY
+{
+    THDB                 *thread;
+    struct _THREAD_ENTRY *next;
+} THREAD_ENTRY;
 
-extern THDB *THREAD_Create( PDB32 *pdb, DWORD stack_size,
-                            LPTHREAD_START_ROUTINE start_addr );
-extern void THREAD_Destroy( K32OBJ *ptr );
-extern THDB *THREAD_Current(void);
-extern THDB *THREAD_SwitchThread( CONTEXT *context );
+/* A thread queue is a circular list; a THREAD_QUEUE is a pointer */
+/* to the end of the queue (i.e. where we add elements) */
+typedef THREAD_ENTRY *THREAD_QUEUE;
 
+/* THDB <-> Thread id conversion macros */
+#define THREAD_OBFUSCATOR       ((DWORD)0xdeadbeef)
+#define THREAD_ID_TO_THDB(id)   ((THDB *)((id) ^ THREAD_OBFUSCATOR))
+#define THDB_TO_THREAD_ID(thdb) ((DWORD)(thdb) ^ THREAD_OBFUSCATOR)
+
+#ifdef __i386__
+/* On the i386, the current thread is in the %fs register */
+# define SET_CUR_THREAD(thdb) SET_FS((thdb)->teb_sel)
+#else
 extern THDB *pCurrentThread;
+# define SET_CUR_THREAD(thdb) (pCurrentThread = (thdb))
+#endif  /* __i386__ */
+
+
+/* scheduler/thread.c */
+extern THDB *THREAD_Create( struct _PDB32 *pdb, DWORD stack_size,
+                            LPTHREAD_START_ROUTINE start_addr, LPVOID param );
+extern THDB *THREAD_Current(void);
+extern void THREAD_AddQueue( THREAD_QUEUE *queue, THDB *thread );
+extern void THREAD_RemoveQueue( THREAD_QUEUE *queue, THDB *thread );
+
+/* scheduler/synchro.c */
+extern void SYNC_WaitForCondition( WAIT_STRUCT *wait, DWORD timeout );
+extern void SYNC_WakeUp( THREAD_QUEUE *queue, DWORD max );
 
 #endif  /* __WINE_THREAD_H */
diff --git a/include/version.h b/include/version.h
index d3413e2..bb64ee6 100644
--- a/include/version.h
+++ b/include/version.h
@@ -1 +1 @@
-#define WINE_RELEASE_INFO "Wine release 971221"
+#define WINE_RELEASE_INFO "Wine release 980104"
diff --git a/include/windows.h b/include/windows.h
index 86cb5b8..d9fe47d 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -5463,7 +5463,8 @@
     DWORD	dwLanguageId;
 } MSGBOXPARAMS32W,*LPMSGBOXPARAMS32W;
 
-DECL_WINELIB_TYPE_AW(MSGBOXPARAMS)
+DECL_WINELIB_TYPE_AW(MSGBOXPARAMS);
+DECL_WINELIB_TYPE_AW(LPMSGBOXPARAMS);
 
 #pragma pack(4)
 
@@ -5682,7 +5683,8 @@
 BOOL32      WINAPI EnumSystemLocales32W(LOCALE_ENUMPROC32W,DWORD);
 #define     EnumSystemLocales WINELIB_NAME_AW(EnumSystemLocales)
 BOOL32      WINAPI EnumThreadWindows(DWORD,WNDENUMPROC32,LPARAM);
-void        WINAPI ExitProcess(DWORD);
+VOID        WINAPI ExitProcess(DWORD);
+VOID        WINAPI ExitThread(DWORD);
 BOOL32      WINAPI ExitWindowsEx(UINT32,DWORD);
 DWORD       WINAPI ExpandEnvironmentStrings32A(LPCSTR,LPSTR,DWORD);
 DWORD       WINAPI ExpandEnvironmentStrings32W(LPCWSTR,LPWSTR,DWORD);
@@ -5783,6 +5785,9 @@
 DWORD       WINAPI HeapSize(HANDLE32,DWORD,LPVOID);
 BOOL32      WINAPI HeapUnlock(HANDLE32);
 BOOL32      WINAPI HeapValidate(HANDLE32,DWORD,LPCVOID);
+LONG        WINAPI InterlockedDecrement(LPLONG);
+LONG        WINAPI InterlockedExchange(LPLONG,LONG);
+LONG        WINAPI InterlockedIncrement(LPLONG);
 BOOL32      WINAPI IsDBCSLeadByteEx(UINT32,BYTE);
 BOOL32      WINAPI IsProcessorFeaturePresent(DWORD);
 BOOL32      WINAPI IsWindowUnicode(HWND32);
@@ -5802,6 +5807,7 @@
 BOOL32      WINAPI MoveFileEx32A(LPCSTR,LPCSTR,DWORD);
 BOOL32      WINAPI MoveFileEx32W(LPCWSTR,LPCWSTR,DWORD);
 #define     MoveFileEx WINELIB_NAME_AW(MoveFileEx)
+DWORD       WINAPI MsgWaitForMultipleObjects(DWORD,HANDLE32*,BOOL32,DWORD,DWORD);
 HANDLE32    WINAPI OpenEvent32A(DWORD,BOOL32,LPCSTR);
 HANDLE32    WINAPI OpenEvent32W(DWORD,BOOL32,LPCWSTR);
 #define     OpenEvent WINELIB_NAME_AW(OpenEvent)
@@ -5811,9 +5817,11 @@
 HANDLE32    WINAPI OpenMutex32A(DWORD,BOOL32,LPCSTR);
 HANDLE32    WINAPI OpenMutex32W(DWORD,BOOL32,LPCWSTR);
 #define     OpenMutex WINELIB_NAME_AW(OpenMutex)
+HANDLE32    WINAPI OpenProcess(DWORD,BOOL32,DWORD);
 HANDLE32    WINAPI OpenSemaphore32A(DWORD,BOOL32,LPCSTR);
 HANDLE32    WINAPI OpenSemaphore32W(DWORD,BOOL32,LPCWSTR);
 #define     OpenSemaphore WINELIB_NAME_AW(OpenSemaphore)
+BOOL32      WINAPI PulseEvent(HANDLE32);
 DWORD       WINAPI QueryDosDevice32A(LPCSTR,LPSTR,DWORD);
 DWORD       WINAPI QueryDosDevice32W(LPCWSTR,LPWSTR,DWORD);
 #define     QueryDosDevice WINELIB_NAME_AW(QueryDosDevice)
@@ -5843,6 +5851,7 @@
                                       LPDWORD,LPFILETIME);
 #define     RegQueryInfoKey WINELIB_NAME_AW(RegQueryInfoKey)
 BOOL32      WINAPI ReleaseSemaphore(HANDLE32,LONG,LPLONG);
+BOOL32      WINAPI ResetEvent(HANDLE32);
 VOID        WINAPI RtlFillMemory(LPVOID,UINT32,UINT32);
 VOID        WINAPI RtlMoveMemory(LPVOID,LPCVOID,UINT32);
 VOID        WINAPI RtlZeroMemory(LPVOID,UINT32);
@@ -5860,6 +5869,7 @@
 BOOL32      WINAPI SetEnvironmentVariable32A(LPCSTR,LPCSTR);
 BOOL32      WINAPI SetEnvironmentVariable32W(LPCWSTR,LPCWSTR);
 #define     SetEnvironmentVariable WINELIB_NAME_AW(SetEnvironmentVariable)
+BOOL32      WINAPI SetEvent(HANDLE32);
 VOID        WINAPI SetFileApisToANSI(void);
 VOID        WINAPI SetFileApisToOEM(void);
 DWORD       WINAPI SetFilePointer(HFILE32,LONG,LPLONG,DWORD);
@@ -5894,6 +5904,10 @@
 BOOL32      WINAPI VirtualQuery(LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
 BOOL32      WINAPI VirtualQueryEx(HANDLE32,LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
 BOOL32      WINAPI VirtualUnlock(LPVOID,DWORD);
+DWORD       WINAPI WaitForMultipleObjects(DWORD,const HANDLE32*,BOOL32,DWORD);
+DWORD       WINAPI WaitForMultipleObjectsEx(DWORD,const HANDLE32*,BOOL32,DWORD,BOOL32);
+DWORD       WINAPI WaitForSingleObject(HANDLE32,DWORD);
+DWORD       WINAPI WaitForSingleObjectEx(HANDLE32,DWORD,BOOL32);
 BOOL32      WINAPI WriteConsole32A(HANDLE32,LPCVOID,DWORD,LPDWORD,LPVOID);
 BOOL32      WINAPI WriteConsole32W(HANDLE32,LPCVOID,DWORD,LPDWORD,LPVOID);
 #define     WriteConsole WINELIB_NAME_AW(WriteConsole)
@@ -8160,6 +8174,8 @@
 
 /* Extra functions that don't exist in the Windows API */
 
+HPEN16      WINAPI GetSysColorPen16(INT16);
+HPEN32      WINAPI GetSysColorPen32(INT32);
 INT32       WINAPI LoadMessage32A(HINSTANCE32,UINT32,WORD,LPSTR,INT32);
 INT32       WINAPI LoadMessage32W(HINSTANCE32,UINT32,WORD,LPWSTR,INT32);
 SEGPTR      WINAPI WIN16_GlobalLock16(HGLOBAL16);
diff --git a/include/winerror.h b/include/winerror.h
index dd2f3f3..a0a996f 100644
--- a/include/winerror.h
+++ b/include/winerror.h
@@ -4,6 +4,12 @@
 
 extern int WIN32_LastError;
 
+#define MAKE_HRESULT(sev,fac,code) \
+    ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
+#define MAKE_SCODE(sev,fac,code) \
+        ((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
+
+
 /* ERROR_UNKNOWN is a placeholder for error conditions which haven't
  * been tested yet so we're not exactly sure what will be returned.
  * All instances of ERROR_UNKNOWN should be tested under Win95/NT
@@ -37,6 +43,8 @@
 #define ERROR_FILENAME_EXCED_RANGE  206
 #define ERROR_MORE_DATA             234
 #define ERROR_NO_MORE_ITEMS         259
+#define ERROR_NOT_OWNER             288
+#define ERROR_TOO_MANY_POSTS        298
 #define ERROR_INVALID_ADDRESS       487
 #define ERROR_CAN_NOT_COMPLETE      1003
 #define ERROR_IO_DEVICE             1117
@@ -48,11 +56,13 @@
 /* HRESULT values for OLE, SHELL and other Interface stuff */
 #define	NOERROR				0
 #define	S_OK				0
+#define	E_FAIL				0x80000008
 #define	E_UNEXPECTED			0x8000FFFF
-#define	E_OUTOFMEMORY			0x8007000E
-#define	E_INVALIDARG			0x80070057
 
 #define	OLE_E_ENUM_NOMORE		0x80040002
 #define	CLASS_E_CLASSNOTAVAILABLE	0x80040111
 
+#define	E_OUTOFMEMORY			0x8007000E
+#define	E_INVALIDARG			0x80070057
+
 #endif  /* __WINE_WINERROR_H */
diff --git a/include/winnt.h b/include/winnt.h
index 0d53299..be00784 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -194,6 +194,10 @@
 #define EXCEPTION_PRIV_INSTRUCTION      STATUS_PRIVILEGED_INSTRUCTION
 #define EXCEPTION_IN_PAGE_ERROR         STATUS_IN_PAGE_ERROR
 
+#define MAXIMUM_WAIT_OBJECTS 64
+#define MAXIMUM_SUSPEND_COUNT 127
+
+
 /*
  * Return values from the actual exception handlers
  */
diff --git a/include/winsock.h b/include/winsock.h
index edee250..ca7357c 100644
--- a/include/winsock.h
+++ b/include/winsock.h
@@ -176,7 +176,7 @@
 #define WS_SOCK_RDM        4               /* reliably-delivered message */
 #define WS_SOCK_SEQPACKET  5               /* sequenced packet stream */
 
-#define WS_SOL_SOCKET		(-1)
+#define WS_SOL_SOCKET		0xffff
 #define WS_IPPROTO_TCP		6
 
 /*
diff --git a/include/wintypes.h b/include/wintypes.h
index a5ab556..527fbcb 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -59,7 +59,7 @@
 # if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)
 #  define __stdcall __attribute__((__stdcall__))
 #  define __cdecl   __attribute__((__cdecl__))
-#  define __RESTORE_ES  __asm__ __volatile__("pushw %ds\n\tpopw %es")
+#  define __RESTORE_ES  __asm__ __volatile__("pushl %ds\n\tpopl %es")
 # else
 #  error You need gcc >= 2.7 to build Wine on a 386
 # endif  /* __GNUC__ */