
This diff has been extracted from code obtained from Jeremy Visser's website:

  http://jeremy.visser.name/2009/01/15/parallels-wined3d-code-download/

which in turn was obtained from Stefan Dösinger:

  http://84.112.174.163/~stefan/WineD3D-0.9.36-Parallels.zip

who obtained it directly from Parallels in July 2nd, 2007:

  http://wiki.winehq.org/Parallels

It is therefore copyrighted by Parallels and licensed under the GNU LGPL

Note: some useless stuff such as support files for compiling with MSVC has
      been removed, and all added code was processed with "fromdos" to cleanup
      the printer chair return control bytes.

diff -Nur wine-0.9.36/dlls/d3d8/d3d8_main.c parallels/dlls/d3d8/d3d8_main.c
--- wine-0.9.36/dlls/d3d8/d3d8_main.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d8/d3d8_main.c	2009-01-29 12:56:04.000000000 +0100
@@ -24,35 +24,176 @@
 #include "d3d8_private.h"
 #include "wine/debug.h"
 
+typedef IWineD3D* (WINAPI *fnWineDirect3DCreate)(UINT, UINT, IUnknown *);
+
+static HMODULE hWineD3D = (HMODULE) -1;
+static fnWineDirect3DCreate pWineDirect3DCreate;
+
 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
 
+#ifdef WINE_NATIVEWIN32
+static HMODULE hD3D8;
+
+BOOL (WINAPI *pCheckFullscreen)();
+HRESULT (WINAPI *pDebugSetMute)(void);
+IDirect3D8* (WINAPI *pDirect3DCreate8)(UINT SDKVersion);
+HRESULT (WINAPI *pValidateVertexShader)(
+    DWORD* vertexshader, DWORD* reserved1, DWORD* reserved2, int bool, DWORD* toto);
+HRESULT (WINAPI *pValidatePixelShader)(
+    DWORD* pixelshader, DWORD* reserved1, int bool, DWORD* toto);
+
+BOOL
+IsPassthrough()
+{
+    if (!hD3D8)
+        return FALSE;
+    if (hD3D8 != (HMODULE) -1)
+        return TRUE;
+    hD3D8 = LoadLibraryA("d3d8.sav");
+    if (hD3D8) {
+#define getproc(x) *(FARPROC *)&p##x = GetProcAddress(hD3D8, #x)
+        getproc(CheckFullscreen);
+        getproc(DebugSetMute);
+        getproc(Direct3DCreate8);
+        getproc(ValidateVertexShader);
+        getproc(ValidatePixelShader);
+#undef getproc
+    }
+    return hD3D8 != NULL;
+}
+#endif
+
 HRESULT WINAPI D3D8GetSWInfo(void) {
     FIXME("(void): stub\n");
     return 0;
 }
 
+BOOL WINAPI
+CheckFullscreen()
+{
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pCheckFullscreen();
+#endif
+    return FALSE;
+}
+
 void WINAPI DebugSetMute(void) {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        pDebugSetMute();
+#endif
     /* nothing to do */
 }
 
 IDirect3D8* WINAPI Direct3DCreate8(UINT SDKVersion) {
-    IDirect3D8Impl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3D8Impl));
+    IDirect3D8Impl* object;
 
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirect3DCreate8(SDKVersion);
+#endif
+    if (hWineD3D == (HMODULE) -1)
+    {
+        hWineD3D = LoadLibraryA("wined3d");
+        if (hWineD3D)
+            pWineDirect3DCreate = (fnWineDirect3DCreate) GetProcAddress(hWineD3D, "WineDirect3DCreate");
+    }
+
+    if (!hWineD3D)
+    {
+        ERR("Couldn't load WineD3D - OpenGL libs not present?\n");
+        return NULL;
+    }
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3D8Impl));
     object->lpVtbl = &Direct3D8_Vtbl;
     object->ref = 1;
-    object->WineD3D = WineDirect3DCreate(SDKVersion, 8, (IUnknown *)object);
+    object->WineD3D = pWineDirect3DCreate(SDKVersion, 8, (IUnknown *)object);
 
     TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
 
     return (IDirect3D8*) object;
 }
 
+/***********************************************************************
+ * get_config_key
+ *
+ * Reads a config key from the registry. Taken from WineD3D
+ *
+ ***********************************************************************/
+static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
+{
+    if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
+    if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
+    return ERROR_FILE_NOT_FOUND;
+}
+
 /* At process attach */
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
 {
     TRACE("fdwReason=%d\n", fdwReason);
-    if (fdwReason == DLL_PROCESS_ATTACH)
-        DisableThreadLibraryCalls(hInstDLL);
+    if (fdwReason == DLL_PROCESS_ATTACH) {
+        char buffer[MAX_PATH+64];
+        DWORD size = sizeof(buffer);
+        HKEY hkey = 0;
+        HKEY appkey = 0;
+        DWORD len;
+
+#if defined(WINE_NATIVEWIN32) && !defined(NDEBUG)
+        debug_init();
+#endif
+       DisableThreadLibraryCalls(hInstDLL);
+
+       /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
+       if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey )
+           && RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Direct3D", &hkey ) )
+           hkey = 0;
+
+       len = GetModuleFileNameA( 0, buffer, MAX_PATH );
+       if (len && len < MAX_PATH)
+       {
+            char *p, *appname = buffer;
+            if ((p = strrchr( appname, '/' ))) appname = p + 1;
+            if ((p = strrchr( appname, '\\' ))) appname = p + 1;
+            TRACE("appname = [%s]\n", appname);
+            memmove(
+                buffer + strlen( "Software\\Wine\\AppDefaults\\" ),
+                appname, strlen( appname ) + 1);
+            memcpy(
+                buffer, "Software\\Wine\\AppDefaults\\",
+                strlen( "Software\\Wine\\AppDefaults\\" ));
+            strcat( buffer, "\\Direct3D" );
+
+            /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
+            if (RegOpenKeyA( HKEY_CURRENT_USER, buffer, &appkey )
+                && RegOpenKeyA( HKEY_LOCAL_MACHINE, buffer, &appkey ))
+                appkey = 0;
+       }
+
+       if ( 0 != hkey || 0 != appkey )
+       {
+#ifdef WINE_NATIVEWIN32
+            if ( !get_config_key( hkey, appkey, "Passthrough", buffer, size) )
+            {
+                if (!strcmp(buffer,"true") || !strcmp(buffer,"yes"))
+                {
+                    TRACE("Passthrough mode\n");
+                    hD3D8 = (HMODULE) -1;
+                }
+            }
+#endif
+        }
+    }
+    else if (fdwReason == DLL_PROCESS_DETACH)
+    {
+        if (hWineD3D && hWineD3D != (HMODULE) -1)
+            FreeLibrary(hWineD3D);
+#ifdef WINE_NATIVEWIN32
+        if (hD3D8 && hD3D8 != (HMODULE) -1)
+            FreeLibrary(hD3D8);
+#endif
+    }
 
     return TRUE;
 }
@@ -67,6 +208,11 @@
 HRESULT WINAPI ValidateVertexShader(DWORD* vertexshader, DWORD* reserved1, DWORD* reserved2, int bool, DWORD* toto)
 { 
   HRESULT ret;
+
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pValidateVertexShader(vertexshader, reserved1, reserved2, bool, toto);
+#endif
   FIXME("(%p %p %p %d %p): stub\n", vertexshader, reserved1, reserved2, bool, toto);
 
   if (!vertexshader)
@@ -97,6 +243,11 @@
 HRESULT WINAPI ValidatePixelShader(DWORD* pixelshader, DWORD* reserved1, int bool, DWORD* toto)
 {
   HRESULT ret;
+
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pValidatePixelShader(pixelshader, reserved1, bool, toto);
+#endif
   FIXME("(%p %p %d %p): stub\n", pixelshader, reserved1, bool, toto);
   
   if (!pixelshader)
diff -Nur wine-0.9.36/dlls/d3d8/d3d8_private.h parallels/dlls/d3d8/d3d8_private.h
--- wine-0.9.36/dlls/d3d8/d3d8_private.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d8/d3d8_private.h	2009-01-29 12:56:05.000000000 +0100
@@ -28,9 +28,14 @@
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
 #define COBJMACROS
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winuser.h"
+# include "wingdi.h"
+#else
+# include <windows.h>
+#endif
 #include "wine/debug.h"
 #include "d3d8.h"
 #include "wine/wined3d_interface.h"
diff -Nur wine-0.9.36/dlls/d3d8/device.c parallels/dlls/d3d8/device.c
--- wine-0.9.36/dlls/d3d8/device.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d8/device.c	2009-01-29 12:56:04.000000000 +0100
@@ -22,15 +22,6 @@
 #include "config.h"
 
 #include <math.h>
-#include <stdarg.h>
-
-#define NONAMELESSUNION
-#define NONAMELESSSTRUCT
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "wingdi.h"
-#include "wine/debug.h"
 
 #include "d3d8_private.h"
 
@@ -205,6 +196,7 @@
     return IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,(IWineD3DSurface*)pSurface->wineD3DSurface);
 }
 
+/* XXX DX9.0 SDK suggests int for coordinates */
 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     TRACE("(%p) Relay\n", This);
@@ -1678,7 +1670,7 @@
     IDirect3DDevice8Impl_GetDisplayMode,
     IDirect3DDevice8Impl_GetCreationParameters,
     IDirect3DDevice8Impl_SetCursorProperties,
-    IDirect3DDevice8Impl_SetCursorPosition,
+    IDirect3DDevice8Impl_SetCursorPosition, /* XXX DX9.0 SDK suggests int for coordinates */
     IDirect3DDevice8Impl_ShowCursor,
     IDirect3DDevice8Impl_CreateAdditionalSwapChain,
     IDirect3DDevice8Impl_Reset,
diff -Nur wine-0.9.36/dlls/d3d8/directx.c parallels/dlls/d3d8/directx.c
--- wine-0.9.36/dlls/d3d8/directx.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d8/directx.c	2009-01-29 12:56:05.000000000 +0100
@@ -22,19 +22,10 @@
 
 #include "config.h"
 
-#include <stdarg.h>
+#include "d3d8_private.h"
 
-#define NONAMELESSUNION
-#define NONAMELESSSTRUCT
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "wine/debug.h"
 #include "wine/unicode.h"
 
-#include "d3d8_private.h"
-
 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
 
 /* IDirect3D IUnknown parts follow: */
diff -Nur wine-0.9.36/dlls/d3d8/tests/visual.c parallels/dlls/d3d8/tests/visual.c
--- wine-0.9.36/dlls/d3d8/tests/visual.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d8/tests/visual.c	2009-01-29 12:56:05.000000000 +0100
@@ -202,7 +202,7 @@
     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %s\n", DXGetErrorString8(hr));
-    hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLED_RED | D3DCOLORWRITEENABLED_GREEN | D3DCOLORWRITEENABLED_BLUE);
+    hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %s\n", DXGetErrorString8(hr));
 
     hr = IDirect3DDevice8_SetVertexShader(device, fvf);
diff -Nur wine-0.9.36/dlls/d3d8/vertexdeclaration.c parallels/dlls/d3d8/vertexdeclaration.c
--- wine-0.9.36/dlls/d3d8/vertexdeclaration.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d8/vertexdeclaration.c	2009-01-29 12:56:05.000000000 +0100
@@ -69,7 +69,12 @@
     return ref_count;
 }
 
+#ifdef WINE_NATIVEWIN32
+/* D3DVSDT_* are defines in MS headers */
+static const char *debug_d3dvsdt_type(int d3dvsdt_type)
+#else
 static const char *debug_d3dvsdt_type(D3DVSDT_TYPE d3dvsdt_type)
+#endif
 {
     switch (d3dvsdt_type)
     {
@@ -89,7 +94,12 @@
     }
 }
 
+#ifdef WINE_NATIVEWIN32
+/* D3DVSDE_* are defines in MS headers */
+static const char *debug_d3dvsde_register(int d3dvsde_register)
+#else
 static const char *debug_d3dvsde_register(D3DVSDE_REGISTER d3dvsde_register)
+#endif
 {
     switch (d3dvsde_register)
     {
diff -Nur wine-0.9.36/dlls/d3d9/d3d9_main.c parallels/dlls/d3d9/d3d9_main.c
--- wine-0.9.36/dlls/d3d9/d3d9_main.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d9/d3d9_main.c	2009-01-29 12:56:04.000000000 +0100
@@ -25,37 +25,222 @@
 #include "initguid.h"
 #include "d3d9_private.h"
 
+typedef IWineD3D* (WINAPI *fnWineDirect3DCreate)(UINT, UINT, IUnknown *);
+
+static HMODULE hWineD3D = (HMODULE) -1;
+static fnWineDirect3DCreate pWineDirect3DCreate;
+
 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
 
 static int D3DPERF_event_level = 0;
 
+#ifdef WINE_NATIVEWIN32
+static HMODULE hD3D9;
+
+HRESULT (WINAPI *pD3D9GetSWInfo)(void);
+BOOL (WINAPI *pCheckFullscreen)();
+HRESULT (WINAPI *pDebugSetLevel)(void);
+HRESULT (WINAPI *pDebugSetMute)(void);
+IDirect3D9* (WINAPI *pDirect3DCreate9)(UINT SDKVersion);
+HRESULT (WINAPI *pDirect3DCreate9Ex)(UINT SDKVersion, VOID** ppD3D);
+
+BOOL
+IsPassthrough()
+{
+    if (!hD3D9)
+        return FALSE;
+    if (hD3D9 != (HMODULE) -1)
+        return TRUE;
+    hD3D9 = LoadLibraryA("d3d9.sav");
+    if (hD3D9) {
+#define getproc(x) *(FARPROC *)&p##x = GetProcAddress(hD3D9, #x)
+        getproc(D3D9GetSWInfo);
+        getproc(CheckFullscreen);
+        getproc(DebugSetLevel);
+        getproc(DebugSetMute);
+        getproc(Direct3DCreate9);
+        getproc(Direct3DCreate9Ex);
+#undef getproc
+    }
+    return hD3D9 != NULL;
+}
+#endif
+
 HRESULT WINAPI D3D9GetSWInfo(void) {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pD3D9GetSWInfo();
+#endif
+    FIXME("(void): stub\n");
+    return 0;
+}
+
+BOOL WINAPI
+CheckFullscreen()
+{
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pCheckFullscreen();
+#endif
+    return FALSE;
+}
+
+HRESULT WINAPI DebugSetLevel(void) {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDebugSetLevel();
+#endif
     FIXME("(void): stub\n");
     return 0;
 }
 
-void WINAPI DebugSetMute(void) {
-    /* nothing to do */
+HRESULT WINAPI DebugSetMute(void) {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDebugSetMute();
+#endif
+    FIXME("(void): stub\n");
+    return 0;
 }
 
 IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion) {
-    IDirect3D9Impl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3D9Impl));
+    IDirect3D9Impl* object;
+
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirect3DCreate9(SDKVersion);
+#endif
+    if (hWineD3D == (HMODULE) -1)
+    {
+        hWineD3D = LoadLibraryA("wined3d");
+        if (hWineD3D)
+            pWineDirect3DCreate = (fnWineDirect3DCreate) GetProcAddress(hWineD3D, "WineDirect3DCreate");
+    }
+
+    if (!hWineD3D)
+    {
+        ERR("Couldn't load WineD3D - OpenGL libs not present?\n");
+        return NULL;
+    }
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3D9Impl));
 
     object->lpVtbl = &Direct3D9_Vtbl;
     object->ref = 1;
-    object->WineD3D = WineDirect3DCreate(SDKVersion, 9, (IUnknown *)object);
+    object->WineD3D = pWineDirect3DCreate(SDKVersion, 9, (IUnknown *)object);
 
     TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
 
     return (IDirect3D9*) object;
 }
 
+HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, VOID** ppD3D) {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirect3DCreate9Ex(SDKVersion, ppD3D);
+#endif
+    TRACE("SDKVersion = %x\n", SDKVersion);
+    /* When D3D9L features are not supported (no WDDM driver installed) */
+
+    if (ppD3D)
+        *ppD3D = NULL;
+
+    return D3DERR_NOTAVAILABLE;
+}
+
+HRESULT WINAPI Direct3DShaderValidatorCreate9(void) {
+    FIXME("(void): stub\n");
+
+    return 0;
+}
+
+HRESULT WINAPI PSGPError(void) {
+    FIXME("(void): stub\n");
+
+    return 0;
+}
+
+HRESULT WINAPI PSGPSampleTexture(void) {
+    FIXME("(void): stub\n");
+
+    return 0;
+}
+
+/***********************************************************************
+ * get_config_key
+ *
+ * Reads a config key from the registry. Taken from WineD3D
+ *
+ ***********************************************************************/
+static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
+{
+    if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
+    if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
+    return ERROR_FILE_NOT_FOUND;
+}
+
 /* At process attach */
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
 {
     TRACE("fdwReason=%d\n", fdwReason);
-    if (fdwReason == DLL_PROCESS_ATTACH)
-        DisableThreadLibraryCalls(hInstDLL);
+    if (fdwReason == DLL_PROCESS_ATTACH) {
+        char buffer[MAX_PATH+64];
+        DWORD size = sizeof(buffer);
+        HKEY hkey = 0;
+        HKEY appkey = 0;
+        DWORD len;
+
+       DisableThreadLibraryCalls(hInstDLL);
+
+       /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
+       if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey )
+           && RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Direct3D", &hkey ) )
+           hkey = 0;
+
+       len = GetModuleFileNameA( 0, buffer, MAX_PATH );
+       if (len && len < MAX_PATH)
+       {
+            char *p, *appname = buffer;
+            if ((p = strrchr( appname, '/' ))) appname = p + 1;
+            if ((p = strrchr( appname, '\\' ))) appname = p + 1;
+            TRACE("appname = [%s]\n", appname);
+            memmove(
+                buffer + strlen( "Software\\Wine\\AppDefaults\\" ),
+                appname, strlen( appname ) + 1);
+            memcpy(
+                buffer, "Software\\Wine\\AppDefaults\\",
+                strlen( "Software\\Wine\\AppDefaults\\" ));
+            strcat( buffer, "\\Direct3D" );
+
+            /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
+            if (RegOpenKeyA( HKEY_CURRENT_USER, buffer, &appkey )
+                && RegOpenKeyA( HKEY_LOCAL_MACHINE, buffer, &appkey ))
+                appkey = 0;
+       }
+
+       if ( 0 != hkey || 0 != appkey )
+       {
+#ifdef WINE_NATIVEWIN32
+            if ( !get_config_key( hkey, appkey, "Passthrough", buffer, size) )
+            {
+                if (!strcmp(buffer,"true") || !strcmp(buffer,"yes"))
+                {
+                    TRACE("Passthrough mode\n");
+                    hD3D9 = (HMODULE) -1;
+                }
+            }
+#endif
+        }
+    }
+    else if (fdwReason == DLL_PROCESS_DETACH)
+    {
+        if (hWineD3D && hWineD3D != (HMODULE) -1)
+            FreeLibrary(hWineD3D);
+#ifdef WINE_NATIVEWIN32
+        if (hD3D9 && hD3D9 != (HMODULE) -1)
+            FreeLibrary(hD3D9);
+#endif
+    }
 
     return TRUE;
 }
diff -Nur wine-0.9.36/dlls/d3d9/d3d9_private.h parallels/dlls/d3d9/d3d9_private.h
--- wine-0.9.36/dlls/d3d9/d3d9_private.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/d3d9/d3d9_private.h	2009-01-29 12:56:04.000000000 +0100
@@ -28,13 +28,15 @@
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
 #define COBJMACROS
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "winuser.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "wingdi.h"
+# include "winuser.h"
+#else
+# include <windows.h>
+#endif
 #include "wine/debug.h"
-#include "wine/unicode.h"
-
 #include "d3d9.h"
 #include "wine/wined3d_interface.h"
 
diff -Nur wine-0.9.36/dlls/ddraw/clipper.c parallels/dlls/ddraw/clipper.c
--- wine-0.9.36/dlls/ddraw/clipper.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/clipper.c	2009-01-29 12:56:05.000000000 +0100
@@ -25,11 +25,13 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "ddraw.h"
-#include "winerror.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "wingdi.h"
+# include "ddraw.h"
+# include "winerror.h"
+#endif
 
 #include "ddraw_private.h"
 
diff -Nur wine-0.9.36/dlls/ddraw/ddraw.c parallels/dlls/ddraw/ddraw.c
--- wine-0.9.36/dlls/ddraw/ddraw.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/ddraw.c	2009-01-29 12:56:05.000000000 +0100
@@ -30,11 +30,13 @@
 #define COBJMACROS
 #define NONAMELESSUNION
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -117,11 +119,13 @@
         *obj = ICOM_INTERFACE(This, IDirectDraw4);
         TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
     }
+#ifndef WINE_NATIVEWIN32
     else if ( IsEqualGUID( &IID_IDirectDraw3, refiid ) )
     {
         *obj = ICOM_INTERFACE(This, IDirectDraw3);
         TRACE("(%p) Returning IDirectDraw3 interface at %p\n", This, *obj);
     }
+#endif
     else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
     {
         *obj = ICOM_INTERFACE(This, IDirectDraw2);
@@ -2189,7 +2193,8 @@
         if( (hr == D3D_OK) && (window != 0) )
         {
             RECT rect;
-            if(GetWindowRect(window, &rect) )
+            /* if(GetWindowRect(window, &rect)) */
+            if(GetClientRect(window, &rect))
             {
                 /* This is a hack until I find a better solution */
                 if( (rect.right - rect.left) <= 1 ||
@@ -2269,7 +2274,7 @@
      */
     if(DDSD->dwFlags & DDSD_BACKBUFFERCOUNT)
     {
-        extra_surfaces = DDSD->dwBackBufferCount;
+        extra_surfaces = DDSD->u5.dwBackBufferCount;
         desc2.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; /* It's not a front buffer */
         desc2.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
     }
@@ -2474,7 +2479,7 @@
     static const struct compare_info compare[] =
     {
         CMP(ALPHABITDEPTH, dwAlphaBitDepth),
-        CMP(BACKBUFFERCOUNT, dwBackBufferCount),
+        CMP(BACKBUFFERCOUNT, u5.dwBackBufferCount),
         CMP(CAPS, ddsCaps),
         CMP(CKDESTBLT, ddckCKDestBlt),
         CMP(CKDESTOVERLAY, u3 /* ddckCKDestOverlay */),
@@ -2827,7 +2832,7 @@
     localParameters.BackBufferWidth                 = primary->surface_desc.dwWidth;
     localParameters.BackBufferHeight                = primary->surface_desc.dwHeight;
     localParameters.BackBufferFormat                = PixelFormat_DD2WineD3D(&primary->surface_desc.u4.ddpfPixelFormat);
-    localParameters.BackBufferCount                 = (primary->surface_desc.dwFlags & DDSD_BACKBUFFERCOUNT) ? primary->surface_desc.dwBackBufferCount : 0;
+    localParameters.BackBufferCount                 = (primary->surface_desc.dwFlags & DDSD_BACKBUFFERCOUNT) ? primary->surface_desc.u5.dwBackBufferCount : 0;
     localParameters.MultiSampleType                 = WINED3DMULTISAMPLE_NONE;
     localParameters.MultiSampleQuality              = 0;
     localParameters.SwapEffect                      = WINED3DSWAPEFFECT_COPY;
@@ -2881,6 +2886,15 @@
                         IUnknown *UnkOuter)
 {
     IDirectDrawClipperImpl* object;
+
+#ifdef WINE_NATIVEWIN32
+    extern BOOL IsPassthrough();
+    extern HRESULT (WINAPI *pDirectDrawCreateClipper)(
+        DWORD Flags, IDirectDrawClipper **Clipper, IUnknown *UnkOuter);
+
+    if (IsPassthrough())
+        return pDirectDrawCreateClipper(Flags, Clipper, UnkOuter);
+#endif
     TRACE("(%08x,%p,%p)\n", Flags, Clipper, UnkOuter);
 
     if (UnkOuter != NULL) return CLASS_E_NOAGGREGATION;
diff -Nur wine-0.9.36/dlls/ddraw/ddraw_private.h parallels/dlls/ddraw/ddraw_private.h
--- wine-0.9.36/dlls/ddraw/ddraw_private.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/ddraw_private.h	2009-01-29 12:56:05.000000000 +0100
@@ -24,11 +24,15 @@
 #include <stdarg.h>
 #include <stdio.h>
 
-#include "windef.h"
-#include "winbase.h"
-#include "wtypes.h"
-#include "wingdi.h"
-#include "winuser.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "wtypes.h"
+# include "wingdi.h"
+# include "winuser.h"
+#else
+# include <windows.h>
+#endif
 #include "ddraw.h"
 #include "ddrawi.h"
 #include "d3d.h"
@@ -94,7 +98,9 @@
     /* IUnknown fields */
     ICOM_VFIELD_MULTI(IDirectDraw7);
     ICOM_VFIELD_MULTI(IDirectDraw4);
+#ifndef WINE_NATIVEWIN32
     ICOM_VFIELD_MULTI(IDirectDraw3);
+#endif
     ICOM_VFIELD_MULTI(IDirectDraw2);
     ICOM_VFIELD_MULTI(IDirectDraw);
     ICOM_VFIELD_MULTI(IDirect3D7);
@@ -163,7 +169,9 @@
 /* Declare the VTables. They can be found ddraw.c */
 const IDirectDraw7Vtbl IDirectDraw7_Vtbl;
 const IDirectDraw4Vtbl IDirectDraw4_Vtbl;
+#ifndef WINE_NATIVEWIN32
 const IDirectDraw3Vtbl IDirectDraw3_Vtbl;
+#endif
 const IDirectDraw2Vtbl IDirectDraw2_Vtbl;
 const IDirectDrawVtbl  IDirectDraw1_Vtbl;
 
diff -Nur wine-0.9.36/dlls/ddraw/ddraw_thunks.c parallels/dlls/ddraw/ddraw_thunks.c
--- wine-0.9.36/dlls/ddraw/ddraw_thunks.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/ddraw_thunks.c	2009-01-29 12:56:05.000000000 +0100
@@ -27,11 +27,13 @@
 #define COBJMACROS
 #define NONAMELESSUNION
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -62,6 +64,7 @@
 				       iid, ppObj);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_QueryInterface(LPDIRECTDRAW3 This, REFIID iid, LPVOID *ppObj)
 {
@@ -70,6 +73,7 @@
 							  IDirectDraw7, This),
 				       iid, ppObj);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_QueryInterface(LPDIRECTDRAW4 This, REFIID iid, LPVOID *ppObj)
@@ -106,6 +110,7 @@
     return ref;
 }
 
+#ifndef WINE_NATIVEWIN32
 static ULONG WINAPI
 IDirectDraw3Impl_AddRef(LPDIRECTDRAW3 iface)
 {
@@ -118,6 +123,7 @@
 
     return ref;
 }
+#endif
 
 static ULONG WINAPI
 IDirectDraw4Impl_AddRef(LPDIRECTDRAW4 iface)
@@ -166,6 +172,7 @@
     return ref;
 }
 
+#ifndef WINE_NATIVEWIN32
 static ULONG WINAPI
 IDirectDraw3Impl_Release(LPDIRECTDRAW3 iface)
 {
@@ -182,6 +189,7 @@
 
     return ref;
 }
+#endif
 
 static ULONG WINAPI
 IDirectDraw4Impl_Release(LPDIRECTDRAW4 iface)
@@ -216,13 +224,15 @@
 						   This));
 }
 
-    static HRESULT WINAPI
+#ifndef WINE_NATIVEWIN32
+static HRESULT WINAPI
 IDirectDraw3Impl_Compact(LPDIRECTDRAW3 This)
 {
     return IDirectDraw7_Compact(COM_INTERFACE_CAST(IDirectDrawImpl,
 						   IDirectDraw3, IDirectDraw7,
 						   This));
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_Compact(LPDIRECTDRAW4 This)
@@ -256,6 +266,7 @@
 				      dwFlags, ppClipper, pUnkOuter);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_CreateClipper(LPDIRECTDRAW3 This, DWORD dwFlags,
 			       LPDIRECTDRAWCLIPPER *ppClipper,
@@ -267,6 +278,7 @@
 							 This),
 				      dwFlags, ppClipper, pUnkOuter);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_CreateClipper(LPDIRECTDRAW4 This, DWORD dwFlags,
@@ -329,6 +341,7 @@
     return hr;
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_CreatePalette(LPDIRECTDRAW3 This, DWORD dwFlags,
 			       LPPALETTEENTRY pEntries,
@@ -353,6 +366,7 @@
     }
     return hr;
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_CreatePalette(LPDIRECTDRAW4 This, DWORD dwFlags,
@@ -451,6 +465,7 @@
     return hr;
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_CreateSurface(LPDIRECTDRAW3 This, LPDDSURFACEDESC pSDesc,
 			       LPDIRECTDRAWSURFACE *ppSurface,
@@ -486,6 +501,7 @@
 
     return hr;
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
@@ -564,6 +580,7 @@
     return hr;
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_DuplicateSurface(LPDIRECTDRAW3 This, LPDIRECTDRAWSURFACE pSrc,
 				  LPDIRECTDRAWSURFACE *ppDst)
@@ -587,6 +604,7 @@
 
     return hr;
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_DuplicateSurface(LPDIRECTDRAW4 This,
@@ -655,6 +673,7 @@
 					 EnumDisplayModesCallbackThunk);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_EnumDisplayModes(LPDIRECTDRAW3 This, DWORD dwFlags,
 				  LPDDSURFACEDESC pDDSD, LPVOID context,
@@ -672,6 +691,7 @@
 					 dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext,
 					 EnumDisplayModesCallbackThunk);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_EnumDisplayModes(LPDIRECTDRAW4 This, DWORD dwFlags,
@@ -740,6 +760,7 @@
 				     &cbcontext, EnumSurfacesCallbackThunk);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_EnumSurfaces(LPDIRECTDRAW3 This, DWORD dwFlags,
 			      LPDDSURFACEDESC pDDSD, LPVOID context,
@@ -756,6 +777,7 @@
 				     dwFlags, (LPDDSURFACEDESC2)pDDSD,
 				     &cbcontext, EnumSurfacesCallbackThunk);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_EnumSurfaces(LPDIRECTDRAW4 This, DWORD dwFlags,
@@ -787,6 +809,7 @@
 							    This));
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_FlipToGDISurface(LPDIRECTDRAW3 This)
 {
@@ -795,6 +818,7 @@
 							    IDirectDraw7,
 							    This));
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_FlipToGDISurface(LPDIRECTDRAW4 This)
@@ -821,6 +845,7 @@
 						   This), pDDC1, pDDC2);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetCaps(LPDIRECTDRAW3 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
 {
@@ -828,6 +853,7 @@
 						   IDirectDraw3, IDirectDraw7,
 						   This), pDDC1, pDDC2);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetCaps(LPDIRECTDRAW4 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
@@ -855,6 +881,7 @@
 				       (LPDDSURFACEDESC2)pDDSD);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetDisplayMode(LPDIRECTDRAW3 This, LPDDSURFACEDESC pDDSD)
 {
@@ -863,6 +890,7 @@
 							  IDirectDraw7, This),
 				       (LPDDSURFACEDESC2)pDDSD);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetDisplayMode(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pDDSD)
@@ -895,6 +923,7 @@
 				       lpNumCodes, lpCodes);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetFourCCCodes(LPDIRECTDRAW3 This, LPDWORD lpNumCodes,
 				LPDWORD lpCodes)
@@ -905,6 +934,7 @@
 							  This),
 				       lpNumCodes, lpCodes);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetFourCCCodes(LPDIRECTDRAW4 This, LPDWORD lpNumCodes,
@@ -955,6 +985,7 @@
     return hr;
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetGDISurface(LPDIRECTDRAW3 This, LPDIRECTDRAWSURFACE *ppSurf)
 {
@@ -973,6 +1004,7 @@
 
     return hr;
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetGDISurface(LPDIRECTDRAW4 This,
@@ -1005,6 +1037,7 @@
 					    pdwFreq);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetMonitorFrequency(LPDIRECTDRAW3 This, LPDWORD pdwFreq)
 {
@@ -1014,6 +1047,7 @@
 							       This),
 					    pdwFreq);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetMonitorFrequency(LPDIRECTDRAW4 This, LPDWORD pdwFreq)
@@ -1043,6 +1077,7 @@
 						       This), pdwLine);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetScanLine(LPDIRECTDRAW3 This, LPDWORD pdwLine)
 {
@@ -1051,6 +1086,7 @@
 						       IDirectDraw7,
 						       This), pdwLine);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetScanLine(LPDIRECTDRAW4 This, LPDWORD pdwLine)
@@ -1081,6 +1117,7 @@
 					       lpbIsInVB);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetVerticalBlankStatus(LPDIRECTDRAW3 This, LPBOOL lpbIsInVB)
 {
@@ -1090,6 +1127,7 @@
 								  This),
 					       lpbIsInVB);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetVerticalBlankStatus(LPDIRECTDRAW4 This, LPBOOL lpbIsInVB)
@@ -1123,6 +1161,7 @@
     return ret_value;
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_Initialize(LPDIRECTDRAW3 iface, LPGUID pGUID)
 {
@@ -1133,6 +1172,7 @@
 
     return ret_value;
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_Initialize(LPDIRECTDRAW4 iface, LPGUID pGUID)
@@ -1164,6 +1204,7 @@
 							      This));
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_RestoreDisplayMode(LPDIRECTDRAW3 This)
 {
@@ -1172,6 +1213,7 @@
 							      IDirectDraw7,
 							      This));
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_RestoreDisplayMode(LPDIRECTDRAW4 This)
@@ -1204,6 +1246,7 @@
 					    hWnd, dwFlags);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_SetCooperativeLevel(LPDIRECTDRAW3 This, HWND hWnd,
 				     DWORD dwFlags)
@@ -1214,6 +1257,7 @@
 							       This),
 					    hWnd, dwFlags);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_SetCooperativeLevel(LPDIRECTDRAW4 This, HWND hWnd,
@@ -1247,6 +1291,7 @@
 				       a, b, c, d, e);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_SetDisplayMode(LPDIRECTDRAW3 This, DWORD a, DWORD b, DWORD c,
 				DWORD d, DWORD e)
@@ -1257,6 +1302,7 @@
 							  This),
 				       a, b, c, d, e);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_SetDisplayMode(LPDIRECTDRAW4 This, DWORD a, DWORD b, DWORD c,
@@ -1291,6 +1337,7 @@
 					     dwFlags, hEvent);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_WaitForVerticalBlank(LPDIRECTDRAW3 This, DWORD dwFlags,
 				      HANDLE hEvent)
@@ -1301,6 +1348,7 @@
 								This),
 					     dwFlags, hEvent);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_WaitForVerticalBlank(LPDIRECTDRAW4 This, DWORD dwFlags,
@@ -1327,6 +1375,7 @@
 					   &Caps2, pdwTotal, pdwFree);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetAvailableVidMem(LPDIRECTDRAW3 This, LPDDSCAPS pCaps,
 				    LPDWORD pdwTotal, LPDWORD pdwFree)
@@ -1340,6 +1389,7 @@
 							      This),
 					   &Caps2, pdwTotal, pdwFree);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetAvailableVidMem(LPDIRECTDRAW4 This, LPDDSCAPS2 pCaps,
@@ -1352,6 +1402,7 @@
 					   pCaps, pdwTotal, pdwFree);
 }
 
+#ifndef WINE_NATIVEWIN32
 static HRESULT WINAPI
 IDirectDraw3Impl_GetSurfaceFromDC(LPDIRECTDRAW3 This, HDC hDC,
 				  LPDIRECTDRAWSURFACE *pSurf)
@@ -1362,6 +1413,7 @@
 							    This),
 					 hDC, (LPDIRECTDRAWSURFACE7 *)pSurf);
 }
+#endif
 
 static HRESULT WINAPI
 IDirectDraw4Impl_GetSurfaceFromDC(LPDIRECTDRAW4 This, HDC hDC,
@@ -1465,6 +1517,7 @@
     IDirectDraw2Impl_GetAvailableVidMem
 };
 
+#ifndef WINE_NATIVEWIN32
 const IDirectDraw3Vtbl IDirectDraw3_Vtbl =
 {
     IDirectDraw3Impl_QueryInterface,
@@ -1493,6 +1546,7 @@
     IDirectDraw3Impl_GetAvailableVidMem,
     IDirectDraw3Impl_GetSurfaceFromDC,
 };
+#endif
 
 const IDirectDraw4Vtbl IDirectDraw4_Vtbl =
 {
diff -Nur wine-0.9.36/dlls/ddraw/device.c parallels/dlls/ddraw/device.c
--- wine-0.9.36/dlls/ddraw/device.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/device.c	2009-01-29 12:56:05.000000000 +0100
@@ -28,7 +28,6 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -37,11 +36,13 @@
 
 #define COBJMACROS
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -49,6 +50,7 @@
 #include "d3d.h"
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
@@ -1307,7 +1309,7 @@
 static HRESULT WINAPI
 IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface,
                                 D3DMATRIXHANDLE D3DMatHandle,
-                                D3DMATRIX *D3DMatrix)
+                                D3DMATRIX * const D3DMatrix)
 {
     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
     TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
diff -Nur wine-0.9.36/dlls/ddraw/direct3d.c parallels/dlls/ddraw/direct3d.c
--- wine-0.9.36/dlls/ddraw/direct3d.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/direct3d.c	2009-01-29 12:56:05.000000000 +0100
@@ -18,7 +18,6 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -27,11 +26,13 @@
 
 #define COBJMACROS
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -39,6 +40,7 @@
 #include "d3d.h"
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
 
@@ -787,7 +789,7 @@
     object->wineD3DDevice = This->wineD3DDevice;
 
     /* Create an index buffer, it's needed for indexed drawing */
-    IndexBufferParent = HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl *));
+    IndexBufferParent = HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl));
     if(!IndexBufferParent)
     {
         ERR("Allocating memory for an index buffer parent failed\n");
@@ -1362,6 +1364,9 @@
     Desc123->dtcTransformCaps.dwCaps = D3DTRANSFORMCAPS_CLIP;
     Desc123->bClipping = TRUE;
     Desc123->dlcLightingCaps.dwSize = sizeof(D3DLIGHTINGCAPS);
+#ifndef D3DLIGHTCAPS_PARALLELPOINT
+#define D3DLIGHTCAPS_PARALLELPOINT 0x00000008
+#endif
     Desc123->dlcLightingCaps.dwCaps = D3DLIGHTCAPS_DIRECTIONAL | D3DLIGHTCAPS_PARALLELPOINT | D3DLIGHTCAPS_POINT | D3DLIGHTCAPS_SPOT;
     Desc123->dlcLightingCaps.dwLightingModel = D3DLIGHTINGMODEL_RGB;
     Desc123->dlcLightingCaps.dwNumLights = Desc7->dwMaxActiveLights;
diff -Nur wine-0.9.36/dlls/ddraw/executebuffer.c parallels/dlls/ddraw/executebuffer.c
--- wine-0.9.36/dlls/ddraw/executebuffer.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/executebuffer.c	2009-01-29 12:56:05.000000000 +0100
@@ -31,11 +31,13 @@
 #define COBJMACROS
 #define NONAMELESSUNION
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -144,7 +146,11 @@
 			
 		for (i = 0; i < count; i++) {
                     LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
+#ifndef WINE_NATIVEWIN32
 		    TRACE_(d3d7)("  v1: %d  v2: %d  v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
+#else
+		    TRACE_(d3d7)("  v1: %d  v2: %d  v3: %d\n",ci->v1, ci->v2, ci->v3);
+#endif
 		    TRACE_(d3d7)("  Flags : ");
 		    if (TRACE_ON(d3d7)) {
 			/* Wireframe */
@@ -165,9 +171,15 @@
 	       		    TRACE_(d3d7)("STARTFLAT(%d) ", ci->wFlags);
 	    		TRACE_(d3d7)("\n");
         	    }
-		    This->indices[(i * 3)    ] = ci->u1.v1;
-		    This->indices[(i * 3) + 1] = ci->u2.v2;
-		    This->indices[(i * 3) + 2] = ci->u3.v3;
+#ifndef WINE_NATIVEWIN32
+                    This->indices[(i * 3)    ] = ci->u1.v1;
+                    This->indices[(i * 3) + 1] = ci->u2.v2;
+                    This->indices[(i * 3) + 2] = ci->u3.v3;
+#else
+                    This->indices[(i * 3)    ] = ci->v1;
+                    This->indices[(i * 3) + 1] = ci->v2;
+                    This->indices[(i * 3) + 2] = ci->v3;
+#endif
                     instr += size;
 		}
                 /* IDirect3DDevices have color keying always enabled -
@@ -222,6 +234,7 @@
 		for (i = 0; i < count; i++) {
 		    LPD3DSTATE ci = (LPD3DSTATE) instr;
 
+#ifndef WINE_NATIVEWIN32
                     if(!ci->u2.dwArg[0]) {
                         ERR("Setting a NULL matrix handle, what should I do?\n");
                     } else if(ci->u2.dwArg[0] > lpDevice->numHandles) {
@@ -232,6 +245,18 @@
                         IDirect3DDevice7_SetTransform(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
                                                       ci->u1.drstRenderStateType, (LPD3DMATRIX) lpDevice->Handles[ci->u2.dwArg[0] - 1].ptr);
                     }
+#else
+                    if(!ci->dwArg[0]) {
+                        ERR("Setting a NULL matrix handle, what should I do?\n");
+                    } else if(ci->dwArg[0] > lpDevice->numHandles) {
+                        ERR("Handle %d is out of bounds\n", ci->dwArg[0]);
+                    } else if(lpDevice->Handles[ci->dwArg[0] - 1].type != DDrawHandle_Matrix) {
+                        ERR("Handle %d is not a matrix handle\n", ci->dwArg[0]);
+                    } else {
+                        IDirect3DDevice7_SetTransform(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
+                                                      ci->drstRenderStateType, (LPD3DMATRIX) lpDevice->Handles[ci->dwArg[0] - 1].ptr);
+                    }
+#endif
 		    instr += size;
 		}
 	    } break;
@@ -243,12 +268,23 @@
 		for (i = 0; i < count; i++) {
 		    LPD3DSTATE ci = (LPD3DSTATE) instr;
 
+#ifndef WINE_NATIVEWIN32
                     TRACE("(%08x,%08x)\n",ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
 
 		    if (!ci->u1.dlstLightStateType && (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
 			ERR("Unexpected Light State Type\n");
 		    else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) {
+
 			IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) ci->u2.dwArg[0];
+#else
+                    TRACE("(%08x,%08x)\n",ci->dlstLightStateType, ci->dwArg[0]);
+
+		    if (!ci->dlstLightStateType && (ci->dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
+			ERR("Unexpected Light State Type\n");
+		    else if (ci->dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) {
+
+			IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) ci->dwArg[0];
+#endif
 
 			if (mat != NULL) {
 			    mat->activate(mat);
@@ -256,8 +292,13 @@
 			    FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
 			}
 		    }
+#ifndef WINE_NATIVEWIN32
 		   else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */) {
 			switch (ci->u2.dwArg[0]) {
+#else
+		   else if (ci->dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */) {
+			switch (ci->dwArg[0]) {
+#endif
 			    case D3DCOLOR_MONO:
 			       ERR("DDCOLOR_MONO should not happen!\n");
 			       break;
@@ -269,7 +310,11 @@
 			}
 		    } else {
 		    	D3DRENDERSTATETYPE rs = 0;
+#ifndef WINE_NATIVEWIN32
 		    	switch (ci->u1.dlstLightStateType) {
+#else
+		    	switch (ci->dlstLightStateType) {
+#endif
 
 		    	    case D3DLIGHTSTATE_AMBIENT:       /* 2 */
 				rs = D3DRENDERSTATE_AMBIENT;
@@ -293,8 +338,13 @@
 				break;
 			}
 			
+#ifndef WINE_NATIVEWIN32
 		        IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
 	                                		rs,ci->u2.dwArg[0]);
+#else
+		        IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
+	                                		rs,ci->dwArg[0]);
+#endif
 		   }
 
 		   instr += size;
@@ -308,8 +358,13 @@
 		for (i = 0; i < count; i++) {
 		    LPD3DSTATE ci = (LPD3DSTATE) instr;
 		    
+#ifndef WINE_NATIVEWIN32
 		    IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
 						    ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
+#else
+		    IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
+						    ci->drstRenderStateType, ci->dwArg[0]);
+#endif
 
 		    instr += size;
 		}
@@ -410,6 +465,7 @@
                         multiply_matrix(&mat,&proj_mat,&mat);
 
 			for (nb = 0; nb < ci->dwCount; nb++) {
+#ifndef WINE_NATIVEWIN32
 			    /* Normals transformation */
 			    nx = (src->u4.nx * mat2->_11) + (src->u5.ny * mat2->_21) + (src->u6.nz * mat2->_31);
 			    ny = (src->u4.nx * mat2->_12) + (src->u5.ny * mat2->_22) + (src->u6.nz * mat2->_32);
@@ -434,6 +490,32 @@
 				       + Viewport->dwY + Viewport->dwHeight / 2;
 			    dst->u3.sz /= dst->u4.rhw;
 			    dst->u4.rhw = 1 / dst->u4.rhw;
+#else
+			    /* Normals transformation */
+			    nx = (src->nx * mat2->_11) + (src->ny * mat2->_21) + (src->nz * mat2->_31);
+			    ny = (src->nx * mat2->_12) + (src->ny * mat2->_22) + (src->nz * mat2->_32);
+			    nz = (src->nx * mat2->_13) + (src->ny * mat2->_23) + (src->nz * mat2->_33);
+			    
+			    /* No lighting yet */
+			    dst->color = 0xFFFFFFFF; /* Opaque white */
+			    dst->specular = 0xFF000000; /* No specular and no fog factor */
+			    
+			    dst->tu  = src->tu;
+			    dst->tv  = src->tv;
+			    
+			    /* Now, the matrix multiplication */
+			    dst->sx = (src->x * mat._11) + (src->y * mat._21) + (src->z * mat._31) + (1.0 * mat._41);
+			    dst->sy = (src->x * mat._12) + (src->y * mat._22) + (src->z * mat._32) + (1.0 * mat._42);
+			    dst->sz = (src->x * mat._13) + (src->y * mat._23) + (src->z * mat._33) + (1.0 * mat._43);
+			    dst->rhw = (src->x * mat._14) + (src->y * mat._24) + (src->z * mat._34) + (1.0 * mat._44);
+
+			    dst->sx = dst->sx / dst->rhw * Viewport->dwWidth / 2
+				       + Viewport->dwX + Viewport->dwWidth / 2;
+			    dst->sy = dst->sy / dst->rhw * Viewport->dwHeight / 2
+				       + Viewport->dwY + Viewport->dwHeight / 2;
+			    dst->sz /= dst->rhw;
+			    dst->rhw = 1 / dst->rhw;
+#endif
 
 			    src++;
 			    dst++;
@@ -459,6 +541,7 @@
 			multiply_matrix(&mat,&proj_mat,&mat);
 
 			for (nb = 0; nb < ci->dwCount; nb++) {
+#ifndef WINE_NATIVEWIN32
 			    dst->u5.color = src->u4.color;
 			    dst->u6.specular = src->u5.specular;
 			    dst->u7.tu = src->u6.tu;
@@ -474,6 +557,23 @@
 			    dst->u2.sy /= dst->u4.rhw * Viewport->dvScaleY * Viewport->dwHeight / 2 + Viewport->dwY;
 			    dst->u3.sz /= dst->u4.rhw;
 			    dst->u4.rhw = 1 / dst->u4.rhw;
+#else
+			    dst->color = src->color;
+			    dst->specular = src->specular;
+			    dst->tu = src->tu;
+			    dst->tv = src->tv;
+			    
+			    /* Now, the matrix multiplication */
+			    dst->sx = (src->x * mat._11) + (src->y * mat._21) + (src->z * mat._31) + (1.0 * mat._41);
+			    dst->sy = (src->x * mat._12) + (src->y * mat._22) + (src->z * mat._32) + (1.0 * mat._42);
+			    dst->sz = (src->x * mat._13) + (src->y * mat._23) + (src->z * mat._33) + (1.0 * mat._43);
+			    dst->rhw = (src->x * mat._14) + (src->y * mat._24) + (src->z * mat._34) + (1.0 * mat._44);
+
+			    dst->sx /= dst->rhw * Viewport->dvScaleX * Viewport->dwWidth / 2 + Viewport->dwX;
+			    dst->sy /= dst->rhw * Viewport->dvScaleY * Viewport->dwHeight / 2 + Viewport->dwY;
+			    dst->sz /= dst->rhw;
+			    dst->rhw = 1 / dst->rhw;
+#endif
 
 			    src++;
 			    dst++;
diff -Nur wine-0.9.36/dlls/ddraw/gamma.c parallels/dlls/ddraw/gamma.c
--- wine-0.9.36/dlls/ddraw/gamma.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/gamma.c	2009-01-29 12:56:05.000000000 +0100
@@ -20,7 +20,6 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -29,11 +28,13 @@
 
 #define COBJMACROS
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -41,6 +42,7 @@
 #include "d3d.h"
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
diff -Nur wine-0.9.36/dlls/ddraw/light.c parallels/dlls/ddraw/light.c
--- wine-0.9.36/dlls/ddraw/light.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/light.c	2009-01-29 12:56:05.000000000 +0100
@@ -21,7 +21,6 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -30,11 +29,13 @@
 
 #define COBJMACROS
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -42,6 +43,7 @@
 #include "d3d.h"
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
 
diff -Nur wine-0.9.36/dlls/ddraw/main.c parallels/dlls/ddraw/main.c
--- wine-0.9.36/dlls/ddraw/main.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/main.c	2009-01-29 12:56:05.000000000 +0100
@@ -25,7 +25,6 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -34,19 +33,22 @@
 
 #define COBJMACROS
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+# include "winreg.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
-#include "winreg.h"
 
 #include "ddraw.h"
 #include "d3d.h"
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 typedef IWineD3D* (WINAPI *fnWineDirect3DCreate)(UINT, UINT, IUnknown *);
 
@@ -71,6 +73,79 @@
 };
 static CRITICAL_SECTION ddraw_list_cs = { &ddraw_list_cs_debug, -1, 0, 0, 0, 0 };
 
+#ifdef WINE_NATIVEWIN32
+static HMODULE hDDraw = (HMODULE) -1;
+
+VOID (WINAPI *pAcquireDDThreadLock)();
+BOOL (WINAPI *pCheckFullscreen)();
+BOOL (WINAPI *pCompleteCreateSysmemSurface)(DWORD arg0);
+HRESULT (WINAPI *pD3DParseUnknownCommand)(DWORD arg0, DWORD arg1);
+HRESULT (WINAPI *pDDGetAttachedSurfaceLcl)(
+    DWORD arg0, DWORD arg1, DWORD arg2);
+HRESULT (WINAPI *pDDInternalLock)(DWORD arg0, DWORD arg1);
+HRESULT (WINAPI *pDDInternalUnlock)(DWORD arg0);
+HRESULT (WINAPI *pDSoundHelp)(DWORD arg0, DWORD arg1, DWORD arg2);
+HRESULT (WINAPI *pDirectDrawCreate)(
+    GUID *GUID, IDirectDraw **DD, IUnknown *UnkOuter);
+HRESULT (WINAPI *pDirectDrawCreateEx)(
+    GUID *GUID, void **DD, REFIID iid, IUnknown *UnkOuter);
+HRESULT (WINAPI *pDirectDrawCreateClipper)(
+    DWORD Flags, IDirectDrawClipper **Clipper, IUnknown *UnkOuter);
+HRESULT (WINAPI *pDirectDrawEnumerateA)(
+    LPDDENUMCALLBACKA Callback, void *Context);
+HRESULT (WINAPI *pDirectDrawEnumerateExA)(
+    LPDDENUMCALLBACKEXA Callback, void *Context, DWORD Flags);
+HRESULT (WINAPI *pDirectDrawEnumerateW)(
+    LPDDENUMCALLBACKW Callback, LPVOID Context);
+HRESULT (WINAPI *pDirectDrawEnumerateExW)(
+    LPDDENUMCALLBACKEXW Callback, LPVOID Context, DWORD Flags);
+HRESULT (WINAPI *pDllCanUnloadNow)(void);
+HRESULT (WINAPI *pDllGetClassObject)(
+    REFCLSID rclsid, REFIID riid, LPVOID *ppv);
+DWORD (WINAPI *pGetDDSurfaceLocal)(
+    DWORD arg0, DWORD arg1, DWORD arg2);
+HRESULT (WINAPI *pGetSurfaceFromDC)(
+    DWORD arg0, DWORD arg1, DWORD arg2);
+VOID (WINAPI *pReleaseDDThreadLock)();
+
+BOOL
+IsPassthrough()
+{
+    if (hDDraw == (HMODULE) -1)
+        hDDraw = GetModuleHandle("opengl32.dll") ? (HMODULE) -2 : NULL;
+    if (!hDDraw)
+        return FALSE;
+    if (hDDraw != (HMODULE) -2)
+        return TRUE;
+    hDDraw = LoadLibraryA("ddraw.sav");
+    if (hDDraw) {
+#define getproc(x) *(FARPROC *)&p##x = GetProcAddress(hDDraw, #x)
+        getproc(AcquireDDThreadLock);
+        getproc(CheckFullscreen);
+        getproc(CompleteCreateSysmemSurface);
+        getproc(D3DParseUnknownCommand);
+        getproc(DDGetAttachedSurfaceLcl);
+        getproc(DDInternalLock);
+        getproc(DDInternalUnlock);
+        getproc(DSoundHelp);
+        getproc(DirectDrawCreate);
+        getproc(DirectDrawCreateEx);
+        getproc(DirectDrawCreateClipper);
+        getproc(DirectDrawEnumerateA);
+        getproc(DirectDrawEnumerateExA);
+        getproc(DirectDrawEnumerateW);
+        getproc(DirectDrawEnumerateExW);
+        getproc(DllCanUnloadNow);
+        getproc(DllGetClassObject);
+        getproc(GetDDSurfaceLocal);
+        getproc(GetSurfaceFromDC);
+        getproc(ReleaseDDThreadLock);
+#undef getproc
+    }
+    return hDDraw != NULL;
+}
+#endif
+
 /***********************************************************************
  *
  * Helper function for DirectDrawCreate and friends
@@ -149,7 +224,9 @@
      */
     ICOM_INIT_INTERFACE(This, IDirectDraw,  IDirectDraw1_Vtbl);
     ICOM_INIT_INTERFACE(This, IDirectDraw2, IDirectDraw2_Vtbl);
+#ifndef WINE_NATIVEWIN32
     ICOM_INIT_INTERFACE(This, IDirectDraw3, IDirectDraw3_Vtbl);
+#endif
     ICOM_INIT_INTERFACE(This, IDirectDraw4, IDirectDraw4_Vtbl);
     ICOM_INIT_INTERFACE(This, IDirectDraw7, IDirectDraw7_Vtbl);
     ICOM_INIT_INTERFACE(This, IDirect3D,  IDirect3D1_Vtbl);
@@ -358,6 +435,10 @@
                  IDirectDraw **DD,
                  IUnknown *UnkOuter)
 {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirectDrawCreate(GUID, DD, UnkOuter);
+#endif
     TRACE("(%s,%p,%p)\n", debugstr_guid(GUID), DD, UnkOuter);
 
     return DDRAW_Create(GUID, (void **) DD, UnkOuter, &IID_IDirectDraw);
@@ -378,6 +459,10 @@
                    REFIID iid,
                    IUnknown *UnkOuter)
 {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirectDrawCreateEx(GUID, DD, iid, UnkOuter);
+#endif
     TRACE("(%s,%p,%s,%p)\n", debugstr_guid(GUID), DD, debugstr_guid(iid), UnkOuter);
 
     if (!IsEqualGUID(iid, &IID_IDirectDraw7))
@@ -412,6 +497,10 @@
 {
     BOOL stop = FALSE;
 
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirectDrawEnumerateA(Callback, Context);
+#endif
     TRACE(" Enumerating default DirectDraw HAL interface\n");
     /* We only have one driver */
     __TRY
@@ -446,8 +535,12 @@
                        DWORD Flags)
 {
     BOOL stop = FALSE;
-    TRACE("Enumerating default DirectDraw HAL interface\n");
 
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirectDrawEnumerateExA(Callback, Context, Flags);
+#endif
+    TRACE("Enumerating default DirectDraw HAL interface\n");
     /* We only have one driver by now */
     __TRY
     {
@@ -476,6 +569,33 @@
  * The Flag member is not supported right now.
  *
  ***********************************************************************/
+HRESULT WINAPI
+DirectDrawEnumerateW(LPDDENUMCALLBACKW Callback, LPVOID Context)
+{
+    BOOL stop = FALSE;
+
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirectDrawEnumerateW(Callback, Context);
+#endif
+    TRACE(" Enumerating default DirectDraw HAL interface\n");
+    /* We only have one driver */
+    __TRY
+    {
+        static WCHAR driver_desc[] = L"DirectDraw HAL",
+        driver_name[] = L"display";
+
+        stop = !Callback(NULL, driver_desc, driver_name, Context);
+    }
+    __EXCEPT_PAGE_FAULT
+    {
+        return E_INVALIDARG;
+    }
+    __ENDTRY
+
+    TRACE(" End of enumeration\n");
+    return DD_OK;
+}
 
 /***********************************************************************
  * DirectDrawEnumerateExW (DDRAW.@)
@@ -486,6 +606,35 @@
  * The Flag member is not supported right now.
  *
  ***********************************************************************/
+HRESULT WINAPI
+DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW Callback, LPVOID Context, DWORD Flags)
+{
+    BOOL stop = FALSE;
+
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDirectDrawEnumerateExW(Callback, Context, Flags);
+#endif
+    TRACE("Enumerating default DirectDraw HAL interface\n");
+    /* We only have one driver by now */
+    __TRY
+    {
+        static WCHAR driver_desc[] = L"DirectDraw HAL",
+        driver_name[] = L"display";
+
+        /* QuickTime expects the description "DirectDraw HAL" */
+        stop = !Callback(NULL, driver_desc, driver_name, Context, 0);
+    }
+    __EXCEPT_PAGE_FAULT
+    {
+        return E_INVALIDARG;
+    }
+    __ENDTRY;
+
+    TRACE("End of enumeration\n");
+    return DD_OK;
+}
+
 
 /***********************************************************************
  * Classfactory implementation.
@@ -711,6 +860,10 @@
     unsigned int i;
     IClassFactoryImpl *factory;
 
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDllGetClassObject(rclsid, riid, ppv);
+#endif
     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
 
     if ( !IsEqualGUID( &IID_IClassFactory, riid )
@@ -751,6 +904,11 @@
  */
 HRESULT WINAPI DllCanUnloadNow(void)
 {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDllCanUnloadNow();
+#endif
+
     FIXME("(void): stub\n");
     return S_FALSE;
 }
@@ -810,6 +968,98 @@
     return ERROR_FILE_NOT_FOUND;
 }
 
+#ifdef WINE_NATIVEWIN32
+/***********************************************************************
+ * Stubs for unimplemented functions
+ *
+ ***********************************************************************/
+VOID WINAPI
+AcquireDDThreadLock()
+{
+    if (IsPassthrough())
+        pAcquireDDThreadLock();
+}
+
+VOID WINAPI
+ReleaseDDThreadLock()
+{
+    if (IsPassthrough())
+        pReleaseDDThreadLock();
+}
+
+HRESULT WINAPI
+DDInternalLock(DWORD arg0, DWORD arg1)
+{
+    if (IsPassthrough())
+        return pDDInternalLock(arg0, arg1);
+    return 0;
+}
+
+HRESULT WINAPI
+DDInternalUnlock(DWORD arg0)
+{
+    if (IsPassthrough())
+        return pDDInternalUnlock(arg0);
+    return 0;
+}
+
+HRESULT WINAPI
+DDGetAttachedSurfaceLcl(DWORD arg0, DWORD arg1, DWORD arg2)
+{
+    if (IsPassthrough())
+        return pDDGetAttachedSurfaceLcl(arg0, arg1, arg2);
+    return DDERR_GENERIC;
+}
+
+DWORD WINAPI
+GetDDSurfaceLocal(DWORD arg0, DWORD arg1, DWORD arg2)
+{
+    if (IsPassthrough())
+        return pGetDDSurfaceLocal(arg0, arg1, arg2);
+    return 0;
+}
+
+HRESULT WINAPI
+GetSurfaceFromDC(DWORD arg0, DWORD arg1, DWORD arg2)
+{
+    if (IsPassthrough())
+        return pGetSurfaceFromDC(arg0, arg1, arg2);
+    return DDERR_GENERIC;
+}
+
+BOOL WINAPI
+CompleteCreateSysmemSurface(DWORD arg0)
+{
+    if (IsPassthrough())
+        return pCompleteCreateSysmemSurface(arg0);
+    return FALSE;
+}
+
+BOOL WINAPI
+CheckFullscreen()
+{
+    if (IsPassthrough())
+        return pCheckFullscreen();
+    return FALSE;
+}
+
+HRESULT WINAPI
+DSoundHelp(DWORD arg0, DWORD arg1, DWORD arg2)
+{
+    if (IsPassthrough())
+        return pDSoundHelp(arg0, arg1, arg2);
+    return DDERR_GENERIC;
+}
+
+HRESULT WINAPI
+D3DParseUnknownCommand(DWORD arg0, DWORD arg1)
+{
+    if (IsPassthrough())
+        return pD3DParseUnknownCommand(arg0, arg1);
+    return 0;
+}
+#endif
+
 /***********************************************************************
  * DllMain (DDRAW.0)
  *
@@ -826,30 +1076,41 @@
     TRACE("(%p,%x,%p)\n", hInstDLL, Reason, lpv);
     if (Reason == DLL_PROCESS_ATTACH)
     {
-        char buffer[MAX_PATH+10];
+        char buffer[MAX_PATH+64];
         DWORD size = sizeof(buffer);
         HKEY hkey = 0;
         HKEY appkey = 0;
         DWORD len;
 
+#if defined(WINE_NATIVEWIN32) && !defined(NDEBUG)
+        debug_init();
+#endif
+       DisableThreadLibraryCalls(hInstDLL);
+
        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
-       if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
+       if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey )
+           && RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Direct3D", &hkey ) )
+           hkey = 0;
 
        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
        if (len && len < MAX_PATH)
        {
-            HKEY tmpkey;
+            char *p, *appname = buffer;
+            if ((p = strrchr( appname, '/' ))) appname = p + 1;
+            if ((p = strrchr( appname, '\\' ))) appname = p + 1;
+            TRACE("appname = [%s]\n", appname);
+            memmove(
+                buffer + strlen( "Software\\Wine\\AppDefaults\\" ),
+                appname, strlen( appname ) + 1);
+            memcpy(
+                buffer, "Software\\Wine\\AppDefaults\\",
+                strlen( "Software\\Wine\\AppDefaults\\" ));
+            strcat( buffer, "\\Direct3D" );
+
             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
-            if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
-            {
-                char *p, *appname = buffer;
-                if ((p = strrchr( appname, '/' ))) appname = p + 1;
-                if ((p = strrchr( appname, '\\' ))) appname = p + 1;
-                strcat( appname, "\\Direct3D" );
-                TRACE("appname = [%s]\n", appname);
-                if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
-                RegCloseKey( tmpkey );
-            }
+            if (RegOpenKeyA( HKEY_CURRENT_USER, buffer, &appkey )
+                && RegOpenKeyA( HKEY_LOCAL_MACHINE, buffer, &appkey ))
+                appkey = 0;
        }
 
        if ( 0 != hkey || 0 != appkey )
@@ -871,9 +1132,17 @@
                     ERR("Unknown default surface type. Supported are:\n gdi, opengl\n");
                 }
             }
+#ifdef WINE_NATIVEWIN32
+            if ( !get_config_key( hkey, appkey, "Passthrough", buffer, size) )
+            {
+                if (!strcmp(buffer,"true") || !strcmp(buffer,"yes"))
+                {
+                    TRACE("Passthrough mode\n");
+                    hDDraw = (HMODULE) -2;
+                }
+            }
+#endif
         }
-
-        DisableThreadLibraryCalls(hInstDLL);
     }
     else if (Reason == DLL_PROCESS_DETACH)
     {
@@ -895,7 +1164,9 @@
                 /* Add references to each interface to avoid freeing them unexpectadely */
                 IDirectDraw_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw));
                 IDirectDraw2_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw2));
+#ifndef WINE_NATIVEWIN32
                 IDirectDraw3_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw3));
+#endif
                 IDirectDraw4_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw4));
                 IDirectDraw7_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw7));
 
@@ -934,11 +1205,19 @@
                     */
                 while(IDirectDraw_Release(ICOM_INTERFACE(ddraw, IDirectDraw)));
                 while(IDirectDraw2_Release(ICOM_INTERFACE(ddraw, IDirectDraw2)));
+#ifndef WINE_NATIVEWIN32
                 while(IDirectDraw3_Release(ICOM_INTERFACE(ddraw, IDirectDraw3)));
+#endif
                 while(IDirectDraw4_Release(ICOM_INTERFACE(ddraw, IDirectDraw4)));
                 while(IDirectDraw7_Release(ICOM_INTERFACE(ddraw, IDirectDraw7)));
             }
         }
+        if (hWineD3D && hWineD3D != (HMODULE) -1)
+            FreeLibrary(hWineD3D);
+#ifdef WINE_NATIVEWIN32
+        if (hDDraw && hDDraw != (HMODULE) -1 && hDDraw != (HMODULE) -2)
+            FreeLibrary(hDDraw);
+#endif
     }
 
     return TRUE;
diff -Nur wine-0.9.36/dlls/ddraw/material.c parallels/dlls/ddraw/material.c
--- wine-0.9.36/dlls/ddraw/material.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/material.c	2009-01-29 12:56:05.000000000 +0100
@@ -30,11 +30,13 @@
 #define COBJMACROS
 #define NONAMELESSUNION
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -452,11 +454,19 @@
     D3DMATERIAL7 d3d7mat;
 
     TRACE("Activating material %p\n", This);
+#ifndef WINE_NATIVEWIN32
     d3d7mat.u.diffuse = This->mat.u.diffuse;
     d3d7mat.u1.ambient = This->mat.u1.ambient;
     d3d7mat.u2.specular = This->mat.u2.specular;
     d3d7mat.u3.emissive = This->mat.u3.emissive;
     d3d7mat.u4.power = This->mat.u4.power;
+#else
+    d3d7mat.diffuse = This->mat.diffuse;
+    d3d7mat.ambient = This->mat.ambient;
+    d3d7mat.specular = This->mat.specular;
+    d3d7mat.emissive = This->mat.emissive;
+    d3d7mat.power = This->mat.power;
+#endif
 
     IDirect3DDevice7_SetMaterial(ICOM_INTERFACE(This->active_device, IDirect3DDevice7),
                                  &d3d7mat);
diff -Nur wine-0.9.36/dlls/ddraw/palette.c parallels/dlls/ddraw/palette.c
--- wine-0.9.36/dlls/ddraw/palette.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/palette.c	2009-01-29 12:56:05.000000000 +0100
@@ -19,7 +19,6 @@
 
 #include "config.h"
 #include "winerror.h"
-#include "wine/debug.h"
 
 #define COBJMACROS
 
@@ -27,6 +26,7 @@
 #include <string.h>
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 
diff -Nur wine-0.9.36/dlls/ddraw/parent.c parallels/dlls/ddraw/parent.c
--- wine-0.9.36/dlls/ddraw/parent.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/parent.c	2009-01-29 12:56:05.000000000 +0100
@@ -23,7 +23,6 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -32,11 +31,13 @@
 
 #define COBJMACROS
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -44,6 +45,7 @@
 #include "d3d.h"
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 
diff -Nur wine-0.9.36/dlls/ddraw/regsvr.c parallels/dlls/ddraw/regsvr.c
--- wine-0.9.36/dlls/ddraw/regsvr.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/regsvr.c	2009-01-29 12:56:05.000000000 +0100
@@ -18,15 +18,21 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include "config.h"
+
 #include <stdarg.h>
 #include <string.h>
 
-#include "windef.h"
-#include "winbase.h"
-#include "winreg.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "winerror.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winreg.h"
+# include "wingdi.h"
+# include "winuser.h"
+# include "winerror.h"
+#else
+# include <windows.h>
+#endif
 
 #include "ddraw.h"
 
diff -Nur wine-0.9.36/dlls/ddraw/surface.c parallels/dlls/ddraw/surface.c
--- wine-0.9.36/dlls/ddraw/surface.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/surface.c	2009-01-29 12:56:05.000000000 +0100
@@ -34,11 +34,13 @@
 #define COBJMACROS
 #define NONAMELESSUNION
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -426,10 +428,18 @@
         /* Earlier dx apps put garbage into these members, clear them */
         our_caps.dwCaps2 = 0;
         our_caps.dwCaps3 = 0;
+#ifndef WINE_NATIVEWIN32
         our_caps.dwCaps4 = 0;
+#else
+        our_caps.u1.dwCaps4 = 0;
+#endif
     }
 
+#ifndef WINE_NATIVEWIN32
     TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.dwCaps4); /* FIXME: Better debugging */
+#else
+    TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.u1.dwCaps4); /* FIXME: Better debugging */
+#endif
 
     /* First, look at the complex chain */
     surf = This;
@@ -442,7 +452,11 @@
                    surf->surface_desc.ddsCaps.dwCaps,
                    surf->surface_desc.ddsCaps.dwCaps2,
                    surf->surface_desc.ddsCaps.dwCaps3,
+#ifndef WINE_NATIVEWIN32
                    surf->surface_desc.ddsCaps.dwCaps4);
+#else
+                   surf->surface_desc.ddsCaps.u1.dwCaps4);
+#endif
         }
 
         if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
@@ -474,7 +488,11 @@
                    surf->surface_desc.ddsCaps.dwCaps,
                    surf->surface_desc.ddsCaps.dwCaps2,
                    surf->surface_desc.ddsCaps.dwCaps3,
+#ifndef WINE_NATIVEWIN32
                    surf->surface_desc.ddsCaps.dwCaps4);
+#else
+                   surf->surface_desc.ddsCaps.u1.dwCaps4);
+#endif
         }
 
         if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
diff -Nur wine-0.9.36/dlls/ddraw/surface_thunks.c parallels/dlls/ddraw/surface_thunks.c
--- wine-0.9.36/dlls/ddraw/surface_thunks.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/surface_thunks.c	2009-01-29 12:56:05.000000000 +0100
@@ -18,16 +18,19 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
+
 #include <stdarg.h>
 
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "ddraw.h"
-#include "winerror.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "wingdi.h"
+# include "ddraw.h"
+# include "winerror.h"
+#endif
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 #include "ddcomimpl.h"
 
 #define CONVERT(pdds) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,	\
@@ -188,7 +191,11 @@
     caps.dwCaps  = pCaps->dwCaps;
     caps.dwCaps2 = 0;
     caps.dwCaps3 = 0;
+#ifndef WINE_NATIVEWIN32
     caps.dwCaps4 = 0;
+#else
+    caps.u1.dwCaps4 = 0;
+#endif
 
     hr = IDirectDrawSurface7_GetAttachedSurface(CONVERT(This), &caps,
 						&pAttached7);
diff -Nur wine-0.9.36/dlls/ddraw/tests/d3d.c parallels/dlls/ddraw/tests/d3d.c
--- wine-0.9.36/dlls/ddraw/tests/d3d.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/tests/d3d.c	2009-01-29 12:56:05.000000000 +0100
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include "config.h"
+
 #include <assert.h>
 #include "wine/test.h"
 #include "ddraw.h"
@@ -244,7 +246,11 @@
     U3(light.dcvDiffuse).b = 1.f;
     U3(light.dvDirection).z = 1.f;
 
+#ifndef WINE_NATIVEWIN32
     light.dvAttenuation0 = -1.0 / 0.0; /* -INFINITY */
+#else
+    *(long *)&light.dvAttenuation0 = 0xff800000L;
+#endif
     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
     ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
 
@@ -260,11 +266,19 @@
     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
 
+#ifndef WINE_NATIVEWIN32
     light.dvAttenuation0 = 1.0 / 0.0; /* +INFINITY */
+#else
+    *(long *)&light.dvAttenuation0 = 0x7f800000L;
+#endif
     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
 
+#ifndef WINE_NATIVEWIN32
     light.dvAttenuation0 = 0.0 / 0.0; /* NaN */
+#else
+    *(long *)&light.dvAttenuation0 = 0x7fC00000L;
+#endif
     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
 
diff -Nur wine-0.9.36/dlls/ddraw/texture.c parallels/dlls/ddraw/texture.c
--- wine-0.9.36/dlls/ddraw/texture.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/texture.c	2009-01-29 12:56:05.000000000 +0100
@@ -30,11 +30,13 @@
 #define COBJMACROS
 #define NONAMELESSUNION
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
diff -Nur wine-0.9.36/dlls/ddraw/utils.c parallels/dlls/ddraw/utils.c
--- wine-0.9.36/dlls/ddraw/utils.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/utils.c	2009-01-29 12:56:05.000000000 +0100
@@ -715,7 +715,11 @@
     in_bis.dwCaps = in->dwCaps;
     in_bis.dwCaps2 = 0;
     in_bis.dwCaps3 = 0;
+#ifndef WINE_NATIVEWIN32
     in_bis.dwCaps4 = 0;
+#else
+    in_bis.u1.dwCaps4 = 0;
+#endif
 
     DDRAW_dump_DDSCAPS2(&in_bis);
 }
@@ -832,7 +836,7 @@
             ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
             ME(DDSD_PITCH, DDRAW_dump_DWORD, u1 /* lPitch */),
             ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1 /* dwLinearSize */),
-            ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, dwBackBufferCount),
+            ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, u5.dwBackBufferCount),
             ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2 /* dwMipMapCount */),
             ME(DDSD_ZBUFFERBITDEPTH, DDRAW_dump_DWORD, u2 /* dwZBufferBitDepth */), /* This is for 'old-style' D3D */
             ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2 /* dwRefreshRate */),
@@ -913,7 +917,11 @@
     pOut->dwCaps = pIn->dwCaps;
     pOut->dwCaps2 = 0;
     pOut->dwCaps3 = 0;
+#ifndef WINE_NATIVEWIN32
     pOut->dwCaps4 = 0;
+#else
+    pOut->u1.dwCaps4 = 0;
+#endif
 }
 
 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn, DDDEVICEIDENTIFIER* pOut)
@@ -967,6 +975,9 @@
       FE(DDCAPS_PALETTE),
       FE(DDCAPS_PALETTEVSYNC),
       FE(DDCAPS_READSCANLINE),
+#ifndef DDCAPS_STEREOVIEW
+#define DDCAPS_STEREOVIEW 0x00040000
+#endif
       FE(DDCAPS_STEREOVIEW),
       FE(DDCAPS_VBI),
       FE(DDCAPS_ZBLTS),
diff -Nur wine-0.9.36/dlls/ddraw/vertexbuffer.c parallels/dlls/ddraw/vertexbuffer.c
--- wine-0.9.36/dlls/ddraw/vertexbuffer.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/vertexbuffer.c	2009-01-29 12:56:05.000000000 +0100
@@ -21,7 +21,6 @@
 
 #include "config.h"
 #include "wine/port.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -30,11 +29,13 @@
 
 #define COBJMACROS
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -42,6 +43,7 @@
 #include "d3d.h"
 
 #include "ddraw_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
diff -Nur wine-0.9.36/dlls/ddraw/viewport.c parallels/dlls/ddraw/viewport.c
--- wine-0.9.36/dlls/ddraw/viewport.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddraw/viewport.c	2009-01-29 12:56:05.000000000 +0100
@@ -30,11 +30,13 @@
 #define COBJMACROS
 #define NONAMELESSUNION
 
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "winerror.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winnls.h"
+# include "winerror.h"
+# include "wingdi.h"
+#endif
 #include "wine/exception.h"
 #include "excpt.h"
 
@@ -401,10 +403,17 @@
     {
         This->background = (IDirect3DMaterialImpl *) This->ddraw->d3ddevice->Handles[hMat - 1].ptr;
         TRACE(" setting background color : %f %f %f %f\n",
+#ifndef WINE_NATIVEWIN32
               This->background->mat.u.diffuse.u1.r,
               This->background->mat.u.diffuse.u2.g,
               This->background->mat.u.diffuse.u3.b,
               This->background->mat.u.diffuse.u4.a);
+#else
+              This->background->mat.diffuse.r,
+              This->background->mat.diffuse.g,
+              This->background->mat.diffuse.b,
+              This->background->mat.diffuse.a);
+#endif
     }
     else
     {
@@ -536,10 +545,17 @@
 	    ERR(" Trying to clear the color buffer without background material !\n");
 	} else {
 	    color = 
+#ifndef WINE_NATIVEWIN32
 	      ((int) ((This->background->mat.u.diffuse.u1.r) * 255) << 16) |
 	      ((int) ((This->background->mat.u.diffuse.u2.g) * 255) <<  8) |
 	      ((int) ((This->background->mat.u.diffuse.u3.b) * 255) <<  0) |
 	      ((int) ((This->background->mat.u.diffuse.u4.a) * 255) << 24);
+#else
+	      ((int) ((This->background->mat.diffuse.r) * 255) << 16) |
+	      ((int) ((This->background->mat.diffuse.g) * 255) <<  8) |
+	      ((int) ((This->background->mat.diffuse.b) * 255) <<  0) |
+	      ((int) ((This->background->mat.diffuse.a) * 255) << 24);
+#endif
 	}
     }
 
diff -Nur wine-0.9.36/dlls/ddrawex/ddrawex_private.h parallels/dlls/ddrawex/ddrawex_private.h
--- wine-0.9.36/dlls/ddrawex/ddrawex_private.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddrawex/ddrawex_private.h	2009-01-29 12:56:05.000000000 +0100
@@ -22,6 +22,7 @@
 DEFINE_GUID(CLSID_DirectDrawFactory, 0x4fd2a832, 0x86c8, 0x11d0, 0x8f, 0xca, 0x0, 0xc0, 0x4f, 0xd9, 0x18, 0x9d);
 DEFINE_GUID(IID_IDirectDrawFactory, 0x4fd2a833, 0x86c8, 0x11d0, 0x8f, 0xca, 0x0, 0xc0, 0x4f, 0xd9, 0x18, 0x9d);
 
+#undef INTERFACE
 #define INTERFACE IDirectDrawFactory
 DECLARE_INTERFACE_(IDirectDrawFactory, IUnknown)
 {
diff -Nur wine-0.9.36/dlls/ddrawex/main.c parallels/dlls/ddrawex/main.c
--- wine-0.9.36/dlls/ddrawex/main.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddrawex/main.c	2009-01-29 12:56:05.000000000 +0100
@@ -20,22 +20,51 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-
-#include "wine/debug.h"
+#include "config.h"
 
 #define COBJMACROS
 
-#include "winbase.h"
-#include "wingdi.h"
+#ifndef WINE_NATIVEWIN32
+# include "winbase.h"
+# include "wingdi.h"
+#else
+# include <windows.h>
+#endif
 
 #include "ddraw.h"
 
 #include "initguid.h"
 #include "ddrawex_private.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 
 
+#ifdef WINE_NATIVEWIN32
+static HMODULE hDDrawEx;
+
+HRESULT (WINAPI *pDllCanUnloadNow)(void);
+HRESULT (WINAPI *pDllGetClassObject)(
+    REFCLSID rclsid, REFIID riid, LPVOID *ppv);
+
+BOOL
+IsPassthrough()
+{
+    if (!hDDrawEx)
+        return FALSE;
+    if (hDDrawEx != (HMODULE) -1)
+        return TRUE;
+    hDDrawEx = LoadLibraryA("ddrawex.sav");
+    if (hDDrawEx) {
+#define getproc(x) *(FARPROC *)&p##x = GetProcAddress(hDDrawEx, #x)
+        getproc(DllCanUnloadNow);
+        getproc(DllGetClassObject);
+#undef getproc
+    }
+    return hDDrawEx != NULL;
+}
+#endif
+
 /*******************************************************************************
  * IDirectDrawClassFactory::QueryInterface
  *
@@ -211,7 +240,11 @@
 
     TRACE("\n");
 
+#ifndef WINE_NATIVEWIN32
     hr = DirectDrawCreateEx(pGUID, (void**)ppDirectDraw, &IID_IDirectDraw3, pUnkOuter);
+#else
+    hr = DirectDrawCreateEx(pGUID, (void**)ppDirectDraw, &IID_IDirectDraw7, pUnkOuter);
+#endif
 
     if (FAILED(hr))
         return hr;
@@ -288,6 +321,11 @@
  */
 HRESULT WINAPI DllCanUnloadNow(void)
 {
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDllCanUnloadNow();
+#endif
+
     FIXME("(void): stub\n");
     return S_FALSE;
 }
@@ -300,6 +338,10 @@
 {
     IClassFactoryImpl *factory;
 
+#ifdef WINE_NATIVEWIN32
+    if (IsPassthrough())
+        return pDllGetClassObject(rclsid, riid, ppv);
+#endif
     TRACE("ddrawex (%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
 
     if (!IsEqualGUID( &IID_IClassFactory, riid)
@@ -327,6 +369,19 @@
 
 
 /***********************************************************************
+ * get_config_key
+ *
+ * Reads a config key from the registry. Taken from WineD3D
+ *
+ ***********************************************************************/
+static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
+{
+    if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
+    if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
+    return ERROR_FILE_NOT_FOUND;
+}
+
+/***********************************************************************
  * DllMain (DDRAWEX.0)
  *
  ***********************************************************************/
@@ -336,5 +391,53 @@
         void *lpv)
 {
     TRACE("(%p,%x,%p)\n", hInstDLL, Reason, lpv);
+#ifdef WINE_NATIVEWIN32
+    if (Reason == DLL_PROCESS_ATTACH)
+    {
+        char buffer[MAX_PATH+64];
+        DWORD size = sizeof(buffer);
+        HKEY hkey = 0;
+        HKEY appkey = 0;
+        DWORD len;
+
+       /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
+       if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey )
+           && RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Direct3D", &hkey ) )
+           hkey = 0;
+
+       len = GetModuleFileNameA( 0, buffer, MAX_PATH );
+       if (len && len < MAX_PATH)
+       {
+            char *p, *appname = buffer;
+            if ((p = strrchr( appname, '/' ))) appname = p + 1;
+            if ((p = strrchr( appname, '\\' ))) appname = p + 1;
+            TRACE("appname = [%s]\n", appname);
+            memmove(
+                buffer + strlen( "Software\\Wine\\AppDefaults\\" ),
+                appname, strlen( appname ) + 1);
+            memcpy(
+                buffer, "Software\\Wine\\AppDefaults\\",
+                strlen( "Software\\Wine\\AppDefaults\\" ));
+            strcat( buffer, "\\Direct3D" );
+
+            /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
+            if (RegOpenKeyA( HKEY_CURRENT_USER, buffer, &appkey )
+                && RegOpenKeyA( HKEY_LOCAL_MACHINE, buffer, &appkey ))
+                appkey = 0;
+       }
+
+       if ( 0 != hkey || 0 != appkey )
+       {
+            if ( !get_config_key( hkey, appkey, "Passthrough", buffer, size) )
+            {
+                if (!strcmp(buffer,"true") || !strcmp(buffer,"yes"))
+                {
+                    TRACE("Passthrough mode\n");
+                    hDDrawEx = (HMODULE) -1;
+                }
+            }
+        }
+    }
+#endif
     return TRUE;
 }
diff -Nur wine-0.9.36/dlls/ddrawex/regsvr.c parallels/dlls/ddrawex/regsvr.c
--- wine-0.9.36/dlls/ddrawex/regsvr.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/ddrawex/regsvr.c	2009-01-29 12:56:05.000000000 +0100
@@ -19,15 +19,21 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include "config.h"
+
 #include <stdarg.h>
 #include <string.h>
 
-#include "windef.h"
-#include "winbase.h"
-#include "winreg.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "winerror.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winreg.h"
+# include "wingdi.h"
+# include "winuser.h"
+# include "winerror.h"
+#else
+# include <windows.h>
+#endif
 
 #include "ddraw.h"
 #include "ddrawex_private.h"
diff -Nur wine-0.9.36/dlls/ddrawex/version.rc parallels/dlls/ddrawex/version.rc
--- wine-0.9.36/dlls/ddrawex/version.rc	1970-01-01 01:00:00.000000000 +0100
+++ parallels/dlls/ddrawex/version.rc	2009-01-29 12:56:05.000000000 +0100
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2001 Ove Kaaven
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#define WINE_OLESELFREGISTER
+#define WINE_FILEDESCRIPTION_STR "Wine DirectDrawEx"
+#define WINE_FILENAME_STR "ddrawex.dll"
+#define WINE_FILEVERSION 5,3,1,904
+#define WINE_FILEVERSION_STR "5.3.1.904"
+#define WINE_PRODUCTVERSION 5,3,1,904
+#define WINE_PRODUCTVERSION_STR "5.3.1.904"
+
+#include "wine/wine_common_ver.rc"
diff -Nur wine-0.9.36/dlls/wined3d/basetexture.c parallels/dlls/wined3d/basetexture.c
--- wine-0.9.36/dlls/wined3d/basetexture.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/basetexture.c	2009-01-29 12:56:04.000000000 +0100
@@ -137,7 +137,7 @@
 }
 
 void     WINAPI        IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface) {
-    return IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
+    /*return*/ IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
 }
 
 WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface) {
diff -Nur wine-0.9.36/dlls/wined3d/context.c parallels/dlls/wined3d/context.c
--- wine-0.9.36/dlls/wined3d/context.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/context.c	2009-01-29 12:56:03.000000000 +0100
@@ -70,7 +70,11 @@
  *  drawable: drawable used with this context.
  *
  *****************************************************************************/
+#ifndef WINE_NATIVEWIN32
 static WineD3DContext *AddContextToArray(IWineD3DDeviceImpl *This, Display *display, GLXContext glCtx, Drawable drawable) {
+#else
+static WineD3DContext *AddContextToArray(IWineD3DDeviceImpl *This, HGLRC glCtx, HDC hdc) {
+#endif
     WineD3DContext **oldArray = This->contexts;
     DWORD state;
 
@@ -92,9 +96,14 @@
         return NULL;
     }
 
+#ifndef WINE_NATIVEWIN32
     This->contexts[This->numContexts]->display = display;
     This->contexts[This->numContexts]->glCtx = glCtx;
     This->contexts[This->numContexts]->drawable = drawable;
+#else
+    This->contexts[This->numContexts]->glCtx = glCtx;
+    This->contexts[This->numContexts]->hdc = hdc;
+#endif
     HeapFree(GetProcessHeap(), 0, oldArray);
 
     /* Mark all states dirty to force a proper initialization of the states on the first use of the context
@@ -108,6 +117,7 @@
     return This->contexts[This->numContexts - 1];
 }
 
+#ifndef WINE_NATIVEWIN32
 /* Returns an array of compatible FBconfig(s).
  * The array must be freed with XFree. Requires ENTER_GL()
  */
@@ -187,6 +197,7 @@
 
    return cfgs;
 }
+#endif
 
 /*****************************************************************************
  * CreateContext
@@ -200,6 +211,7 @@
  *  win: Target window. NULL for a pbuffer
  *
  *****************************************************************************/
+#ifndef WINE_NATIVEWIN32
 WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, Display *display, Window win) {
     Drawable drawable = win, oldDrawable;
     XVisualInfo *visinfo = NULL;
@@ -370,6 +382,132 @@
     return ret;
 }
 
+#else /*WINE_NATIVEWIN32*/
+
+static BOOL SelectPixelFormat(HDC hdc, DWORD bits) {
+    int index = 1;
+    int maxindex;
+
+    if (bits == 24)
+        bits = 32;
+    do {
+        PIXELFORMATDESCRIPTOR pfd;
+
+        maxindex = wglDescribePixelFormat(hdc, index, sizeof(pfd), &pfd);
+        /* skip non-GL formats */
+        if (~pfd.dwFlags
+            & (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
+            /* double buffering and GDI are mutually exclusive */
+                | PFD_DOUBLEBUFFER))
+            continue;
+        /* skip software GL implementation */
+        if (pfd.dwFlags & PFD_GENERIC_FORMAT)
+            continue;
+        /* we're not going to provide a palette, or do we?
+        if (pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE)
+            continue; */
+        /* skip paletized modes
+        if (pfd.iPixelType != PFD_TYPE_RGBA)
+            continue; */
+        /* do we need good depth buffer and stencil support?
+        if (pfd.cDepthBits < 15 || pfd.cStencilBits < 8)
+            continue; */
+        /* match bit depth */
+        if (pfd.cColorBits != bits)
+            continue;
+        /* pixel format can only be set once per window */
+        if (wglSetPixelFormat(hdc, index, &pfd))
+            return TRUE;
+    } while (index++ < maxindex);
+    return FALSE;
+}
+
+WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND hwnd) {
+    HDC hdc, oldHdc;
+    HGLRC ctx = NULL, oldCtx;
+    WineD3DContext *ret = NULL;
+
+    TRACE("(%p): Creating a %s context for render target %p\n", This, hwnd ? "onscreen" : "offscreen", target);
+
+    if(!hwnd) {
+        ERR("Cannot find a frame buffer configuration for the pbuffer\n");
+        goto out;
+    } else {
+        hdc = GetDC(hwnd);
+    }
+
+    if (!SelectPixelFormat(hdc, GetDeviceCaps(hdc, BITSPIXEL))
+        || !(ctx = wglCreateContext(hdc))) {
+        ERR("Failed to create a wgl context\n");
+        goto out;
+    }
+    ret = AddContextToArray(This, ctx, hdc);
+    if(!ret) {
+        ERR("Failed to add the newly created context to the context list\n");
+        wglDeleteContext(ctx);
+        goto out;
+    }
+    ret->surface = (IWineD3DSurface *) target;
+    ret->isPBuffer = hwnd == 0;
+
+    TRACE("Successfully created new context %p\n", ret);
+
+    /* Set up the context defaults */
+    oldCtx = wglGetCurrentContext();
+    oldHdc = wglGetCurrentDC();
+    if(!wglMakeCurrent(hdc, ctx)) {
+        ERR("Cannot activate context to set up defaults\n");
+        goto out;
+    }
+
+    TRACE("Setting up the screen\n");
+    /* Clear the screen */
+    glClearColor(1.0, 0.0, 0.0, 0.0);
+    checkGLcall("glClearColor");
+    glClearIndex(0);
+    glClearDepth(1);
+    glClearStencil(0xffff);
+
+    checkGLcall("glClear");
+
+    glColor3f(1.0, 1.0, 1.0);
+    checkGLcall("glColor3f");
+
+    glEnable(GL_LIGHTING);
+    checkGLcall("glEnable");
+
+    glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
+    checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
+
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
+    checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
+
+    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+    checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
+
+    glPixelStorei(GL_PACK_ALIGNMENT, SURFACE_ALIGNMENT);
+    checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, SURFACE_ALIGNMENT);");
+    glPixelStorei(GL_UNPACK_ALIGNMENT, SURFACE_ALIGNMENT);
+    checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, SURFACE_ALIGNMENT);");
+
+    if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
+        /* Most textures will use client storage if supported. Exceptions are non-native power of 2 textures
+         * and textures in DIB sections(due to the memory protection).
+         */
+        glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
+        checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
+    }
+
+    if(oldHdc && oldCtx) {
+        wglMakeCurrent(oldHdc, oldCtx);
+    }
+
+out:
+    return ret;
+}
+
+#endif /* WINE_NATIVEWIN32 */
+
 /*****************************************************************************
  * RemoveContextFromArray
  *
@@ -398,7 +536,7 @@
             ERR("Cannot allocate a new context array, PANIC!!!\n");
         }
         t = 0;
-        for(s = 0; s < This->numContexts; s++) {
+        for(s = 0; s <= This->numContexts; s++) {
             if(oldArray[s] == context) continue;
             This->contexts[t] = oldArray[s];
             t++;
@@ -425,6 +563,7 @@
 
     /* check that we are the current context first */
     TRACE("Destroying ctx %p\n", context);
+#ifndef WINE_NATIVEWIN32
     if(glXGetCurrentContext() == context->glCtx){
         glXMakeCurrent(context->display, None, NULL);
     }
@@ -433,6 +572,15 @@
     if(context->isPBuffer) {
         glXDestroyPbuffer(context->display, context->drawable);
     }
+#else
+    if(wglGetCurrentContext() == context->glCtx) {
+        wglMakeCurrent(0, 0);
+    }
+    wglDeleteContext(context->glCtx);
+    ReleaseDC(WindowFromDC(context->hdc), context->hdc);
+    if(context->isPBuffer) {
+    }
+#endif
     RemoveContextFromArray(This, context);
 }
 
@@ -679,8 +827,12 @@
                          * Create the context on the same server as the primary swapchain. The primary swapchain is exists at this point.
                          */
                         This->pbufferContext = CreateContext(This, targetimpl,
+#ifndef WINE_NATIVEWIN32
                                                              ((IWineD3DSwapChainImpl *) This->swapchains[0])->context[0]->display,
                                                              0 /* Window */);
+#else
+                                                             0 /* HWND */);
+#endif
                         This->pbufferWidth = targetimpl->currentDesc.Width;
                         This->pbufferHeight = targetimpl->currentDesc.Height;
                     }
@@ -753,10 +905,15 @@
 
     /* Activate the opengl context */
     if(context != This->activeContext) {
+#ifndef WINE_NATIVEWIN32
         Bool ret;
         TRACE("Switching gl ctx to %p, drawable=%ld, ctx=%p\n", context, context->drawable, context->glCtx);
         ret = glXMakeCurrent(context->display, context->drawable, context->glCtx);
         if(ret == FALSE) {
+#else
+        TRACE("Switching gl ctx to %p, hdc=%p, ctx=%p\n", context, context->hdc, context->glCtx);
+        if(!wglMakeCurrent(context->hdc, context->glCtx)) {
+#endif
             ERR("Failed to activate the new context\n");
         }
         This->activeContext = context;
diff -Nur wine-0.9.36/dlls/wined3d/cubetexture.c parallels/dlls/wined3d/cubetexture.c
--- wine-0.9.36/dlls/wined3d/cubetexture.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/cubetexture.c	2009-01-29 12:56:03.000000000 +0100
@@ -172,7 +172,7 @@
 }
 
 static void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface) {
-  return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
+  /*return*/ IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
 }
 
 /* Internal function, No d3d mapping */
diff -Nur wine-0.9.36/dlls/wined3d/device.c parallels/dlls/wined3d/device.c
--- wine-0.9.36/dlls/wined3d/device.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/device.c	2009-01-29 12:56:04.000000000 +0100
@@ -50,6 +50,7 @@
     0.0                       /* Phi */
 };
 
+#ifndef WINE_NATIVEWIN32
 /* x11drv GDI escapes */
 #define X11DRV_ESCAPE 6789
 enum x11drv_escape_codes
@@ -69,6 +70,7 @@
                     sizeof(display), (LPSTR)&display )) display = NULL;
     return display;
 }
+#endif
 
 /* static function declarations */
 static void WINAPI IWineD3DDeviceImpl_AddResource(IWineD3DDevice *iface, IWineD3DResource *resource);
@@ -1192,27 +1194,35 @@
     /* Get the parameters and save them */
     style = GetWindowLongW(window, GWL_STYLE);
     exStyle = GetWindowLongW(window, GWL_EXSTYLE);
-    This->style = style;
-    This->exStyle = exStyle;
 
     /* Filter out window decorations */
-    style &= ~WS_CAPTION;
-    style &= ~WS_THICKFRAME;
-    exStyle &= ~WS_EX_WINDOWEDGE;
-    exStyle &= ~WS_EX_CLIENTEDGE;
+    if ((style & (WS_CAPTION | WS_THICKFRAME)) && !(style & WS_POPUP)) {
+        This->style = style;
 
-    /* Make sure the window is managed, otherwise we won't get keyboard input */
-    style |= WS_POPUP | WS_SYSMENU;
+        style &= ~WS_CAPTION;
+        style &= ~WS_THICKFRAME;
+        /* Make sure the window is managed, otherwise we won't get keyboard input */
+        style |= WS_POPUP | WS_SYSMENU;
 
-    TRACE("Old style was %08x,%08x, setting to %08x,%08x\n",
-          This->style, This->exStyle, style, exStyle);
+        SetWindowLongW(window, GWL_STYLE, style);
+    }
+    if (exStyle & (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)) {
+        This->exStyle = exStyle;
 
-    SetWindowLongW(window, GWL_STYLE, style);
-    SetWindowLongW(window, GWL_EXSTYLE, exStyle);
+        exStyle &= ~WS_EX_WINDOWEDGE;
+        exStyle &= ~WS_EX_CLIENTEDGE;
 
-    /* Inform the window about the update. */
+        SetWindowLongW(window, GWL_EXSTYLE, exStyle);
+    }
+    if (This->style || This->exStyle) {
+        TRACE("Old style was %08x,%08x, setting to %08x,%08x\n",
+              This->style, This->exStyle, style, exStyle);
+    }
     SetWindowPos(window, HWND_TOP, 0, 0,
-            This->ddraw_width, This->ddraw_height, SWP_FRAMECHANGED);
+        This->ddraw_width, This->ddraw_height,
+        /* Inform the window about the update. */
+        ((This->style || This->exStyle) ? SWP_FRAMECHANGED : 0)
+            | SWP_NOCOPYBITS);
     ShowWindow(window, SW_NORMAL);
 }
 
@@ -1252,17 +1262,19 @@
 }
 
 /* example at http://www.fairyengine.com/articles/dxmultiviews.htm */
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevice* iface, WINED3DPRESENT_PARAMETERS*  pPresentationParameters,                                                                   IWineD3DSwapChain** ppSwapChain,
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevice* iface, WINED3DPRESENT_PARAMETERS*  pPresentationParameters,
+                                                                   IWineD3DSwapChain** ppSwapChain,
                                                             IUnknown* parent,
                                                             D3DCB_CREATERENDERTARGETFN D3DCB_CreateRenderTarget,
                                                             D3DCB_CREATEDEPTHSTENCILSURFACEFN D3DCB_CreateDepthStencil) {
     IWineD3DDeviceImpl      *This = (IWineD3DDeviceImpl *)iface;
-
     HDC                     hDc;
     IWineD3DSwapChainImpl  *object; /** NOTE: impl ref allowed since this is a create function **/
     HRESULT                 hr = WINED3D_OK;
     IUnknown               *bufferParent;
+#ifndef WINE_NATIVEWIN32
     Display                *display;
+#endif
 
     TRACE("(%p) : Created Aditional Swap Chain\n", This);
 
@@ -1291,14 +1303,25 @@
         object->win_handle = This->createParms.hFocusWindow;
     }
 
+#ifndef WINE_NATIVEWIN32
     object->win_handle = GetAncestor(object->win_handle, GA_ROOT);
     if ( !( object->win = (Window)GetPropA(object->win_handle, "__wine_x11_whole_window") ) ) {
         ERR("Can't get drawable (window), HWND:%p doesn't have the property __wine_x11_whole_window\n", object->win_handle);
         return WINED3DERR_NOTAVAILABLE;
     }
-    hDc                = GetDC(object->win_handle);
-    display            = get_display(hDc);
+#endif
+    hDc = GetDC(object->win_handle);
+    object->orig_width = GetSystemMetrics(SM_CXSCREEN);
+    object->orig_height = GetSystemMetrics(SM_CYSCREEN);
+    object->orig_fmt = pixelformat_for_depth(GetDeviceCaps(hDc, BITSPIXEL) * GetDeviceCaps(hDc, PLANES));
+
+#ifndef WINE_NATIVEWIN32
+    display = get_display(hDc);
+#endif
+
     ReleaseDC(object->win_handle, hDc);
+
+#ifndef WINE_NATIVEWIN32
     TRACE("Using a display of %p %p\n", display, hDc);
 
     if (NULL == display || NULL == hDc) {
@@ -1310,10 +1333,7 @@
         WARN("Failed to get a valid XVisuial ID for the window %p\n", object->win_handle);
         return WINED3DERR_NOTAVAILABLE;
     }
-
-    object->orig_width = GetSystemMetrics(SM_CXSCREEN);
-    object->orig_height = GetSystemMetrics(SM_CYSCREEN);
-    object->orig_fmt = pixelformat_for_depth(GetDeviceCaps(hDc, BITSPIXEL) * GetDeviceCaps(hDc, PLANES));
+#endif
 
     /** MSDN: If Windowed is TRUE and either of the BackBufferWidth/Height values is zero,
      *  then the corresponding dimension of the client area of the hDeviceWindow
@@ -1374,7 +1394,12 @@
     object->num_contexts = 1;
 
     ENTER_GL();
-    object->context[0] = CreateContext(This, (IWineD3DSurfaceImpl *) object->frontBuffer, display, object->win);
+    object->context[0] = CreateContext(
+#ifndef WINE_NATIVEWIN32
+        This, (IWineD3DSurfaceImpl *) object->frontBuffer, display, object->win);
+#else
+        This, (IWineD3DSurfaceImpl *) object->frontBuffer, object->win_handle);
+#endif
     LEAVE_GL();
 
     if (!object->context) {
@@ -1383,7 +1408,11 @@
         goto error;
     } else {
         TRACE("Context created (HWND=%p, glContext=%p, Window=%ld)\n",
+#ifndef WINE_NATIVEWIN32
                object->win_handle, object->context[0]->glCtx, object->win);
+#else
+               object->win_handle, object->context[0]->glCtx, object->win_handle);
+#endif
     }
 
    /*********************
@@ -1395,10 +1424,9 @@
    * so we should really check to see if there is a fullscreen swapchain already
    * I think Windows and X have different ideas about fullscreen, does a single head count as full screen?
     **************************************/
-
    if (!pPresentationParameters->Windowed) {
-
         DEVMODEW devmode;
+#ifndef WINE_NATIVEWIN32
         HDC      hdc;
         int      bpp = 0;
         RECT     clip_rc;
@@ -1409,7 +1437,8 @@
         ReleaseDC(0, hdc);
 
         /* Change the display settings */
-        memset(&devmode, 0, sizeof(DEVMODEW));
+        memset(&devmode, 0, sizeof(devmode));
+        devmode.dmSize       = sizeof(devmode);
         devmode.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
         devmode.dmBitsPerPel = (bpp >= 24) ? 32 : bpp; /* Stupid XVidMode cannot change bpp */
         devmode.dmPelsWidth  = pPresentationParameters->BackBufferWidth;
@@ -1427,6 +1456,21 @@
         /* And finally clip mouse to our screen */
         SetRect(&clip_rc, 0, 0, devmode.dmPelsWidth, devmode.dmPelsHeight);
         ClipCursor(&clip_rc);
+#else
+        /* Change the display settings */
+        memset(&devmode, 0, sizeof(devmode));
+        devmode.dmSize       = sizeof(devmode);
+        EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
+        devmode.dmPelsWidth  = pPresentationParameters->BackBufferWidth;
+        devmode.dmPelsHeight = pPresentationParameters->BackBufferHeight;
+        ChangeDisplaySettingsExW(0, &devmode, NULL, CDS_FULLSCREEN, NULL);
+        /* For GetDisplayMode */
+        This->ddraw_width = devmode.dmPelsWidth;
+        This->ddraw_height = devmode.dmPelsHeight;
+        This->ddraw_format = pPresentationParameters->BackBufferFormat;
+
+        IWineD3DDevice_SetFullscreen(iface, TRUE);
+#endif
     }
 
    /*********************
@@ -1781,11 +1825,12 @@
     object->palNumEntries = IWineD3DPaletteImpl_Size(Flags);
 	
     object->hpal = CreatePalette((const LOGPALETTE*)&(object->palVersion));
-
+#ifndef WINE_NATIVEWIN32
     if(!object->hpal) {
         HeapFree( GetProcessHeap(), 0, object);
         return E_OUTOFMEMORY;
     }
+#endif
 
     hr = IWineD3DPalette_SetEntries((IWineD3DPalette *) object, 0, 0, IWineD3DPaletteImpl_Size(Flags), PalEnt);
     if(FAILED(hr)) {
@@ -1857,8 +1902,11 @@
     * Initialize openGL extension related variables
     *  with Default values
     */
-
+#ifndef WINE_NATIVEWIN32
     ((IWineD3DImpl *) This->wineD3D)->isGLInfoValid = IWineD3DImpl_FillGLCaps(This->wineD3D, swapchain->context[0]->display);
+#else
+    ((IWineD3DImpl *) This->wineD3D)->isGLInfoValid = IWineD3DImpl_FillGLCaps(This->wineD3D);
+#endif
     /* Setup all the devices defaults */
     IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock *)This->stateBlock);
 #if 0
@@ -1915,7 +1963,7 @@
 static HRESULT WINAPI IWineD3DDeviceImpl_Uninit3D(IWineD3DDevice *iface, D3DCB_DESTROYSURFACEFN D3DCB_DestroyDepthStencilSurface, D3DCB_DESTROYSWAPCHAINFN D3DCB_DestroySwapChain) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     int sampler;
-    uint i;
+    unsigned int i;
     TRACE("(%p)\n", This);
 
     if(!This->d3d_initialized) return WINED3DERR_INVALIDCALL;
@@ -2029,6 +2077,8 @@
      * but we don't have any hwnd
      */
 
+    memset(&devmode, 0, sizeof(devmode));
+    devmode.dmSize = sizeof(devmode);
     devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
     devmode.dmBitsPerPel = formatDesc->bpp * 8;
     if(devmode.dmBitsPerPel == 24) devmode.dmBitsPerPel = 32;
@@ -2070,9 +2120,11 @@
     if(This->ddraw_window)
       MoveWindow(This->ddraw_window, 0, 0, pMode->Width, pMode->Height, TRUE);
 
+#ifndef WINE_NATIVEWIN32
     /* And finally clip mouse to our screen */
     SetRect(&clip_rc, 0, 0, pMode->Width, pMode->Height);
     ClipCursor(&clip_rc);
+#endif
 
     return WINED3D_OK;
 }
@@ -2456,11 +2508,11 @@
             rho = pLight->Theta + (pLight->Phi - pLight->Theta)/(2*pLight->Falloff);
         }
         if (rho < 0.0001) rho = 0.0001f;
-        object->exponent = -0.3/log(cos(rho/2));
+        object->exponent = -0.3f/log(cos(rho/2));
 	if (object->exponent > 128.0) {
 		object->exponent = 128.0;
 	}
-        object->cutoff = pLight->Phi*90/M_PI;
+        object->cutoff = pLight->Phi*90.0f/M_PI;
 
         /* FIXME: Range */
         break;
@@ -2952,11 +3004,16 @@
 
     This->updateStateBlock->set.scissorRect = TRUE;
     This->updateStateBlock->changed.scissorRect = TRUE;
-    if(EqualRect(&This->updateStateBlock->scissorRect, pRect)) {
+    /* if(EqualRect(&This->updateStateBlock->scissorRect, pRect)) { */
+    if (This->updateStateBlock->scissorRect.left == pRect->left
+            && This->updateStateBlock->scissorRect.right == pRect->right
+            && This->updateStateBlock->scissorRect.top == pRect->top
+            && This->updateStateBlock->scissorRect.bottom == pRect->bottom) {
         TRACE("App is setting the old scissor rectangle over, nothing to do\n");
         return WINED3D_OK;
     }
-    CopyRect(&This->updateStateBlock->scissorRect, pRect);
+    /* CopyRect(&This->updateStateBlock->scissorRect, pRect); */
+    This->updateStateBlock->scissorRect = *pRect;
 
     if(This->isRecordingState) {
         TRACE("Recording... not performing anything\n");
@@ -4330,7 +4387,8 @@
     if(Flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL) && This->stencilBufferTarget == NULL) {
         WARN("Clearing depth and/or stencil without a depth stencil buffer attached, returning WINED3DERR_INVALIDCALL\n");
         /* TODO: What about depth stencil buffers without stencil bits? */
-        return WINED3DERR_INVALIDCALL;
+        /* return WINED3DERR_INVALIDCALL; */
+        Flags &= ~(WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL);
     }
 
     ENTER_GL();
diff -Nur wine-0.9.36/dlls/wined3d/directx.c parallels/dlls/wined3d/directx.c
--- wine-0.9.36/dlls/wined3d/directx.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/directx.c	2009-01-29 12:56:04.000000000 +0100
@@ -37,6 +37,7 @@
 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
 #define GLINFO_LOCATION This->gl_info
 
+#ifndef WINE_NATIVEWIN32
 /**********************************************************
  * Utility functions follow
  **********************************************************/
@@ -60,6 +61,7 @@
                     sizeof(display), (LPSTR)&display )) display = NULL;
     return display;
 }
+#endif /*!WINE_NATIVEWIN32*/
 
 /* lookup tables */
 int minLookup[MAX_LOOKUPS];
@@ -78,7 +80,9 @@
 static int             wined3d_fake_gl_context_ref = 0;
 static BOOL            wined3d_fake_gl_context_foreign;
 static BOOL            wined3d_fake_gl_context_available = FALSE;
+#ifndef WINE_NATIVEWIN32
 static Display*        wined3d_fake_gl_context_display = NULL;
+#endif
 
 static CRITICAL_SECTION wined3d_fake_gl_context_cs;
 static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
@@ -91,7 +95,13 @@
 static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
 
 static void WineD3D_ReleaseFakeGLContext(void) {
+#ifndef WINE_NATIVEWIN32
     GLXContext glCtx;
+#else
+    HGLRC glCtx;
+    HDC hdc;
+    HWND hwnd;
+#endif
 
     EnterCriticalSection(&wined3d_fake_gl_context_cs);
 
@@ -101,14 +111,28 @@
         return;
     }
 
+#ifndef WINE_NATIVEWIN32
     glCtx = glXGetCurrentContext();
+#else
+    glCtx = wglGetCurrentContext();
+#endif
 
     TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
     if (0 == (--wined3d_fake_gl_context_ref) ) {
         if(!wined3d_fake_gl_context_foreign && glCtx) {
             TRACE_(d3d_caps)("destroying fake GL context\n");
+#ifndef WINE_NATIVEWIN32
             glXMakeCurrent(wined3d_fake_gl_context_display, None, NULL);
             glXDestroyContext(wined3d_fake_gl_context_display, glCtx);
+#else
+            hdc = wglGetCurrentDC();
+            hwnd = WindowFromDC(hdc);
+            wglMakeCurrent(0, 0);
+            wglDeleteContext(glCtx);
+            ReleaseDC(hwnd, hdc);
+            DestroyWindow(hwnd);
+            UnregisterClassW(L"wined3d_CapsWindowClass", GetModuleHandleW(L"wined3d.dll"));
+#endif
         }
         wined3d_fake_gl_context_available = FALSE;
     }
@@ -118,9 +142,54 @@
     LEAVE_GL();
 }
 
+static BOOL WineD3D_SelectPixelFormat(HDC hdc, DWORD bits) {
+    int index = 1;
+    int maxindex;
+
+    if (bits == 24)
+        bits = 32;
+    do {
+        PIXELFORMATDESCRIPTOR pfd;
+
+        maxindex = wglDescribePixelFormat(hdc, index, sizeof(pfd), &pfd);
+        /* skip non-GL formats */
+        if (~pfd.dwFlags
+            & (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
+            /* double buffering and GDI are mutually exclusive */
+                | PFD_DOUBLEBUFFER))
+            continue;
+        /* skip software GL implementation */
+        if (pfd.dwFlags & PFD_GENERIC_FORMAT)
+            continue;
+        /* we're not going to provide a palette, or do we?
+        if (pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE)
+            continue; */
+        /* skip paletized modes
+        if (pfd.iPixelType != PFD_TYPE_RGBA)
+            continue; */
+        /* do we need good depth buffer and stencil support?
+        if (pfd.cDepthBits < 15 || pfd.cStencilBits < 8)
+            continue; */
+        /* match bit depth */
+        if (pfd.cColorBits != bits)
+            continue;
+        /* pixel format can only be set once per window */
+        if (wglSetPixelFormat(hdc, index, &pfd))
+            return TRUE;
+    } while (index++ < maxindex);
+    return FALSE;
+}
+
 static BOOL WineD3D_CreateFakeGLContext(void) {
+#ifndef WINE_NATIVEWIN32
     XVisualInfo* visInfo;
     GLXContext   glCtx;
+#else
+    HGLRC glCtx;
+    HDC hdc;
+    HWND hwnd;
+    WNDCLASSW clss;
+#endif
 
     ENTER_GL();
     EnterCriticalSection(&wined3d_fake_gl_context_cs);
@@ -131,6 +200,7 @@
 
     wined3d_fake_gl_context_foreign = TRUE;
 
+#ifndef WINE_NATIVEWIN32
     if(!wined3d_fake_gl_context_display) {
         HDC        device_context = GetDC(0);
 
@@ -182,6 +252,41 @@
         XFree(visInfo);
 
     }
+#else /*WINE_NATIVEWIN32*/
+    glCtx = wglGetCurrentContext();
+
+    if (!glCtx) {
+        wined3d_fake_gl_context_foreign = FALSE;
+
+        TRACE_(d3d_caps)("Creating Fake GL Context\n");
+
+        memset(&clss, 0, sizeof(clss));
+        clss.hInstance = GetModuleHandleW(L"wined3d.dll");
+        clss.lpfnWndProc = DefWindowProcW;
+        clss.lpszClassName = L"wined3d_CapsWindowClass";
+        clss.hCursor = LoadCursor(0, IDC_ARROW);
+        RegisterClassW(&clss);
+
+        hwnd = CreateWindowExW(
+            0 /*don't: WS_EX_TOPMOST*/,
+            L"wined3d_CapsWindowClass", L"wined3d_CapsWindow",
+            WS_POPUP | WS_VISIBLE,
+            0, 0, GetSystemMetrics(SM_CXSCREEN), 1/*GetSystemMetrics(SM_CYSCREEN)*/,
+            0, 0, clss.hInstance, 0);
+        hdc = GetDC(hwnd);
+
+        /* Create a GL context */
+        if (!WineD3D_SelectPixelFormat(hdc, GetDeviceCaps(hdc, BITSPIXEL))
+            || !(glCtx = wglCreateContext(hdc))) {
+            WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
+            goto fail;
+        }
+        if (!wglMakeCurrent(hdc, glCtx)) {
+            WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
+            goto fail;
+        }
+    }
+#endif /*WINE_NATIVEWIN32*/
 
   ret:
     TRACE_(d3d_caps)("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
@@ -190,8 +295,14 @@
     LeaveCriticalSection(&wined3d_fake_gl_context_cs);
     return TRUE;
   fail:
+#ifndef WINE_NATIVEWIN32
     if(visInfo) XFree(visInfo);
     if(glCtx) glXDestroyContext(wined3d_fake_gl_context_display, glCtx);
+#else
+    if (glCtx) wglDeleteContext(glCtx);
+    if (hdc) ReleaseDC(hwnd, hdc);
+    if (hwnd) DestroyWindow(hwnd);
+#endif
     LeaveCriticalSection(&wined3d_fake_gl_context_cs);
     LEAVE_GL();
     return FALSE;
@@ -313,8 +424,11 @@
 /**********************************************************
  * IWineD3D parts follows
  **********************************************************/
-
+#ifndef WINE_NATIVEWIN32
 BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface, Display* display) {
+#else
+BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface) {
+#endif
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->gl_info;
 
@@ -324,8 +438,7 @@
     const char *gl_string_cursor = NULL;
     GLint       gl_max;
     GLfloat     gl_floatv[2];
-    Bool        test = 0;
-    int         major, minor;
+    int         major = 0, minor = 9;
     BOOL        return_value = TRUE;
     int         i;
 
@@ -335,20 +448,27 @@
     if (!WineD3D_CreateFakeGLContext() || wined3d_fake_gl_context_foreign)
         return_value = FALSE;
 
+#ifndef WINE_NATIVEWIN32
     TRACE_(d3d_caps)("(%p, %p)\n", gl_info, display);
+#else
+    TRACE_(d3d_caps)("(%p)\n", gl_info);
+#endif
 
     gl_string = (const char *) glGetString(GL_RENDERER);
     if (NULL == gl_string)
 	gl_string = "None";
     strcpy(gl_info->gl_renderer, gl_string);
 
+#ifndef WINE_NATIVEWIN32
     /* Fill in the GL info retrievable depending on the display */
     if (NULL != display) {
+        Bool test = 0;
         test = glXQueryVersion(display, &major, &minor);
         gl_info->glx_version = ((major & 0x0000FFFF) << 16) | (minor & 0x0000FFFF);
     } else {
         FIXME("Display must not be NULL, use glXGetCurrentDisplay or getAdapterDisplay()\n");
     }
+#endif
     gl_string = (const char *) glGetString(GL_VENDOR);
 
     TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
@@ -359,7 +479,7 @@
         } else if (strstr(gl_string, "ATI")) {
             gl_info->gl_vendor = VENDOR_ATI;
         } else if (strstr(gl_string, "Intel(R)") || 
-		   strstr(gl_info->gl_renderer, "Intel(R)")) {
+                strstr(gl_info->gl_renderer, "Intel(R)")) {
             gl_info->gl_vendor = VENDOR_INTEL;
         } else if (strstr(gl_string, "Mesa")) {
             gl_info->gl_vendor = VENDOR_MESA;
@@ -385,13 +505,8 @@
                 break;
             }
 
-            gl_string_cursor = strstr(gl_string_cursor, " ");
-            if (!gl_string_cursor) {
-                ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
-                break;
-            }
-
-            while (*gl_string_cursor == ' ') {
+            gl_string_cursor += strlen("NVIDIA");
+            while (*gl_string_cursor == ' ' || *gl_string_cursor == '-') {
                 ++gl_string_cursor;
             }
 
@@ -509,9 +624,13 @@
     gl_info->ps_arb_constantsF = 0;
 
     /* Now work out what GL support this card really has */
+#ifndef WINE_NATIVEWIN32
 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
-    GL_EXT_FUNCS_GEN;
-    GLX_EXT_FUNCS_GEN;
+#else
+#define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) wglGetProcAddress(#pfn);
+#endif
+    GL_EXT_FUNCS_GEN
+    GLX_EXT_FUNCS_GEN
 #undef USE_GL_FUNC
 
     /* Retrieve opengl defaults */
@@ -551,7 +670,7 @@
                 GL_Extensions++;
             }
             memcpy(ThisExtn, Start, (GL_Extensions - Start));
-            TRACE_(d3d_caps)("- %s\n", ThisExtn);
+            /* TRACE_(d3d_caps)("- %s\n", ThisExtn); */
 
             /**
              * ARB
@@ -1036,6 +1155,7 @@
 
 /* TODO: config lookups */
 
+#ifndef WINE_NATIVEWIN32
     if (display != NULL) {
         GLX_Extensions = glXQueryExtensionsString(display, DefaultScreen(display));
         TRACE_(d3d_caps)("GLX_Extensions reported:\n");
@@ -1057,7 +1177,7 @@
             }
         }
     }
-
+#endif /*WINE_NATIVEWIN32*/
 
     WineD3D_ReleaseFakeGLContext();
     return return_value;
@@ -1112,6 +1232,8 @@
         if (!DEBUG_SINGLE_MODE) {
             DEVMODEW DevModeW;
 
+            DevModeW.dmSize = sizeof(DevModeW);
+            DevModeW.dmDriverExtra = 0;
             while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
                 j++;
                 switch (Format)
@@ -1166,6 +1288,8 @@
         int i = 0;
         int j = 0;
 
+        DevModeW.dmSize = sizeof(DevModeW);
+        DevModeW.dmDriverExtra = 0;
         /* If we are filtering to a specific format (D3D9), then need to skip
            all unrelated modes, but if mode is irrelevant (D3D8), then we can
            just count through the ones with valid bit depths */
@@ -1199,6 +1323,8 @@
         }
         ModeIdx = j - 1;
 
+        DevModeW.dmSize = sizeof(DevModeW);
+        DevModeW.dmDriverExtra = 0;
         /* Now get the display mode via the calculated index */
         if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
             pMode->Width        = DevModeW.dmPelsWidth;
@@ -1263,6 +1389,8 @@
         int bpp = 0;
         DEVMODEW DevModeW;
 
+        DevModeW.dmSize = sizeof(DevModeW);
+        DevModeW.dmDriverExtra = 0;
         EnumDisplaySettingsExW(NULL, (DWORD)-1, &DevModeW, 0);
         pMode->Width        = DevModeW.dmPelsWidth;
         pMode->Height       = DevModeW.dmPelsHeight;
@@ -1290,6 +1418,7 @@
     return WINED3D_OK;
 }
 
+#ifndef WINE_NATIVEWIN32
 static Display * WINAPI IWineD3DImpl_GetAdapterDisplay(IWineD3D *iface, UINT Adapter) {
     Display *display;
     HDC     device_context;
@@ -1301,6 +1430,7 @@
     ReleaseDC(0, device_context);
     return display;
 }
+#endif
 
 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
    and fields being inserted in the middle, a new structure is used in place    */
@@ -1323,7 +1453,11 @@
            a temporary context may differ from the final ones                 */
         if (!isGLInfoValid) {
             /* If we don't know the device settings, go query them now */
+#ifndef WINE_NATIVEWIN32
             isGLInfoValid = IWineD3DImpl_FillGLCaps(iface, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
+#else
+            isGLInfoValid = IWineD3DImpl_FillGLCaps(iface);
+#endif
         }
 
         /* Return the information requested */
@@ -1355,6 +1489,7 @@
     return WINED3D_OK;
 }
 
+#ifndef WINE_NATIVEWIN32
 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(Display *display, GLXFBConfig cfgs, WINED3DFORMAT Format) {
 #if 0 /* This code performs a strict test between the format and the current X11  buffer depth, which may give the best performance */
   int gl_test;
@@ -1479,6 +1614,7 @@
   return FALSE;
 #endif
 }
+#endif
 
 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
                                                    WINED3DFORMAT AdapterFormat,
@@ -1486,9 +1622,12 @@
                                                    WINED3DFORMAT DepthStencilFormat) {
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
     HRESULT hr = WINED3DERR_NOTAVAILABLE;
+#ifndef WINE_NATIVEWIN32
     GLXFBConfig* cfgs = NULL;
     int nCfgs = 0;
     int it;
+#else
+#endif
 
     WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
            This, Adapter,
@@ -1502,6 +1641,7 @@
         return WINED3DERR_INVALIDCALL;
     }
 
+#ifndef WINE_NATIVEWIN32
     if(WineD3D_CreateFakeGLContext())
         cfgs = glXGetFBConfigs(wined3d_fake_gl_context_display, DefaultScreen(wined3d_fake_gl_context_display), &nCfgs);
 
@@ -1523,6 +1663,10 @@
     }
 
     WineD3D_ReleaseFakeGLContext();
+#else
+	/* TODO: scan available pixel formats */
+    hr = WINED3D_OK;
+#endif
 
     if (hr != WINED3D_OK)
         TRACE_(d3d_caps)("Failed to match stencil format to device\n");
@@ -1566,10 +1710,13 @@
                                             WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
 
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
+    HRESULT hr = WINED3DERR_NOTAVAILABLE;
+#ifndef WINE_NATIVEWIN32
     GLXFBConfig* cfgs = NULL;
     int nCfgs = 0;
     int it;
-    HRESULT hr = WINED3DERR_NOTAVAILABLE;
+#else
+#endif
 
     TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
           This,
@@ -1584,6 +1731,7 @@
         return WINED3DERR_INVALIDCALL;
     }
 
+#ifndef WINE_NATIVEWIN32
     if (WineD3D_CreateFakeGLContext()) {
       cfgs = glXGetFBConfigs(wined3d_fake_gl_context_display, DefaultScreen(wined3d_fake_gl_context_display), &nCfgs);
       for (it = 0; it < nCfgs; ++it) {
@@ -1598,6 +1746,10 @@
           ERR("unsupported format %s\n", debug_d3dformat(DisplayFormat));
       WineD3D_ReleaseFakeGLContext();
     }
+#else
+	/* TODO: scan available pixel formats */
+    hr = WINED3D_OK;
+#endif
 
     if(hr != WINED3D_OK)
         TRACE_(d3d_caps)("returning something different from WINED3D_OK\n");
@@ -1869,7 +2021,11 @@
     /* If we don't know the device settings, go query them now */
     if (!This->isGLInfoValid) {
         /* use the desktop window to fill gl caps */
+#ifndef WINE_NATIVEWIN32
         BOOL rc = IWineD3DImpl_FillGLCaps(iface, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
+#else
+        BOOL rc = IWineD3DImpl_FillGLCaps(iface);
+#endif
 
         /* We are running off a real context, save the values */
         if (rc) This->isGLInfoValid = TRUE;
@@ -2479,7 +2635,11 @@
     /* Setup some defaults for creating the implicit swapchain */
     ENTER_GL();
     /* FIXME: GL info should be per adapter */
+#ifndef WINE_NATIVEWIN32
     IWineD3DImpl_FillGLCaps(iface, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
+#else
+    IWineD3DImpl_FillGLCaps(iface);
+#endif
     LEAVE_GL();
     select_shader_mode(&This->gl_info, DeviceType, &object->ps_selected_mode, &object->vs_selected_mode);
     if (object->ps_selected_mode == SHADER_GLSL || object->vs_selected_mode == SHADER_GLSL) {
diff -Nur wine-0.9.36/dlls/wined3d/drawprim.c parallels/dlls/wined3d/drawprim.c
--- wine-0.9.36/dlls/wined3d/drawprim.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/drawprim.c	2009-01-29 12:56:04.000000000 +0100
@@ -482,7 +482,7 @@
     /* Adding the stream offset once is cheaper than doing it every iteration. Do not modify the strided data, it is a pointer
      * to the strided Data in the device and might be needed intact on the next draw
      */
-    for (textureNo = 0, texture_idx = 0; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
+    for (textureNo = 0; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
         if(sd->u.s.texCoords[textureNo].lpData) {
             texCoords[textureNo] = sd->u.s.texCoords[textureNo].lpData + streamOffset[sd->u.s.texCoords[textureNo].streamNo];
         } else {
@@ -547,7 +547,7 @@
         }
 
         /* Texture coords --------------------------- */
-        for (textureNo = 0, texture_idx = 0; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
+        for (textureNo = 0, texture_idx = GL_TEXTURE0_ARB; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
 
             if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0) {
                 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
@@ -740,7 +740,7 @@
                 VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z));
                 glVertex3f(x, y, z);
             } else {
-                GLfloat w = 1.0 / rhw;
+                GLfloat w = 1.0f / rhw;
                 VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f / rhw=%f\n", x,y,z,rhw));
                 glVertex4f(x*w, y*w, z*w, w);
             }
diff -Nur wine-0.9.36/dlls/wined3d/indexbuffer.c parallels/dlls/wined3d/indexbuffer.c
--- wine-0.9.36/dlls/wined3d/indexbuffer.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/indexbuffer.c	2009-01-29 12:56:04.000000000 +0100
@@ -107,7 +107,7 @@
 }
 
 static void WINAPI IWineD3DIndexBufferImpl_PreLoad(IWineD3DIndexBuffer *iface) {
-    return IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
+    /*return*/ IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
 }
 
 static WINED3DRESOURCETYPE WINAPI IWineD3DIndexBufferImpl_GetType(IWineD3DIndexBuffer *iface) {
diff -Nur wine-0.9.36/dlls/wined3d/palette.c parallels/dlls/wined3d/palette.c
--- wine-0.9.36/dlls/wined3d/palette.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/palette.c	2009-01-29 12:56:03.000000000 +0100
@@ -19,8 +19,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 #include "config.h"
-#include "winerror.h"
-#include "wine/debug.h"
 
 #include <assert.h>
 #include <string.h>
diff -Nur wine-0.9.36/dlls/wined3d/pglmini.c parallels/dlls/wined3d/pglmini.c
--- wine-0.9.36/dlls/wined3d/pglmini.c	1970-01-01 01:00:00.000000000 +0100
+++ parallels/dlls/wined3d/pglmini.c	2009-01-29 12:56:03.000000000 +0100
@@ -0,0 +1,281 @@
+#include "config.h"
+
+#include <windows.h>
+
+#include <GL/gl.h>
+
+#include "pglmini.h"
+
+#undef wglDescribePixelFormat
+#undef wglSetPixelFormat
+#undef wglMakeCurrent
+#undef wglGetCurrentContext
+#undef wglGetCurrentDC
+#undef wglCreateContext
+#undef wglDeleteContext
+#undef wglGetProcAddress
+
+
+BOOL WINE_WINAPI(*pwglMakeCurrent)(HDC hdc, HGLRC hgl);
+HGLRC WINE_WINAPI(*pwglGetCurrentContext)(VOID);
+HDC WINE_WINAPI(*pwglGetCurrentDC)(VOID);
+
+int WINE_WINAPI(*pDrvDescribePixelFormat)(
+    HDC hdc, int index, UINT size, LPPIXELFORMATDESCRIPTOR format);
+BOOL WINE_WINAPI(*pDrvSetPixelFormat)(HDC hdc, int index);
+PVOID WINE_APIENTRY(*pDrvSetContext)(HDC hdc, HGLRC hgl, PVOID);
+VOID WINE_APIENTRY(*pDrvReleaseContext)(HGLRC hgl);
+BOOL WINE_APIENTRY(*pDrvSwapBuffers)(HDC hdc);
+
+HGLRC WINE_APIENTRY(*pDrvCreateContext)(HDC hdc);
+BOOL WINE_APIENTRY(*pDrvDeleteContext)(HGLRC hgl);
+PROC WINE_APIENTRY(*pDrvGetProcAddress)(LPCSTR name);
+
+struct pgl_iat_s pgl_iat;
+
+static const char *pgl_names[] = {
+	"glAlphaFunc",
+	"glBegin",
+	"glBindTexture",
+	"glBlendFunc",
+	"glClear",
+	"glClearColor",
+	"glClearDepth",
+	"glClearIndex",
+	"glClearStencil",
+	"glClipPlane",
+	"glColor3d",
+	"glColor3f",
+	"glColor4f",
+	"glColor4ub",
+	"glColorMask",
+	"glColorMaterial",
+	"glColorPointer",
+	"glCopyTexImage2D",
+	"glCopyTexSubImage2D",
+	"glCullFace",
+	"glDeleteTextures",
+	"glDepthFunc",
+	"glDepthMask",
+	"glDepthRange",
+	"glDisable",
+	"glDisableClientState",
+	"glDrawArrays",
+	"glDrawBuffer",
+	"glDrawElements",
+	"glDrawPixels",
+	"glEnable",
+	"glEnableClientState",
+	"glEnd",
+	"glFlush",
+	"glFogf",
+	"glFogfv",
+	"glFogi",
+	"glFrontFace",
+	"glGenTextures",
+	"glGetError",
+	"glGetFloatv",
+	"glGetIntegerv",
+	"glGetString",
+	"glGetTexImage",
+	"glHint",
+	"glLightModelfv",
+	"glLightModeli",
+	"glLightf",
+	"glLightfv",
+	"glLineStipple",
+	"glLoadIdentity",
+	"glLoadMatrixf",
+	"glMaterialf",
+	"glMaterialfv",
+	"glMatrixMode",
+	"glMultMatrixf",
+	"glNormal3f",
+	"glNormalPointer",
+	"glOrtho",
+	"glPixelStorei",
+	"glPixelZoom",
+	"glPointSize",
+	"glPolygonMode",
+	"glPolygonOffset",
+	"glPopAttrib",
+	"glPopMatrix",
+	"glPrioritizeTextures",
+	"glPushAttrib",
+	"glPushMatrix",
+	"glRasterPos3i",
+	"glRasterPos3iv",
+	"glReadBuffer",
+	"glReadPixels",
+	"glScissor",
+	"glShadeModel",
+	"glStencilFunc",
+	"glStencilMask",
+	"glStencilOp",
+	"glTexCoord1f",
+	"glTexCoord2f",
+	"glTexCoord3f",
+	"glTexCoord3iv",
+	"glTexCoord4f",
+	"glTexCoordPointer",
+	"glTexEnvf",
+	"glTexEnvfv",
+	"glTexEnvi",
+	"glTexGenfv",
+	"glTexGeni",
+	"glTexImage2D",
+	"glTexParameterfv",
+	"glTexParameteri",
+	"glTexSubImage2D",
+	"glTranslatef",
+	"glVertex2f",
+	"glVertex2i",
+	"glVertex3d",
+	"glVertex3f",
+	"glVertex4f",
+	"glVertexPointer",
+	"glViewport",
+};
+struct pgl_assert_s {
+    char assert_size[sizeof(pgl_iat) == sizeof(pgl_names) ? 1 : -1];
+};
+
+
+HMODULE hPrlicd32;
+HMODULE hOpengl32;
+
+BOOL
+pglInit()
+{
+    int i;
+
+    hPrlicd32 = LoadLibrary("prlicd32.dll");
+    if (hPrlicd32) {
+#define getproc(x) *(FARPROC *)&p##x = GetProcAddress(hPrlicd32, #x)
+        getproc(DrvDescribePixelFormat);
+        getproc(DrvSetPixelFormat);
+        getproc(DrvSetContext);
+        getproc(DrvReleaseContext);
+        getproc(DrvSwapBuffers);
+        getproc(DrvCreateContext);
+        getproc(DrvDeleteContext);
+        getproc(DrvGetProcAddress);
+#undef getproc
+        for (i = sizeof(pgl_names)/sizeof(pgl_names[1]); --i >= 0; ) {
+            ((FARPROC *)&pgl_iat)[i] = GetProcAddress(hPrlicd32, pgl_names[i]);
+        }
+        return TRUE;
+    }
+    hOpengl32 = LoadLibrary("opengl32.dll");
+    if (hOpengl32) {
+#define getproc(x) *(FARPROC *)&p##x = GetProcAddress(hOpengl32, #x)
+        getproc(wglMakeCurrent);
+        getproc(wglGetCurrentContext);
+        getproc(wglGetCurrentDC);
+#undef getproc
+#define getproc(x, y) *(FARPROC *)&p##x = GetProcAddress(hOpengl32, #y)
+        getproc(DrvCreateContext, wglCreateContext);
+        getproc(DrvDeleteContext, wglDeleteContext);
+        getproc(DrvGetProcAddress, wglGetProcAddress);
+#undef getproc
+        for (i = sizeof(pgl_names)/sizeof(pgl_names[1]); --i >= 0; ) {
+            ((FARPROC *)&pgl_iat)[i] = GetProcAddress(hOpengl32, pgl_names[i]);
+        }
+        return TRUE;
+    }
+    return FALSE;
+}
+
+VOID
+pglFini()
+{
+    if (hPrlicd32)
+        FreeLibrary(hPrlicd32);
+    hPrlicd32 = NULL;
+    if (hOpengl32)
+        FreeLibrary(hOpengl32);
+    hOpengl32 = NULL;
+}
+
+
+static HDC g_hdc;
+static HGLRC g_hgl;
+
+int WINAPI
+pglDescribePixelFormat(
+    HDC hdc, int index, UINT size, LPPIXELFORMATDESCRIPTOR format)
+{
+    if (pDrvDescribePixelFormat)
+        return pDrvDescribePixelFormat(hdc, index, size, format);
+    return DescribePixelFormat(hdc, index, size, format);
+}
+
+BOOL WINAPI
+pglSetPixelFormat(HDC hdc, int index, const LPPIXELFORMATDESCRIPTOR format)
+{
+    if (pDrvSetPixelFormat)
+        return pDrvSetPixelFormat(hdc, index);
+    return SetPixelFormat(hdc, index, format);
+}
+
+BOOL WINAPI
+pglMakeCurrent(HDC hdc, HGLRC hgl)
+{
+    if (pwglMakeCurrent)
+        return pwglMakeCurrent(hdc, hgl);
+    if (!hgl) {
+        if (g_hgl)
+            pDrvReleaseContext(g_hgl);
+        g_hdc = 0;
+        g_hgl = 0;
+        return TRUE;
+    }
+    if (pDrvSetContext(hdc, hgl, 0)) {
+        g_hdc = hdc;
+        g_hgl = hgl;
+        return TRUE;
+    }
+    return FALSE;
+}
+
+HGLRC WINAPI
+pglGetCurrentContext(VOID)
+{
+    if (pwglGetCurrentContext)
+        return pwglGetCurrentContext();
+    return g_hgl;
+}
+
+HDC WINAPI
+pglGetCurrentDC(VOID)
+{
+    if (pwglGetCurrentDC)
+        return pwglGetCurrentDC();
+    return g_hdc;
+}
+
+BOOL WINAPI
+pglSwapBuffers(HDC hdc)
+{
+    if (pDrvSwapBuffers)
+        return pDrvSwapBuffers(hdc);
+    return SwapBuffers(hdc);
+}
+
+HGLRC WINAPI
+pglCreateContext(HDC hdc)
+{
+    return pDrvCreateContext(hdc);
+}
+
+BOOL WINAPI
+pglDeleteContext(HGLRC hgl)
+{
+    return pDrvDeleteContext(hgl);
+}
+
+PROC WINAPI
+pglGetProcAddress(LPCSTR name)
+{
+    return pDrvGetProcAddress(name);
+}
diff -Nur wine-0.9.36/dlls/wined3d/pglmini.h parallels/dlls/wined3d/pglmini.h
--- wine-0.9.36/dlls/wined3d/pglmini.h	1970-01-01 01:00:00.000000000 +0100
+++ parallels/dlls/wined3d/pglmini.h	2009-01-29 12:56:04.000000000 +0100
@@ -0,0 +1,237 @@
+#ifndef __WINE_PGLMINI_H
+#define __WINE_PGLMINI_H
+
+BOOL pglInit();
+VOID pglFini();
+
+
+int WINAPI pglDescribePixelFormat(
+    HDC hdc, int index, UINT size, LPPIXELFORMATDESCRIPTOR format);
+BOOL WINAPI pglSetPixelFormat(
+    HDC hdc, int index, const LPPIXELFORMATDESCRIPTOR format);
+HGLRC WINAPI pglCreateContext(HDC hdc);
+BOOL WINAPI pglDeleteContext(HGLRC hgl);
+HGLRC WINAPI pglGetCurrentContext(VOID);
+HDC WINAPI pglGetCurrentDC(VOID);
+BOOL WINAPI pglMakeCurrent(HDC hdc, HGLRC hgl);
+PROC WINAPI pglGetProcAddress(LPCSTR name);
+BOOL WINAPI pglSwapBuffers(HDC hdc);
+
+#define wglDescribePixelFormat pglDescribePixelFormat
+#define wglSetPixelFormat pglSetPixelFormat
+#define wglCreateContext pglCreateContext
+#define wglDeleteContext pglDeleteContext
+#define wglGetCurrentContext pglGetCurrentContext
+#define wglGetCurrentDC pglGetCurrentDC
+#define wglMakeCurrent pglMakeCurrent
+#define wglGetProcAddress pglGetProcAddress
+#define wglSwapBuffers pglSwapBuffers
+
+struct pgl_iat_s {
+	void WINE_APIENTRY(*pglAlphaFunc)(GLenum func, GLclampf ref);
+	void WINE_APIENTRY(*pglBegin)(GLenum mode);
+	void WINE_APIENTRY(*pglBindTexture)(GLenum target, GLuint texture);
+	void WINE_APIENTRY(*pglBlendFunc)(GLenum sfactor, GLenum dfactor);
+	void WINE_APIENTRY(*pglClear)(GLbitfield mask);
+	void WINE_APIENTRY(*pglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+	void WINE_APIENTRY(*pglClearDepth)(GLclampd depth);
+	void WINE_APIENTRY(*pglClearIndex)(GLfloat c);
+	void WINE_APIENTRY(*pglClearStencil)(GLint s);
+	void WINE_APIENTRY(*pglClipPlane)(GLenum plane, const GLdouble *equation);
+	void WINE_APIENTRY(*pglColor3d)(GLdouble red, GLdouble green, GLdouble blue);
+	void WINE_APIENTRY(*pglColor3f)(GLfloat red, GLfloat green, GLfloat blue);
+	void WINE_APIENTRY(*pglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+	void WINE_APIENTRY(*pglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
+	void WINE_APIENTRY(*pglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+	void WINE_APIENTRY(*pglColorMaterial)(GLenum face, GLenum mode);
+	void WINE_APIENTRY(*pglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+	void WINE_APIENTRY(*pglCopyTexImage2D)(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+	void WINE_APIENTRY(*pglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+	void WINE_APIENTRY(*pglCullFace)(GLenum mode);
+	void WINE_APIENTRY(*pglDeleteTextures)(GLsizei n, const GLuint *textures);
+	void WINE_APIENTRY(*pglDepthFunc)(GLenum func);
+	void WINE_APIENTRY(*pglDepthMask)(GLboolean flag);
+	void WINE_APIENTRY(*pglDepthRange)(GLclampd zNear, GLclampd zFar);
+	void WINE_APIENTRY(*pglDisable)(GLenum cap);
+	void WINE_APIENTRY(*pglDisableClientState)(GLenum array);
+	void WINE_APIENTRY(*pglDrawArrays)(GLenum mode, GLint first, GLsizei count);
+	void WINE_APIENTRY(*pglDrawBuffer)(GLenum mode);
+	void WINE_APIENTRY(*pglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
+	void WINE_APIENTRY(*pglDrawPixels)(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+	void WINE_APIENTRY(*pglEnable)(GLenum cap);
+	void WINE_APIENTRY(*pglEnableClientState)(GLenum array);
+	void WINE_APIENTRY(*pglEnd)(void);
+	void WINE_APIENTRY(*pglFlush)(void);
+	void WINE_APIENTRY(*pglFogf)(GLenum pname, GLfloat param);
+	void WINE_APIENTRY(*pglFogfv)(GLenum pname, const GLfloat *params);
+	void WINE_APIENTRY(*pglFogi)(GLenum pname, GLint param);
+	void WINE_APIENTRY(*pglFrontFace)(GLenum mode);
+	void WINE_APIENTRY(*pglGenTextures)(GLsizei n, GLuint *textures);
+	GLenum WINE_APIENTRY(*pglGetError)(void);
+	void WINE_APIENTRY(*pglGetFloatv)(GLenum pname, GLfloat *params);
+	void WINE_APIENTRY(*pglGetIntegerv)(GLenum pname, GLint *params);
+	const GLubyte * WINE_APIENTRY(*pglGetString)(GLenum name);
+	void WINE_APIENTRY(*pglGetTexImage)(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels);
+	void WINE_APIENTRY(*pglHint)(GLenum target, GLenum mode);
+	void WINE_APIENTRY(*pglLightModelfv)(GLenum pname, const GLfloat *params);
+	void WINE_APIENTRY(*pglLightModeli)(GLenum pname, GLint param);
+	void WINE_APIENTRY(*pglLightf)(GLenum light, GLenum pname, GLfloat param);
+	void WINE_APIENTRY(*pglLightfv)(GLenum light, GLenum pname, const GLfloat *params);
+	void WINE_APIENTRY(*pglLineStipple)(GLint factor, GLushort pattern);
+	void WINE_APIENTRY(*pglLoadIdentity)(void);
+	void WINE_APIENTRY(*pglLoadMatrixf)(const GLfloat *m);
+	void WINE_APIENTRY(*pglMaterialf)(GLenum face, GLenum pname, GLfloat param);
+	void WINE_APIENTRY(*pglMaterialfv)(GLenum face, GLenum pname, const GLfloat *params);
+	void WINE_APIENTRY(*pglMatrixMode)(GLenum mode);
+	void WINE_APIENTRY(*pglMultMatrixf)(const GLfloat *m);
+	void WINE_APIENTRY(*pglNormal3f)(GLfloat nx, GLfloat ny, GLfloat nz);
+	void WINE_APIENTRY(*pglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *pointer);
+	void WINE_APIENTRY(*pglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+	void WINE_APIENTRY(*pglPixelStorei)(GLenum pname, GLint param);
+	void WINE_APIENTRY(*pglPixelZoom)(GLfloat xfactor, GLfloat yfactor);
+	void WINE_APIENTRY(*pglPointSize)(GLfloat size);
+	void WINE_APIENTRY(*pglPolygonMode)(GLenum face, GLenum mode);
+	void WINE_APIENTRY(*pglPolygonOffset)(GLfloat factor, GLfloat units);
+	void WINE_APIENTRY(*pglPopAttrib)(void);
+	void WINE_APIENTRY(*pglPopMatrix)(void);
+	void WINE_APIENTRY(*pglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
+	void WINE_APIENTRY(*pglPushAttrib)(GLbitfield mask);
+	void WINE_APIENTRY(*pglPushMatrix)(void);
+	void WINE_APIENTRY(*pglRasterPos3i)(GLint x, GLint y, GLint z);
+	void WINE_APIENTRY(*pglRasterPos3iv)(const GLint *v);
+	void WINE_APIENTRY(*pglReadBuffer)(GLenum mode);
+	void WINE_APIENTRY(*pglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
+	void WINE_APIENTRY(*pglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
+	void WINE_APIENTRY(*pglShadeModel)(GLenum mode);
+	void WINE_APIENTRY(*pglStencilFunc)(GLenum func, GLint ref, GLuint mask);
+	void WINE_APIENTRY(*pglStencilMask)(GLuint mask);
+	void WINE_APIENTRY(*pglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
+	void WINE_APIENTRY(*pglTexCoord1f)(GLfloat s);
+	void WINE_APIENTRY(*pglTexCoord2f)(GLfloat s, GLfloat t);
+	void WINE_APIENTRY(*pglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
+	void WINE_APIENTRY(*pglTexCoord3iv)(const GLint *v);
+	void WINE_APIENTRY(*pglTexCoord4f)(GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+	void WINE_APIENTRY(*pglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+	void WINE_APIENTRY(*pglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
+	void WINE_APIENTRY(*pglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
+	void WINE_APIENTRY(*pglTexEnvi)(GLenum target, GLenum pname, GLint param);
+	void WINE_APIENTRY(*pglTexGenfv)(GLenum coord, GLenum pname, const GLfloat *params);
+	void WINE_APIENTRY(*pglTexGeni)(GLenum coord, GLenum pname, GLint param);
+	void WINE_APIENTRY(*pglTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+	void WINE_APIENTRY(*pglTexParameterfv)(GLenum target, GLenum pname, const GLfloat *params);
+	void WINE_APIENTRY(*pglTexParameteri)(GLenum target, GLenum pname, GLint param);
+	void WINE_APIENTRY(*pglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+	void WINE_APIENTRY(*pglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
+	void WINE_APIENTRY(*pglVertex2f)(GLfloat x, GLfloat y);
+	void WINE_APIENTRY(*pglVertex2i)(GLint x, GLint y);
+	void WINE_APIENTRY(*pglVertex3d)(GLdouble x, GLdouble y, GLdouble z);
+	void WINE_APIENTRY(*pglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
+	void WINE_APIENTRY(*pglVertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+	void WINE_APIENTRY(*pglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
+	void WINE_APIENTRY(*pglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
+};
+extern struct pgl_iat_s pgl_iat;
+
+#define glAlphaFunc pgl_iat.pglAlphaFunc
+#define glBegin pgl_iat.pglBegin
+#define glBindTexture pgl_iat.pglBindTexture
+#define glBlendFunc pgl_iat.pglBlendFunc
+#define glClear pgl_iat.pglClear
+#define glClearColor pgl_iat.pglClearColor
+#define glClearDepth pgl_iat.pglClearDepth
+#define glClearIndex pgl_iat.pglClearIndex
+#define glClearStencil pgl_iat.pglClearStencil
+#define glClipPlane pgl_iat.pglClipPlane
+#define glColor3d pgl_iat.pglColor3d
+#define glColor3f pgl_iat.pglColor3f
+#define glColor4f pgl_iat.pglColor4f
+#define glColor4ub pgl_iat.pglColor4ub
+#define glColorMask pgl_iat.pglColorMask
+#define glColorMaterial pgl_iat.pglColorMaterial
+#define glColorPointer pgl_iat.pglColorPointer
+#define glCopyTexImage2D pgl_iat.pglCopyTexImage2D
+#define glCopyTexSubImage2D pgl_iat.pglCopyTexSubImage2D
+#define glCullFace pgl_iat.pglCullFace
+#define glDeleteTextures pgl_iat.pglDeleteTextures
+#define glDepthFunc pgl_iat.pglDepthFunc
+#define glDepthMask pgl_iat.pglDepthMask
+#define glDepthRange pgl_iat.pglDepthRange
+#define glDisable pgl_iat.pglDisable
+#define glDisableClientState pgl_iat.pglDisableClientState
+#define glDrawArrays pgl_iat.pglDrawArrays
+#define glDrawBuffer pgl_iat.pglDrawBuffer
+#define glDrawElements pgl_iat.pglDrawElements
+#define glDrawPixels pgl_iat.pglDrawPixels
+#define glEnable pgl_iat.pglEnable
+#define glEnableClientState pgl_iat.pglEnableClientState
+#define glEnd pgl_iat.pglEnd
+#define glFlush pgl_iat.pglFlush
+#define glFogf pgl_iat.pglFogf
+#define glFogfv pgl_iat.pglFogfv
+#define glFogi pgl_iat.pglFogi
+#define glFrontFace pgl_iat.pglFrontFace
+#define glGenTextures pgl_iat.pglGenTextures
+#define glGetError pgl_iat.pglGetError
+#define glGetFloatv pgl_iat.pglGetFloatv
+#define glGetIntegerv pgl_iat.pglGetIntegerv
+#define glGetString pgl_iat.pglGetString
+#define glGetTexImage pgl_iat.pglGetTexImage
+#define glHint pgl_iat.pglHint
+#define glLightModelfv pgl_iat.pglLightModelfv
+#define glLightModeli pgl_iat.pglLightModeli
+#define glLightf pgl_iat.pglLightf
+#define glLightfv pgl_iat.pglLightfv
+#define glLineStipple pgl_iat.pglLineStipple
+#define glLoadIdentity pgl_iat.pglLoadIdentity
+#define glLoadMatrixf pgl_iat.pglLoadMatrixf
+#define glMaterialf pgl_iat.pglMaterialf
+#define glMaterialfv pgl_iat.pglMaterialfv
+#define glMatrixMode pgl_iat.pglMatrixMode
+#define glMultMatrixf pgl_iat.pglMultMatrixf
+#define glNormal3f pgl_iat.pglNormal3f
+#define glNormalPointer pgl_iat.pglNormalPointer
+#define glOrtho pgl_iat.pglOrtho
+#define glPixelStorei pgl_iat.pglPixelStorei
+#define glPixelZoom pgl_iat.pglPixelZoom
+#define glPointSize pgl_iat.pglPointSize
+#define glPolygonMode pgl_iat.pglPolygonMode
+#define glPolygonOffset pgl_iat.pglPolygonOffset
+#define glPopAttrib pgl_iat.pglPopAttrib
+#define glPopMatrix pgl_iat.pglPopMatrix
+#define glPrioritizeTextures pgl_iat.pglPrioritizeTextures
+#define glPushAttrib pgl_iat.pglPushAttrib
+#define glPushMatrix pgl_iat.pglPushMatrix
+#define glRasterPos3i pgl_iat.pglRasterPos3i
+#define glRasterPos3iv pgl_iat.pglRasterPos3iv
+#define glReadBuffer pgl_iat.pglReadBuffer
+#define glReadPixels pgl_iat.pglReadPixels
+#define glScissor pgl_iat.pglScissor
+#define glShadeModel pgl_iat.pglShadeModel
+#define glStencilFunc pgl_iat.pglStencilFunc
+#define glStencilMask pgl_iat.pglStencilMask
+#define glStencilOp pgl_iat.pglStencilOp
+#define glTexCoord1f pgl_iat.pglTexCoord1f
+#define glTexCoord2f pgl_iat.pglTexCoord2f
+#define glTexCoord3f pgl_iat.pglTexCoord3f
+#define glTexCoord3iv pgl_iat.pglTexCoord3iv
+#define glTexCoord4f pgl_iat.pglTexCoord4f
+#define glTexCoordPointer pgl_iat.pglTexCoordPointer
+#define	glTexEnvf pgl_iat.pglTexEnvf
+#define	glTexEnvfv pgl_iat.pglTexEnvfv
+#define	glTexEnvi pgl_iat.pglTexEnvi
+#define glTexGenfv pgl_iat.pglTexGenfv
+#define glTexGeni pgl_iat.pglTexGeni
+#define glTexImage2D pgl_iat.pglTexImage2D
+#define glTexParameterfv pgl_iat.pglTexParameterfv
+#define glTexParameteri pgl_iat.pglTexParameteri
+#define glTexSubImage2D pgl_iat.pglTexSubImage2D
+#define glTranslatef pgl_iat.pglTranslatef
+#define glVertex2f pgl_iat.pglVertex2f
+#define glVertex2i pgl_iat.pglVertex2i
+#define glVertex3d pgl_iat.pglVertex3d
+#define glVertex3f pgl_iat.pglVertex3f
+#define glVertex4f pgl_iat.pglVertex4f
+#define glVertexPointer pgl_iat.pglVertexPointer
+#define glViewport pgl_iat.pglViewport
+
+#endif
diff -Nur wine-0.9.36/dlls/wined3d/state.c parallels/dlls/wined3d/state.c
--- wine-0.9.36/dlls/wined3d/state.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/state.c	2009-01-29 12:56:04.000000000 +0100
@@ -96,9 +96,28 @@
                     stateblock->wineD3DDevice->strided_streams.u.s.position_transformed) ? TRUE : FALSE;
 
     if (stateblock->renderState[WINED3DRS_LIGHTING] && !transformed) {
+        /* Direct 3D still uses vertex color when lighting is enabled in
+         * contrast to Open GL
+         * The Lost Watch screensaver enables lighting, disables all
+         * light sources and sets ambient lighting to {0, 0, 0, 0}
+         * check for this case
+         */
+        float col[4];
+        unsigned int k;
+
+        D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_AMBIENT], col);
+        if (col[0] != 0.f && col[1] != 0.f && col[2] != 0.f && col[3] != 0.f)
+            goto enable;
+        for(k = 0; k < stateblock->wineD3DDevice->maxConcurrentLights; ++k) {
+            if (stateblock->activeLights[k])
+                goto enable;
+        }
+        goto disable;
+enable:
         glEnable(GL_LIGHTING);
         checkGLcall("glEnable GL_LIGHTING");
     } else {
+disable:
         glDisable(GL_LIGHTING);
         checkGLcall("glDisable GL_LIGHTING");
     }
@@ -328,7 +347,7 @@
 
     TRACE("Setting BlendFactor to %d\n", stateblock->renderState[WINED3DRS_BLENDFACTOR]);
     D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_BLENDFACTOR], col);
-    glBlendColor (col[0],col[1],col[2],col[3]);
+    GL_EXTCALL(glBlendColor (col[0],col[1],col[2],col[3]));
     checkGLcall("glBlendColor");
 }
 
@@ -2321,8 +2340,8 @@
         checkGLcall("glOrtho");
 
         /* Window Coord 0 is the middle of the first pixel, so translate by 3/8 pixels */
-        glTranslatef(0.375, 0.375, 0);
-        checkGLcall("glTranslatef(0.375, 0.375, 0)");
+        glTranslatef(0.375f, 0.375f, 0);
+        checkGLcall("glTranslatef(0.375f, 0.375f, 0)");
         /* D3D texture coordinates are flipped compared to OpenGL ones, so
          * render everything upside down when rendering offscreen. */
         if (stateblock->wineD3DDevice->render_offscreen) {
@@ -2337,8 +2356,8 @@
             be identity), the x coords of both ends of the line would be not
             -1 and 1 respectively but (-1-1/viewport_widh) and (1-1/viewport_width)
             instead.                                                               */
-        glTranslatef(0.9 / stateblock->viewport.Width, -0.9 / stateblock->viewport.Height, 0);
-        checkGLcall("glTranslatef (0.9 / width, -0.9 / height, 0)");
+        glTranslatef(0.9f / stateblock->viewport.Width, -0.9f / stateblock->viewport.Height, 0);
+        checkGLcall("glTranslatef (0.9f / width, -0.9f / height, 0)");
 
         /* D3D texture coordinates are flipped compared to OpenGL ones, so
             * render everything upside down when rendering offscreen. */
@@ -3056,7 +3075,7 @@
          * TODO: Move to the viewport state
          */
         if (useVertexShaderFunction) {
-            device->posFixup[1] = device->render_offscreen ? -1.0 : 1.0;
+            device->posFixup[1] = device->render_offscreen ? -1.0f : 1.0f;
         }
     }
 
@@ -3155,8 +3174,8 @@
 
     checkGLcall("glViewport");
 
-    stateblock->wineD3DDevice->posFixup[2] = 0.9 / stateblock->viewport.Width;
-    stateblock->wineD3DDevice->posFixup[3] = -0.9 / stateblock->viewport.Height;
+    stateblock->wineD3DDevice->posFixup[2] = 0.9f / stateblock->viewport.Width;
+    stateblock->wineD3DDevice->posFixup[3] = -0.9f / stateblock->viewport.Height;
     if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
         transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context);
     }
@@ -3204,7 +3223,7 @@
         checkGLcall("glLightfv");
 
         if ((lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range) >= FLT_MIN) {
-            quad_att = 1.4/(lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range);
+            quad_att = 1.4f/(lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range);
         } else {
             quad_att = 0; /*  0 or  MAX?  (0 seems to be ok) */
         }
diff -Nur wine-0.9.36/dlls/wined3d/surface.c parallels/dlls/wined3d/surface.c
--- wine-0.9.36/dlls/wined3d/surface.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/surface.c	2009-01-29 12:56:03.000000000 +0100
@@ -2647,6 +2647,9 @@
         rect.y1 = DestRect->top;
         rect.x2 = DestRect->right;
         rect.y2 = DestRect->bottom;
+        /* Front buffer coordinates are screen coordinates. Map them to client area */
+        if (This->resource.usage & WINED3DUSAGE_RENDERTARGET)
+            MapWindowPoints(NULL, This->resource.wineD3DDevice->ddraw_window, (LPPOINT)&rect, 2);
     } else {
         rect.x1 = 0;
         rect.y1 = 0;
@@ -2820,6 +2823,7 @@
         DWORD oldCKeyFlags = Src->CKeyFlags;
         WINEDDCOLORKEY oldBltCKey = This->SrcBltCKey;
         RECT SourceRectangle;
+        GLenum buffer = 0;
 
         TRACE("Blt from surface %p to rendertarget %p\n", Src, This);
 
@@ -2873,7 +2877,7 @@
             TRACE("Drawing to offscreen buffer\n");
             glDrawBuffer(myDevice->offscreenBuffer);
         } else {
-            GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This, (IWineD3DSwapChain *)dstSwapchain);
+            buffer = surface_get_gl_buffer((IWineD3DSurface *)This, (IWineD3DSwapChain *)dstSwapchain);
             TRACE("Drawing to %#x buffer\n", buffer);
             glDrawBuffer(buffer);
             checkGLcall("glDrawBuffer");
@@ -2931,6 +2935,12 @@
         glEnd();
         checkGLcall("glEnd");
 
+        /* flush after drawing to front buffer */
+        if (buffer == GL_FRONT) {
+            glFlush();
+            checkGLcall("glFlush");
+        }
+
         if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
             glDisable(GL_ALPHA_TEST);
             checkGLcall("glDisable(GL_ALPHA_TEST)");
@@ -2970,6 +2980,7 @@
         if (Flags & WINEDDBLT_COLORFILL) {
             /* This is easy to handle for the D3D Device... */
             DWORD color;
+            GLenum buffer = 0;
 
             TRACE("Colorfill\n");
 
@@ -3010,18 +3021,17 @@
 
             TRACE("Calling GetSwapChain with mydevice = %p\n", myDevice);
             if(dstSwapchain && dstSwapchain->backBuffer && This == (IWineD3DSurfaceImpl*) dstSwapchain->backBuffer[0]) {
-                glDrawBuffer(GL_BACK);
-                checkGLcall("glDrawBuffer(GL_BACK)");
+                buffer = GL_BACK;
             } else if (dstSwapchain && This == (IWineD3DSurfaceImpl*) dstSwapchain->frontBuffer) {
-                glDrawBuffer(GL_FRONT);
-                checkGLcall("glDrawBuffer(GL_FRONT)");
+                buffer = GL_FRONT;
             } else if(This == (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
-                glDrawBuffer(myDevice->offscreenBuffer);
-                checkGLcall("glDrawBuffer(myDevice->offscreenBuffer3)");
+                buffer = myDevice->offscreenBuffer;
             } else {
                 TRACE("Surface is higher back buffer, falling back to software\n");
                 return WINED3DERR_INVALIDCALL;
             }
+            glDrawBuffer(buffer);
+            checkGLcall("glDrawBuffer()");
 
             TRACE("(%p) executing Render Target override, color = %x\n", This, color);
 
@@ -3033,6 +3043,12 @@
                                 0.0 /* Z */,
                                 0 /* Stencil */);
 
+            /* flush after drawing to front buffer */
+            if (buffer == GL_FRONT) {
+                glFlush();
+                checkGLcall("glFlush");
+            }
+
             /* Restore the original draw buffer */
             if(!dstSwapchain) {
                 glDrawBuffer(myDevice->offscreenBuffer);
diff -Nur wine-0.9.36/dlls/wined3d/surface_gdi.c parallels/dlls/wined3d/surface_gdi.c
--- wine-0.9.36/dlls/wined3d/surface_gdi.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/surface_gdi.c	2009-01-29 12:56:04.000000000 +0100
@@ -50,10 +50,13 @@
 x11_copy_to_screen(IWineD3DSurfaceImpl *This,
                    LPRECT rc)
 {
-    if(This->resource.usage & WINED3DUSAGE_RENDERTARGET)
+    HWND hDisplayWnd = This->resource.wineD3DDevice->ddraw_window;
+
+    if((This->resource.usage & WINED3DUSAGE_RENDERTARGET)
+        /* avoid drawing to NULL window which maps to display */
+        && hDisplayWnd)
     {
         POINT offset = {0,0};
-        HWND hDisplayWnd;
         HDC hDisplayDC;
         HDC hSurfaceDC = 0;
         RECT drawrect;
@@ -61,13 +64,13 @@
 
         hSurfaceDC = This->hDC;
 
-        hDisplayWnd = This->resource.wineD3DDevice->ddraw_window;
         hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
         if(rc)
         {
             TRACE(" copying rect (%d,%d)->(%d,%d), offset (%d,%d)\n",
             rc->left, rc->top, rc->right, rc->bottom, offset.x, offset.y);
         }
+
 #if 0
         /* FIXME: this doesn't work... if users really want to run
         * X in 8bpp, then we need to call directly into display.drv
@@ -580,6 +583,9 @@
     if (DestRect)
     {
         memcpy(&xdst,DestRect,sizeof(xdst));
+        /* Front buffer coordinates are screen coordinates. Map them to client area */
+        if (This->resource.usage & WINED3DUSAGE_RENDERTARGET)
+            MapWindowPoints(NULL, This->resource.wineD3DDevice->ddraw_window, (LPPOINT)&xdst, 2);
     }
     else
     {
@@ -1213,7 +1219,22 @@
     {
         int pitch;
 
+#ifndef WINE_NATIVEWIN32
         UnionRect(&lock_union, &lock_src, &lock_dst);
+#else
+        if (lock_src.top >= lock_src.bottom
+                || lock_src.left >= lock_src.right)
+            lock_union = lock_dst;
+        else if (lock_dst.top >= lock_dst.bottom
+                || lock_dst.left >= lock_dst.right)
+            lock_union = lock_src;
+        else {
+            lock_union.top = lock_src.top < lock_dst.top ? lock_src.top : lock_dst.top;
+            lock_union.left = lock_src.left < lock_dst.left ? lock_src.left : lock_dst.left;
+            lock_union.bottom = lock_src.bottom > lock_dst.bottom ? lock_src.bottom : lock_dst.bottom;
+            lock_union.right = lock_src.right > lock_dst.right ? lock_src.right : lock_dst.right;
+        }
+#endif
 
         /* Lock the union of the two rectangles */
         ret = IWineD3DSurface_LockRect(iface, &dlock, &lock_union, 0);
diff -Nur wine-0.9.36/dlls/wined3d/swapchain.c parallels/dlls/wined3d/swapchain.c
--- wine-0.9.36/dlls/wined3d/swapchain.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/swapchain.c	2009-01-29 12:56:04.000000000 +0100
@@ -24,6 +24,7 @@
 #include "wined3d_private.h"
 
 
+#ifndef WINE_NATIVEWIN32
 /* TODO: move to shared header (or context manager )*/
 /* x11drv GDI escapes */
 #define X11DRV_ESCAPE 6789
@@ -44,6 +45,7 @@
                     sizeof(display), (LPSTR)&display )) display = NULL;
     return display;
 }
+#endif
 
 /*TODO: some of the additional parameters may be required to
     set the gamma ramp (for some weird reason microsoft have left swap gammaramp in device
@@ -197,8 +199,13 @@
 
     if (pSourceRect || pDestRect) FIXME("Unhandled present options %p/%p\n", pSourceRect, pDestRect);
     /* TODO: If only source rect or dest rect are supplied then clip the window to match */
+#ifndef WINE_NATIVEWIN32
     TRACE("preseting display %p, drawable %ld\n", This->context[0]->display, This->context[0]->drawable);
+#else
+    TRACE("preseting HDC %p\n", This->context[0]->hdc);
+#endif
 
+#ifndef WINE_NATIVEWIN32
     /* Don't call checkGLcall, as glGetError is not applicable here */
     if (hDestWindowOverride && This->win_handle != hDestWindowOverride) {
         HDC hDc;
@@ -238,10 +245,18 @@
             IWineD3DSurface_UnlockRect(This->backBuffer[0]);
         }
     }
+#else
+	/* TODO: ??? */
+#endif
 
+#ifndef WINE_NATIVEWIN32
     glXSwapBuffers(This->context[0]->display, This->context[0]->drawable); /* TODO: cycle through the swapchain buffers */
-
     TRACE("glXSwapBuffers called, Starting new frame\n");
+#else
+    wglSwapBuffers(This->context[0]->hdc);
+    TRACE("wglSwapBuffers called, Starting new frame\n");
+#endif
+
     /* FPS support */
     if (TRACE_ON(fps))
     {
diff -Nur wine-0.9.36/dlls/wined3d/texture.c parallels/dlls/wined3d/texture.c
--- wine-0.9.36/dlls/wined3d/texture.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/texture.c	2009-01-29 12:56:04.000000000 +0100
@@ -165,7 +165,7 @@
 }
 
 static void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
-  return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
+  /*return*/ IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
 }
 
 /* Internal function, No d3d mapping */
diff -Nur wine-0.9.36/dlls/wined3d/utils.c parallels/dlls/wined3d/utils.c
--- wine-0.9.36/dlls/wined3d/utils.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/utils.c	2009-01-29 12:56:04.000000000 +0100
@@ -2267,6 +2267,7 @@
     checkGLcall("glLoadMatrixf(mat)");
 }
 
+#ifndef WINE_NATIVEWIN32
 #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
 
 /* Convertes a D3D format into a OpenGL configuration format */
@@ -2436,6 +2437,7 @@
 }
 
 #undef GLINFO_LOCATION
+#endif
 
 /* DirectDraw stuff */
 WINED3DFORMAT pixelformat_for_depth(DWORD depth) {
diff -Nur wine-0.9.36/dlls/wined3d/volume.c parallels/dlls/wined3d/volume.c
--- wine-0.9.36/dlls/wined3d/volume.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/volume.c	2009-01-29 12:56:04.000000000 +0100
@@ -94,7 +94,7 @@
 }
 
 static void WINAPI IWineD3DVolumeImpl_PreLoad(IWineD3DVolume *iface) {
-    return IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
+    /*return*/ IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
 }
 
 static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeImpl_GetType(IWineD3DVolume *iface) {
diff -Nur wine-0.9.36/dlls/wined3d/volumetexture.c parallels/dlls/wined3d/volumetexture.c
--- wine-0.9.36/dlls/wined3d/volumetexture.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/volumetexture.c	2009-01-29 12:56:04.000000000 +0100
@@ -150,7 +150,7 @@
 }
 
 static void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
-  return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
+  /*return*/ IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
 }
 
 /* Internal function, No d3d mapping */
diff -Nur wine-0.9.36/dlls/wined3d/wined3d_main.c parallels/dlls/wined3d/wined3d_main.c
--- wine-0.9.36/dlls/wined3d/wined3d_main.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/wined3d_main.c	2009-01-29 12:56:04.000000000 +0100
@@ -28,8 +28,10 @@
 WINE_DEFAULT_DEBUG_CHANNEL(wine_d3d);
 
 int num_lock = 0;
+#ifndef WINE_NATIVEWIN32
 void (*wine_tsx11_lock_ptr)(void) = NULL;
 void (*wine_tsx11_unlock_ptr)(void) = NULL;
+#endif
 
 
 /* When updating default value here, make sure to update winecfg as well,
@@ -91,40 +93,56 @@
     TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
     if (fdwReason == DLL_PROCESS_ATTACH)
     {
+#ifndef WINE_NATIVEWIN32
        HMODULE mod;
-       char buffer[MAX_PATH+10];
+#endif
+       char buffer[MAX_PATH+64];
        DWORD size = sizeof(buffer);
        HKEY hkey = 0;
        HKEY appkey = 0;
        DWORD len;
        wined3d_settings.emulated_textureram = 64*1024*1024;
 
+#if defined(WINE_NATIVEWIN32) && !defined(NDEBUG)
+       debug_init();
+#endif
        DisableThreadLibraryCalls(hInstDLL);
 
+#ifndef WINE_NATIVEWIN32
        mod = GetModuleHandleA( "winex11.drv" );
        if (mod)
        {
            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
        }
+#else
+       if (!pglInit())
+           return FALSE;
+#endif
        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
-       if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
+       if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey )
+           && RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Direct3D", &hkey ) )
+           hkey = 0;
 
        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
        if (len && len < MAX_PATH)
        {
-            HKEY tmpkey;
+            char *p, *appname = buffer;
+            if ((p = strrchr( appname, '/' ))) appname = p + 1;
+            if ((p = strrchr( appname, '\\' ))) appname = p + 1;
+            TRACE("appname = [%s]\n", appname);
+            memmove(
+                buffer + strlen( "Software\\Wine\\AppDefaults\\" ),
+                appname, strlen( appname ) + 1);
+            memcpy(
+                buffer, "Software\\Wine\\AppDefaults\\",
+                strlen( "Software\\Wine\\AppDefaults\\" ));
+            strcat( buffer, "\\Direct3D" );
+
             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
-            if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
-            {
-                char *p, *appname = buffer;
-                if ((p = strrchr( appname, '/' ))) appname = p + 1;
-                if ((p = strrchr( appname, '\\' ))) appname = p + 1;
-                strcat( appname, "\\Direct3D" );
-                TRACE("appname = [%s]\n", appname);
-                if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
-                RegCloseKey( tmpkey );
-            }
+            if (RegOpenKeyA( HKEY_CURRENT_USER, buffer, &appkey )
+                && RegOpenKeyA( HKEY_LOCAL_MACHINE, buffer, &appkey ))
+                appkey = 0;
        }
 
        if ( 0 != hkey || 0 != appkey )
@@ -247,5 +265,11 @@
        if (appkey) RegCloseKey( appkey );
        if (hkey) RegCloseKey( hkey );
     }
+#ifdef WINE_NATIVEWIN32
+    else if (fdwReason == DLL_PROCESS_DETACH)
+    {
+        pglFini();
+    }
+#endif
     return TRUE;
 }
diff -Nur wine-0.9.36/dlls/wined3d/wined3d_private.h parallels/dlls/wined3d/wined3d_private.h
--- wine-0.9.36/dlls/wined3d/wined3d_private.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/dlls/wined3d/wined3d_private.h	2009-01-29 12:56:03.000000000 +0100
@@ -29,13 +29,19 @@
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
 #define COBJMACROS
-#include "windef.h"
-#include "winbase.h"
-#include "winreg.h"
-#include "wingdi.h"
-#include "winuser.h"
+#ifndef WINE_NATIVEWIN32
+# include "windef.h"
+# include "winbase.h"
+# include "winreg.h"
+# include "wingdi.h"
+# include "winuser.h"
+# include "winerror.h"
+#else
+# include <windows.h>
+#endif
 #include "wine/debug.h"
 #include "wine/unicode.h"
+#include "wine/port.h"
 
 #include "wined3d_private_types.h"
 #include "wine/wined3d_interface.h"
@@ -43,6 +49,10 @@
 #include "wine/wined3d_gl.h"
 #include "wine/list.h"
 
+#ifdef WINE_NATIVEWIN32
+# include "pglmini.h"
+#endif
+
 /* Hash table functions */
 typedef unsigned int (hash_function_t)(void *key);
 typedef BOOL (compare_function_t)(void *keya, void *keyb);
@@ -209,6 +219,8 @@
 extern const shader_backend_t arb_program_shader_backend;
 extern const shader_backend_t none_shader_backend;
 
+#ifndef WINE_NATIVEWIN32
+
 /* X11 locking */
 
 extern void (*wine_tsx11_lock_ptr)(void);
@@ -225,6 +237,11 @@
 #define LEAVE_GL() wine_tsx11_unlock_ptr()
 #endif
 
+#else
+#define ENTER_GL() ((void)0)
+#define LEAVE_GL() ((void)0)
+#endif /*WINE_NATIVEWIN32*/
+
 /*****************************************************************************
  * Defines
  */
@@ -265,6 +282,7 @@
 
 /* Checking of API calls */
 /* --------------------- */
+#if !defined(WINE_NATIVEWIN32) /*|| !defined(NDEBUG)*/
 #define checkGLcall(A)                                          \
 {                                                               \
     GLint err = glGetError();                                   \
@@ -277,6 +295,9 @@
        err = glGetError();                                      \
     } while (err != GL_NO_ERROR);                               \
 } 
+#else
+#define checkGLcall(A) ((void)0)
+#endif
 
 /* Trace routines / diagnostics */
 /* ---------------------------- */
@@ -350,6 +371,7 @@
 
 /* Checking of per-vertex related GL calls */
 /* --------------------- */
+#if !defined(WINE_NATIVEWIN32) /*|| !defined(NDEBUG)*/
 #define vcheckGLcall(A)                                         \
 {                                                               \
     GLint err = glGetError();                                   \
@@ -362,6 +384,9 @@
        err = glGetError();                                      \
     } while (err != GL_NO_ERROR);                               \
 }
+#else
+#define vcheckGLcall(A) ((void)0)
+#endif
 
 /* TODO: Confirm each of these works when wined3d move completed */
 #if 0 /* NOTE: Must be 0 in cvs */
@@ -518,9 +543,14 @@
     BOOL                    last_was_blit, last_was_ckey;
 
     /* The actual opengl context */
+#ifndef WINE_NATIVEWIN32
     GLXContext              glCtx;
     Drawable                drawable;
     Display                 *display;
+#else
+    HGLRC                   glCtx;
+    HDC                     hdc;
+#endif
     BOOL                    isPBuffer;
 };
 
@@ -530,13 +560,21 @@
     CTXUSAGE_BLIT               = 3,    /* OpenGL states are set up 3D drawing */
 } ContextUsage;
 
-void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
+#ifndef WINE_NATIVEWIN32
 WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, Display *display, Window win);
+#else
+WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND hwnd);
+#endif
+void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);
 void apply_fbo_state(IWineD3DDevice *iface);
 
 /* Routine to fill gl caps for swapchains and IWineD3D */
+#ifndef WINE_NATIVEWIN32
 BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface, Display* display);
+#else
+BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface);
+#endif
 
 /* Macros for doing basic GPU detection based on opengl capabilities */
 #define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
@@ -649,7 +687,7 @@
     WINED3DDEVTYPE                  devType;
 
     IWineD3DSwapChain     **swapchains;
-    uint                    NumberOfSwapChains;
+    unsigned int          NumberOfSwapChains;
 
     ResourceList           *resources; /* a linked list to track resources created by the device */
 
@@ -735,7 +773,7 @@
 void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state);
 static inline BOOL isStateDirty(WineD3DContext *context, DWORD state) {
     DWORD idx = state >> 5;
-    BYTE shift = state & 0x1f;
+    BYTE shift = (BYTE)(state & 0x1f);
     return context->isStateDirty[idx] & (1 << shift);
 }
 
@@ -1378,7 +1416,9 @@
     unsigned int            num_contexts;
 
     HWND                    win_handle;
+#ifndef WINE_NATIVEWIN32
     Window                  win;
+#endif
 } IWineD3DSwapChainImpl;
 
 extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
@@ -1998,6 +2038,6 @@
 }
 
 void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, const WINED3DRECT *src_rect,
-        IWineD3DSurface *dst_surface, const WINED3DRECT *dst_rect, WINED3DTEXTUREFILTERTYPE filter, BOOL flip);
+        IWineD3DSurface *dst_surface, const WINED3DRECT *dst_rect, const WINED3DTEXTUREFILTERTYPE filter, BOOL flip);
 
 #endif
diff -Nur wine-0.9.36/include/ddrawi.h parallels/include/ddrawi.h
--- wine-0.9.36/include/ddrawi.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/include/ddrawi.h	2009-01-29 12:56:06.000000000 +0100
@@ -267,11 +267,13 @@
     DWORD	dwNLVBRops[DD_ROP_SPACE];
 } DDNONLOCALVIDMEMCAPS,*LPDDNONLOCALVIDMEMCAPS;
 
+#ifndef WINE_NATIVEWIN32
 typedef struct _DDSCAPSEX {
     DWORD	dwCaps2;
     DWORD	dwCaps3;
     DWORD	dwCaps4;
 } DDSCAPSEX,*LPDDSCAPSEX;
+#endif
 
 #define DDSCAPS_EXECUTEBUFFER	DDSCAPS_RESERVED2
 #define DDSCAPS2_VERTEXBUFFER	DDSCAPS2_RESERVED1
diff -Nur wine-0.9.36/include/wine/exception.h parallels/include/wine/exception.h
--- wine-0.9.36/include/wine/exception.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/include/wine/exception.h	2009-01-29 12:56:05.000000000 +0100
@@ -21,9 +21,6 @@
 #ifndef __WINE_WINE_EXCEPTION_H
 #define __WINE_WINE_EXCEPTION_H
 
-#include <setjmp.h>
-#include <windef.h>
-
 /* The following definitions allow using exceptions in Wine and Winelib code
  *
  * They should be used like this:
@@ -75,6 +72,9 @@
 
 #else  /* USE_COMPILER_EXCEPTIONS */
 
+#include <setjmp.h>
+#include <windef.h>
+
 #ifndef __GNUC__
 #define __attribute__(x) /* nothing */
 #endif
@@ -154,8 +154,6 @@
 extern DWORD __wine_finally_handler( PEXCEPTION_RECORD record, EXCEPTION_REGISTRATION_RECORD *frame,
                                      CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher );
 
-#endif /* USE_COMPILER_EXCEPTIONS */
-
 static inline EXCEPTION_REGISTRATION_RECORD *__wine_push_frame( EXCEPTION_REGISTRATION_RECORD *frame )
 {
 #if defined(__GNUC__) && defined(__i386__)
@@ -187,6 +185,10 @@
 #endif
 }
 
+#endif /* USE_COMPILER_EXCEPTIONS */
+
+
+#ifndef WINE_NATIVEWIN32
 
 /* Wine-specific exceptions codes */
 
@@ -200,4 +202,6 @@
 
 extern void __wine_enter_vm86( CONTEXT *context );
 
+#endif /* WINE_NATIVEWIN32 */
+
 #endif  /* __WINE_WINE_EXCEPTION_H */
diff -Nur wine-0.9.36/include/wine/port.h parallels/include/wine/port.h
--- wine-0.9.36/include/wine/port.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/include/wine/port.h	2009-01-29 12:56:05.000000000 +0100
@@ -412,6 +412,52 @@
     return ret;
 }
 
+#elif defined(_MSC_VER)
+
+#pragma warning(push)
+// suppress "no return value"
+// assemply inlines do return [edx:]eax per register convention
+#pragma warning(disable:4035)
+
+inline int interlocked_cmpxchg( int *dest, int swap, int compare )
+{
+    __asm mov ecx, dest
+    __asm mov eax, compare
+    __asm mov edx, swap
+    __asm lock cmpxchg [ecx], edx
+}
+
+inline void *interlocked_cmpxchg_ptr( void **dest, void *swap, void *compare )
+{
+    __asm mov ecx, dest
+    __asm mov eax, compare
+    __asm mov edx, swap
+    __asm lock cmpxchg [ecx], edx
+}
+
+inline int interlocked_xchg( int *dest, int val )
+{
+    __asm mov ecx, dest
+    __asm mov eax, val
+    __asm lock xchg [ecx], eax
+}
+
+inline void *interlocked_xchg_ptr( void **dest, void *val )
+{
+    __asm mov ecx, dest
+    __asm mov eax, val
+    __asm lock xchg [ecx], eax
+}
+
+inline int interlocked_xchg_add( int *dest, int incr )
+{
+    __asm mov ecx, dest
+    __asm mov eax, incr
+    __asm lock xadd [ecx], eax
+}
+
+#pragma warning(pop)
+
 #else  /* __i386___ && __GNUC__ */
 
 extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
diff -Nur wine-0.9.36/include/wine/test.h parallels/include/wine/test.h
--- wine-0.9.36/include/wine/test.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/include/wine/test.h	2009-01-29 12:56:05.000000000 +0100
@@ -23,8 +23,7 @@
 
 #include <stdarg.h>
 #include <stdlib.h>
-#include <windef.h>
-#include <winbase.h>
+#include <windows.h>
 
 #ifdef __WINE_WINE_LIBRARY_H
 #error wine/library.h should not be used in Wine tests
diff -Nur wine-0.9.36/include/wine/unicode.h parallels/include/wine/unicode.h
--- wine-0.9.36/include/wine/unicode.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/include/wine/unicode.h	2009-01-29 12:56:05.000000000 +0100
@@ -23,9 +23,14 @@
 
 #include <stdarg.h>
 
-#include <windef.h>
-#include <winbase.h>
-#include <winnls.h>
+#ifndef WINE_NATIVEWIN32
+# include <windef.h>
+# include <winbase.h>
+# include <winnls.h>
+#else
+# include <windows.h>
+# include <mbstring.h>
+#endif
 
 #ifdef __WINE_WINE_TEST_H
 #error This file should not be used in Wine tests
@@ -96,7 +101,15 @@
 extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
 extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
 extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
+#ifndef WINE_NATIVEWIN32
 extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
+#else
+WINE_UNICODE_INLINE long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
+WINE_UNICODE_INLINE long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base )
+{
+    return wcstol( nptr, endptr, base );
+}
+#endif
 extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
 extern int sprintfW( WCHAR *str, const WCHAR *format, ... );
 extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... );
@@ -112,17 +125,26 @@
 WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch );
 WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch )
 {
+#ifndef WINE_NATIVEWIN32
     extern WINE_UNICODE_API const WCHAR wine_casemap_lower[];
     return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
+#else
+    return _mbctolower( ch );
+#endif
 }
 
 WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch );
 WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch )
 {
+#ifndef WINE_NATIVEWIN32
     extern WINE_UNICODE_API const WCHAR wine_casemap_upper[];
     return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
+#else
+    return _mbctoupper( ch );
+#endif
 }
 
+#ifndef WINE_NATIVEWIN32
 /* the character type contains the C1_* flags in the low 12 bits */
 /* and the C2_* type in the high 4 bits */
 WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch );
@@ -197,6 +219,7 @@
 {
     return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
 }
+#endif
 
 /* some useful string manipulation routines */
 
diff -Nur wine-0.9.36/include/wine/wined3d_gl.h parallels/include/wine/wined3d_gl.h
--- wine-0.9.36/include/wine/wined3d_gl.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/include/wine/wined3d_gl.h	2009-01-29 12:56:05.000000000 +0100
@@ -29,6 +29,8 @@
 
 #ifdef HAVE_OPENGL
 
+#ifndef WINE_NATIVEWIN32
+
 #undef APIENTRY
 #undef CALLBACK
 #undef WINAPI
@@ -46,6 +48,16 @@
 #undef APIENTRY
 #define APIENTRY
 
+#else
+
+#include <windows.h>
+
+#include <GL/gl.h>
+#ifdef HAVE_GL_GLEXT_H
+# include <GL/glext.h>
+#endif
+
+#endif
 /****************************************************
  * OpenGL Extensions (EXT and ARB)
  *     #defines and functions pointer
@@ -1389,7 +1401,7 @@
  *  defines and functions pointer
  ****************************************************/
 
-
+#ifndef WINE_NATIVEWIN32
 /****************************************************
  * OpenGL GLX Official Version
  *  defines and functions pointer
@@ -1413,7 +1425,7 @@
 typedef int           (APIENTRY * PGLXFNGLXQUERYCONTEXTPROC) (Display *dpy, GLXContext ctx, int attribute, int *value);
 typedef void          (APIENTRY * PGLXFNGLXSELECTEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long event_mask);
 typedef void          (APIENTRY * PGLXFNGLXGETSELECTEDEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long *event_mask);
-
+#endif
 
 /****************************************************
  * Enumerated types
@@ -1866,6 +1878,8 @@
     USE_GL_FUNC(PGLFNVERTEXATTRIB4USVPROC, glVertexAttrib4usv); \
     USE_GL_FUNC(PGLFNVERTEXATTRIBPOINTERPROC, glVertexAttribPointer); \
 
+#ifndef WINE_NATIVEWIN32
+
 #define GLX_EXT_FUNCS_GEN \
     /** GLX_VERSION_1_3 **/ \
     USE_GL_FUNC(PGLXFNGLXCREATEPBUFFERPROC,          glXCreatePbuffer); \
@@ -1885,13 +1899,21 @@
 #define WINAPI      __stdcall
 #define APIENTRY    WINAPI
 
+#else
+
+#define GLX_EXT_FUNCS_GEN
+
+#endif
+
 /****************************************************
  * Structures       
  ****************************************************/
-#define USE_GL_FUNC(type, pfn) type pfn;
+#define USE_GL_FUNC(type, pfn) type pfn
 typedef struct _WineD3D_GL_Info {
 
+#ifndef WINE_NATIVE_WIN32
   DWORD  glx_version;
+#endif
   DWORD  gl_version;
 
   GL_Vendors gl_vendor;
@@ -1937,9 +1959,9 @@
   BOOL supported[OPENGL_SUPPORTED_EXT_END + 1];
 
   /** OpenGL EXT and ARB functions ptr */
-  GL_EXT_FUNCS_GEN;
+  GL_EXT_FUNCS_GEN
   /** OpenGL GLX functions ptr */
-  GLX_EXT_FUNCS_GEN;
+  GLX_EXT_FUNCS_GEN
   /** OpenGL 2.0 functions ptr */
   /* GL2_FUNCS_GEN; */
   /**/
diff -Nur wine-0.9.36/include/wine/wined3d_interface.h parallels/include/wine/wined3d_interface.h
--- wine-0.9.36/include/wine/wined3d_interface.h	2007-04-27 16:48:53.000000000 +0200
+++ parallels/include/wine/wined3d_interface.h	2009-01-29 12:56:05.000000000 +0100
@@ -190,7 +190,7 @@
 /*****************************************************************************
  * Callback functions required for predefining surfaces / stencils
  */
-typedef HRESULT WINAPI (*D3DCB_CREATERENDERTARGETFN) (IUnknown *pDevice,
+typedef HRESULT WINE_WINAPI (*D3DCB_CREATERENDERTARGETFN) (IUnknown *pDevice,
                                                IUnknown   *pSuperior,
                                                UINT       Width,
                                                UINT       Height,
@@ -201,7 +201,7 @@
                                                struct IWineD3DSurface **ppSurface,
                                                HANDLE    *pSharedHandle);
 
-typedef HRESULT WINAPI (*D3DCB_CREATESURFACEFN) (IUnknown *pDevice,
+typedef HRESULT WINE_WINAPI (*D3DCB_CREATESURFACEFN) (IUnknown *pDevice,
                                                IUnknown   *pSuperior,
                                                UINT       Width,
                                                UINT       Height,
@@ -212,7 +212,7 @@
                                                struct IWineD3DSurface **ppSurface,
                                                HANDLE    *pSharedHandle);
 
-typedef HRESULT WINAPI (*D3DCB_CREATEDEPTHSTENCILSURFACEFN) (IUnknown *pDevice,
+typedef HRESULT WINE_WINAPI (*D3DCB_CREATEDEPTHSTENCILSURFACEFN) (IUnknown *pDevice,
                                                IUnknown   *pSuperior,
                                                UINT       Width,
                                                UINT       Height,
@@ -224,7 +224,7 @@
                                                HANDLE    *pSharedHandle);
 
 
-typedef HRESULT WINAPI (*D3DCB_CREATEVOLUMEFN) (IUnknown *pDevice,
+typedef HRESULT WINE_WINAPI (*D3DCB_CREATEVOLUMEFN) (IUnknown *pDevice,
                                                IUnknown   *pSuperior,
                                                UINT       Width,
                                                UINT       Height,
@@ -235,7 +235,7 @@
                                                struct IWineD3DVolume **ppVolume,
                                                HANDLE    *pSharedHandle);
 
-typedef HRESULT WINAPI (*D3DCB_CREATEADDITIONALSWAPCHAIN) (IUnknown *pDevice,
+typedef HRESULT WINE_WINAPI (*D3DCB_CREATEADDITIONALSWAPCHAIN) (IUnknown *pDevice,
                                                WINED3DPRESENT_PARAMETERS *pPresentationParameters,
                                                struct IWineD3DSwapChain **pSwapChain
                                                );
@@ -243,16 +243,17 @@
 /*****************************************************************************
  * Callback functions for custom implicit object destruction.
  */
-typedef ULONG WINAPI (*D3DCB_DESTROYSWAPCHAINFN) (struct IWineD3DSwapChain *pSwapChain);
+typedef ULONG WINE_WINAPI (*D3DCB_DESTROYSWAPCHAINFN) (struct IWineD3DSwapChain *pSwapChain);
 
-typedef ULONG WINAPI (*D3DCB_DESTROYSURFACEFN) (struct IWineD3DSurface *pSurface);
+typedef ULONG WINE_WINAPI (*D3DCB_DESTROYSURFACEFN) (struct IWineD3DSurface *pSurface);
 
-typedef ULONG WINAPI (*D3DCB_DESTROYVOLUMEFN) (struct IWineD3DVolume *pVolume);
+typedef ULONG WINE_WINAPI (*D3DCB_DESTROYVOLUMEFN) (struct IWineD3DVolume *pVolume);
 
 /*****************************************************************************
  * IWineD3DBase interface
  */
 
+#undef INTERFACE
 #define INTERFACE IWineD3DBase
 DECLARE_INTERFACE_(IWineD3DBase, IUnknown)
 {
@@ -292,7 +293,7 @@
     STDMETHOD(RegisterSoftwareDevice)(THIS_ void * pInitializeFunction) PURE;
     STDMETHOD_(HMONITOR,GetAdapterMonitor)(THIS_ UINT Adapter) PURE;
     STDMETHOD_(UINT,GetAdapterModeCount)(THIS_ UINT Adapter, WINED3DFORMAT Format) PURE;
-    STDMETHOD(EnumAdapterModes)(THIS_ UINT  Adapter, UINT  Mode, WINED3DFORMAT Format, WINED3DDISPLAYMODE * pMode) PURE;
+    STDMETHOD(EnumAdapterModes)(THIS_ UINT  Adapter, WINED3DFORMAT Format, UINT  Mode, WINED3DDISPLAYMODE * pMode) PURE;
     STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT  Adapter, WINED3DDISPLAYMODE *pMode) PURE;
     STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter, DWORD Flags, WINED3DADAPTER_IDENTIFIER* pIdentifier) PURE;
     STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT  Adapter, WINED3DDEVTYPE  DeviceType, WINED3DFORMAT  SurfaceFormat, BOOL  Windowed, WINED3DMULTISAMPLE_TYPE  MultiSampleType, DWORD *pQuality) PURE;
diff -Nur wine-0.9.36/libs/wine/debug.c parallels/libs/wine/debug.c
--- wine-0.9.36/libs/wine/debug.c	2007-04-27 16:48:53.000000000 +0200
+++ parallels/libs/wine/debug.c	2009-01-29 12:56:06.000000000 +0100
@@ -19,6 +19,9 @@
  */
 
 #include "config.h"
+#ifdef WINE_NATIVEWIN32
+# include <windows.h>
+#endif
 #include "wine/port.h"
 
 #include <stdlib.h>
@@ -28,7 +31,9 @@
 #include <ctype.h>
 
 #include "wine/debug.h"
-#include "wine/library.h"
+#ifndef WINE_NATIVEWIN32
+# include "wine/library.h"
+#endif
 
 static const char * const debug_classes[] = { "fixme", "err", "warn", "trace" };
 
@@ -171,7 +176,11 @@
         "Example: WINEDEBUG=+all,warn-heap\n"
         "    turns on all messages except warning heap messages\n"
         "Available message classes: err, warn, fixme, trace\n";
+#ifndef WINE_NATIVEWIN32
     write( 2, usage, sizeof(usage) - 1 );
+#else
+    fputs( usage, stderr );
+#endif
     exit(1);
 }
 
@@ -371,7 +380,15 @@
 /* default implementation of wine_dbg_vprintf */
 static int default_dbg_vprintf( const char *format, va_list args )
 {
+#ifndef WINE_NATIVEWIN32
     return vfprintf( stderr, format, args );
+#else
+    char buf[1024];
+    wvsprintfA(buf, format, args);
+    buf[sizeof(buf) - 1] = '\0';
+    OutputDebugStringA(buf);
+    return 0;
+#endif
 }
 
 
