Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk	(revision 25949)
@@ -150,7 +150,7 @@
     wined3d/nvidia_texture_shader.c \
     wined3d/palette.c \
-    wined3d/pixelshader.c \
     wined3d/query.c \
     wined3d/resource.c \
+	wined3d/shader.c \
 	wined3d/shader_sm1.c \
 	wined3d/shader_sm4.c \
@@ -166,5 +166,4 @@
     wined3d/utils.c \
     wined3d/vertexdeclaration.c \
-    wined3d/vertexshader.c \
 	wined3d/view.c \
     wined3d/volume.c \
@@ -197,6 +196,4 @@
     d3d8/indexbuffer.c \
     d3d8/pixelshader.c \
-    d3d8/resource.c \
-    d3d8/stateblock.c \
     d3d8/surface.c \
     d3d8/swapchain.c \
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c	(revision 25949)
@@ -36,4 +36,7 @@
 static HRESULT WINAPI IDirect3DCubeTexture8Impl_QueryInterface(LPDIRECT3DCUBETEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
+
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource8)
@@ -54,5 +57,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -71,13 +74,17 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
 
-        IUnknown_Release(This->parentDevice);
         wined3d_mutex_lock();
         IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
@@ -85,20 +92,16 @@
 
 /* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
-static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(LPDIRECT3DCUBETEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8 *iface, IDirect3DDevice8 **device)
+{
+    IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice8 *)This->parentDevice;
+    IDirect3DDevice8_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -106,5 +109,7 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -118,5 +123,7 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -130,5 +137,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -142,5 +150,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -154,5 +163,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -165,5 +175,6 @@
 static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -175,5 +186,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     D3DRESOURCETYPE type;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -188,5 +200,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     DWORD lod;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, lod %u.\n", iface, LODNew);
 
     wined3d_mutex_lock();
@@ -200,5 +213,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     DWORD lod;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -212,5 +226,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     DWORD cnt;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -227,5 +242,5 @@
     WINED3DSURFACE_DESC    wined3ddesc;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
 
     wined3d_mutex_lock();
@@ -253,5 +268,5 @@
     IWineD3DSurface *mySurface = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, FaceType, Level, ppCubeMapSurface);
 
     wined3d_mutex_lock();
@@ -269,5 +284,7 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
+            iface, FaceType, Level, pLockedRect, pRect, Flags);
 
     wined3d_mutex_lock();
@@ -281,5 +298,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, face %#x, level %u.\n", iface, FaceType, Level);
 
     wined3d_mutex_lock();
@@ -293,5 +311,6 @@
     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, face %#x, dirty_rect %p.\n", iface, FaceType, pDirtyRect);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c	(revision 25949)
@@ -45,5 +45,5 @@
 }
 
-IDirect3D8* WINAPI Direct3DCreate8(UINT SDKVersion) {
+IDirect3D8* WINAPI DECLSPEC_HOTPATCH Direct3DCreate8(UINT SDKVersion) {
     IDirect3D8Impl* object;
     TRACE("SDKVersion = %x\n", SDKVersion);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h	(revision 25949)
@@ -122,12 +122,4 @@
 typedef struct IDirect3DVolume8Impl IDirect3DVolume8Impl;
 typedef struct IDirect3DVertexBuffer8Impl IDirect3DVertexBuffer8Impl;
-
-/** Private Interfaces: */
-typedef struct IDirect3DStateBlockImpl IDirect3DStateBlockImpl;
-typedef struct IDirect3DVertexShaderImpl IDirect3DVertexShaderImpl;
-typedef struct IDirect3DPixelShaderImpl IDirect3DPixelShaderImpl;
-typedef struct IDirect3DVertexShaderDeclarationImpl IDirect3DVertexShaderDeclarationImpl;
-
-/* Advance declaration of structures to satisfy compiler */
 typedef struct IDirect3DVertexShader8Impl IDirect3DVertexShader8Impl;
 
@@ -157,14 +149,4 @@
     IWineD3D               *WineD3D;
 };
-
-/* ---------------- */
-/* IDirect3DDevice8 */
-/* ---------------- */
-
-/*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl DECLSPEC_HIDDEN;
-extern const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -221,4 +203,7 @@
 };
 
+HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapter,
+        D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
+
 /* ---------------- */
 /* IDirect3DVolume8 */
@@ -252,9 +237,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl DECLSPEC_HIDDEN;
-
-/*****************************************************************************
  * IDirect3DSwapChain8 implementation structure
  */
@@ -271,4 +251,7 @@
     LPDIRECT3DDEVICE8              parentDevice;
 };
+
+HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device,
+        D3DPRESENT_PARAMETERS *present_parameters) DECLSPEC_HIDDEN;
 
 /* ----------------- */
@@ -460,13 +443,4 @@
         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
 
-/* ----------------------- */
-/* IDirect3DStateBlockImpl */
-/* ----------------------- */
-
-/* TODO: Generate a valid GUIDs */
-/* {83B073CE-6F30-11d9-C687-00046142C14F} */
-DEFINE_GUID(IID_IDirect3DStateBlock8,
-0x83b073ce, 0x6f30, 0x11d9, 0xc6, 0x87, 0x0, 0x4, 0x61, 0x42, 0xc1, 0x4f);
-
 DEFINE_GUID(IID_IDirect3DVertexDeclaration8,
 0x5dd7478d, 0xcbf3, 0x41a6, 0x8c, 0xfd, 0xfd, 0x19, 0x2b, 0x11, 0xc7, 0x90);
@@ -478,10 +452,43 @@
 0x6d3bdbdc, 0x5b02, 0x4415, 0xb8, 0x52, 0xce, 0x5e, 0x8b, 0xcc, 0xb2, 0x89);
 
-
-/*****************************************************************************
- * IDirect3DStateBlock8 interface
- */
-#define INTERFACE IDirect3DStateBlock8
-DECLARE_INTERFACE_(IDirect3DStateBlock8, IUnknown)
+/*****************************************************************************
+ * IDirect3DVertexDeclaration8 interface
+ */
+#define INTERFACE IDirect3DVertexDeclaration8
+DECLARE_INTERFACE_(IDirect3DVertexDeclaration8, IUnknown)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** obj_ptr) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+};
+#undef INTERFACE
+
+/*** IUnknown methods ***/
+#define IDirect3DVertexDeclaration8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
+#define IDirect3DVertexDeclaration8_AddRef(p)              (p)->lpVtbl->AddRef(p)
+#define IDirect3DVertexDeclaration8_Release(p)             (p)->lpVtbl->Release(p)
+
+typedef struct {
+    const IDirect3DVertexDeclaration8Vtbl *lpVtbl;
+    LONG ref_count;
+
+    DWORD *elements;
+    DWORD elements_size; /* Size of elements, in bytes */
+
+    IWineD3DVertexDeclaration *wined3d_vertex_declaration;
+    DWORD shader_handle;
+} IDirect3DVertexDeclaration8Impl;
+
+HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
+        IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN;
+HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
+        IDirect3DDevice8Impl *device, DWORD fvf) DECLSPEC_HIDDEN;
+
+/*****************************************************************************
+ * IDirect3DVertexShader8 interface
+ */
+#define INTERFACE IDirect3DVertexShader8
+DECLARE_INTERFACE_(IDirect3DVertexShader8, IUnknown)
 {
     /*** IUnknown methods ***/
@@ -489,76 +496,21 @@
     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
     STDMETHOD_(ULONG,Release)(THIS) PURE;
-    /*** IDirect3DStateBlock9 methods ***/
-    STDMETHOD(GetDevice)(THIS_ struct IDirect3DDevice8** ppDevice) PURE;
-    STDMETHOD(Capture)(THIS) PURE;
-    STDMETHOD(Apply)(THIS) PURE;
 };
 #undef INTERFACE
 
 /*** IUnknown methods ***/
-#define IDirect3DStateBlock8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
-#define IDirect3DStateBlock8_AddRef(p)              (p)->lpVtbl->AddRef(p)
-#define IDirect3DStateBlock8_Release(p)             (p)->lpVtbl->Release(p)
-/*** IDirect3DStateBlock9 methods ***/
-#define IDirect3DStateBlock8_GetDevice(p,a)         (p)->lpVtbl->GetDevice(p,a)
-#define IDirect3DStateBlock8_Capture(p)             (p)->lpVtbl->Capture(p)
-#define IDirect3DStateBlock8_Apply(p)               (p)->lpVtbl->Apply(p)
-
-/*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl DECLSPEC_HIDDEN;
-
-/*****************************************************************************
- * IDirect3DStateBlock implementation structure
- */
-typedef struct  IDirect3DStateBlock8Impl {
-    /* IUnknown fields */
-    const IDirect3DStateBlock8Vtbl *lpVtbl;
-    LONG                   ref;
-
-    /* IDirect3DResource8 fields */
-    IWineD3DStateBlock             *wineD3DStateBlock;
-} IDirect3DStateBlock8Impl;
-
-/*****************************************************************************
- * IDirect3DVertexDeclaration8 interface
- */
-#define INTERFACE IDirect3DVertexDeclaration8
-DECLARE_INTERFACE_(IDirect3DVertexDeclaration8, IUnknown)
-{
-    /*** IUnknown methods ***/
-    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** obj_ptr) PURE;
-    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
-    STDMETHOD_(ULONG,Release)(THIS) PURE;
-};
-#undef INTERFACE
-
-/*** IUnknown methods ***/
-#define IDirect3DVertexDeclaration8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
-#define IDirect3DVertexDeclaration8_AddRef(p)              (p)->lpVtbl->AddRef(p)
-#define IDirect3DVertexDeclaration8_Release(p)             (p)->lpVtbl->Release(p)
-
-typedef struct {
-    const IDirect3DVertexDeclaration8Vtbl *lpVtbl;
-    LONG ref_count;
-
-    DWORD *elements;
-    DWORD elements_size; /* Size of elements, in bytes */
-
-    IWineD3DVertexDeclaration *wined3d_vertex_declaration;
-    DWORD shader_handle;
-} IDirect3DVertexDeclaration8Impl;
-
-HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
-        IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN;
-HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
-        IDirect3DDevice8Impl *device, DWORD fvf) DECLSPEC_HIDDEN;
-
-/*****************************************************************************
- * IDirect3DVertexShader8 interface
- */
-#define INTERFACE IDirect3DVertexShader8
-DECLARE_INTERFACE_(IDirect3DVertexShader8, IUnknown)
+#define IDirect3DVertexShader8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
+#define IDirect3DVertexShader8_AddRef(p)              (p)->lpVtbl->AddRef(p)
+#define IDirect3DVertexShader8_Release(p)             (p)->lpVtbl->Release(p)
+
+/* ------------------------- */
+/* IDirect3DVertexShader8Impl */
+/* ------------------------- */
+
+/*****************************************************************************
+ * IDirect3DPixelShader8 interface
+ */
+#define INTERFACE IDirect3DPixelShader8
+DECLARE_INTERFACE_(IDirect3DPixelShader8,IUnknown)
 {
     /*** IUnknown methods ***/
@@ -570,26 +522,4 @@
 
 /*** IUnknown methods ***/
-#define IDirect3DVertexShader8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
-#define IDirect3DVertexShader8_AddRef(p)              (p)->lpVtbl->AddRef(p)
-#define IDirect3DVertexShader8_Release(p)             (p)->lpVtbl->Release(p)
-
-/* ------------------------- */
-/* IDirect3DVertexShader8Impl */
-/* ------------------------- */
-
-/*****************************************************************************
- * IDirect3DPixelShader8 interface
- */
-#define INTERFACE IDirect3DPixelShader8
-DECLARE_INTERFACE_(IDirect3DPixelShader8,IUnknown)
-{
-    /*** IUnknown methods ***/
-    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
-    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
-    STDMETHOD_(ULONG,Release)(THIS) PURE;
-};
-#undef INTERFACE
-
-/*** IUnknown methods ***/
 #define IDirect3DPixelShader8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
 #define IDirect3DPixelShader8_AddRef(p)              (p)->lpVtbl->AddRef(p)
@@ -635,10 +565,5 @@
 WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
 void load_local_constants(const DWORD *d3d8_elements, IWineD3DVertexShader *wined3d_vertex_shader) DECLSPEC_HIDDEN;
-UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
-        WINED3DVERTEXELEMENT **wined3d_elements) DECLSPEC_HIDDEN;
 size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN;
 
-/* Callbacks */
-extern ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) DECLSPEC_HIDDEN;
-
 #endif /* __WINE_D3DX8_PRIVATE_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c	(revision 25949)
@@ -84,5 +84,5 @@
         case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
         case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
-        case WINED3DFMT_S8_UINT_D24_UNORM: return D3DFMT_D24S8;
+        case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
         case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
         case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
@@ -135,5 +135,5 @@
         case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
         case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
-        case D3DFMT_D24S8: return WINED3DFMT_S8_UINT_D24_UNORM;
+        case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
         case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
         case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
@@ -263,8 +263,22 @@
 }
 
+static ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
+{
+    IUnknown *parent;
+
+    TRACE("swapchain %p.\n", swapchain);
+
+    IWineD3DSwapChain_GetParent(swapchain, &parent);
+    IUnknown_Release(parent);
+    return IUnknown_Release(parent);
+}
+
 /* IDirect3D IUnknown parts follow: */
 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
 {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
+
+    TRACE("iface %p, riid %s, object %p.\n",
+            iface, debugstr_guid(riid), ppobj);
 
     if (IsEqualGUID(riid, &IID_IUnknown)
@@ -291,5 +305,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     return ref;
@@ -303,5 +317,5 @@
     ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
@@ -330,15 +344,9 @@
 
 /* IDirect3DDevice Interface follow: */
-static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hr;
-
-    TRACE("(%p) : Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
+{
+    TRACE("iface %p.\n", iface);
+
+    return D3D_OK;
 }
 
@@ -347,5 +355,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -360,5 +368,6 @@
     HRESULT hr;
 
-    TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
+    TRACE("iface %p, byte_count %u.\n", iface, Bytes);
+    FIXME("Byte count ignored.\n");
 
     wined3d_mutex_lock();
@@ -374,5 +383,5 @@
     IWineD3D* pWineD3D;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
 
     if (NULL == ppD3D8) {
@@ -402,5 +411,6 @@
     WINED3DCAPS *pWineCaps;
 
-    TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
+    TRACE("iface %p, caps %p.\n", iface, pCaps);
+
     if(NULL == pCaps){
         return D3DERR_INVALIDCALL;
@@ -426,5 +436,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, mode %p.\n", iface, pMode);
 
     wined3d_mutex_lock();
@@ -440,5 +451,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, parameters %p.\n", iface, pParameters);
 
     wined3d_mutex_lock();
@@ -453,5 +465,8 @@
     IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
+            iface, XHotSpot, YHotSpot, pCursorBitmap);
+
     if(!pCursorBitmap) {
         WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
@@ -468,5 +483,7 @@
 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, x %u, y %u, flags %#x.\n",
+            iface, XScreenSpace, YScreenSpace, Flags);
 
     wined3d_mutex_lock();
@@ -478,5 +495,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     BOOL ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, show %#x.\n", iface, bShow);
 
     wined3d_mutex_lock();
@@ -487,27 +505,42 @@
 }
 
-static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DSwapChain8Impl* object;
-    HRESULT hrc = D3D_OK;
+static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
+        D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
+    IDirect3DSwapChain8Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, present_parameters %p, swapchain %p.\n",
+            iface, present_parameters, swapchain);
+
+    object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate swapchain memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = swapchain_init(object, This, present_parameters);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize swapchain, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created swapchain %p.\n", object);
+    *swapchain = (IDirect3DSwapChain8 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     WINED3DPRESENT_PARAMETERS localParameters;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* Fix the back buffer count */
-    if(pPresentationParameters->BackBufferCount == 0) {
-        pPresentationParameters->BackBufferCount = 1;
-    }
-
-    object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *pSwapChain = NULL;
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-    object->ref = 1;
-    object->lpVtbl = &Direct3DSwapChain8_Vtbl;
-
-    /* Allocate an associated WineD3DDevice object */
+    HRESULT hr;
+
+    TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
+
     localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
     localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
@@ -527,6 +560,8 @@
 
     wined3d_mutex_lock();
-    hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
-            &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
+    hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
+    if(SUCCEEDED(hr)) {
+        hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
+    }
     wined3d_mutex_unlock();
 
@@ -545,58 +580,4 @@
     pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
 
-    if (hrc != D3D_OK) {
-        FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
-        HeapFree(GetProcessHeap(), 0 , object);
-        *pSwapChain = NULL;
-    }else{
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *pSwapChain = (IDirect3DSwapChain8 *)object;
-    }
-    TRACE("(%p) returning %p\n", This, *pSwapChain);
-    return hrc;
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    WINED3DPRESENT_PARAMETERS localParameters;
-    HRESULT hr;
-
-    TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
-
-    localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
-    localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
-    localParameters.BackBufferFormat                            = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
-    localParameters.BackBufferCount                             = pPresentationParameters->BackBufferCount;
-    localParameters.MultiSampleType                             = pPresentationParameters->MultiSampleType;
-    localParameters.MultiSampleQuality                          = 0; /* d3d9 only */
-    localParameters.SwapEffect                                  = pPresentationParameters->SwapEffect;
-    localParameters.hDeviceWindow                               = pPresentationParameters->hDeviceWindow;
-    localParameters.Windowed                                    = pPresentationParameters->Windowed;
-    localParameters.EnableAutoDepthStencil                      = pPresentationParameters->EnableAutoDepthStencil;
-    localParameters.AutoDepthStencilFormat                      = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
-    localParameters.Flags                                       = pPresentationParameters->Flags;
-    localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
-    localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
-    localParameters.AutoRestoreDisplayMode                      = TRUE;
-
-    wined3d_mutex_lock();
-    hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
-    wined3d_mutex_unlock();
-
-    pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
-    pPresentationParameters->BackBufferHeight                   = localParameters.BackBufferHeight;
-    pPresentationParameters->BackBufferFormat                   = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
-    pPresentationParameters->BackBufferCount                    = localParameters.BackBufferCount;
-    pPresentationParameters->MultiSampleType                    = localParameters.MultiSampleType;
-    pPresentationParameters->SwapEffect                         = localParameters.SwapEffect;
-    pPresentationParameters->hDeviceWindow                      = localParameters.hDeviceWindow;
-    pPresentationParameters->Windowed                           = localParameters.Windowed;
-    pPresentationParameters->EnableAutoDepthStencil             = localParameters.EnableAutoDepthStencil;
-    pPresentationParameters->AutoDepthStencilFormat             = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
-    pPresentationParameters->Flags                              = localParameters.Flags;
-    pPresentationParameters->FullScreen_RefreshRateInHz         = localParameters.FullScreen_RefreshRateInHz;
-    pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
-
     return hr;
 }
@@ -605,5 +586,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
+            iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
 
     wined3d_mutex_lock();
@@ -619,5 +602,6 @@
     HRESULT rc = D3D_OK;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
+            iface, BackBuffer, Type, ppBackBuffer);
 
     wined3d_mutex_lock();
@@ -635,5 +619,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
 
     wined3d_mutex_lock();
@@ -646,5 +631,6 @@
 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
 
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
@@ -656,5 +642,6 @@
 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, ramp %p.\n", iface, pRamp);
 
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
@@ -829,5 +816,8 @@
     HRESULT hr;
 
-    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
+    TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
+            "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
+            iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
+            Usage, Pool, MultiSample, MultisampleQuality);
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
@@ -855,5 +845,7 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
     HRESULT hr;
-    TRACE("Relay\n");
+
+    TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
+            iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
 
     hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
@@ -865,5 +857,7 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
     HRESULT hr;
-    TRACE("Relay\n");
+
+    TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
+            iface, Width, Height, Format, MultiSample, ppSurface);
 
     /* TODO: Verify that Discard is false */
@@ -877,5 +871,7 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
     HRESULT hr;
-    TRACE("Relay\n");
+
+    TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
+            iface, Width, Height, Format, ppSurface);
 
     hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
@@ -892,26 +888,18 @@
     HRESULT              hr = WINED3D_OK;
     WINED3DFORMAT        srcFormat, destFormat;
-    UINT                 srcWidth,  destWidth;
-    UINT                 srcHeight, destHeight;
-    UINT                 srcSize;
     WINED3DSURFACE_DESC  winedesc;
 
-    TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
-          pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
-
-
-    /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
+    TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
+            iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
+
+    /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
+     * destination texture is in WINED3DPOOL_DEFAULT. */
 
     wined3d_mutex_lock();
     IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
     srcFormat = winedesc.format;
-    srcWidth = winedesc.width;
-    srcHeight = winedesc.height;
-    srcSize = winedesc.size;
 
     IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
     destFormat = winedesc.format;
-    destWidth = winedesc.width;
-    destHeight = winedesc.height;
 
     /* Check that the source and destination formats match */
@@ -923,5 +911,4 @@
         TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
         IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
-        destFormat = srcFormat;
     }
 
@@ -950,5 +937,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
 
     wined3d_mutex_lock();
@@ -964,5 +952,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
 
     if (pDestSurface == NULL) {
@@ -984,5 +972,6 @@
     IWineD3DSurface *original_ds = NULL;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
 
     wined3d_mutex_lock();
@@ -993,5 +982,5 @@
         hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
         if (SUCCEEDED(hr) && pSurface)
-            hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
+            hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface, TRUE);
         if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
     }
@@ -1008,5 +997,5 @@
     IWineD3DSurface *pRenderTarget;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
 
     if (ppRenderTarget == NULL) {
@@ -1034,5 +1023,6 @@
     IWineD3DSurface *pZStencilSurface;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
+
     if(ppZStencilSurface == NULL){
         return D3DERR_INVALIDCALL;
@@ -1057,5 +1047,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -1066,8 +1057,9 @@
 }
 
-static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
+    HRESULT hr;
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -1081,5 +1073,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
+            iface, Count, pRects, Flags, Color, Z, Stencil);
 
     /* Note: D3DRECT is compatible with WINED3DRECT */
@@ -1094,5 +1088,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
@@ -1107,5 +1102,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
@@ -1120,5 +1116,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
@@ -1133,5 +1130,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
     /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
@@ -1146,5 +1144,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
     /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
@@ -1159,5 +1158,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, material %p.\n", iface, pMaterial);
 
     /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
@@ -1172,5 +1172,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, material %p.\n", iface, pMaterial);
 
     /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
@@ -1185,5 +1186,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
     /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
@@ -1198,5 +1200,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
     /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
@@ -1211,5 +1214,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
 
     wined3d_mutex_lock();
@@ -1223,5 +1227,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
 
     wined3d_mutex_lock();
@@ -1235,5 +1240,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
 
     wined3d_mutex_lock();
@@ -1247,5 +1253,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
 
     wined3d_mutex_lock();
@@ -1259,5 +1266,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
 
     wined3d_mutex_lock();
@@ -1271,5 +1279,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
 
     wined3d_mutex_lock();
@@ -1283,5 +1292,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -1294,9 +1304,8 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hr;
-    IWineD3DStateBlock* wineD3DStateBlock;
-    IDirect3DStateBlock8Impl* object;
-
-    TRACE("(%p) Relay\n", This);
+    IWineD3DStateBlock *stateblock;
+    HRESULT hr;
+
+    TRACE("iface %p, token %p.\n", iface, pToken);
 
     /* Tell wineD3D to endstateblock before anything else (in case we run out
@@ -1304,5 +1313,5 @@
      */
     wined3d_mutex_lock();
-    hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
+    hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
     if (hr != D3D_OK) {
         WARN("IWineD3DDevice_EndStateBlock returned an error\n");
@@ -1311,12 +1320,5 @@
     }
 
-    /* allocate a new IDirectD3DStateBlock */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
-    object->ref = 1;
-    object->lpVtbl = &Direct3DStateBlock8_Vtbl;
-
-    object->wineD3DStateBlock = wineD3DStateBlock;
-
-    *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
+    *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
     wined3d_mutex_unlock();
 
@@ -1324,10 +1326,12 @@
     {
         ERR("Failed to create a handle\n");
-        IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
+        wined3d_mutex_lock();
+        IWineD3DStateBlock_Release(stateblock);
+        wined3d_mutex_unlock();
         return E_FAIL;
     }
     ++*pToken;
 
-    TRACE("Returning %#x (%p).\n", *pToken, object);
+    TRACE("Returning %#x (%p).\n", *pToken, stateblock);
 
     return hr;
@@ -1336,12 +1340,12 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
     IDirect3DDevice8Impl     *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DStateBlock8Impl *pSB;
-    HRESULT hr;
-
-    TRACE("(%p) %#x Relay\n", This, Token);
-
-    wined3d_mutex_lock();
-    pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
-    if (!pSB)
+    IWineD3DStateBlock *stateblock;
+    HRESULT hr;
+
+    TRACE("iface %p, token %#x.\n", iface, Token);
+
+    wined3d_mutex_lock();
+    stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
+    if (!stateblock)
     {
         WARN("Invalid handle (%#x) passed.\n", Token);
@@ -1349,5 +1353,5 @@
         return D3DERR_INVALIDCALL;
     }
-    hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
+    hr = IWineD3DStateBlock_Apply(stateblock);
     wined3d_mutex_unlock();
 
@@ -1357,12 +1361,12 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DStateBlock8Impl *pSB;
-    HRESULT hr;
-
-    TRACE("(%p) %#x Relay\n", This, Token);
-
-    wined3d_mutex_lock();
-    pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
-    if (!pSB)
+    IWineD3DStateBlock *stateblock;
+    HRESULT hr;
+
+    TRACE("iface %p, token %#x.\n", iface, Token);
+
+    wined3d_mutex_lock();
+    stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
+    if (!stateblock)
     {
         WARN("Invalid handle (%#x) passed.\n", Token);
@@ -1370,5 +1374,5 @@
         return D3DERR_INVALIDCALL;
     }
-    hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
+    hr = IWineD3DStateBlock_Capture(stateblock);
     wined3d_mutex_unlock();
 
@@ -1378,22 +1382,23 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DStateBlock8Impl *pSB;
-
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
-    wined3d_mutex_unlock();
-
-    if (!pSB)
+    IWineD3DStateBlock *stateblock;
+
+    TRACE("iface %p, token %#x.\n", iface, Token);
+
+    wined3d_mutex_lock();
+    stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
+
+    if (!stateblock)
     {
         WARN("Invalid handle (%#x) passed.\n", Token);
+        wined3d_mutex_unlock();
         return D3DERR_INVALIDCALL;
     }
 
-    if (IUnknown_Release((IUnknown *)pSB))
-    {
-        ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
-    }
+    if (IWineD3DStateBlock_Release((IUnknown *)stateblock))
+    {
+        ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
+    }
+    wined3d_mutex_unlock();
 
     return D3D_OK;
@@ -1404,8 +1409,8 @@
 {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DStateBlock8Impl *object;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
+    IWineD3DStateBlock *stateblock;
+    HRESULT hr;
+
+    TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
 
     if (Type != D3DSBT_ALL
@@ -1417,26 +1422,15 @@
     }
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
-    if (!object)
-    {
-        ERR("Failed to allocate memory.\n");
-        return E_OUTOFMEMORY;
-    }
-
-    object->lpVtbl = &Direct3DStateBlock8_Vtbl;
-    object->ref = 1;
-
     wined3d_mutex_lock();
     hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
-            &object->wineD3DStateBlock, (IUnknown *)object);
+            &stateblock, NULL);
     if (FAILED(hr))
     {
         wined3d_mutex_unlock();
         ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
         return hr;
     }
 
-    *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
+    *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
     wined3d_mutex_unlock();
 
@@ -1444,10 +1438,12 @@
     {
         ERR("Failed to allocate a handle.\n");
-        IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
+        wined3d_mutex_lock();
+        IWineD3DStateBlock_Release(stateblock);
+        wined3d_mutex_unlock();
         return E_FAIL;
     }
     ++*handle;
 
-    TRACE("Returning %#x (%p).\n", *handle, object);
+    TRACE("Returning %#x (%p).\n", *handle, stateblock);
 
     return hr;
@@ -1457,5 +1453,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
 
@@ -1470,5 +1467,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
 
     wined3d_mutex_lock();
@@ -1484,5 +1482,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
 
     if(ppTexture == NULL){
@@ -1517,5 +1515,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
+
+    TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
 
     wined3d_mutex_lock();
@@ -1569,5 +1568,6 @@
     const struct tss_lookup *l = &tss_lookup[Type];
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
 
     wined3d_mutex_lock();
@@ -1583,5 +1583,6 @@
     const struct tss_lookup *l = &tss_lookup[Type];
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
 
     wined3d_mutex_lock();
@@ -1596,5 +1597,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
 
     wined3d_mutex_lock();
@@ -1605,7 +1607,9 @@
 }
 
-static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    FIXME("(%p) : stub\n", This);
+static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
+        DWORD info_id, void *info, DWORD info_size)
+{
+    FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
+
     return D3D_OK;
 }
@@ -1614,5 +1618,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
 
     wined3d_mutex_lock();
@@ -1626,5 +1631,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
 
     wined3d_mutex_lock();
@@ -1638,5 +1644,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
 
     wined3d_mutex_lock();
@@ -1650,5 +1657,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
 
     wined3d_mutex_lock();
@@ -1664,5 +1672,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
+            iface, PrimitiveType, StartVertex, PrimitiveCount);
 
     wined3d_mutex_lock();
@@ -1679,5 +1689,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
+            iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
 
     wined3d_mutex_lock();
@@ -1693,5 +1705,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
+            iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
 
     wined3d_mutex_lock();
@@ -1711,5 +1725,9 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
+            "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
+            iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
+            pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
 
     wined3d_mutex_lock();
@@ -1727,5 +1745,7 @@
     HRESULT hr;
     IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
+            iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
 
     wined3d_mutex_lock();
@@ -1854,5 +1874,5 @@
     HRESULT hr;
 
-    TRACE("(%p) : Relay\n", This);
+    TRACE("iface %p, shader %#x.\n", iface, pShader);
 
     if (VS_HIGHESTFIXEDFXF >= pShader) {
@@ -1896,5 +1916,5 @@
     HRESULT hrc;
 
-    TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
+    TRACE("iface %p, shader %p.\n", iface, ppShader);
 
     wined3d_mutex_lock();
@@ -1934,5 +1954,5 @@
     IWineD3DVertexShader *cur = NULL;
 
-    TRACE("(%p) : pShader %#x\n", This, pShader);
+    TRACE("iface %p, shader %#x.\n", iface, pShader);
 
     wined3d_mutex_lock();
@@ -1967,5 +1987,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, ConstantCount);
 
     if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
@@ -1985,5 +2007,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, ConstantCount);
 
     if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
@@ -2005,5 +2029,6 @@
     IDirect3DVertexShader8Impl *shader;
 
-    TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
+    TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
+            iface, pVertexShader, pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -2041,5 +2066,6 @@
     HRESULT hr;
 
-    TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
+    TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
+            iface, pVertexShader, pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -2070,5 +2096,6 @@
     HRESULT hr;
     IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
 
     /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
@@ -2093,5 +2120,5 @@
     HRESULT rc = D3D_OK;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
 
     if(ppIndexData == NULL){
@@ -2174,5 +2201,5 @@
     HRESULT hr;
 
-    TRACE("(%p) : pShader %#x\n", This, pShader);
+    TRACE("iface %p, shader %#x.\n", iface, pShader);
 
     wined3d_mutex_lock();
@@ -2203,7 +2230,8 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IWineD3DPixelShader *object;
-
     HRESULT hrc = D3D_OK;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, shader %p.\n", iface, ppShader);
+
     if (NULL == ppShader) {
         TRACE("(%p) Invalid call\n", This);
@@ -2234,5 +2262,5 @@
     IWineD3DPixelShader *cur = NULL;
 
-    TRACE("(%p) : pShader %#x\n", This, pShader);
+    TRACE("iface %p, shader %#x.\n", iface, pShader);
 
     wined3d_mutex_lock();
@@ -2243,5 +2271,5 @@
         WARN("Invalid handle (%#x) passed.\n", pShader);
         wined3d_mutex_unlock();
-        return D3D_OK;
+        return D3DERR_INVALIDCALL;
     }
 
@@ -2267,5 +2295,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, ConstantCount);
 
     wined3d_mutex_lock();
@@ -2279,5 +2309,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, ConstantCount);
 
     wined3d_mutex_lock();
@@ -2293,5 +2325,6 @@
     HRESULT hr;
 
-    TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
+    TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
+            iface, pPixelShader, pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -2314,5 +2347,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
+            iface, Handle, pNumSegs, pRectPatchInfo);
 
     wined3d_mutex_lock();
@@ -2326,5 +2361,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
+            iface, Handle, pNumSegs, pTriPatchInfo);
 
     wined3d_mutex_lock();
@@ -2338,5 +2375,6 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, handle %#x.\n", iface, Handle);
 
     wined3d_mutex_lock();
@@ -2350,5 +2388,7 @@
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
+            iface, StreamNumber, pStreamData, Stride);
 
     wined3d_mutex_lock();
@@ -2366,5 +2406,6 @@
     HRESULT rc = D3D_OK;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
+            iface, StreamNumber, pStream, pStride);
 
     if(pStream == NULL){
@@ -2388,6 +2429,5 @@
 }
 
-
-const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
+static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
 {
     IDirect3DDevice8Impl_QueryInterface,
@@ -2717,5 +2757,5 @@
 }
 
-const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
+static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
 {
     /* IUnknown methods */
@@ -2731,2 +2771,101 @@
     device_parent_CreateSwapChain,
 };
+
+HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapter,
+        D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
+{
+    WINED3DPRESENT_PARAMETERS wined3d_parameters;
+    HRESULT hr;
+
+    device->lpVtbl = &Direct3DDevice8_Vtbl;
+    device->device_parent_vtbl = &d3d8_wined3d_device_parent_vtbl;
+    device->ref = 1;
+    device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+            D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
+    if (!device->handle_table.entries)
+    {
+        ERR("Failed to allocate handle table memory.\n");
+        return E_OUTOFMEMORY;
+    }
+    device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
+
+    wined3d_mutex_lock();
+    hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
+            (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d device, hr %#x.\n", hr);
+        wined3d_mutex_unlock();
+        HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
+        return hr;
+    }
+
+    if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
+
+    wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
+    wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
+    wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
+    wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
+    wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
+    wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
+    wined3d_parameters.SwapEffect = parameters->SwapEffect;
+    wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
+    wined3d_parameters.Windowed = parameters->Windowed;
+    wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
+    wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
+    wined3d_parameters.Flags = parameters->Flags;
+    wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
+    wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
+    wined3d_parameters.AutoRestoreDisplayMode = TRUE;
+
+    hr = IWineD3DDevice_Init3D(device->WineD3DDevice, &wined3d_parameters);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize 3D, hr %#x.\n", hr);
+        IWineD3DDevice_Release(device->WineD3DDevice);
+        wined3d_mutex_unlock();
+        HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
+        return hr;
+    }
+
+    hr = IWineD3DDevice_SetRenderState(device->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
+        goto err;
+    }
+
+    parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
+    parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
+    parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
+    parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
+    parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
+    parameters->SwapEffect = wined3d_parameters.SwapEffect;
+    parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
+    parameters->Windowed = wined3d_parameters.Windowed;
+    parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
+    parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
+    parameters->Flags = wined3d_parameters.Flags;
+    parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
+    parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
+
+    device->declArraySize = 16;
+    device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
+    if (!device->decls)
+    {
+        ERR("Failed to allocate FVF vertex delcaration map memory.\n");
+        hr = E_OUTOFMEMORY;
+        goto err;
+    }
+
+    return D3D_OK;
+
+err:
+    wined3d_mutex_lock();
+    IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D8CB_DestroySwapChain);
+    IWineD3DDevice_Release(device->WineD3DDevice);
+    wined3d_mutex_unlock();
+    HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
+    return hr;
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c	(revision 25949)
@@ -52,4 +52,6 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3D8)) {
@@ -68,5 +70,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     return ref;
@@ -77,5 +79,5 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
@@ -96,5 +98,6 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%p)\n", This, pInitializeFunction);
+
+    TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
 
     wined3d_mutex_lock();
@@ -108,5 +111,6 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -124,5 +128,6 @@
     HRESULT hr;
 
-    TRACE("(%p)->(%d,%08x, %p\n", This, Adapter, Flags, pIdentifier);
+    TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
+            iface, Adapter, Flags, pIdentifier);
 
     adapter_id.driver = pIdentifier->Driver;
@@ -151,5 +156,6 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%d)\n", This, Adapter);
+
+    TRACE("iface %p, adapter %u.\n", iface, Adapter);
 
     wined3d_mutex_lock();
@@ -163,5 +169,7 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%d, %d, %p)\n", This, Adapter, Mode, pMode);
+
+    TRACE("iface %p, adapter %u, mode_idx %u, mode %p.\n",
+            iface, Adapter, Mode, pMode);
 
     wined3d_mutex_lock();
@@ -177,5 +185,7 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%d,%p)\n", This, Adapter, pMode);
+
+    TRACE("iface %p, adapter %u, mode %p.\n",
+            iface, Adapter, pMode);
 
     wined3d_mutex_lock();
@@ -193,5 +203,7 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%d, %d, %d, %d, %s)\n", This, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed ? "true" : "false");
+
+    TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
+            iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
 
     wined3d_mutex_lock();
@@ -209,5 +221,7 @@
     HRESULT hr;
     WINED3DRESOURCETYPE WineD3DRType;
-    TRACE("(%p)->(%d, %d, %d, %08x, %d, %d)\n", This, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
+
+    TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
+            iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
 
     if(CheckFormat == D3DFMT_R8G8B8)
@@ -243,5 +257,7 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)-<(%d, %d, %d, %s, %d)\n", This, Adapter, DeviceType, SurfaceFormat, Windowed ? "true" : "false", MultiSampleType);
+
+    TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x.\n",
+            iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType);
 
     wined3d_mutex_lock();
@@ -258,5 +274,7 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)-<(%d, %d, %d, %d, %d)\n", This, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
+
+    TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
+            iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
 
     wined3d_mutex_lock();
@@ -288,5 +306,5 @@
     WINED3DCAPS *pWineCaps;
 
-    TRACE("(%p) Relay %d %u %p\n", This, Adapter, DeviceType, pCaps);
+    TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
 
     if(NULL == pCaps){
@@ -313,5 +331,6 @@
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HMONITOR ret;
-    TRACE("(%p)->(%d)\n", This, Adapter);
+
+    TRACE("iface %p, adapter %u.\n", iface, Adapter);
 
     wined3d_mutex_lock();
@@ -322,117 +341,33 @@
 }
 
-ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
-    IUnknown* swapChainParent;
-    TRACE("(%p) call back\n", pSwapChain);
-
-    IWineD3DSwapChain_GetParent(pSwapChain, &swapChainParent);
-    IUnknown_Release(swapChainParent);
-    return IUnknown_Release(swapChainParent);
-}
-
-static HRESULT WINAPI IDirect3D8Impl_CreateDevice(LPDIRECT3D8 iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
-                                            DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
-                                            IDirect3DDevice8** ppReturnedDeviceInterface) {
-
-    IDirect3D8Impl       *This   = (IDirect3D8Impl *)iface;
-    IDirect3DDevice8Impl *object = NULL;
-    WINED3DPRESENT_PARAMETERS localParameters;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    /* Check the validity range of the adapter parameter */
-    if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
-        *ppReturnedDeviceInterface = NULL;
-        return D3DERR_INVALIDCALL;
-    }
-
-    /* Allocate the storage for the device object */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice8Impl));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *ppReturnedDeviceInterface = NULL;
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &Direct3DDevice8_Vtbl;
-    object->device_parent_vtbl = &d3d8_wined3d_device_parent_vtbl;
-    object->ref = 1;
-    object->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*object->handle_table.entries));
-    object->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
-    *ppReturnedDeviceInterface = (IDirect3DDevice8 *)object;
-
-    /* Allocate an associated WineD3DDevice object */
-    wined3d_mutex_lock();
-    hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
-            (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
-
-    if (hr != D3D_OK) {
+static HRESULT WINAPI IDirect3D8Impl_CreateDevice(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type,
+        HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, IDirect3DDevice8 **device)
+{
+    IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
+    IDirect3DDevice8Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
+            iface, adapter, device_type, focus_window, flags, parameters, device);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate device memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize device, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppReturnedDeviceInterface = NULL;
-        wined3d_mutex_unlock();
-
         return hr;
     }
 
-    TRACE("(%p) : Created Device %p\n", This, object);
-
-    localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
-    localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
-    localParameters.BackBufferFormat                            = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
-    localParameters.BackBufferCount                             = pPresentationParameters->BackBufferCount;
-    localParameters.MultiSampleType                             = pPresentationParameters->MultiSampleType;
-    localParameters.MultiSampleQuality                          = 0; /* d3d9 only */
-    localParameters.SwapEffect                                  = pPresentationParameters->SwapEffect;
-    localParameters.hDeviceWindow                               = pPresentationParameters->hDeviceWindow;
-    localParameters.Windowed                                    = pPresentationParameters->Windowed;
-    localParameters.EnableAutoDepthStencil                      = pPresentationParameters->EnableAutoDepthStencil;
-    localParameters.AutoDepthStencilFormat                      = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
-    localParameters.Flags                                       = pPresentationParameters->Flags;
-    localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
-    localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
-    localParameters.AutoRestoreDisplayMode                      = TRUE;
-
-    if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
-        IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
-    }
-
-    hr = IWineD3DDevice_Init3D(object->WineD3DDevice, &localParameters);
-    wined3d_mutex_unlock();
-
-    pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
-    pPresentationParameters->BackBufferHeight                   = localParameters.BackBufferHeight;
-    pPresentationParameters->BackBufferFormat                   = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
-    pPresentationParameters->BackBufferCount                    = localParameters.BackBufferCount;
-    pPresentationParameters->MultiSampleType                    = localParameters.MultiSampleType;
-    pPresentationParameters->SwapEffect                         = localParameters.SwapEffect;
-    pPresentationParameters->hDeviceWindow                      = localParameters.hDeviceWindow;
-    pPresentationParameters->Windowed                           = localParameters.Windowed;
-    pPresentationParameters->EnableAutoDepthStencil             = localParameters.EnableAutoDepthStencil;
-    pPresentationParameters->AutoDepthStencilFormat             = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
-    pPresentationParameters->Flags                              = localParameters.Flags;
-    pPresentationParameters->FullScreen_RefreshRateInHz         = localParameters.FullScreen_RefreshRateInHz;
-    pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
-
-    if (hr != D3D_OK) {
-        FIXME("(%p) D3D Initialization failed for WineD3DDevice %p\n", This, object->WineD3DDevice);
-        HeapFree(GetProcessHeap(), 0, object);
-        *ppReturnedDeviceInterface = NULL;
-    }
-
-    object->declArraySize = 16;
-    object->decls = HeapAlloc(GetProcessHeap(), 0, object->declArraySize * sizeof(*object->decls));
-    if(!object->decls) {
-        ERR("Out of memory\n");
-
-        wined3d_mutex_lock();
-        IWineD3DDevice_Release(object->WineD3DDevice);
-        wined3d_mutex_unlock();
-
-        HeapFree(GetProcessHeap(), 0, object);
-        *ppReturnedDeviceInterface = NULL;
-        hr = E_OUTOFMEMORY;
-    }
-    return hr;
+    TRACE("Created device %p.\n", object);
+    *device = (IDirect3DDevice8 *)object;
+
+    return D3D_OK;
 }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c	(revision 25949)
@@ -37,4 +37,6 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource8)
@@ -54,5 +56,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -71,11 +73,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice8_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
@@ -83,20 +89,16 @@
 
 /* IDirect3DIndexBuffer8 IDirect3DResource8 Interface follow: */
-static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(IDirect3DIndexBuffer8 *iface, IDirect3DDevice8 **device)
+{
+    IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice8 *)This->parentDevice;
+    IDirect3DDevice8_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -104,5 +106,7 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -116,5 +120,7 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -128,5 +134,6 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -140,5 +147,6 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -152,5 +160,6 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -163,5 +172,6 @@
 static void WINAPI IDirect3DIndexBuffer8Impl_PreLoad(LPDIRECT3DINDEXBUFFER8 iface) {
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -170,7 +180,7 @@
 }
 
-static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer8Impl_GetType(LPDIRECT3DINDEXBUFFER8 iface) {
-    IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
-    TRACE("(%p)\n", This);
+static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer8Impl_GetType(IDirect3DIndexBuffer8 *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     return D3DRTYPE_INDEXBUFFER;
@@ -181,5 +191,7 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
+            iface, OffsetToLock, SizeToLock, ppbData, Flags);
 
     wined3d_mutex_lock();
@@ -193,5 +205,6 @@
     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -206,5 +219,6 @@
     HRESULT hr;
     WINED3DBUFFER_DESC desc;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/pixelshader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/pixelshader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/pixelshader.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DPixelShader8Impl *This = (IDirect3DPixelShader8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DPixelShader8)) {
@@ -54,5 +56,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -70,5 +72,5 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/resource.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/resource.c	(revision 25947)
+++ 	(revision )
@@ -1,142 +1,0 @@
-/*
- * IDirect3DResource8 implementation
- *
- * Copyright 2005 Oliver Stieber
- *
- * 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
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
-#include "config.h"
-#include "d3d8_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
-
-/* IDirect3DResource8 IUnknown parts follow: */
-static HRESULT WINAPI IDirect3DResource8Impl_QueryInterface(LPDIRECT3DRESOURCE8 iface, REFIID riid, LPVOID* ppobj) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-
-    if (IsEqualGUID(riid, &IID_IUnknown)
-        || IsEqualGUID(riid, &IID_IDirect3DResource8)) {
-        IUnknown_AddRef(iface);
-        *ppobj = This;
-        return S_OK;
-    }
-
-    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
-    *ppobj = NULL;
-    return E_NOINTERFACE;
-}
-
-static ULONG WINAPI IDirect3DResource8Impl_AddRef(LPDIRECT3DRESOURCE8 iface) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    ULONG ref = InterlockedIncrement(&This->ref);
-
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
-
-    return ref;
-}
-
-static ULONG WINAPI IDirect3DResource8Impl_Release(LPDIRECT3DRESOURCE8 iface) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    ULONG ref = InterlockedDecrement(&This->ref);
-
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
-
-    if (ref == 0) {
-        IWineD3DResource_Release(This->wineD3DResource);
-        HeapFree(GetProcessHeap(), 0, This);
-    }
-    return ref;
-}
-
-/* IDirect3DResource8 Interface follow: */
-HRESULT WINAPI IDirect3DResource8Impl_GetDevice(LPDIRECT3DRESOURCE8 iface, IDirect3DDevice8** ppDevice) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    IWineD3DDevice *myDevice = NULL;
-
-    TRACE("(%p) Relay\n", This);
-
-    IWineD3DResource_GetDevice(This->wineD3DResource, &myDevice);
-    IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
-    IWineD3DDevice_Release(myDevice);
-    return D3D_OK;
-}
-
-static HRESULT WINAPI IDirect3DResource8Impl_SetPrivateData(LPDIRECT3DRESOURCE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    return IWineD3DResource_SetPrivateData(This->wineD3DResource, refguid, pData, SizeOfData, Flags);
-}
-
-static HRESULT WINAPI IDirect3DResource8Impl_GetPrivateData(LPDIRECT3DRESOURCE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    return IWineD3DResource_GetPrivateData(This->wineD3DResource, refguid, pData, pSizeOfData);
-}
-
-static HRESULT WINAPI IDirect3DResource8Impl_FreePrivateData(LPDIRECT3DRESOURCE8 iface, REFGUID refguid) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    return IWineD3DResource_FreePrivateData(This->wineD3DResource, refguid);
-}
-
-static DWORD  WINAPI IDirect3DResource8Impl_SetPriority(LPDIRECT3DRESOURCE8 iface, DWORD PriorityNew) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    return IWineD3DResource_SetPriority(This->wineD3DResource, PriorityNew);
-}
-
-static DWORD WINAPI IDirect3DResource8Impl_GetPriority(LPDIRECT3DRESOURCE8 iface) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    return IWineD3DResource_GetPriority(This->wineD3DResource);
-}
-
-static void WINAPI IDirect3DResource8Impl_PreLoad(LPDIRECT3DRESOURCE8 iface) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    IWineD3DResource_PreLoad(This->wineD3DResource);
-    return;
-}
-
-static D3DRESOURCETYPE WINAPI IDirect3DResource8Impl_GetType(LPDIRECT3DRESOURCE8 iface) {
-    IDirect3DResource8Impl *This = (IDirect3DResource8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    return IWineD3DResource_GetType(This->wineD3DResource);
-}
-
-const IDirect3DResource8Vtbl Direct3DResource8_Vtbl =
-{
-    IDirect3DResource8Impl_QueryInterface,
-    IDirect3DResource8Impl_AddRef,
-    IDirect3DResource8Impl_Release,
-    IDirect3DResource8Impl_GetDevice,
-    IDirect3DResource8Impl_SetPrivateData,
-    IDirect3DResource8Impl_GetPrivateData,
-    IDirect3DResource8Impl_FreePrivateData,
-    IDirect3DResource8Impl_SetPriority,
-    IDirect3DResource8Impl_GetPriority,
-    IDirect3DResource8Impl_PreLoad,
-    IDirect3DResource8Impl_GetType
-};
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/stateblock.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/stateblock.c	(revision 25947)
+++ 	(revision )
@@ -1,135 +1,0 @@
-/*
- * IDirect3DStateBlock8 implementation
- *
- * Copyright 2002-2003 Raphael Junqueira
- * Copyright 2002-2003 Jason Edmeades
- * Copyright 2005 Oliver Stieber
- *
- * 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
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
-#include "config.h"
-#include "d3d8_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
-
-/* NOTE: DirectX8 doesn't export an IDirect3DStateBlock8, the interface is used internally to keep d3d8 and d3d9 as similar as possible */
-/* IDirect3DStateBlock8 IUnknown parts follow: */
-static HRESULT WINAPI IDirect3DStateBlock8Impl_QueryInterface(IDirect3DStateBlock8 *iface, REFIID riid, LPVOID *ppobj) {
-    IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
-
-    if (IsEqualGUID(riid, &IID_IUnknown)
-        || IsEqualGUID(riid, &IID_IDirect3DStateBlock8)) {
-        IUnknown_AddRef(iface);
-        *ppobj = This;
-        return S_OK;
-    }
-
-    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
-    *ppobj = NULL;
-    return E_NOINTERFACE;
-}
-
-static ULONG WINAPI IDirect3DStateBlock8Impl_AddRef(IDirect3DStateBlock8 *iface) {
-    IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
-    ULONG ref = InterlockedIncrement(&This->ref);
-
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
-
-    return ref;
-}
-
-static ULONG WINAPI IDirect3DStateBlock8Impl_Release(IDirect3DStateBlock8 *iface) {
-    IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
-    ULONG ref = InterlockedDecrement(&This->ref);
-
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
-
-    if (ref == 0) {
-        wined3d_mutex_lock();
-        IWineD3DStateBlock_Release(This->wineD3DStateBlock);
-        wined3d_mutex_unlock();
-
-        HeapFree(GetProcessHeap(), 0, This);
-    }
-    return ref;
-}
-
-/* IDirect3DStateBlock8 Interface follow: */
-static HRESULT WINAPI IDirect3DStateBlock8Impl_GetDevice(IDirect3DStateBlock8 *iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3DStateBlock8Impl_Capture(IDirect3DStateBlock8 *iface) {
-    IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3DStateBlock8Impl_Apply(IDirect3DStateBlock8 *iface) {
-    IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
-const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl =
-{
-    /* IUnknown */
-    IDirect3DStateBlock8Impl_QueryInterface,
-    IDirect3DStateBlock8Impl_AddRef,
-    IDirect3DStateBlock8Impl_Release,
-    /* IDirect3DStateBlock8 */
-    IDirect3DStateBlock8Impl_GetDevice,
-    IDirect3DStateBlock8Impl_Capture,
-    IDirect3DStateBlock8Impl_Apply
-};
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c	(revision 25949)
@@ -37,4 +37,6 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource8)
@@ -53,5 +55,5 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -62,4 +64,7 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedIncrement(&This->ref);
+
+        TRACE("%p increasing refcount to %u.\n", iface, ref);
+
         if (ref == 1)
         {
@@ -69,5 +74,5 @@
             wined3d_mutex_unlock();
         }
-        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+
         return ref;
     }
@@ -77,5 +82,5 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -86,12 +91,16 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedDecrement(&This->ref);
-        TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+
+        TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
         if (ref == 0) {
-            if (This->parentDevice) IUnknown_Release(This->parentDevice);
+            IDirect3DDevice8 *parentDevice = This->parentDevice;
+
             /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
             wined3d_mutex_lock();
             IWineD3DSurface_Release(This->wineD3DSurface);
             wined3d_mutex_unlock();
+
+            if (parentDevice) IDirect3DDevice8_Release(parentDevice);
         }
 
@@ -101,20 +110,33 @@
 
 /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
-static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p)->(%p)\n", This, ppDevice);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device)
+{
+    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    if (This->forwardReference)
+    {
+        IDirect3DResource8 *resource;
+        HRESULT hr;
+
+        hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
+        if (SUCCEEDED(hr))
+        {
+            hr = IDirect3DResource8_GetDevice(resource, device);
+            IDirect3DResource8_Release(resource);
+
+            TRACE("Returning device %p.\n", *device);
+        }
+
+        return hr;
+    }
+
+    *device = (IDirect3DDevice8 *)This->parentDevice;
+    IDirect3DDevice8_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -122,5 +144,7 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -134,5 +158,7 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -146,5 +172,6 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -160,5 +187,5 @@
     HRESULT res;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
 
     if (!This->container) return E_NOINTERFACE;
@@ -174,5 +201,6 @@
     WINED3DSURFACE_DESC    wined3ddesc;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
@@ -198,6 +226,6 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-    TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
+
+    TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags);
 
     wined3d_mutex_lock();
@@ -228,5 +256,6 @@
     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/swapchain.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/swapchain.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/swapchain.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DSwapChain8Impl *This = (IDirect3DSwapChain8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DSwapChain8)) {
@@ -54,5 +56,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     return ref;
@@ -63,5 +65,5 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
@@ -80,5 +82,7 @@
     IDirect3DSwapChain8Impl *This = (IDirect3DSwapChain8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
+            iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
 
     wined3d_mutex_lock();
@@ -94,5 +98,6 @@
     IWineD3DSurface *mySurface = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
+            iface, iBackBuffer, Type, ppBackBuffer);
 
     wined3d_mutex_lock();
@@ -107,5 +112,5 @@
 }
 
-const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl =
+static const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl =
 {
     IDirect3DSwapChain8Impl_QueryInterface,
@@ -115,2 +120,58 @@
     IDirect3DSwapChain8Impl_GetBackBuffer
 };
+
+HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device,
+        D3DPRESENT_PARAMETERS *present_parameters)
+{
+    WINED3DPRESENT_PARAMETERS wined3d_parameters;
+    HRESULT hr;
+
+    swapchain->ref = 1;
+    swapchain->lpVtbl = &Direct3DSwapChain8_Vtbl;
+
+    wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
+    wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
+    wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
+    wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount);
+    wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType;
+    wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
+    wined3d_parameters.SwapEffect = present_parameters->SwapEffect;
+    wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
+    wined3d_parameters.Windowed = present_parameters->Windowed;
+    wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
+    wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
+    wined3d_parameters.Flags = present_parameters->Flags;
+    wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
+    wined3d_parameters.PresentationInterval = present_parameters->FullScreen_PresentationInterval;
+    wined3d_parameters.AutoRestoreDisplayMode = TRUE;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateSwapChain(device->WineD3DDevice, &wined3d_parameters,
+            &swapchain->wineD3DSwapChain, (IUnknown *)swapchain, SURFACE_OPENGL);
+    wined3d_mutex_unlock();
+
+    present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
+    present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
+    present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
+    present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
+    present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
+    present_parameters->SwapEffect = wined3d_parameters.SwapEffect;
+    present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
+    present_parameters->Windowed = wined3d_parameters.Windowed;
+    present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
+    present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
+    present_parameters->Flags = wined3d_parameters.Flags;
+    present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
+    present_parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
+
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
+        return hr;
+    }
+
+    swapchain->parentDevice = (IDirect3DDevice8 *)device;
+    IDirect3DDevice8_AddRef(swapchain->parentDevice);
+
+    return D3D_OK;
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c	(revision 25949)
@@ -37,4 +37,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource8)
@@ -55,5 +57,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -72,11 +74,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice8_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DTexture_Release(This->wineD3DTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
@@ -84,20 +90,16 @@
 
 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
-static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(IDirect3DTexture8 *iface, IDirect3DDevice8 **device)
+{
+    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice8 *)This->parentDevice;
+    IDirect3DDevice8_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -105,5 +107,7 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -117,5 +121,7 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -129,5 +135,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -141,5 +148,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -153,5 +161,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -164,5 +173,6 @@
 static void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -174,5 +184,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     D3DRESOURCETYPE type;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -187,5 +198,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, lod %u.\n", iface, LODNew);
 
     wined3d_mutex_lock();
@@ -199,5 +211,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -211,5 +224,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -223,8 +237,8 @@
 static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
-    HRESULT hr;
-
-    WINED3DSURFACE_DESC    wined3ddesc;
-    TRACE("(%p) Relay\n", This);
+    WINED3DSURFACE_DESC wined3ddesc;
+    HRESULT hr;
+
+    TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
 
     wined3d_mutex_lock();
@@ -252,5 +266,5 @@
     IWineD3DSurface *mySurface = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
 
     wined3d_mutex_lock();
@@ -268,5 +282,7 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
+            iface, Level, pLockedRect, pRect, Flags);
 
     wined3d_mutex_lock();
@@ -280,5 +296,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, level %u.\n", iface, Level);
 
     wined3d_mutex_lock();
@@ -292,5 +309,6 @@
     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexbuffer.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexbuffer.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexbuffer.c	(revision 25949)
@@ -37,4 +37,6 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource8)
@@ -55,5 +57,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -72,11 +74,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice8_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
 
@@ -85,20 +91,16 @@
 
 /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
-static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device)
+{
+    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice8 *)This->parentDevice;
+    IDirect3DDevice8_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -106,5 +108,7 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -118,5 +122,7 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -130,5 +136,6 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -142,5 +149,6 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -154,5 +162,6 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -165,5 +174,6 @@
 static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -172,7 +182,7 @@
 }
 
-static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
-    IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
-    TRACE("(%p)\n", This);
+static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(IDirect3DVertexBuffer8 *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     return D3DRTYPE_VERTEXBUFFER;
@@ -183,5 +193,7 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
+            iface, OffsetToLock, SizeToLock, ppbData, Flags);
 
     wined3d_mutex_lock();
@@ -195,5 +207,6 @@
     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -208,5 +221,6 @@
     HRESULT hr;
     WINED3DBUFFER_DESC desc;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
@@ -268,5 +282,5 @@
     wined3d_mutex_lock();
     hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
-            usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
+            usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
             (IUnknown *)buffer, &d3d8_vertexbuffer_wined3d_parent_ops);
     wined3d_mutex_unlock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexdeclaration.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexdeclaration.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexdeclaration.c	(revision 25949)
@@ -39,5 +39,5 @@
 static HRESULT WINAPI IDirect3DVertexDeclaration8Impl_QueryInterface(IDirect3DVertexDeclaration8 *iface, REFIID riid, void **obj_ptr)
 {
-    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj_ptr);
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj_ptr);
 
     if (IsEqualGUID(riid, &IID_IUnknown)
@@ -56,7 +56,7 @@
 {
     IDirect3DVertexDeclaration8Impl *This = (IDirect3DVertexDeclaration8Impl *)iface;
-
     ULONG ref_count = InterlockedIncrement(&This->ref_count);
-    TRACE("(%p) : AddRef increasing to %d\n", This, ref_count);
+
+    TRACE("%p increasing refcount to %u.\n", iface, ref_count);
 
     if (ref_count == 1)
@@ -73,7 +73,7 @@
 {
     IDirect3DVertexDeclaration8Impl *This = (IDirect3DVertexDeclaration8Impl *)iface;
-
     ULONG ref_count = InterlockedDecrement(&This->ref_count);
-    TRACE("(%p) : Releasing to %d\n", This, ref_count);
+
+    TRACE("%p decreasing refcount to %u.\n", iface, ref_count);
 
     if (!ref_count) {
@@ -311,5 +311,6 @@
 
 /* TODO: find out where rhw (or positionT) is for declaration8 */
-UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size, WINED3DVERTEXELEMENT **wined3d_elements)
+static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
+        WINED3DVERTEXELEMENT **wined3d_elements)
 {
     const DWORD *token = d3d8_elements;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVertexShader8)) {
@@ -54,5 +56,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1 && This->wineD3DVertexShader)
@@ -77,5 +79,5 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c	(revision 25949)
@@ -37,4 +37,6 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
@@ -52,5 +54,5 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -61,5 +63,6 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedIncrement(&This->ref);
-        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+
+        TRACE("%p increasing refcount to %u.\n", iface, ref);
 
         if (ref == 1)
@@ -77,5 +80,5 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -87,5 +90,6 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedDecrement(&This->ref);
-        TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+
+        TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
         if (ref == 0) {
@@ -100,15 +104,22 @@
 
 /* IDirect3DVolume8 Interface follow: */
-static HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
-    IWineD3DDevice       *myDevice = NULL;
-
-    wined3d_mutex_lock();
-    IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
-    IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
-    IWineD3DDevice_Release(myDevice);
-    wined3d_mutex_unlock();
-
-    return D3D_OK;
+static HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(IDirect3DVolume8 *iface, IDirect3DDevice8 **device)
+{
+    IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
+    IDirect3DResource8 *resource;
+    HRESULT hr;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
+    if (SUCCEEDED(hr))
+    {
+        hr = IDirect3DResource8_GetDevice(resource, device);
+        IDirect3DResource8_Release(resource);
+
+        TRACE("Returning device %p.\n", *device);
+    }
+
+    return hr;
 }
 
@@ -116,5 +127,7 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -128,5 +141,7 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -140,5 +155,6 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -153,5 +169,6 @@
     HRESULT res;
 
-    TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
+    TRACE("iface %p, riid %s, container %p.\n",
+            iface, debugstr_guid(riid), ppContainer);
 
     if (!This->container) return E_NOINTERFACE;
@@ -173,5 +190,5 @@
     WINED3DVOLUME_DESC     wined3ddesc;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
@@ -197,5 +214,7 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
+
+    TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
+            iface, pLockedVolume, pBox, Flags);
 
     wined3d_mutex_lock();
@@ -209,5 +228,6 @@
     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c	(revision 25949)
@@ -37,4 +37,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
     || IsEqualGUID(riid, &IID_IDirect3DResource8)
@@ -55,5 +57,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -72,11 +74,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice8 *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice8_Release(parentDevice);
     }
     return ref;
@@ -84,20 +90,16 @@
 
 /* IDirect3DVolumeTexture8 IDirect3DResource8 Interface follow: */
-static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
-    IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DVolumeTexture_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(IDirect3DVolumeTexture8 *iface, IDirect3DDevice8 **device)
+{
+    IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice8 *)This->parentDevice;
+    IDirect3DDevice8_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -105,5 +107,7 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -117,5 +121,7 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -129,5 +135,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -141,5 +148,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -153,5 +161,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -164,5 +173,6 @@
 static void WINAPI IDirect3DVolumeTexture8Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE8 iface) {
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -174,5 +184,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     D3DRESOURCETYPE type;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -187,5 +198,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, lod %u.\n", iface, LODNew);
 
     wined3d_mutex_lock();
@@ -199,5 +211,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -211,5 +224,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -226,5 +240,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
 
     wined3d_mutex_lock();
@@ -252,5 +266,5 @@
     IWineD3DVolume *myVolume = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, volume %p.\n", iface, Level, ppVolumeLevel);
 
     wined3d_mutex_lock();
@@ -268,5 +282,7 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
+
+    TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
+            iface, Level, pLockedVolume, pBox, Flags);
 
     wined3d_mutex_lock();
@@ -280,5 +296,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
+
+    TRACE("iface %p, level %u.\n", iface, Level);
 
     wined3d_mutex_lock();
@@ -292,5 +309,6 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, dirty_box %p.\n", iface, pDirtyBox);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c	(revision 25949)
@@ -39,4 +39,7 @@
 static HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
+
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
@@ -57,5 +60,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -74,13 +77,17 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
 
-        IDirect3DDevice9Ex_Release(This->parentDevice);
         wined3d_mutex_lock();
         IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -88,20 +95,16 @@
 
 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
-static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(IDirect3DCubeTexture9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -109,5 +112,7 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -121,5 +126,7 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -133,5 +140,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -145,5 +153,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -157,5 +166,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -168,5 +178,6 @@
 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -178,5 +189,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     D3DRESOURCETYPE ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -191,5 +203,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, lod %u.\n", iface, LODNew);
 
     wined3d_mutex_lock();
@@ -203,5 +216,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -215,5 +229,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -227,5 +242,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
 
     wined3d_mutex_lock();
@@ -239,5 +255,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     D3DTEXTUREFILTERTYPE ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -250,5 +267,6 @@
 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -263,5 +281,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
 
     wined3d_mutex_lock();
@@ -289,5 +307,5 @@
     IWineD3DSurface *mySurface = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, FaceType, Level, ppCubeMapSurface);
 
     wined3d_mutex_lock();
@@ -305,5 +323,7 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
+            iface, FaceType, Level, pLockedRect, pRect, Flags);
 
     wined3d_mutex_lock();
@@ -317,5 +337,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, face %#x, level %u.\n", iface, FaceType, Level);
 
     wined3d_mutex_lock();
@@ -329,5 +350,6 @@
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, face %#x, dirty_rect %p.\n", iface, FaceType, pDirtyRect);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c	(revision 25949)
@@ -43,5 +43,5 @@
 }
 
-IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion) {
+IDirect3D9* WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT SDKVersion) {
     IDirect3D9Impl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3D9Impl));
 
@@ -63,5 +63,5 @@
 }
 
-HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **direct3d9ex) {
+HRESULT WINAPI DECLSPEC_HOTPATCH Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **direct3d9ex) {
     IDirect3D9 *ret;
     IDirect3D9Impl* object;
@@ -88,5 +88,7 @@
 void* WINAPI Direct3DShaderValidatorCreate9(void)
 {
-    FIXME("stub\n");
+    static int once;
+
+    if (!once++) FIXME("stub\n");
     return NULL;
 }
@@ -109,5 +111,5 @@
  */
 int WINAPI D3DPERF_BeginEvent(D3DCOLOR color, LPCWSTR name) {
-    FIXME("(color %#x, name %s) : stub\n", color, debugstr_w(name));
+    TRACE("(color %#x, name %s) : stub\n", color, debugstr_w(name));
 
     return D3DPERF_event_level++;
@@ -118,5 +120,5 @@
  */
 int WINAPI D3DPERF_EndEvent(void) {
-    FIXME("(void) : stub\n");
+    TRACE("(void) : stub\n");
 
     return --D3DPERF_event_level;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 25949)
@@ -168,14 +168,4 @@
 void filter_caps(D3DCAPS9* pCaps) DECLSPEC_HIDDEN;
 
-/* ---------------- */
-/* IDirect3DDevice9 */
-/* ---------------- */
-
-/*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl DECLSPEC_HIDDEN;
-extern const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl DECLSPEC_HIDDEN;
-
 /*****************************************************************************
  * IDirect3DDevice9 implementation structure
@@ -200,8 +190,8 @@
 } IDirect3DDevice9Impl;
 
+HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
+        HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
 
 /* IDirect3DDevice9: */
-extern HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
-        D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DSwapChain9 **pSwapChain) DECLSPEC_HIDDEN;
 extern HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface,
         UINT iSwapChain, IDirect3DSwapChain9 **pSwapChain) DECLSPEC_HIDDEN;
@@ -301,4 +291,7 @@
 } IDirect3DSwapChain9Impl;
 
+HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
+        D3DPRESENT_PARAMETERS *present_parameters) DECLSPEC_HIDDEN;
+
 /* ----------------- */
 /* IDirect3DSurface9 */
@@ -581,7 +574,3 @@
 } IDirect3DQuery9Impl;
 
-
-/* Callbacks */
-extern ULONG WINAPI D3D9CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain) DECLSPEC_HIDDEN;
-
 #endif /* __WINE_D3D9_PRIVATE_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 25949)
@@ -76,5 +76,5 @@
         case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
         case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
-        case WINED3DFMT_S8_UINT_D24_UNORM: return D3DFMT_D24S8;
+        case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
         case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
         case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
@@ -141,5 +141,5 @@
         case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
         case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
-        case D3DFMT_D24S8: return WINED3DFMT_S8_UINT_D24_UNORM;
+        case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
         case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
         case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
@@ -191,4 +191,15 @@
 }
 
+static ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
+{
+    IDirect3DSwapChain9Impl *parent;
+
+    TRACE("swapchain %p.\n", swapchain);
+
+    IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)&parent);
+    parent->isImplicit = FALSE;
+    return IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)parent);
+}
+
 /* IDirect3D IUnknown parts follow: */
 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
@@ -196,4 +207,6 @@
     IDirect3D9 *d3d;
     IDirect3D9Impl *d3dimpl;
+
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
 
     if (IsEqualGUID(riid, &IID_IUnknown)
@@ -240,10 +253,10 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     return ref;
 }
 
-static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
+static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     ULONG ref;
@@ -252,5 +265,5 @@
     ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
@@ -277,19 +290,17 @@
 
 /* IDirect3DDevice Interface follow: */
-static HRESULT  WINAPI  IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9EX iface) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hr;
-    TRACE("(%p)\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
-    wined3d_mutex_unlock();
-
-    if(hr == WINED3D_OK && This->notreset) {
-        TRACE("D3D9 Device is marked not reset\n");
-        hr = D3DERR_DEVICENOTRESET;
-    }
-
-    return hr;
+static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+
+    TRACE("iface %p.\n", iface);
+
+    if (This->notreset)
+    {
+        TRACE("D3D9 device is marked not reset.\n");
+        return D3DERR_DEVICENOTRESET;
+    }
+
+    return D3D_OK;
 }
 
@@ -297,5 +308,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -309,5 +321,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -323,5 +336,5 @@
     IWineD3D* pWineD3D;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
 
     if (NULL == ppD3D9) {
@@ -350,5 +363,6 @@
     WINED3DCAPS *pWineCaps;
 
-    TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
+    TRACE("iface %p, caps %p.\n", iface, pCaps);
+
     if(NULL == pCaps){
         return D3DERR_INVALIDCALL;
@@ -380,5 +394,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode);
 
     wined3d_mutex_lock();
@@ -394,5 +409,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, parameters %p.\n", iface, pParameters);
 
     wined3d_mutex_lock();
@@ -408,5 +424,7 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
+            iface, XHotSpot, YHotSpot, pCursorBitmap);
+
     if(!pCursorBitmap) {
         WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
@@ -423,5 +441,6 @@
 static void     WINAPI  IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, XScreenSpace, YScreenSpace, Flags);
 
     wined3d_mutex_lock();
@@ -433,5 +452,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     BOOL ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, show %#x.\n", iface, bShow);
 
     wined3d_mutex_lock();
@@ -440,4 +460,35 @@
 
     return ret;
+}
+
+static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
+        D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DSwapChain9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, present_parameters %p, swapchain %p.\n",
+            iface, present_parameters, swapchain);
+
+    object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate swapchain memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = swapchain_init(object, This, present_parameters);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize swapchain, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created swapchain %p.\n", object);
+    *swapchain = (IDirect3DSwapChain9 *)object;
+
+    return D3D_OK;
 }
 
@@ -500,5 +551,5 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
+static HRESULT  WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     WINED3DPRESENT_PARAMETERS localParameters;
@@ -507,5 +558,5 @@
     UINT i;
 
-    TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
+    TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
 
     /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
@@ -578,9 +629,11 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
+static HRESULT  WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
  pDirtyRegion) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
+            iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
 
     wined3d_mutex_lock();
@@ -596,5 +649,6 @@
     HRESULT rc = D3D_OK;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
+            iface, iSwapChain, BackBuffer, Type, ppBackBuffer);
 
     wined3d_mutex_lock();
@@ -611,5 +665,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
 
     wined3d_mutex_lock();
@@ -623,5 +678,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, enable %#x.\n", iface, bEnableDialogs);
 
     wined3d_mutex_lock();
@@ -636,5 +692,6 @@
 {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
 
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
@@ -646,5 +703,6 @@
 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
 
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
@@ -822,5 +880,8 @@
     HRESULT hr;
 
-    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
+    TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
+            "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
+            iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
+            Usage, Pool, MultiSample, MultisampleQuality);
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
@@ -851,5 +912,9 @@
 {
     HRESULT hr;
-    TRACE("Relay\n");
+
+    TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
+            "lockable %#x, surface %p, shared_handle %p.\n",
+            iface, Width, Height, Format, MultiSample, MultisampleQuality,
+            Lockable, ppSurface, pSharedHandle);
 
     hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
@@ -864,5 +929,9 @@
                                                                 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
     HRESULT hr;
-    TRACE("Relay\n");
+
+    TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
+            "discard %#x, surface %p, shared_handle %p.\n",
+            iface, Width, Height, Format, MultiSample, MultisampleQuality,
+            Discard, ppSurface, pSharedHandle);
 
     hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
@@ -876,5 +945,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
+            iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
 
     wined3d_mutex_lock();
@@ -888,5 +959,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
 
     wined3d_mutex_lock();
@@ -897,10 +969,12 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
+        IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
+{
     IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
     IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
     HRESULT hr;
-    TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
+
+    TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
 
     wined3d_mutex_lock();
@@ -915,5 +989,6 @@
     IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
 
     wined3d_mutex_lock();
@@ -924,11 +999,13 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
+        const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
+{
     IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
     IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
     HRESULT hr;
 
-    TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
+    TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
+            iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
 
     wined3d_mutex_lock();
@@ -947,5 +1024,6 @@
     WINED3DSURFACE_DESC desc;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
 
     wined3d_mutex_lock();
@@ -976,5 +1054,8 @@
 static HRESULT  WINAPI  IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
     HRESULT hr;
-    TRACE("Relay\n");
+
+    TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
+            iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
+
     if(Pool == D3DPOOL_MANAGED ){
         FIXME("Attempting to create a managed offscreen plain surface\n");
@@ -1000,5 +1081,6 @@
     IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
 
     if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
@@ -1009,5 +1091,5 @@
 
     wined3d_mutex_lock();
-    hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
+    hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
     wined3d_mutex_unlock();
 
@@ -1020,5 +1102,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
 
     if (ppRenderTarget == NULL) {
@@ -1060,5 +1142,6 @@
     IDirect3DSurface9 *pOldSurface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
 
     pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
@@ -1070,6 +1153,4 @@
         IDirect3DSurface9_Release(pOldSurface);
     }
-
-    pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
     hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
     if (pZStencilSurface) {
@@ -1086,5 +1167,6 @@
     IWineD3DSurface *pZStencilSurface;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
+
     if(ppZStencilSurface == NULL){
         return D3DERR_INVALIDCALL;
@@ -1109,5 +1191,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -1118,8 +1201,9 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -1133,5 +1217,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
+            iface, Count, pRects, Flags, Color, Z, Stencil);
 
     /* Note: D3DRECT is compatible with WINED3DRECT */
@@ -1146,5 +1232,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
@@ -1160,5 +1247,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
@@ -1173,5 +1260,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
@@ -1186,5 +1274,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
     /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
@@ -1199,5 +1288,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
     /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
@@ -1212,5 +1302,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, material %p.\n", iface, pMaterial);
 
     /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
@@ -1225,5 +1316,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, material %p.\n", iface, pMaterial);
 
     /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
@@ -1238,5 +1330,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
     /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
@@ -1251,5 +1344,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
     /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
@@ -1264,5 +1358,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
 
     wined3d_mutex_lock();
@@ -1276,5 +1371,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
 
     wined3d_mutex_lock();
@@ -1288,5 +1384,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
 
     wined3d_mutex_lock();
@@ -1300,5 +1397,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
 
     wined3d_mutex_lock();
@@ -1309,8 +1407,9 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+static HRESULT  WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+
+    TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
 
     wined3d_mutex_lock();
@@ -1324,5 +1423,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
 
     wined3d_mutex_lock();
@@ -1336,5 +1436,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
 
     wined3d_mutex_lock();
@@ -1348,5 +1449,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
 
     wined3d_mutex_lock();
@@ -1362,5 +1464,5 @@
     HRESULT rc = D3D_OK;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
 
     if(ppTexture == NULL){
@@ -1387,5 +1489,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
+
+    TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
 
     wined3d_mutex_lock();
@@ -1437,5 +1540,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
 
     wined3d_mutex_lock();
@@ -1449,5 +1553,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
 
     wined3d_mutex_lock();
@@ -1463,5 +1568,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
 
     wined3d_mutex_lock();
@@ -1472,8 +1578,9 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+
+    TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
 
     wined3d_mutex_lock();
@@ -1487,5 +1594,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
 
     wined3d_mutex_lock();
@@ -1501,5 +1609,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
 
     wined3d_mutex_lock();
@@ -1513,5 +1622,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
 
     wined3d_mutex_lock();
@@ -1525,5 +1635,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
 
     wined3d_mutex_lock();
@@ -1537,5 +1648,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
 
     wined3d_mutex_lock();
@@ -1549,5 +1661,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, rect %p.\n", iface, pRect);
 
     wined3d_mutex_lock();
@@ -1561,5 +1674,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, rect %p.\n", iface, pRect);
 
     wined3d_mutex_lock();
@@ -1573,5 +1687,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, software %#x.\n", iface, bSoftware);
 
     wined3d_mutex_lock();
@@ -1585,5 +1700,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     BOOL ret;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -1597,5 +1713,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
 
     wined3d_mutex_lock();
@@ -1609,5 +1726,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     float ret;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -1623,5 +1741,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
+            iface, PrimitiveType, StartVertex, PrimitiveCount);
 
     wined3d_mutex_lock();
@@ -1638,7 +1758,10 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
+
+    TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
+            "vertex_count %u, start_idx %u, primitive_count %u.\n",
+            iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
+            NumVertices, startIndex, primCount);
+
     wined3d_mutex_lock();
     IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
@@ -1656,5 +1779,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
+            iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
 
     wined3d_mutex_lock();
@@ -1673,5 +1798,9 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
+            "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
+            iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
+            pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
 
     wined3d_mutex_lock();
@@ -1690,5 +1819,7 @@
     HRESULT hr;
     IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
+            iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
 
     wined3d_mutex_lock();
@@ -1797,5 +1928,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, fvf %#x.\n", iface, FVF);
 
     if (!FVF)
@@ -1822,9 +1953,10 @@
 }
 
-static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9EX iface, DWORD* pFVF) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
+{
     IDirect3DVertexDeclaration9 *decl;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, fvf %p.\n", iface, pFVF);
 
     hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
@@ -1884,5 +2016,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
+            iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
 
     wined3d_mutex_lock();
@@ -1900,5 +2034,6 @@
     HRESULT rc = D3D_OK;
 
-    TRACE("(%p) Relay\n" , This);
+    TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
+            iface, StreamNumber, pStream, OffsetInBytes, pStride);
 
     if(pStream == NULL){
@@ -1927,5 +2062,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
 
     wined3d_mutex_lock();
@@ -1939,5 +2075,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
+
+    TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
 
     wined3d_mutex_lock();
@@ -1952,5 +2089,6 @@
     HRESULT hr;
     IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, buffer %p.\n", iface, pIndexData);
 
     wined3d_mutex_lock();
@@ -1968,5 +2106,5 @@
     HRESULT rc = D3D_OK;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
 
     if(ppIndexData == NULL){
@@ -2021,5 +2159,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
+            iface, Handle, pNumSegs, pRectPatchInfo);
 
     wined3d_mutex_lock();
@@ -2033,5 +2173,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
+            iface, Handle, pNumSegs, pTriPatchInfo);
 
     wined3d_mutex_lock();
@@ -2045,5 +2187,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, handle %#x.\n", iface, Handle);
 
     wined3d_mutex_lock();
@@ -2054,96 +2197,139 @@
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(LPDIRECT3DDEVICE9EX iface, UINT width, UINT height, float *rows, float *columns) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d, %d, %p, %p) Stub!\n", This, width, height, rows, columns);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
+        UINT width, UINT height, float *rows, float *columns)
+{
+    FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
+            iface, width, height, rows, columns);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_ComposeRects(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%p, %p, %p, %d, %p, %d, %d, %d) Stub!\n", This, pSrc, pDst, pSrcRectDescs, NumRects, pDstRectDescs, Operation, Xoffset, Yoffset);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
+        IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
+        UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
+{
+    FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
+            "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
+            iface, src_surface, dst_surface, src_descs, rect_count,
+            dst_descs, operation, offset_x, offset_y);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_PresentEx(LPDIRECT3DDEVICE9EX iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p= -> (%p), %p, %p, %p, 0x%08x) Stub!\n", This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
+        const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
+        const RGNDATA *dirty_region, DWORD flags)
+{
+    FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
+            iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_GetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT *pPriority) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%p) Stub!\n", This, pPriority);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
+{
+    FIXME("iface %p, priority %p stub!\n", iface, priority);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_SetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT Priority) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d) Stub!\n", This, Priority);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
+{
+    FIXME("iface %p, priority %d stub!\n", iface, priority);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_WaitForVBlank(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d) Stub!\n", This, iSwapChain);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
+{
+    FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_CheckresourceResidency(LPDIRECT3DDEVICE9EX iface, IDirect3DResource9 ** pResourceArray, UINT32 Numresources) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%p, %d) Stub!\n", This, pResourceArray, Numresources);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
+        IDirect3DResource9 **resources, UINT32 resource_count)
+{
+    FIXME("iface %p, resources %p, resource_count %u stub!\n",
+            iface, resources, resource_count);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_SetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT MaxLatency) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d) Stub!\n", This, MaxLatency);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
+{
+    FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_GetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT *pMaxLatency) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%p) Stub!\n", This, pMaxLatency);
-    *pMaxLatency = 2;
+static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
+{
+    FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
+
+    *max_latency = 2;
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_CheckdeviceState(LPDIRECT3DDEVICE9EX iface, HWND hDestinationWindow) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%p) Stub!\n", This, hDestinationWindow);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
+{
+    FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_CreateRenderTargetEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Lockable, IDirect3DSurface9 ** ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d, %d, %d, %d, %d, %s, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, MultiSample, MultiSampleQuality, Lockable ? "true" : "false", ppSurface, pSharedHandle, Usage);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
+        UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
+        BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
+{
+    FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
+            "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
+            iface, width, height, format, multisample_type, multisample_quality,
+            lockable, surface, shared_handle, usage);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d, %d, %d, %d, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
+        UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
+        HANDLE *shared_handle, DWORD usage)
+{
+    FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
+            iface, width, height, format, pool, surface, shared_handle, usage);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d, %d, %d, %d, %d, %s, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, MultiSample, MultiSampleQuality, Discard ? "true" : "false", ppSurface, pSharedHandle, Usage);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
+        UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
+        BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
+{
+    FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
+            "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
+            iface, width, height, format, multisample_type, multisample_quality,
+            discard, surface, shared_handle, usage);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_ResetEx(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%p) Stub!\n", This, pPresentationParameters);
+static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
+        D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
+{
+    FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9ExImpl_GetDisplayModeEx(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
-    FIXME("(%p)->(%d, %p, %p) Stub!\n", This, iSwapChain, pMode, pRotation);
+static HRESULT  WINAPI  IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
+        UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
+{
+    FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
+
     return WINED3DERR_INVALIDCALL;
 }
 
-const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
+static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
 {
     /* IUnknown */
@@ -2275,8 +2461,8 @@
     IDirect3DDevice9ExImpl_SetGPUThreadPriority,
     IDirect3DDevice9ExImpl_WaitForVBlank,
-    IDirect3DDevice9ExImpl_CheckresourceResidency,
+    IDirect3DDevice9ExImpl_CheckResourceResidency,
     IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
     IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
-    IDirect3DDevice9ExImpl_CheckdeviceState,
+    IDirect3DDevice9ExImpl_CheckDeviceState,
     IDirect3DDevice9ExImpl_CreateRenderTargetEx,
     IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
@@ -2517,5 +2703,5 @@
 }
 
-const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
+static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
 {
     /* IUnknown methods */
@@ -2531,2 +2717,110 @@
     device_parent_CreateSwapChain,
 };
+
+HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
+        HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
+{
+    WINED3DPRESENT_PARAMETERS *wined3d_parameters;
+    UINT i, count = 1;
+    HRESULT hr;
+
+    device->lpVtbl = &Direct3DDevice9_Vtbl;
+    device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
+    device->ref = 1;
+
+    wined3d_mutex_lock();
+    hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
+            (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d device, hr %#x.\n", hr);
+        wined3d_mutex_unlock();
+        return hr;
+    }
+
+    if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
+    {
+        WINED3DCAPS caps;
+
+        IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
+        count = caps.NumberOfAdaptersInGroup;
+    }
+
+    if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
+
+    wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
+    if (!wined3d_parameters)
+    {
+        ERR("Failed to allocate wined3d parameters.\n");
+        IWineD3DDevice_Release(device->WineD3DDevice);
+        wined3d_mutex_unlock();
+        return E_OUTOFMEMORY;
+    }
+
+    for (i = 0; i < count; ++i)
+    {
+        wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
+        wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
+        wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
+        wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
+        wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
+        wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
+        wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
+        wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
+        wined3d_parameters[i].Windowed = parameters[i].Windowed;
+        wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
+        wined3d_parameters[i].AutoDepthStencilFormat =
+                wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
+        wined3d_parameters[i].Flags = parameters[i].Flags;
+        wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
+        wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
+        wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
+    }
+
+    hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize 3D, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, wined3d_parameters);
+        IWineD3DDevice_Release(device->WineD3DDevice);
+        wined3d_mutex_unlock();
+        return hr;
+    }
+
+    wined3d_mutex_unlock();
+
+    for (i = 0; i < count; ++i)
+    {
+        parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
+        parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
+        parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
+        parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
+        parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
+        parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
+        parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
+        parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
+        parameters[i].Windowed = wined3d_parameters[i].Windowed;
+        parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
+        parameters[i].AutoDepthStencilFormat =
+                d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
+        parameters[i].Flags = wined3d_parameters[i].Flags;
+        parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
+        parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
+    }
+    HeapFree(GetProcessHeap(), 0, wined3d_parameters);
+
+    /* Initialize the converted declaration array. This creates a valid pointer
+     * and when adding decls HeapReAlloc() can be used without further checking. */
+    device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
+    if (!device->convertedDecls)
+    {
+        ERR("Failed to allocate FVF vertex declaration map memory.\n");
+        wined3d_mutex_lock();
+        IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D9CB_DestroySwapChain);
+        IWineD3DDevice_Release(device->WineD3DDevice);
+        wined3d_mutex_unlock();
+        return E_OUTOFMEMORY;
+    }
+
+    return D3D_OK;
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 25949)
@@ -39,4 +39,6 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3D9)) {
@@ -67,5 +69,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     return ref;
@@ -76,5 +78,5 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
@@ -93,5 +95,6 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%p)\n", This, pInitializeFunction);
+
+    TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
 
     wined3d_mutex_lock();
@@ -105,5 +108,6 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("%p\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -118,4 +122,7 @@
     WINED3DADAPTER_IDENTIFIER adapter_id;
     HRESULT hr;
+
+    TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
+            iface, Adapter, Flags, pIdentifier);
 
     adapter_id.driver = pIdentifier->Driver;
@@ -144,5 +151,6 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%d, %d\n", This, Adapter, Format);
+
+    TRACE("iface %p, adapter %u, format %#x.\n", iface, Adapter, Format);
 
     /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out */
@@ -161,5 +169,8 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%d, %d, %d, %p)\n", This, Adapter, Format, Mode, pMode);
+
+    TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
+            iface, Adapter, Format, Mode, pMode);
+
     /* We can't pass this to WineD3D, otherwise it'll think it came from D3D8 or DDraw.
        It's supposed to fail anyway, so no harm returning failure. */
@@ -181,4 +192,6 @@
     HRESULT hr;
 
+    TRACE("iface %p, adapter %u, mode %p.\n", iface, Adapter, pMode);
+
     wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
@@ -195,6 +208,7 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p)->(%d, %d, %d, %d, %s\n", This, Adapter, CheckType, DisplayFormat,
-          BackBufferFormat, Windowed ? "true" : "false");
+
+    TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
+            iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
 
     wined3d_mutex_lock();
@@ -212,5 +226,7 @@
     HRESULT hr;
     WINED3DRESOURCETYPE WineD3DRType;
-    TRACE("%p\n", This);
+
+    TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
+            iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
 
     /* This format is nothing special and it is supported perfectly.
@@ -251,5 +267,7 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("%p\n", This);
+
+    TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
+            iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
 
     wined3d_mutex_lock();
@@ -266,5 +284,7 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("%p\n", This);
+
+    TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
+            iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
 
     wined3d_mutex_lock();
@@ -280,5 +300,7 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
-    TRACE("%p\n", This);
+
+    TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
+            iface, Adapter, DeviceType, SourceFormat, TargetFormat);
 
     wined3d_mutex_lock();
@@ -355,5 +377,5 @@
     WINED3DCAPS *pWineCaps;
 
-    TRACE("(%p) Relay %d %u %p\n", This, Adapter, DeviceType, pCaps);
+    TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
 
     if(NULL == pCaps){
@@ -385,5 +407,6 @@
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HMONITOR ret;
-    TRACE("%p\n", This);
+
+    TRACE("iface %p, adapter %u.\n", iface, Adapter);
 
     wined3d_mutex_lock();
@@ -394,155 +417,95 @@
 }
 
-ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
-    IDirect3DSwapChain9Impl* swapChainParent;
-    TRACE("(%p) call back\n", pSwapChain);
-
-    IWineD3DSwapChain_GetParent(pSwapChain,(IUnknown **) &swapChainParent);
-    swapChainParent->isImplicit = FALSE;
-    /* Swap chain had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
-    return IDirect3DSwapChain9_Release((IDirect3DSwapChain9*) swapChainParent);
-}
-
-static HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType,
-                                                  HWND hFocusWindow, DWORD BehaviourFlags,
-                                                  D3DPRESENT_PARAMETERS* pPresentationParameters,
-                                                  IDirect3DDevice9** ppReturnedDeviceInterface) {
-
-    IDirect3D9Impl       *This   = (IDirect3D9Impl *)iface;
-    IDirect3DDevice9Impl *object = NULL;
-    WINED3DPRESENT_PARAMETERS *localParameters;
-    UINT i, count = 1;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    /* Check the validity range of the adapter parameter */
-    if (Adapter >= IDirect3D9Impl_GetAdapterCount(iface)) {
-        *ppReturnedDeviceInterface = NULL;
-        return D3DERR_INVALIDCALL;
-    }
-
-    /* Allocate the storage for the device object */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice9Impl));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *ppReturnedDeviceInterface = NULL;
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &Direct3DDevice9_Vtbl;
-    object->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
-    object->ref = 1;
-    *ppReturnedDeviceInterface = (IDirect3DDevice9 *)object;
-
-    /* Allocate an associated WineD3DDevice object */
-    wined3d_mutex_lock();
-    hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
-            (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
-    if (hr != D3D_OK) {
+static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
+        D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
+        IDirect3DDevice9 **device)
+{
+    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
+    IDirect3DDevice9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
+            iface, adapter, device_type, focus_window, flags, parameters, device);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate device memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize device, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppReturnedDeviceInterface = NULL;
-        wined3d_mutex_unlock();
-
         return hr;
     }
 
-    TRACE("(%p) : Created Device %p\n", This, object);
-
-    if (BehaviourFlags & D3DCREATE_ADAPTERGROUP_DEVICE)
-    {
-        WINED3DCAPS caps;
-
-        IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, &caps);
-        count = caps.NumberOfAdaptersInGroup;
-    }
-
-    if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
-        IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
-    }
-
-    localParameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*localParameters) * count);
-    for (i = 0; i < count; ++i)
-    {
-        localParameters[i].BackBufferWidth = pPresentationParameters[i].BackBufferWidth;
-        localParameters[i].BackBufferHeight = pPresentationParameters[i].BackBufferHeight;
-        localParameters[i].BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters[i].BackBufferFormat);
-        localParameters[i].BackBufferCount = pPresentationParameters[i].BackBufferCount;
-        localParameters[i].MultiSampleType = pPresentationParameters[i].MultiSampleType;
-        localParameters[i].MultiSampleQuality = pPresentationParameters[i].MultiSampleQuality;
-        localParameters[i].SwapEffect = pPresentationParameters[i].SwapEffect;
-        localParameters[i].hDeviceWindow = pPresentationParameters[i].hDeviceWindow;
-        localParameters[i].Windowed = pPresentationParameters[i].Windowed;
-        localParameters[i].EnableAutoDepthStencil = pPresentationParameters[i].EnableAutoDepthStencil;
-        localParameters[i].AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters[i].AutoDepthStencilFormat);
-        localParameters[i].Flags = pPresentationParameters[i].Flags;
-        localParameters[i].FullScreen_RefreshRateInHz = pPresentationParameters[i].FullScreen_RefreshRateInHz;
-        localParameters[i].PresentationInterval = pPresentationParameters[i].PresentationInterval;
-        localParameters[i].AutoRestoreDisplayMode = TRUE;
-    }
-
-    hr = IWineD3DDevice_Init3D(object->WineD3DDevice, localParameters);
-    if (hr != D3D_OK) {
-        FIXME("(%p) D3D Initialization failed for WineD3DDevice %p\n", This, object->WineD3DDevice);
-        HeapFree(GetProcessHeap(), 0, object);
-        *ppReturnedDeviceInterface = NULL;
-    }
-
-    for (i = 0; i < count; ++i)
-    {
-        pPresentationParameters[i].BackBufferWidth = localParameters[i].BackBufferWidth;
-        pPresentationParameters[i].BackBufferHeight = localParameters[i].BackBufferHeight;
-        pPresentationParameters[i].BackBufferFormat = d3dformat_from_wined3dformat(localParameters[i].BackBufferFormat);
-        pPresentationParameters[i].BackBufferCount = localParameters[i].BackBufferCount;
-        pPresentationParameters[i].MultiSampleType = localParameters[i].MultiSampleType;
-        pPresentationParameters[i].MultiSampleQuality = localParameters[i].MultiSampleQuality;
-        pPresentationParameters[i].SwapEffect = localParameters[i].SwapEffect;
-        pPresentationParameters[i].hDeviceWindow = localParameters[i].hDeviceWindow;
-        pPresentationParameters[i].Windowed = localParameters[i].Windowed;
-        pPresentationParameters[i].EnableAutoDepthStencil = localParameters[i].EnableAutoDepthStencil;
-        pPresentationParameters[i].AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters[i].AutoDepthStencilFormat);
-        pPresentationParameters[i].Flags = localParameters[i].Flags;
-        pPresentationParameters[i].FullScreen_RefreshRateInHz = localParameters[i].FullScreen_RefreshRateInHz;
-        pPresentationParameters[i].PresentationInterval = localParameters[i].PresentationInterval;
-    }
-    HeapFree(GetProcessHeap(), 0, localParameters);
-
-    /* Initialize the converted declaration array. This creates a valid pointer and when adding decls HeapReAlloc
-     * can be used without further checking
-     */
-    object->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
-static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface, UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter) {
-    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
-    FIXME("(%p)->(%d, %p): Stub!\n", This, Adapter, pFilter);
+    TRACE("Created device %p.\n", object);
+    *device = (IDirect3DDevice9 *)object;
+
+    return D3D_OK;
+}
+
+static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
+        UINT adapter, const D3DDISPLAYMODEFILTER *filter)
+{
+    FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
+
     return D3DERR_DRIVERINTERNALERROR;
 }
 
-static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface, UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) {
-    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
-    FIXME("(%p)->(%d, %p, %p): Stub!\n", This, Adapter, pFilter, pMode);
+static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface,
+        UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
+{
+    FIXME("iface %p, adapter %u, filter %p, mode_idx %u, mode %p stub!\n",
+            iface, adapter, filter, mode_idx, mode);
+
     return D3DERR_DRIVERINTERNALERROR;
 }
 
-static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface, UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
-    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
-    FIXME("(%p)->(%d, %p, %p): Stub!\n", This, Adapter, pMode, pRotation);
+static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
+        UINT adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
+{
+    FIXME("iface %p, adapter %u, mode %p, rotation %p stub!\n",
+            iface, adapter, mode, rotation);
+
     return D3DERR_DRIVERINTERNALERROR;
 }
 
-static HRESULT WINAPI IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, struct IDirect3DDevice9Ex **ppReturnedDeviceInterface) {
-    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
-    FIXME("(%p)->(%d, %d, %p, 0x%08x, %p, %p, %p): Stub!\n", This, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface);
-    *ppReturnedDeviceInterface = NULL;
+static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface,
+        UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
+        D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
+{
+    FIXME("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x,\n"
+            "parameters %p, mode %p, device %p stub!\n",
+            iface, adapter, device_type, focus_window, flags,
+            parameters, mode, device);
+
+    *device = NULL;
+
     return D3DERR_DRIVERINTERNALERROR;
 }
 
-static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT Adapter, LUID *pLUID) {
-    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
-    FIXME("(%p)->(%d, %p)\n", This, Adapter, pLUID);
-    return D3DERR_DRIVERINTERNALERROR;
+static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
+{
+    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
+    WINED3DADAPTER_IDENTIFIER adapter_id;
+    HRESULT hr;
+
+    TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
+
+    adapter_id.driver_size = 0;
+    adapter_id.description_size = 0;
+    adapter_id.device_name_size = 0;
+
+    wined3d_mutex_lock();
+    hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, adapter, 0, &adapter_id);
+    wined3d_mutex_unlock();
+
+    memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
+
+    return hr;
 }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
@@ -55,5 +57,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -72,11 +74,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -84,20 +90,16 @@
 
 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
-static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(IDirect3DIndexBuffer9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -105,5 +107,7 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -117,5 +121,7 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -129,5 +135,6 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -141,5 +148,6 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -153,5 +161,6 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -164,5 +173,6 @@
 static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -171,7 +181,7 @@
 }
 
-static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
-    IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
-    TRACE("(%p)\n", This);
+static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(IDirect3DIndexBuffer9 *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     return D3DRTYPE_INDEXBUFFER;
@@ -182,5 +192,7 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
+            iface, OffsetToLock, SizeToLock, ppbData, Flags);
 
     wined3d_mutex_lock();
@@ -194,5 +206,6 @@
     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -207,5 +220,6 @@
     HRESULT hr;
     WINED3DBUFFER_DESC desc;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/pixelshader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/pixelshader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/pixelshader.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DPixelShader9)) {
@@ -54,5 +56,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -71,11 +73,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DPixelShader_Release(This->wineD3DPixelShader);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -83,17 +89,15 @@
 
 /* IDirect3DPixelShader9 Interface follow: */
-static HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(LPDIRECT3DPIXELSHADER9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
-    IWineD3DDevice *myDevice = NULL;
-
-    TRACE("(%p) : Relay\n", This);
-
-    wined3d_mutex_lock();
-    IWineD3DPixelShader_GetDevice(This->wineD3DPixelShader, &myDevice);
-    IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
-    IWineD3DDevice_Release(myDevice);
-    wined3d_mutex_unlock();
-
-    TRACE("(%p) returning (%p)\n", This, *ppDevice);
+static HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
     return D3D_OK;
 }
@@ -102,5 +106,6 @@
     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, data %p, data_size %p.\n", iface, pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -160,5 +165,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)pShader;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, shader %p.\n", iface, shader);
 
     wined3d_mutex_lock();
@@ -172,7 +178,8 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IWineD3DPixelShader *object;
-
-    HRESULT hrc = D3D_OK;
-    TRACE("(%p) Relay\n", This);
+    HRESULT hrc;
+
+    TRACE("iface %p, shader %p.\n", iface, ppShader);
+
     if (ppShader == NULL) {
         TRACE("(%p) Invalid call\n", This);
@@ -207,5 +214,7 @@
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4fCount);
 
     wined3d_mutex_lock();
@@ -220,5 +229,6 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4fCount);
 
     wined3d_mutex_lock();
@@ -232,5 +242,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4iCount);
 
     wined3d_mutex_lock();
@@ -244,5 +256,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4iCount);
 
     wined3d_mutex_lock();
@@ -256,5 +270,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, BoolCount);
 
     wined3d_mutex_lock();
@@ -268,5 +284,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, BoolCount);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/query.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/query.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/query.c	(revision 25949)
@@ -38,5 +38,6 @@
 static HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(LPDIRECT3DQUERY9 iface, REFIID riid, LPVOID* ppobj) {
     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
 
     if (IsEqualGUID(riid, &IID_IUnknown)
@@ -56,5 +57,6 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
+
     return ref;
 }
@@ -64,5 +66,5 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
@@ -78,64 +80,63 @@
 
 /* IDirect3DQuery9 Interface follow: */
-static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(LPDIRECT3DQUERY9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
-    IWineD3DDevice* pDevice;
+static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(IDirect3DQuery9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
+}
+
+static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
+    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
-    if(hr != D3D_OK){
-        *ppDevice = NULL;
-    }else{
-        hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(pDevice);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
-static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
+    TRACE("iface %p.\n", iface);
+
+    wined3d_mutex_lock();
+    hr = IWineD3DQuery_GetType(This->wineD3DQuery);
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
+    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
+    DWORD ret;
+
+    TRACE("iface %p.\n", iface);
+
+    wined3d_mutex_lock();
+    ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
+    wined3d_mutex_unlock();
+
+    return ret;
+}
+
+static HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DQuery_GetType(This->wineD3DQuery);
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
-static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
-    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
-    DWORD ret;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
-    wined3d_mutex_unlock();
-
-    return ret;
-}
-
-static HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
+
+    TRACE("iface %p, flags %#x.\n", iface, dwIssueFlags);
+
+    wined3d_mutex_lock();
+    hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
-    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, data %p, size %u, flags %#x.\n",
+            iface, pData, dwSize, dwGetDataFlags);
 
     wined3d_mutex_lock();
@@ -166,5 +167,5 @@
     HRESULT hr = D3D_OK;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, type %#x, query %p.\n", iface, Type, ppQuery);
 
     if (!ppQuery)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c	(revision 25949)
@@ -39,4 +39,6 @@
     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
@@ -55,5 +57,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     return ref;
@@ -64,5 +66,5 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
@@ -78,17 +80,26 @@
 
 /* IDirect3DStateBlock9 Interface follow: */
-static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(LPDIRECT3DSTATEBLOCK9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
+static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
+    IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
+    HRESULT hr;
+
+    TRACE("iface %p.\n", iface);
+
+    wined3d_mutex_lock();
+    hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
     wined3d_mutex_unlock();
 
@@ -96,20 +107,9 @@
 }
 
-static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
-    IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
-    wined3d_mutex_unlock();
-
-    return hr;
-}
-
 static HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface) {
     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -140,5 +140,5 @@
    HRESULT hrc = D3D_OK;
 
-   TRACE("(%p) Relay\n", This);
+   TRACE("iface %p, type %#x, stateblock %p.\n", iface, Type, ppStateBlock);
 
    if(Type != D3DSBT_ALL         && Type != D3DSBT_PIXELSTATE &&
@@ -174,5 +174,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -190,5 +191,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, stateblock %p.\n", iface, ppSB);
 
     /* Tell wineD3D to endstateblock before anything else (in case we run out
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
@@ -54,5 +56,5 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -63,4 +65,7 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedIncrement(&This->ref);
+
+        TRACE("%p increasing refcount to %u.\n", iface, ref);
+
         if (ref == 1)
         {
@@ -70,5 +75,4 @@
             wined3d_mutex_unlock();
         }
-        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
         return ref;
@@ -80,5 +84,5 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -89,11 +93,16 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedDecrement(&This->ref);
-        TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+
+        TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
         if (ref == 0) {
-            if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
+            IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
             wined3d_mutex_lock();
             IWineD3DSurface_Release(This->wineD3DSurface);
             wined3d_mutex_unlock();
+
+            /* Release the device last, as it may cause the device to be destroyed. */
+            if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice);
         }
 
@@ -103,20 +112,33 @@
 
 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
-static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p)->(%p)\n", This, ppDevice);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    if (This->forwardReference)
+    {
+        IDirect3DResource9 *resource;
+        HRESULT hr;
+
+        hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
+        if (SUCCEEDED(hr))
+        {
+            hr = IDirect3DResource9_GetDevice(resource, device);
+            IDirect3DResource9_Release(resource);
+
+            TRACE("Returning device %p.\n", *device);
+        }
+
+        return hr;
+    }
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -124,5 +146,7 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -136,5 +160,7 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -148,5 +174,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -160,5 +187,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -172,5 +200,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -183,5 +212,6 @@
 static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -193,5 +223,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     D3DRESOURCETYPE ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -207,5 +238,5 @@
     HRESULT res;
 
-    TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
+    TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
 
     if (!This->container) return E_NOINTERFACE;
@@ -226,5 +257,6 @@
     WINED3DSURFACE_DESC wined3ddesc;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
@@ -250,8 +282,8 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
+
+    TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags);
+
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
     wined3d_mutex_unlock();
@@ -263,5 +295,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -279,5 +312,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, hdc %p.\n", iface, phdc);
 
     if(!This->getdc_supported)
@@ -298,5 +332,6 @@
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, hdc %p.\n", iface, hdc);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c	(revision 25949)
@@ -40,4 +40,6 @@
     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
@@ -56,5 +58,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
@@ -67,8 +69,9 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         if (!This->isImplicit) {
             wined3d_mutex_lock();
@@ -78,4 +81,7 @@
             HeapFree(GetProcessHeap(), 0, This);
         }
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -83,9 +89,10 @@
 
 /* IDirect3DSwapChain9 parts follow: */
-static HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
-    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
+static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
+    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
+    HRESULT hr;
+
+    TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x.\n",
+            iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
 
     wined3d_mutex_lock();
@@ -99,5 +106,6 @@
     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, surface %p.\n", iface, pDestSurface);
 
     wined3d_mutex_lock();
@@ -113,5 +121,6 @@
     IWineD3DSurface *mySurface = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
+            iface, iBackBuffer, Type, ppBackBuffer);
 
     wined3d_mutex_lock();
@@ -130,5 +139,6 @@
     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
 
     wined3d_mutex_lock();
@@ -142,5 +152,6 @@
     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, mode %p.\n", iface, pMode);
 
     wined3d_mutex_lock();
@@ -153,20 +164,16 @@
 }
 
-static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
-    HRESULT hrc = D3D_OK;
-    IWineD3DDevice *device = NULL;
-
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
-    if (hrc == D3D_OK && NULL != device) {
-       IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
-       IWineD3DDevice_Release(device);
-    }
-    wined3d_mutex_unlock();
-
-    return hrc;
+static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(IDirect3DSwapChain9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -176,5 +183,5 @@
     HRESULT hr;
 
-    TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
+    TRACE("iface %p, parameters %p.\n", iface, pPresentationParameters);
 
     wined3d_mutex_lock();
@@ -215,83 +222,68 @@
 };
 
-
-/* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
-HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    IDirect3DSwapChain9Impl* object;
-    HRESULT hrc = D3D_OK;
-    WINED3DPRESENT_PARAMETERS localParameters;
-
-    TRACE("(%p) Relay\n", This);
-
-    object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-    object->ref = 1;
-    object->lpVtbl = &Direct3DSwapChain9_Vtbl;
-
-    /* The back buffer count is set to one if it's 0 */
-    if(pPresentationParameters->BackBufferCount == 0) {
-        pPresentationParameters->BackBufferCount = 1;
-    }
-
-    /* Allocate an associated WineD3DDevice object */
-    localParameters.BackBufferWidth                     = pPresentationParameters->BackBufferWidth;
-    localParameters.BackBufferHeight                    = pPresentationParameters->BackBufferHeight;
-    localParameters.BackBufferFormat                    = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
-    localParameters.BackBufferCount                     = pPresentationParameters->BackBufferCount;
-    localParameters.MultiSampleType                     = pPresentationParameters->MultiSampleType;
-    localParameters.MultiSampleQuality                  = pPresentationParameters->MultiSampleQuality;
-    localParameters.SwapEffect                          = pPresentationParameters->SwapEffect;
-    localParameters.hDeviceWindow                       = pPresentationParameters->hDeviceWindow;
-    localParameters.Windowed                            = pPresentationParameters->Windowed;
-    localParameters.EnableAutoDepthStencil              = pPresentationParameters->EnableAutoDepthStencil;
-    localParameters.AutoDepthStencilFormat              = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
-    localParameters.Flags                               = pPresentationParameters->Flags;
-    localParameters.FullScreen_RefreshRateInHz          = pPresentationParameters->FullScreen_RefreshRateInHz;
-    localParameters.PresentationInterval                = pPresentationParameters->PresentationInterval;
-    localParameters.AutoRestoreDisplayMode              = TRUE;
-
-    wined3d_mutex_lock();
-    hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
-            &object->wineD3DSwapChain, (IUnknown*)object, SURFACE_OPENGL);
-    wined3d_mutex_unlock();
-
-    pPresentationParameters->BackBufferWidth            = localParameters.BackBufferWidth;
-    pPresentationParameters->BackBufferHeight           = localParameters.BackBufferHeight;
-    pPresentationParameters->BackBufferFormat           = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
-    pPresentationParameters->BackBufferCount            = localParameters.BackBufferCount;
-    pPresentationParameters->MultiSampleType            = localParameters.MultiSampleType;
-    pPresentationParameters->MultiSampleQuality         = localParameters.MultiSampleQuality;
-    pPresentationParameters->SwapEffect                 = localParameters.SwapEffect;
-    pPresentationParameters->hDeviceWindow              = localParameters.hDeviceWindow;
-    pPresentationParameters->Windowed                   = localParameters.Windowed;
-    pPresentationParameters->EnableAutoDepthStencil     = localParameters.EnableAutoDepthStencil;
-    pPresentationParameters->AutoDepthStencilFormat     = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
-    pPresentationParameters->Flags                      = localParameters.Flags;
-    pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
-    pPresentationParameters->PresentationInterval       = localParameters.PresentationInterval;
-
-    if (hrc != D3D_OK) {
-        FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
-        HeapFree(GetProcessHeap(), 0 , object);
-    } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        *pSwapChain = (IDirect3DSwapChain9 *)object;
-        TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
-    }
-    TRACE("(%p) returning %p\n", This, *pSwapChain);
-    return hrc;
-}
-
-HRESULT  WINAPI  IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
+HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
+        D3DPRESENT_PARAMETERS *present_parameters)
+{
+    WINED3DPRESENT_PARAMETERS wined3d_parameters;
+    HRESULT hr;
+
+    swapchain->ref = 1;
+    swapchain->lpVtbl = &Direct3DSwapChain9_Vtbl;
+
+    wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
+    wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
+    wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
+    wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount);
+    wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType;
+    wined3d_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
+    wined3d_parameters.SwapEffect = present_parameters->SwapEffect;
+    wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
+    wined3d_parameters.Windowed = present_parameters->Windowed;
+    wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
+    wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
+    wined3d_parameters.Flags = present_parameters->Flags;
+    wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
+    wined3d_parameters.PresentationInterval = present_parameters->PresentationInterval;
+    wined3d_parameters.AutoRestoreDisplayMode = TRUE;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateSwapChain(device->WineD3DDevice, &wined3d_parameters,
+            &swapchain->wineD3DSwapChain, (IUnknown *)swapchain, SURFACE_OPENGL);
+    wined3d_mutex_unlock();
+
+    present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
+    present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
+    present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
+    present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
+    present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
+    present_parameters->MultiSampleQuality = wined3d_parameters.MultiSampleQuality;
+    present_parameters->SwapEffect = wined3d_parameters.SwapEffect;
+    present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
+    present_parameters->Windowed = wined3d_parameters.Windowed;
+    present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
+    present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
+    present_parameters->Flags = wined3d_parameters.Flags;
+    present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
+    present_parameters->PresentationInterval = wined3d_parameters.PresentationInterval;
+
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
+        return hr;
+    }
+
+    swapchain->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(swapchain->parentDevice);
+
+    return D3D_OK;
+}
+
+HRESULT  WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hrc = D3D_OK;
     IWineD3DSwapChain *swapchain = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, swapchain_idx %u, swapchain %p.\n",
+            iface, iSwapChain, pSwapChain);
 
     wined3d_mutex_lock();
@@ -311,5 +303,6 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     UINT ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 25949)
@@ -39,4 +39,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
@@ -57,5 +59,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -74,11 +76,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DTexture_Release(This->wineD3DTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -86,20 +92,16 @@
 
 /* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
-static HRESULT WINAPI IDirect3DTexture9Impl_GetDevice(LPDIRECT3DTEXTURE9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DTexture9Impl_GetDevice(IDirect3DTexture9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -107,5 +109,7 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -119,5 +123,7 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -131,5 +137,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -143,5 +150,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -155,5 +163,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -166,5 +175,6 @@
 static void WINAPI IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface) {
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -176,5 +186,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -189,5 +200,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, lod %u.\n", iface, LODNew);
 
     wined3d_mutex_lock();
@@ -201,5 +213,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -213,5 +226,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     DWORD ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -225,5 +239,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
 
     wined3d_mutex_lock();
@@ -237,5 +252,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     D3DTEXTUREFILTERTYPE ret;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -248,5 +264,6 @@
 static void WINAPI IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) {
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -261,5 +278,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
 
     wined3d_mutex_lock();
@@ -287,5 +304,5 @@
     IWineD3DSurface *mySurface = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
 
     wined3d_mutex_lock();
@@ -303,5 +320,7 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
+            iface, Level, pLockedRect, pRect, Flags);
 
     wined3d_mutex_lock();
@@ -315,5 +334,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, level %u.\n", iface, Level);
 
     wined3d_mutex_lock();
@@ -327,5 +347,6 @@
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/version.rc
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/version.rc	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/version.rc	(revision 25949)
@@ -26,22 +26,4 @@
  */
 
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
 #define WINE_FILEDESCRIPTION_STR "Wine Direct3D"
 #define WINE_FILENAME_STR "d3d9.dll"
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c	(revision 25949)
@@ -39,4 +39,6 @@
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
@@ -56,5 +58,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -73,11 +75,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -85,20 +91,16 @@
 
 /* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
-static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -107,5 +109,6 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -119,5 +122,7 @@
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -131,5 +136,6 @@
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -143,5 +149,6 @@
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -155,5 +162,6 @@
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -166,5 +174,6 @@
 static void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -173,7 +182,7 @@
 }
 
-static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface) {
-    IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
-    TRACE("(%p)\n", This);
+static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(IDirect3DVertexBuffer9 *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     return D3DRTYPE_VERTEXBUFFER;
@@ -184,5 +193,7 @@
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
+            iface, OffsetToLock, SizeToLock, ppbData, Flags);
 
     wined3d_mutex_lock();
@@ -196,5 +207,6 @@
     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -209,5 +221,6 @@
     HRESULT hr;
     WINED3DBUFFER_DESC desc;
-    TRACE("(%p) Relay\n", This);
+
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
@@ -270,5 +283,5 @@
     wined3d_mutex_lock();
     hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
-            usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
+            usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
             (IUnknown *)buffer, &d3d9_vertexbuffer_wined3d_parent_ops);
     wined3d_mutex_unlock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexdeclaration.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexdeclaration.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexdeclaration.c	(revision 25949)
@@ -207,4 +207,6 @@
     IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVertexDeclaration9)) {
@@ -223,5 +225,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if(ref == 1) {
@@ -255,11 +257,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         if(!This->convFVF) {
             IDirect3DVertexDeclaration9Impl_Destroy(iface);
         }
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -267,20 +273,17 @@
 
 /* IDirect3DVertexDeclaration9 Interface follow: */
-static HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDevice(LPDIRECT3DVERTEXDECLARATION9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
-    IWineD3DDevice *myDevice = NULL;
-    HRESULT hr = D3D_OK;
-
-    TRACE("(%p) : Relay\n", iface);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DVertexDeclaration_GetDevice(This->wineD3DVertexDeclaration, &myDevice);
-    if (hr == D3D_OK && myDevice != NULL) {
-        hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(myDevice);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDevice(IDirect3DVertexDeclaration9 *iface,
+        IDirect3DDevice9 **device)
+{
+    IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -288,5 +291,5 @@
     IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface;
 
-    TRACE("(%p) : pDecl %p, pNumElements %p)\n", This, pDecl, pNumElements);
+    TRACE("iface %p, elements %p, element_count %p.\n", iface, pDecl, pNumElements);
 
     *pNumElements = This->element_count;
@@ -409,4 +412,5 @@
     if (FAILED(hr))
     {
+        HeapFree(GetProcessHeap(), 0, declaration->elements);
         WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
         return hr;
@@ -424,5 +428,5 @@
     HRESULT hr = D3D_OK;
 
-    TRACE("(%p) : Relay\n", iface);
+    TRACE("iface %p, vertex declaration %p.\n", iface, pDecl);
 
     wined3d_mutex_lock();
@@ -438,5 +442,5 @@
     HRESULT hr = D3D_OK;
 
-    TRACE("(%p) : Relay+\n", iface);
+    TRACE("iface %p, declaration %p.\n", iface, ppDecl);
 
     if (NULL == ppDecl) {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
@@ -54,5 +56,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -71,11 +73,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DVertexShader_Release(This->wineD3DVertexShader);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -83,22 +89,16 @@
 
 /* IDirect3DVertexShader9 Interface follow: */
-static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
-    IWineD3DDevice *myDevice = NULL;
-    HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
-    if (WINED3D_OK == hr && myDevice != NULL) {
-        hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(myDevice);
-    } else {
-        *ppDevice = NULL;
-    }
-    wined3d_mutex_unlock();
-
-    TRACE("(%p) returning (%p)\n", This, *ppDevice);
-    return hr;
+static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -106,5 +106,6 @@
     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, data %p, data_size %p.\n", iface, pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -165,5 +166,5 @@
     HRESULT hrc = D3D_OK;
 
-    TRACE("(%p) : Relay\n", This);
+    TRACE("iface %p, shader %p.\n", iface, pShader);
 
     wined3d_mutex_lock();
@@ -180,5 +181,5 @@
     HRESULT hrc = D3D_OK;
 
-    TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
+    TRACE("iface %p, shader %p.\n", iface, ppShader);
 
     wined3d_mutex_lock();
@@ -209,5 +210,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4fCount);
 
     if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
@@ -228,4 +231,7 @@
     HRESULT hr;
 
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4fCount);
+
     if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
         WARN("Trying to access %u constants, but d3d9 only supports %u\n",
@@ -234,6 +240,4 @@
     }
 
-    TRACE("(%p) : Relay\n", This);
-
     wined3d_mutex_lock();
     hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
@@ -246,5 +250,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4iCount);
 
     wined3d_mutex_lock();
@@ -258,5 +264,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, Vector4iCount);
 
     wined3d_mutex_lock();
@@ -270,5 +278,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, BoolCount);
 
     wined3d_mutex_lock();
@@ -282,5 +292,7 @@
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) : Relay\n", This);
+
+    TRACE("iface %p, register %u, data %p, count %u.\n",
+            iface, Register, pConstantData, BoolCount);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
@@ -53,5 +55,5 @@
     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -62,5 +64,6 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedIncrement(&This->ref);
-        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+
+        TRACE("%p increasing refcount to %u.\n", iface, ref);
 
         if (ref == 1)
@@ -78,5 +81,5 @@
     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
     if (This->forwardReference) {
@@ -87,5 +90,6 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedDecrement(&This->ref);
-        TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+
+        TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
         if (ref == 0) {
@@ -100,19 +104,22 @@
 
 /* IDirect3DVolume9 Interface follow: */
-static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
-    IWineD3DDevice       *myDevice = NULL;
-
-    TRACE("iface %p, ppDevice %p\n", iface, ppDevice);
-
-    wined3d_mutex_lock();
-
-    IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
-    IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
-    IWineD3DDevice_Release(myDevice);
-
-    wined3d_mutex_unlock();
-
-    return D3D_OK;
+static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(IDirect3DVolume9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
+    IDirect3DResource9 *resource;
+    HRESULT hr;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
+    if (SUCCEEDED(hr))
+    {
+        hr = IDirect3DResource9_GetDevice(resource, device);
+        IDirect3DResource9_Release(resource);
+
+        TRACE("Returning device %p.\n", *device);
+    }
+
+    return hr;
 }
 
@@ -121,5 +128,6 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -136,5 +144,6 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -151,5 +160,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -166,5 +175,5 @@
     HRESULT res;
 
-    TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
+    TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
 
     if (!This->container) return E_NOINTERFACE;
@@ -186,5 +195,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, desc %p.\n", iface, pDesc);
 
     wined3d_mutex_lock();
@@ -212,5 +221,6 @@
     HRESULT hr;
 
-    TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
+    TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
+            iface, pLockedVolume, pBox, Flags);
 
     wined3d_mutex_lock();
@@ -228,5 +238,5 @@
     HRESULT hr;
 
-    TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c	(revision 25949)
@@ -38,4 +38,6 @@
     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
 
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
     if (IsEqualGUID(riid, &IID_IUnknown)
     || IsEqualGUID(riid, &IID_IDirect3DResource9)
@@ -56,5 +58,5 @@
     ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+    TRACE("%p increasing refcount to %u.\n", iface, ref);
 
     if (ref == 1)
@@ -73,11 +75,15 @@
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
     if (ref == 0) {
-        IDirect3DDevice9Ex_Release(This->parentDevice);
+        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
         wined3d_mutex_lock();
         IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
         wined3d_mutex_unlock();
+
+        /* Release the device last, as it may cause the device to be destroyed. */
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
@@ -85,21 +91,16 @@
 
 /* IDirect3DVolumeTexture9 IDirect3DResource9 Interface follow: */
-static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
-    IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
-    IWineD3DDevice *wined3d_device;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    wined3d_mutex_lock();
-    hr = IWineD3DStateBlock_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
-    if (SUCCEEDED(hr))
-    {
-        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
-        IWineD3DDevice_Release(wined3d_device);
-    }
-    wined3d_mutex_unlock();
-
-    return hr;
+static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetDevice(IDirect3DVolumeTexture9 *iface, IDirect3DDevice9 **device)
+{
+    IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
+
+    TRACE("iface %p, device %p.\n", iface, device);
+
+    *device = (IDirect3DDevice9 *)This->parentDevice;
+    IDirect3DDevice9_AddRef(*device);
+
+    TRACE("Returning device %p.\n", *device);
+
+    return D3D_OK;
 }
 
@@ -108,5 +109,6 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
+            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
@@ -123,5 +125,6 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
+            iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
@@ -138,5 +141,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
@@ -153,5 +156,5 @@
     DWORD priority;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, priority %u.\n", iface, PriorityNew);
 
     wined3d_mutex_lock();
@@ -168,5 +171,5 @@
     DWORD priority;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -182,5 +185,5 @@
     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -195,5 +198,5 @@
     D3DRESOURCETYPE type;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -211,5 +214,5 @@
     DWORD lod;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, lod %u.\n", iface, LODNew);
 
     wined3d_mutex_lock();
@@ -226,5 +229,5 @@
     DWORD lod;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -241,5 +244,5 @@
     DWORD level_count;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -256,5 +259,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
 
     wined3d_mutex_lock();
@@ -271,5 +274,5 @@
     D3DTEXTUREFILTERTYPE filter_type;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -285,5 +288,5 @@
     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
@@ -300,5 +303,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
 
     wined3d_mutex_lock();
@@ -327,5 +330,5 @@
     IWineD3DVolume *myVolume = NULL;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, level %u, volume %p.\n", iface, Level, ppVolumeLevel);
 
     wined3d_mutex_lock();
@@ -346,5 +349,6 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
+    TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
+            iface, Level, pLockedVolume, pBox, Flags);
 
     wined3d_mutex_lock();
@@ -362,5 +366,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
+    TRACE("iface %p, level %u.\n", iface, Level);
 
     wined3d_mutex_lock();
@@ -377,5 +381,5 @@
     HRESULT hr;
 
-    TRACE("(%p) Relay\n", This);
+    TRACE("iface %p, dirty_box %p.\n", iface, pDirtyBox);
 
     wined3d_mutex_lock();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/basetsd.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/basetsd.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/basetsd.h	(revision 25949)
@@ -112,7 +112,17 @@
 #endif
 
-/* Win32 or Win64 dependent typedef/defines. */
-
-#ifdef _WIN64
+/* Basic pointer-sized integer types */
+
+#if defined(__midl) || defined(__WIDL__)
+
+typedef /* [public] */ signed __int3264   INT_PTR, *PINT_PTR;
+typedef /* [public] */ signed __int3264   LONG_PTR, *PLONG_PTR;
+typedef /* [public] */ unsigned __int3264 UINT_PTR, *PUINT_PTR;
+typedef /* [public] */ unsigned __int3264 ULONG_PTR, *PULONG_PTR;
+typedef ULONG_PTR                   DWORD_PTR, *PDWORD_PTR;
+
+#elif defined(_WIN64)
+
+#define __int3264 __int64
 
 typedef signed __int64   INT_PTR, *PINT_PTR;
@@ -120,5 +130,21 @@
 typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
 typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
-typedef unsigned __int64 DWORD_PTR, *PDWORD_PTR;
+typedef ULONG_PTR        DWORD_PTR, *PDWORD_PTR;
+
+#else
+
+#define __int3264 __int32
+
+typedef long          INT_PTR, *PINT_PTR;
+typedef unsigned long UINT_PTR, *PUINT_PTR;
+typedef long          LONG_PTR, *PLONG_PTR;
+typedef unsigned long ULONG_PTR, *PULONG_PTR;
+typedef ULONG_PTR     DWORD_PTR, *PDWORD_PTR;
+
+#endif
+
+/* Win32 or Win64 dependent typedef/defines. */
+
+#ifdef _WIN64
 
 #define MAXINT_PTR 0x7fffffffffffffff
@@ -210,10 +236,4 @@
 
 #else /* FIXME: defined(_WIN32) */
-
-typedef long INT_PTR, *PINT_PTR;
-typedef unsigned long UINT_PTR, *PUINT_PTR;
-typedef long LONG_PTR, *PLONG_PTR;
-typedef unsigned long ULONG_PTR, *PULONG_PTR;
-typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
 
 #define MAXINT_PTR 0x7fffffff
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/cfgmgr32.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/cfgmgr32.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/cfgmgr32.h	(revision 25949)
@@ -107,4 +107,7 @@
 #define NUM_CR_RESULTS                  0x3c
 
+#define MAX_DEVICE_ID_LEN               200
+#define MAX_DEVNODE_ID_LEN              MAX_DEVICE_ID_LEN
+
 #define MAX_CLASS_NAME_LEN              32
 #define MAX_GUID_STRING_LEN             39
@@ -134,4 +137,7 @@
 CMAPI CONFIGRET WINAPI CM_Get_Device_IDW(DEVINST,PWSTR,ULONG,ULONG);
 #define     CM_Get_Device_ID WINELIB_NAME_AW(CM_Get_Device_ID)
+CMAPI CONFIGRET WINAPI CM_Get_Device_ID_ExA(DEVINST,PSTR,ULONG,ULONG,HMACHINE);
+CMAPI CONFIGRET WINAPI CM_Get_Device_ID_ExW(DEVINST,PWSTR,ULONG,ULONG,HMACHINE);
+#define     CM_Get_Device_ID_Ex WINELIB_NAME_AW(CM_Get_Device_ID_Ex)
 CMAPI CONFIGRET WINAPI CM_Get_Device_ID_ListA(PCSTR,PCHAR,ULONG,ULONG);
 CMAPI CONFIGRET WINAPI CM_Get_Device_ID_ListW(PCWSTR,PWCHAR,ULONG,ULONG);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.h	(revision 25949)
@@ -1783,4 +1783,8 @@
 #define TTTOOLINFOW_V1_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lpszText)
 #define TTTOOLINFO_V1_SIZE  CCSIZEOF_STRUCT(WINELIB_NAME_AW(TTTOOLINFO), lpszText)
+#define TTTOOLINFOA_V2_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lParam)
+#define TTTOOLINFOW_V2_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lParam)
+#define TTTOOLINFOA_V3_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lpReserved)
+#define TTTOOLINFOW_V3_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lpReserved)
 
 typedef struct _TT_HITTESTINFOA
@@ -3019,4 +3023,5 @@
 #define LVSIL_SMALL             1
 #define LVSIL_STATE             2
+#define LVSIL_GROUPHEADER       3
 
 /* following 2 flags only for LVS_OWNERDATA listviews */
@@ -3026,9 +3031,10 @@
 
 
-#define LVFI_PARAM              0X0001
-#define LVFI_STRING             0X0002
-#define LVFI_PARTIAL            0X0008
-#define LVFI_WRAP               0X0020
-#define LVFI_NEARESTXY          0X0040
+#define LVFI_PARAM              0x0001
+#define LVFI_STRING             0x0002
+#define LVFI_SUBSTRING          0x0004
+#define LVFI_PARTIAL            0x0008
+#define LVFI_WRAP               0x0020
+#define LVFI_NEARESTXY          0x0040
 
 #define LVIF_TEXT               0x0001
@@ -4270,7 +4276,8 @@
 #define TCN_LAST                (0U-580U)
 #define TCN_KEYDOWN             (TCN_FIRST - 0)
-#define TCN_SELCHANGE		(TCN_FIRST - 1)
+#define TCN_SELCHANGE           (TCN_FIRST - 1)
 #define TCN_SELCHANGING         (TCN_FIRST - 2)
 #define TCN_GETOBJECT           (TCN_FIRST - 3)
+#define TCN_FOCUSCHANGE         (TCN_FIRST - 4)
 
 #include <pshpack1.h>
@@ -4675,4 +4682,5 @@
 #define MCS_NOTODAY            0x0010
 #define MCS_NOTODAYCIRCLE      0x0008
+#define MCS_NOTRAILINGDATES    0x0040
 
 #define MCHT_TITLE             0x00010000
@@ -4710,5 +4718,12 @@
         UINT uHit;
         SYSTEMTIME st;
+        /* Vista */
+        RECT rc;
+        INT iOffset;
+        INT iRow;
+        INT iCol;
 } MCHITTESTINFO, *PMCHITTESTINFO;
+
+#define MCHITTESTINFO_V1_SIZE CCSIZEOF_STRUCT(MCHITTESTINFO, st)
 
 typedef struct tagNMSELCHANGE
@@ -4734,49 +4749,49 @@
 
 #define MonthCal_GetCurSel(hmc, pst) \
-		(BOOL)SNDMSGA(hmc, MCM_GETCURSEL, 0, (LPARAM)(pst))
+		(BOOL)SNDMSG(hmc, MCM_GETCURSEL, 0, (LPARAM)(pst))
 #define MonthCal_SetCurSel(hmc, pst)  \
-		(BOOL)SNDMSGA(hmc, MCM_SETCURSEL, 0, (LPARAM)(pst))
+		(BOOL)SNDMSG(hmc, MCM_SETCURSEL, 0, (LPARAM)(pst))
 #define MonthCal_GetMaxSelCount(hmc) \
-		(DWORD)SNDMSGA(hmc, MCM_GETMAXSELCOUNT, 0, 0L)
+		(DWORD)SNDMSG(hmc, MCM_GETMAXSELCOUNT, 0, 0L)
 #define MonthCal_SetMaxSelCount(hmc, n) \
-		(BOOL)SNDMSGA(hmc, MCM_SETMAXSELCOUNT, (WPARAM)(n), 0L)
+		(BOOL)SNDMSG(hmc, MCM_SETMAXSELCOUNT, (WPARAM)(n), 0L)
 #define MonthCal_GetSelRange(hmc, rgst) \
-		SNDMSGA(hmc, MCM_GETSELRANGE, 0, (LPARAM) (rgst))
+		SNDMSG(hmc, MCM_GETSELRANGE, 0, (LPARAM) (rgst))
 #define MonthCal_SetSelRange(hmc, rgst) \
-		SNDMSGA(hmc, MCM_SETSELRANGE, 0, (LPARAM) (rgst))
+		SNDMSG(hmc, MCM_SETSELRANGE, 0, (LPARAM) (rgst))
 #define MonthCal_GetMonthRange(hmc, gmr, rgst) \
-		(DWORD)SNDMSGA(hmc, MCM_GETMONTHRANGE, (WPARAM)(gmr), (LPARAM)(rgst))
+		(DWORD)SNDMSG(hmc, MCM_GETMONTHRANGE, (WPARAM)(gmr), (LPARAM)(rgst))
 #define MonthCal_SetDayState(hmc, cbds, rgds) \
-		SNDMSGA(hmc, MCM_SETDAYSTATE, (WPARAM)(cbds), (LPARAM)(rgds))
+		SNDMSG(hmc, MCM_SETDAYSTATE, (WPARAM)(cbds), (LPARAM)(rgds))
 #define MonthCal_GetMinReqRect(hmc, prc) \
-		SNDMSGA(hmc, MCM_GETMINREQRECT, 0, (LPARAM)(prc))
+		SNDMSG(hmc, MCM_GETMINREQRECT, 0, (LPARAM)(prc))
 #define MonthCal_SetColor(hmc, iColor, clr)\
-        SNDMSGA(hmc, MCM_SETCOLOR, iColor, clr)
+        SNDMSG(hmc, MCM_SETCOLOR, iColor, clr)
 #define MonthCal_GetColor(hmc, iColor) \
-		SNDMSGA(hmc, MCM_SETCOLOR, iColor, 0)
+		SNDMSG(hmc, MCM_SETCOLOR, iColor, 0)
 #define MonthCal_GetToday(hmc, pst)\
-		(BOOL)SNDMSGA(hmc, MCM_GETTODAY, 0, (LPARAM)pst)
+		(BOOL)SNDMSG(hmc, MCM_GETTODAY, 0, (LPARAM)pst)
 #define MonthCal_SetToday(hmc, pst)\
-		SNDMSGA(hmc, MCM_SETTODAY, 0, (LPARAM)pst)
+		SNDMSG(hmc, MCM_SETTODAY, 0, (LPARAM)pst)
 #define MonthCal_HitTest(hmc, pinfo) \
-        SNDMSGA(hmc, MCM_HITTEST, 0, (LPARAM)(PMCHITTESTINFO)pinfo)
+        SNDMSG(hmc, MCM_HITTEST, 0, (LPARAM)(PMCHITTESTINFO)pinfo)
 #define MonthCal_SetFirstDayOfWeek(hmc, iDay) \
-        SNDMSGA(hmc, MCM_SETFIRSTDAYOFWEEK, 0, iDay)
+        SNDMSG(hmc, MCM_SETFIRSTDAYOFWEEK, 0, iDay)
 #define MonthCal_GetFirstDayOfWeek(hmc) \
-        (DWORD)SNDMSGA(hmc, MCM_GETFIRSTDAYOFWEEK, 0, 0)
+        (DWORD)SNDMSG(hmc, MCM_GETFIRSTDAYOFWEEK, 0, 0)
 #define MonthCal_GetRange(hmc, rgst) \
-        (DWORD)SNDMSGA(hmc, MCM_GETRANGE, 0, (LPARAM)(rgst))
+        (DWORD)SNDMSG(hmc, MCM_GETRANGE, 0, (LPARAM)(rgst))
 #define MonthCal_SetRange(hmc, gd, rgst) \
-        (BOOL)SNDMSGA(hmc, MCM_SETRANGE, (WPARAM)(gd), (LPARAM)(rgst))
+        (BOOL)SNDMSG(hmc, MCM_SETRANGE, (WPARAM)(gd), (LPARAM)(rgst))
 #define MonthCal_GetMonthDelta(hmc) \
-        (int)SNDMSGA(hmc, MCM_GETMONTHDELTA, 0, 0)
+        (int)SNDMSG(hmc, MCM_GETMONTHDELTA, 0, 0)
 #define MonthCal_SetMonthDelta(hmc, n) \
-        (int)SNDMSGA(hmc, MCM_SETMONTHDELTA, n, 0)
+        (int)SNDMSG(hmc, MCM_SETMONTHDELTA, n, 0)
 #define MonthCal_GetMaxTodayWidth(hmc) \
-        (DWORD)SNDMSGA(hmc, MCM_GETMAXTODAYWIDTH, 0, 0)
+        (DWORD)SNDMSG(hmc, MCM_GETMAXTODAYWIDTH, 0, 0)
 #define MonthCal_SetUnicodeFormat(hwnd, fUnicode)  \
-        (BOOL)SNDMSGA((hwnd), MCM_SETUNICODEFORMAT, (WPARAM)(fUnicode), 0)
+        (BOOL)SNDMSG((hwnd), MCM_SETUNICODEFORMAT, (WPARAM)(fUnicode), 0)
 #define MonthCal_GetUnicodeFormat(hwnd)  \
-        (BOOL)SNDMSGA((hwnd), MCM_GETUNICODEFORMAT, 0, 0)
+        (BOOL)SNDMSG((hwnd), MCM_GETUNICODEFORMAT, 0, 0)
 
 
@@ -4938,11 +4953,11 @@
 
 #define DateTime_GetSystemtime(hdp, pst)   \
-  (DWORD)SNDMSGA (hdp, DTM_GETSYSTEMTIME , 0, (LPARAM)(pst))
+  (DWORD)SNDMSG (hdp, DTM_GETSYSTEMTIME , 0, (LPARAM)(pst))
 #define DateTime_SetSystemtime(hdp, gd, pst)   \
-  (BOOL)SNDMSGA (hdp, DTM_SETSYSTEMTIME, (LPARAM)(gd), (LPARAM)(pst))
+  (BOOL)SNDMSG (hdp, DTM_SETSYSTEMTIME, (LPARAM)(gd), (LPARAM)(pst))
 #define DateTime_GetRange(hdp, rgst)  \
-  (DWORD)SNDMSGA (hdp, DTM_GETRANGE, 0, (LPARAM)(rgst))
+  (DWORD)SNDMSG (hdp, DTM_GETRANGE, 0, (LPARAM)(rgst))
 #define DateTime_SetRange(hdp, gd, rgst) \
-   (BOOL)SNDMSGA (hdp, DTM_SETRANGE, (WPARAM)(gd), (LPARAM)(rgst))
+   (BOOL)SNDMSG (hdp, DTM_SETRANGE, (WPARAM)(gd), (LPARAM)(rgst))
 #define DateTime_SetFormatA(hdp, sz)  \
   (BOOL)SNDMSGA (hdp, DTM_SETFORMATA, 0, (LPARAM)(sz))
@@ -4951,13 +4966,13 @@
 #define DateTime_SetFormat WINELIB_NAME_AW(DateTime_SetFormat)
 #define DateTime_GetMonthCalColor(hdp, iColor) \
-  SNDMSGA (hdp, DTM_GETMCCOLOR, iColor, 0)
+  SNDMSG (hdp, DTM_GETMCCOLOR, iColor, 0)
 #define DateTime_SetMonthCalColor(hdp, iColor, clr) \
-  SNDMSGA (hdp, DTM_SETMCCOLOR, iColor, clr)
+  SNDMSG (hdp, DTM_SETMCCOLOR, iColor, clr)
 #define DateTime_GetMonthCal(hdp)  \
-  (HWND) SNDMSGA (hdp, DTM_GETMONTHCAL, 0, 0)
+  (HWND) SNDMSG (hdp, DTM_GETMONTHCAL, 0, 0)
 #define DateTime_SetMonthCalFont(hdp, hfont, fRedraw) \
-  SNDMSGA (hdp, DTM_SETMCFONT, (WPARAM)hfont, (LPARAM)fRedraw)
+  SNDMSG (hdp, DTM_SETMCFONT, (WPARAM)hfont, (LPARAM)fRedraw)
 #define DateTime_GetMonthCalFont(hdp) \
-  SNDMSGA (hdp, DTM_GETMCFONT, 0, 0)
+  SNDMSG (hdp, DTM_GETMCFONT, 0, 0)
 
 #define DA_LAST         (0x7fffffff)
@@ -5016,4 +5031,8 @@
 #endif
 
+/* SysLink styles */
+#define LWS_TRANSPARENT      0x0001
+#define LWS_IGNORERETURN     0x0002
+
 /* SysLink messages */
 #define LM_HITTEST           (WM_USER + 768)
@@ -5117,5 +5136,5 @@
 
 /**************************************************************************
- * List box control
+ * Listbox control
  */
 
@@ -5131,5 +5150,5 @@
 
 /**************************************************************************
- * Scroll bar control
+ * Scrollbar control
  */
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.rh
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.rh	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.rh	(revision 25949)
@@ -15,13 +15,4 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
  */
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/config.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/config.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/config.h	(revision 25949)
@@ -4,6 +4,9 @@
 #define __WINE_CONFIG_H
 
-/* Specifies the compiler flag that forces a short wchar_t */
-//#define CC_FLAG_SHORT_WCHAR "-fshort-wchar"
+/* Define to a function attribute for Microsoft hotpatch assembly prefix. */
+#define DECLSPEC_HOTPATCH /* */
+
+/* Define to the file extension for executables. */
+#define EXEEXT ".exe"
 
 /* Define to 1 if you have the <alias.h> header file. */
@@ -16,4 +19,7 @@
 /* #undef HAVE_ALSA_ASOUNDLIB_H */
 
+/* Define to 1 if you have the <AL/al.h> header file. */
+/* #undef HAVE_AL_AL_H */
+
 /* Define to 1 if you have the <arpa/inet.h> header file. */
 #define HAVE_ARPA_INET_H 1
@@ -46,7 +52,4 @@
 /* #undef HAVE_CHSIZE */
 
-/* Define to 1 if you have the `clone' function. */
-/* #undef HAVE_CLONE */
-
 /* Define to 1 if you have the <CoreAudio/CoreAudio.h> header file. */
 /* #undef HAVE_COREAUDIO_COREAUDIO_H */
@@ -59,5 +62,5 @@
 
 /* Define if you have the daylight variable */
-//#define HAVE_DAYLIGHT 1
+/* #undef HAVE_DAYLIGHT*/
 
 /* Define to 1 if you have the <dbus/dbus.h> header file. */
@@ -78,11 +81,11 @@
 
 /* Define to 1 if you have the <dlfcn.h> header file. */
-//#define HAVE_DLFCN_H 1
+/* #undef HAVE_DLFCN_H*/
 
 /* Define to 1 if you have the `dlopen' function. */
-//#define HAVE_DLOPEN 1
+/* #undef HAVE_DLOPEN*/
 
 /* Define to 1 if you have the <elf.h> header file. */
-//#define HAVE_ELF_H 1
+/* #undef HAVE_ELF_H*/
 
 /* Define to 1 if you have the `epoll_create' function. */
@@ -95,4 +98,10 @@
 #define HAVE_FFS 1
 
+/* Define to 1 if you have the `finite' function. */
+#define HAVE_FINITE 1
+
+/* Define to 1 if you have the <float.h> header file. */
+#define HAVE_FLOAT_H 1
+
 /* Define to 1 if you have the `fnmatch' function. */
 #define HAVE_FNMATCH 1
@@ -101,10 +110,4 @@
 #define HAVE_FNMATCH_H 1
 
-/* Define to 1 if you have the `finite' function. */
-#define HAVE_FINITE 1
-
-/* Define to 1 if you have the <float.h> header file. */
-#define HAVE_FLOAT_H 1
-
 /* Define to 1 if you have the <fontconfig/fontconfig.h> header file. */
 /* #undef HAVE_FONTCONFIG_FONTCONFIG_H */
@@ -125,10 +128,10 @@
 /* #undef HAVE_FREETYPE_FTGLYPH_H */
 
+/* Define to 1 if you have the <freetype/ftlcdfil.h> header file. */
+/* #undef HAVE_FREETYPE_FTLCDFIL_H */
+
 /* Define to 1 if you have the <freetype/ftmodapi.h> header file. */
 /* #undef HAVE_FREETYPE_FTMODAPI_H */
 
-/* Define to 1 if you have the <freetype/ftnames.h> header file. */
-/* #undef HAVE_FREETYPE_FTNAMES_H */
-
 /* Define to 1 if you have the <freetype/ftoutln.h> header file. */
 /* #undef HAVE_FREETYPE_FTOUTLN_H */
@@ -204,5 +207,5 @@
 
 /* Define to 1 if you have the `getpagesize' function. */
-//#define HAVE_GETPAGESIZE 1
+/* #undef HAVE_GETPAGESIZE */
 
 /* Define to 1 if you have the `getprotobyname' function. */
@@ -213,5 +216,5 @@
 
 /* Define to 1 if you have the `getpwuid' function. */
-//#define HAVE_GETPWUID 1
+/* #undef HAVE_GETPWUID */
 
 /* Define to 1 if you have the `getservbyport' function. */
@@ -225,8 +228,5 @@
 
 /* Define to 1 if you have the `getuid' function. */
-//#define HAVE_GETUID 1
-
-/* Define to 1 if you have the <GL/glext.h> header file. */
-/* #undef HAVE_GL_GLEXT_H */
+/* #undef HAVE_GETUID */
 
 /* Define to 1 if you have the <GL/glu.h> header file. */
@@ -242,4 +242,13 @@
 /* #undef HAVE_GPHOTO2 */
 
+/* Define to 1 if you have the <grp.h> header file. */
+/* #undef HAVE_GRP_H */
+
+/* Define to 1 if you have the <gsm/gsm.h> header file. */
+/* #undef HAVE_GSM_GSM_H */
+
+/* Define to 1 if you have the <gsm.h> header file. */
+/* #undef HAVE_GSM_H */
+
 /* Define to 1 if you have the <hal/libhal.h> header file. */
 /* #undef HAVE_HAL_LIBHAL_H */
@@ -248,7 +257,13 @@
 #define HAVE_IEEEFP_H 1
 
+/* Define to 1 if you have the <inet/mib2.h> header file. */
+/* #undef HAVE_INET_MIB2_H */
+
 /* Define to 1 if you have the `inet_network' function. */
 #define HAVE_INET_NETWORK 1
 
+/* Define to 1 if you have the `inet_ntop' function. */
+#define HAVE_INET_NTOP 1
+
 /* Define to 1 if you have the `inet_pton' function. */
 #define HAVE_INET_PTON 1
@@ -257,4 +272,10 @@
 #define HAVE_INTTYPES_H 1
 
+/* Define to 1 if you have the `IOHIDManagerCreate' function. */
+/* #undef HAVE_IOHIDMANAGERCREATE */
+
+/* Define to 1 if you have the <IOKit/hid/IOHIDLib.h> header file. */
+/* #undef HAVE_IOKIT_HID_IOHIDLIB_H */
+
 /* Define to 1 if you have the <IOKit/IOKitLib.h> header file. */
 /* #undef HAVE_IOKIT_IOKITLIB_H */
@@ -264,8 +285,8 @@
 
 /* Define to 1 if you have the `isinf' function. */
-#define HAVE_ISINF 1
+/* #undef HAVE_ISINF */
 
 /* Define to 1 if you have the `isnan' function. */
-#define HAVE_ISNAN 1
+/* #undef HAVE_ISNAN */
 
 /* Define to 1 if you have the <jack/jack.h> header file. */
@@ -278,4 +299,7 @@
 /* #undef HAVE_KQUEUE */
 
+/* Define to 1 if you have the <kstat.h> header file. */
+/* #undef HAVE_KSTAT_H */
+
 /* Define to 1 if you have the <lber.h> header file. */
 /* #undef HAVE_LBER_H */
@@ -329,4 +353,7 @@
 /* #undef HAVE_LIBI386 */
 
+/* Define to 1 if you have the `kstat' library (-lkstat). */
+/* #undef HAVE_LIBKSTAT */
+
 /* Define to 1 if you have the `ossaudio' library (-lossaudio). */
 /* #undef HAVE_LIBOSSAUDIO */
@@ -380,4 +407,7 @@
 /* #undef HAVE_LINUX_IPX_H */
 
+/* Define to 1 if you have the <linux/irda.h> header file. */
+/* #undef HAVE_LINUX_IRDA_H */
+
 /* Define to 1 if you have the <linux/joystick.h> header file. */
 /* #undef HAVE_LINUX_JOYSTICK_H */
@@ -392,4 +422,7 @@
 /* #undef HAVE_LINUX_SERIAL_H */
 
+/* Define to 1 if you have the <linux/types.h> header file. */
+/* #undef HAVE_LINUX_TYPES_H */
+
 /* Define to 1 if you have the <linux/ucdrom.h> header file. */
 /* #undef HAVE_LINUX_UCDROM_H */
@@ -419,4 +452,10 @@
 /* #undef HAVE_MACH_MACH_H */
 
+/* Define to 1 if you have the <mach-o/dyld_images.h> header file. */
+/* #undef HAVE_MACH_O_DYLD_IMAGES_H */
+
+/* Define to 1 if you have the <mach-o/nlist.h> header file. */
+/* #undef HAVE_MACH_O_NLIST_H */
+
 /* Define to 1 if you have the `memmove' function. */
 #define HAVE_MEMMOVE 1
@@ -426,5 +465,5 @@
 
 /* Define to 1 if you have the `mmap' function. */
-//#define HAVE_MMAP 1
+/* #undef HAVE_MMAP */
 
 /* Define to 1 if you have the <mntent.h> header file. */
@@ -437,4 +476,7 @@
 /* #undef HAVE_MOUSEMASK */
 
+/* Define to 1 if you have the <mpg123.h> header file. */
+/* #undef HAVE_MPG123_H */
+
 /* Define if you have NAS including devel headers */
 /* #undef HAVE_NAS */
@@ -452,6 +494,9 @@
 /* #undef HAVE_NETINET_IF_ETHER_H */
 
+/* Define to 1 if you have the <netinet/if_inarp.h> header file. */
+/* #undef HAVE_NETINET_IF_INARP_H */
+
 /* Define to 1 if you have the <netinet/in.h> header file. */
-//#define HAVE_NETINET_IN_H 1
+/* #undef HAVE_NETINET_IN_H */
 
 /* Define to 1 if you have the <netinet/in_pcb.h> header file. */
@@ -459,11 +504,11 @@
 
 /* Define to 1 if you have the <netinet/in_systm.h> header file. */
-//#define HAVE_NETINET_IN_SYSTM_H 1
+/* #undef HAVE_NETINET_IN_SYSTM_H */
 
 /* Define to 1 if you have the <netinet/ip.h> header file. */
-//#define HAVE_NETINET_IP_H 1
+/* #undef HAVE_NETINET_IP_H */
 
 /* Define to 1 if you have the <netinet/ip_icmp.h> header file. */
-//#define HAVE_NETINET_IP_ICMP_H 1
+/* #undef HAVE_NETINET_IP_ICMP_H */
 
 /* Define to 1 if you have the <netinet/ip_var.h> header file. */
@@ -474,5 +519,5 @@
 
 /* Define to 1 if you have the <netinet/tcp.h> header file. */
-//#define HAVE_NETINET_TCP_H 1
+/* #undef HAVE_NETINET_TCP_H */
 
 /* Define to 1 if you have the <netinet/tcp_timer.h> header file. */
@@ -483,5 +528,5 @@
 
 /* Define to 1 if you have the <netinet/udp.h> header file. */
-//#define HAVE_NETINET_UDP_H 1
+/* #undef HAVE_NETINET_UDP_H */
 
 /* Define to 1 if you have the <netinet/udp_var.h> header file. */
@@ -498,5 +543,5 @@
 
 /* Define to 1 if you have the <net/if.h> header file. */
-//#define HAVE_NET_IF_H 1
+/* #undef HAVE_NET_IF_H */
 
 /* Define to 1 if you have the <net/if_types.h> header file. */
@@ -506,5 +551,5 @@
 /* #undef HAVE_NET_ROUTE_H */
 
-/* Define to 1 if `_msg_ptr' is member of `ns_msg'. */
+/* Define to 1 if `_msg_ptr' is a member of `ns_msg'. */
 /* #undef HAVE_NS_MSG__MSG_PTR */
 
@@ -512,4 +557,10 @@
 #define HAVE_OFF_T 1
 
+/* Define if mkdir takes only one argument */
+/* #undef HAVE_ONE_ARG_MKDIR */
+
+/* Define to 1 if you have the <OpenAL/al.h> header file. */
+/* #undef HAVE_OPENAL_AL_H */
+
 /* Define if OpenGL is present on the system */
 /* #undef HAVE_OPENGL */
@@ -525,5 +576,8 @@
 
 /* Define to 1 if the system has the type `pid_t'. */
-//#define HAVE_PID_T 1
+/* #undef HAVE_PID_T */
+
+/* Define to 1 if you have the `pipe2' function. */
+/* #undef HAVE_PIPE2 */
 
 /* Define to 1 if you have the <png.h> header file. */
@@ -539,4 +593,10 @@
 #define HAVE_POPEN 1
 
+/* Define to 1 if you have the `port_create' function. */
+/* #undef HAVE_PORT_CREATE */
+
+/* Define to 1 if you have the <port.h> header file. */
+/* #undef HAVE_PORT_H */
+
 /* Define if we can use ppdev.h for parallel port access */
 /* #undef HAVE_PPDEV */
@@ -564,17 +624,11 @@
 
 /* Define to 1 if you have the <pthread.h> header file. */
-//#define HAVE_PTHREAD_H 1
+/* #undef HAVE_PTHREAD_H */
 
 /* Define to 1 if you have the <pthread_np.h> header file. */
 /* #undef HAVE_PTHREAD_NP_H */
 
-/* Define to 1 if the system has the type `pthread_rwlockattr_t'. */
-//#define HAVE_PTHREAD_RWLOCKATTR_T 1
-
-/* Define to 1 if the system has the type `pthread_rwlock_t'. */
-//#define HAVE_PTHREAD_RWLOCK_T 1
-
 /* Define to 1 if you have the <pwd.h> header file. */
-//#define HAVE_PWD_H 1
+/* #undef HAVE_PWD_H */
 
 /* Define to 1 if you have the `pwrite' function. */
@@ -599,14 +653,14 @@
 /* #undef HAVE_RESOLV_H */
 
-/* Define to 1 if you have the `rfork' function. */
-/* #undef HAVE_RFORK */
-
 /* Define to 1 if you have the <sched.h> header file. */
 #define HAVE_SCHED_H 1
 
+/* Define to 1 if you have the `sched_setaffinity' function. */
+/* #undef HAVE_SCHED_SETAFFINITY */
+
 /* Define to 1 if you have the `sched_yield' function. */
 #define HAVE_SCHED_YIELD 1
 
-/* Define to 1 if `cmd' is member of `scsireq_t'. */
+/* Define to 1 if `cmd' is a member of `scsireq_t'. */
 /* #undef HAVE_SCSIREQ_T_CMD */
 
@@ -630,10 +684,10 @@
 
 /* Define to 1 if you have the `setrlimit' function. */
-//#define HAVE_SETRLIMIT 1
+/* #undef HAVE_SETRLIMIT */
 
 /* Define to 1 if you have the `settimeofday' function. */
 #define HAVE_SETTIMEOFDAY 1
 
-/* Define to 1 if `interface_id' is member of `sg_io_hdr_t'. */
+/* Define to 1 if `interface_id' is a member of `sg_io_hdr_t'. */
 /* #undef HAVE_SG_IO_HDR_T_INTERFACE_ID */
 
@@ -644,5 +698,5 @@
 /* #undef HAVE_SIGALTSTACK */
 
-/* Define to 1 if `si_fd' is member of `siginfo_t'. */
+/* Define to 1 if `si_fd' is a member of `siginfo_t'. */
 /* #undef HAVE_SIGINFO_T_SI_FD */
 
@@ -651,5 +705,5 @@
 
 /* Define to 1 if the system has the type `sigset_t'. */
-//#define HAVE_SIGSET_T 1
+#define HAVE_SIGSET_T 1
 
 /* Define to 1 if the system has the type `size_t'. */
@@ -657,5 +711,8 @@
 
 /* Define to 1 if you have the `snprintf' function. */
-//#define HAVE_SNPRINTF 1
+/* #undef HAVE_SNPRINTF */
+
+/* Define to 1 if you have the `socketpair' function. */
+#define HAVE_SOCKETPAIR 1
 
 /* Define to 1 if you have the <soundcard.h> header file. */
@@ -674,6 +731,9 @@
 #define HAVE_STATVFS 1
 
+/* Define to 1 if you have the <stdbool.h> header file. */
+#define HAVE_STDBOOL_H 1
+
 /* Define to 1 if you have the <stdint.h> header file. */
-//#define HAVE_STDINT_H 1
+/* #undef HAVE_STDINT_H */
 
 /* Define to 1 if you have the <stdlib.h> header file. */
@@ -698,4 +758,7 @@
 #define HAVE_STRNCASECMP 1
 
+/* Define to 1 if you have the <stropts.h> header file. */
+/* #undef HAVE_STROPTS_H */
+
 /* Define to 1 if you have the `strtold' function. */
 /* #undef HAVE_STRTOLD */
@@ -707,63 +770,72 @@
 #define HAVE_STRTOULL 1
 
-/* Define to 1 if `direction' is member of `struct ff_effect'. */
+/* Define to 1 if `direction' is a member of `struct ff_effect'. */
 /* #undef HAVE_STRUCT_FF_EFFECT_DIRECTION */
 
-/* Define to 1 if `msg_accrights' is member of `struct msghdr'. */
+/* Define to 1 if `icps_outhist' is a member of `struct icmpstat'. */
+/* #undef HAVE_STRUCT_ICMPSTAT_ICPS_OUTHIST */
+
+/* Define to 1 if `msg_accrights' is a member of `struct msghdr'. */
 /* #undef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
 
-/* Define to 1 if `mt_blkno' is member of `struct mtget'. */
+/* Define to 1 if `mt_blkno' is a member of `struct mtget'. */
 #define HAVE_STRUCT_MTGET_MT_BLKNO 1
 
-/* Define to 1 if `mt_blksiz' is member of `struct mtget'. */
+/* Define to 1 if `mt_blksiz' is a member of `struct mtget'. */
 /* #undef HAVE_STRUCT_MTGET_MT_BLKSIZ */
 
-/* Define to 1 if `mt_gstat' is member of `struct mtget'. */
+/* Define to 1 if `mt_gstat' is a member of `struct mtget'. */
 #define HAVE_STRUCT_MTGET_MT_GSTAT 1
 
-/* Define to 1 if `name' is member of `struct option'. */
+/* Define to 1 if `name' is a member of `struct option'. */
 #define HAVE_STRUCT_OPTION_NAME 1
 
-/* Define to 1 if `sin6_scope_id' is member of `struct sockaddr_in6'. */
+/* Define to 1 if `sin6_scope_id' is a member of `struct sockaddr_in6'. */
 /* #undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
 
-/* Define to 1 if `sa_len' is member of `struct sockaddr'. */
+/* Define to 1 if `sa_len' is a member of `struct sockaddr'. */
 /* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */
 
-/* Define to 1 if `sun_len' is member of `struct sockaddr_un'. */
+/* Define to 1 if `sun_len' is a member of `struct sockaddr_un'. */
 /* #undef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
 
-/* Define to 1 if `f_bavail' is member of `struct statfs'. */
+/* Define to 1 if `f_bavail' is a member of `struct statfs'. */
 #define HAVE_STRUCT_STATFS_F_BAVAIL 1
 
-/* Define to 1 if `f_bfree' is member of `struct statfs'. */
+/* Define to 1 if `f_bfree' is a member of `struct statfs'. */
 #define HAVE_STRUCT_STATFS_F_BFREE 1
 
-/* Define to 1 if `f_favail' is member of `struct statfs'. */
+/* Define to 1 if `f_favail' is a member of `struct statfs'. */
 /* #undef HAVE_STRUCT_STATFS_F_FAVAIL */
 
-/* Define to 1 if `f_ffree' is member of `struct statfs'. */
+/* Define to 1 if `f_ffree' is a member of `struct statfs'. */
 #define HAVE_STRUCT_STATFS_F_FFREE 1
 
-/* Define to 1 if `f_frsize' is member of `struct statfs'. */
+/* Define to 1 if `f_frsize' is a member of `struct statfs'. */
 /* #undef HAVE_STRUCT_STATFS_F_FRSIZE */
 
-/* Define to 1 if `f_namelen' is member of `struct statfs'. */
+/* Define to 1 if `f_namelen' is a member of `struct statfs'. */
 #define HAVE_STRUCT_STATFS_F_NAMELEN 1
 
-/* Define to 1 if `f_blocks' is member of `struct statvfs'. */
+/* Define to 1 if `f_blocks' is a member of `struct statvfs'. */
 #define HAVE_STRUCT_STATVFS_F_BLOCKS 1
 
-/* Define to 1 if `st_atim' is member of `struct stat'. */
+/* Define to 1 if `st_atim' is a member of `struct stat'. */
 #define HAVE_STRUCT_STAT_ST_ATIM 1
 
-/* Define to 1 if `st_blocks' is member of `struct stat'. */
+/* Define to 1 if `st_blocks' is a member of `struct stat'. */
 #define HAVE_STRUCT_STAT_ST_BLOCKS 1
 
-/* Define to 1 if `st_ctim' is member of `struct stat'. */
+/* Define to 1 if `st_ctim' is a member of `struct stat'. */
 #define HAVE_STRUCT_STAT_ST_CTIM 1
 
-/* Define to 1 if `st_mtim' is member of `struct stat'. */
+/* Define to 1 if `st_mtim' is a member of `struct stat'. */
 #define HAVE_STRUCT_STAT_ST_MTIM 1
+
+/* Define to 1 if the system has the type `struct xinpgen'. */
+/* #undef HAVE_STRUCT_XINPGEN */
+
+/* Define to 1 if you have the `symlink' function. */
+/* #undef HAVE_SYMLINK */
 
 /* Define to 1 if you have the <syscall.h> header file. */
@@ -794,4 +866,7 @@
 /* #undef HAVE_SYS_FILIO_H */
 
+/* Define to 1 if you have the <sys/inotify.h> header file. */
+/* #undef HAVE_SYS_INOTIFY_H */
+
 /* Define to 1 if you have the <sys/ioctl.h> header file. */
 #define HAVE_SYS_IOCTL_H 1
@@ -806,9 +881,6 @@
 /* #undef HAVE_SYS_LINK_H */
 
-/* Define to 1 if you have the <sys/lwp.h> header file. */
-/* #undef HAVE_SYS_LWP_H */
-
 /* Define to 1 if you have the <sys/mman.h> header file. */
-//#define HAVE_SYS_MMAN_H 1
+/* #undef HAVE_SYS_MMAN_H */
 
 /* Define to 1 if you have the <sys/modem.h> header file. */
@@ -833,12 +905,12 @@
 /* #undef HAVE_SYS_PRCTL_H */
 
+/* Define to 1 if you have the <sys/protosw.h> header file. */
+/* #undef HAVE_SYS_PROTOSW_H */
+
 /* Define to 1 if you have the <sys/ptrace.h> header file. */
 /* #undef HAVE_SYS_PTRACE_H */
 
-/* Define to 1 if you have the <sys/reg.h> header file. */
-/* #undef HAVE_SYS_REG_H */
-
 /* Define to 1 if you have the <sys/resource.h> header file. */
-//#define HAVE_SYS_RESOURCE_H 1
+/* #undef HAVE_SYS_RESOURCE_H */
 
 /* Define to 1 if you have the <sys/scsiio.h> header file. */
@@ -846,8 +918,8 @@
 
 /* Define to 1 if you have the <sys/shm.h> header file. */
-//#define HAVE_SYS_SHM_H 1
+/* #undef HAVE_SYS_SHM_H */
 
 /* Define to 1 if you have the <sys/signal.h> header file. */
-//#define HAVE_SYS_SIGNAL_H 1
+/* #undef HAVE_SYS_SIGNAL_H */
 
 /* Define to 1 if you have the <sys/socketvar.h> header file. */
@@ -884,4 +956,10 @@
 /* #undef HAVE_SYS_THR_H */
 
+/* Define to 1 if you have the <sys/tihdr.h> header file. */
+/* #undef HAVE_SYS_TIHDR_H */
+
+/* Define to 1 if you have the <sys/timeout.h> header file. */
+/* #undef HAVE_SYS_TIMEOUT_H */
+
 /* Define to 1 if you have the <sys/times.h> header file. */
 #define HAVE_SYS_TIMES_H 1
@@ -902,4 +980,7 @@
 /* #undef HAVE_SYS_USER_H */
 
+/* Define to 1 if you have the <sys/utsname.h> header file. */
+/* #undef HAVE_SYS_UTSNAME_H */
+
 /* Define to 1 if you have the <sys/vfs.h> header file. */
 #define HAVE_SYS_VFS_H 1
@@ -930,5 +1011,5 @@
 
 /* Define to 1 if you have the <unistd.h> header file. */
-//#define HAVE_UNISTD_H 1
+/* #undef HAVE_UNISTD_H */
 
 /* Define to 1 if you have the `usleep' function. */
@@ -944,9 +1025,6 @@
 /* #undef HAVE_VALGRIND_VALGRIND_H */
 
-/* Define if we have va_copy */
-#define HAVE_VA_COPY 1
-
 /* Define to 1 if you have the `vsnprintf' function. */
-//#define HAVE_VSNPRINTF 1
+/* #undef HAVE_VSNPRINTF */
 
 /* Define to 1 if you have the `wait4' function. */
@@ -965,4 +1043,7 @@
 /* #undef HAVE_X11_EXTENSIONS_XF86VMODE_H */
 
+/* Define to 1 if you have the <X11/extensions/xf86vmproto.h> header file. */
+/* #undef HAVE_X11_EXTENSIONS_XF86VMPROTO_H */
+
 /* Define to 1 if you have the <X11/extensions/Xinerama.h> header file. */
 /* #undef HAVE_X11_EXTENSIONS_XINERAMA_H */
@@ -992,5 +1073,5 @@
 /* #undef HAVE_X11_XUTIL_H */
 
-/* Define to 1 if `callback' is member of `XICCallback'. */
+/* Define to 1 if `callback' is a member of `XICCallback'. */
 /* #undef HAVE_XICCALLBACK_CALLBACK */
 
@@ -1007,4 +1088,10 @@
 /* #undef HAVE_XRENDERSETPICTURETRANSFORM */
 
+/* Define to 1 if you have the `z' library (-lz). */
+#define HAVE_ZLIB 1
+
+/* Define to 1 if you have the <zlib.h> header file. */
+#define HAVE_ZLIB_H 1
+
 /* Define to 1 if you have the `_pclose' function. */
 #define HAVE__PCLOSE 1
@@ -1037,7 +1124,4 @@
 #define HAVE__VSNPRINTF 1
 
-/* Define if we have __va_copy */
-#define HAVE___VA_COPY 1
-
 /* Define to the address where bug reports for this package should be sent. */
 #define PACKAGE_BUGREPORT "wine-devel@winehq.org"
@@ -1047,17 +1131,14 @@
 
 /* Define to the full name and version of this package. */
-#define PACKAGE_STRING "Wine 1.1.10"
-
-/* Define to 1 if you have the `z' library (-lz). */
-#define HAVE_ZLIB 1
-
-/* Define to 1 if you have the <zlib.h> header file. */
-#define HAVE_ZLIB_H 1
+#define PACKAGE_STRING "Wine 1.1.36"
 
 /* Define to the one symbol short name of this package. */
 #define PACKAGE_TARNAME "wine"
 
+/* Define to the home page for this package. */
+#define PACKAGE_URL "http://www.winehq.org"
+
 /* Define to the version of this package. */
-#define PACKAGE_VERSION "1.1.10"
+#define PACKAGE_VERSION "1.1.36"
 
 /* Define to the soname of the libcapi20 library. */
@@ -1088,4 +1169,7 @@
 /* #undef SONAME_LIBGNUTLS */
 
+/* Define to the soname of the libgsm library. */
+/* #undef SONAME_LIBGSM */
+
 /* Define to the soname of the libhal library. */
 /* #undef SONAME_LIBHAL */
@@ -1150,4 +1234,10 @@
 /* Define to 1 if the X Window System is missing or not being used. */
 #define X_DISPLAY_MISSING 1
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
 
 /* Define to a macro to output a .cfi assembly pseudo-op */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d10shader.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d10shader.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d10shader.h	(revision 25949)
@@ -92,4 +92,35 @@
 } D3D10_SHADER_VARIABLE_TYPE, *LPD3D10_SHADER_VARIABLE_TYPE;
 
+typedef enum D3D10_CBUFFER_TYPE
+{
+    D3D10_CT_CBUFFER = 0,
+    D3D10_CT_TBUFFER = 1
+} D3D10_CBUFFER_TYPE, *LPD3D10_CBUFFER_TYPE;
+
+typedef enum D3D10_NAME
+{
+    D3D10_NAME_UNDEFINED = 0,
+    D3D10_NAME_POSITION = 1,
+    D3D10_NAME_CLIP_DISTANCE = 2,
+    D3D10_NAME_CULL_DISTANCE = 3,
+    D3D10_NAME_RENDER_TARGET_ARRAY_INDEX = 4,
+    D3D10_NAME_VIEWPORT_ARRAY_INDEX = 5,
+    D3D10_NAME_VERTEX_ID = 6,
+    D3D10_NAME_PRIMITIVE_ID = 7,
+    D3D10_NAME_INSTANCE_ID = 8,
+    D3D10_NAME_IS_FRONT_FACE = 9,
+    D3D10_NAME_SAMPLE_INDEX = 10,
+    D3D10_NAME_TARGET = 64,
+    D3D10_NAME_DEPTH = 65,
+} D3D10_NAME;
+
+typedef enum D3D10_REGISTER_COMPONENT_TYPE
+{
+    D3D10_REGISTER_COMPONENT_UNKNOWN = 0,
+    D3D10_REGISTER_COMPONENT_UINT32 = 1,
+    D3D10_REGISTER_COMPONENT_SINT32 = 2,
+    D3D10_REGISTER_COMPONENT_FLOAT32 = 3,
+} D3D10_REGISTER_COMPONENT_TYPE;
+
 typedef struct _D3D10_SHADER_MACRO
 {
@@ -98,3 +129,18 @@
 } D3D10_SHADER_MACRO, *LPD3D10_SHADER_MACRO;
 
+typedef struct _D3D10_SIGNATURE_PARAMETER_DESC
+{
+    LPCSTR SemanticName;
+    UINT SemanticIndex;
+    UINT Register;
+    D3D10_NAME SystemValueType;
+    D3D10_REGISTER_COMPONENT_TYPE ComponentType;
+    BYTE Mask;
+    BYTE ReadWriteMask;
+} D3D10_SIGNATURE_PARAMETER_DESC;
+
+LPCSTR WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device);
+LPCSTR WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device);
+LPCSTR WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device);
+
 #endif /* __WINE_D3D10SHADER_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d9.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d9.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d9.h	(revision 25949)
@@ -1718,16 +1718,20 @@
     /* IDirect3DDevice9Ex methods */
     STDMETHOD(SetConvolutionMonoKernel)(THIS_ UINT width, UINT height, float *rows, float *columns) PURE;
-    STDMETHOD(ComposeRects)(THIS_ IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) PURE;
+    STDMETHOD(ComposeRects)(THIS_ IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface,
+            IDirect3DVertexBuffer9 *src_descs, UINT rect_count, IDirect3DVertexBuffer9 *dst_descs,
+            D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y) PURE;
     STDMETHOD(PresentEx)(THIS_ CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) PURE;
     STDMETHOD(GetGPUThreadPriority)(THIS_ INT *pPriority) PURE;
     STDMETHOD(SetGPUThreadPriority)(THIS_ INT Priority) PURE;
     STDMETHOD(WaitForVBlank)(THIS_ UINT iSwapChain) PURE;
-    STDMETHOD(CheckresourceResidency)(THIS_ IDirect3DResource9 ** pResourceArray, UINT32 Numresources) PURE;
+    STDMETHOD(CheckResourceResidency)(THIS_ IDirect3DResource9 **resources, UINT32 resource_count) PURE;
     STDMETHOD(SetMaximumFrameLatency)(THIS_ UINT MaxLatency) PURE;
     STDMETHOD(GetMaximumFrameLatency)(THIS_ UINT *pMaxLatenxy) PURE;
-    STDMETHOD(CheckdeviceState)(THIS_ HWND hDestinationWindow) PURE;
+    STDMETHOD(CheckDeviceState)(THIS_ HWND dst_window) PURE;
     STDMETHOD(CreateRenderTargetEx)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Lockable, IDirect3DSurface9 ** ppSurface, HANDLE *pSharedHandle, DWORD Usage) PURE;
     STDMETHOD(CreateOffscreenPlainSurfaceEx)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) PURE;
-    STDMETHOD(CreateDepthStencilSurfaceEx)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurfface, HANDLE *pSharedHandle, DWORD Usage) PURE;
+    STDMETHOD(CreateDepthStencilSurfaceEx)(THIS_ UINT width, UINT height, D3DFORMAT format,
+            D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL discard,
+            IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage) PURE;
     STDMETHOD(ResetEx)(THIS_ D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) PURE;
     STDMETHOD(GetDisplayModeEx)(THIS_ UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) PURE;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d9types.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d9types.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d9types.h	(revision 25949)
@@ -1567,3 +1567,15 @@
 #endif /* D3D_DISABLE_9EX */
 
+typedef enum _D3DSHADER_COMPARISON
+{
+    D3DSPC_RESERVED0 = 0,
+    D3DSPC_GT,
+    D3DSPC_EQ,
+    D3DSPC_GE,
+    D3DSPC_LT,
+    D3DSPC_NE,
+    D3DSPC_LE,
+    D3DSPC_RESERVED1,
+} D3DSHADER_COMPARISON;
+
 #endif /* __WINE_D3D9TYPES_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drm.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drm.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drm.h	(revision 25949)
@@ -41,3 +41,175 @@
 DEFINE_GUID(IID_IDirect3DRM3,               0x4516ec83, 0x8f20, 0x11d0, 0x9b, 0x6d, 0x00, 0x00, 0xc0, 0x78, 0x1b, 0xc3);
 
+typedef void *LPDIRECT3DRM;
+
+HRESULT WINAPI Direct3DRMCreate(LPDIRECT3DRM* ppDirect3DRM);
+
+/*****************************************************************************
+ * IDirect3DRMObject interface
+ */
+#ifdef WINE_NO_UNICODE_MACROS
+#undef GetClassName
+#endif
+#define INTERFACE IDirect3DRM
+DECLARE_INTERFACE_(IDirect3DRM,IUnknown)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    /*** IDirect3DRM methods ***/
+    STDMETHOD(CreateObject)(THIS_ REFCLSID rclsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj) PURE;
+    STDMETHOD(CreateFrame)(THIS_ LPDIRECT3DRMFRAME, LPDIRECT3DRMFRAME *) PURE;
+    STDMETHOD(CreateMesh)(THIS_ LPDIRECT3DRMMESH *) PURE;
+    STDMETHOD(CreateMeshBuilder)(THIS_ LPDIRECT3DRMMESHBUILDER *) PURE;
+    STDMETHOD(CreateFace)(THIS_ LPDIRECT3DRMFACE *) PURE;
+    STDMETHOD(CreateAnimation)(THIS_ LPDIRECT3DRMANIMATION *) PURE;
+    STDMETHOD(CreateAnimationSet)(THIS_ LPDIRECT3DRMANIMATIONSET *) PURE;
+    STDMETHOD(CreateTexture)(THIS_ LPD3DRMIMAGE, LPDIRECT3DRMTEXTURE *) PURE;
+    STDMETHOD(CreateLight)(THIS_ D3DRMLIGHTTYPE, D3DCOLOR, LPDIRECT3DRMLIGHT *) PURE;
+    STDMETHOD(CreateLightRGB)(THIS_ D3DRMLIGHTTYPE, D3DVALUE, D3DVALUE, D3DVALUE, LPDIRECT3DRMLIGHT *) PURE;
+    STDMETHOD(CreateMaterial)(THIS_ D3DVALUE, LPDIRECT3DRMMATERIAL *) PURE;
+    STDMETHOD(CreateDevice)(THIS_ DWORD, DWORD, LPDIRECT3DRMDEVICE *) PURE;
+    STDMETHOD(CreateDeviceFromSurface)(THIS_ LPGUID pGUID, LPDIRECTDRAW pDD, LPDIRECTDRAWSURFACE pDDSBack,
+        LPDIRECT3DRMDEVICE *) PURE;
+    STDMETHOD(CreateDeviceFromD3D)(THIS_ LPDIRECT3D pD3D, LPDIRECT3DDEVICE pD3DDev, LPDIRECT3DRMDEVICE *) PURE;
+    STDMETHOD(CreateDeviceFromClipper)(THIS_ LPDIRECTDRAWCLIPPER pDDClipper, LPGUID pGUID, int width, int height,
+        LPDIRECT3DRMDEVICE *) PURE;
+    STDMETHOD(CreateShadow)(THIS_ LPDIRECT3DRMVISUAL, LPDIRECT3DRMLIGHT, D3DVALUE px, D3DVALUE py, D3DVALUE pz,
+        D3DVALUE nx, D3DVALUE ny, D3DVALUE nz, LPDIRECT3DRMVISUAL *) PURE;
+    STDMETHOD(CreateTextureFromSurface)(THIS_ LPDIRECTDRAWSURFACE pDDS, LPDIRECT3DRMTEXTURE *) PURE;
+    STDMETHOD(CreateViewport)(THIS_ LPDIRECT3DRMDEVICE, LPDIRECT3DRMFRAME, DWORD, DWORD, DWORD, DWORD,
+        LPDIRECT3DRMVIEWPORT *) PURE;
+    STDMETHOD(CreateWrap)(THIS_ D3DRMWRAPTYPE, LPDIRECT3DRMFRAME, D3DVALUE ox, D3DVALUE oy, D3DVALUE oz,
+        D3DVALUE dx, D3DVALUE dy, D3DVALUE dz, D3DVALUE ux, D3DVALUE uy, D3DVALUE uz, D3DVALUE ou, D3DVALUE ov,
+        D3DVALUE su, D3DVALUE sv, LPDIRECT3DRMWRAP *) PURE;
+    STDMETHOD(CreateUserVisual)(THIS_ D3DRMUSERVISUALCALLBACK, LPVOID pArg, LPDIRECT3DRMUSERVISUAL *) PURE;
+    STDMETHOD(LoadTexture)(THIS_ const char *, LPDIRECT3DRMTEXTURE *) PURE;
+    STDMETHOD(LoadTextureFromResource)(THIS_ HRSRC rs, LPDIRECT3DRMTEXTURE *) PURE;
+    STDMETHOD(SetSearchPath)(THIS_ LPCSTR) PURE;
+    STDMETHOD(AddSearchPath)(THIS_ LPCSTR) PURE;
+    STDMETHOD(GetSearchPath)(THIS_ DWORD *size_return, LPSTR path_return) PURE;
+    STDMETHOD(SetDefaultTextureColors)(THIS_ DWORD) PURE;
+    STDMETHOD(SetDefaultTextureShades)(THIS_ DWORD) PURE;
+    STDMETHOD(GetDevices)(THIS_ LPDIRECT3DRMDEVICEARRAY *) PURE;
+    STDMETHOD(GetNamedObject)(THIS_ const char *, LPDIRECT3DRMOBJECT *) PURE;
+    STDMETHOD(EnumerateObjects)(THIS_ D3DRMOBJECTCALLBACK, LPVOID) PURE;
+    STDMETHOD(Load)(THIS_ LPVOID, LPVOID, LPIID *, DWORD, D3DRMLOADOPTIONS, D3DRMLOADCALLBACK, LPVOID,
+        D3DRMLOADTEXTURECALLBACK, LPVOID, LPDIRECT3DRMFRAME) PURE;
+    STDMETHOD(Tick)(THIS_ D3DVALUE) PURE;
+};
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+/*** IUnknown methods ***/
+#define IDirect3DRM_QueryInterface(p,a,b)                         (p)->lpVtbl->QueryInterface(p,a,b)
+#define IDirect3DRM_AddRef(p)                                     (p)->lpVtbl->AddRef(p)
+#define IDirect3DRM_Release(p)                                    (p)->lpVtbl->Release(p)
+/*** IDirect3DRM methods ***/
+#define IDirect3DRM_CreateObject(p,a,b,c,d)                       (p)->lpVtbl->CreateObject(p,a,b,d)
+#define IDirect3DRM_CreateFrame(p,a,b)                            (p)->lpVtbl->CreateFrame(p,a,b)
+#define IDirect3DRM_CreateMesh(p,a)                               (p)->lpVtbl->CreateMesh(p,a)
+#define IDirect3DRM_CreateMeshBuilder(p,a)                        (p)->lpVtbl->CreateMeshBuilder(p,a)
+#define IDirect3DRM_CreateFace(p,a)                               (p)->lpVtbl->CreateFace(p,a)
+#define IDirect3DRM_CreateAnimation(p,a)                          (p)->lpVtbl->CreateAnimation(p,a)
+#define IDirect3DRM_CreateAnimationSet(p,a)                       (p)->lpVtbl->CreateAnimationSet(p,a)
+#define IDirect3DRM_CreateTexture(p,a,b)                          (p)->lpVtbl->CreateTexture(p,a,b)
+#define IDirect3DRM_CreateLight(p,a,b,c)                          (p)->lpVtbl->CreateLight(p,a,b,c)
+#define IDirect3DRM_CreateLightRGB(p,a,b,c,d,e)                   (p)->lpVtbl->CreateLightRGB(p,a,b,c,d,e)
+#define IDirect3DRM_CreateMaterial(p,a,b)                         (p)->lpVtbl->CreateMaterial(p,a,b)
+#define IDirect3DRM_CreateDevice(p,a,b,c)                         (p)->lpVtbl->CreateDevice(p,a,b,c)
+#define IDirect3DRM_CreateDeviceFromSurface(p,a,b,c,d)            (p)->lpVtbl->CreateDeviceFromSurface(p,a,b,c,d)
+#define IDirect3DRM_CreateDeviceFromD3D(p,a,b,c)                  (p)->lpVtbl->CreateDeviceFromD3D(p,a,b,c)
+#define IDirect3DRM_CreateDeviceFromClipper(p,a,b,c,d,e)          (p)->lpVtbl->CreateDeviceFromClipper(p,a,b,c,d,e)
+#define IDirect3DRM_CreateTextureFromSurface(p,a,b)               (p)->lpVtbl->CreateTextureFromSurface(p,a,b)
+#define IDirect3DRM_CreateShadow(p,a,b,c,d,e,f,g,h,i)             (p)->lpVtbl->CreateShadow(p,a,b,c,d,e,f,g,h,i)
+#define IDirect3DRM_CreateViewport(p,a,b,c,d,e,f,g)               (p)->lpVtbl->CreateViewport(p,a,b,c,d,e,f,g)
+#define IDirect3DRM_CreateWrap(p,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,q) (p)->lpVtbl->CreateWrap(p,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,q)
+#define IDirect3DRM_CreateUserVisual(p,a,b,c)                     (p)->lpVtbl->CreateUserVisual(p,a,b,c)
+#define IDirect3DRM_LoadTexture(p,a,b)                            (p)->lpVtbl->LoadTexture(p,a,b)
+#define IDirect3DRM_LoadTextureFromResource(p,a,b)                (p)->lpVtbl->LoadTextureFromResource(p,a,b)
+#define IDirect3DRM_SetSearchPath(p,a)                            (p)->lpVtbl->SetSearchPath(p,a)
+#define IDirect3DRM_AddSearchPath(p,a)                            (p)->lpVtbl->AddSearchPath(p,a)
+#define IDirect3DRM_GetSearchPath(p,a,b)                          (p)->lpVtbl->GetSearchPath(p,a,b)
+#define IDirect3DRM_SetDefaultTextureColors(p,a)                  (p)->lpVtbl->SetDefaultTextureColors(p,a)
+#define IDirect3DRM_SetDefaultTextureShades(p,a)                  (p)->lpVtbl->SetDefaultTextureShades(p,a)
+#define IDirect3DRM_GetDevices(p,a)                               (p)->lpVtbl->GetDevices(p,a)
+#define IDirect3DRM_GetNamedObject(p,a,b)                         (p)->lpVtbl->GetNamedObject(p,a,b)
+#define IDirect3DRM_EnumerateObjects(p,a,b)                       (p)->lpVtbl->EnumerateObjects(p,a,b)
+#define IDirect3DRM_Load(p,a,b,c,d,e,f,g,h,i,j)                   (p)->lpVtbl->Load(p,a,b,c,d,e,f,g,h,i,j)
+#define IDirect3DRM_Tick(p,a)                                     (p)->lpVtbl->Tick(p,a)
+#else
+/*** IUnknown methods ***/
+#define IDirect3DRM_QueryInterface(p,a,b)                         (p)->QueryInterface(a,b)
+#define IDirect3DRM_AddRef(p)                                     (p)->AddRef()
+#define IDirect3DRM_Release(p)                                    (p)->Release()
+/*** IDirect3DRM methods ***/
+#define IDirect3DRM_CreateObject(p,a,b,c,d)                       (p)->CreateObject(a,b,d)
+#define IDirect3DRM_CreateFrame(p,a,b)                            (p)->CreateFrame(a,b)
+#define IDirect3DRM_CreateMesh(p,a)                               (p)->CreateMesh(a)
+#define IDirect3DRM_CreateMeshBuilder(p,a)                        (p)->CreateMeshBuilder(a)
+#define IDirect3DRM_CreateFace(p,a)                               (p)->CreateFace(a)
+#define IDirect3DRM_CreateAnimation(p,a)                          (p)->CreateAnimation(a)
+#define IDirect3DRM_CreateAnimationSet(p,a)                       (p)->CreateAnimationSet(a)
+#define IDirect3DRM_CreateTexture(p,a,b)                          (p)->CreateTexture(a,b)
+#define IDirect3DRM_CreateLight(p,a,b,c)                          (p)->CreateLight(a,b,c)
+#define IDirect3DRM_CreateLightRGB(p,a,b,c,d,e)                   (p)->CreateLightRGB(a,b,c,d,e)
+#define IDirect3DRM_CreateMaterial(p,a,b)                         (p)->CreateMaterial(a,b)
+#define IDirect3DRM_CreateDevice(p,a,b,c)                         (p)->CreateDevice(a,b,c)
+#define IDirect3DRM_CreateDeviceFromSurface(p,a,b,c,d)            (p)->CreateDeviceFromSurface(a,b,c,d)
+#define IDirect3DRM_CreateDeviceFromD3D(p,a,b,c)                  (p)->CreateDeviceFromD3D(a,b,c)
+#define IDirect3DRM_CreateDeviceFromClipper(p,a,b,c,d,e)          (p)->CreateDeviceFromClipper(a,b,c,d,e)
+#define IDirect3DRM_CreateTextureFromSurface(p,a,b)               (p)->CreateTextureFromSurface(a,b)
+#define IDirect3DRM_CreateShadow(p,a,b,c,d,e,f,g,h,i)             (p)->CreateShadow(a,b,c,d,e,f,g,h,i)
+#define IDirect3DRM_CreateViewport(p,a,b,c,d,e,f,g)               (p)->CreateViewport(a,b,c,d,e,f,g)
+#define IDirect3DRM_CreateWrap(p,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) (p)->CreateWrap(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
+#define IDirect3DRM_CreateUserVisual(p,a,b,c)                     (p)->CreateUserVisual(a,b,c)
+#define IDirect3DRM_LoadTexture(p,a,b)                            (p)->LoadTexture(a,b)
+#define IDirect3DRM_LoadTextureFromResource(p,a,b)                (p)->LoadTextureFromResource(a,b)
+#define IDirect3DRM_SetSearchPath(p,a)                            (p)->SetSearchPath(a)
+#define IDirect3DRM_AddSearchPath(p,a)                            (p)->AddSearchPath(a)
+#define IDirect3DRM_GetSearchPath(p,a,b)                          (p)->GetSearchPath(a,b)
+#define IDirect3DRM_SetDefaultTextureColors(p,a)                  (p)->SetDefaultTextureColors(a)
+#define IDirect3DRM_SetDefaultTextureShades(p,a)                  (p)->SetDefaultTextureShades(a)
+#define IDirect3DRM_GetDevices(p,a)                               (p)->GetDevices(a)
+#define IDirect3DRM_GetNamedObject(p,a,b)                         (p)->GetNamedObject(a,b)
+#define IDirect3DRM_EnumerateObjects(p,a,b)                       (p)->EnumerateObjects(a,b)
+#define IDirect3DRM_Load(p,a,b,c,d,e,f,g,h,i,j)                   (p)->Load(a,b,c,d,e,f,g,h,i,j)
+#define IDirect3DRM_Tick(p,a)                                     (p)->Tick(a)
+#endif
+
+#define D3DRM_OK                        DD_OK
+#define D3DRMERR_BADOBJECT              MAKE_DDHRESULT(781)
+#define D3DRMERR_BADTYPE                MAKE_DDHRESULT(782)
+#define D3DRMERR_BADALLOC               MAKE_DDHRESULT(783)
+#define D3DRMERR_FACEUSED               MAKE_DDHRESULT(784)
+#define D3DRMERR_NOTFOUND               MAKE_DDHRESULT(785)
+#define D3DRMERR_NOTDONEYET             MAKE_DDHRESULT(786)
+#define D3DRMERR_FILENOTFOUND           MAKE_DDHRESULT(787)
+#define D3DRMERR_BADFILE                MAKE_DDHRESULT(788)
+#define D3DRMERR_BADDEVICE              MAKE_DDHRESULT(789)
+#define D3DRMERR_BADVALUE               MAKE_DDHRESULT(790)
+#define D3DRMERR_BADMAJORVERSION        MAKE_DDHRESULT(791)
+#define D3DRMERR_BADMINORVERSION        MAKE_DDHRESULT(792)
+#define D3DRMERR_UNABLETOEXECUTE        MAKE_DDHRESULT(793)
+#define D3DRMERR_LIBRARYNOTFOUND        MAKE_DDHRESULT(794)
+#define D3DRMERR_INVALIDLIBRARY         MAKE_DDHRESULT(795)
+#define D3DRMERR_PENDING                MAKE_DDHRESULT(796)
+#define D3DRMERR_NOTENOUGHDATA          MAKE_DDHRESULT(797)
+#define D3DRMERR_REQUESTTOOLARGE        MAKE_DDHRESULT(798)
+#define D3DRMERR_REQUESTTOOSMALL        MAKE_DDHRESULT(799)
+#define D3DRMERR_CONNECTIONLOST         MAKE_DDHRESULT(800)
+#define D3DRMERR_LOADABORTED            MAKE_DDHRESULT(801)
+#define D3DRMERR_NOINTERNET             MAKE_DDHRESULT(802)
+#define D3DRMERR_BADCACHEFILE           MAKE_DDHRESULT(803)
+#define D3DRMERR_BOXNOTSET              MAKE_DDHRESULT(804)
+#define D3DRMERR_BADPMDATA              MAKE_DDHRESULT(805)
+#define D3DRMERR_CLIENTNOTREGISTERED    MAKE_DDHRESULT(806)
+#define D3DRMERR_NOTCREATEDFROMDDS      MAKE_DDHRESULT(807)
+#define D3DRMERR_NOSUCHKEY              MAKE_DDHRESULT(808)
+#define D3DRMERR_INCOMPATABLEKEY        MAKE_DDHRESULT(809)
+#define D3DRMERR_ELEMENTINUSE           MAKE_DDHRESULT(810)
+#define D3DRMERR_TEXTUREFORMATNOTFOUND  MAKE_DDHRESULT(811)
+#define D3DRMERR_NOTAGGREGATED          MAKE_DDHRESULT(812)
+
 #endif /* __D3DRM_H__ */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drmdef.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drmdef.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drmdef.h	(revision 25949)
@@ -38,9 +38,58 @@
 
 typedef D3DVALUE D3DRMMATRIX4D[4][4];
-typedef struct _D3DRMQUATERNION
-{
+
+typedef struct _D3DRMQUATERNION {
     D3DVALUE s;
     D3DVECTOR v;
 } D3DRMQUATERNION, *LPD3DRMQUATERNION;
+
+typedef enum _D3DRMLIGHTTYPE {
+    D3DRMLIGHT_AMBIENT,
+    D3DRMLIGHT_POINT,
+    D3DRMLIGHT_SPOT,
+    D3DRMLIGHT_DIRECTIONAL,
+    D3DRMLIGHT_PARALLELPOINT
+} D3DRMLIGHTTYPE, *LPD3DRMLIGHTTYPE;
+
+typedef struct _D3DRMPALETTEENTRY {
+    unsigned char red;
+    unsigned char green;
+    unsigned char blue;
+    unsigned char flags;
+} D3DRMPALETTEENTRY, *LPD3DRMPALETTEENTRY;
+
+typedef struct _D3DRMIMAGE {
+    int width;
+    int height;
+    int aspectx;
+    int aspecty;
+    int depth;
+    int rgb;
+    int bytes_per_line;
+    void* buffer1;
+    void* buffer2;
+    unsigned long red_mask;
+    unsigned long green_mask;
+    unsigned long blue_mask;
+    unsigned long alpha_mask;
+    int palette_size;
+    D3DRMPALETTEENTRY* palette;
+} D3DRMIMAGE, *LPD3DRMIMAGE;
+
+typedef enum _D3DRMWRAPTYPE {
+    D3DRMWRAP_FLAT,
+    D3DRMWRAP_CYLINDER,
+    D3DRMWRAP_SPHERE,
+    D3DRMWRAP_CHROME,
+    D3DRMWRAP_SHEET,
+    D3DRMWRAP_BOX
+} D3DRMWRAPTYPE, *LPD3DRMWRAPTYPE;
+
+typedef DWORD D3DRMLOADOPTIONS;
+
+typedef enum _D3DRMUSERVISUALREASON {
+    D3DRMUSERVISUAL_CANSEE,
+    D3DRMUSERVISUAL_RENDER
+} D3DRMUSERVISUALREASON, *LPD3DRMUSERVISUALREASON;
 
 void WINAPI D3DRMMatrixFromQuaternion(D3DRMMATRIX4D, LPD3DRMQUATERNION);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drmobj.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drmobj.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3drmobj.h	(revision 25949)
@@ -46,5 +46,19 @@
 
 typedef struct IDirect3DRMObject          *LPDIRECT3DRMOBJECT, **LPLPDIRECT3DRMOBJECT;
+typedef struct IDirect3DRMDevice          *LPDIRECT3DRMDEVICE, **LPLPDIRECT3DRMDEVICE;
+typedef struct IDirect3DRMViewport        *LPDIRECT3DRMVIEWPORT, **LPLPDIRECT3DRMVIEWPORT;
+typedef struct IDirect3DRMFrame           *LPDIRECT3DRMFRAME, **LPLPDIRECT3DRMFRAME;
 typedef struct IDirect3DRMVisual          *LPDIRECT3DRMVISUAL, **LPLPDIRECT3DRMVISUAL;
+typedef struct IDirect3DRMMesh            *LPDIRECT3DRMMESH, **LPLPDIRECT3DRMMESH;
+typedef struct IDirect3DRMMeshBuilder     *LPDIRECT3DRMMESHBUILDER, **LPLPDIRECT3DRMMESHBUILDER;
+typedef struct IDirect3DRMFace            *LPDIRECT3DRMFACE, **LPLPDIRECT3DRMFACE;
+typedef struct IDirect3DRMLight           *LPDIRECT3DRMLIGHT, **LPLPDIRECT3DRMLIGHT;
+typedef struct IDirect3DRMTexture         *LPDIRECT3DRMTEXTURE, **LPLPDIRECT3DRMTEXTURE;
+typedef struct IDirect3DRMWrap            *LPDIRECT3DRMWRAP, **LPLPDIRECT3DRMWRAP;
+typedef struct IDirect3DRMMaterial        *LPDIRECT3DRMMATERIAL, **LPLPDIRECT3DRMMATERIAL;
+typedef struct IDirect3DRMAnimation       *LPDIRECT3DRMANIMATION, **LPLPDIRECT3DRMANIMATION;
+typedef struct IDirect3DRMAnimationSet    *LPDIRECT3DRMANIMATIONSET, **LPLPDIRECT3DRMANIMATIONSET;
+typedef struct IDirect3DRMUserVisual      *LPDIRECT3DRMUSERVISUAL, **LPLPDIRECT3DRMUSERVISUAL;
+typedef struct IDirect3DRMDeviceArray     *LPDIRECT3DRMDEVICEARRAY, **LPLPDIRECT3DRMDEVICEARRAY;
 
 /* ********************************************************************
@@ -53,4 +67,8 @@
 
 typedef void (__cdecl *D3DRMOBJECTCALLBACK)(LPDIRECT3DRMOBJECT obj, LPVOID arg);
+typedef int (__cdecl *D3DRMUSERVISUALCALLBACK)(LPDIRECT3DRMUSERVISUAL obj, LPVOID arg,
+    D3DRMUSERVISUALREASON reason, LPDIRECT3DRMDEVICE dev, LPDIRECT3DRMVIEWPORT view);
+typedef HRESULT (__cdecl *D3DRMLOADTEXTURECALLBACK)(char *tex_name, void *arg, LPDIRECT3DRMTEXTURE *);
+typedef void (__cdecl *D3DRMLOADCALLBACK)(LPDIRECT3DRMOBJECT object, REFIID objectguid, LPVOID arg);
 
 typedef struct _D3DRMPICKDESC
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9shader.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9shader.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9shader.h	(revision 25949)
@@ -30,4 +30,25 @@
 #ifndef __D3DX9SHADER_H__
 #define __D3DX9SHADER_H__
+
+#define D3DXSHADER_DEBUG                          0x1
+#define D3DXSHADER_SKIPVALIDATION                 0x2
+#define D3DXSHADER_SKIPOPTIMIZATION               0x4
+#define D3DXSHADER_PACKMATRIX_ROWMAJOR            0x8
+#define D3DXSHADER_PACKMATRIX_COLUMNMAJOR         0x10
+#define D3DXSHADER_PARTIALPRECISION               0x20
+#define D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT        0x40
+#define D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT        0x80
+#define D3DXSHADER_NO_PRESHADER                   0x100
+#define D3DXSHADER_AVOID_FLOW_CONTROL             0x200
+#define D3DXSHADER_PREFER_FLOW_CONTROL            0x400
+#define D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY 0x1000
+#define D3DXSHADER_IEEE_STRICTNESS                0x2000
+
+#define D3DXSHADER_OPTIMIZATION_LEVEL0            0x4000
+#define D3DXSHADER_OPTIMIZATION_LEVEL1            0x0
+#define D3DXSHADER_OPTIMIZATION_LEVEL2            0xC000
+#define D3DXSHADER_OPTIMIZATION_LEVEL3            0x8000
+
+#define D3DXSHADER_USE_LEGACY_D3DX9_31_DLL        0x10000
 
 typedef LPCSTR D3DXHANDLE;
@@ -74,4 +95,24 @@
 } D3DXMACRO, *LPD3DXMACRO;
 
+typedef enum _D3DXINCLUDE_TYPE
+{
+    D3DXINC_LOCAL,
+    D3DXINC_SYSTEM,
+    D3DXINC_FORCE_DWORD = 0x7fffffff,
+} D3DXINCLUDE_TYPE, *LPD3DXINCLUDE_TYPE;
+
+#undef INTERFACE
+#define INTERFACE ID3DXInclude
+
+DECLARE_INTERFACE(ID3DXInclude)
+{
+    STDMETHOD(Open)(THIS_ D3DXINCLUDE_TYPE include_type, LPCSTR filename, LPCVOID parent_data, LPCVOID *data, UINT *bytes) PURE;
+    STDMETHOD(Close)(THIS_ LPCVOID data) PURE;
+};
+
+#define ID3DXInclude_Open(p,a,b,c,d,e)  (p)->lpVtbl->Open(p,a,b,c,d,e)
+#define ID3DXInclude_Close(p,a)         (p)->lpVtbl->Close(p,a)
+
+typedef struct ID3DXInclude *LPD3DXINCLUDE;
 
 #ifdef __cplusplus
@@ -84,4 +125,42 @@
 LPCSTR WINAPI D3DXGetVertexShaderProfile(LPDIRECT3DDEVICE9 device);
 
+HRESULT WINAPI D3DXAssembleShaderFromFileA(LPCSTR filename,
+                                           CONST D3DXMACRO* defines,
+                                           LPD3DXINCLUDE include,
+                                           DWORD flags,
+                                           LPD3DXBUFFER* shader,
+                                           LPD3DXBUFFER* error_messages);
+
+HRESULT WINAPI D3DXAssembleShaderFromFileW(LPCWSTR filename,
+                                           CONST D3DXMACRO* defines,
+                                           LPD3DXINCLUDE include,
+                                           DWORD flags,
+                                           LPD3DXBUFFER* shader,
+                                           LPD3DXBUFFER* error_messages);
+
+HRESULT WINAPI D3DXAssembleShaderFromResourceA(HMODULE module,
+                                               LPCSTR resource,
+                                               CONST D3DXMACRO* defines,
+                                               LPD3DXINCLUDE include,
+                                               DWORD flags,
+                                               LPD3DXBUFFER* shader,
+                                               LPD3DXBUFFER* error_messages);
+
+HRESULT WINAPI D3DXAssembleShaderFromResourceW(HMODULE module,
+                                               LPCWSTR resource,
+                                               CONST D3DXMACRO* defines,
+                                               LPD3DXINCLUDE include,
+                                               DWORD flags,
+                                               LPD3DXBUFFER* shader,
+                                               LPD3DXBUFFER* error_messages);
+
+HRESULT WINAPI D3DXAssembleShader(LPCSTR data,
+                                  UINT data_len,
+                                  CONST D3DXMACRO* defines,
+                                  LPD3DXINCLUDE include,
+                                  DWORD flags,
+                                  LPD3DXBUFFER* shader,
+                                  LPD3DXBUFFER* error_messages);
+
 #ifdef __cplusplus
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbghelp.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbghelp.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbghelp.h	(revision 25949)
@@ -1471,4 +1471,5 @@
 BOOL    WINAPI SymRegisterCallback(HANDLE, PSYMBOL_REGISTERED_CALLBACK, PVOID);
 BOOL    WINAPI SymRegisterFunctionEntryCallback(HANDLE, PSYMBOL_FUNCENTRY_CALLBACK, PVOID);
+BOOL    WINAPI SymRefreshModuleList(HANDLE);
 BOOL    WINAPI SymUnDName(PIMAGEHLP_SYMBOL, PSTR, DWORD);
 BOOL    WINAPI SymUnloadModule(HANDLE, DWORD);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbprop.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbprop.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbprop.idl	(revision 25949)
@@ -50,5 +50,5 @@
              [in, out] ULONG *pcPropertyInfoSets,
              [out, size_is(,*pcPropertyInfoSets)] DBPROPINFOSET **prgPropertyInfoSets,
-             [out, /*annotation("__deref_out_z_opt")*/] OLECHAR **ppDescBuffer);
+             [out, annotation("__deref_out_z_opt")] OLECHAR **ppDescBuffer);
 
     [call_as(GetPropertyInfo)] HRESULT RemoteGetPropertyInfo(
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbs.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbs.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dbs.idl	(revision 25949)
@@ -119,2 +119,219 @@
     IUnknown *pSession;
 } DBIMPLICITSESSION;
+
+typedef WORD DBTYPE;
+
+enum DBTYPEENUM
+{
+    DBTYPE_EMPTY         = 0,
+    DBTYPE_NULL          = 1,
+    DBTYPE_I2            = 2,
+    DBTYPE_I4            = 3,
+    DBTYPE_R4            = 4,
+    DBTYPE_R8            = 5,
+    DBTYPE_CY            = 6,
+    DBTYPE_DATE          = 7,
+    DBTYPE_BSTR          = 8,
+    DBTYPE_IDISPATCH     = 9,
+    DBTYPE_ERROR         = 10,
+    DBTYPE_BOOL          = 11,
+    DBTYPE_VARIANT       = 12,
+    DBTYPE_IUNKNOWN      = 13,
+    DBTYPE_DECIMAL       = 14,
+    DBTYPE_I1            = 16,
+    DBTYPE_UI1           = 17,
+    DBTYPE_UI2           = 18,
+    DBTYPE_UI4           = 19,
+    DBTYPE_I8            = 20,
+    DBTYPE_UI8           = 21,
+    DBTYPE_GUID          = 72,
+    DBTYPE_BYTES         = 128,
+    DBTYPE_STR           = 129,
+    DBTYPE_WSTR          = 130,
+    DBTYPE_NUMERIC       = 131,
+    DBTYPE_UDT           = 132,
+    DBTYPE_DBDATE        = 133,
+    DBTYPE_DBTIME        = 134,
+    DBTYPE_DBTIMESTAMP   = 135,
+
+    DBTYPE_VECTOR        = 0x1000,
+    DBTYPE_ARRAY         = 0x2000,
+    DBTYPE_BYREF         = 0x4000,
+    DBTYPE_RESERVED      = 0x8000
+};
+
+enum DBTYPEENUM15
+{
+    DBTYPE_HCHAPTER      = 136
+};
+
+enum DBTYPEENUM20
+{
+    DBTYPE_FILETIME      = 64,
+    DBTYPE_PROPVARIANT   = 138,
+    DBTYPE_VARNUMERIC    = 139
+};
+
+typedef DWORD DBSTATUS;
+
+enum DBSTATUSENUM
+{
+    DBSTATUS_S_OK = 0,
+    DBSTATUS_E_BADACCESSOR = 1,
+    DBSTATUS_E_CANTCONVERTVALUE = 2,
+    DBSTATUS_S_ISNULL = 3,
+    DBSTATUS_S_TRUNCATED = 4,
+    DBSTATUS_E_SIGNMISMATCH = 5,
+    DBSTATUS_E_DATAOVERFLOW = 6,
+    DBSTATUS_E_CANTCREATE = 7,
+    DBSTATUS_E_UNAVAILABLE = 8,
+    DBSTATUS_E_PERMISSIONDENIED = 9,
+    DBSTATUS_E_INTEGRITYVIOLATION = 10,
+    DBSTATUS_E_SCHEMAVIOLATION = 11,
+    DBSTATUS_E_BADSTATUS = 12,
+    DBSTATUS_S_DEFAULT = 13
+};
+
+cpp_quote("DEFINE_GUID(DBGUID_SESSION,    0xc8b522f5, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);")
+cpp_quote("DEFINE_GUID(DBGUID_ROWSET,     0xc8b522f6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);")
+cpp_quote("DEFINE_GUID(DBGUID_ROW,        0xc8b522f7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);")
+cpp_quote("DEFINE_GUID(DBGUID_STREAM,     0xc8b522f9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);")
+
+typedef struct tagDBCOLUMNACCESS
+{
+    void *pData;
+    DBID columnid;
+    DBLENGTH cbDataLen;
+    DBSTATUS dwStatus;
+    DBLENGTH cbMaxLen;
+    DB_DWRESERVE dwReserved;
+    DBTYPE wType;
+    BYTE bPrecision;
+    BYTE bScale;
+} DBCOLUMNACCESS;
+
+typedef DWORD DBROWSTATUS;
+
+enum DBROWSTATUSENUM
+{
+    DBROWSTATUS_S_OK         = 0,
+    /* FIXME */
+    DBROWSTATUS_E_FAIL       = 19,
+
+};
+
+typedef DWORD DBPART;
+
+enum DBPARTENUM
+{
+    DBPART_INVALID  = 0,
+    DBPART_VALUE    = 1,
+    DBPART_LENGTH   = 2,
+    DBPART_STATUS   = 4,
+};
+
+typedef DWORD DBPARAMIO;
+
+enum DBPARAMIOENUM
+{
+    DBPARAMIO_NOTPARAM = 0,
+    DBPARAMIO_INPUT    = 1,
+    DBPARAMIO_OUTPUT   = 2,
+};
+
+typedef DWORD DBMEMOWNER;
+
+enum DBMEMOWNERENUM
+{
+    DBMEMOWNER_CLIENTOWNED    = 0,
+    DBMEMOWNER_PROVIDEROWNED  = 1,
+};
+
+typedef struct tagDBOBJECT
+{
+    DWORD dwFlags;
+    IID iid;
+} DBOBJECT;
+
+typedef struct tagDBBINDEXT
+{
+    [size_is((ULONG)ulExtension)] BYTE *pExtension;
+    DBCOUNTITEM ulExtension;
+} DBBINDEXT;
+
+typedef struct tagDBBINDING
+{
+    DBORDINAL iOrdinal;
+    DBBYTEOFFSET obValue;
+    DBBYTEOFFSET obLength;
+    DBBYTEOFFSET obStatus;
+    ITypeInfo *pTypeInfo;
+    DBOBJECT *pObject;
+    DBBINDEXT *pBindExt;
+    DBPART dwPart;
+    DBMEMOWNER dwMemOwner;
+    DBPARAMIO eParamIO;
+    DBLENGTH cbMaxLen;
+    DWORD dwFlags;
+    DBTYPE wType;
+    BYTE bPrecision;
+    BYTE bScale;
+} DBBINDING;
+
+typedef ULONG_PTR HACCESSOR;
+
+cpp_quote("#define DB_INVALID_HACCESSOR 0x00")
+
+typedef ULONG_PTR HROW;
+
+cpp_quote("#define DB_NULL_HROW 0x00")
+
+typedef ULONG_PTR HWATCHREGION;
+
+cpp_quote("#define DBWATCHREGION_NULL NULL")
+
+typedef ULONG_PTR HCHAPTER;
+
+cpp_quote("#define DB_NULL_HCHAPTER 0x00")
+
+typedef struct tagDBPARAMS
+{
+    void *pData;
+    DB_UPARAMS cParamSets;
+    HACCESSOR hAccessor;
+} DBPARAMS;
+
+typedef DWORD DBASYNCHOP;
+
+enum DBASYNCHOPENUM
+{
+    DBSYNCHOP_OPEN,
+};
+
+typedef DWORD DBASYNCHPHASE;
+
+enum DBASYNCHPHASEENUM
+{
+    DBASYNCHPHASE_INITIALIZATION,
+    DBASYNCHPHASE_POPULATION,
+    DBASYNCHPHASE_COMPLETE,
+    DBASYNCHPHASE_CANCELED,
+};
+
+typedef struct tagRMTPACK
+{
+    ISequentialStream *pISeqStream;
+    ULONG cbData;
+    ULONG cBSTR;
+    [size_is(cBSTR)] BSTR *rgBSTR;
+    ULONG cVARIANT;
+    [size_is(cVARIANT)] VARIANT *rgVARIANT;
+    ULONG cIDISPATCH;
+    [size_is(cIDISPATCH)] IDispatch **rgIDISPATCH;
+    ULONG cIUNKNOWN;
+    [size_is(cIUNKNOWN)] IUnknown **rgIUNKNOWN;
+    ULONG cPROPVARIANT;
+    [size_is(cPROPVARIANT)] PROPVARIANT *rgPROPVARIANT;
+    ULONG cArray;
+    [size_is(cArray)] VARIANT *rgArray;
+} RMTPACK;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/usb.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/usb.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/usb.h	(revision 25949)
@@ -92,4 +92,62 @@
 typedef PVOID USBD_INTERFACE_HANDLE;
 
+#define USBD_STATUS_SUCCESS                          ((USBD_STATUS)0x00000000)
+#define USBD_STATUS_PENDING                          ((USBD_STATUS)0x40000000)
+#define USBD_STATUS_CRC                              ((USBD_STATUS)0xC0000001)
+#define USBD_STATUS_BTSTUFF                          ((USBD_STATUS)0xC0000002)
+#define USBD_STATUS_DATA_TOGGLE_MISMATCH             ((USBD_STATUS)0xC0000003)
+#define USBD_STATUS_STALL_PID                        ((USBD_STATUS)0xC0000004)
+#define USBD_STATUS_DEV_NOT_RESPONDING               ((USBD_STATUS)0xC0000005)
+#define USBD_STATUS_PID_CHECK_FAILURE                ((USBD_STATUS)0xC0000006)
+#define USBD_STATUS_UNEXPECTED_PID                   ((USBD_STATUS)0xC0000007)
+#define USBD_STATUS_DATA_OVERRUN                     ((USBD_STATUS)0xC0000008)
+#define USBD_STATUS_DATA_UNDERRUN                    ((USBD_STATUS)0xC0000009)
+#define USBD_STATUS_RESERVED1                        ((USBD_STATUS)0xC000000A)
+#define USBD_STATUS_RESERVED2                        ((USBD_STATUS)0xC000000B)
+#define USBD_STATUS_BUFFER_OVERRUN                   ((USBD_STATUS)0xC000000C)
+#define USBD_STATUS_BUFFER_UNDERRUN                  ((USBD_STATUS)0xC000000D)
+#define USBD_STATUS_NOT_ACCESSED                     ((USBD_STATUS)0xC000000F)
+#define USBD_STATUS_FIFO                             ((USBD_STATUS)0xC0000010)
+#define USBD_STATUS_XACT_ERROR                       ((USBD_STATUS)0xC0000011)
+#define USBD_STATUS_BABBLE_DETECTED                  ((USBD_STATUS)0xC0000012)
+#define USBD_STATUS_DATA_BUFFER_ERROR                ((USBD_STATUS)0xC0000013)
+#define USBD_STATUS_ENDPOINT_HALTED                  ((USBD_STATUS)0xC0000030)
+#define USBD_STATUS_INVALID_URB_FUNCTION             ((USBD_STATUS)0x80000200)
+#define USBD_STATUS_INVALID_PARAMETER                ((USBD_STATUS)0x80000300)
+#define USBD_STATUS_ERROR_BUSY                       ((USBD_STATUS)0x80000400)
+#define USBD_STATUS_INVALID_PIPE_HANDLE              ((USBD_STATUS)0x80000600)
+#define USBD_STATUS_NO_BANDWIDTH                     ((USBD_STATUS)0x80000700)
+#define USBD_STATUS_INTERNAL_HC_ERROR                ((USBD_STATUS)0x80000800)
+#define USBD_STATUS_ERROR_SHORT_TRANSFER             ((USBD_STATUS)0x80000900)
+#define USBD_STATUS_BAD_START_FRAME                  ((USBD_STATUS)0xC0000A00)
+#define USBD_STATUS_ISOCH_REQUEST_FAILED             ((USBD_STATUS)0xC0000B00)
+#define USBD_STATUS_FRAME_CONTROL_OWNED              ((USBD_STATUS)0xC0000C00)
+#define USBD_STATUS_FRAME_CONTROL_NOT_OWNED          ((USBD_STATUS)0xC0000D00)
+#define USBD_STATUS_NOT_SUPPORTED                    ((USBD_STATUS)0xC0000E00)
+#define USBD_STATUS_INVALID_CONFIGURATION_DESCRIPTOR ((USBD_STATUS)0xC0000F00)
+#define USBD_STATUS_INSUFFICIENT_RESOURCES           ((USBD_STATUS)0xC0001000)
+#define USBD_STATUS_SET_CONFIG_FAILED                ((USBD_STATUS)0xC0002000)
+#define USBD_STATUS_BUFFER_TOO_SMALL                 ((USBD_STATUS)0xC0003000)
+#define USBD_STATUS_INTERFACE_NOT_FOUND              ((USBD_STATUS)0xC0004000)
+#define USBD_STATUS_INVALID_PIPE_FLAGS               ((USBD_STATUS)0xC0005000)
+#define USBD_STATUS_TIMEOUT                          ((USBD_STATUS)0xC0006000)
+#define USBD_STATUS_DEVICE_GONE                      ((USBD_STATUS)0xC0007000)
+#define USBD_STATUS_STATUS_NOT_MAPPED                ((USBD_STATUS)0xC0008000)
+#define USBD_STATUS_CANCELED                         ((USBD_STATUS)0xC0010000)
+#define USBD_STATUS_ISO_NOT_ACCESSED_BY_HW           ((USBD_STATUS)0xC0020000)
+#define USBD_STATUS_ISO_TD_ERROR                     ((USBD_STATUS)0xC0030000)
+#define USBD_STATUS_ISO_NA_LATE_USBPORT              ((USBD_STATUS)0xC0040000)
+#define USBD_STATUS_ISO_NOT_ACCESSED_LATE            ((USBD_STATUS)0xC0050000)
+
+#define USBD_SUCCESS(Status) ((USBD_STATUS)(Status) >= 0)
+#define USBD_PENDING(Status) ((ULONG)(Status) >> 30 == 1)
+#define USBD_ERROR(Status)   ((USBD_STATUS)(Status) < 0)
+
+typedef struct _USBD_VERSION_INFORMATION {
+    ULONG  USBDI_Version;
+    ULONG  Supported_USB_Version;
+} USBD_VERSION_INFORMATION;
+typedef struct _USBD_VERSION_INFORMATION *PUSBD_VERSION_INFORMATION;
+
 typedef enum _USBD_PIPE_TYPE {
     UsbdPipeTypeControl,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/wdm.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/wdm.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/wdm.h	(revision 25949)
@@ -68,4 +68,9 @@
   DISPATCHER_HEADER  Header;
 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
+
+typedef struct _KSEMAPHORE {
+  DISPATCHER_HEADER  Header;
+  LONG Limit;
+} KSEMAPHORE, *PKSEMAPHORE, *PRKSEMAPHORE;
 
 typedef struct _KDPC {
@@ -139,5 +144,5 @@
 typedef struct _ETHREAD *PETHREAD;
 typedef struct _FREE_FUNCTION *PFREE_FUNCTION;
-typedef struct _KTHREAD *PKTHREAD;
+typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
 typedef struct _EPROCESS *PEPROCESS;
 typedef struct _ERESOURCE *PERESOURCE;
@@ -1050,4 +1055,5 @@
 
 NTSTATUS  WINAPI IoAllocateDriverObjectExtension(PDRIVER_OBJECT,PVOID,ULONG,PVOID*);
+PVOID     WINAPI IoAllocateErrorLogEntry(PVOID,UCHAR);
 PIRP      WINAPI IoAllocateIrp(CCHAR,BOOLEAN);
 NTSTATUS  WINAPI IoCreateDevice(DRIVER_OBJECT*,ULONG,UNICODE_STRING*,DEVICE_TYPE,ULONG,BOOLEAN,DEVICE_OBJECT**);
@@ -1068,6 +1074,10 @@
 void      WINAPI KeQueryTickCount(LARGE_INTEGER*);
 ULONG     WINAPI KeQueryTimeIncrement(void);
-
+LONG      WINAPI KeReleaseSemaphore(PRKSEMAPHORE,KPRIORITY,LONG,BOOLEAN);
+KPRIORITY WINAPI KeSetPriorityThread(PKTHREAD,KPRIORITY);
+
+PVOID     WINAPI MmAllocateContiguousMemory(SIZE_T,PHYSICAL_ADDRESS);
 PVOID     WINAPI MmAllocateNonCachedMemory(SIZE_T);
+PMDL      WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS,PHYSICAL_ADDRESS,PHYSICAL_ADDRESS,SIZE_T);
 void      WINAPI MmFreeNonCachedMemory(PVOID,SIZE_T);
 MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/winsplp.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/winsplp.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/winsplp.h	(revision 25949)
@@ -290,6 +290,5 @@
                  DWORD fdwFlags, DWORD fdwOptions, LPVOID pPrinterNotifyOptions);
  BOOL   (WINAPI *fpFindClosePrinterChangeNotification)(HANDLE hChange);
- BOOL   (WINAPI *fpAddPortEx)(HANDLE hMonitor, LPWSTR pName, DWORD Level,
-                 LPBYTE lpBuffer, LPWSTR lpMonitorName);
+ BOOL   (WINAPI *fpAddPortEx)(LPWSTR, DWORD, LPBYTE, LPWSTR);
  BOOL   (WINAPI *fpShutDown)(LPVOID pvReserved);
  BOOL   (WINAPI *fpRefreshPrinterChangeNotification)(HANDLE hPrinter,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dinput.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dinput.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dinput.h	(revision 25949)
@@ -1116,5 +1116,5 @@
 typedef struct _DIACTIONA {
 	UINT_PTR	uAppData;
-	DWORD		dwSemantics;
+	DWORD		dwSemantic;
 	DWORD		dwFlags;
 	union {
@@ -1130,5 +1130,5 @@
 typedef struct _DIACTIONW {
 	UINT_PTR	uAppData;
-	DWORD		dwSemantics;
+	DWORD		dwSemantic;
 	DWORD		dwFlags;
 	union {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dsound.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dsound.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dsound.h	(revision 25949)
@@ -1084,5 +1084,5 @@
 #define IDirectSound3DBuffer_GetVelocity(p,a)              (p)->lpVtbl->GetVelocity(p,a)
 #define IDirectSound3DBuffer_SetAllParameters(p,a,b)       (p)->lpVtbl->SetAllParameters(p,a,b)
-#define IDirectSound3DBuffer_SetConeAngles(p,a,b)          (p)->lpVtbl->SetConeAngles(p,a,b)
+#define IDirectSound3DBuffer_SetConeAngles(p,a,b,c)        (p)->lpVtbl->SetConeAngles(p,a,b,c)
 #define IDirectSound3DBuffer_SetConeOrientation(p,a,b,c,d) (p)->lpVtbl->SetConeOrientation(p,a,b,c,d)
 #define IDirectSound3DBuffer_SetConeOutsideVolume(p,a,b)   (p)->lpVtbl->SetConeOutsideVolume(p,a,b)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dwmapi.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dwmapi.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dwmapi.h	(revision 25949)
@@ -41,4 +41,14 @@
 DECLARE_HANDLE(HTHUMBNAIL);
 
+typedef struct _MilMatrix3x2D
+{
+    DOUBLE S_11;
+    DOUBLE S_12;
+    DOUBLE S_21;
+    DOUBLE S_22;
+    DOUBLE DX;
+    DOUBLE DY;
+} MilMatrix3x2D;
+
 DWMAPI DwmEnableComposition(UINT);
 DWMAPI DwmEnableMMCSS(BOOL);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/evntrace.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/evntrace.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/evntrace.h	(revision 25949)
@@ -186,4 +186,25 @@
 };
 
+typedef struct _EVENT_TRACE_PROPERTIES
+{
+    WNODE_HEADER Wnode;
+    ULONG BufferSize;
+    ULONG MinimumBuffers;
+    ULONG MaximumBuffers;
+    ULONG MaximumFileSize;
+    ULONG LogFileMode;
+    ULONG FlushTimer;
+    LONG AgeLimit;
+    ULONG NumberOfBuffers;
+    ULONG FreeBuffers;
+    ULONG EventsLost;
+    ULONG BuffersWritten;
+    ULONG LogBuffersLost;
+    ULONG RealTimeBuffersLost;
+    HANDLE LoggerThreadId;
+    ULONG LoggerFileNameOffset;
+    ULONG LoggerNameOffset;
+} EVENT_TRACE_PROPERTIES, *PEVENT_TRACE_PROPERTIES;
+
 ULONG WINAPI CloseTrace(TRACEHANDLE);
 ULONG WINAPI EnableTrace(ULONG,ULONG,ULONG,LPCGUID,TRACEHANDLE);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusenums.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusenums.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusenums.h	(revision 25949)
@@ -299,4 +299,11 @@
     HotkeyPrefixShow   = 1,
     HotkeyPrefixHide   = 2
+};
+
+enum PaletteFlags
+{
+    PaletteFlagsHasAlpha        = 1,
+    PaletteFlagsGrayScale       = 2,
+    PaletteFlagsHalftone        = 4
 };
 
@@ -465,4 +472,5 @@
 typedef enum HotkeyPrefix HotkeyPrefix;
 typedef enum PenAlignment GpPenAlignment;
+typedef enum PaletteFlags PaletteFlags;
 typedef enum ImageCodecFlags ImageCodecFlags;
 typedef enum CombineMode CombineMode;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h	(revision 25949)
@@ -55,4 +55,5 @@
     PixelFormat,BitmapData*);
 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap*,INT,INT,ARGB);
+GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap*,REAL,REAL);
 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap*,BitmapData*);
 GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL,REAL,REAL,REAL,PixelFormat,GpBitmap*,GpBitmap**);
@@ -72,4 +73,5 @@
 GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap*,HICON*);
 GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect*);
+GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect*,const VOID*,const UINT);
 
 /* Brush */
@@ -77,4 +79,10 @@
 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush*);
 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush*,GpBrushType*);
+
+/* CachedBitmap */
+GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap*,GpGraphics*,
+    GpCachedBitmap**);
+GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap*);
+GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics*,GpCachedBitmap*,INT,INT);
 
 /* CustomLineCap */
@@ -84,5 +92,7 @@
 GpStatus WINGDIPAPI GdipDeleteCustomLineCap(GpCustomLineCap*);
 GpStatus WINGDIPAPI GdipGetCustomLineCapBaseCap(GpCustomLineCap*,GpLineCap*);
+GpStatus WINGDIPAPI GdipSetCustomLineCapBaseCap(GpCustomLineCap*,GpLineCap);
 GpStatus WINGDIPAPI GdipGetCustomLineCapBaseInset(GpCustomLineCap*,REAL*);
+GpStatus WINGDIPAPI GdipSetCustomLineCapBaseInset(GpCustomLineCap*,REAL);
 GpStatus WINGDIPAPI GdipSetCustomLineCapStrokeCaps(GpCustomLineCap*,GpLineCap,
     GpLineCap);
@@ -90,4 +100,6 @@
 GpStatus WINGDIPAPI GdipSetCustomLineCapStrokeJoin(GpCustomLineCap*,GpLineJoin);
 GpStatus WINGDIPAPI GdipGetCustomLineCapWidthScale(GpCustomLineCap*,REAL*);
+GpStatus WINGDIPAPI GdipSetCustomLineCapWidthScale(GpCustomLineCap*,REAL);
+GpStatus WINGDIPAPI GdipSetCustomLineCapBaseInset(GpCustomLineCap*,REAL);
 
 /* Font */
@@ -114,4 +126,6 @@
 GpStatus WINGDIPAPI GdipDeletePrivateFontCollection(GpFontCollection**);
 GpStatus WINGDIPAPI GdipPrivateAddFontFile(GpFontCollection*, GDIPCONST WCHAR*);
+GpStatus WINGDIPAPI GdipPrivateAddMemoryFont(GpFontCollection*,
+        GDIPCONST void*,INT);
 GpStatus WINGDIPAPI GdipGetFontCollectionFamilyCount(GpFontCollection*, INT*);
 GpStatus WINGDIPAPI GdipGetFontCollectionFamilyList(GpFontCollection*, INT,
@@ -144,4 +158,5 @@
 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND,GpGraphics**);
 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND,GpGraphics**);
+HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void);
 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *);
 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics*,GpPen*,REAL,REAL,REAL,REAL,REAL,REAL);
@@ -161,4 +176,6 @@
 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics*,GpPen*,GDIPCONST GpPointF*,INT,INT,INT,REAL);
 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics*,GpPen*,GDIPCONST GpPoint*,INT,INT,INT,REAL);
+GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics*,GDIPCONST UINT16*,INT,
+    GDIPCONST GpFont*,GDIPCONST GpBrush*,GDIPCONST PointF*,INT,GDIPCONST GpMatrix*);
 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics*,GpPen*,REAL,REAL,REAL,REAL);
 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics*,GpPen*,INT,INT,INT,INT);
@@ -227,4 +244,6 @@
 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics*,REAL*);
 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics*,REAL*);
+GpStatus WINGDIPAPI GdipGetImageDecoders(UINT,UINT,ImageCodecInfo*);
+GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT*,UINT*);
 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage*,GpGraphics**);
 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics*,InterpolationMode*);
@@ -248,7 +267,15 @@
     INT, GDIPCONST GpFont*, GDIPCONST RectF*, GDIPCONST GpStringFormat*, INT,
     GpRegion**);
+GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics*,GDIPCONST UINT16*,INT,
+    GDIPCONST GpFont*,GDIPCONST PointF*,INT,GDIPCONST GpMatrix*,RectF*);
 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics*,GDIPCONST WCHAR*,INT,
     GDIPCONST GpFont*,GDIPCONST RectF*,GDIPCONST GpStringFormat*,RectF*,INT*,INT*);
 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics*,GDIPCONST GpMatrix*,GpMatrixOrder);
+GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR*,HDC,EmfType,
+    GDIPCONST GpRectF*,MetafileFrameUnit,GDIPCONST WCHAR*,GpMetafile**);
+GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR*,HDC,EmfType,
+    GDIPCONST GpRect*,MetafileFrameUnit,GDIPCONST WCHAR*,GpMetafile**);
+GpStatus WINGDIPAPI GdipRecordMetafileI(HDC,EmfType,GDIPCONST GpRect*,
+    MetafileFrameUnit,GDIPCONST WCHAR*,GpMetafile**);
 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics*,HDC);
 GpStatus WINGDIPAPI GdipResetClip(GpGraphics*);
@@ -259,4 +286,5 @@
 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics*,REAL,REAL,GpMatrixOrder);
 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics*,HRGN,CombineMode);
+GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics*,GpGraphics*,CombineMode);
 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics*,GpPath*,CombineMode);
 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics*,REAL,REAL,REAL,REAL,CombineMode);
@@ -269,4 +297,5 @@
 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics*,GpUnit);
 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics*,PixelOffsetMode);
+GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics*,INT,INT);
 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics*,SmoothingMode);
 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics*,UINT);
@@ -346,4 +375,13 @@
 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath*);
 GpStatus WINGDIPAPI GdipTransformPath(GpPath*,GpMatrix*);
+GpStatus WINGDIPAPI GdipWarpPath(GpPath*,GpMatrix*,GDIPCONST GpPointF*,INT,REAL,
+    REAL,REAL,REAL,WarpMode,REAL);
+GpStatus WINGDIPAPI GdipWidenPath(GpPath*,GpPen*,GpMatrix*,REAL);
+
+/* HatchBrush */
+GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle,ARGB,ARGB,GpHatch**);
+GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch*,ARGB*);
+GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch*,ARGB*);
+GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch*,HatchStyle*);
 
 /* Image */
@@ -362,4 +400,5 @@
 GpStatus WINGDIPAPI GdipGetImageItemData(GpImage*,ImageItemData*);
 GpStatus WINGDIPAPI GdipGetImagePalette(GpImage*,ColorPalette*,INT);
+GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage*,INT*);
 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage*,PixelFormat*);
 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage*,GUID*);
@@ -373,4 +412,5 @@
 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage*,PROPID,UINT*);
 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage*,UINT*,UINT*);
+GpStatus WINGDIPAPI GdipImageForceValidation(GpImage*);
 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage*,GDIPCONST GUID*,UINT*);
 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage*,UINT*);
@@ -392,4 +432,6 @@
 GpStatus WINGDIPAPI GdipCreateImageAttributes(GpImageAttributes**);
 GpStatus WINGDIPAPI GdipDisposeImageAttributes(GpImageAttributes*);
+GpStatus WINGDIPAPI GdipSetImageAttributesCachedBackground(GpImageAttributes*,
+    BOOL);
 GpStatus WINGDIPAPI GdipSetImageAttributesColorKeys(GpImageAttributes*,
     ColorAdjustType,BOOL,ARGB,ARGB);
@@ -397,4 +439,18 @@
     ColorAdjustType,BOOL,GDIPCONST ColorMatrix*,GDIPCONST ColorMatrix*,
     ColorMatrixFlags);
+GpStatus WINGDIPAPI GdipSetImageAttributesGamma(GpImageAttributes*,
+    ColorAdjustType,BOOL,REAL);
+GpStatus WINGDIPAPI GdipSetImageAttributesNoOp(GpImageAttributes*,
+    ColorAdjustType,BOOL);
+GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannel(GpImageAttributes*,
+    ColorAdjustType,BOOL,ColorChannelFlags);
+GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannelColorProfile(
+    GpImageAttributes*,ColorAdjustType,BOOL,GDIPCONST WCHAR*);
+GpStatus WINGDIPAPI GdipSetImageAttributesRemapTable(GpImageAttributes*,
+    ColorAdjustType,BOOL,UINT,GDIPCONST ColorMap*);
+GpStatus WINGDIPAPI GdipSetImageAttributesThreshold(GpImageAttributes*,
+    ColorAdjustType,BOOL,REAL);
+GpStatus WINGDIPAPI GdipSetImageAttributesToIdentity(GpImageAttributes*,
+    ColorAdjustType);
 GpStatus WINGDIPAPI GdipSetImageAttributesWrapMode(GpImageAttributes*,WrapMode,
     ARGB,BOOL);
@@ -426,9 +482,16 @@
 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient*,ARGB*,REAL*,INT);
 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient*,INT*);
+GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient*);
+GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient*,REAL,GpMatrixOrder);
+GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient*,REAL,REAL,
+    GpMatrixOrder);
 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient*,ARGB,ARGB);
 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient*,BOOL);
 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient*,REAL,REAL);
+GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient*,GDIPCONST GpMatrix*);
 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient*,REAL,REAL);
 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient*,GpWrapMode);
+GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient*,REAL,REAL,
+    GpMatrixOrder);
 
 /* Matrix */
@@ -476,4 +539,8 @@
 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromWmf(HMETAFILE,GDIPCONST WmfPlaceableFileHeader*,MetafileHeader*);
 
+/* Notification */
+GpStatus WINAPI GdiplusNotificationHook(ULONG_PTR*);
+void WINAPI GdiplusNotificationUnhook(ULONG_PTR);
+
 /* PathGradientBrush */
 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF*,INT,GpWrapMode,GpPathGradient**);
@@ -489,4 +556,6 @@
 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient*,BOOL*);
 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient*,INT*);
+GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient*,
+    GDIPCONST ARGB*,GDIPCONST REAL*,INT);
 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient*,GpRectF*);
 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient*,GpRect*);
@@ -536,4 +605,6 @@
 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen*,GpDashStyle*);
 GpStatus WINGDIPAPI GdipGetPenMode(GpPen*,GpPenAlignment*);
+GpStatus WINGDIPAPI GdipResetPenTransform(GpPen*);
+GpStatus WINGDIPAPI GdipScalePenTransform(GpPen*,REAL,REAL,GpMatrixOrder);
 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen*,GpBrush*);
 GpStatus WINGDIPAPI GdipSetPenColor(GpPen*,ARGB);
@@ -634,7 +705,13 @@
 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture*,GpMatrix*);
 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture*, GpWrapMode*);
+GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture*,
+    GDIPCONST GpMatrix*,GpMatrixOrder);
 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture*);
+GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture*,REAL,GpMatrixOrder);
+GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture*,REAL,REAL,GpMatrixOrder);
 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *,GDIPCONST GpMatrix*);
 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture*, GpWrapMode);
+GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture*,REAL,REAL,
+    GpMatrixOrder);
 
 /* Without wrapper methods */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusimaging.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusimaging.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusimaging.h	(revision 25949)
@@ -40,4 +40,8 @@
 DEFINE_GUID(ImageFormatEXIF,      0xb96b3cb2, 0x728, 0x11d3, 0x9d, 0x7b, 0, 0, 0xf8, 0x1e, 0xf3, 0x2e);
 DEFINE_GUID(ImageFormatIcon,      0xb96b3cb5, 0x728, 0x11d3, 0x9d, 0x7b, 0, 0, 0xf8, 0x1e, 0xf3, 0x2e);
+
+DEFINE_GUID(FrameDimensionTime,       0x6aedbd6d, 0x3fb5, 0x418a, 0x83, 0xa6, 0x7f, 0x45, 0x22, 0x9d, 0xc8, 0x72);
+DEFINE_GUID(FrameDimensionPage,       0x7462dc86, 0x6180, 0x4c7e, 0x8e, 0x3f, 0xee, 0x73, 0x33, 0xa7, 0xa4, 0x83);
+DEFINE_GUID(FrameDimensionResolution, 0x84236f7b, 0x3bd3, 0x428f, 0x8d, 0xab, 0x4e, 0xa1, 0x43, 0x9c, 0xa3, 0x15);
 
 enum ImageLockMode
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/hlink.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/hlink.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/hlink.idl	(revision 25949)
@@ -161,5 +161,5 @@
 
 /*****************************************************************************
- *    IHlink interface
+ *    IHlinkSite interface
  */
 [
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ks.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ks.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ks.h	(revision 25949)
@@ -29,5 +29,47 @@
 #define _KS_
 
-/* FIXME dummy placeholder for now */
+typedef union tagKSIDENTIFIER
+{
+    struct
+    {
+        GUID Set;
+        ULONG Id;
+        ULONG Flags;
+    } DUMMYSTRUCTNAME;
+    LONGLONG Alignment;
+} KSIDENTIFIER;
+
+typedef KSIDENTIFIER KSPROPERTY, *PKSPROPERTY, KSMETHOD, *PKSMETHOD, KSEVENT, *PKSEVENT;
+
+typedef enum
+{
+    KSPIN_DATAFLOW_IN = 1,
+    KSPIN_DATAFLOW_OUT
+} KSPIN_DATAFLOW, *PKSPIN_DATAFLOW;
+
+#define KSDATAFORMAT_BIT_TEMPORAL_COMPRESSION 0
+#define KSDATAFORMAT_BIT_ATTRIBUTES 1
+#define KSDATAFORMAT_TEMPORAL_COMPRESSION (1 << 0)
+#define KSDATAFORMAT_ATTRIBUTES 1 (1 << 1)
+
+#define KSDATARANGE_BIT_ATTRIBUTES 1
+#define KSDATARANGE_BIT_REQUIRED_ATTRIBUTES 2
+#define KSDATARANGE_ATTRIBUTES (1 << 1)
+#define KSDATARANGE_REQUIRED_ATTRIBUTES (1 << 2)
+
+typedef union unionKSDATAFORMAT
+{
+    struct
+    {
+        ULONG FormatSize;
+        ULONG Flags;
+        ULONG SampleSize;
+        ULONG Reserved;
+        GUID MajorFormat;
+        GUID SubFormat;
+        GUID Specifier;
+    } DUMMYSTRUCTNAME;
+    LONGLONG Alignment;
+} KSDATAFORMAT, *PKSDATAFORMAT, KSDATARANGE, *PKSDATARANGE;
 
 #endif  /* _KS_ */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ksmedia.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ksmedia.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ksmedia.h	(revision 25949)
@@ -44,3 +44,101 @@
 #define KSAUDIO_SPEAKER_7POINT1 (KSAUDIO_SPEAKER_5POINT1 | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER)
 
+typedef LONGLONG REFERENCE_TIME;
+
+typedef enum
+{
+    eConnTypeUnknown = 0,
+    eConnType3Point5mm,
+    eConnTypeQuarter,
+    eConnTypeAtapiInternal,
+    eConnTypeRCA,
+    eConnTypeOptical,
+    eConnTypeOtherDigital,
+    eConnTypeOtherAnalog,
+    eConnTypeMultichannelAnalogDIN,
+    eConnTypeXlrProfessional,
+    eConnTypeRj11Modem,
+    eConnTypeCombination
+} EPcxConnectionType;
+
+typedef enum
+{
+    eGeoLocRear = 1,
+    eGeoLocFront,
+    eGeoLocLeft,
+    eGeoLocRight,
+    eGeoLocTop,
+    eGeoLocBottom,
+    eGeoLocRearPanel,
+    eGeoLocRiser,
+    eGeoLocInsideMobileLid,
+    eGeoLocDrivebay,
+    eGeoLocHDMI,
+    eGeoLocOutsideMobileLid,
+    eGeoLocATAPI,
+    eGeoLocReserved5,
+    eGeoLocReserved6
+} EPcxGeoLocation;
+
+typedef enum
+{
+    eGenLocPrimaryBox = 0,
+    eGenLocInternal,
+    eGenLocSeparate,
+    eGenLocOther
+} EPcxGenLocation;
+
+typedef enum
+{
+    ePortConnJack = 0,
+    ePortConnIntegratedDevice,
+    ePortConnBothIntegratedAndJack,
+    ePortConnUnknown
+} EPxcPortConnection;
+
+typedef struct
+{
+    DWORD ChannelMapping;
+    COLORREF Color;
+    EPcxConnectionType ConnectionType;
+    EPcxGeoLocation GeoLocation;
+    EPcxGenLocation GenLocation;
+    EPxcPortConnection PortConnection;
+    BOOL IsConnected;
+} KSJACK_DESCRIPTION;
+
+typedef KSJACK_DESCRIPTION *PKSJACK_DESCRIPTION;
+
+typedef enum
+{
+    KSJACK_SINK_CONNECTIONTYPE_HDMI = 0,
+    KSJACK_SINK_CONNECTIONTYPE_DISPLAYPORT
+} KSJACK_SINK_CONNECTIONTYPE;
+
+#define MAX_SINK_DESCRIPTION_NAME_LENGTH 32
+
+typedef struct _tagKSJACK_SINK_INFORMATION
+{
+    KSJACK_SINK_CONNECTIONTYPE ConnType;
+    WORD ManufacturerId;
+    WORD ProductId;
+    WORD AudioLatency;
+    BOOL HDCPCapable;
+    BOOL AICapable;
+    UCHAR SinkDescriptionLength;
+    WCHAR SinkDescription[MAX_SINK_DESCRIPTION_NAME_LENGTH];
+    LUID PortId;
+} KSJACK_SINK_INFORMATION;
+
+#define JACKDESC2_PRESENCE_DETECT_CAPABILITY 0x1
+#define JACKDESC2_DYNAMIC_FORMAT_CHANGE_CAPABILITY 0x2
+
+typedef struct _tagKSJACK_DESCRIPTION2
+{
+    DWORD DeviceStateInfo;
+    DWORD JackCapabilities;
+} KSJACK_DESCRIPTION2;
+
+typedef struct _tagKSJACK_DESCRIPTION2 *PKSJACK_DESCRIPTION2;
+
 #endif  /* _KSMEDIA_ */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/lmaccess.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/lmaccess.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/lmaccess.h	(revision 25949)
@@ -477,4 +477,5 @@
 NET_API_STATUS WINAPI NetUserEnum(LPCWSTR,DWORD,DWORD,LPBYTE*,DWORD,LPDWORD,LPDWORD,LPDWORD);
 NET_API_STATUS WINAPI NetUserGetInfo(LPCWSTR,LPCWSTR,DWORD,LPBYTE*);
+NET_API_STATUS WINAPI NetUserGetGroups(LPCWSTR,LPCWSTR,DWORD,LPBYTE*,DWORD,LPDWORD,LPDWORD);
 NET_API_STATUS WINAPI NetUserGetLocalGroups(LPCWSTR,LPCWSTR,DWORD,DWORD,LPBYTE*,DWORD,LPDWORD,LPDWORD);
 NET_API_STATUS WINAPI NetUserModalsGet(LPCWSTR,DWORD,LPBYTE*);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapi.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapi.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapi.h	(revision 25949)
@@ -37,5 +37,5 @@
 #ifndef __LHANDLE
 #define __LHANDLE
-typedef ULONG                   LHANDLE, *LPLHANDLE;
+typedef ULONG_PTR               LHANDLE, *LPLHANDLE;
 #endif
 #define lhSessionNull           ((LHANDLE)0)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapidefs.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapidefs.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapidefs.h	(revision 25949)
@@ -1,4 +1,5 @@
 /*
  * Copyright (C) 1998 Justin Bradford
+ * Copyright (c) 2009 Owen Rudge for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -93,6 +94,5 @@
 typedef struct IABContainer IABContainer;
 typedef IABContainer *LPABCONT;
-typedef struct IAttach IAttach;
-typedef IAttach *LPATTACH;
+typedef struct IAttach *LPATTACH;
 typedef struct IDistList IDistList;
 typedef IDistList *LPDISTLIST;
@@ -100,16 +100,11 @@
 typedef IMailUser *LPMAILUSER;
 typedef struct IMAPIAdviseSink *LPMAPIADVISESINK;
-typedef struct IMAPIContainer IMAPIContainer;
-typedef IMAPIContainer *LPMAPICONTAINER;
-typedef struct IMAPIFolder IMAPIFolder;
-typedef IMAPIFolder *LPMAPIFOLDER;
+typedef struct IMAPIContainer *LPMAPICONTAINER;
+typedef struct IMAPIFolder *LPMAPIFOLDER;
 typedef struct IMAPIProgress IMAPIProgress;
 typedef IMAPIProgress *LPMAPIPROGRESS;
 typedef struct IMAPIStatus IMAPIStatus;
 typedef IMAPIStatus *LPMAPISTATUS;
-typedef struct IMessage IMessage;
-typedef IMessage *LPMESSAGE;
-typedef struct IMsgStore IMsgStore;
-typedef IMsgStore *LPMDB;
+typedef struct IMessage *LPMESSAGE;
 typedef struct IProfSect IProfSect;
 typedef IProfSect *LPPROFSECT;
@@ -166,4 +161,5 @@
 /* Flags for various calls */
 #define MAPI_MODIFY                   0x00000001U /* Object can be modified */
+#define MAPI_CREATE                   0x00000002U /* Object can be created */
 #define MAPI_ACCESS_MODIFY            MAPI_MODIFY /* Want write access */
 #define MAPI_ACCESS_READ              0x00000002U /* Want read access */
@@ -172,4 +168,5 @@
 #define MAPI_ACCESS_CREATE_CONTENTS   0x00000010U
 #define MAPI_ACCESS_CREATE_ASSOCIATED 0x00000020U
+#define MAPI_USE_DEFAULT              0x00000040U
 #define MAPI_UNICODE                  0x80000000U /* Strings in this call are Unicode */
 
@@ -179,4 +176,7 @@
 #define fMapiUnicode 0U
 #endif
+
+/* IMAPISession::OpenMessageStore() flags */
+#define MDB_NO_DIALOG           0x00000001
 
 /* Types of message receivers */
@@ -770,4 +770,7 @@
 typedef LONG (WINAPI NOTIFCALLBACK)(LPVOID,ULONG,LPNOTIFICATION);
 typedef NOTIFCALLBACK *LPNOTIFCALLBACK;
+
+/* IMAPIContainer::OpenEntry flags */
+#define MAPI_BEST_ACCESS    0x00000010
 
 /*****************************************************************************
@@ -905,18 +908,260 @@
 #define IMAPIProp_Release(p)                   (p)->lpVtbl->Release(p)
         /*** IMAPIProp methods ***/
-#define IMAPIProp_GetLastError(p,a,b,c)        (p)->lpVtbl->GetLastError(p,a,b,c)        
-#define IMAPIProp_SaveChanges(p,a)             (p)->lpVtbl->SaveChanges(p,a)             
-#define IMAPIProp_GetProps(p,a,b,c,d)          (p)->lpVtbl->GetProps(p,a,b,c,d)          
-#define IMAPIProp_GetPropList(p,a,b)           (p)->lpVtbl->GetPropList(p,a,b)           
-#define IMAPIProp_OpenProperty(p,a,b,c,d,e)    (p)->lpVtbl->OpenProperty(p,a,b,c,d,e)    
-#define IMAPIProp_SetProps(p,a,b,c)            (p)->lpVtbl->SetProps(p,a,b,c)            
-#define IMAPIProp_DeleteProps(p,a,b)           (p)->lpVtbl->DeleteProps(p,a,b)           
-#define IMAPIProp_CopyTo(p,a,b,c,d,e,f,g,h,i)  (p)->lpVtbl->CopyTo(p,a,b,c,d,e,f,g,h,i)  
-#define IMAPIProp_CopyProps(p,a,b,c,d,e,f,g)   (p)->lpVtbl->CopyProps(p,a,b,c,d,e,f,g)   
-#define IMAPIProp_GetNamesFromIDs(p,a,b,c,d,e) (p)->lpVtbl->GetNamesFromIDs(p,a,b,c,d,e) 
-#define IMAPIProp_GetIDsFromNames(p,a,b,c,d)   (p)->lpVtbl->GetIDsFromNames(p,a,b,c,d)   
+#define IMAPIProp_GetLastError(p,a,b,c)        (p)->lpVtbl->GetLastError(p,a,b,c)
+#define IMAPIProp_SaveChanges(p,a)             (p)->lpVtbl->SaveChanges(p,a)
+#define IMAPIProp_GetProps(p,a,b,c,d)          (p)->lpVtbl->GetProps(p,a,b,c,d)
+#define IMAPIProp_GetPropList(p,a,b)           (p)->lpVtbl->GetPropList(p,a,b)
+#define IMAPIProp_OpenProperty(p,a,b,c,d,e)    (p)->lpVtbl->OpenProperty(p,a,b,c,d,e)
+#define IMAPIProp_SetProps(p,a,b,c)            (p)->lpVtbl->SetProps(p,a,b,c)
+#define IMAPIProp_DeleteProps(p,a,b)           (p)->lpVtbl->DeleteProps(p,a,b)
+#define IMAPIProp_CopyTo(p,a,b,c,d,e,f,g,h,i)  (p)->lpVtbl->CopyTo(p,a,b,c,d,e,f,g,h,i)
+#define IMAPIProp_CopyProps(p,a,b,c,d,e,f,g)   (p)->lpVtbl->CopyProps(p,a,b,c,d,e,f,g)
+#define IMAPIProp_GetNamesFromIDs(p,a,b,c,d,e) (p)->lpVtbl->GetNamesFromIDs(p,a,b,c,d,e)
+#define IMAPIProp_GetIDsFromNames(p,a,b,c,d)   (p)->lpVtbl->GetIDsFromNames(p,a,b,c,d)
 #endif
 
 typedef IMAPIProp *LPMAPIPROP;
+
+#define KEEP_OPEN_READONLY      (0x00000001U)
+#define KEEP_OPEN_READWRITE     (0x00000002U)
+#define FORCE_SAVE              (0x00000004U)
+
+/*****************************************************************************
+ * IMsgStore interface
+ */
+#define INTERFACE IMsgStore
+DECLARE_INTERFACE_(IMsgStore,IMAPIProp)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    /*** IMAPIProp methods ***/
+    STDMETHOD(GetLastError)(THIS_ HRESULT hRes, ULONG ulFlags, LPMAPIERROR *lppErr) PURE;
+    STDMETHOD(SaveChanges)(THIS_ ULONG ulFlags) PURE;
+    STDMETHOD(GetProps)(THIS_ LPSPropTagArray lpPropTags, ULONG ulFlags, ULONG *lpValues, LPSPropValue *lppProps) PURE;
+    STDMETHOD(GetPropList)(THIS_ ULONG  ulFlags, LPSPropTagArray *lppPropTagArray) PURE;
+    STDMETHOD(OpenProperty)(THIS_ ULONG ulPropTag, LPCIID lpIid, ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lppUnk) PURE;
+    STDMETHOD(SetProps)(THIS_ ULONG cValues, LPSPropValue lpProps, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(DeleteProps)(THIS_ LPSPropTagArray lpPropTags, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyTo)(THIS_ ULONG ciidExclude, LPCIID lpIid, LPSPropTagArray lpProps, ULONG ulParam,
+                      LPMAPIPROGRESS lpProgress, LPCIID lpIface,LPVOID lpDest, ULONG ulFlags,
+                      LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyProps)(THIS_ LPSPropTagArray lpIncludeProps, ULONG ulParam, LPMAPIPROGRESS lpProgress,
+                         LPCIID lpIid, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems) PURE;
+    STDMETHOD(GetNamesFromIDs)(THIS_ LPSPropTagArray *lppPropTags, LPGUID lpIid, ULONG ulFlags, ULONG *lpCount,
+                               LPMAPINAMEID **lpppNames) PURE;
+    STDMETHOD(GetIDsFromNames)(THIS_ ULONG cPropNames, LPMAPINAMEID *lppNames, ULONG ulFlags, LPSPropTagArray *lppPropTags) PURE;
+    /*** IMsgStore methods ***/
+    STDMETHOD(Advise)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulEventMask, LPMAPIADVISESINK lpAdviseSink,
+                      ULONG * lpulConnection) PURE;
+    STDMETHOD(Unadvise)(THIS_ ULONG ulConnection) PURE;
+    STDMETHOD(CompareEntryIDs)(THIS_ ULONG cbEntryID1, LPENTRYID lpEntryID1, ULONG cbEntryID2, LPENTRYID lpEntryID2,
+                ULONG ulFlags, ULONG * lpulResult) PURE;
+    STDMETHOD(OpenEntry)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, LPCIID lpInterface, ULONG ulFlags, ULONG *lpulObjType,
+                LPUNKNOWN *lppUnk) PURE;
+    STDMETHOD(SetReceiveFolder)(THIS_ LPSTR lpszMessageClass, ULONG ulFlags, ULONG cbEntryID, LPENTRYID lpEntryID) PURE;
+    STDMETHOD(GetReceiveFolder)(THIS_ LPSTR lpszMessageClass, ULONG ulFlags, ULONG * lpcbEntryID, LPENTRYID *lppEntryID,
+                LPSTR *lppszExplicitClass) PURE;
+    STDMETHOD(GetReceiveFolderTable)(THIS_ ULONG ulFlags, LPMAPITABLE * lppTable) PURE;
+    STDMETHOD(StoreLogoff)(THIS_ ULONG * lpulFlags) PURE;
+    STDMETHOD(AbortSubmit)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulFlags) PURE;
+    STDMETHOD(GetOutgoingQueue)(THIS_ ULONG ulFlags, LPMAPITABLE * lppTable) PURE;
+    STDMETHOD(SetLockState)(THIS_ LPMESSAGE lpMessage, ULONG ulLockState) PURE;
+    STDMETHOD(FinishedMsg)(THIS_ ULONG ulFlags, ULONG cbEntryID, LPENTRYID lpEntryID) PURE;
+    STDMETHOD(NotifyNewMail)(THIS_ LPNOTIFICATION lpNotification) PURE;
+};
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+        /*** IUnknown methods ***/
+#define IMsgStore_QueryInterface(p,a,b)        (p)->lpVtbl->QueryInterface(p,a,b)
+#define IMsgStore_AddRef(p)                    (p)->lpVtbl->AddRef(p)
+#define IMsgStore_Release(p)                   (p)->lpVtbl->Release(p)
+        /*** IMAPIProp methods ***/
+#define IMsgStore_GetLastError(p,a,b,c)        (p)->lpVtbl->GetLastError(p,a,b,c)
+#define IMsgStore_SaveChanges(p,a)             (p)->lpVtbl->SaveChanges(p,a)
+#define IMsgStore_GetProps(p,a,b,c,d)          (p)->lpVtbl->GetProps(p,a,b,c,d)
+#define IMsgStore_GetPropList(p,a,b)           (p)->lpVtbl->GetPropList(p,a,b)
+#define IMsgStore_OpenProperty(p,a,b,c,d,e)    (p)->lpVtbl->OpenProperty(p,a,b,c,d,e)
+#define IMsgStore_SetProps(p,a,b,c)            (p)->lpVtbl->SetProps(p,a,b,c)
+#define IMsgStore_DeleteProps(p,a,b)           (p)->lpVtbl->DeleteProps(p,a,b)
+#define IMsgStore_CopyTo(p,a,b,c,d,e,f,g,h,i)  (p)->lpVtbl->CopyTo(p,a,b,c,d,e,f,g,h,i)
+#define IMsgStore_CopyProps(p,a,b,c,d,e,f,g)   (p)->lpVtbl->CopyProps(p,a,b,c,d,e,f,g)
+#define IMsgStore_GetNamesFromIDs(p,a,b,c,d,e) (p)->lpVtbl->GetNamesFromIDs(p,a,b,c,d,e)
+#define IMsgStore_GetIDsFromNames(p,a,b,c,d)   (p)->lpVtbl->GetIDsFromNames(p,a,b,c,d)
+        /*** IMsgStore methods ***/
+#define IMsgStore_Advise(p,a,b,c,d,e)            (p)->lpVtbl->Advise(p,a,b,c,d,e)
+#define IMsgStore_Unadvise(p,a)                  (p)->lpVtbl->Unadvise(p,a)
+#define IMsgStore_CompareEntryIDs(p,a,b,c,d,e,f) (p)->lpVtbl->CompareEntryIDs(p,a,b,c,d,e,f)
+#define IMsgStore_OpenEntry(p,a,b,c,d,e,f)       (p)->lpVtbl->OpenEntry(p,a,b,c,d,e,f)
+#define IMsgStore_SetReceiveFolder(p,a,b,c,d)    (p)->lpVtbl->SetReceiveFolder(p,a,b,c,d)
+#define IMsgStore_GetReceiveFolder(p,a,b,c,d,e)  (p)->lpVtbl->GetReceiveFolder(p,a,b,c,d,e)
+#define IMsgStore_GetReceiveFolderTable(p,a,b)   (p)->lpVtbl->GetReceiveFolderTable(p,a,b)
+#define IMsgStore_StoreLogoff(p,a)               (p)->lpVtbl->StoreLogoff(p,a)
+#define IMsgStore_AbortSubmit(p,a,b,c)           (p)->lpVtbl->AbortSubmit(p,a,b,c)
+#define IMsgStore_GetOutgoingQueue(p,a,b)        (p)->lpVtbl->GetOutgoingQueue(p,a,b)
+#define IMsgStore_SetLockState(p,a,b)            (p)->lpVtbl->SetLockState(p,a,b)
+#define IMsgStore_FinishedMsg(p,a,b,c)           (p)->lpVtbl->FinishedMsg(p,a,b,c)
+#define IMsgStore_NotifyNewMail(p,a)             (p)->lpVtbl->NotifyNewMail(p,a)
+
+#endif
+
+typedef IMsgStore *LPMDB;
+
+/*****************************************************************************
+ * IMAPIContainer interface
+ */
+#define INTERFACE IMAPIContainer
+DECLARE_INTERFACE_(IMAPIContainer,IMAPIProp)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    /*** IMAPIProp methods ***/
+    STDMETHOD(GetLastError)(THIS_ HRESULT hRes, ULONG ulFlags, LPMAPIERROR *lppErr) PURE;
+    STDMETHOD(SaveChanges)(THIS_ ULONG ulFlags) PURE;
+    STDMETHOD(GetProps)(THIS_ LPSPropTagArray lpPropTags, ULONG ulFlags, ULONG *lpValues, LPSPropValue *lppProps) PURE;
+    STDMETHOD(GetPropList)(THIS_ ULONG  ulFlags, LPSPropTagArray *lppPropTagArray) PURE;
+    STDMETHOD(OpenProperty)(THIS_ ULONG ulPropTag, LPCIID lpIid, ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lppUnk) PURE;
+    STDMETHOD(SetProps)(THIS_ ULONG cValues, LPSPropValue lpProps, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(DeleteProps)(THIS_ LPSPropTagArray lpPropTags, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyTo)(THIS_ ULONG ciidExclude, LPCIID lpIid, LPSPropTagArray lpProps, ULONG ulParam,
+                      LPMAPIPROGRESS lpProgress, LPCIID lpIface,LPVOID lpDest, ULONG ulFlags,
+                      LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyProps)(THIS_ LPSPropTagArray lpIncludeProps, ULONG ulParam, LPMAPIPROGRESS lpProgress,
+                         LPCIID lpIid, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems) PURE;
+    STDMETHOD(GetNamesFromIDs)(THIS_ LPSPropTagArray *lppPropTags, LPGUID lpIid, ULONG ulFlags, ULONG *lpCount,
+                               LPMAPINAMEID **lpppNames) PURE;
+    STDMETHOD(GetIDsFromNames)(THIS_ ULONG cPropNames, LPMAPINAMEID *lppNames, ULONG ulFlags, LPSPropTagArray *lppPropTags) PURE;
+    /*** IMAPIContainer methods ***/
+    STDMETHOD(GetContentsTable)(THIS_ ULONG ulFlags, LPMAPITABLE * lppTable) PURE;
+    STDMETHOD(GetHierarchyTable)(THIS_ ULONG ulFlags, LPMAPITABLE * lppTable) PURE;
+    STDMETHOD(OpenEntry)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, LPCIID lpInterface, ULONG ulFlags,
+                         ULONG * lpulObjType, LPUNKNOWN * lppUnk) PURE;
+    STDMETHOD(SetSearchCriteria)(THIS_ LPSRestriction lpRestriction, LPENTRYLIST lpContainerList, ULONG ulSearchFlags) PURE;
+    STDMETHOD(GetSearchCriteria)(THIS_ ULONG ulFlags, LPSRestriction * lppRestriction, LPENTRYLIST * lppContainerList,
+                                 ULONG * lpulSearchState) PURE;
+};
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+        /*** IUnknown methods ***/
+#define IMAPIContainer_QueryInterface(p,a,b)        (p)->lpVtbl->QueryInterface(p,a,b)
+#define IMAPIContainer_AddRef(p)                    (p)->lpVtbl->AddRef(p)
+#define IMAPIContainer_Release(p)                   (p)->lpVtbl->Release(p)
+        /*** IMAPIProp methods ***/
+#define IMAPIContainer_GetLastError(p,a,b,c)        (p)->lpVtbl->GetLastError(p,a,b,c)
+#define IMAPIContainer_SaveChanges(p,a)             (p)->lpVtbl->SaveChanges(p,a)
+#define IMAPIContainer_GetProps(p,a,b,c,d)          (p)->lpVtbl->GetProps(p,a,b,c,d)
+#define IMAPIContainer_GetPropList(p,a,b)           (p)->lpVtbl->GetPropList(p,a,b)
+#define IMAPIContainer_OpenProperty(p,a,b,c,d,e)    (p)->lpVtbl->OpenProperty(p,a,b,c,d,e)
+#define IMAPIContainer_SetProps(p,a,b,c)            (p)->lpVtbl->SetProps(p,a,b,c)
+#define IMAPIContainer_DeleteProps(p,a,b)           (p)->lpVtbl->DeleteProps(p,a,b)
+#define IMAPIContainer_CopyTo(p,a,b,c,d,e,f,g,h,i)  (p)->lpVtbl->CopyTo(p,a,b,c,d,e,f,g,h,i)
+#define IMAPIContainer_CopyProps(p,a,b,c,d,e,f,g)   (p)->lpVtbl->CopyProps(p,a,b,c,d,e,f,g)
+#define IMAPIContainer_GetNamesFromIDs(p,a,b,c,d,e) (p)->lpVtbl->GetNamesFromIDs(p,a,b,c,d,e)
+#define IMAPIContainer_GetIDsFromNames(p,a,b,c,d)   (p)->lpVtbl->GetIDsFromNames(p,a,b,c,d)
+        /*** IMAPIContainer methods ***/
+#define IMAPIContainer_GetContentsTable(p,a,b)      (p)->lpVtbl->GetContentsTable(p,a,b)
+#define IMAPIContainer_GetHierarchyTable(p,a,b)     (p)->lpVtbl->GetHierarchyTable(p,a,b)
+#define IMAPIContainer_OpenEntry(p,a,b,c,d,e,f)     (p)->lpVtbl->OpenEntry(p,a,b,c,d,e,f)
+#define IMAPIContainer_SetSearchCriteria(p,a,b,c)   (p)->lpVtbl->SetSearchCriteria(p,a,b,c)
+#define IMAPIContainer_GetSearchCriteria(p,a,b,c,d) (p)->lpVtbl->GetSearchCriteria(p,a,b,c,d)
+
+#endif
+
+/*****************************************************************************
+ * IMAPIFolder interface
+ */
+#define INTERFACE IMAPIFolder
+DECLARE_INTERFACE_(IMAPIFolder,IMAPIContainer)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    /*** IMAPIProp methods ***/
+    STDMETHOD(GetLastError)(THIS_ HRESULT hRes, ULONG ulFlags, LPMAPIERROR *lppErr) PURE;
+    STDMETHOD(SaveChanges)(THIS_ ULONG ulFlags) PURE;
+    STDMETHOD(GetProps)(THIS_ LPSPropTagArray lpPropTags, ULONG ulFlags, ULONG *lpValues, LPSPropValue *lppProps) PURE;
+    STDMETHOD(GetPropList)(THIS_ ULONG  ulFlags, LPSPropTagArray *lppPropTagArray) PURE;
+    STDMETHOD(OpenProperty)(THIS_ ULONG ulPropTag, LPCIID lpIid, ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lppUnk) PURE;
+    STDMETHOD(SetProps)(THIS_ ULONG cValues, LPSPropValue lpProps, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(DeleteProps)(THIS_ LPSPropTagArray lpPropTags, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyTo)(THIS_ ULONG ciidExclude, LPCIID lpIid, LPSPropTagArray lpProps, ULONG ulParam,
+                      LPMAPIPROGRESS lpProgress, LPCIID lpIface,LPVOID lpDest, ULONG ulFlags,
+                      LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyProps)(THIS_ LPSPropTagArray lpIncludeProps, ULONG ulParam, LPMAPIPROGRESS lpProgress,
+                         LPCIID lpIid, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems) PURE;
+    STDMETHOD(GetNamesFromIDs)(THIS_ LPSPropTagArray *lppPropTags, LPGUID lpIid, ULONG ulFlags, ULONG *lpCount,
+                               LPMAPINAMEID **lpppNames) PURE;
+    STDMETHOD(GetIDsFromNames)(THIS_ ULONG cPropNames, LPMAPINAMEID *lppNames, ULONG ulFlags, LPSPropTagArray *lppPropTags) PURE;
+    /*** IMAPIContainer methods ***/
+    STDMETHOD(GetContentsTable)(THIS_ ULONG ulFlags, LPMAPITABLE * lppTable) PURE;
+    STDMETHOD(GetHierarchyTable)(THIS_ ULONG ulFlags, LPMAPITABLE * lppTable) PURE;
+    STDMETHOD(OpenEntry)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, LPCIID lpInterface, ULONG ulFlags,
+                         ULONG * lpulObjType, LPUNKNOWN * lppUnk) PURE;
+    STDMETHOD(SetSearchCriteria)(THIS_ LPSRestriction lpRestriction, LPENTRYLIST lpContainerList, ULONG ulSearchFlags) PURE;
+    STDMETHOD(GetSearchCriteria)(THIS_ ULONG ulFlags, LPSRestriction * lppRestriction, LPENTRYLIST * lppContainerList,
+                                 ULONG * lpulSearchState) PURE;
+    /*** IMAPIFolder methods ***/
+    STDMETHOD(CreateMessage)(THIS_ LPCIID lpInterface, ULONG ulFlags, LPMESSAGE *lppMessage) PURE;
+    STDMETHOD(CopyMessages)(THIS_ LPENTRYLIST lpMsgList, LPCIID lpInterface, LPVOID lpDestFolder, ULONG ulUIParam,
+                            LPMAPIPROGRESS lpProgress, ULONG ulFlags) PURE;
+    STDMETHOD(DeleteMessages)(THIS_ LPENTRYLIST lpMsgList, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags) PURE;
+    STDMETHOD(CreateFolder)(THIS_ ULONG ulFolderType, LPSTR lpszFolderName, LPSTR lpszFolderComment, LPCIID lpInterface,
+                            ULONG ulFlags, LPMAPIFOLDER lppFolder) PURE;
+    STDMETHOD(CopyFolder)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, LPCIID lpInterface, LPVOID lpDestFolder,
+                          LPSTR lpszNewFolderName, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags) PURE;
+    STDMETHOD(DeleteFolder)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulUIParam, LPMAPIPROGRESS lpProgress,
+                            ULONG ulFlags) PURE;
+    STDMETHOD(SetReadFlags)(THIS_ LPENTRYLIST lpMsgList, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags) PURE;
+    STDMETHOD(GetMessageStatus)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulFlags, ULONG * lpulMessageStatus) PURE;
+    STDMETHOD(SetMessageStatus)(THIS_ ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulNewStatus,
+                                ULONG ulNewStatusMask, ULONG * lpulOldStatus) PURE;
+    STDMETHOD(SaveContentsSort)(THIS_ LPSSortOrderSet lpSortCriteria, ULONG ulFlags) PURE;
+    STDMETHOD(EmptyFolder) (THIS_ ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags) PURE;
+};
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+        /*** IUnknown methods ***/
+#define IMAPIFolder_QueryInterface(p,a,b)        (p)->lpVtbl->QueryInterface(p,a,b)
+#define IMAPIFolder_AddRef(p)                    (p)->lpVtbl->AddRef(p)
+#define IMAPIFolder_Release(p)                   (p)->lpVtbl->Release(p)
+        /*** IMAPIProp methods ***/
+#define IMAPIFolder_GetLastError(p,a,b,c)        (p)->lpVtbl->GetLastError(p,a,b,c)
+#define IMAPIFolder_SaveChanges(p,a)             (p)->lpVtbl->SaveChanges(p,a)
+#define IMAPIFolder_GetProps(p,a,b,c,d)          (p)->lpVtbl->GetProps(p,a,b,c,d)
+#define IMAPIFolder_GetPropList(p,a,b)           (p)->lpVtbl->GetPropList(p,a,b)
+#define IMAPIFolder_OpenProperty(p,a,b,c,d,e)    (p)->lpVtbl->OpenProperty(p,a,b,c,d,e)
+#define IMAPIFolder_SetProps(p,a,b,c)            (p)->lpVtbl->SetProps(p,a,b,c)
+#define IMAPIFolder_DeleteProps(p,a,b)           (p)->lpVtbl->DeleteProps(p,a,b)
+#define IMAPIFolder_CopyTo(p,a,b,c,d,e,f,g,h,i)  (p)->lpVtbl->CopyTo(p,a,b,c,d,e,f,g,h,i)
+#define IMAPIFolder_CopyProps(p,a,b,c,d,e,f,g)   (p)->lpVtbl->CopyProps(p,a,b,c,d,e,f,g)
+#define IMAPIFolder_GetNamesFromIDs(p,a,b,c,d,e) (p)->lpVtbl->GetNamesFromIDs(p,a,b,c,d,e)
+#define IMAPIFolder_GetIDsFromNames(p,a,b,c,d)   (p)->lpVtbl->GetIDsFromNames(p,a,b,c,d)
+        /*** IMAPIContainer methods ***/
+#define IMAPIFolder_GetContentsTable(p,a,b)      (p)->lpVtbl->GetContentsTable(p,a,b)
+#define IMAPIFolder_GetHierarchyTable(p,a,b)     (p)->lpVtbl->GetHierarchyTable(p,a,b)
+#define IMAPIFolder_OpenEntry(p,a,b,c,d,e,f)     (p)->lpVtbl->OpenEntry(p,a,b,c,d,e,f)
+#define IMAPIFolder_SetSearchCriteria(p,a,b,c)   (p)->lpVtbl->SetSearchCriteria(p,a,b,c)
+#define IMAPIFolder_GetSearchCriteria(p,a,b,c,d) (p)->lpVtbl->GetSearchCriteria(p,a,b,c,d)
+        /*** IMAPIFolder methods ***/
+#define IMAPIFolder_CreateMessage(p,a,b,c)        (p)->lpVtbl->CreateMessage(p,a,b,c)
+#define IMAPIFolder_CopyMessages(p,a,b,c,d,e,f)   (p)->lpVtbl->CopyMessages(p,a,b,c,d,e,f)
+#define IMAPIFolder_DeleteMessages(p,a,b,c,d)     (p)->lpVtbl->DeleteMessages(p,a,b,c,d)
+#define IMAPIFolder_CreateFolder(p,a,b,c,d,e,f)   (p)->lpVtbl->CreateFolder(p,a,b,c,d,e,f)
+#define IMAPIFolder_CopyFolder(p,a,b,c,d,e,f,g,h) (p)->lpVtbl->CopyFolder(p,a,b,c,d,e,f,g,h)
+#define IMAPIFolder_DeleteFolder(p,a,b,c,d,e)     (p)->lpVtbl->CreateFolder(p,a,b,c,d,e)
+#define IMAPIFolder_SetReadFlags(p,a,b,c,d)       (p)->lpVtbl->SetReadFlags(p,a,b,c,d)
+#define IMAPIFolder_GetMessageStatus(p,a,b,c,d)   (p)->lpVtbl->GetMessageStatus(p,a,b,c,d)
+#define IMAPIFolder_SetMessageStatus(p,a,b,c,d,e) (p)->lpVtbl->SetMessageStatus(p,a,b,c,d,e)
+#define IMAPIFolder_SaveContentsSort(p,a,b)       (p)->lpVtbl->SaveContentsSort(p,a,b)
+#define IMAPIFolder_EmptyFolder(p,a,b,c)          (p)->lpVtbl->EmptyFolder(p,a,b,c)
+
+#endif
 
 typedef struct
@@ -959,3 +1204,132 @@
 } ADRLIST, *LPADRLIST;
 
+/*****************************************************************************
+ * IMessage interface
+ */
+#define INTERFACE IMessage
+DECLARE_INTERFACE_(IMessage,IMAPIProp)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    /*** IMAPIProp methods ***/
+    STDMETHOD(GetLastError)(THIS_ HRESULT hRes, ULONG ulFlags, LPMAPIERROR *lppErr) PURE;
+    STDMETHOD(SaveChanges)(THIS_ ULONG ulFlags) PURE;
+    STDMETHOD(GetProps)(THIS_ LPSPropTagArray lpPropTags, ULONG ulFlags, ULONG *lpValues, LPSPropValue *lppProps) PURE;
+    STDMETHOD(GetPropList)(THIS_ ULONG  ulFlags, LPSPropTagArray *lppPropTagArray) PURE;
+    STDMETHOD(OpenProperty)(THIS_ ULONG ulPropTag, LPCIID lpIid, ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lppUnk) PURE;
+    STDMETHOD(SetProps)(THIS_ ULONG cValues, LPSPropValue lpProps, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(DeleteProps)(THIS_ LPSPropTagArray lpPropTags, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyTo)(THIS_ ULONG ciidExclude, LPCIID lpIid, LPSPropTagArray lpProps, ULONG ulParam,
+                      LPMAPIPROGRESS lpProgress, LPCIID lpIface,LPVOID lpDest, ULONG ulFlags,
+                      LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyProps)(THIS_ LPSPropTagArray lpIncludeProps, ULONG ulParam, LPMAPIPROGRESS lpProgress,
+                         LPCIID lpIid, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems) PURE;
+    STDMETHOD(GetNamesFromIDs)(THIS_ LPSPropTagArray *lppPropTags, LPGUID lpIid, ULONG ulFlags, ULONG *lpCount,
+                               LPMAPINAMEID **lpppNames) PURE;
+    STDMETHOD(GetIDsFromNames)(THIS_ ULONG cPropNames, LPMAPINAMEID *lppNames, ULONG ulFlags, LPSPropTagArray *lppPropTags) PURE;
+    /*** IMessage methods ***/
+    STDMETHOD(GetAttachmentTable)(THIS_ ULONG ulFlags, LPMAPITABLE *lppTable) PURE;
+    STDMETHOD(OpenAttach)(THIS_ ULONG ulAttachmentNum, LPCIID lpInterface, ULONG ulFlags, LPATTACH *lppAttach) PURE;
+    STDMETHOD(CreateAttach)(THIS_ LPCIID lpInterface, ULONG ulFlags, ULONG *lpulAttachmentNum, LPATTACH *lppAttach) PURE;
+    STDMETHOD(DeleteAttach)(THIS_ ULONG ulAttachmentNum, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags) PURE;
+    STDMETHOD(GetRecipientTable)(THIS_ ULONG ulFlags, LPMAPITABLE *lppTable) PURE;
+    STDMETHOD(ModifyRecipients)(THIS_ ULONG ulFlags, LPADRLIST lpMods) PURE;
+    STDMETHOD(SubmitMessage)(THIS_ ULONG ulFlags) PURE;
+    STDMETHOD(SetReadFlag)(THIS_ ULONG ulFlags) PURE;
+};
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+        /*** IUnknown methods ***/
+#define IMessage_QueryInterface(p,a,b)        (p)->lpVtbl->QueryInterface(p,a,b)
+#define IMessage_AddRef(p)                    (p)->lpVtbl->AddRef(p)
+#define IMessage_Release(p)                   (p)->lpVtbl->Release(p)
+        /*** IMAPIProp methods ***/
+#define IMessage_GetLastError(p,a,b,c)        (p)->lpVtbl->GetLastError(p,a,b,c)
+#define IMessage_SaveChanges(p,a)             (p)->lpVtbl->SaveChanges(p,a)
+#define IMessage_GetProps(p,a,b,c,d)          (p)->lpVtbl->GetProps(p,a,b,c,d)
+#define IMessage_GetPropList(p,a,b)           (p)->lpVtbl->GetPropList(p,a,b)
+#define IMessage_OpenProperty(p,a,b,c,d,e)    (p)->lpVtbl->OpenProperty(p,a,b,c,d,e)
+#define IMessage_SetProps(p,a,b,c)            (p)->lpVtbl->SetProps(p,a,b,c)
+#define IMessage_DeleteProps(p,a,b)           (p)->lpVtbl->DeleteProps(p,a,b)
+#define IMessage_CopyTo(p,a,b,c,d,e,f,g,h,i)  (p)->lpVtbl->CopyTo(p,a,b,c,d,e,f,g,h,i)
+#define IMessage_CopyProps(p,a,b,c,d,e,f,g)   (p)->lpVtbl->CopyProps(p,a,b,c,d,e,f,g)
+#define IMessage_GetNamesFromIDs(p,a,b,c,d,e) (p)->lpVtbl->GetNamesFromIDs(p,a,b,c,d,e)
+#define IMessage_GetIDsFromNames(p,a,b,c,d)   (p)->lpVtbl->GetIDsFromNames(p,a,b,c,d)
+        /*** IMessage methods ***/
+#define IMessage_GetAttachmentTable(p,a,b)    (p)->lpVtbl->GetAttachmentTable(p,a,b)
+#define IMessage_OpenAttach(p,a,b,c,d)        (p)->lpVtbl->OpenAttach(p,a,b,c,d)
+#define IMessage_CreateAttach(p,a,b,c,d)      (p)->lpVtbl->CreateAttach(p,a,b,c,d)
+#define IMessage_DeleteAttach(p,a,b,c,d)      (p)->lpVtbl->DeleteAttach(p,a,b,c,d)
+#define IMessage_GetRecipientTable(p,a,b)     (p)->lpVtbl->GetRecipientTable(p,a,b)
+#define IMessage_ModifyRecipients(p,a,b)      (p)->lpVtbl->ModifyRecipients(p,a,b)
+#define IMessage_SubmitMessage(p,a)           (p)->lpVtbl->SubmitMessage(p,a)
+#define IMessage_SetReadFlag(p,a)             (p)->lpVtbl->SetReadFlag(p,a)
+
+#endif
+
+/* Message flags (PR_MESSAGE_FLAGS) */
+
+#define MSGFLAG_READ         0x00000001U
+#define MSGFLAG_UNMODIFIED   0x00000002U
+#define MSGFLAG_SUBMIT       0x00000004U
+#define MSGFLAG_UNSENT       0x00000008U
+#define MSGFLAG_HASATTACH    0x00000010U
+#define MSGFLAG_FROMME       0x00000020U
+
+/*****************************************************************************
+ * IAttach interface
+ */
+#define INTERFACE IAttach
+DECLARE_INTERFACE_(IAttach,IMAPIProp)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    /*** IMAPIProp methods ***/
+    STDMETHOD(GetLastError)(THIS_ HRESULT hRes, ULONG ulFlags, LPMAPIERROR *lppErr) PURE;
+    STDMETHOD(SaveChanges)(THIS_ ULONG ulFlags) PURE;
+    STDMETHOD(GetProps)(THIS_ LPSPropTagArray lpPropTags, ULONG ulFlags, ULONG *lpValues, LPSPropValue *lppProps) PURE;
+    STDMETHOD(GetPropList)(THIS_ ULONG  ulFlags, LPSPropTagArray *lppPropTagArray) PURE;
+    STDMETHOD(OpenProperty)(THIS_ ULONG ulPropTag, LPCIID lpIid, ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lppUnk) PURE;
+    STDMETHOD(SetProps)(THIS_ ULONG cValues, LPSPropValue lpProps, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(DeleteProps)(THIS_ LPSPropTagArray lpPropTags, LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyTo)(THIS_ ULONG ciidExclude, LPCIID lpIid, LPSPropTagArray lpProps, ULONG ulParam,
+                      LPMAPIPROGRESS lpProgress, LPCIID lpIface,LPVOID lpDest, ULONG ulFlags,
+                      LPSPropProblemArray *lppProbs) PURE;
+    STDMETHOD(CopyProps)(THIS_ LPSPropTagArray lpIncludeProps, ULONG ulParam, LPMAPIPROGRESS lpProgress,
+                         LPCIID lpIid, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems) PURE;
+    STDMETHOD(GetNamesFromIDs)(THIS_ LPSPropTagArray *lppPropTags, LPGUID lpIid, ULONG ulFlags, ULONG *lpCount,
+                               LPMAPINAMEID **lpppNames) PURE;
+    STDMETHOD(GetIDsFromNames)(THIS_ ULONG cPropNames, LPMAPINAMEID *lppNames, ULONG ulFlags, LPSPropTagArray *lppPropTags) PURE;
+};
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+        /*** IUnknown methods ***/
+#define IAttach_QueryInterface(p,a,b)        (p)->lpVtbl->QueryInterface(p,a,b)
+#define IAttach_AddRef(p)                    (p)->lpVtbl->AddRef(p)
+#define IAttach_Release(p)                   (p)->lpVtbl->Release(p)
+        /*** IMAPIProp methods ***/
+#define IAttach_GetLastError(p,a,b,c)        (p)->lpVtbl->GetLastError(p,a,b,c)
+#define IAttach_SaveChanges(p,a)             (p)->lpVtbl->SaveChanges(p,a)
+#define IAttach_GetProps(p,a,b,c,d)          (p)->lpVtbl->GetProps(p,a,b,c,d)
+#define IAttach_GetPropList(p,a,b)           (p)->lpVtbl->GetPropList(p,a,b)
+#define IAttach_OpenProperty(p,a,b,c,d,e)    (p)->lpVtbl->OpenProperty(p,a,b,c,d,e)
+#define IAttach_SetProps(p,a,b,c)            (p)->lpVtbl->SetProps(p,a,b,c)
+#define IAttach_DeleteProps(p,a,b)           (p)->lpVtbl->DeleteProps(p,a,b)
+#define IAttach_CopyTo(p,a,b,c,d,e,f,g,h,i)  (p)->lpVtbl->CopyTo(p,a,b,c,d,e,f,g,h,i)
+#define IAttach_CopyProps(p,a,b,c,d,e,f,g)   (p)->lpVtbl->CopyProps(p,a,b,c,d,e,f,g)
+#define IAttach_GetNamesFromIDs(p,a,b,c,d,e) (p)->lpVtbl->GetNamesFromIDs(p,a,b,c,d,e)
+#define IAttach_GetIDsFromNames(p,a,b,c,d)   (p)->lpVtbl->GetIDsFromNames(p,a,b,c,d)
+#endif
+
+/* Attachment flags */
+
+#define NO_ATTACHMENT        0x00000000U
+#define ATTACH_BY_VALUE      0x00000001U
+
 #endif /*MAPIDEFS_H*/
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapitags.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapitags.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mapitags.h	(revision 25949)
@@ -462,4 +462,5 @@
 #define PR_DEFAULT_VIEW_ENTRYID PROP_TAG(PT_BINARY,0x3616)
 #define PR_ASSOC_CONTENT_COUNT PROP_TAG(PT_I4,0x3617)
+#define PR_IPM_DRAFTS_ENTRYID PROP_TAG(PT_BINARY,0x36D7)
 #define PR_ATTACHMENT_X400_PARAMETERS PROP_TAG(PT_BINARY,0x3700)
 #define PR_ATTACH_DATA_OBJ PROP_TAG(PT_OBJECT,0x3701)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mmsystem.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mmsystem.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mmsystem.h	(revision 25949)
@@ -1819,5 +1819,5 @@
 #define MCI_USER_MESSAGES               (0x400 + DRV_MCI_FIRST)
 
-#define MCI_ALL_DEVICE_ID               0xFFFF
+#define MCI_ALL_DEVICE_ID               0xFFFFFFFF
 
 #define MCI_DEVTYPE_VCR                 (MCI_STRING_OFFSET + 1)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mscoree.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mscoree.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mscoree.idl	(revision 25949)
@@ -37,5 +37,9 @@
 cpp_quote("HRESULT     WINAPI GetRequestedRuntimeInfo(LPCWSTR,LPCWSTR,LPCWSTR,DWORD,DWORD,LPWSTR,DWORD,DWORD*,LPWSTR,DWORD,DWORD*);")
 cpp_quote("HRESULT     WINAPI LoadLibraryShim(LPCWSTR,LPCWSTR,LPVOID,HMODULE*);")
+cpp_quote("#ifdef WINE_STRICT_PROTOTYPES")
+cpp_quote("typedef HRESULT (__stdcall *FLockClrVersionCallback)(void);")
+cpp_quote("#else")
 cpp_quote("typedef HRESULT (__stdcall *FLockClrVersionCallback)();")
+cpp_quote("#endif")
 cpp_quote("HRESULT     WINAPI LockClrVersion(FLockClrVersionCallback,FLockClrVersionCallback*,FLockClrVersionCallback*);")
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtmdid.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtmdid.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtmdid.h	(revision 25949)
@@ -30,4 +30,6 @@
 
 #define DISPID_NORMAL_FIRST     1000
+#define DISPID_IE8_NORMAL_FIRST (DISPID_NORMAL_FIRST+150)
+
 #define DISPID_OMDOCUMENT       DISPID_NORMAL_FIRST
 #define DISPID_DATATRANSFER     DISPID_NORMAL_FIRST
@@ -106,4 +108,31 @@
 #define DISPID_GENERIC          DISPID_NORMAL_FIRST
 #define DISPID_DOMIMPLEMENTATION  DISPID_NORMAL_FIRST
+#define DISPID_DOCUMENTCOMPATIBLEINFO  DISPID_NORMAL_FIRST
+#define DISPID_DOCUMENTCOMPATIBLEINFOCOLLECTION  DISPID_NORMAL_FIRST
+
+#define DISPID_IE8_ANCHOR        DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_AREA          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_BASE          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_BODY          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_FORM          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_HEAD          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_IMG           DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_INPUT         DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_LINK          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_MOD           DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_SCRIPT        DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_ATTR          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_NAMEDNODEMAP  DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_COLLECTION    DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_PARAM         DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_EMBED         DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_BLOCK         DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_META          DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_STYLE         DISPID_IE8_NORMAL_FIRST
+#define DISPID_IE8_SELECT        DISPID_IE8_NORMAL_FIRST
+
+#define DISPID_IE8_ELEMENTBASE  (DISPID_ELEMENT+200)
+#define DISPID_IE8_ELEMENTMAX   (DISPID_SITE-1)
+#define DISPID_IE8_ELEMENT      DISPID_IE8_ELEMENTBASE
 
 #define DISPID_COLLECTION      (DISPID_NORMAL_FIRST+500)
@@ -545,98 +574,7 @@
 #define DISPID_EVPROP_ONFOCUSIN            (DISPID_EVENTS+91)
 #define DISPID_EVPROP_ONFOCUSOUT           (DISPID_EVENTS+92)
-#define DISPID_EVPROPS_COUNT               93
-
-#define DISPID_EVMETH_ONMOUSEOVER           STDDISPID_XOBJ_ONMOUSEOVER
-#define DISPID_EVMETH_ONMOUSEOUT            STDDISPID_XOBJ_ONMOUSEOUT
-#define DISPID_EVMETH_ONMOUSEDOWN           DISPID_MOUSEDOWN
-#define DISPID_EVMETH_ONMOUSEUP             DISPID_MOUSEUP
-#define DISPID_EVMETH_ONMOUSEMOVE           DISPID_MOUSEMOVE
-#define DISPID_EVMETH_ONKEYDOWN             DISPID_KEYDOWN
-#define DISPID_EVMETH_ONKEYUP               DISPID_KEYUP
-#define DISPID_EVMETH_ONKEYPRESS            DISPID_KEYPRESS
-#define DISPID_EVMETH_ONCLICK               DISPID_CLICK
-#define DISPID_EVMETH_ONDBLCLICK            DISPID_DBLCLICK
-#define DISPID_EVMETH_ONSELECT              DISPID_ONSELECT
-#define DISPID_EVMETH_ONSUBMIT              DISPID_ONSUBMIT
-#define DISPID_EVMETH_ONRESET               DISPID_ONRESET
-#define DISPID_EVMETH_ONHELP                STDDISPID_XOBJ_ONHELP
-#define DISPID_EVMETH_ONFOCUS               STDDISPID_XOBJ_ONFOCUS
-#define DISPID_EVMETH_ONBLUR                STDDISPID_XOBJ_ONBLUR
-#define DISPID_EVMETH_ONROWEXIT             STDDISPID_XOBJ_ONROWEXIT
-#define DISPID_EVMETH_ONROWENTER            STDDISPID_XOBJ_ONROWENTER
-#define DISPID_EVMETH_ONBOUNCE              DISPID_ONBOUNCE
-#define DISPID_EVMETH_ONBEFOREUPDATE        STDDISPID_XOBJ_BEFOREUPDATE
-#define DISPID_EVMETH_ONAFTERUPDATE         STDDISPID_XOBJ_AFTERUPDATE
-#define DISPID_EVMETH_ONBEFOREDRAGOVER      EVENTID_CommonCtrlEvent_BeforeDragOver
-#define DISPID_EVMETH_ONBEFOREDROPORPASTE   EVENTID_CommonCtrlEvent_BeforeDropOrPaste
-#define DISPID_EVMETH_ONREADYSTATECHANGE    DISPID_READYSTATECHANGE
-#define DISPID_EVMETH_ONFINISH              DISPID_ONFINISH
-#define DISPID_EVMETH_ONSTART               DISPID_ONSTART
-#define DISPID_EVMETH_ONABORT               DISPID_ONABORT
-#define DISPID_EVMETH_ONERROR               DISPID_ONERROR
-#define DISPID_EVMETH_ONCHANGE              DISPID_ONCHANGE
-#define DISPID_EVMETH_ONSCROLL              DISPID_ONSCROLL
-#define DISPID_EVMETH_ONLOAD                DISPID_ONLOAD
-#define DISPID_EVMETH_ONUNLOAD              DISPID_ONUNLOAD
-#define DISPID_EVMETH_ONLAYOUT              DISPID_ONLAYOUT
-#define DISPID_EVMETH_ONDRAGSTART           STDDISPID_XOBJ_ONDRAGSTART
-#define DISPID_EVMETH_ONRESIZE              DISPID_ONRESIZE
-#define DISPID_EVMETH_ONSELECTSTART         STDDISPID_XOBJ_ONSELECTSTART
-#define DISPID_EVMETH_ONERRORUPDATE         STDDISPID_XOBJ_ERRORUPDATE
-#define DISPID_EVMETH_ONBEFOREUNLOAD        DISPID_ONBEFOREUNLOAD
-#define DISPID_EVMETH_ONDATASETCHANGED      STDDISPID_XOBJ_ONDATASETCHANGED
-#define DISPID_EVMETH_ONDATAAVAILABLE       STDDISPID_XOBJ_ONDATAAVAILABLE
-#define DISPID_EVMETH_ONDATASETCOMPLETE     STDDISPID_XOBJ_ONDATASETCOMPLETE
-#define DISPID_EVMETH_ONFILTER              STDDISPID_XOBJ_ONFILTER
-#define DISPID_EVMETH_ONCHANGEFOCUS         DISPID_ONCHANGEFOCUS
-#define DISPID_EVMETH_ONCHANGEBLUR          DISPID_ONCHANGEBLUR
-#define DISPID_EVMETH_ONLOSECAPTURE         STDDISPID_XOBJ_ONLOSECAPTURE
-#define DISPID_EVMETH_ONPROPERTYCHANGE      STDDISPID_XOBJ_ONPROPERTYCHANGE
-#define DISPID_EVMETH_ONPERSISTSAVE         DISPID_ONPERSISTSAVE
-#define DISPID_EVMETH_ONDRAG                STDDISPID_XOBJ_ONDRAG
-#define DISPID_EVMETH_ONDRAGEND             STDDISPID_XOBJ_ONDRAGEND
-#define DISPID_EVMETH_ONDRAGENTER           STDDISPID_XOBJ_ONDRAGENTER
-#define DISPID_EVMETH_ONDRAGOVER            STDDISPID_XOBJ_ONDRAGOVER
-#define DISPID_EVMETH_ONDRAGLEAVE           STDDISPID_XOBJ_ONDRAGLEAVE
-#define DISPID_EVMETH_ONDROP                STDDISPID_XOBJ_ONDROP
-#define DISPID_EVMETH_ONCUT                 STDDISPID_XOBJ_ONCUT
-#define DISPID_EVMETH_ONCOPY                STDDISPID_XOBJ_ONCOPY
-#define DISPID_EVMETH_ONPASTE               STDDISPID_XOBJ_ONPASTE
-#define DISPID_EVMETH_ONBEFORECUT           STDDISPID_XOBJ_ONBEFORECUT
-#define DISPID_EVMETH_ONBEFORECOPY          STDDISPID_XOBJ_ONBEFORECOPY
-#define DISPID_EVMETH_ONBEFOREPASTE         STDDISPID_XOBJ_ONBEFOREPASTE
-#define DISPID_EVMETH_ONPERSISTLOAD         DISPID_ONPERSISTLOAD
-#define DISPID_EVMETH_ONROWSDELETE          STDDISPID_XOBJ_ONROWSDELETE
-#define DISPID_EVMETH_ONROWSINSERTED        STDDISPID_XOBJ_ONROWSINSERTED
-#define DISPID_EVMETH_ONCELLCHANGE          STDDISPID_XOBJ_ONCELLCHANGE
-#define DISPID_EVMETH_ONCONTEXTMENU         DISPID_ONCONTEXTMENU
-#define DISPID_EVMETH_ONBEFOREPRINT         DISPID_ONBEFOREPRINT
-#define DISPID_EVMETH_ONAFTERPRINT          DISPID_ONAFTERPRINT
-#define DISPID_EVMETH_ONSTOP                DISPID_ONSTOP
-#define DISPID_EVMETH_ONBEFOREEDITFOCUS     DISPID_ONBEFOREEDITFOCUS
-#define DISPID_EVMETH_ONMOUSEHOVER          DISPID_ONMOUSEHOVER
-#define DISPID_EVMETH_ONCONTENTREADY        DISPID_ONCONTENTREADY
-#define DISPID_EVMETH_ONLAYOUTCOMPLETE      DISPID_ONLAYOUTCOMPLETE
-#define DISPID_EVMETH_ONPAGE                DISPID_ONPAGE
-#define DISPID_EVMETH_ONLINKEDOVERFLOW      DISPID_ONLINKEDOVERFLOW
-#define DISPID_EVMETH_ONMOUSEWHEEL          DISPID_ONMOUSEWHEEL
-#define DISPID_EVMETH_ONBEFOREDEACTIVAT     DISPID_ONBEFOREDEACTIVATE
-#define DISPID_EVMETH_ONMOVE                DISPID_ONMOVE
-#define DISPID_EVMETH_ONCONTROLSELECT       DISPID_ONCONTROLSELECT
-#define DISPID_EVMETH_ONSELECTIONCHANGE     DISPID_ONSELECTIONCHANGE
-#define DISPID_EVMETH_ONMOVESTART           DISPID_ONMOVESTART
-#define DISPID_EVMETH_ONMOVEEND             DISPID_ONMOVEEND
-#define DISPID_EVMETH_ONRESIZESTART         DISPID_ONRESIZESTART
-#define DISPID_EVMETH_ONRESIZEEND           DISPID_ONRESIZEEND
-#define DISPID_EVMETH_ONMOUSEENTER          DISPID_ONMOUSEENTER
-#define DISPID_EVMETH_ONMOUSELEAVE          DISPID_ONMOUSELEAVE
-#define DISPID_EVMETH_ONACTIVATE            DISPID_ONACTIVATE
-#define DISPID_EVMETH_ONDEACTIVATE          DISPID_ONDEACTIVATE
-#define DISPID_EVMETH_ONMULTILAYOUTCLEANUP  DISPID_ONMULTILAYOUTCLEANUP
-#define DISPID_EVMETH_ONBEFOREACTIVATE      DISPID_ONBEFOREACTIVATE
-#define DISPID_EVMETH_ONFOCUSIN             DISPID_ONFOCUSIN
-#define DISPID_EVMETH_ONFOCUSOUT            DISPID_ONFOCUSOUT
-#define DISPID_EVPROPS_COUNT                93
-
+#define DISPID_EVPROP_ONSTORAGE            (DISPID_EVENTS+93)
+#define DISPID_EVPROP_ONSTORAGECOMMIT      (DISPID_EVENTS+94)
+#define DISPID_EVPROPS_COUNT               95
 
 #define DISPID_EVMETH_ONMOUSEOVER           STDDISPID_XOBJ_ONMOUSEOVER
@@ -730,4 +668,6 @@
 #define DISPID_EVMETH_ONFOCUSIN             DISPID_ONFOCUSIN
 #define DISPID_EVMETH_ONFOCUSOUT            DISPID_ONFOCUSOUT
+#define DISPID_EVMETH_ONSTORAGE             DISPID_ONSTORAGE
+#define DISPID_EVMETH_ONSTORAGECOMMIT       DISPID_ONSTORAGECOMMIT
 
 #define DISPID_ONABORT               (DISPID_NORMAL_FIRST)
@@ -778,4 +718,6 @@
 #define DISPID_ONFOCUSIN             (DISPID_NORMAL_FIRST+48)
 #define DISPID_ONFOCUSOUT            (DISPID_NORMAL_FIRST+49)
+#define DISPID_ONSTORAGE             (DISPID_NORMAL_FIRST+50)
+#define DISPID_ONSTORAGECOMMIT       (DISPID_NORMAL_FIRST+51)
 
 /* HTMLDocumentEvents */
@@ -997,4 +939,11 @@
 #define DISPID_IHTMLDOCUMENT5_COMPATMODE          DISPID_OMDOCUMENT+102
 
+/* IHTMLDocument6 */
+#define DISPID_IHTMLDOCUMENT6_COMPATIBLE          DISPID_OMDOCUMENT+103
+#define DISPID_IHTMLDOCUMENT6_DOCUMENTMODE        DISPID_OMDOCUMENT+104
+#define DISPID_IHTMLDOCUMENT6_ONSTORAGE           DISPID_EVPROP_ONSTORAGE
+#define DISPID_IHTMLDOCUMENT6_ONSTORAGECOMMIT     DISPID_EVPROP_ONSTORAGECOMMIT
+#define DISPID_IHTMLDOCUMENT6_IE8_GETELEMENTBYID  DISPID_OMDOCUMENT+105
+#define DISPID_IHTMLDOCUMENT6_UPDATESETTINGS      DISPID_OMDOCUMENT+106
 
 /* IHTMLElementCollection */
@@ -1010,4 +959,11 @@
 /* IHTMLElementCollection3 */
 #define DISPID_IHTMLELEMENTCOLLECTION3_NAMEDITEM  DISPID_COLLECTION+6
+
+/* IHTMLAttributeCollection3 */
+#define DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_GETNAMEDITEM     DISPID_IE8_NAMEDNODEMAP
+#define DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_SETNAMEDITEM     DISPID_IE8_NAMEDNODEMAP+1
+#define DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_REMOVENAMEDITEM  DISPID_IE8_NAMEDNODEMAP+2
+#define DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_ITEM             DISPID_IE8_NAMEDNODEMAP+4
+#define DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_LENGTH           DISPID_IE8_NAMEDNODEMAP+3
 
 /* IHTMLDOMChildrenCollection */
@@ -1311,4 +1267,47 @@
 #define DISPID_IHTMLELEMENT4_ONFOCUSIN            DISPID_EVPROP_ONFOCUSIN
 #define DISPID_IHTMLELEMENT4_ONFOCUSOUT           DISPID_EVPROP_ONFOCUSOUT
+
+/* IElementSelector */
+#define DISPID_IELEMENTSELECTOR_QUERYSELECTOR     DISPID_ELEMENT+114
+#define DISPID_IELEMENTSELECTOR_QUERYSELECTORALL  DISPID_ELEMENT+115
+
+/* IHTMLElement5 */
+#define DISPID_IHTMLELEMENT5_IE8_GETATTRIBUTENODE     DISPID_IE8_ELEMENT
+#define DISPID_IHTMLELEMENT5_IE8_SETATTRIBUTENODE     DISPID_IE8_ELEMENT+1
+#define DISPID_IHTMLELEMENT5_IE8_REMOVEATTRIBUTENODE  DISPID_IE8_ELEMENT+2
+#define DISPID_IHTMLELEMENT5_HASATTRIBUTE             DISPID_IE8_ELEMENT+3
+#define DISPID_IHTMLELEMENT5_ROLE                     DISPID_IE8_ELEMENT+4
+#define DISPID_IHTMLELEMENT5_ARIABUSY                 DISPID_IE8_ELEMENT+5
+#define DISPID_IHTMLELEMENT5_ARIACHECKED              DISPID_IE8_ELEMENT+6
+#define DISPID_IHTMLELEMENT5_ARIADISABLED             DISPID_IE8_ELEMENT+7
+#define DISPID_IHTMLELEMENT5_ARIAEXPANDED             DISPID_IE8_ELEMENT+8
+#define DISPID_IHTMLELEMENT5_ARIAHASPOPUP             DISPID_IE8_ELEMENT+9
+#define DISPID_IHTMLELEMENT5_ARIAHIDDEN               DISPID_IE8_ELEMENT+10
+#define DISPID_IHTMLELEMENT5_ARIAINVALID              DISPID_IE8_ELEMENT+11
+#define DISPID_IHTMLELEMENT5_ARIAMULTISELECTABLE      DISPID_IE8_ELEMENT+12
+#define DISPID_IHTMLELEMENT5_ARIAPRESSED              DISPID_IE8_ELEMENT+13
+#define DISPID_IHTMLELEMENT5_ARIAREADONLY             DISPID_IE8_ELEMENT+14
+#define DISPID_IHTMLELEMENT5_ARIAREQUIRED             DISPID_IE8_ELEMENT+15
+#define DISPID_IHTMLELEMENT5_ARIASECRET               DISPID_IE8_ELEMENT+16
+#define DISPID_IHTMLELEMENT5_ARIASELECTED             DISPID_IE8_ELEMENT+17
+#define DISPID_IHTMLELEMENT5_IE8_GETATTRIBUTE         DISPID_IE8_ELEMENT+18
+#define DISPID_IHTMLELEMENT5_IE8_SETATTRIBUTE         DISPID_IE8_ELEMENT+19
+#define DISPID_IHTMLELEMENT5_IE8_REMOVEATTRIBUTE      DISPID_IE8_ELEMENT+20
+#define DISPID_IHTMLELEMENT5_IE8_ATTRIBUTES           DISPID_IE8_ELEMENT+21
+#define DISPID_IHTMLELEMENT5_ARIAVALUENOW             DISPID_IE8_ELEMENT+22
+#define DISPID_IHTMLELEMENT5_ARIAPOSINSET             DISPID_IE8_ELEMENT+23
+#define DISPID_IHTMLELEMENT5_ARIASETSIZE              DISPID_IE8_ELEMENT+24
+#define DISPID_IHTMLELEMENT5_ARIALEVEL                DISPID_IE8_ELEMENT+25
+#define DISPID_IHTMLELEMENT5_ARIAVALUEMIN             DISPID_IE8_ELEMENT+26
+#define DISPID_IHTMLELEMENT5_ARIAVALUEMAX             DISPID_IE8_ELEMENT+27
+#define DISPID_IHTMLELEMENT5_ARIACONTROLS             DISPID_IE8_ELEMENT+28
+#define DISPID_IHTMLELEMENT5_ARIADESCRIBEDBY          DISPID_IE8_ELEMENT+29
+#define DISPID_IHTMLELEMENT5_ARIAFLOWTO               DISPID_IE8_ELEMENT+30
+#define DISPID_IHTMLELEMENT5_ARIALABELLEDBY           DISPID_IE8_ELEMENT+31
+#define DISPID_IHTMLELEMENT5_ARIAACTIVEDESCENDANT     DISPID_IE8_ELEMENT+32
+#define DISPID_IHTMLELEMENT5_ARIAOWNS                 DISPID_IE8_ELEMENT+33
+#define DISPID_IHTMLELEMENT5_HASATTRIBUTES            DISPID_IE8_ELEMENT+34
+#define DISPID_IHTMLELEMENT5_ARIALIVE                 DISPID_IE8_ELEMENT+35
+#define DISPID_IHTMLELEMENT5_ARIARELEVANT             DISPID_IE8_ELEMENT+36
 
 /* IHTMLGenericElement */
@@ -1792,4 +1791,14 @@
 #define DISPID_IHTMLSCREEN_FONTSMOOTHINGENABLED   (DISPID_SCREEN+8)
 
+/* IHTMLScreen2 */
+#define DISPID_IHTMLSCREEN2_LOGICALXDPI  DISPID_SCREEN+9
+#define DISPID_IHTMLSCREEN2_LOGICALYDPI  DISPID_SCREEN+10
+#define DISPID_IHTMLSCREEN2_DEVICEXDPI   DISPID_SCREEN+11
+#define DISPID_IHTMLSCREEN2_DEVICEYDPI   DISPID_SCREEN+12
+
+/* IHTMLScreen3 */
+#define DISPID_IHTMLSCREEN3_SYSTEMXDPI  DISPID_SCREEN+13
+#define DISPID_IHTMLSCREEN3_SYSTEMYDPI  DISPID_SCREEN+14
+
 /* IHTMLOptionElementFactory */
 #define DISPID_IHTMLOPTIONELEMENTFACTORY_CREATE   DISPID_VALUE
@@ -1822,4 +1831,12 @@
 #define DISPID_IHTMLFORMELEMENT__NEWENUM   DISPID_NEWENUM
 #define DISPID_IHTMLFORMELEMENT_ITEM       DISPID_VALUE
+
+/* HTMLFormElementEvents */
+#define DISPID_HTMLFORMELEMENTEVENTS_ONSUBMIT  DISPID_EVMETH_ONSUBMIT
+#define DISPID_HTMLFORMELEMENTEVENTS_ONRESET   DISPID_EVMETH_ONRESET
+
+/* HTMLFormElementEvents2 */
+#define DISPID_HTMLFORMELEMENTEVENTS2_ONSUBMIT  DISPID_EVMETH_ONSUBMIT
+#define DISPID_HTMLFORMELEMENTEVENTS2_ONRESET   DISPID_EVMETH_ONRESET
 
 /* IHTMLStyleSheetsCollection */
@@ -2008,4 +2025,32 @@
 #define DISPID_IHTMLDOMATTRIBUTE_SPECIFIED  DISPID_DOMATTRIBUTE+1
 
+/* IHTMLDOMAttribute2 */
+#define DISPID_IHTMLDOMATTRIBUTE2_NAME             DISPID_DOMATTRIBUTE+3
+#define DISPID_IHTMLDOMATTRIBUTE2_VALUE            DISPID_DOMATTRIBUTE+4
+#define DISPID_IHTMLDOMATTRIBUTE2_EXPANDO          DISPID_DOMATTRIBUTE+5
+#define DISPID_IHTMLDOMATTRIBUTE2_NODETYPE         DISPID_DOMATTRIBUTE+6
+#define DISPID_IHTMLDOMATTRIBUTE2_PARENTNODE       DISPID_DOMATTRIBUTE+7
+#define DISPID_IHTMLDOMATTRIBUTE2_CHILDNODES       DISPID_DOMATTRIBUTE+8
+#define DISPID_IHTMLDOMATTRIBUTE2_FIRSTCHILD       DISPID_DOMATTRIBUTE+9
+#define DISPID_IHTMLDOMATTRIBUTE2_LASTCHILD        DISPID_DOMATTRIBUTE+10
+#define DISPID_IHTMLDOMATTRIBUTE2_PREVIOUSSIBLING  DISPID_DOMATTRIBUTE+11
+#define DISPID_IHTMLDOMATTRIBUTE2_NEXTSIBLING      DISPID_DOMATTRIBUTE+12
+#define DISPID_IHTMLDOMATTRIBUTE2_ATTRIBUTES       DISPID_DOMATTRIBUTE+13
+#define DISPID_IHTMLDOMATTRIBUTE2_OWNERDOCUMENT    DISPID_DOMATTRIBUTE+14
+#define DISPID_IHTMLDOMATTRIBUTE2_INSERTBEFORE     DISPID_DOMATTRIBUTE+15
+#define DISPID_IHTMLDOMATTRIBUTE2_REPLACECHILD     DISPID_DOMATTRIBUTE+16
+#define DISPID_IHTMLDOMATTRIBUTE2_REMOVECHILD      DISPID_DOMATTRIBUTE+17
+#define DISPID_IHTMLDOMATTRIBUTE2_APPENDCHILD      DISPID_DOMATTRIBUTE+18
+#define DISPID_IHTMLDOMATTRIBUTE2_HASCHILDNODES    DISPID_DOMATTRIBUTE+19
+#define DISPID_IHTMLDOMATTRIBUTE2_CLONENODE        DISPID_DOMATTRIBUTE+20
+
+/* IHTMLDocumentCompatibleInfo */
+#define DISPID_IHTMLDOCUMENTCOMPATIBLEINFO_USERAGENT  DISPID_DOCUMENTCOMPATIBLEINFO
+#define DISPID_IHTMLDOCUMENTCOMPATIBLEINFO_VERSION    DISPID_DOCUMENTCOMPATIBLEINFO+1
+
+/* IHTMLDocumentCompatibleInfoCollection */
+#define DISPID_IHTMLDOCUMENTCOMPATIBLEINFOCOLLECTION_ITEM    DISPID_DOCUMENTCOMPATIBLEINFOCOLLECTION
+#define DISPID_IHTMLDOCUMENTCOMPATIBLEINFOCOLLECTION_LENGTH  DISPID_DOCUMENTCOMPATIBLEINFOCOLLECTION+1
+
 /* IHTMLBodyElement */
 #define DISPID_IHTMLBODYELEMENT_BACKGROUND        DISPID_A_BACKGROUNDIMAGE
@@ -2056,4 +2101,16 @@
 #define DISPID_IHTMLANCHORELEMENT_FOCUS         DISPID_SITE+0
 #define DISPID_IHTMLANCHORELEMENT_BLUR          DISPID_SITE+2
+
+/* IHTMLAnchorElement2 */
+#define DISPID_IHTMLANCHORELEMENT2_CHARSET   DISPID_ANCHOR+23
+#define DISPID_IHTMLANCHORELEMENT2_COORDS    DISPID_ANCHOR+24
+#define DISPID_IHTMLANCHORELEMENT2_HREFLANG  DISPID_ANCHOR+25
+#define DISPID_IHTMLANCHORELEMENT2_SHAPE     DISPID_ANCHOR+26
+#define DISPID_IHTMLANCHORELEMENT2_TYPE      DISPID_ANCHOR+27
+
+/* IHTMLAnchorElement3 */
+#define DISPID_IHTMLANCHORELEMENT3_IE8_SHAPE   DISPID_IE8_ANCHOR+1
+#define DISPID_IHTMLANCHORELEMENT3_IE8_COORDS  DISPID_IE8_ANCHOR+2
+#define DISPID_IHTMLANCHORELEMENT3_IE8_HREF    DISPID_IE8_ANCHOR+3
 
 /* IHTMLTxtRange */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl	(revision 25949)
@@ -122,4 +122,8 @@
 }
 
+#define WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL                     \
+    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]       \
+    IDispatch *constructor()
+
 interface IHTMLDocument2;
 interface IHTMLStyleSheetsCollection;
@@ -929,8 +933,8 @@
  */
 [
-	odl,
-	oleautomation,
-	dual,
-	uuid(3050F3CF-98B5-11CF-BB82-00AA00BDCE0B)
+    odl,
+    oleautomation,
+    dual,
+    uuid(3050F3CF-98B5-11CF-BB82-00AA00BDCE0B)
 ]
 interface IHTMLRuleStyle : IDispatch
@@ -3411,4 +3415,69 @@
 }
 
+#define WINE_IHTMLDOMNODE_DISPINTERFACE_DECL                            \
+    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]                         \
+    LONG nodeType();                                                    \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]                       \
+    IHTMLDOMNode* parentNode();                                         \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]                             \
+    VARIANT_BOOL hasChildNodes();                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]                       \
+    IDispatch* childNodes();                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]                       \
+    IDispatch* attributes();                                            \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]                              \
+    IHTMLDOMNode* insertBefore(                                         \
+            [in] IHTMLDOMNode* newChild,                                \
+            [optional, in] VARIANT refChild);                           \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]                               \
+    IHTMLDOMNode* removeChild([in] IHTMLDOMNode* oldChild);             \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]                              \
+    IHTMLDOMNode* replaceChild(                                         \
+        [in] IHTMLDOMNode* newChild,                                    \
+        [in] IHTMLDOMNode* oldChild);                                   \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_CLONENODE)]                                 \
+    IHTMLDOMNode* cloneNode([in] VARIANT_BOOL fDeep);                   \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]                                \
+    IHTMLDOMNode* removeNode([defaultvalue(0), in] VARIANT_BOOL fDeep); \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]                                  \
+    IHTMLDOMNode* swapNode([in] IHTMLDOMNode* otherNode);               \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]                               \
+    IHTMLDOMNode* replaceNode([in] IHTMLDOMNode* replacement);          \
+                                                                        \
+    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]                               \
+    IHTMLDOMNode* appendChild([in] IHTMLDOMNode* newChild);             \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]                         \
+    BSTR nodeName();                                                    \
+                                                                        \
+    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]                        \
+    void nodeValue(VARIANT v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]                        \
+    VARIANT nodeValue();                                                \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]                       \
+    IHTMLDOMNode* firstChild();                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]                        \
+    IHTMLDOMNode* lastChild();                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]                  \
+    IHTMLDOMNode* previousSibling();                                    \
+                                                                        \
+    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]                      \
+    IHTMLDOMNode* nextSibling()
+
 /*****************************************************************************
  *    IHTMLDOMNode2 interface
@@ -3426,4 +3495,12 @@
 }
 
+#define WINE_IHTMLDOMNODE2_DISPINTERFACE_DECL           \
+    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]   \
+    IDispatch *ownerDocument()
+
+#define WINE_HTMLDOMNODE_DISPINTERFACE_DECL     \
+    WINE_IHTMLDOMNODE_DISPINTERFACE_DECL;       \
+    WINE_IHTMLDOMNODE2_DISPINTERFACE_DECL
+
 /*****************************************************************************
  *    IHTMLDOMAttribute interface
@@ -3448,4 +3525,85 @@
     [propget, id(DISPID_IHTMLDOMATTRIBUTE_SPECIFIED)]
     HRESULT specified([retval, out] VARIANT_BOOL *p);
+}
+
+/*****************************************************************************
+ *    IHTMLDOMAttribute2 interface
+ */
+[
+    odl,
+    oleautomation,
+    dual,
+    uuid(3050f810-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IHTMLDOMAttribute2 : IDispatch
+{
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_NAME)]
+    HRESULT name([retval, out] BSTR *p);
+
+    [propput, id(DISPID_IHTMLDOMATTRIBUTE2_VALUE)]
+    HRESULT value([in] BSTR v);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_VALUE)]
+    HRESULT value([retval, out] BSTR *p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_EXPANDO)]
+    HRESULT expando([retval, out] VARIANT_BOOL *p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_NODETYPE)]
+    HRESULT nodeType([retval, out] long *p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_PARENTNODE)]
+    HRESULT parentNode([retval, out] IHTMLDOMNode **p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_CHILDNODES)]
+    HRESULT childNodes([retval, out] IDispatch **p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_FIRSTCHILD)]
+    HRESULT firstChild([retval, out] IHTMLDOMNode **p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_LASTCHILD)]
+    HRESULT lastChild([retval, out] IHTMLDOMNode **p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_PREVIOUSSIBLING)]
+    HRESULT previousSibling([retval, out] IHTMLDOMNode **p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_NEXTSIBLING)]
+    HRESULT nextSibling([retval, out] IHTMLDOMNode **p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_ATTRIBUTES)]
+    HRESULT attributes([retval, out] IDispatch **p);
+
+    [propget, id(DISPID_IHTMLDOMATTRIBUTE2_OWNERDOCUMENT)]
+    HRESULT ownerDocument([retval, out] IDispatch **p);
+
+    [id(DISPID_IHTMLDOMATTRIBUTE2_INSERTBEFORE)]
+    HRESULT insertBefore(
+            [in] IHTMLDOMNode *newChild,
+            [optional, in] VARIANT refChild,
+            [retval, out] IHTMLDOMNode **node);
+
+    [id(DISPID_IHTMLDOMATTRIBUTE2_REPLACECHILD)]
+    HRESULT replaceChild(
+            [in] IHTMLDOMNode *newChild,
+            [in] IHTMLDOMNode *oldChild,
+            [retval, out] IHTMLDOMNode **node);
+
+    [id(DISPID_IHTMLDOMATTRIBUTE2_REMOVECHILD)]
+    HRESULT removeChild(
+            [in] IHTMLDOMNode *oldChild,
+            [retval, out] IHTMLDOMNode **node);
+
+    [id(DISPID_IHTMLDOMATTRIBUTE2_APPENDCHILD)]
+    HRESULT appendChild(
+            [in] IHTMLDOMNode *newChild,
+            [retval, out] IHTMLDOMNode **node);
+
+    [id(DISPID_IHTMLDOMATTRIBUTE2_HASCHILDNODES)]
+    HRESULT hasChildNodes([retval, out] VARIANT_BOOL *fChildren);
+
+    [id(DISPID_IHTMLDOMATTRIBUTE2_CLONENODE)]
+    HRESULT cloneNode(
+            [in] VARIANT_BOOL fDeep,
+            [retval, out] IHTMLDOMAttribute **clonedNode);
 }
 
@@ -3538,4 +3696,40 @@
 
 /*****************************************************************************
+ *    IHTMLDocumentCompatibleInfo interface
+ */
+[
+    odl,
+    oleautomation,
+    dual,
+    uuid(3051041a-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IHTMLDocumentCompatibleInfo : IDispatch
+{
+    [propget, id(DISPID_IHTMLDOCUMENTCOMPATIBLEINFO_USERAGENT)]
+    HRESULT userAgent([retval, out] BSTR *p);
+
+    [propget, id(DISPID_IHTMLDOCUMENTCOMPATIBLEINFO_VERSION)]
+    HRESULT version([retval, out] BSTR *p);
+}
+
+/*****************************************************************************
+ *    IHTMLDocumentCompatibleInfoCollection interface
+ */
+[
+    odl,
+    oleautomation,
+    dual,
+    uuid(30510418-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IHTMLDocumentCompatibleInfoCollection : IDispatch
+{
+    [propget, id(DISPID_IHTMLDOCUMENTCOMPATIBLEINFOCOLLECTION_LENGTH)]
+    HRESULT length([retval, out] long *p);
+
+    [id(DISPID_IHTMLDOCUMENTCOMPATIBLEINFOCOLLECTION_ITEM)]
+    HRESULT item([in] long i, [retval, out]IHTMLDocumentCompatibleInfo **p);
+}
+
+/*****************************************************************************
  *    DispHTMLDOMTextNode dispinterface
  */
@@ -3587,70 +3781,40 @@
             [in] BSTR bstrstring);
 
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode* cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode* nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
+    WINE_HTMLDOMNODE_DISPINTERFACE_DECL;
+}
+
+/*****************************************************************************
+ *    IHTMLAttributeCollection3 interface
+ */
+[
+    odl,
+    oleautomation,
+    dual,
+    uuid(30510469-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IHTMLAttributeCollection3 : IDispatch
+{
+    [id(DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_GETNAMEDITEM)]
+    HRESULT getNamedItem(
+            [in] BSTR bstrName,
+            [retval, out] IHTMLDOMAttribute **ppNodeOut);
+
+    [id(DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_SETNAMEDITEM)]
+    HRESULT setNamedItem(
+            [in] IHTMLDOMAttribute *pNodeIn,
+            [retval, out] IHTMLDOMAttribute **ppNodeOut);
+
+    [id(DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_REMOVENAMEDITEM)]
+    HRESULT removeNamedItem(
+            [in] BSTR bstrName,
+            [retval, out] IHTMLDOMAttribute **ppNodeOut);
+
+    [id(DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_ITEM)]
+    HRESULT item(
+            [in] long index,
+            [retval, out] IHTMLDOMAttribute **ppNodeOut);
+
+    [propget, id(DISPID_IHTMLATTRIBUTECOLLECTION3_IE8_LENGTH)]
+    HRESULT length([retval, out] long *p);
 }
 
@@ -3985,4 +4149,276 @@
 }
 
+#define WINE_IHTMLELEMENT_DISPINTERFACE_DECL                            \
+    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]                              \
+    void setAttribute(                                                  \
+        [in] BSTR strAttributeName,                                     \
+        [in] VARIANT AttValue,                                          \
+        [defaultvalue(1), in] LONG lFlags);                             \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]                              \
+    VARIANT getAttribute(                                               \
+        [in] BSTR strAttributeName,                                     \
+        [defaultvalue(0), in] LONG lFlags);                             \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]                           \
+    VARIANT_BOOL removeAttribute(                                       \
+        [in] BSTR strAttributeName,                                     \
+        [defaultvalue(1), in] LONG lFlags);                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]              \
+    void className(BSTR v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]              \
+    BSTR className();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]                     \
+    void id(BSTR v);                                                    \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]                     \
+    BSTR id();                                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]                          \
+    BSTR tagName();                                                     \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]                    \
+    IHTMLElement *parentElement();                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]              \
+    IHTMLStyle *style();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]    \
+    void onhelp(VARIANT v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]    \
+    VARIANT onhelp();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]   \
+    void onclick(VARIANT v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]   \
+    VARIANT onclick();                                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]\
+    void ondblclick(VARIANT v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]\
+    VARIANT ondblclick();                                               \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable] \
+    void onkeydown(VARIANT v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable] \
+    VARIANT onkeydown();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]   \
+    void onkeyup(VARIANT v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]   \
+    VARIANT onkeyup();                                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]\
+    void onkeypress(VARIANT v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]\
+    VARIANT onkeypress();                                               \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]\
+    void onmouseout(VARIANT v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]\
+    VARIANT onmouseout();                                               \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable] \
+    void onmouseover(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable] \
+    VARIANT onmouseover();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable] \
+    void onmousemove(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable] \
+    VARIANT onmousemove();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable] \
+    void onmousedown(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable] \
+    VARIANT onmousedown();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable] \
+    void onmouseup(VARIANT v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable] \
+    VARIANT onmouseup();                                                \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)] IDispatch* document();  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]     \
+    void title(BSTR v);                                                 \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]     \
+    BSTR title();                                                       \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]  \
+    void language(BSTR v);                                              \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]  \
+    BSTR language();                                                    \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable] \
+    void onselectstart(VARIANT v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable] \
+    VARIANT onselectstart();                                            \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]                            \
+    void scrollIntoView([optional, in] VARIANT varargStart);            \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_CONTAINS)]                                  \
+    VARIANT_BOOL contains([in] IHTMLElement* pChild);                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]            \
+    LONG sourceIndex();                                                 \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]                     \
+    VARIANT recordNumber();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_LANG)]                             \
+    void lang(BSTR v);                                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_LANG)]                             \
+    BSTR lang();                                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]                       \
+    LONG offsetLeft();                                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]                        \
+    LONG offsetTop();                                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]                      \
+    LONG offsetWidth();                                                 \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]                     \
+    LONG offsetHeight();                                                \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]                     \
+    IHTMLElement* offsetParent();                                       \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]                        \
+    void innerHTML(BSTR v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]                        \
+    BSTR innerHTML();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]                        \
+    void innerText(BSTR v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]                        \
+    BSTR innerText();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]                        \
+    void outerHTML(BSTR v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]                        \
+    BSTR outerHTML();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]                        \
+    void outerText(BSTR v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]                        \
+    BSTR outerText();                                                   \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]                        \
+    void insertAdjacentHTML(                                            \
+        [in] BSTR where,                                                \
+        [in] BSTR html);                                                \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]                        \
+    void insertAdjacentText(                                            \
+        [in] BSTR where,                                                \
+        [in] BSTR text);                                                \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]                   \
+    IHTMLElement* parentTextEdit();                                     \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]                       \
+    VARIANT_BOOL isTextEdit();                                          \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_CLICK)]                                     \
+    void click();                                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]                          \
+    IHTMLFiltersCollection* filters();                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable] \
+    void ondragstart(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable] \
+    VARIANT ondragstart();                                              \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT_TOSTRING)]                                  \
+    BSTR toString();                                                    \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable] \
+    void onbeforeupdate(VARIANT v);                                     \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable] \
+    VARIANT onbeforeupdate();                                           \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable] \
+    void onafterupdate(VARIANT v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable] \
+    VARIANT onafterupdate();                                            \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable] \
+    void onerrorupdate(VARIANT v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable] \
+    VARIANT onerrorupdate();                                            \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable] \
+    void onrowexit(VARIANT v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable] \
+    VARIANT onrowexit();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable] \
+    void onrowenter(VARIANT v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable] \
+    VARIANT onrowenter();                                               \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable] \
+    void ondatasetchanged(VARIANT v);                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable] \
+    VARIANT ondatasetchanged();                                         \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable] \
+    void ondataavailable(VARIANT v);                                    \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable] \
+    VARIANT ondataavailable();                                          \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable] \
+    void ondatasetcomplete(VARIANT v);                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable] \
+    VARIANT ondatasetcomplete();                                        \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable] \
+    void onfilterchange(VARIANT v);                                     \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable] \
+    VARIANT onfilterchange();                                           \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]                         \
+    IDispatch* children();                                              \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT_ALL)]                              \
+    IDispatch* all()
+
 /*****************************************************************************
  *    IHTMLElement2 interface
@@ -4324,4 +4760,303 @@
 }
 
+#define WINE_IHTMLELEMENT2_DISPINTERFACE_DECL                           \
+    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]                       \
+    BSTR scopeName();                                                   \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]                               \
+    void setCapture([defaultvalue(-1), in] VARIANT_BOOL containerCapture); \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]                           \
+    void releaseCapture();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable] \
+    void onlosecapture(VARIANT v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable] \
+    VARIANT onlosecapture();                                            \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]                       \
+    BSTR componentFromPoint([in] LONG x,[in] LONG y);                   \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]                                 \
+    void doScroll([optional, in] VARIANT component);                    \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable] \
+    void onscroll(VARIANT v);                                           \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable] \
+    VARIANT onscroll();                                                 \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]   \
+    void ondrag(VARIANT v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]   \
+    VARIANT ondrag();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable] \
+    void ondragend(VARIANT v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable] \
+    VARIANT ondragend();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable] \
+    void ondragenter(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable] \
+    VARIANT ondragenter();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable] \
+    void ondragover(VARIANT v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable] \
+    VARIANT ondragover();                                               \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable] \
+    void ondragleave(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable] \
+    VARIANT ondragleave();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]   \
+    void ondrop(VARIANT v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]   \
+    VARIANT ondrop();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable] \
+    void onbeforecut(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable] \
+    VARIANT onbeforecut();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]    \
+    void oncut(VARIANT v);                                              \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]    \
+    VARIANT oncut();                                                    \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable] \
+    void onbeforecopy(VARIANT v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable] \
+    VARIANT onbeforecopy();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]   \
+    void oncopy(VARIANT v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]   \
+    VARIANT oncopy();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable] \
+    void onbeforepaste(VARIANT v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable] \
+    VARIANT onbeforepaste();                                            \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]  \
+    void onpaste(VARIANT v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]  \
+    VARIANT onpaste();                                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]      \
+    IHTMLCurrentStyle* currentStyle();                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable] \
+    void onpropertychange(VARIANT v);                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable] \
+    VARIANT onpropertychange();                                         \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]                           \
+    IHTMLRectCollection* getClientRects();                              \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]                    \
+    IHTMLRect* getBoundingClientRect();                                 \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]                            \
+    void setExpression(                                                 \
+        [in] BSTR propname,                                             \
+        [in] BSTR expr,                                                 \
+        [defaultvalue(""), in] BSTR lang);                              \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]                            \
+    VARIANT getExpression([in] BSTR propname);                          \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]                         \
+    VARIANT_BOOL removeExpression([in] BSTR propname);                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable] \
+    void tabIndex(short v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable] \
+    short tabIndex();                                                   \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_FOCUS)]                                    \
+    void focus();                                                       \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]\
+    void accessKey(BSTR v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]\
+    BSTR accessKey();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]   \
+    void onblur(VARIANT v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]   \
+    VARIANT onblur();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]  \
+    void onfocus(VARIANT v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]  \
+    VARIANT onfocus();                                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable] \
+    void onresize(VARIANT v);                                           \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable] \
+    VARIANT onresize();                                                 \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_BLUR)]                                     \
+    void blur();                                                        \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]                                \
+    void addFilter([in] IUnknown* pUnk);                                \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]                             \
+    void removeFilter([in] IUnknown* pUnk);                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable] \
+    LONG clientHeight();                                                \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable] \
+    LONG clientWidth();                                                 \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable] \
+    LONG clientTop();                                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable] \
+    LONG clientLeft();                                                  \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]                              \
+    VARIANT_BOOL attachEvent(                                           \
+            [in] BSTR event,                                            \
+            [in] IDispatch* pDisp);                                     \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]                              \
+    void detachEvent(                                                   \
+            [in] BSTR event,                                            \
+            [in] IDispatch* pDisp);                                     \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)] VARIANT readyState(); \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable] \
+    void onreadystatechange(VARIANT v);                                 \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable] \
+    VARIANT onreadystatechange();                                       \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable] \
+    void onrowsdelete(VARIANT v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable] \
+    VARIANT onrowsdelete();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable] \
+    void onrowsinserted(VARIANT v);                                     \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable] \
+    VARIANT onrowsinserted();                                           \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable] \
+    void oncellchange(VARIANT v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable] \
+    VARIANT oncellchange();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]      \
+    void dir(BSTR v);                                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]      \
+    BSTR dir();                                                         \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]                       \
+    IDispatch* createControlRange();                                    \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable] \
+    LONG scrollHeight();                                                \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable] \
+    LONG scrollWidth();                                                 \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]\
+    void scrollTop(LONG v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]\
+    LONG scrollTop();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable] \
+    void scrollLeft(LONG v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable] \
+    LONG scrollLeft();                                                  \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]                          \
+    void clearAttributes();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable] \
+    void oncontextmenu(VARIANT v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable] \
+    VARIANT oncontextmenu();                                            \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]                    \
+    IHTMLElement* insertAdjacentElement(                                \
+        [in] BSTR where,                                                \
+        [in] IHTMLElement* insertedElement);                            \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]                             \
+    IHTMLElement* applyElement([in] IHTMLElement* apply,[in] BSTR where); \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]                          \
+    BSTR getAdjacentText([in] BSTR where);                              \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]                      \
+    BSTR replaceAdjacentText([in] BSTR where,[in] BSTR newText);        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]                 \
+    VARIANT_BOOL canHaveChildren();                                     \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]                              \
+    LONG addBehavior([in] BSTR bstrUrl,[optional, in] VARIANT* pvarFactory); \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]                           \
+    VARIANT_BOOL removeBehavior([in] LONG cookie);                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]      \
+    IHTMLStyle* runtimeStyle();                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]                    \
+    IDispatch* behaviorUrns();                                          \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]                          \
+    void tagUrn(BSTR v);                                                \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]                          \
+    BSTR tagUrn();                                                      \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable] \
+    void onbeforeeditfocus(VARIANT v);                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable] \
+    VARIANT onbeforeeditfocus();                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted] \
+    LONG readyStateValue();                                             \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]                     \
+    IHTMLElementCollection* getElementsByTagName([in] BSTR v)
 
 /*****************************************************************************
@@ -4466,5 +5201,141 @@
     [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
     HRESULT glyphMode([retval, out] LONG * p);
-};
+}
+
+#define WINE_IHTMLELEMENT3_DISPINTERFACE_DECL                           \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]                          \
+    void mergeAttributes(                                               \
+            [in] IHTMLElement* mergeThis,                               \
+            [optional, in] VARIANT* pvarFlags);                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]                     \
+    VARIANT_BOOL isMultiLine();                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]                     \
+    VARIANT_BOOL canHaveHTML();                                         \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable] \
+    void onlayoutcomplete(VARIANT v);                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable] \
+    VARIANT onlayoutcomplete();                                         \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]   \
+    void onpage(VARIANT v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]   \
+    VARIANT onpage();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable] \
+    void inflateBlock(VARIANT_BOOL v);                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable] \
+    VARIANT_BOOL inflateBlock();                                        \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable] \
+    void onbeforedeactivate(VARIANT v);                                 \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable] \
+    VARIANT onbeforedeactivate();                                       \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]                                \
+    void setActive();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable] \
+    void contentEditable(BSTR v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable] \
+    BSTR contentEditable();                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]               \
+    VARIANT_BOOL isContentEditable();                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]\
+    void hideFocus(VARIANT_BOOL v);                                     \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]\
+    VARIANT_BOOL hideFocus();                                           \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable] \
+    void disabled(VARIANT_BOOL v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable] \
+    VARIANT_BOOL disabled();                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]                      \
+    VARIANT_BOOL isDisabled();                                          \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]   \
+    void onmove(VARIANT v);                                             \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]   \
+    VARIANT onmove();                                                   \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable] \
+    void oncontrolselect(VARIANT v);                                    \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable] \
+    VARIANT oncontrolselect();                                          \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]                                \
+    VARIANT_BOOL fireEvent(                                             \
+        [in] BSTR bstrEventName,                                        \
+        [optional, in] VARIANT* pvarEventObject);                       \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable] \
+    void onresizestart(VARIANT v);                                      \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable] \
+    VARIANT onresizestart();                                            \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable] \
+    void onresizeend(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable] \
+    VARIANT onresizeend();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable] \
+    void onmovestart(VARIANT v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable] \
+    VARIANT onmovestart();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]\
+    void onmoveend(VARIANT v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]\
+    VARIANT onmoveend();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable] \
+    void onmouseenter(VARIANT v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable] \
+    VARIANT onmouseenter();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable] \
+    void onmouseleave(VARIANT v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable] \
+    VARIANT onmouseleave();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable] \
+    void onactivate(VARIANT v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable] \
+    VARIANT onactivate();                                               \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable] \
+    void ondeactivate(VARIANT v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable] \
+    VARIANT ondeactivate();                                             \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]                                 \
+    VARIANT_BOOL dragDrop();                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable] \
+    LONG glyphMode()
+
 /*****************************************************************************
  *    IHTMLElement4 interface
@@ -4518,5 +5389,338 @@
     [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
     HRESULT onfocusout([retval, out] VARIANT * p);
-};
+}
+
+#define WINE_IHTMLELEMENT4_DISPINTERFACE_DECL                           \
+    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable] \
+    void onmousewheel(VARIANT v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable] \
+    VARIANT onmousewheel();                                             \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]                                \
+    void normalize();                                                   \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]                         \
+    IHTMLDOMAttribute* getAttributeNode([in] BSTR bstrname);            \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]                         \
+    IHTMLDOMAttribute* setAttributeNode([in] IHTMLDOMAttribute* pattr); \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]                      \
+    IHTMLDOMAttribute* removeAttributeNode([in] IHTMLDOMAttribute* pattr); \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable] \
+    void onbeforeactivate(VARIANT v);                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable] \
+    VARIANT onbeforeactivate();                                         \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]\
+    void onfocusin(VARIANT v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]\
+    VARIANT onfocusin();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable] \
+    void onfocusout(VARIANT v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable] \
+    VARIANT onfocusout()
+
+#define WINE_IELEMENTSELECTOR_DISPINTERFACE_DECL                \
+    [id(DISPID_IELEMENTSELECTOR_QUERYSELECTOR)]                 \
+    IHTMLElement *querySelector([in] BSTR v);                   \
+                                                                \
+    [id(DISPID_IELEMENTSELECTOR_QUERYSELECTORALL)]              \
+    IHTMLDOMChildrenCollection *querySelectorAll([in] BSTR v)
+
+/*****************************************************************************
+ *    IHTMLUniqueName interface
+ */
+[
+    odl,
+    oleautomation,
+    dual,
+    uuid(3050f4d0-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IHTMLUniqueName : IDispatch
+{
+    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
+    HRESULT uniqueNumber([retval, out] LONG * p);
+
+    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
+    HRESULT uniqueID([retval, out] BSTR * p);
+}
+
+#define WINE_IHTMLUNIQUENAME_DISPINTERFACE_DECL                 \
+    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]  \
+    LONG uniqueNumber();                                        \
+                                                                \
+    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]      \
+    BSTR uniqueID()
+
+#define WINE_IHTMLELEMENT5_DISPINTERFACE_DECL                           \
+    [id(DISPID_IHTMLELEMENT5_IE8_GETATTRIBUTENODE)]                     \
+    IHTMLDOMAttribute2 *ie8_getAttributeNode([in] BSTR bstrname);       \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT5_IE8_SETATTRIBUTENODE)]                     \
+    IHTMLDOMAttribute2 *ie8_setAttributeNode([in] IHTMLDOMAttribute2 *pattr); \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT5_IE8_REMOVEATTRIBUTENODE)]                  \
+    IHTMLDOMAttribute2 *ie8_removeAttributeNode([in] IHTMLDOMAttribute2 *pattr); \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT5_HASATTRIBUTE)]                             \
+    VARIANT_BOOL hasAttribute([in] BSTR name);                          \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ROLE), displaybind, bindable]     \
+    void role(BSTR v);                                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ROLE), displaybind, bindable]     \
+    BSTR role();                                                        \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIABUSY), displaybind, bindable] \
+    void ariaBusy(BSTR v);                                              \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIABUSY), displaybind, bindable] \
+    BSTR ariaBusy();                                                    \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIACHECKED), displaybind, bindable] \
+    void ariaChecked(BSTR v);                                           \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIACHECKED), displaybind, bindable] \
+    BSTR ariaChecked();                                                 \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIADISABLED), displaybind, bindable] \
+    void ariaDisabled(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIADISABLED), displaybind, bindable] \
+    BSTR ariaDisabled();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAEXPANDED), displaybind, bindable] \
+    void ariaExpanded(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAEXPANDED), displaybind, bindable] \
+    BSTR ariaExpanded();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAHASPOPUP), displaybind, bindable]\
+    void ariaHaspopup(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAHASPOPUP), displaybind, bindable] \
+    BSTR ariaHaspopup();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAHIDDEN), displaybind, bindable] \
+    void ariaHidden(BSTR v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAHIDDEN), displaybind, bindable] \
+    BSTR ariaHidden();                                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAINVALID), displaybind, bindable] \
+    void ariaInvalid(BSTR v);                                           \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAINVALID), displaybind, bindable] \
+    BSTR ariaInvalid();                                                 \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAMULTISELECTABLE), displaybind, bindable] \
+    void ariaMultiselectable(BSTR v);                                   \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAMULTISELECTABLE), displaybind, bindable] \
+    BSTR ariaMultiselectable();                                         \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAPRESSED), displaybind, bindable] \
+    void ariaPressed(BSTR v);                                           \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAPRESSED), displaybind, bindable] \
+    BSTR ariaPressed();                                                 \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAREADONLY), displaybind, bindable] \
+    void ariaReadonly(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAREADONLY), displaybind, bindable] \
+    BSTR ariaReadonly();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAREQUIRED), displaybind, bindable] \
+    void ariaRequired(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAREQUIRED), displaybind, bindable] \
+    BSTR ariaRequired();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIASECRET), displaybind, bindable] \
+    void ariaSecret(BSTR v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIASECRET), displaybind, bindable] \
+    BSTR ariaSecret();                                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIASELECTED), displaybind, bindable] \
+    void ariaSelected(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIASELECTED), displaybind, bindable] \
+    BSTR ariaSelected();                                                \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT5_IE8_GETATTRIBUTE)]                         \
+    VARIANT ie8_getAttribute([in] BSTR strAttributeName);               \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT5_IE8_SETATTRIBUTE)]                         \
+    void ie8_setAttribute([in] BSTR strAttributeName,[in] VARIANT AttributeValue); \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT5_IE8_REMOVEATTRIBUTE)]                      \
+    VARIANT_BOOL ie8_removeAttribute([in] BSTR strAttributeName);       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_IE8_ATTRIBUTES)]                  \
+    IHTMLAttributeCollection3 *ie8_attributes();                        \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAVALUENOW), displaybind, bindable] \
+    void ariaValuenow(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAVALUENOW), displaybind, bindable] \
+    BSTR ariaValuenow();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAPOSINSET), displaybind, bindable] \
+    void ariaPosinset(short v);                                         \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAPOSINSET), displaybind, bindable] \
+    short ariaPosinset();                                               \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIASETSIZE), displaybind, bindable] \
+    void ariaSetsize(short v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIASETSIZE), displaybind, bindable] \
+    short ariaSetsize();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIALEVEL), displaybind, bindable]\
+    void ariaLevel(short v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIALEVEL), displaybind, bindable]\
+    short ariaLevel();                                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAVALUEMIN), displaybind, bindable] \
+    void ariaValuemin(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAVALUEMIN), displaybind, bindable] \
+    BSTR ariaValuemin();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAVALUEMAX), displaybind, bindable] \
+    void ariaValuemax(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAVALUEMAX), displaybind, bindable] \
+    BSTR ariaValuemax();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIACONTROLS), displaybind, bindable] \
+    void ariaControls(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIACONTROLS), displaybind, bindable] \
+    BSTR ariaControls();                                                \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIADESCRIBEDBY), displaybind, bindable] \
+    void ariaDescribedby(BSTR v);                                       \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIADESCRIBEDBY), displaybind, bindable] \
+    BSTR ariaDescribedby();                                             \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAFLOWTO), displaybind, bindable] \
+    void ariaFlowto(BSTR v);                                            \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAFLOWTO), displaybind, bindable] \
+    BSTR ariaFlowto();                                                  \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIALABELLEDBY), displaybind, bindable] \
+    void ariaLabelledby(BSTR v);                                        \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIALABELLEDBY), displaybind, bindable] \
+    BSTR ariaLabelledby();                                              \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAACTIVEDESCENDANT), displaybind, bindable] \
+    void ariaActivedescendant(BSTR v);                                  \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAACTIVEDESCENDANT), displaybind, bindable] \
+    BSTR ariaActivedescendant();                                        \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIAOWNS), displaybind, bindable] \
+    void ariaOwns(BSTR v);                                              \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIAOWNS), displaybind, bindable] \
+    BSTR ariaOwns();                                                    \
+                                                                        \
+    [id(DISPID_IHTMLELEMENT5_HASATTRIBUTES)]                            \
+    VARIANT_BOOL hasAttributes();                                       \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIALIVE), displaybind, bindable] \
+    void ariaLive(BSTR v);                                              \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIALIVE), displaybind, bindable] \
+    BSTR ariaLive();                                                    \
+                                                                        \
+    [propput, id(DISPID_IHTMLELEMENT5_ARIARELEVANT), displaybind, bindable] \
+    void ariaRelevant(BSTR v);                                          \
+                                                                        \
+    [propget, id(DISPID_IHTMLELEMENT5_ARIARELEVANT), displaybind, bindable] \
+    BSTR ariaRelevant()
+
+[
+    odl,
+    oleautomation,
+    dual,
+    uuid(3050f3f2-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IHTMLDatabinding : IDispatch
+{
+    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
+    HRESULT dataFld([in] BSTR v);
+
+    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
+    HRESULT dataFld([retval, out] BSTR * p);
+
+    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
+    HRESULT dataSrc([in] BSTR v);
+
+    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
+    HRESULT dataSrc([retval, out] BSTR * p);
+
+    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
+    HRESULT dataFormatAs([in] BSTR v);
+
+    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
+    HRESULT dataFormatAs([retval, out] BSTR * p);
+}
+
+#define WINE_IHTMLDATABINDING_DISPINTERFACE_DECL        \
+    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]      \
+    void dataFld(BSTR v);                               \
+                                                        \
+    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]      \
+    BSTR dataFld();                                     \
+                                                        \
+    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]      \
+    void dataSrc(BSTR v);                               \
+                                                        \
+    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]      \
+    BSTR dataSrc();                                     \
+                                                        \
+    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)] \
+    void dataFormatAs(BSTR v);                          \
+                                                        \
+    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)] \
+    BSTR dataFormatAs()
+
+#define WINE_HTMLELEMENT_DISPINTERFACE_DECL     \
+    WINE_IHTMLELEMENT_DISPINTERFACE_DECL;       \
+    WINE_IHTMLELEMENT2_DISPINTERFACE_DECL;      \
+    WINE_IHTMLELEMENT3_DISPINTERFACE_DECL;      \
+    WINE_IHTMLELEMENT4_DISPINTERFACE_DECL;      \
+    WINE_IHTMLUNIQUENAME_DISPINTERFACE_DECL;    \
+    WINE_HTMLDOMNODE_DISPINTERFACE_DECL;        \
+    WINE_IHTMLELEMENT5_DISPINTERFACE_DECL;      \
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL
+
+#define WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL \
+    WINE_IHTMLELEMENT_DISPINTERFACE_DECL;       \
+    WINE_IHTMLELEMENT2_DISPINTERFACE_DECL;      \
+    WINE_IHTMLELEMENT3_DISPINTERFACE_DECL;      \
+    WINE_IHTMLELEMENT4_DISPINTERFACE_DECL;      \
+    WINE_IHTMLUNIQUENAME_DISPINTERFACE_DECL;    \
+    WINE_HTMLDOMNODE_DISPINTERFACE_DECL;        \
+    WINE_IHTMLDATABINDING_DISPINTERFACE_DECL;   \
+    WINE_IHTMLELEMENT5_DISPINTERFACE_DECL;      \
+    WINE_IELEMENTSELECTOR_DISPINTERFACE_DECL;   \
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL
 
 /*****************************************************************************
@@ -4552,825 +5756,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propget, id(DISPID_IHTMLGENERICELEMENT_RECORDSET), hidden]
@@ -5427,6 +5811,5 @@
     VARIANT_BOOL readOnly();
 
-    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
-    IDispatch* constructor();
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL;
 }
 
@@ -5476,6 +5859,5 @@
     IHTMLStyleSheetRule* item([in] long index);
 
-    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
-    IDispatch* constructor();
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL;
 }
 
@@ -5520,6 +5902,5 @@
     BSTR pseudoClass();
 
-    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
-    IDispatch* constructor();
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL;
 }
 [
@@ -5565,6 +5946,5 @@
     IHTMLStyleSheetPage* item([in] long index);
 
-    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
-    IDispatch* constructor();
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL;
 }
 
@@ -6051,4 +6431,511 @@
 
 /*****************************************************************************
+ *    DispHTMLFormElement dispinterface
+ */
+[
+    hidden,
+    uuid(3050F510-98B5-11CF-BB82-00AA00BDCE0B)
+]
+dispinterface DispHTMLFormElement
+{
+properties:
+methods:
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_ACTION)]
+    void action(BSTR v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_ACTION)]
+    BSTR action();
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_ENCODING)]
+    void encoding(BSTR v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_ENCODING)]
+    BSTR encoding();
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_METHOD)]
+    void method(BSTR v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_METHOD)]
+    BSTR method();
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_ELEMENTS)]
+    IDispatch *elements();
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_TARGET)]
+    void target(BSTR v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_TARGET)]
+    BSTR target();
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_NAME)]
+    void name(BSTR v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_NAME)]
+    BSTR name();
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_ONSUBMIT)]
+    void onsubmit(VARIANT v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_ONSUBMIT)]
+    VARIANT onsubmit();
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_ONRESET)]
+    void onreset(VARIANT v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_ONRESET)]
+    VARIANT onreset();
+
+    [id(DISPID_IHTMLFORMELEMENT_SUBMIT)]
+    void submit();
+
+    [id(DISPID_IHTMLFORMELEMENT_RESET)]
+    void reset();
+
+    [propput, id(DISPID_IHTMLFORMELEMENT_LENGTH)]
+    void length(long v);
+
+    [propget, id(DISPID_IHTMLFORMELEMENT_LENGTH)]
+    long length();
+
+    [propget, id(DISPID_IHTMLFORMELEMENT__NEWENUM), hidden, restricted]
+    IUnknown *_newEnum();
+
+    [id(DISPID_IHTMLFORMELEMENT_ITEM)]
+    IDispatch *item(VARIANT name, VARIANT index);
+
+    [id(DISPID_IHTMLFORMELEMENT_TAGS)]
+    IDispatch *tags(VARIANT tagName);
+}
+
+[
+    hidden,
+    uuid(3050F364-98B5-11CF-BB82-00AA00BDCE0B)
+]
+dispinterface HTMLFormElementEvents
+{
+properties:
+methods:
+    [id(DISPID_HTMLELEMENTEVENTS_ONHELP)]
+    VARIANT_BOOL onhelp();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONCLICK)]
+    VARIANT_BOOL onclick();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDBLCLICK)]
+    VARIANT_BOOL ondblclick();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONKEYPRESS)]
+    VARIANT_BOOL onkeypress();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONKEYDOWN)]
+    void onkeydown();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONKEYUP)]
+    void onkeyup();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSEOUT)]
+    void onmouseout();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSEOVER)]
+    void onmouseover();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSEMOVE)]
+    void onmousemove();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSEDOWN)]
+    void onmousedown();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSEUP)]
+    void onmouseup();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONSELECTSTART)]
+    VARIANT_BOOL onselectstart();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONFILTERCHANGE)]
+    void onfilterchange();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDRAGSTART)]
+    VARIANT_BOOL ondragstart();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBEFOREUPDATE)]
+    VARIANT_BOOL onbeforeupdate();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONAFTERUPDATE)]
+    void onafterupdate();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONERRORUPDATE)]
+    VARIANT_BOOL onerrorupdate();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONROWEXIT)]
+    VARIANT_BOOL onrowexit();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONROWENTER)]
+    void onrowenter();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDATASETCHANGED)]
+    void ondatasetchanged();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDATAAVAILABLE)]
+    void ondataavailable();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDATASETCOMPLETE)]
+    void ondatasetcomplete();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONLOSECAPTURE)]
+    void onlosecapture();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONPROPERTYCHANGE)]
+    void onpropertychange();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONSCROLL)]
+    void onscroll();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONFOCUS)]
+    void onfocus();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBLUR)]
+    void onblur();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONRESIZE)]
+    void onresize();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDRAG)]
+    VARIANT_BOOL ondrag();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDRAGEND)]
+    void ondragend();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDRAGENTER)]
+    VARIANT_BOOL ondragenter();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDRAGOVER)]
+    VARIANT_BOOL ondragover();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDRAGLEAVE)]
+    void ondragleave();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDROP)]
+    VARIANT_BOOL ondrop();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBEFORECUT)]
+    VARIANT_BOOL onbeforecut();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONCUT)]
+    VARIANT_BOOL oncut();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBEFORECOPY)]
+    VARIANT_BOOL onbeforecopy();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONCOPY)]
+    VARIANT_BOOL oncopy();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBEFOREPASTE)]
+    VARIANT_BOOL onbeforepaste();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONPASTE)]
+    VARIANT_BOOL onpaste();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONCONTEXTMENU)]
+    VARIANT_BOOL oncontextmenu();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONROWSDELETE)]
+    void onrowsdelete();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONROWSINSERTED)]
+    void onrowsinserted();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONCELLCHANGE)]
+    void oncellchange();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONREADYSTATECHANGE)]
+    void onreadystatechange();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBEFOREEDITFOCUS)]
+    void onbeforeeditfocus();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONLAYOUTCOMPLETE)]
+    void onlayoutcomplete();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONPAGE)]
+    void onpage();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBEFOREDEACTIVATE)]
+    VARIANT_BOOL onbeforedeactivate();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONBEFOREACTIVATE)]
+    VARIANT_BOOL onbeforeactivate();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOVE)]
+    void onmove();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONCONTROLSELECT)]
+    VARIANT_BOOL oncontrolselect();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOVESTART)]
+    VARIANT_BOOL onmovestart();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOVEEND)]
+    void onmoveend();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONRESIZESTART)]
+    VARIANT_BOOL onresizestart();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONRESIZEEND)]
+    void onresizeend();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSEENTER)]
+    void onmouseenter();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSELEAVE)]
+    void onmouseleave();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONMOUSEWHEEL)]
+    VARIANT_BOOL onmousewheel();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONACTIVATE)]
+    void onactivate();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONDEACTIVATE)]
+    void ondeactivate();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONFOCUSIN)]
+    void onfocusin();
+
+    [id(DISPID_HTMLELEMENTEVENTS_ONFOCUSOUT)]
+    void onfocusout();
+
+    [id(DISPID_HTMLFORMELEMENTEVENTS_ONSUBMIT)]
+    VARIANT_BOOL onsubmit();
+
+    [id(DISPID_HTMLFORMELEMENTEVENTS_ONRESET)]
+    VARIANT_BOOL onreset();
+};
+
+interface IHTMLEventObj;
+
+[
+    hidden,
+    uuid(3050F614-98B5-11CF-BB82-00AA00BDCE0B)
+]
+dispinterface HTMLFormElementEvents2
+{
+properties:
+methods:
+    [id(DISPID_HTMLELEMENTEVENTS2_ONHELP)]
+    VARIANT_BOOL onhelp([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONCLICK)]
+    VARIANT_BOOL onclick([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDBLCLICK)]
+    VARIANT_BOOL ondblclick([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONKEYPRESS)]
+    VARIANT_BOOL onkeypress([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONKEYDOWN)]
+    void onkeydown([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONKEYUP)]
+    void onkeyup([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSEOUT)]
+    void onmouseout([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSEOVER)]
+    void onmouseover([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSEMOVE)]
+    void onmousemove([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSEDOWN)]
+    void onmousedown([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSEUP)]
+    void onmouseup([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONSELECTSTART)]
+    VARIANT_BOOL onselectstart([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONFILTERCHANGE)]
+    void onfilterchange([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDRAGSTART)]
+    VARIANT_BOOL ondragstart([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONBEFOREUPDATE)]
+    VARIANT_BOOL onbeforeupdate([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONAFTERUPDATE)]
+    void onafterupdate([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONERRORUPDATE)]
+    VARIANT_BOOL onerrorupdate([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONROWEXIT)]
+    VARIANT_BOOL onrowexit([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONROWENTER)]
+    void onrowenter([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDATASETCHANGED)]
+    void ondatasetchanged([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDATAAVAILABLE)]
+    void ondataavailable([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDATASETCOMPLETE)]
+    void ondatasetcomplete([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONLOSECAPTURE)]
+    void onlosecapture([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONPROPERTYCHANGE)]
+    void onpropertychange([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONSCROLL)]
+    void onscroll([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONFOCUS)]
+    void onfocus([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONBLUR)]
+    void onblur([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONRESIZE)]
+    void onresize([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDRAG)]
+    VARIANT_BOOL ondrag([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDRAGEND)]
+    void ondragend([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDRAGENTER)]
+    VARIANT_BOOL ondragenter([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDRAGOVER)]
+    VARIANT_BOOL ondragover([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDRAGLEAVE)]
+    void ondragleave([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDROP)]
+    VARIANT_BOOL ondrop([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONBEFORECUT)]
+    VARIANT_BOOL onbeforecut([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONCUT)]
+    VARIANT_BOOL oncut([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONBEFORECOPY)]
+    VARIANT_BOOL onbeforecopy([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONCOPY)]
+    VARIANT_BOOL oncopy([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONBEFOREPASTE)]
+    VARIANT_BOOL onbeforepaste([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONPASTE)]
+    VARIANT_BOOL onpaste([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONCONTEXTMENU)]
+    VARIANT_BOOL oncontextmenu([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONROWSDELETE)]
+    void onrowsdelete([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONROWSINSERTED)]
+    void onrowsinserted([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONCELLCHANGE)]
+    void oncellchange([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONREADYSTATECHANGE)]
+    void onreadystatechange([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONLAYOUTCOMPLETE)]
+    void onlayoutcomplete([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONPAGE)]
+    void onpage([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSEENTER)]
+    void onmouseenter([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSELEAVE)]
+    void onmouseleave([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONACTIVATE)]
+    void onactivate([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONDEACTIVATE)]
+    void ondeactivate([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONBEFOREDEACTIVATE)]
+    VARIANT_BOOL onbeforedeactivate([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONBEFOREACTIVATE)]
+    VARIANT_BOOL onbeforeactivate([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONFOCUSIN)]
+    void onfocusin([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONFOCUSOUT)]
+    void onfocusout([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOVE)]
+    void onmove([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONCONTROLSELECT)]
+    VARIANT_BOOL oncontrolselect([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOVESTART)]
+    VARIANT_BOOL onmovestart([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOVEEND)]
+    void onmoveend([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONRESIZESTART)]
+    VARIANT_BOOL onresizestart([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONRESIZEEND)]
+    void onresizeend([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLELEMENTEVENTS2_ONMOUSEWHEEL)]
+    VARIANT_BOOL onmousewheel([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLFORMELEMENTEVENTS2_ONSUBMIT)]
+    VARIANT_BOOL onsubmit([in] IHTMLEventObj* pEvtObj);
+
+    [id(DISPID_HTMLFORMELEMENTEVENTS2_ONRESET)]
+    VARIANT_BOOL onreset([in] IHTMLEventObj* pEvtObj);
+};
+
+[
+    noncreatable,
+    uuid(3050F24D-98B5-11CF-BB82-00AA00BDCE0B)
+]
+coclass HTMLFormElement
+{
+    [default]           dispinterface DispHTMLFormElement;
+    [source, default]   dispinterface HTMLFormElementEvents;
+    [source]            dispinterface HTMLFormElementEvents2;
+                        interface IHTMLElement;
+                        interface IHTMLElement2;
+                        interface IHTMLElement3;
+                        interface IHTMLElement4;
+                        interface IHTMLUniqueName;
+                        interface IHTMLDOMNode;
+                        interface IHTMLDOMNode2;
+                        interface IHTMLDOMConstructor;
+                        interface IHTMLFormElement;
+}
+
+/*****************************************************************************
  *    IHTMLTextContainer interface
  */
@@ -6252,5 +7139,5 @@
     oleautomation,
     dual,
-    uuid(3050F38E-98B5-11CF-BB82-00AAA0BDCE0B)
+    uuid(3050F38E-98B5-11CF-BB82-00AA00BDCE0B)
 ]
 interface IHTMLImageElementFactory : IDispatch
@@ -6274,843 +7161,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    void dataFld(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    BSTR dataFld();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    void dataSrc(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    BSTR dataSrc();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    void dataFormatAs(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    BSTR dataFormatAs();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLIMGELEMENT_ISMAP), displaybind, bindable]
@@ -7260,50 +7309,5 @@
     [propget, id(DISPID_IHTMLIMGELEMENT2_LONGDESC), displaybind, bindable]
     BSTR longDesc();
-};
-
-/*****************************************************************************
- *    IHTMLUniqueName interface
- */
-[
-    odl,
-    oleautomation,
-    dual,
-    uuid(3050f4d0-98b5-11cf-bb82-00aa00bdce0b)
-]
-interface IHTMLUniqueName : IDispatch
-{
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    HRESULT uniqueNumber([retval, out] LONG * p);
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    HRESULT uniqueID([retval, out] BSTR * p);
-};
-
-[
-    odl,
-    oleautomation,
-    dual,
-    uuid(3050f3f2-98b5-11cf-bb82-00aa00bdce0b)
-]
-interface IHTMLDatabinding : IDispatch
-{
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    HRESULT dataFld([in] BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    HRESULT dataFld([retval, out] BSTR * p);
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    HRESULT dataSrc([in] BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    HRESULT dataSrc([retval, out] BSTR * p);
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    HRESULT dataFormatAs([in] BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    HRESULT dataFormatAs([retval, out] BSTR * p);
-};
+}
 
 /*****************************************************************************
@@ -7522,812 +7526,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-        [in] BSTR strAttributeName,
-        [in] VARIANT AttValue,
-        [defaultvalue(1), in] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-        [in] BSTR strAttributeName,
-        [defaultvalue(0), in] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-        [in] BSTR strAttributeName,
-        [defaultvalue(1), in] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement* parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle* style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)] IDispatch* document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([optional, in] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement* pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement* offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-        [in] BSTR where,
-        [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-        [in] BSTR where,
-        [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement* parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)] void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection* filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch* children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch* all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([defaultvalue(-1), in] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint([in] LONG x,[in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([optional, in] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-     void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-     VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle* currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection* getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect* getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-        [in] BSTR propname,
-        [in] BSTR expr,
-        [defaultvalue(""), in] BSTR lang);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-     VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown* pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown* pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-        [in] BSTR event,
-        [in] IDispatch* pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-        [in] BSTR event,
-        [in] IDispatch* pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)] VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-     void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch* createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement* insertAdjacentElement(
-        [in] BSTR where,
-        [in] IHTMLElement* insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement* applyElement([in] IHTMLElement* apply,[in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText([in] BSTR where,[in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior([in] BSTR bstrUrl,[optional, in] VARIANT* pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle* runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch* behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection* getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-        [in] IHTMLElement* mergeThis,
-        [optional, in] VARIANT* pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-        [in] BSTR bstrEventName,
-        [optional, in] VARIANT* pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-     void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable] VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-     IHTMLDOMAttribute* getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute* setAttributeNode([in] IHTMLDOMAttribute* pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute* removeAttributeNode([in] IHTMLDOMAttribute* pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode* parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch* childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch* attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode* insertBefore(
-        [in] IHTMLDOMNode* newChild,
-        [optional, in] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode* removeChild([in] IHTMLDOMNode* oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode* replaceChild(
-        [in] IHTMLDOMNode* newChild,
-        [in] IHTMLDOMNode* oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode* cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode* removeNode([defaultvalue(0), in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode* swapNode([in] IHTMLDOMNode* otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode* replaceNode([in] IHTMLDOMNode* replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode* appendChild([in] IHTMLDOMNode* newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode* firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode* lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode* previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode* nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch* ownerDocument();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLBODYELEMENT_BACKGROUND), displaybind, bindable]
@@ -8606,4 +7803,159 @@
 
 /*****************************************************************************
+ *    DispHTMLAnchorElement dispinterface
+ */
+[
+    hidden,
+    uuid(3050f502-98b5-11cf-bb82-00aa00bdce0b)
+]
+dispinterface DispHTMLAnchorElement
+{
+properties:
+methods:
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_HREF), displaybind, bindable]
+    void href(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_HREF), displaybind, bindable]
+    BSTR href();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_TARGET), displaybind, bindable]
+    void target(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_TARGET), displaybind, bindable]
+    BSTR target();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_REL), displaybind, bindable]
+    void rel(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_REL), displaybind, bindable]
+    BSTR rel();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_REV), displaybind, bindable]
+    void rev(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_REV), displaybind, bindable]
+    BSTR rev();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_URN), displaybind, bindable]
+    void urn(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_URN), displaybind, bindable]
+    BSTR urn();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_METHODS), displaybind, bindable]
+    void Methods(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_METHODS), displaybind, bindable]
+    BSTR Methods();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_NAME), displaybind, bindable]
+    void name(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_NAME), displaybind, bindable]
+    BSTR name();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_HOST)]
+    void host(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_HOST)]
+    BSTR host();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_HOSTNAME)]
+    void hostname(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_HOSTNAME)]
+    BSTR hostname();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_PATHNAME)]
+    void pathname(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_PATHNAME)]
+    BSTR pathname();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_PORT)]
+    void port(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_PORT)]
+    BSTR port();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_PROTOCOL)]
+    void protocol(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_PROTOCOL)]
+    BSTR protocol();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_SEARCH)]
+    void search(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_SEARCH)]
+    BSTR search();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT_HASH)]
+    void hash(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_HASH)]
+    BSTR hash();
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_PROTOCOLLONG)]
+    BSTR protocolLong();
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_MIMETYPE)]
+    BSTR mimeType();
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT_NAMEPROP)]
+    BSTR nameProp();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT2_CHARSET), displaybind, bindable]
+    void charset(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT2_CHARSET), displaybind, bindable]
+    BSTR charset();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT2_COORDS), displaybind, bindable]
+    void coords(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT2_COORDS), displaybind, bindable]
+    BSTR coords();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT2_HREFLANG), displaybind, bindable]
+    void hreflang(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT2_HREFLANG), displaybind, bindable]
+    BSTR hreflang();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT2_SHAPE), displaybind, bindable]
+    void shape(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT2_SHAPE), displaybind, bindable]
+    BSTR shape();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT2_TYPE), displaybind, bindable]
+    void type(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT2_TYPE), displaybind, bindable]
+    BSTR type();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT3_IE8_SHAPE)]
+    void ie8_shape(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT3_IE8_SHAPE)]
+    BSTR ie8_shape();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT3_IE8_COORDS)]
+    void ie8_coords(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT3_IE8_COORDS)]
+    BSTR ie8_coords();
+
+    [propput, id(DISPID_IHTMLANCHORELEMENT3_IE8_HREF)]
+    void ie8_href(BSTR v);
+
+    [propget, id(DISPID_IHTMLANCHORELEMENT3_IE8_HREF)]
+    BSTR ie8_href();
+}
+
+/*****************************************************************************
  *    IHTMLElementCollection interface
  */
@@ -8781,843 +8133,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    void dataFld(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    BSTR dataFld();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    void dataSrc(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    BSTR dataSrc();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    void dataFormatAs(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    BSTR dataFormatAs();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLSELECTELEMENT_SIZE), displaybind, bindable]
@@ -9813,843 +8327,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    void dataFld(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    BSTR dataFld();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    void dataSrc(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    BSTR dataSrc();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    void dataFormatAs(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    BSTR dataFormatAs();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLOPTIONELEMENT_SELECTED)]
@@ -11013,843 +8689,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    void dataFld(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    BSTR dataFld();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    void dataSrc(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    BSTR dataSrc();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    void dataFormatAs(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    BSTR dataFormatAs();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLINPUTELEMENT_TYPE)]
@@ -12153,825 +8991,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
+    WINE_HTMLELEMENT_DISPINTERFACE_DECL;
 }
 
@@ -13136,8 +9154,8 @@
  */
 [
-	odl,
-	oleautomation,
-	dual,
-	uuid(FECEAAA5-8405-11CF-8BA1-00AA00476DA6)
+    odl,
+    oleautomation,
+    dual,
+    uuid(FECEAAA5-8405-11CF-8BA1-00AA00476DA6)
 ]
 interface IOmNavigator : IDispatch
@@ -13275,6 +9293,5 @@
     IHTMLOpsProfile *userProfile();
 
-    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
-    IDispatch *constructor();
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL;
 }
 
@@ -13432,6 +9449,5 @@
     BSTR toString();
 
-    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
-    IDispatch *constructor();
+    WINE_IHTMLDOMCONSTRUCTOR_DISPINTERFACE_DECL;
 }
 
@@ -14258,4 +10274,67 @@
     HRESULT XMLHttpRequest([retval, out] VARIANT * p);
 };
+
+/*****************************************************************************
+ *    DispHTMLScreen dispinterface
+ */
+[
+    hidden,
+    uuid(3050f591-98b5-11cf-bb82-00aa00bdce0b)
+]
+dispinterface DispHTMLScreen
+{
+properties:
+methods:
+    [propget, id(DISPID_IHTMLSCREEN_COLORDEPTH)]
+    long colorDepth();
+
+    [propput, id(DISPID_IHTMLSCREEN_BUFFERDEPTH)]
+    void bufferDepth(long v);
+
+    [propget, id(DISPID_IHTMLSCREEN_BUFFERDEPTH)]
+    long bufferDepth();
+
+    [propget, id(DISPID_IHTMLSCREEN_WIDTH)]
+    long width();
+
+    [propget, id(DISPID_IHTMLSCREEN_HEIGHT)]
+    long height();
+
+    [propput, id(DISPID_IHTMLSCREEN_UPDATEINTERVAL)]
+    void updateInterval(long v);
+
+    [propget, id(DISPID_IHTMLSCREEN_UPDATEINTERVAL)]
+    long updateInterval();
+
+    [propget, id(DISPID_IHTMLSCREEN_AVAILHEIGHT)]
+    long availHeight();
+
+    [propget, id(DISPID_IHTMLSCREEN_AVAILWIDTH)]
+    long availWidth();
+
+    [propget, id(DISPID_IHTMLSCREEN_FONTSMOOTHINGENABLED)]
+    VARIANT_BOOL fontSmoothingEnabled();
+
+    [propget, id(DISPID_IHTMLSCREEN2_LOGICALXDPI)]
+    long logicalXDPI();
+
+    [propget, id(DISPID_IHTMLSCREEN2_LOGICALYDPI)]
+    long logicalYDPI();
+
+    [propget, id(DISPID_IHTMLSCREEN2_DEVICEXDPI)]
+    long deviceXDPI();
+
+    [propget, id(DISPID_IHTMLSCREEN2_DEVICEYDPI)]
+    long deviceYDPI();
+
+    [propget, id(DISPID_IHTMLSCREEN3_SYSTEMXDPI)]
+    long systemXDPI();
+
+    [propget, id(DISPID_IHTMLSCREEN3_SYSTEMYDPI)]
+    long systemYDPI();
+
+    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
+    IDispatch *constructor();
+}
 
 /*****************************************************************************
@@ -16278,4 +12357,42 @@
 
 /*****************************************************************************
+ *    IHTMLDocument6 interface
+ */
+[
+    odl,
+    oleautomation,
+    dual,
+    uuid(30510417-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IHTMLDocument6 : IDispatch
+{
+    [propget, id(DISPID_IHTMLDOCUMENT6_COMPATIBLE)]
+    HRESULT compatible([retval, out] IHTMLDocumentCompatibleInfoCollection **p);
+
+    [propget, id(DISPID_IHTMLDOCUMENT6_DOCUMENTMODE)]
+    HRESULT documentMode([retval, out] VARIANT *p);
+
+    [propput, id(DISPID_IHTMLDOCUMENT6_ONSTORAGE), displaybind, bindable]
+    HRESULT onstorage([in] VARIANT v);
+
+    [propget, id(DISPID_IHTMLDOCUMENT6_ONSTORAGE), displaybind, bindable]
+    HRESULT onstorage([out] VARIANT *p);
+
+    [propput, id(DISPID_IHTMLDOCUMENT6_ONSTORAGECOMMIT), displaybind, bindable]
+    HRESULT onstoragecommit([in] VARIANT v);
+
+    [propget, id(DISPID_IHTMLDOCUMENT6_ONSTORAGECOMMIT), displaybind, bindable]
+    HRESULT onstoragecommit([out] VARIANT *p);
+
+    [id(DISPID_IHTMLDOCUMENT6_IE8_GETELEMENTBYID)]
+    HRESULT getElementById(
+        [in] BSTR bstrId,
+        [retval, out] IHTMLElement2 **p);
+
+    [id(DISPID_IHTMLDOCUMENT6_UPDATESETTINGS)]
+    HRESULT updateSettings();
+}
+
+/*****************************************************************************
  *    DispHTMLDocument dispinterface
  */
@@ -16853,70 +12970,29 @@
     BSTR compatMode();
 
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-        [in] IHTMLDOMNode *newChild,
-        [optional, in] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-        [in] IHTMLDOMNode *newChild,
-        [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([defaultvalue(0), in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode* otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
+    [propget, id(DISPID_IHTMLDOCUMENT6_COMPATIBLE)]
+    IHTMLDocumentCompatibleInfoCollection *compatible();
+
+    [propget, id(DISPID_IHTMLDOCUMENT6_DOCUMENTMODE)]
+    VARIANT documentMode();
+
+    [propput, id(DISPID_IHTMLDOCUMENT6_ONSTORAGE), displaybind, bindable]
+    void onstorage(VARIANT v);
+
+    [propget, id(DISPID_IHTMLDOCUMENT6_ONSTORAGE), displaybind, bindable]
+    VARIANT onstorage();
+
+    [propput, id(DISPID_IHTMLDOCUMENT6_ONSTORAGECOMMIT), displaybind, bindable]
+    void onstoragecommit(VARIANT v);
+
+    [propget, id(DISPID_IHTMLDOCUMENT6_ONSTORAGECOMMIT), displaybind, bindable]
+    VARIANT onstoragecommit();
+
+    [id(DISPID_IHTMLDOCUMENT6_IE8_GETELEMENTBYID)]
+    IHTMLElement2 *ie8_getElementById([in] BSTR bstrId);
+
+    [id(DISPID_IHTMLDOCUMENT6_UPDATESETTINGS)]
+    void updateSettings();
+
+    WINE_HTMLDOMNODE_DISPINTERFACE_DECL;
 }
 
@@ -16936,4 +13012,5 @@
                       interface IHTMLDocument4;
                       interface IHTMLDocument5;
+                      interface IHTMLDocument6;
                       interface IHTMLDOMNode;
                       interface IHTMLDOMNode2;
@@ -17021,825 +13098,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
+    WINE_HTMLELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLCOMMENTELEMENT_TEXT), displaybind, bindable]
@@ -19060,843 +14317,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    void dataFld(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    BSTR dataFld();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    void dataSrc(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    BSTR dataSrc();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    void dataFormatAs(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    BSTR dataFormatAs();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLTABLE_COLS)]
@@ -20070,825 +14489,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
+    WINE_HTMLELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLTABLEROW_ALIGN)]
@@ -21150,843 +14749,5 @@
 properties:
 methods:
-    [id(DISPID_IHTMLELEMENT_SETATTRIBUTE)]
-    void setAttribute(
-            [in] BSTR strAttributeName,
-            [in] VARIANT AttributeValue,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_GETATTRIBUTE)]
-    VARIANT getAttribute(
-             [in] BSTR strAttributeName,
-             [in, defaultvalue(0)] LONG lFlags);
-
-    [id(DISPID_IHTMLELEMENT_REMOVEATTRIBUTE)]
-    VARIANT_BOOL removeAttribute(
-            [in] BSTR strAttributeName,
-            [in, defaultvalue(1)] LONG lFlags);
-
-    [propput, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    void className(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_CLASSNAME), bindable]
-    BSTR className();
-
-    [propput, id(DISPID_IHTMLELEMENT_ID), bindable]
-    void id(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ID), bindable]
-    BSTR id();
-
-    [propget, id(DISPID_IHTMLELEMENT_TAGNAME)]
-    BSTR tagName();
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTELEMENT)]
-    IHTMLElement *parentElement();
-
-    [propget, id(DISPID_IHTMLELEMENT_STYLE), nonbrowsable]
-    IHTMLStyle *style();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    void onhelp(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONHELP), displaybind, bindable]
-    VARIANT onhelp();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    void onclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONCLICK), displaybind, bindable]
-    VARIANT onclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    void ondblclick(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDBLCLICK), displaybind, bindable]
-    VARIANT ondblclick();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    void onkeydown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYDOWN), displaybind, bindable]
-    VARIANT onkeydown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    void onkeyup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYUP), displaybind, bindable]
-    VARIANT onkeyup();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    void onkeypress(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONKEYPRESS), displaybind, bindable]
-    VARIANT onkeypress();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    void onmouseout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOUT), displaybind, bindable]
-    VARIANT onmouseout();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    void onmouseover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEOVER), displaybind, bindable]
-    VARIANT onmouseover();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    void onmousemove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEMOVE), displaybind, bindable]
-    VARIANT onmousemove();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    void onmousedown(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEDOWN), displaybind, bindable]
-    VARIANT onmousedown();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    void onmouseup(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONMOUSEUP), displaybind, bindable]
-    VARIANT onmouseup();
-
-    [propget, id(DISPID_IHTMLELEMENT_DOCUMENT)]
-    IDispatch *document();
-
-    [propput, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    void title(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_TITLE), displaybind, bindable]
-    BSTR title();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    void language(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANGUAGE), displaybind, bindable]
-    BSTR language();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    void onselectstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONSELECTSTART), displaybind, bindable]
-    VARIANT onselectstart();
-
-    [id(DISPID_IHTMLELEMENT_SCROLLINTOVIEW)]
-    void scrollIntoView([in, optional] VARIANT varargStart);
-
-    [id(DISPID_IHTMLELEMENT_CONTAINS)]
-    VARIANT_BOOL contains([in] IHTMLElement *pChild);
-
-    [propget, id(DISPID_IHTMLELEMENT_SOURCEINDEX), bindable]
-    LONG sourceIndex();
-
-    [propget, id(DISPID_IHTMLELEMENT_RECORDNUMBER)]
-    VARIANT recordNumber();
-
-    [propput, id(DISPID_IHTMLELEMENT_LANG)]
-    void lang(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_LANG)]
-    BSTR lang();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETLEFT)]
-    LONG offsetLeft();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETTOP)]
-    LONG offsetTop();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETWIDTH)]
-    LONG offsetWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETHEIGHT)]
-    LONG offsetHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT_OFFSETPARENT)]
-    IHTMLElement *offsetParent();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    void innerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERHTML)]
-    BSTR innerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    void innerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_INNERTEXT)]
-    BSTR innerText();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    void outerHTML(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERHTML)]
-    BSTR outerHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    void outerText(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT_OUTERTEXT)]
-    BSTR outerText();
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTHTML)]
-    void insertAdjacentHTML(
-            [in] BSTR where,
-            [in] BSTR html);
-
-    [id(DISPID_IHTMLELEMENT_INSERTADJACENTTEXT)]
-    void insertAdjacentText(
-            [in] BSTR where,
-            [in] BSTR text);
-
-    [propget, id(DISPID_IHTMLELEMENT_PARENTTEXTEDIT)]
-    IHTMLElement *parentTextEdit();
-
-    [propget, id(DISPID_IHTMLELEMENT_ISTEXTEDIT)]
-    VARIANT_BOOL isTextEdit();
-
-    [id(DISPID_IHTMLELEMENT_CLICK)]
-    void click();
-
-    [propget, id(DISPID_IHTMLELEMENT_FILTERS)]
-    IHTMLFiltersCollection *filters();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    void ondragstart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDRAGSTART), displaybind, bindable]
-    VARIANT ondragstart();
-
-    [id(DISPID_IHTMLELEMENT_TOSTRING)]
-    BSTR toString();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    void onbeforeupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONBEFOREUPDATE), displaybind, bindable]
-    VARIANT onbeforeupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    void onafterupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONAFTERUPDATE), displaybind, bindable]
-    VARIANT onafterupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    void onerrorupdate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONERRORUPDATE), displaybind, bindable]
-    VARIANT onerrorupdate();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    void onrowexit(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWEXIT), displaybind, bindable]
-    VARIANT onrowexit();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    void onrowenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONROWENTER), displaybind, bindable]
-    VARIANT onrowenter();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    void ondatasetchanged(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCHANGED), displaybind, bindable]
-    VARIANT ondatasetchanged();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    void ondataavailable(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATAAVAILABLE), displaybind, bindable]
-    VARIANT ondataavailable();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    void ondatasetcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONDATASETCOMPLETE), displaybind, bindable]
-    VARIANT ondatasetcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    void onfilterchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT_ONFILTERCHANGE), displaybind, bindable]
-    VARIANT onfilterchange();
-
-    [propget, id(DISPID_IHTMLELEMENT_CHILDREN)]
-    IDispatch *children();
-
-    [propget, id(DISPID_IHTMLELEMENT_ALL)]
-    IDispatch *all();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCOPENAME)]
-    BSTR scopeName();
-
-    [id(DISPID_IHTMLELEMENT2_SETCAPTURE)]
-    void setCapture([in, defaultvalue(-1)] VARIANT_BOOL containerCapture);
-
-    [id(DISPID_IHTMLELEMENT2_RELEASECAPTURE)]
-    void releaseCapture();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    void onlosecapture(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONLOSECAPTURE), displaybind, bindable]
-    VARIANT onlosecapture();
-
-    [id(DISPID_IHTMLELEMENT2_COMPONENTFROMPOINT)]
-    BSTR componentFromPoint(
-            [in] LONG x,
-            [in] LONG y);
-
-    [id(DISPID_IHTMLELEMENT2_DOSCROLL)]
-    void doScroll([in, optional] VARIANT component);
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    void onscroll(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONSCROLL), displaybind, bindable]
-    VARIANT onscroll();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    void ondrag(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAG), displaybind, bindable]
-    VARIANT ondrag();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    void ondragend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGEND), displaybind, bindable]
-    VARIANT ondragend();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    void ondragenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGENTER), displaybind, bindable]
-    VARIANT ondragenter();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    void ondragover(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGOVER), displaybind, bindable]
-    VARIANT ondragover();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    void ondragleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDRAGLEAVE), displaybind, bindable]
-    VARIANT ondragleave();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    void ondrop(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONDROP), displaybind, bindable]
-    VARIANT ondrop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    void onbeforecut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECUT), displaybind, bindable]
-    VARIANT onbeforecut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    void oncut(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCUT), displaybind, bindable]
-    VARIANT oncut();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    void onbeforecopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFORECOPY), displaybind, bindable]
-    VARIANT onbeforecopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    void oncopy(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCOPY), displaybind, bindable]
-    VARIANT oncopy();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    void onbeforepaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREPASTE), displaybind, bindable]
-    VARIANT onbeforepaste();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    void onpaste(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPASTE), displaybind, bindable]
-    VARIANT onpaste();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CURRENTSTYLE), nonbrowsable]
-    IHTMLCurrentStyle *currentStyle();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    void onpropertychange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONPROPERTYCHANGE), displaybind, bindable]
-    VARIANT onpropertychange();
-
-    [id(DISPID_IHTMLELEMENT2_GETCLIENTRECTS)]
-    IHTMLRectCollection *getClientRects();
-
-    [id(DISPID_IHTMLELEMENT2_GETBOUNDINGCLIENTRECT)]
-    IHTMLRect *getBoundingClientRect();
-
-    [id(DISPID_IHTMLELEMENT2_SETEXPRESSION)]
-    void setExpression(
-            [in] BSTR propname,
-            [in] BSTR expression,
-            [in, defaultvalue("")] BSTR language);
-
-    [id(DISPID_IHTMLELEMENT2_GETEXPRESSION)]
-    VARIANT getExpression([in] BSTR propname);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEEXPRESSION)]
-    VARIANT_BOOL removeExpression([in] BSTR propname);
-
-    [propput, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    void tabIndex(short v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TABINDEX), displaybind, bindable]
-    short tabIndex();
-
-    [id(DISPID_IHTMLELEMENT2_FOCUS)]
-    void focus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    void accessKey(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ACCESSKEY), displaybind, bindable]
-    BSTR accessKey();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    void onblur(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBLUR), displaybind, bindable]
-    VARIANT onblur();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    void onfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONFOCUS), displaybind, bindable]
-    VARIANT onfocus();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    void onresize(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONRESIZE), displaybind, bindable]
-    VARIANT onresize();
-
-    [id(DISPID_IHTMLELEMENT2_BLUR)]
-    void blur();
-
-    [id(DISPID_IHTMLELEMENT2_ADDFILTER)]
-    void addFilter([in] IUnknown *pUnk);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEFILTER)]
-    void removeFilter([in] IUnknown *pUnk);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTHEIGHT), displaybind, bindable]
-    LONG clientHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTWIDTH), displaybind, bindable]
-    LONG clientWidth();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTTOP), displaybind, bindable]
-    LONG clientTop();
-
-    [propget, id(DISPID_IHTMLELEMENT2_CLIENTLEFT), displaybind, bindable]
-    LONG clientLeft();
-
-    [id(DISPID_IHTMLELEMENT2_ATTACHEVENT)]
-    VARIANT_BOOL attachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [id(DISPID_IHTMLELEMENT2_DETACHEVENT)]
-    void detachEvent(
-            [in] BSTR event,
-            [in] IDispatch *pDisp);
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATE)]
-    VARIANT readyState();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    void onreadystatechange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONREADYSTATECHANGE), displaybind, bindable]
-    VARIANT onreadystatechange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    void onrowsdelete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSDELETE), displaybind, bindable]
-    VARIANT onrowsdelete();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-    void onrowsinserted(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONROWSINSERTED), displaybind, bindable]
-     VARIANT onrowsinserted();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-     void oncellchange(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCELLCHANGE), displaybind, bindable]
-    VARIANT oncellchange();
-
-    [propput, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    void dir(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_DIR), displaybind, bindable]
-    BSTR dir();
-
-    [id(DISPID_IHTMLELEMENT2_CREATECONTROLRANGE)]
-    IDispatch *createControlRange();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLHEIGHT), displaybind, bindable]
-    LONG scrollHeight();
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLWIDTH), displaybind, bindable]
-    LONG scrollWidth();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    void scrollTop(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLTOP), displaybind, bindable]
-    LONG scrollTop();
-
-    [propput, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    void scrollLeft(LONG v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_SCROLLLEFT), displaybind, bindable]
-    LONG scrollLeft();
-
-    [id(DISPID_IHTMLELEMENT2_CLEARATTRIBUTES)]
-    void clearAttributes();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    void oncontextmenu(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONCONTEXTMENU), displaybind, bindable]
-    VARIANT oncontextmenu();
-
-    [id(DISPID_IHTMLELEMENT2_INSERTADJACENTELEMENT)]
-    IHTMLElement *insertAdjacentElement(
-            [in] BSTR where,
-            [in] IHTMLElement *insertedElement);
-
-    [id(DISPID_IHTMLELEMENT2_APPLYELEMENT)]
-    IHTMLElement *applyElement(
-            [in] IHTMLElement *apply,
-            [in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_GETADJACENTTEXT)]
-    BSTR getAdjacentText([in] BSTR where);
-
-    [id(DISPID_IHTMLELEMENT2_REPLACEADJACENTTEXT)]
-    BSTR replaceAdjacentText(
-            [in] BSTR where,
-            [in] BSTR newText);
-
-    [propget, id(DISPID_IHTMLELEMENT2_CANHAVECHILDREN)]
-    VARIANT_BOOL canHaveChildren();
-
-    [id(DISPID_IHTMLELEMENT2_ADDBEHAVIOR)]
-    LONG addBehavior(
-            [in] BSTR bstrUrl,
-            [in, optional] VARIANT *pvarFactory);
-
-    [id(DISPID_IHTMLELEMENT2_REMOVEBEHAVIOR)]
-    VARIANT_BOOL removeBehavior([in] LONG cookie);
-
-    [propget, id(DISPID_IHTMLELEMENT2_RUNTIMESTYLE), nonbrowsable]
-    IHTMLStyle *runtimeStyle();
-
-    [propget, id(DISPID_IHTMLELEMENT2_BEHAVIORURNS)]
-    IDispatch *behaviorUrns();
-
-    [propput, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    void tagUrn(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_TAGURN)]
-    BSTR tagUrn();
-
-    [propput, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    void onbeforeeditfocus(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT2_ONBEFOREEDITFOCUS), displaybind, bindable]
-    VARIANT onbeforeeditfocus();
-
-    [propget, id(DISPID_IHTMLELEMENT2_READYSTATEVALUE), hidden, restricted]
-    LONG readyStateValue();
-
-    [id(DISPID_IHTMLELEMENT2_GETELEMENTSBYTAGNAME)]
-    IHTMLElementCollection *getElementsByTagName([in] BSTR v);
-
-    [id(DISPID_IHTMLELEMENT3_MERGEATTRIBUTES)]
-    void mergeAttributes(
-            [in] IHTMLElement *mergeThis,
-            [in, optional] VARIANT *pvarFlags);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISMULTILINE)]
-    VARIANT_BOOL isMultiLine();
-
-    [propget, id(DISPID_IHTMLELEMENT3_CANHAVEHTML)]
-    VARIANT_BOOL canHaveHTML();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    void onlayoutcomplete(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONLAYOUTCOMPLETE), displaybind, bindable]
-    VARIANT onlayoutcomplete();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    void onpage(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONPAGE), displaybind, bindable]
-    VARIANT onpage();
-
-    [propput, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    void inflateBlock(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_INFLATEBLOCK), hidden, restricted, nonbrowsable]
-    VARIANT_BOOL inflateBlock();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    void onbeforedeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONBEFOREDEACTIVATE), displaybind, bindable]
-    VARIANT onbeforedeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_SETACTIVE)]
-    void setActive();
-
-    [propput, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    void contentEditable(BSTR v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_CONTENTEDITABLE), displaybind, bindable]
-    BSTR contentEditable();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISCONTENTEDITABLE)]
-    VARIANT_BOOL isContentEditable();
-
-    [propput, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    void hideFocus(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_HIDEFOCUS), displaybind, bindable]
-    VARIANT_BOOL hideFocus();
-
-    [propput, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    void disabled(VARIANT_BOOL v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_DISABLED), displaybind, bindable]
-    VARIANT_BOOL disabled();
-
-    [propget, id(DISPID_IHTMLELEMENT3_ISDISABLED)]
-    VARIANT_BOOL isDisabled();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    void onmove(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVE), displaybind, bindable]
-    VARIANT onmove();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    void oncontrolselect(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONCONTROLSELECT), displaybind, bindable]
-    VARIANT oncontrolselect();
-
-    [id(DISPID_IHTMLELEMENT3_FIREEVENT)]
-    VARIANT_BOOL fireEvent(
-            [in] BSTR bstrEventName,
-            [in, optional] VARIANT *pvarEventObject);
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    void onresizestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZESTART), displaybind, bindable]
-    VARIANT onresizestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    void onresizeend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONRESIZEEND), displaybind, bindable]
-    VARIANT onresizeend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    void onmovestart(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVESTART), displaybind, bindable]
-    VARIANT onmovestart();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    void onmoveend(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOVEEND), displaybind, bindable]
-    VARIANT onmoveend();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    void onmouseenter(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSEENTER), displaybind, bindable]
-    VARIANT onmouseenter();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    void onmouseleave(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONMOUSELEAVE), displaybind, bindable]
-    VARIANT onmouseleave();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    void onactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONACTIVATE), displaybind, bindable]
-    VARIANT onactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    void ondeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT3_ONDEACTIVATE), displaybind, bindable]
-    VARIANT ondeactivate();
-
-    [id(DISPID_IHTMLELEMENT3_DRAGDROP)]
-    VARIANT_BOOL dragDrop();
-
-    [propget, id(DISPID_IHTMLELEMENT3_GLYPHMODE), hidden, restricted, nonbrowsable]
-    LONG glyphMode();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    void onmousewheel(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONMOUSEWHEEL), displaybind, bindable]
-    VARIANT onmousewheel();
-
-    [id(DISPID_IHTMLELEMENT4_NORMALIZE)]
-    void normalize();
-
-    [id(DISPID_IHTMLELEMENT4_GETATTRIBUTENODE)]
-    IHTMLDOMAttribute *getAttributeNode([in] BSTR bstrname);
-
-    [id(DISPID_IHTMLELEMENT4_SETATTRIBUTENODE)]
-    IHTMLDOMAttribute *setAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [id(DISPID_IHTMLELEMENT4_REMOVEATTRIBUTENODE)]
-    IHTMLDOMAttribute *removeAttributeNode([in] IHTMLDOMAttribute *pattr);
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    void onbeforeactivate(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONBEFOREACTIVATE), displaybind, bindable]
-    VARIANT onbeforeactivate();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    void onfocusin(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSIN), displaybind, bindable]
-    VARIANT onfocusin();
-
-    [propput, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    void onfocusout(VARIANT v);
-
-    [propget, id(DISPID_IHTMLELEMENT4_ONFOCUSOUT), displaybind, bindable]
-    VARIANT onfocusout();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUENUMBER), hidden]
-    LONG uniqueNumber();
-
-    [propget, id(DISPID_IHTMLUNIQUENAME_UNIQUEID), hidden]
-    BSTR uniqueID();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODETYPE)]
-    LONG nodeType();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PARENTNODE)]
-    IHTMLDOMNode *parentNode();
-
-    [id(DISPID_IHTMLDOMNODE_HASCHILDNODES)]
-    VARIANT_BOOL hasChildNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_CHILDNODES)]
-    IDispatch *childNodes();
-
-    [propget, id(DISPID_IHTMLDOMNODE_ATTRIBUTES)]
-    IDispatch *attributes();
-
-    [id(DISPID_IHTMLDOMNODE_INSERTBEFORE)]
-    IHTMLDOMNode *insertBefore(
-            [in] IHTMLDOMNode *newChild,
-            [in, optional] VARIANT refChild);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVECHILD)]
-    IHTMLDOMNode *removeChild([in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACECHILD)]
-    IHTMLDOMNode *replaceChild(
-            [in] IHTMLDOMNode *newChild,
-            [in] IHTMLDOMNode *oldChild);
-
-    [id(DISPID_IHTMLDOMNODE_CLONENODE)]
-    IHTMLDOMNode *cloneNode([in] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_REMOVENODE)]
-    IHTMLDOMNode *removeNode([in, defaultvalue(0)] VARIANT_BOOL fDeep);
-
-    [id(DISPID_IHTMLDOMNODE_SWAPNODE)]
-    IHTMLDOMNode *swapNode([in] IHTMLDOMNode *otherNode);
-
-    [id(DISPID_IHTMLDOMNODE_REPLACENODE)]
-    IHTMLDOMNode *replaceNode([in] IHTMLDOMNode *replacement);
-
-    [id(DISPID_IHTMLDOMNODE_APPENDCHILD)]
-    IHTMLDOMNode *appendChild([in] IHTMLDOMNode *newChild);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODENAME)]
-    BSTR nodeName();
-
-    [propput, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    void nodeValue(VARIANT v);
-
-    [propget, id(DISPID_IHTMLDOMNODE_NODEVALUE)]
-    VARIANT nodeValue();
-
-    [propget, id(DISPID_IHTMLDOMNODE_FIRSTCHILD)]
-    IHTMLDOMNode *firstChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_LASTCHILD)]
-    IHTMLDOMNode *lastChild();
-
-    [propget, id(DISPID_IHTMLDOMNODE_PREVIOUSSIBLING)]
-    IHTMLDOMNode *previousSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE_NEXTSIBLING)]
-    IHTMLDOMNode *nextSibling();
-
-    [propget, id(DISPID_IHTMLDOMNODE2_OWNERDOCUMENT)]
-    IDispatch *ownerDocument();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    void dataFld(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFLD)]
-    BSTR dataFld();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    void dataSrc(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATASRC)]
-    BSTR dataSrc();
-
-    [propput, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    void dataFormatAs(BSTR v);
-
-    [propget, id(DISPID_IHTMLDATABINDING_DATAFORMATAS)]
-    BSTR dataFormatAs();
+    WINE_HTMLDATAELEMENT_DISPINTERFACE_DECL;
 
     [propput, id(DISPID_IHTMLFRAMEBASE_SRC)]
@@ -22334,3 +15095,44 @@
 }
 
+/*****************************************************************************
+ *    IElementBehaviorSite interface
+ */
+[
+    odl,
+    uuid(3050F427-98B5-11CF-BB82-00AA00BDCE0B)
+]
+interface IElementBehaviorSite : IUnknown {
+    HRESULT GetElement([out, retval] IHTMLElement **ppElement);
+    HRESULT RegisterNotification([in] long lEvent);
+}
+
+/*****************************************************************************
+ *    IElementBehavior interface
+ */
+[
+    odl,
+    uuid(3050F425-98B5-11CF-BB82-00AA00BDCE0B)
+]
+interface IElementBehavior : IUnknown {
+    HRESULT Init([in] IElementBehaviorSite *pBehaviorSite);
+    HRESULT Notify([in] long lEvent,  [in, out] VARIANT *pVar);
+    HRESULT Detach();
+}
+
+/*****************************************************************************
+ *    IElementBehaviorFactory interface
+ */
+[
+    odl,
+    uuid(3050f429-98b5-11cf-bb82-00aa00bdce0b)
+]
+interface IElementBehaviorFactory : IUnknown
+{
+    HRESULT FindBehavior(
+        [in] BSTR bstrBehavior,
+        [in] BSTR bstrBehaviorUrl,
+        [in] IElementBehaviorSite *pSite,
+        [out] IElementBehavior **ppBehavior);
+}
+
 } /* library MSHTML */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msiquery.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msiquery.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msiquery.h	(revision 25949)
@@ -311,5 +311,5 @@
 UINT WINAPI MsiEnableUIPreview(MSIHANDLE, MSIHANDLE*);
 BOOL WINAPI MsiGetMode(MSIHANDLE, MSIRUNMODE);
-BOOL WINAPI MsiSetMode(MSIHANDLE, MSIRUNMODE, BOOL);
+UINT WINAPI MsiSetMode(MSIHANDLE, MSIRUNMODE, BOOL);
 
 UINT WINAPI MsiViewModify(MSIHANDLE, MSIMODIFY, MSIHANDLE);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdefs.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdefs.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdefs.h	(revision 25949)
@@ -90,4 +90,14 @@
 #endif
 
+#ifndef DECLSPEC_ALIGN
+# if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
+#  define DECLSPEC_ALIGN(x) __declspec(align(x))
+# elif defined(__GNUC__)
+#  define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
+# else
+#  define DECLSPEC_ALIGN(x)
+# endif
+#endif
+
 #ifndef _MSVCRT_LONG_DEFINED
 #define _MSVCRT_LONG_DEFINED
@@ -139,5 +149,5 @@
 
 #ifndef _TIME64_T_DEFINED
-typedef __int64 __time64_t;
+typedef __int64 DECLSPEC_ALIGN(8) __time64_t;
 #define _TIME64_T_DEFINED
 #endif
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/io.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/io.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/io.h	(revision 25949)
@@ -54,5 +54,5 @@
   time_t time_access;
   time_t time_write;
-  __int64        size;
+  __int64 DECLSPEC_ALIGN(8) size;
   char           name[260];
 };
@@ -75,5 +75,5 @@
   time_t  time_access;
   time_t  time_write;
-  __int64         size;
+  __int64 DECLSPEC_ALIGN(8) size;
   wchar_t name[260];
 };
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdio.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdio.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdio.h	(revision 25949)
@@ -83,5 +83,5 @@
 
 #ifndef _FPOS_T_DEFINED
-typedef __int64 fpos_t;
+typedef __int64 DECLSPEC_ALIGN(8) fpos_t;
 #define _FPOS_T_DEFINED
 #endif
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/wchar.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/wchar.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/wchar.h	(revision 25949)
@@ -122,5 +122,5 @@
   time_t time_access;
   time_t time_write;
-  __int64        size;
+  __int64 DECLSPEC_ALIGN(8) size;
   wchar_t name[260];
 };
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/msxml.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/msxml.idl - Do not edit ***/
 
 #include <rpc.h>
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ntsecpkg.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ntsecpkg.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ntsecpkg.h	(revision 25949)
@@ -44,4 +44,7 @@
 #define SECPKG_INTERFACE_VERSION_2                   0x20000
 #define SECPKG_INTERFACE_VERSION_3                   0x40000
+#define SECPKG_INTERFACE_VERSION_4                   0x80000
+#define SECPKG_INTERFACE_VERSION_5                  0x100000
+#define SECPKG_INTERFACE_VERSION_6                  0x200000
 
 /* enum definitions for Secure Service Provider/Authentication Packages */
@@ -153,4 +156,9 @@
     } Info;
 } SECPKG_EXTENDED_INFORMATION, *PSECPKG_EXTENDED_INFORMATION;
+
+typedef struct  _SECPKG_TARGETINFO {
+    PSID DomainSid;
+    PCWSTR ComputerName;
+} SECPKG_TARGETINFO, *PSECPKG_TARGETINFO;
 
 /* callbacks implemented by SSP/AP dlls and called by the LSA */
@@ -355,4 +363,16 @@
 typedef NTSTATUS (NTAPI SpSetCredentialsAttributesFn)(LSA_SEC_HANDLE, ULONG,
  PVOID, ULONG);
+typedef NTSTATUS (NTAPI SpChangeAccountPasswordFn)(PUNICODE_STRING,
+ PUNICODE_STRING, PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PSecBufferDesc);
+typedef NTSTATUS (NTAPI SpQueryMetaDataFn)(LSA_SEC_HANDLE, PUNICODE_STRING,
+ ULONG, PULONG, PUCHAR *, PLSA_SEC_HANDLE);
+typedef NTSTATUS (NTAPI SpExchangeMetaDataFn)(LSA_SEC_HANDLE, PUNICODE_STRING,
+ ULONG, ULONG, PUCHAR, PLSA_SEC_HANDLE);
+typedef NTSTATUS (NTAPI SpGetCredUIContextFn)(LSA_SEC_HANDLE, GUID *, PULONG,
+ PUCHAR *);
+typedef NTSTATUS (NTAPI SpUpdateCredentialsFn)(LSA_SEC_HANDLE, GUID *, ULONG,
+ PUCHAR);
+typedef NTSTATUS (NTAPI SpValidateTargetInfoFn)(PLSA_CLIENT_REQUEST, PVOID,
+ PVOID, ULONG, PSECPKG_TARGETINFO);
 
 /* User-mode functions implemented by SSP/AP obtainable by a dispatch table */
@@ -416,4 +436,13 @@
     SpSetCredentialsAttributesFn *SetCredentialsAttributes;
     /* Packages with version SECPKG_INTERFACE_VERSION_3 end here */
+    SpChangeAccountPasswordFn *ChangeAccountPassword;
+    /* Packages with version SECPKG_INTERFACE_VERSION_4 end here */
+    SpQueryMetaDataFn *QueryMetaData;
+    SpExchangeMetaDataFn *ExchangeMetaData;
+    SpGetCredUIContextFn *GetCredUIContext;
+    SpUpdateCredentialsFn *UpdateCredentials;
+    /* Packages with version SECPKG_INTERFACE_VERSION_5 end here */
+    SpValidateTargetInfoFn *ValidateTargetInfo;
+    /* Packages with version SECPKG_INTERFACE_VERSION_6 end here */
 } SECPKG_FUNCTION_TABLE,
  *PSECPKG_FUNCTION_TABLE;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/oaidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/oaidl.idl - Do not edit ***/
 
 #include <rpc.h>
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/objidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/objidl.idl - Do not edit ***/
 
 #include <rpc.h>
@@ -7832,7 +7832,7 @@
     void *pAuthInfo;
 } SOLE_AUTHENTICATION_INFO;
-#define COLE_DEFAULT_PRINCIPAL (-1)
-
-#define COLE_DEFAULT_AUTHINFO (-1)
+#define COLE_DEFAULT_PRINCIPAL ((OLECHAR *)-1)
+
+#define COLE_DEFAULT_AUTHINFO ((void *)-1)
 
 typedef struct tagSOLE_AUTHENTICATION_LIST {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl	(revision 25949)
@@ -1960,6 +1960,6 @@
   } SOLE_AUTHENTICATION_INFO;
 
-  const OLECHAR *COLE_DEFAULT_PRINCIPAL = /*(OLECHAR*)*/ -1;
-  const void *COLE_DEFAULT_AUTHINFO = /*(void*)*/ -1;
+  const OLECHAR *COLE_DEFAULT_PRINCIPAL = (OLECHAR*) -1;
+  const void *COLE_DEFAULT_AUTHINFO = (void*) -1;
 
   typedef struct tagSOLE_AUTHENTICATION_LIST {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oledb.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oledb.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oledb.idl	(revision 25949)
@@ -39,9 +39,24 @@
 
 typedef ULONG DBBYTEOFFSET;
+typedef LONG  DBROWOFFSET;
+typedef LONG  DBROWCOUNT;
 typedef ULONG DBCOUNTITEM;
 typedef ULONG DBLENGTH;
+typedef ULONG DBORDINAL;
+typedef ULONG DBBKMARK;
+typedef DWORD DB_DWRESERVE;
+typedef ULONG DBREFCOUNT;
+typedef ULONG DB_UPARAMS;
+typedef LONG  DB_LPARAMS;
+typedef DWORD DBHASHVALUE;
 
 #include "dbs.idl"
 
+#include "access.idl"
+#include "rstbas.idl"
+#include "rstinf.idl"
+#include "rstloc.idl"
+#include "cmdbas.idl"
+#include "cmdtxt.idl"
 #include "dbccmd.idl"
 #include "dbcses.idl"
@@ -49,6 +64,10 @@
 #include "dbinit.idl"
 #include "dbdsad.idl"
+#include "asynot.idl"
+#include "asysta.idl"
 #include "sesprp.idl"
 #include "opnrst.idl"
+#include "row.idl"
+#include "rowchg.idl"
 #include "binres.idl"
 #include "crtrow.idl"
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/oleidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/oleidl.idl - Do not edit ***/
 
 #include <rpc.h>
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/propidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/propidl.idl - Do not edit ***/
 
 #include <rpc.h>
@@ -260,5 +260,15 @@
 
 typedef struct tagPROPVARIANT *LPPROPVARIANT;
-#define REFPROPVARIANT const PROPVARIANT *
+#if 0
+typedef const PROPVARIANT *REFPROPVARIANT;
+#endif
+#ifndef _REFPROPVARIANT_DEFINED
+#define _REFPROPVARIANT_DEFINED
+#ifdef __cplusplus
+#define REFPROPVARIANT const PROPVARIANT &
+#else
+#define REFPROPVARIANT const PROPVARIANT * __MIDL_CONST
+#endif
+#endif
 #define PIDDI_THUMBNAIL 0x00000002L /* VT_BLOB */
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.idl	(revision 25949)
@@ -216,5 +216,15 @@
   typedef struct tagPROPVARIANT *LPPROPVARIANT;
 
-  cpp_quote("#define REFPROPVARIANT const PROPVARIANT *")
+  cpp_quote("#if 0")
+  typedef const PROPVARIANT * REFPROPVARIANT;
+  cpp_quote("#endif")
+  cpp_quote("#ifndef _REFPROPVARIANT_DEFINED")
+  cpp_quote("#define _REFPROPVARIANT_DEFINED")
+  cpp_quote("#ifdef __cplusplus")
+  cpp_quote("#define REFPROPVARIANT const PROPVARIANT &")
+  cpp_quote("#else")
+  cpp_quote("#define REFPROPVARIANT const PROPVARIANT * __MIDL_CONST")
+  cpp_quote("#endif")
+  cpp_quote("#endif")
 
   cpp_quote("#define PIDDI_THUMBNAIL 0x00000002L /* VT_BLOB */")
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/prsht.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/prsht.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/prsht.h	(revision 25949)
@@ -276,5 +276,5 @@
 #define PSH_NOCONTEXTHELP       0x02000000
 #ifndef __WINESRC__
-# if _WIN32_IE < 0x0500
+# if defined(_WIN32_IE) && (_WIN32_IE < 0x0500)
 #  define PSH_WIZARD97          PSH_WIZARD97_OLD
 # else
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcdce.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcdce.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcdce.h	(revision 25949)
@@ -118,4 +118,9 @@
 #define RPC_C_PROTSEQ_MAX_REQS_DEFAULT 10
 
+#define RPC_PROTSEQ_TCP     0x1
+#define RPC_PROTSEQ_NMP     0x2
+#define RPC_PROTSEQ_LRPC    0x3
+#define RPC_PROTSEQ_HTTP    0x4
+
 /* RPC_POLICY EndpointFlags */
 #define RPC_C_BIND_TO_ALL_NICS          0x1
@@ -168,6 +173,6 @@
 
 /* values for RPC_SECURITY_QOS*::IdentityTracking */
-#define RPC_C_QOS_IDENTIFY_STATIC   0
-#define RPC_C_QOS_IDENTIFY_DYNAMIC  1
+#define RPC_C_QOS_IDENTITY_STATIC   0
+#define RPC_C_QOS_IDENTITY_DYNAMIC  1
 
 /* flags for RPC_SECURITY_QOS*::Capabilities */
@@ -514,4 +519,26 @@
 #define RpcBindingInqAuthInfo WINELIB_NAME_AW(RpcBindingInqAuthInfo)
 
+RPCRTAPI RPC_STATUS RPC_ENTRY
+  RpcBindingInqAuthClientA( RPC_BINDING_HANDLE ClientBinding, RPC_AUTHZ_HANDLE *Privs,
+                            RPC_CSTR *ServerPrincName, ULONG *AuthnLevel, ULONG *AuthnSvc,
+                            ULONG *AuthzSvc );
+
+RPCRTAPI RPC_STATUS RPC_ENTRY
+  RpcBindingInqAuthClientW( RPC_BINDING_HANDLE ClientBinding, RPC_AUTHZ_HANDLE *Privs,
+                            RPC_WSTR *ServerPrincName, ULONG *AuthnLevel, ULONG *AuthnSvc,
+                            ULONG *AuthzSvc );
+#define RpcBindingInqAuthClient WINELIB_NAME_AW(RpcBindingInqAuthClient)
+
+RPCRTAPI RPC_STATUS RPC_ENTRY
+  RpcBindingInqAuthClientExA( RPC_BINDING_HANDLE ClientBinding, RPC_AUTHZ_HANDLE *Privs,
+                              RPC_CSTR *ServerPrincName, ULONG *AuthnLevel, ULONG *AuthnSvc,
+                              ULONG *AuthzSvc, ULONG Flags );
+
+RPCRTAPI RPC_STATUS RPC_ENTRY
+  RpcBindingInqAuthClientExW( RPC_BINDING_HANDLE ClientBinding, RPC_AUTHZ_HANDLE *Privs,
+                              RPC_WSTR *ServerPrincName, ULONG *AuthnLevel, ULONG *AuthnSvc,
+                              ULONG *AuthzSvc, ULONG Flags );
+#define RpcBindingInqAuthClientEx WINELIB_NAME_AW(RpcBindingInqAuthClientEx)
+
 RPCRTAPI RPC_STATUS RPC_ENTRY RpcCancelThread(void*);
 RPCRTAPI RPC_STATUS RPC_ENTRY RpcCancelThreadEx(void*,LONG);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcndr.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcndr.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcndr.h	(revision 25949)
@@ -107,6 +107,6 @@
 #define small char
 typedef unsigned char byte;
-#define hyper __int64
-#define MIDL_uhyper unsigned __int64
+typedef INT64 hyper;
+typedef UINT64 MIDL_uhyper;
 typedef unsigned char boolean;
 
@@ -214,17 +214,17 @@
   ULONG FullPtrRefId;
   ULONG PointerLength;
-  int fInDontFree:1;
-  int fDontCallFreeInst:1;
-  int fInOnlyParam:1;
-  int fHasReturn:1;
-  int fHasExtensions:1;
-  int fHasNewCorrDesc:1;
-  int fIsIn:1;
-  int fIsOut:1;
-  int fIsOicf:1;
-  int fBufferValid:1;
-  int fHasMemoryValidateCallback:1;
-  int fInFree:1;
-  int fNeedMCCP:1;
+  unsigned int fInDontFree:1;
+  unsigned int fDontCallFreeInst:1;
+  unsigned int fInOnlyParam:1;
+  unsigned int fHasReturn:1;
+  unsigned int fHasExtensions:1;
+  unsigned int fHasNewCorrDesc:1;
+  unsigned int fIsIn:1;
+  unsigned int fIsOut:1;
+  unsigned int fIsOicf:1;
+  unsigned int fBufferValid:1;
+  unsigned int fHasMemoryValidateCallback:1;
+  unsigned int fInFree:1;
+  unsigned int fNeedMCCP:1;
   int fUnused:3;
   int fUnused2:16;
@@ -393,5 +393,9 @@
 typedef void (__RPC_API *STUB_THUNK)( PMIDL_STUB_MESSAGE );
 
+#ifdef WINE_STRICT_PROTOTYPES
+typedef LONG (__RPC_API *SERVER_ROUTINE)(void);
+#else
 typedef LONG (__RPC_API *SERVER_ROUTINE)();
+#endif
 
 typedef struct _MIDL_SERVER_INFO_
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/servprov.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/servprov.idl - Do not edit ***/
 
 #include <rpc.h>
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h	(revision 25949)
@@ -63,5 +63,5 @@
 DWORD        WINAPI SHFormatDrive(HWND,UINT,UINT,UINT);
 void         WINAPI SHFree(LPVOID);
-BOOL         WINAPI GetFileNameFromBrowse(HWND,LPSTR,DWORD,LPCSTR,LPCSTR,LPCSTR,LPCSTR);
+BOOL         WINAPI GetFileNameFromBrowse(HWND,LPWSTR,DWORD,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR);
 HRESULT      WINAPI SHGetInstanceExplorer(IUnknown**);
 HRESULT      WINAPI SHGetFolderPathAndSubDirA(HWND,int,HANDLE,DWORD,LPCSTR,LPSTR);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shobjidl.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shobjidl.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shobjidl.idl	(revision 25949)
@@ -330,20 +330,4 @@
 interface IShellFolder2 : IShellFolder
 {
-    typedef enum
-    {
-        SHCOLSTATE_TYPE_STR = 0x00000001,
-        SHCOLSTATE_TYPE_INT = 0x00000002,
-        SHCOLSTATE_TYPE_DATE = 0x00000003,
-        SHCOLSTATE_TYPEMASK = 0x0000000f,
-        SHCOLSTATE_ONBYDEFAULT = 0x00000010,
-        SHCOLSTATE_SLOW = 0x00000020,
-        SHCOLSTATE_EXTENDED = 0x00000040,
-        SHCOLSTATE_SECONDARYUI = 0x00000080,
-        SHCOLSTATE_HIDDEN = 0x00000100,
-        SHCOLSTATE_PREFER_VARCMP = 0x00000200
-    } SHCOLSTATE;
-
-    typedef DWORD SHCOLSTATEF;
-
     typedef struct
     {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shtypes.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shtypes.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shtypes.idl	(revision 25949)
@@ -82,2 +82,28 @@
 } SHELLDETAILS, *LPSHELLDETAILS;
 cpp_quote("#include <poppack.h>")
+
+typedef [v1_enum] enum tagSHCOLSTATE
+{
+    SHCOLSTATE_DEFAULT = 0,
+    SHCOLSTATE_TYPE_STR,
+    SHCOLSTATE_TYPE_INT,
+    SHCOLSTATE_TYPE_DATE,
+    SHCOLSTATE_TYPEMASK = 0xf,
+    SHCOLSTATE_ONBYDEFAULT = 0x10,
+    SHCOLSTATE_SLOW = 0x20,
+    SHCOLSTATE_EXTENDED = 0x40,
+    SHCOLSTATE_SECONDARYUI = 0x80,
+    SHCOLSTATE_HIDDEN = 0x100,
+    SHCOLSTATE_PREFER_VARCMP = 0x200,
+    SHCOLSTATE_PREFER_FMTCMP = 0x400,
+    SHCOLSTATE_NOSORTBYFOLDERNESS = 0x800,
+    SHCOLSTATE_VIEWONLY = 0x10000,
+    SHCOLSTATE_BATCHREAD = 0x20000,
+    SHCOLSTATE_NO_GROUPBY = 0x40000,
+    SHCOLSTATE_FIXED_WIDTH = 0x1000,
+    SHCOLSTATE_NODPISCALE = 0x2000,
+    SHCOLSTATE_FIXED_RATIO = 0x4000,
+    SHCOLSTATE_DISPLAYMASK = 0xf000
+} SHCOLSTATE;
+
+typedef DWORD SHCOLSTATEF;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/sqltypes.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/sqltypes.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/sqltypes.h	(revision 25949)
@@ -111,4 +111,14 @@
 typedef void*                   SQLHWND;
 
+#ifdef _WIN64
+typedef INT64           SQLLEN;
+typedef UINT64          SQLULEN;
+typedef UINT64          SQLSETPOSIROW;
+#else
+#define SQLLEN          SQLINTEGER
+#define SQLULEN         SQLUINTEGER
+#define SQLSETPOSIROW   SQLUSMALLINT
+#endif
+
 typedef SQLHANDLE          		HENV;
 typedef SQLHANDLE          		HDBC;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/unknwn.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/unknwn.idl - Do not edit ***/
 
 #include <rpc.h>
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/urlmon.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/urlmon.idl - Do not edit ***/
 
 /*
@@ -147,4 +147,9 @@
 #define __IInternetSecurityManager_FWD_DEFINED__
 typedef interface IInternetSecurityManager IInternetSecurityManager;
+#endif
+
+#ifndef __IInternetHostSecurityManager_FWD_DEFINED__
+#define __IInternetHostSecurityManager_FWD_DEFINED__
+typedef interface IInternetHostSecurityManager IInternetHostSecurityManager;
 #endif
 
@@ -3360,4 +3365,139 @@
 #endif  /* __IInternetSecurityManager_INTERFACE_DEFINED__ */
 
+#define SID_SInternetHostSecurityManager IID_IInternetHostSecurityManager
+/*****************************************************************************
+ * IInternetHostSecurityManager interface
+ */
+#ifndef __IInternetHostSecurityManager_INTERFACE_DEFINED__
+#define __IInternetHostSecurityManager_INTERFACE_DEFINED__
+
+DEFINE_GUID(IID_IInternetHostSecurityManager, 0x3af280b6, 0xcb3f, 0x11d0, 0x89,0x1e, 0x00,0xc0,0x4f,0xb6,0xbf,0xc4);
+#if defined(__cplusplus) && !defined(CINTERFACE)
+interface IInternetHostSecurityManager : public IUnknown
+{
+    virtual HRESULT STDMETHODCALLTYPE GetSecurityId(
+        BYTE *pbSecurityId,
+        DWORD *pcbSecurityId,
+        DWORD_PTR dwReserved) = 0;
+
+    virtual HRESULT STDMETHODCALLTYPE ProcessUrlAction(
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        BYTE *pContext,
+        DWORD cbContext,
+        DWORD dwFlags,
+        DWORD dwReserved) = 0;
+
+    virtual HRESULT STDMETHODCALLTYPE QueryCustomPolicy(
+        REFGUID guidKey,
+        BYTE **ppPolicy,
+        DWORD *pcbPolicy,
+        BYTE *pContext,
+        DWORD cbContext,
+        DWORD dwReserved) = 0;
+
+};
+#else
+typedef struct IInternetHostSecurityManagerVtbl {
+    BEGIN_INTERFACE
+
+    /*** IUnknown methods ***/
+    HRESULT (STDMETHODCALLTYPE *QueryInterface)(
+        IInternetHostSecurityManager* This,
+        REFIID riid,
+        void **ppvObject);
+
+    ULONG (STDMETHODCALLTYPE *AddRef)(
+        IInternetHostSecurityManager* This);
+
+    ULONG (STDMETHODCALLTYPE *Release)(
+        IInternetHostSecurityManager* This);
+
+    /*** IInternetHostSecurityManager methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetSecurityId)(
+        IInternetHostSecurityManager* This,
+        BYTE *pbSecurityId,
+        DWORD *pcbSecurityId,
+        DWORD_PTR dwReserved);
+
+    HRESULT (STDMETHODCALLTYPE *ProcessUrlAction)(
+        IInternetHostSecurityManager* This,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        BYTE *pContext,
+        DWORD cbContext,
+        DWORD dwFlags,
+        DWORD dwReserved);
+
+    HRESULT (STDMETHODCALLTYPE *QueryCustomPolicy)(
+        IInternetHostSecurityManager* This,
+        REFGUID guidKey,
+        BYTE **ppPolicy,
+        DWORD *pcbPolicy,
+        BYTE *pContext,
+        DWORD cbContext,
+        DWORD dwReserved);
+
+    END_INTERFACE
+} IInternetHostSecurityManagerVtbl;
+interface IInternetHostSecurityManager {
+    CONST_VTBL IInternetHostSecurityManagerVtbl* lpVtbl;
+};
+
+#ifdef COBJMACROS
+/*** IUnknown methods ***/
+#define IInternetHostSecurityManager_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IInternetHostSecurityManager_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IInternetHostSecurityManager_Release(This) (This)->lpVtbl->Release(This)
+/*** IInternetHostSecurityManager methods ***/
+#define IInternetHostSecurityManager_GetSecurityId(This,pbSecurityId,pcbSecurityId,dwReserved) (This)->lpVtbl->GetSecurityId(This,pbSecurityId,pcbSecurityId,dwReserved)
+#define IInternetHostSecurityManager_ProcessUrlAction(This,dwAction,pPolicy,cbPolicy,pContext,cbContext,dwFlags,dwReserved) (This)->lpVtbl->ProcessUrlAction(This,dwAction,pPolicy,cbPolicy,pContext,cbContext,dwFlags,dwReserved)
+#define IInternetHostSecurityManager_QueryCustomPolicy(This,guidKey,ppPolicy,pcbPolicy,pContext,cbContext,dwReserved) (This)->lpVtbl->QueryCustomPolicy(This,guidKey,ppPolicy,pcbPolicy,pContext,cbContext,dwReserved)
+#endif
+
+#endif
+
+HRESULT STDMETHODCALLTYPE IInternetHostSecurityManager_GetSecurityId_Proxy(
+    IInternetHostSecurityManager* This,
+    BYTE *pbSecurityId,
+    DWORD *pcbSecurityId,
+    DWORD_PTR dwReserved);
+void __RPC_STUB IInternetHostSecurityManager_GetSecurityId_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IInternetHostSecurityManager_ProcessUrlAction_Proxy(
+    IInternetHostSecurityManager* This,
+    DWORD dwAction,
+    BYTE *pPolicy,
+    DWORD cbPolicy,
+    BYTE *pContext,
+    DWORD cbContext,
+    DWORD dwFlags,
+    DWORD dwReserved);
+void __RPC_STUB IInternetHostSecurityManager_ProcessUrlAction_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IInternetHostSecurityManager_QueryCustomPolicy_Proxy(
+    IInternetHostSecurityManager* This,
+    REFGUID guidKey,
+    BYTE **ppPolicy,
+    DWORD *pcbPolicy,
+    BYTE *pContext,
+    DWORD cbContext,
+    DWORD dwReserved);
+void __RPC_STUB IInternetHostSecurityManager_QueryCustomPolicy_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+
+#endif  /* __IInternetHostSecurityManager_INTERFACE_DEFINED__ */
+
 #define URLACTION_MIN                        0x00001000
 #define URLACTION_DOWNLOAD_MIN               0x00001000
@@ -5192,4 +5332,12 @@
 #endif  /* __IInternetProtocolEx_INTERFACE_DEFINED__ */
 
+#define CONFIRMSAFETYACTION_LOADOBJECT  0x00000001
+struct CONFIRMSAFETY {
+    CLSID clsid;
+    IUnknown *pUnk;
+    DWORD dwFlags;
+};
+
+EXTERN_C const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY;
 DEFINE_GUID(CLSID_InternetSecurityManager, 0x7b8a2d94, 0x0ac9, 0x11d1, 0x89, 0x6c, 0x00, 0xc0, 0x4f, 0xB6, 0xbf, 0xc4);
 DEFINE_GUID(CLSID_InternetZoneManager, 0x7B8A2D95, 0x0AC9, 0x11D1, 0x89, 0x6C, 0x00, 0xC0, 0x4F, 0xB6, 0xBF, 0xC4);
@@ -5255,4 +5403,5 @@
 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR,QUERYOPTION,DWORD,LPVOID,DWORD,DWORD*,DWORD);
 HRESULT WINAPI CoInternetSetFeatureEnabled(INTERNETFEATURELIST,DWORD,BOOL);
+HRESULT WINAPI CoInternetGetSecurityUrl(LPCWSTR,LPWSTR*,PSUACTION,DWORD);
 HRESULT WINAPI CreateFormatEnumerator(UINT,FORMATETC*,IEnumFORMATETC**);
 HRESULT WINAPI GetSoftwareUpdateInfo( LPCWSTR szDistUnit, LPSOFTDISTINFO psdi);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.idl	(revision 25949)
@@ -1075,4 +1075,40 @@
 }
 
+/*****************************************************************************
+ * IInternetHostSecurityManager interface
+ */
+cpp_quote("#define SID_SInternetHostSecurityManager IID_IInternetHostSecurityManager")
+
+[
+    local,
+    object,
+    uuid(3af280b6-cb3f-11d0-891e-00c04fb6bfc4),
+    pointer_default(unique)
+]
+interface IInternetHostSecurityManager : IUnknown
+{
+    HRESULT GetSecurityId(
+            [out, size_is(*pcbSecurityId)] BYTE *pbSecurityId,
+            [in, out] DWORD *pcbSecurityId,
+            [in] DWORD_PTR dwReserved);
+
+    HRESULT ProcessUrlAction(
+            [in] DWORD dwAction,
+            [out, size_is(cbPolicy)] BYTE *pPolicy,
+            [in] DWORD cbPolicy,
+            [in] BYTE *pContext,
+            [in] DWORD cbContext,
+            [in] DWORD dwFlags,
+            [in] DWORD dwReserved);
+
+    HRESULT QueryCustomPolicy(
+            [in] REFGUID guidKey,
+            [out, size_is(,*pcbPolicy)] BYTE **ppPolicy,
+            [out] DWORD *pcbPolicy,
+            [in] BYTE *pContext,
+            [in] DWORD cbContext,
+            [in] DWORD dwReserved);
+}
+
 cpp_quote("#define URLACTION_MIN                        0x00001000")
 cpp_quote("#define URLACTION_DOWNLOAD_MIN               0x00001000")
@@ -1653,4 +1689,15 @@
 }
 
+cpp_quote("#define CONFIRMSAFETYACTION_LOADOBJECT  0x00000001")
+
+struct CONFIRMSAFETY
+{
+    CLSID clsid;
+    IUnknown *pUnk;
+    DWORD dwFlags;
+};
+
+cpp_quote("EXTERN_C const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY;")
+
 cpp_quote("DEFINE_GUID(CLSID_InternetSecurityManager, 0x7b8a2d94, 0x0ac9, 0x11d1, 0x89, 0x6c, 0x00, 0xc0, 0x4f, 0xB6, 0xbf, 0xc4);")
 cpp_quote("DEFINE_GUID(CLSID_InternetZoneManager, 0x7B8A2D95, 0x0AC9, 0x11D1, 0x89, 0x6C, 0x00, 0xC0, 0x4F, 0xB6, 0xBF, 0xC4);")
@@ -1721,4 +1768,5 @@
 cpp_quote("HRESULT WINAPI CoInternetQueryInfo(LPCWSTR,QUERYOPTION,DWORD,LPVOID,DWORD,DWORD*,DWORD);")
 cpp_quote("HRESULT WINAPI CoInternetSetFeatureEnabled(INTERNETFEATURELIST,DWORD,BOOL);")
+cpp_quote("HRESULT WINAPI CoInternetGetSecurityUrl(LPCWSTR,LPWSTR*,PSUACTION,DWORD);")
 cpp_quote("HRESULT WINAPI CreateFormatEnumerator(UINT,FORMATETC*,IEnumFORMATETC**);")
 cpp_quote("HRESULT WINAPI GetSoftwareUpdateInfo( LPCWSTR szDistUnit, LPSOFTDISTINFO psdi);")
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/vfw.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/vfw.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/vfw.h	(revision 25949)
@@ -509,5 +509,9 @@
 LRESULT	VFWAPI	ICGetInfo(HIC hic,ICINFO *picinfo, DWORD cb);
 HIC	VFWAPI	ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode);
+#ifdef WINE_STRICT_PROTOTYPES
+HIC	VFWAPI	ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, DRIVERPROC lpfnHandler);
+#else
 HIC	VFWAPI	ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, FARPROC lpfnHandler);
+#endif
 
 LRESULT VFWAPI	ICClose(HIC hic);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h	(revision 25949)
@@ -511,4 +511,8 @@
 #include <poppack.h>
 
+typedef enum _MEMORY_RESOURCE_NOTIFICATION_TYPE {
+    LowMemoryResourceNotification,
+    HighMemoryResourceNotification
+} MEMORY_RESOURCE_NOTIFICATION_TYPE;
 
 #ifndef _SYSTEMTIME_
@@ -1232,4 +1236,13 @@
 DECL_WINELIB_TYPE_AW(HW_PROFILE_INFO)
 DECL_WINELIB_TYPE_AW(LPHW_PROFILE_INFO)
+
+/* Event Logging */
+
+#define EVENTLOG_FULL_INFO          0
+
+typedef struct _EVENTLOG_FULL_INFORMATION {
+    DWORD dwFull;
+} EVENTLOG_FULL_INFORMATION, *LPEVENTLOG_FULL_INFORMATION;
+
 
 /* Stream data structures and defines */
@@ -1392,4 +1405,5 @@
 WINBASEAPI HANDLE      WINAPI CreateMailslotW(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES);
 #define                       CreateMailslot WINELIB_NAME_AW(CreateMailslot)
+WINBASEAPI HANDLE      WINAPI CreateMemoryResourceNotification(MEMORY_RESOURCE_NOTIFICATION_TYPE);
 WINBASEAPI HANDLE      WINAPI CreateMutexA(LPSECURITY_ATTRIBUTES,BOOL,LPCSTR);
 WINBASEAPI HANDLE      WINAPI CreateMutexW(LPSECURITY_ATTRIBUTES,BOOL,LPCWSTR);
@@ -1625,4 +1639,5 @@
 #define                       GetEnvironmentVariable WINELIB_NAME_AW(GetEnvironmentVariable)
 WINBASEAPI UINT        WINAPI GetErrorMode(void);
+WINADVAPI  BOOL        WINAPI GetEventLogInformation(HANDLE,DWORD,LPVOID,DWORD,LPDWORD);
 WINBASEAPI BOOL        WINAPI GetExitCodeProcess(HANDLE,LPDWORD);
 WINBASEAPI BOOL        WINAPI GetExitCodeThread(HANDLE,LPDWORD);
@@ -1701,4 +1716,5 @@
 WINBASEAPI DWORD       WINAPI GetProcessVersion(DWORD);
 WINBASEAPI BOOL        WINAPI GetProcessWorkingSetSize(HANDLE,PSIZE_T,PSIZE_T);
+WINBASEAPI BOOL        WINAPI GetProductInfo(DWORD,DWORD,DWORD,DWORD,PDWORD);
 WINBASEAPI UINT        WINAPI GetProfileIntA(LPCSTR,LPCSTR,INT);
 WINBASEAPI UINT        WINAPI GetProfileIntW(LPCWSTR,LPCWSTR,INT);
@@ -2298,46 +2314,4 @@
 #define     CopyMemory RtlCopyMemory
 
-/* undocumented functions */
-
-typedef struct tagSYSLEVEL
-{
-    CRITICAL_SECTION crst;
-    INT              level;
-} SYSLEVEL;
-
-/* [GS]etProcessDword offsets */
-#define  GPD_APP_COMPAT_FLAGS    (-56)
-#define  GPD_LOAD_DONE_EVENT     (-52)
-#define  GPD_HINSTANCE16         (-48)
-#define  GPD_WINDOWS_VERSION     (-44)
-#define  GPD_THDB                (-40)
-#define  GPD_PDB                 (-36)
-#define  GPD_STARTF_SHELLDATA    (-32)
-#define  GPD_STARTF_HOTKEY       (-28)
-#define  GPD_STARTF_SHOWWINDOW   (-24)
-#define  GPD_STARTF_SIZE         (-20)
-#define  GPD_STARTF_POSITION     (-16)
-#define  GPD_STARTF_FLAGS        (-12)
-#define  GPD_PARENT              (- 8)
-#define  GPD_FLAGS               (- 4)
-#define  GPD_USERDATA            (  0)
-
-WINBASEAPI void        WINAPI DisposeLZ32Handle(HANDLE);
-WINBASEAPI HANDLE      WINAPI DosFileHandleToWin32Handle(HFILE);
-WINBASEAPI DWORD       WINAPI GetProcessDword(DWORD,INT);
-WINBASEAPI VOID        WINAPI GetpWin16Lock(SYSLEVEL**);
-WINBASEAPI DWORD       WINAPI MapLS(LPCVOID);
-WINBASEAPI LPVOID      WINAPI MapSL(DWORD);
-WINBASEAPI VOID        WINAPI ReleaseThunkLock(DWORD*);
-WINBASEAPI VOID        WINAPI RestoreThunkLock(DWORD);
-WINBASEAPI VOID        WINAPI UnMapLS(DWORD);
-WINBASEAPI HFILE       WINAPI Win32HandleToDosFileHandle(HANDLE);
-WINBASEAPI VOID        WINAPI _CheckNotSysLevel(SYSLEVEL *lock);
-WINBASEAPI DWORD       WINAPI _ConfirmWin16Lock(void);
-WINBASEAPI DWORD       WINAPI _ConfirmSysLevel(SYSLEVEL*);
-WINBASEAPI VOID        WINAPI _EnterSysLevel(SYSLEVEL*);
-WINBASEAPI VOID        WINAPI _LeaveSysLevel(SYSLEVEL*);
-
-
 /* Wine internal functions */
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincrypt.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincrypt.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincrypt.h	(revision 25949)
@@ -89,4 +89,7 @@
   DWORD  dwReserved;
 } SCHANNEL_ALG, *PSCHANNEL_ALG;
+
+
+#define CRYPT_IPSEC_HMAC_KEY 0x0100
 
 typedef struct _HMAC_INFO {
@@ -690,6 +693,11 @@
 typedef struct _VTableProvStruc {
     DWORD    Version;
-    FARPROC  pFuncVerifyImage;
-    FARPROC  pFuncReturnhWnd;
+#ifdef WINE_STRICT_PROTOTYPES
+    BOOL     (WINAPI *FuncVerifyImage)(LPCSTR,BYTE*);
+    void     (WINAPI *FuncReturnhWnd)(HWND*);
+#else
+    FARPROC  FuncVerifyImage;
+    FARPROC  FuncReturnhWnd;
+#endif
     DWORD    dwProvType;
     BYTE    *pbContextInfo;
@@ -1341,12 +1349,16 @@
 } CRYPT_URL_INFO, *PCRYPT_URL_INFO;
 
-#define URL_OID_CERTIFICATE_ISSUER         ((LPCSTR)1)
-#define URL_OID_CERTIFICATE_CRL_DIST_POINT ((LPCSTR)2)
-#define URL_OID_CTL_ISSUER                 ((LPCSTR)3)
-#define URL_OID_CTL_NEXT_UPDATE            ((LPCSTR)4)
-#define URL_OID_CRL_ISSUER                 ((LPCSTR)5)
-#define URL_OID_CERTIFICATE_FRESHEST_CRL   ((LPCSTR)6)
-#define URL_OID_CRL_FRESHEST_CRL           ((LPCSTR)7)
-#define URL_OID_CROSS_CERT_DIST_POINT      ((LPCSTR)8)
+#define URL_OID_CERTIFICATE_ISSUER                  ((LPCSTR)1)
+#define URL_OID_CERTIFICATE_CRL_DIST_POINT          ((LPCSTR)2)
+#define URL_OID_CTL_ISSUER                          ((LPCSTR)3)
+#define URL_OID_CTL_NEXT_UPDATE                     ((LPCSTR)4)
+#define URL_OID_CRL_ISSUER                          ((LPCSTR)5)
+#define URL_OID_CERTIFICATE_FRESHEST_CRL            ((LPCSTR)6)
+#define URL_OID_CRL_FRESHEST_CRL                    ((LPCSTR)7)
+#define URL_OID_CROSS_CERT_DIST_POINT               ((LPCSTR)8)
+#define URL_OID_CERTIFICATE_OCSP                    ((LPCSTR)9)
+#define URL_OID_CERTIFICATE_OCSP_AND_CRL_DIST_POINT ((LPCSTR)10)
+#define URL_OID_CERTIFICATE_CRL_DIST_POINT_AND_OCSP ((LPCSTR)11)
+#define URL_OID_CROSS_CERT_SUBJECT_INFO_ACCESS      ((LPCSTR)12)
 
 #define URL_OID_GET_OBJECT_URL_FUNC "UrlDllGetObjectUrl"
@@ -2752,4 +2764,5 @@
 #define CRYPT_STRING_HEXADDR             0x0000000a
 #define CRYPT_STRING_HEXASCIIADDR        0x0000000b
+#define CRYPT_STRING_NOCRLF              0x40000000
 #define CRYPT_STRING_NOCR                0x80000000
 
@@ -2948,4 +2961,5 @@
 #define szOID_ENHANCED_KEY_USAGE            "2.5.29.37"
 #define szOID_FRESHEST_CRL                  "2.5.29.46"
+#define szOID_INHIBIT_ANY_POLICY            "2.5.29.54"
 #define szOID_DOMAIN_COMPONENT              "0.9.2342.19200300.100.1.25"
 #define szOID_PKCS_12_FRIENDLY_NAME_ATTR     "1.2.840.113549.1.9.20"
@@ -4055,4 +4069,11 @@
  DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext);
 
+BOOL WINAPI CertAddEncodedCertificateToSystemStoreA(LPCSTR pszCertStoreName,
+ const BYTE *pbCertEncoded, DWORD cbCertEncoded);
+BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(LPCWSTR pszCertStoreName,
+ const BYTE *pbCertEncoded, DWORD cbCertEncoded);
+#define CertAddEncodedCertificateToSystemStore \
+ WINELIB_NAME_AW(CertAddEncodedCertificateToSystemStore)
+
 BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore,
  DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded,
@@ -4140,4 +4161,7 @@
 BOOL WINAPI CertSerializeCTLStoreElement(PCCTL_CONTEXT pCtlContext,
  DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement);
+
+BOOL WINAPI CertGetIntendedKeyUsage(DWORD dwCertEncodingType,
+ PCERT_INFO pCertInfo, BYTE *pbKeyUsage, DWORD cbKeyUsage);
 
 BOOL WINAPI CertGetEnhancedKeyUsage(PCCERT_CONTEXT pCertContext, DWORD dwFlags,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/windef.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/windef.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/windef.h	(revision 25949)
@@ -237,5 +237,6 @@
 
 #ifdef __WINESRC__
-#define WINE_NO_UNICODE_MACROS
+#define WINE_NO_UNICODE_MACROS 1
+#define WINE_STRICT_PROTOTYPES 1
 #endif
 
@@ -314,8 +315,13 @@
 /* Callback function pointers types */
 
+#ifdef WINE_STRICT_PROTOTYPES
+typedef INT_PTR (CALLBACK *FARPROC)(void);
+typedef INT_PTR (CALLBACK *NEARPROC)(void);
+typedef INT_PTR (CALLBACK *PROC)(void);
+#else
 typedef INT_PTR (CALLBACK *FARPROC)();
 typedef INT_PTR (CALLBACK *NEARPROC)();
 typedef INT_PTR (CALLBACK *PROC)();
-
+#endif
 
 /* Macros to split words and longs. */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/library.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/library.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/library.h	(revision 25949)
@@ -92,4 +92,6 @@
                                           void *arg, int top_down );
 
+#ifdef __i386__
+
 /* LDT management */
 
@@ -102,27 +104,10 @@
 extern unsigned short wine_ldt_realloc_entries( unsigned short sel, int oldcount, int newcount );
 extern void wine_ldt_free_entries( unsigned short sel, int count );
-#if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
 extern unsigned short wine_ldt_alloc_fs(void);
 extern void wine_ldt_init_fs( unsigned short sel, const LDT_ENTRY *entry );
 extern void wine_ldt_free_fs( unsigned short sel );
-#else  /* __i386__ */
-static inline unsigned short wine_ldt_alloc_fs(void) { return 0x0b; /* pseudo GDT selector */ }
-static inline void wine_ldt_init_fs( unsigned short sel, const LDT_ENTRY *entry ) { }
-static inline void wine_ldt_free_fs( unsigned short sel ) { }
-#endif  /* __i386__ */
-
 
 /* the local copy of the LDT */
-#ifdef __CYGWIN__
-# ifdef WINE_EXPORT_LDT_COPY
-#  define WINE_LDT_EXTERN __declspec(dllexport)
-# else
-#  define WINE_LDT_EXTERN __declspec(dllimport)
-# endif
-#else
-# define WINE_LDT_EXTERN extern
-#endif
-
-WINE_LDT_EXTERN struct __wine_ldt_copy
+extern struct __wine_ldt_copy
 {
     void         *base[8192];  /* base address or 0 if entry is free   */
@@ -144,7 +129,4 @@
     ent->HighWord.Bits.BaseMid = (BYTE)((ULONG_PTR)base >> 16);
     ent->HighWord.Bits.BaseHi  = (BYTE)((ULONG_PTR)base >> 24);
-#ifdef _WIN64
-    ent->BaseHigh              = (ULONG_PTR)base >> 32;
-#endif
 }
 static inline void wine_ldt_set_limit( LDT_ENTRY *ent, unsigned int limit )
@@ -157,7 +139,4 @@
 {
     return (void *)(ent->BaseLow |
-#ifdef _WIN64
-                    (ULONG_PTR)ent->BaseHigh << 32 |
-#endif
                     (ULONG_PTR)ent->HighWord.Bits.BaseMid << 16 |
                     (ULONG_PTR)ent->HighWord.Bits.BaseHi << 24);
@@ -192,5 +171,4 @@
 /* segment register access */
 
-#ifdef __i386__
 # ifdef __MINGW32__
 #  define __DEFINE_GET_SEG(seg) \
@@ -221,8 +199,4 @@
 #  define __DEFINE_SET_SEG(seg) extern void wine_set_##seg(unsigned int);
 # endif /* __GNUC__ || _MSC_VER */
-#else  /* __i386__ */
-# define __DEFINE_GET_SEG(seg) static inline unsigned short wine_get_##seg(void) { return 0; }
-# define __DEFINE_SET_SEG(seg) static inline void wine_set_##seg(int val) { /* nothing */ }
-#endif  /* __i386__ */
 
 __DEFINE_GET_SEG(cs)
@@ -237,4 +211,6 @@
 #undef __DEFINE_SET_SEG
 
+#endif  /* __i386__ */
+
 #ifdef __cplusplus
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/list.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/list.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/list.h	(revision 25949)
@@ -231,7 +231,9 @@
 
 /* macros for statically initialized lists */
+#undef LIST_INIT
 #define LIST_INIT(list)  { &(list), &(list) }
 
 /* get pointer to object containing list element */
+#undef LIST_ENTRY
 #define LIST_ENTRY(elem, type, field) \
     ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field)))
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/mscvpdb.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/mscvpdb.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/mscvpdb.h	(revision 25949)
@@ -1652,11 +1652,25 @@
 };
 
+#define LT2_LINES_BLOCK 0x000000f2
+#define LT2_FILES_BLOCK 0x000000f4
+
 /* there's a new line tab structure from MS Studio 2005 and after
- * it's made of:
- * DWORD        000000f4
- * DWORD        lineblk_offset (counting bytes after this field)
- * an array of codeview_linetab2_file structures
- * an array (starting at <lineblk_offset>) of codeview_linetab2_block structures
+ * it's made of a list of codeview_linetab2 blocks.
+ * We've only seen (so far) list with a single LT2_FILES_BLOCK and several
+ * LT2_LINES_BLOCK. The LT2_FILES block has been encountered either as first
+ * or last block of the list.
+ * A LT2_FILES contains one or several codeview_linetab2_file:s
  */
+
+struct codeview_linetab2
+{
+    DWORD       header;
+    DWORD       size_of_block;
+};
+
+static inline const struct codeview_linetab2* codeview_linetab2_next_block(const struct codeview_linetab2* lt2)
+{
+    return (const struct codeview_linetab2*)((const char*)(lt2 + 1) + lt2->size_of_block);
+}
 
 struct codeview_linetab2_file
@@ -1668,14 +1682,19 @@
 };
 
-struct codeview_linetab2_block
-{
-    DWORD       header;         /* 0x000000f2 */
-    DWORD       size_of_block;  /* next block is at # bytes after this field */
-    DWORD       start;          /* start address of function with line numbers */
-    DWORD       seg;            /* segment of function with line numbers */
-    DWORD       size;           /* size of function with line numbers */
-    DWORD       file_offset;    /* offset for accessing corresponding codeview_linetab2_file */
-    DWORD       nlines;         /* number of lines in this block */
-    DWORD       size_lines;     /* number of bytes following for line number information */
+struct codeview_lt2blk_files
+{
+    struct codeview_linetab2            lt2;    /* LT2_FILES */
+    struct codeview_linetab2_file       file[1];
+};
+
+struct codeview_lt2blk_lines
+{
+    struct codeview_linetab2    lt2;            /* LT2_LINE_BLOCK */
+    DWORD                       start;          /* start address of function with line numbers */
+    DWORD                       seg;            /* segment of function with line numbers */
+    DWORD                       size;           /* size of function with line numbers */
+    DWORD                       file_offset;    /* offset for accessing corresponding codeview_linetab2_file */
+    DWORD                       nlines;         /* number of lines in this block */
+    DWORD                       size_lines;     /* number of bytes following for line number information */
     struct {
         DWORD   offset;         /* offset (from <seg>:<start>) for line number */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/rpcfc.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/rpcfc.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/rpcfc.h	(revision 25949)
@@ -177,4 +177,5 @@
 #define RPC_FC_PROC_OIF_RPCFLAGS        0x08
 #define RPC_FC_PROC_OIF_OBJ_V2          0x20
+#define RPC_FC_PROC_OIF_HAS_COMM_OR_FAULT 0x20
 #define RPC_FC_PROC_OIF_NEWINIT         0x40
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/server_protocol.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/server_protocol.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/server_protocol.h	(revision 25949)
@@ -125,7 +125,6 @@
     {
         int          code;
-        int          unicode;
+        data_size_t  length;
         client_ptr_t string;
-        data_size_t  length;
     } output_string;
     struct
@@ -1218,4 +1217,19 @@
 
 
+struct get_handle_unix_name_request
+{
+    struct request_header __header;
+    obj_handle_t   handle;
+};
+struct get_handle_unix_name_reply
+{
+    struct reply_header __header;
+    data_size_t    name_len;
+    /* VARARG(name,string); */
+    char __pad_12[4];
+};
+
+
+
 struct get_handle_fd_request
 {
@@ -2058,6 +2072,4 @@
     data_size_t   length;
     client_ptr_t  string;
-    int           unicode;
-    char __pad_28[4];
 };
 struct output_debug_string_reply
@@ -4121,14 +4133,15 @@
 };
 
-struct get_token_user_request
+struct get_token_sid_request
 {
     struct request_header __header;
     obj_handle_t    handle;
-};
-struct get_token_user_reply
-{
-    struct reply_header __header;
-    data_size_t     user_len;
-    /* VARARG(user,SID); */
+    unsigned int    which_sid;
+};
+struct get_token_sid_reply
+{
+    struct reply_header __header;
+    data_size_t     sid_len;
+    /* VARARG(sid,SID); */
     char __pad_12[4];
 };
@@ -4346,4 +4359,7 @@
     unsigned int   access;
     unsigned int   ref_count;
+    data_size_t    total;
+    /* VARARG(name,unicode_str); */
+    char __pad_20[4];
 };
 
@@ -4622,4 +4638,29 @@
 };
 struct set_window_layered_info_reply
+{
+    struct reply_header __header;
+};
+
+
+
+struct alloc_user_handle_request
+{
+    struct request_header __header;
+};
+struct alloc_user_handle_reply
+{
+    struct reply_header __header;
+    user_handle_t  handle;
+    char __pad_12[4];
+};
+
+
+
+struct free_user_handle_request
+{
+    struct request_header __header;
+    user_handle_t  handle;
+};
+struct free_user_handle_reply
 {
     struct reply_header __header;
@@ -4666,4 +4707,5 @@
     REQ_open_file_object,
     REQ_alloc_file_handle,
+    REQ_get_handle_unix_name,
     REQ_get_handle_fd,
     REQ_flush_file,
@@ -4834,5 +4876,5 @@
     REQ_duplicate_token,
     REQ_access_check,
-    REQ_get_token_user,
+    REQ_get_token_sid,
     REQ_get_token_groups,
     REQ_get_token_default_dacl,
@@ -4867,4 +4909,6 @@
     REQ_get_window_layered_info,
     REQ_set_window_layered_info,
+    REQ_alloc_user_handle,
+    REQ_free_user_handle,
     REQ_NB_REQUESTS
 };
@@ -4911,4 +4955,5 @@
     struct open_file_object_request open_file_object_request;
     struct alloc_file_handle_request alloc_file_handle_request;
+    struct get_handle_unix_name_request get_handle_unix_name_request;
     struct get_handle_fd_request get_handle_fd_request;
     struct flush_file_request flush_file_request;
@@ -5079,5 +5124,5 @@
     struct duplicate_token_request duplicate_token_request;
     struct access_check_request access_check_request;
-    struct get_token_user_request get_token_user_request;
+    struct get_token_sid_request get_token_sid_request;
     struct get_token_groups_request get_token_groups_request;
     struct get_token_default_dacl_request get_token_default_dacl_request;
@@ -5112,4 +5157,6 @@
     struct get_window_layered_info_request get_window_layered_info_request;
     struct set_window_layered_info_request set_window_layered_info_request;
+    struct alloc_user_handle_request alloc_user_handle_request;
+    struct free_user_handle_request free_user_handle_request;
 };
 union generic_reply
@@ -5154,4 +5201,5 @@
     struct open_file_object_reply open_file_object_reply;
     struct alloc_file_handle_reply alloc_file_handle_reply;
+    struct get_handle_unix_name_reply get_handle_unix_name_reply;
     struct get_handle_fd_reply get_handle_fd_reply;
     struct flush_file_reply flush_file_reply;
@@ -5322,5 +5370,5 @@
     struct duplicate_token_reply duplicate_token_reply;
     struct access_check_reply access_check_reply;
-    struct get_token_user_reply get_token_user_reply;
+    struct get_token_sid_reply get_token_sid_reply;
     struct get_token_groups_reply get_token_groups_reply;
     struct get_token_default_dacl_reply get_token_default_dacl_reply;
@@ -5355,7 +5403,9 @@
     struct get_window_layered_info_reply get_window_layered_info_reply;
     struct set_window_layered_info_reply set_window_layered_info_reply;
-};
-
-#define SERVER_PROTOCOL_VERSION 390
+    struct alloc_user_handle_reply alloc_user_handle_reply;
+    struct free_user_handle_reply free_user_handle_reply;
+};
+
+#define SERVER_PROTOCOL_VERSION 395
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wgl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wgl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wgl.h	(revision 25949)
@@ -210,5 +210,9 @@
 #define WGL_CONTEXT_LAYER_PLANE_ARB    0x2093
 #define WGL_CONTEXT_FLAGS_ARB          0x2094
+#define WGL_CONTEXT_PROFILE_MASK_ARB   0x9126
+#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB    0x00000001
+#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
 #define ERROR_INVALID_VERSION_ARB      0x2095
+#define ERROR_INVALID_PROFILE_ARB      0x2096
 #ifndef GLX_ARB_create_context
 #define GLX_CONTEXT_DEBUG_BIT_ARB          0x00000001
@@ -217,4 +221,9 @@
 #define GLX_CONTEXT_MINOR_VERSION_ARB      0x2092
 #define GLX_CONTEXT_FLAGS_ARB              0x2094
+#endif
+#ifndef GLX_ARB_create_context_profile
+#define GLX_CONTEXT_PROFILE_MASK_ARB       0x9126
+#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB   0x00000001
+#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
 #endif
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winbase16.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winbase16.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winbase16.h	(revision 25949)
@@ -330,4 +330,28 @@
 
 /* undocumented functions */
+
+typedef struct tagSYSLEVEL
+{
+    CRITICAL_SECTION crst;
+    INT              level;
+} SYSLEVEL;
+
+/* [GS]etProcessDword offsets */
+#define  GPD_APP_COMPAT_FLAGS    (-56)
+#define  GPD_LOAD_DONE_EVENT     (-52)
+#define  GPD_HINSTANCE16         (-48)
+#define  GPD_WINDOWS_VERSION     (-44)
+#define  GPD_THDB                (-40)
+#define  GPD_PDB                 (-36)
+#define  GPD_STARTF_SHELLDATA    (-32)
+#define  GPD_STARTF_HOTKEY       (-28)
+#define  GPD_STARTF_SHOWWINDOW   (-24)
+#define  GPD_STARTF_SIZE         (-20)
+#define  GPD_STARTF_POSITION     (-16)
+#define  GPD_STARTF_FLAGS        (-12)
+#define  GPD_PARENT              (- 8)
+#define  GPD_FLAGS               (- 4)
+#define  GPD_USERDATA            (  0)
+
 WORD        WINAPI AllocCStoDSAlias16(WORD);
 WORD        WINAPI AllocDStoCSAlias16(WORD);
@@ -337,4 +361,6 @@
 VOID        WINAPI DirectedYield16(HTASK16);
 HGLOBAL16   WINAPI DirectResAlloc16(HINSTANCE16,WORD,UINT16);
+void        WINAPI DisposeLZ32Handle(HANDLE);
+HANDLE      WINAPI DosFileHandleToWin32Handle(HFILE);
 HANDLE16    WINAPI FarGetOwner16(HGLOBAL16);
 VOID        WINAPI FarSetOwner16(HGLOBAL16,HANDLE16);
@@ -356,5 +382,7 @@
 INT16       WINAPI GetModuleUsage16(HINSTANCE16);
 UINT16      WINAPI GetNumTasks16(void);
+VOID        WINAPI GetpWin16Lock(SYSLEVEL**);
 SEGPTR      WINAPI GetpWin16Lock16(void);
+DWORD       WINAPI GetProcessDword(DWORD,INT);
 DWORD       WINAPI GetSelectorLimit16(WORD);
 FARPROC16   WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc);
@@ -385,8 +413,12 @@
 FARPROC16   WINAPI LocalNotify16(FARPROC16);
 HTASK16     WINAPI LockCurrentTask16(BOOL16);
+DWORD       WINAPI MapLS(LPCVOID);
+LPVOID      WINAPI MapSL(DWORD);
 VOID        WINAPI OldYield16(void);
 VOID        WINAPI WIN32_OldYield16(void);
 VOID        WINAPI PostEvent16(HTASK16);
 WORD        WINAPI PrestoChangoSelector16(WORD,WORD);
+VOID        WINAPI ReleaseThunkLock(DWORD*);
+VOID        WINAPI RestoreThunkLock(DWORD);
 WORD        WINAPI SelectorAccessRights16(WORD,WORD,WORD);
 void        WINAPI SetFastQueue16(DWORD,HQUEUE16);
@@ -397,9 +429,16 @@
 HQUEUE16    WINAPI SetThreadQueue16(DWORD,HQUEUE16);
 VOID        WINAPI SwitchStackTo16(WORD,WORD,WORD);
+VOID        WINAPI UnMapLS(DWORD);
 BOOL16      WINAPI WaitEvent16(HTASK16);
+HFILE       WINAPI Win32HandleToDosFileHandle(HANDLE);
 VOID        WINAPI WriteOutProfiles16(void);
 VOID        WINAPI hmemcpy16(LPVOID,LPCVOID,LONG);
+VOID        WINAPI _CheckNotSysLevel(SYSLEVEL *lock);
+DWORD       WINAPI _ConfirmSysLevel(SYSLEVEL*);
+DWORD       WINAPI _ConfirmWin16Lock(void);
 VOID        WINAPI _CreateSysLevel(SYSLEVEL*,INT);
+VOID        WINAPI _EnterSysLevel(SYSLEVEL*);
 VOID        WINAPI _EnterWin16Lock(void);
+VOID        WINAPI _LeaveSysLevel(SYSLEVEL*);
 VOID        WINAPI _LeaveWin16Lock(void);
 
@@ -532,9 +571,3 @@
 BOOL16      WINAPI WriteProfileSection16(LPCSTR,LPCSTR);
 
-/* Some optimizations */
-extern inline LPVOID WINAPI MapSL( SEGPTR segptr )
-{
-    return (char *)wine_ldt_copy.base[SELECTOROF(segptr) >> __AHSHIFT] + OFFSETOF(segptr);
-}
-
 #endif /* __WINE_WINE_WINBASE16_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/windef16.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/windef16.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/windef16.h	(revision 25949)
@@ -161,6 +161,4 @@
 typedef BOOL16  (CALLBACK *DLGPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
 typedef INT16   (CALLBACK *EDITWORDBREAKPROC16)(LPSTR,INT16,INT16,INT16);
-typedef LRESULT (CALLBACK *FARPROC16)();
-typedef INT16   (CALLBACK *PROC16)();
 typedef BOOL16  (CALLBACK *GRAYSTRINGPROC16)(HDC16,LPARAM,INT16);
 typedef LRESULT (CALLBACK *HOOKPROC16)(INT16,WPARAM16,LPARAM);
@@ -170,3 +168,11 @@
 typedef LRESULT (CALLBACK *WNDPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
 
+#ifdef WINE_STRICT_PROTOTYPES
+typedef LRESULT (CALLBACK *FARPROC16)(void);
+typedef INT16   (CALLBACK *PROC16)(void);
+#else
+typedef LRESULT (CALLBACK *FARPROC16)();
+typedef INT16   (CALLBACK *PROC16)();
+#endif
+
 #endif /* __WINE_WINDEF16_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wine_common_ver.rc
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wine_common_ver.rc	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wine_common_ver.rc	(revision 25949)
@@ -123,5 +123,5 @@
 	    VALUE "FileVersion", WINE_FILEVERSION_STR
 	    VALUE "InternalName", WINE_FILENAME
-	    VALUE "LegalCopyright", "Copyright (c) 1993-2009 the Wine project authors (see the file AUTHORS for a complete list)"
+	    VALUE "LegalCopyright", "Copyright (c) 1993-2010 the Wine project authors (see the file AUTHORS for a complete list)"
 	    VALUE "OriginalFilename", WINE_FILENAME_STR
 	    VALUE "ProductName", WINE_PRODUCTNAME_STR
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/wine/wined3d.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/wine/wined3d.idl - Do not edit ***/
 
 #include <rpc.h>
@@ -115,4 +115,9 @@
 #define __IWineD3DVertexShader_FWD_DEFINED__
 typedef interface IWineD3DVertexShader IWineD3DVertexShader;
+#endif
+
+#ifndef __IWineD3DGeometryShader_FWD_DEFINED__
+#define __IWineD3DGeometryShader_FWD_DEFINED__
+typedef interface IWineD3DGeometryShader IWineD3DGeometryShader;
 #endif
 
@@ -141,4 +146,9 @@
     char Buffer[1];
 } RGNDATA;
+typedef struct _LUID {
+    DWORD LowPart;
+    LONG HighPart;
+} LUID;
+typedef struct _LUID *PLUID;
 #endif
 #define WINED3D_OK                                  S_OK
@@ -238,119 +248,116 @@
     WINED3DFMT_D32_UNORM = 19,
     WINED3DFMT_S1_UINT_D15_UNORM = 20,
-    WINED3DFMT_S8_UINT_D24_UNORM = 21,
-    WINED3DFMT_X8D24_UNORM = 22,
-    WINED3DFMT_S4X4_UINT_D24_UNORM = 23,
-    WINED3DFMT_L16_UNORM = 24,
-    WINED3DFMT_S8_UINT_D24_FLOAT = 25,
-    WINED3DFMT_VERTEXDATA = 26,
-    WINED3DFMT_R8G8_SNORM_Cx = 27,
-    WINED3DFMT_R32G32B32A32_TYPELESS = 28,
-    WINED3DFMT_R32G32B32A32_FLOAT = 29,
-    WINED3DFMT_R32G32B32A32_UINT = 30,
-    WINED3DFMT_R32G32B32A32_SINT = 31,
-    WINED3DFMT_R32G32B32_TYPELESS = 32,
-    WINED3DFMT_R32G32B32_FLOAT = 33,
-    WINED3DFMT_R32G32B32_UINT = 34,
-    WINED3DFMT_R32G32B32_SINT = 35,
-    WINED3DFMT_R16G16B16A16_TYPELESS = 36,
-    WINED3DFMT_R16G16B16A16_FLOAT = 37,
-    WINED3DFMT_R16G16B16A16_UNORM = 38,
-    WINED3DFMT_R16G16B16A16_UINT = 39,
-    WINED3DFMT_R16G16B16A16_SNORM = 40,
-    WINED3DFMT_R16G16B16A16_SINT = 41,
-    WINED3DFMT_R32G32_TYPELESS = 42,
-    WINED3DFMT_R32G32_FLOAT = 43,
-    WINED3DFMT_R32G32_UINT = 44,
-    WINED3DFMT_R32G32_SINT = 45,
-    WINED3DFMT_R32G8X24_TYPELESS = 46,
-    WINED3DFMT_D32_FLOAT_S8X24_UINT = 47,
-    WINED3DFMT_R32_FLOAT_X8X24_TYPELESS = 48,
-    WINED3DFMT_X32_TYPELESS_G8X24_UINT = 49,
-    WINED3DFMT_R10G10B10A2_TYPELESS = 50,
-    WINED3DFMT_R10G10B10A2_UNORM = 51,
-    WINED3DFMT_R10G10B10A2_UINT = 52,
-    WINED3DFMT_R10G10B10A2_SNORM = 53,
-    WINED3DFMT_R11G11B10_FLOAT = 54,
-    WINED3DFMT_R8G8B8A8_TYPELESS = 55,
-    WINED3DFMT_R8G8B8A8_UNORM = 56,
-    WINED3DFMT_R8G8B8A8_UNORM_SRGB = 57,
-    WINED3DFMT_R8G8B8A8_UINT = 58,
-    WINED3DFMT_R8G8B8A8_SNORM = 59,
-    WINED3DFMT_R8G8B8A8_SINT = 60,
-    WINED3DFMT_R16G16_TYPELESS = 61,
-    WINED3DFMT_R16G16_FLOAT = 62,
-    WINED3DFMT_R16G16_UNORM = 63,
-    WINED3DFMT_R16G16_UINT = 64,
-    WINED3DFMT_R16G16_SNORM = 65,
-    WINED3DFMT_R16G16_SINT = 66,
-    WINED3DFMT_R32_TYPELESS = 67,
-    WINED3DFMT_D32_FLOAT = 68,
-    WINED3DFMT_R32_FLOAT = 69,
-    WINED3DFMT_R32_UINT = 70,
-    WINED3DFMT_R32_SINT = 71,
-    WINED3DFMT_R24G8_TYPELESS = 72,
-    WINED3DFMT_D24_UNORM_S8_UINT = 73,
-    WINED3DFMT_R24_UNORM_X8_TYPELESS = 74,
-    WINED3DFMT_X24_TYPELESS_G8_UINT = 75,
-    WINED3DFMT_R8G8_TYPELESS = 76,
-    WINED3DFMT_R8G8_UNORM = 77,
-    WINED3DFMT_R8G8_UINT = 78,
-    WINED3DFMT_R8G8_SNORM = 79,
-    WINED3DFMT_R8G8_SINT = 80,
-    WINED3DFMT_R16_TYPELESS = 81,
-    WINED3DFMT_R16_FLOAT = 82,
-    WINED3DFMT_D16_UNORM = 83,
-    WINED3DFMT_R16_UNORM = 84,
-    WINED3DFMT_R16_UINT = 85,
-    WINED3DFMT_R16_SNORM = 86,
-    WINED3DFMT_R16_SINT = 87,
-    WINED3DFMT_R8_TYPELESS = 88,
-    WINED3DFMT_R8_UNORM = 89,
-    WINED3DFMT_R8_UINT = 90,
-    WINED3DFMT_R8_SNORM = 91,
-    WINED3DFMT_R8_SINT = 92,
-    WINED3DFMT_A8_UNORM = 93,
-    WINED3DFMT_R1_UNORM = 94,
-    WINED3DFMT_R9G9B9E5_SHAREDEXP = 95,
-    WINED3DFMT_R8G8_B8G8_UNORM = 96,
-    WINED3DFMT_G8R8_G8B8_UNORM = 97,
-    WINED3DFMT_BC1_TYPELESS = 98,
-    WINED3DFMT_BC1_UNORM = 99,
-    WINED3DFMT_BC1_UNORM_SRGB = 100,
-    WINED3DFMT_BC2_TYPELESS = 101,
-    WINED3DFMT_BC2_UNORM = 102,
-    WINED3DFMT_BC2_UNORM_SRGB = 103,
-    WINED3DFMT_BC3_TYPELESS = 104,
-    WINED3DFMT_BC3_UNORM = 105,
-    WINED3DFMT_BC3_UNORM_SRGB = 106,
-    WINED3DFMT_BC4_TYPELESS = 107,
-    WINED3DFMT_BC4_UNORM = 108,
-    WINED3DFMT_BC4_SNORM = 109,
-    WINED3DFMT_BC5_TYPELESS = 110,
-    WINED3DFMT_BC5_UNORM = 111,
-    WINED3DFMT_BC5_SNORM = 112,
-    WINED3DFMT_B5G6R5_UNORM = 113,
-    WINED3DFMT_B5G5R5A1_UNORM = 114,
-    WINED3DFMT_B8G8R8A8_UNORM = 115,
-    WINED3DFMT_B8G8R8X8_UNORM = 116,
+    WINED3DFMT_X8D24_UNORM = 21,
+    WINED3DFMT_S4X4_UINT_D24_UNORM = 22,
+    WINED3DFMT_L16_UNORM = 23,
+    WINED3DFMT_S8_UINT_D24_FLOAT = 24,
+    WINED3DFMT_VERTEXDATA = 25,
+    WINED3DFMT_R8G8_SNORM_Cx = 26,
+    WINED3DFMT_R32G32B32A32_TYPELESS = 27,
+    WINED3DFMT_R32G32B32A32_FLOAT = 28,
+    WINED3DFMT_R32G32B32A32_UINT = 29,
+    WINED3DFMT_R32G32B32A32_SINT = 30,
+    WINED3DFMT_R32G32B32_TYPELESS = 31,
+    WINED3DFMT_R32G32B32_FLOAT = 32,
+    WINED3DFMT_R32G32B32_UINT = 33,
+    WINED3DFMT_R32G32B32_SINT = 34,
+    WINED3DFMT_R16G16B16A16_TYPELESS = 35,
+    WINED3DFMT_R16G16B16A16_FLOAT = 36,
+    WINED3DFMT_R16G16B16A16_UNORM = 37,
+    WINED3DFMT_R16G16B16A16_UINT = 38,
+    WINED3DFMT_R16G16B16A16_SNORM = 39,
+    WINED3DFMT_R16G16B16A16_SINT = 40,
+    WINED3DFMT_R32G32_TYPELESS = 41,
+    WINED3DFMT_R32G32_FLOAT = 42,
+    WINED3DFMT_R32G32_UINT = 43,
+    WINED3DFMT_R32G32_SINT = 44,
+    WINED3DFMT_R32G8X24_TYPELESS = 45,
+    WINED3DFMT_D32_FLOAT_S8X24_UINT = 46,
+    WINED3DFMT_R32_FLOAT_X8X24_TYPELESS = 47,
+    WINED3DFMT_X32_TYPELESS_G8X24_UINT = 48,
+    WINED3DFMT_R10G10B10A2_TYPELESS = 49,
+    WINED3DFMT_R10G10B10A2_UNORM = 50,
+    WINED3DFMT_R10G10B10A2_UINT = 51,
+    WINED3DFMT_R10G10B10A2_SNORM = 52,
+    WINED3DFMT_R11G11B10_FLOAT = 53,
+    WINED3DFMT_R8G8B8A8_TYPELESS = 54,
+    WINED3DFMT_R8G8B8A8_UNORM = 55,
+    WINED3DFMT_R8G8B8A8_UNORM_SRGB = 56,
+    WINED3DFMT_R8G8B8A8_UINT = 57,
+    WINED3DFMT_R8G8B8A8_SNORM = 58,
+    WINED3DFMT_R8G8B8A8_SINT = 59,
+    WINED3DFMT_R16G16_TYPELESS = 60,
+    WINED3DFMT_R16G16_FLOAT = 61,
+    WINED3DFMT_R16G16_UNORM = 62,
+    WINED3DFMT_R16G16_UINT = 63,
+    WINED3DFMT_R16G16_SNORM = 64,
+    WINED3DFMT_R16G16_SINT = 65,
+    WINED3DFMT_R32_TYPELESS = 66,
+    WINED3DFMT_D32_FLOAT = 67,
+    WINED3DFMT_R32_FLOAT = 68,
+    WINED3DFMT_R32_UINT = 69,
+    WINED3DFMT_R32_SINT = 70,
+    WINED3DFMT_R24G8_TYPELESS = 71,
+    WINED3DFMT_D24_UNORM_S8_UINT = 72,
+    WINED3DFMT_R24_UNORM_X8_TYPELESS = 73,
+    WINED3DFMT_X24_TYPELESS_G8_UINT = 74,
+    WINED3DFMT_R8G8_TYPELESS = 75,
+    WINED3DFMT_R8G8_UNORM = 76,
+    WINED3DFMT_R8G8_UINT = 77,
+    WINED3DFMT_R8G8_SNORM = 78,
+    WINED3DFMT_R8G8_SINT = 79,
+    WINED3DFMT_R16_TYPELESS = 80,
+    WINED3DFMT_R16_FLOAT = 81,
+    WINED3DFMT_D16_UNORM = 82,
+    WINED3DFMT_R16_UNORM = 83,
+    WINED3DFMT_R16_UINT = 84,
+    WINED3DFMT_R16_SNORM = 85,
+    WINED3DFMT_R16_SINT = 86,
+    WINED3DFMT_R8_TYPELESS = 87,
+    WINED3DFMT_R8_UNORM = 88,
+    WINED3DFMT_R8_UINT = 89,
+    WINED3DFMT_R8_SNORM = 90,
+    WINED3DFMT_R8_SINT = 91,
+    WINED3DFMT_A8_UNORM = 92,
+    WINED3DFMT_R1_UNORM = 93,
+    WINED3DFMT_R9G9B9E5_SHAREDEXP = 94,
+    WINED3DFMT_R8G8_B8G8_UNORM = 95,
+    WINED3DFMT_G8R8_G8B8_UNORM = 96,
+    WINED3DFMT_BC1_TYPELESS = 97,
+    WINED3DFMT_BC1_UNORM = 98,
+    WINED3DFMT_BC1_UNORM_SRGB = 99,
+    WINED3DFMT_BC2_TYPELESS = 100,
+    WINED3DFMT_BC2_UNORM = 101,
+    WINED3DFMT_BC2_UNORM_SRGB = 102,
+    WINED3DFMT_BC3_TYPELESS = 103,
+    WINED3DFMT_BC3_UNORM = 104,
+    WINED3DFMT_BC3_UNORM_SRGB = 105,
+    WINED3DFMT_BC4_TYPELESS = 106,
+    WINED3DFMT_BC4_UNORM = 107,
+    WINED3DFMT_BC4_SNORM = 108,
+    WINED3DFMT_BC5_TYPELESS = 109,
+    WINED3DFMT_BC5_UNORM = 110,
+    WINED3DFMT_BC5_SNORM = 111,
+    WINED3DFMT_B5G6R5_UNORM = 112,
+    WINED3DFMT_B5G5R5A1_UNORM = 113,
+    WINED3DFMT_B8G8R8A8_UNORM = 114,
+    WINED3DFMT_B8G8R8X8_UNORM = 115,
+    WINED3DFMT_UYVY = 0x59565955,
+    WINED3DFMT_YUY2 = 0x32595559,
+    WINED3DFMT_YV12 = 0x32315659,
+    WINED3DFMT_DXT1 = 0x31545844,
+    WINED3DFMT_DXT2 = 0x32545844,
+    WINED3DFMT_DXT3 = 0x33545844,
+    WINED3DFMT_DXT4 = 0x34545844,
+    WINED3DFMT_DXT5 = 0x35545844,
+    WINED3DFMT_MULTI2_ARGB8 = 0x3154454d,
+    WINED3DFMT_G8R8_G8B8 = 0x42475247,
+    WINED3DFMT_R8G8_B8G8 = 0x47424752,
+    WINED3DFMT_ATI2N = 0x32495441,
+    WINED3DFMT_INST = 0x54534e49,
+    WINED3DFMT_NVHU = 0x5548564e,
+    WINED3DFMT_NVHS = 0x5348564e,
     WINED3DFMT_FORCE_DWORD = 0xffffffff
 } WINED3DFORMAT;
-#define WINEMAKEFOURCC(ch0, ch1, ch2, ch3) \
-        ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
-        ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
-#define WINED3DFMT_UYVY         WINEMAKEFOURCC('U', 'Y', 'V', 'Y')
-#define WINED3DFMT_YUY2         WINEMAKEFOURCC('Y', 'U', 'Y', '2')
-#define WINED3DFMT_YV12         WINEMAKEFOURCC('Y', 'V', '1', '2')
-#define WINED3DFMT_DXT1         WINEMAKEFOURCC('D', 'X', 'T', '1')
-#define WINED3DFMT_DXT2         WINEMAKEFOURCC('D', 'X', 'T', '2')
-#define WINED3DFMT_DXT3         WINEMAKEFOURCC('D', 'X', 'T', '3')
-#define WINED3DFMT_DXT4         WINEMAKEFOURCC('D', 'X', 'T', '4')
-#define WINED3DFMT_DXT5         WINEMAKEFOURCC('D', 'X', 'T', '5')
-#define WINED3DFMT_MULTI2_ARGB8 WINEMAKEFOURCC('M', 'E', 'T', '1')
-#define WINED3DFMT_G8R8_G8B8    WINEMAKEFOURCC('G', 'R', 'G', 'B')
-#define WINED3DFMT_R8G8_B8G8    WINEMAKEFOURCC('R', 'G', 'B', 'G')
-#define WINED3DFMT_ATI2N        WINEMAKEFOURCC('A', 'T', 'I', '2')
-#define WINED3DFMT_NVHU         WINEMAKEFOURCC('N', 'V', 'H', 'U')
-#define WINED3DFMT_NVHS         WINEMAKEFOURCC('N', 'V', 'H', 'S')
 typedef enum _WINED3DRENDERSTATETYPE {
     WINED3DRS_TEXTUREHANDLE = 1,
@@ -756,10 +763,10 @@
     WINED3DTS_TEXTURE6 = 22,
     WINED3DTS_TEXTURE7 = 23,
+    WINED3DTS_WORLD = 256,
+    WINED3DTS_WORLD1 = 257,
+    WINED3DTS_WORLD2 = 258,
+    WINED3DTS_WORLD3 = 259,
     WINED3DTS_FORCE_DWORD = 0x7fffffff
 } WINED3DTRANSFORMSTATETYPE;
-#define WINED3DTS_WORLD  WINED3DTS_WORLDMATRIX(0)
-#define WINED3DTS_WORLD1 WINED3DTS_WORLDMATRIX(1)
-#define WINED3DTS_WORLD2 WINED3DTS_WORLDMATRIX(2)
-#define WINED3DTS_WORLD3 WINED3DTS_WORLDMATRIX(3)
 #define WINED3DTS_WORLDMATRIX(index) (WINED3DTRANSFORMSTATETYPE)(index + 256)
 typedef enum _WINED3DBASISTYPE {
@@ -960,4 +967,6 @@
 
 #define WINED3DUSAGE_MASK (0x4fff)
+
+#define WINED3DUSAGE_STATICDECL (0x40000000)
 
 #define WINED3DUSAGE_OVERLAY (0x80000000)
@@ -2251,4 +2260,6 @@
     GUID device_identifier;
     DWORD whql_level;
+    LUID adapter_luid;
+    SIZE_T video_memory;
 } WINED3DADAPTER_IDENTIFIER;
 typedef struct _WINED3DPRESENT_PARAMETERS {
@@ -3325,7 +3336,4 @@
 interface IWineD3DResource : public IWineD3DBase
 {
-    virtual HRESULT STDMETHODCALLTYPE GetDevice(
-        IWineD3DDevice **device) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE SetPrivateData(
         REFGUID guid,
@@ -3380,8 +3388,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DResource* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DResource* This,
@@ -3431,5 +3435,4 @@
 #define IWineD3DResource_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DResource_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DResource_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DResource_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -3444,12 +3447,4 @@
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DResource_GetDevice_Proxy(
-    IWineD3DResource* This,
-    IWineD3DDevice **device);
-void __RPC_STUB IWineD3DResource_GetDevice_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DResource_SetPrivateData_Proxy(
     IWineD3DResource* This,
@@ -4020,8 +4015,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DSurface* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DSurface* This,
@@ -4230,5 +4221,4 @@
 #define IWineD3DSurface_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DSurface_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DSurface_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DSurface_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -4640,8 +4630,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DVolume* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DVolume* This,
@@ -4719,5 +4705,4 @@
 #define IWineD3DVolume_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DVolume_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DVolume_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DVolume_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -4859,8 +4844,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DBaseTexture* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DBaseTexture* This,
@@ -4948,5 +4929,4 @@
 #define IWineD3DBaseTexture_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DBaseTexture_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DBaseTexture_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DBaseTexture_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -5110,8 +5090,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DTexture* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DTexture* This,
@@ -5225,5 +5201,4 @@
 #define IWineD3DTexture_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DTexture_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DTexture_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DTexture_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -5361,8 +5336,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DCubeTexture* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DCubeTexture* This,
@@ -5480,5 +5451,4 @@
 #define IWineD3DCubeTexture_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DCubeTexture_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DCubeTexture_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DCubeTexture_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -5616,8 +5586,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DVolumeTexture* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DVolumeTexture* This,
@@ -5731,5 +5697,4 @@
 #define IWineD3DVolumeTexture_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DVolumeTexture_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DVolumeTexture_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DVolumeTexture_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -5820,7 +5785,4 @@
 interface IWineD3DVertexDeclaration : public IWineD3DBase
 {
-    virtual HRESULT STDMETHODCALLTYPE GetDevice(
-        IWineD3DDevice **device) = 0;
-
 };
 #else
@@ -5844,9 +5806,4 @@
         IWineD3DVertexDeclaration* This,
         IUnknown **parent);
-
-    /*** IWineD3DVertexDeclaration methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DVertexDeclaration* This,
-        IWineD3DDevice **device);
 
     END_INTERFACE
@@ -5863,18 +5820,8 @@
 /*** IWineD3DBase methods ***/
 #define IWineD3DVertexDeclaration_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
-/*** IWineD3DVertexDeclaration methods ***/
-#define IWineD3DVertexDeclaration_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #endif
 
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DVertexDeclaration_GetDevice_Proxy(
-    IWineD3DVertexDeclaration* This,
-    IWineD3DDevice **device);
-void __RPC_STUB IWineD3DVertexDeclaration_GetDevice_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 
 #endif  /* __IWineD3DVertexDeclaration_INTERFACE_DEFINED__ */
@@ -5888,9 +5835,6 @@
 DEFINE_GUID(IID_IWineD3DStateBlock, 0x83b073ce, 0x6f30, 0x11d9, 0xc6,0x87, 0x00,0x04,0x61,0x42,0xc1,0x4f);
 #if defined(__cplusplus) && !defined(CINTERFACE)
-interface IWineD3DStateBlock : public IWineD3DBase
+interface IWineD3DStateBlock : public IUnknown
 {
-    virtual HRESULT STDMETHODCALLTYPE GetDevice(
-        IWineD3DDevice **device) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE Capture(
         ) = 0;
@@ -5919,14 +5863,5 @@
         IWineD3DStateBlock* This);
 
-    /*** IWineD3DBase methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetParent)(
-        IWineD3DStateBlock* This,
-        IUnknown **parent);
-
     /*** IWineD3DStateBlock methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DStateBlock* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *Capture)(
         IWineD3DStateBlock* This);
@@ -5949,8 +5884,5 @@
 #define IWineD3DStateBlock_AddRef(This) (This)->lpVtbl->AddRef(This)
 #define IWineD3DStateBlock_Release(This) (This)->lpVtbl->Release(This)
-/*** IWineD3DBase methods ***/
-#define IWineD3DStateBlock_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DStateBlock methods ***/
-#define IWineD3DStateBlock_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DStateBlock_Capture(This) (This)->lpVtbl->Capture(This)
 #define IWineD3DStateBlock_Apply(This) (This)->lpVtbl->Apply(This)
@@ -5960,12 +5892,4 @@
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DStateBlock_GetDevice_Proxy(
-    IWineD3DStateBlock* This,
-    IWineD3DDevice **device);
-void __RPC_STUB IWineD3DStateBlock_GetDevice_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DStateBlock_Capture_Proxy(
     IWineD3DStateBlock* This);
@@ -6002,7 +5926,4 @@
 interface IWineD3DQuery : public IWineD3DBase
 {
-    virtual HRESULT STDMETHODCALLTYPE GetDevice(
-        IWineD3DDevice **device) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE GetData(
         void *data,
@@ -6042,8 +5963,4 @@
 
     /*** IWineD3DQuery methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DQuery* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *GetData)(
         IWineD3DQuery* This,
@@ -6076,5 +5993,4 @@
 #define IWineD3DQuery_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DQuery methods ***/
-#define IWineD3DQuery_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DQuery_GetData(This,data,data_size,flags) (This)->lpVtbl->GetData(This,data,data_size,flags)
 #define IWineD3DQuery_GetDataSize(This) (This)->lpVtbl->GetDataSize(This)
@@ -6085,12 +6001,4 @@
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DQuery_GetDevice_Proxy(
-    IWineD3DQuery* This,
-    IWineD3DDevice **device);
-void __RPC_STUB IWineD3DQuery_GetDevice_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DQuery_GetData_Proxy(
     IWineD3DQuery* This,
@@ -6422,8 +6330,4 @@
 
     /*** IWineD3DResource methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DBuffer* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *SetPrivateData)(
         IWineD3DBuffer* This,
@@ -6488,5 +6392,4 @@
 #define IWineD3DBuffer_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DResource methods ***/
-#define IWineD3DBuffer_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DBuffer_SetPrivateData(This,guid,data,data_size,flags) (This)->lpVtbl->SetPrivateData(This,guid,data,data_size,flags)
 #define IWineD3DBuffer_GetPrivateData(This,guid,data,data_size) (This)->lpVtbl->GetPrivateData(This,guid,data,data_size)
@@ -6544,7 +6447,4 @@
 interface IWineD3DBaseShader : public IWineD3DBase
 {
-    virtual HRESULT STDMETHODCALLTYPE GetDevice(
-        IWineD3DDevice **device) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE GetFunction(
         void *data,
@@ -6574,8 +6474,4 @@
 
     /*** IWineD3DBaseShader methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DBaseShader* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *GetFunction)(
         IWineD3DBaseShader* This,
@@ -6597,5 +6493,4 @@
 #define IWineD3DBaseShader_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DBaseShader methods ***/
-#define IWineD3DBaseShader_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DBaseShader_GetFunction(This,data,data_size) (This)->lpVtbl->GetFunction(This,data,data_size)
 #endif
@@ -6603,12 +6498,4 @@
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DBaseShader_GetDevice_Proxy(
-    IWineD3DBaseShader* This,
-    IWineD3DDevice **device);
-void __RPC_STUB IWineD3DBaseShader_GetDevice_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DBaseShader_GetFunction_Proxy(
     IWineD3DBaseShader* This,
@@ -6661,8 +6548,4 @@
 
     /*** IWineD3DBaseShader methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DVertexShader* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *GetFunction)(
         IWineD3DVertexShader* This,
@@ -6691,5 +6574,4 @@
 #define IWineD3DVertexShader_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DBaseShader methods ***/
-#define IWineD3DVertexShader_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DVertexShader_GetFunction(This,data,data_size) (This)->lpVtbl->GetFunction(This,data,data_size)
 /*** IWineD3DVertexShader methods ***/
@@ -6711,4 +6593,64 @@
 
 #endif  /* __IWineD3DVertexShader_INTERFACE_DEFINED__ */
+
+/*****************************************************************************
+ * IWineD3DGeometryShader interface
+ */
+#ifndef __IWineD3DGeometryShader_INTERFACE_DEFINED__
+#define __IWineD3DGeometryShader_INTERFACE_DEFINED__
+
+DEFINE_GUID(IID_IWineD3DGeometryShader, 0x8276c113, 0x388b, 0x49d1, 0xad,0x8b, 0xc9,0xdd,0x8b,0xcb,0xab,0xcd);
+#if defined(__cplusplus) && !defined(CINTERFACE)
+interface IWineD3DGeometryShader : public IWineD3DBaseShader
+{
+};
+#else
+typedef struct IWineD3DGeometryShaderVtbl {
+    BEGIN_INTERFACE
+
+    /*** IUnknown methods ***/
+    HRESULT (STDMETHODCALLTYPE *QueryInterface)(
+        IWineD3DGeometryShader* This,
+        REFIID riid,
+        void **ppvObject);
+
+    ULONG (STDMETHODCALLTYPE *AddRef)(
+        IWineD3DGeometryShader* This);
+
+    ULONG (STDMETHODCALLTYPE *Release)(
+        IWineD3DGeometryShader* This);
+
+    /*** IWineD3DBase methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetParent)(
+        IWineD3DGeometryShader* This,
+        IUnknown **parent);
+
+    /*** IWineD3DBaseShader methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetFunction)(
+        IWineD3DGeometryShader* This,
+        void *data,
+        UINT *data_size);
+
+    END_INTERFACE
+} IWineD3DGeometryShaderVtbl;
+interface IWineD3DGeometryShader {
+    CONST_VTBL IWineD3DGeometryShaderVtbl* lpVtbl;
+};
+
+#ifdef COBJMACROS
+/*** IUnknown methods ***/
+#define IWineD3DGeometryShader_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IWineD3DGeometryShader_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IWineD3DGeometryShader_Release(This) (This)->lpVtbl->Release(This)
+/*** IWineD3DBase methods ***/
+#define IWineD3DGeometryShader_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
+/*** IWineD3DBaseShader methods ***/
+#define IWineD3DGeometryShader_GetFunction(This,data,data_size) (This)->lpVtbl->GetFunction(This,data,data_size)
+#endif
+
+#endif
+
+
+#endif  /* __IWineD3DGeometryShader_INTERFACE_DEFINED__ */
 
 /*****************************************************************************
@@ -6745,8 +6687,4 @@
 
     /*** IWineD3DBaseShader methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetDevice)(
-        IWineD3DPixelShader* This,
-        IWineD3DDevice **device);
-
     HRESULT (STDMETHODCALLTYPE *GetFunction)(
         IWineD3DPixelShader* This,
@@ -6768,5 +6706,4 @@
 #define IWineD3DPixelShader_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DBaseShader methods ***/
-#define IWineD3DPixelShader_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DPixelShader_GetFunction(This,data,data_size) (This)->lpVtbl->GetFunction(This,data,data_size)
 #endif
@@ -6797,5 +6734,4 @@
         UINT length,
         DWORD usage,
-        DWORD fvf,
         WINED3DPOOL pool,
         IWineD3DBuffer **vertex_buffer,
@@ -6912,4 +6848,11 @@
         const struct wined3d_parent_ops *parent_ops) = 0;
 
+    virtual HRESULT STDMETHODCALLTYPE CreateGeometryShader(
+        const DWORD *byte_code,
+        const struct wined3d_shader_signature *output_signature,
+        IWineD3DGeometryShader **shader,
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
+
     virtual HRESULT STDMETHODCALLTYPE CreatePixelShader(
         const DWORD *function,
@@ -6999,7 +6942,4 @@
         BOOL show) = 0;
 
-    virtual HRESULT STDMETHODCALLTYPE TestCooperativeLevel(
-        ) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE SetClipPlane(
         DWORD plane_idx,
@@ -7132,5 +7072,6 @@
     virtual HRESULT STDMETHODCALLTYPE SetRenderTarget(
         DWORD render_target_idx,
-        IWineD3DSurface *render_target) = 0;
+        IWineD3DSurface *render_target,
+        BOOL set_viewport) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE GetRenderTarget(
@@ -7412,5 +7353,4 @@
         UINT length,
         DWORD usage,
-        DWORD fvf,
         WINED3DPOOL pool,
         IWineD3DBuffer **vertex_buffer,
@@ -7540,4 +7480,12 @@
         const struct wined3d_parent_ops *parent_ops);
 
+    HRESULT (STDMETHODCALLTYPE *CreateGeometryShader)(
+        IWineD3DDevice* This,
+        const DWORD *byte_code,
+        const struct wined3d_shader_signature *output_signature,
+        IWineD3DGeometryShader **shader,
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
+
     HRESULT (STDMETHODCALLTYPE *CreatePixelShader)(
         IWineD3DDevice* This,
@@ -7646,7 +7594,4 @@
         BOOL show);
 
-    HRESULT (STDMETHODCALLTYPE *TestCooperativeLevel)(
-        IWineD3DDevice* This);
-
     HRESULT (STDMETHODCALLTYPE *SetClipPlane)(
         IWineD3DDevice* This,
@@ -7813,5 +7758,6 @@
         IWineD3DDevice* This,
         DWORD render_target_idx,
-        IWineD3DSurface *render_target);
+        IWineD3DSurface *render_target,
+        BOOL set_viewport);
 
     HRESULT (STDMETHODCALLTYPE *GetRenderTarget)(
@@ -8125,5 +8071,5 @@
 /*** IWineD3DDevice methods ***/
 #define IWineD3DDevice_CreateBuffer(This,desc,data,parent,parent_ops,buffer) (This)->lpVtbl->CreateBuffer(This,desc,data,parent,parent_ops,buffer)
-#define IWineD3DDevice_CreateVertexBuffer(This,length,usage,fvf,pool,vertex_buffer,parent,parent_ops) (This)->lpVtbl->CreateVertexBuffer(This,length,usage,fvf,pool,vertex_buffer,parent,parent_ops)
+#define IWineD3DDevice_CreateVertexBuffer(This,length,usage,pool,vertex_buffer,parent,parent_ops) (This)->lpVtbl->CreateVertexBuffer(This,length,usage,pool,vertex_buffer,parent,parent_ops)
 #define IWineD3DDevice_CreateIndexBuffer(This,length,usage,pool,index_buffer,parent,parent_ops) (This)->lpVtbl->CreateIndexBuffer(This,length,usage,pool,index_buffer,parent,parent_ops)
 #define IWineD3DDevice_CreateStateBlock(This,type,stateblock,parent) (This)->lpVtbl->CreateStateBlock(This,type,stateblock,parent)
@@ -8139,4 +8085,5 @@
 #define IWineD3DDevice_CreateVertexDeclarationFromFVF(This,declaration,parent,parent_ops,fvf) (This)->lpVtbl->CreateVertexDeclarationFromFVF(This,declaration,parent,parent_ops,fvf)
 #define IWineD3DDevice_CreateVertexShader(This,function,output_signature,shader,parent,parent_ops) (This)->lpVtbl->CreateVertexShader(This,function,output_signature,shader,parent,parent_ops)
+#define IWineD3DDevice_CreateGeometryShader(This,byte_code,output_signature,shader,parent,parent_ops) (This)->lpVtbl->CreateGeometryShader(This,byte_code,output_signature,shader,parent,parent_ops)
 #define IWineD3DDevice_CreatePixelShader(This,function,output_signature,shader,parent,parent_ops) (This)->lpVtbl->CreatePixelShader(This,function,output_signature,shader,parent,parent_ops)
 #define IWineD3DDevice_CreatePalette(This,flags,palette_entry,palette,parent) (This)->lpVtbl->CreatePalette(This,flags,palette_entry,palette,parent)
@@ -8162,5 +8109,4 @@
 #define IWineD3DDevice_SetCursorPosition(This,x_screen_space,y_screen_space,flags) (This)->lpVtbl->SetCursorPosition(This,x_screen_space,y_screen_space,flags)
 #define IWineD3DDevice_ShowCursor(This,show) (This)->lpVtbl->ShowCursor(This,show)
-#define IWineD3DDevice_TestCooperativeLevel(This) (This)->lpVtbl->TestCooperativeLevel(This)
 #define IWineD3DDevice_SetClipPlane(This,plane_idx,plane) (This)->lpVtbl->SetClipPlane(This,plane_idx,plane)
 #define IWineD3DDevice_GetClipPlane(This,plane_idx,plane) (This)->lpVtbl->GetClipPlane(This,plane_idx,plane)
@@ -8197,5 +8143,5 @@
 #define IWineD3DDevice_SetRenderState(This,state,value) (This)->lpVtbl->SetRenderState(This,state,value)
 #define IWineD3DDevice_GetRenderState(This,state,value) (This)->lpVtbl->GetRenderState(This,state,value)
-#define IWineD3DDevice_SetRenderTarget(This,render_target_idx,render_target) (This)->lpVtbl->SetRenderTarget(This,render_target_idx,render_target)
+#define IWineD3DDevice_SetRenderTarget(This,render_target_idx,render_target,set_viewport) (This)->lpVtbl->SetRenderTarget(This,render_target_idx,render_target,set_viewport)
 #define IWineD3DDevice_GetRenderTarget(This,render_target_idx,render_target) (This)->lpVtbl->GetRenderTarget(This,render_target_idx,render_target)
 #define IWineD3DDevice_SetFrontBackBuffers(This,front,back) (This)->lpVtbl->SetFrontBackBuffers(This,front,back)
@@ -8274,5 +8220,4 @@
     UINT length,
     DWORD usage,
-    DWORD fvf,
     WINED3DPOOL pool,
     IWineD3DBuffer **vertex_buffer,
@@ -8458,4 +8403,16 @@
     PRPC_MESSAGE pRpcMessage,
     DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IWineD3DDevice_CreateGeometryShader_Proxy(
+    IWineD3DDevice* This,
+    const DWORD *byte_code,
+    const struct wined3d_shader_signature *output_signature,
+    IWineD3DGeometryShader **shader,
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
+void __RPC_STUB IWineD3DDevice_CreateGeometryShader_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DDevice_CreatePixelShader_Proxy(
     IWineD3DDevice* This,
@@ -8656,11 +8613,4 @@
     PRPC_MESSAGE pRpcMessage,
     DWORD* pdwStubPhase);
-HRESULT STDMETHODCALLTYPE IWineD3DDevice_TestCooperativeLevel_Proxy(
-    IWineD3DDevice* This);
-void __RPC_STUB IWineD3DDevice_TestCooperativeLevel_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DDevice_SetClipPlane_Proxy(
     IWineD3DDevice* This,
@@ -8963,5 +8913,6 @@
     IWineD3DDevice* This,
     DWORD render_target_idx,
-    IWineD3DSurface *render_target);
+    IWineD3DSurface *render_target,
+    BOOL set_viewport);
 void __RPC_STUB IWineD3DDevice_SetRenderTarget_Stub(
     IRpcStubBuffer* This,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl	(revision 25949)
@@ -61,4 +61,10 @@
     char Buffer[1];
 } RGNDATA;
+
+typedef struct _LUID
+{
+    DWORD LowPart;
+    LONG HighPart;
+} LUID, *PLUID;
 cpp_quote("#endif")
 
@@ -171,5 +177,4 @@
     WINED3DFMT_D32_UNORM,
     WINED3DFMT_S1_UINT_D15_UNORM,
-    WINED3DFMT_S8_UINT_D24_UNORM,
     WINED3DFMT_X8D24_UNORM,
     WINED3DFMT_S4X4_UINT_D24_UNORM,
@@ -267,25 +272,23 @@
     WINED3DFMT_B8G8R8A8_UNORM,
     WINED3DFMT_B8G8R8X8_UNORM,
+    /* FOURCC formats. */
+    WINED3DFMT_UYVY                         = 0x59565955, /* UYVY */
+    WINED3DFMT_YUY2                         = 0x32595559, /* YUY2 */
+    WINED3DFMT_YV12                         = 0x32315659, /* YV12 */
+    WINED3DFMT_DXT1                         = 0x31545844, /* DXT1 */
+    WINED3DFMT_DXT2                         = 0x32545844, /* DXT2 */
+    WINED3DFMT_DXT3                         = 0x33545844, /* DXT3 */
+    WINED3DFMT_DXT4                         = 0x34545844, /* DXT4 */
+    WINED3DFMT_DXT5                         = 0x35545844, /* DXT5 */
+    WINED3DFMT_MULTI2_ARGB8                 = 0x3154454d, /* MET1 */
+    WINED3DFMT_G8R8_G8B8                    = 0x42475247, /* GRGB */
+    WINED3DFMT_R8G8_B8G8                    = 0x47424752, /* RGBG */
+    WINED3DFMT_ATI2N                        = 0x32495441, /* ATI2 */
+    WINED3DFMT_INST                         = 0x54534e49, /* INST */
+    WINED3DFMT_NVHU                         = 0x5548564e, /* NVHU */
+    WINED3DFMT_NVHS                         = 0x5348564e, /* NVHS */
 
     WINED3DFMT_FORCE_DWORD = 0xffffffff
 } WINED3DFORMAT;
-cpp_quote("#define WINEMAKEFOURCC(ch0, ch1, ch2, ch3) \\")
-cpp_quote("        ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\")
-cpp_quote("        ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))")
-cpp_quote("#define WINED3DFMT_UYVY         WINEMAKEFOURCC('U', 'Y', 'V', 'Y')")
-cpp_quote("#define WINED3DFMT_YUY2         WINEMAKEFOURCC('Y', 'U', 'Y', '2')")
-cpp_quote("#define WINED3DFMT_YV12         WINEMAKEFOURCC('Y', 'V', '1', '2')")
-cpp_quote("#define WINED3DFMT_DXT1         WINEMAKEFOURCC('D', 'X', 'T', '1')")
-cpp_quote("#define WINED3DFMT_DXT2         WINEMAKEFOURCC('D', 'X', 'T', '2')")
-cpp_quote("#define WINED3DFMT_DXT3         WINEMAKEFOURCC('D', 'X', 'T', '3')")
-cpp_quote("#define WINED3DFMT_DXT4         WINEMAKEFOURCC('D', 'X', 'T', '4')")
-cpp_quote("#define WINED3DFMT_DXT5         WINEMAKEFOURCC('D', 'X', 'T', '5')")
-cpp_quote("#define WINED3DFMT_MULTI2_ARGB8 WINEMAKEFOURCC('M', 'E', 'T', '1')")
-cpp_quote("#define WINED3DFMT_G8R8_G8B8    WINEMAKEFOURCC('G', 'R', 'G', 'B')")
-cpp_quote("#define WINED3DFMT_R8G8_B8G8    WINEMAKEFOURCC('R', 'G', 'B', 'G')")
-/* Vendor specific formats */
-cpp_quote("#define WINED3DFMT_ATI2N        WINEMAKEFOURCC('A', 'T', 'I', '2')")
-cpp_quote("#define WINED3DFMT_NVHU         WINEMAKEFOURCC('N', 'V', 'H', 'U')")
-cpp_quote("#define WINED3DFMT_NVHS         WINEMAKEFOURCC('N', 'V', 'H', 'S')")
 
 typedef enum _WINED3DRENDERSTATETYPE
@@ -732,10 +735,10 @@
     WINED3DTS_TEXTURE6                      = 22,
     WINED3DTS_TEXTURE7                      = 23,
+    WINED3DTS_WORLD                         = 256, /*WINED3DTS_WORLDMATRIX(0)*/
+    WINED3DTS_WORLD1                        = 257,
+    WINED3DTS_WORLD2                        = 258,
+    WINED3DTS_WORLD3                        = 259,
     WINED3DTS_FORCE_DWORD                   = 0x7fffffff
 } WINED3DTRANSFORMSTATETYPE;
-cpp_quote("#define WINED3DTS_WORLD  WINED3DTS_WORLDMATRIX(0)")
-cpp_quote("#define WINED3DTS_WORLD1 WINED3DTS_WORLDMATRIX(1)")
-cpp_quote("#define WINED3DTS_WORLD2 WINED3DTS_WORLDMATRIX(2)")
-cpp_quote("#define WINED3DTS_WORLD3 WINED3DTS_WORLDMATRIX(3)")
 cpp_quote("#define WINED3DTS_WORLDMATRIX(index) (WINED3DTRANSFORMSTATETYPE)(index + 256)")
 
@@ -921,4 +924,5 @@
 const UINT WINED3DUSAGE_DMAP                                    = 0x00004000;
 const UINT WINED3DUSAGE_MASK                                    = 0x00004fff;
+const UINT WINED3DUSAGE_STATICDECL                              = 0x40000000;
 const UINT WINED3DUSAGE_OVERLAY                                 = 0x80000000;
 
@@ -1717,4 +1721,6 @@
     GUID device_identifier;
     DWORD whql_level;
+    LUID adapter_luid;
+    SIZE_T video_memory;
 } WINED3DADAPTER_IDENTIFIER;
 
@@ -2337,7 +2343,4 @@
 interface IWineD3DResource : IWineD3DBase
 {
-    HRESULT GetDevice(
-        [out] IWineD3DDevice **device
-    );
     HRESULT SetPrivateData(
         [in] REFGUID guid,
@@ -2725,7 +2728,4 @@
 interface IWineD3DVertexDeclaration : IWineD3DBase
 {
-    HRESULT GetDevice(
-        [out] IWineD3DDevice **device
-    );
 }
 
@@ -2735,9 +2735,6 @@
     uuid(83b073ce-6f30-11d9-c687-00046142c14f)
 ]
-interface IWineD3DStateBlock : IWineD3DBase
-{
-    HRESULT GetDevice(
-        [out] IWineD3DDevice **device
-    );
+interface IWineD3DStateBlock : IUnknown
+{
     HRESULT Capture(
     );
@@ -2755,7 +2752,4 @@
 interface IWineD3DQuery : IWineD3DBase
 {
-    HRESULT GetDevice(
-        [out] IWineD3DDevice **device
-    );
     HRESULT GetData(
         [out] void *data,
@@ -2847,7 +2841,4 @@
 interface IWineD3DBaseShader : IWineD3DBase
 {
-    HRESULT GetDevice(
-        [out] IWineD3DDevice **device
-    );
     HRESULT GetFunction(
         [out] void *data,
@@ -2873,4 +2864,13 @@
     object,
     local,
+    uuid(8276c113-388b-49d1-ad8b-c9dd8bcbabcd)
+]
+interface IWineD3DGeometryShader : IWineD3DBaseShader
+{
+}
+
+[
+    object,
+    local,
     uuid(818503da-6f30-11d9-c687-00046142c14f)
 ]
@@ -2896,5 +2896,4 @@
         [in] UINT length,
         [in] DWORD usage,
-        [in] DWORD fvf,
         [in] WINED3DPOOL pool,
         [out] IWineD3DBuffer **vertex_buffer,
@@ -3011,4 +3010,11 @@
         [in] const struct wined3d_parent_ops *parent_ops
     );
+    HRESULT CreateGeometryShader(
+        [in] const DWORD *byte_code,
+        [in] const struct wined3d_shader_signature *output_signature,
+        [out] IWineD3DGeometryShader **shader,
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
+    );
     HRESULT CreatePixelShader(
         [in] const DWORD *function,
@@ -3094,6 +3100,4 @@
         [in] BOOL show
     );
-    HRESULT TestCooperativeLevel(
-    );
     HRESULT SetClipPlane(
         [in] DWORD plane_idx,
@@ -3225,5 +3229,6 @@
     HRESULT SetRenderTarget(
         [in] DWORD render_target_idx,
-        [in] IWineD3DSurface *render_target
+        [in] IWineD3DSurface *render_target,
+        [in] BOOL set_viewport
     );
     HRESULT GetRenderTarget(
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winsock16.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winsock16.h	(revision 25947)
+++ 	(revision )
@@ -1,119 +1,0 @@
-/*
- * Copyright (C) the Wine project
- *
- * 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
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
-#ifndef __WINE_WINE_WINSOCK16_H
-#define __WINE_WINE_WINSOCK16_H
-
-#include <stdarg.h>
-#include <windef.h>
-#include <winbase.h>
-#include <pshpack1.h>
-
-typedef UINT16 SOCKET16;
-
-typedef struct
-{
-        UINT16    fd_count;               /* how many are SET? */
-        SOCKET16  fd_array[WS_FD_SETSIZE];   /* an array of SOCKETs */
-} ws_fd_set16;
-
-/* ws_hostent16, ws_protoent16, ws_servent16, ws_netent16
- * are 1-byte aligned here ! */
-typedef struct ws_hostent16
-{
-        SEGPTR  h_name;         /* official name of host */
-        SEGPTR  h_aliases;      /* alias list */
-        INT16   h_addrtype;     /* host address type */
-        INT16   h_length;       /* length of address */
-        SEGPTR  h_addr_list;    /* list of addresses from name server */
-} _ws_hostent16;
-
-typedef struct ws_protoent16
-{
-        SEGPTR  p_name;         /* official protocol name */
-        SEGPTR  p_aliases;      /* alias list */
-        INT16   p_proto;        /* protocol # */
-} _ws_protoent16;
-
-typedef struct ws_servent16
-{
-        SEGPTR  s_name;         /* official service name */
-        SEGPTR  s_aliases;      /* alias list */
-        INT16   s_port;         /* port # */
-        SEGPTR  s_proto;        /* protocol to use */
-} _ws_servent16;
-
-typedef struct ws_netent16
-{
-        SEGPTR  n_name;         /* official name of net */
-        SEGPTR  n_aliases;      /* alias list */
-        INT16   n_addrtype;     /* net address type */
-        INT     n_net;          /* network # */
-} _ws_netent16;
-
-typedef struct WSAData16
-{
-    WORD                    wVersion;
-    WORD                    wHighVersion;
-    char                    szDescription[WSADESCRIPTION_LEN+1];
-    char                    szSystemStatus[WSASYS_STATUS_LEN+1];
-    WORD                    iMaxSockets;
-    WORD                    iMaxUdpDg;
-    SEGPTR                  lpVendorInfo;
-} WSADATA16, *LPWSADATA16;
-
-#include <poppack.h>
-
-#define WS_FD_CLR16(fd, set)   __WS_FD_CLR((fd),(set), ws_fd_set16)
-#define WS_FD_SET16(fd, set)   __WS_FD_SET1((fd),(set), ws_fd_set16)
-#define WS_FD_ZERO16(set)      (((ws_fd_set16*)(set))->fd_count=0)
-#define WS_FD_ISSET16(fd, set) __WSAFDIsSet16((SOCKET16)(fd), (ws_fd_set16*)(set))
-
-#define INVALID_SOCKET16  ((SOCKET16)(~0))
-
-INT16     WINAPI __WSAFDIsSet16( SOCKET16, ws_fd_set16 * );
-INT16     WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA16 lpWSAData);
-void      WINAPI WSASetLastError16(INT16 iError);
-INT16     WINAPI WSAUnhookBlockingHook16(void);
-FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc);
-HANDLE16  WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 wMsg, LPCSTR name, LPCSTR proto,
-                                         SEGPTR buf, INT16 buflen);
-HANDLE16  WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 wMsg, INT16 port,
-                                         LPCSTR proto, SEGPTR buf, INT16 buflen);
-HANDLE16  WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 wMsg,
-                                          LPCSTR name, SEGPTR buf, INT16 buflen);
-HANDLE16  WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd, UINT16 wMsg,
-                                            INT16 number, SEGPTR buf, INT16 buflen);
-HANDLE16  WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 wMsg,
-                                         LPCSTR name, SEGPTR buf, INT16 buflen);
-HANDLE16  WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 wMsg, LPCSTR addr,
-                              INT16 len, INT16 type, SEGPTR buf, INT16 buflen);
-INT16     WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle);
-INT16     WINAPI WSAAsyncSelect16(SOCKET16 s, HWND16 hWnd, UINT16 wMsg, LONG lEvent);
-INT16     WINAPI WSARecvEx16(SOCKET16 s, char *buf, INT16 len, INT16 *flags);
-
-#endif /* __WINE_WINE_WINSOCK16_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winuser16.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winuser16.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winuser16.h	(revision 25949)
@@ -411,7 +411,4 @@
 #define SBM_GETRANGE16           (WM_USER+3)
 #define SBM_ENABLE_ARROWS16      (WM_USER+4)
-#define SBM_SETRANGEREDRAW16     WM_NULL  /* Not in Win16 */
-#define SBM_SETSCROLLINFO16      WM_NULL  /* Not in Win16 */
-#define SBM_GETSCROLLINFO16      WM_NULL  /* Not in Win16 */
 
   /* CBT hook structures */
@@ -459,7 +456,4 @@
 #define BM_SETSTATE16          (WM_USER+3)
 #define BM_SETSTYLE16          (WM_USER+4)
-#define BM_CLICK16             WM_NULL  /* Does not exist in Win16 */
-#define BM_GETIMAGE16          WM_NULL  /* Does not exist in Win16 */
-#define BM_SETIMAGE16          WM_NULL  /* Does not exist in Win16 */
 
 /* Static Control Messages */
@@ -499,13 +493,4 @@
 #define EM_GETWORDBREAKPROC16      (WM_USER+33)
 #define EM_GETPASSWORDCHAR16       (WM_USER+34)
-/*
-  not in win16:
-    EM_SETMARGINS16            WM_NULL
-    EM_GETMARGINS16            WM_NULL
-    EM_GETLIMITTEXT16          WM_NULL
-    EM_POSFROMCHAR16           WM_NULL
-    EM_CHARFROMPOS16           WM_NULL
-    EM_SETLIMITTEXT16          WM_NULL - no name change in win16
-*/
 
 typedef struct
@@ -971,10 +956,5 @@
 /* undocumented functions */
 
-typedef VOID (*SYSTEMTIMERPROC)(WORD);
-
 void        WINAPI ConvertDialog32To16(LPCVOID,DWORD,LPVOID);
-WORD        WINAPI CreateSystemTimer(WORD,SYSTEMTIMERPROC);
-VOID        WINAPI DisableSystemTimers16(void);
-VOID        WINAPI EnableSystemTimers16(void);
 BOOL16      WINAPI EnumTaskWindows16(HTASK16,WNDENUMPROC16,LPARAM);
 BOOL16      WINAPI GrayString16(HDC16,HBRUSH16,GRAYSTRINGPROC16,LPARAM,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wpp.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wpp.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wpp.h	(revision 25949)
@@ -32,14 +32,41 @@
 
 #include <stdio.h>
+#include <stdarg.h>
 
-extern void wpp_add_define( const char *name, const char *value );
+struct wpp_callbacks
+{
+    /* I/O callbacks */
+
+    /* Looks for a file to include, returning the path where it is found */
+    /* parent_name is the directory of the parent source file (for local
+     * includes), includepath is an array of additional include paths */
+    char *(*lookup)( const char *filename, const char *parent_name,
+                     char **include_path, int include_path_count );
+    /* Opens an include file */
+    /* The type param is true if it is a local ("...") include */
+    void *(*open)( const char *filename, int type );
+    /* Closes a previously opened file */
+    void (*close)( void *file );
+    /* Reads buffer from the input */
+    int (*read)( void *file, char *buffer, unsigned int len );
+    /* Writes buffer to the output */
+    void (*write)( const char *buffer, unsigned int len );
+
+    /* Error callbacks */
+    void (*error)( const char *file, int line, int col, const char *near, const char *msg, va_list ap );
+    void (*warning)( const char *file, int line, int col, const char *near, const char *msg, va_list ap );
+};
+
+/* Return value == 0 means successful execution */
+extern int wpp_add_define( const char *name, const char *value );
 extern void wpp_del_define( const char *name );
-extern void wpp_add_cmdline_define( const char *value );
+extern int wpp_add_cmdline_define( const char *value );
 extern void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug );
 extern void wpp_set_pedantic( int on );
-extern void wpp_add_include_path( const char *path );
+extern int wpp_add_include_path( const char *path );
 extern char *wpp_find_include( const char *name, const char *parent_name );
 extern int wpp_parse( const char *input, FILE *output );
 extern int wpp_parse_temp( const char *input, const char *output_base, char **output_name );
+extern void wpp_set_callbacks( const struct wpp_callbacks *callbacks );
 
 #endif  /* __WINE_WPP_H */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winerror.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winerror.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winerror.h	(revision 25949)
@@ -676,4 +676,7 @@
 #define ERROR_LOG_FILE_FULL                                1502
 #define ERROR_EVENTLOG_FILE_CHANGED                        1503
+#define ERROR_INVALID_TASK_NAME                            1550
+#define ERROR_INVALID_TASK_INDEX                           1551
+#define ERROR_THREAD_ALREADY_IN_TASK                       1552
 #define ERROR_INSTALL_SERVICE_FAILURE                      1601
 #define ERROR_INSTALL_USEREXIT                             1602
@@ -1568,4 +1571,14 @@
 #define ERROR_SXS_THREAD_QUERIES_DISABLED                  14010
 #define ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET              14011
+#define ERROR_SXS_CORRUPTION                               14083
+#define ERROR_MUI_FILE_NOT_FOUND                           15100
+#define ERROR_MUI_INVALID_FILE                             15101
+#define ERROR_MUI_INVALID_RC_CONFIG                        15102
+#define ERROR_MUI_INVALID_LOCALE_NAME                      15103
+#define ERROR_MUI_INVALID_ULTIMATEFALLBACK_NAME            15104
+#define ERROR_MUI_FILE_NOT_LOADED                          15105
+#define ERROR_RESOURCE_ENUM_USER_STOP                      15106
+#define ERROR_MUI_INTLSETTINGS_UILANG_NOT_INSTALLED        15107
+#define ERROR_MUI_INTLSETTINGS_INVALID_LOCALE_NAME         15108
 
 /* HRESULT values for OLE, SHELL and other Interface stuff */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winnls.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winnls.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winnls.h	(revision 25949)
@@ -161,7 +161,8 @@
 
 /* Locale flags */
-#define	LOCALE_NOUSEROVERRIDE	    0x80000000
-#define	LOCALE_USE_CP_ACP	    0x40000000
-#define	LOCALE_RETURN_NUMBER	    0x20000000
+#define LOCALE_NOUSEROVERRIDE         0x80000000
+#define LOCALE_USE_CP_ACP             0x40000000
+#define LOCALE_RETURN_NUMBER          0x20000000
+#define LOCALE_RETURN_GENITIVE_NAMES  0x10000000
 
 /* Locale information types */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winnt.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winnt.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winnt.h	(revision 25949)
@@ -306,5 +306,5 @@
 
 /* Eliminate Microsoft C/C++ compiler warning 4715 */
-#if (_MSC_VER > 1200)
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
 # define DEFAULT_UNREACHABLE default: __assume(0)
 #else
@@ -318,4 +318,19 @@
 #define ERROR_SEVERITY_WARNING       0x80000000
 #define ERROR_SEVERITY_ERROR         0xC0000000
+
+#ifdef __cplusplus
+#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
+extern "C++" { \
+    inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a)|((int)b)); } \
+    inline ENUMTYPE operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \
+    inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a)&((int)b)); } \
+    inline ENUMTYPE operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \
+    inline ENUMTYPE operator ~ (ENUMTYPE a) { return (ENUMTYPE)(~((int)a)); } \
+    inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a)^((int)b)); } \
+    inline ENUMTYPE operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \
+}
+#else
+#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */
+#endif
 
 /* Microsoft's macros for declaring functions */
@@ -612,4 +627,6 @@
 #define MAXDWORD      0xffffffff
 
+#define UNICODE_STRING_MAX_CHARS 32767
+
 #define FIELD_OFFSET(type, field) \
   ((LONG)(INT_PTR)&(((type *)0)->field))
@@ -859,7 +876,4 @@
         } Bits;
     } HighWord;
-#ifdef _WIN64  /* FIXME: 64-bit code should not be using the LDT */
-    DWORD BaseHigh;
-#endif
 } LDT_ENTRY, *PLDT_ENTRY;
 
@@ -999,5 +1013,165 @@
 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
 
+#define UNWIND_HISTORY_TABLE_SIZE 12
+
+typedef struct _UNWIND_HISTORY_TABLE_ENTRY
+{
+    ULONG64 ImageBase;
+    PRUNTIME_FUNCTION FunctionEntry;
+} UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
+
+#define UNWIND_HISTORY_TABLE_NONE 0
+#define UNWIND_HISTORY_TABLE_GLOBAL 1
+#define UNWIND_HISTORY_TABLE_LOCAL 2
+
+typedef struct _UNWIND_HISTORY_TABLE
+{
+    ULONG Count;
+    UCHAR Search;
+    ULONG64 LowAddress;
+    ULONG64 HighAddress;
+    UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
+} UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
+
+typedef struct _KNONVOLATILE_CONTEXT_POINTERS
+{
+    union
+    {
+        PM128A FloatingContext[16];
+        struct
+        {
+            PM128A Xmm0;
+            PM128A Xmm1;
+            PM128A Xmm2;
+            PM128A Xmm3;
+            PM128A Xmm4;
+            PM128A Xmm5;
+            PM128A Xmm6;
+            PM128A Xmm7;
+            PM128A Xmm8;
+            PM128A Xmm9;
+            PM128A Xmm10;
+            PM128A Xmm11;
+            PM128A Xmm12;
+            PM128A Xmm13;
+            PM128A Xmm14;
+            PM128A Xmm15;
+        } DUMMYSTRUCTNAME;
+    } DUMMYUNIONNAME1;
+
+    union
+    {
+        PULONG64 IntegerContext[16];
+        struct
+        {
+            PULONG64 Rax;
+            PULONG64 Rcx;
+            PULONG64 Rdx;
+            PULONG64 Rbx;
+            PULONG64 Rsp;
+            PULONG64 Rbp;
+            PULONG64 Rsi;
+            PULONG64 Rdi;
+            PULONG64 R8;
+            PULONG64 R9;
+            PULONG64 R10;
+            PULONG64 R11;
+            PULONG64 R12;
+            PULONG64 R13;
+            PULONG64 R14;
+            PULONG64 R15;
+        } DUMMYSTRUCTNAME;
+    } DUMMYUNIONNAME2;
+} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
+
+BOOLEAN CDECL            RtlAddFunctionTable(RUNTIME_FUNCTION*,DWORD,DWORD64);
+BOOLEAN CDECL            RtlDeleteFunctionTable(RUNTIME_FUNCTION*);
+PRUNTIME_FUNCTION WINAPI RtlLookupFunctionEntry(DWORD64,DWORD64*,UNWIND_HISTORY_TABLE*);
+PVOID WINAPI             RtlVirtualUnwind(ULONG,ULONG64,ULONG64,RUNTIME_FUNCTION*,CONTEXT*,PVOID*,ULONG64*,KNONVOLATILE_CONTEXT_POINTERS*);
+
+#define UNW_FLAG_NHANDLER  0
+#define UNW_FLAG_EHANDLER  1
+#define UNW_FLAG_UHANDLER  2
+#define UNW_FLAG_CHAININFO 4
+
 #endif /* __x86_64__ */
+
+/* IA64 context definitions */
+#ifdef __ia64__
+
+typedef struct _FRAME_POINTERS {
+  ULONGLONG MemoryStackFp;
+  ULONGLONG BackingStoreFp;
+} FRAME_POINTERS, *PFRAME_POINTERS;
+
+#define UNWIND_HISTORY_TABLE_SIZE 12
+
+typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
+  ULONG64 ImageBase;
+  ULONG64 Gp;
+  PRUNTIME_FUNCTION FunctionEntry;
+} UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
+
+typedef struct _UNWIND_HISTORY_TABLE {
+  ULONG Count;
+  UCHAR Search;
+  ULONG64 LowAddress;
+  ULONG64 HighAddress;
+  UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
+} UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
+
+typedef struct _KNONVOLATILE_CONTEXT_POINTERS
+{
+    PFLOAT128  FltS0;
+    PFLOAT128  FltS1;
+    PFLOAT128  FltS2;
+    PFLOAT128  FltS3;
+    PFLOAT128  HighFloatingContext[10];
+    PFLOAT128  FltS4;
+    PFLOAT128  FltS5;
+    PFLOAT128  FltS6;
+    PFLOAT128  FltS7;
+    PFLOAT128  FltS8;
+    PFLOAT128  FltS9;
+    PFLOAT128  FltS10;
+    PFLOAT128  FltS11;
+    PFLOAT128  FltS12;
+    PFLOAT128  FltS13;
+    PFLOAT128  FltS14;
+    PFLOAT128  FltS15;
+    PFLOAT128  FltS16;
+    PFLOAT128  FltS17;
+    PFLOAT128  FltS18;
+    PFLOAT128  FltS19;
+    PULONGLONG IntS0;
+    PULONGLONG IntS1;
+    PULONGLONG IntS2;
+    PULONGLONG IntS3;
+    PULONGLONG IntSp;
+    PULONGLONG IntS0Nat;
+    PULONGLONG IntS1Nat;
+    PULONGLONG IntS2Nat;
+    PULONGLONG IntS3Nat;
+    PULONGLONG IntSpNat;
+    PULONGLONG Preds;
+    PULONGLONG BrRp;
+    PULONGLONG BrS0;
+    PULONGLONG BrS1;
+    PULONGLONG BrS2;
+    PULONGLONG BrS3;
+    PULONGLONG BrS4;
+    PULONGLONG ApUNAT;
+    PULONGLONG ApLC;
+    PULONGLONG ApEC;
+    PULONGLONG RsPFS;
+    PULONGLONG StFSR;
+    PULONGLONG StFIR;
+    PULONGLONG StFDR;
+    PULONGLONG Cflag;
+} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
+
+ULONGLONG WINAPI RtlVirtualUnwind(ULONGLONG,ULONGLONG,RUNTIME_FUNCTION*,CONTEXT*,BOOLEAN*,FRAME_POINTERS*,KNONVOLATILE_CONTEXT_POINTERS*);
+
+#endif /* __ia64__ */
 
 /* Alpha context definitions */
@@ -1719,4 +1893,49 @@
 
 NTSYSAPI void WINAPI RtlCaptureContext(CONTEXT*);
+
+/*
+ * Product types
+ */
+#define PRODUCT_UNLICENSED                              0xABCDABCD
+#define PRODUCT_BUSINESS                                0x00000006
+#define PRODUCT_BUSINESS_N                              0x00000010
+#define PRODUCT_CLUSTER_SERVER                          0x00000012
+#define PRODUCT_DATACENTER_SERVER                       0x00000008
+#define PRODUCT_DATACENTER_SERVER_CORE                  0x0000000C
+#define PRODUCT_DATACENTER_SERVER_CORE_V                0x00000027
+#define PRODUCT_SERVER_V                                0x00000025
+#define PRODUCT_ENTERPRISE                              0x00000004
+#define PRODUCT_ENTERPRISE_N                            0x0000001B
+#define PRODUCT_ENTERPRISE_SERVER                       0x0000000A
+#define PRODUCT_ENTERPRISE_SERVER_CORE                  0x0000000E
+#define PRODUCT_ENTERPRISE_SERVER_CORE_V                0x00000029
+#define PRODUCT_ENTERPRISE_SERVER_IA64                  0x0000000F
+#define PRODUCT_ENTERPRISE_SERVER_V                     0x00000026
+#define PRODUCT_HOME_BASIC                              0x00000002
+#define PRODUCT_HOME_BASIC_N                            0x00000005
+#define PRODUCT_HOME_PREMIUM                            0x00000003
+#define PRODUCT_HOME_PREMIUM_N                          0x0000001A
+#define PRODUCT_HYPERV                                  0x0000002A
+#define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT        0x0000001E
+#define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING         0x00000020
+#define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY          0x0000001F
+#define PRODUCT_SERVER_FOR_SMALLBUSINESS                0x00000018
+#define PRODUCT_SERVER_FOR_SMALLBUSINESS_V              0x00000023
+#define PRODUCT_SMALLBUSINESS_SERVER                    0x00000009
+#define PRODUCT_STANDARD_SERVER                         0x00000007
+#define PRODUCT_STANDARD_SERVER_CORE                    0x0000000D
+#define PRODUCT_STANDARD_SERVER_CORE_V                  0x00000028
+#define PRODUCT_STANDARD_SERVER_V                       0x00000024
+#define PRODUCT_STARTER                                 0x0000000B
+#define PRODUCT_STORAGE_ENTERPRISE_SERVER               0x00000017
+#define PRODUCT_STORAGE_EXPRESS_SERVER                  0x00000014
+#define PRODUCT_STORAGE_STANDARD_SERVER                 0x00000015
+#define PRODUCT_STORAGE_WORKGROUP_SERVER                0x00000016
+#define PRODUCT_UNDEFINED                               0x00000000
+#define PRODUCT_ULTIMATE                                0x00000001
+#define PRODUCT_ULTIMATE_N                              0x0000001C
+#define PRODUCT_WEB_SERVER                              0x00000011
+#define PRODUCT_WEB_SERVER_CORE                         0x0000001D
+
 
 /*
@@ -4937,4 +5156,28 @@
 #define EVENTLOG_AUDIT_FAILURE          0x0010
 
+#define EVENTLOG_SEQUENTIAL_READ        0x0001
+#define EVENTLOG_SEEK_READ              0x0002
+#define EVENTLOG_FORWARDS_READ          0x0004
+#define EVENTLOG_BACKWARDS_READ         0x0008
+
+typedef struct _EVENTLOGRECORD {
+    DWORD  Length;
+    DWORD  Reserved;
+    DWORD  RecordNumber;
+    DWORD  TimeGenerated;
+    DWORD  TimeWritten;
+    DWORD  EventID;
+    WORD   EventType;
+    WORD   NumStrings;
+    WORD   EventCategory;
+    WORD   ReservedFlags;
+    DWORD  ClosingRecordNumber;
+    DWORD  StringOffset;
+    DWORD  UserSidLength;
+    DWORD  UserSidOffset;
+    DWORD  DataLength;
+    DWORD  DataOffset;
+} EVENTLOGRECORD, *PEVENTLOGRECORD;
+
 #define SERVICE_BOOT_START   0x00000000
 #define SERVICE_SYSTEM_START 0x00000001
@@ -5244,4 +5487,6 @@
 } JOBOBJECTINFOCLASS;
 
+NTSYSAPI BOOLEAN NTAPI RtlGetProductInfo(DWORD,DWORD,DWORD,DWORD,PDWORD);
+
 #ifdef __cplusplus
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h	(revision 25949)
@@ -417,4 +417,18 @@
     FileAttributeTagInformation,
     FileTrackingInformation,
+    FileIdBothDirectoryInformation,
+    FileIdFullDirectoryInformation,
+    FileValidDataLengthInformation,
+    FileShortNameInformation = 40,
+    /* 41, 42, 43 undocumented */
+    FileSfioReserveInformation = 44,
+    FileSfioVolumeInformation = 45,
+    FileHardLinkInformation = 46,
+    /* 47 undocumented */
+    FileNormalizedNameInformation = 48,
+    /* 49 undocumented */
+    FileIdGlobalTxDirectoryInformation = 50,
+    /* 51, 52, 53 undocumented */
+    FileStandardLinkInformation = 54,
     FileMaximumInformation
 } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
@@ -449,4 +463,20 @@
 } FILE_FULL_DIRECTORY_INFORMATION, *PFILE_FULL_DIRECTORY_INFORMATION,
   FILE_FULL_DIR_INFORMATION, *PFILE_FULL_DIR_INFORMATION;
+
+typedef struct _FILE_ID_FULL_DIRECTORY_INFORMATION {
+    ULONG               NextEntryOffset;
+    ULONG               FileIndex;
+    LARGE_INTEGER       CreationTime;
+    LARGE_INTEGER       LastAccessTime;
+    LARGE_INTEGER       LastWriteTime;
+    LARGE_INTEGER       ChangeTime;
+    LARGE_INTEGER       EndOfFile;
+    LARGE_INTEGER       AllocationSize;
+    ULONG               FileAttributes;
+    ULONG               FileNameLength;
+    ULONG               EaSize;
+    LARGE_INTEGER       FileId;
+    WCHAR               FileName[ANYSIZE_ARRAY];
+} FILE_ID_FULL_DIRECTORY_INFORMATION, *PFILE_ID_FULL_DIRECTORY_INFORMATION;
 
 typedef struct _FILE_BOTH_DIRECTORY_INFORMATION {
@@ -468,4 +498,22 @@
   FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION;
 
+typedef struct _FILE_ID_BOTH_DIRECTORY_INFORMATION {
+    ULONG               NextEntryOffset;
+    ULONG               FileIndex;
+    LARGE_INTEGER       CreationTime;
+    LARGE_INTEGER       LastAccessTime;
+    LARGE_INTEGER       LastWriteTime;
+    LARGE_INTEGER       ChangeTime;
+    LARGE_INTEGER       EndOfFile;
+    LARGE_INTEGER       AllocationSize;
+    ULONG               FileAttributes;
+    ULONG               FileNameLength;
+    ULONG               EaSize;
+    CHAR                ShortNameLength;
+    WCHAR               ShortName[12];
+    LARGE_INTEGER       FileId;
+    WCHAR               FileName[ANYSIZE_ARRAY];
+} FILE_ID_BOTH_DIRECTORY_INFORMATION, *PFILE_ID_BOTH_DIRECTORY_INFORMATION;
+
 typedef struct _FILE_BASIC_INFORMATION {
     LARGE_INTEGER CreationTime;
@@ -624,5 +672,6 @@
     KeyBasicInformation,
     KeyNodeInformation,
-    KeyFullInformation
+    KeyFullInformation,
+    KeyNameInformation
 } KEY_INFORMATION_CLASS;
 
@@ -770,4 +819,5 @@
     ThreadSetTlsArrayAddress,
     ThreadIsIoPending,
+    ThreadHideFromDebugger,
     MaxThreadInfoClass
 } THREADINFOCLASS;
@@ -842,172 +892,4 @@
     UNC_DOT_PATH           /* "//." */
 } DOS_PATHNAME_TYPE;
-
-/***********************************************************************
- * IA64 specific types and data structures
- */
-
-#ifdef __ia64__
-
-typedef struct _FRAME_POINTERS {
-  ULONGLONG MemoryStackFp;
-  ULONGLONG BackingStoreFp;
-} FRAME_POINTERS, *PFRAME_POINTERS;
-
-#define UNWIND_HISTORY_TABLE_SIZE 12
-
-typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
-  ULONG64 ImageBase;
-  ULONG64 Gp;
-  PRUNTIME_FUNCTION FunctionEntry;
-} UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
-
-typedef struct _UNWIND_HISTORY_TABLE {
-  ULONG Count;
-  UCHAR Search;
-  ULONG64 LowAddress;
-  ULONG64 HighAddress;
-  UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
-} UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
-
-typedef struct _KNONVOLATILE_CONTEXT_POINTERS
-{
-    PFLOAT128  FltS0;
-    PFLOAT128  FltS1;
-    PFLOAT128  FltS2;
-    PFLOAT128  FltS3;
-    PFLOAT128  HighFloatingContext[10];
-    PFLOAT128  FltS4;
-    PFLOAT128  FltS5;
-    PFLOAT128  FltS6;
-    PFLOAT128  FltS7;
-    PFLOAT128  FltS8;
-    PFLOAT128  FltS9;
-    PFLOAT128  FltS10;
-    PFLOAT128  FltS11;
-    PFLOAT128  FltS12;
-    PFLOAT128  FltS13;
-    PFLOAT128  FltS14;
-    PFLOAT128  FltS15;
-    PFLOAT128  FltS16;
-    PFLOAT128  FltS17;
-    PFLOAT128  FltS18;
-    PFLOAT128  FltS19;
-    PULONGLONG IntS0;
-    PULONGLONG IntS1;
-    PULONGLONG IntS2;
-    PULONGLONG IntS3;
-    PULONGLONG IntSp;
-    PULONGLONG IntS0Nat;
-    PULONGLONG IntS1Nat;
-    PULONGLONG IntS2Nat;
-    PULONGLONG IntS3Nat;
-    PULONGLONG IntSpNat;
-    PULONGLONG Preds;
-    PULONGLONG BrRp;
-    PULONGLONG BrS0;
-    PULONGLONG BrS1;
-    PULONGLONG BrS2;
-    PULONGLONG BrS3;
-    PULONGLONG BrS4;
-    PULONGLONG ApUNAT;
-    PULONGLONG ApLC;
-    PULONGLONG ApEC;
-    PULONGLONG RsPFS;
-    PULONGLONG StFSR;
-    PULONGLONG StFIR;
-    PULONGLONG StFDR;
-    PULONGLONG Cflag;
-} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
-
-ULONGLONG WINAPI RtlVirtualUnwind(ULONGLONG,ULONGLONG,RUNTIME_FUNCTION*,CONTEXT*,BOOLEAN*,FRAME_POINTERS*,KNONVOLATILE_CONTEXT_POINTERS*);
-
-#endif /* defined(__ia64__) */
-
-/***********************************************************************
- * x86-64 specific types and data structures
- */
-
-#ifdef __x86_64__
-
-#define UNWIND_HISTORY_TABLE_SIZE 12
-
-typedef struct _UNWIND_HISTORY_TABLE_ENTRY
-{
-    ULONG64 ImageBase;
-    PRUNTIME_FUNCTION FunctionEntry;
-} UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
-
-#define UNWIND_HISTORY_TABLE_NONE 0
-#define UNWIND_HISTORY_TABLE_GLOBAL 1
-#define UNWIND_HISTORY_TABLE_LOCAL 2
-
-typedef struct _UNWIND_HISTORY_TABLE
-{
-    ULONG Count;
-    UCHAR Search;
-    ULONG64 LowAddress;
-    ULONG64 HighAddress;
-    UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
-} UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
-
-typedef struct _KNONVOLATILE_CONTEXT_POINTERS
-{
-    union
-    {
-        PM128A FloatingContext[16];
-        struct
-        {
-            PM128A Xmm0;
-            PM128A Xmm1;
-            PM128A Xmm2;
-            PM128A Xmm3;
-            PM128A Xmm4;
-            PM128A Xmm5;
-            PM128A Xmm6;
-            PM128A Xmm7;
-            PM128A Xmm8;
-            PM128A Xmm9;
-            PM128A Xmm10;
-            PM128A Xmm11;
-            PM128A Xmm12;
-            PM128A Xmm13;
-            PM128A Xmm14;
-            PM128A Xmm15;
-        } DUMMYSTRUCTNAME;
-    } DUMMYUNIONNAME1;
-
-    union
-    {
-        PULONG64 IntegerContext[16];
-        struct
-        {
-            PULONG64 Rax;
-            PULONG64 Rcx;
-            PULONG64 Rdx;
-            PULONG64 Rbx;
-            PULONG64 Rsp;
-            PULONG64 Rbp;
-            PULONG64 Rsi;
-            PULONG64 Rdi;
-            PULONG64 R8;
-            PULONG64 R9;
-            PULONG64 R10;
-            PULONG64 R11;
-            PULONG64 R12;
-            PULONG64 R13;
-            PULONG64 R14;
-            PULONG64 R15;
-        } DUMMYSTRUCTNAME;
-    } DUMMYUNIONNAME2;
-} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
-
-PVOID WINAPI RtlVirtualUnwind(ULONG,ULONG64,ULONG64,RUNTIME_FUNCTION*,CONTEXT*,PVOID*,ULONG64*,KNONVOLATILE_CONTEXT_POINTERS*);
-
-#define UNW_FLAG_NHANDLER  0
-#define UNW_FLAG_EHANDLER  1
-#define UNW_FLAG_UHANDLER  2
-#define UNW_FLAG_CHAININFO 4
-
-#endif  /* __x86_64 */
 
 
@@ -1076,4 +958,9 @@
     WCHAR         Class[1];
 } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
+
+typedef struct _KEY_NAME_INFORMATION {
+    ULONG         NameLength;
+    WCHAR         Name[1];
+} KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
 
 typedef struct _KEY_VALUE_ENTRY
@@ -1625,7 +1512,5 @@
 #define FILE_PIPE_CLIENT_END            0x00000000
 
-#if (_WIN32_WINNT >= 0x0501)
 #define INTERNAL_TS_ACTIVE_CONSOLE_ID ( *((volatile ULONG*)(0x7ffe02d8)) )
-#endif /* (_WIN32_WINNT >= 0x0501) */
 
 #define LOGONID_CURRENT    ((ULONG)-1)
@@ -1689,4 +1574,8 @@
 #define SE_MAX_WELL_KNOWN_PRIVILEGE      SE_CREATE_GLOBAL_PRIVILEGE
 
+/* NtGlobalFlag bits */
+#define FLG_HEAP_ENABLE_TAIL_CHECK       0x00000010
+#define FLG_HEAP_ENABLE_FREE_CHECK       0x00000020
+#define FLG_HEAP_DISABLE_COALESCING      0x00200000
 
 /* Rtl*Registry* functions structs and defines */
@@ -1737,5 +1626,5 @@
 typedef VOID (CALLBACK *PRTL_OVERLAPPED_COMPLETION_ROUTINE)(DWORD,DWORD,LPVOID);
 
-typedef VOID (*PTIMER_APC_ROUTINE) ( PVOID, ULONG, LONG );
+typedef VOID (CALLBACK *PTIMER_APC_ROUTINE) ( PVOID, ULONG, LONG );
 
 typedef enum _EVENT_TYPE {
@@ -2361,4 +2250,5 @@
 NTSYSAPI DWORD     WINAPI RtlGetLastWin32Error(void);
 NTSYSAPI DWORD     WINAPI RtlGetLongestNtPathLength(void);
+NTSYSAPI ULONG     WINAPI RtlGetNtGlobalFlags(void);
 NTSYSAPI BOOLEAN   WINAPI RtlGetNtProductType(LPDWORD);
 NTSYSAPI NTSTATUS  WINAPI RtlGetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR,PSID *,PBOOLEAN);
@@ -2421,4 +2311,5 @@
 NTSYSAPI NTSTATUS  WINAPI RtlQueryAtomInAtomTable(RTL_ATOM_TABLE,RTL_ATOM,ULONG*,ULONG*,WCHAR*,ULONG*);
 NTSYSAPI NTSTATUS  WINAPI RtlQueryEnvironmentVariable_U(PWSTR,PUNICODE_STRING,PUNICODE_STRING);
+NTSYSAPI NTSTATUS  WINAPI RtlQueryHeapInformation(HANDLE,HEAP_INFORMATION_CLASS,PVOID,SIZE_T,PSIZE_T);
 NTSYSAPI NTSTATUS  WINAPI RtlQueryInformationAcl(PACL,LPVOID,DWORD,ACL_INFORMATION_CLASS);
 NTSYSAPI NTSTATUS  WINAPI RtlQueryInformationActivationContext(ULONG,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.h	(revision 25949)
@@ -1502,4 +1502,7 @@
 #define ENUM_CURRENT_SETTINGS  ((DWORD) -1)
 #define ENUM_REGISTRY_SETTINGS ((DWORD) -2)
+
+/* Used for PrintWindow */
+#define PW_CLIENTONLY   0x00000001
 
 /****** Window classes ******/
@@ -3056,4 +3059,12 @@
 #define SPI_GETUIEFFECTS               0x103E
 #define SPI_SETUIEFFECTS               0x103F
+#define SPI_GETDISABLEOVERLAPPEDCONTENT 0x1040
+#define SPI_SETDISABLEOVERLAPPEDCONTENT 0x1041
+#define SPI_GETCLIENTAREAANIMATION     0x1042
+#define SPI_SETCLIENTAREAANIMATION     0x1043
+#define SPI_GETCLEARTYPE               0x1048
+#define SPI_SETCLEARTYPE               0x1049
+#define SPI_GETSPEECHRECOGNITION       0x104A
+#define SPI_SETSPEECHRECOGNITION       0x104B
 #define SPI_GETFOREGROUNDLOCKTIMEOUT   0x2000
 #define SPI_SETFOREGROUNDLOCKTIMEOUT   0x2001
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.rh
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.rh	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.rh	(revision 25949)
@@ -15,13 +15,4 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
  */
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wmistr.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wmistr.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wmistr.h	(revision 25949)
@@ -43,3 +43,27 @@
 } WMIDPREQUESTCODE;
 
+typedef struct _WNODE_HEADER
+{
+    ULONG BufferSize;
+    ULONG ProvicerId;
+    union
+    {
+        ULONG64 HistoricalContext;
+        struct
+        {
+            ULONG Version;
+            ULONG Linkage;
+        } DUMMYSTRUCTNAME;
+
+    } DUMMYUNIONNAME;
+    union
+    {
+        HANDLE KernelHandle;
+        LARGE_INTEGER TimeStamp;
+    } DUMMYUNIONNAME2;
+    GUID Guid;
+    ULONG ClientContext;
+    ULONG Flags;
+} WNODE_HEADER, *PWNODE_HEADER;
+
 #endif /* _WMISTR_ */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wnaspi32.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wnaspi32.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wnaspi32.h	(revision 25949)
@@ -160,5 +160,5 @@
   BYTE        SRB_HaStat;         /* 16 Host Adapter Status */
   BYTE        SRB_TargStat;       /* 17 Target Status */
-  void        (*SRB_PostProc)();  /* 18 Post routine */
+  void        (*SRB_PostProc)( struct tagSRB32_ExecSCSICmd * ); /* 18 Post routine */
   void        *SRB_Rsvd2;         /* 1C Reserved */
   BYTE        SRB_Rsvd3[16];      /* 20 Reserved for expansion */
@@ -189,5 +189,5 @@
  BYTE         SRB_HaStat;               /* 16 Host Adapter Status */
  BYTE         SRB_TargStat;             /* 17 Target Status */
- void         (*SRB_PostProc)();        /* 18 Post routine */
+ void         (*SRB_PostProc)( struct tagSRB32_BusDeviceReset * ); /* 18 Post routine */
  void         *SRB_Rsvd2;               /* 1c Reserved */
  BYTE         SRB_Rsvd3[32];            /* 20 Reserved */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ws2def.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ws2def.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ws2def.h	(revision 25949)
@@ -68,5 +68,5 @@
         short ss_family;
         char __ss_pad1[WS(_SS_PAD1SIZE)];
-        __int64 __ss_align;
+        __int64 DECLSPEC_ALIGN(8) __ss_align;
         char __ss_pad2[WS(_SS_PAD2SIZE)];
 } SOCKADDR_STORAGE, *PSOCKADDR_STORAGE, *LPSOCKADDR_STORAGE;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h	(revision 25949)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.30 from ../../include/wtypes.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.36 from ../../include/wtypes.idl - Do not edit ***/
 
 #include <rpc.h>
@@ -74,7 +74,7 @@
 typedef DWORD LCID;
 typedef USHORT LANGID;
-typedef unsigned __int64 DWORDLONG;
-typedef __int64 LONGLONG;
-typedef unsigned __int64 ULONGLONG;
+typedef UINT64 DWORDLONG;
+typedef INT64 LONGLONG;
+typedef UINT64 ULONGLONG;
 typedef struct _LARGE_INTEGER {
     LONGLONG QuadPart;
@@ -396,5 +396,5 @@
         LONG hInproc;
         FLAGGED_BYTE_BLOB *hRemote;
-        __int64 hInproc64;
+        INT64 hInproc64;
     } u;
 } userHGLOBAL;
@@ -412,5 +412,5 @@
         LONG hInproc;
         BYTE_BLOB *hRemote;
-        __int64 hInproc64;
+        INT64 hInproc64;
     } u;
 } userHMETAFILE;
@@ -427,5 +427,5 @@
         LONG hInproc;
         remoteMETAFILEPICT *hRemote;
-        __int64 hInproc64;
+        INT64 hInproc64;
     } u;
 } userHMETAFILEPICT;
@@ -440,5 +440,5 @@
         LONG hInproc;
         BYTE_BLOB *hRemote;
-        __int64 hInproc64;
+        INT64 hInproc64;
     } u;
 } userHENHMETAFILE;
@@ -463,5 +463,5 @@
         LONG hInproc;
         userBITMAP *hRemote;
-        __int64 hInproc64;
+        INT64 hInproc64;
     } u;
 } userHBITMAP;
@@ -481,5 +481,5 @@
         LONG hInproc;
         rpcLOGPALETTE *hRemote;
-        __int64 hInproc64;
+        INT64 hInproc64;
     } u;
 } userHPALETTE;
@@ -746,4 +746,11 @@
     } tagged_union;
 } uCLSSPEC;
+#ifndef PROPERTYKEY_DEFINED
+#define PROPERTYKEY_DEFINED
+typedef struct _tagpropertykey {
+    GUID fmtid;
+    DWORD pid;
+} PROPERTYKEY;
+#endif /*PROPERTYKEY_DEFINED*/
 
 #endif  /* __IWinTypes_INTERFACE_DEFINED__ */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.idl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.idl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.idl	(revision 25949)
@@ -837,3 +837,12 @@
 } uCLSSPEC;
 
+cpp_quote("#ifndef PROPERTYKEY_DEFINED")
+cpp_quote("#define PROPERTYKEY_DEFINED")
+typedef struct _tagpropertykey
+{
+    GUID fmtid;
+    DWORD pid;
+} PROPERTYKEY;
+cpp_quote("#endif /*PROPERTYKEY_DEFINED*/")
+
 } /* interface IWinTypes */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/cpmap.pl
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/cpmap.pl	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/cpmap.pl	(revision 25949)
@@ -18,13 +18,4 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-#
-
-#
-# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
-# other than GPL or LGPL is available it will apply instead, Sun elects to use only
-# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
-# a choice of LGPL license versions is made available with the language indicating
-# that LGPLv2 or any later version may be used, or where a choice of which version
-# of the LGPL is applied is otherwise unspecified.
 #
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/defaults
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/defaults	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/defaults	(revision 25949)
@@ -34,22 +34,4 @@
 # are handled automatically and do not have to be defined here. They can
 # still be defined if necessary to override the unicode decomposition.
-#
-
-#
-# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
-# other than GPL or LGPL is available it will apply instead, Sun elects to use only
-# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
-# a choice of LGPL license versions is made available with the language indicating
-# that LGPLv2 or any later version may be used, or where a choice of which version
-# of the LGPL is applied is otherwise unspecified.
-#
-
-#
-# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
-# other than GPL or LGPL is available it will apply instead, Sun elects to use only
-# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
-# a choice of LGPL license versions is made available with the language indicating
-# that LGPLv2 or any later version may be used, or where a choice of which version
-# of the LGPL is applied is otherwise unspecified.
 #
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/ldt.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/ldt.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/ldt.c	(revision 25949)
@@ -41,10 +41,9 @@
 #include "windef.h"
 #include "winbase.h"
-#define WINE_EXPORT_LDT_COPY
 #include "wine/library.h"
 
-#ifdef __i386__
-
-#ifdef linux
+#if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
+
+#ifdef __linux__
 
 #ifdef HAVE_SYS_SYSCALL_H
@@ -129,6 +128,4 @@
 #endif
 
-#endif  /* __i386__ */
-
 /* local copy of the LDT */
 #ifdef __APPLE__
@@ -200,6 +197,4 @@
 
     if (index < LDT_FIRST_ENTRY) return 0;  /* cannot modify reserved entries */
-
-#ifdef __i386__
 
 #ifdef linux
@@ -245,6 +240,4 @@
 #endif
 
-#endif  /* __i386__ */
-
     if (ret >= 0)
     {
@@ -395,6 +388,4 @@
 
 
-#if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
-
 static int global_fs_sel = -1;  /* global selector for %fs shared among all threads */
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/mmap.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/mmap.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/mmap.c	(revision 25949)
@@ -359,4 +359,10 @@
 
     reserve_malloc_space( 8 * 1024 * 1024 );
+
+    if (!list_head( &reserved_areas ))
+    {
+        /* if we don't have a preloader, try to reserve some space below 2Gb */
+        reserve_area( (void *)0x00110000, (void *)0x40000000 );
+    }
 
     /* check for a reserved area starting at the user space limit */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/port.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/port.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/port.c	(revision 25949)
@@ -181,4 +181,18 @@
                    "mtlr 0\n\t"         /* return address -> lr */
                    "blr")               /* return */
+#elif defined(__arm__)
+__ASM_GLOBAL_FUNC( wine_call_on_stack,
+                   "str r14, [r13, #4]\n\t"     /* save return address on stack */
+                   "sub r2, r2, #16\n\t"        /* reserve space on new stack */
+                   "str r13, [r2, #12]\n\t"     /* store old sp */
+                   "mov r3, r0\n\t"             /* func */
+                   "mov r0, r1\n\t"             /* arg */
+                   "mov r13, r2\n\t"            /* stack */
+                   "mov r2, #0\n\t"             /* zero */
+                   "str r2, [r13]\n\t"          /* bottom of stack */
+                   "sub r13, r13, #16\n\t"      /* create a frame for this function */
+                   "blx r3\n\t"                 /* call func */
+                   "ldr r13, [r13, #28]\n\t"    /* fetch old sp */
+                   "ldr r15, [r13, #4]")        /* fetch return address and return */
 #else
 #error You must implement wine_switch_to_stack for your platform
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/string.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/string.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/string.c	(revision 25949)
@@ -419,4 +419,5 @@
                     while (*buffiter)
                         *fmta++ = *buffiter++;
+                    iter++;
                 }
                 else
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c	(revision 25949)
@@ -1,1 +1,1 @@
-const char wine_build[] = "wine-1.1.30";
+const char wine_build[] = "wine-1.1.36";
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/wine.def
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/wine.def	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/wine.def	(revision 25949)
@@ -87,13 +87,4 @@
     wine_init_argv0_path
     wine_is_dbcs_leadbyte
-    wine_ldt_alloc_entries
-    wine_ldt_copy
-    wine_ldt_free_entries
-    wine_ldt_get_entry
-    wine_ldt_get_ptr
-    wine_ldt_init_locking
-    wine_ldt_is_system
-    wine_ldt_realloc_entries
-    wine_ldt_set_entry
     wine_pthread_get_functions
     wine_pthread_set_functions
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c	(revision 25949)
@@ -56,5 +56,5 @@
     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *) shader;
     if(!This->baseShader.reg_maps.usesmova) return FALSE;
-    return !GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION);
+    return !gl_info->supported[NV_VERTEX_PROGRAM2_OPTION];
 }
 
@@ -62,13 +62,14 @@
 static inline BOOL use_nv_clip(const struct wined3d_gl_info *gl_info)
 {
-    return GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION);
+    return gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]
+            && !(gl_info->quirks & WINED3D_QUIRK_NV_CLIP_BROKEN);
 }
 
 static BOOL need_helper_const(const struct wined3d_gl_info *gl_info)
 {
-    if (!GL_SUPPORT(NV_VERTEX_PROGRAM) /* Need to init colors. */
-        || gl_info->quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT /* Load the immval offset. */
-        || gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W /* Have to init texcoords. */
-        || (!use_nv_clip(gl_info)) /* Init the clip texcoord */)
+    if (!gl_info->supported[NV_VERTEX_PROGRAM] /* Need to init colors. */
+            || gl_info->quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT /* Load the immval offset. */
+            || gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W /* Have to init texcoords. */
+            || (!use_nv_clip(gl_info)) /* Init the clip texcoord */)
     {
         return TRUE;
@@ -92,10 +93,4 @@
     return stateblock->lowest_disabled_stage < 7;
 }
-
-/* Internally used shader constants. Applications can use constants 0 to GL_LIMITS(vshader_constantsF) - 1,
- * so upload them above that
- */
-#define ARB_SHADER_PRIVCONST_BASE (GL_LIMITS(vshader_constantsF) - 1)
-#define ARB_SHADER_PRIVCONST_POS ARB_SHADER_PRIVCONST_BASE + 0
 
 /* ARB_program_shader private data */
@@ -115,7 +110,7 @@
     union
     {
-        unsigned int                loop_no;
-        unsigned int                ifc_no;
-    };
+        unsigned int                loop;
+        unsigned int                ifc;
+    } no;
     struct wined3d_shader_loop_control loop_control;
     BOOL                            had_else;
@@ -167,14 +162,15 @@
         {
             WORD                    bools;
-            char                    clip_control[2];
+            char                    clip_texcoord;
+            char                    clipplane_mask;
         }                           boolclip;
         DWORD                       boolclip_compare;
-    };
+    } clip;
     DWORD                           ps_signature;
     union
     {
-        unsigned char               vertex_samplers[4];
-        DWORD                       vertex_samplers_compare;
-    };
+        unsigned char               samplers[4];
+        DWORD                       samplers_compare;
+    } vertex;
     unsigned char                   loop_ctrl[MAX_CONST_I][3];
 };
@@ -342,5 +338,6 @@
     }
 
-    if(GL_SUPPORT(EXT_GPU_PROGRAM_PARAMETERS)) {
+    if (gl_info->supported[EXT_GPU_PROGRAM_PARAMETERS])
+    {
         /* TODO: Benchmark if we're better of with finding the dirty constants ourselves,
          * or just reloading *all* constants at once
@@ -550,5 +547,5 @@
 static void shader_arb_load_constants(const struct wined3d_context *context, char usePixelShader, char useVertexShader)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     IWineD3DStateBlockImpl* stateBlock = device->stateBlock;
     const struct wined3d_gl_info *gl_info = context->gl_info;
@@ -580,5 +577,5 @@
     /* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active
      * context. On a context switch the old context will be fully dirtified */
-    if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice != This) return;
+    if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.device != This) return;
 
     memset(context->vshader_const_dirty + start, 1, sizeof(*context->vshader_const_dirty) * count);
@@ -593,5 +590,5 @@
     /* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active
      * context. On a context switch the old context will be fully dirtified */
-    if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice != This) return;
+    if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.device != This) return;
 
     memset(context->pshader_const_dirty + start, 1, sizeof(*context->pshader_const_dirty) * count);
@@ -641,10 +638,13 @@
      * and don't know which are actually used.
      */
-    if(pshader) {
-        max_constantsF = GL_LIMITS(pshader_constantsF);
-    } else {
+    if (pshader)
+    {
+        max_constantsF = gl_info->limits.arb_ps_native_constants;
+    }
+    else
+    {
         if(This->baseShader.reg_maps.usesrelconstF) {
             DWORD highest_constf = 0, clip_limit;
-            max_constantsF = GL_LIMITS(vshader_constantsF) - reserved_vs_const(iface, gl_info);
+            max_constantsF = gl_info->limits.arb_vs_native_constants - reserved_vs_const(iface, gl_info);
             max_constantsF -= count_bits(This->baseShader.reg_maps.integer_constants);
 
@@ -656,18 +656,28 @@
             }
 
-            clip_limit = GL_LIMITS(clipplanes);
-            if(ctx->target_version == ARB) clip_limit = min(clip_limit, 4);
+            if(use_nv_clip(gl_info) && ctx->target_version >= NV2)
+            {
+                if(ctx->cur_vs_args->super.clip_enabled)
+                    clip_limit = gl_info->limits.clipplanes;
+                else
+                    clip_limit = 0;
+            }
+            else
+            {
+                unsigned int mask = ctx->cur_vs_args->clip.boolclip.clipplane_mask;
+                clip_limit = min(count_bits(mask), 4);
+            }
             *num_clipplanes = min(clip_limit, max_constantsF - highest_constf - 1);
             max_constantsF -= *num_clipplanes;
             if(*num_clipplanes < clip_limit)
             {
-                WARN("Only %u clipplanes out of %u enabled\n", *num_clipplanes, GL_LIMITS(clipplanes));
+                WARN("Only %u clipplanes out of %u enabled\n", *num_clipplanes, gl_info->limits.clipplanes);
             }
         }
         else
         {
-            if(ctx->target_version >= NV2) *num_clipplanes = GL_LIMITS(clipplanes);
-            else *num_clipplanes = min(GL_LIMITS(clipplanes), 4);
-            max_constantsF = GL_LIMITS(vshader_constantsF);
+            if (ctx->target_version >= NV2) *num_clipplanes = gl_info->limits.clipplanes;
+            else *num_clipplanes = min(gl_info->limits.clipplanes, 4);
+            max_constantsF = gl_info->limits.arb_vs_native_constants;
         }
     }
@@ -701,4 +711,19 @@
         }
     }
+
+    /* After subtracting privately used constants from the hardware limit(they are loaded as
+     * local constants), make sure the shader doesn't violate the env constant limit
+     */
+    if(pshader)
+    {
+        max_constantsF = min(max_constantsF, gl_info->limits.arb_ps_float_constants);
+    }
+    else
+    {
+        max_constantsF = min(max_constantsF, gl_info->limits.arb_vs_float_constants);
+    }
+
+    /* Avoid declaring more constants than needed */
+    max_constantsF = min(max_constantsF, This->baseShader.limits.constant_float);
 
     /* we use the array-based constants array if the local constants are marked for loading,
@@ -1256,5 +1281,5 @@
     if(sampler_idx >= MAX_FRAGMENT_SAMPLERS)
     {
-        sampler_idx = priv->cur_vs_args->vertex_samplers[sampler_idx - MAX_FRAGMENT_SAMPLERS];
+        sampler_idx = priv->cur_vs_args->vertex.samplers[sampler_idx - MAX_FRAGMENT_SAMPLERS];
     }
 
@@ -1587,5 +1612,4 @@
         case WINED3DSIH_SUB: instruction = "SUB"; break;
         case WINED3DSIH_MOVA:instruction = "ARR"; break;
-        case WINED3DSIH_SGN: instruction = "SSG"; break;
         case WINED3DSIH_DSX: instruction = "DDX"; break;
         default: instruction = "";
@@ -2464,11 +2488,12 @@
     struct shader_arb_ctx_priv *ctx = ins->ctx->backend_data;
 
-    /* SGN is only valid in vertex shaders */
-    if(ctx->target_version == NV2) {
-        shader_hw_map2gl(ins);
-        return;
-    }
     shader_arb_get_dst_param(ins, &ins->dst[0], dst_name);
     shader_arb_get_src_param(ins, &ins->src[0], 0, src_name);
+
+    /* SGN is only valid in vertex shaders */
+    if(ctx->target_version >= NV2) {
+        shader_addline(buffer, "SSG%s %s, %s;\n", shader_arb_get_modifier(ins), dst_name, src_name);
+        return;
+    }
 
     /* If SRC > 0.0, -SRC < SRC = TRUE, otherwise false.
@@ -2605,6 +2630,6 @@
         /* The constant loader makes sure to load -1 into iX.w */
         shader_addline(buffer, "ARLC aL, %s.xywz;\n", src_name);
-        shader_addline(buffer, "BRA loop_%u_end (LE.x);\n", control_frame->loop_no);
-        shader_addline(buffer, "loop_%u_start:\n", control_frame->loop_no);
+        shader_addline(buffer, "BRA loop_%u_end (LE.x);\n", control_frame->no.loop);
+        shader_addline(buffer, "loop_%u_start:\n", control_frame->no.loop);
     }
     else
@@ -2632,6 +2657,6 @@
 
         shader_addline(buffer, "ARLC aL, %s.xywz;\n", src_name);
-        shader_addline(buffer, "BRA loop_%u_end (LE.x);\n", control_frame->loop_no);
-        shader_addline(buffer, "loop_%u_start:\n", control_frame->loop_no);
+        shader_addline(buffer, "BRA loop_%u_end (LE.x);\n", control_frame->no.loop);
+        shader_addline(buffer, "loop_%u_start:\n", control_frame->no.loop);
     }
     else
@@ -2653,6 +2678,6 @@
 
         shader_addline(buffer, "ARAC aL.xy, aL;\n");
-        shader_addline(buffer, "BRA loop_%u_start (GT.x);\n", control_frame->loop_no);
-        shader_addline(buffer, "loop_%u_end:\n", control_frame->loop_no);
+        shader_addline(buffer, "BRA loop_%u_start (GT.x);\n", control_frame->no.loop);
+        shader_addline(buffer, "loop_%u_end:\n", control_frame->no.loop);
 
         if(priv->loop_depth > 1) shader_addline(buffer, "POPA aL;\n");
@@ -2676,6 +2701,6 @@
 
         shader_addline(buffer, "ARAC aL.xy, aL;\n");
-        shader_addline(buffer, "BRA loop_%u_start (GT.x);\n", control_frame->loop_no);
-        shader_addline(buffer, "loop_%u_end:\n", control_frame->loop_no);
+        shader_addline(buffer, "BRA loop_%u_start (GT.x);\n", control_frame->no.loop);
+        shader_addline(buffer, "loop_%u_end:\n", control_frame->no.loop);
 
         if(priv->loop_depth > 1) shader_addline(buffer, "POPA aL;\n");
@@ -2707,5 +2732,5 @@
     if(vshader)
     {
-        shader_addline(buffer, "BRA loop_%u_end;\n", control_frame->loop_no);
+        shader_addline(buffer, "BRA loop_%u_end;\n", control_frame->no.loop);
     }
     else
@@ -2765,5 +2790,5 @@
          */
         shader_addline(buffer, "SUBC TA, %s, %s;\n", src_name0, src_name1);
-        shader_addline(buffer, "BRA loop_%u_end (%s.x);\n", control_frame->loop_no, comp);
+        shader_addline(buffer, "BRA loop_%u_end (%s.x);\n", control_frame->no.loop, comp);
     }
     else
@@ -2793,5 +2818,5 @@
         comp = get_compare(invert_compare(ins->flags));
         shader_addline(buffer, "SUBC TA, %s, %s;\n", src_name0, src_name1);
-        shader_addline(buffer, "BRA ifc_%u_else (%s.x);\n", control_frame->ifc_no, comp);
+        shader_addline(buffer, "BRA ifc_%u_else (%s.x);\n", control_frame->no.ifc, comp);
     }
     else
@@ -2813,6 +2838,6 @@
     if(vshader)
     {
-        shader_addline(buffer, "BRA ifc_%u_endif;\n", control_frame->ifc_no);
-        shader_addline(buffer, "ifc_%u_else:\n", control_frame->ifc_no);
+        shader_addline(buffer, "BRA ifc_%u_endif;\n", control_frame->no.ifc);
+        shader_addline(buffer, "ifc_%u_else:\n", control_frame->no.ifc);
         control_frame->had_else = TRUE;
     }
@@ -2835,10 +2860,10 @@
         if(control_frame->had_else)
         {
-            shader_addline(buffer, "ifc_%u_endif:\n", control_frame->ifc_no);
+            shader_addline(buffer, "ifc_%u_endif:\n", control_frame->no.ifc);
         }
         else
         {
             shader_addline(buffer, "#No else branch. else is endif\n");
-            shader_addline(buffer, "ifc_%u_else:\n", control_frame->ifc_no);
+            shader_addline(buffer, "ifc_%u_else:\n", control_frame->no.ifc);
         }
     }
@@ -2930,17 +2955,20 @@
     if(use_nv_clip(gl_info) && priv_ctx->target_version >= NV2)
     {
-        for(i = 0; i < priv_ctx->vs_clipplanes; i++)
-        {
-            shader_addline(buffer, "DP4 result.clip[%u].x, TMP_OUT, state.clip[%u].plane;\n", i, i);
-        }
-    }
-    else if(args->boolclip.clip_control[0])
+        if(args->super.clip_enabled)
+        {
+            for(i = 0; i < priv_ctx->vs_clipplanes; i++)
+            {
+                shader_addline(buffer, "DP4 result.clip[%u].x, TMP_OUT, state.clip[%u].plane;\n", i, i);
+            }
+        }
+    }
+    else if(args->clip.boolclip.clip_texcoord)
     {
         unsigned int cur_clip = 0;
         char component[4] = {'x', 'y', 'z', 'w'};
 
-        for(i = 0; i < GL_LIMITS(clipplanes); i++)
-        {
-            if(args->boolclip.clip_control[1] & (1 << i))
+        for (i = 0; i < gl_info->limits.clipplanes; ++i)
+        {
+            if(args->clip.boolclip.clipplane_mask & (1 << i))
             {
                 shader_addline(buffer, "DP4 TA.%c, TMP_OUT, state.clip[%u].plane;\n",
@@ -2964,5 +2992,5 @@
         }
         shader_addline(buffer, "MOV result.texcoord[%u], TA;\n",
-                       args->boolclip.clip_control[0] - 1);
+                       args->clip.boolclip.clip_texcoord - 1);
     }
 
@@ -3146,5 +3174,4 @@
         */
     }
-    shader_addline(buffer, "MOV result.color, %s;\n", fragcolor);
     /* [0.0;1.0] clamping. Not needed, this is done implicitly */
 }
@@ -3173,5 +3200,5 @@
     };
     unsigned int i;
-    const struct wined3d_shader_signature_element *sig = This->input_signature;
+    const struct wined3d_shader_signature_element *sig = This->baseShader.input_signature;
     const char *semantic_name;
     DWORD semantic_idx;
@@ -3320,8 +3347,11 @@
 
     shader_addline(buffer, "!!ARBfp1.0\n");
-    if(want_nv_prog && GL_SUPPORT(NV_FRAGMENT_PROGRAM2)) {
+    if (want_nv_prog && gl_info->supported[NV_FRAGMENT_PROGRAM2])
+    {
         shader_addline(buffer, "OPTION NV_fragment_program2;\n");
         priv_ctx.target_version = NV3;
-    } else if(want_nv_prog && GL_SUPPORT(NV_FRAGMENT_PROGRAM_OPTION)) {
+    }
+    else if (want_nv_prog && gl_info->supported[NV_FRAGMENT_PROGRAM_OPTION])
+    {
         shader_addline(buffer, "OPTION NV_fragment_program;\n");
         priv_ctx.target_version = NV2;
@@ -3396,6 +3426,6 @@
 
     /* Base Declarations */
-    next_local = shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION,
-            lconst_map, NULL, &priv_ctx);
+    next_local = shader_generate_arb_declarations((IWineD3DBaseShader *)This,
+            reg_maps, buffer, gl_info, lconst_map, NULL, &priv_ctx);
 
     for (i = 0, map = reg_maps->bumpmat; map; map >>= 1, ++i)
@@ -3483,5 +3513,5 @@
         struct arb_ps_np2fixup_info* const fixup = priv_ctx.cur_np2fixup_info;
         const WORD map = priv_ctx.cur_ps_args->super.np2_fixup;
-        const UINT max_lconsts = gl_info->ps_arb_max_local_constants;
+        const UINT max_lconsts = gl_info->limits.arb_ps_local_constants;
 
         fixup->offset = next_local;
@@ -3522,5 +3552,7 @@
         arbfp_add_sRGB_correction(buffer, fragcolor, srgbtmp[0], srgbtmp[1], srgbtmp[2], srgbtmp[3],
                                   priv_ctx.target_version >= NV2);
-    } else if(reg_maps->shader_version.major < 2) {
+    }
+
+    if(strcmp(fragcolor, "result.color")) {
         shader_addline(buffer, "MOV result.color, %s;\n", fragcolor);
     }
@@ -3648,4 +3680,5 @@
     };
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) shader->baseShader.device;
+    IWineD3DBaseShaderClass *baseshader = &shader->baseShader;
     const struct wined3d_shader_signature_element *sig;
     const char *semantic_name;
@@ -3675,7 +3708,7 @@
 
         /* Map declared regs to builtins. Use "TA" to /dev/null unread output */
-        for(i = 0; i < (sizeof(shader->output_signature) / sizeof(*shader->output_signature)); i++)
-        {
-            semantic_name = shader->output_signature[i].semantic_name;
+        for (i = 0; i < (sizeof(baseshader->output_signature) / sizeof(*baseshader->output_signature)); ++i)
+        {
+            semantic_name = baseshader->output_signature[i].semantic_name;
             if(semantic_name == NULL) continue;
 
@@ -3683,5 +3716,5 @@
             {
                 TRACE("o%u is TMP_OUT\n", i);
-                if(shader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "TMP_OUT";
+                if (baseshader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "TMP_OUT";
                 else priv_ctx->vs_output[i] = "TA";
             }
@@ -3689,24 +3722,26 @@
             {
                 TRACE("o%u is result.pointsize\n", i);
-                if(shader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "result.pointsize";
+                if (baseshader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "result.pointsize";
                 else priv_ctx->vs_output[i] = "TA";
             }
             else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_COLOR))
             {
-                TRACE("o%u is result.color.?, idx %u\n", i, shader->output_signature[i].semantic_idx);
-                if(shader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "result.color.primary";
-                else if(shader->output_signature[i].semantic_idx == 1) priv_ctx->vs_output[i] = "result.color.secondary";
+                TRACE("o%u is result.color.?, idx %u\n", i, baseshader->output_signature[i].semantic_idx);
+                if (baseshader->output_signature[i].semantic_idx == 0)
+                    priv_ctx->vs_output[i] = "result.color.primary";
+                else if (baseshader->output_signature[i].semantic_idx == 1)
+                    priv_ctx->vs_output[i] = "result.color.secondary";
                 else priv_ctx->vs_output[i] = "TA";
             }
             else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_TEXCOORD))
             {
-                TRACE("o%u is %s\n", i, texcoords[shader->output_signature[i].semantic_idx]);
-                if(shader->output_signature[i].semantic_idx >= 8) priv_ctx->vs_output[i] = "TA";
-                else priv_ctx->vs_output[i] = texcoords[shader->output_signature[i].semantic_idx];
+                TRACE("o%u is %s\n", i, texcoords[baseshader->output_signature[i].semantic_idx]);
+                if (baseshader->output_signature[i].semantic_idx >= 8) priv_ctx->vs_output[i] = "TA";
+                else priv_ctx->vs_output[i] = texcoords[baseshader->output_signature[i].semantic_idx];
             }
             else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_FOG))
             {
                 TRACE("o%u is result.fogcoord\n", i);
-                if(shader->output_signature[i].semantic_idx > 0) priv_ctx->vs_output[i] = "TA";
+                if (baseshader->output_signature[i].semantic_idx > 0) priv_ctx->vs_output[i] = "TA";
                 else priv_ctx->vs_output[i] = "result.fogcoord";
             }
@@ -3722,5 +3757,5 @@
      * Its maybe not the shader where the signature came from, but it is the same signature and faster to find
      */
-    sig = ((IWineD3DPixelShaderImpl *)device->stateBlock->pixelShader)->input_signature;
+    sig = ((IWineD3DPixelShaderImpl *)device->stateBlock->pixelShader)->baseShader.input_signature;
     TRACE("Pixel shader uses declared varyings\n");
 
@@ -3772,9 +3807,9 @@
 
     /* Map declared to declared */
-    for(i = 0; i < (sizeof(shader->output_signature) / sizeof(*shader->output_signature)); i++)
+    for (i = 0; i < (sizeof(baseshader->output_signature) / sizeof(*baseshader->output_signature)); ++i)
     {
         /* Write unread output to TA to throw them away */
         priv_ctx->vs_output[i] = "TA";
-        semantic_name = shader->output_signature[i].semantic_name;
+        semantic_name = baseshader->output_signature[i].semantic_name;
         if(semantic_name == NULL)
         {
@@ -3782,12 +3817,12 @@
         }
 
-        if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_POSITION) &&
-           shader->output_signature[i].semantic_idx == 0)
+        if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_POSITION)
+                && baseshader->output_signature[i].semantic_idx == 0)
         {
             priv_ctx->vs_output[i] = "TMP_OUT";
             continue;
         }
-        else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_PSIZE) &&
-           shader->output_signature[i].semantic_idx == 0)
+        else if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_PSIZE)
+                && baseshader->output_signature[i].semantic_idx == 0)
         {
             priv_ctx->vs_output[i] = "result.pointsize";
@@ -3802,6 +3837,6 @@
             }
 
-            if(strcmp(sig[j].semantic_name, semantic_name) == 0 &&
-               sig[j].semantic_idx == shader->output_signature[i].semantic_idx)
+            if (strcmp(sig[j].semantic_name, semantic_name) == 0
+                    && sig[j].semantic_idx == baseshader->output_signature[i].semantic_idx)
             {
                 priv_ctx->vs_output[i] = decl_idx_to_string[sig[j].register_idx];
@@ -3843,9 +3878,12 @@
      * mesurable performance penalty, and we can always make use of it for clipplanes.
      */
-    if(GL_SUPPORT(NV_VERTEX_PROGRAM3)) {
+    if (gl_info->supported[NV_VERTEX_PROGRAM3])
+    {
         shader_addline(buffer, "OPTION NV_vertex_program3;\n");
         priv_ctx.target_version = NV3;
         shader_addline(buffer, "ADDRESS aL;\n");
-    } else if(GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION)) {
+    }
+    else if (gl_info->supported[NV_VERTEX_PROGRAM2_OPTION])
+    {
         shader_addline(buffer, "OPTION NV_vertex_program2;\n");
         priv_ctx.target_version = NV2;
@@ -3867,6 +3905,6 @@
 
     /* Base Declarations */
-    next_local = shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION,
-            lconst_map, &priv_ctx.vs_clipplanes, &priv_ctx);
+    next_local = shader_generate_arb_declarations((IWineD3DBaseShader *)This,
+            reg_maps, buffer, gl_info, lconst_map, &priv_ctx.vs_clipplanes, &priv_ctx);
 
     for(i = 0; i < MAX_CONST_I; i++)
@@ -3906,8 +3944,9 @@
      * this can eat a number of instructions, so skip it unless this cap is set as well
      */
-    if(!GL_SUPPORT(NV_VERTEX_PROGRAM)) {
+    if (!gl_info->supported[NV_VERTEX_PROGRAM])
+    {
         shader_addline(buffer, "MOV result.color.secondary, -helper_const.wwwy;\n");
 
-        if ((GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W && !device->frag_pipe->ffp_proj_control)
+        if (gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W && !device->frag_pipe->ffp_proj_control)
         {
             int i;
@@ -3991,5 +4030,5 @@
 
         if(shader->baseShader.reg_maps.shader_version.major < 3) shader_data->input_signature_idx = ~0;
-        else shader_data->input_signature_idx = find_input_signature(priv, shader->input_signature);
+        else shader_data->input_signature_idx = find_input_signature(priv, shader->baseShader.input_signature);
 
         shader_data->has_signature_idx = TRUE;
@@ -3998,5 +4037,5 @@
         if (!device->vs_clipping)
             shader_data->clipplane_emulation = shader_find_free_input_register(&shader->baseShader.reg_maps,
-                    GL_LIMITS(texture_stages) - 1);
+                    gl_info->limits.texture_stages - 1);
         else
             shader_data->clipplane_emulation = ~0U;
@@ -4056,8 +4095,9 @@
                                  const DWORD use_map, BOOL skip_int) {
     if((stored->super.swizzle_map & use_map) != new->super.swizzle_map) return FALSE;
+    if(stored->super.clip_enabled != new->super.clip_enabled) return FALSE;
     if(stored->super.fog_src != new->super.fog_src) return FALSE;
-    if(stored->boolclip_compare != new->boolclip_compare) return FALSE;
+    if(stored->clip.boolclip_compare != new->clip.boolclip_compare) return FALSE;
     if(stored->ps_signature != new->ps_signature) return FALSE;
-    if(stored->vertex_samplers_compare != new->vertex_samplers_compare) return FALSE;
+    if(stored->vertex.samplers_compare != new->vertex.samplers_compare) return FALSE;
     if(skip_int) return TRUE;
 
@@ -4087,5 +4127,7 @@
      */
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
-        if(vs_args_equal(&shader_data->gl_shaders[i].args, args, use_map, GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION))) {
+        if (vs_args_equal(&shader_data->gl_shaders[i].args, args,
+                use_map, gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]))
+        {
             return &shader_data->gl_shaders[i];
         }
@@ -4161,5 +4203,5 @@
     /* Skip if unused or local, or supported natively */
     int_skip = ~shader->baseShader.reg_maps.integer_constants | shader->baseShader.reg_maps.local_int_consts;
-    if(int_skip == 0xffff || GL_SUPPORT(NV_FRAGMENT_PROGRAM_OPTION))
+    if (int_skip == 0xffff || gl_info->supported[NV_FRAGMENT_PROGRAM_OPTION])
     {
         memset(&args->loop_ctrl, 0, sizeof(args->loop_ctrl));
@@ -4193,5 +4235,5 @@
     find_vs_compile_args(shader, stateblock, &args->super);
 
-    args->boolclip_compare = 0;
+    args->clip.boolclip_compare = 0;
     if(use_ps(stateblock))
     {
@@ -4200,5 +4242,5 @@
         args->ps_signature = shader_priv->input_signature_idx;
 
-        args->boolclip.clip_control[0] = shader_priv->clipplane_emulation + 1;
+        args->clip.boolclip.clip_texcoord = shader_priv->clipplane_emulation + 1;
     }
     else
@@ -4207,34 +4249,35 @@
         if(!dev->vs_clipping)
         {
-            args->boolclip.clip_control[0] = ffp_clip_emul(stateblock) ? GL_LIMITS(texture_stages) : 0;
-        }
-        /* Otherwise: Setting boolclip_compare set clip_control[0] to 0 */
-    }
-
-    if(args->boolclip.clip_control[0])
+            args->clip.boolclip.clip_texcoord = ffp_clip_emul(stateblock) ? gl_info->limits.texture_stages : 0;
+        }
+        /* Otherwise: Setting boolclip_compare set clip_texcoord to 0 */
+    }
+
+    if(args->clip.boolclip.clip_texcoord)
     {
         if(stateblock->renderState[WINED3DRS_CLIPPING])
         {
-            args->boolclip.clip_control[1] = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
-        }
-        /* clip_control[1] was set to 0 by setting boolclip_compare to 0 */
+            args->clip.boolclip.clipplane_mask = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
+        }
+        /* clipplane_mask was set to 0 by setting boolclip_compare to 0 */
     }
 
     /* This forces all local boolean constants to 1 to make them stateblock independent */
-    args->boolclip.bools = shader->baseShader.reg_maps.local_bool_consts;
+    args->clip.boolclip.bools = shader->baseShader.reg_maps.local_bool_consts;
     /* TODO: Figure out if it would be better to store bool constants as bitmasks in the stateblock */
     for(i = 0; i < MAX_CONST_B; i++)
     {
-        if(stateblock->vertexShaderConstantB[i]) args->boolclip.bools |= ( 1 << i);
-    }
-
-    args->vertex_samplers[0] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 0];
-    args->vertex_samplers[1] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 1];
-    args->vertex_samplers[2] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 2];
-    args->vertex_samplers[3] = 0;
+        if(stateblock->vertexShaderConstantB[i]) args->clip.boolclip.bools |= ( 1 << i);
+    }
+
+    args->vertex.samplers[0] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 0];
+    args->vertex.samplers[1] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 1];
+    args->vertex.samplers[2] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 2];
+    args->vertex.samplers[3] = 0;
 
     /* Skip if unused or local */
     int_skip = ~shader->baseShader.reg_maps.integer_constants | shader->baseShader.reg_maps.local_int_consts;
-    if(int_skip == 0xffff || GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION)) /* This is about flow control, not clipping */
+    /* This is about flow control, not clipping. */
+    if (int_skip == 0xffff || gl_info->supported[NV_VERTEX_PROGRAM2_OPTION])
     {
         memset(&args->loop_ctrl, 0, sizeof(args->loop_ctrl));
@@ -4262,5 +4305,5 @@
 static void shader_arb_select(const struct wined3d_context *context, BOOL usePS, BOOL useVS)
 {
-    IWineD3DDeviceImpl *This = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *This = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     struct shader_arb_priv *priv = This->shader_priv;
     const struct wined3d_gl_info *gl_info = context->gl_info;
@@ -4312,5 +4355,7 @@
         if (compiled->np2fixup_info.super.active)
             shader_arb_load_np2fixup_constants((IWineD3DDevice *)This, usePS, useVS);
-    } else if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && !priv->use_arbfp_fixed_func) {
+    }
+    else if (gl_info->supported[ARB_FRAGMENT_PROGRAM] && !priv->use_arbfp_fixed_func)
+    {
         /* Disable only if we're not using arbfp fixed function fragment processing. If this is used,
         * keep GL_FRAGMENT_PROGRAM_ARB enabled, and the fixed function pipeline will bind the fixed function
@@ -4346,5 +4391,6 @@
             priv->last_vs_color_unclamp = compiled->need_color_unclamp;
 
-            if (GL_SUPPORT(ARB_COLOR_BUFFER_FLOAT)) {
+            if (gl_info->supported[ARB_COLOR_BUFFER_FLOAT])
+            {
                 GL_EXTCALL(glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, !compiled->need_color_unclamp));
                 checkGLcall("glClampColorARB");
@@ -4353,5 +4399,7 @@
             }
         }
-    } else if(GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
+    }
+    else if (gl_info->supported[ARB_VERTEX_PROGRAM])
+    {
         priv->current_vprogram_id = 0;
         glDisable(GL_VERTEX_PROGRAM_ARB);
@@ -4415,13 +4463,20 @@
 
         if(!shader_data) return; /* This can happen if a shader was never compiled */
-        ENTER_GL();
-
-        if(shader_data->num_gl_shaders) ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-
-        for(i = 0; i < shader_data->num_gl_shaders; i++) {
-            GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
-            checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
-        }
-        LEAVE_GL();
+
+        if (shader_data->num_gl_shaders)
+        {
+            struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+
+            ENTER_GL();
+            for (i = 0; i < shader_data->num_gl_shaders; ++i)
+            {
+                GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
+                checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
+            }
+            LEAVE_GL();
+
+            context_release(context);
+        }
+
         HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
         HeapFree(GetProcessHeap(), 0, shader_data);
@@ -4433,13 +4488,20 @@
 
         if(!shader_data) return; /* This can happen if a shader was never compiled */
-        ENTER_GL();
-
-        if(shader_data->num_gl_shaders) ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-
-        for(i = 0; i < shader_data->num_gl_shaders; i++) {
-            GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
-            checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
-        }
-        LEAVE_GL();
+
+        if (shader_data->num_gl_shaders)
+        {
+            struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+
+            ENTER_GL();
+            for (i = 0; i < shader_data->num_gl_shaders; ++i)
+            {
+                GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
+                checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
+            }
+            LEAVE_GL();
+
+            context_release(context);
+        }
+
         HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
         HeapFree(GetProcessHeap(), 0, shader_data);
@@ -4516,4 +4578,7 @@
         struct shader_caps *pCaps)
 {
+    DWORD vs_consts = min(gl_info->limits.arb_vs_float_constants, gl_info->limits.arb_vs_native_constants);
+    DWORD ps_consts = min(gl_info->limits.arb_ps_float_constants, gl_info->limits.arb_ps_native_constants);
+
     /* We don't have an ARB fixed function pipeline yet, so let the none backend set its caps,
      * then overwrite the shader specific ones
@@ -4521,11 +4586,12 @@
     none_shader_backend.shader_get_caps(devtype, gl_info, pCaps);
 
-    if(GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
-        if(GL_SUPPORT(NV_VERTEX_PROGRAM3))
+    if (gl_info->supported[ARB_VERTEX_PROGRAM])
+    {
+        if (gl_info->supported[NV_VERTEX_PROGRAM3])
         {
             pCaps->VertexShaderVersion = WINED3DVS_VERSION(3,0);
             TRACE_(d3d_caps)("Hardware vertex shader version 3.0 enabled (NV_VERTEX_PROGRAM3)\n");
         }
-        else if(GL_LIMITS(vshader_constantsF) >= 256)
+        else if (vs_consts >= 256)
         {
             /* Shader Model 2.0 requires at least 256 vertex shader constants */
@@ -4538,14 +4604,15 @@
             TRACE_(d3d_caps)("Hardware vertex shader version 1.1 enabled (ARB_PROGRAM)\n");
         }
-        pCaps->MaxVertexShaderConst = GL_LIMITS(vshader_constantsF);
-    }
-
-    if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
-        if(GL_SUPPORT(NV_FRAGMENT_PROGRAM2))
+        pCaps->MaxVertexShaderConst = vs_consts;
+    }
+
+    if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
+    {
+        if (gl_info->supported[NV_FRAGMENT_PROGRAM2])
         {
             pCaps->PixelShaderVersion    = WINED3DPS_VERSION(3,0);
             TRACE_(d3d_caps)("Hardware pixel shader version 3.0 enabled (NV_FRAGMENT_PROGRAM2)\n");
         }
-        else if(GL_LIMITS(pshader_constantsF) >= 32)
+        else if (ps_consts >= 32)
         {
             /* Shader Model 2.0 requires at least 32 pixel shader constants */
@@ -4559,5 +4626,5 @@
         }
         pCaps->PixelShader1xMaxValue = 8.0f;
-        pCaps->MaxPixelShaderConst = GL_LIMITS(pshader_constantsF);
+        pCaps->MaxPixelShaderConst = ps_consts;
     }
 
@@ -4621,4 +4688,5 @@
     /* WINED3DSIH_CND           */ pshader_hw_cnd,
     /* WINED3DSIH_CRS           */ shader_hw_map2gl,
+    /* WINED3DSIH_CUT           */ NULL,
     /* WINED3DSIH_DCL           */ NULL,
     /* WINED3DSIH_DEF           */ NULL,
@@ -4632,4 +4700,5 @@
     /* WINED3DSIH_DSY           */ shader_hw_dsy,
     /* WINED3DSIH_ELSE          */ shader_hw_else,
+    /* WINED3DSIH_EMIT          */ NULL,
     /* WINED3DSIH_ENDIF         */ shader_hw_endif,
     /* WINED3DSIH_ENDLOOP       */ shader_hw_endloop,
@@ -4638,6 +4707,8 @@
     /* WINED3DSIH_EXPP          */ shader_hw_scalar_op,
     /* WINED3DSIH_FRC           */ shader_hw_map2gl,
+    /* WINED3DSIH_IADD          */ NULL,
     /* WINED3DSIH_IF            */ NULL /* Hardcoded into the shader */,
     /* WINED3DSIH_IFC           */ shader_hw_ifc,
+    /* WINED3DSIH_IGE           */ NULL,
     /* WINED3DSIH_LABEL         */ shader_hw_label,
     /* WINED3DSIH_LIT           */ shader_hw_map2gl,
@@ -4646,4 +4717,5 @@
     /* WINED3DSIH_LOOP          */ shader_hw_loop,
     /* WINED3DSIH_LRP           */ shader_hw_lrp,
+    /* WINED3DSIH_LT            */ NULL,
     /* WINED3DSIH_M3x2          */ shader_hw_mnxn,
     /* WINED3DSIH_M3x3          */ shader_hw_mnxn,
@@ -4718,5 +4790,5 @@
     else
     {
-        if(vshader) bools = priv->cur_vs_args->boolclip.bools;
+        if(vshader) bools = priv->cur_vs_args->clip.boolclip.bools;
         else bools = priv->cur_ps_args->bools;
         return bools & flag;
@@ -4879,5 +4951,5 @@
         if(priv->target_version >= NV2)
         {
-            control_frame->loop_no = priv->num_loops++;
+            control_frame->no.loop = priv->num_loops++;
             priv->loop_depth++;
         }
@@ -5008,5 +5080,5 @@
         control_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*control_frame));
         control_frame->type = IFC;
-        control_frame->ifc_no = priv->num_ifcs++;
+        control_frame->no.ifc = priv->num_ifcs++;
         list_add_head(&priv->control_frames, &control_frame->entry);
     }
@@ -5203,5 +5275,5 @@
 
     caps->MaxTextureBlendStages   = 8;
-    caps->MaxSimultaneousTextures = min(GL_LIMITS(fragment_samplers), 8);
+    caps->MaxSimultaneousTextures = min(gl_info->limits.fragment_samplers, 8);
 
     caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
@@ -5209,9 +5281,9 @@
 #undef GLINFO_LOCATION
 
-#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION stateblock->device->adapter->gl_info
 static void state_texfactor_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    IWineD3DDeviceImpl *device = stateblock->device;
     float col[4];
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
 
     /* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite
@@ -5221,5 +5293,4 @@
         if (use_ps(stateblock)) return;
 
-        device = stateblock->wineD3DDevice;
         context->pshader_const_dirty[ARB_FFP_CONST_TFACTOR] = 1;
         device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_TFACTOR + 1);
@@ -5234,6 +5305,6 @@
 static void state_arb_specularenable(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    IWineD3DDeviceImpl *device = stateblock->device;
     float col[4];
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
 
     /* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite
@@ -5243,5 +5314,4 @@
         if (use_ps(stateblock)) return;
 
-        device = stateblock->wineD3DDevice;
         context->pshader_const_dirty[ARB_FFP_CONST_SPECULAR_ENABLE] = 1;
         device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_SPECULAR_ENABLE + 1);
@@ -5263,5 +5333,5 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
     float mat[2][2];
 
@@ -5300,5 +5370,5 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
     float param[4];
 
@@ -5785,4 +5855,5 @@
         shader_addline(&buffer, "MAD ret, fragment.color.secondary, specular_enable, %s;\n", final_combiner_src);
         arbfp_add_sRGB_correction(&buffer, "ret", "arg0", "arg1", "arg2", "tempreg", FALSE);
+        shader_addline(&buffer, "MOV result.color, ret;\n");
     } else {
         shader_addline(&buffer, "MAD result.color, fragment.color.secondary, specular_enable, %s;\n", final_combiner_src);
@@ -5820,5 +5891,5 @@
 static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
     struct shader_arb_priv *priv = device->fragment_priv;
     BOOL use_pshader = use_ps(stateblock);
@@ -5856,5 +5927,6 @@
             }
             new_desc->num_textures_used = 0;
-            for(i = 0; i < GL_LIMITS(texture_stages); i++) {
+            for (i = 0; i < context->gl_info->limits.texture_stages; ++i)
+            {
                 if(settings.op[i].cop == WINED3DTOP_DISABLE) break;
                 new_desc->num_textures_used = i;
@@ -6149,4 +6221,7 @@
     checkGLcall("Delete yuv programs");
     LEAVE_GL();
+
+    HeapFree(GetProcessHeap(), 0, device->blit_priv);
+    device->blit_priv = NULL;
 }
 
@@ -6602,4 +6677,5 @@
 static void arbfp_blit_unset(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
     ENTER_GL();
@@ -6608,9 +6684,11 @@
     glDisable(GL_TEXTURE_2D);
     checkGLcall("glDisable(GL_TEXTURE_2D)");
-    if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+    if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+    {
         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
         checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
     }
-    if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+    if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+    {
         glDisable(GL_TEXTURE_RECTANGLE_ARB);
         checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/ati_fragment_shader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/ati_fragment_shader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/ati_fragment_shader.c	(revision 25949)
@@ -412,5 +412,6 @@
 
     /* Pass 1: Generate sampling instructions for perturbation maps */
-      for(stage = 0; stage < GL_LIMITS(textures); stage++) {
+    for (stage = 0; stage < gl_info->limits.textures; ++stage)
+    {
         if(op[stage].cop == WINED3DTOP_DISABLE) break;
         if(op[stage].cop != WINED3DTOP_BUMPENVMAP &&
@@ -437,5 +438,6 @@
 
     /* Pass 2: Generate perturbation calculations */
-    for(stage = 0; stage < GL_LIMITS(textures); stage++) {
+    for (stage = 0; stage < gl_info->limits.textures; ++stage)
+    {
         GLuint argmodextra_x, argmodextra_y;
         struct color_fixup_desc fixup;
@@ -485,5 +487,6 @@
 
     /* Pass 3: Generate sampling instructions for regular textures */
-    for(stage = 0; stage < GL_LIMITS(textures); stage++) {
+    for (stage = 0; stage < gl_info->limits.textures; ++stage)
+    {
         if(op[stage].cop == WINED3DTOP_DISABLE) {
             break;
@@ -805,8 +808,8 @@
 #undef GLINFO_LOCATION
 
-#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION stateblock->device->adapter->gl_info
 static void set_tex_op_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl          *This = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *This = stateblock->device;
     const struct atifs_ffp_desc *desc;
     struct ffp_frag_settings     settings;
@@ -825,5 +828,6 @@
         }
         new_desc->num_textures_used = 0;
-        for(i = 0; i < GL_LIMITS(texture_stages); i++) {
+        for (i = 0; i < context->gl_info->limits.texture_stages; ++i)
+        {
             if(settings.op[i].cop == WINED3DTOP_DISABLE) break;
             new_desc->num_textures_used = i;
@@ -831,5 +835,5 @@
 
         memcpy(&new_desc->parent.settings, &settings, sizeof(settings));
-        new_desc->shader = gen_ati_shader(settings.op, &GLINFO_LOCATION);
+        new_desc->shader = gen_ati_shader(settings.op, context->gl_info);
         add_ffp_frag_shader(&priv->fragment_shaders, &new_desc->parent);
         TRACE("Allocated fixed function replacement shader descriptor %p\n", new_desc);
@@ -895,5 +899,5 @@
 static void atifs_apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
     BOOL use_vshader = use_vs(stateblock);
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c	(revision 25949)
@@ -56,4 +56,5 @@
     /* WINED3DSIH_CND           */ "cnd",
     /* WINED3DSIH_CRS           */ "crs",
+    /* WINED3DSIH_CUT           */ "cut",
     /* WINED3DSIH_DCL           */ "dcl",
     /* WINED3DSIH_DEF           */ "def",
@@ -67,4 +68,5 @@
     /* WINED3DSIH_DSY           */ "dsy",
     /* WINED3DSIH_ELSE          */ "else",
+    /* WINED3DSIH_EMIT          */ "emit",
     /* WINED3DSIH_ENDIF         */ "endif",
     /* WINED3DSIH_ENDLOOP       */ "endloop",
@@ -73,6 +75,8 @@
     /* WINED3DSIH_EXPP          */ "expp",
     /* WINED3DSIH_FRC           */ "frc",
+    /* WINED3DSIH_IADD          */ "iadd",
     /* WINED3DSIH_IF            */ "if",
     /* WINED3DSIH_IFC           */ "ifc",
+    /* WINED3DSIH_IGE           */ "ige",
     /* WINED3DSIH_LABEL         */ "label",
     /* WINED3DSIH_LIT           */ "lit",
@@ -81,4 +85,5 @@
     /* WINED3DSIH_LOOP          */ "loop",
     /* WINED3DSIH_LRP           */ "lrp",
+    /* WINED3DSIH_LT            */ "lt",
     /* WINED3DSIH_M3x2          */ "m3x2",
     /* WINED3DSIH_M3x3          */ "m3x3",
@@ -374,24 +379,24 @@
 }
 
+static const char *semantic_names[] =
+{
+    /* WINED3DDECLUSAGE_POSITION        */ "SV_POSITION",
+    /* WINED3DDECLUSAGE_BLENDWEIGHT     */ "BLENDWEIGHT",
+    /* WINED3DDECLUSAGE_BLENDINDICES    */ "BLENDINDICES",
+    /* WINED3DDECLUSAGE_NORMAL          */ "NORMAL",
+    /* WINED3DDECLUSAGE_PSIZE           */ "PSIZE",
+    /* WINED3DDECLUSAGE_TEXCOORD        */ "TEXCOORD",
+    /* WINED3DDECLUSAGE_TANGENT         */ "TANGENT",
+    /* WINED3DDECLUSAGE_BINORMAL        */ "BINORMAL",
+    /* WINED3DDECLUSAGE_TESSFACTOR      */ "TESSFACTOR",
+    /* WINED3DDECLUSAGE_POSITIONT       */ "POSITIONT",
+    /* WINED3DDECLUSAGE_COLOR           */ "COLOR",
+    /* WINED3DDECLUSAGE_FOG             */ "FOG",
+    /* WINED3DDECLUSAGE_DEPTH           */ "DEPTH",
+    /* WINED3DDECLUSAGE_SAMPLE          */ "SAMPLE",
+};
+
 static const char *shader_semantic_name_from_usage(WINED3DDECLUSAGE usage)
 {
-    static const char *semantic_names[] =
-    {
-        /* WINED3DDECLUSAGE_POSITION        */ "SV_POSITION",
-        /* WINED3DDECLUSAGE_BLENDWEIGHT     */ "BLENDWEIGHT",
-        /* WINED3DDECLUSAGE_BLENDINDICES    */ "BLENDINDICES",
-        /* WINED3DDECLUSAGE_NORMAL          */ "NORMAL",
-        /* WINED3DDECLUSAGE_PSIZE           */ "PSIZE",
-        /* WINED3DDECLUSAGE_TEXCOORD        */ "TEXCOORD",
-        /* WINED3DDECLUSAGE_TANGENT         */ "TANGENT",
-        /* WINED3DDECLUSAGE_BINORMAL        */ "BINORMAL",
-        /* WINED3DDECLUSAGE_TESSFACTOR      */ "TESSFACTOR",
-        /* WINED3DDECLUSAGE_POSITIONT       */ "POSITIONT",
-        /* WINED3DDECLUSAGE_COLOR           */ "COLOR",
-        /* WINED3DDECLUSAGE_FOG             */ "FOG",
-        /* WINED3DDECLUSAGE_DEPTH           */ "DEPTH",
-        /* WINED3DDECLUSAGE_SAMPLE          */ "SAMPLE",
-    };
-
     if (usage >= sizeof(semantic_names) / sizeof(*semantic_names))
     {
@@ -401,4 +406,16 @@
 
     return semantic_names[usage];
+}
+
+WINED3DDECLUSAGE shader_usage_from_semantic_name(const char *name)
+{
+    unsigned int i;
+
+    for (i = 0; i < sizeof(semantic_names) / sizeof(*semantic_names); ++i)
+    {
+        if (!strcmp(name, semantic_names[i])) return i;
+    }
+
+    return ~0U;
 }
 
@@ -423,6 +440,5 @@
 
 HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
-        struct shader_reg_maps *reg_maps, struct wined3d_shader_attribute *attributes,
-        struct wined3d_shader_signature_element *input_signature,
+        struct shader_reg_maps *reg_maps, struct wined3d_shader_signature_element *input_signature,
         struct wined3d_shader_signature_element *output_signature, const DWORD *byte_code, DWORD constf_size)
 {
@@ -484,17 +500,8 @@
             switch (semantic.reg.reg.type)
             {
-                /* Vshader: mark attributes used
-                 * Pshader: mark 3.0 input registers used, save token */
+                /* Mark input registers used. */
                 case WINED3DSPR_INPUT:
                     reg_maps->input_registers |= 1 << semantic.reg.reg.idx;
-                    if (shader_version.type == WINED3D_SHADER_TYPE_VERTEX)
-                    {
-                        attributes[semantic.reg.reg.idx].usage = semantic.usage;
-                        attributes[semantic.reg.reg.idx].usage_idx = semantic.usage_idx;
-                    }
-                    else
-                    {
-                        shader_signature_from_semantic(&input_signature[semantic.reg.reg.idx], &semantic);
-                    }
+                    shader_signature_from_semantic(&input_signature[semantic.reg.reg.idx], &semantic);
                     break;
 
@@ -1402,5 +1409,4 @@
 static BOOL shader_none_dirty_const(IWineD3DDevice *iface) {return FALSE;}
 
-#define GLINFO_LOCATION      (*gl_info)
 static void shader_none_get_caps(WINED3DDEVTYPE devtype,
         const struct wined3d_gl_info *gl_info, struct shader_caps *pCaps)
@@ -1411,5 +1417,5 @@
     pCaps->PixelShader1xMaxValue = 0.0f;
 }
-#undef GLINFO_LOCATION
+
 static BOOL shader_none_color_fixup_supported(struct color_fixup_desc fixup)
 {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 25949)
@@ -36,5 +36,4 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
 
 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
@@ -92,9 +91,10 @@
 {
     IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-
-    if(This->baseTexture.texture_rgb.name ||
-       This->baseTexture.texture_srgb.name) {
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+    IWineD3DDeviceImpl *device = This->resource.device;
+    struct wined3d_context *context = NULL;
+
+    if (This->baseTexture.texture_rgb.name || This->baseTexture.texture_srgb.name)
+    {
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
     }
 
@@ -105,4 +105,7 @@
         gltexture_delete(&This->baseTexture.texture_srgb);
     }
+
+    if (context) context_release(context);
+
     This->baseTexture.texture_rgb.dirty = TRUE;
     This->baseTexture.texture_srgb.dirty = TRUE;
@@ -131,5 +134,5 @@
         This->baseTexture.texture_srgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
         if(This->baseTexture.bindCount) {
-            IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(This->baseTexture.sampler));
+            IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_SAMPLER(This->baseTexture.sampler));
         }
     }
@@ -159,5 +162,5 @@
 {
   IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-  IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+  IWineD3DDeviceImpl *device = This->resource.device;
   UINT textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
 
@@ -171,5 +174,6 @@
        * immediately.
        */
-      ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+      struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+
       ENTER_GL();
       glBindTexture(textureDimensions, This->baseTexture.texture_rgb.name);
@@ -193,4 +197,6 @@
       }
       LEAVE_GL();
+
+      context_release(context);
   }
   This->baseTexture.filterType = FilterType;
@@ -210,8 +216,6 @@
 void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface)
 {
-  IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-  /* TODO: implement filters using GL_SGI_generate_mipmaps http://oss.sgi.com/projects/ogl-sample/registry/SGIS/generate_mipmap.txt */
-  FIXME("(%p) : stub\n", This);
-  return ;
+    /* TODO: Implement filters using GL_SGI_generate_mipmaps. */
+    FIXME("iface %p stub!\n", iface);
 }
 
@@ -329,27 +333,29 @@
 
 /* GL locking is done by the caller */
-static inline void apply_wrap(const GLint textureDimensions, const DWORD state, const GLint type,
-                              BOOL cond_np2) {
-    GLint wrapParm;
-
-    if (state < minLookup[WINELOOKUP_WARPPARAM] || state > maxLookup[WINELOOKUP_WARPPARAM]) {
-        FIXME("Unrecognized or unsupported WINED3DTADDRESS_U value %d\n", state);
-    } else {
-        if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
-            /* Cubemaps are always set to clamp, regardless of the sampler state. */
-            wrapParm = GL_CLAMP_TO_EDGE;
-        } else if(cond_np2) {
-            if(state == WINED3DTADDRESS_WRAP) {
-                wrapParm = GL_CLAMP_TO_EDGE;
-            } else {
-                wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
-            }
-        } else {
-            wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
-        }
-        TRACE("Setting WRAP_S to %d for %x\n", wrapParm, textureDimensions);
-        glTexParameteri(textureDimensions, type, wrapParm);
-        checkGLcall("glTexParameteri(..., type, wrapParm)");
-    }
+static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
+        WINED3DTEXTUREADDRESS d3d_wrap, GLenum param, BOOL cond_np2)
+{
+    GLint gl_wrap;
+
+    if (d3d_wrap < WINED3DTADDRESS_WRAP || d3d_wrap > WINED3DTADDRESS_MIRRORONCE)
+    {
+        FIXME("Unrecognized or unsupported WINED3DTEXTUREADDRESS %#x.\n", d3d_wrap);
+        return;
+    }
+
+    if (target == GL_TEXTURE_CUBE_MAP_ARB
+            || (cond_np2 && d3d_wrap == WINED3DTADDRESS_WRAP))
+    {
+        /* Cubemaps are always set to clamp, regardless of the sampler state. */
+        gl_wrap = GL_CLAMP_TO_EDGE;
+    }
+    else
+    {
+        gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3DTADDRESS_WRAP];
+    }
+
+    TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
+    glTexParameteri(target, param, gl_wrap);
+    checkGLcall("glTexParameteri(target, param, gl_wrap)");
 }
 
@@ -357,5 +363,6 @@
 void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
         const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
-        const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1])
+        const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
+        const struct wined3d_gl_info *gl_info)
 {
     IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
@@ -378,5 +385,5 @@
     if(samplerStates[WINED3DSAMP_ADDRESSU]      != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) {
         state = samplerStates[WINED3DSAMP_ADDRESSU];
-        apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
+        apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
         gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
     }
@@ -384,5 +391,5 @@
     if(samplerStates[WINED3DSAMP_ADDRESSV]      != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) {
         state = samplerStates[WINED3DSAMP_ADDRESSV];
-        apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
+        apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
         gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
     }
@@ -390,5 +397,5 @@
     if(samplerStates[WINED3DSAMP_ADDRESSW]      != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) {
         state = samplerStates[WINED3DSAMP_ADDRESSW];
-        apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
+        apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
         gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
     }
@@ -480,5 +487,5 @@
     if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
     {
-        if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC))
+        if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
         {
             glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 25949)
@@ -39,8 +39,65 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
 
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
-
-#define VB_MAXDECLCHANGES     100     /* After that number we stop converting */
-#define VB_RESETDECLCHANGE    1000    /* Reset the changecount after that number of draws */
+#define GLINFO_LOCATION This->resource.device->adapter->gl_info
+
+#define VB_MAXDECLCHANGES     100     /* After that number of decl changes we stop converting */
+#define VB_RESETDECLCHANGE    1000    /* Reset the decl changecount after that number of draws */
+#define VB_MAXFULLCONVERSIONS 5       /* Number of full conversions before we stop converting */
+#define VB_RESETFULLCONVS     20      /* Reset full conversion counts after that number of draws */
+
+static inline BOOL buffer_add_dirty_area(struct wined3d_buffer *This, UINT offset, UINT size)
+{
+    if (!This->buffer_object) return TRUE;
+
+    if (This->maps_size <= This->modified_areas)
+    {
+        void *new = HeapReAlloc(GetProcessHeap(), 0, This->maps,
+                                This->maps_size * 2 * sizeof(*This->maps));
+        if (!new)
+        {
+            ERR("Out of memory\n");
+            return FALSE;
+        }
+        else
+        {
+            This->maps = new;
+            This->maps_size *= 2;
+        }
+    }
+
+    if(!offset && !size)
+    {
+        size = This->resource.size;
+    }
+
+    This->maps[This->modified_areas].offset = offset;
+    This->maps[This->modified_areas].size = size;
+    This->modified_areas++;
+    return TRUE;
+}
+
+static inline void buffer_clear_dirty_areas(struct wined3d_buffer *This)
+{
+    This->modified_areas = 0;
+}
+
+static inline BOOL buffer_is_dirty(struct wined3d_buffer *This)
+{
+    return This->modified_areas != 0;
+}
+
+static inline BOOL buffer_is_fully_dirty(struct wined3d_buffer *This)
+{
+    unsigned int i;
+
+    for(i = 0; i < This->modified_areas; i++)
+    {
+        if(This->maps[i].offset == 0 && This->maps[i].size == This->resource.size)
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
 
 /* Context activation is done by the caller. */
@@ -48,4 +105,5 @@
 {
     GLenum error, gl_usage;
+    const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
 
     TRACE("Creating an OpenGL vertex buffer object for IWineD3DVertexBuffer %p Usage(%s)\n",
@@ -73,4 +131,5 @@
     {
         ERR("Failed to create a VBO with error %s (%#x)\n", debug_glerror(error), error);
+        LEAVE_GL();
         goto fail;
     }
@@ -78,5 +137,5 @@
     if(This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
     {
-        IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_INDEXBUFFER);
+        IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER);
     }
     GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
@@ -85,24 +144,27 @@
     {
         ERR("Failed to bind the VBO with error %s (%#x)\n", debug_glerror(error), error);
+        LEAVE_GL();
         goto fail;
     }
 
     /* Don't use static, because dx apps tend to update the buffer
-    * quite often even if they specify 0 usage. Because we always keep the local copy
-    * we never read from the vbo and can create a write only opengl buffer.
-    */
-    switch(This->resource.usage & (WINED3DUSAGE_WRITEONLY | WINED3DUSAGE_DYNAMIC))
-    {
-        case WINED3DUSAGE_WRITEONLY | WINED3DUSAGE_DYNAMIC:
-        case WINED3DUSAGE_DYNAMIC:
-            TRACE("Gl usage = GL_STREAM_DRAW\n");
-            gl_usage = GL_STREAM_DRAW_ARB;
-            break;
-
-        case WINED3DUSAGE_WRITEONLY:
-        default:
-            TRACE("Gl usage = GL_DYNAMIC_DRAW\n");
-            gl_usage = GL_DYNAMIC_DRAW_ARB;
-            break;
+     * quite often even if they specify 0 usage.
+     */
+    if(This->resource.usage & WINED3DUSAGE_DYNAMIC)
+    {
+        TRACE("Gl usage = GL_STREAM_DRAW_ARB\n");
+        gl_usage = GL_STREAM_DRAW_ARB;
+    }
+    else
+    {
+        TRACE("Gl usage = GL_DYNAMIC_DRAW_ARB\n");
+        gl_usage = GL_DYNAMIC_DRAW_ARB;
+
+        if(gl_info->supported[APPLE_FLUSH_BUFFER_RANGE])
+        {
+            GL_EXTCALL(glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE));
+            checkGLcall("glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE)");
+            This->flags |= WINED3D_BUFFER_FLUSH;
+        }
     }
 
@@ -114,4 +176,5 @@
     GL_EXTCALL(glBufferDataARB(This->buffer_type_hint, This->resource.size, This->resource.allocatedMemory, gl_usage));
     error = glGetError();
+    LEAVE_GL();
     if (error != GL_NO_ERROR)
     {
@@ -120,14 +183,14 @@
     }
 
-    LEAVE_GL();
-
     This->buffer_object_size = This->resource.size;
     This->buffer_object_usage = gl_usage;
-    This->dirty_start = 0;
-    This->dirty_end = This->resource.size;
 
     if(This->flags & WINED3D_BUFFER_DOUBLEBUFFER)
     {
-        This->flags |= WINED3D_BUFFER_DIRTY;
+        if(!buffer_add_dirty_area(This, 0, 0))
+        {
+            ERR("buffer_add_dirty_area failed, this is not expected\n");
+            goto fail;
+        }
     }
     else
@@ -136,5 +199,4 @@
         This->resource.allocatedMemory = NULL;
         This->resource.heapMemory = NULL;
-        This->flags &= ~WINED3D_BUFFER_DIRTY;
     }
 
@@ -144,9 +206,12 @@
     /* Clean up all vbo init, but continue because we can work without a vbo :-) */
     ERR("Failed to create a vertex buffer object. Continuing, but performance issues may occur\n");
-    if (This->buffer_object) GL_EXTCALL(glDeleteBuffersARB(1, &This->buffer_object));
+    if (This->buffer_object)
+    {
+        ENTER_GL();
+        GL_EXTCALL(glDeleteBuffersARB(1, &This->buffer_object));
+        LEAVE_GL();
+    }
     This->buffer_object = 0;
-    LEAVE_GL();
-
-    return;
+    buffer_clear_dirty_areas(This);
 }
 
@@ -158,5 +223,5 @@
     BOOL ret = FALSE;
     unsigned int i;
-    DWORD offset = This->resource.wineD3DDevice->stateBlock->streamOffset[attrib->stream_idx];
+    DWORD offset = This->resource.device->stateBlock->streamOffset[attrib->stream_idx];
     DWORD_PTR data;
 
@@ -213,4 +278,6 @@
 {
     const struct wined3d_stream_info_element *attrib = &si->elements[attrib_idx];
+    IWineD3DDeviceImpl *device = This->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     BOOL ret = FALSE;
     WINED3DFORMAT format;
@@ -225,5 +292,6 @@
     format = attrib->format_desc->format;
     /* Look for newly appeared conversion */
-    if (!GL_SUPPORT(ARB_HALF_FLOAT_VERTEX) && (format == WINED3DFMT_R16G16_FLOAT || format == WINED3DFMT_R16G16B16A16_FLOAT))
+    if (!gl_info->supported[ARB_HALF_FLOAT_VERTEX]
+            && (format == WINED3DFMT_R16G16_FLOAT || format == WINED3DFMT_R16G16B16A16_FLOAT))
     {
         ret = buffer_process_converted_attribute(This, CONV_FLOAT16_2, attrib, stride_this_run);
@@ -318,5 +386,6 @@
 static BOOL buffer_find_decl(struct wined3d_buffer *This)
 {
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     const struct wined3d_stream_info *si = &device->strided_streams;
     UINT stride_this_run = 0;
@@ -331,6 +400,5 @@
     if (This->flags & WINED3D_BUFFER_HASDESC)
     {
-        if(((IWineD3DImpl *)device->wineD3D)->dxVersion == 7 ||
-             This->resource.format_desc->format != WINED3DFMT_VERTEXDATA) return FALSE;
+        if(This->resource.usage & WINED3DUSAGE_STATICDECL) return FALSE;
     }
 
@@ -425,5 +493,5 @@
          * the attributes that our current fixed function pipeline implementation cares for.
          */
-        BOOL support_d3dcolor = GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA);
+        BOOL support_d3dcolor = gl_info->supported[EXT_VERTEX_ARRAY_BGRA];
         ret = buffer_check_attribute(This, si, WINED3D_FFP_POSITION,
                 TRUE, TRUE,  FALSE, &stride_this_run, &float16_used) || ret;
@@ -479,5 +547,5 @@
         if(This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
         {
-            IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_INDEXBUFFER);
+            IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER);
         }
 
@@ -614,7 +682,8 @@
     if (This->buffer_object)
     {
-        IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        IWineD3DDeviceImpl *device = This->resource.device;
+        struct wined3d_context *context;
+
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
 
         /* Download the buffer, but don't permanently enable double buffering */
@@ -631,4 +700,15 @@
         This->buffer_object = 0;
         This->flags |= WINED3D_BUFFER_CREATEBO; /* Recreate the buffer object next load */
+        buffer_clear_dirty_areas(This);
+
+        context_release(context);
+
+        HeapFree(GetProcessHeap(), 0, This->conversion_shift);
+        This->conversion_shift = NULL;
+        HeapFree(GetProcessHeap(), 0, This->conversion_map);
+        This->conversion_map = NULL;
+        This->stride = 0;
+        This->conversion_stride = 0;
+        This->flags &= ~WINED3D_BUFFER_HASDESC;
     }
 }
@@ -646,4 +726,5 @@
         resource_cleanup((IWineD3DResource *)iface);
         This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
+        HeapFree(GetProcessHeap(), 0, This->maps);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -660,9 +741,4 @@
 
 /* IWineD3DResource methods */
-
-static HRESULT STDMETHODCALLTYPE buffer_GetDevice(IWineD3DBuffer *iface, IWineD3DDevice **device)
-{
-    return resource_get_device((IWineD3DResource *)iface, device);
-}
 
 static HRESULT STDMETHODCALLTYPE buffer_SetPrivateData(IWineD3DBuffer *iface,
@@ -696,6 +772,7 @@
 {
     struct wined3d_buffer *This = (struct wined3d_buffer *)iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-    UINT start = 0, end = 0, vertices;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    UINT start = 0, end = 0, len = 0, vertices;
+    struct wined3d_context *context;
     BOOL decl_changed = FALSE;
     unsigned int i, j;
@@ -704,5 +781,5 @@
     TRACE("iface %p\n", iface);
 
-    ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
 
     if (!This->buffer_object)
@@ -716,5 +793,6 @@
         else
         {
-            return; /* Not doing any conversion */
+            /* Not doing any conversion */
+            goto end;
         }
     }
@@ -727,5 +805,12 @@
     }
 
-    if (!decl_changed && !(This->flags & WINED3D_BUFFER_HASDESC && This->flags & WINED3D_BUFFER_DIRTY)) return;
+    if (!decl_changed && !(This->flags & WINED3D_BUFFER_HASDESC && buffer_is_dirty(This)))
+    {
+        context_release(context);
+        ++This->draw_count;
+        if (This->draw_count > VB_RESETDECLCHANGE) This->decl_change_count = 0;
+        if (This->draw_count > VB_RESETFULLCONVS) This->full_conversion_count = 0;
+        return;
+    }
 
     /* If applications change the declaration over and over, reconverting all the time is a huge
@@ -735,17 +820,14 @@
     if (decl_changed)
     {
-        ++This->conversion_count;
+        ++This->decl_change_count;
         This->draw_count = 0;
 
-        if (This->conversion_count > VB_MAXDECLCHANGES)
-        {
-            FIXME("Too many declaration changes, stopping converting\n");
-
-            ENTER_GL();
-            GL_EXTCALL(glDeleteBuffersARB(1, &This->buffer_object));
-            checkGLcall("glDeleteBuffersARB");
-            LEAVE_GL();
-            This->buffer_object = 0;
-            HeapFree(GetProcessHeap(), 0, This->conversion_shift);
+        if (This->decl_change_count > VB_MAXDECLCHANGES ||
+            (This->conversion_map && (This->resource.usage & WINED3DUSAGE_DYNAMIC)))
+        {
+            FIXME("Too many declaration changes or converting dynamic buffer, stopping converting\n");
+
+            IWineD3DBuffer_UnLoad(iface);
+            This->flags &= ~WINED3D_BUFFER_CREATEBO;
 
             /* The stream source state handler might have read the memory of the vertex buffer already
@@ -755,6 +837,5 @@
              */
             IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC);
-
-            return;
+            goto end;
         }
         buffer_check_buffer_object_size(This);
@@ -766,6 +847,22 @@
          * decl changes and reset the decl change count after a specific number of them
          */
-        ++This->draw_count;
-        if (This->draw_count > VB_RESETDECLCHANGE) This->conversion_count = 0;
+        if(buffer_is_fully_dirty(This))
+        {
+            ++This->full_conversion_count;
+            if(This->full_conversion_count > VB_MAXFULLCONVERSIONS)
+            {
+                FIXME("Too many full buffer conversions, stopping converting\n");
+                IWineD3DBuffer_UnLoad(iface);
+                This->flags &= ~WINED3D_BUFFER_CREATEBO;
+                IWineD3DDeviceImpl_MarkStateDirty(device, STATE_STREAMSRC);
+                goto end;
+            }
+        }
+        else
+        {
+            ++This->draw_count;
+            if (This->draw_count > VB_RESETDECLCHANGE) This->decl_change_count = 0;
+            if (This->draw_count > VB_RESETFULLCONVS) This->full_conversion_count = 0;
+        }
     }
 
@@ -774,29 +871,15 @@
         /* The declaration changed, reload the whole buffer */
         WARN("Reloading buffer because of decl change\n");
-        start = 0;
-        end = This->resource.size;
-    }
-    else
-    {
-        /* No decl change, but dirty data, reload the changed stuff */
-        if (This->conversion_shift)
-        {
-            if (This->dirty_start != 0 || This->dirty_end != 0)
-            {
-                FIXME("Implement partial buffer loading with shifted conversion\n");
-            }
-        }
-        start = This->dirty_start;
-        end = This->dirty_end;
-    }
-
-    /* Mark the buffer clean */
-    This->flags &= ~WINED3D_BUFFER_DIRTY;
-    This->dirty_start = 0;
-    This->dirty_end = 0;
+        buffer_clear_dirty_areas(This);
+        if(!buffer_add_dirty_area(This, 0, 0))
+        {
+            ERR("buffer_add_dirty_area failed, this is not expected\n");
+            return;
+        }
+    }
 
     if(This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
     {
-        IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_INDEXBUFFER);
+        IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER);
     }
 
@@ -810,16 +893,24 @@
 
         /* Nothing to do because we locked directly into the vbo */
-        if(!(This->flags & WINED3D_BUFFER_DOUBLEBUFFER)) return;
-
-        if (!device->isInDraw)
-        {
-            ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-        }
+        if (!(This->flags & WINED3D_BUFFER_DOUBLEBUFFER))
+        {
+            context_release(context);
+            return;
+        }
+
         ENTER_GL();
         GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
         checkGLcall("glBindBufferARB");
-        GL_EXTCALL(glBufferSubDataARB(This->buffer_type_hint, start, end-start, This->resource.allocatedMemory + start));
-        checkGLcall("glBufferSubDataARB");
+        while(This->modified_areas)
+        {
+            This->modified_areas--;
+            start = This->maps[This->modified_areas].offset;
+            len = This->maps[This->modified_areas].size;
+            GL_EXTCALL(glBufferSubDataARB(This->buffer_type_hint, start, len, This->resource.allocatedMemory + start));
+            checkGLcall("glBufferSubDataARB");
+        }
         LEAVE_GL();
+
+        context_release(context);
         return;
     }
@@ -837,4 +928,13 @@
         TRACE("Shifted conversion\n");
         data = HeapAlloc(GetProcessHeap(), 0, vertices * This->conversion_stride);
+
+        start = 0;
+        len = This->resource.size;
+        end = start + len;
+
+        if (This->maps[0].offset || This->maps[0].size != This->resource.size)
+        {
+            FIXME("Implement partial buffer load with shifted conversion\n");
+        }
 
         for (i = start / This->stride; i < min((end / This->stride) + 1, vertices); ++i)
@@ -877,42 +977,54 @@
     {
         data = HeapAlloc(GetProcessHeap(), 0, This->resource.size);
-        memcpy(data + start, This->resource.allocatedMemory + start, end - start);
-        for (i = start / This->stride; i < min((end / This->stride) + 1, vertices); ++i)
-        {
-            for (j = 0; j < This->stride; ++j)
+
+        while(This->modified_areas)
+        {
+            This->modified_areas--;
+            start = This->maps[This->modified_areas].offset;
+            len = This->maps[This->modified_areas].size;
+            end = start + len;
+
+            memcpy(data + start, This->resource.allocatedMemory + start, end - start);
+            for (i = start / This->stride; i < min((end / This->stride) + 1, vertices); ++i)
             {
-                switch(This->conversion_map[j])
+                for (j = 0; j < This->stride; ++j)
                 {
-                    case CONV_NONE:
-                        /* Done already */
-                        j += 3;
-                        break;
-                    case CONV_D3DCOLOR:
-                        fixup_d3dcolor((DWORD *) (data + i * This->stride + j));
-                        j += 3;
-                        break;
-
-                    case CONV_POSITIONT:
-                        fixup_transformed_pos((float *) (data + i * This->stride + j));
-                        j += 15;
-                        break;
-
-                    case CONV_FLOAT16_2:
-                        ERR("Did not expect FLOAT16 conversion in unshifted conversion\n");
-                    default:
-                        FIXME("Unimplemented conversion %d in shifted conversion\n", This->conversion_map[j]);
+                    switch(This->conversion_map[j])
+                    {
+                        case CONV_NONE:
+                            /* Done already */
+                            j += 3;
+                            break;
+                        case CONV_D3DCOLOR:
+                            fixup_d3dcolor((DWORD *) (data + i * This->stride + j));
+                            j += 3;
+                            break;
+
+                        case CONV_POSITIONT:
+                            fixup_transformed_pos((float *) (data + i * This->stride + j));
+                            j += 15;
+                            break;
+
+                        case CONV_FLOAT16_2:
+                            ERR("Did not expect FLOAT16 conversion in unshifted conversion\n");
+                        default:
+                            FIXME("Unimplemented conversion %d in shifted conversion\n", This->conversion_map[j]);
+                    }
                 }
             }
-        }
-
-        ENTER_GL();
-        GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
-        checkGLcall("glBindBufferARB");
-        GL_EXTCALL(glBufferSubDataARB(This->buffer_type_hint, start, end - start, data + start));
-        checkGLcall("glBufferSubDataARB");
-        LEAVE_GL();
+
+            ENTER_GL();
+            GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
+            checkGLcall("glBindBufferARB");
+            GL_EXTCALL(glBufferSubDataARB(This->buffer_type_hint, start, len, data + start));
+            checkGLcall("glBufferSubDataARB");
+            LEAVE_GL();
+        }
     }
 
     HeapFree(GetProcessHeap(), 0, data);
+
+end:
+    context_release(context);
 }
 
@@ -931,47 +1043,27 @@
     TRACE("iface %p, offset %u, size %u, data %p, flags %#x\n", iface, offset, size, data, flags);
 
+    if (!buffer_add_dirty_area(This, offset, size)) return E_OUTOFMEMORY;
+
     count = InterlockedIncrement(&This->lock_count);
 
-    if (This->flags & WINED3D_BUFFER_DIRTY)
-    {
-        if (This->dirty_start > offset) This->dirty_start = offset;
-
-        if (size)
-        {
-            if (This->dirty_end < offset + size) This->dirty_end = offset + size;
-        }
-        else
-        {
-            This->dirty_end = This->resource.size;
-        }
-    }
-    else
-    {
-        This->dirty_start = offset;
-        if (size) This->dirty_end = offset + size;
-        else This->dirty_end = This->resource.size;
-    }
-
     if(!(This->flags & WINED3D_BUFFER_DOUBLEBUFFER) && This->buffer_object)
     {
         if(count == 1)
         {
-            IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+            IWineD3DDeviceImpl *device = This->resource.device;
+            struct wined3d_context *context;
 
             if(This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
             {
-                IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_INDEXBUFFER);
+                IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER);
             }
 
-            ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+            context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
             ENTER_GL();
             GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
             This->resource.allocatedMemory = GL_EXTCALL(glMapBufferARB(This->buffer_type_hint, GL_READ_WRITE_ARB));
             LEAVE_GL();
-        }
-    }
-    else
-    {
-        This->flags |= WINED3D_BUFFER_DIRTY;
+            context_release(context);
+        }
     }
 
@@ -987,4 +1079,5 @@
 {
     struct wined3d_buffer *This = (struct wined3d_buffer *)iface;
+    ULONG i;
 
     TRACE("(%p)\n", This);
@@ -1009,18 +1102,33 @@
     if(!(This->flags & WINED3D_BUFFER_DOUBLEBUFFER) && This->buffer_object)
     {
-        IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+        IWineD3DDeviceImpl *device = This->resource.device;
+        struct wined3d_context *context;
 
         if(This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
         {
-            IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_INDEXBUFFER);
-        }
-
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+            IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER);
+        }
+
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
         GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object));
+
+        if(This->flags & WINED3D_BUFFER_FLUSH)
+        {
+            for(i = 0; i < This->modified_areas; i++)
+            {
+                GL_EXTCALL(glFlushMappedBufferRangeAPPLE(This->buffer_type_hint,
+                                                         This->maps[i].offset,
+                                                         This->maps[i].size));
+                checkGLcall("glFlushMappedBufferRangeAPPLE");
+            }
+        }
+
         GL_EXTCALL(glUnmapBufferARB(This->buffer_type_hint));
         LEAVE_GL();
+        context_release(context);
 
         This->resource.allocatedMemory = NULL;
+        buffer_clear_dirty_areas(This);
     }
     else if (This->flags & WINED3D_BUFFER_HASDESC)
@@ -1055,5 +1163,4 @@
     buffer_GetParent,
     /* IWineD3DResource methods */
-    buffer_GetDevice,
     buffer_SetPrivateData,
     buffer_GetPrivateData,
@@ -1076,4 +1183,6 @@
     const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, &device->adapter->gl_info);
     HRESULT hr;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    BOOL dynamic_buffer_ok;
 
     if (!size)
@@ -1096,4 +1205,31 @@
     TRACE("size %#x, usage %#x, format %s, memory @ %p, iface @ %p.\n", buffer->resource.size, buffer->resource.usage,
             debug_d3dformat(buffer->resource.format_desc->format), buffer->resource.allocatedMemory, buffer);
+
+    /* TODO: GL_ARB_map_buffer_range */
+    dynamic_buffer_ok = gl_info->supported[APPLE_FLUSH_BUFFER_RANGE];
+
+    /* Observations show that drawStridedSlow is faster on dynamic VBs than converting +
+     * drawStridedFast (half-life 2 and others).
+     *
+     * Basically converting the vertices in the buffer is quite expensive, and observations
+     * show that drawStridedSlow is faster than converting + uploading + drawStridedFast.
+     * Therefore do not create a VBO for WINED3DUSAGE_DYNAMIC buffers.
+     */
+    if (!gl_info->supported[ARB_VERTEX_BUFFER_OBJECT])
+    {
+        TRACE("Not creating a vbo because GL_ARB_vertex_buffer is not supported\n");
+    }
+    else if(buffer->resource.pool == WINED3DPOOL_SYSTEMMEM)
+    {
+        TRACE("Not creating a vbo because the vertex buffer is in system memory\n");
+    }
+    else if(!dynamic_buffer_ok && (buffer->resource.usage & WINED3DUSAGE_DYNAMIC))
+    {
+        TRACE("Not creating a vbo because the buffer has dynamic usage and no GL support\n");
+    }
+    else
+    {
+        buffer->flags |= WINED3D_BUFFER_CREATEBO;
+    }
 
     if (data)
@@ -1122,4 +1258,14 @@
     }
 
+    buffer->maps = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->maps));
+    if (!buffer->maps)
+    {
+        ERR("Out of memory\n");
+        buffer_UnLoad((IWineD3DBuffer *)buffer);
+        resource_cleanup((IWineD3DResource *)buffer);
+        return E_OUTOFMEMORY;
+    }
+    buffer->maps_size = 1;
+
     return WINED3D_OK;
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/clipper.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/clipper.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/clipper.c	(revision 25949)
@@ -38,20 +38,21 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
 
-static HRESULT WINAPI IWineD3DClipperImpl_QueryInterface(IWineD3DClipper *iface, REFIID riid, void **Obj)
-{
-    IWineD3DClipperImpl *This = (IWineD3DClipperImpl *)iface;
-
-    TRACE("(%p)->(%p,%p)\n", This, riid, Obj);
-    if (IsEqualGUID(&IID_IUnknown, riid)
-        || IsEqualGUID(&IID_IWineD3DClipper, riid))
-    {
-        *Obj = iface;
-        IWineD3DClipper_AddRef(iface);
+static HRESULT WINAPI IWineD3DClipperImpl_QueryInterface(IWineD3DClipper *iface, REFIID riid, void **object)
+{
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
+
+    if (IsEqualGUID(riid, &IID_IWineD3DClipper)
+            || IsEqualGUID(riid, &IID_IWineD3DBase)
+            || IsEqualGUID(riid, &IID_IUnknown))
+    {
+        IUnknown_AddRef(iface);
+        *object = iface;
         return S_OK;
     }
-    else
-    {
-        return E_NOINTERFACE;
-    }
+
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *object = NULL;
+    return E_NOINTERFACE;
 }
 
@@ -153,9 +154,9 @@
 static HRESULT WINAPI IWineD3DClipperImpl_SetClipList(IWineD3DClipper *iface, const RGNDATA *rgn, DWORD Flags)
 {
-    IWineD3DClipperImpl *This = (IWineD3DClipperImpl *)iface;
     static int warned = 0;
 
     if (warned++ < 10 || rgn == NULL)
-        FIXME("(%p,%p,%d),stub!\n",This,rgn,Flags);
+        FIXME("iface %p, region %p, flags %#x stub!\n", iface, rgn, Flags);
+
     return WINED3D_OK;
 }
@@ -172,6 +173,5 @@
 static HRESULT WINAPI IWineD3DClipperImpl_IsClipListChanged(IWineD3DClipper *iface, BOOL *changed)
 {
-    IWineD3DClipperImpl *This = (IWineD3DClipperImpl *)iface;
-    FIXME("(%p)->(%p),stub!\n",This,changed);
+    FIXME("iface %p, changed %p stub!\n", iface, changed);
 
     /* XXX What is safest? */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 25949)
@@ -98,5 +98,5 @@
     unsigned int i;
 
-    for (i = 0; i < GL_LIMITS(buffers); ++i)
+    for (i = 0; i < gl_info->limits.buffers; ++i)
     {
         gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, 0, 0);
@@ -127,5 +127,5 @@
 {
     const IWineD3DSurfaceImpl *surface_impl = (IWineD3DSurfaceImpl *)surface;
-    IWineD3DDeviceImpl *device = surface_impl->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = surface_impl->resource.device;
     IWineD3DBaseTextureImpl *texture_impl;
     BOOL update_minfilter = FALSE;
@@ -298,25 +298,28 @@
         FIXME("FBO status %s (%#x)\n", debug_fbostatus(status), status);
 
-        if (context->current_fbo)
-        {
-            /* Dump the FBO attachments */
-            for (i = 0; i < GL_LIMITS(buffers); ++i)
-            {
-                attachment = (IWineD3DSurfaceImpl *)context->current_fbo->render_targets[i];
-                if (attachment)
-                {
-                    FIXME("\tColor attachment %d: (%p) %s %ux%u\n",
-                            i, attachment, debug_d3dformat(attachment->resource.format_desc->format),
-                            attachment->pow2Width, attachment->pow2Height);
-                }
-            }
-            attachment = (IWineD3DSurfaceImpl *)context->current_fbo->depth_stencil;
+        if (!context->current_fbo)
+        {
+            ERR("FBO 0 is incomplete, driver bug?\n");
+            return;
+        }
+
+        /* Dump the FBO attachments */
+        for (i = 0; i < gl_info->limits.buffers; ++i)
+        {
+            attachment = (IWineD3DSurfaceImpl *)context->current_fbo->render_targets[i];
             if (attachment)
             {
-                FIXME("\tDepth attachment: (%p) %s %ux%u\n",
-                        attachment, debug_d3dformat(attachment->resource.format_desc->format),
+                FIXME("\tColor attachment %d: (%p) %s %ux%u\n",
+                        i, attachment, debug_d3dformat(attachment->resource.format_desc->format),
                         attachment->pow2Width, attachment->pow2Height);
             }
         }
+        attachment = (IWineD3DSurfaceImpl *)context->current_fbo->depth_stencil;
+        if (attachment)
+        {
+            FIXME("\tDepth attachment: (%p) %s %ux%u\n",
+                    attachment, debug_d3dformat(attachment->resource.format_desc->format),
+                    attachment->pow2Width, attachment->pow2Height);
+        }
     }
 }
@@ -324,11 +327,11 @@
 static struct fbo_entry *context_create_fbo_entry(struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
     struct fbo_entry *entry;
 
     entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
-    entry->render_targets = HeapAlloc(GetProcessHeap(), 0, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
-    memcpy(entry->render_targets, device->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
+    entry->render_targets = HeapAlloc(GetProcessHeap(), 0, gl_info->limits.buffers * sizeof(*entry->render_targets));
+    memcpy(entry->render_targets, device->render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets));
     entry->depth_stencil = device->stencilBufferTarget;
     entry->attached = FALSE;
@@ -341,5 +344,5 @@
 static void context_reuse_fbo_entry(struct wined3d_context *context, struct fbo_entry *entry)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
 
@@ -347,5 +350,5 @@
     context_clean_fbo_attachments(gl_info);
 
-    memcpy(entry->render_targets, device->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
+    memcpy(entry->render_targets, device->render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets));
     entry->depth_stencil = device->stencilBufferTarget;
     entry->attached = FALSE;
@@ -370,5 +373,5 @@
 static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
     struct fbo_entry *entry;
@@ -376,5 +379,6 @@
     LIST_FOR_EACH_ENTRY(entry, &context->fbo_list, struct fbo_entry, entry)
     {
-        if (!memcmp(entry->render_targets, device->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets))
+        if (!memcmp(entry->render_targets,
+                device->render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets))
                 && entry->depth_stencil == device->stencilBufferTarget)
         {
@@ -405,5 +409,5 @@
 static void context_apply_fbo_entry(struct wined3d_context *context, struct fbo_entry *entry)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
     unsigned int i;
@@ -414,5 +418,5 @@
     {
         /* Apply render targets */
-        for (i = 0; i < GL_LIMITS(buffers); ++i)
+        for (i = 0; i < gl_info->limits.buffers; ++i)
         {
             IWineD3DSurface *render_target = device->render_targets[i];
@@ -431,6 +435,8 @@
 
         entry->attached = TRUE;
-    } else {
-        for (i = 0; i < GL_LIMITS(buffers); ++i)
+    }
+    else
+    {
+        for (i = 0; i < gl_info->limits.buffers; ++i)
         {
             if (device->render_targets[i])
@@ -441,5 +447,5 @@
     }
 
-    for (i = 0; i < GL_LIMITS(buffers); ++i)
+    for (i = 0; i < gl_info->limits.buffers; ++i)
     {
         if (device->render_targets[i])
@@ -453,4 +459,11 @@
 static void context_apply_fbo_state(struct wined3d_context *context)
 {
+    struct fbo_entry *entry, *entry2;
+
+    LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_destroy_list, struct fbo_entry, entry)
+    {
+        context_destroy_fbo_entry(context, entry);
+    }
+
     if (context->render_offscreen)
     {
@@ -462,5 +475,7 @@
     }
 
-    /*context_check_fbo_status(context);*/
+#ifdef DEBUG
+    context_check_fbo_status(context);
+#endif
 }
 
@@ -476,5 +491,5 @@
     else
     {
-        if (GL_SUPPORT(ARB_OCCLUSION_QUERY))
+        if (gl_info->supported[ARB_OCCLUSION_QUERY])
         {
             ENTER_GL();
@@ -533,5 +548,5 @@
     else
     {
-        if (GL_SUPPORT(APPLE_FENCE))
+        if (gl_info->supported[APPLE_FENCE])
         {
             ENTER_GL();
@@ -542,5 +557,5 @@
             TRACE("Allocated event query %u in context %p.\n", query->id, context);
         }
-        else if(GL_SUPPORT(NV_FENCE))
+        else if(gl_info->supported[NV_FENCE])
         {
             ENTER_GL();
@@ -599,6 +614,4 @@
         case WINED3DRTYPE_SURFACE:
         {
-            ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
-
             for (i = 0; i < This->numContexts; ++i)
             {
@@ -609,25 +622,25 @@
                 if (context->current_rt == (IWineD3DSurface *)resource) context->current_rt = NULL;
 
-                ENTER_GL();
-
                 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_list, struct fbo_entry, entry)
                 {
-                    BOOL destroyed = FALSE;
                     UINT j;
 
-                    for (j = 0; !destroyed && j < GL_LIMITS(buffers); ++j)
+                    if (entry->depth_stencil == (IWineD3DSurface *)resource)
+                    {
+                        list_remove(&entry->entry);
+                        list_add_head(&context->fbo_destroy_list, &entry->entry);
+                        continue;
+                    }
+
+                    for (j = 0; j < gl_info->limits.buffers; ++j)
                     {
                         if (entry->render_targets[j] == (IWineD3DSurface *)resource)
                         {
-                            context_destroy_fbo_entry(context, entry);
-                            destroyed = TRUE;
+                            list_remove(&entry->entry);
+                            list_add_head(&context->fbo_destroy_list, &entry->entry);
+                            break;
                         }
                     }
-
-                    if (!destroyed && entry->depth_stencil == (IWineD3DSurface *)resource)
-                        context_destroy_fbo_entry(context, entry);
                 }
-
-                LEAVE_GL();
             }
 
@@ -637,4 +650,16 @@
         default:
             break;
+    }
+}
+
+static void context_validate(struct wined3d_context *context)
+{
+    HWND wnd = WindowFromDC(context->hdc);
+
+    if (wnd != context->win_handle)
+    {
+        WARN("DC %p belongs to window %p instead of %p.\n",
+                context->hdc, wnd, context->win_handle);
+        context->valid = 0;
     }
 }
@@ -646,8 +671,13 @@
     struct wined3d_event_query *event_query;
     struct fbo_entry *entry, *entry2;
-    BOOL has_glctx;
-
-    has_glctx = pwglMakeCurrent(context->hdc, context->glCtx);
-    if (!has_glctx) WARN("Failed to activate context. Window already destroyed?\n");
+    HGLRC restore_ctx;
+    HDC restore_dc;
+
+    restore_ctx = pwglGetCurrentContext();
+    restore_dc = pwglGetCurrentDC();
+
+    context_validate(context);
+    if (context->valid && restore_ctx != context->glCtx) pwglMakeCurrent(context->hdc, context->glCtx);
+    else restore_ctx = NULL;
 
     ENTER_GL();
@@ -655,5 +685,6 @@
     LIST_FOR_EACH_ENTRY(occlusion_query, &context->occlusion_queries, struct wined3d_occlusion_query, entry)
     {
-        if (has_glctx && GL_SUPPORT(ARB_OCCLUSION_QUERY)) GL_EXTCALL(glDeleteQueriesARB(1, &occlusion_query->id));
+        if (context->valid && gl_info->supported[ARB_OCCLUSION_QUERY])
+            GL_EXTCALL(glDeleteQueriesARB(1, &occlusion_query->id));
         occlusion_query->context = NULL;
     }
@@ -661,17 +692,25 @@
     LIST_FOR_EACH_ENTRY(event_query, &context->event_queries, struct wined3d_event_query, entry)
     {
-        if (has_glctx)
-        {
-            if (GL_SUPPORT(APPLE_FENCE)) GL_EXTCALL(glDeleteFencesAPPLE(1, &event_query->id));
-            else if (GL_SUPPORT(NV_FENCE)) GL_EXTCALL(glDeleteFencesNV(1, &event_query->id));
+        if (context->valid)
+        {
+            if (gl_info->supported[APPLE_FENCE]) GL_EXTCALL(glDeleteFencesAPPLE(1, &event_query->id));
+            else if (gl_info->supported[NV_FENCE]) GL_EXTCALL(glDeleteFencesNV(1, &event_query->id));
         }
         event_query->context = NULL;
     }
 
-    LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_list, struct fbo_entry, entry) {
-        if (!has_glctx) entry->id = 0;
+    LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_destroy_list, struct fbo_entry, entry)
+    {
+        if (!context->valid) entry->id = 0;
         context_destroy_fbo_entry(context, entry);
     }
-    if (has_glctx)
+
+    LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_list, struct fbo_entry, entry)
+    {
+        if (!context->valid) entry->id = 0;
+        context_destroy_fbo_entry(context, entry);
+    }
+
+    if (context->valid)
     {
         if (context->src_fbo)
@@ -690,10 +729,10 @@
         }
 
-        if (GL_SUPPORT(ARB_OCCLUSION_QUERY))
+        if (gl_info->supported[ARB_OCCLUSION_QUERY])
             GL_EXTCALL(glDeleteQueriesARB(context->free_occlusion_query_count, context->free_occlusion_queries));
 
-        if (GL_SUPPORT(APPLE_FENCE))
+        if (gl_info->supported[APPLE_FENCE])
             GL_EXTCALL(glDeleteFencesAPPLE(context->free_event_query_count, context->free_event_queries));
-        else if (GL_SUPPORT(NV_FENCE))
+        else if (gl_info->supported[NV_FENCE])
             GL_EXTCALL(glDeleteFencesNV(context->free_event_query_count, context->free_event_queries));
 
@@ -706,10 +745,19 @@
     HeapFree(GetProcessHeap(), 0, context->free_event_queries);
 
-    if (!pwglMakeCurrent(NULL, NULL))
+    if (restore_ctx)
+    {
+        if (!pwglMakeCurrent(restore_dc, restore_ctx))
+        {
+            DWORD err = GetLastError();
+            ERR("Failed to restore GL context %p on device context %p, last error %#x.\n",
+                    restore_ctx, restore_dc, err);
+        }
+    }
+    else if (pwglGetCurrentContext() && !pwglMakeCurrent(NULL, NULL))
     {
         ERR("Failed to disable GL context.\n");
     }
 
-    if (context->isPBuffer)
+    if (context->pbuffer)
     {
         GL_EXTCALL(wglReleasePbufferDCARB(context->pbuffer, context->hdc));
@@ -795,4 +843,49 @@
 }
 
+void context_release(struct wined3d_context *context)
+{
+    TRACE("Releasing context %p, level %u.\n", context, context->level);
+
+    if (WARN_ON(d3d))
+    {
+        if (!context->level)
+            WARN("Context %p is not active.\n", context);
+        else if (context != context_get_current())
+            WARN("Context %p is not the current context.\n", context);
+    }
+
+    if (!--context->level && context->restore_ctx)
+    {
+        TRACE("Restoring GL context %p on device context %p.\n", context->restore_ctx, context->restore_dc);
+        if (!pwglMakeCurrent(context->restore_dc, context->restore_ctx))
+        {
+            DWORD err = GetLastError();
+            ERR("Failed to restore GL context %p on device context %p, last error %#x.\n",
+                    context->restore_ctx, context->restore_dc, err);
+        }
+        context->restore_ctx = NULL;
+        context->restore_dc = NULL;
+    }
+}
+
+static void context_enter(struct wined3d_context *context)
+{
+    TRACE("Entering context %p, level %u.\n", context, context->level + 1);
+
+    if (!context->level++)
+    {
+        const struct wined3d_context *current_context = context_get_current();
+        HGLRC current_gl = pwglGetCurrentContext();
+
+        if (current_gl && (!current_context || current_context->glCtx != current_gl))
+        {
+            TRACE("Another GL context (%p on device context %p) is already current.\n",
+                    current_gl, pwglGetCurrentDC());
+            context->restore_ctx = current_gl;
+            context->restore_dc = pwglGetCurrentDC();
+        }
+    }
+}
+
 /*****************************************************************************
  * Context_MarkStateDirty
@@ -817,6 +910,6 @@
 
     context->dirtyArray[context->numDirtyEntries++] = rep;
-    idx = rep >> 5;
-    shift = rep & 0x1f;
+    idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
+    shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
     context->isStateDirty[idx] |= (1 << shift);
 }
@@ -825,5 +918,5 @@
  * AddContextToArray
  *
- * Adds a context to the context array. Helper function for CreateContext
+ * Adds a context to the context array. Helper function for context_create().
  *
  * This method is not called in performance-critical code paths, only when a
@@ -935,8 +1028,8 @@
      * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
      * issue needs to be fixed. */
-    if (ds_format_desc->format != WINED3DFMT_S8_UINT_D24_UNORM)
+    if (ds_format_desc->format != WINED3DFMT_D24_UNORM_S8_UINT)
     {
         FIXME("Add OpenGL context recreation support to SetDepthStencilSurface\n");
-        ds_format_desc = getFormatDescEntry(WINED3DFMT_S8_UINT_D24_UNORM, &This->adapter->gl_info);
+        ds_format_desc = getFormatDescEntry(WINED3DFMT_D24_UNORM_S8_UINT, &This->adapter->gl_info);
     }
 
@@ -1059,5 +1152,5 @@
 
 /*****************************************************************************
- * CreateContext
+ * context_create
  *
  * Creates a new context for a window, or a pbuffer context.
@@ -1071,5 +1164,5 @@
  *
  *****************************************************************************/
-struct wined3d_context *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target,
+struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target,
         HWND win_handle, BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms)
 {
@@ -1173,8 +1266,9 @@
         /* D3D only allows multisampling when SwapEffect is set to WINED3DSWAPEFFECT_DISCARD */
         if(pPresentParms->MultiSampleType && (pPresentParms->SwapEffect == WINED3DSWAPEFFECT_DISCARD)) {
-            if(!GL_SUPPORT(ARB_MULTISAMPLE))
+            if (!gl_info->supported[ARB_MULTISAMPLE])
                 ERR("The program is requesting multisampling without support!\n");
-            else {
-                ERR("Requesting MultiSampleType=%d\n", pPresentParms->MultiSampleType);
+            else
+            {
+                TRACE("Requesting multisample type %#x.\n", pPresentParms->MultiSampleType);
                 numSamples = pPresentParms->MultiSampleType;
             }
@@ -1209,5 +1303,7 @@
             if(oldPixelFormat == iPixelFormat) {
                 /* We don't have to do anything as the formats are the same :) */
-            } else if(oldPixelFormat && GL_SUPPORT(WGL_WINE_PIXEL_FORMAT_PASSTHROUGH)) {
+            }
+            else if (oldPixelFormat && gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH])
+            {
                 res = GL_EXTCALL(wglSetPixelFormatWINE(hdc, iPixelFormat, NULL));
 
@@ -1260,19 +1356,21 @@
         goto out;
     }
+    ret->valid = 1;
     ret->gl_info = &This->adapter->gl_info;
     ret->surface = (IWineD3DSurface *) target;
     ret->current_rt = (IWineD3DSurface *)target;
-    ret->isPBuffer = create_pbuffer;
+    ret->render_offscreen = surface_is_offscreen((IWineD3DSurface *) target);
+    ret->draw_buffer_dirty = TRUE;
     ret->tid = GetCurrentThreadId();
     if(This->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) This)) {
         /* Create the dirty constants array and initialize them to dirty */
         ret->vshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
-                sizeof(*ret->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
+                sizeof(*ret->vshader_const_dirty) * This->d3d_vshader_constantF);
         ret->pshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
-                sizeof(*ret->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
+                sizeof(*ret->pshader_const_dirty) * This->d3d_pshader_constantF);
         memset(ret->vshader_const_dirty, 1,
-               sizeof(*ret->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
+               sizeof(*ret->vshader_const_dirty) * This->d3d_vshader_constantF);
         memset(ret->pshader_const_dirty, 1,
-                sizeof(*ret->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
+                sizeof(*ret->pshader_const_dirty) * This->d3d_pshader_constantF);
     }
 
@@ -1294,4 +1392,7 @@
 
     list_init(&ret->fbo_list);
+    list_init(&ret->fbo_destroy_list);
+
+    context_enter(ret);
 
     /* Set up the context defaults */
@@ -1299,4 +1400,5 @@
     {
         ERR("Cannot activate context to set up defaults\n");
+        context_release(ret);
         goto out;
     }
@@ -1330,5 +1432,6 @@
     checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, This->surface_alignment);");
 
-    if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
+    if (gl_info->supported[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).
@@ -1337,5 +1440,6 @@
         checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
     }
-    if(GL_SUPPORT(ARB_VERTEX_BLEND)) {
+    if (gl_info->supported[ARB_VERTEX_BLEND])
+    {
         /* Direct3D always uses n-1 weights for n world matrices and uses 1 - sum for the last one
          * this is equal to GL_WEIGHT_SUM_UNITY_ARB. Enabling it doesn't do anything unless
@@ -1345,9 +1449,11 @@
         checkGLcall("glEnable(GL_WEIGHT_SUM_UNITY_ARB)");
     }
-    if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
+    if (gl_info->supported[NV_TEXTURE_SHADER2])
+    {
         /* Set up the previous texture input for all shader units. This applies to bump mapping, and in d3d
          * the previous texture where to source the offset from is always unit - 1.
          */
-        for(s = 1; s < GL_LIMITS(textures); s++) {
+        for (s = 1; s < gl_info->limits.textures; ++s)
+        {
             GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
             glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1);
@@ -1355,5 +1461,6 @@
         }
     }
-    if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
+    if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
+    {
         /* MacOS(radeon X1600 at least, but most likely others too) refuses to draw if GLSL and ARBFP are
          * enabled, but the currently bound arbfp program is 0. Enabling ARBFP with prog 0 is invalid, but
@@ -1374,5 +1481,6 @@
     }
 
-    for(s = 0; s < GL_LIMITS(point_sprite_units); s++) {
+    for (s = 0; s < gl_info->limits.point_sprite_units; ++s)
+    {
         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
         glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
@@ -1380,9 +1488,9 @@
     }
 
-    if (GL_SUPPORT(ARB_PROVOKING_VERTEX))
+    if (gl_info->supported[ARB_PROVOKING_VERTEX])
     {
         GL_EXTCALL(glProvokingVertex(GL_FIRST_VERTEX_CONVENTION));
     }
-    else if (GL_SUPPORT(EXT_PROVOKING_VERTEX))
+    else if (gl_info->supported[EXT_PROVOKING_VERTEX])
     {
         GL_EXTCALL(glProvokingVertexEXT(GL_FIRST_VERTEX_CONVENTION_EXT));
@@ -1414,5 +1522,5 @@
  *
  * Similar to the former call this isn't a performance critical function. A
- * helper function for DestroyContext.
+ * helper function for context_destroy().
  *
  * Params:
@@ -1469,7 +1577,7 @@
 
 /*****************************************************************************
- * DestroyContext
- *
- * Destroys a wineD3DContext
+ * context_destroy
+ *
+ * Destroys a wined3d context
  *
  * Params:
@@ -1478,5 +1586,5 @@
  *
  *****************************************************************************/
-void DestroyContext(IWineD3DDeviceImpl *This, struct wined3d_context *context)
+void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context)
 {
     BOOL destroy;
@@ -1487,10 +1595,6 @@
     {
         context_destroy_gl_resources(context);
+        TlsSetValue(wined3d_context_tls_idx, NULL);
         destroy = TRUE;
-
-        if (!context_set_current(NULL))
-        {
-            ERR("Failed to clear current D3D context.\n");
-        }
     }
     else
@@ -1532,14 +1636,14 @@
  *  This: Device to activate the context for
  *  context: Context to setup
- *  width: render target width
- *  height: render target height
  *
  *****************************************************************************/
 /* Context activation is done by the caller. */
-static inline void SetupForBlit(IWineD3DDeviceImpl *This, struct wined3d_context *context, UINT width, UINT height)
+static void SetupForBlit(IWineD3DDeviceImpl *This, struct wined3d_context *context)
 {
     int i;
     const struct StateEntry *StateTable = This->StateTable;
     const struct wined3d_gl_info *gl_info = context->gl_info;
+    UINT width = ((IWineD3DSurfaceImpl *)context->current_rt)->currentDesc.Width;
+    UINT height = ((IWineD3DSurfaceImpl *)context->current_rt)->currentDesc.Height;
     DWORD sampler;
 
@@ -1584,10 +1688,12 @@
      * function texture unit. No need to care for higher samplers
      */
-    for(i = GL_LIMITS(textures) - 1; i > 0 ; i--) {
+    for (i = gl_info->limits.textures - 1; i > 0 ; --i)
+    {
         sampler = This->rev_tex_unit_map[i];
         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
         checkGLcall("glActiveTextureARB");
 
-        if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+        if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+        {
             glDisable(GL_TEXTURE_CUBE_MAP_ARB);
             checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
@@ -1595,5 +1701,6 @@
         glDisable(GL_TEXTURE_3D);
         checkGLcall("glDisable GL_TEXTURE_3D");
-        if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+        if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+        {
             glDisable(GL_TEXTURE_RECTANGLE_ARB);
             checkGLcall("glDisable GL_TEXTURE_RECTANGLE_ARB");
@@ -1618,5 +1725,6 @@
     sampler = This->rev_tex_unit_map[0];
 
-    if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+    if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+    {
         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
         checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
@@ -1624,5 +1732,6 @@
     glDisable(GL_TEXTURE_3D);
     checkGLcall("glDisable GL_TEXTURE_3D");
-    if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+    if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+    {
         glDisable(GL_TEXTURE_RECTANGLE_ARB);
         checkGLcall("glDisable GL_TEXTURE_RECTANGLE_ARB");
@@ -1638,5 +1747,6 @@
     checkGLcall("glLoadIdentity()");
 
-    if (GL_SUPPORT(EXT_TEXTURE_LOD_BIAS)) {
+    if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
+    {
         glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
                   GL_TEXTURE_LOD_BIAS_EXT,
@@ -1679,5 +1789,6 @@
     checkGLcall("glDisable GL_SCISSOR_TEST");
     Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), StateTable);
-    if(GL_SUPPORT(ARB_POINT_SPRITE)) {
+    if (gl_info->supported[ARB_POINT_SPRITE])
+    {
         glDisable(GL_POINT_SPRITE_ARB);
         checkGLcall("glDisable GL_POINT_SPRITE_ARB");
@@ -1687,5 +1798,6 @@
     checkGLcall("glColorMask");
     Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE), StateTable);
-    if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+    if (gl_info->supported[EXT_SECONDARY_COLOR])
+    {
         glDisable(GL_COLOR_SUM_EXT);
         Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SPECULARENABLE), StateTable);
@@ -1742,5 +1854,5 @@
 
     /* Create a new context for the thread */
-    return IWineD3DSwapChainImpl_CreateContextForThread(swapchain);
+    return swapchain_create_context_for_thread(swapchain);
 }
 
@@ -1757,9 +1869,10 @@
  *
  *****************************************************************************/
-static inline struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid)
+static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target)
 {
     IWineD3DSwapChain *swapchain = NULL;
     struct wined3d_context *current_context = context_get_current();
     const struct StateEntry *StateTable = This->StateTable;
+    DWORD tid = GetCurrentThreadId();
     struct wined3d_context *context;
     BOOL old_render_offscreen;
@@ -1771,5 +1884,5 @@
         if (current_context
                 && current_context->current_rt
-                && ((IWineD3DSurfaceImpl *)current_context->surface)->resource.wineD3DDevice == This)
+                && ((IWineD3DSurfaceImpl *)current_context->surface)->resource.device == This)
         {
             target = current_context->current_rt;
@@ -1785,4 +1898,5 @@
     if (current_context && current_context->current_rt == target)
     {
+        context_validate(current_context);
         return current_context;
     }
@@ -1794,5 +1908,5 @@
 
         old_render_offscreen = context->render_offscreen;
-        context->render_offscreen = FALSE;
+        context->render_offscreen = surface_is_offscreen(target);
         /* The context != This->activeContext will catch a NOP context change. This can occur
          * if we are switching back to swapchain rendering in case of FBO or Back Buffer offscreen
@@ -1819,15 +1933,16 @@
                     || This->pbufferHeight < targetimpl->currentDesc.Height)
             {
-                if (This->pbufferContext) DestroyContext(This, This->pbufferContext);
+                if (This->pbufferContext) context_destroy(This, This->pbufferContext);
 
                 /* The display is irrelevant here, the window is 0. But
-                 * CreateContext needs a valid X connection. Create the context
+                 * context_create() needs a valid X connection. Create the context
                  * on the same server as the primary swapchain. The primary
                  * swapchain is exists at this point. */
-                This->pbufferContext = CreateContext(This, targetimpl,
+                This->pbufferContext = context_create(This, targetimpl,
                         ((IWineD3DSwapChainImpl *)This->swapchains[0])->context[0]->win_handle,
                         TRUE /* pbuffer */, &((IWineD3DSwapChainImpl *)This->swapchains[0])->presentParms);
                 This->pbufferWidth = targetimpl->currentDesc.Width;
                 This->pbufferHeight = targetimpl->currentDesc.Height;
+                if (This->pbufferContext) context_release(This->pbufferContext);
             }
 
@@ -1852,5 +1967,5 @@
             /* Stay with the currently active context. */
             if (current_context
-                    && ((IWineD3DSurfaceImpl *)current_context->surface)->resource.wineD3DDevice == This)
+                    && ((IWineD3DSurfaceImpl *)current_context->surface)->resource.device == This)
             {
                 context = current_context;
@@ -1872,4 +1987,6 @@
     }
 
+    context_validate(context);
+
     if (context->render_offscreen != old_render_offscreen)
     {
@@ -1915,5 +2032,5 @@
 
             /* surface_internal_preload() requires a context to load the
-             * texture, so it will call ActivateContext. Set isInDraw to true
+             * texture, so it will call context_acquire(). Set isInDraw to true
              * to signal surface_internal_preload() that it has a context. */
 
@@ -1922,5 +2039,5 @@
              * reading back the render target. We should probably call
              * context_set_current(context) here and then rely on
-             * ActivateContext() doing the right thing. */
+             * context_acquire() doing the right thing. */
             This->isInDraw = TRUE;
 
@@ -1952,13 +2069,11 @@
     const struct wined3d_gl_info *gl_info = context->gl_info;
     IWineD3DSurface *rt = context->current_rt;
-    IWineD3DSwapChain *swapchain;
     IWineD3DDeviceImpl *device;
 
-    device = ((IWineD3DSurfaceImpl *)rt)->resource.wineD3DDevice;
-    if (SUCCEEDED(IWineD3DSurface_GetContainer(rt, &IID_IWineD3DSwapChain, (void **)&swapchain)))
-    {
-        IWineD3DSwapChain_Release((IUnknown *)swapchain);
+    device = ((IWineD3DSurfaceImpl *)rt)->resource.device;
+    if (!surface_is_offscreen(rt))
+    {
         ENTER_GL();
-        glDrawBuffer(surface_get_gl_buffer(rt, swapchain));
+        glDrawBuffer(surface_get_gl_buffer(rt));
         checkGLcall("glDrawBuffers()");
         LEAVE_GL();
@@ -1971,7 +2086,7 @@
             if (!blit)
             {
-                if (GL_SUPPORT(ARB_DRAW_BUFFERS))
+                if (gl_info->supported[ARB_DRAW_BUFFERS])
                 {
-                    GL_EXTCALL(glDrawBuffersARB(GL_LIMITS(buffers), device->draw_buffers));
+                    GL_EXTCALL(glDrawBuffersARB(gl_info->limits.buffers, device->draw_buffers));
                     checkGLcall("glDrawBuffers()");
                 }
@@ -1995,52 +2110,17 @@
 }
 
-/*****************************************************************************
- * ActivateContext
- *
- * Finds a rendering context and drawable matching the device and render
- * target for the current thread, activates them and puts them into the
- * requested state.
- *
- * Params:
- *  This: Device to activate the context for
- *  target: Requested render target
- *  usage: Prepares the context for blitting, drawing or other actions
- *
- *****************************************************************************/
-struct wined3d_context *ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, enum ContextUsage usage)
-{
-    struct wined3d_context *current_context = context_get_current();
-    DWORD                         tid = GetCurrentThreadId();
-    DWORD                         i, dirtyState, idx;
-    BYTE                          shift;
-    const struct StateEntry       *StateTable = This->StateTable;
-    const struct wined3d_gl_info *gl_info;
-    struct wined3d_context *context;
-
-    TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
-
-    context = FindContext(This, target, tid);
-
-    gl_info = context->gl_info;
-
-    /* Activate the opengl context */
-    if (context != current_context)
-    {
-        if (!context_set_current(context)) ERR("Failed to activate the new context.\n");
-        else This->frag_pipe->enable_extension((IWineD3DDevice *)This, !context->last_was_blit);
-
-        if (context->vshader_const_dirty)
-        {
-            memset(context->vshader_const_dirty, 1,
-                    sizeof(*context->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
-            This->highest_dirty_vs_const = GL_LIMITS(vshader_constantsF);
-        }
-        if (context->pshader_const_dirty)
-        {
-            memset(context->pshader_const_dirty, 1,
-                   sizeof(*context->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
-            This->highest_dirty_ps_const = GL_LIMITS(pshader_constantsF);
-        }
-    }
+/* GL locking is done by the caller. */
+void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer)
+{
+    glDrawBuffer(buffer);
+    checkGLcall("glDrawBuffer()");
+    context->draw_buffer_dirty = TRUE;
+}
+
+/* Context activation is done by the caller. */
+static void context_apply_state(struct wined3d_context *context, IWineD3DDeviceImpl *device, enum ContextUsage usage)
+{
+    const struct StateEntry *state_table = device->StateTable;
+    unsigned int i;
 
     switch (usage) {
@@ -2065,5 +2145,5 @@
                     ENTER_GL();
                     context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
-                    context_attach_surface_fbo(context, GL_FRAMEBUFFER, 0, target);
+                    context_attach_surface_fbo(context, GL_FRAMEBUFFER, 0, context->current_rt);
                     context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, NULL, FALSE);
                     LEAVE_GL();
@@ -2094,5 +2174,5 @@
         case CTXUSAGE_CLEAR:
             if(context->last_was_blit) {
-                This->frag_pipe->enable_extension((IWineD3DDevice *) This, TRUE);
+                device->frag_pipe->enable_extension((IWineD3DDevice *)device, TRUE);
             }
 
@@ -2103,5 +2183,5 @@
             glDisable(GL_BLEND);
             LEAVE_GL();
-            Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
+            Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_table);
 
             ENTER_GL();
@@ -2110,6 +2190,6 @@
             LEAVE_GL();
             context->last_was_blit = FALSE;
-            Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), StateTable);
-            Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
+            Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), state_table);
+            Context_MarkStateDirty(context, STATE_SCISSORRECT, state_table);
             break;
 
@@ -2117,16 +2197,17 @@
             /* This needs all dirty states applied */
             if(context->last_was_blit) {
-                This->frag_pipe->enable_extension((IWineD3DDevice *) This, TRUE);
-            }
-
-            IWineD3DDeviceImpl_FindTexUnitMap(This);
+                device->frag_pipe->enable_extension((IWineD3DDevice *)device, TRUE);
+            }
+
+            IWineD3DDeviceImpl_FindTexUnitMap(device);
 
             ENTER_GL();
-            for(i=0; i < context->numDirtyEntries; i++) {
-                dirtyState = context->dirtyArray[i];
-                idx = dirtyState >> 5;
-                shift = dirtyState & 0x1f;
+            for (i = 0; i < context->numDirtyEntries; ++i)
+            {
+                DWORD rep = context->dirtyArray[i];
+                DWORD idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
+                BYTE shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
                 context->isStateDirty[idx] &= ~(1 << shift);
-                StateTable[dirtyState].apply(dirtyState, This->stateBlock, context);
+                state_table[rep].apply(rep, device->stateBlock, context);
             }
             LEAVE_GL();
@@ -2136,7 +2217,5 @@
 
         case CTXUSAGE_BLIT:
-            SetupForBlit(This, context,
-                         ((IWineD3DSurfaceImpl *)target)->currentDesc.Width,
-                         ((IWineD3DSurfaceImpl *)target)->currentDesc.Height);
+            SetupForBlit(device, context);
             break;
 
@@ -2144,4 +2223,59 @@
             FIXME("Unexpected context usage requested\n");
     }
+}
+
+/*****************************************************************************
+ * context_acquire
+ *
+ * Finds a rendering context and drawable matching the device and render
+ * target for the current thread, activates them and puts them into the
+ * requested state.
+ *
+ * Params:
+ *  This: Device to activate the context for
+ *  target: Requested render target
+ *  usage: Prepares the context for blitting, drawing or other actions
+ *
+ *****************************************************************************/
+struct wined3d_context *context_acquire(IWineD3DDeviceImpl *device, IWineD3DSurface *target, enum ContextUsage usage)
+{
+    struct wined3d_context *current_context = context_get_current();
+    struct wined3d_context *context;
+
+    TRACE("device %p, target %p, usage %#x.\n", device, target, usage);
+
+    context = FindContext(device, target);
+    context_enter(context);
+    if (!context->valid) return context;
+
+    if (context != current_context)
+    {
+        if (!context_set_current(context)) ERR("Failed to activate the new context.\n");
+        else device->frag_pipe->enable_extension((IWineD3DDevice *)device, !context->last_was_blit);
+
+        if (context->vshader_const_dirty)
+        {
+            memset(context->vshader_const_dirty, 1,
+                    sizeof(*context->vshader_const_dirty) * device->d3d_vshader_constantF);
+            device->highest_dirty_vs_const = device->d3d_vshader_constantF;
+        }
+        if (context->pshader_const_dirty)
+        {
+            memset(context->pshader_const_dirty, 1,
+                   sizeof(*context->pshader_const_dirty) * device->d3d_pshader_constantF);
+            device->highest_dirty_ps_const = device->d3d_pshader_constantF;
+        }
+    }
+    else if (context->restore_ctx)
+    {
+        if (!pwglMakeCurrent(context->hdc, context->glCtx))
+        {
+            DWORD err = GetLastError();
+            ERR("Failed to make GL context %p current on device context %p, last error %#x.\n",
+                    context->hdc, context->glCtx, err);
+        }
+    }
+
+    context_apply_state(context, device, usage);
 
     return context;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 25949)
@@ -37,11 +37,10 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
 
-#define GLINFO_LOCATION (*gl_info)
-
 static void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
 {
     /* Override the IWineD3DResource Preload method. */
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    struct wined3d_context *context = NULL;
     unsigned int i, j;
     BOOL srgb_mode;
@@ -75,7 +74,7 @@
     if (!device->isInDraw)
     {
-        /* No danger of recursive calls, ActivateContext sets isInDraw to true
+        /* No danger of recursive calls, context_acquire() sets isInDraw to true
          * when loading offscreen render targets into their texture. */
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
     }
 
@@ -119,4 +118,6 @@
     /* No longer dirty. */
     *dirty = FALSE;
+
+    if (context) context_release(context);
 }
 
@@ -148,11 +149,7 @@
 }
 
-#undef GLINFO_LOCATION
-
 /* *******************************************
    IWineD3DCubeTexture IUnknown parts follow
    ******************************************* */
-
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
 
 static HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DCubeTexture *iface, REFIID riid, LPVOID *ppobj)
@@ -196,8 +193,4 @@
    IWineD3DCubeTexture IWineD3DResource parts follow
    **************************************************** */
-static HRESULT WINAPI IWineD3DCubeTextureImpl_GetDevice(IWineD3DCubeTexture *iface, IWineD3DDevice** ppDevice) {
-    return resource_get_device((IWineD3DResource *)iface, ppDevice);
-}
-
 static HRESULT WINAPI IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
     return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
@@ -314,14 +307,14 @@
 }
 
-static UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface){
-    IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
-    TRACE("(%p)\n", This);
+static UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     return GL_TEXTURE_CUBE_MAP_ARB;
 }
 
-static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface) {
-    IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
-    TRACE("(%p)\n", This);
+static BOOL WINAPI IWineD3DCubeTextureImpl_IsCondNP2(IWineD3DCubeTexture *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     return FALSE;
@@ -417,5 +410,4 @@
     /* IWineD3DResource */
     IWineD3DCubeTextureImpl_GetParent,
-    IWineD3DCubeTextureImpl_GetDevice,
     IWineD3DCubeTextureImpl_SetPrivateData,
     IWineD3DCubeTextureImpl_GetPrivateData,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 25949)
@@ -308,5 +308,6 @@
             stream_info->elements[idx].buffer_object = buffer_object;
 
-            if (!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA) && element->format_desc->format == WINED3DFMT_B8G8R8A8_UNORM)
+            if (!This->adapter->gl_info.supported[EXT_VERTEX_ARRAY_BGRA]
+                    && element->format_desc->format == WINED3DFMT_B8G8R8A8_UNORM)
             {
                 stream_info->swizzle_map |= 1 << idx;
@@ -330,8 +331,8 @@
 }
 
-static void stream_info_element_from_strided(IWineD3DDeviceImpl *This,
+static void stream_info_element_from_strided(const struct wined3d_gl_info *gl_info,
         const struct WineDirect3DStridedData *strided, struct wined3d_stream_info_element *e)
 {
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(strided->format, &This->adapter->gl_info);
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(strided->format, gl_info);
     e->format_desc = format_desc;
     e->stride = strided->dwStride;
@@ -341,5 +342,5 @@
 }
 
-void device_stream_info_from_strided(IWineD3DDeviceImpl *This,
+void device_stream_info_from_strided(const struct wined3d_gl_info *gl_info,
         const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info)
 {
@@ -349,16 +350,16 @@
 
     if (strided->position.lpData)
-        stream_info_element_from_strided(This, &strided->position, &stream_info->elements[WINED3D_FFP_POSITION]);
+        stream_info_element_from_strided(gl_info, &strided->position, &stream_info->elements[WINED3D_FFP_POSITION]);
     if (strided->normal.lpData)
-        stream_info_element_from_strided(This, &strided->normal, &stream_info->elements[WINED3D_FFP_NORMAL]);
+        stream_info_element_from_strided(gl_info, &strided->normal, &stream_info->elements[WINED3D_FFP_NORMAL]);
     if (strided->diffuse.lpData)
-        stream_info_element_from_strided(This, &strided->diffuse, &stream_info->elements[WINED3D_FFP_DIFFUSE]);
+        stream_info_element_from_strided(gl_info, &strided->diffuse, &stream_info->elements[WINED3D_FFP_DIFFUSE]);
     if (strided->specular.lpData)
-        stream_info_element_from_strided(This, &strided->specular, &stream_info->elements[WINED3D_FFP_SPECULAR]);
+        stream_info_element_from_strided(gl_info, &strided->specular, &stream_info->elements[WINED3D_FFP_SPECULAR]);
 
     for (i = 0; i < WINED3DDP_MAXTEXCOORD; ++i)
     {
         if (strided->texCoords[i].lpData)
-            stream_info_element_from_strided(This, &strided->texCoords[i],
+            stream_info_element_from_strided(gl_info, &strided->texCoords[i],
                     &stream_info->elements[WINED3D_FFP_TEXCOORD0 + i]);
     }
@@ -370,5 +371,5 @@
         if (!stream_info->elements[i].format_desc) continue;
 
-        if (!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA)
+        if (!gl_info->supported[EXT_VERTEX_ARRAY_BGRA]
                 && stream_info->elements[i].format_desc->format == WINED3DFMT_B8G8R8A8_UNORM)
         {
@@ -434,6 +435,6 @@
         This->haveHardwareCursor = FALSE;
 
-        IWineD3D_Release(This->wineD3D);
-        This->wineD3D = NULL;
+        IWineD3D_Release(This->wined3d);
+        This->wined3d = NULL;
         HeapFree(GetProcessHeap(), 0, This);
         TRACE("Freed device  %p\n", This);
@@ -488,13 +489,14 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *iface, UINT Size,
-        DWORD Usage, DWORD FVF, WINED3DPOOL Pool, IWineD3DBuffer **ppVertexBuffer,
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *iface,
+        UINT Size, DWORD Usage, WINED3DPOOL Pool, IWineD3DBuffer **ppVertexBuffer,
         IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     struct wined3d_buffer *object;
-    int dxVersion = ( (IWineD3DImpl *) This->wineD3D)->dxVersion;
     HRESULT hr;
-    BOOL conv;
+
+    TRACE("iface %p, size %u, usage %#x, pool %#x, buffer %p, parent %p, parent_ops %p.\n",
+            iface, Size, Usage, Pool, ppVertexBuffer, parent, parent_ops);
 
     if (Pool == WINED3DPOOL_SCRATCH)
@@ -526,34 +528,6 @@
 
     TRACE("Created buffer %p.\n", object);
-    TRACE("FVF %#x, Pool %#x.\n", FVF, Pool);
     *ppVertexBuffer = (IWineD3DBuffer *)object;
 
-    /* Observations show that drawStridedSlow is faster on dynamic VBs than converting +
-     * drawStridedFast (half-life 2).
-     *
-     * Basically converting the vertices in the buffer is quite expensive, and observations
-     * show that drawStridedSlow is faster than converting + uploading + drawStridedFast.
-     * Therefore do not create a VBO for WINED3DUSAGE_DYNAMIC buffers.
-     *
-     * Direct3D7 has another problem: Its vertexbuffer api doesn't offer a way to specify
-     * the range of vertices being locked, so each lock will require the whole buffer to be transformed.
-     * Moreover geometry data in dx7 is quite simple, so drawStridedSlow isn't a big hit. A plus
-     * is that the vertex buffers fvf can be trusted in dx7. So only create non-converted vbos for
-     * dx7 apps.
-     * There is a IDirect3DVertexBuffer7::Optimize call after which the buffer can't be locked any
-     * more. In this call we can convert dx7 buffers too.
-     */
-    conv = ((FVF & WINED3DFVF_POSITION_MASK) == WINED3DFVF_XYZRHW ) || (FVF & (WINED3DFVF_DIFFUSE | WINED3DFVF_SPECULAR));
-    if(!GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT)) {
-        TRACE("Not creating a vbo because GL_ARB_vertex_buffer is not supported\n");
-    } else if(Pool == WINED3DPOOL_SYSTEMMEM) {
-        TRACE("Not creating a vbo because the vertex buffer is in system memory\n");
-    } else if(Usage & WINED3DUSAGE_DYNAMIC) {
-        TRACE("Not creating a vbo because the buffer has dynamic usage\n");
-    } else if(dxVersion <= 7 && conv) {
-        TRACE("Not creating a vbo because dxVersion is 7 and the fvf needs conversion\n");
-    } else {
-        object->flags |= WINED3D_BUFFER_CREATEBO;
-    }
     return WINED3D_OK;
 }
@@ -578,6 +552,7 @@
     }
 
-    hr = buffer_init(object, This, Length, Usage, WINED3DFMT_UNKNOWN,
-            Pool, GL_ELEMENT_ARRAY_BUFFER_ARB, NULL, parent, parent_ops);
+    hr = buffer_init(object, This, Length, Usage | WINED3DUSAGE_STATICDECL,
+            WINED3DFMT_UNKNOWN, Pool, GL_ELEMENT_ARRAY_BUFFER_ARB, NULL,
+            parent, parent_ops);
     if (FAILED(hr))
     {
@@ -589,8 +564,4 @@
     TRACE("Created buffer %p.\n", object);
 
-    if(Pool != WINED3DPOOL_SYSTEMMEM && !(Usage & WINED3DUSAGE_DYNAMIC) && GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT)) {
-        object->flags |= WINED3D_BUFFER_CREATEBO;
-    }
-
     *ppIndexBuffer = (IWineD3DBuffer *) object;
 
@@ -598,271 +569,29 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, WINED3DSTATEBLOCKTYPE Type, IWineD3DStateBlock** ppStateBlock, IUnknown *parent) {
-
-    IWineD3DDeviceImpl     *This = (IWineD3DDeviceImpl *)iface;
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice *iface,
+        WINED3DSTATEBLOCKTYPE type, IWineD3DStateBlock **stateblock, IUnknown *parent)
+{
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     IWineD3DStateBlockImpl *object;
-    unsigned int i, j;
-    HRESULT temp_result;
+    HRESULT hr;
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if(!object)
     {
-        ERR("Out of memory\n");
-        *ppStateBlock = NULL;
-        return WINED3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &IWineD3DStateBlock_Vtbl;
-    object->wineD3DDevice = This;
-    object->parent = parent;
-    object->ref = 1;
-    object->blockType = Type;
-
-    *ppStateBlock = (IWineD3DStateBlock *)object;
-
-    for(i = 0; i < LIGHTMAP_SIZE; i++) {
-        list_init(&object->lightMap[i]);
-    }
-
-    temp_result = allocate_shader_constants(object);
-    if (FAILED(temp_result))
-    {
+        ERR("Failed to allocate stateblock memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = stateblock_init(object, This, type);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize stateblock, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        return temp_result;
-    }
-
-    /* Special case - Used during initialization to produce a placeholder stateblock
-          so other functions called can update a state block                         */
-    if (Type == WINED3DSBT_INIT || Type == WINED3DSBT_RECORDED)
-    {
-        /* Don't bother increasing the reference count otherwise a device will never
-           be freed due to circular dependencies                                   */
-        return WINED3D_OK;
-    }
-
-    /* Otherwise, might as well set the whole state block to the appropriate values  */
-    if (This->stateBlock != NULL)
-        stateblock_copy((IWineD3DStateBlock*) object, (IWineD3DStateBlock*) This->stateBlock);
-    else
-        memset(object->streamFreq, 1, sizeof(object->streamFreq));
-
-    /* Reset the ref and type after kludging it */
-    object->wineD3DDevice = This;
-    object->ref           = 1;
-    object->blockType     = Type;
-
-    TRACE("Updating changed flags appropriate for type %d\n", Type);
-
-    if (Type == WINED3DSBT_ALL) {
-
-        TRACE("ALL => Pretend everything has changed\n");
-        stateblock_savedstates_set((IWineD3DStateBlock*) object, &object->changed, TRUE);
-
-        /* Lights are not part of the changed / set structure */
-        for(j = 0; j < LIGHTMAP_SIZE; j++) {
-            struct list *e;
-            LIST_FOR_EACH(e, &object->lightMap[j]) {
-                PLIGHTINFOEL *light = LIST_ENTRY(e, PLIGHTINFOEL, entry);
-                light->changed = TRUE;
-                light->enabledChanged = TRUE;
-            }
-        }
-        for(j = 1; j <= WINEHIGHEST_RENDER_STATE; j++) {
-            object->contained_render_states[j - 1] = j;
-        }
-        object->num_contained_render_states = WINEHIGHEST_RENDER_STATE;
-        /* TODO: Filter unused transforms between TEXTURE8 and WORLD0? */
-        for(j = 1; j <= HIGHEST_TRANSFORMSTATE; j++) {
-            object->contained_transform_states[j - 1] = j;
-        }
-        object->num_contained_transform_states = HIGHEST_TRANSFORMSTATE;
-        for(j = 0; j < GL_LIMITS(vshader_constantsF); j++) {
-            object->contained_vs_consts_f[j] = j;
-        }
-        object->num_contained_vs_consts_f = GL_LIMITS(vshader_constantsF);
-        for(j = 0; j < MAX_CONST_I; j++) {
-            object->contained_vs_consts_i[j] = j;
-        }
-        object->num_contained_vs_consts_i = MAX_CONST_I;
-        for(j = 0; j < MAX_CONST_B; j++) {
-            object->contained_vs_consts_b[j] = j;
-        }
-        object->num_contained_vs_consts_b = MAX_CONST_B;
-        for(j = 0; j < GL_LIMITS(pshader_constantsF); j++) {
-            object->contained_ps_consts_f[j] = j;
-        }
-        object->num_contained_ps_consts_f = GL_LIMITS(pshader_constantsF);
-        for(j = 0; j < MAX_CONST_I; j++) {
-            object->contained_ps_consts_i[j] = j;
-        }
-        object->num_contained_ps_consts_i = MAX_CONST_I;
-        for(j = 0; j < MAX_CONST_B; j++) {
-            object->contained_ps_consts_b[j] = j;
-        }
-        object->num_contained_ps_consts_b = MAX_CONST_B;
-        for(i = 0; i < MAX_TEXTURES; i++) {
-            for (j = 0; j <= WINED3D_HIGHEST_TEXTURE_STATE; ++j)
-            {
-                object->contained_tss_states[object->num_contained_tss_states].stage = i;
-                object->contained_tss_states[object->num_contained_tss_states].state = j;
-                object->num_contained_tss_states++;
-            }
-        }
-        for(i = 0; i < MAX_COMBINED_SAMPLERS; i++) {
-            for(j = 1; j <= WINED3D_HIGHEST_SAMPLER_STATE; j++) {
-                object->contained_sampler_states[object->num_contained_sampler_states].stage = i;
-                object->contained_sampler_states[object->num_contained_sampler_states].state = j;
-                object->num_contained_sampler_states++;
-            }
-        }
-
-        for(i = 0; i < MAX_STREAMS; i++) {
-            if(object->streamSource[i]) {
-                IWineD3DBuffer_AddRef(object->streamSource[i]);
-            }
-        }
-        if(object->pIndexData) {
-            IWineD3DBuffer_AddRef(object->pIndexData);
-        }
-        if(object->vertexShader) {
-            IWineD3DVertexShader_AddRef(object->vertexShader);
-        }
-        if(object->pixelShader) {
-            IWineD3DPixelShader_AddRef(object->pixelShader);
-        }
-
-    } else if (Type == WINED3DSBT_PIXELSTATE) {
-
-        TRACE("PIXELSTATE => Pretend all pixel shates have changed\n");
-        stateblock_savedstates_set((IWineD3DStateBlock*) object, &object->changed, FALSE);
-
-        object->changed.pixelShader = TRUE;
-
-        /* Pixel Shader Constants */
-        for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) {
-            object->contained_ps_consts_f[i] = i;
-            object->changed.pixelShaderConstantsF[i] = TRUE;
-        }
-        object->num_contained_ps_consts_f = GL_LIMITS(pshader_constantsF);
-        for (i = 0; i < MAX_CONST_B; ++i) {
-            object->contained_ps_consts_b[i] = i;
-            object->changed.pixelShaderConstantsB |= (1 << i);
-        }
-        object->num_contained_ps_consts_b = MAX_CONST_B;
-        for (i = 0; i < MAX_CONST_I; ++i) {
-            object->contained_ps_consts_i[i] = i;
-            object->changed.pixelShaderConstantsI |= (1 << i);
-        }
-        object->num_contained_ps_consts_i = MAX_CONST_I;
-
-        for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
-            DWORD rs = SavedPixelStates_R[i];
-            object->changed.renderState[rs >> 5] |= 1 << (rs & 0x1f);
-            object->contained_render_states[i] = rs;
-        }
-        object->num_contained_render_states = NUM_SAVEDPIXELSTATES_R;
-        for (j = 0; j < MAX_TEXTURES; j++) {
-            for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
-                DWORD state = SavedPixelStates_T[i];
-                object->changed.textureState[j] |= 1 << state;
-                object->contained_tss_states[object->num_contained_tss_states].stage = j;
-                object->contained_tss_states[object->num_contained_tss_states].state = state;
-                object->num_contained_tss_states++;
-            }
-        }
-        for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++) {
-            for (i =0; i < NUM_SAVEDPIXELSTATES_S;i++) {
-                DWORD state = SavedPixelStates_S[i];
-                object->changed.samplerState[j] |= 1 << state;
-                object->contained_sampler_states[object->num_contained_sampler_states].stage = j;
-                object->contained_sampler_states[object->num_contained_sampler_states].state = state;
-                object->num_contained_sampler_states++;
-            }
-        }
-        if(object->pixelShader) {
-            IWineD3DPixelShader_AddRef(object->pixelShader);
-        }
-
-        /* Pixel state blocks do not contain vertex buffers. Set them to NULL to avoid wrong refcounting
-         * on them. This makes releasing the buffer easier
-         */
-        for(i = 0; i < MAX_STREAMS; i++) {
-            object->streamSource[i] = NULL;
-        }
-        object->pIndexData = NULL;
-        object->vertexShader = NULL;
-
-    } else if (Type == WINED3DSBT_VERTEXSTATE) {
-
-        TRACE("VERTEXSTATE => Pretend all vertex shates have changed\n");
-        stateblock_savedstates_set((IWineD3DStateBlock*) object, &object->changed, FALSE);
-
-        object->changed.vertexShader = TRUE;
-
-        /* Vertex Shader Constants */
-        for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
-            object->changed.vertexShaderConstantsF[i] = TRUE;
-            object->contained_vs_consts_f[i] = i;
-        }
-        object->num_contained_vs_consts_f = GL_LIMITS(vshader_constantsF);
-        for (i = 0; i < MAX_CONST_B; ++i) {
-            object->contained_vs_consts_b[i] = i;
-            object->changed.vertexShaderConstantsB |= (1 << i);
-        }
-        object->num_contained_vs_consts_b = MAX_CONST_B;
-        for (i = 0; i < MAX_CONST_I; ++i) {
-            object->contained_vs_consts_i[i] = i;
-            object->changed.vertexShaderConstantsI |= (1 << i);
-        }
-        object->num_contained_vs_consts_i = MAX_CONST_I;
-        for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
-            DWORD rs = SavedVertexStates_R[i];
-            object->changed.renderState[rs >> 5] |= 1 << (rs & 0x1f);
-            object->contained_render_states[i] = rs;
-        }
-        object->num_contained_render_states = NUM_SAVEDVERTEXSTATES_R;
-        for (j = 0; j < MAX_TEXTURES; j++) {
-            for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
-                DWORD state = SavedVertexStates_T[i];
-                object->changed.textureState[j] |= 1 << state;
-                object->contained_tss_states[object->num_contained_tss_states].stage = j;
-                object->contained_tss_states[object->num_contained_tss_states].state = state;
-                object->num_contained_tss_states++;
-            }
-        }
-        for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
-            for (i =0; i < NUM_SAVEDVERTEXSTATES_S;i++) {
-                DWORD state = SavedVertexStates_S[i];
-                object->changed.samplerState[j] |= 1 << state;
-                object->contained_sampler_states[object->num_contained_sampler_states].stage = j;
-                object->contained_sampler_states[object->num_contained_sampler_states].state = state;
-                object->num_contained_sampler_states++;
-            }
-        }
-
-        for(j = 0; j < LIGHTMAP_SIZE; j++) {
-            struct list *e;
-            LIST_FOR_EACH(e, &object->lightMap[j]) {
-                PLIGHTINFOEL *light = LIST_ENTRY(e, PLIGHTINFOEL, entry);
-                light->changed = TRUE;
-                light->enabledChanged = TRUE;
-            }
-        }
-
-        for(i = 0; i < MAX_STREAMS; i++) {
-            if(object->streamSource[i]) {
-                IWineD3DBuffer_AddRef(object->streamSource[i]);
-            }
-        }
-        if(object->vertexShader) {
-            IWineD3DVertexShader_AddRef(object->vertexShader);
-        }
-        object->pIndexData = NULL;
-        object->pixelShader = NULL;
-    } else {
-        FIXME("Unrecognized state block type %d\n", Type);
-    }
-
-    TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
+        return hr;
+    }
+
+    TRACE("Created stateblock %p.\n", object);
+    *stateblock = (IWineD3DStateBlock *)object;
+
     return WINED3D_OK;
 }
@@ -889,5 +618,4 @@
     {
         ERR("Failed to allocate surface memory.\n");
-        *ppSurface = NULL;
         return WINED3DERR_OUTOFVIDEOMEMORY;
     }
@@ -899,5 +627,4 @@
         WARN("Failed to initialize surface, returning %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppSurface = NULL;
         return hr;
     }
@@ -1069,4 +796,5 @@
 static HRESULT WINAPI IWineD3DDeviceImpl_CreateQuery(IWineD3DDevice *iface, WINED3DQUERYTYPE Type, IWineD3DQuery **ppQuery, IUnknown* parent) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     IWineD3DQueryImpl *object; /*NOTE: impl ref allowed since this is a create function */
     HRESULT hr = WINED3DERR_NOTAVAILABLE;
@@ -1077,5 +805,5 @@
     case WINED3DQUERYTYPE_OCCLUSION:
         TRACE("(%p) occlusion query\n", This);
-        if (GL_SUPPORT(ARB_OCCLUSION_QUERY))
+        if (gl_info->supported[ARB_OCCLUSION_QUERY])
             hr = WINED3D_OK;
         else
@@ -1086,5 +814,6 @@
 
     case WINED3DQUERYTYPE_EVENT:
-        if(!(GL_SUPPORT(NV_FENCE) || GL_SUPPORT(APPLE_FENCE) )) {
+        if (!gl_info->supported[NV_FENCE] && !gl_info->supported[APPLE_FENCE])
+        {
             /* Half-Life 2 needs this query. It does not render the main menu correctly otherwise
              * Pretend to support it, faking this query does not do much harm except potentially lowering performance
@@ -1128,5 +857,5 @@
     object->type = Type;
     object->state = QUERY_CREATED;
-    object->wineD3DDevice = This;
+    object->device = This;
     object->parent = parent;
     object->ref = 1;
@@ -1166,395 +895,34 @@
 }
 
-/*****************************************************************************
- * IWineD3DDeviceImpl_SetupFullscreenWindow
- *
- * Helper function that modifies a HWND's Style and ExStyle for proper
- * fullscreen use.
- *
- * Params:
- *  iface: Pointer to the IWineD3DDevice interface
- *  window: Window to setup
- *
- *****************************************************************************/
-static LONG fullscreen_style(LONG orig_style) {
-    LONG style = orig_style;
-    style &= ~WS_CAPTION;
-    style &= ~WS_THICKFRAME;
-
-    /* Make sure the window is managed, otherwise we won't get keyboard input */
-    style |= WS_POPUP | WS_SYSMENU;
-
-    return style;
-}
-
-static LONG fullscreen_exStyle(LONG orig_exStyle) {
-    LONG exStyle = orig_exStyle;
-
-    /* Filter out window decorations */
-    exStyle &= ~WS_EX_WINDOWEDGE;
-    exStyle &= ~WS_EX_CLIENTEDGE;
-
-    return exStyle;
-}
-
-static void IWineD3DDeviceImpl_SetupFullscreenWindow(IWineD3DDevice *iface, HWND window, UINT w, UINT h) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-
-    LONG style, exStyle;
-    /* Don't do anything if an original style is stored.
-     * That shouldn't happen
-     */
-    TRACE("(%p): Setting up window %p for exclusive mode\n", This, window);
-    if (This->style || This->exStyle) {
-        ERR("(%p): Want to change the window parameters of HWND %p, but "
-            "another style is stored for restoration afterwards\n", This, window);
-    }
-
-    /* Get the parameters and save them */
-    style = GetWindowLongW(window, GWL_STYLE);
-    exStyle = GetWindowLongW(window, GWL_EXSTYLE);
-    This->style = style;
-    This->exStyle = exStyle;
-
-    style = fullscreen_style(style);
-    exStyle = fullscreen_exStyle(exStyle);
-
-    TRACE("Old style was %08x,%08x, setting to %08x,%08x\n",
-          This->style, This->exStyle, style, exStyle);
-
-    SetWindowLongW(window, GWL_STYLE, style);
-    SetWindowLongW(window, GWL_EXSTYLE, exStyle);
-
-    /* Inform the window about the update. */
-    SetWindowPos(window, HWND_TOP, 0, 0,
-                 w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
-}
-
-/*****************************************************************************
- * IWineD3DDeviceImpl_RestoreWindow
- *
- * Helper function that restores a windows' properties when taking it out
- * of fullscreen mode
- *
- * Params:
- *  iface: Pointer to the IWineD3DDevice interface
- *  window: Window to setup
- *
- *****************************************************************************/
-static void IWineD3DDeviceImpl_RestoreWindow(IWineD3DDevice *iface, HWND window) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    LONG style, exStyle;
-
-    /* This could be a DDSCL_NORMAL -> DDSCL_NORMAL
-     * switch, do nothing
-     */
-    if (!This->style && !This->exStyle) return;
-
-    TRACE("(%p): Restoring window settings of window %p to %08x, %08x\n",
-          This, window, This->style, This->exStyle);
-
-    style = GetWindowLongW(window, GWL_STYLE);
-    exStyle = GetWindowLongW(window, GWL_EXSTYLE);
-
-    /* Only restore the style if the application didn't modify it during the fullscreen phase.
-     * Some applications change it before calling Reset() when switching between windowed and
-     * fullscreen modes(HL2), some depend on the original style(Eve Online)
-     */
-    if(style == fullscreen_style(This->style) &&
-       exStyle == fullscreen_style(This->exStyle)) {
-        SetWindowLongW(window, GWL_STYLE, This->style);
-        SetWindowLongW(window, GWL_EXSTYLE, This->exStyle);
-    }
-
-    /* Delete the old values */
-    This->style = 0;
-    This->exStyle = 0;
-
-    /* Inform the window about the update */
-    SetWindowPos(window, 0 /* InsertAfter, ignored */,
-                 0, 0, 0, 0, /* Pos, Size, ignored */
-                 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
-}
-
-/* example at http://www.fairyengine.com/articles/dxmultiviews.htm */
 static HRESULT WINAPI IWineD3DDeviceImpl_CreateSwapChain(IWineD3DDevice *iface,
-        WINED3DPRESENT_PARAMETERS *pPresentationParameters, IWineD3DSwapChain **ppSwapChain,
+        WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain,
         IUnknown *parent, WINED3DSURFTYPE surface_type)
 {
-    IWineD3DDeviceImpl      *This = (IWineD3DDeviceImpl *)iface;
-
-    HDC                     hDc;
-    IWineD3DSwapChainImpl  *object; /** NOTE: impl ref allowed since this is a create function **/
-    HRESULT                 hr;
-    BOOL                    displaymode_set = FALSE;
-    WINED3DDISPLAYMODE      Mode;
-    const struct GlPixelFormatDesc *format_desc;
-
-    TRACE("(%p) : Created Additional Swap Chain\n", This);
-
-   /** FIXME: Test under windows to find out what the life cycle of a swap chain is,
-   * does a device hold a reference to a swap chain giving them a lifetime of the device
-   * or does the swap chain notify the device of its destruction.
-    *******************************/
-
-    /* Check the params */
-    if(pPresentationParameters->BackBufferCount > WINED3DPRESENT_BACK_BUFFER_MAX) {
-        ERR("App requested %d back buffers, this is not supported for now\n", pPresentationParameters->BackBufferCount);
-        return WINED3DERR_INVALIDCALL;
-    } else if (pPresentationParameters->BackBufferCount > 1) {
-        FIXME("The app requests more than one back buffer, this can't be supported properly. Please configure the application to use double buffering(=1 back buffer) if possible\n");
-    }
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    IWineD3DSwapChainImpl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, present_parameters %p, swapchain %p, parent %p, surface_type %#x.\n",
+            iface, present_parameters, swapchain, parent, surface_type);
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if(!object)
-    {
-        ERR("Out of memory\n");
-        *ppSwapChain = NULL;
-        return WINED3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    switch(surface_type) {
-        case SURFACE_GDI:
-            object->lpVtbl = &IWineGDISwapChain_Vtbl;
-            break;
-        case SURFACE_OPENGL:
-            object->lpVtbl = &IWineD3DSwapChain_Vtbl;
-            break;
-        case SURFACE_UNKNOWN:
-            FIXME("Caller tried to create a SURFACE_UNKNOWN swapchain\n");
-            HeapFree(GetProcessHeap(), 0, object);
-            return WINED3DERR_INVALIDCALL;
-    }
-    object->wineD3DDevice = This;
-    object->parent = parent;
-    object->ref = 1;
-
-    *ppSwapChain = (IWineD3DSwapChain *)object;
-
-    /*********************
-    * Lookup the window Handle and the relating X window handle
-    ********************/
-
-    /* Setup hwnd we are using, plus which display this equates to */
-    object->win_handle = pPresentationParameters->hDeviceWindow;
-    if (!object->win_handle) {
-        object->win_handle = This->createParms.hFocusWindow;
-    }
-    if(!pPresentationParameters->Windowed && object->win_handle) {
-        IWineD3DDeviceImpl_SetupFullscreenWindow(iface, object->win_handle,
-                                                 pPresentationParameters->BackBufferWidth,
-                                                 pPresentationParameters->BackBufferHeight);
-    }
-
-    hDc                = GetDC(object->win_handle);
-    TRACE("Using hDc %p\n", hDc);
-
-    if (NULL == hDc) {
-        WARN("Failed to get a HDc for Window %p\n", object->win_handle);
-        return WINED3DERR_NOTAVAILABLE;
-    }
-
-    /* Get info on the current display setup */
-    IWineD3D_GetAdapterDisplayMode(This->wineD3D, This->adapter->num, &Mode);
-    object->orig_width = Mode.Width;
-    object->orig_height = Mode.Height;
-    object->orig_fmt = Mode.Format;
-    format_desc = getFormatDescEntry(Mode.Format, &GLINFO_LOCATION);
-
-    if (pPresentationParameters->Windowed &&
-        ((pPresentationParameters->BackBufferWidth == 0) ||
-         (pPresentationParameters->BackBufferHeight == 0) ||
-         (pPresentationParameters->BackBufferFormat == WINED3DFMT_UNKNOWN))) {
-
-        RECT Rect;
-        GetClientRect(object->win_handle, &Rect);
-
-        if (pPresentationParameters->BackBufferWidth == 0) {
-           pPresentationParameters->BackBufferWidth = Rect.right;
-           TRACE("Updating width to %d\n", pPresentationParameters->BackBufferWidth);
-        }
-        if (pPresentationParameters->BackBufferHeight == 0) {
-           pPresentationParameters->BackBufferHeight = Rect.bottom;
-           TRACE("Updating height to %d\n", pPresentationParameters->BackBufferHeight);
-        }
-        if (pPresentationParameters->BackBufferFormat == WINED3DFMT_UNKNOWN) {
-           pPresentationParameters->BackBufferFormat = object->orig_fmt;
-           TRACE("Updating format to %s\n", debug_d3dformat(object->orig_fmt));
-        }
-    }
-
-    /* Put the correct figures in the presentation parameters */
-    TRACE("Copying across presentation parameters\n");
-    object->presentParms = *pPresentationParameters;
-
-    TRACE("calling rendertarget CB\n");
-    hr = IWineD3DDeviceParent_CreateRenderTarget(This->device_parent, parent,
-            object->presentParms.BackBufferWidth, object->presentParms.BackBufferHeight,
-            object->presentParms.BackBufferFormat, object->presentParms.MultiSampleType,
-            object->presentParms.MultiSampleQuality, TRUE /* Lockable */, &object->frontBuffer);
-    if (SUCCEEDED(hr)) {
-        IWineD3DSurface_SetContainer(object->frontBuffer, (IWineD3DBase *)object);
-        ((IWineD3DSurfaceImpl *)object->frontBuffer)->Flags |= SFLAG_SWAPCHAIN;
-        if(surface_type == SURFACE_OPENGL) {
-            IWineD3DSurface_ModifyLocation(object->frontBuffer, SFLAG_INDRAWABLE, TRUE);
-        }
-    } else {
-        ERR("Failed to create the front buffer\n");
-        goto error;
-    }
-
-   /*********************
-   * Windowed / Fullscreen
-   *******************/
-
-   /**
-   * TODO: MSDN says that we are only allowed one fullscreen swapchain per device,
-   * 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) {
-        WINED3DDISPLAYMODE mode;
-
-
-        /* Change the display settings */
-        mode.Width = pPresentationParameters->BackBufferWidth;
-        mode.Height = pPresentationParameters->BackBufferHeight;
-        mode.Format = pPresentationParameters->BackBufferFormat;
-        mode.RefreshRate = pPresentationParameters->FullScreen_RefreshRateInHz;
-
-        IWineD3DDevice_SetDisplayMode(iface, 0, &mode);
-        displaymode_set = TRUE;
-    }
-
-        /**
-     * Create an opengl context for the display visual
-     *  NOTE: the visual is chosen as the window is created and the glcontext cannot
-     *     use different properties after that point in time. FIXME: How to handle when requested format
-     *     doesn't match actual visual? Cannot choose one here - code removed as it ONLY works if the one
-     *     it chooses is identical to the one already being used!
-         **********************************/
-    /** FIXME: Handle stencil appropriately via EnableAutoDepthStencil / AutoDepthStencilFormat **/
-
-    object->context = HeapAlloc(GetProcessHeap(), 0, sizeof(object->context));
-    if(!object->context) {
-        ERR("Failed to create the context array\n");
-        hr = E_OUTOFMEMORY;
-        goto error;
-    }
-    object->num_contexts = 1;
-
-    if(surface_type == SURFACE_OPENGL) {
-        object->context[0] = CreateContext(This, (IWineD3DSurfaceImpl *) object->frontBuffer, object->win_handle, FALSE /* pbuffer */, pPresentationParameters);
-        if (!object->context[0]) {
-            ERR("Failed to create a new context\n");
-            hr = WINED3DERR_NOTAVAILABLE;
-            goto error;
-        } else {
-            TRACE("Context created (HWND=%p, glContext=%p)\n",
-                object->win_handle, object->context[0]->glCtx);
-        }
-    }
-
-   /*********************
-   * Create the back, front and stencil buffers
-   *******************/
-    if(object->presentParms.BackBufferCount > 0) {
-        UINT i;
-
-        object->backBuffer = HeapAlloc(GetProcessHeap(), 0, sizeof(IWineD3DSurface *) * object->presentParms.BackBufferCount);
-        if(!object->backBuffer) {
-            ERR("Out of memory\n");
-            hr = E_OUTOFMEMORY;
-            goto error;
-        }
-
-        for(i = 0; i < object->presentParms.BackBufferCount; i++) {
-            TRACE("calling rendertarget CB\n");
-            hr = IWineD3DDeviceParent_CreateRenderTarget(This->device_parent, parent,
-                    object->presentParms.BackBufferWidth, object->presentParms.BackBufferHeight,
-                    object->presentParms.BackBufferFormat, object->presentParms.MultiSampleType,
-                    object->presentParms.MultiSampleQuality, TRUE /* Lockable */, &object->backBuffer[i]);
-            if(SUCCEEDED(hr)) {
-                IWineD3DSurface_SetContainer(object->backBuffer[i], (IWineD3DBase *)object);
-                ((IWineD3DSurfaceImpl *)object->backBuffer[i])->Flags |= SFLAG_SWAPCHAIN;
-            } else {
-                ERR("Cannot create new back buffer\n");
-                goto error;
-            }
-            if(surface_type == SURFACE_OPENGL) {
-                ENTER_GL();
-                glDrawBuffer(GL_BACK);
-                checkGLcall("glDrawBuffer(GL_BACK)");
-                LEAVE_GL();
-            }
-        }
-    } else {
-        object->backBuffer = NULL;
-
-        /* Single buffering - draw to front buffer */
-        if(surface_type == SURFACE_OPENGL) {
-            ENTER_GL();
-            glDrawBuffer(GL_FRONT);
-            checkGLcall("glDrawBuffer(GL_FRONT)");
-            LEAVE_GL();
-        }
-    }
-
-    /* Under directX swapchains share the depth stencil, so only create one depth-stencil */
-    if (pPresentationParameters->EnableAutoDepthStencil && surface_type == SURFACE_OPENGL) {
-        TRACE("Creating depth stencil buffer\n");
-        if (This->auto_depth_stencil_buffer == NULL ) {
-            hr = IWineD3DDeviceParent_CreateDepthStencilSurface(This->device_parent, parent,
-                    object->presentParms.BackBufferWidth, object->presentParms.BackBufferHeight,
-                    object->presentParms.AutoDepthStencilFormat, object->presentParms.MultiSampleType,
-                    object->presentParms.MultiSampleQuality, FALSE /* FIXME: Discard */,
-                    &This->auto_depth_stencil_buffer);
-            if (SUCCEEDED(hr)) {
-                IWineD3DSurface_SetContainer(This->auto_depth_stencil_buffer, 0);
-            } else {
-                ERR("Failed to create the auto depth stencil\n");
-                goto error;
-            }
-        }
-    }
-
-    IWineD3DSwapChain_GetGammaRamp((IWineD3DSwapChain *) object, &object->orig_gamma);
-
-    TRACE("Created swapchain %p\n", object);
-    TRACE("FrontBuf @ %p, BackBuf @ %p, DepthStencil %d\n",object->frontBuffer, object->backBuffer ? object->backBuffer[0] : NULL, pPresentationParameters->EnableAutoDepthStencil);
-    return WINED3D_OK;
-
-error:
-    if (displaymode_set) {
-        DEVMODEW devmode;
-        RECT     clip_rc;
-
-        SetRect(&clip_rc, 0, 0, object->orig_width, object->orig_height);
-        ClipCursor(NULL);
-
-        /* Change the display settings */
-        memset(&devmode, 0, sizeof(devmode));
-        devmode.dmSize       = sizeof(devmode);
-        devmode.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
-        devmode.dmBitsPerPel = format_desc->byte_count * 8;
-        devmode.dmPelsWidth  = object->orig_width;
-        devmode.dmPelsHeight = object->orig_height;
-        ChangeDisplaySettingsExW(This->adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
-    }
-
-    if (object->backBuffer) {
-        UINT i;
-        for(i = 0; i < object->presentParms.BackBufferCount; i++) {
-            if (object->backBuffer[i]) IWineD3DSurface_Release(object->backBuffer[i]);
-        }
-        HeapFree(GetProcessHeap(), 0, object->backBuffer);
-        object->backBuffer = NULL;
-    }
-    if(object->context && object->context[0])
-        DestroyContext(This, object->context[0]);
-    if (object->frontBuffer) IWineD3DSurface_Release(object->frontBuffer);
-    HeapFree(GetProcessHeap(), 0, object);
-    return hr;
+    if (!object)
+    {
+        ERR("Failed to allocate swapchain memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = swapchain_init(object, surface_type, This, present_parameters, parent);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize swapchain, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created swapchain %p.\n", object);
+    *swapchain = (IWineD3DSwapChain *)object;
+
+    return WINED3D_OK;
 }
 
@@ -1609,5 +977,5 @@
     }
 
-    TRACE("Created verrtex declaration %p.\n", object);
+    TRACE("Created vertex declaration %p.\n", object);
     *declaration = (IWineD3DVertexDeclaration *)object;
 
@@ -1801,4 +1169,34 @@
 }
 
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateGeometryShader(IWineD3DDevice *iface,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IWineD3DGeometryShader **shader, IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops)
+{
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    struct wined3d_geometryshader *object;
+    HRESULT hr;
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate shader memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = geometryshader_init(object, This, byte_code, output_signature, parent, parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created geometry shader %p.\n", object);
+    *shader = (IWineD3DGeometryShader *)object;
+
+    return WINED3D_OK;
+}
+
 static HRESULT WINAPI IWineD3DDeviceImpl_CreatePixelShader(IWineD3DDevice *iface,
         const DWORD *pFunction, const struct wined3d_shader_signature *output_signature,
@@ -1850,5 +1248,5 @@
     object->Flags = Flags;
     object->parent = Parent;
-    object->wineD3DDevice = This;
+    object->device = This;
     object->palNumEntries = IWineD3DPaletteImpl_Size(Flags);
     object->hpal = CreatePalette((const LOGPALETTE*)&(object->palVersion));
@@ -1917,16 +1315,13 @@
     }
 
-    out:
-    if(dcb) {
-        DeleteDC(dcb);
-    }
-    if(hbm) {
-        DeleteObject(hbm);
-    }
-    return;
+out:
+    if (dcb) DeleteDC(dcb);
+    if (hbm) DeleteObject(hbm);
 }
 
 /* Context activation is done by the caller. */
-static void create_dummy_textures(IWineD3DDeviceImpl *This) {
+static void create_dummy_textures(IWineD3DDeviceImpl *This)
+{
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     unsigned int i;
     /* Under DirectX you can have texture stage operations even if no texture is
@@ -1937,10 +1332,13 @@
     ENTER_GL();
 
-    if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
+    if (gl_info->supported[APPLE_CLIENT_STORAGE])
+    {
         /* The dummy texture does not have client storage backing */
         glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
         checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
     }
-    for (i = 0; i < GL_LIMITS(textures); i++) {
+
+    for (i = 0; i < gl_info->limits.textures; ++i)
+    {
         GLubyte white = 255;
 
@@ -1962,5 +1360,7 @@
         checkGLcall("glTexImage2D");
     }
-    if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
+
+    if (gl_info->supported[APPLE_CLIENT_STORAGE])
+    {
         /* Reenable because if supported it is enabled by default */
         glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
@@ -1971,9 +1371,22 @@
 }
 
+/* Context activation is done by the caller. */
+static void destroy_dummy_textures(IWineD3DDeviceImpl *device, const struct wined3d_gl_info *gl_info)
+{
+    ENTER_GL();
+    glDeleteTextures(gl_info->limits.textures, device->dummyTextureName);
+    checkGLcall("glDeleteTextures(gl_info->limits.textures, device->dummyTextureName)");
+    LEAVE_GL();
+
+    memset(device->dummyTextureName, 0, gl_info->limits.textures * sizeof(*device->dummyTextureName));
+}
+
 static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface,
         WINED3DPRESENT_PARAMETERS *pPresentationParameters)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     IWineD3DSwapChainImpl *swapchain = NULL;
+    struct wined3d_context *context;
     HRESULT hr;
     DWORD state;
@@ -1985,5 +1398,14 @@
     if(!This->adapter->opengl) return WINED3DERR_INVALIDCALL;
 
-    /* TODO: Test if OpenGL is compiled in and loaded */
+    if (!pPresentationParameters->Windowed)
+    {
+        This->focus_window = This->createParms.hFocusWindow;
+        if (!This->focus_window) This->focus_window = pPresentationParameters->hDeviceWindow;
+        if (!wined3d_register_window(This->focus_window, This))
+        {
+            ERR("Failed to register window %p.\n", This->focus_window);
+            return E_FAIL;
+        }
+    }
 
     TRACE("(%p) : Creating stateblock\n", This);
@@ -2001,6 +1423,8 @@
     IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)This->updateStateBlock);
 
-    This->render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DSurface *) * GL_LIMITS(buffers));
-    This->draw_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLenum) * GL_LIMITS(buffers));
+    This->render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+            sizeof(IWineD3DSurface *) * gl_info->limits.buffers);
+    This->draw_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+            sizeof(GLenum) * gl_info->limits.buffers);
 
     This->NumberOfPalettes = 1;
@@ -2008,4 +1432,5 @@
     if(!This->palettes || !This->render_targets || !This->draw_buffers) {
         ERR("Out of memory!\n");
+        hr = E_OUTOFMEMORY;
         goto err_out;
     }
@@ -2013,4 +1438,5 @@
     if(!This->palettes[0]) {
         ERR("Out of memory!\n");
+        hr = E_OUTOFMEMORY;
         goto err_out;
     }
@@ -2024,6 +1450,8 @@
 
     /* Initialize the texture unit mapping to a 1:1 mapping */
-    for (state = 0; state < MAX_COMBINED_SAMPLERS; ++state) {
-        if (state < GL_LIMITS(fragment_samplers)) {
+    for (state = 0; state < MAX_COMBINED_SAMPLERS; ++state)
+    {
+        if (state < gl_info->limits.fragment_samplers)
+        {
             This->texUnitMap[state] = state;
             This->rev_tex_unit_map[state] = state;
@@ -2034,4 +1462,6 @@
     }
 
+    if (This->focus_window) SetFocus(This->focus_window);
+
     /* Setup the implicit swapchain. This also initializes a context. */
     TRACE("Creating implicit swapchain\n");
@@ -2088,4 +1518,7 @@
     /* Setup all the devices defaults */
     IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock *)This->stateBlock);
+
+    context = context_acquire(This, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD);
+
     create_dummy_textures(This);
 
@@ -2100,4 +1533,7 @@
     switch(wined3d_settings.offscreen_rendering_mode) {
         case ORM_FBO:
+            This->offscreenBuffer = GL_COLOR_ATTACHMENT0;
+            break;
+
         case ORM_PBUFFER:
             This->offscreenBuffer = GL_BACK;
@@ -2120,4 +1556,6 @@
     LEAVE_GL();
 
+    context_release(context);
+
     /* Clear the screen */
     IWineD3DDevice_Clear((IWineD3DDevice *) This, 0, NULL,
@@ -2160,4 +1598,5 @@
         This->shader_backend->shader_free_private(iface);
     }
+    if (This->focus_window) wined3d_unregister_window(This->focus_window);
     return hr;
 }
@@ -2205,6 +1644,6 @@
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
-    const struct wined3d_context *context;
     const struct wined3d_gl_info *gl_info;
+    struct wined3d_context *context;
     int sampler;
     UINT i;
@@ -2216,5 +1655,5 @@
      * it was created. Thus make sure a context is active for the glDelete* calls
      */
-    context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
     gl_info = context->gl_info;
 
@@ -2243,5 +1682,5 @@
 
     /* Delete the pbuffer context if there is any */
-    if(This->pbufferContext) DestroyContext(This, This->pbufferContext);
+    if(This->pbufferContext) context_destroy(This, This->pbufferContext);
 
     /* Delete the mouse cursor texture */
@@ -2325,4 +1764,6 @@
     }
 
+    context_release(context);
+
     for(i=0; i < This->NumberOfSwapChains; i++) {
         TRACE("Releasing the implicit swapchain %d\n", i);
@@ -2347,4 +1788,7 @@
 
     This->d3d_initialized = FALSE;
+
+    if (This->focus_window) wined3d_unregister_window(This->focus_window);
+
     return WINED3D_OK;
 }
@@ -2378,6 +1822,4 @@
     /*For now just store the flag(needed in case of ddraw) */
     This->createParms.BehaviorFlags |= WINED3DCREATE_MULTITHREADED;
-
-    return;
 }
 
@@ -2387,5 +1829,5 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     LONG ret;
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(pMode->Format, &GLINFO_LOCATION);
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(pMode->Format, &This->adapter->gl_info);
     RECT clip_rc;
 
@@ -2445,6 +1887,6 @@
 static HRESULT WINAPI IWineD3DDeviceImpl_GetDirect3D(IWineD3DDevice *iface, IWineD3D **ppD3D) {
    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-   *ppD3D= This->wineD3D;
-   TRACE("(%p) : wineD3D returning %p\n", This,  *ppD3D);
+   *ppD3D = This->wined3d;
+   TRACE("Returning %p.\n", *ppD3D);
    IWineD3D_AddRef(*ppD3D);
    return WINED3D_OK;
@@ -2681,5 +2123,5 @@
 static HRESULT WINAPI IWineD3DDeviceImpl_SetLight(IWineD3DDevice *iface, DWORD Index, CONST WINED3DLIGHT* pLight) {
     float rho;
-    PLIGHTINFOEL *object = NULL;
+    struct wined3d_light_info *object = NULL;
     UINT Hi = LIGHTMAP_HASHFUNC(Index);
     struct list *e;
@@ -2720,6 +2162,7 @@
     }
 
-    LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi]) {
-        object = LIST_ENTRY(e, PLIGHTINFOEL, entry);
+    LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi])
+    {
+        object = LIST_ENTRY(e, struct wined3d_light_info, entry);
         if(object->OriginalIndex == Index) break;
         object = NULL;
@@ -2736,5 +2179,4 @@
         object->glIndex = -1;
         object->OriginalIndex = Index;
-        object->changed = TRUE;
     }
 
@@ -2824,6 +2266,7 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_GetLight(IWineD3DDevice *iface, DWORD Index, WINED3DLIGHT* pLight) {
-    PLIGHTINFOEL *lightInfo = NULL;
+static HRESULT WINAPI IWineD3DDeviceImpl_GetLight(IWineD3DDevice *iface, DWORD Index, WINED3DLIGHT *pLight)
+{
+    struct wined3d_light_info *lightInfo = NULL;
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     DWORD Hi = LIGHTMAP_HASHFUNC(Index);
@@ -2831,6 +2274,7 @@
     TRACE("(%p) : Idx(%d), pLight(%p)\n", This, Index, pLight);
 
-    LIST_FOR_EACH(e, &This->stateBlock->lightMap[Hi]) {
-        lightInfo = LIST_ENTRY(e, PLIGHTINFOEL, entry);
+    LIST_FOR_EACH(e, &This->stateBlock->lightMap[Hi])
+    {
+        lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
         if(lightInfo->OriginalIndex == Index) break;
         lightInfo = NULL;
@@ -2850,6 +2294,7 @@
  *   (Note for consistency, renamed d3dx function by adding the 'set' prefix)
  *****/
-static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, DWORD Index, BOOL Enable) {
-    PLIGHTINFOEL *lightInfo = NULL;
+static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, DWORD Index, BOOL Enable)
+{
+    struct wined3d_light_info *lightInfo = NULL;
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     UINT Hi = LIGHTMAP_HASHFUNC(Index);
@@ -2857,6 +2302,7 @@
     TRACE("(%p) : Idx(%d), enable? %d\n", This, Index, Enable);
 
-    LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi]) {
-        lightInfo = LIST_ENTRY(e, PLIGHTINFOEL, entry);
+    LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi])
+    {
+        lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
         if(lightInfo->OriginalIndex == Index) break;
         lightInfo = NULL;
@@ -2871,6 +2317,7 @@
 
         /* Search for it again! Should be fairly quick as near head of list */
-        LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi]) {
-            lightInfo = LIST_ENTRY(e, PLIGHTINFOEL, entry);
+        LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi])
+        {
+            lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
             if(lightInfo->OriginalIndex == Index) break;
             lightInfo = NULL;
@@ -2882,5 +2329,4 @@
     }
 
-    lightInfo->enabledChanged = TRUE;
     if(!Enable) {
         if(lightInfo->glIndex != -1) {
@@ -2932,7 +2378,7 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_GetLightEnable(IWineD3DDevice *iface, DWORD Index,BOOL* pEnable) {
-
-    PLIGHTINFOEL *lightInfo = NULL;
+static HRESULT WINAPI IWineD3DDeviceImpl_GetLightEnable(IWineD3DDevice *iface, DWORD Index,BOOL* pEnable)
+{
+    struct wined3d_light_info *lightInfo = NULL;
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     struct list *e;
@@ -2940,6 +2386,7 @@
     TRACE("(%p) : for idx(%d)\n", This, Index);
 
-    LIST_FOR_EACH(e, &This->stateBlock->lightMap[Hi]) {
-        lightInfo = LIST_ENTRY(e, PLIGHTINFOEL, entry);
+    LIST_FOR_EACH(e, &This->stateBlock->lightMap[Hi])
+    {
+        lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
         if(lightInfo->OriginalIndex == Index) break;
         lightInfo = NULL;
@@ -2963,5 +2410,6 @@
 
     /* Validate Index */
-    if (Index >= GL_LIMITS(clipplanes)) {
+    if (Index >= This->adapter->gl_info.limits.clipplanes)
+    {
         TRACE("Application has requested clipplane this device doesn't support\n");
         return WINED3DERR_INVALIDCALL;
@@ -2999,5 +2447,6 @@
 
     /* Validate Index */
-    if (Index >= GL_LIMITS(clipplanes)) {
+    if (Index >= This->adapter->gl_info.limits.clipplanes)
+    {
         TRACE("Application has requested clipplane this device doesn't support\n");
         return WINED3DERR_INVALIDCALL;
@@ -3338,4 +2787,7 @@
     TRACE("(%p) : pDecl=%p\n", This, pDecl);
 
+    if (pDecl) IWineD3DVertexDeclaration_AddRef(pDecl);
+    if (oldDecl) IWineD3DVertexDeclaration_Release(oldDecl);
+
     This->updateStateBlock->vertexDecl = pDecl;
     This->updateStateBlock->changed.vertexDecl = TRUE;
@@ -3695,5 +3147,5 @@
             ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.reg_maps.sampler_type;
     const WINED3DSAMPLER_TEXTURE_TYPE *pshader_sampler_type = NULL;
-    int start = min(MAX_COMBINED_SAMPLERS, GL_LIMITS(combined_samplers)) - 1;
+    int start = min(MAX_COMBINED_SAMPLERS, This->adapter->gl_info.limits.combined_samplers) - 1;
     int i;
 
@@ -3954,4 +3406,5 @@
         DWORD DestFVF)
 {
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     char *dest_ptr, *dest_conv = NULL, *dest_conv_addr = NULL;
     unsigned int i;
@@ -3982,5 +3435,5 @@
      * write correct opengl data into it. It's cheap and allows us to run drawStridedFast
      */
-    if (!dest->buffer_object && GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT))
+    if (!dest->buffer_object && gl_info->supported[ARB_VERTEX_BUFFER_OBJECT])
     {
         dest->flags |= WINED3D_BUFFER_CREATEBO;
@@ -4300,5 +3753,8 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     struct wined3d_stream_info stream_info;
+    struct wined3d_context *context;
     BOOL vbo = FALSE, streamWasUP = This->stateBlock->streamIsUP;
+    HRESULT hr;
+
     TRACE("(%p)->(%d,%d,%d,%p,%p,%d\n", This, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
 
@@ -4308,5 +3764,5 @@
 
     /* Need any context to write to the vbo. */
-    ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
 
     /* ProcessVertices reads from vertex buffers, which have to be assigned. DrawPrimitive and DrawPrimitiveUP
@@ -4345,6 +3801,10 @@
     }
 
-    return process_vertices_strided(This, DestIndex, VertexCount, &stream_info,
+    hr = process_vertices_strided(This, DestIndex, VertexCount, &stream_info,
             (struct wined3d_buffer *)pDestBuffer, Flags, DestFVF);
+
+    context_release(context);
+
+    return hr;
 }
 
@@ -4409,5 +3869,6 @@
              */
 
-            for(i = Stage + 1; i < GL_LIMITS(texture_stages); i++) {
+            for (i = Stage + 1; i < This->adapter->gl_info.limits.texture_stages; ++i)
+            {
                 if(This->updateStateBlock->textureState[i][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
                     break;
@@ -4436,9 +3897,119 @@
  * Get / Set Texture
  *****/
-static HRESULT WINAPI IWineD3DDeviceImpl_SetTexture(IWineD3DDevice *iface, DWORD Stage, IWineD3DBaseTexture* pTexture) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DBaseTexture *oldTexture;
-
-    TRACE("(%p) : Stage %#x, Texture %p\n", This, Stage, pTexture);
+static HRESULT WINAPI IWineD3DDeviceImpl_SetTexture(IWineD3DDevice *iface,
+        DWORD stage, IWineD3DBaseTexture *texture)
+{
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    IWineD3DBaseTexture *prev;
+
+    TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
+
+    if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
+        stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
+
+    /* Windows accepts overflowing this array... we do not. */
+    if (stage >= sizeof(This->stateBlock->textures) / sizeof(*This->stateBlock->textures))
+    {
+        WARN("Ignoring invalid stage %u.\n", stage);
+        return WINED3D_OK;
+    }
+
+    /* SetTexture isn't allowed on textures in WINED3DPOOL_SCRATCH */
+    if (texture && ((IWineD3DTextureImpl *)texture)->resource.pool == WINED3DPOOL_SCRATCH)
+    {
+        WARN("Rejecting attempt to set scratch texture.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    This->updateStateBlock->changed.textures |= 1 << stage;
+
+    prev = This->updateStateBlock->textures[stage];
+    TRACE("Previous texture %p.\n", prev);
+
+    if (texture == prev)
+    {
+        TRACE("App is setting the same texture again, nothing to do.\n");
+        return WINED3D_OK;
+    }
+
+    TRACE("Setting new texture to %p.\n", texture);
+    This->updateStateBlock->textures[stage] = texture;
+
+    if (This->isRecordingState)
+    {
+        TRACE("Recording... not performing anything\n");
+
+        if (texture) IWineD3DBaseTexture_AddRef(texture);
+        if (prev) IWineD3DBaseTexture_Release(prev);
+
+        return WINED3D_OK;
+    }
+
+    if (texture)
+    {
+        IWineD3DBaseTextureImpl *t = (IWineD3DBaseTextureImpl *)texture;
+        LONG bind_count = InterlockedIncrement(&t->baseTexture.bindCount);
+        UINT dimensions = IWineD3DBaseTexture_GetTextureDimensions(texture);
+
+        IWineD3DBaseTexture_AddRef(texture);
+
+        if (!prev || dimensions != IWineD3DBaseTexture_GetTextureDimensions(prev))
+        {
+            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADER);
+        }
+
+        if (!prev && stage < MAX_TEXTURES)
+        {
+            /* The source arguments for color and alpha ops have different
+             * meanings when a NULL texture is bound, so the COLOROP and
+             * ALPHAOP have to be dirtified. */
+            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(stage, WINED3DTSS_COLOROP));
+            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(stage, WINED3DTSS_ALPHAOP));
+        }
+
+        if (bind_count == 1) t->baseTexture.sampler = stage;
+    }
+
+    if (prev)
+    {
+        IWineD3DBaseTextureImpl *t = (IWineD3DBaseTextureImpl *)prev;
+        LONG bind_count = InterlockedDecrement(&t->baseTexture.bindCount);
+
+        IWineD3DBaseTexture_Release(prev);
+
+        if (!texture && stage < MAX_TEXTURES)
+        {
+            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(stage, WINED3DTSS_COLOROP));
+            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(stage, WINED3DTSS_ALPHAOP));
+        }
+
+        if (bind_count && t->baseTexture.sampler == stage)
+        {
+            unsigned int i;
+
+            /* Search for other stages the texture is bound to. Shouldn't
+             * happen if applications bind textures to a single stage only. */
+            TRACE("Searching for other stages the texture is bound to.\n");
+            for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
+            {
+                if (This->updateStateBlock->textures[i] == prev)
+                {
+                    TRACE("Texture is also bound to stage %u.\n", i);
+                    t->baseTexture.sampler = i;
+                    break;
+                }
+            }
+        }
+    }
+
+    IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(stage));
+
+    return WINED3D_OK;
+}
+
+static HRESULT WINAPI IWineD3DDeviceImpl_GetTexture(IWineD3DDevice *iface, DWORD Stage, IWineD3DBaseTexture** ppTexture) {
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+
+    TRACE("(%p) : Stage %#x, ppTexture %p\n", This, Stage, ppTexture);
 
     if (Stage >= WINED3DVERTEXTEXTURESAMPLER0 && Stage <= WINED3DVERTEXTEXTURESAMPLER3) {
@@ -4451,105 +4022,4 @@
     }
 
-    oldTexture = This->updateStateBlock->textures[Stage];
-
-    /* SetTexture isn't allowed on textures in WINED3DPOOL_SCRATCH */
-    if (pTexture && ((IWineD3DTextureImpl*)pTexture)->resource.pool == WINED3DPOOL_SCRATCH)
-    {
-        WARN("(%p) Attempt to set scratch texture rejected\n", pTexture);
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    TRACE("GL_LIMITS %d\n",GL_LIMITS(sampler_stages));
-    TRACE("(%p) : oldtexture(%p)\n", This,oldTexture);
-
-    This->updateStateBlock->changed.textures |= 1 << Stage;
-    TRACE("(%p) : setting new texture to %p\n", This, pTexture);
-    This->updateStateBlock->textures[Stage]         = pTexture;
-
-    /* Handle recording of state blocks */
-    if (This->isRecordingState) {
-        TRACE("Recording... not performing anything\n");
-        return WINED3D_OK;
-    }
-
-    if(oldTexture == pTexture) {
-        TRACE("App is setting the same texture again, nothing to do\n");
-        return WINED3D_OK;
-    }
-
-    /** NOTE: MSDN says that setTexture increases the reference count,
-    * and that the application must set the texture back to null (or have a leaky application),
-    * This means we should pass the refcount up to the parent
-     *******************************/
-    if (NULL != This->updateStateBlock->textures[Stage]) {
-        IWineD3DBaseTextureImpl *new = (IWineD3DBaseTextureImpl *) This->updateStateBlock->textures[Stage];
-        ULONG bindCount = InterlockedIncrement(&new->baseTexture.bindCount);
-        UINT dimensions = IWineD3DBaseTexture_GetTextureDimensions(pTexture);
-
-        IWineD3DBaseTexture_AddRef(This->updateStateBlock->textures[Stage]);
-
-        if (!oldTexture || dimensions != IWineD3DBaseTexture_GetTextureDimensions(oldTexture))
-        {
-            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADER);
-        }
-
-        if(oldTexture == NULL && Stage < MAX_TEXTURES) {
-            /* The source arguments for color and alpha ops have different meanings when a NULL texture is bound,
-             * so the COLOROP and ALPHAOP have to be dirtified.
-             */
-            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(Stage, WINED3DTSS_COLOROP));
-            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(Stage, WINED3DTSS_ALPHAOP));
-        }
-        if(bindCount == 1) {
-            new->baseTexture.sampler = Stage;
-        }
-        /* More than one assignment? Doesn't matter, we only need one gl texture unit to use for uploading */
-
-    }
-
-    if (NULL != oldTexture) {
-        IWineD3DBaseTextureImpl *old = (IWineD3DBaseTextureImpl *) oldTexture;
-        LONG bindCount = InterlockedDecrement(&old->baseTexture.bindCount);
-
-        IWineD3DBaseTexture_Release(oldTexture);
-        if(pTexture == NULL && Stage < MAX_TEXTURES) {
-            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(Stage, WINED3DTSS_COLOROP));
-            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_TEXTURESTAGE(Stage, WINED3DTSS_ALPHAOP));
-        }
-
-        if(bindCount && old->baseTexture.sampler == Stage) {
-            int i;
-            /* Have to do a search for the other sampler(s) where the texture is bound to
-             * Shouldn't happen as long as apps bind a texture only to one stage
-             */
-            TRACE("Searcing for other sampler / stage id where the texture is bound to\n");
-            for(i = 0; i < MAX_COMBINED_SAMPLERS; i++) {
-                if(This->updateStateBlock->textures[i] == oldTexture) {
-                    old->baseTexture.sampler = i;
-                    break;
-                }
-            }
-        }
-    }
-
-    IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(Stage));
-
-    return WINED3D_OK;
-}
-
-static HRESULT WINAPI IWineD3DDeviceImpl_GetTexture(IWineD3DDevice *iface, DWORD Stage, IWineD3DBaseTexture** ppTexture) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-
-    TRACE("(%p) : Stage %#x, ppTexture %p\n", This, Stage, ppTexture);
-
-    if (Stage >= WINED3DVERTEXTEXTURESAMPLER0 && Stage <= WINED3DVERTEXTEXTURESAMPLER3) {
-        Stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS);
-    }
-
-    if (Stage >= sizeof(This->stateBlock->textures)/sizeof(This->stateBlock->textures[0])) {
-        ERR("Current stage overflows textures array (stage %d)\n", Stage);
-        return WINED3D_OK; /* Windows accepts overflowing this array ... we do not. */
-    }
-
     *ppTexture=This->stateBlock->textures[Stage];
     if (*ppTexture)
@@ -4564,20 +4034,29 @@
  * Get Back Buffer
  *****/
-static HRESULT WINAPI IWineD3DDeviceImpl_GetBackBuffer(IWineD3DDevice *iface, UINT iSwapChain, UINT BackBuffer, WINED3DBACKBUFFER_TYPE Type,
-                                                IWineD3DSurface **ppBackBuffer) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DSwapChain *swapChain;
+static HRESULT WINAPI IWineD3DDeviceImpl_GetBackBuffer(IWineD3DDevice *iface, UINT swapchain_idx,
+        UINT backbuffer_idx, WINED3DBACKBUFFER_TYPE backbuffer_type, IWineD3DSurface **backbuffer)
+{
+    IWineD3DSwapChain *swapchain;
     HRESULT hr;
 
-    TRACE("(%p) : BackBuf %d Type %d SwapChain %d returning %p\n", This, BackBuffer, Type, iSwapChain, *ppBackBuffer);
-
-    hr = IWineD3DDeviceImpl_GetSwapChain(iface,  iSwapChain, &swapChain);
-    if (hr == WINED3D_OK) {
-        hr = IWineD3DSwapChain_GetBackBuffer(swapChain, BackBuffer, Type, ppBackBuffer);
-            IWineD3DSwapChain_Release(swapChain);
-    } else {
-        *ppBackBuffer = NULL;
-    }
-    return hr;
+    TRACE("iface %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
+            iface, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer);
+
+    hr = IWineD3DDeviceImpl_GetSwapChain(iface, swapchain_idx, &swapchain);
+    if (FAILED(hr))
+    {
+        WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr);
+        return hr;
+    }
+
+    hr = IWineD3DSwapChain_GetBackBuffer(swapchain, backbuffer_idx, backbuffer_type, backbuffer);
+    IWineD3DSwapChain_Release(swapchain);
+    if (FAILED(hr))
+    {
+        WARN("Failed to get backbuffer %u, hr %#x.\n", backbuffer_idx, hr);
+        return hr;
+    }
+
+    return WINED3D_OK;
 }
 
@@ -4585,5 +4064,5 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WARN("(%p) : stub, calling idirect3d for now\n", This);
-    return IWineD3D_GetDeviceCaps(This->wineD3D, This->adapterNo, This->devType, pCaps);
+    return IWineD3D_GetDeviceCaps(This->wined3d, This->adapter->ordinal, This->devType, pCaps);
 }
 
@@ -4646,5 +4125,4 @@
 static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IWineD3DStateBlock** ppStateBlock) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    unsigned int i, j;
     IWineD3DStateBlockImpl *object = This->updateStateBlock;
 
@@ -4655,91 +4133,5 @@
     }
 
-    for (i = 0; i <= WINEHIGHEST_RENDER_STATE >> 5; ++i)
-    {
-        DWORD map = object->changed.renderState[i];
-        for (j = 0; map; map >>= 1, ++j)
-        {
-            if (!(map & 1)) continue;
-
-            object->contained_render_states[object->num_contained_render_states++] = (i << 5) | j;
-        }
-    }
-
-    for (i = 0; i <= HIGHEST_TRANSFORMSTATE >> 5; ++i)
-    {
-        DWORD map = object->changed.transform[i];
-        for (j = 0; map; map >>= 1, ++j)
-        {
-            if (!(map & 1)) continue;
-
-            object->contained_transform_states[object->num_contained_transform_states++] = (i << 5) | j;
-        }
-    }
-    for(i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
-        if(object->changed.vertexShaderConstantsF[i]) {
-            object->contained_vs_consts_f[object->num_contained_vs_consts_f] = i;
-            object->num_contained_vs_consts_f++;
-        }
-    }
-    for(i = 0; i < MAX_CONST_I; i++) {
-        if (object->changed.vertexShaderConstantsI & (1 << i))
-        {
-            object->contained_vs_consts_i[object->num_contained_vs_consts_i] = i;
-            object->num_contained_vs_consts_i++;
-        }
-    }
-    for(i = 0; i < MAX_CONST_B; i++) {
-        if (object->changed.vertexShaderConstantsB & (1 << i))
-        {
-            object->contained_vs_consts_b[object->num_contained_vs_consts_b] = i;
-            object->num_contained_vs_consts_b++;
-        }
-    }
-    for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i)
-    {
-        if (object->changed.pixelShaderConstantsF[i])
-        {
-            object->contained_ps_consts_f[object->num_contained_ps_consts_f] = i;
-            ++object->num_contained_ps_consts_f;
-        }
-    }
-    for(i = 0; i < MAX_CONST_I; i++) {
-        if (object->changed.pixelShaderConstantsI & (1 << i))
-        {
-            object->contained_ps_consts_i[object->num_contained_ps_consts_i] = i;
-            object->num_contained_ps_consts_i++;
-        }
-    }
-    for(i = 0; i < MAX_CONST_B; i++) {
-        if (object->changed.pixelShaderConstantsB & (1 << i))
-        {
-            object->contained_ps_consts_b[object->num_contained_ps_consts_b] = i;
-            object->num_contained_ps_consts_b++;
-        }
-    }
-    for(i = 0; i < MAX_TEXTURES; i++) {
-        DWORD map = object->changed.textureState[i];
-
-        for(j = 0; map; map >>= 1, ++j)
-        {
-            if (!(map & 1)) continue;
-
-            object->contained_tss_states[object->num_contained_tss_states].stage = i;
-            object->contained_tss_states[object->num_contained_tss_states].state = j;
-            ++object->num_contained_tss_states;
-        }
-    }
-    for(i = 0; i < MAX_COMBINED_SAMPLERS; i++){
-        DWORD map = object->changed.samplerState[i];
-
-        for (j = 0; map; map >>= 1, ++j)
-        {
-            if (!(map & 1)) continue;
-
-            object->contained_sampler_states[object->num_contained_sampler_states].stage = i;
-            object->contained_sampler_states[object->num_contained_sampler_states].state = j;
-            ++object->num_contained_sampler_states;
-        }
-    }
+    stateblock_init_contained_states(object);
 
     *ppStateBlock = (IWineD3DStateBlock*) object;
@@ -4769,6 +4161,9 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_EndScene(IWineD3DDevice *iface) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+static HRESULT WINAPI IWineD3DDeviceImpl_EndScene(IWineD3DDevice *iface)
+{
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    struct wined3d_context *context;
+
     TRACE("(%p)\n", This);
 
@@ -4778,10 +4173,10 @@
     }
 
-    ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
     /* We only have to do this if we need to read the, swapbuffers performs a flush for us */
     wglFlush();
     /* No checkGLcall here to avoid locking the lock just for checking a call that hardly ever
-     * fails
-     */
+     * fails. */
+    context_release(context);
 
     This->inScene = FALSE;
@@ -4790,12 +4185,12 @@
 
 static HRESULT WINAPI IWineD3DDeviceImpl_Present(IWineD3DDevice *iface,
-                                          CONST RECT* pSourceRect, CONST RECT* pDestRect,
-                                          HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+        const RECT *pSourceRect, const RECT *pDestRect,
+        HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
+{
     IWineD3DSwapChain *swapChain = NULL;
     int i;
     int swapchains = IWineD3DDeviceImpl_GetNumberOfSwapChains(iface);
 
-    TRACE("(%p) Presenting the frame\n", This);
+    TRACE("iface %p.\n", iface);
 
     for(i = 0 ; i < swapchains ; i ++) {
@@ -4858,5 +4253,5 @@
     }
 
-    context = ActivateContext(This, (IWineD3DSurface *)target, CTXUSAGE_CLEAR);
+    context = context_acquire(This, (IWineD3DSurface *)target, CTXUSAGE_CLEAR);
 
     target->get_drawable_size(context, &drawable_width, &drawable_height);
@@ -4998,4 +4393,6 @@
     }
 
+    context_release(context);
+
     return WINED3D_OK;
 }
@@ -5245,18 +4642,19 @@
     This->stateBlock->baseVertexIndex = 0;
     This->up_strided = DrawPrimStrideData;
-    drawPrimitive(iface, 0 /* numindices */, 0 /* start_idx */, idxSize, pIndexData);
+    drawPrimitive(iface, vertex_count, 0 /* start_idx */, idxSize, pIndexData);
     This->up_strided = NULL;
     return WINED3D_OK;
 }
 
-static HRESULT IWineD3DDeviceImpl_UpdateVolume(IWineD3DDevice *iface, IWineD3DVolume *pSourceVolume, IWineD3DVolume *pDestinationVolume) {
-    /* This is a helper function for UpdateTexture, there is no public UpdateVolume method in d3d. Since it's
-     * not callable by the app directly no parameter validation checks are needed here.
-     */
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+/* This is a helper function for UpdateTexture, there is no UpdateVolume method in D3D. */
+static HRESULT IWineD3DDeviceImpl_UpdateVolume(IWineD3DDevice *iface,
+        IWineD3DVolume *pSourceVolume, IWineD3DVolume *pDestinationVolume)
+{
     WINED3DLOCKED_BOX src;
     WINED3DLOCKED_BOX dst;
     HRESULT hr;
-    TRACE("(%p)->(%p, %p)\n", This, pSourceVolume, pDestinationVolume);
+
+    TRACE("iface %p, src_volume %p, dst_volume %p.\n",
+            iface, pSourceVolume, pDestinationVolume);
 
     /* TODO: Implement direct loading into the gl volume instead of using memcpy and
@@ -5282,67 +4680,92 @@
 }
 
-/* Yet another way to update a texture, some apps use this to load default textures instead of using surface/texture lock/unlock */
-static HRESULT WINAPI IWineD3DDeviceImpl_UpdateTexture (IWineD3DDevice *iface, IWineD3DBaseTexture *pSourceTexture,  IWineD3DBaseTexture *pDestinationTexture){
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    HRESULT hr = WINED3D_OK;
-    WINED3DRESOURCETYPE sourceType;
-    WINED3DRESOURCETYPE destinationType;
-    int i ,levels;
-
-    /* TODO: think about moving the code into IWineD3DBaseTexture  */
-
-    TRACE("(%p) Source %p Destination %p\n", This, pSourceTexture, pDestinationTexture);
-
-    /* verify that the source and destination textures aren't NULL */
-    if (NULL == pSourceTexture || NULL == pDestinationTexture) {
-        WARN("(%p) : source (%p) and destination (%p) textures must not be NULL, returning WINED3DERR_INVALIDCALL\n",
-             This, pSourceTexture, pDestinationTexture);
-        hr = WINED3DERR_INVALIDCALL;
-    }
-
-    if (pSourceTexture == pDestinationTexture) {
-        WARN("(%p) : source (%p) and destination (%p) textures must be different, returning WINED3DERR_INVALIDCALL\n",
-             This, pSourceTexture, pDestinationTexture);
-        hr = WINED3DERR_INVALIDCALL;
-    }
-    /* Verify that the source and destination textures are the same type */
-    sourceType      = IWineD3DBaseTexture_GetType(pSourceTexture);
-    destinationType = IWineD3DBaseTexture_GetType(pDestinationTexture);
-
-    if (sourceType != destinationType) {
-        WARN("(%p) Sorce and destination types must match, returning WINED3DERR_INVALIDCALL\n",
-             This);
-        hr = WINED3DERR_INVALIDCALL;
-    }
-
-    /* check that both textures have the identical numbers of levels  */
-    if (IWineD3DBaseTexture_GetLevelCount(pDestinationTexture)  != IWineD3DBaseTexture_GetLevelCount(pSourceTexture)) {
-        WARN("(%p) : source (%p) and destination (%p) textures must have identical numbers of levels, returning WINED3DERR_INVALIDCALL\n", This, pSourceTexture, pDestinationTexture);
-        hr = WINED3DERR_INVALIDCALL;
-    }
-
-    if (WINED3D_OK == hr) {
-        IWineD3DBaseTextureImpl *pDestImpl = (IWineD3DBaseTextureImpl *) pDestinationTexture;
-
-        /* Make sure that the destination texture is loaded */
-        pDestImpl->baseTexture.internal_preload(pDestinationTexture, SRGB_RGB);
-
-        /* Update every surface level of the texture */
-        levels = IWineD3DBaseTexture_GetLevelCount(pDestinationTexture);
-
-        switch (sourceType) {
+static HRESULT WINAPI IWineD3DDeviceImpl_UpdateTexture(IWineD3DDevice *iface,
+        IWineD3DBaseTexture *src_texture, IWineD3DBaseTexture *dst_texture)
+{
+    unsigned int level_count, i;
+    WINED3DRESOURCETYPE type;
+    HRESULT hr;
+
+    TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
+
+    /* Verify that the source and destination textures are non-NULL. */
+    if (!src_texture || !dst_texture)
+    {
+        WARN("Source and destination textures must be non-NULL, returning WINED3DERR_INVALIDCALL.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    if (src_texture == dst_texture)
+    {
+        WARN("Source and destination are the same object, returning WINED3DERR_INVALIDCALL.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    /* Verify that the source and destination textures are the same type. */
+    type = IWineD3DBaseTexture_GetType(src_texture);
+    if (IWineD3DBaseTexture_GetType(dst_texture) != type)
+    {
+        WARN("Source and destination have different types, returning WINED3DERR_INVALIDCALL.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    /* Check that both textures have the identical numbers of levels. */
+    level_count = IWineD3DBaseTexture_GetLevelCount(src_texture);
+    if (IWineD3DBaseTexture_GetLevelCount(dst_texture) != level_count)
+    {
+        WARN("Source and destination have different level counts, returning WINED3DERR_INVALIDCALL.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    /* Make sure that the destination texture is loaded. */
+    ((IWineD3DBaseTextureImpl *)dst_texture)->baseTexture.internal_preload(dst_texture, SRGB_RGB);
+
+    /* Update every surface level of the texture. */
+    switch (type)
+    {
         case WINED3DRTYPE_TEXTURE:
+        {
+            IWineD3DSurface *src_surface;
+            IWineD3DSurface *dst_surface;
+
+            for (i = 0; i < level_count; ++i)
             {
-                IWineD3DSurface *srcSurface;
-                IWineD3DSurface *destSurface;
-
-                for (i = 0 ; i < levels ; ++i) {
-                    IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture *)pSourceTexture,      i, &srcSurface);
-                    IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture *)pDestinationTexture, i, &destSurface);
-                    hr = IWineD3DDevice_UpdateSurface(iface, srcSurface, NULL, destSurface, NULL);
-                    IWineD3DSurface_Release(srcSurface);
-                    IWineD3DSurface_Release(destSurface);
-                    if (WINED3D_OK != hr) {
-                        WARN("(%p) : Call to update surface failed\n", This);
+                IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture *)src_texture, i, &src_surface);
+                IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture *)dst_texture, i, &dst_surface);
+                hr = IWineD3DDevice_UpdateSurface(iface, src_surface, NULL, dst_surface, NULL);
+                IWineD3DSurface_Release(dst_surface);
+                IWineD3DSurface_Release(src_surface);
+                if (FAILED(hr))
+                {
+                    WARN("IWineD3DDevice_UpdateSurface failed, hr %#x.\n", hr);
+                    return hr;
+                }
+            }
+            break;
+        }
+
+        case WINED3DRTYPE_CUBETEXTURE:
+        {
+            IWineD3DSurface *src_surface;
+            IWineD3DSurface *dst_surface;
+            WINED3DCUBEMAP_FACES face;
+
+            for (i = 0; i < level_count; ++i)
+            {
+                /* Update each cube face. */
+                for (face = WINED3DCUBEMAP_FACE_POSITIVE_X; face <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++face)
+                {
+                    hr = IWineD3DCubeTexture_GetCubeMapSurface((IWineD3DCubeTexture *)src_texture,
+                            face, i, &src_surface);
+                    if (FAILED(hr)) ERR("Failed to get src cube surface face %u, level %u, hr %#x.\n", face, i, hr);
+                    hr = IWineD3DCubeTexture_GetCubeMapSurface((IWineD3DCubeTexture *)dst_texture,
+                            face, i, &dst_surface);
+                    if (FAILED(hr)) ERR("Failed to get dst cube surface face %u, level %u, hr %#x.\n", face, i, hr);
+                    hr = IWineD3DDevice_UpdateSurface(iface, src_surface, NULL, dst_surface, NULL);
+                    IWineD3DSurface_Release(dst_surface);
+                    IWineD3DSurface_Release(src_surface);
+                    if (FAILED(hr))
+                    {
+                        WARN("IWineD3DDevice_UpdateSurface failed, hr %#x.\n", hr);
                         return hr;
                     }
@@ -5350,63 +4773,33 @@
             }
             break;
-        case WINED3DRTYPE_CUBETEXTURE:
+        }
+
+        case WINED3DRTYPE_VOLUMETEXTURE:
+        {
+            IWineD3DVolume *src_volume;
+            IWineD3DVolume *dst_volume;
+
+            for (i = 0; i < level_count; ++i)
             {
-                IWineD3DSurface *srcSurface;
-                IWineD3DSurface *destSurface;
-                WINED3DCUBEMAP_FACES faceType;
-
-                for (i = 0 ; i < levels ; ++i) {
-                    /* Update each cube face */
-                    for (faceType = WINED3DCUBEMAP_FACE_POSITIVE_X; faceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++faceType){
-                        hr = IWineD3DCubeTexture_GetCubeMapSurface((IWineD3DCubeTexture *)pSourceTexture,      faceType, i, &srcSurface);
-                        if (WINED3D_OK != hr) {
-                            FIXME("(%p) : Failed to get src cube surface facetype %d, level %d\n", This, faceType, i);
-                        } else {
-                            TRACE("Got srcSurface %p\n", srcSurface);
-                        }
-                        hr = IWineD3DCubeTexture_GetCubeMapSurface((IWineD3DCubeTexture *)pDestinationTexture, faceType, i, &destSurface);
-                        if (WINED3D_OK != hr) {
-                            FIXME("(%p) : Failed to get src cube surface facetype %d, level %d\n", This, faceType, i);
-                        } else {
-                            TRACE("Got desrSurface %p\n", destSurface);
-                        }
-                        hr = IWineD3DDevice_UpdateSurface(iface, srcSurface, NULL, destSurface, NULL);
-                        IWineD3DSurface_Release(srcSurface);
-                        IWineD3DSurface_Release(destSurface);
-                        if (WINED3D_OK != hr) {
-                            WARN("(%p) : Call to update surface failed\n", This);
-                            return hr;
-                        }
-                    }
+                IWineD3DVolumeTexture_GetVolumeLevel((IWineD3DVolumeTexture *)src_texture, i, &src_volume);
+                IWineD3DVolumeTexture_GetVolumeLevel((IWineD3DVolumeTexture *)dst_texture, i, &dst_volume);
+                hr = IWineD3DDeviceImpl_UpdateVolume(iface, src_volume, dst_volume);
+                IWineD3DVolume_Release(dst_volume);
+                IWineD3DVolume_Release(src_volume);
+                if (FAILED(hr))
+                {
+                    WARN("IWineD3DDeviceImpl_UpdateVolume failed, hr %#x.\n", hr);
+                    return hr;
                 }
             }
             break;
-
-        case WINED3DRTYPE_VOLUMETEXTURE:
-            {
-                IWineD3DVolume  *srcVolume  = NULL;
-                IWineD3DVolume  *destVolume = NULL;
-
-                for (i = 0 ; i < levels ; ++i) {
-                    IWineD3DVolumeTexture_GetVolumeLevel((IWineD3DVolumeTexture *)pSourceTexture,      i, &srcVolume);
-                    IWineD3DVolumeTexture_GetVolumeLevel((IWineD3DVolumeTexture *)pDestinationTexture, i, &destVolume);
-                    hr =  IWineD3DDeviceImpl_UpdateVolume(iface, srcVolume, destVolume);
-                    IWineD3DVolume_Release(srcVolume);
-                    IWineD3DVolume_Release(destVolume);
-                    if (WINED3D_OK != hr) {
-                        WARN("(%p) : Call to update volume failed\n", This);
-                        return hr;
-                    }
-                }
-            }
-            break;
+        }
 
         default:
-            FIXME("(%p) : Unsupported source and destination type\n", This);
-            hr = WINED3DERR_INVALIDCALL;
-        }
-    }
-
-    return hr;
+            FIXME("Unsupported texture type %#x.\n", type);
+            return WINED3DERR_INVALIDCALL;
+    }
+
+    return WINED3D_OK;
 }
 
@@ -5600,30 +4993,38 @@
 }
 
-
-static HRESULT  WINAPI  IWineD3DDeviceImpl_GetRasterStatus(IWineD3DDevice *iface, UINT iSwapChain, WINED3DRASTER_STATUS* pRasterStatus) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DSwapChain *swapChain;
+static HRESULT WINAPI IWineD3DDeviceImpl_GetRasterStatus(IWineD3DDevice *iface,
+        UINT swapchain_idx, WINED3DRASTER_STATUS *raster_status)
+{
+    IWineD3DSwapChain *swapchain;
     HRESULT hr;
 
-    TRACE("(%p) :  SwapChain %d returning %p\n", This, iSwapChain, pRasterStatus);
-
-    hr = IWineD3DDeviceImpl_GetSwapChain(iface, iSwapChain, &swapChain);
-    if(hr == WINED3D_OK){
-        hr = IWineD3DSwapChain_GetRasterStatus(swapChain, pRasterStatus);
-        IWineD3DSwapChain_Release(swapChain);
-    }else{
-        FIXME("(%p) IWineD3DSwapChain_GetRasterStatus returned in error\n", This);
-    }
-    return hr;
-}
-
-
-static HRESULT  WINAPI  IWineD3DDeviceImpl_SetNPatchMode(IWineD3DDevice *iface, float nSegments) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    TRACE("iface %p, swapchain_idx %u, raster_status %p.\n",
+            iface, swapchain_idx, raster_status);
+
+    hr = IWineD3DDeviceImpl_GetSwapChain(iface, swapchain_idx, &swapchain);
+    if (FAILED(hr))
+    {
+        WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr);
+        return hr;
+    }
+
+    hr = IWineD3DSwapChain_GetRasterStatus(swapchain, raster_status);
+    IWineD3DSwapChain_Release(swapchain);
+    if (FAILED(hr))
+    {
+        WARN("Failed to get raster status, hr %#x.\n", hr);
+        return hr;
+    }
+
+    return WINED3D_OK;
+}
+
+static HRESULT WINAPI IWineD3DDeviceImpl_SetNPatchMode(IWineD3DDevice *iface, float nSegments)
+{
     static BOOL warned;
     if(nSegments != 0.0f) {
         if (!warned)
         {
-            FIXME("(%p) : stub nSegments(%f)\n", This, nSegments);
+            FIXME("iface %p, nSegments %.8e stub!\n", iface, nSegments);
             warned = TRUE;
         }
@@ -5632,10 +5033,10 @@
 }
 
-static float    WINAPI  IWineD3DDeviceImpl_GetNPatchMode(IWineD3DDevice *iface) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+static float WINAPI IWineD3DDeviceImpl_GetNPatchMode(IWineD3DDevice *iface)
+{
     static BOOL warned;
     if (!warned)
     {
-        FIXME("(%p) : stub returning(%f)\n", This, 0.0f);
+        FIXME("iface %p stub!\n", iface);
         warned = TRUE;
     }
@@ -5663,4 +5064,5 @@
     int bpp;
     CONVERT_TYPES convert = NO_CONVERSION;
+    struct wined3d_context *context;
 
     WINED3DSURFACE_DESC  winedesc;
@@ -5706,5 +5108,5 @@
     }
 
-    ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
 
     ENTER_GL();
@@ -5797,4 +5199,5 @@
 
     LEAVE_GL();
+    context_release(context);
 
     IWineD3DSurface_ModifyLocation(pDestinationSurface, SFLAG_INTEXTURE, TRUE);
@@ -5895,8 +5298,10 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_DrawTriPatch(IWineD3DDevice *iface, UINT Handle, CONST float* pNumSegs, CONST WINED3DTRIPATCH_INFO* pTriPatchInfo) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    TRACE("(%p) Handle(%d) noSegs(%p) tripatch(%p)\n", This, Handle, pNumSegs, pTriPatchInfo);
-    FIXME("(%p) : Stub\n", This);
+static HRESULT WINAPI IWineD3DDeviceImpl_DrawTriPatch(IWineD3DDevice *iface,
+        UINT handle, const float *segment_count, const WINED3DTRIPATCH_INFO *patch_info)
+{
+    FIXME("iface %p, handle %#x, segment_count %p, patch_info %p stub!\n",
+            iface, handle, segment_count, patch_info);
+
     return WINED3D_OK;
 }
@@ -5944,22 +5349,19 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     struct wined3d_context *context;
-    IWineD3DSwapChain *swapchain;
-
-    swapchain = get_swapchain(surface);
-    if (swapchain) {
-        GLenum buffer;
-
+
+    if (!surface_is_offscreen(surface))
+    {
         TRACE("Surface %p is onscreen\n", surface);
 
-        context = ActivateContext(This, surface, CTXUSAGE_RESOURCELOAD);
+        context = context_acquire(This, surface, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
         context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
-        buffer = surface_get_gl_buffer(surface, swapchain);
-        glDrawBuffer(buffer);
-        checkGLcall("glDrawBuffer()");
-    } else {
+        context_set_draw_buffer(context, surface_get_gl_buffer(surface));
+    }
+    else
+    {
         TRACE("Surface %p is offscreen\n", surface);
 
-        context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+        context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
         context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
@@ -5970,5 +5372,5 @@
     if (rect) {
         glEnable(GL_SCISSOR_TEST);
-        if(!swapchain) {
+        if(surface_is_offscreen(surface)) {
             glScissor(rect->x1, rect->y1, rect->x2 - rect->x1, rect->y2 - rect->y1);
         } else {
@@ -5993,11 +5395,6 @@
     checkGLcall("glClear");
 
-    if (swapchain && surface == ((IWineD3DSwapChainImpl *)swapchain)->frontBuffer
-            && ((IWineD3DSwapChainImpl *)swapchain)->backBuffer) {
-        glDrawBuffer(GL_BACK);
-        checkGLcall("glDrawBuffer()");
-    }
-
     LEAVE_GL();
+    context_release(context);
 }
 
@@ -6110,9 +5507,11 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_ColorFill(IWineD3DDevice *iface, IWineD3DSurface *pSurface, CONST WINED3DRECT* pRect, WINED3DCOLOR color) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+static HRESULT WINAPI IWineD3DDeviceImpl_ColorFill(IWineD3DDevice *iface,
+        IWineD3DSurface *pSurface, const WINED3DRECT *pRect, WINED3DCOLOR color)
+{
     IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *) pSurface;
     WINEDDBLTFX BltFx;
-    TRACE("(%p) Colour fill Surface: %p rect: %p color: 0x%08x\n", This, pSurface, pRect, color);
+
+    TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
 
     if (surface->resource.pool != WINED3DPOOL_DEFAULT && surface->resource.pool != WINED3DPOOL_SYSTEMMEM) {
@@ -6192,6 +5591,8 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
 
-    if (RenderTargetIndex >= GL_LIMITS(buffers)) {
-        ERR("(%p) : Only %d render targets are supported.\n", This, GL_LIMITS(buffers));
+    if (RenderTargetIndex >= This->adapter->gl_info.limits.buffers)
+    {
+        ERR("(%p) : Only %d render targets are supported.\n",
+                This, This->adapter->gl_info.limits.buffers);
         return WINED3DERR_INVALIDCALL;
     }
@@ -6205,6 +5606,7 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_SetFrontBackBuffers(IWineD3DDevice *iface, IWineD3DSurface *Front, IWineD3DSurface *Back) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+static HRESULT WINAPI IWineD3DDeviceImpl_SetFrontBackBuffers(IWineD3DDevice *iface,
+        IWineD3DSurface *Front, IWineD3DSurface *Back)
+{
     IWineD3DSurfaceImpl *FrontImpl = (IWineD3DSurfaceImpl *) Front;
     IWineD3DSurfaceImpl *BackImpl = (IWineD3DSurfaceImpl *) Back;
@@ -6212,5 +5614,5 @@
     HRESULT hr;
 
-    TRACE("(%p)->(%p,%p)\n", This, FrontImpl, BackImpl);
+    TRACE("iface %p, front %p, back %p.\n", iface, Front, Back);
 
     hr = IWineD3DDevice_GetSwapChain(iface, 0, (IWineD3DSwapChain **) &Swapchain);
@@ -6350,12 +5752,13 @@
     dst_swapchain = get_swapchain(dst_surface);
 
-    if (src_swapchain) context = ActivateContext(This, src_surface, CTXUSAGE_RESOURCELOAD);
-    else if (dst_swapchain) context = ActivateContext(This, dst_surface, CTXUSAGE_RESOURCELOAD);
-    else context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    if (src_swapchain) context = context_acquire(This, src_surface, CTXUSAGE_RESOURCELOAD);
+    else if (dst_swapchain) context = context_acquire(This, dst_surface, CTXUSAGE_RESOURCELOAD);
+    else context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
 
     gl_info = context->gl_info;
 
-    if (src_swapchain) {
-        GLenum buffer = surface_get_gl_buffer(src_surface, src_swapchain);
+    if (!surface_is_offscreen(src_surface))
+    {
+        GLenum buffer = surface_get_gl_buffer(src_surface);
 
         TRACE("Source surface %p is onscreen\n", src_surface);
@@ -6394,6 +5797,7 @@
 
     /* Attach dst surface to dst fbo */
-    if (dst_swapchain) {
-        GLenum buffer = surface_get_gl_buffer(dst_surface, dst_swapchain);
+    if (!surface_is_offscreen(dst_surface))
+    {
+        GLenum buffer = surface_get_gl_buffer(dst_surface);
 
         TRACE("Destination surface %p is onscreen\n", dst_surface);
@@ -6419,7 +5823,8 @@
         ENTER_GL();
         context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
-        glDrawBuffer(buffer);
-        checkGLcall("glDrawBuffer()");
-    } else {
+        context_set_draw_buffer(context, buffer);
+    }
+    else
+    {
         TRACE("Destination surface %p is offscreen\n", dst_surface);
 
@@ -6427,6 +5832,5 @@
         context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, &context->dst_fbo);
         context_attach_surface_fbo(context, GL_DRAW_FRAMEBUFFER, 0, dst_surface);
-        glDrawBuffer(GL_COLOR_ATTACHMENT0);
-        checkGLcall("glDrawBuffer()");
+        context_set_draw_buffer(context, GL_COLOR_ATTACHMENT0);
         context_attach_depth_stencil_fbo(context, GL_DRAW_FRAMEBUFFER, NULL, FALSE);
     }
@@ -6444,24 +5848,20 @@
     }
 
+    LEAVE_GL();
+    context_release(context);
+
     IWineD3DSurface_ModifyLocation(dst_surface, SFLAG_INDRAWABLE, TRUE);
-
-    /* If we switched from GL_BACK to GL_FRONT above, we need to switch back here */
-    if (dst_swapchain && dst_surface == ((IWineD3DSwapChainImpl *)dst_swapchain)->frontBuffer
-            && ((IWineD3DSwapChainImpl *)dst_swapchain)->backBuffer) {
-        glDrawBuffer(GL_BACK);
-        checkGLcall("glDrawBuffer()");
-    }
-    LEAVE_GL();
-}
-
-static HRESULT WINAPI IWineD3DDeviceImpl_SetRenderTarget(IWineD3DDevice *iface, DWORD RenderTargetIndex, IWineD3DSurface *pRenderTarget) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    WINED3DVIEWPORT viewport;
+}
+
+static HRESULT WINAPI IWineD3DDeviceImpl_SetRenderTarget(IWineD3DDevice *iface, DWORD RenderTargetIndex, IWineD3DSurface *pRenderTarget,
+                                                         BOOL set_viewport) {
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
 
     TRACE("(%p) : Setting rendertarget %d to %p\n", This, RenderTargetIndex, pRenderTarget);
 
-    if (RenderTargetIndex >= GL_LIMITS(buffers)) {
+    if (RenderTargetIndex >= This->adapter->gl_info.limits.buffers)
+    {
         WARN("(%p) : Unsupported target %u set, returning WINED3DERR_INVALIDCALL(only %u supported)\n",
-             This, RenderTargetIndex, GL_LIMITS(buffers));
+                This, RenderTargetIndex, This->adapter->gl_info.limits.buffers);
         return WINED3DERR_INVALIDCALL;
     }
@@ -6490,13 +5890,22 @@
 
     /* Render target 0 is special */
-    if(RenderTargetIndex == 0) {
-        /* Finally, reset the viewport as the MSDN states. */
-        viewport.Height = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Height;
-        viewport.Width  = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Width;
-        viewport.X      = 0;
-        viewport.Y      = 0;
-        viewport.MaxZ   = 1.0f;
-        viewport.MinZ   = 0.0f;
-        IWineD3DDeviceImpl_SetViewport(iface, &viewport);
+    if(RenderTargetIndex == 0 && set_viewport) {
+        /* Finally, reset the viewport and scissor rect as the MSDN states.
+         * Tests show that stateblock recording is ignored, the change goes
+         * directly into the primary stateblock.
+         */
+        This->stateBlock->viewport.Height = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Height;
+        This->stateBlock->viewport.Width  = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Width;
+        This->stateBlock->viewport.X      = 0;
+        This->stateBlock->viewport.Y      = 0;
+        This->stateBlock->viewport.MaxZ   = 1.0f;
+        This->stateBlock->viewport.MinZ   = 0.0f;
+        IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VIEWPORT);
+
+        This->stateBlock->scissorRect.top = 0;
+        This->stateBlock->scissorRect.left = 0;
+        This->stateBlock->scissorRect.right = This->stateBlock->viewport.Width;
+        This->stateBlock->scissorRect.bottom = This->stateBlock->viewport.Height;
+        IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SCISSORRECT);
     }
     return WINED3D_OK;
@@ -6525,7 +5934,8 @@
                 surface_modify_ds_location(This->stencilBufferTarget, SFLAG_DS_DISCARDED);
             } else {
-                struct wined3d_context *context = ActivateContext(This, This->render_targets[0], CTXUSAGE_RESOURCELOAD);
+                struct wined3d_context *context = context_acquire(This, This->render_targets[0], CTXUSAGE_RESOURCELOAD);
                 surface_load_ds_location(This->stencilBufferTarget, context, SFLAG_DS_OFFSCREEN);
                 surface_modify_ds_location(This->stencilBufferTarget, SFLAG_DS_OFFSCREEN);
+                context_release(context);
             }
         }
@@ -6560,8 +5970,9 @@
     /* some basic validation checks */
     if(This->cursorTexture) {
-        ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+        struct wined3d_context *context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
         glDeleteTextures(1, &This->cursorTexture);
         LEAVE_GL();
+        context_release(context);
         This->cursorTexture = 0;
     }
@@ -6602,6 +6013,7 @@
             if (SUCCEEDED(IWineD3DSurface_LockRect(pCursorBitmap, &rect, NULL, WINED3DLOCK_READONLY)))
             {
-                const struct GlPixelFormatDesc *glDesc =
-                        getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, &GLINFO_LOCATION);
+                const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
+                const struct GlPixelFormatDesc *glDesc = getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, gl_info);
+                struct wined3d_context *context;
                 char *mem, *bits = rect.pBits;
                 GLint intfmt = glDesc->glInternal;
@@ -6621,9 +6033,10 @@
                 IWineD3DSurface_UnlockRect(pCursorBitmap);
 
-                ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+                context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
 
                 ENTER_GL();
 
-                if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
+                if (gl_info->supported[APPLE_CLIENT_STORAGE])
+                {
                     glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
                     checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
@@ -6648,5 +6061,6 @@
                 checkGLcall("glTexImage2D");
 
-                if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
+                if (gl_info->supported[APPLE_CLIENT_STORAGE])
+                {
                     glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
                     checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
@@ -6654,4 +6068,6 @@
 
                 LEAVE_GL();
+
+                context_release(context);
             }
             else
@@ -6681,10 +6097,8 @@
             cursorInfo.xHotspot = XHotSpot;
             cursorInfo.yHotspot = YHotSpot;
-            cursorInfo.hbmMask = CreateBitmap(pSur->currentDesc.Width,
-                                              pSur->currentDesc.Height, 1,
-                                              1, &maskBits);
-            cursorInfo.hbmColor = CreateBitmap(pSur->currentDesc.Width,
-                                               pSur->currentDesc.Height, 1,
-                                               32, lockedRect.pBits);
+            cursorInfo.hbmMask = CreateBitmap(pSur->currentDesc.Width, pSur->currentDesc.Height,
+                    1, 1, maskBits);
+            cursorInfo.hbmColor = CreateBitmap(pSur->currentDesc.Width, pSur->currentDesc.Height,
+                    1, 32, lockedRect.pBits);
             IWineD3DSurface_UnlockRect(pCursorBitmap);
             /* Create our cursor and clean up. */
@@ -6747,29 +6161,4 @@
 }
 
-static HRESULT  WINAPI  IWineD3DDeviceImpl_TestCooperativeLevel(IWineD3DDevice* iface) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
-    IWineD3DResourceImpl *resource;
-    TRACE("(%p) : state (%u)\n", This, This->state);
-
-    /* TODO: Implement wrapping of the WndProc so that mimimize and maximize can be monitored and the states adjusted. */
-    switch (This->state) {
-    case WINED3D_OK:
-        return WINED3D_OK;
-    case WINED3DERR_DEVICELOST:
-        {
-            LIST_FOR_EACH_ENTRY(resource, &This->resources, IWineD3DResourceImpl, resource.resource_list_entry) {
-                if (resource->resource.pool == WINED3DPOOL_DEFAULT)
-                    return WINED3DERR_DEVICENOTRESET;
-            }
-            return WINED3DERR_DEVICELOST;
-        }
-    case WINED3DERR_DRIVERINTERNALERROR:
-        return WINED3DERR_DRIVERINTERNALERROR;
-    }
-
-    /* Unknown state */
-    return WINED3DERR_DRIVERINTERNALERROR;
-}
-
 static HRESULT WINAPI evict_managed_resource(IWineD3DResource *resource, void *data) {
     TRACE("checking resource %p for eviction\n", resource);
@@ -6782,7 +6171,7 @@
 }
 
-static HRESULT  WINAPI  IWineD3DDeviceImpl_EvictManagedResources(IWineD3DDevice* iface) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
-    TRACE("(%p)\n", This);
+static HRESULT WINAPI IWineD3DDeviceImpl_EvictManagedResources(IWineD3DDevice *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     IWineD3DDevice_EnumResources(iface, evict_managed_resource, NULL);
@@ -6790,7 +6179,8 @@
 }
 
-static void updateSurfaceDesc(IWineD3DSurfaceImpl *surface, const WINED3DPRESENT_PARAMETERS* pPresentationParameters)
-{
-    IWineD3DDeviceImpl *This = surface->resource.wineD3DDevice; /* for GL_SUPPORT */
+static HRESULT updateSurfaceDesc(IWineD3DSurfaceImpl *surface, const WINED3DPRESENT_PARAMETERS* pPresentationParameters)
+{
+    IWineD3DDeviceImpl *device = surface->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
     /* Reallocate proper memory for the front and back buffer and adjust their sizes */
@@ -6807,6 +6197,7 @@
     surface->currentDesc.Width = pPresentationParameters->BackBufferWidth;
     surface->currentDesc.Height = pPresentationParameters->BackBufferHeight;
-    if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) || GL_SUPPORT(ARB_TEXTURE_RECTANGLE) ||
-        GL_SUPPORT(WINE_NORMALIZED_TEXRECT)) {
+    if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[ARB_TEXTURE_RECTANGLE]
+            || gl_info->supported[WINE_NORMALIZED_TEXRECT])
+    {
         surface->pow2Width = pPresentationParameters->BackBufferWidth;
         surface->pow2Height = pPresentationParameters->BackBufferHeight;
@@ -6823,8 +6214,9 @@
     if (surface->texture_name)
     {
-        ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+        struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
         glDeleteTextures(1, &surface->texture_name);
         LEAVE_GL();
+        context_release(context);
         surface->texture_name = 0;
         surface->Flags &= ~SFLAG_CLIENT;
@@ -6840,10 +6232,12 @@
     surface->resource.heapMemory = NULL;
     surface->resource.size = IWineD3DSurface_GetPitch((IWineD3DSurface *) surface) * surface->pow2Width;
-    /* INDRAWABLE is a sane place for implicit targets after the reset, INSYSMEM is more appropriate for depth stencils. */
-    if (surface->resource.usage & WINED3DUSAGE_DEPTHSTENCIL) {
-        IWineD3DSurface_ModifyLocation((IWineD3DSurface *) surface, SFLAG_INSYSMEM, TRUE);
-    } else {
-        IWineD3DSurface_ModifyLocation((IWineD3DSurface *) surface, SFLAG_INDRAWABLE, TRUE);
-    }
+
+    /* Put all surfaces into sysmem - the drawable might disappear if the backbuffer was rendered
+     * to a FBO */
+    if(!surface_init_sysmem((IWineD3DSurface *) surface))
+    {
+        return E_OUTOFMEMORY;
+    }
+    return WINED3D_OK;
 }
 
@@ -6866,8 +6260,8 @@
     if(!pp->BackBufferHeight) return TRUE;
 
-    count = IWineD3D_GetAdapterModeCount(This->wineD3D, This->adapter->num, WINED3DFMT_UNKNOWN);
+    count = IWineD3D_GetAdapterModeCount(This->wined3d, This->adapter->ordinal, WINED3DFMT_UNKNOWN);
     for(i = 0; i < count; i++) {
         memset(&m, 0, sizeof(m));
-        hr = IWineD3D_EnumAdapterModes(This->wineD3D, This->adapter->num, WINED3DFMT_UNKNOWN, i, &m);
+        hr = IWineD3D_EnumAdapterModes(This->wined3d, This->adapter->ordinal, WINED3DFMT_UNKNOWN, i, &m);
         if(FAILED(hr)) {
             ERR("EnumAdapterModes failed\n");
@@ -6885,10 +6279,9 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) swapchain_iface;
-    const struct wined3d_context *context;
     const struct wined3d_gl_info *gl_info;
-    UINT i;
+    struct wined3d_context *context;
     IWineD3DBaseShaderImpl *shader;
 
-    context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
     gl_info = context->gl_info;
 
@@ -6914,16 +6307,11 @@
     This->frag_pipe->free_private(iface);
     This->shader_backend->shader_free_private(iface);
-
-    ENTER_GL();
-    for (i = 0; i < GL_LIMITS(textures); i++) {
-        /* Textures are recreated below */
-        glDeleteTextures(1, &This->dummyTextureName[i]);
-        checkGLcall("glDeleteTextures(1, &This->dummyTextureName[i])");
-        This->dummyTextureName[i] = 0;
-    }
-    LEAVE_GL();
-
-    while(This->numContexts) {
-        DestroyContext(This, This->contexts[0]);
+    destroy_dummy_textures(This, gl_info);
+
+    context_release(context);
+
+    while (This->numContexts)
+    {
+        context_destroy(This, This->contexts[0]);
     }
     HeapFree(GetProcessHeap(), 0, swapchain->context);
@@ -6935,4 +6323,5 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) swapchain_iface;
+    struct wined3d_context *context;
     HRESULT hr;
     IWineD3DSurfaceImpl *target;
@@ -6940,37 +6329,57 @@
     /* Recreate the primary swapchain's context */
     swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
-    if(swapchain->backBuffer) {
-        target = (IWineD3DSurfaceImpl *) swapchain->backBuffer[0];
-    } else {
-        target = (IWineD3DSurfaceImpl *) swapchain->frontBuffer;
-    }
-    swapchain->context[0] = CreateContext(This, target, swapchain->win_handle, FALSE,
-                                          &swapchain->presentParms);
+    if (!swapchain->context)
+    {
+        ERR("Failed to allocate memory for swapchain context array.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    target = (IWineD3DSurfaceImpl *)(swapchain->backBuffer ? swapchain->backBuffer[0] : swapchain->frontBuffer);
+    context = context_create(This, target, swapchain->win_handle, FALSE, &swapchain->presentParms);
+    if (!context)
+    {
+        WARN("Failed to create context.\n");
+        HeapFree(GetProcessHeap(), 0, swapchain->context);
+        return E_FAIL;
+    }
+
+    swapchain->context[0] = context;
     swapchain->num_contexts = 1;
-
     create_dummy_textures(This);
+    context_release(context);
 
     hr = This->shader_backend->shader_alloc_private(iface);
-    if(FAILED(hr)) {
-        ERR("Failed to recreate shader private data\n");
-        goto err_out;
-    }
+    if (FAILED(hr))
+    {
+        ERR("Failed to allocate shader private data, hr %#x.\n", hr);
+        goto err;
+    }
+
     hr = This->frag_pipe->alloc_private(iface);
-    if(FAILED(hr)) {
-        TRACE("Fragment pipeline private data couldn't be allocated\n");
-        goto err_out;
-    }
+    if (FAILED(hr))
+    {
+        ERR("Failed to allocate fragment pipe private data, hr %#x.\n", hr);
+        This->shader_backend->shader_free_private(iface);
+        goto err;
+    }
+
     hr = This->blitter->alloc_private(iface);
-    if(FAILED(hr)) {
-        TRACE("Blitter private data couldn't be allocated\n");
-        goto err_out;
-    }
-
-    return WINED3D_OK;
-
-err_out:
-    This->blitter->free_private(iface);
-    This->frag_pipe->free_private(iface);
-    This->shader_backend->shader_free_private(iface);
+    if (FAILED(hr))
+    {
+        ERR("Failed to allocate blitter private data, hr %#x.\n", hr);
+        This->frag_pipe->free_private(iface);
+        This->shader_backend->shader_free_private(iface);
+        goto err;
+    }
+
+    return WINED3D_OK;
+
+err:
+    context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
+    destroy_dummy_textures(This, context->gl_info);
+    context_release(context);
+    context_destroy(This, context);
+    HeapFree(GetProcessHeap(), 0, swapchain->context);
+    swapchain->num_contexts = 0;
     return hr;
 }
@@ -7098,10 +6507,26 @@
         swapchain->presentParms.BackBufferHeight = pPresentationParameters->BackBufferHeight;
 
-        updateSurfaceDesc((IWineD3DSurfaceImpl *)swapchain->frontBuffer, pPresentationParameters);
+        hr = updateSurfaceDesc((IWineD3DSurfaceImpl *)swapchain->frontBuffer, pPresentationParameters);
+        if(FAILED(hr))
+        {
+            IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
+            return hr;
+        }
+
         for(i = 0; i < swapchain->presentParms.BackBufferCount; i++) {
-            updateSurfaceDesc((IWineD3DSurfaceImpl *)swapchain->backBuffer[i], pPresentationParameters);
+            hr = updateSurfaceDesc((IWineD3DSurfaceImpl *)swapchain->backBuffer[i], pPresentationParameters);
+            if(FAILED(hr))
+            {
+                IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
+                return hr;
+            }
         }
         if(This->auto_depth_stencil_buffer) {
-            updateSurfaceDesc((IWineD3DSurfaceImpl *)This->auto_depth_stencil_buffer, pPresentationParameters);
+            hr = updateSurfaceDesc((IWineD3DSurfaceImpl *)This->auto_depth_stencil_buffer, pPresentationParameters);
+            if(FAILED(hr))
+            {
+                IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
+                return hr;
+            }
         }
     }
@@ -7116,7 +6541,6 @@
             if(swapchain->presentParms.Windowed) {
                 /* switch from windowed to fs */
-                IWineD3DDeviceImpl_SetupFullscreenWindow(iface, swapchain->win_handle,
-                                                         pPresentationParameters->BackBufferWidth,
-                                                         pPresentationParameters->BackBufferHeight);
+                swapchain_setup_fullscreen_window(swapchain, pPresentationParameters->BackBufferWidth,
+                        pPresentationParameters->BackBufferHeight);
             } else {
                 /* Fullscreen -> fullscreen mode change */
@@ -7127,5 +6551,5 @@
         } else if(swapchain->win_handle && !swapchain->presentParms.Windowed) {
             /* Fullscreen -> windowed switch */
-            IWineD3DDeviceImpl_RestoreWindow(iface, swapchain->win_handle);
+            swapchain_restore_fullscreen_window(swapchain);
         }
         swapchain->presentParms.Windowed = pPresentationParameters->Windowed;
@@ -7138,7 +6562,6 @@
         This->style = 0;
         This->exStyle = 0;
-        IWineD3DDeviceImpl_SetupFullscreenWindow(iface, swapchain->win_handle,
-                                                 pPresentationParameters->BackBufferWidth,
-                                                 pPresentationParameters->BackBufferHeight);
+        swapchain_setup_fullscreen_window(swapchain, pPresentationParameters->BackBufferWidth,
+                pPresentationParameters->BackBufferHeight);
         This->style = style;
         This->exStyle = exStyle;
@@ -7157,4 +6580,30 @@
     }
 
+    if(wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+    {
+        RECT client_rect;
+        GetClientRect(swapchain->win_handle, &client_rect);
+
+        if(!swapchain->presentParms.BackBufferCount)
+        {
+            TRACE("Single buffered rendering\n");
+            swapchain->render_to_fbo = FALSE;
+        }
+        else if(swapchain->presentParms.BackBufferWidth  != client_rect.right  ||
+                swapchain->presentParms.BackBufferHeight != client_rect.bottom )
+        {
+            TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u\n",
+                    swapchain->presentParms.BackBufferWidth,
+                    swapchain->presentParms.BackBufferHeight,
+                    client_rect.right, client_rect.bottom);
+            swapchain->render_to_fbo = TRUE;
+        }
+        else
+        {
+            TRACE("Rendering directly to GL_BACK\n");
+            swapchain->render_to_fbo = FALSE;
+        }
+    }
+
     hr = create_primary_opengl_context(iface, (IWineD3DSwapChain *) swapchain);
     IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
@@ -7166,10 +6615,10 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_SetDialogBoxMode(IWineD3DDevice *iface, BOOL bEnableDialogs) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    /** FIXME: always true at the moment **/
-    if(!bEnableDialogs) {
-        FIXME("(%p) Dialogs cannot be disabled yet\n", This);
-    }
+static HRESULT WINAPI IWineD3DDeviceImpl_SetDialogBoxMode(IWineD3DDevice *iface, BOOL enable_dialogs)
+{
+    TRACE("iface %p, enable_dialogs %#x.\n", iface, enable_dialogs);
+
+    if (!enable_dialogs) FIXME("Dialogs cannot be disabled yet.\n");
+
     return WINED3D_OK;
 }
@@ -7193,5 +6642,4 @@
         IWineD3DSwapChain_Release(swapchain);
     }
-    return;
 }
 
@@ -7205,5 +6653,4 @@
         IWineD3DSwapChain_Release(swapchain);
     }
-    return;
 }
 
@@ -7247,5 +6694,6 @@
             if (This->d3d_initialized)
             {
-                for (i = 0; i < GL_LIMITS(buffers); ++i) {
+                for (i = 0; i < This->adapter->gl_info.limits.buffers; ++i)
+                {
                     if (This->render_targets[i] == (IWineD3DSurface *)resource) {
                         This->render_targets[i] = NULL;
@@ -7350,5 +6798,5 @@
  **********************************************************/
 
-const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl =
+static const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl =
 {
     /*** IUnknown methods ***/
@@ -7374,4 +6822,5 @@
     IWineD3DDeviceImpl_CreateVertexDeclarationFromFVF,
     IWineD3DDeviceImpl_CreateVertexShader,
+    IWineD3DDeviceImpl_CreateGeometryShader,
     IWineD3DDeviceImpl_CreatePixelShader,
     IWineD3DDeviceImpl_CreatePalette,
@@ -7398,5 +6847,4 @@
     IWineD3DDeviceImpl_SetCursorPosition,
     IWineD3DDeviceImpl_ShowCursor,
-    IWineD3DDeviceImpl_TestCooperativeLevel,
     /*** Getters and setters **/
     IWineD3DDeviceImpl_SetClipPlane,
@@ -7497,121 +6945,80 @@
 };
 
-const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R] = {
-    WINED3DRS_ALPHABLENDENABLE   ,
-    WINED3DRS_ALPHAFUNC          ,
-    WINED3DRS_ALPHAREF           ,
-    WINED3DRS_ALPHATESTENABLE    ,
-    WINED3DRS_BLENDOP            ,
-    WINED3DRS_COLORWRITEENABLE   ,
-    WINED3DRS_DESTBLEND          ,
-    WINED3DRS_DITHERENABLE       ,
-    WINED3DRS_FILLMODE           ,
-    WINED3DRS_FOGDENSITY         ,
-    WINED3DRS_FOGEND             ,
-    WINED3DRS_FOGSTART           ,
-    WINED3DRS_LASTPIXEL          ,
-    WINED3DRS_SHADEMODE          ,
-    WINED3DRS_SRCBLEND           ,
-    WINED3DRS_STENCILENABLE      ,
-    WINED3DRS_STENCILFAIL        ,
-    WINED3DRS_STENCILFUNC        ,
-    WINED3DRS_STENCILMASK        ,
-    WINED3DRS_STENCILPASS        ,
-    WINED3DRS_STENCILREF         ,
-    WINED3DRS_STENCILWRITEMASK   ,
-    WINED3DRS_STENCILZFAIL       ,
-    WINED3DRS_TEXTUREFACTOR      ,
-    WINED3DRS_WRAP0              ,
-    WINED3DRS_WRAP1              ,
-    WINED3DRS_WRAP2              ,
-    WINED3DRS_WRAP3              ,
-    WINED3DRS_WRAP4              ,
-    WINED3DRS_WRAP5              ,
-    WINED3DRS_WRAP6              ,
-    WINED3DRS_WRAP7              ,
-    WINED3DRS_ZENABLE            ,
-    WINED3DRS_ZFUNC              ,
-    WINED3DRS_ZWRITEENABLE
-};
-
-const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T] = {
-    WINED3DTSS_ALPHAARG0             ,
-    WINED3DTSS_ALPHAARG1             ,
-    WINED3DTSS_ALPHAARG2             ,
-    WINED3DTSS_ALPHAOP               ,
-    WINED3DTSS_BUMPENVLOFFSET        ,
-    WINED3DTSS_BUMPENVLSCALE         ,
-    WINED3DTSS_BUMPENVMAT00          ,
-    WINED3DTSS_BUMPENVMAT01          ,
-    WINED3DTSS_BUMPENVMAT10          ,
-    WINED3DTSS_BUMPENVMAT11          ,
-    WINED3DTSS_COLORARG0             ,
-    WINED3DTSS_COLORARG1             ,
-    WINED3DTSS_COLORARG2             ,
-    WINED3DTSS_COLOROP               ,
-    WINED3DTSS_RESULTARG             ,
-    WINED3DTSS_TEXCOORDINDEX         ,
-    WINED3DTSS_TEXTURETRANSFORMFLAGS
-};
-
-const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S] = {
-    WINED3DSAMP_ADDRESSU         ,
-    WINED3DSAMP_ADDRESSV         ,
-    WINED3DSAMP_ADDRESSW         ,
-    WINED3DSAMP_BORDERCOLOR      ,
-    WINED3DSAMP_MAGFILTER        ,
-    WINED3DSAMP_MINFILTER        ,
-    WINED3DSAMP_MIPFILTER        ,
-    WINED3DSAMP_MIPMAPLODBIAS    ,
-    WINED3DSAMP_MAXMIPLEVEL      ,
-    WINED3DSAMP_MAXANISOTROPY    ,
-    WINED3DSAMP_SRGBTEXTURE      ,
-    WINED3DSAMP_ELEMENTINDEX
-};
-
-const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R] = {
-    WINED3DRS_AMBIENT                       ,
-    WINED3DRS_AMBIENTMATERIALSOURCE         ,
-    WINED3DRS_CLIPPING                      ,
-    WINED3DRS_CLIPPLANEENABLE               ,
-    WINED3DRS_COLORVERTEX                   ,
-    WINED3DRS_DIFFUSEMATERIALSOURCE         ,
-    WINED3DRS_EMISSIVEMATERIALSOURCE        ,
-    WINED3DRS_FOGDENSITY                    ,
-    WINED3DRS_FOGEND                        ,
-    WINED3DRS_FOGSTART                      ,
-    WINED3DRS_FOGTABLEMODE                  ,
-    WINED3DRS_FOGVERTEXMODE                 ,
-    WINED3DRS_INDEXEDVERTEXBLENDENABLE      ,
-    WINED3DRS_LIGHTING                      ,
-    WINED3DRS_LOCALVIEWER                   ,
-    WINED3DRS_MULTISAMPLEANTIALIAS          ,
-    WINED3DRS_MULTISAMPLEMASK               ,
-    WINED3DRS_NORMALIZENORMALS              ,
-    WINED3DRS_PATCHEDGESTYLE                ,
-    WINED3DRS_POINTSCALE_A                  ,
-    WINED3DRS_POINTSCALE_B                  ,
-    WINED3DRS_POINTSCALE_C                  ,
-    WINED3DRS_POINTSCALEENABLE              ,
-    WINED3DRS_POINTSIZE                     ,
-    WINED3DRS_POINTSIZE_MAX                 ,
-    WINED3DRS_POINTSIZE_MIN                 ,
-    WINED3DRS_POINTSPRITEENABLE             ,
-    WINED3DRS_RANGEFOGENABLE                ,
-    WINED3DRS_SPECULARMATERIALSOURCE        ,
-    WINED3DRS_TWEENFACTOR                   ,
-    WINED3DRS_VERTEXBLEND                   ,
-    WINED3DRS_CULLMODE                      ,
-    WINED3DRS_FOGCOLOR
-};
-
-const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T] = {
-    WINED3DTSS_TEXCOORDINDEX         ,
-    WINED3DTSS_TEXTURETRANSFORMFLAGS
-};
-
-const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S] = {
-    WINED3DSAMP_DMAPOFFSET
-};
+HRESULT device_init(IWineD3DDeviceImpl *device, IWineD3DImpl *wined3d,
+        UINT adapter_idx, WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags,
+        IUnknown *parent, IWineD3DDeviceParent *device_parent)
+{
+    struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
+    const struct fragment_pipeline *fragment_pipeline;
+    struct shader_caps shader_caps;
+    struct fragment_caps ffp_caps;
+    WINED3DDISPLAYMODE mode;
+    unsigned int i;
+    HRESULT hr;
+
+    device->lpVtbl = &IWineD3DDevice_Vtbl;
+    device->ref = 1;
+    device->wined3d = (IWineD3D *)wined3d;
+    IWineD3D_AddRef(device->wined3d);
+    device->adapter = wined3d->adapter_count ? adapter : NULL;
+    device->parent  = parent;
+    device->device_parent = device_parent;
+    list_init(&device->resources);
+    list_init(&device->shaders);
+
+    device->surface_alignment = wined3d->dxVersion == 7 ? DDRAW_PITCH_ALIGNMENT : D3D8_PITCH_ALIGNMENT;
+    device->posFixup[0] = 1.0f; /* This is needed to get the x coord unmodified through a MAD. */
+
+    /* Get the initial screen setup for ddraw. */
+    hr = IWineD3D_GetAdapterDisplayMode((IWineD3D *)wined3d, adapter_idx, &mode);
+    if (FAILED(hr))
+    {
+        ERR("Failed to get the adapter's display mode, hr %#x.\n", hr);
+        IWineD3D_Release(device->wined3d);
+        return hr;
+    }
+    device->ddraw_width = mode.Width;
+    device->ddraw_height = mode.Height;
+    device->ddraw_format = mode.Format;
+
+    /* Save the creation parameters. */
+    device->createParms.AdapterOrdinal = adapter_idx;
+    device->createParms.DeviceType = device_type;
+    device->createParms.hFocusWindow = focus_window;
+    device->createParms.BehaviorFlags = flags;
+
+    device->devType = device_type;
+    for (i = 0; i < PATCHMAP_SIZE; ++i) list_init(&device->patches[i]);
+
+    select_shader_mode(&adapter->gl_info, &device->ps_selected_mode, &device->vs_selected_mode);
+    device->shader_backend = select_shader_backend(adapter, device_type);
+
+    memset(&shader_caps, 0, sizeof(shader_caps));
+    device->shader_backend->shader_get_caps(device_type, &adapter->gl_info, &shader_caps);
+    device->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst;
+    device->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst;
+    device->vs_clipping = shader_caps.VSClipping;
+
+    memset(&ffp_caps, 0, sizeof(ffp_caps));
+    fragment_pipeline = select_fragment_implementation(adapter, device_type);
+    device->frag_pipe = fragment_pipeline;
+    fragment_pipeline->get_caps(device_type, &adapter->gl_info, &ffp_caps);
+    device->max_ffp_textures = ffp_caps.MaxSimultaneousTextures;
+    device->max_ffp_texture_stages = ffp_caps.MaxTextureBlendStages;
+
+    hr = compile_state_table(device->StateTable, device->multistate_funcs, &adapter->gl_info,
+            ffp_vertexstate_template, fragment_pipeline, misc_state_template);
+    if (FAILED(hr))
+    {
+        ERR("Failed to compile state table, hr %#x.\n", hr);
+        IWineD3D_Release(device->wined3d);
+        return hr;
+    }
+
+    device->blitter = select_blit_implementation(adapter, device_type);
+
+    return WINED3D_OK;
+}
+
 
 void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state) {
@@ -7627,6 +7034,6 @@
 
         context->dirtyArray[context->numDirtyEntries++] = rep;
-        idx = rep >> 5;
-        shift = rep & 0x1f;
+        idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
+        shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
         context->isStateDirty[idx] |= (1 << shift);
     }
@@ -7635,5 +7042,5 @@
 void get_drawable_size_pbuffer(struct wined3d_context *context, UINT *width, UINT *height)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->current_rt)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->current_rt)->resource.device;
     /* The drawable size of a pbuffer render target is the current pbuffer size. */
     *width = device->pbufferWidth;
@@ -7659,2 +7066,24 @@
     *height = surface->currentDesc.Height;
 }
+
+LRESULT device_process_message(IWineD3DDeviceImpl *device, HWND window,
+        UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc)
+{
+    if (device->filter_messages)
+    {
+        TRACE("Filtering message: window %p, message %#x, wparam %#lx, lparam %#lx.\n",
+                window, message, wparam, lparam);
+        return DefWindowProcW(window, message, wparam, lparam);
+    }
+
+    if (message == WM_DESTROY)
+    {
+        TRACE("unregister window %p.\n", window);
+        wined3d_unregister_window(window);
+
+        if (device->focus_window == window) device->focus_window = NULL;
+        else ERR("Window %p is not the focus window for device %p.\n", window, device);
+    }
+
+    return CallWindowProcW(proc, window, message, wparam, lparam);
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 25949)
@@ -56,4 +56,5 @@
     {"GL_APPLE_ycbcr_422",                  APPLE_YCBCR_422,                0                           },
     {"GL_APPLE_float_pixels",               APPLE_FLOAT_PIXELS,             0                           },
+    {"GL_APPLE_flush_buffer_range",         APPLE_FLUSH_BUFFER_RANGE,       0                           },
 
     /* ATI */
@@ -165,21 +166,4 @@
 
 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat, WINED3DSURFTYPE SurfaceType);
-static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
-        WINED3DDEVTYPE DeviceType);
-static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
-static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
-
-/* lookup tables */
-const int minLookup[MAX_LOOKUPS] =
-{
-    WINED3DTADDRESS_WRAP, /* WINELOOKUP_WARPPARAM */
-};
-
-const int maxLookup[MAX_LOOKUPS] =
-{
-    WINED3DTADDRESS_MIRRORONCE, /* WINELOOKUP_WARPPARAM */
-};
-
-DWORD *stateLookup[MAX_LOOKUPS];
 
 const struct min_lookup minMipLookup[] =
@@ -238,4 +222,6 @@
     HWND wnd;
     HGLRC gl_ctx;
+    HDC restore_dc;
+    HGLRC restore_gl_ctx;
 };
 
@@ -257,4 +243,9 @@
     ReleaseDC(ctx->wnd, ctx->dc);
     DestroyWindow(ctx->wnd);
+
+    if (ctx->restore_gl_ctx && !pwglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
+    {
+        ERR_(d3d_caps)("Failed to restore previous GL context.\n");
+    }
 }
 
@@ -265,4 +256,7 @@
 
     TRACE("getting context...\n");
+
+    ctx->restore_dc = pwglGetCurrentDC();
+    ctx->restore_gl_ctx = pwglGetCurrentContext();
 
     /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
@@ -330,4 +324,8 @@
     if (ctx->wnd) DestroyWindow(ctx->wnd);
     ctx->wnd = NULL;
+    if (ctx->restore_gl_ctx && !pwglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
+    {
+        ERR_(d3d_caps)("Failed to restore previous GL context.\n");
+    }
 
     return FALSE;
@@ -335,10 +333,17 @@
 
 /* Adjust the amount of used texture memory */
-long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
-    struct WineD3DAdapter *adapter = D3DDevice->adapter;
+long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram)
+{
+    struct wined3d_adapter *adapter = D3DDevice->adapter;
 
     adapter->UsedTextureRam += glram;
     TRACE("Adjusted gl ram by %ld to %d\n", glram, adapter->UsedTextureRam);
     return adapter->UsedTextureRam;
+}
+
+static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
+{
+    HeapFree(GetProcessHeap(), 0, adapter->gl_info.gl_formats);
+    HeapFree(GetProcessHeap(), 0, adapter->cfgs);
 }
 
@@ -381,5 +386,5 @@
         for (i = 0; i < This->adapter_count; ++i)
         {
-            HeapFree(GetProcessHeap(), 0, This->adapters[i].cfgs);
+            wined3d_adapter_cleanup(&This->adapters[i]);
         }
         HeapFree(GetProcessHeap(), 0, This);
@@ -387,65 +392,4 @@
 
     return ref;
-}
-
-/* Set the shader type for this device, depending on the given capabilities
- * and the user preferences in wined3d_settings. */
-static void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected)
-{
-    if (wined3d_settings.vs_mode == VS_NONE) {
-        *vs_selected = SHADER_NONE;
-    } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
-        /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
-         * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
-         * shaders only on this card. */
-        if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2])
-            *vs_selected = SHADER_ARB;
-        else
-            *vs_selected = SHADER_GLSL;
-    } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
-        *vs_selected = SHADER_ARB;
-    } else {
-        *vs_selected = SHADER_NONE;
-    }
-
-    if (wined3d_settings.ps_mode == PS_NONE) {
-        *ps_selected = SHADER_NONE;
-    } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
-        *ps_selected = SHADER_GLSL;
-    } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
-        *ps_selected = SHADER_ARB;
-    } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
-        *ps_selected = SHADER_ATI;
-    } else {
-        *ps_selected = SHADER_NONE;
-    }
-}
-
-/** Select the number of report maximum shader constants based on the selected shader modes */
-static void select_shader_max_constants(int ps_selected_mode, int vs_selected_mode, struct wined3d_gl_info *gl_info)
-{
-    switch (vs_selected_mode) {
-        case SHADER_GLSL:
-            gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF;
-            break;
-        case SHADER_ARB:
-            gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF;
-            break;
-        default:
-            gl_info->max_vshader_constantsF = 0;
-            break;
-    }
-
-    switch (ps_selected_mode) {
-        case SHADER_GLSL:
-            gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF;
-            break;
-        case SHADER_ARB:
-            gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF;
-            break;
-        default:
-            gl_info->max_pshader_constantsF = 0;
-            break;
-    }
 }
 
@@ -500,18 +444,20 @@
 }
 
-static BOOL match_ati_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
-{
-    if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
-    if (gl_info->gl_card == CARD_ATI_RADEON_9500) return TRUE;
-    if (gl_info->gl_card == CARD_ATI_RADEON_X700) return TRUE;
-    if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return TRUE;
+static BOOL match_ati_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    if (vendor != VENDOR_ATI) return FALSE;
+    if (device == CARD_ATI_RADEON_9500) return TRUE;
+    if (device == CARD_ATI_RADEON_X700) return TRUE;
+    if (device == CARD_ATI_RADEON_X1600) return TRUE;
     return FALSE;
 }
 
-static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
-{
-    if (gl_info->gl_vendor == VENDOR_NVIDIA)
-    {
-        if (gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5800 || gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5600)
+static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    if (vendor == VENDOR_NVIDIA)
+    {
+        if (device == CARD_NVIDIA_GEFORCEFX_5800 || device == CARD_NVIDIA_GEFORCEFX_5600)
         {
             return TRUE;
@@ -521,5 +467,6 @@
 }
 
-static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
 {
     /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
@@ -616,26 +563,30 @@
 }
 
-static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
-{
-    return gl_info->gl_vendor == VENDOR_INTEL && match_apple(gl_info, gl_renderer);
-}
-
-static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
-{
-    if (!match_apple(gl_info, gl_renderer)) return FALSE;
-    if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
-    if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return FALSE;
+static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    return vendor == VENDOR_INTEL && match_apple(gl_info, gl_renderer, vendor, device);
+}
+
+static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    if (!match_apple(gl_info, gl_renderer, vendor, device)) return FALSE;
+    if (vendor != VENDOR_ATI) return FALSE;
+    if (device == CARD_ATI_RADEON_X1600) return FALSE;
     return TRUE;
 }
 
-static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
-{
-    if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
-    if (match_apple(gl_info, gl_renderer)) return FALSE;
+static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    if (vendor != VENDOR_ATI) return FALSE;
+    if (match_apple(gl_info, gl_renderer, vendor, device)) return FALSE;
     if (strstr(gl_renderer, "DRI")) return FALSE; /* Filter out Mesa DRI drivers. */
     return TRUE;
 }
 
-static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
 {
     /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
@@ -646,14 +597,15 @@
      *
      * dx10 cards usually have 64 varyings */
-    return gl_info->max_glsl_varyings > 44;
+    return gl_info->limits.glsl_varyings > 44;
 }
 
 /* A GL context is provided by the caller */
-static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
 {
     GLenum error;
     DWORD data[16];
 
-    if(!GL_SUPPORT(EXT_SECONDARY_COLOR)) return FALSE;
+    if (!gl_info->supported[EXT_SECONDARY_COLOR]) return FALSE;
 
     ENTER_GL();
@@ -676,10 +628,64 @@
 }
 
+static BOOL match_apple_nvts(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    if (!match_apple(gl_info, gl_renderer, vendor, device)) return FALSE;
+    return gl_info->supported[NV_TEXTURE_SHADER];
+}
+
+/* A GL context is provided by the caller */
+static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    GLuint prog;
+    BOOL ret = FALSE;
+    GLint pos;
+    const char *testcode =
+        "!!ARBvp1.0\n"
+        "OPTION NV_vertex_program2;\n"
+        "MOV result.clip[0], 0.0;\n"
+        "MOV result.position, 0.0;\n"
+        "END\n";
+
+    if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
+
+    ENTER_GL();
+    while(glGetError());
+
+    GL_EXTCALL(glGenProgramsARB(1, &prog));
+    if(!prog)
+    {
+        ERR("Failed to create the NVvp clip test program\n");
+        LEAVE_GL();
+        return FALSE;
+    }
+    GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
+    GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+                                  strlen(testcode), testcode));
+    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    if(pos != -1)
+    {
+        WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
+        TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
+        ret = TRUE;
+        while(glGetError());
+    }
+    else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
+
+    GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
+    GL_EXTCALL(glDeleteProgramsARB(1, &prog));
+    checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
+
+    LEAVE_GL();
+    return ret;
+}
+
 static void quirk_arb_constants(struct wined3d_gl_info *gl_info)
 {
-    TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->vs_arb_constantsF);
-    gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
-    TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL.\n", gl_info->ps_arb_constantsF);
-    gl_info->ps_glsl_constantsF = gl_info->ps_arb_constantsF;
+    TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->limits.arb_vs_native_constants);
+    gl_info->limits.glsl_vs_float_constants = gl_info->limits.arb_vs_native_constants;
+    TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL.\n", gl_info->limits.arb_ps_native_constants);
+    gl_info->limits.glsl_ps_float_constants = gl_info->limits.arb_ps_native_constants;
 }
 
@@ -711,5 +717,5 @@
     {
         TRACE("Limiting point sprites to one texture unit.\n");
-        gl_info->max_point_sprite_units = 1;
+        gl_info->limits.point_sprite_units = 1;
     }
 }
@@ -793,7 +799,20 @@
 }
 
+static void quirk_apple_nvts(struct wined3d_gl_info *gl_info)
+{
+    gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
+    gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
+    gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
+}
+
+static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
+{
+    gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
+}
+
 struct driver_quirk
 {
-    BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer);
+    BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+            enum wined3d_pci_vendor vendor, enum wined3d_pci_device device);
     void (*apply)(struct wined3d_gl_info *gl_info);
     const char *description;
@@ -857,5 +876,18 @@
         quirk_allows_specular_alpha,
         "Allow specular alpha quirk"
-    }
+    },
+    {
+        /* The pixel formats provided by GL_NV_texture_shader are broken on OSX
+         * (rdar://5682521).
+         */
+        match_apple_nvts,
+        quirk_apple_nvts,
+        "Apple NV_texture_shader disable"
+    },
+    {
+        match_broken_nv_clip,
+        quirk_disable_nvvp_clip,
+        "Apple NV_vertex_program clip bug quirk"
+    },
 };
 
@@ -864,5 +896,24 @@
  * bugs, features, etc.
  *
- * If a card is not found in this table, the GL driver version is reported. */
+ * The driver version has the form "x.y.z.w".
+ *
+ * "x" is the Windows version the driver is meant for:
+ * 4 -> 95/98/NT4
+ * 5 -> 2000
+ * 6 -> 2000/XP
+ * 7 -> Vista
+ * 8 -> Win 7
+ *
+ * "y" is the Direct3D level the driver supports:
+ * 11 -> d3d6
+ * 12 -> d3d7
+ * 13 -> d3d8
+ * 14 -> d3d9
+ * 15 -> d3d10
+ *
+ * "z" is unknown, possibly vendor specific.
+ *
+ * "w" is the vendor specific driver version.
+ */
 struct driver_version_information
 {
@@ -870,5 +921,5 @@
     WORD card;                      /* reported PCI card device ID  */
     const char *description;        /* Description of the card e.g. NVIDIA RIVA TNT */
-    WORD hipart_hi, hipart_lo;      /* driver hiword to report      */
+    WORD d3d_level;                 /* driver hiword to report      */
     WORD lopart_hi, lopart_lo;      /* driver loword to report      */
 };
@@ -882,52 +933,159 @@
      *
      * All version numbers used below are from the Linux nvidia drivers. */
-    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT,           "NVIDIA RIVA TNT",                  7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT2,          "NVIDIA RIVA TNT2/TNT2 Pro",        7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE,            "NVIDIA GeForce 256",               7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2_MX,        "NVIDIA GeForce2 MX/MX 400",        9,  6,  4,  3      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2,           "NVIDIA GeForce2 GTS/GeForce2 Pro", 7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE3,           "NVIDIA GeForce3",                  9,  6,  10, 9371   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_MX,        "NVIDIA GeForce4 MX 460",           9,  6,  10, 9371   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_TI4200,    "NVIDIA GeForce4 Ti 4200",          9,  6,  10, 9371   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5200,     "NVIDIA GeForce FX 5200",           7,  15, 11, 7516   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5600,     "NVIDIA GeForce FX 5600",           7,  15, 11, 7516   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5800,     "NVIDIA GeForce FX 5800",           7,  15, 11, 7516   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6200,       "NVIDIA GeForce 6200",              7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6600GT,     "NVIDIA GeForce 6600 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6800,       "NVIDIA GeForce 6800",              7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7300,       "NVIDIA GeForce Go 7300",           7,  15, 11, 8585   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7400,       "NVIDIA GeForce Go 7400",           7,  15, 11, 8585   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7600,       "NVIDIA GeForce 7600 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7800GT,     "NVIDIA GeForce 7800 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8300GS,     "NVIDIA GeForce 8300 GS",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600GT,     "NVIDIA GeForce 8600 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600MGT,    "NVIDIA GeForce 8600M GT",          7,  15, 11, 8585   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8800GTS,    "NVIDIA GeForce 8800 GTS",          7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9200,       "NVIDIA GeForce 9200",              7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9400GT,     "NVIDIA GeForce 9400 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9500GT,     "NVIDIA GeForce 9500 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9600GT,     "NVIDIA GeForce 9600 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9800GT,     "NVIDIA GeForce 9800 GT",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX260,     "NVIDIA GeForce GTX 260",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX275,     "NVIDIA GeForce GTX 275",           7,  15, 11, 8618   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX280,     "NVIDIA GeForce GTX 280",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT,           "NVIDIA RIVA TNT",                  1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT2,          "NVIDIA RIVA TNT2/TNT2 Pro",        1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE,            "NVIDIA GeForce 256",               1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2_MX,        "NVIDIA GeForce2 MX/MX 400",        6,  4,  3      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2,           "NVIDIA GeForce2 GTS/GeForce2 Pro", 1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE3,           "NVIDIA GeForce3",                  6,  10, 9371   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_MX,        "NVIDIA GeForce4 MX 460",           6,  10, 9371   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_TI4200,    "NVIDIA GeForce4 Ti 4200",          6,  10, 9371   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5200,     "NVIDIA GeForce FX 5200",           15, 11, 7516   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5600,     "NVIDIA GeForce FX 5600",           15, 11, 7516   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5800,     "NVIDIA GeForce FX 5800",           15, 11, 7516   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6200,       "NVIDIA GeForce 6200",              15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6600GT,     "NVIDIA GeForce 6600 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6800,       "NVIDIA GeForce 6800",              15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7300,       "NVIDIA GeForce Go 7300",           15, 11, 8585   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7400,       "NVIDIA GeForce Go 7400",           15, 11, 8585   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7600,       "NVIDIA GeForce 7600 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7800GT,     "NVIDIA GeForce 7800 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8300GS,     "NVIDIA GeForce 8300 GS",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600GT,     "NVIDIA GeForce 8600 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600MGT,    "NVIDIA GeForce 8600M GT",          15, 11, 8585   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8800GTS,    "NVIDIA GeForce 8800 GTS",          15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9200,       "NVIDIA GeForce 9200",              15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9400GT,     "NVIDIA GeForce 9400 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9500GT,     "NVIDIA GeForce 9500 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9600GT,     "NVIDIA GeForce 9600 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9800GT,     "NVIDIA GeForce 9800 GT",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX260,     "NVIDIA GeForce GTX 260",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX275,     "NVIDIA GeForce GTX 275",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX280,     "NVIDIA GeForce GTX 280",           15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT240,      "NVIDIA GeForce GT 240",            15, 11, 8618   },
 
     /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode. */
-    {VENDOR_ATI,        CARD_ATI_RADEON_9500,           "ATI Radeon 9500",                  6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_X700,           "ATI Radeon X700 SE",               6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_X1600,          "ATI Radeon X1600 Series",          6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD2300,         "ATI Mobility Radeon HD 2300",      6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD2600,         "ATI Mobility Radeon HD 2600",      6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD2900,         "ATI Radeon HD 2900 XT",            6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD4350,         "ATI Radeon HD 4350",               6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD4600,         "ATI Radeon HD 4600 Series",        6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD4700,         "ATI Radeon HD 4700 Series",        6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD4800,         "ATI Radeon HD 4800 Series",        6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_9500,           "ATI Radeon 9500",                  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_X700,           "ATI Radeon X700 SE",               14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_X1600,          "ATI Radeon X1600 Series",          14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD2300,         "ATI Mobility Radeon HD 2300",      14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD2600,         "ATI Mobility Radeon HD 2600",      14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD2900,         "ATI Radeon HD 2900 XT",            14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4350,         "ATI Radeon HD 4350",               14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4600,         "ATI Radeon HD 4600 Series",        14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4700,         "ATI Radeon HD 4700 Series",        14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4800,         "ATI Radeon HD 4800 Series",        14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD5700,         "ATI Radeon HD 5700 Series",        14, 10, 8681    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD5800,         "ATI Radeon HD 5800 Series",        14, 10, 8681    },
 
     /* TODO: Add information about legacy ATI hardware, Intel and other cards. */
 };
 
+static void init_driver_info(struct wined3d_driver_info *driver_info,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
+{
+    OSVERSIONINFOW os_version;
+    WORD driver_os_version;
+    unsigned int i;
+
+    if (wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
+    {
+        TRACE_(d3d_caps)("Overriding PCI vendor ID with: %04x\n", wined3d_settings.pci_vendor_id);
+        vendor = wined3d_settings.pci_vendor_id;
+    }
+    driver_info->vendor = vendor;
+
+    if (wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
+    {
+        TRACE_(d3d_caps)("Overriding PCI device ID with: %04x\n", wined3d_settings.pci_device_id);
+        device = wined3d_settings.pci_device_id;
+    }
+    driver_info->device = device;
+
+    switch (vendor)
+    {
+        case VENDOR_ATI:
+            driver_info->name = "ati2dvag.dll";
+            break;
+
+        case VENDOR_NVIDIA:
+            driver_info->name = "nv4_disp.dll";
+            break;
+
+        default:
+            FIXME_(d3d_caps)("Unhandled vendor %04x.\n", vendor);
+            driver_info->name = "Display";
+            break;
+    }
+
+    memset(&os_version, 0, sizeof(os_version));
+    os_version.dwOSVersionInfoSize = sizeof(os_version);
+    if (!GetVersionExW(&os_version))
+    {
+        ERR("Failed to get OS version, reporting 2000/XP.\n");
+        driver_os_version = 6;
+    }
+    else
+    {
+        TRACE("OS version %u.%u.\n", os_version.dwMajorVersion, os_version.dwMinorVersion);
+        switch (os_version.dwMajorVersion)
+        {
+            case 4:
+                driver_os_version = 4;
+                break;
+
+            case 5:
+                driver_os_version = 6;
+                break;
+
+            case 6:
+                if (os_version.dwMinorVersion == 0)
+                {
+                    driver_os_version = 7;
+                }
+                else
+                {
+                    if (os_version.dwMinorVersion > 1)
+                    {
+                        FIXME("Unhandled OS version %u.%u, reporting Win 7.\n",
+                                os_version.dwMajorVersion, os_version.dwMinorVersion);
+                    }
+                    driver_os_version = 8;
+                }
+                break;
+
+            default:
+                FIXME("Unhandled OS version %u.%u, reporting 2000/XP.\n",
+                        os_version.dwMajorVersion, os_version.dwMinorVersion);
+                driver_os_version = 6;
+                break;
+        }
+    }
+
+    driver_info->description = "Direct3D HAL";
+    driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, 15);
+    driver_info->version_low = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
+
+    for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); ++i)
+    {
+        if (vendor == driver_version_table[i].vendor && device == driver_version_table[i].card)
+        {
+            TRACE_(d3d_caps)("Found card %04x:%04x in driver DB.\n", vendor, device);
+
+            driver_info->description = driver_version_table[i].description;
+            driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, driver_version_table[i].d3d_level);
+            driver_info->version_low = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
+                    driver_version_table[i].lopart_lo);
+            break;
+        }
+    }
+
+    TRACE_(d3d_caps)("Reporting (fake) driver version 0x%08x-0x%08x.\n",
+            driver_info->version_high, driver_info->version_low);
+}
+
 /* Context activation is done by the caller. */
-static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer)
+static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
 {
     unsigned int i;
@@ -935,5 +1093,5 @@
     for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
     {
-        if (!quirk_table[i].match(gl_info, gl_renderer)) continue;
+        if (!quirk_table[i].match(gl_info, gl_renderer, vendor, device)) continue;
         TRACE_(d3d_caps)("Applying driver quirk \"%s\".\n", quirk_table[i].description);
         quirk_table[i].apply(gl_info);
@@ -942,26 +1100,4 @@
     /* Find out if PBOs work as they are supposed to. */
     test_pbo_functionality(gl_info);
-
-    /* Fixup the driver version we'll report to the app. */
-    gl_info->driver_version        = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
-    gl_info->driver_version_hipart = MAKEDWORD_VERSION(7, 1);
-    for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); ++i)
-    {
-        if (gl_info->gl_vendor == driver_version_table[i].vendor
-                && gl_info->gl_card == driver_version_table[i].card)
-        {
-            TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB.\n",
-                    gl_info->gl_vendor, gl_info->gl_card);
-
-            gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
-                    driver_version_table[i].lopart_lo);
-            gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
-                    driver_version_table[i].hipart_lo);
-            gl_info->driver_description = driver_version_table[i].description;
-            break;
-        }
-    }
-    TRACE_(d3d_caps)("Reporting (fake) driver version 0x%08X-0x%08X.\n",
-            gl_info->driver_version_hipart, gl_info->driver_version);
 }
 
@@ -984,5 +1120,5 @@
 }
 
-static GL_Vendors wined3d_guess_vendor(const char *gl_vendor, const char *gl_renderer)
+static enum wined3d_pci_vendor wined3d_guess_vendor(const char *gl_vendor, const char *gl_renderer)
 {
     if (strstr(gl_vendor, "NVIDIA"))
@@ -999,5 +1135,6 @@
     if (strstr(gl_vendor, "Mesa")
             || strstr(gl_vendor, "DRI R300 Project")
-            || strstr(gl_vendor, "Tungsten Graphics, Inc"))
+            || strstr(gl_vendor, "Tungsten Graphics, Inc")
+            || strstr(gl_vendor, "VMware, Inc."))
         return VENDOR_MESA;
 
@@ -1007,6 +1144,6 @@
 }
 
-static GL_Cards wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
-        GL_Vendors *vendor, unsigned int *vidmem)
+static enum wined3d_pci_device wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        enum wined3d_pci_vendor *vendor, unsigned int *vidmem)
 {
     /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of
@@ -1095,4 +1232,10 @@
                     return CARD_NVIDIA_GEFORCE_GTX260;
                 }
+                /* Geforce 200 - midend */
+                if (strstr(gl_renderer, "GT 240"))
+                {
+                   *vidmem = 512;
+                   return CARD_NVIDIA_GEFORCE_GT240;
+                }
 
                 /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
@@ -1161,5 +1304,7 @@
 
                 /* Geforce8 - lowend */
-                if (strstr(gl_renderer, "8300")
+                if (strstr(gl_renderer, "8100")
+                        || strstr(gl_renderer, "8200")
+                        || strstr(gl_renderer, "8300")
                         || strstr(gl_renderer, "8400")
                         || strstr(gl_renderer, "8500"))
@@ -1306,4 +1451,22 @@
             if (WINE_D3D9_CAPABLE(gl_info))
             {
+                /* Radeon EG CYPRESS XT / PRO HD5800 - highend */
+                if (strstr(gl_renderer, "HD 5800")          /* Radeon EG CYPRESS HD58xx generic renderer string */
+                        || strstr(gl_renderer, "HD 5850")   /* Radeon EG CYPRESS XT */
+                        || strstr(gl_renderer, "HD 5870"))  /* Radeon EG CYPRESS PRO */
+                {
+                    *vidmem = 1024; /* note: HD58xx cards use 1024MB  */
+                    return CARD_ATI_RADEON_HD5800;
+                }
+
+                /* Radeon EG JUNIPER XT / LE HD5700 - midend */
+                if (strstr(gl_renderer, "HD 5700")          /* Radeon EG JUNIPER HD57xx generic renderer string */
+                        || strstr(gl_renderer, "HD 5750")   /* Radeon EG JUNIPER LE */
+                        || strstr(gl_renderer, "HD 5770"))  /* Radeon EG JUNIPER XT */
+                {
+                    *vidmem = 512; /* note: HD5770 cards use 1024MB and HD5750 cards use 512MB or 1024MB  */
+                    return CARD_ATI_RADEON_HD5700;
+                }
+
                 /* Radeon R7xx HD4800 - highend */
                 if (strstr(gl_renderer, "HD 4800")          /* Radeon RV7xx HD48xx generic renderer string */
@@ -1471,9 +1634,11 @@
 
 /* Context activation is done by the caller. */
-static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_gl_info *gl_info)
+static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_driver_info *driver_info, struct wined3d_gl_info *gl_info)
 {
     const char *GL_Extensions    = NULL;
     const char *WGL_Extensions   = NULL;
     const char *gl_string        = NULL;
+    enum wined3d_pci_vendor vendor;
+    enum wined3d_pci_device device;
     GLint       gl_max;
     GLfloat     gl_floatv[2];
@@ -1517,6 +1682,6 @@
         return FALSE;
     }
-    gl_info->gl_vendor = wined3d_guess_vendor(gl_string, gl_renderer);
-    TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
+    vendor = wined3d_guess_vendor(gl_string, gl_renderer);
+    TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), vendor);
 
     /* Parse the GL_VERSION field into major and minor information */
@@ -1537,37 +1702,38 @@
      */
     memset(gl_info->supported, 0, sizeof(gl_info->supported));
-    gl_info->max_buffers        = 1;
-    gl_info->max_textures       = 1;
-    gl_info->max_texture_stages = 1;
-    gl_info->max_fragment_samplers = 1;
-    gl_info->max_vertex_samplers = 0;
-    gl_info->max_combined_samplers = gl_info->max_fragment_samplers + gl_info->max_vertex_samplers;
-    gl_info->max_sampler_stages = 1;
-    gl_info->ps_arb_max_temps = 0;
-    gl_info->ps_arb_max_instructions = 0;
-    gl_info->vs_arb_max_temps = 0;
-    gl_info->vs_arb_max_instructions = 0;
-    gl_info->vs_glsl_constantsF = 0;
-    gl_info->ps_glsl_constantsF = 0;
-    gl_info->vs_arb_constantsF = 0;
-    gl_info->ps_arb_constantsF = 0;
-    gl_info->ps_arb_max_local_constants = 0;
+    gl_info->limits.buffers = 1;
+    gl_info->limits.textures = 1;
+    gl_info->limits.texture_stages = 1;
+    gl_info->limits.fragment_samplers = 1;
+    gl_info->limits.vertex_samplers = 0;
+    gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers + gl_info->limits.vertex_samplers;
+    gl_info->limits.sampler_stages = 1;
+    gl_info->limits.glsl_vs_float_constants = 0;
+    gl_info->limits.glsl_ps_float_constants = 0;
+    gl_info->limits.arb_vs_float_constants = 0;
+    gl_info->limits.arb_vs_native_constants = 0;
+    gl_info->limits.arb_vs_instructions = 0;
+    gl_info->limits.arb_vs_temps = 0;
+    gl_info->limits.arb_ps_float_constants = 0;
+    gl_info->limits.arb_ps_local_constants = 0;
+    gl_info->limits.arb_ps_instructions = 0;
+    gl_info->limits.arb_ps_temps = 0;
 
     /* Retrieve opengl defaults */
     glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
-    gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
+    gl_info->limits.clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
     TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
 
     glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
-    gl_info->max_lights = gl_max;
+    gl_info->limits.lights = gl_max;
     TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
 
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
-    gl_info->max_texture_size = gl_max;
+    gl_info->limits.texture_size = gl_max;
     TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
 
     glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
-    gl_info->max_pointsizemin = gl_floatv[0];
-    gl_info->max_pointsize = gl_floatv[1];
+    gl_info->limits.pointsize_min = gl_floatv[0];
+    gl_info->limits.pointsize_max = gl_floatv[1];
     TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
 
@@ -1698,5 +1864,5 @@
     {
         glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
-        gl_info->max_buffers = gl_max;
+        gl_info->limits.buffers = gl_max;
         TRACE_(d3d_caps)("Max draw buffers: %u.\n", gl_max);
     }
@@ -1704,6 +1870,6 @@
     {
         glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
-        gl_info->max_textures = min(MAX_TEXTURES, gl_max);
-        TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->max_textures);
+        gl_info->limits.textures = min(MAX_TEXTURES, gl_max);
+        TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->limits.textures);
 
         if (gl_info->supported[NV_REGISTER_COMBINERS])
@@ -1711,11 +1877,11 @@
             GLint tmp;
             glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
-            gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
+            gl_info->limits.texture_stages = min(MAX_TEXTURES, tmp);
         }
         else
         {
-            gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
-        }
-        TRACE_(d3d_caps)("Max texture stages: %d.\n", gl_info->max_texture_stages);
+            gl_info->limits.texture_stages = min(MAX_TEXTURES, gl_max);
+        }
+        TRACE_(d3d_caps)("Max texture stages: %d.\n", gl_info->limits.texture_stages);
 
         if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
@@ -1723,11 +1889,11 @@
             GLint tmp;
             glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
-            gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
+            gl_info->limits.fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
         }
         else
         {
-            gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
-        }
-        TRACE_(d3d_caps)("Max fragment samplers: %d.\n", gl_info->max_fragment_samplers);
+            gl_info->limits.fragment_samplers = max(gl_info->limits.fragment_samplers, gl_max);
+        }
+        TRACE_(d3d_caps)("Max fragment samplers: %d.\n", gl_info->limits.fragment_samplers);
 
         if (gl_info->supported[ARB_VERTEX_SHADER])
@@ -1735,7 +1901,7 @@
             GLint tmp;
             glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
-            gl_info->max_vertex_samplers = tmp;
+            gl_info->limits.vertex_samplers = tmp;
             glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
-            gl_info->max_combined_samplers = tmp;
+            gl_info->limits.combined_samplers = tmp;
 
             /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
@@ -1753,67 +1919,75 @@
              * So this is just a check to check that our assumption holds true. If not, write a warning
              * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
-            if (gl_info->max_vertex_samplers && gl_info->max_combined_samplers < 12
-                    && MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers)
+            if (gl_info->limits.vertex_samplers && gl_info->limits.combined_samplers < 12
+                    && MAX_TEXTURES + gl_info->limits.vertex_samplers > gl_info->limits.combined_samplers)
             {
                 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
-                        gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
+                        gl_info->limits.vertex_samplers, gl_info->limits.combined_samplers);
                 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
-                if (gl_info->max_combined_samplers > MAX_TEXTURES)
-                    gl_info->max_vertex_samplers = gl_info->max_combined_samplers - MAX_TEXTURES;
+                if (gl_info->limits.combined_samplers > MAX_TEXTURES)
+                    gl_info->limits.vertex_samplers = gl_info->limits.combined_samplers - MAX_TEXTURES;
                 else
-                    gl_info->max_vertex_samplers = 0;
+                    gl_info->limits.vertex_samplers = 0;
             }
         }
         else
         {
-            gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
-        }
-        TRACE_(d3d_caps)("Max vertex samplers: %u.\n", gl_info->max_vertex_samplers);
-        TRACE_(d3d_caps)("Max combined samplers: %u.\n", gl_info->max_combined_samplers);
+            gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers;
+        }
+        TRACE_(d3d_caps)("Max vertex samplers: %u.\n", gl_info->limits.vertex_samplers);
+        TRACE_(d3d_caps)("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
     }
     if (gl_info->supported[ARB_VERTEX_BLEND])
     {
         glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
-        gl_info->max_blends = gl_max;
-        TRACE_(d3d_caps)("Max blends: %u.\n", gl_info->max_blends);
+        gl_info->limits.blends = gl_max;
+        TRACE_(d3d_caps)("Max blends: %u.\n", gl_info->limits.blends);
     }
     if (gl_info->supported[EXT_TEXTURE3D])
     {
         glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
-        gl_info->max_texture3d_size = gl_max;
-        TRACE_(d3d_caps)("Max texture3D size: %d.\n", gl_info->max_texture3d_size);
+        gl_info->limits.texture3d_size = gl_max;
+        TRACE_(d3d_caps)("Max texture3D size: %d.\n", gl_info->limits.texture3d_size);
     }
     if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
     {
         glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
-        gl_info->max_anisotropy = gl_max;
-        TRACE_(d3d_caps)("Max anisotropy: %d.\n", gl_info->max_anisotropy);
+        gl_info->limits.anisotropy = gl_max;
+        TRACE_(d3d_caps)("Max anisotropy: %d.\n", gl_info->limits.anisotropy);
     }
     if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
     {
         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
-        gl_info->ps_arb_constantsF = gl_max;
-        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->ps_arb_constantsF);
+        gl_info->limits.arb_ps_float_constants = gl_max;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->limits.arb_ps_float_constants);
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
+        gl_info->limits.arb_ps_native_constants = gl_max;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native float constants: %d.\n",
+                gl_info->limits.arb_ps_native_constants);
         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
-        gl_info->ps_arb_max_temps = gl_max;
-        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->ps_arb_max_temps);
+        gl_info->limits.arb_ps_temps = gl_max;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_ps_temps);
         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
-        gl_info->ps_arb_max_instructions = gl_max;
-        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->ps_arb_max_instructions);
+        gl_info->limits.arb_ps_instructions = gl_max;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->limits.arb_ps_instructions);
         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
-        gl_info->ps_arb_max_local_constants = gl_max;
-        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->ps_arb_max_instructions);
+        gl_info->limits.arb_ps_local_constants = gl_max;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->limits.arb_ps_instructions);
     }
     if (gl_info->supported[ARB_VERTEX_PROGRAM])
     {
         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
-        gl_info->vs_arb_constantsF = gl_max;
-        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->vs_arb_constantsF);
+        gl_info->limits.arb_vs_float_constants = gl_max;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->limits.arb_vs_float_constants);
+        GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
+        gl_info->limits.arb_vs_native_constants = gl_max;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native float constants: %d.\n",
+                gl_info->limits.arb_vs_native_constants);
         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
-        gl_info->vs_arb_max_temps = gl_max;
-        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->vs_arb_max_temps);
+        gl_info->limits.arb_vs_temps = gl_max;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_vs_temps);
         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
-        gl_info->vs_arb_max_instructions = gl_max;
-        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->vs_arb_max_instructions);
+        gl_info->limits.arb_vs_instructions = gl_max;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->limits.arb_vs_instructions);
 
         if (test_arb_vs_offset_limit(gl_info)) gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
@@ -1822,23 +1996,23 @@
     {
         glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
-        gl_info->vs_glsl_constantsF = gl_max / 4;
-        TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->vs_glsl_constantsF);
+        gl_info->limits.glsl_vs_float_constants = gl_max / 4;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->limits.glsl_vs_float_constants);
     }
     if (gl_info->supported[ARB_FRAGMENT_SHADER])
     {
         glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
-        gl_info->ps_glsl_constantsF = gl_max / 4;
-        TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->ps_glsl_constantsF);
+        gl_info->limits.glsl_ps_float_constants = gl_max / 4;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->limits.glsl_ps_float_constants);
         glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
-        gl_info->max_glsl_varyings = gl_max;
+        gl_info->limits.glsl_varyings = gl_max;
         TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
     }
     if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
     {
-        glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
+        glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->limits.shininess);
     }
     else
     {
-        gl_info->max_shininess = 128.0f;
+        gl_info->limits.shininess = 128.0f;
     }
     if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
@@ -1869,9 +2043,9 @@
     if (gl_info->supported[ARB_POINT_SPRITE])
     {
-        gl_info->max_point_sprite_units = gl_info->max_textures;
+        gl_info->limits.point_sprite_units = gl_info->limits.textures;
     }
     else
     {
-        gl_info->max_point_sprite_units = 0;
+        gl_info->limits.point_sprite_units = 0;
     }
     checkGLcall("extension detection");
@@ -1882,5 +2056,5 @@
      * of samplers. The GF4 for example can use only 2 samplers (no fragment
      * shaders), but 8 texture stages (register combiners). */
-    gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
+    gl_info->limits.sampler_stages = max(gl_info->limits.fragment_samplers, gl_info->limits.texture_stages);
 
     if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
@@ -1944,10 +2118,11 @@
 
     /* MRTs are currently only supported when FBOs are used. */
-    if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
-        gl_info->max_buffers = 1;
-    }
-
-    gl_info->gl_card = wined3d_guess_card(gl_info, gl_renderer, &gl_info->gl_vendor, &vidmem);
-    TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
+    if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
+    {
+        gl_info->limits.buffers = 1;
+    }
+
+    device = wined3d_guess_card(gl_info, gl_renderer, &vendor, &vidmem);
+    TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", vendor, device);
 
     /* If we have an estimate use it, else default to 64MB;  */
@@ -1957,19 +2132,12 @@
         gl_info->vidmem = WINE_DEFAULT_VIDMEM;
 
-    /* Load all the lookup tables */
-    for (i = 0; i < MAX_LOOKUPS; i++) {
-        stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
-    }
-
-    stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP   - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
-    stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP  - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
-    stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
-             gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
-    stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
-             gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
-    stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
-             gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
-    stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
-             gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
+    gl_info->wrap_lookup[WINED3DTADDRESS_WRAP - WINED3DTADDRESS_WRAP] = GL_REPEAT;
+    gl_info->wrap_lookup[WINED3DTADDRESS_MIRROR - WINED3DTADDRESS_WRAP] =
+            gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
+    gl_info->wrap_lookup[WINED3DTADDRESS_CLAMP - WINED3DTADDRESS_WRAP] = GL_CLAMP_TO_EDGE;
+    gl_info->wrap_lookup[WINED3DTADDRESS_BORDER - WINED3DTADDRESS_WRAP] =
+            gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
+    gl_info->wrap_lookup[WINED3DTADDRESS_MIRRORONCE - WINED3DTADDRESS_WRAP] =
+            gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
 
     /* Make sure there's an active HDC else the WGL extensions will fail */
@@ -2018,5 +2186,6 @@
     }
 
-    fixup_extensions(gl_info, gl_renderer);
+    fixup_extensions(gl_info, gl_renderer, vendor, device);
+    init_driver_info(driver_info, vendor, device);
     add_gl_compat_wrappers(gl_info);
 
@@ -2037,7 +2206,8 @@
 }
 
-static HRESULT  WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
+static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void *init_function)
+{
+    FIXME("iface %p, init_function %p stub!\n", iface, init_function);
+
     return WINED3D_OK;
 }
@@ -2069,4 +2239,6 @@
     /* TODO: Store modes per adapter and read it from the adapter structure */
     if (Adapter == 0) { /* Display */
+        const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(Format, &This->adapters[Adapter].gl_info);
+        UINT format_bits = format_desc->byte_count * CHAR_BIT;
         unsigned int i = 0;
         unsigned int j = 0;
@@ -2079,26 +2251,13 @@
         {
             ++j;
-            switch (Format)
+
+            if (Format == WINED3DFMT_UNKNOWN)
             {
-                case WINED3DFMT_UNKNOWN:
-                    /* This is for D3D8, do not enumerate P8 here */
-                    if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
-                    break;
-
-                case WINED3DFMT_B8G8R8X8_UNORM:
-                    if (mode.dmBitsPerPel == 32) ++i;
-                    break;
-
-                case WINED3DFMT_B5G6R5_UNORM:
-                    if (mode.dmBitsPerPel == 16) ++i;
-                    break;
-
-                case WINED3DFMT_P8_UINT:
-                    if (mode.dmBitsPerPel == 8) ++i;
-                    break;
-
-                default:
-                    /* Skip other modes as they do not match the requested format */
-                    break;
+                /* This is for D3D8, do not enumerate P8 here */
+                if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
+            }
+            else if (mode.dmBitsPerPel == format_bits)
+            {
+                ++i;
             }
         }
@@ -2127,4 +2286,6 @@
     if (Adapter == 0)
     {
+        const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(Format, &This->adapters[Adapter].gl_info);
+        UINT format_bits = format_desc->byte_count * CHAR_BIT;
         DEVMODEW DevModeW;
         int ModeIdx = 0;
@@ -2138,25 +2299,14 @@
            all unrelated modes, but if mode is irrelevant (D3D8), then we can
            just count through the ones with valid bit depths */
-        while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
-            switch (Format)
+        while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0))
+        {
+            if (Format == WINED3DFMT_UNKNOWN)
             {
-                case WINED3DFMT_UNKNOWN:
-                    /* This is D3D8. Do not enumerate P8 here */
-                    if (DevModeW.dmBitsPerPel == 32 ||
-                        DevModeW.dmBitsPerPel == 16) i++;
-                    break;
-                case WINED3DFMT_B8G8R8X8_UNORM:
-                    if (DevModeW.dmBitsPerPel == 32) i++;
-                    break;
-                case WINED3DFMT_B5G6R5_UNORM:
-                    if (DevModeW.dmBitsPerPel == 16) i++;
-                    break;
-                case WINED3DFMT_P8_UINT:
-                    if (DevModeW.dmBitsPerPel == 8) i++;
-                    break;
-                default:
-                    /* Modes that don't match what we support can get an early-out */
-                    TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
-                    return WINED3DERR_INVALIDCALL;
+                /* This is for D3D8, do not enumerate P8 here */
+                if (DevModeW.dmBitsPerPel == 32 || DevModeW.dmBitsPerPel == 16) ++i;
+            }
+            else if (DevModeW.dmBitsPerPel == format_bits)
+            {
+                ++i;
             }
         }
@@ -2199,7 +2349,7 @@
 }
 
-static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
+static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE *pMode)
+{
+    TRACE("iface %p, adapter_idx %u, display_mode %p.\n", iface, Adapter, pMode);
 
     if (NULL == pMode ||
@@ -2240,4 +2390,5 @@
                                                    WINED3DADAPTER_IDENTIFIER* pIdentifier) {
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
+    struct wined3d_adapter *adapter;
     size_t len;
 
@@ -2248,4 +2399,6 @@
     }
 
+    adapter = &This->adapters[Adapter];
+
     /* Return the information requested */
     TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
@@ -2253,6 +2406,7 @@
     if (pIdentifier->driver_size)
     {
-        len = min(strlen(This->adapters[Adapter].driver), pIdentifier->driver_size - 1);
-        memcpy(pIdentifier->driver, This->adapters[Adapter].driver, len);
+        const char *name = adapter->driver_info.name;
+        len = min(strlen(name), pIdentifier->driver_size - 1);
+        memcpy(pIdentifier->driver, name, len);
         pIdentifier->driver[len] = '\0';
     }
@@ -2260,11 +2414,5 @@
     if (pIdentifier->description_size)
     {
-        const char *description;
-
-        if (This->adapters[Adapter].gl_info.driver_description)
-            description = This->adapters[Adapter].gl_info.driver_description;
-        else
-            description = This->adapters[Adapter].description;
-
+        const char *description = adapter->driver_info.description;
         len = min(strlen(description), pIdentifier->description_size - 1);
         memcpy(pIdentifier->description, description, len);
@@ -2288,25 +2436,14 @@
     }
 
-    pIdentifier->driver_version.u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
-    pIdentifier->driver_version.u.LowPart = This->adapters[Adapter].gl_info.driver_version;
-    pIdentifier->vendor_id = This->adapters[Adapter].gl_info.gl_vendor;
-    pIdentifier->device_id = This->adapters[Adapter].gl_info.gl_card;
+    pIdentifier->driver_version.u.HighPart = adapter->driver_info.version_high;
+    pIdentifier->driver_version.u.LowPart = adapter->driver_info.version_low;
+    pIdentifier->vendor_id = adapter->driver_info.vendor;
+    pIdentifier->device_id = adapter->driver_info.device;
     pIdentifier->subsystem_id = 0;
     pIdentifier->revision = 0;
     memcpy(&pIdentifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(pIdentifier->device_identifier));
-
-    if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
-    {
-        TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id);
-        pIdentifier->device_id = wined3d_settings.pci_device_id;
-    }
-
-    if(wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
-    {
-        TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id);
-        pIdentifier->vendor_id = wined3d_settings.pci_vendor_id;
-    }
-
     pIdentifier->whql_level = (Flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
+    memcpy(&pIdentifier->adapter_luid, &adapter->luid, sizeof(pIdentifier->adapter_luid));
+    pIdentifier->video_memory = adapter->TextureRam;
 
     return WINED3D_OK;
@@ -2401,5 +2538,5 @@
     int nCfgs;
     const WineD3D_PixelFormat *cfgs;
-    const struct WineD3DAdapter *adapter;
+    const struct wined3d_adapter *adapter;
     const struct GlPixelFormatDesc *rt_format_desc;
     const struct GlPixelFormatDesc *ds_format_desc;
@@ -2443,5 +2580,5 @@
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
     const struct GlPixelFormatDesc *glDesc;
-    const struct WineD3DAdapter *adapter;
+    const struct wined3d_adapter *adapter;
 
     TRACE_(d3d_caps)("(%p)-> (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
@@ -2531,17 +2668,12 @@
 
 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
-                                            WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
-
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
+        WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed)
+{
     HRESULT hr = WINED3DERR_NOTAVAILABLE;
     UINT nmodes;
 
-    TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
-          This,
-          Adapter,
-          DeviceType, debug_d3ddevicetype(DeviceType),
-          DisplayFormat, debug_d3dformat(DisplayFormat),
-          BackBufferFormat, debug_d3dformat(BackBufferFormat),
-          Windowed);
+    TRACE("iface %p, adapter_idx %u, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
+            iface, Adapter, debug_d3ddevicetype(DeviceType), debug_d3dformat(DisplayFormat),
+            debug_d3dformat(BackBufferFormat), Windowed);
 
     if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
@@ -2623,5 +2755,5 @@
 
 /* Check if we support bumpmapping for a format */
-static BOOL CheckBumpMapCapability(struct WineD3DAdapter *adapter,
+static BOOL CheckBumpMapCapability(struct wined3d_adapter *adapter,
         WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
 {
@@ -2654,5 +2786,5 @@
 
 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
-static BOOL CheckDepthStencilCapability(struct WineD3DAdapter *adapter,
+static BOOL CheckDepthStencilCapability(struct wined3d_adapter *adapter,
         const struct GlPixelFormatDesc *display_format_desc, const struct GlPixelFormatDesc *ds_format_desc)
 {
@@ -2678,5 +2810,5 @@
 }
 
-static BOOL CheckFilterCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
+static BOOL CheckFilterCapability(struct wined3d_adapter *adapter, const struct GlPixelFormatDesc *format_desc)
 {
     /* The flags entry of a format contains the filtering capability */
@@ -2687,5 +2819,5 @@
 
 /* Check the render target capabilities of a format */
-static BOOL CheckRenderTargetCapability(struct WineD3DAdapter *adapter,
+static BOOL CheckRenderTargetCapability(struct wined3d_adapter *adapter,
         const struct GlPixelFormatDesc *adapter_format_desc, const struct GlPixelFormatDesc *check_format_desc)
 {
@@ -2745,10 +2877,11 @@
 }
 
-static BOOL CheckSrgbReadCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
+static BOOL CheckSrgbReadCapability(struct wined3d_adapter *adapter, const struct GlPixelFormatDesc *format_desc)
 {
     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
 
     /* Check for supported sRGB formats (Texture loading and framebuffer) */
-    if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
+    if (!gl_info->supported[EXT_TEXTURE_SRGB])
+    {
         TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
         return FALSE;
@@ -2777,5 +2910,5 @@
 }
 
-static BOOL CheckSrgbWriteCapability(struct WineD3DAdapter *adapter,
+static BOOL CheckSrgbWriteCapability(struct wined3d_adapter *adapter,
         WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
 {
@@ -2800,5 +2933,5 @@
 
 /* Check if a format support blending in combination with pixel shaders */
-static BOOL CheckPostPixelShaderBlendingCapability(struct WineD3DAdapter *adapter,
+static BOOL CheckPostPixelShaderBlendingCapability(struct wined3d_adapter *adapter,
         const struct GlPixelFormatDesc *format_desc)
 {
@@ -2809,5 +2942,5 @@
 }
 
-static BOOL CheckWrapAndMipCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
+static BOOL CheckWrapAndMipCapability(struct wined3d_adapter *adapter, const struct GlPixelFormatDesc *format_desc)
 {
     /* OpenGL supports mipmapping on all formats basically. Wrapping is unsupported,
@@ -2824,5 +2957,5 @@
 
 /* Check if a texture format is supported on the given adapter */
-static BOOL CheckTextureCapability(struct WineD3DAdapter *adapter,
+static BOOL CheckTextureCapability(struct wined3d_adapter *adapter,
         WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
 {
@@ -2889,5 +3022,5 @@
         case WINED3DFMT_X8D24_UNORM:
         case WINED3DFMT_S4X4_UINT_D24_UNORM:
-        case WINED3DFMT_S8_UINT_D24_UNORM:
+        case WINED3DFMT_D24_UNORM_S8_UINT:
         case WINED3DFMT_S8_UINT_D24_FLOAT:
         case WINED3DFMT_D32_UNORM:
@@ -2921,5 +3054,6 @@
         case WINED3DFMT_DXT4:
         case WINED3DFMT_DXT5:
-            if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
+            if (gl_info->supported[EXT_TEXTURE_COMPRESSION_S3TC])
+            {
                 TRACE_(d3d_caps)("[OK]\n");
                 return TRUE;
@@ -2951,5 +3085,6 @@
         case WINED3DFMT_UYVY:
         case WINED3DFMT_YUY2:
-            if(GL_SUPPORT(APPLE_YCBCR_422)) {
+            if (gl_info->supported[APPLE_YCBCR_422])
+            {
                 TRACE_(d3d_caps)("[OK]\n");
                 return TRUE;
@@ -2971,5 +3106,6 @@
         case WINED3DFMT_R16G16_FLOAT:
         case WINED3DFMT_R16G16B16A16_FLOAT:
-            if(GL_SUPPORT(ARB_TEXTURE_FLOAT) && GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
+            if (gl_info->supported[ARB_TEXTURE_FLOAT] && gl_info->supported[ARB_HALF_FLOAT_PIXEL])
+            {
                 TRACE_(d3d_caps)("[OK]\n");
                 return TRUE;
@@ -2981,5 +3117,6 @@
         case WINED3DFMT_R32G32_FLOAT:
         case WINED3DFMT_R32G32B32A32_FLOAT:
-            if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
+            if (gl_info->supported[ARB_TEXTURE_FLOAT])
+            {
                 TRACE_(d3d_caps)("[OK]\n");
                 return TRUE;
@@ -2998,7 +3135,8 @@
          * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
          */
-        case WINEMAKEFOURCC('I','N','S','T'):
+        case WINED3DFMT_INST:
             TRACE("ATI Instancing check hack\n");
-            if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
+            if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_VERTEX_SHADER])
+            {
                 TRACE_(d3d_caps)("[OK]\n");
                 return TRUE;
@@ -3016,5 +3154,7 @@
         /* Vendor specific formats */
         case WINED3DFMT_ATI2N:
-            if(GL_SUPPORT(ATI_TEXTURE_COMPRESSION_3DC) || GL_SUPPORT(EXT_TEXTURE_COMPRESSION_RGTC)) {
+            if (gl_info->supported[ATI_TEXTURE_COMPRESSION_3DC]
+                    || gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
+            {
                 shader_backend = select_shader_backend(adapter, DeviceType);
                 fp = select_fragment_implementation(adapter, DeviceType);
@@ -3053,5 +3193,5 @@
 }
 
-static BOOL CheckSurfaceCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *adapter_format_desc,
+static BOOL CheckSurfaceCapability(struct wined3d_adapter *adapter, const struct GlPixelFormatDesc *adapter_format_desc,
         WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *check_format_desc, WINED3DSURFTYPE SurfaceType)
 {
@@ -3105,9 +3245,10 @@
 }
 
-static BOOL CheckVertexTextureCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
+static BOOL CheckVertexTextureCapability(struct wined3d_adapter *adapter, const struct GlPixelFormatDesc *format_desc)
 {
     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
 
-    if (!GL_LIMITS(vertex_samplers)) {
+    if (!gl_info->limits.vertex_samplers)
+    {
         TRACE_(d3d_caps)("[FAILED]\n");
         return FALSE;
@@ -3117,5 +3258,6 @@
     {
         case WINED3DFMT_R32G32B32A32_FLOAT:
-            if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
+            if (!gl_info->supported[ARB_TEXTURE_FLOAT])
+            {
                 TRACE_(d3d_caps)("[FAILED]\n");
                 return FALSE;
@@ -3136,5 +3278,5 @@
 {
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    struct WineD3DAdapter *adapter = &This->adapters[Adapter];
+    struct wined3d_adapter *adapter = &This->adapters[Adapter];
     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(CheckFormat, gl_info);
@@ -3171,5 +3313,6 @@
          *                    - D3DUSAGE_QUERY_WRAPANDMIP
          */
-        if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+        if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+        {
             /* Check if the texture format is around */
             if (CheckTextureCapability(adapter, DeviceType, format_desc))
@@ -3177,5 +3320,6 @@
                 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
                     /* Check for automatic mipmap generation support */
-                    if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
+                    if (gl_info->supported[SGIS_GENERATE_MIPMAP])
+                    {
                         UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
                     } else {
@@ -3343,5 +3487,6 @@
             if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
                 /* Check for automatic mipmap generation support */
-                if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
+                if (gl_info->supported[SGIS_GENERATE_MIPMAP])
+                {
                     UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
                 } else {
@@ -3476,5 +3621,6 @@
 
         /* Check volume texture and volume usage caps */
-        if(GL_SUPPORT(EXT_TEXTURE3D)) {
+        if (gl_info->supported[EXT_TEXTURE3D])
+        {
             if (!CheckTextureCapability(adapter, DeviceType, format_desc))
             {
@@ -3580,5 +3726,6 @@
             case WINED3DFMT_R8G8B8A8_SNORM:
             case WINED3DFMT_R16G16_SNORM:
-            if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
+            if (!gl_info->supported[NV_TEXTURE_SHADER])
+            {
                 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
                 return WINED3DERR_NOTAVAILABLE;
@@ -3587,5 +3734,6 @@
 
             case WINED3DFMT_R8G8_SNORM:
-            if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
+            if (!gl_info->supported[NV_TEXTURE_SHADER])
+            {
                 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
                 return WINED3DERR_NOTAVAILABLE;
@@ -3629,67 +3777,12 @@
 }
 
-static HRESULT  WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
-                                                          WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-
-    FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
-          This,
-          Adapter,
-          DeviceType, debug_d3ddevicetype(DeviceType),
-          SourceFormat, debug_d3dformat(SourceFormat),
-          TargetFormat, debug_d3dformat(TargetFormat));
+static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, WINED3DFORMAT src_format, WINED3DFORMAT dst_format)
+{
+    FIXME("iface %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n",
+            iface, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
+            debug_d3dformat(dst_format));
+
     return WINED3D_OK;
-}
-
-static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
-{
-    const shader_backend_t *ret;
-    int vs_selected_mode;
-    int ps_selected_mode;
-
-    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
-    if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
-        ret = &glsl_shader_backend;
-    } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
-        ret = &arb_program_shader_backend;
-    } else {
-        ret = &none_shader_backend;
-    }
-    return ret;
-}
-
-static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
-        WINED3DDEVTYPE DeviceType)
-{
-    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
-    int vs_selected_mode;
-    int ps_selected_mode;
-
-    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
-    if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
-        return &arbfp_fragment_pipeline;
-    } else if(ps_selected_mode == SHADER_ATI) {
-        return &atifs_fragment_pipeline;
-    } else if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
-        return &nvts_fragment_pipeline;
-    } else if(GL_SUPPORT(NV_REGISTER_COMBINERS)) {
-        return &nvrc_fragment_pipeline;
-    } else {
-        return &ffp_fragment_pipeline;
-    }
-}
-
-static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
-{
-    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
-    int vs_selected_mode;
-    int ps_selected_mode;
-
-    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
-    if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
-        return &arbfp_blit;
-    } else {
-        return &ffp_blit;
-    }
 }
 
@@ -3700,5 +3793,5 @@
 
     IWineD3DImpl    *This = (IWineD3DImpl *)iface;
-    struct WineD3DAdapter *adapter = &This->adapters[Adapter];
+    struct wined3d_adapter *adapter = &This->adapters[Adapter];
     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     int vs_selected_mode;
@@ -3718,8 +3811,4 @@
     select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
 
-    /* This function should *not* be modifying GL caps
-     * TODO: move the functionality where it belongs */
-    select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
-
     /* ------------------------------------------------
        The following fields apply to both d3d8 and d3d9
@@ -3732,5 +3821,6 @@
                                      WINED3DCAPS2_FULLSCREENGAMMA |
                                      WINED3DCAPS2_DYNAMICTEXTURES;
-    if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
+    if (gl_info->supported[SGIS_GENERATE_MIPMAP])
+    {
         pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
     }
@@ -3778,5 +3868,5 @@
                                         WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
 
-    if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
+    if (gl_info->supported[EXT_BLEND_EQUATION_SEPARATE] && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
         pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
 
@@ -3794,10 +3884,12 @@
                                      WINED3DPRASTERCAPS_DEPTHBIAS;
 
-    if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
+    if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
+    {
         pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY    |
                              WINED3DPRASTERCAPS_ZBIAS         |
                              WINED3DPRASTERCAPS_MIPMAPLODBIAS;
     }
-    if(GL_SUPPORT(NV_FOG_DISTANCE)) {
+    if (gl_info->supported[NV_FOG_DISTANCE])
+    {
         pCaps->RasterCaps         |= WINED3DPRASTERCAPS_FOGRANGE;
     }
@@ -3849,5 +3941,6 @@
      */
 
-    if( GL_SUPPORT(EXT_BLEND_COLOR)) {
+    if (gl_info->supported[EXT_BLEND_COLOR])
+    {
         pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
         pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
@@ -3881,10 +3974,12 @@
                           WINED3DPTEXTURECAPS_PERSPECTIVE;
 
-    if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
+    if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
+    {
         pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
                               WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
     }
 
-    if( GL_SUPPORT(EXT_TEXTURE3D)) {
+    if (gl_info->supported[EXT_TEXTURE3D])
+    {
         pCaps->TextureCaps |=  WINED3DPTEXTURECAPS_VOLUMEMAP      |
                                WINED3DPTEXTURECAPS_MIPVOLUMEMAP   |
@@ -3892,5 +3987,6 @@
     }
 
-    if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+    if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+    {
         pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP     |
                               WINED3DPTEXTURECAPS_MIPCUBEMAP    |
@@ -3912,10 +4008,12 @@
                                WINED3DPTFILTERCAPS_NEAREST;
 
-    if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
+    if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
+    {
         pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
                                     WINED3DPTFILTERCAPS_MINFANISOTROPIC;
     }
 
-    if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+    if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+    {
         pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR       |
                                        WINED3DPTFILTERCAPS_MAGFPOINT        |
@@ -3931,5 +4029,6 @@
                                        WINED3DPTFILTERCAPS_NEAREST;
 
-        if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
+        if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
+        {
             pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
                                             WINED3DPTFILTERCAPS_MINFANISOTROPIC;
@@ -3938,5 +4037,6 @@
         pCaps->CubeTextureFilterCaps = 0;
 
-    if (GL_SUPPORT(EXT_TEXTURE3D)) {
+    if (gl_info->supported[EXT_TEXTURE3D])
+    {
         pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR       |
                                          WINED3DPTFILTERCAPS_MAGFPOINT        |
@@ -3958,25 +4058,32 @@
                                  WINED3DPTADDRESSCAPS_WRAP;
 
-    if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
+    if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
+    {
         pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
     }
-    if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
+    if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
+    {
         pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
     }
-    if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
+    if (gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
+    {
         pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
     }
 
-    if (GL_SUPPORT(EXT_TEXTURE3D)) {
+    if (gl_info->supported[EXT_TEXTURE3D])
+    {
         pCaps->VolumeTextureAddressCaps =  WINED3DPTADDRESSCAPS_INDEPENDENTUV |
                                            WINED3DPTADDRESSCAPS_CLAMP  |
                                            WINED3DPTADDRESSCAPS_WRAP;
-        if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
+        if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
+        {
             pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
         }
-        if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
+        if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
+        {
             pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
         }
-        if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
+        if (gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
+        {
             pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
         }
@@ -3993,14 +4100,14 @@
      */
 
-    pCaps->MaxTextureWidth  = GL_LIMITS(texture_size);
-    pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
-
-    if(GL_SUPPORT(EXT_TEXTURE3D))
-        pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
+    pCaps->MaxTextureWidth = gl_info->limits.texture_size;
+    pCaps->MaxTextureHeight = gl_info->limits.texture_size;
+
+    if (gl_info->supported[EXT_TEXTURE3D])
+        pCaps->MaxVolumeExtent = gl_info->limits.texture3d_size;
     else
         pCaps->MaxVolumeExtent = 0;
 
     pCaps->MaxTextureRepeat = 32768;
-    pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
+    pCaps->MaxTextureAspectRatio = gl_info->limits.texture_size;
     pCaps->MaxVertexW = 1.0f;
 
@@ -4018,9 +4125,11 @@
                           WINED3DSTENCILCAPS_REPLACE |
                           WINED3DSTENCILCAPS_ZERO;
-    if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
+    if (gl_info->supported[EXT_STENCIL_WRAP])
+    {
         pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR  |
                               WINED3DSTENCILCAPS_INCR;
     }
-    if (GL_SUPPORT(EXT_STENCIL_TWO_SIDE) || GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
+    if (gl_info->supported[EXT_STENCIL_TWO_SIDE] || gl_info->supported[ATI_SEPARATE_STENCIL])
+    {
         pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
     }
@@ -4028,12 +4137,12 @@
     pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
 
-    pCaps->MaxUserClipPlanes       = GL_LIMITS(clipplanes);
-    pCaps->MaxActiveLights         = GL_LIMITS(lights);
-
-    pCaps->MaxVertexBlendMatrices      = GL_LIMITS(blends);
+    pCaps->MaxUserClipPlanes = gl_info->limits.clipplanes;
+    pCaps->MaxActiveLights = gl_info->limits.lights;
+
+    pCaps->MaxVertexBlendMatrices = gl_info->limits.blends;
     pCaps->MaxVertexBlendMatrixIndex   = 0;
 
-    pCaps->MaxAnisotropy   = GL_LIMITS(anisotropy);
-    pCaps->MaxPointSize    = GL_LIMITS(pointsize);
+    pCaps->MaxAnisotropy = gl_info->limits.anisotropy;
+    pCaps->MaxPointSize = gl_info->limits.pointsize_max;
 
 
@@ -4059,5 +4168,5 @@
     pCaps->NumberOfAdaptersInGroup           = 1;
 
-    pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
+    pCaps->NumSimultaneousRTs = gl_info->limits.buffers;
 
     pCaps->StretchRectFilterCaps             = WINED3DPTFILTERCAPS_MINFPOINT  |
@@ -4119,13 +4228,15 @@
         pCaps->VS20Caps.Caps                     = WINED3DVS20CAPS_PREDICATION;
         pCaps->VS20Caps.DynamicFlowControlDepth  = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
-        pCaps->VS20Caps.NumTemps                 = max(32, adapter->gl_info.vs_arb_max_temps);
+        pCaps->VS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_vs_temps);
         pCaps->VS20Caps.StaticFlowControlDepth   = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
 
         pCaps->MaxVShaderInstructionsExecuted    = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
-        pCaps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.vs_arb_max_instructions);
-    } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
+        pCaps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions);
+    }
+    else if (pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0))
+    {
         pCaps->VS20Caps.Caps                     = 0;
         pCaps->VS20Caps.DynamicFlowControlDepth  = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
-        pCaps->VS20Caps.NumTemps                 = max(12, adapter->gl_info.vs_arb_max_temps);
+        pCaps->VS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_vs_temps);
         pCaps->VS20Caps.StaticFlowControlDepth   = 1;
 
@@ -4153,15 +4264,18 @@
                 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
         pCaps->PS20Caps.DynamicFlowControlDepth  = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
-        pCaps->PS20Caps.NumTemps                 = max(32, adapter->gl_info.ps_arb_max_temps);
+        pCaps->PS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_ps_temps);
         pCaps->PS20Caps.StaticFlowControlDepth   = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
         pCaps->PS20Caps.NumInstructionSlots      = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
 
         pCaps->MaxPShaderInstructionsExecuted    = 65535;
-        pCaps->MaxPixelShader30InstructionSlots  = max(WINED3DMIN30SHADERINSTRUCTIONS, adapter->gl_info.ps_arb_max_instructions);
-    } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
+        pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS,
+                adapter->gl_info.limits.arb_ps_instructions);
+    }
+    else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0))
+    {
         /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
         pCaps->PS20Caps.Caps                     = 0;
         pCaps->PS20Caps.DynamicFlowControlDepth  = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
-        pCaps->PS20Caps.NumTemps                 = max(12, adapter->gl_info.ps_arb_max_temps);
+        pCaps->PS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_ps_temps);
         pCaps->PS20Caps.StaticFlowControlDepth   = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
         pCaps->PS20Caps.NumInstructionSlots      = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
@@ -4192,5 +4306,6 @@
                            WINED3DDTCAPS_SHORT2N   |
                            WINED3DDTCAPS_SHORT4N;
-        if (GL_SUPPORT(ARB_HALF_FLOAT_VERTEX)) {
+        if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
+        {
             pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
                                 WINED3DDTCAPS_FLOAT16_4;
@@ -4269,111 +4384,43 @@
 }
 
-/* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
-   and fields being inserted in the middle, a new structure is used in place    */
-static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter,
-        WINED3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviourFlags, IUnknown *parent,
-        IWineD3DDeviceParent *device_parent, IWineD3DDevice **ppReturnedDeviceInterface)
-{
-    IWineD3DDeviceImpl *object  = NULL;
-    IWineD3DImpl       *This    = (IWineD3DImpl *)iface;
-    struct WineD3DAdapter *adapter = &This->adapters[Adapter];
-    WINED3DDISPLAYMODE  mode;
-    const struct fragment_pipeline *frag_pipeline = NULL;
-    int i;
-    struct fragment_caps ffp_caps;
-    struct shader_caps shader_caps;
+static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags, IUnknown *parent,
+        IWineD3DDeviceParent *device_parent, IWineD3DDevice **device)
+{
+    IWineD3DImpl *This = (IWineD3DImpl *)iface;
+    IWineD3DDeviceImpl *object;
     HRESULT hr;
 
+    TRACE("iface %p, adapter_idx %u, device_type %#x, focus_window %p, flags %#x.\n"
+            "parent %p, device_parent %p, device %p.\n",
+            iface, adapter_idx, device_type, focus_window, flags,
+            parent, device_parent, device);
+
     /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
-     * number and create a device without a 3D adapter for 2D only operation.
-     */
-    if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
+     * number and create a device without a 3D adapter for 2D only operation. */
+    if (IWineD3D_GetAdapterCount(iface) && adapter_idx >= IWineD3D_GetAdapterCount(iface))
+    {
         return WINED3DERR_INVALIDCALL;
     }
 
-    /* Create a WineD3DDevice object */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
-    *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
-    TRACE("Created WineD3DDevice object @ %p\n", object);
-    if (NULL == object) {
-      return WINED3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    /* Set up initial COM information */
-    object->lpVtbl  = &IWineD3DDevice_Vtbl;
-    object->ref     = 1;
-    object->wineD3D = iface;
-    object->adapter = This->adapter_count ? adapter : NULL;
-    IWineD3D_AddRef(object->wineD3D);
-    object->parent  = parent;
-    object->device_parent = device_parent;
-    list_init(&object->resources);
-    list_init(&object->shaders);
-
-    if(This->dxVersion == 7) {
-        object->surface_alignment = DDRAW_PITCH_ALIGNMENT;
-    } else {
-        object->surface_alignment = D3D8_PITCH_ALIGNMENT;
-    }
-    object->posFixup[0] = 1.0f; /* This is needed to get the x coord unmodified through a MAD. */
-
-    /* Set the state up as invalid until the device is fully created */
-    object->state   = WINED3DERR_DRIVERINTERNALERROR;
-
-    TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
-          hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
-
-    /* Save the creation parameters */
-    object->createParms.AdapterOrdinal = Adapter;
-    object->createParms.DeviceType     = DeviceType;
-    object->createParms.hFocusWindow   = hFocusWindow;
-    object->createParms.BehaviorFlags  = BehaviourFlags;
-
-    /* Initialize other useful values */
-    object->adapterNo                    = Adapter;
-    object->devType                      = DeviceType;
-
-    select_shader_mode(&adapter->gl_info, &object->ps_selected_mode, &object->vs_selected_mode);
-    object->shader_backend = select_shader_backend(adapter, DeviceType);
-
-    memset(&shader_caps, 0, sizeof(shader_caps));
-    object->shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
-    object->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst;
-    object->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst;
-    object->vs_clipping = shader_caps.VSClipping;
-
-    memset(&ffp_caps, 0, sizeof(ffp_caps));
-    frag_pipeline = select_fragment_implementation(adapter, DeviceType);
-    object->frag_pipe = frag_pipeline;
-    frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &ffp_caps);
-    object->max_ffp_textures = ffp_caps.MaxSimultaneousTextures;
-    object->max_ffp_texture_stages = ffp_caps.MaxTextureBlendStages;
-    hr = compile_state_table(object->StateTable, object->multistate_funcs, &adapter->gl_info,
-                        ffp_vertexstate_template, frag_pipeline, misc_state_template);
-
-    if (FAILED(hr)) {
-        IWineD3D_Release(object->wineD3D);
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate device memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = device_init(object, This, adapter_idx, device_type, focus_window, flags, parent, device_parent);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize device, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-
         return hr;
     }
 
-    object->blitter = select_blit_implementation(adapter, DeviceType);
-
-    /* set the state of the device to valid */
-    object->state = WINED3D_OK;
-
-    /* Get the initial screen setup for ddraw */
-    IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
-
-    object->ddraw_width = mode.Width;
-    object->ddraw_height = mode.Height;
-    object->ddraw_format = mode.Format;
-
-    for(i = 0; i < PATCHMAP_SIZE; i++) {
-        list_init(&object->patches[i]);
-    }
-
-    IWineD3DDeviceParent_WineD3DDeviceCreated(device_parent, *ppReturnedDeviceInterface);
+    TRACE("Created device %p.\n", object);
+    *device = (IWineD3DDevice *)object;
+
+    IWineD3DDeviceParent_WineD3DDeviceCreated(device_parent, *device);
 
     return WINED3D_OK;
@@ -4385,14 +4432,4 @@
     *pParent = This->parent;
     return WINED3D_OK;
-}
-
-ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
-    IUnknown* volumeParent;
-    TRACE("(%p) call back\n", pVolume);
-
-    /* Now, release the parent, which will take care of cleaning up the volume for us */
-    IWineD3DVolume_GetParent(pVolume, &volumeParent);
-    IUnknown_Release(volumeParent);
-    return IUnknown_Release(volumeParent);
 }
 
@@ -4505,14 +4542,20 @@
     specular_funcs[WINED3D_FFP_EMIT_FLOAT1]      = invalid_func;
     specular_funcs[WINED3D_FFP_EMIT_FLOAT2]      = invalid_func;
-    if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+    if (gl_info->supported[EXT_SECONDARY_COLOR])
+    {
         specular_funcs[WINED3D_FFP_EMIT_FLOAT3]  = (glAttribFunc)GL_EXTCALL(glSecondaryColor3fvEXT);
-    } else {
+    }
+    else
+    {
         specular_funcs[WINED3D_FFP_EMIT_FLOAT3]  = warn_no_specular_func;
     }
     specular_funcs[WINED3D_FFP_EMIT_FLOAT4]      = invalid_func;
-    if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+    if (gl_info->supported[EXT_SECONDARY_COLOR])
+    {
         specular_func_3ubv = (glAttribFunc)GL_EXTCALL(glSecondaryColor3ubvEXT);
         specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
-    } else {
+    }
+    else
+    {
         specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
     }
@@ -4566,5 +4609,5 @@
     multi_texcoord_funcs[WINED3D_FFP_EMIT_UDEC3]     = invalid_texcoord_func;
     multi_texcoord_funcs[WINED3D_FFP_EMIT_DEC3N]     = invalid_texcoord_func;
-    if (GL_SUPPORT(NV_HALF_FLOAT))
+    if (gl_info->supported[NV_HALF_FLOAT])
     {
         /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT */
@@ -4634,5 +4677,5 @@
     /* For now only one default adapter */
     {
-        struct WineD3DAdapter *adapter = &This->adapters[0];
+        struct wined3d_adapter *adapter = &This->adapters[0];
         const struct wined3d_gl_info *gl_info = &adapter->gl_info;
         struct wined3d_fake_gl_ctx fake_gl_ctx = {0};
@@ -4645,7 +4688,16 @@
 
         TRACE("Initializing default adapter\n");
-        adapter->num = 0;
+        adapter->ordinal = 0;
         adapter->monitorPoint.x = -1;
         adapter->monitorPoint.y = -1;
+
+        if (!AllocateLocallyUniqueId(&adapter->luid))
+        {
+            DWORD err = GetLastError();
+            ERR("Failed to set adapter LUID (%#x).\n", err);
+            goto nogl_adapter;
+        }
+        TRACE("Allocated LUID %08x:%08x for adapter.\n",
+                adapter->luid.HighPart, adapter->luid.LowPart);
 
         if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx))
@@ -4655,5 +4707,5 @@
         }
 
-        ret = IWineD3DImpl_FillGLCaps(&adapter->gl_info);
+        ret = IWineD3DImpl_FillGLCaps(&adapter->driver_info, &adapter->gl_info);
         if(!ret) {
             ERR("Failed to initialize gl caps for default adapter\n");
@@ -4661,5 +4713,5 @@
             goto nogl_adapter;
         }
-        ret = initPixelFormats(&adapter->gl_info);
+        ret = initPixelFormats(&adapter->gl_info, adapter->driver_info.vendor);
         if(!ret) {
             ERR("Failed to init gl formats\n");
@@ -4669,7 +4721,4 @@
 
         hdc = fake_gl_ctx.dc;
-
-        adapter->driver = "Display";
-        adapter->description = "Direct3D HAL";
 
         /* Use the VideoRamSize registry setting when set */
@@ -4687,5 +4736,5 @@
         strcpyW(adapter->DeviceName, DisplayDevice.DeviceName);
 
-        if(GL_SUPPORT(WGL_ARB_PIXEL_FORMAT))
+        if (gl_info->supported[WGL_ARB_PIXEL_FORMAT])
         {
             int attribute;
@@ -4731,6 +4780,8 @@
 
                 cfgs->pbufferDrawable = FALSE;
-                /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown attributes. */
-                if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
+                /* Check for pbuffer support when it is around as
+                 * wglGetPixelFormatAttribiv fails for unknown attributes. */
+                if (gl_info->supported[WGL_ARB_PBUFFER])
+                {
                     int attrib = WGL_DRAW_TO_PBUFFER_ARB;
                     int value;
@@ -4741,5 +4792,6 @@
                 cfgs->numSamples = 0;
                 /* Check multisample support */
-                if(GL_SUPPORT(ARB_MULTISAMPLE)) {
+                if (gl_info->supported[ARB_MULTISAMPLE])
+                {
                     int attrib[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
                     int value[2];
@@ -4833,5 +4885,4 @@
 
         select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
-        select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
         fillGLAttribFuncs(&adapter->gl_info);
         adapter->opengl = TRUE;
@@ -4845,11 +4896,11 @@
     /* Initialize an adapter for ddraw-only memory counting */
     memset(This->adapters, 0, sizeof(This->adapters));
-    This->adapters[0].num = 0;
+    This->adapters[0].ordinal = 0;
     This->adapters[0].opengl = FALSE;
     This->adapters[0].monitorPoint.x = -1;
     This->adapters[0].monitorPoint.y = -1;
 
-    This->adapters[0].driver = "Display";
-    This->adapters[0].description = "WineD3D DirectDraw Emulation";
+    This->adapters[0].driver_info.name = "Display";
+    This->adapters[0].driver_info.description = "WineD3D DirectDraw Emulation";
     if(wined3d_settings.emulated_textureram) {
         This->adapters[0].TextureRam = wined3d_settings.emulated_textureram;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c	(revision 25949)
@@ -49,9 +49,7 @@
         UINT count, UINT idx_size, const void *idx_data, UINT start_idx)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-
     if (idx_size)
     {
-        TRACE("(%p) : glElements(%x, %d, ...)\n", This, primitive_type, count);
+        TRACE("(%p) : glElements(%x, %d, ...)\n", iface, primitive_type, count);
 
         glDrawElements(primitive_type, count,
@@ -62,5 +60,5 @@
     else
     {
-        TRACE("(%p) : glDrawArrays(%#x, %d, %d)\n", This, primitive_type, start_idx, count);
+        TRACE("(%p) : glDrawArrays(%#x, %d, %d)\n", iface, primitive_type, start_idx, count);
 
         glDrawArrays(primitive_type, start_idx, count);
@@ -88,7 +86,8 @@
     BOOL                      pixelShader = use_ps(This->stateBlock);
     BOOL specular_fog = FALSE;
-    UINT texture_stages = GL_LIMITS(texture_stages);
     const BYTE *texCoords[WINED3DDP_MAXTEXCOORD];
     const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+    UINT texture_stages = gl_info->limits.texture_stages;
     const struct wined3d_stream_info_element *element;
     UINT num_untracked_materials;
@@ -159,5 +158,5 @@
                 && This->stateBlock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE)
         {
-            if (GL_SUPPORT(EXT_FOG_COORD))
+            if (gl_info->supported[EXT_FOG_COORD])
             {
                 if (element->format_desc->format == WINED3DFMT_B8G8R8A8_UNORM) specular_fog = TRUE;
@@ -177,5 +176,5 @@
         }
     }
-    else if (GL_SUPPORT(EXT_SECONDARY_COLOR))
+    else if (gl_info->supported[EXT_SECONDARY_COLOR])
     {
         GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
@@ -187,5 +186,5 @@
         DWORD texture_idx = This->texUnitMap[textureNo];
 
-        if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0)
+        if (!gl_info->supported[ARB_MULTITEXTURE] && textureNo > 0)
         {
             FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
@@ -217,5 +216,5 @@
         {
             TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo);
-            if (GL_SUPPORT(ARB_MULTITEXTURE))
+            if (gl_info->supported[ARB_MULTITEXTURE])
                 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, 0, 0, 0, 1));
             else
@@ -326,4 +325,6 @@
 static inline void send_attribute(IWineD3DDeviceImpl *This, WINED3DFORMAT format, const UINT index, const void *ptr)
 {
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
+
     switch(format)
     {
@@ -345,5 +346,5 @@
             break;
         case WINED3DFMT_B8G8R8A8_UNORM:
-            if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA))
+            if (gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
             {
                 const DWORD *src = ptr;
@@ -398,8 +399,11 @@
              * byte float according to the IEEE standard
              */
-            if (GL_SUPPORT(NV_HALF_FLOAT)) {
+            if (gl_info->supported[NV_HALF_FLOAT])
+            {
                 /* Not supported by GL_ARB_half_float_vertex */
                 GL_EXTCALL(glVertexAttrib2hvNV(index, ptr));
-            } else {
+            }
+            else
+            {
                 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
                 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
@@ -408,8 +412,11 @@
             break;
         case WINED3DFMT_R16G16B16A16_FLOAT:
-            if (GL_SUPPORT(NV_HALF_FLOAT)) {
+            if (gl_info->supported[NV_HALF_FLOAT])
+            {
                 /* Not supported by GL_ARB_half_float_vertex */
                 GL_EXTCALL(glVertexAttrib4hvNV(index, ptr));
-            } else {
+            }
+            else
+            {
                 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
                 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
@@ -594,5 +601,5 @@
     {
         /* Invalidate the back buffer memory so LockRect will read it the next time */
-        for (i = 0; i < GL_LIMITS(buffers); ++i)
+        for (i = 0; i < This->adapter->gl_info.limits.buffers; ++i)
         {
             target = (IWineD3DSurfaceImpl *)This->render_targets[i];
@@ -608,8 +615,8 @@
     This->isInDraw = TRUE;
 
-    context = ActivateContext(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
+    context = context_acquire(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
 
     if (This->stencilBufferTarget) {
-        /* Note that this depends on the ActivateContext call above to set
+        /* Note that this depends on the context_acquire() call above to set
          * This->render_offscreen properly. We don't currently take the
          * Z-compare function into account, but we could skip loading the
@@ -695,4 +702,6 @@
     /* Finished updating the screen, restore lock */
     LEAVE_GL();
+    context_release(context);
+
     TRACE("Done all gl drawing\n");
 
@@ -778,4 +787,5 @@
     struct wined3d_stream_info stream_info;
     struct wined3d_stream_info_element *e;
+    struct wined3d_context *context;
     const BYTE *data;
     const WINED3DRECTPATCH_INFO *info = &patch->RectPatchInfo;
@@ -787,5 +797,5 @@
      * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
      * patch (as opposed to normal draws) will most likely need different changes anyway. */
-    ActivateContext(This, NULL, CTXUSAGE_BLIT);
+    context = context_acquire(This, NULL, CTXUSAGE_BLIT);
 
     /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
@@ -869,5 +879,6 @@
         IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_AMBIENT));
 
-        for(i = 3; i < GL_LIMITS(lights); i++) {
+        for (i = 3; i < context->gl_info->limits.lights; ++i)
+        {
             glDisable(GL_LIGHT0 + i);
             checkGLcall("glDisable(GL_LIGHT0 + i)");
@@ -969,4 +980,5 @@
         ERR("Feedback failed. Expected %d elements back\n", buffer_size);
         HeapFree(GetProcessHeap(), 0, feedbuffer);
+        context_release(context);
         return WINED3DERR_DRIVERINTERNALERROR;
     } else if(i != buffer_size) {
@@ -974,4 +986,5 @@
         ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size, i);
         HeapFree(GetProcessHeap(), 0, feedbuffer);
+        context_release(context);
         return WINED3DERR_DRIVERINTERNALERROR;
     } else {
@@ -1088,4 +1101,6 @@
     LEAVE_GL();
 
+    context_release(context);
+
     HeapFree(GetProcessHeap(), 0, feedbuffer);
 
@@ -1097,5 +1112,5 @@
         vtxStride += 4 * sizeof(float);
     }
-    memset(&patch->strided, 0, sizeof(&patch->strided));
+    memset(&patch->strided, 0, sizeof(patch->strided));
     patch->strided.position.format = WINED3DFMT_R32G32B32_FLOAT;
     patch->strided.position.lpData = (BYTE *) patch->mem;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/gl_compat.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/gl_compat.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/gl_compat.c	(revision 25949)
@@ -352,8 +352,8 @@
 /* End GL_EXT_fog_coord emulation */
 
-#define GLINFO_LOCATION (*gl_info)
 void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info)
 {
-    if(!GL_SUPPORT(ARB_MULTITEXTURE)) {
+    if (!gl_info->supported[ARB_MULTITEXTURE])
+    {
         TRACE("Applying GL_ARB_multitexture emulation hooks\n");
         gl_info->glActiveTextureARB         = wine_glActiveTextureARB;
@@ -390,5 +390,6 @@
     }
 
-    if(!GL_SUPPORT(EXT_FOG_COORD)) {
+    if (!gl_info->supported[EXT_FOG_COORD])
+    {
         /* This emulation isn't perfect. There are a number of potential problems, but they should
          * not matter in practise:
@@ -415,8 +416,11 @@
          * dependent loading for this extension if we ever hit this situation
          */
-        if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
+        if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
+        {
             FIXME("GL implementation supports GL_ARB_fragment_program but not GL_EXT_fog_coord\n");
             FIXME("The fog coord emulation will most likely fail\n");
-        } else if(GL_SUPPORT(ARB_FRAGMENT_SHADER)) {
+        }
+        else if (gl_info->supported[ARB_FRAGMENT_SHADER])
+        {
             FIXME("GL implementation supports GL_ARB_fragment_shader but not GL_EXT_fog_coord\n");
             FIXME("The fog coord emulation will most likely fail\n");
@@ -543,3 +547,2 @@
     }
 }
-#undef GLINFO_LOCATION
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 25949)
@@ -265,5 +265,5 @@
         if (name_loc != -1) {
             DWORD mapped_unit = tex_unit_map[i];
-            if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < GL_LIMITS(fragment_samplers))
+            if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < gl_info->limits.fragment_samplers)
             {
                 TRACE("Loading %s for texture %d\n", sampler_name, mapped_unit);
@@ -290,5 +290,5 @@
         if (name_loc != -1) {
             DWORD mapped_unit = tex_unit_map[MAX_FRAGMENT_SAMPLERS + i];
-            if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < GL_LIMITS(combined_samplers))
+            if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < gl_info->limits.combined_samplers)
             {
                 TRACE("Loading %s for texture %d\n", sampler_name, mapped_unit);
@@ -641,5 +641,5 @@
         char usePixelShader, char useVertexShader)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
     IWineD3DStateBlockImpl* stateBlock = device->stateBlock;
@@ -805,5 +805,5 @@
 static unsigned int vec4_varyings(DWORD shader_major, const struct wined3d_gl_info *gl_info)
 {
-    unsigned int ret = GL_LIMITS(glsl_varyings) / 4;
+    unsigned int ret = gl_info->limits.glsl_varyings / 4;
     /* 4.0 shaders do not write clip coords because d3d10 does not support user clipplanes */
     if(shader_major > 3) return ret;
@@ -853,8 +853,11 @@
          * 2) The shader uses indirect addressing, less constants than supported, but uses a constant index > #supported consts
          */
-        if(pshader) {
-            /* No indirect addressing here */
-            max_constantsF = GL_LIMITS(pshader_constantsF);
-        } else {
+        if (pshader)
+        {
+            /* No indirect addressing here. */
+            max_constantsF = gl_info->limits.glsl_ps_float_constants;
+        }
+        else
+        {
             if(This->baseShader.reg_maps.usesrelconstF) {
                 /* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix).
@@ -863,7 +866,11 @@
                  * (Unfortunately the Nvidia driver doesn't store 128 and -128 in one float).
                  *
-                 * Writing gl_ClipPos requires one uniform for each clipplane as well.
+                 * Writing gl_ClipVertex requires one uniform for each clipplane as well.
                  */
-                max_constantsF = GL_LIMITS(vshader_constantsF) - 3 - GL_LIMITS(clipplanes);
+                max_constantsF = gl_info->limits.glsl_vs_float_constants - 3;
+                if(ctx_priv->cur_vs_args->clip_enabled)
+                {
+                    max_constantsF -= gl_info->limits.clipplanes;
+                }
                 max_constantsF -= count_bits(This->baseShader.reg_maps.integer_constants);
                 /* Strictly speaking a bool only uses one scalar, but the nvidia(Linux) compiler doesn't pack them properly,
@@ -873,7 +880,9 @@
                 max_constantsF -= count_bits(This->baseShader.reg_maps.boolean_constants);
                 /* Set by driver quirks in directx.c */
-                max_constantsF -= GLINFO_LOCATION.reserved_glsl_constants;
-            } else {
-                max_constantsF = GL_LIMITS(vshader_constantsF);
+                max_constantsF -= gl_info->reserved_glsl_constants;
+            }
+            else
+            {
+                max_constantsF = gl_info->limits.glsl_vs_float_constants;
             }
         }
@@ -933,6 +942,9 @@
                     srgb_cmp);
         }
-        if(reg_maps->vpos || reg_maps->usesdsy) {
-            if(This->baseShader.limits.constant_float + extra_constants_needed + 1 < GL_LIMITS(pshader_constantsF)) {
+        if (reg_maps->vpos || reg_maps->usesdsy)
+        {
+            if (This->baseShader.limits.constant_float + extra_constants_needed
+                    + 1 < gl_info->limits.glsl_ps_float_constants)
+            {
                 shader_addline(buffer, "uniform vec4 ycorrection;\n");
                 ((IWineD3DPixelShaderImpl *) This)->vpos_uniform = 1;
@@ -1319,6 +1331,6 @@
 
         case WINED3DSPR_COLOROUT:
-            if (reg->idx >= GL_LIMITS(buffers))
-                WARN("Write to render target %u, only %d supported\n", reg->idx, GL_LIMITS(buffers));
+            if (reg->idx >= gl_info->limits.buffers)
+                WARN("Write to render target %u, only %d supported.\n", reg->idx, gl_info->limits.buffers);
 
             sprintf(register_name, "gl_FragData[%u]", reg->idx);
@@ -1967,5 +1979,4 @@
         case WINED3DSIH_NRM: instruction = "normalize"; break;
         case WINED3DSIH_EXP: instruction = "exp2"; break;
-        case WINED3DSIH_SGN: instruction = "sign"; break;
         case WINED3DSIH_DSX: instruction = "dFdx"; break;
         case WINED3DSIH_DSY: instruction = "ycorrection.y * dFdy"; break;
@@ -2460,4 +2471,19 @@
 }
 
+/* sgn in vs_2_0 has 2 extra parameters(registers for temporary storage) which we don't use
+ * here. But those extra parameters require a dedicated function for sgn, since map2gl would
+ * generate invalid code
+ */
+static void shader_glsl_sgn(const struct wined3d_shader_instruction *ins)
+{
+    glsl_src_param_t src0_param;
+    DWORD write_mask;
+
+    write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
+    shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
+
+    shader_addline(ins->ctx->buffer, "sign(%s));\n", src0_param.param_str);
+}
+
 /** Process the WINED3DSIO_LOOP instruction in GLSL:
  * Start a for() loop where src1.y is the initial value of aL,
@@ -2755,5 +2781,6 @@
     DWORD swizzle = ins->src[1].swizzle;
 
-    if(!GL_SUPPORT(ARB_SHADER_TEXTURE_LOD)) {
+    if (!gl_info->supported[ARB_SHADER_TEXTURE_LOD])
+    {
         FIXME("texldd used, but not supported by hardware. Falling back to regular tex\n");
         return shader_glsl_tex(ins);
@@ -3572,5 +3599,5 @@
          */
         device = (IWineD3DDeviceImpl *) vs->baseShader.device;
-        if (((GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W)
+        if ((gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W)
                 && ps_major == 0 && vs_major > 0 && !device->frag_pipe->ffp_proj_control)
         {
@@ -3590,5 +3617,5 @@
 
         /* The vertex shader writes to its own varyings, the pixel shader needs them in the builtin ones */
-        output_signature = vs->output_signature;
+        output_signature = vs->baseShader.output_signature;
 
         shader_addline(buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT);
@@ -3619,5 +3646,5 @@
                 if (semantic_idx < 8)
                 {
-                    if (!((GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W) || ps_major > 0)
+                    if (!(gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W) || ps_major > 0)
                         write_mask |= WINED3DSP_WRITEMASK_3;
 
@@ -3642,5 +3669,5 @@
         WORD map = vs->baseShader.reg_maps.output_registers;
 
-        output_signature = vs->output_signature;
+        output_signature = vs->baseShader.output_signature;
 
         /* This one is tricky: a 3.0 pixel shader reads from a 3.0 vertex shader */
@@ -3667,5 +3694,5 @@
 
         /* Then, fix the pixel shader input */
-        handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->input_signature,
+        handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->baseShader.input_signature,
                 &ps->baseShader.reg_maps, output_signature, &vs->baseShader.reg_maps);
 
@@ -3678,5 +3705,5 @@
          * read gl_TexCoord and gl_ColorX, otherwise we'll run out of varyings
          */
-        handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->input_signature,
+        handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->baseShader.input_signature,
                 &ps->baseShader.reg_maps, NULL, NULL);
         shader_addline(buffer, "}\n");
@@ -3732,8 +3759,10 @@
     shader_addline(buffer, "#version 120\n");
 
-    if(GL_SUPPORT(ARB_SHADER_TEXTURE_LOD) && reg_maps->usestexldd) {
+    if (gl_info->supported[ARB_SHADER_TEXTURE_LOD] && reg_maps->usestexldd)
+    {
         shader_addline(buffer, "#extension GL_ARB_shader_texture_lod : enable\n");
     }
-    if (GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+    if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+    {
         /* The spec says that it doesn't have to be explicitly enabled, but the nvidia
          * drivers write a warning if we don't do so
@@ -3748,5 +3777,6 @@
     if (reg_maps->shader_version.major >= 3 && args->vp_mode != vertexshader)
     {
-        shader_glsl_input_pack((IWineD3DPixelShader *) This, buffer, This->input_signature, reg_maps, args->vp_mode);
+        shader_glsl_input_pack((IWineD3DPixelShader *) This, buffer,
+                This->baseShader.input_signature, reg_maps, args->vp_mode);
     }
 
@@ -3806,5 +3836,5 @@
     GL_EXTCALL(glShaderSourceARB(shader_obj, 1, (const char**)&buffer->buffer, NULL));
     GL_EXTCALL(glCompileShaderARB(shader_obj));
-    print_glsl_info_log(&GLINFO_LOCATION, shader_obj);
+    print_glsl_info_log(gl_info, shader_obj);
 
     /* Store the shader object */
@@ -3860,5 +3890,7 @@
     shader_addline(buffer, "gl_Position.y = gl_Position.y * posFixup.y;\n");
     shader_addline(buffer, "gl_Position.xy += posFixup.zw * gl_Position.ww;\n");
-    shader_addline(buffer, "gl_ClipVertex = gl_Position;\n");
+    if(args->clip_enabled) {
+        shader_addline(buffer, "gl_ClipVertex = gl_Position;\n");
+    }
 
     /* Z coord [0;1]->[-1;1] mapping, see comment in transform_projection in state.c
@@ -3875,5 +3907,5 @@
     GL_EXTCALL(glShaderSourceARB(shader_obj, 1, (const char**)&buffer->buffer, NULL));
     GL_EXTCALL(glCompileShaderARB(shader_obj));
-    print_glsl_info_log(&GLINFO_LOCATION, shader_obj);
+    print_glsl_info_log(gl_info, shader_obj);
 
     return shader_obj;
@@ -3952,4 +3984,5 @@
                                  const DWORD use_map) {
     if((stored->swizzle_map & use_map) != new->swizzle_map) return FALSE;
+    if((stored->clip_enabled) != new->clip_enabled) return FALSE;
     return stored->fog_src == new->fog_src;
 }
@@ -4127,21 +4160,27 @@
     TRACE("Linking GLSL shader program %u\n", programId);
     GL_EXTCALL(glLinkProgramARB(programId));
-    print_glsl_info_log(&GLINFO_LOCATION, programId);
-
-    entry->vuniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(vshader_constantsF));
-    for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
+    print_glsl_info_log(gl_info, programId);
+
+    entry->vuniformF_locations = HeapAlloc(GetProcessHeap(), 0,
+            sizeof(GLhandleARB) * gl_info->limits.glsl_vs_float_constants);
+    for (i = 0; i < gl_info->limits.glsl_vs_float_constants; ++i)
+    {
         snprintf(glsl_name, sizeof(glsl_name), "VC[%i]", i);
         entry->vuniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
     }
-    for (i = 0; i < MAX_CONST_I; ++i) {
+    for (i = 0; i < MAX_CONST_I; ++i)
+    {
         snprintf(glsl_name, sizeof(glsl_name), "VI[%i]", i);
         entry->vuniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
     }
-    entry->puniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(pshader_constantsF));
-    for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) {
+    entry->puniformF_locations = HeapAlloc(GetProcessHeap(), 0,
+            sizeof(GLhandleARB) * gl_info->limits.glsl_ps_float_constants);
+    for (i = 0; i < gl_info->limits.glsl_ps_float_constants; ++i)
+    {
         snprintf(glsl_name, sizeof(glsl_name), "PC[%i]", i);
         entry->puniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
     }
-    for (i = 0; i < MAX_CONST_I; ++i) {
+    for (i = 0; i < MAX_CONST_I; ++i)
+    {
         snprintf(glsl_name, sizeof(glsl_name), "PI[%i]", i);
         entry->puniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
@@ -4275,5 +4314,5 @@
     GL_EXTCALL(glLinkProgramARB(program_id));
 
-    print_glsl_info_log(&GLINFO_LOCATION, program_id);
+    print_glsl_info_log(gl_info, program_id);
 
     /* Once linked we can mark the shaders for deletion. They will be deleted once the program
@@ -4288,5 +4327,5 @@
 static void shader_glsl_select(const struct wined3d_context *context, BOOL usePS, BOOL useVS)
 {
-    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
     struct shader_glsl_priv *priv = device->shader_priv;
@@ -4301,9 +4340,13 @@
     current_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->vertex_color_clamp : GL_FIXED_ONLY_ARB;
 
-    if (old_vertex_color_clamp != current_vertex_color_clamp) {
-        if (GL_SUPPORT(ARB_COLOR_BUFFER_FLOAT)) {
+    if (old_vertex_color_clamp != current_vertex_color_clamp)
+    {
+        if (gl_info->supported[ARB_COLOR_BUFFER_FLOAT])
+        {
             GL_EXTCALL(glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, current_vertex_color_clamp));
             checkGLcall("glClampColorARB");
-        } else {
+        }
+        else
+        {
             FIXME("vertex color clamp needs to be changed, but extension not supported.\n");
         }
@@ -4361,8 +4404,8 @@
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)This->baseShader.device;
     struct shader_glsl_priv *priv = device->shader_priv;
-    const struct wined3d_context *context;
     const struct wined3d_gl_info *gl_info;
     IWineD3DPixelShaderImpl *ps = NULL;
     IWineD3DVertexShaderImpl *vs = NULL;
+    struct wined3d_context *context;
 
     /* Note: Do not use QueryInterface here to find out which shader type this is because this code
@@ -4382,5 +4425,5 @@
         }
 
-        context = ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
         gl_info = context->gl_info;
 
@@ -4402,5 +4445,5 @@
         }
 
-        context = ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
         gl_info = context->gl_info;
 
@@ -4461,4 +4504,6 @@
         vs->baseShader.backend_data = NULL;
     }
+
+    context_release(context);
 }
 
@@ -4518,5 +4563,6 @@
     const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv));
-    SIZE_T stack_size = wined3d_log2i(max(GL_LIMITS(vshader_constantsF), GL_LIMITS(pshader_constantsF))) + 1;
+    SIZE_T stack_size = wined3d_log2i(max(gl_info->limits.glsl_vs_float_constants,
+            gl_info->limits.glsl_ps_float_constants)) + 1;
 
     if (!shader_buffer_init(&priv->shader_buffer))
@@ -4533,5 +4579,5 @@
     }
 
-    if (!constant_heap_init(&priv->vconst_heap, GL_LIMITS(vshader_constantsF)))
+    if (!constant_heap_init(&priv->vconst_heap, gl_info->limits.glsl_vs_float_constants))
     {
         ERR("Failed to initialize vertex shader constant heap\n");
@@ -4539,5 +4585,5 @@
     }
 
-    if (!constant_heap_init(&priv->pconst_heap, GL_LIMITS(pshader_constantsF)))
+    if (!constant_heap_init(&priv->pconst_heap, gl_info->limits.glsl_ps_float_constants))
     {
         ERR("Failed to initialize pixel shader constant heap\n");
@@ -4586,4 +4632,5 @@
     constant_heap_free(&priv->vconst_heap);
     HeapFree(GetProcessHeap(), 0, priv->stack);
+    shader_buffer_free(&priv->shader_buffer);
 
     HeapFree(GetProcessHeap(), 0, This->shader_priv);
@@ -4608,10 +4655,10 @@
      */
     if ((gl_info->supported[NV_VERTEX_PROGRAM2] && !gl_info->supported[NV_VERTEX_PROGRAM3])
-            || gl_info->ps_arb_max_instructions <= 512)
+            || gl_info->limits.arb_ps_instructions <= 512)
         pCaps->VertexShaderVersion = WINED3DVS_VERSION(2,0);
     else
         pCaps->VertexShaderVersion = WINED3DVS_VERSION(3,0);
     TRACE_(d3d_caps)("Hardware vertex shader version %d.%d enabled (GLSL)\n", (pCaps->VertexShaderVersion >> 8) & 0xff, pCaps->VertexShaderVersion & 0xff);
-    pCaps->MaxVertexShaderConst = GL_LIMITS(vshader_constantsF);
+    pCaps->MaxVertexShaderConst = gl_info->limits.glsl_vs_float_constants;
 
     /* Older DX9-class videocards (GeforceFX / Radeon >9500/X*00) only support pixel shader 2.0/2.0a/2.0b.
@@ -4627,10 +4674,10 @@
      */
     if ((gl_info->supported[NV_FRAGMENT_PROGRAM] && !gl_info->supported[NV_FRAGMENT_PROGRAM2])
-            || (gl_info->ps_arb_max_instructions <= 512))
+            || gl_info->limits.arb_ps_instructions <= 512)
         pCaps->PixelShaderVersion = WINED3DPS_VERSION(2,0);
     else
         pCaps->PixelShaderVersion = WINED3DPS_VERSION(3,0);
 
-    pCaps->MaxPixelShaderConst = GL_LIMITS(pshader_constantsF);
+    pCaps->MaxPixelShaderConst = gl_info->limits.glsl_ps_float_constants;
 
     /* FIXME: The following line is card dependent. -8.0 to 8.0 is the
@@ -4684,4 +4731,5 @@
     /* WINED3DSIH_CND           */ shader_glsl_cnd,
     /* WINED3DSIH_CRS           */ shader_glsl_cross,
+    /* WINED3DSIH_CUT           */ NULL,
     /* WINED3DSIH_DCL           */ NULL,
     /* WINED3DSIH_DEF           */ NULL,
@@ -4695,4 +4743,5 @@
     /* WINED3DSIH_DSY           */ shader_glsl_map2gl,
     /* WINED3DSIH_ELSE          */ shader_glsl_else,
+    /* WINED3DSIH_EMIT          */ NULL,
     /* WINED3DSIH_ENDIF         */ shader_glsl_end,
     /* WINED3DSIH_ENDLOOP       */ shader_glsl_end,
@@ -4701,6 +4750,8 @@
     /* WINED3DSIH_EXPP          */ shader_glsl_expp,
     /* WINED3DSIH_FRC           */ shader_glsl_map2gl,
+    /* WINED3DSIH_IADD          */ NULL,
     /* WINED3DSIH_IF            */ shader_glsl_if,
     /* WINED3DSIH_IFC           */ shader_glsl_ifc,
+    /* WINED3DSIH_IGE           */ NULL,
     /* WINED3DSIH_LABEL         */ shader_glsl_label,
     /* WINED3DSIH_LIT           */ shader_glsl_lit,
@@ -4709,4 +4760,5 @@
     /* WINED3DSIH_LOOP          */ shader_glsl_loop,
     /* WINED3DSIH_LRP           */ shader_glsl_lrp,
+    /* WINED3DSIH_LT            */ NULL,
     /* WINED3DSIH_M3x2          */ shader_glsl_mnxn,
     /* WINED3DSIH_M3x3          */ shader_glsl_mnxn,
@@ -4730,5 +4782,5 @@
     /* WINED3DSIH_SETP          */ NULL,
     /* WINED3DSIH_SGE           */ shader_glsl_compare,
-    /* WINED3DSIH_SGN           */ shader_glsl_map2gl,
+    /* WINED3DSIH_SGN           */ shader_glsl_sgn,
     /* WINED3DSIH_SINCOS        */ shader_glsl_sincos,
     /* WINED3DSIH_SLT           */ shader_glsl_compare,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/nvidia_texture_shader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/nvidia_texture_shader.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/nvidia_texture_shader.c	(revision 25949)
@@ -39,5 +39,5 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
 
-#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION stateblock->device->adapter->gl_info
 
 /* GL locking for state handlers is done by the caller. */
@@ -143,4 +143,5 @@
 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl*)iface;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     tex_op_args tex_op_args = {{0}, {0}, {0}};
     GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
@@ -439,5 +440,6 @@
         case WINED3DTOP_BUMPENVMAPLUMINANCE:
         case WINED3DTOP_BUMPENVMAP:
-            if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
+            if (gl_info->supported[NV_TEXTURE_SHADER])
+            {
                 /* The bump map stage itself isn't exciting, just read the texture. But tell the next stage to
                  * perform bump mapping and source from the current stage. Pretty much a SELECTARG2.
@@ -467,6 +469,7 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
-    BOOL tex_used = stateblock->wineD3DDevice->fixed_function_usage_map & (1 << stage);
+    BOOL tex_used = stateblock->device->fixed_function_usage_map & (1 << stage);
+    DWORD mapped_stage = stateblock->device->texUnitMap[stage];
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     TRACE("Setting color op for stage %d\n", stage);
@@ -479,5 +482,6 @@
     if (mapped_stage != WINED3D_UNMAPPED_STAGE)
     {
-        if (tex_used && mapped_stage >= GL_LIMITS(textures)) {
+        if (tex_used && mapped_stage >= gl_info->limits.textures)
+        {
             FIXME("Attempt to enable unsupported stage!\n");
             return;
@@ -502,13 +506,16 @@
             glDisable(GL_TEXTURE_3D);
             checkGLcall("glDisable(GL_TEXTURE_3D)");
-            if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+            if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+            {
                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
             }
-            if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+            if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+            {
                 glDisable(GL_TEXTURE_RECTANGLE_ARB);
                 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
             }
-            if(GL_SUPPORT(NV_TEXTURE_SHADER2) && mapped_stage < GL_LIMITS(textures)) {
+            if (gl_info->supported[NV_TEXTURE_SHADER2] && mapped_stage < gl_info->limits.textures)
+            {
                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
             }
@@ -521,9 +528,14 @@
      * if the sampler for this stage is dirty
      */
-    if(!isStateDirty(context, STATE_SAMPLER(stage))) {
-        if (tex_used) {
-            if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
+    if (!isStateDirty(context, STATE_SAMPLER(stage)))
+    {
+        if (tex_used)
+        {
+            if (gl_info->supported[NV_TEXTURE_SHADER2])
+            {
                 nvts_activate_dimensions(stage, stateblock, context);
-            } else {
+            }
+            else
+            {
                 texture_activate_dimensions(stage, stateblock, context);
             }
@@ -532,5 +544,5 @@
 
     /* Set the texture combiners */
-    set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
+    set_tex_op_nvrc((IWineD3DDevice *)stateblock->device, FALSE, stage,
                         stateblock->textureState[stage][WINED3DTSS_COLOROP],
                         stateblock->textureState[stage][WINED3DTSS_COLORARG1],
@@ -543,5 +555,6 @@
      * thus the texture shader may have to be updated
      */
-    if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
+    if (gl_info->supported[NV_TEXTURE_SHADER2])
+    {
         BOOL usesBump = (stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE ||
                             stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP) ? TRUE : FALSE;
@@ -560,5 +573,5 @@
 {
     DWORD sampler = state - STATE_SAMPLER(0);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
+    DWORD mapped_stage = stateblock->device->texUnitMap[sampler];
 
     /* No need to enable / disable anything here for unused samplers. The tex_colorop
@@ -566,5 +579,5 @@
     * will take care of this business
     */
-    if(mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= GL_LIMITS(textures)) return;
+    if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) return;
     if(sampler >= stateblock->lowest_disabled_stage) return;
     if(isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return;
@@ -576,5 +589,5 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage + 1];
+    DWORD mapped_stage = stateblock->device->texUnitMap[stage + 1];
     float mat[2][2];
 
@@ -585,5 +598,6 @@
      * for stage + 1. Keep the nvrc tex unit mapping in mind too
      */
-    if(mapped_stage < GL_LIMITS(textures)) {
+    if (mapped_stage < context->gl_info->limits.textures)
+    {
         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
         checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage))");
@@ -607,7 +621,5 @@
     GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
 }
-#undef GLINFO_LOCATION
-
-#define GLINFO_LOCATION (*gl_info)
+
 /* Context activation is done by the caller. */
 static void nvrc_enable(IWineD3DDevice *iface, BOOL enable) { }
@@ -653,5 +665,6 @@
                             WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA;
 
-    if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
+    if (gl_info->supported[NV_TEXTURE_SHADER2])
+    {
         /* Bump mapping is supported already in NV_TEXTURE_SHADER, but that extension does
          * not support 3D textures. This asks for trouble if an app uses both bump mapping
@@ -669,6 +682,6 @@
 #endif
 
-    pCaps->MaxTextureBlendStages   = GL_LIMITS(texture_stages);
-    pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
+    pCaps->MaxTextureBlendStages = gl_info->limits.texture_stages;
+    pCaps->MaxSimultaneousTextures = gl_info->limits.textures;
 
     pCaps->PrimitiveMiscCaps |=  WINED3DPMISCCAPS_TSSARGTEMP;
@@ -676,5 +689,5 @@
     /* The caps below can be supported but aren't handled yet in utils.c 'd3dta_to_combiner_input', disable them until support is fixed */
 #if 0
-    if (GL_SUPPORT(NV_REGISTER_COMBINERS2))
+    if (gl_info->supported[NV_REGISTER_COMBINERS2])
     pCaps->PrimitiveMiscCaps |=  WINED3DPMISCCAPS_PERSTAGECONSTANT;
 #endif
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c	(revision 25949)
@@ -41,18 +41,21 @@
 #define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT)
 
-static HRESULT  WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID refiid, void **obj) {
-    IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
-    TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
-
-    if (IsEqualGUID(refiid, &IID_IUnknown)
-        || IsEqualGUID(refiid, &IID_IWineD3DPalette)) {
-        *obj = iface;
-        IWineD3DPalette_AddRef(iface);
+static HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID riid, void **object)
+{
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
+
+    if (IsEqualGUID(riid, &IID_IWineD3DPalette)
+            || IsEqualGUID(riid, &IID_IWineD3DBase)
+            || IsEqualGUID(riid, &IID_IUnknown))
+    {
+        IUnknown_AddRef(iface);
+        *object = iface;
         return S_OK;
     }
-    else {
-        *obj = NULL;
-        return E_NOINTERFACE;
-    }
+
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *object = NULL;
+    return E_NOINTERFACE;
 }
 
@@ -162,5 +165,6 @@
     /* If the palette is attached to the render target, update all render targets */
 
-    LIST_FOR_EACH_ENTRY(res, &This->wineD3DDevice->resources, IWineD3DResourceImpl, resource.resource_list_entry) {
+    LIST_FOR_EACH_ENTRY(res, &This->device->resources, IWineD3DResourceImpl, resource.resource_list_entry)
+    {
         if(IWineD3DResource_GetType((IWineD3DResource *) res) == WINED3DRTYPE_SURFACE) {
             IWineD3DSurfaceImpl *impl = (IWineD3DSurfaceImpl *) res;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c	(revision 25947)
+++ 	(revision )
@@ -1,456 +1,0 @@
-/*
- * shaders implementation
- *
- * Copyright 2002-2003 Jason Edmeades
- * Copyright 2002-2003 Raphael Junqueira
- * Copyright 2004 Christian Costa
- * Copyright 2005 Oliver Stieber
- * Copyright 2006 Ivan Gyurdiev
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
- * Copyright 2009 Henri Verbeet for CodeWeavers
- *
- * 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
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <stdio.h>
-
-#include "wined3d_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
-
-#define GLINFO_LOCATION ((IWineD3DDeviceImpl *) This->baseShader.device)->adapter->gl_info
-
-static HRESULT  WINAPI IWineD3DPixelShaderImpl_QueryInterface(IWineD3DPixelShader *iface, REFIID riid, LPVOID *ppobj) {
-    TRACE("iface %p, riid %s, ppobj %p\n", iface, debugstr_guid(riid), ppobj);
-
-    if (IsEqualGUID(riid, &IID_IWineD3DPixelShader)
-            || IsEqualGUID(riid, &IID_IWineD3DBaseShader)
-            || IsEqualGUID(riid, &IID_IWineD3DBase)
-            || IsEqualGUID(riid, &IID_IUnknown))
-    {
-        IUnknown_AddRef(iface);
-        *ppobj = iface;
-        return S_OK;
-    }
-
-    WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
-
-    *ppobj = NULL;
-    return E_NOINTERFACE;
-}
-
-static ULONG  WINAPI IWineD3DPixelShaderImpl_AddRef(IWineD3DPixelShader *iface) {
-    IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
-    ULONG refcount = InterlockedIncrement(&This->baseShader.ref);
-
-    TRACE("%p increasing refcount to %u\n", This, refcount);
-
-    return refcount;
-}
-
-static ULONG  WINAPI IWineD3DPixelShaderImpl_Release(IWineD3DPixelShader *iface) {
-    IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
-    ULONG refcount = InterlockedDecrement(&This->baseShader.ref);
-
-    TRACE("%p decreasing refcount to %u\n", This, refcount);
-
-    if (!refcount)
-    {
-        shader_cleanup((IWineD3DBaseShader *)iface);
-        This->baseShader.parent_ops->wined3d_object_destroyed(This->baseShader.parent);
-        HeapFree(GetProcessHeap(), 0, This);
-    }
-
-    return refcount;
-}
-
-/* *******************************************
-   IWineD3DPixelShader IWineD3DPixelShader parts follow
-   ******************************************* */
-
-static HRESULT  WINAPI IWineD3DPixelShaderImpl_GetParent(IWineD3DPixelShader *iface, IUnknown** parent){
-    IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
-
-    *parent = This->baseShader.parent;
-    IUnknown_AddRef(*parent);
-    TRACE("(%p) : returning %p\n", This, *parent);
-    return WINED3D_OK;
-}
-
-static HRESULT  WINAPI IWineD3DPixelShaderImpl_GetDevice(IWineD3DPixelShader* iface, IWineD3DDevice **pDevice){
-    IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
-    IWineD3DDevice_AddRef(This->baseShader.device);
-    *pDevice = This->baseShader.device;
-    TRACE("(%p) returning %p\n", This, *pDevice);
-    return WINED3D_OK;
-}
-
-
-static HRESULT  WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader* impl, VOID* pData, UINT* pSizeOfData) {
-  IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)impl;
-  TRACE("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
-
-  if (NULL == pData) {
-    *pSizeOfData = This->baseShader.functionLength;
-    return WINED3D_OK;
-  }
-  if (*pSizeOfData < This->baseShader.functionLength) {
-    /* MSDN claims (for d3d8 at least) that if *pSizeOfData is smaller
-     * than the required size we should write the required size and
-     * return D3DERR_MOREDATA. That's not actually true. */
-    return WINED3DERR_INVALIDCALL;
-  }
-
-  TRACE("(%p) : GetFunction copying to %p\n", This, pData);
-  memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
-
-  return WINED3D_OK;
-}
-
-static void pshader_set_limits(IWineD3DPixelShaderImpl *This)
-{
-    DWORD shader_version = WINED3D_SHADER_VERSION(This->baseShader.reg_maps.shader_version.major,
-            This->baseShader.reg_maps.shader_version.minor);
-
-    This->baseShader.limits.attributes = 0;
-    This->baseShader.limits.address = 0;
-    This->baseShader.limits.packed_output = 0;
-
-    switch (shader_version)
-    {
-        case WINED3D_SHADER_VERSION(1,0):
-        case WINED3D_SHADER_VERSION(1,1):
-        case WINED3D_SHADER_VERSION(1,2):
-        case WINED3D_SHADER_VERSION(1,3):
-            This->baseShader.limits.temporary = 2;
-            This->baseShader.limits.constant_float = 8;
-            This->baseShader.limits.constant_int = 0;
-            This->baseShader.limits.constant_bool = 0;
-            This->baseShader.limits.texcoord = 4;
-            This->baseShader.limits.sampler = 4;
-            This->baseShader.limits.packed_input = 0;
-            This->baseShader.limits.label = 0;
-            break;
-
-        case WINED3D_SHADER_VERSION(1,4):
-            This->baseShader.limits.temporary = 6;
-            This->baseShader.limits.constant_float = 8;
-            This->baseShader.limits.constant_int = 0;
-            This->baseShader.limits.constant_bool = 0;
-            This->baseShader.limits.texcoord = 6;
-            This->baseShader.limits.sampler = 6;
-            This->baseShader.limits.packed_input = 0;
-            This->baseShader.limits.label = 0;
-            break;
-
-        /* FIXME: temporaries must match D3DPSHADERCAPS2_0.NumTemps */
-        case WINED3D_SHADER_VERSION(2,0):
-            This->baseShader.limits.temporary = 32;
-            This->baseShader.limits.constant_float = 32;
-            This->baseShader.limits.constant_int = 16;
-            This->baseShader.limits.constant_bool = 16;
-            This->baseShader.limits.texcoord = 8;
-            This->baseShader.limits.sampler = 16;
-            This->baseShader.limits.packed_input = 0;
-            break;
-
-        case WINED3D_SHADER_VERSION(2,1):
-            This->baseShader.limits.temporary = 32;
-            This->baseShader.limits.constant_float = 32;
-            This->baseShader.limits.constant_int = 16;
-            This->baseShader.limits.constant_bool = 16;
-            This->baseShader.limits.texcoord = 8;
-            This->baseShader.limits.sampler = 16;
-            This->baseShader.limits.packed_input = 0;
-            This->baseShader.limits.label = 16;
-            break;
-
-        case WINED3D_SHADER_VERSION(4,0):
-            FIXME("Using 3.0 limits for 4.0 shader\n");
-            /* Fall through */
-
-        case WINED3D_SHADER_VERSION(3,0):
-            This->baseShader.limits.temporary = 32;
-            This->baseShader.limits.constant_float = 224;
-            This->baseShader.limits.constant_int = 16;
-            This->baseShader.limits.constant_bool = 16;
-            This->baseShader.limits.texcoord = 0;
-            This->baseShader.limits.sampler = 16;
-            This->baseShader.limits.packed_input = 12;
-            This->baseShader.limits.label = 16; /* FIXME: 2048 */
-            break;
-
-        default:
-            This->baseShader.limits.temporary = 32;
-            This->baseShader.limits.constant_float = 32;
-            This->baseShader.limits.constant_int = 16;
-            This->baseShader.limits.constant_bool = 16;
-            This->baseShader.limits.texcoord = 8;
-            This->baseShader.limits.sampler = 16;
-            This->baseShader.limits.packed_input = 0;
-            This->baseShader.limits.label = 0;
-            FIXME("Unrecognized pixel shader version %u.%u\n",
-                    This->baseShader.reg_maps.shader_version.major,
-                    This->baseShader.reg_maps.shader_version.minor);
-    }
-}
-
-static HRESULT pixelshader_set_function(IWineD3DPixelShaderImpl *shader,
-        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
-{
-    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)shader->baseShader.device;
-    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    unsigned int i, highest_reg_used = 0, num_regs_used = 0;
-    shader_reg_maps *reg_maps = &shader->baseShader.reg_maps;
-    const struct wined3d_shader_frontend *fe;
-    HRESULT hr;
-
-    TRACE("shader %p, byte_code %p, output_signature %p.\n", shader, byte_code, output_signature);
-
-    fe = shader_select_frontend(*byte_code);
-    if (!fe)
-    {
-        FIXME("Unable to find frontend for shader.\n");
-        return WINED3DERR_INVALIDCALL;
-    }
-    shader->baseShader.frontend = fe;
-    shader->baseShader.frontend_data = fe->shader_init(byte_code, output_signature);
-    if (!shader->baseShader.frontend_data)
-    {
-        FIXME("Failed to initialize frontend.\n");
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    /* First pass: trace shader */
-    if (TRACE_ON(d3d_shader)) shader_trace_init(fe, shader->baseShader.frontend_data, byte_code);
-
-    /* Initialize immediate constant lists */
-    list_init(&shader->baseShader.constantsF);
-    list_init(&shader->baseShader.constantsB);
-    list_init(&shader->baseShader.constantsI);
-
-    /* Second pass: figure out which registers are used, what the semantics are, etc.. */
-    hr = shader_get_registers_used((IWineD3DBaseShader *)shader, fe,
-            reg_maps, NULL, shader->input_signature, NULL,
-            byte_code, gl_info->max_pshader_constantsF);
-    if (FAILED(hr)) return hr;
-
-    pshader_set_limits(shader);
-
-    for (i = 0; i < MAX_REG_INPUT; ++i)
-    {
-        if (shader->input_reg_used[i])
-        {
-            ++num_regs_used;
-            highest_reg_used = i;
-        }
-    }
-
-    /* Don't do any register mapping magic if it is not needed, or if we can't
-     * achieve anything anyway */
-    if (highest_reg_used < (gl_info->max_glsl_varyings / 4)
-            || num_regs_used > (gl_info->max_glsl_varyings / 4))
-    {
-        if (num_regs_used > (gl_info->max_glsl_varyings / 4))
-        {
-            /* This happens with relative addressing. The input mapper function
-             * warns about this if the higher registers are declared too, so
-             * don't write a FIXME here */
-            WARN("More varying registers used than supported\n");
-        }
-
-        for (i = 0; i < MAX_REG_INPUT; ++i)
-        {
-            shader->input_reg_map[i] = i;
-        }
-
-        shader->declared_in_count = highest_reg_used + 1;
-    }
-    else
-    {
-        shader->declared_in_count = 0;
-        for (i = 0; i < MAX_REG_INPUT; ++i)
-        {
-            if (shader->input_reg_used[i]) shader->input_reg_map[i] = shader->declared_in_count++;
-            else shader->input_reg_map[i] = ~0U;
-        }
-    }
-
-    shader->baseShader.load_local_constsF = FALSE;
-
-    TRACE("(%p) : Copying byte code.\n", shader);
-
-    shader->baseShader.function = HeapAlloc(GetProcessHeap(), 0, shader->baseShader.functionLength);
-    if (!shader->baseShader.function) return E_OUTOFMEMORY;
-    memcpy(shader->baseShader.function, byte_code, shader->baseShader.functionLength);
-
-    return WINED3D_OK;
-}
-
-void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures)
-{
-    WINED3DSAMPLER_TEXTURE_TYPE *sampler_type = reg_maps->sampler_type;
-    unsigned int i;
-
-    if (reg_maps->shader_version.major != 1) return;
-
-    for (i = 0; i < max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS); ++i)
-    {
-        /* We don't sample from this sampler */
-        if (!sampler_type[i]) continue;
-
-        if (!textures[i])
-        {
-            ERR("No texture bound to sampler %u, using 2D\n", i);
-            sampler_type[i] = WINED3DSTT_2D;
-            continue;
-        }
-
-        switch (IWineD3DBaseTexture_GetTextureDimensions(textures[i]))
-        {
-            case GL_TEXTURE_RECTANGLE_ARB:
-            case GL_TEXTURE_2D:
-                /* We have to select between texture rectangles and 2D textures later because 2.0 and
-                 * 3.0 shaders only have WINED3DSTT_2D as well */
-                sampler_type[i] = WINED3DSTT_2D;
-                break;
-
-            case GL_TEXTURE_3D:
-                sampler_type[i] = WINED3DSTT_VOLUME;
-                break;
-
-            case GL_TEXTURE_CUBE_MAP_ARB:
-                sampler_type[i] = WINED3DSTT_CUBE;
-                break;
-
-            default:
-                FIXME("Unrecognized texture type %#x, using 2D\n",
-                        IWineD3DBaseTexture_GetTextureDimensions(textures[i]));
-                sampler_type[i] = WINED3DSTT_2D;
-        }
-    }
-}
-
-static const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
-{
-    /*** IUnknown methods ***/
-    IWineD3DPixelShaderImpl_QueryInterface,
-    IWineD3DPixelShaderImpl_AddRef,
-    IWineD3DPixelShaderImpl_Release,
-    /*** IWineD3DBase methods ***/
-    IWineD3DPixelShaderImpl_GetParent,
-    /*** IWineD3DBaseShader methods ***/
-    IWineD3DPixelShaderImpl_GetDevice,
-    IWineD3DPixelShaderImpl_GetFunction
-    /*** IWineD3DPixelShader methods ***/
-};
-
-void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args) {
-    UINT i;
-    IWineD3DBaseTextureImpl *tex;
-
-    memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set */
-    args->srgb_correction = stateblock->renderState[WINED3DRS_SRGBWRITEENABLE] ? 1 : 0;
-    args->np2_fixup = 0;
-
-    for(i = 0; i < MAX_FRAGMENT_SAMPLERS; i++) {
-        if (!shader->baseShader.reg_maps.sampler_type[i]) continue;
-        tex = (IWineD3DBaseTextureImpl *) stateblock->textures[i];
-        if(!tex) {
-            args->color_fixup[i] = COLOR_FIXUP_IDENTITY;
-            continue;
-        }
-        args->color_fixup[i] = tex->resource.format_desc->color_fixup;
-
-        /* Flag samplers that need NP2 texcoord fixup. */
-        if(!tex->baseTexture.pow2Matrix_identity) {
-            args->np2_fixup |= (1 << i);
-        }
-    }
-    if (shader->baseShader.reg_maps.shader_version.major >= 3)
-    {
-        if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed)
-        {
-            args->vp_mode = pretransformed;
-        }
-        else if (use_vs(stateblock))
-        {
-            args->vp_mode = vertexshader;
-        } else {
-            args->vp_mode = fixedfunction;
-        }
-        args->fog = FOG_OFF;
-    } else {
-        args->vp_mode = vertexshader;
-        if(stateblock->renderState[WINED3DRS_FOGENABLE]) {
-            switch(stateblock->renderState[WINED3DRS_FOGTABLEMODE]) {
-                case WINED3DFOG_NONE:
-                    if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed
-                            || use_vs(stateblock))
-                    {
-                        args->fog = FOG_LINEAR;
-                        break;
-                    }
-                    switch(stateblock->renderState[WINED3DRS_FOGVERTEXMODE]) {
-                        case WINED3DFOG_NONE: /* Drop through */
-                        case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
-                        case WINED3DFOG_EXP:    args->fog = FOG_EXP;    break;
-                        case WINED3DFOG_EXP2:   args->fog = FOG_EXP2;   break;
-                    }
-                    break;
-
-                case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
-                case WINED3DFOG_EXP:    args->fog = FOG_EXP;    break;
-                case WINED3DFOG_EXP2:   args->fog = FOG_EXP2;   break;
-            }
-        } else {
-            args->fog = FOG_OFF;
-        }
-    }
-}
-
-HRESULT pixelshader_init(IWineD3DPixelShaderImpl *shader, IWineD3DDeviceImpl *device,
-        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
-        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
-{
-    HRESULT hr;
-
-    if (!byte_code) return WINED3DERR_INVALIDCALL;
-
-    shader->lpVtbl = &IWineD3DPixelShader_Vtbl;
-    shader_init(&shader->baseShader, device, parent, parent_ops);
-
-    hr = pixelshader_set_function(shader, byte_code, output_signature);
-    if (FAILED(hr))
-    {
-        WARN("Failed to set function, hr %#x.\n", hr);
-        shader_cleanup((IWineD3DBaseShader *)shader);
-        return hr;
-    }
-
-    return WINED3D_OK;
-}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 25949)
@@ -4,4 +4,5 @@
  * Copyright 2005 Oliver Stieber
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers.
  *
  * This library is free software; you can redistribute it and/or
@@ -39,5 +40,5 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
-#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION This->device->adapter->gl_info
 
 /* *******************************************
@@ -97,21 +98,15 @@
    IWineD3DQuery IWineD3DQuery parts follow
    ******************************************* */
-static HRESULT  WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
-    IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
-
-    *parent= (IUnknown*) parent;
+static HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown **parent)
+{
+    TRACE("iface %p, parent %p.\n", iface, parent);
+
+    *parent = (IUnknown *)parent;
     IUnknown_AddRef(*parent);
-    TRACE("(%p) : returning %p\n", This, *parent);
+
+    TRACE("Returning %p.\n", *parent);
+
     return WINED3D_OK;
 }
-
-static HRESULT  WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
-    IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
-    IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
-    *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
-    TRACE("(%p) returning %p\n", This, *pDevice);
-    return WINED3D_OK;
-}
-
 
 static HRESULT  WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
@@ -280,4 +275,7 @@
     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
     struct wined3d_occlusion_query *query = This->extendedData;
+    IWineD3DDeviceImpl *device = This->device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    struct wined3d_context *context;
     DWORD* data = pData;
     GLuint available;
@@ -304,5 +302,5 @@
     }
 
-    if (!GL_SUPPORT(ARB_OCCLUSION_QUERY))
+    if (!gl_info->supported[ARB_OCCLUSION_QUERY])
     {
         WARN("(%p) : Occlusion queries not supported. Returning 1.\n", This);
@@ -318,5 +316,5 @@
     }
 
-    ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
 
     ENTER_GL();
@@ -344,4 +342,6 @@
     LEAVE_GL();
 
+    context_release(context);
+
     return res;
 }
@@ -350,5 +350,6 @@
     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
     struct wined3d_event_query *query = This->extendedData;
-    BOOL* data = pData;
+    struct wined3d_context *context;
+    BOOL *data = pData;
 
     TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
@@ -358,5 +359,5 @@
     if (!query->context)
     {
-        ERR("Query not started, returning TRUE.\n");
+        TRACE("Query not started, returning TRUE.\n");
         *data = TRUE;
 
@@ -373,14 +374,14 @@
     }
 
-    ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
 
     ENTER_GL();
 
-    if (GL_SUPPORT(APPLE_FENCE))
+    if (context->gl_info->supported[APPLE_FENCE])
     {
         *data = GL_EXTCALL(glTestFenceAPPLE(query->id));
         checkGLcall("glTestFenceAPPLE");
     }
-    else if (GL_SUPPORT(NV_FENCE))
+    else if (context->gl_info->supported[NV_FENCE])
     {
         *data = GL_EXTCALL(glTestFenceNV(query->id));
@@ -394,4 +395,6 @@
 
     LEAVE_GL();
+
+    context_release(context);
 
     return S_OK;
@@ -481,15 +484,15 @@
             {
                 context_free_event_query(query);
-                context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
+                context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
                 context_alloc_event_query(context, query);
             }
             else
             {
-                ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
+                context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
             }
         }
         else
         {
-            context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
+            context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
             context_alloc_event_query(context, query);
         }
@@ -497,10 +500,10 @@
         ENTER_GL();
 
-        if (GL_SUPPORT(APPLE_FENCE))
+        if (context->gl_info->supported[APPLE_FENCE])
         {
             GL_EXTCALL(glSetFenceAPPLE(query->id));
             checkGLcall("glSetFenceAPPLE");
         }
-        else if (GL_SUPPORT(NV_FENCE))
+        else if (context->gl_info->supported[NV_FENCE])
         {
             GL_EXTCALL(glSetFenceNV(query->id, GL_ALL_COMPLETED_NV));
@@ -509,4 +512,6 @@
 
         LEAVE_GL();
+
+        context_release(context);
     }
     else if(dwIssueFlags & WINED3DISSUE_BEGIN)
@@ -527,6 +532,8 @@
 static HRESULT  WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface,  DWORD dwIssueFlags) {
     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
-
-    if (GL_SUPPORT(ARB_OCCLUSION_QUERY))
+    IWineD3DDeviceImpl *device = This->device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+
+    if (gl_info->supported[ARB_OCCLUSION_QUERY])
     {
         struct wined3d_occlusion_query *query = This->extendedData;
@@ -543,10 +550,10 @@
 
                     context_free_occlusion_query(query);
-                    context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
+                    context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
                     context_alloc_occlusion_query(context, query);
                 }
                 else
                 {
-                    ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
+                    context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
 
                     ENTER_GL();
@@ -559,5 +566,5 @@
             {
                 if (query->context) context_free_occlusion_query(query);
-                context = ActivateContext(This->wineD3DDevice, NULL, CTXUSAGE_RESOURCELOAD);
+                context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
                 context_alloc_occlusion_query(context, query);
             }
@@ -567,4 +574,6 @@
             checkGLcall("glBeginQuery()");
             LEAVE_GL();
+
+            context_release(context);
         }
         if (dwIssueFlags & WINED3DISSUE_END) {
@@ -581,5 +590,5 @@
                 else
                 {
-                    ActivateContext(This->wineD3DDevice, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
+                    context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
 
                     ENTER_GL();
@@ -587,4 +596,6 @@
                     checkGLcall("glEndQuery()");
                     LEAVE_GL();
+
+                    context_release(context);
                 }
             }
@@ -632,5 +643,4 @@
      /*** IWineD3Dquery methods ***/
     IWineD3DQueryImpl_GetParent,
-    IWineD3DQueryImpl_GetDevice,
     IWineD3DQueryImpl_GetData,
     IWineD3DQueryImpl_GetDataSize,
@@ -647,5 +657,4 @@
     /*** IWineD3Dquery methods ***/
     IWineD3DQueryImpl_GetParent,
-    IWineD3DQueryImpl_GetDevice,
     IWineD3DEventQueryImpl_GetData,
     IWineD3DEventQueryImpl_GetDataSize,
@@ -662,5 +671,4 @@
     /*** IWineD3Dquery methods ***/
     IWineD3DQueryImpl_GetParent,
-    IWineD3DQueryImpl_GetDevice,
     IWineD3DOcclusionQueryImpl_GetData,
     IWineD3DOcclusionQueryImpl_GetDataSize,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 25949)
@@ -43,5 +43,5 @@
     struct IWineD3DResourceClass *resource = &((IWineD3DResourceImpl *)iface)->resource;
 
-    resource->wineD3DDevice = device;
+    resource->device = device;
     resource->parent = parent;
     resource->resourceType = resource_type;
@@ -97,5 +97,5 @@
     if (This->resource.pool == WINED3DPOOL_DEFAULT) {
         TRACE("Decrementing device memory pool by %u\n", This->resource.size);
-        WineD3DAdapterChangeGLRam(This->resource.wineD3DDevice, -This->resource.size);
+        WineD3DAdapterChangeGLRam(This->resource.device, -This->resource.size);
     }
 
@@ -112,14 +112,5 @@
     This->resource.heapMemory = 0;
 
-    if (This->resource.wineD3DDevice) device_resource_released(This->resource.wineD3DDevice, iface);
-}
-
-HRESULT resource_get_device(IWineD3DResource *iface, IWineD3DDevice** ppDevice)
-{
-    IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
-    TRACE("(%p) : returning %p\n", This, This->resource.wineD3DDevice);
-    *ppDevice = (IWineD3DDevice *) This->resource.wineD3DDevice;
-    IWineD3DDevice_AddRef(*ppDevice);
-    return WINED3D_OK;
+    if (This->resource.device) device_resource_released(This->resource.device, iface);
 }
 
@@ -198,5 +189,6 @@
     if (data->flags & WINED3DSPD_IUNKNOWN) {
         *(LPUNKNOWN *)pData = data->ptr.object;
-        if(((IWineD3DImpl *) This->resource.wineD3DDevice->wineD3D)->dxVersion != 7) {
+        if (((IWineD3DImpl *)This->resource.device->wined3d)->dxVersion != 7)
+        {
             /* D3D8 and D3D9 addref the private data, DDraw does not. This can't be handled in
              * ddraw because it doesn't know if the pointer returned is an IUnknown * or just a
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader.c	(revision 25949)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader.c	(revision 25949)
@@ -0,0 +1,863 @@
+/*
+ * Copyright 2002-2003 Jason Edmeades
+ * Copyright 2002-2003 Raphael Junqueira
+ * Copyright 2004 Christian Costa
+ * Copyright 2005 Oliver Stieber
+ * Copyright 2006 Ivan Gyurdiev
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
+ *
+ * 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
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+#include "config.h"
+
+#include <math.h>
+#include <stdio.h>
+
+#include "wined3d_private.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
+
+static void shader_get_parent(IWineD3DBaseShaderImpl *shader, IUnknown **parent)
+{
+    *parent = shader->baseShader.parent;
+    IUnknown_AddRef(*parent);
+    TRACE("shader %p, returning %p.\n", shader, *parent);
+}
+
+static HRESULT shader_get_function(IWineD3DBaseShaderImpl *shader, void *data, UINT *data_size)
+{
+    if (!data)
+    {
+        *data_size = shader->baseShader.functionLength;
+        return WINED3D_OK;
+    }
+
+    if (*data_size < shader->baseShader.functionLength)
+    {
+        /* MSDN claims (for d3d8 at least) that if *pSizeOfData is smaller
+         * than the required size we should write the required size and
+         * return D3DERR_MOREDATA. That's not actually true. */
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    memcpy(data, shader->baseShader.function, shader->baseShader.functionLength);
+
+    return WINED3D_OK;
+}
+
+static HRESULT shader_set_function(IWineD3DBaseShaderImpl *shader, const DWORD *byte_code,
+        const struct wined3d_shader_signature *output_signature, DWORD float_const_count)
+{
+    struct shader_reg_maps *reg_maps = &shader->baseShader.reg_maps;
+    const struct wined3d_shader_frontend *fe;
+    HRESULT hr;
+
+    TRACE("shader %p, byte_code %p, output_signature %p, float_const_count %u.\n",
+            shader, byte_code, output_signature, float_const_count);
+
+    fe = shader_select_frontend(*byte_code);
+    if (!fe)
+    {
+        FIXME("Unable to find frontend for shader.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+    shader->baseShader.frontend = fe;
+    shader->baseShader.frontend_data = fe->shader_init(byte_code, output_signature);
+    if (!shader->baseShader.frontend_data)
+    {
+        FIXME("Failed to initialize frontend.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    /* First pass: trace shader. */
+    if (TRACE_ON(d3d_shader)) shader_trace_init(fe, shader->baseShader.frontend_data, byte_code);
+
+    /* Initialize immediate constant lists. */
+    list_init(&shader->baseShader.constantsF);
+    list_init(&shader->baseShader.constantsB);
+    list_init(&shader->baseShader.constantsI);
+
+    /* Second pass: figure out which registers are used, what the semantics are, etc. */
+    hr = shader_get_registers_used((IWineD3DBaseShader *)shader, fe,
+            reg_maps, shader->baseShader.input_signature, shader->baseShader.output_signature,
+            byte_code, float_const_count);
+    if (FAILED(hr)) return hr;
+
+    shader->baseShader.function = HeapAlloc(GetProcessHeap(), 0, shader->baseShader.functionLength);
+    if (!shader->baseShader.function) return E_OUTOFMEMORY;
+    memcpy(shader->baseShader.function, byte_code, shader->baseShader.functionLength);
+
+    return WINED3D_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE vertexshader_QueryInterface(IWineD3DVertexShader *iface, REFIID riid, void **object)
+{
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
+
+    if (IsEqualGUID(riid, &IID_IWineD3DVertexShader)
+            || IsEqualGUID(riid, &IID_IWineD3DBaseShader)
+            || IsEqualGUID(riid, &IID_IWineD3DBase)
+            || IsEqualGUID(riid, &IID_IUnknown))
+    {
+        IUnknown_AddRef(iface);
+        *object = iface;
+        return S_OK;
+    }
+
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *object = NULL;
+    return E_NOINTERFACE;
+}
+
+static ULONG STDMETHODCALLTYPE vertexshader_AddRef(IWineD3DVertexShader *iface)
+{
+    IWineD3DVertexShaderImpl *shader = (IWineD3DVertexShaderImpl *)iface;
+    ULONG refcount = InterlockedIncrement(&shader->baseShader.ref);
+
+    TRACE("%p increasing refcount to %u.\n", shader, refcount);
+
+    return refcount;
+}
+
+static ULONG STDMETHODCALLTYPE vertexshader_Release(IWineD3DVertexShader *iface)
+{
+    IWineD3DVertexShaderImpl *shader = (IWineD3DVertexShaderImpl *)iface;
+    ULONG refcount = InterlockedDecrement(&shader->baseShader.ref);
+
+    TRACE("%p decreasing refcount to %u.\n", shader, refcount);
+
+    if (!refcount)
+    {
+        shader_cleanup((IWineD3DBaseShader *)iface);
+        shader->baseShader.parent_ops->wined3d_object_destroyed(shader->baseShader.parent);
+        HeapFree(GetProcessHeap(), 0, shader);
+    }
+
+    return refcount;
+}
+
+static HRESULT STDMETHODCALLTYPE vertexshader_GetParent(IWineD3DVertexShader *iface, IUnknown **parent)
+{
+    TRACE("iface %p, parent %p.\n", iface, parent);
+
+    shader_get_parent((IWineD3DBaseShaderImpl *)iface, parent);
+
+    return WINED3D_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE vertexshader_GetFunction(IWineD3DVertexShader *iface, void *data, UINT *data_size)
+{
+    TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
+
+    return shader_get_function((IWineD3DBaseShaderImpl *)iface, data, data_size);
+}
+
+/* Set local constants for d3d8 shaders. */
+static HRESULT STDMETHODCALLTYPE vertexshader_SetLocalConstantsF(IWineD3DVertexShader *iface,
+        UINT start_idx, const float *src_data, UINT count)
+{
+    IWineD3DVertexShaderImpl *shader =(IWineD3DVertexShaderImpl *)iface;
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)shader->baseShader.device;
+    UINT i, end_idx;
+
+    TRACE("iface %p, start_idx %u, src_data %p, count %u.\n", iface, start_idx, src_data, count);
+
+    end_idx = start_idx + count;
+    if (end_idx > device->d3d_vshader_constantF)
+    {
+        WARN("end_idx %u > float constants limit %u.\n", end_idx, device->d3d_vshader_constantF);
+        end_idx = device->d3d_vshader_constantF;
+    }
+
+    for (i = start_idx; i < end_idx; ++i)
+    {
+        local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
+        if (!lconst) return E_OUTOFMEMORY;
+
+        lconst->idx = i;
+        memcpy(lconst->value, src_data + (i - start_idx) * 4 /* 4 components */, 4 * sizeof(float));
+        list_add_head(&shader->baseShader.constantsF, &lconst->entry);
+    }
+
+    return WINED3D_OK;
+}
+
+static const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl =
+{
+    /* IUnknown methods */
+    vertexshader_QueryInterface,
+    vertexshader_AddRef,
+    vertexshader_Release,
+    /* IWineD3DBase methods */
+    vertexshader_GetParent,
+    /* IWineD3DBaseShader methods */
+    vertexshader_GetFunction,
+    /* IWineD3DVertexShader methods */
+    vertexshader_SetLocalConstantsF,
+};
+
+void find_vs_compile_args(IWineD3DVertexShaderImpl *shader,
+        IWineD3DStateBlockImpl *stateblock, struct vs_compile_args *args)
+{
+    args->fog_src = stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE ? VS_FOG_COORD : VS_FOG_Z;
+    args->clip_enabled = stateblock->renderState[WINED3DRS_CLIPPING]
+            && stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
+    args->swizzle_map = ((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.swizzle_map;
+}
+
+static BOOL match_usage(BYTE usage1, BYTE usage_idx1, BYTE usage2, BYTE usage_idx2)
+{
+    if (usage_idx1 != usage_idx2) return FALSE;
+    if (usage1 == usage2) return TRUE;
+    if (usage1 == WINED3DDECLUSAGE_POSITION && usage2 == WINED3DDECLUSAGE_POSITIONT) return TRUE;
+    if (usage2 == WINED3DDECLUSAGE_POSITION && usage1 == WINED3DDECLUSAGE_POSITIONT) return TRUE;
+
+    return FALSE;
+}
+
+BOOL vshader_get_input(IWineD3DVertexShader *iface, BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum)
+{
+    IWineD3DVertexShaderImpl *shader = (IWineD3DVertexShaderImpl *)iface;
+    WORD map = shader->baseShader.reg_maps.input_registers;
+    unsigned int i;
+
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (!(map & 1)) continue;
+
+        if (match_usage(shader->attributes[i].usage,
+                shader->attributes[i].usage_idx, usage_req, usage_idx_req))
+        {
+            *regnum = i;
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
+static void vertexshader_set_limits(IWineD3DVertexShaderImpl *shader)
+{
+    DWORD shader_version = WINED3D_SHADER_VERSION(shader->baseShader.reg_maps.shader_version.major,
+            shader->baseShader.reg_maps.shader_version.minor);
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)shader->baseShader.device;
+
+    shader->baseShader.limits.texcoord = 0;
+    shader->baseShader.limits.attributes = 16;
+    shader->baseShader.limits.packed_input = 0;
+
+    switch (shader_version)
+    {
+        case WINED3D_SHADER_VERSION(1, 0):
+        case WINED3D_SHADER_VERSION(1, 1):
+            shader->baseShader.limits.temporary = 12;
+            shader->baseShader.limits.constant_bool = 0;
+            shader->baseShader.limits.constant_int = 0;
+            shader->baseShader.limits.address = 1;
+            shader->baseShader.limits.packed_output = 0;
+            shader->baseShader.limits.sampler = 0;
+            shader->baseShader.limits.label = 0;
+            /* TODO: vs_1_1 has a minimum of 96 constants. What happens when
+             * a vs_1_1 shader is used on a vs_3_0 capable card that has 256
+             * constants? */
+            shader->baseShader.limits.constant_float = min(256, device->d3d_vshader_constantF);
+            break;
+
+        case WINED3D_SHADER_VERSION(2, 0):
+        case WINED3D_SHADER_VERSION(2, 1):
+            shader->baseShader.limits.temporary = 12;
+            shader->baseShader.limits.constant_bool = 16;
+            shader->baseShader.limits.constant_int = 16;
+            shader->baseShader.limits.address = 1;
+            shader->baseShader.limits.packed_output = 0;
+            shader->baseShader.limits.sampler = 0;
+            shader->baseShader.limits.label = 16;
+            shader->baseShader.limits.constant_float = min(256, device->d3d_vshader_constantF);
+            break;
+
+        case WINED3D_SHADER_VERSION(4, 0):
+            FIXME("Using 3.0 limits for 4.0 shader.\n");
+            /* Fall through. */
+
+        case WINED3D_SHADER_VERSION(3, 0):
+            shader->baseShader.limits.temporary = 32;
+            shader->baseShader.limits.constant_bool = 32;
+            shader->baseShader.limits.constant_int = 32;
+            shader->baseShader.limits.address = 1;
+            shader->baseShader.limits.packed_output = 12;
+            shader->baseShader.limits.sampler = 4;
+            shader->baseShader.limits.label = 16; /* FIXME: 2048 */
+            /* DX10 cards on Windows advertise a d3d9 constant limit of 256
+             * even though they are capable of supporting much more (GL
+             * drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
+             * wined3d-advertised maximum. Clamp the constant limit for <= 3.0
+             * shaders to 256. */
+            shader->baseShader.limits.constant_float = min(256, device->d3d_vshader_constantF);
+            break;
+
+        default:
+            shader->baseShader.limits.temporary = 12;
+            shader->baseShader.limits.constant_bool = 16;
+            shader->baseShader.limits.constant_int = 16;
+            shader->baseShader.limits.address = 1;
+            shader->baseShader.limits.packed_output = 0;
+            shader->baseShader.limits.sampler = 0;
+            shader->baseShader.limits.label = 16;
+            shader->baseShader.limits.constant_float = min(256, device->d3d_vshader_constantF);
+            FIXME("Unrecognized vertex shader version \"%u.%u\".\n",
+                    shader->baseShader.reg_maps.shader_version.major,
+                    shader->baseShader.reg_maps.shader_version.minor);
+    }
+}
+
+HRESULT vertexshader_init(IWineD3DVertexShaderImpl *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    struct shader_reg_maps *reg_maps = &shader->baseShader.reg_maps;
+    unsigned int i;
+    HRESULT hr;
+    WORD map;
+
+    if (!byte_code) return WINED3DERR_INVALIDCALL;
+
+    shader->lpVtbl = &IWineD3DVertexShader_Vtbl;
+    shader_init(&shader->baseShader, device, parent, parent_ops);
+
+    hr = shader_set_function((IWineD3DBaseShaderImpl *)shader, byte_code,
+            output_signature, device->d3d_vshader_constantF);
+    if (FAILED(hr))
+    {
+        WARN("Failed to set function, hr %#x.\n", hr);
+        shader_cleanup((IWineD3DBaseShader *)shader);
+        return hr;
+    }
+
+    map = shader->baseShader.reg_maps.input_registers;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (!(map & 1) || !shader->baseShader.input_signature[i].semantic_name) continue;
+
+        shader->attributes[i].usage =
+                shader_usage_from_semantic_name(shader->baseShader.input_signature[i].semantic_name);
+        shader->attributes[i].usage_idx = shader->baseShader.input_signature[i].semantic_idx;
+    }
+
+    if (output_signature)
+    {
+        for (i = 0; i < output_signature->element_count; ++i)
+        {
+            struct wined3d_shader_signature_element *e = &output_signature->elements[i];
+            reg_maps->output_registers |= 1 << e->register_idx;
+            shader->baseShader.output_signature[e->register_idx] = *e;
+        }
+    }
+
+    vertexshader_set_limits(shader);
+
+    if (device->vs_selected_mode == SHADER_ARB
+            && (gl_info->quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT)
+            && shader->min_rel_offset <= shader->max_rel_offset)
+    {
+        if (shader->max_rel_offset - shader->min_rel_offset > 127)
+        {
+            FIXME("The difference between the minimum and maximum relative offset is > 127.\n");
+            FIXME("Which this OpenGL implementation does not support. Try using GLSL.\n");
+            FIXME("Min: %d, Max: %d.\n", shader->min_rel_offset, shader->max_rel_offset);
+        }
+        else if (shader->max_rel_offset - shader->min_rel_offset > 63)
+        {
+            shader->rel_offset = shader->min_rel_offset + 63;
+        }
+        else if (shader->max_rel_offset > 63)
+        {
+            shader->rel_offset = shader->min_rel_offset;
+        }
+        else
+        {
+            shader->rel_offset = 0;
+        }
+    }
+
+    shader->baseShader.load_local_constsF = shader->baseShader.reg_maps.usesrelconstF
+            && !list_empty(&shader->baseShader.constantsF);
+
+    return WINED3D_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE geometryshader_QueryInterface(IWineD3DGeometryShader *iface,
+        REFIID riid, void **object)
+{
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
+
+    if (IsEqualGUID(riid, &IID_IWineD3DGeometryShader)
+            || IsEqualGUID(riid, &IID_IWineD3DBaseShader)
+            || IsEqualGUID(riid, &IID_IWineD3DBase)
+            || IsEqualGUID(riid, &IID_IUnknown))
+    {
+        IUnknown_AddRef(iface);
+        *object = iface;
+        return S_OK;
+    }
+
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *object = NULL;
+    return E_NOINTERFACE;
+}
+
+static ULONG STDMETHODCALLTYPE geometryshader_AddRef(IWineD3DGeometryShader *iface)
+{
+    struct wined3d_geometryshader *shader = (struct wined3d_geometryshader *)iface;
+    ULONG refcount = InterlockedIncrement(&shader->base_shader.ref);
+
+    TRACE("%p increasing refcount to %u.\n", shader, refcount);
+
+    return refcount;
+}
+
+static ULONG STDMETHODCALLTYPE geometryshader_Release(IWineD3DGeometryShader *iface)
+{
+    struct wined3d_geometryshader *shader = (struct wined3d_geometryshader *)iface;
+    ULONG refcount = InterlockedDecrement(&shader->base_shader.ref);
+
+    TRACE("%p decreasing refcount to %u.\n", shader, refcount);
+
+    if (!refcount)
+    {
+        shader_cleanup((IWineD3DBaseShader *)iface);
+        shader->base_shader.parent_ops->wined3d_object_destroyed(shader->base_shader.parent);
+        HeapFree(GetProcessHeap(), 0, shader);
+    }
+
+    return refcount;
+}
+
+static HRESULT STDMETHODCALLTYPE geometryshader_GetParent(IWineD3DGeometryShader *iface, IUnknown **parent)
+{
+    TRACE("iface %p, parent %p.\n", iface, parent);
+
+    shader_get_parent((IWineD3DBaseShaderImpl *)iface, parent);
+
+    return WINED3D_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE geometryshader_GetFunction(IWineD3DGeometryShader *iface, void *data, UINT *data_size)
+{
+    TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
+
+    return shader_get_function((IWineD3DBaseShaderImpl *)iface, data, data_size);
+}
+
+static const IWineD3DGeometryShaderVtbl wined3d_geometryshader_vtbl =
+{
+    /* IUnknown methods */
+    geometryshader_QueryInterface,
+    geometryshader_AddRef,
+    geometryshader_Release,
+    /* IWineD3DBase methods */
+    geometryshader_GetParent,
+    /* IWineD3DBaseShader methods */
+    geometryshader_GetFunction,
+};
+
+HRESULT geometryshader_init(struct wined3d_geometryshader *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    HRESULT hr;
+
+    shader->vtbl = &wined3d_geometryshader_vtbl;
+    shader_init(&shader->base_shader, device, parent, parent_ops);
+
+    hr = shader_set_function((IWineD3DBaseShaderImpl *)shader, byte_code, output_signature, 0);
+    if (FAILED(hr))
+    {
+        WARN("Failed to set function, hr %#x.\n", hr);
+        shader_cleanup((IWineD3DBaseShader *)shader);
+        return hr;
+    }
+
+    shader->base_shader.load_local_constsF = FALSE;
+
+    return WINED3D_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE pixelshader_QueryInterface(IWineD3DPixelShader *iface, REFIID riid, void **object)
+{
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
+
+    if (IsEqualGUID(riid, &IID_IWineD3DPixelShader)
+            || IsEqualGUID(riid, &IID_IWineD3DBaseShader)
+            || IsEqualGUID(riid, &IID_IWineD3DBase)
+            || IsEqualGUID(riid, &IID_IUnknown))
+    {
+        IUnknown_AddRef(iface);
+        *object = iface;
+        return S_OK;
+    }
+
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *object = NULL;
+    return E_NOINTERFACE;
+}
+
+static ULONG STDMETHODCALLTYPE pixelshader_AddRef(IWineD3DPixelShader *iface)
+{
+    IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)iface;
+    ULONG refcount = InterlockedIncrement(&shader->baseShader.ref);
+
+    TRACE("%p increasing refcount to %u.\n", shader, refcount);
+
+    return refcount;
+}
+
+static ULONG STDMETHODCALLTYPE pixelshader_Release(IWineD3DPixelShader *iface)
+{
+    IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)iface;
+    ULONG refcount = InterlockedDecrement(&shader->baseShader.ref);
+
+    TRACE("%p decreasing refcount to %u.\n", shader, refcount);
+
+    if (!refcount)
+    {
+        shader_cleanup((IWineD3DBaseShader *)iface);
+        shader->baseShader.parent_ops->wined3d_object_destroyed(shader->baseShader.parent);
+        HeapFree(GetProcessHeap(), 0, shader);
+    }
+
+    return refcount;
+}
+
+static HRESULT STDMETHODCALLTYPE pixelshader_GetParent(IWineD3DPixelShader *iface, IUnknown **parent)
+{
+    TRACE("iface %p, parent %p.\n", iface, parent);
+
+    shader_get_parent((IWineD3DBaseShaderImpl *)iface, parent);
+
+    return WINED3D_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE pixelshader_GetFunction(IWineD3DPixelShader *iface, void *data, UINT *data_size)
+{
+    TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
+
+    return shader_get_function((IWineD3DBaseShaderImpl *)iface, data, data_size);
+}
+
+static const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
+{
+    /* IUnknown methods */
+    pixelshader_QueryInterface,
+    pixelshader_AddRef,
+    pixelshader_Release,
+    /* IWineD3DBase methods */
+    pixelshader_GetParent,
+    /* IWineD3DBaseShader methods */
+    pixelshader_GetFunction
+};
+
+void find_ps_compile_args(IWineD3DPixelShaderImpl *shader,
+        IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args)
+{
+    IWineD3DBaseTextureImpl *texture;
+    UINT i;
+
+    memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set. */
+    args->srgb_correction = stateblock->renderState[WINED3DRS_SRGBWRITEENABLE] ? 1 : 0;
+    args->np2_fixup = 0;
+
+    for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
+    {
+        if (!shader->baseShader.reg_maps.sampler_type[i]) continue;
+        texture = (IWineD3DBaseTextureImpl *)stateblock->textures[i];
+        if (!texture)
+        {
+            args->color_fixup[i] = COLOR_FIXUP_IDENTITY;
+            continue;
+        }
+        args->color_fixup[i] = texture->resource.format_desc->color_fixup;
+
+        /* Flag samplers that need NP2 texcoord fixup. */
+        if (!texture->baseTexture.pow2Matrix_identity)
+        {
+            args->np2_fixup |= (1 << i);
+        }
+    }
+    if (shader->baseShader.reg_maps.shader_version.major >= 3)
+    {
+        if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed)
+        {
+            args->vp_mode = pretransformed;
+        }
+        else if (use_vs(stateblock))
+        {
+            args->vp_mode = vertexshader;
+        }
+        else
+        {
+            args->vp_mode = fixedfunction;
+        }
+        args->fog = FOG_OFF;
+    }
+    else
+    {
+        args->vp_mode = vertexshader;
+        if (stateblock->renderState[WINED3DRS_FOGENABLE])
+        {
+            switch (stateblock->renderState[WINED3DRS_FOGTABLEMODE])
+            {
+                case WINED3DFOG_NONE:
+                    if (((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.position_transformed
+                            || use_vs(stateblock))
+                    {
+                        args->fog = FOG_LINEAR;
+                        break;
+                    }
+
+                    switch (stateblock->renderState[WINED3DRS_FOGVERTEXMODE])
+                    {
+                        case WINED3DFOG_NONE: /* Fall through. */
+                        case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
+                        case WINED3DFOG_EXP:    args->fog = FOG_EXP;    break;
+                        case WINED3DFOG_EXP2:   args->fog = FOG_EXP2;   break;
+                    }
+                    break;
+
+                case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break;
+                case WINED3DFOG_EXP:    args->fog = FOG_EXP;    break;
+                case WINED3DFOG_EXP2:   args->fog = FOG_EXP2;   break;
+            }
+        }
+        else
+        {
+            args->fog = FOG_OFF;
+        }
+    }
+}
+
+static void pixelshader_set_limits(IWineD3DPixelShaderImpl *shader)
+{
+    DWORD shader_version = WINED3D_SHADER_VERSION(shader->baseShader.reg_maps.shader_version.major,
+            shader->baseShader.reg_maps.shader_version.minor);
+
+    shader->baseShader.limits.attributes = 0;
+    shader->baseShader.limits.address = 0;
+    shader->baseShader.limits.packed_output = 0;
+
+    switch (shader_version)
+    {
+        case WINED3D_SHADER_VERSION(1, 0):
+        case WINED3D_SHADER_VERSION(1, 1):
+        case WINED3D_SHADER_VERSION(1, 2):
+        case WINED3D_SHADER_VERSION(1, 3):
+            shader->baseShader.limits.temporary = 2;
+            shader->baseShader.limits.constant_float = 8;
+            shader->baseShader.limits.constant_int = 0;
+            shader->baseShader.limits.constant_bool = 0;
+            shader->baseShader.limits.texcoord = 4;
+            shader->baseShader.limits.sampler = 4;
+            shader->baseShader.limits.packed_input = 0;
+            shader->baseShader.limits.label = 0;
+            break;
+
+        case WINED3D_SHADER_VERSION(1, 4):
+            shader->baseShader.limits.temporary = 6;
+            shader->baseShader.limits.constant_float = 8;
+            shader->baseShader.limits.constant_int = 0;
+            shader->baseShader.limits.constant_bool = 0;
+            shader->baseShader.limits.texcoord = 6;
+            shader->baseShader.limits.sampler = 6;
+            shader->baseShader.limits.packed_input = 0;
+            shader->baseShader.limits.label = 0;
+            break;
+
+        /* FIXME: Temporaries must match D3DPSHADERCAPS2_0.NumTemps. */
+        case WINED3D_SHADER_VERSION(2, 0):
+            shader->baseShader.limits.temporary = 32;
+            shader->baseShader.limits.constant_float = 32;
+            shader->baseShader.limits.constant_int = 16;
+            shader->baseShader.limits.constant_bool = 16;
+            shader->baseShader.limits.texcoord = 8;
+            shader->baseShader.limits.sampler = 16;
+            shader->baseShader.limits.packed_input = 0;
+            break;
+
+        case WINED3D_SHADER_VERSION(2, 1):
+            shader->baseShader.limits.temporary = 32;
+            shader->baseShader.limits.constant_float = 32;
+            shader->baseShader.limits.constant_int = 16;
+            shader->baseShader.limits.constant_bool = 16;
+            shader->baseShader.limits.texcoord = 8;
+            shader->baseShader.limits.sampler = 16;
+            shader->baseShader.limits.packed_input = 0;
+            shader->baseShader.limits.label = 16;
+            break;
+
+        case WINED3D_SHADER_VERSION(4, 0):
+            FIXME("Using 3.0 limits for 4.0 shader.\n");
+            /* Fall through. */
+
+        case WINED3D_SHADER_VERSION(3, 0):
+            shader->baseShader.limits.temporary = 32;
+            shader->baseShader.limits.constant_float = 224;
+            shader->baseShader.limits.constant_int = 16;
+            shader->baseShader.limits.constant_bool = 16;
+            shader->baseShader.limits.texcoord = 0;
+            shader->baseShader.limits.sampler = 16;
+            shader->baseShader.limits.packed_input = 12;
+            shader->baseShader.limits.label = 16; /* FIXME: 2048 */
+            break;
+
+        default:
+            shader->baseShader.limits.temporary = 32;
+            shader->baseShader.limits.constant_float = 32;
+            shader->baseShader.limits.constant_int = 16;
+            shader->baseShader.limits.constant_bool = 16;
+            shader->baseShader.limits.texcoord = 8;
+            shader->baseShader.limits.sampler = 16;
+            shader->baseShader.limits.packed_input = 0;
+            shader->baseShader.limits.label = 0;
+            FIXME("Unrecognized pixel shader version %u.%u\n",
+                    shader->baseShader.reg_maps.shader_version.major,
+                    shader->baseShader.reg_maps.shader_version.minor);
+    }
+}
+
+HRESULT pixelshader_init(IWineD3DPixelShaderImpl *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    unsigned int i, highest_reg_used = 0, num_regs_used = 0;
+    HRESULT hr;
+
+    if (!byte_code) return WINED3DERR_INVALIDCALL;
+
+    shader->lpVtbl = &IWineD3DPixelShader_Vtbl;
+    shader_init(&shader->baseShader, device, parent, parent_ops);
+
+    hr = shader_set_function((IWineD3DBaseShaderImpl *)shader, byte_code,
+            output_signature, device->d3d_pshader_constantF);
+    if (FAILED(hr))
+    {
+        WARN("Failed to set function, hr %#x.\n", hr);
+        shader_cleanup((IWineD3DBaseShader *)shader);
+        return hr;
+    }
+
+    pixelshader_set_limits(shader);
+
+    for (i = 0; i < MAX_REG_INPUT; ++i)
+    {
+        if (shader->input_reg_used[i])
+        {
+            ++num_regs_used;
+            highest_reg_used = i;
+        }
+    }
+
+    /* Don't do any register mapping magic if it is not needed, or if we can't
+     * achieve anything anyway */
+    if (highest_reg_used < (gl_info->limits.glsl_varyings / 4)
+            || num_regs_used > (gl_info->limits.glsl_varyings / 4))
+    {
+        if (num_regs_used > (gl_info->limits.glsl_varyings / 4))
+        {
+            /* This happens with relative addressing. The input mapper function
+             * warns about this if the higher registers are declared too, so
+             * don't write a FIXME here */
+            WARN("More varying registers used than supported\n");
+        }
+
+        for (i = 0; i < MAX_REG_INPUT; ++i)
+        {
+            shader->input_reg_map[i] = i;
+        }
+
+        shader->declared_in_count = highest_reg_used + 1;
+    }
+    else
+    {
+        shader->declared_in_count = 0;
+        for (i = 0; i < MAX_REG_INPUT; ++i)
+        {
+            if (shader->input_reg_used[i]) shader->input_reg_map[i] = shader->declared_in_count++;
+            else shader->input_reg_map[i] = ~0U;
+        }
+    }
+
+    shader->baseShader.load_local_constsF = FALSE;
+
+    return WINED3D_OK;
+}
+
+void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures)
+{
+    WINED3DSAMPLER_TEXTURE_TYPE *sampler_type = reg_maps->sampler_type;
+    unsigned int i;
+
+    if (reg_maps->shader_version.major != 1) return;
+
+    for (i = 0; i < max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS); ++i)
+    {
+        /* We don't sample from this sampler. */
+        if (!sampler_type[i]) continue;
+
+        if (!textures[i])
+        {
+            WARN("No texture bound to sampler %u, using 2D.\n", i);
+            sampler_type[i] = WINED3DSTT_2D;
+            continue;
+        }
+
+        switch (IWineD3DBaseTexture_GetTextureDimensions(textures[i]))
+        {
+            case GL_TEXTURE_RECTANGLE_ARB:
+            case GL_TEXTURE_2D:
+                /* We have to select between texture rectangles and 2D
+                 * textures later because 2.0 and 3.0 shaders only have
+                 * WINED3DSTT_2D as well. */
+                sampler_type[i] = WINED3DSTT_2D;
+                break;
+
+            case GL_TEXTURE_3D:
+                sampler_type[i] = WINED3DSTT_VOLUME;
+                break;
+
+            case GL_TEXTURE_CUBE_MAP_ARB:
+                sampler_type[i] = WINED3DSTT_CUBE;
+                break;
+
+            default:
+                FIXME("Unrecognized texture type %#x, using 2D.\n",
+                        IWineD3DBaseTexture_GetTextureDimensions(textures[i]));
+                sampler_type[i] = WINED3DSTT_2D;
+        }
+    }
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm1.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm1.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm1.c	(revision 25949)
@@ -109,7 +109,98 @@
 };
 
+enum wined3d_sm1_opcode
+{
+    WINED3D_SM1_OP_NOP          = 0x00,
+    WINED3D_SM1_OP_MOV          = 0x01,
+    WINED3D_SM1_OP_ADD          = 0x02,
+    WINED3D_SM1_OP_SUB          = 0x03,
+    WINED3D_SM1_OP_MAD          = 0x04,
+    WINED3D_SM1_OP_MUL          = 0x05,
+    WINED3D_SM1_OP_RCP          = 0x06,
+    WINED3D_SM1_OP_RSQ          = 0x07,
+    WINED3D_SM1_OP_DP3          = 0x08,
+    WINED3D_SM1_OP_DP4          = 0x09,
+    WINED3D_SM1_OP_MIN          = 0x0a,
+    WINED3D_SM1_OP_MAX          = 0x0b,
+    WINED3D_SM1_OP_SLT          = 0x0c,
+    WINED3D_SM1_OP_SGE          = 0x0d,
+    WINED3D_SM1_OP_EXP          = 0x0e,
+    WINED3D_SM1_OP_LOG          = 0x0f,
+    WINED3D_SM1_OP_LIT          = 0x10,
+    WINED3D_SM1_OP_DST          = 0x11,
+    WINED3D_SM1_OP_LRP          = 0x12,
+    WINED3D_SM1_OP_FRC          = 0x13,
+    WINED3D_SM1_OP_M4x4         = 0x14,
+    WINED3D_SM1_OP_M4x3         = 0x15,
+    WINED3D_SM1_OP_M3x4         = 0x16,
+    WINED3D_SM1_OP_M3x3         = 0x17,
+    WINED3D_SM1_OP_M3x2         = 0x18,
+    WINED3D_SM1_OP_CALL         = 0x19,
+    WINED3D_SM1_OP_CALLNZ       = 0x1a,
+    WINED3D_SM1_OP_LOOP         = 0x1b,
+    WINED3D_SM1_OP_RET          = 0x1c,
+    WINED3D_SM1_OP_ENDLOOP      = 0x1d,
+    WINED3D_SM1_OP_LABEL        = 0x1e,
+    WINED3D_SM1_OP_DCL          = 0x1f,
+    WINED3D_SM1_OP_POW          = 0x20,
+    WINED3D_SM1_OP_CRS          = 0x21,
+    WINED3D_SM1_OP_SGN          = 0x22,
+    WINED3D_SM1_OP_ABS          = 0x23,
+    WINED3D_SM1_OP_NRM          = 0x24,
+    WINED3D_SM1_OP_SINCOS       = 0x25,
+    WINED3D_SM1_OP_REP          = 0x26,
+    WINED3D_SM1_OP_ENDREP       = 0x27,
+    WINED3D_SM1_OP_IF           = 0x28,
+    WINED3D_SM1_OP_IFC          = 0x29,
+    WINED3D_SM1_OP_ELSE         = 0x2a,
+    WINED3D_SM1_OP_ENDIF        = 0x2b,
+    WINED3D_SM1_OP_BREAK        = 0x2c,
+    WINED3D_SM1_OP_BREAKC       = 0x2d,
+    WINED3D_SM1_OP_MOVA         = 0x2e,
+    WINED3D_SM1_OP_DEFB         = 0x2f,
+    WINED3D_SM1_OP_DEFI         = 0x30,
+
+    WINED3D_SM1_OP_TEXCOORD     = 0x40,
+    WINED3D_SM1_OP_TEXKILL      = 0x41,
+    WINED3D_SM1_OP_TEX          = 0x42,
+    WINED3D_SM1_OP_TEXBEM       = 0x43,
+    WINED3D_SM1_OP_TEXBEML      = 0x44,
+    WINED3D_SM1_OP_TEXREG2AR    = 0x45,
+    WINED3D_SM1_OP_TEXREG2GB    = 0x46,
+    WINED3D_SM1_OP_TEXM3x2PAD   = 0x47,
+    WINED3D_SM1_OP_TEXM3x2TEX   = 0x48,
+    WINED3D_SM1_OP_TEXM3x3PAD   = 0x49,
+    WINED3D_SM1_OP_TEXM3x3TEX   = 0x4a,
+    WINED3D_SM1_OP_TEXM3x3DIFF  = 0x4b,
+    WINED3D_SM1_OP_TEXM3x3SPEC  = 0x4c,
+    WINED3D_SM1_OP_TEXM3x3VSPEC = 0x4d,
+    WINED3D_SM1_OP_EXPP         = 0x4e,
+    WINED3D_SM1_OP_LOGP         = 0x4f,
+    WINED3D_SM1_OP_CND          = 0x50,
+    WINED3D_SM1_OP_DEF          = 0x51,
+    WINED3D_SM1_OP_TEXREG2RGB   = 0x52,
+    WINED3D_SM1_OP_TEXDP3TEX    = 0x53,
+    WINED3D_SM1_OP_TEXM3x2DEPTH = 0x54,
+    WINED3D_SM1_OP_TEXDP3       = 0x55,
+    WINED3D_SM1_OP_TEXM3x3      = 0x56,
+    WINED3D_SM1_OP_TEXDEPTH     = 0x57,
+    WINED3D_SM1_OP_CMP          = 0x58,
+    WINED3D_SM1_OP_BEM          = 0x59,
+    WINED3D_SM1_OP_DP2ADD       = 0x5a,
+    WINED3D_SM1_OP_DSX          = 0x5b,
+    WINED3D_SM1_OP_DSY          = 0x5c,
+    WINED3D_SM1_OP_TEXLDD       = 0x5d,
+    WINED3D_SM1_OP_SETP         = 0x5e,
+    WINED3D_SM1_OP_TEXLDL       = 0x5f,
+    WINED3D_SM1_OP_BREAKP       = 0x60,
+
+    WINED3D_SM1_OP_PHASE        = 0xfffd,
+    WINED3D_SM1_OP_COMMENT      = 0xfffe,
+    WINED3D_SM1_OP_END          = 0Xffff,
+};
+
 struct wined3d_sm1_opcode_info
 {
-    unsigned int opcode;
+    enum wined3d_sm1_opcode opcode;
     UINT dst_count;
     UINT param_count;
@@ -129,65 +220,66 @@
 {
     /* Arithmetic */
-    {WINED3DSIO_NOP,          0, 0, WINED3DSIH_NOP,          0,                           0                          },
-    {WINED3DSIO_MOV,          1, 2, WINED3DSIH_MOV,          0,                           0                          },
-    {WINED3DSIO_MOVA,         1, 2, WINED3DSIH_MOVA,         WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_ADD,          1, 3, WINED3DSIH_ADD,          0,                           0                          },
-    {WINED3DSIO_SUB,          1, 3, WINED3DSIH_SUB,          0,                           0                          },
-    {WINED3DSIO_MAD,          1, 4, WINED3DSIH_MAD,          0,                           0                          },
-    {WINED3DSIO_MUL,          1, 3, WINED3DSIH_MUL,          0,                           0                          },
-    {WINED3DSIO_RCP,          1, 2, WINED3DSIH_RCP,          0,                           0                          },
-    {WINED3DSIO_RSQ,          1, 2, WINED3DSIH_RSQ,          0,                           0                          },
-    {WINED3DSIO_DP3,          1, 3, WINED3DSIH_DP3,          0,                           0                          },
-    {WINED3DSIO_DP4,          1, 3, WINED3DSIH_DP4,          0,                           0                          },
-    {WINED3DSIO_MIN,          1, 3, WINED3DSIH_MIN,          0,                           0                          },
-    {WINED3DSIO_MAX,          1, 3, WINED3DSIH_MAX,          0,                           0                          },
-    {WINED3DSIO_SLT,          1, 3, WINED3DSIH_SLT,          0,                           0                          },
-    {WINED3DSIO_SGE,          1, 3, WINED3DSIH_SGE,          0,                           0                          },
-    {WINED3DSIO_ABS,          1, 2, WINED3DSIH_ABS,          0,                           0                          },
-    {WINED3DSIO_EXP,          1, 2, WINED3DSIH_EXP,          0,                           0                          },
-    {WINED3DSIO_LOG,          1, 2, WINED3DSIH_LOG,          0,                           0                          },
-    {WINED3DSIO_EXPP,         1, 2, WINED3DSIH_EXPP,         0,                           0                          },
-    {WINED3DSIO_LOGP,         1, 2, WINED3DSIH_LOGP,         0,                           0                          },
-    {WINED3DSIO_LIT,          1, 2, WINED3DSIH_LIT,          0,                           0                          },
-    {WINED3DSIO_DST,          1, 3, WINED3DSIH_DST,          0,                           0                          },
-    {WINED3DSIO_LRP,          1, 4, WINED3DSIH_LRP,          0,                           0                          },
-    {WINED3DSIO_FRC,          1, 2, WINED3DSIH_FRC,          0,                           0                          },
-    {WINED3DSIO_POW,          1, 3, WINED3DSIH_POW,          0,                           0                          },
-    {WINED3DSIO_CRS,          1, 3, WINED3DSIH_CRS,          0,                           0                          },
-    {WINED3DSIO_SGN,          1, 2, WINED3DSIH_SGN,          0,                           0                          },
-    {WINED3DSIO_NRM,          1, 2, WINED3DSIH_NRM,          0,                           0                          },
-    {WINED3DSIO_SINCOS,       1, 4, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
-    {WINED3DSIO_SINCOS,       1, 2, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(3,0), -1                         },
+    {WINED3D_SM1_OP_NOP,      0, 0, WINED3DSIH_NOP,          0,                           0                          },
+    {WINED3D_SM1_OP_MOV,      1, 2, WINED3DSIH_MOV,          0,                           0                          },
+    {WINED3D_SM1_OP_MOVA,     1, 2, WINED3DSIH_MOVA,         WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_ADD,      1, 3, WINED3DSIH_ADD,          0,                           0                          },
+    {WINED3D_SM1_OP_SUB,      1, 3, WINED3DSIH_SUB,          0,                           0                          },
+    {WINED3D_SM1_OP_MAD,      1, 4, WINED3DSIH_MAD,          0,                           0                          },
+    {WINED3D_SM1_OP_MUL,      1, 3, WINED3DSIH_MUL,          0,                           0                          },
+    {WINED3D_SM1_OP_RCP,      1, 2, WINED3DSIH_RCP,          0,                           0                          },
+    {WINED3D_SM1_OP_RSQ,      1, 2, WINED3DSIH_RSQ,          0,                           0                          },
+    {WINED3D_SM1_OP_DP3,      1, 3, WINED3DSIH_DP3,          0,                           0                          },
+    {WINED3D_SM1_OP_DP4,      1, 3, WINED3DSIH_DP4,          0,                           0                          },
+    {WINED3D_SM1_OP_MIN,      1, 3, WINED3DSIH_MIN,          0,                           0                          },
+    {WINED3D_SM1_OP_MAX,      1, 3, WINED3DSIH_MAX,          0,                           0                          },
+    {WINED3D_SM1_OP_SLT,      1, 3, WINED3DSIH_SLT,          0,                           0                          },
+    {WINED3D_SM1_OP_SGE,      1, 3, WINED3DSIH_SGE,          0,                           0                          },
+    {WINED3D_SM1_OP_ABS,      1, 2, WINED3DSIH_ABS,          0,                           0                          },
+    {WINED3D_SM1_OP_EXP,      1, 2, WINED3DSIH_EXP,          0,                           0                          },
+    {WINED3D_SM1_OP_LOG,      1, 2, WINED3DSIH_LOG,          0,                           0                          },
+    {WINED3D_SM1_OP_EXPP,     1, 2, WINED3DSIH_EXPP,         0,                           0                          },
+    {WINED3D_SM1_OP_LOGP,     1, 2, WINED3DSIH_LOGP,         0,                           0                          },
+    {WINED3D_SM1_OP_LIT,      1, 2, WINED3DSIH_LIT,          0,                           0                          },
+    {WINED3D_SM1_OP_DST,      1, 3, WINED3DSIH_DST,          0,                           0                          },
+    {WINED3D_SM1_OP_LRP,      1, 4, WINED3DSIH_LRP,          0,                           0                          },
+    {WINED3D_SM1_OP_FRC,      1, 2, WINED3DSIH_FRC,          0,                           0                          },
+    {WINED3D_SM1_OP_POW,      1, 3, WINED3DSIH_POW,          0,                           0                          },
+    {WINED3D_SM1_OP_CRS,      1, 3, WINED3DSIH_CRS,          0,                           0                          },
+    {WINED3D_SM1_OP_SGN,      1, 4, WINED3DSIH_SGN,          WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
+    {WINED3D_SM1_OP_SGN,      1, 2, WINED3DSIH_SGN,          WINED3D_SHADER_VERSION(3,0), -1                         },
+    {WINED3D_SM1_OP_NRM,      1, 2, WINED3DSIH_NRM,          0,                           0                          },
+    {WINED3D_SM1_OP_SINCOS,   1, 4, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
+    {WINED3D_SM1_OP_SINCOS,   1, 2, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(3,0), -1                         },
     /* Matrix */
-    {WINED3DSIO_M4x4,         1, 3, WINED3DSIH_M4x4,         0,                           0                          },
-    {WINED3DSIO_M4x3,         1, 3, WINED3DSIH_M4x3,         0,                           0                          },
-    {WINED3DSIO_M3x4,         1, 3, WINED3DSIH_M3x4,         0,                           0                          },
-    {WINED3DSIO_M3x3,         1, 3, WINED3DSIH_M3x3,         0,                           0                          },
-    {WINED3DSIO_M3x2,         1, 3, WINED3DSIH_M3x2,         0,                           0                          },
+    {WINED3D_SM1_OP_M4x4,     1, 3, WINED3DSIH_M4x4,         0,                           0                          },
+    {WINED3D_SM1_OP_M4x3,     1, 3, WINED3DSIH_M4x3,         0,                           0                          },
+    {WINED3D_SM1_OP_M3x4,     1, 3, WINED3DSIH_M3x4,         0,                           0                          },
+    {WINED3D_SM1_OP_M3x3,     1, 3, WINED3DSIH_M3x3,         0,                           0                          },
+    {WINED3D_SM1_OP_M3x2,     1, 3, WINED3DSIH_M3x2,         0,                           0                          },
     /* Declare registers */
-    {WINED3DSIO_DCL,          0, 2, WINED3DSIH_DCL,          0,                           0                          },
+    {WINED3D_SM1_OP_DCL,      0, 2, WINED3DSIH_DCL,          0,                           0                          },
     /* Constant definitions */
-    {WINED3DSIO_DEF,          1, 5, WINED3DSIH_DEF,          0,                           0                          },
-    {WINED3DSIO_DEFB,         1, 2, WINED3DSIH_DEFB,         0,                           0                          },
-    {WINED3DSIO_DEFI,         1, 5, WINED3DSIH_DEFI,         0,                           0                          },
+    {WINED3D_SM1_OP_DEF,      1, 5, WINED3DSIH_DEF,          0,                           0                          },
+    {WINED3D_SM1_OP_DEFB,     1, 2, WINED3DSIH_DEFB,         0,                           0                          },
+    {WINED3D_SM1_OP_DEFI,     1, 5, WINED3DSIH_DEFI,         0,                           0                          },
     /* Flow control */
-    {WINED3DSIO_REP,          0, 1, WINED3DSIH_REP,          WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_ENDREP,       0, 0, WINED3DSIH_ENDREP,       WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_IF,           0, 1, WINED3DSIH_IF,           WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_IFC,          0, 2, WINED3DSIH_IFC,          WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_ELSE,         0, 0, WINED3DSIH_ELSE,         WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_ENDIF,        0, 0, WINED3DSIH_ENDIF,        WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_BREAK,        0, 0, WINED3DSIH_BREAK,        WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_BREAKC,       0, 2, WINED3DSIH_BREAKC,       WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_BREAKP,       0, 1, WINED3DSIH_BREAKP,       0,                           0                          },
-    {WINED3DSIO_CALL,         0, 1, WINED3DSIH_CALL,         WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_CALLNZ,       0, 2, WINED3DSIH_CALLNZ,       WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_LOOP,         0, 2, WINED3DSIH_LOOP,         WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_RET,          0, 0, WINED3DSIH_RET,          WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_ENDLOOP,      0, 0, WINED3DSIH_ENDLOOP,      WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_LABEL,        0, 1, WINED3DSIH_LABEL,        WINED3D_SHADER_VERSION(2,0), -1                         },
-
-    {WINED3DSIO_SETP,         1, 3, WINED3DSIH_SETP,         0,                           0                          },
-    {WINED3DSIO_TEXLDL,       1, 3, WINED3DSIH_TEXLDL,       WINED3D_SHADER_VERSION(3,0), -1                         },
+    {WINED3D_SM1_OP_REP,      0, 1, WINED3DSIH_REP,          WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_ENDREP,   0, 0, WINED3DSIH_ENDREP,       WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_IF,       0, 1, WINED3DSIH_IF,           WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_IFC,      0, 2, WINED3DSIH_IFC,          WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_ELSE,     0, 0, WINED3DSIH_ELSE,         WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_ENDIF,    0, 0, WINED3DSIH_ENDIF,        WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_BREAK,    0, 0, WINED3DSIH_BREAK,        WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_BREAKC,   0, 2, WINED3DSIH_BREAKC,       WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_BREAKP,   0, 1, WINED3DSIH_BREAKP,       0,                           0                          },
+    {WINED3D_SM1_OP_CALL,     0, 1, WINED3DSIH_CALL,         WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_CALLNZ,   0, 2, WINED3DSIH_CALLNZ,       WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_LOOP,     0, 2, WINED3DSIH_LOOP,         WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_RET,      0, 0, WINED3DSIH_RET,          WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_ENDLOOP,  0, 0, WINED3DSIH_ENDLOOP,      WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_LABEL,    0, 1, WINED3DSIH_LABEL,        WINED3D_SHADER_VERSION(2,0), -1                         },
+
+    {WINED3D_SM1_OP_SETP,     1, 3, WINED3DSIH_SETP,         0,                           0                          },
+    {WINED3D_SM1_OP_TEXLDL,   1, 3, WINED3DSIH_TEXLDL,       WINED3D_SHADER_VERSION(3,0), -1                         },
     {0,                       0, 0, WINED3DSIH_TABLE_SIZE,   0,                           0                          },
 };
@@ -196,93 +288,93 @@
 {
     /* Arithmetic */
-    {WINED3DSIO_NOP,          0, 0, WINED3DSIH_NOP,          0,                           0                          },
-    {WINED3DSIO_MOV,          1, 2, WINED3DSIH_MOV,          0,                           0                          },
-    {WINED3DSIO_ADD,          1, 3, WINED3DSIH_ADD,          0,                           0                          },
-    {WINED3DSIO_SUB,          1, 3, WINED3DSIH_SUB,          0,                           0                          },
-    {WINED3DSIO_MAD,          1, 4, WINED3DSIH_MAD,          0,                           0                          },
-    {WINED3DSIO_MUL,          1, 3, WINED3DSIH_MUL,          0,                           0                          },
-    {WINED3DSIO_RCP,          1, 2, WINED3DSIH_RCP,          0,                           0                          },
-    {WINED3DSIO_RSQ,          1, 2, WINED3DSIH_RSQ,          0,                           0                          },
-    {WINED3DSIO_DP3,          1, 3, WINED3DSIH_DP3,          0,                           0                          },
-    {WINED3DSIO_DP4,          1, 3, WINED3DSIH_DP4,          0,                           0                          },
-    {WINED3DSIO_MIN,          1, 3, WINED3DSIH_MIN,          0,                           0                          },
-    {WINED3DSIO_MAX,          1, 3, WINED3DSIH_MAX,          0,                           0                          },
-    {WINED3DSIO_SLT,          1, 3, WINED3DSIH_SLT,          0,                           0                          },
-    {WINED3DSIO_SGE,          1, 3, WINED3DSIH_SGE,          0,                           0                          },
-    {WINED3DSIO_ABS,          1, 2, WINED3DSIH_ABS,          0,                           0                          },
-    {WINED3DSIO_EXP,          1, 2, WINED3DSIH_EXP,          0,                           0                          },
-    {WINED3DSIO_LOG,          1, 2, WINED3DSIH_LOG,          0,                           0                          },
-    {WINED3DSIO_EXPP,         1, 2, WINED3DSIH_EXPP,         0,                           0                          },
-    {WINED3DSIO_LOGP,         1, 2, WINED3DSIH_LOGP,         0,                           0                          },
-    {WINED3DSIO_DST,          1, 3, WINED3DSIH_DST,          0,                           0                          },
-    {WINED3DSIO_LRP,          1, 4, WINED3DSIH_LRP,          0,                           0                          },
-    {WINED3DSIO_FRC,          1, 2, WINED3DSIH_FRC,          0,                           0                          },
-    {WINED3DSIO_CND,          1, 4, WINED3DSIH_CND,          WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,4)},
-    {WINED3DSIO_CMP,          1, 4, WINED3DSIH_CMP,          WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(3,0)},
-    {WINED3DSIO_POW,          1, 3, WINED3DSIH_POW,          0,                           0                          },
-    {WINED3DSIO_CRS,          1, 3, WINED3DSIH_CRS,          0,                           0                          },
-    {WINED3DSIO_NRM,          1, 2, WINED3DSIH_NRM,          0,                           0                          },
-    {WINED3DSIO_SINCOS,       1, 4, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
-    {WINED3DSIO_SINCOS,       1, 2, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(3,0), -1                         },
-    {WINED3DSIO_DP2ADD,       1, 4, WINED3DSIH_DP2ADD,       WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_NOP,      0, 0, WINED3DSIH_NOP,          0,                           0                          },
+    {WINED3D_SM1_OP_MOV,      1, 2, WINED3DSIH_MOV,          0,                           0                          },
+    {WINED3D_SM1_OP_ADD,      1, 3, WINED3DSIH_ADD,          0,                           0                          },
+    {WINED3D_SM1_OP_SUB,      1, 3, WINED3DSIH_SUB,          0,                           0                          },
+    {WINED3D_SM1_OP_MAD,      1, 4, WINED3DSIH_MAD,          0,                           0                          },
+    {WINED3D_SM1_OP_MUL,      1, 3, WINED3DSIH_MUL,          0,                           0                          },
+    {WINED3D_SM1_OP_RCP,      1, 2, WINED3DSIH_RCP,          0,                           0                          },
+    {WINED3D_SM1_OP_RSQ,      1, 2, WINED3DSIH_RSQ,          0,                           0                          },
+    {WINED3D_SM1_OP_DP3,      1, 3, WINED3DSIH_DP3,          0,                           0                          },
+    {WINED3D_SM1_OP_DP4,      1, 3, WINED3DSIH_DP4,          0,                           0                          },
+    {WINED3D_SM1_OP_MIN,      1, 3, WINED3DSIH_MIN,          0,                           0                          },
+    {WINED3D_SM1_OP_MAX,      1, 3, WINED3DSIH_MAX,          0,                           0                          },
+    {WINED3D_SM1_OP_SLT,      1, 3, WINED3DSIH_SLT,          0,                           0                          },
+    {WINED3D_SM1_OP_SGE,      1, 3, WINED3DSIH_SGE,          0,                           0                          },
+    {WINED3D_SM1_OP_ABS,      1, 2, WINED3DSIH_ABS,          0,                           0                          },
+    {WINED3D_SM1_OP_EXP,      1, 2, WINED3DSIH_EXP,          0,                           0                          },
+    {WINED3D_SM1_OP_LOG,      1, 2, WINED3DSIH_LOG,          0,                           0                          },
+    {WINED3D_SM1_OP_EXPP,     1, 2, WINED3DSIH_EXPP,         0,                           0                          },
+    {WINED3D_SM1_OP_LOGP,     1, 2, WINED3DSIH_LOGP,         0,                           0                          },
+    {WINED3D_SM1_OP_DST,      1, 3, WINED3DSIH_DST,          0,                           0                          },
+    {WINED3D_SM1_OP_LRP,      1, 4, WINED3DSIH_LRP,          0,                           0                          },
+    {WINED3D_SM1_OP_FRC,      1, 2, WINED3DSIH_FRC,          0,                           0                          },
+    {WINED3D_SM1_OP_CND,      1, 4, WINED3DSIH_CND,          WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,4)},
+    {WINED3D_SM1_OP_CMP,      1, 4, WINED3DSIH_CMP,          WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(3,0)},
+    {WINED3D_SM1_OP_POW,      1, 3, WINED3DSIH_POW,          0,                           0                          },
+    {WINED3D_SM1_OP_CRS,      1, 3, WINED3DSIH_CRS,          0,                           0                          },
+    {WINED3D_SM1_OP_NRM,      1, 2, WINED3DSIH_NRM,          0,                           0                          },
+    {WINED3D_SM1_OP_SINCOS,   1, 4, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
+    {WINED3D_SM1_OP_SINCOS,   1, 2, WINED3DSIH_SINCOS,       WINED3D_SHADER_VERSION(3,0), -1                         },
+    {WINED3D_SM1_OP_DP2ADD,   1, 4, WINED3DSIH_DP2ADD,       WINED3D_SHADER_VERSION(2,0), -1                         },
     /* Matrix */
-    {WINED3DSIO_M4x4,         1, 3, WINED3DSIH_M4x4,         0,                           0                          },
-    {WINED3DSIO_M4x3,         1, 3, WINED3DSIH_M4x3,         0,                           0                          },
-    {WINED3DSIO_M3x4,         1, 3, WINED3DSIH_M3x4,         0,                           0                          },
-    {WINED3DSIO_M3x3,         1, 3, WINED3DSIH_M3x3,         0,                           0                          },
-    {WINED3DSIO_M3x2,         1, 3, WINED3DSIH_M3x2,         0,                           0                          },
+    {WINED3D_SM1_OP_M4x4,     1, 3, WINED3DSIH_M4x4,         0,                           0                          },
+    {WINED3D_SM1_OP_M4x3,     1, 3, WINED3DSIH_M4x3,         0,                           0                          },
+    {WINED3D_SM1_OP_M3x4,     1, 3, WINED3DSIH_M3x4,         0,                           0                          },
+    {WINED3D_SM1_OP_M3x3,     1, 3, WINED3DSIH_M3x3,         0,                           0                          },
+    {WINED3D_SM1_OP_M3x2,     1, 3, WINED3DSIH_M3x2,         0,                           0                          },
     /* Register declarations */
-    {WINED3DSIO_DCL,          0, 2, WINED3DSIH_DCL,          0,                           0                          },
+    {WINED3D_SM1_OP_DCL,      0, 2, WINED3DSIH_DCL,          0,                           0                          },
     /* Flow control */
-    {WINED3DSIO_REP,          0, 1, WINED3DSIH_REP,          WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_ENDREP,       0, 0, WINED3DSIH_ENDREP,       WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_IF,           0, 1, WINED3DSIH_IF,           WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_IFC,          0, 2, WINED3DSIH_IFC,          WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_ELSE,         0, 0, WINED3DSIH_ELSE,         WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_ENDIF,        0, 0, WINED3DSIH_ENDIF,        WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_BREAK,        0, 0, WINED3DSIH_BREAK,        WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_BREAKC,       0, 2, WINED3DSIH_BREAKC,       WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_BREAKP,       0, 1, WINED3DSIH_BREAKP,       0,                           0                          },
-    {WINED3DSIO_CALL,         0, 1, WINED3DSIH_CALL,         WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_CALLNZ,       0, 2, WINED3DSIH_CALLNZ,       WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_LOOP,         0, 2, WINED3DSIH_LOOP,         WINED3D_SHADER_VERSION(3,0), -1                         },
-    {WINED3DSIO_RET,          0, 0, WINED3DSIH_RET,          WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_ENDLOOP,      0, 0, WINED3DSIH_ENDLOOP,      WINED3D_SHADER_VERSION(3,0), -1                         },
-    {WINED3DSIO_LABEL,        0, 1, WINED3DSIH_LABEL,        WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_REP,      0, 1, WINED3DSIH_REP,          WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_ENDREP,   0, 0, WINED3DSIH_ENDREP,       WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_IF,       0, 1, WINED3DSIH_IF,           WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_IFC,      0, 2, WINED3DSIH_IFC,          WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_ELSE,     0, 0, WINED3DSIH_ELSE,         WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_ENDIF,    0, 0, WINED3DSIH_ENDIF,        WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_BREAK,    0, 0, WINED3DSIH_BREAK,        WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_BREAKC,   0, 2, WINED3DSIH_BREAKC,       WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_BREAKP,   0, 1, WINED3DSIH_BREAKP,       0,                           0                          },
+    {WINED3D_SM1_OP_CALL,     0, 1, WINED3DSIH_CALL,         WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_CALLNZ,   0, 2, WINED3DSIH_CALLNZ,       WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_LOOP,     0, 2, WINED3DSIH_LOOP,         WINED3D_SHADER_VERSION(3,0), -1                         },
+    {WINED3D_SM1_OP_RET,      0, 0, WINED3DSIH_RET,          WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_ENDLOOP,  0, 0, WINED3DSIH_ENDLOOP,      WINED3D_SHADER_VERSION(3,0), -1                         },
+    {WINED3D_SM1_OP_LABEL,    0, 1, WINED3DSIH_LABEL,        WINED3D_SHADER_VERSION(2,1), -1                         },
     /* Constant definitions */
-    {WINED3DSIO_DEF,          1, 5, WINED3DSIH_DEF,          0,                           0                          },
-    {WINED3DSIO_DEFB,         1, 2, WINED3DSIH_DEFB,         0,                           0                          },
-    {WINED3DSIO_DEFI,         1, 5, WINED3DSIH_DEFI,         0,                           0                          },
+    {WINED3D_SM1_OP_DEF,      1, 5, WINED3DSIH_DEF,          0,                           0                          },
+    {WINED3D_SM1_OP_DEFB,     1, 2, WINED3DSIH_DEFB,         0,                           0                          },
+    {WINED3D_SM1_OP_DEFI,     1, 5, WINED3DSIH_DEFI,         0,                           0                          },
     /* Texture */
-    {WINED3DSIO_TEXCOORD,     1, 1, WINED3DSIH_TEXCOORD,     0,                           WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXCOORD,     1, 2, WINED3DSIH_TEXCOORD,     WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
-    {WINED3DSIO_TEXKILL,      1, 1, WINED3DSIH_TEXKILL,      WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(3,0)},
-    {WINED3DSIO_TEX,          1, 1, WINED3DSIH_TEX,          0,                           WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEX,          1, 2, WINED3DSIH_TEX,          WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
-    {WINED3DSIO_TEX,          1, 3, WINED3DSIH_TEX,          WINED3D_SHADER_VERSION(2,0), -1                         },
-    {WINED3DSIO_TEXBEM,       1, 2, WINED3DSIH_TEXBEM,       0,                           WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXBEML,      1, 2, WINED3DSIH_TEXBEML,      WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXREG2AR,    1, 2, WINED3DSIH_TEXREG2AR,    WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXREG2GB,    1, 2, WINED3DSIH_TEXREG2GB,    WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXREG2RGB,   1, 2, WINED3DSIH_TEXREG2RGB,   WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x2PAD,   1, 2, WINED3DSIH_TEXM3x2PAD,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x2TEX,   1, 2, WINED3DSIH_TEXM3x2TEX,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3PAD,   1, 2, WINED3DSIH_TEXM3x3PAD,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3DIFF,  1, 2, WINED3DSIH_TEXM3x3DIFF,  WINED3D_SHADER_VERSION(0,0), WINED3D_SHADER_VERSION(0,0)},
-    {WINED3DSIO_TEXM3x3SPEC,  1, 3, WINED3DSIH_TEXM3x3SPEC,  WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3VSPEC, 1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3TEX,   1, 2, WINED3DSIH_TEXM3x3TEX,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXDP3TEX,    1, 2, WINED3DSIH_TEXDP3TEX,    WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x2DEPTH, 1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3D_SHADER_VERSION(1,3), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXDP3,       1, 2, WINED3DSIH_TEXDP3,       WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3,      1, 2, WINED3DSIH_TEXM3x3,      WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
-    {WINED3DSIO_TEXDEPTH,     1, 1, WINED3DSIH_TEXDEPTH,     WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
-    {WINED3DSIO_BEM,          1, 3, WINED3DSIH_BEM,          WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
-    {WINED3DSIO_DSX,          1, 2, WINED3DSIH_DSX,          WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_DSY,          1, 2, WINED3DSIH_DSY,          WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_TEXLDD,       1, 5, WINED3DSIH_TEXLDD,       WINED3D_SHADER_VERSION(2,1), -1                         },
-    {WINED3DSIO_SETP,         1, 3, WINED3DSIH_SETP,         0,                           0                          },
-    {WINED3DSIO_TEXLDL,       1, 3, WINED3DSIH_TEXLDL,       WINED3D_SHADER_VERSION(3,0), -1                         },
-    {WINED3DSIO_PHASE,        0, 0, WINED3DSIH_PHASE,        0,                           0                          },
+    {WINED3D_SM1_OP_TEXCOORD, 1, 1, WINED3DSIH_TEXCOORD,     0,                           WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXCOORD, 1, 2, WINED3DSIH_TEXCOORD,     WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
+    {WINED3D_SM1_OP_TEXKILL,  1, 1, WINED3DSIH_TEXKILL,      WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(3,0)},
+    {WINED3D_SM1_OP_TEX,      1, 1, WINED3DSIH_TEX,          0,                           WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEX,      1, 2, WINED3DSIH_TEX,          WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
+    {WINED3D_SM1_OP_TEX,      1, 3, WINED3DSIH_TEX,          WINED3D_SHADER_VERSION(2,0), -1                         },
+    {WINED3D_SM1_OP_TEXBEM,   1, 2, WINED3DSIH_TEXBEM,       0,                           WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXBEML,  1, 2, WINED3DSIH_TEXBEML,      WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXREG2AR,      1, 2, WINED3DSIH_TEXREG2AR,    WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXREG2GB,      1, 2, WINED3DSIH_TEXREG2GB,    WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXREG2RGB,     1, 2, WINED3DSIH_TEXREG2RGB,   WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x2PAD,     1, 2, WINED3DSIH_TEXM3x2PAD,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x2TEX,     1, 2, WINED3DSIH_TEXM3x2TEX,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x3PAD,     1, 2, WINED3DSIH_TEXM3x3PAD,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x3DIFF,    1, 2, WINED3DSIH_TEXM3x3DIFF,  WINED3D_SHADER_VERSION(0,0), WINED3D_SHADER_VERSION(0,0)},
+    {WINED3D_SM1_OP_TEXM3x3SPEC,    1, 3, WINED3DSIH_TEXM3x3SPEC,  WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x3VSPEC,   1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x3TEX,     1, 2, WINED3DSIH_TEXM3x3TEX,   WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXDP3TEX,      1, 2, WINED3DSIH_TEXDP3TEX,    WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x2DEPTH,   1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3D_SHADER_VERSION(1,3), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXDP3,   1, 2, WINED3DSIH_TEXDP3,       WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXM3x3,  1, 2, WINED3DSIH_TEXM3x3,      WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
+    {WINED3D_SM1_OP_TEXDEPTH, 1, 1, WINED3DSIH_TEXDEPTH,     WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
+    {WINED3D_SM1_OP_BEM,      1, 3, WINED3DSIH_BEM,          WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
+    {WINED3D_SM1_OP_DSX,      1, 2, WINED3DSIH_DSX,          WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_DSY,      1, 2, WINED3DSIH_DSY,          WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_TEXLDD,   1, 5, WINED3DSIH_TEXLDD,       WINED3D_SHADER_VERSION(2,1), -1                         },
+    {WINED3D_SM1_OP_SETP,     1, 3, WINED3DSIH_SETP,         0,                           0                          },
+    {WINED3D_SM1_OP_TEXLDL,   1, 3, WINED3DSIH_TEXLDL,       WINED3D_SHADER_VERSION(3,0), -1                         },
+    {WINED3D_SM1_OP_PHASE,    0, 0, WINED3DSIH_PHASE,        0,                           0                          },
     {0,                       0, 0, WINED3DSIH_TABLE_SIZE,   0,                           0                          },
 };
@@ -424,5 +516,16 @@
 static void *shader_sm1_init(const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
 {
-    struct wined3d_sm1_data *priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
+    struct wined3d_sm1_data *priv;
+    BYTE major, minor;
+
+    major = WINED3D_SM1_VERSION_MAJOR(*byte_code);
+    minor = WINED3D_SM1_VERSION_MINOR(*byte_code);
+    if (WINED3D_SHADER_VERSION(major, minor) > WINED3D_SHADER_VERSION(3, 0))
+    {
+        WARN("Invalid shader version %u.%u (%#x).\n", major, minor, *byte_code);
+        return NULL;
+    }
+
+    priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
     if (!priv)
     {
@@ -552,5 +655,5 @@
     DWORD token = **ptr;
 
-    if ((token & WINED3DSI_OPCODE_MASK) != WINED3DSIO_COMMENT)
+    if ((token & WINED3DSI_OPCODE_MASK) != WINED3D_SM1_OP_COMMENT)
     {
         *comment = NULL;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c	(revision 25949)
@@ -59,8 +59,18 @@
 {
     WINED3D_SM4_OP_ADD      = 0x00,
+    WINED3D_SM4_OP_BREAK    = 0x02,
+    WINED3D_SM4_OP_BREAKC   = 0x03,
+    WINED3D_SM4_OP_CUT      = 0x09,
     WINED3D_SM4_OP_DP3      = 0x10,
     WINED3D_SM4_OP_DP4      = 0x11,
+    WINED3D_SM4_OP_EMIT     = 0x13,
+    WINED3D_SM4_OP_ENDIF    = 0x15,
+    WINED3D_SM4_OP_ENDLOOP  = 0x16,
     WINED3D_SM4_OP_EXP      = 0x19,
+    WINED3D_SM4_OP_IADD     = 0x1e,
+    WINED3D_SM4_OP_IF       = 0x1f,
+    WINED3D_SM4_OP_IGE      = 0x21,
     WINED3D_SM4_OP_LOG      = 0x2f,
+    WINED3D_SM4_OP_LT       = 0x31,
     WINED3D_SM4_OP_MIN      = 0x33,
     WINED3D_SM4_OP_MAX      = 0x34,
@@ -112,8 +122,18 @@
 {
     {WINED3D_SM4_OP_ADD,    WINED3DSIH_ADD,         1,  2},
+    {WINED3D_SM4_OP_BREAK,  WINED3DSIH_BREAK,       0,  0},
+    {WINED3D_SM4_OP_BREAKC, WINED3DSIH_BREAKP,      0,  1},
+    {WINED3D_SM4_OP_CUT,    WINED3DSIH_CUT,         0,  0},
     {WINED3D_SM4_OP_DP3,    WINED3DSIH_DP3,         1,  2},
     {WINED3D_SM4_OP_DP4,    WINED3DSIH_DP4,         1,  2},
+    {WINED3D_SM4_OP_EMIT,   WINED3DSIH_EMIT,        0,  0},
+    {WINED3D_SM4_OP_ENDIF,  WINED3DSIH_ENDIF,       0,  0},
+    {WINED3D_SM4_OP_ENDLOOP,WINED3DSIH_ENDLOOP,     0,  0},
     {WINED3D_SM4_OP_EXP,    WINED3DSIH_EXP,         1,  1},
+    {WINED3D_SM4_OP_IADD,   WINED3DSIH_IADD,        1,  2},
+    {WINED3D_SM4_OP_IF,     WINED3DSIH_IF,          0,  1},
+    {WINED3D_SM4_OP_IGE,    WINED3DSIH_IGE,         1,  2},
     {WINED3D_SM4_OP_LOG,    WINED3DSIH_LOG,         1,  1},
+    {WINED3D_SM4_OP_LT,     WINED3DSIH_LT,          1,  2},
     {WINED3D_SM4_OP_MIN,    WINED3DSIH_MIN,         1,  2},
     {WINED3D_SM4_OP_MAX,    WINED3DSIH_MAX,         1,  2},
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c	(revision 25949)
@@ -105,5 +105,5 @@
 
     if (stateblock->renderState[WINED3DRS_LIGHTING]
-            && !stateblock->wineD3DDevice->strided_streams.position_transformed)
+            && !stateblock->device->strided_streams.position_transformed)
     {
         glEnable(GL_LIGHTING);
@@ -118,5 +118,6 @@
 {
     /* No z test without depth stencil buffers */
-    if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) {
+    if (!stateblock->device->stencilBufferTarget)
+    {
         TRACE("No Z buffer - disabling depth test\n");
         glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */
@@ -251,7 +252,7 @@
 static void state_blend(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *)stateblock->device->render_targets[0];
     int srcBlend = GL_ZERO;
     int dstBlend = GL_ZERO;
-    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *) stateblock->wineD3DDevice->render_targets[0];
 
     /* GL_LINE_SMOOTH needs GL_BLEND to work, according to the red book, and special blending params */
@@ -262,5 +263,6 @@
         /* Disable blending in all cases even without pixelshaders. With blending on we could face a big performance penalty.
          * The d3d9 visual test confirms the behavior. */
-        if (!(target->resource.format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
+        if (context->render_offscreen
+                && !(target->resource.format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
         {
             glDisable(GL_BLEND);
@@ -381,5 +383,6 @@
 
         /* Separate alpha blending requires GL_EXT_blend_function_separate, so make sure it is around */
-        if(!GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE)) {
+        if (!context->gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
+        {
             WARN("Unsupported in local OpenGL implementation: glBlendFuncSeparateEXT\n");
             return;
@@ -456,6 +459,7 @@
     /* colorkey fixup for stage 0 alphaop depends on WINED3DRS_ALPHABLENDENABLE state,
         so it may need updating */
-    if (stateblock->renderState[WINED3DRS_COLORKEYENABLE]) {
-        const struct StateEntry *StateTable = stateblock->wineD3DDevice->StateTable;
+    if (stateblock->renderState[WINED3DRS_COLORKEYENABLE])
+    {
+        const struct StateEntry *StateTable = stateblock->device->StateTable;
         StateTable[STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP)].apply(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context);
     }
@@ -511,6 +515,7 @@
     }
 
-    if(enable_ckey || context->last_was_ckey) {
-        const struct StateEntry *StateTable = stateblock->wineD3DDevice->StateTable;
+    if (enable_ckey || context->last_was_ckey)
+    {
+        const struct StateEntry *StateTable = stateblock->device->StateTable;
         StateTable[STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP)].apply(STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), stateblock, context);
     }
@@ -545,8 +550,9 @@
 static void state_clipping(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     DWORD enable  = 0xFFFFFFFF;
     DWORD disable = 0x00000000;
 
-    if (!stateblock->wineD3DDevice->vs_clipping && use_vs(stateblock))
+    if (!stateblock->device->vs_clipping && use_vs(stateblock))
     {
         /* The spec says that opengl clipping planes are disabled when using shaders. Direct3D planes aren't,
@@ -575,5 +581,5 @@
         enable  = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
         disable = ~stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
-        if (GL_SUPPORT(ARB_DEPTH_CLAMP))
+        if (gl_info->supported[ARB_DEPTH_CLAMP])
         {
             glDisable(GL_DEPTH_CLAMP);
@@ -583,5 +589,5 @@
         disable = 0xffffffff;
         enable  = 0x00;
-        if (GL_SUPPORT(ARB_DEPTH_CLAMP))
+        if (gl_info->supported[ARB_DEPTH_CLAMP])
         {
             glEnable(GL_DEPTH_CLAMP);
@@ -625,5 +631,7 @@
 
     /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */
-    if(stateblock->renderState[WINED3DRS_BLENDOPALPHA] && !GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE)) {
+    if (stateblock->renderState[WINED3DRS_BLENDOPALPHA]
+            && !context->gl_info->supported[EXT_BLEND_EQUATION_SEPARATE])
+    {
         WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparateEXT\n");
         return;
@@ -663,4 +671,5 @@
 static void state_specularenable(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
      * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
@@ -698,13 +707,14 @@
         checkGLcall("glMaterialfv");
 
-        if(stateblock->material.Power > GL_LIMITS(shininess)) {
+        if (stateblock->material.Power > gl_info->limits.shininess)
+        {
             /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0
              * and 128.0, although in d3d neither -1 nor 129 produce an error. GL_NV_max_light_exponent
-             * allows bigger values. If the extension is supported, GL_LIMITS(shininess) contains the
-             * value reported by the extension, otherwise 128. For values > GL_LIMITS(shininess) clamp
+             * allows bigger values. If the extension is supported, gl_info->limits.shininess contains the
+             * value reported by the extension, otherwise 128. For values > gl_info->limits.shininess clamp
              * them, it should be safe to do so without major visual distortions.
              */
-            WARN("Material power = %f, limit %f\n", stateblock->material.Power, GL_LIMITS(shininess));
-            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, GL_LIMITS(shininess));
+            WARN("Material power = %f, limit %f\n", stateblock->material.Power, gl_info->limits.shininess);
+            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, gl_info->limits.shininess);
         } else {
             glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, stateblock->material.Power);
@@ -712,12 +722,16 @@
         checkGLcall("glMaterialf(GL_SHININESS)");
 
-        if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+        if (gl_info->supported[EXT_SECONDARY_COLOR])
+        {
             glEnable(GL_COLOR_SUM_EXT);
-        } else {
+        }
+        else
+        {
             TRACE("Specular colors cannot be enabled in this version of opengl\n");
         }
         checkGLcall("glEnable(GL_COLOR_SUM)");
 
-        if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
+        if (gl_info->supported[NV_REGISTER_COMBINERS])
+        {
             GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
             checkGLcall("glFinalCombinerInputNV()");
@@ -731,12 +745,16 @@
 
         /* for the case of disabled lighting: */
-        if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+        if (gl_info->supported[EXT_SECONDARY_COLOR])
+        {
             glDisable(GL_COLOR_SUM_EXT);
-        } else {
+        }
+        else
+        {
             TRACE("Specular colors cannot be disabled in this version of opengl\n");
         }
         checkGLcall("glDisable(GL_COLOR_SUM)");
 
-        if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
+        if (gl_info->supported[NV_REGISTER_COMBINERS])
+        {
             GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
             checkGLcall("glFinalCombinerInputNV()");
@@ -744,12 +762,16 @@
     }
 
-    TRACE("(%p) : Diffuse (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Diffuse.r, stateblock->material.Diffuse.g,
-          stateblock->material.Diffuse.b, stateblock->material.Diffuse.a);
-    TRACE("(%p) : Ambient (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Ambient.r, stateblock->material.Ambient.g,
-          stateblock->material.Ambient.b, stateblock->material.Ambient.a);
-    TRACE("(%p) : Specular (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Specular.r, stateblock->material.Specular.g,
-          stateblock->material.Specular.b, stateblock->material.Specular.a);
-    TRACE("(%p) : Emissive (%f,%f,%f,%f)\n", stateblock->wineD3DDevice, stateblock->material.Emissive.r, stateblock->material.Emissive.g,
-          stateblock->material.Emissive.b, stateblock->material.Emissive.a);
+    TRACE("(%p) : Diffuse {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
+            stateblock->material.Diffuse.r, stateblock->material.Diffuse.g,
+            stateblock->material.Diffuse.b, stateblock->material.Diffuse.a);
+    TRACE("(%p) : Ambient {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
+            stateblock->material.Ambient.r, stateblock->material.Ambient.g,
+            stateblock->material.Ambient.b, stateblock->material.Ambient.a);
+    TRACE("(%p) : Specular {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
+            stateblock->material.Specular.r, stateblock->material.Specular.g,
+            stateblock->material.Specular.b, stateblock->material.Specular.a);
+    TRACE("(%p) : Emissive {%.8e, %.8e, %.8e, %.8e}\n", stateblock->device,
+            stateblock->material.Emissive.r, stateblock->material.Emissive.g,
+            stateblock->material.Emissive.b, stateblock->material.Emissive.a);
 
     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*) &stateblock->material.Ambient);
@@ -772,5 +794,6 @@
 
     /* And now the default texture color as well */
-    for (i = 0; i < GL_LIMITS(texture_stages); i++) {
+    for (i = 0; i < context->gl_info->limits.texture_stages; ++i)
+    {
         /* Note the WINED3DRS value applies to all textures, but GL has one
          * per texture, so apply it now ready to be used!
@@ -799,4 +822,5 @@
 static void state_stencil(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     DWORD onesided_enable = FALSE;
     DWORD twosided_enable = FALSE;
@@ -812,6 +836,7 @@
     GLint stencilPass_ccw = GL_KEEP;
 
-    /* No stencil test without a stencil buffer */
-    if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) {
+    /* No stencil test without a stencil buffer. */
+    if (!stateblock->device->stencilBufferTarget)
+    {
         glDisable(GL_STENCIL_TEST);
         checkGLcall("glDisable GL_STENCIL_TEST");
@@ -845,5 +870,6 @@
         checkGLcall("glEnable GL_STENCIL_TEST");
 
-        if(GL_SUPPORT(EXT_STENCIL_TWO_SIDE)) {
+        if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
+        {
             /* Apply back first, then front. This function calls glActiveStencilFaceEXT,
              * which has an effect on the code below too. If we apply the front face
@@ -856,5 +882,7 @@
             renderstate_stencil_twosided(context, GL_FRONT,
                     func, ref, mask, stencilFail, depthFail, stencilPass);
-        } else if(GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
+        }
+        else if (gl_info->supported[ATI_SEPARATE_STENCIL])
+        {
             GL_EXTCALL(glStencilFuncSeparateATI(func, func_ccw, ref, mask));
             checkGLcall("glStencilFuncSeparateATI(...)");
@@ -866,6 +894,9 @@
             ERR("Separate (two sided) stencil not supported on this version of opengl. Caps weren't honored?\n");
         }
-    } else if(onesided_enable) {
-        if(GL_SUPPORT(EXT_STENCIL_TWO_SIDE)) {
+    }
+    else if(onesided_enable)
+    {
+        if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
+        {
             glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
             checkGLcall("glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
@@ -889,11 +920,5 @@
 static void state_stencilwrite2s(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    DWORD mask;
-
-    if(stateblock->wineD3DDevice->stencilBufferTarget) {
-        mask = stateblock->renderState[WINED3DRS_STENCILWRITEMASK];
-    } else {
-        mask = 0;
-    }
+    DWORD mask = stateblock->device->stencilBufferTarget ? stateblock->renderState[WINED3DRS_STENCILWRITEMASK] : 0;
 
     GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
@@ -908,11 +933,5 @@
 static void state_stencilwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    DWORD mask;
-
-    if(stateblock->wineD3DDevice->stencilBufferTarget) {
-        mask = stateblock->renderState[WINED3DRS_STENCILWRITEMASK];
-    } else {
-        mask = 0;
-    }
+    DWORD mask = stateblock->device->stencilBufferTarget ? stateblock->renderState[WINED3DRS_STENCILWRITEMASK] : 0;
 
     glStencilMask(mask);
@@ -1189,5 +1208,5 @@
 static void state_colormat(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
     GLenum Parm = 0;
 
@@ -1358,5 +1377,5 @@
      */
     if (stateblock->renderState[WINED3DRS_NORMALIZENORMALS]
-            && (stateblock->wineD3DDevice->strided_streams.use_map & (1 << WINED3D_FFP_NORMAL)))
+            && (stateblock->device->strided_streams.use_map & (1 << WINED3D_FFP_NORMAL)))
     {
         glEnable(GL_NORMALIZE);
@@ -1432,4 +1451,5 @@
 static void state_pscale(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     /* TODO: Group this with the viewport */
     /*
@@ -1455,17 +1475,19 @@
         float h = stateblock->viewport.Height;
 
-        if(pointSize.f < GL_LIMITS(pointsizemin)) {
-            /*
-             * Minimum valid point size for OpenGL is driver specific. For Direct3D it is
+        if (pointSize.f < gl_info->limits.pointsize_min)
+        {
+            /* Minimum valid point size for OpenGL is driver specific. For Direct3D it is
              * 0.0f. This means that OpenGL will clamp really small point sizes to the
              * driver minimum. To correct for this we need to multiply by the scale factor when sizes
              * are less than 1.0f. scale_factor =  1.0f / point_size.
              */
-            scaleFactor = pointSize.f / GL_LIMITS(pointsizemin);
+            scaleFactor = pointSize.f / gl_info->limits.pointsize_min;
             /* Clamp the point size, don't rely on the driver to do it. MacOS says min point size
              * is 1.0, but then accepts points below that and draws too small points
              */
-            pointSize.f = GL_LIMITS(pointsizemin);
-        } else if(pointSize.f > GL_LIMITS(pointsize)) {
+            pointSize.f = gl_info->limits.pointsize_min;
+        }
+        else if(pointSize.f > gl_info->limits.pointsize_max)
+        {
             /* gl already scales the input to glPointSize,
              * d3d scales the result after the point size scale.
@@ -1473,7 +1495,7 @@
              * scaling to scale it bigger, and set the gl point size to max
              */
-            scaleFactor = pointSize.f / GL_LIMITS(pointsize);
+            scaleFactor = pointSize.f / gl_info->limits.pointsize_max;
             TRACE("scale: %f\n", scaleFactor);
-            pointSize.f = GL_LIMITS(pointsize);
+            pointSize.f = gl_info->limits.pointsize_max;
         } else {
             scaleFactor = 1.0f;
@@ -1486,9 +1508,11 @@
     }
 
-    if(GL_SUPPORT(ARB_POINT_PARAMETERS)) {
+    if (gl_info->supported[ARB_POINT_PARAMETERS])
+    {
         GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
         checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...)");
     }
-    else if(GL_SUPPORT(EXT_POINT_PARAMETERS)) {
+    else if (gl_info->supported[EXT_POINT_PARAMETERS])
+    {
         GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
         checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)");
@@ -1560,5 +1584,6 @@
 static void state_pointsprite_w(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    BOOL warned = FALSE;
+    static BOOL warned;
+
     /* TODO: NV_POINT_SPRITE */
     if (!warned && stateblock->renderState[WINED3DRS_POINTSPRITEENABLE]) {
@@ -1571,8 +1596,14 @@
 static void state_pointsprite(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    if (stateblock->renderState[WINED3DRS_POINTSPRITEENABLE]) {
-        BOOL warned = FALSE;
-        if(GL_LIMITS(point_sprite_units) < GL_LIMITS(textures) && !warned) {
-            if(use_ps(stateblock) || stateblock->lowest_disabled_stage > GL_LIMITS(point_sprite_units)) {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+
+    if (stateblock->renderState[WINED3DRS_POINTSPRITEENABLE])
+    {
+        static BOOL warned;
+
+        if (gl_info->limits.point_sprite_units < gl_info->limits.textures && !warned)
+        {
+            if (use_ps(stateblock) || stateblock->lowest_disabled_stage > gl_info->limits.point_sprite_units)
+            {
                 FIXME("The app uses point sprite texture coordinates on more units than supported by the driver\n");
                 warned = TRUE;
@@ -1615,5 +1646,5 @@
        stateblock->renderState[WINED3DRS_WRAP14] ||
        stateblock->renderState[WINED3DRS_WRAP15] ) {
-        FIXME("(WINED3DRS_WRAP0) Texture wraping not yet supported\n");
+        FIXME("(WINED3DRS_WRAP0) Texture wrapping not yet supported\n");
     }
 }
@@ -1648,17 +1679,31 @@
 }
 
+/* The Direct3D depth bias is specified in normalized depth coordinates. In
+ * OpenGL the bias is specified in units of "the smallest value that is
+ * guaranteed to produce a resolvable offset for a given implementation". To
+ * convert from D3D to GL we need to divide the D3D depth bias by that value.
+ * There's no practical way to retrieve that value from a given GL
+ * implementation, but the D3D application has essentially the same problem,
+ * which makes a guess of 1e-6f seem reasonable here. Note that
+ * SLOPESCALEDEPTHBIAS is a scaling factor for the depth slope, and doesn't
+ * need to be scaled. */
 static void state_depthbias(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    union {
-        DWORD d;
-        float f;
-    } tmpvalue;
-
-    if(stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS] ||
-       stateblock->renderState[WINED3DRS_DEPTHBIAS]) {
-        tmpvalue.d = stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS];
+    if (stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS]
+            || stateblock->renderState[WINED3DRS_DEPTHBIAS])
+    {
+        union
+        {
+            DWORD d;
+            float f;
+        } scale_bias, const_bias;
+
+        scale_bias.d = stateblock->renderState[WINED3DRS_SLOPESCALEDEPTHBIAS];
+        const_bias.d = stateblock->renderState[WINED3DRS_DEPTHBIAS];
+
         glEnable(GL_POLYGON_OFFSET_FILL);
         checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
-        glPolygonOffset(tmpvalue.f, *((float*)&stateblock->renderState[WINED3DRS_DEPTHBIAS]));
+
+        glPolygonOffset(scale_bias.f, const_bias.f * 1e6f);
         checkGLcall("glPolygonOffset(...)");
     } else {
@@ -1913,4 +1958,5 @@
         BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     GLenum src1, src2, src3;
     GLenum opr1, opr2, opr3;
@@ -1979,5 +2025,6 @@
 
     /* Other texture operations require special extensions: */
-    if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
+    if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
+    {
         if (isAlpha) {
             opr = GL_SRC_ALPHA;
@@ -2564,5 +2611,6 @@
             break;
         case WINED3DTOP_SUBTRACT:
-            if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE)) {
+            if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, useext(GL_SUBTRACT)");
@@ -2655,8 +2703,11 @@
             break;
         case WINED3DTOP_DOTPRODUCT3:
-            if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
+            if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
-            } else if (GL_SUPPORT(EXT_TEXTURE_ENV_DOT3)) {
+            }
+            else if (gl_info->supported[EXT_TEXTURE_ENV_DOT3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
@@ -2694,5 +2745,6 @@
             break;
         case WINED3DTOP_ADDSMOOTH:
-            if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
+            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
@@ -2721,5 +2773,6 @@
                 break;
         case WINED3DTOP_BLENDTEXTUREALPHAPM:
-            if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
+            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
@@ -2742,5 +2795,6 @@
                 break;
         case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
-            if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
+            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
@@ -2769,5 +2823,6 @@
                 break;
         case WINED3DTOP_MODULATECOLOR_ADDALPHA:
-            if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
+            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
@@ -2796,5 +2851,6 @@
                 break;
         case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
-            if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
+            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
@@ -2823,5 +2879,6 @@
                 break;
         case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
-            if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
+            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
@@ -2856,5 +2913,6 @@
                 break;
         case WINED3DTOP_MULTIPLYADD:
-            if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3)) {
+            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
+            {
                 glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
                 checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
@@ -2878,5 +2936,6 @@
         case WINED3DTOP_BUMPENVMAPLUMINANCE:
         case WINED3DTOP_BUMPENVMAP:
-            if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
+            if (gl_info->supported[NV_TEXTURE_SHADER2])
+            {
                 /* Technically texture shader support without register combiners is possible, but not expected to occur
                  * on real world cards, so for now a fixme should be enough
@@ -2890,5 +2949,6 @@
     if (Handled) {
         BOOL  combineOK = TRUE;
-        if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
+        if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
+        {
             DWORD op2;
 
@@ -2938,6 +2998,7 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
-    BOOL tex_used = stateblock->wineD3DDevice->fixed_function_usage_map & (1 << stage);
+    BOOL tex_used = stateblock->device->fixed_function_usage_map & (1 << stage);
+    DWORD mapped_stage = stateblock->device->texUnitMap[stage];
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     TRACE("Setting color op for stage %d\n", stage);
@@ -2950,5 +3011,6 @@
     if (mapped_stage != WINED3D_UNMAPPED_STAGE)
     {
-        if (tex_used && mapped_stage >= GL_LIMITS(textures)) {
+        if (tex_used && mapped_stage >= gl_info->limits.textures)
+        {
             FIXME("Attempt to enable unsupported stage!\n");
             return;
@@ -2967,9 +3029,11 @@
             glDisable(GL_TEXTURE_3D);
             checkGLcall("glDisable(GL_TEXTURE_3D)");
-            if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+            if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+            {
                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
             }
-            if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+            if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+            {
                 glDisable(GL_TEXTURE_RECTANGLE_ARB);
                 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
@@ -2987,5 +3051,5 @@
     }
 
-    set_tex_op(context, (IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
+    set_tex_op(context, (IWineD3DDevice *)stateblock->device, FALSE, stage,
                 stateblock->textureState[stage][WINED3DTSS_COLOROP],
                 stateblock->textureState[stage][WINED3DTSS_COLORARG1],
@@ -2997,6 +3061,7 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
-    BOOL tex_used = stateblock->wineD3DDevice->fixed_function_usage_map & (1 << stage);
+    BOOL tex_used = stateblock->device->fixed_function_usage_map & (1 << stage);
+    DWORD mapped_stage = stateblock->device->texUnitMap[stage];
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     DWORD op, arg1, arg2, arg0;
 
@@ -3005,5 +3070,6 @@
     if (mapped_stage != WINED3D_UNMAPPED_STAGE)
     {
-        if (tex_used && mapped_stage >= GL_LIMITS(textures)) {
+        if (tex_used && mapped_stage >= gl_info->limits.textures)
+        {
             FIXME("Attempt to enable unsupported stage!\n");
             return;
@@ -3083,12 +3149,12 @@
      */
     TRACE("Setting alpha op for stage %d\n", stage);
-    if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
-        set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
-                         op, arg1, arg2, arg0,
-                         mapped_stage,
-                         stateblock->textureState[stage][WINED3DTSS_RESULTARG]);
-    } else {
-        set_tex_op(context, (IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
-                    op, arg1, arg2, arg0);
+    if (gl_info->supported[NV_REGISTER_COMBINERS])
+    {
+        set_tex_op_nvrc((IWineD3DDevice *)stateblock->device, TRUE, stage, op, arg1, arg2, arg0,
+                mapped_stage, stateblock->textureState[stage][WINED3DTSS_RESULTARG]);
+    }
+    else
+    {
+        set_tex_op(context, (IWineD3DDevice *)stateblock->device, TRUE, stage, op, arg1, arg2, arg0);
     }
 }
@@ -3097,5 +3163,5 @@
 {
     DWORD texUnit = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[texUnit];
+    DWORD mapped_stage = stateblock->device->texUnitMap[texUnit];
     BOOL generated;
     int coordIdx;
@@ -3109,8 +3175,6 @@
 
     if (mapped_stage == WINED3D_UNMAPPED_STAGE) return;
-
-    if(mapped_stage >= GL_LIMITS(textures)) {
-        return;
-    }
+    if (mapped_stage >= context->gl_info->limits.textures) return;
+
     GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
     checkGLcall("glActiveTextureARB");
@@ -3120,8 +3184,8 @@
     set_texture_matrix(&stateblock->transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0],
             stateblock->textureState[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS], generated, context->last_was_rhw,
-            stateblock->wineD3DDevice->strided_streams.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))
-            ? stateblock->wineD3DDevice->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format_desc->format
+            stateblock->device->strided_streams.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))
+            ? stateblock->device->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format_desc->format
             : WINED3DFMT_UNKNOWN,
-            stateblock->wineD3DDevice->frag_pipe->ffp_proj_control);
+            stateblock->device->frag_pipe->ffp_proj_control);
 
     /* The sampler applying function calls us if this changes */
@@ -3144,5 +3208,6 @@
     unsigned int texture_idx;
 
-    for (texture_idx = 0; texture_idx < GL_LIMITS(texture_stages); ++texture_idx) {
+    for (texture_idx = 0; texture_idx < context->gl_info->limits.texture_stages; ++texture_idx)
+    {
         GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx));
         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -3153,12 +3218,14 @@
         const struct wined3d_stream_info *si, GLuint *curVBO)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     const UINT *offset = stateblock->streamOffset;
     unsigned int mapped_stage = 0;
     unsigned int textureNo = 0;
 
-    for (textureNo = 0; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
+    for (textureNo = 0; textureNo < gl_info->limits.texture_stages; ++textureNo)
+    {
         int coordIdx = stateblock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX];
 
-        mapped_stage = stateblock->wineD3DDevice->texUnitMap[textureNo];
+        mapped_stage = stateblock->device->texUnitMap[textureNo];
         if (mapped_stage == WINED3D_UNMAPPED_STAGE) continue;
 
@@ -3188,7 +3255,9 @@
         }
     }
-    if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
-        /* The number of the mapped stages increases monotonically, so it's fine to use the last used one */
-        for (textureNo = mapped_stage + 1; textureNo < GL_LIMITS(textures); ++textureNo) {
+    if (gl_info->supported[NV_REGISTER_COMBINERS])
+    {
+        /* The number of the mapped stages increases monotonically, so it's fine to use the last used one. */
+        for (textureNo = mapped_stage + 1; textureNo < gl_info->limits.textures; ++textureNo)
+        {
             GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1));
         }
@@ -3201,9 +3270,10 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
+    DWORD mapped_stage = stateblock->device->texUnitMap[stage];
     static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f };
     static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f };
     static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f };
     static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f };
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     if (mapped_stage == WINED3D_UNMAPPED_STAGE)
@@ -3213,5 +3283,6 @@
     }
 
-    if(mapped_stage >= GL_LIMITS(fragment_samplers)) {
+    if (mapped_stage >= gl_info->limits.fragment_samplers)
+    {
         WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage);
         return;
@@ -3271,5 +3342,5 @@
             /* Note that NV_TEXGEN_REFLECTION support is implied when
              * ARB_TEXTURE_CUBE_MAP is supported */
-            if (!GL_SUPPORT(NV_TEXGEN_REFLECTION))
+            if (!gl_info->supported[NV_TEXGEN_REFLECTION])
             {
                 FIXME("WINED3DTSS_TCI_CAMERASPACENORMAL not supported.\n");
@@ -3302,5 +3373,5 @@
             /* Note that NV_TEXGEN_REFLECTION support is implied when
              * ARB_TEXTURE_CUBE_MAP is supported */
-            if (!GL_SUPPORT(NV_TEXGEN_REFLECTION))
+            if (!gl_info->supported[NV_TEXGEN_REFLECTION])
             {
                 FIXME("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR not supported.\n");
@@ -3365,8 +3436,8 @@
          * TODO: Tidy that up to reload only the arrays of the changed unit
          */
-        GLuint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? ~0U : 0;
+        GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
 
         unloadTexCoords(context);
-        loadTexCoords(context, stateblock, &stateblock->wineD3DDevice->strided_streams, &curVBO);
+        loadTexCoords(context, stateblock, &stateblock->device->strided_streams, &curVBO);
     }
 }
@@ -3374,5 +3445,5 @@
 static void shaderconstant(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
 
     /* Vertex and pixel shader states will call a shader upload, don't do anything as long one of them
@@ -3426,5 +3497,6 @@
             if (texIsPow2) context->lastWasPow2Texture |= 1 << sampler;
             else context->lastWasPow2Texture &= ~(1 << sampler);
-            transform_texture(STATE_TEXTURESTAGE(stateblock->wineD3DDevice->texUnitMap[sampler], WINED3DTSS_TEXTURETRANSFORMFLAGS), stateblock, context);
+            transform_texture(STATE_TEXTURESTAGE(stateblock->device->texUnitMap[sampler],
+                    WINED3DTSS_TEXTURETRANSFORMFLAGS), stateblock, context);
         }
     }
@@ -3434,5 +3506,6 @@
 {
     DWORD sampler = state - STATE_SAMPLER(0);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
+    DWORD mapped_stage = stateblock->device->texUnitMap[sampler];
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     union {
         float f;
@@ -3451,5 +3524,6 @@
     }
 
-    if (mapped_stage >= GL_LIMITS(combined_samplers)) {
+    if (mapped_stage >= gl_info->limits.combined_samplers)
+    {
         return;
     }
@@ -3463,7 +3537,8 @@
         IWineD3DBaseTexture_BindTexture(stateblock->textures[sampler], srgb);
         basetexture_apply_state_changes(stateblock->textures[sampler],
-                stateblock->textureState[sampler], stateblock->samplerState[sampler]);
-
-        if (GL_SUPPORT(EXT_TEXTURE_LOD_BIAS)) {
+                stateblock->textureState[sampler], stateblock->samplerState[sampler], gl_info);
+
+        if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
+        {
             tmpvalue.d = stateblock->samplerState[sampler][WINED3DSAMP_MIPMAPLODBIAS];
             glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
@@ -3484,10 +3559,13 @@
 
         /* Trigger shader constant reloading (for NP2 texcoord fixup) */
-        if (!tex_impl->baseTexture.pow2Matrix_identity) {
-            IWineD3DDeviceImpl* d3ddevice = stateblock->wineD3DDevice;
+        if (!tex_impl->baseTexture.pow2Matrix_identity)
+        {
+            IWineD3DDeviceImpl *d3ddevice = stateblock->device;
             d3ddevice->shader_backend->shader_load_np2fixup_constants(
                 (IWineD3DDevice*)d3ddevice, use_ps(stateblock), use_vs(stateblock));
         }
-    } else if(mapped_stage < GL_LIMITS(textures)) {
+    }
+    else if (mapped_stage < gl_info->limits.textures)
+    {
         if(sampler < stateblock->lowest_disabled_stage) {
             /* TODO: What should I do with pixel shaders here ??? */
@@ -3499,6 +3577,6 @@
             }
         } /* Otherwise tex_colorop disables the stage */
-        glBindTexture(GL_TEXTURE_2D, stateblock->wineD3DDevice->dummyTextureName[sampler]);
-        checkGLcall("glBindTexture(GL_TEXTURE_2D, stateblock->wineD3DDevice->dummyTextureName[sampler])");
+        glBindTexture(GL_TEXTURE_2D, stateblock->device->dummyTextureName[sampler]);
+        checkGLcall("glBindTexture(GL_TEXTURE_2D, stateblock->device->dummyTextureName[sampler])");
     }
 }
@@ -3506,5 +3584,5 @@
 void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
     BOOL use_pshader = use_ps(stateblock);
     BOOL use_vshader = use_vs(stateblock);
@@ -3583,8 +3661,11 @@
     } else {
         /* In the general case, the view matrix is the identity matrix */
-        if (stateblock->wineD3DDevice->view_ident) {
+        if (stateblock->device->view_ident)
+        {
             glLoadMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
             checkGLcall("glLoadMatrixf");
-        } else {
+        }
+        else
+        {
             glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
             checkGLcall("glLoadMatrixf");
@@ -3599,5 +3680,6 @@
     UINT index = state - STATE_CLIPPLANE(0);
 
-    if(isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW)) || index >= GL_LIMITS(clipplanes)) {
+    if (isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW)) || index >= context->gl_info->limits.clipplanes)
+    {
         return;
     }
@@ -3636,5 +3718,6 @@
     TRACE("Setting world matrix %d\n", matrix);
 
-    if(matrix >= GL_LIMITS(blends)) {
+    if (matrix >= context->gl_info->limits.blends)
+    {
         WARN("Unsupported blend matrix set\n");
         return;
@@ -3659,8 +3742,11 @@
      * weighting the view matrix incorrectly it has to be multiplied into every gl modelview matrix
      */
-    if(stateblock->wineD3DDevice->view_ident) {
+    if (stateblock->device->view_ident)
+    {
         glLoadMatrixf(&stateblock->transforms[WINED3DTS_WORLDMATRIX(matrix)].u.m[0][0]);
         checkGLcall("glLoadMatrixf");
-    } else {
+    }
+    else
+    {
         glLoadMatrixf(&stateblock->transforms[WINED3DTS_VIEW].u.m[0][0]);
         checkGLcall("glLoadMatrixf");
@@ -3706,12 +3792,15 @@
             GL_EXTCALL(glVertexBlendARB(stateblock->renderState[WINED3DRS_VERTEXBLEND] + 1));
 
-            if(!stateblock->wineD3DDevice->vertexBlendUsed) {
+            if (!stateblock->device->vertexBlendUsed)
+            {
                 unsigned int i;
-                for(i = 1; i < GL_LIMITS(blends); i++) {
-                    if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(i)))) {
+                for (i = 1; i < context->gl_info->limits.blends; ++i)
+                {
+                    if (!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(i))))
+                    {
                         transform_worldex(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(i)), stateblock, context);
                     }
                 }
-                stateblock->wineD3DDevice->vertexBlendUsed = TRUE;
+                stateblock->device->vertexBlendUsed = TRUE;
             }
             break;
@@ -3735,4 +3824,6 @@
 static void transform_view(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+    const struct wined3d_light_info *light = NULL;
     unsigned int k;
 
@@ -3743,6 +3834,4 @@
      */
 
-    const PLIGHTINFOEL *light = NULL;
-
     glMatrixMode(GL_MODELVIEW);
     checkGLcall("glMatrixMode(GL_MODELVIEW)");
@@ -3751,5 +3840,6 @@
 
     /* Reset lights. TODO: Call light apply func */
-    for(k = 0; k < stateblock->wineD3DDevice->maxConcurrentLights; k++) {
+    for (k = 0; k < stateblock->device->maxConcurrentLights; ++k)
+    {
         light = stateblock->activeLights[k];
         if(!light) continue;
@@ -3761,5 +3851,6 @@
 
     /* Reset Clipping Planes  */
-    for (k = 0; k < GL_LIMITS(clipplanes); k++) {
+    for (k = 0; k < gl_info->limits.clipplanes; ++k)
+    {
         if(!isStateDirty(context, STATE_CLIPPLANE(k))) {
             clipplane(STATE_CLIPPLANE(k), stateblock, context);
@@ -3782,6 +3873,8 @@
 
     /* Avoid looping over a number of matrices if the app never used the functionality */
-    if(stateblock->wineD3DDevice->vertexBlendUsed) {
-        for(k = 1; k < GL_LIMITS(blends); k++) {
+    if (stateblock->device->vertexBlendUsed)
+    {
+        for (k = 1; k < gl_info->limits.blends; ++k)
+        {
             if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(k)))) {
                 transform_worldex(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(k)), stateblock, context);
@@ -3808,5 +3901,6 @@
         maxZ   = stateblock->viewport.MaxZ;
 
-        if(!stateblock->wineD3DDevice->untransformed) {
+        if (!stateblock->device->untransformed)
+        {
             /* Transformed vertices are supposed to bypass the whole transform pipeline including
              * frustum clipping. This can't be done in opengl, so this code adjusts the Z range to
@@ -3931,16 +4025,19 @@
 
 /* This should match any arrays loaded in loadVertexData.
- * stateblock impl is required for GL_SUPPORT
  * TODO: Only load / unload arrays if we have to.
  */
 static inline void unloadVertexData(const struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+
     glDisableClientState(GL_VERTEX_ARRAY);
     glDisableClientState(GL_NORMAL_ARRAY);
     glDisableClientState(GL_COLOR_ARRAY);
-    if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+    if (gl_info->supported[EXT_SECONDARY_COLOR])
+    {
         glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
     }
-    if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
+    if (gl_info->supported[ARB_VERTEX_BLEND])
+    {
         glDisableClientState(GL_WEIGHT_ARRAY_ARB);
     }
@@ -3978,5 +4075,6 @@
         const struct wined3d_stream_info *stream_info, struct wined3d_context *context)
 {
-    GLuint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? ~0U : 0;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+    GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
     int i;
     const UINT *offset = stateblock->streamOffset;
@@ -3985,5 +4083,5 @@
 
     /* Default to no instancing */
-    stateblock->wineD3DDevice->instancedDraw = FALSE;
+    stateblock->device->instancedDraw = FALSE;
 
     for (i = 0; i < MAX_ATTRIBS; i++) {
@@ -3998,5 +4096,5 @@
         {
             if (context->numbered_array_mask & (1 << i)) unload_numbered_array(stateblock, context, i);
-            stateblock->wineD3DDevice->instancedDraw = TRUE;
+            stateblock->device->instancedDraw = TRUE;
             continue;
         }
@@ -4080,5 +4178,5 @@
                     break;
                 case WINED3DFMT_B8G8R8A8_UNORM:
-                    if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA))
+                    if (gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
                     {
                         const DWORD *src = (const DWORD *)ptr;
@@ -4153,6 +4251,7 @@
         const struct wined3d_stream_info *si)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     const UINT *offset = stateblock->streamOffset;
-    GLuint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? ~0U : 0;
+    GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
     const struct wined3d_stream_info_element *e;
 
@@ -4160,5 +4259,5 @@
 
     /* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */
-    stateblock->wineD3DDevice->instancedDraw = FALSE;
+    stateblock->device->instancedDraw = FALSE;
 
     /* Blend Data ---------------------------------------------- */
@@ -4168,5 +4267,6 @@
         e = &si->elements[WINED3D_FFP_BLENDWEIGHT];
 
-        if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
+        if (gl_info->supported[ARB_VERTEX_BLEND])
+        {
             TRACE("Blend %d %p %d\n", e->format_desc->component_count,
                     e->data + stateblock->loadBaseVertexIndex * e->stride, e->stride + offset[e->stream_idx]);
@@ -4209,9 +4309,12 @@
             WARN("unsupported blending in openGl\n");
         }
-    } else {
-        if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
+    }
+    else
+    {
+        if (gl_info->supported[ARB_VERTEX_BLEND])
+        {
             static const GLbyte one = 1;
             GL_EXTCALL(glWeightbvARB(1, &one));
-            checkGLcall("glWeightivARB(GL_LIMITS(blends), weights)");
+            checkGLcall("glWeightivARB(gl_info->max_blends, weights)");
         }
     }
@@ -4321,5 +4424,6 @@
 
         e = &si->elements[WINED3D_FFP_SPECULAR];
-        if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+        if (gl_info->supported[EXT_SECONDARY_COLOR])
+        {
             GLenum type = e->format_desc->gl_vtx_type;
             GLint format = e->format_desc->gl_vtx_format;
@@ -4332,5 +4436,5 @@
             }
 
-            if(format != 4 || (GLINFO_LOCATION.quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
+            if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
             {
                 /* Usually specular colors only allow 3 components, since they have no alpha. In D3D, the specular alpha
@@ -4368,7 +4472,9 @@
         VTRACE(("Specular colour is not supported in this GL implementation\n"));
         }
-
-    } else {
-        if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+    }
+    else
+    {
+        if (gl_info->supported[EXT_SECONDARY_COLOR])
+        {
             GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
             checkGLcall("glSecondaryColor3fEXT(0, 0, 0)");
@@ -4403,11 +4509,10 @@
     TRACE_STRIDED((dataLocations), WINED3D_FFP_TEXCOORD6);
     TRACE_STRIDED((dataLocations), WINED3D_FFP_TEXCOORD7);
-
-    return;
 }
 
 static void streamsrc(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+    IWineD3DDeviceImpl *device = stateblock->device;
     BOOL fixup = FALSE;
     struct wined3d_stream_info *dataLocations = &device->strided_streams;
@@ -4421,5 +4526,5 @@
         /* Note: this is a ddraw fixed-function code path */
         TRACE("================ Strided Input ===================\n");
-        device_stream_info_from_strided(device, device->up_strided, dataLocations);
+        device_stream_info_from_strided(gl_info, device->up_strided, dataLocations);
 
         if(TRACE_ON(d3d)) {
@@ -4450,5 +4555,6 @@
     {
         WORD slow_mask = (1 << WINED3D_FFP_PSIZE);
-        slow_mask |= -!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA) & ((1 << WINED3D_FFP_DIFFUSE) | (1 << WINED3D_FFP_SPECULAR));
+        slow_mask |= -!gl_info->supported[EXT_VERTEX_ARRAY_BGRA]
+                & ((1 << WINED3D_FFP_DIFFUSE) | (1 << WINED3D_FFP_SPECULAR));
 
         if (fixup || (!dataLocations->position_transformed
@@ -4494,10 +4600,10 @@
 static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     BOOL updateFog = FALSE;
     BOOL useVertexShaderFunction = use_vs(stateblock);
     BOOL usePixelShaderFunction = use_ps(stateblock);
+    IWineD3DDeviceImpl *device = stateblock->device;
     BOOL transformed;
-    /* Some stuff is in the device until we have per context tracking */
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
     BOOL wasrhw = context->last_was_rhw;
     unsigned int i;
@@ -4575,5 +4681,6 @@
                 state_clipping(STATE_RENDER(WINED3DRS_CLIPPLANEENABLE), stateblock, context);
             }
-            for(i = 0; i < GL_LIMITS(clipplanes); i++) {
+            for (i = 0; i < gl_info->limits.clipplanes; ++i)
+            {
                 clipplane(STATE_CLIPPLANE(i), stateblock, context);
             }
@@ -4589,5 +4696,6 @@
                  * state_clipping state handler
                  */
-                for(i = 0; i < GL_LIMITS(clipplanes); i++) {
+                for (i = 0; i < gl_info->limits.clipplanes; ++i)
+                {
                     glDisable(GL_CLIP_PLANE0 + i);
                     checkGLcall("glDisable(GL_CLIP_PLANE0 + i)");
@@ -4618,5 +4726,6 @@
              * device->vs_clipping is false.
              */
-            for(i = 0; i < GL_LIMITS(clipplanes); i++) {
+            for (i = 0; i < gl_info->limits.clipplanes; ++i)
+            {
                 clipplane(STATE_CLIPPLANE(i), stateblock, context);
             }
@@ -4652,8 +4761,12 @@
 static void viewport_miscpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *)stateblock->device->render_targets[0];
     UINT width, height;
-    IWineD3DSurfaceImpl *target;
-
-    glDepthRange(stateblock->viewport.MinZ, stateblock->viewport.MaxZ);
+    WINED3DVIEWPORT vp = stateblock->viewport;
+
+    if(vp.Width > target->currentDesc.Width) vp.Width = target->currentDesc.Width;
+    if(vp.Height > target->currentDesc.Height) vp.Height = target->currentDesc.Height;
+
+    glDepthRange(vp.MinZ, vp.MaxZ);
     checkGLcall("glDepthRange");
     /* Note: GL requires lower left, DirectX supplies upper left. This is reversed when using offscreen rendering
@@ -4661,14 +4774,11 @@
     if (context->render_offscreen)
     {
-        glViewport(stateblock->viewport.X,
-                   stateblock->viewport.Y,
-                   stateblock->viewport.Width, stateblock->viewport.Height);
+        glViewport(vp.X, vp.Y, vp.Width, vp.Height);
     } else {
-        target = (IWineD3DSurfaceImpl *) stateblock->wineD3DDevice->render_targets[0];
         target->get_drawable_size(context, &width, &height);
 
-        glViewport(stateblock->viewport.X,
-                   (height - (stateblock->viewport.Y + stateblock->viewport.Height)),
-                   stateblock->viewport.Width, stateblock->viewport.Height);
+        glViewport(vp.X,
+                   (height - (vp.Y + vp.Height)),
+                   vp.Width, vp.Height);
     }
 
@@ -4680,6 +4790,6 @@
     GLfloat yoffset = -(63.0f / 64.0f) / stateblock->viewport.Height;
 
-    stateblock->wineD3DDevice->posFixup[2] = (63.0f / 64.0f) / stateblock->viewport.Width;
-    stateblock->wineD3DDevice->posFixup[3] = stateblock->wineD3DDevice->posFixup[1] * yoffset;
+    stateblock->device->posFixup[2] = (63.0f / 64.0f) / stateblock->viewport.Width;
+    stateblock->device->posFixup[3] = stateblock->device->posFixup[1] * yoffset;
 
     if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
@@ -4694,5 +4804,5 @@
 {
     UINT Index = state - STATE_ACTIVELIGHT(0);
-    const PLIGHTINFOEL *lightInfo = stateblock->activeLights[Index];
+    const struct wined3d_light_info *lightInfo = stateblock->activeLights[Index];
 
     if(!lightInfo) {
@@ -4803,14 +4913,12 @@
         checkGLcall("glEnable(GL_LIGHT0 + Index)");
     }
-
-    return;
 }
 
 static void scissorrect(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
+    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *)stateblock->device->render_targets[0];
     RECT *pRect = &stateblock->scissorRect;
     UINT height;
     UINT width;
-    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *) stateblock->wineD3DDevice->render_targets[0];
 
     target->get_drawable_size(context, &width, &height);
@@ -4818,5 +4926,5 @@
      * Warning2: Even in windowed mode the coords are relative to the window, not the screen
      */
-    TRACE("(%p) Setting new Scissor Rect to %d:%d-%d:%d\n", stateblock->wineD3DDevice, pRect->left, pRect->bottom - height,
+    TRACE("(%p) Setting new Scissor Rect to %d:%d-%d:%d\n", stateblock->device, pRect->left, pRect->bottom - height,
           pRect->right - pRect->left, pRect->bottom - pRect->top);
 
@@ -5534,5 +5642,4 @@
 #undef GLINFO_LOCATION
 
-#define GLINFO_LOCATION (*gl_info)
 /* Context activation is done by the caller. */
 static void ffp_enable(IWineD3DDevice *iface, BOOL enable) { }
@@ -5551,7 +5658,8 @@
                             WINED3DTEXOPCAPS_DISABLE;
 
-    if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE) ||
-        GL_SUPPORT(EXT_TEXTURE_ENV_COMBINE) ||
-        GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
+    if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE]
+            || gl_info->supported[EXT_TEXTURE_ENV_COMBINE]
+            || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
+    {
         pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA  |
                                 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA  |
@@ -5561,6 +5669,7 @@
                                 WINED3DTEXOPCAPS_SUBTRACT;
     }
-    if (GL_SUPPORT(ATI_TEXTURE_ENV_COMBINE3) ||
-        GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
+    if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]
+            || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
+    {
         pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_ADDSMOOTH              |
                                 WINED3DTEXOPCAPS_MULTIPLYADD            |
@@ -5569,9 +5678,9 @@
                                 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
     }
-    if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3))
+    if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
         pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_DOTPRODUCT3;
 
-    pCaps->MaxTextureBlendStages   = GL_LIMITS(texture_stages);
-    pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
+    pCaps->MaxTextureBlendStages = gl_info->limits.texture_stages;
+    pCaps->MaxSimultaneousTextures = gl_info->limits.textures;
 }
 
@@ -5616,13 +5725,13 @@
 static void multistate_apply_2(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    stateblock->wineD3DDevice->multistate_funcs[state][0](state, stateblock, context);
-    stateblock->wineD3DDevice->multistate_funcs[state][1](state, stateblock, context);
+    stateblock->device->multistate_funcs[state][0](state, stateblock, context);
+    stateblock->device->multistate_funcs[state][1](state, stateblock, context);
 }
 
 static void multistate_apply_3(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    stateblock->wineD3DDevice->multistate_funcs[state][0](state, stateblock, context);
-    stateblock->wineD3DDevice->multistate_funcs[state][1](state, stateblock, context);
-    stateblock->wineD3DDevice->multistate_funcs[state][2](state, stateblock, context);
+    stateblock->device->multistate_funcs[state][0](state, stateblock, context);
+    stateblock->device->multistate_funcs[state][1](state, stateblock, context);
+    stateblock->device->multistate_funcs[state][2](state, stateblock, context);
 }
 
@@ -5670,5 +5779,5 @@
             if(set[cur[i].state]) continue;
             /* Skip state lines depending on unsupported extensions */
-            if (!GL_SUPPORT(cur[i].extension)) continue;
+            if (!gl_info->supported[cur[i].extension]) continue;
             set[cur[i].state] = TRUE;
             /* In some cases having an extension means that nothing has to be
@@ -5737,3 +5846,2 @@
     return E_OUTOFMEMORY;
 }
-#undef GLINFO_LOCATION
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c	(revision 25949)
@@ -6,4 +6,5 @@
  * Copyright 2005 Oliver Stieber
  * Copyright 2007 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -35,34 +36,196 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
-#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
-
-/***************************************
- * Stateblock helper functions follow
- **************************************/
+
+static const DWORD pixel_states_render[] =
+{
+    WINED3DRS_ALPHABLENDENABLE,
+    WINED3DRS_ALPHAFUNC,
+    WINED3DRS_ALPHAREF,
+    WINED3DRS_ALPHATESTENABLE,
+    WINED3DRS_ANTIALIASEDLINEENABLE,
+    WINED3DRS_BLENDFACTOR,
+    WINED3DRS_BLENDOP,
+    WINED3DRS_BLENDOPALPHA,
+    WINED3DRS_CCW_STENCILFAIL,
+    WINED3DRS_CCW_STENCILPASS,
+    WINED3DRS_CCW_STENCILZFAIL,
+    WINED3DRS_COLORWRITEENABLE,
+    WINED3DRS_COLORWRITEENABLE1,
+    WINED3DRS_COLORWRITEENABLE2,
+    WINED3DRS_COLORWRITEENABLE3,
+    WINED3DRS_DEPTHBIAS,
+    WINED3DRS_DESTBLEND,
+    WINED3DRS_DESTBLENDALPHA,
+    WINED3DRS_DITHERENABLE,
+    WINED3DRS_FILLMODE,
+    WINED3DRS_FOGDENSITY,
+    WINED3DRS_FOGEND,
+    WINED3DRS_FOGSTART,
+    WINED3DRS_LASTPIXEL,
+    WINED3DRS_SCISSORTESTENABLE,
+    WINED3DRS_SEPARATEALPHABLENDENABLE,
+    WINED3DRS_SHADEMODE,
+    WINED3DRS_SLOPESCALEDEPTHBIAS,
+    WINED3DRS_SRCBLEND,
+    WINED3DRS_SRCBLENDALPHA,
+    WINED3DRS_SRGBWRITEENABLE,
+    WINED3DRS_STENCILENABLE,
+    WINED3DRS_STENCILFAIL,
+    WINED3DRS_STENCILFUNC,
+    WINED3DRS_STENCILMASK,
+    WINED3DRS_STENCILPASS,
+    WINED3DRS_STENCILREF,
+    WINED3DRS_STENCILWRITEMASK,
+    WINED3DRS_STENCILZFAIL,
+    WINED3DRS_TEXTUREFACTOR,
+    WINED3DRS_TWOSIDEDSTENCILMODE,
+    WINED3DRS_WRAP0,
+    WINED3DRS_WRAP1,
+    WINED3DRS_WRAP10,
+    WINED3DRS_WRAP11,
+    WINED3DRS_WRAP12,
+    WINED3DRS_WRAP13,
+    WINED3DRS_WRAP14,
+    WINED3DRS_WRAP15,
+    WINED3DRS_WRAP2,
+    WINED3DRS_WRAP3,
+    WINED3DRS_WRAP4,
+    WINED3DRS_WRAP5,
+    WINED3DRS_WRAP6,
+    WINED3DRS_WRAP7,
+    WINED3DRS_WRAP8,
+    WINED3DRS_WRAP9,
+    WINED3DRS_ZENABLE,
+    WINED3DRS_ZFUNC,
+    WINED3DRS_ZWRITEENABLE,
+};
+
+static const DWORD pixel_states_texture[] =
+{
+    WINED3DTSS_ALPHAARG0,
+    WINED3DTSS_ALPHAARG1,
+    WINED3DTSS_ALPHAARG2,
+    WINED3DTSS_ALPHAOP,
+    WINED3DTSS_BUMPENVLOFFSET,
+    WINED3DTSS_BUMPENVLSCALE,
+    WINED3DTSS_BUMPENVMAT00,
+    WINED3DTSS_BUMPENVMAT01,
+    WINED3DTSS_BUMPENVMAT10,
+    WINED3DTSS_BUMPENVMAT11,
+    WINED3DTSS_COLORARG0,
+    WINED3DTSS_COLORARG1,
+    WINED3DTSS_COLORARG2,
+    WINED3DTSS_COLOROP,
+    WINED3DTSS_RESULTARG,
+    WINED3DTSS_TEXCOORDINDEX,
+    WINED3DTSS_TEXTURETRANSFORMFLAGS,
+};
+
+static const DWORD pixel_states_sampler[] =
+{
+    WINED3DSAMP_ADDRESSU,
+    WINED3DSAMP_ADDRESSV,
+    WINED3DSAMP_ADDRESSW,
+    WINED3DSAMP_BORDERCOLOR,
+    WINED3DSAMP_MAGFILTER,
+    WINED3DSAMP_MINFILTER,
+    WINED3DSAMP_MIPFILTER,
+    WINED3DSAMP_MIPMAPLODBIAS,
+    WINED3DSAMP_MAXMIPLEVEL,
+    WINED3DSAMP_MAXANISOTROPY,
+    WINED3DSAMP_SRGBTEXTURE,
+    WINED3DSAMP_ELEMENTINDEX,
+};
+
+static const DWORD vertex_states_render[] =
+{
+    WINED3DRS_ADAPTIVETESS_W,
+    WINED3DRS_ADAPTIVETESS_X,
+    WINED3DRS_ADAPTIVETESS_Y,
+    WINED3DRS_ADAPTIVETESS_Z,
+    WINED3DRS_AMBIENT,
+    WINED3DRS_AMBIENTMATERIALSOURCE,
+    WINED3DRS_CLIPPING,
+    WINED3DRS_CLIPPLANEENABLE,
+    WINED3DRS_COLORVERTEX,
+    WINED3DRS_CULLMODE,
+    WINED3DRS_DIFFUSEMATERIALSOURCE,
+    WINED3DRS_EMISSIVEMATERIALSOURCE,
+    WINED3DRS_ENABLEADAPTIVETESSELLATION,
+    WINED3DRS_FOGCOLOR,
+    WINED3DRS_FOGDENSITY,
+    WINED3DRS_FOGENABLE,
+    WINED3DRS_FOGEND,
+    WINED3DRS_FOGSTART,
+    WINED3DRS_FOGTABLEMODE,
+    WINED3DRS_FOGVERTEXMODE,
+    WINED3DRS_INDEXEDVERTEXBLENDENABLE,
+    WINED3DRS_LIGHTING,
+    WINED3DRS_LOCALVIEWER,
+    WINED3DRS_MAXTESSELLATIONLEVEL,
+    WINED3DRS_MINTESSELLATIONLEVEL,
+    WINED3DRS_MULTISAMPLEANTIALIAS,
+    WINED3DRS_MULTISAMPLEMASK,
+    WINED3DRS_NORMALDEGREE,
+    WINED3DRS_NORMALIZENORMALS,
+    WINED3DRS_PATCHEDGESTYLE,
+    WINED3DRS_POINTSCALE_A,
+    WINED3DRS_POINTSCALE_B,
+    WINED3DRS_POINTSCALE_C,
+    WINED3DRS_POINTSCALEENABLE,
+    WINED3DRS_POINTSIZE,
+    WINED3DRS_POINTSIZE_MAX,
+    WINED3DRS_POINTSIZE_MIN,
+    WINED3DRS_POINTSPRITEENABLE,
+    WINED3DRS_POSITIONDEGREE,
+    WINED3DRS_RANGEFOGENABLE,
+    WINED3DRS_SHADEMODE,
+    WINED3DRS_SPECULARENABLE,
+    WINED3DRS_SPECULARMATERIALSOURCE,
+    WINED3DRS_TWEENFACTOR,
+    WINED3DRS_VERTEXBLEND,
+};
+
+static const DWORD vertex_states_texture[] =
+{
+    WINED3DTSS_TEXCOORDINDEX,
+    WINED3DTSS_TEXTURETRANSFORMFLAGS,
+};
+
+static const DWORD vertex_states_sampler[] =
+{
+    WINED3DSAMP_DMAPOFFSET,
+};
 
 /* Allocates the correct amount of space for pixel and vertex shader constants,
  * along with their set/changed flags on the given stateblock object
  */
-HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object)
-{
-    IWineD3DStateBlockImpl *This = object;
+static HRESULT stateblock_allocate_shader_constants(IWineD3DStateBlockImpl *object)
+{
+    IWineD3DDeviceImpl *device = object->device;
 
     /* Allocate space for floating point constants */
-    object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
+    object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+            sizeof(float) * device->d3d_pshader_constantF * 4);
     if (!object->pixelShaderConstantF) goto fail;
 
-    object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(pshader_constantsF));
+    object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+            sizeof(BOOL) * device->d3d_pshader_constantF);
     if (!object->changed.pixelShaderConstantsF) goto fail;
 
-    object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
+    object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+            sizeof(float) * device->d3d_vshader_constantF * 4);
     if (!object->vertexShaderConstantF) goto fail;
 
-    object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
+    object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+            sizeof(BOOL) * device->d3d_vshader_constantF);
     if (!object->changed.vertexShaderConstantsF) goto fail;
 
-    object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
+    object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0,
+            sizeof(DWORD) * device->d3d_vshader_constantF);
     if (!object->contained_vs_consts_f) goto fail;
 
-    object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
+    object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0,
+            sizeof(DWORD) * device->d3d_pshader_constantF);
     if (!object->contained_ps_consts_f) goto fail;
 
@@ -80,39 +243,4 @@
 }
 
-/** Copy all members of one stateblock to another */
-static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES *dest, const SAVEDSTATES *source)
-{
-    IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
-    unsigned bsize = sizeof(BOOL);
-
-    /* Single values */
-    dest->primitive_type = source->primitive_type;
-    dest->indices = source->indices;
-    dest->material = source->material;
-    dest->viewport = source->viewport;
-    dest->vertexDecl = source->vertexDecl;
-    dest->pixelShader = source->pixelShader;
-    dest->vertexShader = source->vertexShader;
-    dest->scissorRect = dest->scissorRect;
-
-    /* Fixed size arrays */
-    dest->streamSource = source->streamSource;
-    dest->streamFreq = source->streamFreq;
-    dest->textures = source->textures;
-    memcpy(dest->transform, source->transform, sizeof(source->transform));
-    memcpy(dest->renderState, source->renderState, sizeof(source->renderState));
-    memcpy(dest->textureState, source->textureState, sizeof(source->textureState));
-    memcpy(dest->samplerState, source->samplerState, sizeof(source->samplerState));
-    dest->clipplane = source->clipplane;
-    dest->pixelShaderConstantsB = source->pixelShaderConstantsB;
-    dest->pixelShaderConstantsI = source->pixelShaderConstantsI;
-    dest->vertexShaderConstantsB = source->vertexShaderConstantsB;
-    dest->vertexShaderConstantsI = source->vertexShaderConstantsI;
-
-    /* Dynamically sized arrays */
-    memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
-    memcpy(dest->vertexShaderConstantsF, source->vertexShaderConstantsF, bsize * GL_LIMITS(vshader_constantsF));
-}
-
 static inline void stateblock_set_bits(DWORD *map, UINT map_size)
 {
@@ -122,133 +250,219 @@
 }
 
-/** Set all members of a stateblock savedstate to the given value */
-void stateblock_savedstates_set(IWineD3DStateBlock *iface, SAVEDSTATES *states, BOOL value)
-{
-    IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
-    unsigned bsize = sizeof(BOOL);
+/* Set all members of a stateblock savedstate to the given value */
+static void stateblock_savedstates_set_all(SAVEDSTATES *states, DWORD vs_consts, DWORD ps_consts)
+{
+    unsigned int i;
 
     /* Single values */
-    states->primitive_type = value;
-    states->indices = value;
-    states->material = value;
-    states->viewport = value;
-    states->vertexDecl = value;
-    states->pixelShader = value;
-    states->vertexShader = value;
-    states->scissorRect = value;
+    states->primitive_type = 1;
+    states->indices = 1;
+    states->material = 1;
+    states->viewport = 1;
+    states->vertexDecl = 1;
+    states->pixelShader = 1;
+    states->vertexShader = 1;
+    states->scissorRect = 1;
 
     /* Fixed size arrays */
-    if (value)
-    {
-        int i;
-        states->streamSource = 0xffff;
-        states->streamFreq = 0xffff;
-        states->textures = 0xfffff;
-        stateblock_set_bits(states->transform, HIGHEST_TRANSFORMSTATE + 1);
-        stateblock_set_bits(states->renderState, WINEHIGHEST_RENDER_STATE + 1);
-        for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = 0x3ffff;
-        for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = 0x3fff;
-        states->clipplane = 0xffffffff;
-        states->pixelShaderConstantsB = 0xffff;
-        states->pixelShaderConstantsI = 0xffff;
-        states->vertexShaderConstantsB = 0xffff;
-        states->vertexShaderConstantsI = 0xffff;
-    }
-    else
-    {
-        states->streamSource = 0;
-        states->streamFreq = 0;
-        states->textures = 0;
-        memset(states->transform, 0, sizeof(states->transform));
-        memset(states->renderState, 0, sizeof(states->renderState));
-        memset(states->textureState, 0, sizeof(states->textureState));
-        memset(states->samplerState, 0, sizeof(states->samplerState));
-        states->clipplane = 0;
-        states->pixelShaderConstantsB = 0;
-        states->pixelShaderConstantsI = 0;
-        states->vertexShaderConstantsB = 0;
-        states->vertexShaderConstantsI = 0;
-    }
+    states->streamSource = 0xffff;
+    states->streamFreq = 0xffff;
+    states->textures = 0xfffff;
+    stateblock_set_bits(states->transform, HIGHEST_TRANSFORMSTATE + 1);
+    stateblock_set_bits(states->renderState, WINEHIGHEST_RENDER_STATE + 1);
+    for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = 0x3ffff;
+    for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = 0x3fff;
+    states->clipplane = 0xffffffff;
+    states->pixelShaderConstantsB = 0xffff;
+    states->pixelShaderConstantsI = 0xffff;
+    states->vertexShaderConstantsB = 0xffff;
+    states->vertexShaderConstantsI = 0xffff;
 
     /* Dynamically sized arrays */
-    memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF));
-    memset(states->vertexShaderConstantsF, value, bsize * GL_LIMITS(vshader_constantsF));
-}
-
-void stateblock_copy(
-    IWineD3DStateBlock* destination,
-    IWineD3DStateBlock* source) {
-    int l;
-
-    IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)source;
-    IWineD3DStateBlockImpl *Dest = (IWineD3DStateBlockImpl *)destination;
-
-    /* IUnknown fields */
-    Dest->lpVtbl                = This->lpVtbl;
-    Dest->ref                   = This->ref;
-
-    /* IWineD3DStateBlock information */
-    Dest->parent                = This->parent;
-    Dest->wineD3DDevice         = This->wineD3DDevice;
-    Dest->blockType             = This->blockType;
-
-    /* Saved states */
-    stateblock_savedstates_copy(source, &Dest->changed, &This->changed);
-
-    /* Single items */
-    Dest->gl_primitive_type = This->gl_primitive_type;
-    Dest->vertexDecl = This->vertexDecl;
-    Dest->vertexShader = This->vertexShader;
-    Dest->streamIsUP = This->streamIsUP;
-    Dest->pIndexData = This->pIndexData;
-    Dest->IndexFmt = This->IndexFmt;
-    Dest->baseVertexIndex = This->baseVertexIndex;
-    /* Dest->lights = This->lights; */
-    Dest->clip_status = This->clip_status;
-    Dest->viewport = This->viewport;
-    Dest->material = This->material;
-    Dest->pixelShader = This->pixelShader;
-    Dest->scissorRect = This->scissorRect;
-
-    /* Lights */
-    memset(This->activeLights, 0, sizeof(This->activeLights));
-    for(l = 0; l < LIGHTMAP_SIZE; l++) {
-        struct list *e1, *e2;
-        LIST_FOR_EACH_SAFE(e1, e2, &Dest->lightMap[l]) {
-            PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
-            list_remove(&light->entry);
-            HeapFree(GetProcessHeap(), 0, light);
-        }
-
-        LIST_FOR_EACH(e1, &This->lightMap[l]) {
-            PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry), *light2;
-            light2 = HeapAlloc(GetProcessHeap(), 0, sizeof(*light));
-            *light2 = *light;
-            list_add_tail(&Dest->lightMap[l], &light2->entry);
-            if(light2->glIndex != -1) Dest->activeLights[light2->glIndex] = light2;
-        }
-    }
-
-    /* Fixed size arrays */
-    memcpy(Dest->vertexShaderConstantB, This->vertexShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
-    memcpy(Dest->vertexShaderConstantI, This->vertexShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
-    memcpy(Dest->pixelShaderConstantB, This->pixelShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
-    memcpy(Dest->pixelShaderConstantI, This->pixelShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
-
-    memcpy(Dest->streamStride, This->streamStride, sizeof(UINT) * MAX_STREAMS);
-    memcpy(Dest->streamOffset, This->streamOffset, sizeof(UINT) * MAX_STREAMS);
-    memcpy(Dest->streamSource, This->streamSource, sizeof(IWineD3DBuffer *) * MAX_STREAMS);
-    memcpy(Dest->streamFreq,   This->streamFreq,   sizeof(UINT) * MAX_STREAMS);
-    memcpy(Dest->streamFlags,  This->streamFlags,  sizeof(UINT) * MAX_STREAMS);
-    memcpy(Dest->transforms,   This->transforms,   sizeof(WINED3DMATRIX) * (HIGHEST_TRANSFORMSTATE + 1));
-    memcpy(Dest->clipplane,    This->clipplane,    sizeof(double) * MAX_CLIPPLANES * 4);
-    memcpy(Dest->renderState,  This->renderState,  sizeof(DWORD) * (WINEHIGHEST_RENDER_STATE + 1));
-    memcpy(Dest->textures,     This->textures,     sizeof(IWineD3DBaseTexture*) * MAX_COMBINED_SAMPLERS);
-    memcpy(Dest->textureState, This->textureState, sizeof(DWORD) * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
-    memcpy(Dest->samplerState, This->samplerState, sizeof(DWORD) * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
-
-    /* Dynamically sized arrays */
-    memcpy(Dest->vertexShaderConstantF, This->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
-    memcpy(Dest->pixelShaderConstantF,  This->pixelShaderConstantF,  sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
+    memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * ps_consts);
+    memset(states->vertexShaderConstantsF, TRUE, sizeof(BOOL) * vs_consts);
+}
+
+static void stateblock_savedstates_set_pixel(SAVEDSTATES *states, const DWORD num_constants)
+{
+    DWORD texture_mask = 0;
+    WORD sampler_mask = 0;
+    unsigned int i;
+
+    states->pixelShader = 1;
+
+    for (i = 0; i < sizeof(pixel_states_render) / sizeof(*pixel_states_render); ++i)
+    {
+        DWORD rs = pixel_states_render[i];
+        states->renderState[rs >> 5] |= 1 << (rs & 0x1f);
+    }
+
+    for (i = 0; i < sizeof(pixel_states_texture) / sizeof(*pixel_states_texture); ++i)
+        texture_mask |= 1 << pixel_states_texture[i];
+    for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = texture_mask;
+    for (i = 0; i < sizeof(pixel_states_sampler) / sizeof(*pixel_states_sampler); ++i)
+        sampler_mask |= 1 << pixel_states_sampler[i];
+    for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = sampler_mask;
+    states->pixelShaderConstantsB = 0xffff;
+    states->pixelShaderConstantsI = 0xffff;
+
+    memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * num_constants);
+}
+
+static void stateblock_savedstates_set_vertex(SAVEDSTATES *states, const DWORD num_constants)
+{
+    DWORD texture_mask = 0;
+    WORD sampler_mask = 0;
+    unsigned int i;
+
+    states->vertexDecl = 1;
+    states->vertexShader = 1;
+
+    for (i = 0; i < sizeof(vertex_states_render) / sizeof(*vertex_states_render); ++i)
+    {
+        DWORD rs = vertex_states_render[i];
+        states->renderState[rs >> 5] |= 1 << (rs & 0x1f);
+    }
+
+    for (i = 0; i < sizeof(vertex_states_texture) / sizeof(*vertex_states_texture); ++i)
+        texture_mask |= 1 << vertex_states_texture[i];
+    for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = texture_mask;
+    for (i = 0; i < sizeof(vertex_states_sampler) / sizeof(*vertex_states_sampler); ++i)
+        sampler_mask |= 1 << vertex_states_sampler[i];
+    for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = sampler_mask;
+    states->vertexShaderConstantsB = 0xffff;
+    states->vertexShaderConstantsI = 0xffff;
+
+    memset(states->vertexShaderConstantsF, TRUE, sizeof(BOOL) * num_constants);
+}
+
+void stateblock_init_contained_states(IWineD3DStateBlockImpl *stateblock)
+{
+    IWineD3DDeviceImpl *device = stateblock->device;
+    unsigned int i, j;
+
+    for (i = 0; i <= WINEHIGHEST_RENDER_STATE >> 5; ++i)
+    {
+        DWORD map = stateblock->changed.renderState[i];
+        for (j = 0; map; map >>= 1, ++j)
+        {
+            if (!(map & 1)) continue;
+
+            stateblock->contained_render_states[stateblock->num_contained_render_states] = (i << 5) | j;
+            ++stateblock->num_contained_render_states;
+        }
+    }
+
+    for (i = 0; i <= HIGHEST_TRANSFORMSTATE >> 5; ++i)
+    {
+        DWORD map = stateblock->changed.transform[i];
+        for (j = 0; map; map >>= 1, ++j)
+        {
+            if (!(map & 1)) continue;
+
+            stateblock->contained_transform_states[stateblock->num_contained_transform_states] = (i << 5) | j;
+            ++stateblock->num_contained_transform_states;
+        }
+    }
+
+    for (i = 0; i < device->d3d_vshader_constantF; ++i)
+    {
+        if (stateblock->changed.vertexShaderConstantsF[i])
+        {
+            stateblock->contained_vs_consts_f[stateblock->num_contained_vs_consts_f] = i;
+            ++stateblock->num_contained_vs_consts_f;
+        }
+    }
+
+    for (i = 0; i < MAX_CONST_I; ++i)
+    {
+        if (stateblock->changed.vertexShaderConstantsI & (1 << i))
+        {
+            stateblock->contained_vs_consts_i[stateblock->num_contained_vs_consts_i] = i;
+            ++stateblock->num_contained_vs_consts_i;
+        }
+    }
+
+    for (i = 0; i < MAX_CONST_B; ++i)
+    {
+        if (stateblock->changed.vertexShaderConstantsB & (1 << i))
+        {
+            stateblock->contained_vs_consts_b[stateblock->num_contained_vs_consts_b] = i;
+            ++stateblock->num_contained_vs_consts_b;
+        }
+    }
+
+    for (i = 0; i < device->d3d_pshader_constantF; ++i)
+    {
+        if (stateblock->changed.pixelShaderConstantsF[i])
+        {
+            stateblock->contained_ps_consts_f[stateblock->num_contained_ps_consts_f] = i;
+            ++stateblock->num_contained_ps_consts_f;
+        }
+    }
+
+    for (i = 0; i < MAX_CONST_I; ++i)
+    {
+        if (stateblock->changed.pixelShaderConstantsI & (1 << i))
+        {
+            stateblock->contained_ps_consts_i[stateblock->num_contained_ps_consts_i] = i;
+            ++stateblock->num_contained_ps_consts_i;
+        }
+    }
+
+    for (i = 0; i < MAX_CONST_B; ++i)
+    {
+        if (stateblock->changed.pixelShaderConstantsB & (1 << i))
+        {
+            stateblock->contained_ps_consts_b[stateblock->num_contained_ps_consts_b] = i;
+            ++stateblock->num_contained_ps_consts_b;
+        }
+    }
+
+    for (i = 0; i < MAX_TEXTURES; ++i)
+    {
+        DWORD map = stateblock->changed.textureState[i];
+
+        for(j = 0; map; map >>= 1, ++j)
+        {
+            if (!(map & 1)) continue;
+
+            stateblock->contained_tss_states[stateblock->num_contained_tss_states].stage = i;
+            stateblock->contained_tss_states[stateblock->num_contained_tss_states].state = j;
+            ++stateblock->num_contained_tss_states;
+        }
+    }
+
+    for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
+    {
+        DWORD map = stateblock->changed.samplerState[i];
+
+        for (j = 0; map; map >>= 1, ++j)
+        {
+            if (!(map & 1)) continue;
+
+            stateblock->contained_sampler_states[stateblock->num_contained_sampler_states].stage = i;
+            stateblock->contained_sampler_states[stateblock->num_contained_sampler_states].state = j;
+            ++stateblock->num_contained_sampler_states;
+        }
+    }
+}
+
+static void stateblock_init_lights(IWineD3DStateBlockImpl *stateblock, struct list *light_map)
+{
+    unsigned int i;
+
+    for (i = 0; i < LIGHTMAP_SIZE; ++i)
+    {
+        const struct wined3d_light_info *src_light;
+
+        LIST_FOR_EACH_ENTRY(src_light, &light_map[i], struct wined3d_light_info, entry)
+        {
+            struct wined3d_light_info *dst_light = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_light));
+
+            *dst_light = *src_light;
+            list_add_tail(&stateblock->lightMap[i], &dst_light->entry);
+        }
+    }
 }
 
@@ -261,6 +475,6 @@
     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
     if (IsEqualGUID(riid, &IID_IUnknown)
-        || IsEqualGUID(riid, &IID_IWineD3DBase)
-        || IsEqualGUID(riid, &IID_IWineD3DStateBlock)){
+            || IsEqualGUID(riid, &IID_IWineD3DStateBlock))
+    {
         IUnknown_AddRef(iface);
         *ppobj = This;
@@ -288,15 +502,9 @@
         int counter;
 
-        /* type 0 represents the primary stateblock, so free all the resources */
-        if (This->blockType == WINED3DSBT_INIT) {
-            /* NOTE: according to MSDN: The application is responsible for making sure the texture references are cleared down */
-            for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++) {
-                if (This->textures[counter]) {
-                    /* release our 'internal' hold on the texture */
-                    if(0 != IWineD3DBaseTexture_Release(This->textures[counter])) {
-                        TRACE("Texture still referenced by stateblock, applications has leaked Stage = %u Texture = %p\n", counter, This->textures[counter]);
-                    }
-                }
-            }
+        if (This->vertexDecl) IWineD3DVertexDeclaration_Release(This->vertexDecl);
+
+        for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++)
+        {
+            if (This->textures[counter]) IWineD3DBaseTexture_Release(This->textures[counter]);
         }
 
@@ -315,6 +523,7 @@
         for(counter = 0; counter < LIGHTMAP_SIZE; counter++) {
             struct list *e1, *e2;
-            LIST_FOR_EACH_SAFE(e1, e2, &This->lightMap[counter]) {
-                PLIGHTINFOEL *light = LIST_ENTRY(e1, PLIGHTINFOEL, entry);
+            LIST_FOR_EACH_SAFE(e1, e2, &This->lightMap[counter])
+            {
+                struct wined3d_light_info *light = LIST_ENTRY(e1, struct wined3d_light_info, entry);
                 list_remove(&light->entry);
                 HeapFree(GetProcessHeap(), 0, light);
@@ -336,22 +545,6 @@
  * IWineD3DStateBlockImpl parts follows
  **********************************************************/
-static HRESULT  WINAPI IWineD3DStateBlockImpl_GetParent(IWineD3DStateBlock *iface, IUnknown **pParent) {
-    IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
-    IUnknown_AddRef(This->parent);
-    *pParent = This->parent;
-    return WINED3D_OK;
-}
-
-static HRESULT  WINAPI IWineD3DStateBlockImpl_GetDevice(IWineD3DStateBlock *iface, IWineD3DDevice** ppDevice){
-
-    IWineD3DStateBlockImpl *This   = (IWineD3DStateBlockImpl *)iface;
-
-    *ppDevice = (IWineD3DDevice*)This->wineD3DDevice;
-    IWineD3DDevice_AddRef(*ppDevice);
-    return WINED3D_OK;
-
-}
-
-static inline void record_lights(IWineD3DStateBlockImpl *This, IWineD3DStateBlockImpl *targetStateBlock) {
+static void record_lights(IWineD3DStateBlockImpl *This, const IWineD3DStateBlockImpl *targetStateBlock)
+{
     UINT i;
 
@@ -363,27 +556,24 @@
         LIST_FOR_EACH(e, &This->lightMap[i]) {
             BOOL updated = FALSE;
-            PLIGHTINFOEL *src = LIST_ENTRY(e, PLIGHTINFOEL, entry), *realLight;
-            if (!src->changed && !src->enabledChanged) continue;
+            struct wined3d_light_info *src = LIST_ENTRY(e, struct wined3d_light_info, entry), *realLight;
 
             /* Look up the light in the destination */
             LIST_FOR_EACH(f, &targetStateBlock->lightMap[i]) {
-                realLight = LIST_ENTRY(f, PLIGHTINFOEL, entry);
-                if(realLight->OriginalIndex == src->OriginalIndex) {
-                    if(src->changed) {
-                        src->OriginalParms = realLight->OriginalParms;
+                realLight = LIST_ENTRY(f, struct wined3d_light_info, entry);
+                if (realLight->OriginalIndex == src->OriginalIndex)
+                {
+                    src->OriginalParms = realLight->OriginalParms;
+
+                    if (realLight->glIndex == -1 && src->glIndex != -1)
+                    {
+                        /* Light disabled */
+                        This->activeLights[src->glIndex] = NULL;
                     }
-                    if(src->enabledChanged) {
-                            /* Need to double check because enabledChanged does not catch enabled -> disabled -> enabled
-                        * or disabled -> enabled -> disabled changes
-                            */
-                        if(realLight->glIndex == -1 && src->glIndex != -1) {
-                            /* Light disabled */
-                            This->activeLights[src->glIndex] = NULL;
-                        } else if(realLight->glIndex != -1 && src->glIndex == -1){
-                            /* Light enabled */
-                            This->activeLights[realLight->glIndex] = src;
-                        }
-                        src->glIndex = realLight->glIndex;
+                    else if (realLight->glIndex != -1 && src->glIndex == -1)
+                    {
+                        /* Light enabled */
+                        This->activeLights[realLight->glIndex] = src;
                     }
+                    src->glIndex = realLight->glIndex;
                     updated = TRUE;
                     break;
@@ -391,13 +581,17 @@
             }
 
-            if(updated) {
-                /* Found a light, all done, proceed with next hash entry */
-                continue;
-            } else if(src->changed) {
-                /* Otherwise assign defaul params */
+            if (!updated)
+            {
+                /* This can happen if the light was originally created as a
+                 * default light for SetLightEnable() while recording. */
+                WARN("Light %u in stateblock %p does not exist in device stateblock %p.\n",
+                        src->OriginalIndex, This, targetStateBlock);
+
                 src->OriginalParms = WINED3D_default_light;
-            } else {
-                /* Not enabled by default */
-                src->glIndex = -1;
+                if (src->glIndex != -1)
+                {
+                    This->activeLights[src->glIndex] = NULL;
+                    src->glIndex = -1;
+                }
             }
         }
@@ -405,341 +599,275 @@
 }
 
-static HRESULT  WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){
-
-    IWineD3DStateBlockImpl *This             = (IWineD3DStateBlockImpl *)iface;
-    IWineD3DStateBlockImpl *targetStateBlock = This->wineD3DDevice->stateBlock;
-    unsigned int i, j;
+static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
+{
+    IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
+    IWineD3DStateBlockImpl *targetStateBlock = This->device->stateBlock;
+    unsigned int i;
     DWORD map;
 
     TRACE("(%p) : Updating state block %p ------------------v\n", targetStateBlock, This);
 
-    /* If not recorded, then update can just recapture */
-    if (This->blockType == WINED3DSBT_RECORDED) {
-
-        /* Recorded => Only update 'changed' values */
-        if (This->changed.vertexShader && This->vertexShader != targetStateBlock->vertexShader) {
-            TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader);
-
-            if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
-            if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
-            This->vertexShader = targetStateBlock->vertexShader;
-        }
-
-        /* Vertex Shader Float Constants */
-        for (j = 0; j < This->num_contained_vs_consts_f; ++j) {
-            i = This->contained_vs_consts_f[j];
-            TRACE("Setting %p from %p %u to {%f, %f, %f, %f}\n", This, targetStateBlock, i,
-                    targetStateBlock->vertexShaderConstantF[i * 4],
-                    targetStateBlock->vertexShaderConstantF[i * 4 + 1],
-                    targetStateBlock->vertexShaderConstantF[i * 4 + 2],
-                    targetStateBlock->vertexShaderConstantF[i * 4 + 3]);
-
-            This->vertexShaderConstantF[i * 4]      = targetStateBlock->vertexShaderConstantF[i * 4];
-            This->vertexShaderConstantF[i * 4 + 1]  = targetStateBlock->vertexShaderConstantF[i * 4 + 1];
-            This->vertexShaderConstantF[i * 4 + 2]  = targetStateBlock->vertexShaderConstantF[i * 4 + 2];
-            This->vertexShaderConstantF[i * 4 + 3]  = targetStateBlock->vertexShaderConstantF[i * 4 + 3];
-        }
-
-        /* Vertex Shader Integer Constants */
-        for (j = 0; j < This->num_contained_vs_consts_i; ++j) {
-            i = This->contained_vs_consts_i[j];
-            TRACE("Setting %p from %p %u to {%d, %d, %d, %d}\n", This, targetStateBlock, i,
-                    targetStateBlock->vertexShaderConstantI[i * 4],
-                    targetStateBlock->vertexShaderConstantI[i * 4 + 1],
-                    targetStateBlock->vertexShaderConstantI[i * 4 + 2],
-                    targetStateBlock->vertexShaderConstantI[i * 4 + 3]);
-
-            This->vertexShaderConstantI[i * 4]      = targetStateBlock->vertexShaderConstantI[i * 4];
-            This->vertexShaderConstantI[i * 4 + 1]  = targetStateBlock->vertexShaderConstantI[i * 4 + 1];
-            This->vertexShaderConstantI[i * 4 + 2]  = targetStateBlock->vertexShaderConstantI[i * 4 + 2];
-            This->vertexShaderConstantI[i * 4 + 3]  = targetStateBlock->vertexShaderConstantI[i * 4 + 3];
-        }
-
-        /* Vertex Shader Boolean Constants */
-        for (j = 0; j < This->num_contained_vs_consts_b; ++j) {
-            i = This->contained_vs_consts_b[j];
-            TRACE("Setting %p from %p %u to %s\n", This, targetStateBlock, i,
-                    targetStateBlock->vertexShaderConstantB[i] ? "TRUE" : "FALSE");
-
-            This->vertexShaderConstantB[i] =  targetStateBlock->vertexShaderConstantB[i];
-        }
-
-        /* Pixel Shader Float Constants */
-        for (j = 0; j < This->num_contained_ps_consts_f; ++j) {
-            i = This->contained_ps_consts_f[j];
-            TRACE("Setting %p from %p %u to {%f, %f, %f, %f}\n", This, targetStateBlock, i,
-                    targetStateBlock->pixelShaderConstantF[i * 4],
-                    targetStateBlock->pixelShaderConstantF[i * 4 + 1],
-                    targetStateBlock->pixelShaderConstantF[i * 4 + 2],
-                    targetStateBlock->pixelShaderConstantF[i * 4 + 3]);
-
-            This->pixelShaderConstantF[i * 4]      = targetStateBlock->pixelShaderConstantF[i * 4];
-            This->pixelShaderConstantF[i * 4 + 1]  = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
-            This->pixelShaderConstantF[i * 4 + 2]  = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
-            This->pixelShaderConstantF[i * 4 + 3]  = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
-        }
-
-        /* Pixel Shader Integer Constants */
-        for (j = 0; j < This->num_contained_ps_consts_i; ++j) {
-            i = This->contained_ps_consts_i[j];
-            TRACE("Setting %p from %p %u to {%d, %d, %d, %d}\n", This, targetStateBlock, i,
-                    targetStateBlock->pixelShaderConstantI[i * 4],
-                    targetStateBlock->pixelShaderConstantI[i * 4 + 1],
-                    targetStateBlock->pixelShaderConstantI[i * 4 + 2],
-                    targetStateBlock->pixelShaderConstantI[i * 4 + 3]);
-
-            This->pixelShaderConstantI[i * 4]      = targetStateBlock->pixelShaderConstantI[i * 4];
-            This->pixelShaderConstantI[i * 4 + 1]  = targetStateBlock->pixelShaderConstantI[i * 4 + 1];
-            This->pixelShaderConstantI[i * 4 + 2]  = targetStateBlock->pixelShaderConstantI[i * 4 + 2];
-            This->pixelShaderConstantI[i * 4 + 3]  = targetStateBlock->pixelShaderConstantI[i * 4 + 3];
-        }
-
-        /* Pixel Shader Boolean Constants */
-        for (j = 0; j < This->num_contained_ps_consts_b; ++j) {
-            i = This->contained_ps_consts_b[j];
-            TRACE("Setting %p from %p %u to %s\n", This, targetStateBlock, i,
-                    targetStateBlock->pixelShaderConstantB[i] ? "TRUE" : "FALSE");
-
-            This->pixelShaderConstantB[i] =  targetStateBlock->pixelShaderConstantB[i];
-        }
-
-        /* Others + Render & Texture */
-        for (i = 0; i < This->num_contained_transform_states; i++) {
-            TRACE("Updating transform %u\n", i);
-            This->transforms[This->contained_transform_states[i]] =
-                targetStateBlock->transforms[This->contained_transform_states[i]];
-        }
-
-        if (This->changed.primitive_type) This->gl_primitive_type = targetStateBlock->gl_primitive_type;
-
-        if (This->changed.indices && ((This->pIndexData != targetStateBlock->pIndexData)
-                        || (This->baseVertexIndex != targetStateBlock->baseVertexIndex)
-                        || (This->IndexFmt != targetStateBlock->IndexFmt))) {
-            TRACE("Updating pIndexData to %p, baseVertexIndex to %d\n",
-                    targetStateBlock->pIndexData, targetStateBlock->baseVertexIndex);
-            if(targetStateBlock->pIndexData) IWineD3DBuffer_AddRef(targetStateBlock->pIndexData);
-            if(This->pIndexData) IWineD3DBuffer_Release(This->pIndexData);
-            This->pIndexData = targetStateBlock->pIndexData;
-            This->baseVertexIndex = targetStateBlock->baseVertexIndex;
-            This->IndexFmt = targetStateBlock->IndexFmt;
-        }
-
-        if(This->changed.vertexDecl && This->vertexDecl != targetStateBlock->vertexDecl){
-            TRACE("Updating vertex declaration from %p to %p\n", This->vertexDecl, targetStateBlock->vertexDecl);
-
-            This->vertexDecl = targetStateBlock->vertexDecl;
-        }
-
-        if (This->changed.material && memcmp(&targetStateBlock->material,
-                                                    &This->material,
-                                                    sizeof(WINED3DMATERIAL)) != 0) {
-            TRACE("Updating material\n");
-            This->material = targetStateBlock->material;
-        }
-
-        if (This->changed.viewport && memcmp(&targetStateBlock->viewport,
-                                                    &This->viewport,
-                                                    sizeof(WINED3DVIEWPORT)) != 0) {
-            TRACE("Updating viewport\n");
-            This->viewport = targetStateBlock->viewport;
-        }
-
-        if(This->changed.scissorRect && memcmp(&targetStateBlock->scissorRect,
-                                           &This->scissorRect,
-                                           sizeof(targetStateBlock->scissorRect)))
-        {
-            TRACE("Updating scissor rect\n");
-            targetStateBlock->scissorRect = This->scissorRect;
-        }
-
-        map = This->changed.streamSource;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            if (!(map & 1)) continue;
-
-            if (This->streamStride[i] != targetStateBlock->streamStride[i]
-                    || This->streamSource[i] != targetStateBlock->streamSource[i])
-            {
-                TRACE("Updating stream source %u to %p, stride to %u\n",
-                        i, targetStateBlock->streamSource[i], targetStateBlock->streamStride[i]);
-                This->streamStride[i] = targetStateBlock->streamStride[i];
-                if (targetStateBlock->streamSource[i]) IWineD3DBuffer_AddRef(targetStateBlock->streamSource[i]);
-                if (This->streamSource[i]) IWineD3DBuffer_Release(This->streamSource[i]);
-                This->streamSource[i] = targetStateBlock->streamSource[i];
-            }
-        }
-
-        map = This->changed.streamFreq;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            if (!(map & 1)) continue;
-
-            if (This->streamFreq[i] != targetStateBlock->streamFreq[i]
-                    || This->streamFlags[i] != targetStateBlock->streamFlags[i])
-            {
-                TRACE("Updating stream frequency %u to %u flags to %#x\n",
-                        i, targetStateBlock->streamFreq[i], targetStateBlock->streamFlags[i]);
-                This->streamFreq[i] = targetStateBlock->streamFreq[i];
-                This->streamFlags[i] = targetStateBlock->streamFlags[i];
-            }
-        }
-
-        map = This->changed.clipplane;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            if (!(map & 1)) continue;
-
-            if (memcmp(targetStateBlock->clipplane[i], This->clipplane[i], sizeof(*This->clipplane)))
-            {
-                TRACE("Updating clipplane %u\n", i);
-                memcpy(This->clipplane[i], targetStateBlock->clipplane[i], sizeof(*This->clipplane));
-            }
-        }
-
-        /* Render */
-        for (i = 0; i < This->num_contained_render_states; i++) {
-            TRACE("Updating renderState %u to %u\n", This->contained_render_states[i],
-                    targetStateBlock->renderState[This->contained_render_states[i]]);
-            This->renderState[This->contained_render_states[i]] = targetStateBlock->renderState[This->contained_render_states[i]];
-        }
-
-        /* Texture states */
-        for (j = 0; j < This->num_contained_tss_states; j++) {
-            DWORD stage = This->contained_tss_states[j].stage;
-            DWORD state = This->contained_tss_states[j].state;
-
-            TRACE("Updating texturestage state %u, %u to %u (was %u)\n", stage, state,
-                    targetStateBlock->textureState[stage][state], This->textureState[stage][state]);
-            This->textureState[stage][state] = targetStateBlock->textureState[stage][state];
-        }
-
-        /* Samplers */
-        /* TODO: move over to using memcpy */
-        map = This->changed.textures;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            if (!(map & 1)) continue;
-
-            TRACE("Updating texture %u to %p (was %p)\n", i, targetStateBlock->textures[i], This->textures[i]);
-            This->textures[i] = targetStateBlock->textures[i];
-        }
-
-        for (j = 0; j < This->num_contained_sampler_states; j++) {
-            DWORD stage = This->contained_sampler_states[j].stage;
-            DWORD state = This->contained_sampler_states[j].state;
-            TRACE("Updating sampler state %u, %u to %u (was %u)\n", stage, state,
-                    targetStateBlock->samplerState[stage][state], This->samplerState[stage][state]);
-            This->samplerState[stage][state] = targetStateBlock->samplerState[stage][state];
-        }
-        if(This->changed.pixelShader && This->pixelShader != targetStateBlock->pixelShader) {
-            if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
-            if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
-            This->pixelShader = targetStateBlock->pixelShader;
-        }
-
-        record_lights(This, targetStateBlock);
-    } else if(This->blockType == WINED3DSBT_ALL) {
+    if (This->changed.vertexShader && This->vertexShader != targetStateBlock->vertexShader)
+    {
+        TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader);
+
+        if (targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
+        if (This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
+        This->vertexShader = targetStateBlock->vertexShader;
+    }
+
+    /* Vertex Shader Float Constants */
+    for (i = 0; i < This->num_contained_vs_consts_f; ++i)
+    {
+        unsigned int idx = This->contained_vs_consts_f[i];
+
+        TRACE("Setting %p from %p %u to {%.8e, %.8e, %.8e, %.8e}.\n",
+                This, targetStateBlock, idx,
+                targetStateBlock->vertexShaderConstantF[idx * 4 + 0],
+                targetStateBlock->vertexShaderConstantF[idx * 4 + 1],
+                targetStateBlock->vertexShaderConstantF[idx * 4 + 2],
+                targetStateBlock->vertexShaderConstantF[idx * 4 + 3]);
+
+        This->vertexShaderConstantF[idx * 4 + 0] = targetStateBlock->vertexShaderConstantF[idx * 4 + 0];
+        This->vertexShaderConstantF[idx * 4 + 1] = targetStateBlock->vertexShaderConstantF[idx * 4 + 1];
+        This->vertexShaderConstantF[idx * 4 + 2] = targetStateBlock->vertexShaderConstantF[idx * 4 + 2];
+        This->vertexShaderConstantF[idx * 4 + 3] = targetStateBlock->vertexShaderConstantF[idx * 4 + 3];
+    }
+
+    /* Vertex Shader Integer Constants */
+    for (i = 0; i < This->num_contained_vs_consts_i; ++i)
+    {
+        unsigned int idx = This->contained_vs_consts_i[i];
+
+        TRACE("Setting %p from %p %u to {%d, %d, %d, %d}.\n",
+                This, targetStateBlock, idx,
+                targetStateBlock->vertexShaderConstantI[idx * 4 + 0],
+                targetStateBlock->vertexShaderConstantI[idx * 4 + 1],
+                targetStateBlock->vertexShaderConstantI[idx * 4 + 2],
+                targetStateBlock->vertexShaderConstantI[idx * 4 + 3]);
+
+        This->vertexShaderConstantI[idx * 4 + 0] = targetStateBlock->vertexShaderConstantI[idx * 4 + 0];
+        This->vertexShaderConstantI[idx * 4 + 1] = targetStateBlock->vertexShaderConstantI[idx * 4 + 1];
+        This->vertexShaderConstantI[idx * 4 + 2] = targetStateBlock->vertexShaderConstantI[idx * 4 + 2];
+        This->vertexShaderConstantI[idx * 4 + 3] = targetStateBlock->vertexShaderConstantI[idx * 4 + 3];
+    }
+
+    /* Vertex Shader Boolean Constants */
+    for (i = 0; i < This->num_contained_vs_consts_b; ++i)
+    {
+        unsigned int idx = This->contained_vs_consts_b[i];
+
+        TRACE("Setting %p from %p %u to %s.\n",
+                This, targetStateBlock, idx,
+                targetStateBlock->vertexShaderConstantB[idx] ? "TRUE" : "FALSE");
+
+        This->vertexShaderConstantB[idx] = targetStateBlock->vertexShaderConstantB[idx];
+    }
+
+    /* Pixel Shader Float Constants */
+    for (i = 0; i < This->num_contained_ps_consts_f; ++i)
+    {
+        unsigned int idx = This->contained_ps_consts_f[i];
+
+        TRACE("Setting %p from %p %u to {%.8e, %.8e, %.8e, %.8e}.\n",
+                This, targetStateBlock, idx,
+                targetStateBlock->pixelShaderConstantF[idx * 4 + 0],
+                targetStateBlock->pixelShaderConstantF[idx * 4 + 1],
+                targetStateBlock->pixelShaderConstantF[idx * 4 + 2],
+                targetStateBlock->pixelShaderConstantF[idx * 4 + 3]);
+
+        This->pixelShaderConstantF[idx * 4 + 0] = targetStateBlock->pixelShaderConstantF[idx * 4 + 0];
+        This->pixelShaderConstantF[idx * 4 + 1] = targetStateBlock->pixelShaderConstantF[idx * 4 + 1];
+        This->pixelShaderConstantF[idx * 4 + 2] = targetStateBlock->pixelShaderConstantF[idx * 4 + 2];
+        This->pixelShaderConstantF[idx * 4 + 3] = targetStateBlock->pixelShaderConstantF[idx * 4 + 3];
+    }
+
+    /* Pixel Shader Integer Constants */
+    for (i = 0; i < This->num_contained_ps_consts_i; ++i)
+    {
+        unsigned int idx = This->contained_ps_consts_i[i];
+        TRACE("Setting %p from %p %u to {%d, %d, %d, %d}.\n",
+                This, targetStateBlock, idx,
+                targetStateBlock->pixelShaderConstantI[idx * 4 + 0],
+                targetStateBlock->pixelShaderConstantI[idx * 4 + 1],
+                targetStateBlock->pixelShaderConstantI[idx * 4 + 2],
+                targetStateBlock->pixelShaderConstantI[idx * 4 + 3]);
+
+        This->pixelShaderConstantI[idx * 4 + 0] = targetStateBlock->pixelShaderConstantI[idx * 4 + 0];
+        This->pixelShaderConstantI[idx * 4 + 1] = targetStateBlock->pixelShaderConstantI[idx * 4 + 1];
+        This->pixelShaderConstantI[idx * 4 + 2] = targetStateBlock->pixelShaderConstantI[idx * 4 + 2];
+        This->pixelShaderConstantI[idx * 4 + 3] = targetStateBlock->pixelShaderConstantI[idx * 4 + 3];
+    }
+
+    /* Pixel Shader Boolean Constants */
+    for (i = 0; i < This->num_contained_ps_consts_b; ++i)
+    {
+        unsigned int idx = This->contained_ps_consts_b[i];
+        TRACE("Setting %p from %p %u to %s.\n", This, targetStateBlock, idx,
+                targetStateBlock->pixelShaderConstantB[idx] ? "TRUE" : "FALSE");
+
+        This->pixelShaderConstantB[idx] = targetStateBlock->pixelShaderConstantB[idx];
+    }
+
+    /* Others + Render & Texture */
+    for (i = 0; i < This->num_contained_transform_states; ++i)
+    {
+        WINED3DTRANSFORMSTATETYPE transform = This->contained_transform_states[i];
+
+        TRACE("Updating transform %#x.\n", transform);
+
+        This->transforms[transform] = targetStateBlock->transforms[transform];
+    }
+
+    if (This->changed.primitive_type) This->gl_primitive_type = targetStateBlock->gl_primitive_type;
+
+    if (This->changed.indices
+            && ((This->pIndexData != targetStateBlock->pIndexData)
+                || (This->baseVertexIndex != targetStateBlock->baseVertexIndex)
+                || (This->IndexFmt != targetStateBlock->IndexFmt)))
+    {
+        TRACE("Updating pIndexData to %p, baseVertexIndex to %d.\n",
+                targetStateBlock->pIndexData, targetStateBlock->baseVertexIndex);
+
+        if (targetStateBlock->pIndexData) IWineD3DBuffer_AddRef(targetStateBlock->pIndexData);
+        if (This->pIndexData) IWineD3DBuffer_Release(This->pIndexData);
+        This->pIndexData = targetStateBlock->pIndexData;
+        This->baseVertexIndex = targetStateBlock->baseVertexIndex;
+        This->IndexFmt = targetStateBlock->IndexFmt;
+    }
+
+    if (This->changed.vertexDecl && This->vertexDecl != targetStateBlock->vertexDecl)
+    {
+        TRACE("Updating vertex declaration from %p to %p.\n", This->vertexDecl, targetStateBlock->vertexDecl);
+
+        if (targetStateBlock->vertexDecl) IWineD3DVertexDeclaration_AddRef(targetStateBlock->vertexDecl);
+        if (This->vertexDecl) IWineD3DVertexDeclaration_Release(This->vertexDecl);
         This->vertexDecl = targetStateBlock->vertexDecl;
-        memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
-        memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
-        memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
-        This->gl_primitive_type = targetStateBlock->gl_primitive_type;
-        memcpy(This->streamStride, targetStateBlock->streamStride, sizeof(This->streamStride));
-        memcpy(This->streamOffset, targetStateBlock->streamOffset, sizeof(This->streamOffset));
-        memcpy(This->streamFreq, targetStateBlock->streamFreq, sizeof(This->streamFreq));
-        memcpy(This->streamFlags, targetStateBlock->streamFlags, sizeof(This->streamFlags));
-        This->baseVertexIndex = targetStateBlock->baseVertexIndex;
-        memcpy(This->transforms, targetStateBlock->transforms, sizeof(This->transforms));
-        record_lights(This, targetStateBlock);
-        memcpy(This->clipplane, targetStateBlock->clipplane, sizeof(This->clipplane));
-        This->clip_status = targetStateBlock->clip_status;
+    }
+
+    if (This->changed.material
+            && memcmp(&targetStateBlock->material, &This->material, sizeof(This->material)))
+    {
+        TRACE("Updating material.\n");
+
+        This->material = targetStateBlock->material;
+    }
+
+    if (This->changed.viewport
+            && memcmp(&targetStateBlock->viewport, &This->viewport, sizeof(This->viewport)))
+    {
+        TRACE("Updating viewport.\n");
+
         This->viewport = targetStateBlock->viewport;
-        This->material = targetStateBlock->material;
-        memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
-        memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
-        memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
-        memcpy(This->renderState, targetStateBlock->renderState, sizeof(This->renderState));
-        memcpy(This->textures, targetStateBlock->textures, sizeof(This->textures));
-        memcpy(This->textureState, targetStateBlock->textureState, sizeof(This->textureState));
-        memcpy(This->samplerState, targetStateBlock->samplerState, sizeof(This->samplerState));
-        This->scissorRect = targetStateBlock->scissorRect;
-
-        if(targetStateBlock->pIndexData != This->pIndexData ||
-           targetStateBlock->IndexFmt != This->IndexFmt) {
-            if (targetStateBlock->pIndexData) IWineD3DBuffer_AddRef(targetStateBlock->pIndexData);
-            if (This->pIndexData) IWineD3DBuffer_Release(This->pIndexData);
-            This->pIndexData = targetStateBlock->pIndexData;
-            This->IndexFmt = targetStateBlock->IndexFmt;
-        }
-        for(i = 0; i < MAX_STREAMS; i++) {
-            if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
-                if(targetStateBlock->streamSource[i]) IWineD3DBuffer_AddRef(targetStateBlock->streamSource[i]);
-                if(This->streamSource[i]) IWineD3DBuffer_Release(This->streamSource[i]);
-                This->streamSource[i] = targetStateBlock->streamSource[i];
-            }
-        }
-        if(This->vertexShader != targetStateBlock->vertexShader) {
-            if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
-            if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
-            This->vertexShader = targetStateBlock->vertexShader;
-        }
-        if(This->pixelShader != targetStateBlock->pixelShader) {
-            if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
-            if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
-            This->pixelShader = targetStateBlock->pixelShader;
-        }
-    } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
-        memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
-        memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
-        memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
-        record_lights(This, targetStateBlock);
-        for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
-            This->renderState[SavedVertexStates_R[i]] = targetStateBlock->renderState[SavedVertexStates_R[i]];
-        }
-        for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
-            for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
-                This->samplerState[j][SavedVertexStates_S[i]] = targetStateBlock->samplerState[j][SavedVertexStates_S[i]];
-            }
-        }
-        for (j = 0; j < MAX_TEXTURES; j++) {
-            for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
-                This->textureState[j][SavedVertexStates_R[i]] = targetStateBlock->textureState[j][SavedVertexStates_R[i]];
-            }
-        }
-        for(i = 0; i < MAX_STREAMS; i++) {
-            if(targetStateBlock->streamSource[i] != This->streamSource[i]) {
-                if (targetStateBlock->streamSource[i]) IWineD3DBuffer_AddRef(targetStateBlock->streamSource[i]);
-                if (This->streamSource[i]) IWineD3DBuffer_Release(This->streamSource[i]);
-                This->streamSource[i] = targetStateBlock->streamSource[i];
-            }
-        }
-        if(This->vertexShader != targetStateBlock->vertexShader) {
-            if(targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader);
-            if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader);
-            This->vertexShader = targetStateBlock->vertexShader;
-        }
-    } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
-        memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
-        memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
-        memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
-        for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
-            This->renderState[SavedPixelStates_R[i]] = targetStateBlock->renderState[SavedPixelStates_R[i]];
-        }
-        for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
-            for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
-                This->samplerState[j][SavedPixelStates_S[i]] = targetStateBlock->samplerState[j][SavedPixelStates_S[i]];
-            }
-        }
-        for (j = 0; j < MAX_TEXTURES; j++) {
-            for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
-                This->textureState[j][SavedPixelStates_R[i]] = targetStateBlock->textureState[j][SavedPixelStates_R[i]];
-            }
-        }
-        if(This->pixelShader != targetStateBlock->pixelShader) {
-            if(targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
-            if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
-            This->pixelShader = targetStateBlock->pixelShader;
-        }
-    }
+    }
+
+    if(This->changed.scissorRect
+            && memcmp(&targetStateBlock->scissorRect, &This->scissorRect, sizeof(This->scissorRect)))
+    {
+        TRACE("Updating scissor rect.\n");
+
+        targetStateBlock->scissorRect = This->scissorRect;
+    }
+
+    map = This->changed.streamSource;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (!(map & 1)) continue;
+
+        if (This->streamStride[i] != targetStateBlock->streamStride[i]
+                || This->streamSource[i] != targetStateBlock->streamSource[i])
+        {
+            TRACE("Updating stream source %u to %p, stride to %u.\n",
+                    i, targetStateBlock->streamSource[i], targetStateBlock->streamStride[i]);
+
+            This->streamStride[i] = targetStateBlock->streamStride[i];
+            if (targetStateBlock->streamSource[i]) IWineD3DBuffer_AddRef(targetStateBlock->streamSource[i]);
+            if (This->streamSource[i]) IWineD3DBuffer_Release(This->streamSource[i]);
+            This->streamSource[i] = targetStateBlock->streamSource[i];
+        }
+    }
+
+    map = This->changed.streamFreq;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (!(map & 1)) continue;
+
+        if (This->streamFreq[i] != targetStateBlock->streamFreq[i]
+                || This->streamFlags[i] != targetStateBlock->streamFlags[i])
+        {
+            TRACE("Updating stream frequency %u to %u flags to %#x.\n",
+                    i, targetStateBlock->streamFreq[i], targetStateBlock->streamFlags[i]);
+
+            This->streamFreq[i] = targetStateBlock->streamFreq[i];
+            This->streamFlags[i] = targetStateBlock->streamFlags[i];
+        }
+    }
+
+    map = This->changed.clipplane;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (!(map & 1)) continue;
+
+        if (memcmp(targetStateBlock->clipplane[i], This->clipplane[i], sizeof(*This->clipplane)))
+        {
+            TRACE("Updating clipplane %u.\n", i);
+            memcpy(This->clipplane[i], targetStateBlock->clipplane[i], sizeof(*This->clipplane));
+        }
+    }
+
+    /* Render */
+    for (i = 0; i < This->num_contained_render_states; ++i)
+    {
+        WINED3DRENDERSTATETYPE rs = This->contained_render_states[i];
+
+        TRACE("Updating renderState %#x to %u.\n", rs, targetStateBlock->renderState[rs]);
+
+        This->renderState[rs] = targetStateBlock->renderState[rs];
+    }
+
+    /* Texture states */
+    for (i = 0; i < This->num_contained_tss_states; ++i)
+    {
+        DWORD stage = This->contained_tss_states[i].stage;
+        DWORD state = This->contained_tss_states[i].state;
+
+        TRACE("Updating texturestage state %u, %u to %u (was %u).\n", stage, state,
+                targetStateBlock->textureState[stage][state], This->textureState[stage][state]);
+
+        This->textureState[stage][state] = targetStateBlock->textureState[stage][state];
+    }
+
+    /* Samplers */
+    map = This->changed.textures;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (!(map & 1)) continue;
+
+        TRACE("Updating texture %u to %p (was %p).\n", i, targetStateBlock->textures[i], This->textures[i]);
+
+        if (targetStateBlock->textures[i]) IWineD3DBaseTexture_AddRef(targetStateBlock->textures[i]);
+        if (This->textures[i]) IWineD3DBaseTexture_Release(This->textures[i]);
+        This->textures[i] = targetStateBlock->textures[i];
+    }
+
+    for (i = 0; i < This->num_contained_sampler_states; ++i)
+    {
+        DWORD stage = This->contained_sampler_states[i].stage;
+        DWORD state = This->contained_sampler_states[i].state;
+
+        TRACE("Updating sampler state %u, %u to %u (was %u).\n", stage, state,
+                targetStateBlock->samplerState[stage][state], This->samplerState[stage][state]);
+
+        This->samplerState[stage][state] = targetStateBlock->samplerState[stage][state];
+    }
+
+    if (This->changed.pixelShader && This->pixelShader != targetStateBlock->pixelShader)
+    {
+        if (targetStateBlock->pixelShader) IWineD3DPixelShader_AddRef(targetStateBlock->pixelShader);
+        if (This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
+        This->pixelShader = targetStateBlock->pixelShader;
+    }
+
+    record_lights(This, targetStateBlock);
 
     TRACE("(%p) : Updated state block %p ------------------^\n", targetStateBlock, This);
@@ -748,31 +876,25 @@
 }
 
-static inline void apply_lights(IWineD3DDevice *pDevice, IWineD3DStateBlockImpl *This) {
+static void apply_lights(IWineD3DDevice *pDevice, const IWineD3DStateBlockImpl *This)
+{
     UINT i;
     for(i = 0; i < LIGHTMAP_SIZE; i++) {
         struct list *e;
 
-        LIST_FOR_EACH(e, &This->lightMap[i]) {
-            const PLIGHTINFOEL *light = LIST_ENTRY(e, PLIGHTINFOEL, entry);
-
-            if(light->changed) {
-                IWineD3DDevice_SetLight(pDevice, light->OriginalIndex, &light->OriginalParms);
-            }
-            if(light->enabledChanged) {
-                IWineD3DDevice_SetLightEnable(pDevice, light->OriginalIndex, light->glIndex != -1);
-            }
-        }
-    }
-}
-
-static HRESULT  WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface){
+        LIST_FOR_EACH(e, &This->lightMap[i])
+        {
+            const struct wined3d_light_info *light = LIST_ENTRY(e, struct wined3d_light_info, entry);
+
+            IWineD3DDevice_SetLight(pDevice, light->OriginalIndex, &light->OriginalParms);
+            IWineD3DDevice_SetLightEnable(pDevice, light->OriginalIndex, light->glIndex != -1);
+        }
+    }
+}
+
+static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface)
+{
     IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
-    IWineD3DDevice*        pDevice     = (IWineD3DDevice*)This->wineD3DDevice;
-
-/*Copy thing over to updateBlock is isRecording otherwise StateBlock,
-should really perform a delta so that only the changes get updated*/
-
-    UINT i;
-    UINT j;
+    IWineD3DDevice *pDevice = (IWineD3DDevice *)This->device;
+    unsigned int i;
     DWORD map;
 
@@ -781,295 +903,152 @@
     TRACE("Blocktype: %d\n", This->blockType);
 
-    if(This->blockType == WINED3DSBT_RECORDED) {
-        if (This->changed.vertexShader) {
-            IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
-        }
-        /* Vertex Shader Constants */
-        for (i = 0; i < This->num_contained_vs_consts_f; i++) {
-            IWineD3DDevice_SetVertexShaderConstantF(pDevice, This->contained_vs_consts_f[i],
-                    This->vertexShaderConstantF + This->contained_vs_consts_f[i] * 4, 1);
-        }
-        for (i = 0; i < This->num_contained_vs_consts_i; i++) {
-            IWineD3DDevice_SetVertexShaderConstantI(pDevice, This->contained_vs_consts_i[i],
-                    This->vertexShaderConstantI + This->contained_vs_consts_i[i] * 4, 1);
-        }
-        for (i = 0; i < This->num_contained_vs_consts_b; i++) {
-            IWineD3DDevice_SetVertexShaderConstantB(pDevice, This->contained_vs_consts_b[i],
-                    This->vertexShaderConstantB + This->contained_vs_consts_b[i], 1);
-        }
-
-        apply_lights(pDevice, This);
-
-        if (This->changed.pixelShader) {
-            IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
-        }
-        /* Pixel Shader Constants */
-        for (i = 0; i < This->num_contained_ps_consts_f; i++) {
-            IWineD3DDevice_SetPixelShaderConstantF(pDevice, This->contained_ps_consts_f[i],
-                    This->pixelShaderConstantF + This->contained_ps_consts_f[i] * 4, 1);
-        }
-        for (i = 0; i < This->num_contained_ps_consts_i; i++) {
-            IWineD3DDevice_SetPixelShaderConstantI(pDevice, This->contained_ps_consts_i[i],
-                    This->pixelShaderConstantI + This->contained_ps_consts_i[i] * 4, 1);
-        }
-        for (i = 0; i < This->num_contained_ps_consts_b; i++) {
-            IWineD3DDevice_SetPixelShaderConstantB(pDevice, This->contained_ps_consts_b[i],
-                    This->pixelShaderConstantB + This->contained_ps_consts_b[i], 1);
-        }
-
-        /* Render */
-        for (i = 0; i <= This->num_contained_render_states; i++) {
-            IWineD3DDevice_SetRenderState(pDevice, This->contained_render_states[i],
-                                          This->renderState[This->contained_render_states[i]]);
-        }
-        /* Texture states */
-        for (i = 0; i < This->num_contained_tss_states; i++) {
-            DWORD stage = This->contained_tss_states[i].stage;
-            DWORD state = This->contained_tss_states[i].state;
-            ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[stage][state]         = This->textureState[stage][state];
-            ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.textureState[stage] |= 1 << state;
-            /* TODO: Record a display list to apply all gl states. For now apply by brute force */
-            IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_TEXTURESTAGE(stage, state));
-        }
-        /* Sampler states */
-        for (i = 0; i < This->num_contained_sampler_states; i++) {
-            DWORD stage = This->contained_sampler_states[i].stage;
-            DWORD state = This->contained_sampler_states[i].state;
-            ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[stage][state]         = This->samplerState[stage][state];
-            ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.samplerState[stage] |= 1 << state;
-            IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_SAMPLER(stage));
-        }
-
-        for (i = 0; i < This->num_contained_transform_states; i++) {
-            IWineD3DDevice_SetTransform(pDevice, This->contained_transform_states[i],
-                                        &This->transforms[This->contained_transform_states[i]]);
-        }
-
-        if (This->changed.primitive_type)
-        {
-                This->wineD3DDevice->updateStateBlock->changed.primitive_type = TRUE;
-                This->wineD3DDevice->updateStateBlock->gl_primitive_type = This->gl_primitive_type;
-        }
-
-        if (This->changed.indices)
-        {
-            IWineD3DDevice_SetIndexBuffer(pDevice, This->pIndexData, This->IndexFmt);
-            IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
-        }
-
-        if (This->changed.vertexDecl) {
-            IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
-        }
-
-        if (This->changed.material ) {
-            IWineD3DDevice_SetMaterial(pDevice, &This->material);
-        }
-
-        if (This->changed.viewport) {
-            IWineD3DDevice_SetViewport(pDevice, &This->viewport);
-        }
-
-        if (This->changed.scissorRect) {
-            IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
-        }
-
-        /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
-        map = This->changed.streamSource;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            if (map & 1) IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
-        }
-
-        map = This->changed.streamFreq;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            if (map & 1) IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
-        }
-
-        map = This->changed.textures;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            if (!(map & 1)) continue;
-
-            if (i < MAX_FRAGMENT_SAMPLERS) IWineD3DDevice_SetTexture(pDevice, i, This->textures[i]);
-            else IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + i - MAX_FRAGMENT_SAMPLERS,
-                    This->textures[i]);
-        }
-
-        map = This->changed.clipplane;
-        for (i = 0; map; map >>= 1, ++i)
-        {
-            float clip[4];
-
-            if (!(map & 1)) continue;
-
-            clip[0] = This->clipplane[i][0];
-            clip[1] = This->clipplane[i][1];
-            clip[2] = This->clipplane[i][2];
-            clip[3] = This->clipplane[i][3];
-            IWineD3DDevice_SetClipPlane(pDevice, i, clip);
-        }
-    } else if(This->blockType == WINED3DSBT_VERTEXSTATE) {
-        IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
-        for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
-            IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
-                    This->vertexShaderConstantF + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_I; i++) {
-            IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
-                    This->vertexShaderConstantI + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_B; i++) {
-            IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
-                    This->vertexShaderConstantB + i, 1);
-        }
-
-        apply_lights(pDevice, This);
-
-        for(i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
-            IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
-        }
-        for(j = 0; j < MAX_TEXTURES; j++) {
-            for(i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
-                IWineD3DDevice_SetTextureStageState(pDevice, j, SavedVertexStates_T[i],
-                        This->textureState[j][SavedVertexStates_T[i]]);
-            }
-        }
-
-        for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
-            for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
-                IWineD3DDevice_SetSamplerState(pDevice, j, SavedVertexStates_S[i],
-                                               This->samplerState[j][SavedVertexStates_S[i]]);
-            }
-        }
-        for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
-            for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
-                IWineD3DDevice_SetSamplerState(pDevice,
-                                               WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
-                                               SavedVertexStates_S[i],
-                                               This->samplerState[j][SavedVertexStates_S[i]]);
-            }
-        }
-    } else if(This->blockType == WINED3DSBT_PIXELSTATE) {
-        IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
-        for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
-            IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
-                    This->pixelShaderConstantF + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_I; i++) {
-            IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
-                    This->pixelShaderConstantI + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_B; i++) {
-            IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
-                    This->pixelShaderConstantB + i, 1);
-        }
-
-        for(i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
-            IWineD3DDevice_SetRenderState(pDevice, SavedPixelStates_R[i], This->renderState[SavedPixelStates_R[i]]);
-        }
-        for(j = 0; j < MAX_TEXTURES; j++) {
-            for(i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
-                IWineD3DDevice_SetTextureStageState(pDevice, j, SavedPixelStates_T[i],
-                        This->textureState[j][SavedPixelStates_T[i]]);
-            }
-        }
-
-        for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
-            for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
-                IWineD3DDevice_SetSamplerState(pDevice, j, SavedPixelStates_S[i],
-                                               This->samplerState[j][SavedPixelStates_S[i]]);
-            }
-        }
-        for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
-            for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
-                IWineD3DDevice_SetSamplerState(pDevice,
-                                               WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS,
-                                               SavedPixelStates_S[i],
-                                               This->samplerState[j][SavedPixelStates_S[i]]);
-            }
-        }
-    } else if(This->blockType == WINED3DSBT_ALL) {
-        IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
-        for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
-            IWineD3DDevice_SetVertexShaderConstantF(pDevice, i,
-                    This->vertexShaderConstantF + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_I; i++) {
-            IWineD3DDevice_SetVertexShaderConstantI(pDevice, i,
-                    This->vertexShaderConstantI + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_B; i++) {
-            IWineD3DDevice_SetVertexShaderConstantB(pDevice, i,
-                    This->vertexShaderConstantB + i, 1);
-        }
-
-        IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
-        for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
-            IWineD3DDevice_SetPixelShaderConstantF(pDevice, i,
-                    This->pixelShaderConstantF + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_I; i++) {
-            IWineD3DDevice_SetPixelShaderConstantI(pDevice, i,
-                    This->pixelShaderConstantI + i * 4, 1);
-        }
-        for (i = 0; i < MAX_CONST_B; i++) {
-            IWineD3DDevice_SetPixelShaderConstantB(pDevice, i,
-                    This->pixelShaderConstantB + i, 1);
-        }
-
-        apply_lights(pDevice, This);
-
-        for(i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
-            IWineD3DDevice_SetRenderState(pDevice, i, This->renderState[i]);
-        }
-        for(j = 0; j < MAX_TEXTURES; j++) {
-            for (i = 0; i <= WINED3D_HIGHEST_TEXTURE_STATE; ++i)
-            {
-                IWineD3DDevice_SetTextureStageState(pDevice, j, i, This->textureState[j][i]);
-            }
-        }
-
-        /* Skip unused values between TEXTURE8 and WORLD0 ? */
-        for(i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) {
-            IWineD3DDevice_SetTransform(pDevice, i, &This->transforms[i]);
-        }
-        This->wineD3DDevice->updateStateBlock->gl_primitive_type = This->gl_primitive_type;
+    if (This->changed.vertexShader) IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader);
+
+    /* Vertex Shader Constants */
+    for (i = 0; i < This->num_contained_vs_consts_f; ++i)
+    {
+        IWineD3DDevice_SetVertexShaderConstantF(pDevice, This->contained_vs_consts_f[i],
+                This->vertexShaderConstantF + This->contained_vs_consts_f[i] * 4, 1);
+    }
+    for (i = 0; i < This->num_contained_vs_consts_i; ++i)
+    {
+        IWineD3DDevice_SetVertexShaderConstantI(pDevice, This->contained_vs_consts_i[i],
+                This->vertexShaderConstantI + This->contained_vs_consts_i[i] * 4, 1);
+    }
+    for (i = 0; i < This->num_contained_vs_consts_b; ++i)
+    {
+        IWineD3DDevice_SetVertexShaderConstantB(pDevice, This->contained_vs_consts_b[i],
+                This->vertexShaderConstantB + This->contained_vs_consts_b[i], 1);
+    }
+
+    apply_lights(pDevice, This);
+
+    if (This->changed.pixelShader) IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
+
+    /* Pixel Shader Constants */
+    for (i = 0; i < This->num_contained_ps_consts_f; ++i)
+    {
+        IWineD3DDevice_SetPixelShaderConstantF(pDevice, This->contained_ps_consts_f[i],
+                This->pixelShaderConstantF + This->contained_ps_consts_f[i] * 4, 1);
+    }
+    for (i = 0; i < This->num_contained_ps_consts_i; ++i)
+    {
+        IWineD3DDevice_SetPixelShaderConstantI(pDevice, This->contained_ps_consts_i[i],
+                This->pixelShaderConstantI + This->contained_ps_consts_i[i] * 4, 1);
+    }
+    for (i = 0; i < This->num_contained_ps_consts_b; ++i)
+    {
+        IWineD3DDevice_SetPixelShaderConstantB(pDevice, This->contained_ps_consts_b[i],
+                This->pixelShaderConstantB + This->contained_ps_consts_b[i], 1);
+    }
+
+    /* Render */
+    for (i = 0; i < This->num_contained_render_states; ++i)
+    {
+        IWineD3DDevice_SetRenderState(pDevice, This->contained_render_states[i],
+                This->renderState[This->contained_render_states[i]]);
+    }
+
+    /* Texture states */
+    for (i = 0; i < This->num_contained_tss_states; ++i)
+    {
+        DWORD stage = This->contained_tss_states[i].stage;
+        DWORD state = This->contained_tss_states[i].state;
+
+        IWineD3DDevice_SetTextureStageState(pDevice, stage, state, This->textureState[stage][state]);
+    }
+
+    /* Sampler states */
+    for (i = 0; i < This->num_contained_sampler_states; ++i)
+    {
+        DWORD stage = This->contained_sampler_states[i].stage;
+        DWORD state = This->contained_sampler_states[i].state;
+        DWORD value = This->samplerState[stage][state];
+
+        if (stage >= MAX_FRAGMENT_SAMPLERS) stage += WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS;
+        IWineD3DDevice_SetSamplerState(pDevice, stage, state, value);
+    }
+
+    for (i = 0; i < This->num_contained_transform_states; ++i)
+    {
+        IWineD3DDevice_SetTransform(pDevice, This->contained_transform_states[i],
+                &This->transforms[This->contained_transform_states[i]]);
+    }
+
+    if (This->changed.primitive_type)
+    {
+        This->device->updateStateBlock->changed.primitive_type = TRUE;
+        This->device->updateStateBlock->gl_primitive_type = This->gl_primitive_type;
+    }
+
+    if (This->changed.indices)
+    {
         IWineD3DDevice_SetIndexBuffer(pDevice, This->pIndexData, This->IndexFmt);
         IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
+    }
+
+    if (This->changed.vertexDecl && This->vertexDecl)
+    {
         IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
+    }
+
+    if (This->changed.material)
+    {
         IWineD3DDevice_SetMaterial(pDevice, &This->material);
+    }
+
+    if (This->changed.viewport)
+    {
         IWineD3DDevice_SetViewport(pDevice, &This->viewport);
+    }
+
+    if (This->changed.scissorRect)
+    {
         IWineD3DDevice_SetScissorRect(pDevice, &This->scissorRect);
-
-        /* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
-        for (i=0; i<MAX_STREAMS; i++) {
-            IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
-            IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
-        }
-        for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
-            UINT sampler = j < MAX_FRAGMENT_SAMPLERS ? j : WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS;
-
-            IWineD3DDevice_SetTexture(pDevice, sampler, This->textures[j]);
-            for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE; ++i)
-            {
-                IWineD3DDevice_SetSamplerState(pDevice, sampler, i, This->samplerState[j][i]);
-            }
-        }
-        for (i = 0; i < GL_LIMITS(clipplanes); i++) {
-            float clip[4];
-
-            clip[0] = This->clipplane[i][0];
-            clip[1] = This->clipplane[i][1];
-            clip[2] = This->clipplane[i][2];
-            clip[3] = This->clipplane[i][3];
-            IWineD3DDevice_SetClipPlane(pDevice, i, clip);
-        }
-    }
-
-    ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1;
-    for(j = 0; j < MAX_TEXTURES - 1; j++) {
-        if(((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
-            ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = j;
+    }
+
+    map = This->changed.streamSource;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (map & 1) IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
+    }
+
+    map = This->changed.streamFreq;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        if (map & 1) IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
+    }
+
+    map = This->changed.textures;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        DWORD stage;
+
+        if (!(map & 1)) continue;
+
+        stage = i < MAX_FRAGMENT_SAMPLERS ? i : WINED3DVERTEXTEXTURESAMPLER0 + i - MAX_FRAGMENT_SAMPLERS;
+        IWineD3DDevice_SetTexture(pDevice, stage, This->textures[i]);
+    }
+
+    map = This->changed.clipplane;
+    for (i = 0; map; map >>= 1, ++i)
+    {
+        float clip[4];
+
+        if (!(map & 1)) continue;
+
+        clip[0] = This->clipplane[i][0];
+        clip[1] = This->clipplane[i][1];
+        clip[2] = This->clipplane[i][2];
+        clip[3] = This->clipplane[i][3];
+        IWineD3DDevice_SetClipPlane(pDevice, i, clip);
+    }
+
+    This->device->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1;
+    for (i = 0; i < MAX_TEXTURES - 1; ++i)
+    {
+        if (This->device->stateBlock->textureState[i][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE)
+        {
+            This->device->stateBlock->lowest_disabled_stage = i;
             break;
         }
@@ -1082,6 +1061,7 @@
 static HRESULT  WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStateBlock* iface) {
     IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
-    IWineD3DDevice         *device = (IWineD3DDevice *)This->wineD3DDevice;
+    IWineD3DDevice *device = (IWineD3DDevice *)This->device;
     IWineD3DDeviceImpl     *ThisDevice = (IWineD3DDeviceImpl *)device;
+    const struct wined3d_gl_info *gl_info = &ThisDevice->adapter->gl_info;
     union {
         WINED3DLINEPATTERN lp;
@@ -1100,5 +1080,5 @@
        once, in order to initialize the complete state of the device and
        all opengl equivalents                                            */
-    TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This, This->wineD3DDevice);
+    TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This, ThisDevice);
     /* TODO: make a special stateblock type for the primary stateblock (it never gets applied so it doesn't need a real type) */
     This->blockType = WINED3DSBT_INIT;
@@ -1181,5 +1161,5 @@
     tmpfloat.f = 1.0f;
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE,                tmpfloat.d);
-    tmpfloat.f = ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion < 9 ? 0.0f : 1.0f;
+    tmpfloat.f = 1.0f;
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MIN,            tmpfloat.d);
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSPRITEENABLE,        FALSE);
@@ -1197,5 +1177,5 @@
     IWineD3DDevice_SetRenderState(device, WINED3DRS_PATCHSEGMENTS,            tmpfloat.d);
     IWineD3DDevice_SetRenderState(device, WINED3DRS_DEBUGMONITORTOKEN,        0xbaadcafe);
-    tmpfloat.f = GL_LIMITS(pointsize);
+    tmpfloat.f = gl_info->limits.pointsize_max;
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MAX,            tmpfloat.d);
     IWineD3DDevice_SetRenderState(device, WINED3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
@@ -1291,5 +1271,6 @@
     }
 
-    for(i = 0; i < GL_LIMITS(textures); i++) {
+    for (i = 0; i < gl_info->limits.textures; ++i)
+    {
         /* Note: This avoids calling SetTexture, so pretend it has been called */
         This->changed.textures |= 1 << i;
@@ -1340,5 +1321,5 @@
  **********************************************************/
 
-const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl =
+static const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl =
 {
     /* IUnknown */
@@ -1347,8 +1328,59 @@
     IWineD3DStateBlockImpl_Release,
     /* IWineD3DStateBlock */
-    IWineD3DStateBlockImpl_GetParent,
-    IWineD3DStateBlockImpl_GetDevice,
     IWineD3DStateBlockImpl_Capture,
     IWineD3DStateBlockImpl_Apply,
     IWineD3DStateBlockImpl_InitStartupStateBlock
 };
+
+HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl *device, WINED3DSTATEBLOCKTYPE type)
+{
+    unsigned int i;
+    HRESULT hr;
+
+    stateblock->lpVtbl = &IWineD3DStateBlock_Vtbl;
+    stateblock->ref = 1;
+    stateblock->device = device;
+    stateblock->blockType = type;
+
+    for (i = 0; i < LIGHTMAP_SIZE; i++)
+    {
+        list_init(&stateblock->lightMap[i]);
+    }
+
+    hr = stateblock_allocate_shader_constants(stateblock);
+    if (FAILED(hr)) return hr;
+
+    /* The WINED3DSBT_INIT stateblock type is used during initialization to
+     * produce a placeholder stateblock so other functions called can update a
+     * state block. */
+    if (type == WINED3DSBT_INIT || type == WINED3DSBT_RECORDED) return WINED3D_OK;
+
+    TRACE("Updating changed flags appropriate for type %#x.\n", type);
+
+    switch (type)
+    {
+        case WINED3DSBT_ALL:
+            stateblock_init_lights(stateblock, device->stateBlock->lightMap);
+            stateblock_savedstates_set_all(&stateblock->changed, device->d3d_vshader_constantF,
+                                           device->d3d_pshader_constantF);
+            break;
+
+        case WINED3DSBT_PIXELSTATE:
+            stateblock_savedstates_set_pixel(&stateblock->changed, device->d3d_pshader_constantF);
+            break;
+
+        case WINED3DSBT_VERTEXSTATE:
+            stateblock_init_lights(stateblock, device->stateBlock->lightMap);
+            stateblock_savedstates_set_vertex(&stateblock->changed, device->d3d_vshader_constantF);
+            break;
+
+        default:
+            FIXME("Unrecognized state block type %#x.\n", type);
+            break;
+    }
+
+    stateblock_init_contained_states(stateblock);
+    IWineD3DStateBlockImpl_Capture((IWineD3DStateBlock *)stateblock);
+
+    return WINED3D_OK;
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 25949)
@@ -48,6 +48,7 @@
 static void surface_cleanup(IWineD3DSurfaceImpl *This)
 {
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    struct wined3d_context *context = NULL;
     renderbuffer_entry_t *entry, *entry2;
 
@@ -60,5 +61,5 @@
     if (device->render_targets && device->render_targets[0])
     {
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
     }
 
@@ -103,4 +104,6 @@
 
     resource_cleanup((IWineD3DResource *)This);
+
+    if (context) context_release(context);
 }
 
@@ -136,5 +139,5 @@
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, &GLINFO_LOCATION);
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
     void (*cleanup)(IWineD3DSurfaceImpl *This);
     unsigned int resource_size;
@@ -329,9 +332,9 @@
     glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
     LEAVE_GL();
-    active_sampler = This->resource.wineD3DDevice->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
+    active_sampler = This->resource.device->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
 
     if (active_sampler != WINED3D_UNMAPPED_STAGE)
     {
-        IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(active_sampler));
+        IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_SAMPLER(active_sampler));
     }
     IWineD3DSurface_BindTexture((IWineD3DSurface *)This, srgb);
@@ -352,5 +355,5 @@
 #undef GLINFO_LOCATION
 
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION This->resource.device->adapter->gl_info
 
 /* This call just downloads data, the caller is responsible for binding the
@@ -400,5 +403,5 @@
 
         /* In case of P8 the index is stored in the alpha component if the primary render target uses P8 */
-        if (format_desc->format == WINED3DFMT_P8_UINT && primary_render_target_is_p8(This->resource.wineD3DDevice))
+        if (format_desc->format == WINED3DFMT_P8_UINT && primary_render_target_is_p8(This->resource.device))
         {
             format = GL_ALPHA;
@@ -407,5 +410,5 @@
 
         if (This->Flags & SFLAG_NONPOW2) {
-            unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
+            unsigned char alignment = This->resource.device->surface_alignment;
             src_pitch = format_desc->byte_count * This->pow2Width;
             dst_pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This);
@@ -560,4 +563,5 @@
 /* Context activation is done by the caller. */
 static void surface_allocate_surface(IWineD3DSurfaceImpl *This, GLenum internal, GLsizei width, GLsizei height, GLenum format, GLenum type) {
+    const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
     const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
     BOOL enable_client_storage = FALSE;
@@ -572,5 +576,6 @@
     ENTER_GL();
 
-    if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
+    if (gl_info->supported[APPLE_CLIENT_STORAGE])
+    {
         if(This->Flags & (SFLAG_NONPOW2 | SFLAG_DIBSECTION | SFLAG_OVERSIZE | SFLAG_CONVERTED) || This->resource.allocatedMemory == NULL) {
             /* In some cases we want to disable client storage.
@@ -620,5 +625,5 @@
 void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    const struct wined3d_gl_info *gl_info = &This->resource.wineD3DDevice->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
     renderbuffer_entry_t *entry;
     GLuint renderbuffer = 0;
@@ -666,14 +671,29 @@
 }
 
-GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain) {
+GLenum surface_get_gl_buffer(IWineD3DSurface *iface)
+{
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    IWineD3DSwapChainImpl *swapchain_impl = (IWineD3DSwapChainImpl *)swapchain;
-
-    TRACE("(%p) : swapchain %p\n", This, swapchain);
-
-    if (swapchain_impl->backBuffer && swapchain_impl->backBuffer[0] == iface) {
+    IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)This->container;
+
+    TRACE("iface %p.\n", iface);
+
+    if (!(This->Flags & SFLAG_SWAPCHAIN))
+    {
+        ERR("Surface %p is not on a swapchain.\n", iface);
+        return GL_NONE;
+    }
+
+    if (swapchain->backBuffer && swapchain->backBuffer[0] == iface)
+    {
+        if (swapchain->render_to_fbo)
+        {
+            TRACE("Returning GL_COLOR_ATTACHMENT0\n");
+            return GL_COLOR_ATTACHMENT0;
+        }
         TRACE("Returning GL_BACK\n");
         return GL_BACK;
-    } else if (swapchain_impl->frontBuffer == iface) {
+    }
+    else if (swapchain->frontBuffer == iface)
+    {
         TRACE("Returning GL_FRONT\n");
         return GL_FRONT;
@@ -758,6 +778,6 @@
     /* TODO: check for locks */
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+    IWineD3DDeviceImpl *device = This->resource.device;
     IWineD3DBaseTexture *baseTexture = NULL;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
 
     TRACE("(%p)Checking to see if the container is a base texture\n", This);
@@ -768,9 +788,9 @@
         IWineD3DBaseTexture_Release(baseTexture);
     } else {
+        struct wined3d_context *context = NULL;
+
         TRACE("(%p) : About to load surface\n", This);
 
-        if(!device->isInDraw) {
-            ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-        }
+        if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
 
         if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
@@ -796,6 +816,7 @@
             LEAVE_GL();
         }
-    }
-    return;
+
+        if (context) context_release(context);
+    }
 }
 
@@ -823,11 +844,36 @@
 }
 
+BOOL surface_init_sysmem(IWineD3DSurface *iface)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
+
+    if(!This->resource.allocatedMemory)
+    {
+        This->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size + RESOURCE_ALIGNMENT);
+        if(!This->resource.heapMemory)
+        {
+            ERR("Out of memory\n");
+            return FALSE;
+        }
+        This->resource.allocatedMemory =
+            (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
+    }
+    else
+    {
+        memset(This->resource.allocatedMemory, 0, This->resource.size);
+    }
+
+    IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
+    return TRUE;
+}
+
 static void WINAPI IWineD3DSurfaceImpl_UnLoad(IWineD3DSurface *iface) {
     IWineD3DBaseTexture *texture = NULL;
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-    const struct wined3d_context *context;
+    IWineD3DDeviceImpl *device = This->resource.device;
     const struct wined3d_gl_info *gl_info;
     renderbuffer_entry_t *entry, *entry2;
+    struct wined3d_context *context;
+
     TRACE("(%p)\n", iface);
 
@@ -838,16 +884,10 @@
          * opengl resources, so we cannot leave early.
          *
-         * Put the most up to date surface location into the drawable. D3D-wise this content
-         * is undefined, so it would be nowhere, but that would make the location management
-         * more complicated. The drawable is a sane location, because if we mark sysmem or
-         * texture up to date, drawPrim will copy the uninitialized texture or sysmem to the
-         * uninitialized drawable. That's pointless and we'd have to allocate the texture /
-         * sysmem copy here.
+         * Put the surfaces into sysmem, and reset the content. The D3D content is undefined,
+         * but we can't set the sysmem INDRAWABLE because when we're rendering the swapchain
+         * or the depth stencil into an FBO the texture or render buffer will be removed
+         * and all flags get lost
          */
-        if (This->resource.usage & WINED3DUSAGE_DEPTHSTENCIL) {
-            IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
-        } else {
-            IWineD3DSurface_ModifyLocation(iface, SFLAG_INDRAWABLE, TRUE);
-        }
+        surface_init_sysmem(iface);
     } else {
         /* Load the surface into system memory */
@@ -859,5 +899,5 @@
     This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
 
-    context = ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
     gl_info = context->gl_info;
 
@@ -895,5 +935,6 @@
         IWineD3DBaseTexture_Release(texture);
     }
-    return;
+
+    context_release(context);
 }
 
@@ -903,7 +944,8 @@
 
 /* Read the framebuffer back into the surface */
-static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, void *dest, UINT pitch) {
-    IWineD3DSwapChainImpl *swapchain;
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
+static void read_from_framebuffer(IWineD3DSurfaceImpl *This, const RECT *rect, void *dest, UINT pitch)
+{
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
+    struct wined3d_context *context;
     BYTE *mem;
     GLint fmt;
@@ -932,5 +974,5 @@
      * context->last_was_blit set on the unlock.
      */
-    ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
+    context = context_acquire(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
     ENTER_GL();
 
@@ -939,14 +981,6 @@
      * that reads sets the read buffer as desired.
      */
-    if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain)))
-    {
-        GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
-        TRACE("Locking %#x buffer\n", buffer);
-        glReadBuffer(buffer);
-        checkGLcall("glReadBuffer");
-
-        IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
-        srcIsUpsideDown = FALSE;
-    } else {
+    if (surface_is_offscreen((IWineD3DSurface *) This))
+    {
         /* Locking the primary render target which is not on a swapchain(=offscreen render target).
          * Read from the back buffer
@@ -955,4 +989,13 @@
         glReadBuffer(myDevice->offscreenBuffer);
         srcIsUpsideDown = TRUE;
+    }
+    else
+    {
+        /* Onscreen surfaces are always part of a swapchain */
+        GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
+        TRACE("Locking %#x buffer\n", buffer);
+        glReadBuffer(buffer);
+        checkGLcall("glReadBuffer");
+        srcIsUpsideDown = FALSE;
     }
 
@@ -1100,4 +1143,5 @@
 
     LEAVE_GL();
+    context_release(context);
 
     /* For P8 textures we need to perform an inverse palette lookup. This is done by searching for a palette
@@ -1145,6 +1189,6 @@
 static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This, BOOL srgb)
 {
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-    IWineD3DSwapChainImpl *swapchain;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    struct wined3d_context *context;
     int bpp;
     GLenum format, internal, type;
@@ -1159,5 +1203,5 @@
      * states in the stateblock, and no driver was found yet that had bugs in that regard.
      */
-    ActivateContext(device, (IWineD3DSurface *) This, CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(device, (IWineD3DSurface *) This, CTXUSAGE_RESOURCELOAD);
     surface_bind_and_dirtify(This, srgb);
 
@@ -1170,7 +1214,7 @@
      * that reads sets the read buffer as desired.
      */
-    if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)This, &IID_IWineD3DSwapChain, (void **)&swapchain)))
-    {
-        GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
+    if (!surface_is_offscreen((IWineD3DSurface *)This))
+    {
+        GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
         TRACE("Locking %#x buffer\n", buffer);
 
@@ -1179,7 +1223,7 @@
         checkGLcall("glReadBuffer");
         LEAVE_GL();
-
-        IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
-    } else {
+    }
+    else
+    {
         /* Locking the primary render target which is not on a swapchain(=offscreen render target).
          * Read from the back buffer
@@ -1213,8 +1257,15 @@
 
     LEAVE_GL();
+
+    context_release(context);
+
     TRACE("Updated target %d\n", This->texture_target);
 }
 
-static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This) {
+static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This)
+{
+    IWineD3DDeviceImpl *device = This->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+
     /* Performance optimization: Count how often a surface is locked, if it is locked regularly do not throw away the system memory copy.
      * This avoids the need to download the surface from opengl all the time. The surface is still downloaded if the opengl texture is
@@ -1233,9 +1284,12 @@
      * Also don't create a PBO for systemmem surfaces.
      */
-    if(GL_SUPPORT(ARB_PIXEL_BUFFER_OBJECT) && (This->Flags & SFLAG_DYNLOCK) && !(This->Flags & (SFLAG_PBO | SFLAG_CONVERTED | SFLAG_NONPOW2)) && (This->resource.pool != WINED3DPOOL_SYSTEMMEM)) {
+    if (gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] && (This->Flags & SFLAG_DYNLOCK)
+            && !(This->Flags & (SFLAG_PBO | SFLAG_CONVERTED | SFLAG_NONPOW2))
+            && (This->resource.pool != WINED3DPOOL_SYSTEMMEM))
+    {
         GLenum error;
-        IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        struct wined3d_context *context;
+
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
 
@@ -1265,5 +1319,8 @@
         This->Flags |= SFLAG_PBO;
         LEAVE_GL();
-    } else if(!(This->resource.allocatedMemory || This->Flags & SFLAG_PBO)) {
+        context_release(context);
+    }
+    else if (!(This->resource.allocatedMemory || This->Flags & SFLAG_PBO))
+    {
         /* Whatever surface we have, make sure that there is memory allocated for the downloaded copy,
          * or a pbo to map
@@ -1282,5 +1339,5 @@
 static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    IWineD3DDeviceImpl  *myDevice = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
     const RECT *pass_rect = pRect;
 
@@ -1332,6 +1389,9 @@
 
 lock_end:
-    if(This->Flags & SFLAG_PBO) {
-        ActivateContext(myDevice, NULL, CTXUSAGE_RESOURCELOAD);
+    if (This->Flags & SFLAG_PBO)
+    {
+        struct wined3d_context *context;
+
+        context = context_acquire(myDevice, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
         GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
@@ -1351,4 +1411,5 @@
 
         LEAVE_GL();
+        context_release(context);
     }
 
@@ -1381,23 +1442,22 @@
     GLint skipBytes = 0;
     UINT pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This);    /* target is argb, 4 byte */
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
-    IWineD3DSwapChainImpl *swapchain;
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
+    struct wined3d_context *context;
 
     /* Activate the correct context for the render target */
-    ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
+    context = context_acquire(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
     ENTER_GL();
 
-    if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)This, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
-        GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
-        TRACE("Unlocking %#x buffer\n", buffer);
-        glDrawBuffer(buffer);
-        checkGLcall("glDrawBuffer");
-
-        IWineD3DSwapChain_Release((IWineD3DSwapChain *)swapchain);
-    } else {
+    if (!surface_is_offscreen((IWineD3DSurface *)This))
+    {
+        GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
+        TRACE("Unlocking %#x buffer.\n", buffer);
+        context_set_draw_buffer(context, buffer);
+    }
+    else
+    {
         /* Primary offscreen render target */
-        TRACE("Offscreen render target\n");
-        glDrawBuffer(myDevice->offscreenBuffer);
-        checkGLcall("glDrawBuffer(myDevice->offscreenBuffer)");
+        TRACE("Offscreen render target.\n");
+        context_set_draw_buffer(context, myDevice->offscreenBuffer);
     }
 
@@ -1466,22 +1526,11 @@
     checkGLcall("glPixelStorei(GL_UNPACK_ROW_LENGTH)");
 
-    if(!swapchain) {
-        glDrawBuffer(myDevice->offscreenBuffer);
-        checkGLcall("glDrawBuffer(myDevice->offscreenBuffer)");
-    } else if(swapchain->backBuffer) {
-        glDrawBuffer(GL_BACK);
-        checkGLcall("glDrawBuffer(GL_BACK)");
-    } else {
-        glDrawBuffer(GL_FRONT);
-        checkGLcall("glDrawBuffer(GL_FRONT)");
-    }
     LEAVE_GL();
-
-    return;
+    context_release(context);
 }
 
 static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    IWineD3DDeviceImpl  *myDevice = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
     BOOL fullsurface;
 
@@ -1491,7 +1540,11 @@
     }
 
-    if (This->Flags & SFLAG_PBO) {
+    if (This->Flags & SFLAG_PBO)
+    {
+        struct wined3d_context *context;
+
         TRACE("Freeing PBO memory\n");
-        ActivateContext(myDevice, NULL, CTXUSAGE_RESOURCELOAD);
+
+        context = context_acquire(myDevice, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
         GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
@@ -1500,4 +1553,6 @@
         checkGLcall("glUnmapBufferARB");
         LEAVE_GL();
+        context_release(context);
+
         This->resource.allocatedMemory = NULL;
     }
@@ -1585,4 +1640,35 @@
 }
 
+static void surface_release_client_storage(IWineD3DSurface *iface)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
+    struct wined3d_context *context;
+
+    context = context_acquire(This->resource.device, NULL, CTXUSAGE_RESOURCELOAD);
+
+    ENTER_GL();
+    glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
+    if(This->texture_name)
+    {
+        surface_bind_and_dirtify(This, FALSE);
+        glTexImage2D(This->texture_target, This->texture_level,
+                     GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+    }
+    if(This->texture_name_srgb)
+    {
+        surface_bind_and_dirtify(This, TRUE);
+        glTexImage2D(This->texture_target, This->texture_level,
+                     GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+    }
+    glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
+
+    LEAVE_GL();
+    context_release(context);
+
+    IWineD3DSurface_ModifyLocation(iface, SFLAG_INSRGBTEX, FALSE);
+    IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
+    surface_force_reload(iface);
+}
+
 static HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC)
 {
@@ -1611,9 +1697,10 @@
     /* Create a DIB section if there isn't a hdc yet */
     if(!This->hDC) {
+        if(This->Flags & SFLAG_CLIENT) {
+            IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL);
+            surface_release_client_storage(iface);
+        }
         hr = IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
         if(FAILED(hr)) return WINED3DERR_INVALIDCALL;
-        if(This->Flags & SFLAG_CLIENT) {
-            surface_internal_preload(iface, SRGB_RGB);
-        }
 
         /* Use the dib section from now on if we are not using a PBO */
@@ -1652,5 +1739,5 @@
             IWineD3DSurfaceImpl *dds_primary;
             IWineD3DSwapChainImpl *swapchain;
-            swapchain = (IWineD3DSwapChainImpl *)This->resource.wineD3DDevice->swapchains[0];
+            swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[0];
             dds_primary = (IWineD3DSurfaceImpl *)swapchain->frontBuffer;
             if (dds_primary && dds_primary->palette)
@@ -1710,5 +1797,6 @@
     BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & WINEDDSD_CKSRCBLT);
     const struct GlPixelFormatDesc *glDesc = This->resource.format_desc;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
     /* Default values: From the surface */
@@ -1722,5 +1810,5 @@
     }
     else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET
-            && !(This->Flags & SFLAG_SWAPCHAIN))
+            && surface_is_offscreen((IWineD3DSurface *) This))
     {
         *internal = glDesc->rtInternal;
@@ -1744,9 +1832,8 @@
              * conflicts with this.
              */
-            if( !(GL_SUPPORT(EXT_PALETTED_TEXTURE) ||
-                  (GL_SUPPORT(ARB_FRAGMENT_PROGRAM) &&
-                   device->render_targets &&
-                   This == (IWineD3DSurfaceImpl*)device->render_targets[0])) ||
-                colorkey_active || !use_texturing ) {
+            if (!(gl_info->supported[EXT_PALETTED_TEXTURE] || (gl_info->supported[ARB_FRAGMENT_PROGRAM]
+                    && device->render_targets && This == (IWineD3DSurfaceImpl*)device->render_targets[0]))
+                    || colorkey_active || !use_texturing)
+            {
                 *format = GL_RGBA;
                 *internal = GL_RGBA;
@@ -1759,5 +1846,6 @@
                 }
             }
-            else if(!GL_SUPPORT(EXT_PALETTED_TEXTURE) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
+            else if (!gl_info->supported[EXT_PALETTED_TEXTURE] && gl_info->supported[ARB_FRAGMENT_PROGRAM])
+            {
                 *format = GL_ALPHA;
                 *type = GL_UNSIGNED_BYTE;
@@ -1816,5 +1904,5 @@
 
         case WINED3DFMT_R8G8_SNORM:
-            if (GL_SUPPORT(NV_TEXTURE_SHADER)) break;
+            if (gl_info->supported[NV_TEXTURE_SHADER]) break;
             *convert = CONVERT_V8U8;
             *format = GL_BGR;
@@ -1825,5 +1913,6 @@
         case WINED3DFMT_R5G5_SNORM_L6_UNORM:
             *convert = CONVERT_L6V5U5;
-            if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
+            if (gl_info->supported[NV_TEXTURE_SHADER])
+            {
                 *target_bpp = 3;
                 /* Use format and types from table */
@@ -1839,5 +1928,6 @@
             *convert = CONVERT_X8L8V8U8;
             *target_bpp = 4;
-            if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
+            if (gl_info->supported[NV_TEXTURE_SHADER])
+            {
                 /* Use formats from gl table. It is a bit unfortunate, but the conversion
                  * is needed to set the X format to 255 to get 1.0 for alpha when sampling
@@ -1853,5 +1943,5 @@
 
         case WINED3DFMT_R8G8B8A8_SNORM:
-            if (GL_SUPPORT(NV_TEXTURE_SHADER)) break;
+            if (gl_info->supported[NV_TEXTURE_SHADER]) break;
             *convert = CONVERT_Q8W8V8U8;
             *format = GL_BGRA;
@@ -1861,5 +1951,5 @@
 
         case WINED3DFMT_R16G16_SNORM:
-            if (GL_SUPPORT(NV_TEXTURE_SHADER)) break;
+            if (gl_info->supported[NV_TEXTURE_SHADER]) break;
             *convert = CONVERT_V16U16;
             *format = GL_BGR;
@@ -1901,6 +1991,6 @@
 
         case WINED3DFMT_S1_UINT_D15_UNORM:
-            if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
-                    || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+            if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
+                    || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
             {
                 *convert = CONVERT_D15S1;
@@ -1910,6 +2000,6 @@
 
         case WINED3DFMT_S4X4_UINT_D24_UNORM:
-            if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
-                    || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+            if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
+                    || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
             {
                 *convert = CONVERT_D24X4S4;
@@ -1918,5 +2008,5 @@
 
         case WINED3DFMT_S8_UINT_D24_FLOAT:
-            if (GL_SUPPORT(ARB_DEPTH_BUFFER_FLOAT))
+            if (gl_info->supported[ARB_DEPTH_BUFFER_FLOAT])
             {
                 *convert = CONVERT_D24FS8;
@@ -1934,5 +2024,5 @@
 static void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey)
 {
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
     IWineD3DPaletteImpl *pal = This->palette;
     BOOL index_in_alpha = FALSE;
@@ -1948,5 +2038,5 @@
     if (!pal)
     {
-        UINT dxVersion = ((IWineD3DImpl *)device->wineD3D)->dxVersion;
+        UINT dxVersion = ((IWineD3DImpl *)device->wined3d)->dxVersion;
 
         /* In DirectDraw the palette is a property of the surface, there are no such things as device palettes. */
@@ -2015,4 +2105,6 @@
         UINT height, UINT outpitch, CONVERT_TYPES convert, IWineD3DSurfaceImpl *This)
 {
+    IWineD3DDeviceImpl *device = This->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     const BYTE *source;
     BYTE *dest;
@@ -2224,5 +2316,6 @@
             unsigned char *Dest;
 
-            if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
+            if (gl_info->supported[NV_TEXTURE_SHADER])
+            {
                 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
                  * fixed function and shaders without further conversion once the surface is
@@ -2278,5 +2371,6 @@
             unsigned char *Dest;
 
-            if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
+            if (gl_info->supported[NV_TEXTURE_SHADER])
+            {
                 /* This implementation works with the fixed function pipeline and shaders
                  * without further modification after converting the surface.
@@ -2450,10 +2544,11 @@
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     BYTE table[256][4];
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
     d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK));
 
     /* Try to use the paletted texture extension */
-    if(GL_SUPPORT(EXT_PALETTED_TEXTURE))
+    if (gl_info->supported[EXT_PALETTED_TEXTURE])
     {
         TRACE("Using GL_EXT_PALETTED_TEXTURE for 8-bit paletted texture support\n");
@@ -2514,6 +2609,7 @@
 }
 
-BOOL palette9_changed(IWineD3DSurfaceImpl *This) {
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+BOOL palette9_changed(IWineD3DSurfaceImpl *This)
+{
+    IWineD3DDeviceImpl *device = This->resource.device;
 
     if (This->palette || (This->resource.format_desc->format != WINED3DFMT_P8_UINT
@@ -2526,6 +2622,8 @@
     }
 
-    if(This->palette9) {
-        if(memcmp(This->palette9, &device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256) == 0) {
+    if (This->palette9)
+    {
+        if (!memcmp(This->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256))
+        {
             return FALSE;
         }
@@ -2533,5 +2631,5 @@
         This->palette9 = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256);
     }
-    memcpy(This->palette9, &device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256);
+    memcpy(This->palette9, device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256);
     return TRUE;
 }
@@ -2612,6 +2710,6 @@
     /* TODO: check for locks */
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+    IWineD3DDeviceImpl *device = This->resource.device;
     IWineD3DBaseTexture *baseTexture = NULL;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
 
     TRACE("(%p)Checking to see if the container is a base texture\n", This);
@@ -2620,12 +2718,14 @@
         IWineD3DBaseTexture_BindTexture(baseTexture, srgb);
         IWineD3DBaseTexture_Release(baseTexture);
-    } else {
+    }
+    else
+    {
+        struct wined3d_context *context = NULL;
         GLuint *name;
+
         TRACE("(%p) : Binding surface\n", This);
 
         name = srgb ? &This->texture_name_srgb : &This->texture_name;
-        if(!device->isInDraw) {
-            ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-        }
+        if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
 
         ENTER_GL();
@@ -2661,6 +2761,7 @@
 
         LEAVE_GL();
-    }
-    return;
+
+        if (context) context_release(context);
+    }
 }
 
@@ -2719,5 +2820,5 @@
         glGetIntegerv(GL_READ_BUFFER, &prevRead);
         checkGLcall("glGetIntegerv");
-        glReadBuffer(swapChain ? GL_BACK : This->resource.wineD3DDevice->offscreenBuffer);
+        glReadBuffer(swapChain ? GL_BACK : This->resource.device->offscreenBuffer);
         checkGLcall("glReadBuffer");
         glCopyTexImage2D(GL_TEXTURE_2D,
@@ -2857,9 +2958,5 @@
         /* For client textures opengl has to be notified */
         if(This->Flags & SFLAG_CLIENT) {
-            DWORD oldFlags = This->Flags;
-            This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
-            if(oldFlags & SFLAG_ALLOCATED) surface_internal_preload(iface, SRGB_RGB);
-            if(oldFlags & SFLAG_SRGBALLOCATED) surface_internal_preload(iface, SRGB_SRGB);
-            /* And hope that the app behaves correctly and did not free the old surface memory before setting a new pointer */
+            surface_release_client_storage(iface);
         }
 
@@ -2874,9 +2971,5 @@
 
         if(This->Flags & SFLAG_CLIENT) {
-            DWORD oldFlags = This->Flags;
-            This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
-            /* This respecifies an empty texture and opengl knows that the old memory is gone */
-            if(oldFlags & SFLAG_ALLOCATED) surface_internal_preload(iface, SRGB_RGB);
-            if(oldFlags & SFLAG_SRGBALLOCATED) surface_internal_preload(iface, SRGB_SRGB);
+            surface_release_client_storage(iface);
         }
     }
@@ -3024,14 +3117,14 @@
  */
 static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
-        IWineD3DSwapChainImpl *swapchain, const WINED3DRECT *srect, const WINED3DRECT *drect,
-        BOOL upsidedown, WINED3DTEXTUREFILTERTYPE Filter)
+        const WINED3DRECT *srect, const WINED3DRECT *drect, BOOL upsidedown, WINED3DTEXTUREFILTERTYPE Filter)
 {
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
     float xrel, yrel;
     UINT row;
     IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
-
-
-    ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
+    struct wined3d_context *context;
+
+
+    context = context_acquire(myDevice, SrcSurface, CTXUSAGE_BLIT);
     surface_internal_preload((IWineD3DSurface *) This, SRGB_RGB);
     ENTER_GL();
@@ -3040,11 +3133,12 @@
     glBindTexture(This->texture_target, This->texture_name);
     checkGLcall("glBindTexture");
-    if(!swapchain) {
+    if(surface_is_offscreen(SrcSurface)) {
         TRACE("Reading from an offscreen target\n");
         upsidedown = !upsidedown;
         glReadBuffer(myDevice->offscreenBuffer);
-    } else {
-        GLenum buffer = surface_get_gl_buffer(SrcSurface, (IWineD3DSwapChain *)swapchain);
-        glReadBuffer(buffer);
+    }
+    else
+    {
+        glReadBuffer(surface_get_gl_buffer(SrcSurface));
     }
     checkGLcall("glReadBuffer");
@@ -3108,4 +3202,5 @@
 
     LEAVE_GL();
+    context_release(context);
 
     /* The texture is now most up to date - If the surface is a render target and has a drawable, this
@@ -3120,6 +3215,6 @@
         BOOL upsidedown, WINED3DTEXTUREFILTERTYPE Filter)
 {
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
     GLuint src, backup = 0;
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
     IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
     float left, right, top, bottom; /* Texture coordinates */
@@ -3130,11 +3225,13 @@
     GLenum texture_target;
     BOOL noBackBufferBackup;
+    BOOL src_offscreen;
 
     TRACE("Using hwstretch blit\n");
     /* Activate the Proper context for reading from the source surface, set it up for blitting */
-    context = ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
+    context = context_acquire(myDevice, SrcSurface, CTXUSAGE_BLIT);
     surface_internal_preload((IWineD3DSurface *) This, SRGB_RGB);
 
-    noBackBufferBackup = !swapchain && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
+    src_offscreen = surface_is_offscreen(SrcSurface);
+    noBackBufferBackup = src_offscreen && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
     if (!noBackBufferBackup && !Src->texture_name)
     {
@@ -3152,5 +3249,5 @@
         drawBuffer = GL_AUX1;
     }
-    else if ((swapchain || myDevice->offscreenBuffer == GL_BACK) && context->aux_buffers >= 1)
+    else if ((!src_offscreen || myDevice->offscreenBuffer == GL_BACK) && context->aux_buffers >= 1)
     {
         /* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */
@@ -3178,10 +3275,13 @@
     }
 
-    if(swapchain) {
-        glReadBuffer(surface_get_gl_buffer(SrcSurface, (IWineD3DSwapChain *)swapchain));
-    } else {
+    if (src_offscreen)
+    {
         TRACE("Reading from an offscreen target\n");
         upsidedown = !upsidedown;
         glReadBuffer(myDevice->offscreenBuffer);
+    }
+    else
+    {
+        glReadBuffer(surface_get_gl_buffer(SrcSurface));
     }
 
@@ -3264,5 +3364,5 @@
     glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
 
-    glDrawBuffer(drawBuffer);
+    context_set_draw_buffer(context, drawBuffer);
     glReadBuffer(drawBuffer);
 
@@ -3341,7 +3441,4 @@
             glVertex2i(fbwidth, 0);
         glEnd();
-    } else {
-        /* Restore the old draw buffer */
-        glDrawBuffer(GL_BACK);
     }
     glDisable(texture_target);
@@ -3360,4 +3457,5 @@
 
     LEAVE_GL();
+    context_release(context);
 
     /* The texture is now most up to date - If the surface is a render target and has a drawable, this
@@ -3372,6 +3470,6 @@
         WINED3DTEXTUREFILTERTYPE Filter)
 {
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
     WINED3DRECT rect;
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
     IWineD3DSwapChainImpl *srcSwapchain = NULL, *dstSwapchain = NULL;
     IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
@@ -3618,5 +3716,5 @@
                                     rect.y2 - rect.y1 > Src->currentDesc.Height) {
             TRACE("No stretching in x direction, using direct framebuffer -> texture copy\n");
-            fb_copy_to_texture_direct(This, SrcSurface, srcSwapchain, &srect, &rect, upsideDown, Filter);
+            fb_copy_to_texture_direct(This, SrcSurface, &srect, &rect, upsideDown, Filter);
         } else {
             TRACE("Using hardware stretching to flip / stretch the texture\n");
@@ -3642,4 +3740,5 @@
         DWORD oldCKeyFlags = Src->CKeyFlags;
         WINEDDCOLORKEY oldBltCKey = Src->SrcBltCKey;
+        struct wined3d_context *context;
         RECT SourceRectangle;
         BOOL paletteOverride = FALSE;
@@ -3718,5 +3817,5 @@
 
         /* Activate the destination context, set it up for blitting */
-        ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
+        context = context_acquire(myDevice, (IWineD3DSurface *)This, CTXUSAGE_BLIT);
 
         /* The coordinates of the ddraw front buffer are always fullscreen ('screen coordinates',
@@ -3836,4 +3935,6 @@
             wglFlush();
 
+        context_release(context);
+
         /* TODO: If the surface is locked often, perform the Blt in software on the memory instead */
         /* The surface is now in the drawable. On onscreen surfaces or without fbos the texture
@@ -3919,5 +4020,5 @@
         IWineD3DSurface *SrcSurface, const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx)
 {
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
     float depth;
 
@@ -3931,5 +4032,5 @@
                 depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x0000fffe;
                 break;
-            case WINED3DFMT_S8_UINT_D24_UNORM:
+            case WINED3DFMT_D24_UNORM_S8_UINT:
             case WINED3DFMT_X8D24_UNORM:
                 depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x00ffffff;
@@ -3960,5 +4061,6 @@
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
+
     TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
     TRACE("(%p): Usage is %s\n", This, debug_d3dusage(This->resource.usage));
@@ -4001,8 +4103,9 @@
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
     IWineD3DSurfaceImpl *srcImpl = (IWineD3DSurfaceImpl *) Source;
-    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *myDevice = This->resource.device;
+
     TRACE("(%p)->(%d, %d, %p, %p, %08x\n", iface, dstx, dsty, Source, rsrc, trans);
 
-    if ( (This->Flags & SFLAG_LOCKED) || ((srcImpl != NULL) && (srcImpl->Flags & SFLAG_LOCKED)))
+    if ( (This->Flags & SFLAG_LOCKED) || (srcImpl->Flags & SFLAG_LOCKED))
     {
         WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
@@ -4012,5 +4115,5 @@
     if(myDevice->inScene &&
        (iface == myDevice->stencilBufferTarget ||
-       (Source && Source == myDevice->stencilBufferTarget))) {
+       (Source == myDevice->stencilBufferTarget))) {
         TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
         return WINED3DERR_INVALIDCALL;
@@ -4019,5 +4122,5 @@
     /* Special cases for RenderTargets */
     if( (This->resource.usage & WINED3DUSAGE_RENDERTARGET) ||
-        ( srcImpl && (srcImpl->resource.usage & WINED3DUSAGE_RENDERTARGET) )) {
+        (srcImpl->resource.usage & WINED3DUSAGE_RENDERTARGET) ) {
 
         RECT SrcRect, DstRect;
@@ -4083,5 +4186,6 @@
         if((This->resource.usage & WINED3DUSAGE_RENDERTARGET) && (convert == NO_CONVERSION))
         {
-            IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+            IWineD3DDeviceImpl *device = This->resource.device;
+            struct wined3d_context *context;
 
             /* Make sure the texture is up to date. This call doesn't do anything if the texture is already up to date. */
@@ -4092,6 +4196,7 @@
 
             /* Re-upload the palette */
-            ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+            context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
             d3dfmt_p8_upload_palette(iface, convert);
+            context_release(context);
         } else {
             if(!(This->Flags & SFLAG_INSYSMEM)) {
@@ -4125,4 +4230,5 @@
     /** Check against the maximum texture sizes supported by the video card **/
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
+    const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
     unsigned int pow2Width, pow2Height;
 
@@ -4131,8 +4237,11 @@
 
     /* Non-power2 support */
-    if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) || GL_SUPPORT(WINE_NORMALIZED_TEXRECT)) {
+    if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[WINE_NORMALIZED_TEXRECT])
+    {
         pow2Width = This->currentDesc.Width;
         pow2Height = This->currentDesc.Height;
-    } else {
+    }
+    else
+    {
         /* Find the nearest pow2 match */
         pow2Width = pow2Height = 1;
@@ -4159,5 +4268,7 @@
 
     TRACE("%p\n", This);
-    if ((This->pow2Width > GL_LIMITS(texture_size) || This->pow2Height > GL_LIMITS(texture_size)) && !(This->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL))) {
+    if ((This->pow2Width > gl_info->limits.texture_size || This->pow2Height > gl_info->limits.texture_size)
+            && !(This->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL)))
+    {
         /* one of three options
         1: Do the same as we do with nonpow 2 and scale the texture, (any texture ops would require the texture to be scaled which is potentially slow)
@@ -4181,6 +4292,7 @@
            doesn't work in combination with ARB_TEXTURE_RECTANGLE.
         */
-        if (This->Flags & SFLAG_NONPOW2 && GL_SUPPORT(ARB_TEXTURE_RECTANGLE)
-                && !(This->resource.format_desc->format == WINED3DFMT_P8_UINT && GL_SUPPORT(EXT_PALETTED_TEXTURE)
+        if (This->Flags & SFLAG_NONPOW2 && gl_info->supported[ARB_TEXTURE_RECTANGLE]
+                && !(This->resource.format_desc->format == WINED3DFMT_P8_UINT
+                && gl_info->supported[EXT_PALETTED_TEXTURE]
                 && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
         {
@@ -4308,5 +4420,5 @@
 static void surface_depth_blt(IWineD3DSurfaceImpl *This, GLuint texture, GLsizei w, GLsizei h, GLenum target)
 {
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
     struct depth_blt_info info;
     GLint old_binding = 0;
@@ -4367,5 +4479,5 @@
 {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
 
@@ -4486,10 +4598,12 @@
 
     if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
-        if (This->Flags & SFLAG_SWAPCHAIN)
+        if (surface_is_offscreen(iface))
+        {
+            /* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
+            if (flag & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)) flag |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
+        }
+        else
         {
             TRACE("Surface %p is an onscreen surface\n", iface);
-        } else {
-            /* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
-            if (flag & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)) flag |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
         }
     }
@@ -4551,10 +4665,10 @@
 static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT *rect_in)
 {
-    const struct wined3d_context *context;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    struct wined3d_context *context;
     struct coords coords[4];
     RECT rect;
     IWineD3DSwapChain *swapchain;
     IWineD3DBaseTexture *texture;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
     GLenum bind_target;
     struct float_rect f;
@@ -4658,5 +4772,5 @@
     }
 
-    context = ActivateContext(device, (IWineD3DSurface*)This, CTXUSAGE_BLIT);
+    context = context_acquire(device, (IWineD3DSurface*)This, CTXUSAGE_BLIT);
 
     ENTER_GL();
@@ -4718,4 +4832,6 @@
         }
     }
+
+    context_release(context);
 }
 
@@ -4743,5 +4859,6 @@
 static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     GLenum format, internal, type;
     CONVERT_TYPES convert;
@@ -4750,14 +4867,18 @@
     BYTE *mem;
     BOOL drawable_read_ok = TRUE;
+    BOOL in_fbo = FALSE;
 
     if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
-        if (This->Flags & SFLAG_SWAPCHAIN)
+        if (surface_is_offscreen(iface))
         {
-            TRACE("Surface %p is an onscreen surface\n", iface);
-        } else {
             /* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets.
              * Prefer SFLAG_INTEXTURE. */
             if (flag == SFLAG_INDRAWABLE) flag = SFLAG_INTEXTURE;
             drawable_read_ok = FALSE;
+            in_fbo = TRUE;
+        }
+        else
+        {
+            TRACE("Surface %p is an onscreen surface\n", iface);
         }
     }
@@ -4783,10 +4904,17 @@
 
         /* Download the surface to system memory */
-        if(This->Flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) {
-            if (!device->isInDraw) ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        if (This->Flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))
+        {
+            struct wined3d_context *context = NULL;
+
+            if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+
             surface_bind_and_dirtify(This, !(This->Flags & SFLAG_INTEXTURE));
-
             surface_download_data(This);
-        } else {
+
+            if (context) context_release(context);
+        }
+        else
+        {
             /* Note: It might be faster to download into a texture first. */
             read_from_framebuffer(This, rect,
@@ -4814,8 +4942,13 @@
             /* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
              * but it isn't set (yet) in all cases it is getting called. */
-            if((convert != NO_CONVERSION) && (This->Flags & SFLAG_PBO)) {
+            if ((convert != NO_CONVERSION) && (This->Flags & SFLAG_PBO))
+            {
+                struct wined3d_context *context = NULL;
+
                 TRACE("Removing the pbo attached to surface %p\n", This);
-                if (!device->isInDraw) ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+
+                if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
                 surface_remove_pbo(This);
+                if (context) context_release(context);
             }
 
@@ -4849,8 +4982,14 @@
         if (drawable_read_ok && (This->Flags & SFLAG_INDRAWABLE)) {
             read_from_framebuffer_texture(This, flag == SFLAG_INSRGBTEX);
-        } else { /* Upload from system memory */
+        }
+        else
+        {
+            /* Upload from system memory */
             BOOL srgb = flag == SFLAG_INSRGBTEX;
             DWORD alloc_flag = srgb ? SFLAG_SRGBALLOCATED : SFLAG_ALLOCATED;
-            d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */, &format, &internal, &type, &convert, &bpp, srgb);
+            struct wined3d_context *context = NULL;
+
+            d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */,
+                    &format, &internal, &type, &convert, &bpp, srgb);
 
             if(srgb) {
@@ -4874,5 +5013,5 @@
             }
 
-            if (!device->isInDraw) ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+            if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
             surface_bind_and_dirtify(This, srgb);
 
@@ -4904,4 +5043,5 @@
                 if(!mem) {
                     ERR("Out of memory %d, %d!\n", outpitch, height);
+                    if (context) context_release(context);
                     return WINED3DERR_OUTOFVIDEOMEMORY;
                 }
@@ -4911,5 +5051,5 @@
             }
             else if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
-                    && (GL_SUPPORT(EXT_PALETTED_TEXTURE) || GL_SUPPORT(ARB_FRAGMENT_PROGRAM)))
+                    && (gl_info->supported[EXT_PALETTED_TEXTURE] || gl_info->supported[ARB_FRAGMENT_PROGRAM]))
             {
                 d3dfmt_p8_upload_palette(iface, convert);
@@ -4953,4 +5093,6 @@
             LEAVE_GL();
 
+            if (context) context_release(context);
+
             /* Don't delete PBO memory */
             if((mem != This->resource.allocatedMemory) && !(This->Flags & SFLAG_PBO))
@@ -4963,6 +5105,5 @@
     }
 
-    if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !(This->Flags & SFLAG_SWAPCHAIN)
-            && (This->Flags & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE))) {
+    if (in_fbo && (This->Flags & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE))) {
         /* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
         This->Flags |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
@@ -5021,4 +5162,20 @@
 }
 
+BOOL surface_is_offscreen(IWineD3DSurface *iface)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
+    IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) This->container;
+
+    /* Not on a swapchain - must be offscreen */
+    if (!(This->Flags & SFLAG_SWAPCHAIN)) return TRUE;
+
+    /* The front buffer is always onscreen */
+    if(iface == swapchain->frontBuffer) return FALSE;
+
+    /* If the swapchain is rendered to an FBO, the backbuffer is
+     * offscreen, otherwise onscreen */
+    return swapchain->render_to_fbo;
+}
+
 const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl =
 {
@@ -5029,5 +5186,4 @@
     /* IWineD3DResource */
     IWineD3DBaseSurfaceImpl_GetParent,
-    IWineD3DBaseSurfaceImpl_GetDevice,
     IWineD3DBaseSurfaceImpl_SetPrivateData,
     IWineD3DBaseSurfaceImpl_GetPrivateData,
@@ -5096,14 +5252,19 @@
 
 /* Context activation is done by the caller. */
-static void ffp_blit_unset(IWineD3DDevice *iface) {
+static void ffp_blit_unset(IWineD3DDevice *iface)
+{
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+
     ENTER_GL();
     glDisable(GL_TEXTURE_2D);
     checkGLcall("glDisable(GL_TEXTURE_2D)");
-    if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+    if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+    {
         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
         checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
     }
-    if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+    if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+    {
         glDisable(GL_TEXTURE_RECTANGLE_ARB);
         checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 25949)
@@ -127,8 +127,4 @@
    IWineD3DSurface IWineD3DResource parts follow
    **************************************************** */
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice) {
-    return resource_get_device((IWineD3DResource *)iface, ppDevice);
-}
-
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
     return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
@@ -176,9 +172,6 @@
 
     /* Standalone surfaces return the device as container. */
-    if (This->container) {
-        container = This->container;
-    } else {
-        container = (IWineD3DBase *)This->resource.wineD3DDevice;
-    }
+    if (This->container) container = This->container;
+    else container = (IWineD3DBase *)This->resource.device;
 
     TRACE("Relaying to QueryInterface\n");
@@ -204,7 +197,7 @@
 }
 
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags) {
-    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    TRACE("(%p)->(%x)\n", This, Flags);
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags)
+{
+    TRACE("iface %p, flags %#x.\n", iface, Flags);
 
     switch (Flags)
@@ -356,5 +349,5 @@
     else
     {
-        unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
+        unsigned char alignment = This->resource.device->surface_alignment;
         ret = This->resource.format_desc->byte_count * This->currentDesc.Width;  /* Bytes / row */
         ret = (ret + alignment - 1) & ~(alignment - 1);
@@ -414,7 +407,6 @@
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
-    IWineD3DSurfaceImpl *RefImpl = (IWineD3DSurfaceImpl *) Ref;
-
-    FIXME("(%p)->(%08x,%p) Stub!\n", This, Flags, RefImpl);
+
+    FIXME("iface %p, flags %#x, ref %p stub!\n", iface, Flags, Ref);
 
     if(!(This->resource.usage & WINED3DUSAGE_OVERLAY))
@@ -521,5 +513,5 @@
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format,
-            &This->resource.wineD3DDevice->adapter->gl_info);
+            &This->resource.device->adapter->gl_info);
 
     if (This->resource.format_desc->format != WINED3DFMT_UNKNOWN)
@@ -531,5 +523,5 @@
     TRACE("(%p) : Setting texture format to (%d,%s)\n", This, format, debug_d3dformat(format));
 
-    This->resource.size = surface_calculate_size(format_desc, This->resource.wineD3DDevice->surface_alignment,
+    This->resource.size = surface_calculate_size(format_desc, This->resource.device->surface_alignment,
             This->pow2Width, This->pow2Height);
 
@@ -807,5 +799,5 @@
     }
 
-    IWineD3DDevice_CreateSurface((IWineD3DDevice *)source->resource.wineD3DDevice, source->currentDesc.Width,
+    IWineD3DDevice_CreateSurface((IWineD3DDevice *)source->resource.device, source->currentDesc.Width,
             source->currentDesc.Height, to_fmt, TRUE /* lockable */, TRUE /* discard  */, 0 /* level */, &ret,
             0 /* usage */, WINED3DPOOL_SCRATCH, WINED3DMULTISAMPLE_NONE /* TODO: Multisampled conversion */,
@@ -1712,4 +1704,12 @@
     {
         DWORD keylow, keyhigh;
+        DWORD mask = Src->resource.format_desc->red_mask |
+                     Src->resource.format_desc->green_mask |
+                     Src->resource.format_desc->blue_mask;
+
+        /* For some 8-bit formats like L8 and P8 color masks don't make sense */
+        if(!mask && bpp==1)
+            mask = 0xff;
+
         TRACE("Color keyed copy\n");
         if (trans & WINEDDBLTFAST_SRCCOLORKEY)
@@ -1733,5 +1733,5 @@
         for (x = 0; x < w; x++) { \
         tmp = s[x]; \
-        if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
+        if ((tmp & mask) < keylow || (tmp & mask) > keyhigh) d[x] = tmp; \
     } \
         s = (const type *)((const BYTE *)s + slock.Pitch); \
@@ -1876,5 +1876,4 @@
 void WINAPI IWineD3DBaseSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb) {
     ERR("Should not be called on base texture\n");
-    return;
 }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c	(revision 25949)
@@ -439,5 +439,5 @@
             IWineD3DSurfaceImpl *dds_primary;
             IWineD3DSwapChainImpl *swapchain;
-            swapchain = (IWineD3DSwapChainImpl *)This->resource.wineD3DDevice->swapchains[0];
+            swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[0];
             dds_primary = (IWineD3DSurfaceImpl *)swapchain->frontBuffer;
             if (dds_primary && dds_primary->palette)
@@ -656,5 +656,4 @@
     /* IWineD3DResource */
     IWineD3DBaseSurfaceImpl_GetParent,
-    IWineD3DBaseSurfaceImpl_GetDevice,
     IWineD3DBaseSurfaceImpl_SetPrivateData,
     IWineD3DBaseSurfaceImpl_GetPrivateData,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 25949)
@@ -43,5 +43,5 @@
 WINE_DECLARE_DEBUG_CHANNEL(fps);
 
-#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION This->device->adapter->gl_info
 
 /*IWineD3DSwapChain parts follow: */
@@ -86,5 +86,5 @@
     for (i = 0; i < This->num_contexts; ++i)
     {
-        DestroyContext(This->wineD3DDevice, This->context[i]);
+        context_destroy(This->device, This->context[i]);
     }
     /* Restore the screen resolution if we rendered in fullscreen
@@ -98,26 +98,146 @@
         mode.RefreshRate = 0;
         mode.Format = This->orig_fmt;
-        IWineD3DDevice_SetDisplayMode((IWineD3DDevice *) This->wineD3DDevice, 0, &mode);
-    }
+        IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)This->device, 0, &mode);
+    }
+
     HeapFree(GetProcessHeap(), 0, This->context);
-
     HeapFree(GetProcessHeap(), 0, This);
+}
+
+/* A GL context is provided by the caller */
+static void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context *context,
+        const RECT *src_rect, const RECT *dst_rect)
+{
+    IWineD3DDeviceImpl *device = This->device;
+    IWineD3DSurfaceImpl *backbuffer = ((IWineD3DSurfaceImpl *) This->backBuffer[0]);
+    UINT src_w = src_rect->right - src_rect->left;
+    UINT src_h = src_rect->bottom - src_rect->top;
+    GLenum gl_filter;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+
+    TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n",
+            This, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
+
+    if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top)
+        gl_filter = GL_NEAREST;
+    else
+        gl_filter = GL_LINEAR;
+
+    if (gl_info->fbo_ops.glBlitFramebuffer)
+    {
+        ENTER_GL();
+        context_bind_fbo(context, GL_READ_FRAMEBUFFER, &context->src_fbo);
+        context_attach_surface_fbo(context, GL_READ_FRAMEBUFFER, 0, This->backBuffer[0]);
+        context_attach_depth_stencil_fbo(context, GL_READ_FRAMEBUFFER, NULL, FALSE);
+
+        context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
+        context_set_draw_buffer(context, GL_BACK);
+
+        glDisable(GL_SCISSOR_TEST);
+        IWineD3DDeviceImpl_MarkStateDirty(This->device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE));
+
+        /* Note that the texture is upside down */
+        gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
+                                           dst_rect->left, dst_rect->bottom, dst_rect->right, dst_rect->top,
+                                           GL_COLOR_BUFFER_BIT, gl_filter);
+        checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n");
+        LEAVE_GL();
+    }
+    else
+    {
+        struct wined3d_context *context2;
+        float tex_left = src_rect->left;
+        float tex_top = src_rect->top;
+        float tex_right = src_rect->right;
+        float tex_bottom = src_rect->bottom;
+
+        context2 = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_BLIT);
+
+        if(backbuffer->Flags & SFLAG_NORMCOORD)
+        {
+            tex_left /= src_w;
+            tex_right /= src_w;
+            tex_top /= src_h;
+            tex_bottom /= src_h;
+        }
+
+        ENTER_GL();
+        context_bind_fbo(context2, GL_DRAW_FRAMEBUFFER, NULL);
+
+        /* Set up the texture. The surface is not in a IWineD3D*Texture container,
+         * so there are no d3d texture settings to dirtify
+         */
+        device->blitter->set_shader((IWineD3DDevice *) device, backbuffer->resource.format_desc,
+                                    backbuffer->texture_target, backbuffer->pow2Width,
+                                    backbuffer->pow2Height);
+        glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+        context_set_draw_buffer(context, GL_BACK);
+
+        /* Set the viewport to the destination rectandle, disable any projection
+         * transformation set up by CTXUSAGE_BLIT, and draw a (-1,-1)-(1,1) quad.
+         *
+         * Back up viewport and matrix to avoid breaking last_was_blit
+         *
+         * Note that CTXUSAGE_BLIT set up viewport and ortho to match the surface
+         * size - we want the GL drawable(=window) size.
+         */
+        glPushAttrib(GL_VIEWPORT_BIT);
+        glViewport(dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom);
+        glMatrixMode(GL_PROJECTION);
+        glPushMatrix();
+        glLoadIdentity();
+
+        glBegin(GL_QUADS);
+            /* bottom left */
+            glTexCoord2f(tex_left, tex_bottom);
+            glVertex2i(-1, -1);
+
+            /* top left */
+            glTexCoord2f(tex_left, tex_top);
+            glVertex2i(-1, 1);
+
+            /* top right */
+            glTexCoord2f(tex_right, tex_top);
+            glVertex2i(1, 1);
+
+            /* bottom right */
+            glTexCoord2f(tex_right, tex_bottom);
+            glVertex2i(1, -1);
+        glEnd();
+
+        glPopMatrix();
+        glPopAttrib();
+
+        device->blitter->unset_shader((IWineD3DDevice *) device);
+        checkGLcall("Swapchain present blit(manual)\n");
+        LEAVE_GL();
+
+        context_release(context2);
+    }
 }
 
 static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
     IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
+    struct wined3d_context *context;
+    RECT src_rect, dst_rect;
+    BOOL render_to_fbo;
     unsigned int sync;
     int retval;
 
-
-    ActivateContext(This->wineD3DDevice, This->backBuffer[0], CTXUSAGE_RESOURCELOAD);
+    context = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_RESOURCELOAD);
 
     /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
-    if(This->wineD3DDevice->bCursorVisible && This->wineD3DDevice->cursorTexture) {
+    if (This->device->bCursorVisible && This->device->cursorTexture)
+    {
         IWineD3DSurfaceImpl cursor;
-        RECT destRect = {This->wineD3DDevice->xScreenSpace - This->wineD3DDevice->xHotSpot,
-                         This->wineD3DDevice->yScreenSpace - This->wineD3DDevice->yHotSpot,
-                         This->wineD3DDevice->xScreenSpace + This->wineD3DDevice->cursorWidth - This->wineD3DDevice->xHotSpot,
-                         This->wineD3DDevice->yScreenSpace + This->wineD3DDevice->cursorHeight - This->wineD3DDevice->yHotSpot};
+        RECT destRect =
+        {
+            This->device->xScreenSpace - This->device->xHotSpot,
+            This->device->yScreenSpace - This->device->yHotSpot,
+            This->device->xScreenSpace + This->device->cursorWidth - This->device->xHotSpot,
+            This->device->yScreenSpace + This->device->cursorHeight - This->device->yHotSpot,
+        };
         TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor);
         /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
@@ -128,14 +248,13 @@
         cursor.lpVtbl = &IWineD3DSurface_Vtbl;
         cursor.resource.ref = 1;
-        cursor.resource.wineD3DDevice = This->wineD3DDevice;
+        cursor.resource.device = This->device;
         cursor.resource.pool = WINED3DPOOL_SCRATCH;
-        cursor.resource.format_desc =
-                getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, &This->wineD3DDevice->adapter->gl_info);
+        cursor.resource.format_desc = getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, context->gl_info);
         cursor.resource.resourceType = WINED3DRTYPE_SURFACE;
-        cursor.texture_name = This->wineD3DDevice->cursorTexture;
+        cursor.texture_name = This->device->cursorTexture;
         cursor.texture_target = GL_TEXTURE_2D;
         cursor.texture_level = 0;
-        cursor.currentDesc.Width = This->wineD3DDevice->cursorWidth;
-        cursor.currentDesc.Height = This->wineD3DDevice->cursorHeight;
+        cursor.currentDesc.Width = This->device->cursorWidth;
+        cursor.currentDesc.Height = This->device->cursorHeight;
         cursor.glRect.left = 0;
         cursor.glRect.top = 0;
@@ -156,11 +275,11 @@
                 NULL, WINEDDBLT_KEYSRC, NULL, WINED3DTEXF_POINT);
     }
-    if(This->wineD3DDevice->logo_surface) {
-        /* Blit the logo into the upper left corner of the drawable */
-        IWineD3DSurface_BltFast(This->backBuffer[0], 0, 0, This->wineD3DDevice->logo_surface, NULL, WINEDDBLTFAST_SRCCOLORKEY);
-    }
-
-    if (pSourceRect || pDestRect) FIXME("Unhandled present rects %s/%s\n", wine_dbgstr_rect(pSourceRect), wine_dbgstr_rect(pDestRect));
-    /* TODO: If only source rect or dest rect are supplied then clip the window to match */
+
+    if (This->device->logo_surface)
+    {
+        /* Blit the logo into the upper left corner of the drawable. */
+        IWineD3DSurface_BltFast(This->backBuffer[0], 0, 0, This->device->logo_surface, NULL, WINEDDBLTFAST_SRCCOLORKEY);
+    }
+
     TRACE("presetting HDC %p\n", This->context[0]->hdc);
 
@@ -168,4 +287,68 @@
     if (hDestWindowOverride && This->win_handle != hDestWindowOverride) {
         IWineD3DSwapChain_SetDestWindowOverride(iface, hDestWindowOverride);
+    }
+
+    render_to_fbo = This->render_to_fbo;
+
+    if (pSourceRect)
+    {
+        src_rect = *pSourceRect;
+        if (!render_to_fbo && (src_rect.left || src_rect.top
+                || src_rect.right != This->presentParms.BackBufferWidth
+                || src_rect.bottom != This->presentParms.BackBufferHeight))
+        {
+            render_to_fbo = TRUE;
+        }
+    }
+    else
+    {
+        src_rect.left = 0;
+        src_rect.top = 0;
+        src_rect.right = This->presentParms.BackBufferWidth;
+        src_rect.bottom = This->presentParms.BackBufferHeight;
+    }
+
+    if (pDestRect) dst_rect = *pDestRect;
+    else GetClientRect(This->win_handle, &dst_rect);
+
+    if (!render_to_fbo && (dst_rect.left || dst_rect.top
+            || dst_rect.right != This->presentParms.BackBufferWidth
+            || dst_rect.bottom != This->presentParms.BackBufferHeight))
+    {
+        render_to_fbo = TRUE;
+    }
+
+    /* Rendering to a window of different size, presenting partial rectangles,
+     * or rendering to a different window needs help from FBO_blit or a textured
+     * draw. Render the swapchain to a FBO in the future.
+     *
+     * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
+     * all these issues - this fails if the window is smaller than the backbuffer.
+     */
+    if (!This->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+    {
+        IWineD3DSurface_LoadLocation(This->backBuffer[0], SFLAG_INTEXTURE, NULL);
+        IWineD3DSurface_ModifyLocation(This->backBuffer[0], SFLAG_INDRAWABLE, FALSE);
+        This->render_to_fbo = TRUE;
+
+        /* Force the context manager to update the render target configuration next draw. */
+        context->current_rt = NULL;
+    }
+
+    if(This->render_to_fbo)
+    {
+        /* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer-
+         * window size mismatch is impossible(fullscreen) and src and dst rectangles are
+         * not allowed(they need the COPY swapeffect)
+         *
+         * The DISCARD swap effect is ok as well since any backbuffer content is allowed after
+         * the swap
+         */
+        if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP )
+        {
+            FIXME("Render-to-fbo with WINED3DSWAPEFFECT_FLIP\n");
+        }
+
+        swapchain_blit(This, context, &src_rect, &dst_rect);
     }
 
@@ -245,11 +428,14 @@
         TRACE("Clearing the color buffer with cyan color\n");
 
-        IWineD3DDevice_Clear((IWineD3DDevice*)This->wineD3DDevice, 0, NULL,
+        IWineD3DDevice_Clear((IWineD3DDevice *)This->device, 0, NULL,
                 WINED3DCLEAR_TARGET, 0xff00ffff, 1.0f, 0);
     }
 
-    if(((IWineD3DSurfaceImpl *) This->frontBuffer)->Flags   & SFLAG_INSYSMEM ||
-       ((IWineD3DSurfaceImpl *) This->backBuffer[0])->Flags & SFLAG_INSYSMEM ) {
-        /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying */
+    if(!This->render_to_fbo &&
+       ( ((IWineD3DSurfaceImpl *) This->frontBuffer)->Flags   & SFLAG_INSYSMEM ||
+         ((IWineD3DSurfaceImpl *) This->backBuffer[0])->Flags & SFLAG_INSYSMEM ) ) {
+        /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
+         * Doesn't work with render_to_fbo because we're not flipping
+         */
         IWineD3DSurfaceImpl *front = (IWineD3DSurfaceImpl *) This->frontBuffer;
         IWineD3DSurfaceImpl *back = (IWineD3DSurfaceImpl *) This->backBuffer[0];
@@ -282,12 +468,16 @@
     }
 
-    if (This->wineD3DDevice->stencilBufferTarget) {
+    if (This->device->stencilBufferTarget)
+    {
         if (This->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
-                || ((IWineD3DSurfaceImpl *)This->wineD3DDevice->stencilBufferTarget)->Flags & SFLAG_DISCARD) {
-            surface_modify_ds_location(This->wineD3DDevice->stencilBufferTarget, SFLAG_DS_DISCARDED);
-        }
-    }
-
-    if(This->presentParms.PresentationInterval != WINED3DPRESENT_INTERVAL_IMMEDIATE && GL_SUPPORT(SGI_VIDEO_SYNC)) {
+                || ((IWineD3DSurfaceImpl *)This->device->stencilBufferTarget)->Flags & SFLAG_DISCARD)
+        {
+            surface_modify_ds_location(This->device->stencilBufferTarget, SFLAG_DS_DISCARDED);
+        }
+    }
+
+    if (This->presentParms.PresentationInterval != WINED3DPRESENT_INTERVAL_IMMEDIATE
+            && context->gl_info->supported[SGI_VIDEO_SYNC])
+    {
         retval = GL_EXTCALL(glXGetVideoSyncSGI(&sync));
         if(retval != 0) {
@@ -330,4 +520,6 @@
     }
 
+    context_release(context);
+
     TRACE("returning\n");
     return WINED3D_OK;
@@ -342,14 +534,17 @@
 
     TRACE("Performing dest override of swapchain %p from window %p to %p\n", This, This->win_handle, window);
-    if(This->context[0] == This->wineD3DDevice->contexts[0]) {
+    if (This->context[0] == This->device->contexts[0])
+    {
         /* The primary context 'owns' all the opengl resources. Destroying and recreating that context requires downloading
          * all opengl resources, deleting the gl resources, destroying all other contexts, then recreating all other contexts
          * and reload the resources
          */
-        delete_opengl_contexts((IWineD3DDevice *) This->wineD3DDevice, iface);
-        This->win_handle             = window;
-        create_primary_opengl_context((IWineD3DDevice *) This->wineD3DDevice, iface);
-    } else {
-        This->win_handle             = window;
+        delete_opengl_contexts((IWineD3DDevice *)This->device, iface);
+        This->win_handle = window;
+        create_primary_opengl_context((IWineD3DDevice *)This->device, iface);
+    }
+    else
+    {
+        This->win_handle = window;
 
         /* The old back buffer has to be copied over to the new back buffer. A lockrect - switchcontext - unlockrect
@@ -362,6 +557,8 @@
         IWineD3DSurface_UnlockRect(This->backBuffer[0]);
 
-        DestroyContext(This->wineD3DDevice, This->context[0]);
-        This->context[0] = CreateContext(This->wineD3DDevice, (IWineD3DSurfaceImpl *) This->frontBuffer, This->win_handle, FALSE /* pbuffer */, &This->presentParms);
+        context_destroy(This->device, This->context[0]);
+        This->context[0] = context_create(This->device, (IWineD3DSurfaceImpl *)This->frontBuffer,
+                This->win_handle, FALSE /* pbuffer */, &This->presentParms);
+        context_release(This->context[0]);
 
         IWineD3DSurface_LockRect(This->backBuffer[0], &r, NULL, WINED3DLOCK_DISCARD);
@@ -373,5 +570,5 @@
 }
 
-const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl =
+static const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl =
 {
     /* IUnknown */
@@ -394,5 +591,348 @@
 };
 
-struct wined3d_context *IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain *iface)
+static LONG fullscreen_style(LONG style)
+{
+    /* Make sure the window is managed, otherwise we won't get keyboard input. */
+    style |= WS_POPUP | WS_SYSMENU;
+    style &= ~(WS_CAPTION | WS_THICKFRAME);
+
+    return style;
+}
+
+static LONG fullscreen_exstyle(LONG exstyle)
+{
+    /* Filter out window decorations. */
+    exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
+
+    return exstyle;
+}
+
+void swapchain_setup_fullscreen_window(IWineD3DSwapChainImpl *swapchain, UINT w, UINT h)
+{
+    IWineD3DDeviceImpl *device = swapchain->device;
+    HWND window = swapchain->win_handle;
+    BOOL filter_messages;
+    LONG style, exstyle;
+
+    TRACE("Setting up window %p for fullscreen mode.\n", window);
+
+    if (device->style || device->exStyle)
+    {
+        ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
+                window, device->style, device->exStyle);
+    }
+
+    device->style = GetWindowLongW(window, GWL_STYLE);
+    device->exStyle = GetWindowLongW(window, GWL_EXSTYLE);
+
+    style = fullscreen_style(device->style);
+    exstyle = fullscreen_exstyle(device->exStyle);
+
+    TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
+            device->style, device->exStyle, style, exstyle);
+
+    filter_messages = device->filter_messages;
+    device->filter_messages = TRUE;
+
+    SetWindowLongW(window, GWL_STYLE, style);
+    SetWindowLongW(window, GWL_EXSTYLE, exstyle);
+    SetWindowPos(window, HWND_TOP, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
+
+    device->filter_messages = filter_messages;
+}
+
+void swapchain_restore_fullscreen_window(IWineD3DSwapChainImpl *swapchain)
+{
+    IWineD3DDeviceImpl *device = swapchain->device;
+    HWND window = swapchain->win_handle;
+    BOOL filter_messages;
+    LONG style, exstyle;
+
+    if (!device->style && !device->exStyle) return;
+
+    TRACE("Restoring window style of window %p to %08x, %08x.\n",
+            window, device->style, device->exStyle);
+
+    style = GetWindowLongW(window, GWL_STYLE);
+    exstyle = GetWindowLongW(window, GWL_EXSTYLE);
+
+    filter_messages = device->filter_messages;
+    device->filter_messages = TRUE;
+
+    /* Only restore the style if the application didn't modify it during the
+     * fullscreen phase. Some applications change it before calling Reset()
+     * when switching between windowed and fullscreen modes (HL2), some
+     * depend on the original style (Eve Online). */
+    if (style == fullscreen_style(device->style) && exstyle == fullscreen_exstyle(device->exStyle))
+    {
+        SetWindowLongW(window, GWL_STYLE, device->style);
+        SetWindowLongW(window, GWL_EXSTYLE, device->exStyle);
+    }
+    SetWindowPos(window, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
+
+    device->filter_messages = filter_messages;
+
+    /* Delete the old values. */
+    device->style = 0;
+    device->exStyle = 0;
+}
+
+
+HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface_type,
+        IWineD3DDeviceImpl *device, WINED3DPRESENT_PARAMETERS *present_parameters, IUnknown *parent)
+{
+    const struct wined3d_adapter *adapter = device->adapter;
+    const struct GlPixelFormatDesc *format_desc;
+    BOOL displaymode_set = FALSE;
+    WINED3DDISPLAYMODE mode;
+    RECT client_rect;
+    HWND window;
+    HRESULT hr;
+    UINT i;
+
+    if (present_parameters->BackBufferCount > WINED3DPRESENT_BACK_BUFFER_MAX)
+    {
+        FIXME("The application requested %u back buffers, this is not supported.\n",
+                present_parameters->BackBufferCount);
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    if (present_parameters->BackBufferCount > 1)
+    {
+        FIXME("The application requested more than one back buffer, this is not properly supported.\n"
+                "Please configure the application to use double buffering (1 back buffer) if possible.\n");
+    }
+
+    switch (surface_type)
+    {
+        case SURFACE_GDI:
+            swapchain->lpVtbl = &IWineGDISwapChain_Vtbl;
+            break;
+
+        case SURFACE_OPENGL:
+            swapchain->lpVtbl = &IWineD3DSwapChain_Vtbl;
+            break;
+
+        case SURFACE_UNKNOWN:
+            FIXME("Caller tried to create a SURFACE_UNKNOWN swapchain.\n");
+            return WINED3DERR_INVALIDCALL;
+    }
+
+    window = present_parameters->hDeviceWindow ? present_parameters->hDeviceWindow : device->createParms.hFocusWindow;
+
+    swapchain->device = device;
+    swapchain->parent = parent;
+    swapchain->ref = 1;
+    swapchain->win_handle = window;
+
+    if (!present_parameters->Windowed && window)
+    {
+        swapchain_setup_fullscreen_window(swapchain, present_parameters->BackBufferWidth,
+                present_parameters->BackBufferHeight);
+    }
+
+    IWineD3D_GetAdapterDisplayMode(device->wined3d, adapter->ordinal, &mode);
+    swapchain->orig_width = mode.Width;
+    swapchain->orig_height = mode.Height;
+    swapchain->orig_fmt = mode.Format;
+    format_desc = getFormatDescEntry(mode.Format, &adapter->gl_info);
+
+    GetClientRect(window, &client_rect);
+    if (present_parameters->Windowed
+            && (!present_parameters->BackBufferWidth || !present_parameters->BackBufferHeight
+            || present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN))
+    {
+
+        if (!present_parameters->BackBufferWidth)
+        {
+            present_parameters->BackBufferWidth = client_rect.right;
+            TRACE("Updating width to %u.\n", present_parameters->BackBufferWidth);
+        }
+
+        if (!present_parameters->BackBufferHeight)
+        {
+            present_parameters->BackBufferHeight = client_rect.bottom;
+            TRACE("Updating height to %u.\n", present_parameters->BackBufferHeight);
+        }
+
+        if (present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN)
+        {
+            present_parameters->BackBufferFormat = swapchain->orig_fmt;
+            TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->orig_fmt));
+        }
+    }
+    swapchain->presentParms = *present_parameters;
+
+    if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
+            && present_parameters->BackBufferCount
+            && (present_parameters->BackBufferWidth != client_rect.right
+            || present_parameters->BackBufferHeight != client_rect.bottom))
+    {
+        TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u.\n",
+                present_parameters->BackBufferWidth,
+                present_parameters->BackBufferHeight,
+                client_rect.right, client_rect.bottom);
+        swapchain->render_to_fbo = TRUE;
+    }
+
+    TRACE("Creating front buffer.\n");
+    hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
+            swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
+            swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
+            swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, &swapchain->frontBuffer);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create front buffer, hr %#x.\n", hr);
+        goto err;
+    }
+
+    IWineD3DSurface_SetContainer(swapchain->frontBuffer, (IWineD3DBase *)swapchain);
+    ((IWineD3DSurfaceImpl *)swapchain->frontBuffer)->Flags |= SFLAG_SWAPCHAIN;
+    if (surface_type == SURFACE_OPENGL)
+    {
+        IWineD3DSurface_ModifyLocation(swapchain->frontBuffer, SFLAG_INDRAWABLE, TRUE);
+    }
+
+    /* MSDN says we're only allowed a single fullscreen swapchain per device,
+     * so we should really check to see if there is a fullscreen swapchain
+     * already. Does a single head count as full screen? */
+
+    if (!present_parameters->Windowed)
+    {
+        WINED3DDISPLAYMODE mode;
+
+        /* Change the display settings */
+        mode.Width = present_parameters->BackBufferWidth;
+        mode.Height = present_parameters->BackBufferHeight;
+        mode.Format = present_parameters->BackBufferFormat;
+        mode.RefreshRate = present_parameters->FullScreen_RefreshRateInHz;
+
+        hr = IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)device, 0, &mode);
+        if (FAILED(hr))
+        {
+            WARN("Failed to set display mode, hr %#x.\n", hr);
+            goto err;
+        }
+        displaymode_set = TRUE;
+    }
+
+    swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(swapchain->context));
+    if (!swapchain->context)
+    {
+        ERR("Failed to create the context array.\n");
+        hr = E_OUTOFMEMORY;
+        goto err;
+    }
+    swapchain->num_contexts = 1;
+
+    if (surface_type == SURFACE_OPENGL)
+    {
+        swapchain->context[0] = context_create(device, (IWineD3DSurfaceImpl *)swapchain->frontBuffer,
+                window, FALSE /* pbuffer */, present_parameters);
+        if (!swapchain->context[0])
+        {
+            WARN("Failed to create context.\n");
+            hr = WINED3DERR_NOTAVAILABLE;
+            goto err;
+        }
+        context_release(swapchain->context[0]);
+    }
+    else
+    {
+        swapchain->context[0] = NULL;
+    }
+
+    if (swapchain->presentParms.BackBufferCount > 0)
+    {
+        swapchain->backBuffer = HeapAlloc(GetProcessHeap(), 0,
+                sizeof(*swapchain->backBuffer) * swapchain->presentParms.BackBufferCount);
+        if (!swapchain->backBuffer)
+        {
+            ERR("Failed to allocate backbuffer array memory.\n");
+            hr = E_OUTOFMEMORY;
+            goto err;
+        }
+
+        for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
+        {
+            TRACE("Creating back buffer %u.\n", i);
+            hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
+                    swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
+                    swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
+                    swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, &swapchain->backBuffer[i]);
+            if (FAILED(hr))
+            {
+                WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
+                goto err;
+            }
+
+            IWineD3DSurface_SetContainer(swapchain->backBuffer[i], (IWineD3DBase *)swapchain);
+            ((IWineD3DSurfaceImpl *)swapchain->backBuffer[i])->Flags |= SFLAG_SWAPCHAIN;
+        }
+    }
+
+    /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */
+    if (present_parameters->EnableAutoDepthStencil && surface_type == SURFACE_OPENGL)
+    {
+        TRACE("Creating depth/stencil buffer.\n");
+        if (!device->auto_depth_stencil_buffer)
+        {
+            hr = IWineD3DDeviceParent_CreateDepthStencilSurface(device->device_parent, parent,
+                    swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
+                    swapchain->presentParms.AutoDepthStencilFormat, swapchain->presentParms.MultiSampleType,
+                    swapchain->presentParms.MultiSampleQuality, FALSE /* FIXME: Discard */,
+                    &device->auto_depth_stencil_buffer);
+            if (FAILED(hr))
+            {
+                WARN("Failed to create the auto depth stencil, hr %#x.\n", hr);
+                goto err;
+            }
+
+            IWineD3DSurface_SetContainer(device->auto_depth_stencil_buffer, NULL);
+        }
+    }
+
+    IWineD3DSwapChain_GetGammaRamp((IWineD3DSwapChain *)swapchain, &swapchain->orig_gamma);
+
+    return WINED3D_OK;
+
+err:
+    if (displaymode_set)
+    {
+        DEVMODEW devmode;
+
+        ClipCursor(NULL);
+
+        /* Change the display settings */
+        memset(&devmode, 0, sizeof(devmode));
+        devmode.dmSize = sizeof(devmode);
+        devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
+        devmode.dmBitsPerPel = format_desc->byte_count * 8;
+        devmode.dmPelsWidth = swapchain->orig_width;
+        devmode.dmPelsHeight = swapchain->orig_height;
+        ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
+    }
+
+    if (swapchain->backBuffer)
+    {
+        for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
+        {
+            if (swapchain->backBuffer[i]) IWineD3DSurface_Release(swapchain->backBuffer[i]);
+        }
+        HeapFree(GetProcessHeap(), 0, swapchain->backBuffer);
+    }
+
+    if (swapchain->context && swapchain->context[0])
+    {
+        context_release(swapchain->context[0]);
+        context_destroy(device, swapchain->context[0]);
+    }
+
+    if (swapchain->frontBuffer) IWineD3DSurface_Release(swapchain->frontBuffer);
+
+    return hr;
+}
+
+struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChain *iface)
 {
     IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *) iface;
@@ -402,15 +942,17 @@
     TRACE("Creating a new context for swapchain %p, thread %d\n", This, GetCurrentThreadId());
 
-    ctx = CreateContext(This->wineD3DDevice, (IWineD3DSurfaceImpl *) This->frontBuffer,
-                        This->context[0]->win_handle, FALSE /* pbuffer */, &This->presentParms);
-    if(!ctx) {
+    ctx = context_create(This->device, (IWineD3DSurfaceImpl *)This->frontBuffer,
+            This->context[0]->win_handle, FALSE /* pbuffer */, &This->presentParms);
+    if (!ctx)
+    {
         ERR("Failed to create a new context for the swapchain\n");
         return NULL;
     }
+    context_release(ctx);
 
     newArray = HeapAlloc(GetProcessHeap(), 0, sizeof(*newArray) * This->num_contexts + 1);
     if(!newArray) {
         ERR("Out of memory when trying to allocate a new context array\n");
-        DestroyContext(This->wineD3DDevice, ctx);
+        context_destroy(This->device, ctx);
         return NULL;
     }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_base.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_base.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_base.c	(revision 25949)
@@ -37,21 +37,21 @@
 
 /* IDirect3DSwapChain IUnknown parts follow: */
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface, REFIID riid, LPVOID *ppobj)
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface, REFIID riid, void **object)
 {
-    IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
-    TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppobj);
-    if (IsEqualGUID(riid, &IID_IUnknown)
-        || IsEqualGUID(riid, &IID_IWineD3DBase)
-        || IsEqualGUID(riid, &IID_IWineD3DSwapChain)){
-        IWineD3DSwapChain_AddRef(iface);
-        if(ppobj == NULL){
-            ERR("Query interface called but now data allocated\n");
-            return E_NOINTERFACE;
-        }
-        *ppobj = This;
-        return WINED3D_OK;
-        }
-        *ppobj = NULL;
-        return E_NOINTERFACE;
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
+
+    if (IsEqualGUID(riid, &IID_IWineD3DSwapChain)
+            || IsEqualGUID(riid, &IID_IWineD3DBase)
+            || IsEqualGUID(riid, &IID_IUnknown))
+    {
+        IUnknown_AddRef(iface);
+        *object = iface;
+        return S_OK;
+    }
+
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *object = NULL;
+    return E_NOINTERFACE;
 }
 
@@ -131,5 +131,4 @@
 
 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetRasterStatus(IWineD3DSwapChain *iface, WINED3DRASTER_STATUS *pRasterStatus) {
-    IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
     static BOOL warned;
     pRasterStatus->InVBlank = TRUE;
@@ -138,5 +137,5 @@
     if (!warned)
     {
-        FIXME("(%p) : stub (once)\n", This);
+        FIXME("iface %p, raster_status %p stub!\n", iface, pRasterStatus);
         warned = TRUE;
     }
@@ -149,5 +148,5 @@
 
     TRACE("(%p)->(%p): Calling GetAdapterDisplayMode\n", This, pMode);
-    hr = IWineD3D_GetAdapterDisplayMode(This->wineD3DDevice->wineD3D, This->wineD3DDevice->adapter->num, pMode);
+    hr = IWineD3D_GetAdapterDisplayMode(This->device->wined3d, This->device->adapter->ordinal, pMode);
 
     TRACE("(%p) : returning w(%d) h(%d) rr(%d) fmt(%u,%s)\n", This, pMode->Width, pMode->Height, pMode->RefreshRate,
@@ -159,5 +158,5 @@
     IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
 
-    *ppDevice = (IWineD3DDevice *) This->wineD3DDevice;
+    *ppDevice = (IWineD3DDevice *)This->device;
 
     /* Note  Calling this method will increase the internal reference count
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_gdi.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_gdi.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_gdi.c	(revision 25949)
@@ -77,7 +77,8 @@
         mode.RefreshRate = 0;
         mode.Format = This->orig_fmt;
-        IWineD3DDevice_SetDisplayMode((IWineD3DDevice *) This->wineD3DDevice, 0, &mode);
-    }
-
+        IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)This->device, 0, &mode);
+    }
+
+    HeapFree(GetProcessHeap(), 0, This->context);
     HeapFree(GetProcessHeap(), 0, This);
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 25949)
@@ -37,11 +37,10 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
 
-#define GLINFO_LOCATION (*gl_info)
-
 static void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
 {
     /* Override the IWineD3DResource PreLoad method. */
     IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
+    struct wined3d_context *context = NULL;
     unsigned int i;
     BOOL srgb_mode;
@@ -72,7 +71,7 @@
     if (!device->isInDraw)
     {
-        /* ActivateContext sets isInDraw to TRUE when loading a pbuffer into a texture,
+        /* context_acquire() sets isInDraw to TRUE when loading a pbuffer into a texture,
          * thus no danger of recursive calls. */
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
     }
 
@@ -107,4 +106,6 @@
     }
 
+    if (context) context_release(context);
+
     /* No longer dirty. */
     *dirty = FALSE;
@@ -135,11 +136,7 @@
 }
 
-#undef GLINFO_LOCATION
-
 /* *******************************************
    IWineD3DTexture IUnknown parts follow
    ******************************************* */
-
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
 
 static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
@@ -184,8 +181,4 @@
    IWineD3DTexture IWineD3DResource parts follow
    **************************************************** */
-static HRESULT WINAPI IWineD3DTextureImpl_GetDevice(IWineD3DTexture *iface, IWineD3DDevice** ppDevice) {
-    return resource_get_device((IWineD3DResource *)iface, ppDevice);
-}
-
 static HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
     return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
@@ -418,5 +411,4 @@
     /* IWineD3DResource */
     IWineD3DTextureImpl_GetParent,
-    IWineD3DTextureImpl_GetDevice,
     IWineD3DTextureImpl_SetPrivateData,
     IWineD3DTextureImpl_GetPrivateData,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c	(revision 25949)
@@ -45,5 +45,4 @@
     UINT bpp;
     short depthSize, stencilSize;
-    BOOL isFourcc;
 };
 
@@ -60,86 +59,121 @@
 static const struct StaticPixelFormatDesc formats[] =
 {
-  /* WINED3DFORMAT                   alphamask    redmask    greenmask    bluemask     bpp    depth  stencil isFourcc */
-    {WINED3DFMT_UNKNOWN,                0x0,        0x0,        0x0,        0x0,        0,      0,      0,      FALSE},
+  /* WINED3DFORMAT                       alphamask    redmask    greenmask    bluemask     bpp    depth  stencil */
+    {WINED3DFMT_UNKNOWN,                    0x0,        0x0,        0x0,        0x0,        0,      0,      0},
     /* FourCC formats */
-    {WINED3DFMT_UYVY,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
-    {WINED3DFMT_YUY2,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
-    {WINED3DFMT_YV12,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT1,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT2,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT3,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT4,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT5,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_MULTI2_ARGB8,           0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
-    {WINED3DFMT_G8R8_G8B8,              0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
-    {WINED3DFMT_R8G8_B8G8,              0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
+    {WINED3DFMT_UYVY,                       0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_YUY2,                       0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_YV12,                       0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_DXT1,                       0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_DXT2,                       0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_DXT3,                       0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_DXT4,                       0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_DXT5,                       0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_MULTI2_ARGB8,               0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0},
+    {WINED3DFMT_G8R8_G8B8,                  0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0},
+    {WINED3DFMT_R8G8_B8G8,                  0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0},
     /* IEEE formats */
-    {WINED3DFMT_R32_FLOAT,              0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R32G32_FLOAT,           0x0,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
-    {WINED3DFMT_R32G32B32_FLOAT,        0x0,        0x0,        0x0,        0x0,        12,     0,      0,      FALSE},
-    {WINED3DFMT_R32G32B32A32_FLOAT,     0x1,        0x0,        0x0,        0x0,        16,     0,      0,      FALSE},
+    {WINED3DFMT_R32_FLOAT,                  0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R32G32_FLOAT,               0x0,        0x0,        0x0,        0x0,        8,      0,      0},
+    {WINED3DFMT_R32G32B32_FLOAT,            0x0,        0x0,        0x0,        0x0,        12,     0,      0},
+    {WINED3DFMT_R32G32B32A32_FLOAT,         0x1,        0x0,        0x0,        0x0,        16,     0,      0},
     /* Hmm? */
-    {WINED3DFMT_R8G8_SNORM_Cx,          0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8_SNORM_Cx,              0x0,        0x0,        0x0,        0x0,        2,      0,      0},
     /* Float */
-    {WINED3DFMT_R16_FLOAT,              0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_FLOAT,           0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_SINT,            0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_FLOAT,     0x1,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_SINT,      0x1,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_R16_FLOAT,                  0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_R16G16_FLOAT,               0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R16G16_SINT,                0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R16G16B16A16_FLOAT,         0x1,        0x0,        0x0,        0x0,        8,      0,      0},
+    {WINED3DFMT_R16G16B16A16_SINT,          0x1,        0x0,        0x0,        0x0,        8,      0,      0},
     /* Palettized formats */
-    {WINED3DFMT_P8_UINT_A8_UNORM,       0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_P8_UINT,                0x0,        0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
+    {WINED3DFMT_P8_UINT_A8_UNORM,           0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_P8_UINT,                    0x0,        0x0,        0x0,        0x0,        1,      0,      0},
     /* Standard ARGB formats. */
-    {WINED3DFMT_B8G8R8_UNORM,           0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 3,      0,      0,      FALSE},
-    {WINED3DFMT_B8G8R8A8_UNORM,         0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0,      FALSE},
-    {WINED3DFMT_B8G8R8X8_UNORM,         0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0,      FALSE},
-    {WINED3DFMT_B5G6R5_UNORM,           0x0,        0x0000f800, 0x000007e0, 0x0000001f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_B5G5R5X1_UNORM,         0x0,        0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_B5G5R5A1_UNORM,         0x00008000, 0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_B4G4R4A4_UNORM,         0x0000f000, 0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_B2G3R3_UNORM,           0x0,        0x000000e0, 0x0000001c, 0x00000003, 1,      0,      0,      FALSE},
-    {WINED3DFMT_A8_UNORM,               0x000000ff, 0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
-    {WINED3DFMT_B2G3R3A8_UNORM,         0x0000ff00, 0x000000e0, 0x0000001c, 0x00000003, 2,      0,      0,      FALSE},
-    {WINED3DFMT_B4G4R4X4_UNORM,         0x0,        0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_UNORM,      0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_UINT,       0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_SNORM,      0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8B8A8_UNORM,         0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8B8A8_UINT,          0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8B8X8_UNORM,         0x0,        0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_UNORM,           0x0,        0x0000ffff, 0xffff0000, 0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_B10G10R10A2_UNORM,      0xc0000000, 0x3ff00000, 0x000ffc00, 0x000003ff, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_UNORM,     0x1,        0x0000ffff, 0xffff0000, 0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_B8G8R8_UNORM,               0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 3,      0,      0},
+    {WINED3DFMT_B8G8R8A8_UNORM,             0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0},
+    {WINED3DFMT_B8G8R8X8_UNORM,             0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0},
+    {WINED3DFMT_B5G6R5_UNORM,               0x0,        0x0000f800, 0x000007e0, 0x0000001f, 2,      0,      0},
+    {WINED3DFMT_B5G5R5X1_UNORM,             0x0,        0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0},
+    {WINED3DFMT_B5G5R5A1_UNORM,             0x00008000, 0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0},
+    {WINED3DFMT_B4G4R4A4_UNORM,             0x0000f000, 0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0},
+    {WINED3DFMT_B2G3R3_UNORM,               0x0,        0x000000e0, 0x0000001c, 0x00000003, 1,      0,      0},
+    {WINED3DFMT_A8_UNORM,                   0x000000ff, 0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_B2G3R3A8_UNORM,             0x0000ff00, 0x000000e0, 0x0000001c, 0x00000003, 2,      0,      0},
+    {WINED3DFMT_B4G4R4X4_UNORM,             0x0,        0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0},
+    {WINED3DFMT_R10G10B10A2_UNORM,          0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0},
+    {WINED3DFMT_R10G10B10A2_UINT,           0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0},
+    {WINED3DFMT_R10G10B10A2_SNORM,          0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0},
+    {WINED3DFMT_R8G8B8A8_UNORM,             0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0},
+    {WINED3DFMT_R8G8B8A8_UINT,              0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0},
+    {WINED3DFMT_R8G8B8X8_UNORM,             0x0,        0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0},
+    {WINED3DFMT_R16G16_UNORM,               0x0,        0x0000ffff, 0xffff0000, 0x0,        4,      0,      0},
+    {WINED3DFMT_B10G10R10A2_UNORM,          0xc0000000, 0x3ff00000, 0x000ffc00, 0x000003ff, 4,      0,      0},
+    {WINED3DFMT_R16G16B16A16_UNORM,         0x1,        0x0000ffff, 0xffff0000, 0x0,        8,      0,      0},
     /* Luminance */
-    {WINED3DFMT_L8_UNORM,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
-    {WINED3DFMT_L8A8_UNORM,             0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_L4A4_UNORM,             0x000000f0, 0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
-    {WINED3DFMT_L16_UNORM,              0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
+    {WINED3DFMT_L8_UNORM,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_L8A8_UNORM,                 0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_L4A4_UNORM,                 0x000000f0, 0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_L16_UNORM,                  0x0,        0x0,        0x0,        0x0,        2,      16,     0},
     /* Bump mapping stuff */
-    {WINED3DFMT_R8G8_SNORM,             0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_R5G5_SNORM_L6_UNORM,    0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8_SNORM_L8X8_UNORM,  0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8B8A8_SNORM,         0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_SNORM,           0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G11B11_SNORM,        0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10_SNORM_A2_UNORM,0xb0000000,0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8_SNORM,                 0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_R5G5_SNORM_L6_UNORM,        0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_R8G8_SNORM_L8X8_UNORM,      0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R8G8B8A8_SNORM,             0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R16G16_SNORM,               0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R10G11B11_SNORM,            0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R10G10B10_SNORM_A2_UNORM,   0xb0000000, 0x0,        0x0,        0x0,        4,      0,      0},
     /* Depth stencil formats */
-    {WINED3DFMT_D16_LOCKABLE,           0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
-    {WINED3DFMT_D32_UNORM,              0x0,        0x0,        0x0,        0x0,        4,      32,     0,      FALSE},
-    {WINED3DFMT_S1_UINT_D15_UNORM,      0x0,        0x0,        0x0,        0x0,        2,      15,     1,      FALSE},
-    {WINED3DFMT_S8_UINT_D24_UNORM,      0x0,        0x0,        0x0,        0x0,        4,      24,     8,      FALSE},
-    {WINED3DFMT_X8D24_UNORM,            0x0,        0x0,        0x0,        0x0,        4,      24,     0,      FALSE},
-    {WINED3DFMT_S4X4_UINT_D24_UNORM,    0x0,        0x0,        0x0,        0x0,        4,      24,     4,      FALSE},
-    {WINED3DFMT_D16_UNORM,              0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
-    {WINED3DFMT_D32_FLOAT,              0x0,        0x0,        0x0,        0x0,        4,      32,     0,      FALSE},
-    {WINED3DFMT_S8_UINT_D24_FLOAT,      0x0,        0x0,        0x0,        0x0,        4,      24,     8,      FALSE},
-    {WINED3DFMT_VERTEXDATA,             0x0,        0x0,        0x0,        0x0,        0,      0,      0,      FALSE},
-    {WINED3DFMT_R16_UINT,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_R32_UINT,               0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_SNORM,     0x0,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_D16_LOCKABLE,               0x0,        0x0,        0x0,        0x0,        2,      16,     0},
+    {WINED3DFMT_D32_UNORM,                  0x0,        0x0,        0x0,        0x0,        4,      32,     0},
+    {WINED3DFMT_S1_UINT_D15_UNORM,          0x0,        0x0,        0x0,        0x0,        2,      15,     1},
+    {WINED3DFMT_D24_UNORM_S8_UINT,          0x0,        0x0,        0x0,        0x0,        4,      24,     8},
+    {WINED3DFMT_X8D24_UNORM,                0x0,        0x0,        0x0,        0x0,        4,      24,     0},
+    {WINED3DFMT_S4X4_UINT_D24_UNORM,        0x0,        0x0,        0x0,        0x0,        4,      24,     4},
+    {WINED3DFMT_D16_UNORM,                  0x0,        0x0,        0x0,        0x0,        2,      16,     0},
+    {WINED3DFMT_D32_FLOAT,                  0x0,        0x0,        0x0,        0x0,        4,      32,     0},
+    {WINED3DFMT_S8_UINT_D24_FLOAT,          0x0,        0x0,        0x0,        0x0,        4,      24,     8},
+    {WINED3DFMT_VERTEXDATA,                 0x0,        0x0,        0x0,        0x0,        0,      0,      0},
+    {WINED3DFMT_R16_UINT,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_R32_UINT,                   0x0,        0x0,        0x0,        0x0,        4,      0,      0},
+    {WINED3DFMT_R16G16B16A16_SNORM,         0x0,        0x0,        0x0,        0x0,        8,      0,      0},
     /* Vendor-specific formats */
-    {WINED3DFMT_ATI2N,                  0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_NVHU,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
-    {WINED3DFMT_NVHS,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
+    {WINED3DFMT_ATI2N,                      0x0,        0x0,        0x0,        0x0,        1,      0,      0},
+    {WINED3DFMT_NVHU,                       0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+    {WINED3DFMT_NVHS,                       0x0,        0x0,        0x0,        0x0,        2,      0,      0},
+};
+
+struct wined3d_format_base_flags
+{
+    WINED3DFORMAT format;
+    DWORD flags;
+};
+
+static const struct wined3d_format_base_flags format_base_flags[] =
+{
+    {WINED3DFMT_UYVY,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_YUY2,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_YV12,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_DXT1,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_DXT2,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_DXT3,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_DXT4,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_DXT5,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_MULTI2_ARGB8,   WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_G8R8_G8B8,      WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_R8G8_B8G8,      WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_P8_UINT,        WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B8G8R8_UNORM,   WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B8G8R8X8_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B5G6R5_UNORM,   WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B5G5R5X1_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B5G5R5A1_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B4G4R4A4_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_B4G4R4X4_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_R8G8B8A8_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_R8G8B8X8_UNORM, WINED3DFMT_FLAG_GETDC},
+    {WINED3DFMT_ATI2N,          WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_NVHU,           WINED3DFMT_FLAG_FOURCC},
+    {WINED3DFMT_NVHS,           WINED3DFMT_FLAG_FOURCC},
 };
 
@@ -304,45 +338,38 @@
     {WINED3DFMT_P8_UINT,                GL_RGBA,                          GL_RGBA,                                0,
             GL_RGBA,                    GL_UNSIGNED_BYTE,
-            WINED3DFMT_FLAG_GETDC,
+            0,
             ARB_FRAGMENT_PROGRAM},
     {WINED3DFMT_P8_UINT,                GL_COLOR_INDEX8_EXT,              GL_COLOR_INDEX8_EXT,                    0,
             GL_COLOR_INDEX,             GL_UNSIGNED_BYTE,
-            WINED3DFMT_FLAG_GETDC,
+            0,
             EXT_PALETTED_TEXTURE},
     /* Standard ARGB formats */
     {WINED3DFMT_B8G8R8_UNORM,           GL_RGB8,                          GL_RGB8,                                0,
             GL_BGR,                     GL_UNSIGNED_BYTE,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
-            WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_B8G8R8A8_UNORM,         GL_RGBA8,                         GL_SRGB8_ALPHA8_EXT,                    0,
             GL_BGRA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
-            WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_B8G8R8X8_UNORM,         GL_RGB8,                          GL_SRGB8_EXT,                           0,
             GL_BGRA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
-            WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_B5G6R5_UNORM,           GL_RGB5,                          GL_RGB5,                          GL_RGB8,
             GL_RGB,                     GL_UNSIGNED_SHORT_5_6_5,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
-            WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_B5G5R5X1_UNORM,         GL_RGB5,                          GL_RGB5_A1,                             0,
             GL_BGRA,                    GL_UNSIGNED_SHORT_1_5_5_5_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING |
-            WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_B5G5R5A1_UNORM,         GL_RGB5_A1,                       GL_RGB5_A1,                             0,
             GL_BGRA,                    GL_UNSIGNED_SHORT_1_5_5_5_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING |
-            WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_B4G4R4A4_UNORM,         GL_RGBA4,                         GL_SRGB8_ALPHA8_EXT,                    0,
             GL_BGRA,                    GL_UNSIGNED_SHORT_4_4_4_4_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING |
-            WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_B2G3R3_UNORM,           GL_R3_G3_B2,                      GL_R3_G3_B2,                            0,
@@ -356,5 +383,5 @@
     {WINED3DFMT_B4G4R4X4_UNORM,         GL_RGB4,                          GL_RGB4,                                0,
             GL_BGRA,                    GL_UNSIGNED_SHORT_4_4_4_4_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_R10G10B10A2_UNORM,      GL_RGB10_A2,                      GL_RGB10_A2,                            0,
@@ -364,9 +391,9 @@
     {WINED3DFMT_R8G8B8A8_UNORM,         GL_RGBA8,                         GL_RGBA8,                               0,
             GL_RGBA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_R8G8B8X8_UNORM,         GL_RGB8,                          GL_RGB8,                                0,
             GL_RGBA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_GETDC,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
     {WINED3DFMT_R16G16_UNORM,           GL_RGB16_EXT,                     GL_RGB16_EXT,               GL_RGBA16_EXT,
@@ -457,13 +484,13 @@
             WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
             ARB_FRAMEBUFFER_OBJECT},
-    {WINED3DFMT_S8_UINT_D24_UNORM,      GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
+    {WINED3DFMT_D24_UNORM_S8_UINT,      GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
             GL_DEPTH_COMPONENT,         GL_UNSIGNED_INT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_S8_UINT_D24_UNORM,      GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
+    {WINED3DFMT_D24_UNORM_S8_UINT,      GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
             GL_DEPTH_STENCIL_EXT,       GL_UNSIGNED_INT_24_8_EXT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
             EXT_PACKED_DEPTH_STENCIL},
-    {WINED3DFMT_S8_UINT_D24_UNORM,      GL_DEPTH24_STENCIL8,              GL_DEPTH24_STENCIL8,                    0,
+    {WINED3DFMT_D24_UNORM_S8_UINT,      GL_DEPTH24_STENCIL8,              GL_DEPTH24_STENCIL8,                    0,
             GL_DEPTH_STENCIL,           GL_UNSIGNED_INT_24_8,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
@@ -552,5 +579,19 @@
         desc->depth_size = formats[i].depthSize;
         desc->stencil_size = formats[i].stencilSize;
-        if (formats[i].isFourcc) desc->Flags |= WINED3DFMT_FLAG_FOURCC;
+    }
+
+    for (i = 0; i < (sizeof(format_base_flags) / sizeof(*format_base_flags)); ++i)
+    {
+        int fmt_idx = getFmtIdx(format_base_flags[i].format);
+
+        if (fmt_idx == -1)
+        {
+            ERR("Format %s (%#x) not found.\n",
+                    debug_d3dformat(format_base_flags[i].format), format_base_flags[i].format);
+            HeapFree(GetProcessHeap(), 0, gl_info->gl_formats);
+            return FALSE;
+        }
+
+        gl_info->gl_formats[fmt_idx].Flags |= format_base_flags[i].flags;
     }
 
@@ -583,6 +624,4 @@
     return TRUE;
 }
-
-#define GLINFO_LOCATION (*gl_info)
 
 /* Context activation is done by the caller. */
@@ -673,6 +712,6 @@
         GLuint rb;
 
-        if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
-                || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+        if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
+                || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
         {
             gl_info->fbo_ops.glGenRenderbuffers(1, &rb);
@@ -693,6 +732,6 @@
         }
 
-        if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
-                || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+        if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
+                || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
         {
             gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
@@ -781,5 +820,5 @@
         }
 
-        if (!GL_SUPPORT(gl_formats_template[i].extension)) continue;
+        if (!gl_info->supported[gl_formats_template[i].extension]) continue;
 
         desc = &gl_info->gl_formats[fmt_idx];
@@ -907,5 +946,5 @@
 }
 
-static void init_format_filter_info(struct wined3d_gl_info *gl_info)
+static void init_format_filter_info(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor)
 {
     unsigned int fmt_idx, i;
@@ -921,10 +960,10 @@
     {
         WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
-        if(gl_info->gl_vendor == VENDOR_NVIDIA && GL_SUPPORT(ARB_TEXTURE_FLOAT))
+        if (vendor == VENDOR_NVIDIA && gl_info->supported[ARB_TEXTURE_FLOAT])
         {
             TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
             filtered = TRUE;
         }
-        else if(GL_LIMITS(glsl_varyings > 44))
+        else if (gl_info->limits.glsl_varyings > 44)
         {
             TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
@@ -1000,5 +1039,5 @@
      * conversion for this format.
      */
-    if (!GL_SUPPORT(NV_TEXTURE_SHADER))
+    if (!gl_info->supported[NV_TEXTURE_SHADER])
     {
         idx = getFmtIdx(WINED3DFMT_R8G8_SNORM);
@@ -1019,5 +1058,5 @@
     }
 
-    if (!GL_SUPPORT(NV_TEXTURE_SHADER))
+    if (!gl_info->supported[NV_TEXTURE_SHADER])
     {
         /* If GL_NV_texture_shader is not supported, those formats are converted, incompatibly
@@ -1043,5 +1082,5 @@
     }
 
-    if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_RGTC))
+    if (gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
     {
         idx = getFmtIdx(WINED3DFMT_ATI2N);
@@ -1049,5 +1088,5 @@
                 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
     }
-    else if (GL_SUPPORT(ATI_TEXTURE_COMPRESSION_3DC))
+    else if (gl_info->supported[ATI_TEXTURE_COMPRESSION_3DC])
     {
         idx = getFmtIdx(WINED3DFMT_ATI2N);
@@ -1056,5 +1095,5 @@
     }
 
-    if (!GL_SUPPORT(APPLE_YCBCR_422))
+    if (!gl_info->supported[APPLE_YCBCR_422])
     {
         idx = getFmtIdx(WINED3DFMT_YUY2);
@@ -1069,5 +1108,5 @@
     gl_info->gl_formats[idx].color_fixup = create_yuv_fixup_desc(YUV_FIXUP_YV12);
 
-    if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA))
+    if (gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
     {
         idx = getFmtIdx(WINED3DFMT_B8G8R8A8_UNORM);
@@ -1075,5 +1114,5 @@
     }
 
-    if (GL_SUPPORT(ARB_HALF_FLOAT_VERTEX))
+    if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
     {
         /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
@@ -1122,4 +1161,5 @@
     {
         HeapFree(GetProcessHeap(), 0, gl_info->gl_formats);
+        gl_info->gl_formats = NULL;
         return FALSE;
     }
@@ -1129,5 +1169,5 @@
 
 /* Context activation is done by the caller. */
-BOOL initPixelFormats(struct wined3d_gl_info *gl_info)
+BOOL initPixelFormats(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor)
 {
     if (!init_format_base_info(gl_info)) return FALSE;
@@ -1139,5 +1179,5 @@
     apply_format_fixups(gl_info);
     init_format_fbo_compat_info(gl_info);
-    init_format_filter_info(gl_info);
+    init_format_filter_info(gl_info, vendor);
 
     return TRUE;
@@ -1145,10 +1185,7 @@
 fail:
     HeapFree(GetProcessHeap(), 0, gl_info->gl_formats);
+    gl_info->gl_formats = NULL;
     return FALSE;
 }
-
-#undef GLINFO_LOCATION
-
-#define GLINFO_LOCATION This->adapter->gl_info
 
 const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const struct wined3d_gl_info *gl_info)
@@ -1203,5 +1240,4 @@
     FMT_TO_STR(WINED3DFMT_D32_UNORM);
     FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM);
-    FMT_TO_STR(WINED3DFMT_S8_UINT_D24_UNORM);
     FMT_TO_STR(WINED3DFMT_X8D24_UNORM);
     FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM);
@@ -2036,5 +2072,4 @@
     checkGLcall("glLoadMatrixf(mat)");
 }
-#undef GLINFO_LOCATION
 
 /* This small helper function is used to convert a bitmask into the number of masked bits */
@@ -2098,5 +2133,5 @@
         case WINED3DFMT_X8D24_UNORM:
         case WINED3DFMT_S4X4_UINT_D24_UNORM:
-        case WINED3DFMT_S8_UINT_D24_UNORM:
+        case WINED3DFMT_D24_UNORM_S8_UINT:
         case WINED3DFMT_S8_UINT_D24_FLOAT:
         case WINED3DFMT_D32_UNORM:
@@ -2200,10 +2235,10 @@
  *
  *********************************************************************/
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
-
-BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]) {
+BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4])
+{
+    const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
     int x1 = Rect->left, x2 = Rect->right;
     int y1 = Rect->top, y2 = Rect->bottom;
-    GLint maxSize = GL_LIMITS(texture_size);
+    GLint maxSize = gl_info->limits.texture_size;
 
     TRACE("(%p)->(%d,%d)-(%d,%d)\n", This,
@@ -2288,6 +2323,7 @@
             }
 
-            if(This->pow2Height > maxSize) {
-                This->glRect.top = x1 - GL_LIMITS(texture_size) / 2;
+            if (This->pow2Height > maxSize)
+            {
+                This->glRect.top = x1 - gl_info->limits.texture_size / 2;
                 if(This->glRect.top < 0) This->glRect.top = 0;
                 This->glRect.bottom = This->glRect.left + maxSize;
@@ -2323,7 +2359,5 @@
     return TRUE;
 }
-#undef GLINFO_LOCATION
-
-#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
+
 void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings, BOOL ignore_textype) {
 #define ARG1 0x01
@@ -2362,9 +2396,11 @@
     DWORD ttff;
     DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2;
-    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
+    IWineD3DDeviceImpl *device = stateblock->device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
     memset(settings, 0, sizeof(*settings));
 
-    for(i = 0; i < GL_LIMITS(texture_stages); i++) {
+    for (i = 0; i < gl_info->limits.texture_stages; ++i)
+    {
         IWineD3DBaseTextureImpl *texture;
         settings->op[i].padding = 0;
@@ -2567,5 +2603,4 @@
     }
 }
-#undef GLINFO_LOCATION
 
 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
@@ -2590,18 +2625,22 @@
  * Requires the caller to activate the correct unit before
  */
-#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
 /* GL locking is done by the caller (state handler) */
 void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    if(stateblock->textures[stage]) {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+
+    if (stateblock->textures[stage])
+    {
         switch (IWineD3DBaseTexture_GetTextureDimensions(stateblock->textures[stage])) {
             case GL_TEXTURE_2D:
                 glDisable(GL_TEXTURE_3D);
                 checkGLcall("glDisable(GL_TEXTURE_3D)");
-                if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+                if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+                {
                     glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                     checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
                 }
-                if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+                if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+                {
                     glDisable(GL_TEXTURE_RECTANGLE_ARB);
                     checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
@@ -2615,5 +2654,6 @@
                 glDisable(GL_TEXTURE_3D);
                 checkGLcall("glDisable(GL_TEXTURE_3D)");
-                if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+                if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+                {
                     glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                     checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
@@ -2623,9 +2663,11 @@
                 break;
             case GL_TEXTURE_3D:
-                if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+                if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+                {
                     glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                     checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
                 }
-                if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+                if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+                {
                     glDisable(GL_TEXTURE_RECTANGLE_ARB);
                     checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
@@ -2641,5 +2683,6 @@
                 glDisable(GL_TEXTURE_3D);
                 checkGLcall("glDisable(GL_TEXTURE_3D)");
-                if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+                if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+                {
                     glDisable(GL_TEXTURE_RECTANGLE_ARB);
                     checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
@@ -2654,9 +2697,11 @@
         glDisable(GL_TEXTURE_3D);
         checkGLcall("glDisable(GL_TEXTURE_3D)");
-        if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
+        if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+        {
             glDisable(GL_TEXTURE_CUBE_MAP_ARB);
             checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
         }
-        if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
+        if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
+        {
             glDisable(GL_TEXTURE_RECTANGLE_ARB);
             checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
@@ -2670,5 +2715,5 @@
 {
     DWORD sampler = state - STATE_SAMPLER(0);
-    DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
+    DWORD mapped_stage = stateblock->device->texUnitMap[sampler];
 
     /* No need to enable / disable anything here for unused samplers. The tex_colorop
@@ -2676,5 +2721,5 @@
     * will take care of this business
     */
-    if(mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= GL_LIMITS(textures)) return;
+    if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) return;
     if(sampler >= stateblock->lowest_disabled_stage) return;
     if(isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return;
@@ -2682,5 +2727,4 @@
     texture_activate_dimensions(sampler, stateblock, context);
 }
-#undef GLINFO_LOCATION
 
 void *wined3d_rb_alloc(size_t size)
@@ -2740,2 +2784,62 @@
     return (i = x >> 16) ? (x = i >> 8) ? l[x] + 24 : l[i] + 16 : (i = x >> 8) ? l[i] + 8 : l[x];
 }
+
+/* Set the shader type for this device, depending on the given capabilities
+ * and the user preferences in wined3d_settings. */
+void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected)
+{
+    if (wined3d_settings.vs_mode == VS_NONE) *vs_selected = SHADER_NONE;
+    else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested)
+    {
+        /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
+         * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
+         * shaders only on this card. */
+        if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2]) *vs_selected = SHADER_ARB;
+        else *vs_selected = SHADER_GLSL;
+    }
+    else if (gl_info->supported[ARB_VERTEX_PROGRAM]) *vs_selected = SHADER_ARB;
+    else *vs_selected = SHADER_NONE;
+
+    if (wined3d_settings.ps_mode == PS_NONE) *ps_selected = SHADER_NONE;
+    else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) *ps_selected = SHADER_GLSL;
+    else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) *ps_selected = SHADER_ARB;
+    else if (gl_info->supported[ATI_FRAGMENT_SHADER]) *ps_selected = SHADER_ATI;
+    else *ps_selected = SHADER_NONE;
+}
+
+const shader_backend_t *select_shader_backend(struct wined3d_adapter *adapter, WINED3DDEVTYPE device_type)
+{
+    int vs_selected_mode, ps_selected_mode;
+
+    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
+    if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) return &glsl_shader_backend;
+    if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) return &arb_program_shader_backend;
+    return &none_shader_backend;
+}
+
+const struct fragment_pipeline *select_fragment_implementation(struct wined3d_adapter *adapter,
+        WINED3DDEVTYPE device_type)
+{
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
+    int vs_selected_mode, ps_selected_mode;
+
+    select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
+    if ((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL)
+            && gl_info->supported[ARB_FRAGMENT_PROGRAM]) return &arbfp_fragment_pipeline;
+    else if (ps_selected_mode == SHADER_ATI) return &atifs_fragment_pipeline;
+    else if (gl_info->supported[NV_REGISTER_COMBINERS]
+            && gl_info->supported[NV_TEXTURE_SHADER2]) return &nvts_fragment_pipeline;
+    else if (gl_info->supported[NV_REGISTER_COMBINERS]) return &nvrc_fragment_pipeline;
+    else return &ffp_fragment_pipeline;
+}
+
+const struct blit_shader *select_blit_implementation(struct wined3d_adapter *adapter, WINED3DDEVTYPE device_type)
+{
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
+    int vs_selected_mode, ps_selected_mode;
+
+    select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
+    if ((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL)
+            && gl_info->supported[ARB_FRAGMENT_PROGRAM]) return &arbfp_blit;
+    else return &ffp_blit;
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexdeclaration.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexdeclaration.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexdeclaration.c	(revision 25949)
@@ -37,6 +37,4 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_decl);
 
-#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
-
 static void dump_wined3dvertexelement(const WINED3DVERTEXELEMENT *element) {
     TRACE("     format: %s (%#x)\n", debug_d3dformat(element->format), element->format);
@@ -78,10 +76,6 @@
     TRACE("(%p) : Releasing from %d\n", This, This->ref);
     ref = InterlockedDecrement(&This->ref);
-    if (ref == 0) {
-        if(iface == This->wineD3DDevice->stateBlock->vertexDecl) {
-            /* See comment in PixelShader::Release */
-            IWineD3DDeviceImpl_MarkStateDirty(This->wineD3DDevice, STATE_VDECL);
-        }
-
+    if (!ref)
+    {
         HeapFree(GetProcessHeap(), 0, This->elements);
         This->parent_ops->wined3d_object_destroyed(This->parent);
@@ -101,14 +95,4 @@
     IUnknown_AddRef(*parent);
     TRACE("(%p) : returning %p\n", This, *parent);
-    return WINED3D_OK;
-}
-
-static HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDevice(IWineD3DVertexDeclaration *iface, IWineD3DDevice** ppDevice) {
-    IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
-    TRACE("(%p) : returning %p\n", This, This->wineD3DDevice);
-
-    *ppDevice = (IWineD3DDevice *) This->wineD3DDevice;
-    IWineD3DDevice_AddRef(*ppDevice);
-
     return WINED3D_OK;
 }
@@ -210,5 +194,4 @@
     /* IWineD3DVertexDeclaration */
     IWineD3DVertexDeclarationImpl_GetParent,
-    IWineD3DVertexDeclarationImpl_GetDevice,
 };
 
@@ -233,5 +216,5 @@
     declaration->parent = parent;
     declaration->parent_ops = parent_ops;
-    declaration->wineD3DDevice = device;
+    declaration->device = device;
     declaration->elements = HeapAlloc(GetProcessHeap(), 0, sizeof(*declaration->elements) * element_count);
     if (!declaration->elements)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c	(revision 25947)
+++ 	(revision )
@@ -1,390 +1,0 @@
-/*
- * shaders implementation
- *
- * Copyright 2002-2003 Jason Edmeades
- * Copyright 2002-2003 Raphael Junqueira
- * Copyright 2004 Christian Costa
- * Copyright 2005 Oliver Stieber
- * Copyright 2006 Ivan Gyurdiev
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
- * Copyright 2009 Henri Verbeet for CodeWeavers
- *
- * 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
- */
-
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <stdio.h>
-
-#include "wined3d_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
-
-#define GLINFO_LOCATION ((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info
-
-static void vshader_set_limits(IWineD3DVertexShaderImpl *This)
-{
-    DWORD shader_version = WINED3D_SHADER_VERSION(This->baseShader.reg_maps.shader_version.major,
-            This->baseShader.reg_maps.shader_version.minor);
-
-    This->baseShader.limits.texcoord = 0;
-    This->baseShader.limits.attributes = 16;
-    This->baseShader.limits.packed_input = 0;
-
-    switch (shader_version)
-    {
-        case WINED3D_SHADER_VERSION(1,0):
-        case WINED3D_SHADER_VERSION(1,1):
-            This->baseShader.limits.temporary = 12;
-            This->baseShader.limits.constant_bool = 0;
-            This->baseShader.limits.constant_int = 0;
-            This->baseShader.limits.address = 1;
-            This->baseShader.limits.packed_output = 0;
-            This->baseShader.limits.sampler = 0;
-            This->baseShader.limits.label = 0;
-            /* TODO: vs_1_1 has a minimum of 96 constants. What happens if a vs_1_1 shader is used
-             * on a vs_3_0 capable card that has 256 constants? */
-            This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
-            break;
-
-        case WINED3D_SHADER_VERSION(2,0):
-        case WINED3D_SHADER_VERSION(2,1):
-            This->baseShader.limits.temporary = 12;
-            This->baseShader.limits.constant_bool = 16;
-            This->baseShader.limits.constant_int = 16;
-            This->baseShader.limits.address = 1;
-            This->baseShader.limits.packed_output = 0;
-            This->baseShader.limits.sampler = 0;
-            This->baseShader.limits.label = 16;
-            This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
-            break;
-
-        case WINED3D_SHADER_VERSION(4,0):
-            FIXME("Using 3.0 limits for 4.0 shader\n");
-            /* Fall through */
-
-        case WINED3D_SHADER_VERSION(3,0):
-            This->baseShader.limits.temporary = 32;
-            This->baseShader.limits.constant_bool = 32;
-            This->baseShader.limits.constant_int = 32;
-            This->baseShader.limits.address = 1;
-            This->baseShader.limits.packed_output = 12;
-            This->baseShader.limits.sampler = 4;
-            This->baseShader.limits.label = 16; /* FIXME: 2048 */
-            /* DX10 cards on Windows advertise a d3d9 constant limit of 256 even though they are capable
-             * of supporting much more(GL drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
-             * wined3d-advertised maximum. Clamp the constant limit for <= 3.0 shaders to 256.s
-             * use constant buffers */
-            This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
-            break;
-
-        default:
-            This->baseShader.limits.temporary = 12;
-            This->baseShader.limits.constant_bool = 16;
-            This->baseShader.limits.constant_int = 16;
-            This->baseShader.limits.address = 1;
-            This->baseShader.limits.packed_output = 0;
-            This->baseShader.limits.sampler = 0;
-            This->baseShader.limits.label = 16;
-            This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
-            FIXME("Unrecognized vertex shader version %u.%u\n",
-                    This->baseShader.reg_maps.shader_version.major,
-                    This->baseShader.reg_maps.shader_version.minor);
-    }
-}
-
-static BOOL match_usage(BYTE usage1, BYTE usage_idx1, BYTE usage2, BYTE usage_idx2) {
-    if (usage_idx1 != usage_idx2) return FALSE;
-    if (usage1 == usage2) return TRUE;
-    if (usage1 == WINED3DDECLUSAGE_POSITION && usage2 == WINED3DDECLUSAGE_POSITIONT) return TRUE;
-    if (usage2 == WINED3DDECLUSAGE_POSITION && usage1 == WINED3DDECLUSAGE_POSITIONT) return TRUE;
-
-    return FALSE;
-}
-
-BOOL vshader_get_input(IWineD3DVertexShader* iface, BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum)
-{
-    IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface;
-    WORD map = This->baseShader.reg_maps.input_registers;
-    unsigned int i;
-
-    for (i = 0; map; map >>= 1, ++i)
-    {
-        if (!(map & 1)) continue;
-
-        if (match_usage(This->attributes[i].usage,
-                This->attributes[i].usage_idx, usage_req, usage_idx_req))
-        {
-            *regnum = i;
-            return TRUE;
-        }
-    }
-    return FALSE;
-}
-
-/* *******************************************
-   IWineD3DVertexShader IUnknown parts follow
-   ******************************************* */
-static HRESULT  WINAPI IWineD3DVertexShaderImpl_QueryInterface(IWineD3DVertexShader *iface, REFIID riid, LPVOID *ppobj) {
-    TRACE("iface %p, riid %s, ppobj %p\n", iface, debugstr_guid(riid), ppobj);
-
-    if (IsEqualGUID(riid, &IID_IWineD3DVertexShader)
-            || IsEqualGUID(riid, &IID_IWineD3DBaseShader)
-            || IsEqualGUID(riid, &IID_IWineD3DBase)
-            || IsEqualGUID(riid, &IID_IUnknown))
-    {
-        IUnknown_AddRef(iface);
-        *ppobj = iface;
-        return S_OK;
-    }
-
-    WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
-
-    *ppobj = NULL;
-    return E_NOINTERFACE;
-}
-
-static ULONG  WINAPI IWineD3DVertexShaderImpl_AddRef(IWineD3DVertexShader *iface) {
-    IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface;
-    ULONG refcount = InterlockedIncrement(&This->baseShader.ref);
-
-    TRACE("%p increasing refcount to %u\n", This, refcount);
-
-    return refcount;
-}
-
-static ULONG WINAPI IWineD3DVertexShaderImpl_Release(IWineD3DVertexShader *iface) {
-    IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface;
-    ULONG refcount = InterlockedDecrement(&This->baseShader.ref);
-
-    TRACE("%p decreasing refcount to %u\n", This, refcount);
-
-    if (!refcount)
-    {
-        shader_cleanup((IWineD3DBaseShader *)iface);
-        This->baseShader.parent_ops->wined3d_object_destroyed(This->baseShader.parent);
-        HeapFree(GetProcessHeap(), 0, This);
-    }
-
-    return refcount;
-}
-
-/* *******************************************
-   IWineD3DVertexShader IWineD3DVertexShader parts follow
-   ******************************************* */
-
-static HRESULT WINAPI IWineD3DVertexShaderImpl_GetParent(IWineD3DVertexShader *iface, IUnknown** parent){
-    IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface;
-
-    *parent = This->baseShader.parent;
-    IUnknown_AddRef(*parent);
-    TRACE("(%p) : returning %p\n", This, *parent);
-    return WINED3D_OK;
-}
-
-static HRESULT WINAPI IWineD3DVertexShaderImpl_GetDevice(IWineD3DVertexShader* iface, IWineD3DDevice **pDevice){
-    IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface;
-    IWineD3DDevice_AddRef(This->baseShader.device);
-    *pDevice = This->baseShader.device;
-    TRACE("(%p) returning %p\n", This, *pDevice);
-    return WINED3D_OK;
-}
-
-static HRESULT WINAPI IWineD3DVertexShaderImpl_GetFunction(IWineD3DVertexShader* impl, VOID* pData, UINT* pSizeOfData) {
-    IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)impl;
-    TRACE("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
-
-    if (NULL == pData) {
-        *pSizeOfData = This->baseShader.functionLength;
-        return WINED3D_OK;
-    }
-    if (*pSizeOfData < This->baseShader.functionLength) {
-        /* MSDN claims (for d3d8 at least) that if *pSizeOfData is smaller
-         * than the required size we should write the required size and
-         * return D3DERR_MOREDATA. That's not actually true. */
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    TRACE("(%p) : GetFunction copying to %p\n", This, pData);
-    memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
-
-    return WINED3D_OK;
-}
-
-static HRESULT vertexshader_set_function(IWineD3DVertexShaderImpl *shader,
-        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
-{
-    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)shader->baseShader.device;
-    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    const struct wined3d_shader_frontend *fe;
-    unsigned int i;
-    HRESULT hr;
-    shader_reg_maps *reg_maps = &shader->baseShader.reg_maps;
-
-    TRACE("shader %p, byte_code %p, output_signature %p.\n", shader, byte_code, output_signature);
-
-    fe = shader_select_frontend(*byte_code);
-    if (!fe)
-    {
-        FIXME("Unable to find frontend for shader.\n");
-        return WINED3DERR_INVALIDCALL;
-    }
-    shader->baseShader.frontend = fe;
-    shader->baseShader.frontend_data = fe->shader_init(byte_code, output_signature);
-    if (!shader->baseShader.frontend_data)
-    {
-        FIXME("Failed to initialize frontend.\n");
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    /* First pass: trace shader */
-    if (TRACE_ON(d3d_shader)) shader_trace_init(fe, shader->baseShader.frontend_data, byte_code);
-
-    /* Initialize immediate constant lists */
-    list_init(&shader->baseShader.constantsF);
-    list_init(&shader->baseShader.constantsB);
-    list_init(&shader->baseShader.constantsI);
-
-    /* Second pass: figure out registers used, semantics, etc.. */
-    shader->min_rel_offset = gl_info->max_vshader_constantsF;
-    shader->max_rel_offset = 0;
-    hr = shader_get_registers_used((IWineD3DBaseShader *)shader, fe,
-            reg_maps, shader->attributes, NULL, shader->output_signature,
-            byte_code, gl_info->max_vshader_constantsF);
-    if (hr != WINED3D_OK) return hr;
-
-    if (output_signature)
-    {
-        for (i = 0; i < output_signature->element_count; ++i)
-        {
-            struct wined3d_shader_signature_element *e = &output_signature->elements[i];
-            reg_maps->output_registers |= 1 << e->register_idx;
-            shader->output_signature[e->register_idx] = *e;
-        }
-    }
-
-    vshader_set_limits(shader);
-
-    if (device->vs_selected_mode == SHADER_ARB
-            && (gl_info->quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT)
-            && shader->min_rel_offset <= shader->max_rel_offset)
-    {
-        if (shader->max_rel_offset - shader->min_rel_offset > 127)
-        {
-            FIXME("The difference between the minimum and maximum relative offset is > 127\n");
-            FIXME("Which this OpenGL implementation does not support. Try using GLSL\n");
-            FIXME("Min: %d, Max: %d\n", shader->min_rel_offset, shader->max_rel_offset);
-        }
-        else if (shader->max_rel_offset - shader->min_rel_offset > 63)
-        {
-            shader->rel_offset = shader->min_rel_offset + 63;
-        }
-        else if (shader->max_rel_offset > 63)
-        {
-            shader->rel_offset = shader->min_rel_offset;
-        }
-        else
-        {
-            shader->rel_offset = 0;
-        }
-    }
-    shader->baseShader.load_local_constsF = shader->baseShader.reg_maps.usesrelconstF
-            && !list_empty(&shader->baseShader.constantsF);
-
-    /* copy the function ... because it will certainly be released by application */
-    shader->baseShader.function = HeapAlloc(GetProcessHeap(), 0, shader->baseShader.functionLength);
-    if (!shader->baseShader.function) return E_OUTOFMEMORY;
-    memcpy(shader->baseShader.function, byte_code, shader->baseShader.functionLength);
-
-    return WINED3D_OK;
-}
-
-/* Set local constants for d3d8 shaders */
-static HRESULT WINAPI IWIneD3DVertexShaderImpl_SetLocalConstantsF(IWineD3DVertexShader *iface,
-        UINT start_idx, const float *src_data, UINT count) {
-    IWineD3DVertexShaderImpl *This =(IWineD3DVertexShaderImpl *)iface;
-    UINT i, end_idx;
-
-    TRACE("(%p) : start_idx %u, src_data %p, count %u\n", This, start_idx, src_data, count);
-
-    end_idx = start_idx + count;
-    if (end_idx > GL_LIMITS(vshader_constantsF)) {
-        WARN("end_idx %u > float constants limit %u\n", end_idx, GL_LIMITS(vshader_constantsF));
-        end_idx = GL_LIMITS(vshader_constantsF);
-    }
-
-    for (i = start_idx; i < end_idx; ++i) {
-        local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
-        if (!lconst) return E_OUTOFMEMORY;
-
-        lconst->idx = i;
-        memcpy(lconst->value, src_data + (i - start_idx) * 4 /* 4 components */, 4 * sizeof(float));
-        list_add_head(&This->baseShader.constantsF, &lconst->entry);
-    }
-
-    return WINED3D_OK;
-}
-
-static const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl =
-{
-    /*** IUnknown methods ***/
-    IWineD3DVertexShaderImpl_QueryInterface,
-    IWineD3DVertexShaderImpl_AddRef,
-    IWineD3DVertexShaderImpl_Release,
-    /*** IWineD3DBase methods ***/
-    IWineD3DVertexShaderImpl_GetParent,
-    /*** IWineD3DBaseShader methods ***/
-    IWineD3DVertexShaderImpl_GetDevice,
-    IWineD3DVertexShaderImpl_GetFunction,
-    /*** IWineD3DVertexShader methods ***/
-    IWIneD3DVertexShaderImpl_SetLocalConstantsF
-};
-
-void find_vs_compile_args(IWineD3DVertexShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct vs_compile_args *args) {
-    args->fog_src = stateblock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE ? VS_FOG_COORD : VS_FOG_Z;
-    args->swizzle_map = ((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.swizzle_map;
-}
-
-HRESULT vertexshader_init(IWineD3DVertexShaderImpl *shader, IWineD3DDeviceImpl *device,
-        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
-        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
-{
-    HRESULT hr;
-
-    if (!byte_code) return WINED3DERR_INVALIDCALL;
-
-    shader->lpVtbl = &IWineD3DVertexShader_Vtbl;
-    shader_init(&shader->baseShader, device, parent, parent_ops);
-
-    hr = vertexshader_set_function(shader, byte_code, output_signature);
-    if (FAILED(hr))
-    {
-        WARN("Failed to set function, hr %#x.\n", hr);
-        shader_cleanup((IWineD3DBaseShader *)shader);
-        return hr;
-    }
-
-    return WINED3D_OK;
-}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 25949)
@@ -35,9 +35,10 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION This->resource.device->adapter->gl_info
 
 /* Context activation is done by the caller. */
 static void volume_bind_and_dirtify(IWineD3DVolume *iface) {
     IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
+    const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
     IWineD3DVolumeTexture *texture;
     DWORD active_sampler;
@@ -54,10 +55,11 @@
      * TODO: Track the current active texture per GL context instead of using glGet
      */
-    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
+    if (gl_info->supported[ARB_MULTITEXTURE])
+    {
         GLint active_texture;
         ENTER_GL();
         glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
         LEAVE_GL();
-        active_sampler = This->resource.wineD3DDevice->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
+        active_sampler = This->resource.device->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
     } else {
         active_sampler = 0;
@@ -66,5 +68,5 @@
     if (active_sampler != WINED3D_UNMAPPED_STAGE)
     {
-        IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(active_sampler));
+        IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_SAMPLER(active_sampler));
     }
 
@@ -105,16 +107,21 @@
    IWineD3DVolume IUnknown parts follow
    ******************************************* */
-static HRESULT WINAPI IWineD3DVolumeImpl_QueryInterface(IWineD3DVolume *iface, REFIID riid, LPVOID *ppobj)
+static HRESULT WINAPI IWineD3DVolumeImpl_QueryInterface(IWineD3DVolume *iface, REFIID riid, void **object)
 {
-    IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
-    TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    if (IsEqualGUID(riid, &IID_IUnknown)
-        || IsEqualGUID(riid, &IID_IWineD3DBase)
-        || IsEqualGUID(riid, &IID_IWineD3DVolume)){
+    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
+
+    if (IsEqualGUID(riid, &IID_IWineD3DVolume)
+            || IsEqualGUID(riid, &IID_IWineD3DResource)
+            || IsEqualGUID(riid, &IID_IWineD3DBase)
+            || IsEqualGUID(riid, &IID_IUnknown))
+    {
         IUnknown_AddRef(iface);
-        *ppobj = This;
+        *object = iface;
         return S_OK;
     }
-    *ppobj = NULL;
+
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *object = NULL;
     return E_NOINTERFACE;
 }
@@ -146,8 +153,4 @@
 }
 
-static HRESULT WINAPI IWineD3DVolumeImpl_GetDevice(IWineD3DVolume *iface, IWineD3DDevice** ppDevice) {
-    return resource_get_device((IWineD3DResource *)iface, ppDevice);
-}
-
 static HRESULT WINAPI IWineD3DVolumeImpl_SetPrivateData(IWineD3DVolume *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
     return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
@@ -195,4 +198,5 @@
     if (!ppContainer) {
         ERR("Called without a valid ppContainer.\n");
+        return E_FAIL;
     }
 
@@ -200,4 +204,5 @@
     if (!This->container) {
         ERR("Volume without an container. Should not happen.\n");
+        return E_FAIL;
     }
 
@@ -291,7 +296,8 @@
 static HRESULT WINAPI IWineD3DVolumeImpl_UnlockBox(IWineD3DVolume *iface) {
     IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
-    if (!This->locked) {
-      ERR("trying to lock unlocked volume@%p\n", This);
-      return WINED3DERR_INVALIDCALL;
+    if (!This->locked)
+    {
+        WARN("Trying to unlock unlocked volume %p.\n", iface);
+        return WINED3DERR_INVALIDCALL;
     }
     TRACE("(%p) : unlocking volume\n", This);
@@ -367,5 +373,4 @@
     /* IWineD3DResource */
     IWineD3DVolumeImpl_GetParent,
-    IWineD3DVolumeImpl_GetDevice,
     IWineD3DVolumeImpl_SetPrivateData,
     IWineD3DVolumeImpl_GetPrivateData,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 25949)
@@ -36,12 +36,11 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
 
-#define GLINFO_LOCATION (*gl_info)
-
 static void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
 {
     /* Override the IWineD3DResource Preload method. */
     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    IWineD3DDeviceImpl *device = This->resource.device;
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    struct wined3d_context *context = NULL;
     BOOL srgb_mode = This->baseTexture.is_srgb;
     BOOL srgb_was_toggled = FALSE;
@@ -50,9 +49,6 @@
     TRACE("(%p) : About to load texture.\n", This);
 
-    if (!device->isInDraw)
-    {
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-    }
-    else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0)
+    if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+    else if (gl_info->supported[EXT_TEXTURE_SRGB] && This->baseTexture.bindCount > 0)
     {
         srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
@@ -83,4 +79,6 @@
     }
 
+    if (context) context_release(context);
+
     /* No longer dirty */
     This->baseTexture.texture_rgb.dirty = FALSE;
@@ -107,11 +105,7 @@
 }
 
-#undef GLINFO_LOCATION
-
 /* *******************************************
    IWineD3DTexture IUnknown parts follow
    ******************************************* */
-
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
 
 static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
@@ -155,8 +149,4 @@
    IWineD3DVolumeTexture IWineD3DResource parts follow
    **************************************************** */
-static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
-    return resource_get_device((IWineD3DResource *)iface, ppDevice);
-}
-
 static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
     return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
@@ -244,20 +234,23 @@
 
 /* Context activation is done by the caller. */
-static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface, BOOL srgb) {
-    IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
+static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface, BOOL srgb)
+{
     BOOL dummy;
-    TRACE("(%p) : relay to BaseTexture\n", This);
+
+    TRACE("iface %p, srgb %#x.\n", iface, srgb);
+
     return basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &dummy);
 }
 
-static UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
-    IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
-    TRACE("(%p)\n", This);
+static UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface)
+{
+    TRACE("iface %p.\n", iface);
+
     return GL_TEXTURE_3D;
 }
 
-static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *iface) {
-    IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
-    TRACE("(%p)\n", This);
+static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *iface)
+{
+    TRACE("iface %p.\n", iface);
 
     return FALSE;
@@ -338,5 +331,4 @@
     /* resource */
     IWineD3DVolumeTextureImpl_GetParent,
-    IWineD3DVolumeTextureImpl_GetDevice,
     IWineD3DVolumeTextureImpl_SetPrivateData,
     IWineD3DVolumeTextureImpl_GetPrivateData,
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 25949)
@@ -83,4 +83,6 @@
 typedef double          GLclampd;
 typedef void            GLvoid;
+typedef ptrdiff_t       GLintptr;
+typedef ptrdiff_t       GLsizeiptr;
 
 /* Booleans */
@@ -2510,7 +2512,7 @@
 typedef void (WINE_GLAPI * PGLFNGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
 typedef GLboolean (WINE_GLAPI * PGLFNISBUFFERARBPROC) (GLuint buffer);
-typedef void (WINE_GLAPI * PGLFNBUFFERDATAARBPROC) (GLenum target, ptrdiff_t size, const GLvoid *data, GLenum usage);
-typedef void (WINE_GLAPI * PGLFNBUFFERSUBDATAARBPROC) (GLenum target, ptrdiff_t offset, ptrdiff_t size, const GLvoid *data);
-typedef void (WINE_GLAPI * PGLFNGETBUFFERSUBDATAARBPROC) (GLenum target, ptrdiff_t offset, ptrdiff_t size, GLvoid *data);
+typedef void (WINE_GLAPI * PGLFNBUFFERDATAARBPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
+typedef void (WINE_GLAPI * PGLFNBUFFERSUBDATAARBPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
+typedef void (WINE_GLAPI * PGLFNGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data);
 typedef GLvoid* (WINE_GLAPI * PGLFNMAPBUFFERARBPROC) (GLenum target, GLenum access);
 typedef GLboolean (WINE_GLAPI * PGLFNUNMAPBUFFERARBPROC) (GLenum target);
@@ -3269,4 +3271,13 @@
 #define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV               0x88F4
 #define GL_MAX_PROGRAM_CALL_DEPTH_NV                      0x88F5
+#endif
+
+/* GL_APPLE_flush_buffer_range */
+#ifndef GL_APPLE_flush_buffer_range
+#define GL_APPLE_flush_buffer_range
+#define GL_BUFFER_SERIALIZED_MODIFY_APPLE                 0x8A12
+#define GL_BUFFER_FLUSHING_UNMAP_APPLE                    0x8A13
+typedef void (WINE_GLAPI *PGLFNBUFFERPARAMETERIAPPLE) (GLenum target, GLenum pname, GLint param);
+typedef void (WINE_GLAPI *PGLFNFLUSHMAPPEDBUFFERRANGEAPPLE) (GLenum target, GLintptr offset, GLsizeiptr size);
 #endif
 
@@ -3471,81 +3482,4 @@
  * Enumerated types
  ****************************************************/
-typedef enum _GL_Vendors {
-  VENDOR_WINE   = 0x0,
-  VENDOR_MESA   = 0x1,
-  VENDOR_ATI    = 0x1002,
-  VENDOR_NVIDIA = 0x10de,
-  VENDOR_INTEL  = 0x8086
-} GL_Vendors;
-
-typedef enum _GL_Cards {
-  CARD_WINE                       =    0x0,
-
-  CARD_ATI_RAGE_128PRO            = 0x5246,
-  CARD_ATI_RADEON_7200            = 0x5144,
-  CARD_ATI_RADEON_8500            = 0x514c,
-  CARD_ATI_RADEON_9500            = 0x4144,
-  CARD_ATI_RADEON_XPRESS_200M     = 0x5955,
-  CARD_ATI_RADEON_X700            = 0x5e4c,
-  CARD_ATI_RADEON_X1600           = 0x71c2,
-  CARD_ATI_RADEON_HD2300          = 0x7210,
-  CARD_ATI_RADEON_HD2600          = 0x9581,
-  CARD_ATI_RADEON_HD2900          = 0x9400,
-  CARD_ATI_RADEON_HD3200          = 0x9620,
-  CARD_ATI_RADEON_HD4350          = 0x954f,
-  CARD_ATI_RADEON_HD4550          = 0x9540,
-  CARD_ATI_RADEON_HD4600          = 0x9495,
-  CARD_ATI_RADEON_HD4650          = 0x9498,
-  CARD_ATI_RADEON_HD4670          = 0x9490,
-  CARD_ATI_RADEON_HD4700          = 0x944e,
-  CARD_ATI_RADEON_HD4770          = 0x94b3,
-  CARD_ATI_RADEON_HD4800          = 0x944c, /* picked one value between 9440,944c,9442,9460 */
-  CARD_ATI_RADEON_HD4830          = 0x944c,
-  CARD_ATI_RADEON_HD4850          = 0x9442,
-  CARD_ATI_RADEON_HD4870          = 0x9440,
-  CARD_ATI_RADEON_HD4890          = 0x9460,
-
-  CARD_NVIDIA_RIVA_128            = 0x0018,
-  CARD_NVIDIA_RIVA_TNT            = 0x0020,
-  CARD_NVIDIA_RIVA_TNT2           = 0x0028,
-  CARD_NVIDIA_GEFORCE             = 0x0100,
-  CARD_NVIDIA_GEFORCE2_MX         = 0x0110,
-  CARD_NVIDIA_GEFORCE2            = 0x0150,
-  CARD_NVIDIA_GEFORCE3            = 0x0200,
-  CARD_NVIDIA_GEFORCE4_MX         = 0x0170,
-  CARD_NVIDIA_GEFORCE4_TI4200     = 0x0253,
-  CARD_NVIDIA_GEFORCEFX_5200      = 0x0320,
-  CARD_NVIDIA_GEFORCEFX_5600      = 0x0312,
-  CARD_NVIDIA_GEFORCEFX_5800      = 0x0302,
-  CARD_NVIDIA_GEFORCE_6200        = 0x014f,
-  CARD_NVIDIA_GEFORCE_6600GT      = 0x0140,
-  CARD_NVIDIA_GEFORCE_6800        = 0x0041,
-  CARD_NVIDIA_GEFORCE_7400        = 0x01d8,
-  CARD_NVIDIA_GEFORCE_7300        = 0x01d7, /* GeForce Go 7300 */
-  CARD_NVIDIA_GEFORCE_7600        = 0x0391,
-  CARD_NVIDIA_GEFORCE_7800GT      = 0x0092,
-  CARD_NVIDIA_GEFORCE_8300GS      = 0x0423,
-  CARD_NVIDIA_GEFORCE_8600GT      = 0x0402,
-  CARD_NVIDIA_GEFORCE_8600MGT     = 0x0407,
-  CARD_NVIDIA_GEFORCE_8800GTS     = 0x0193,
-  CARD_NVIDIA_GEFORCE_9200        = 0x086d,
-  CARD_NVIDIA_GEFORCE_9400GT      = 0x042c,
-  CARD_NVIDIA_GEFORCE_9500GT      = 0x0640,
-  CARD_NVIDIA_GEFORCE_9600GT      = 0x0622,
-  CARD_NVIDIA_GEFORCE_9800GT      = 0x0614,
-  CARD_NVIDIA_GEFORCE_GTX260      = 0x05e2,
-  CARD_NVIDIA_GEFORCE_GTX275      = 0x05e6,
-  CARD_NVIDIA_GEFORCE_GTX280      = 0x05e1,
-
-  CARD_INTEL_845G                 = 0x2562,
-  CARD_INTEL_I830G                = 0x3577,
-  CARD_INTEL_I855G                = 0x3582,
-  CARD_INTEL_I865G                = 0x2572,
-  CARD_INTEL_I915G                = 0x2582,
-  CARD_INTEL_I915GM               = 0x2592,
-  CARD_INTEL_I945GM               = 0x27a2, /* Same as GMA 950?? */
-  CARD_INTEL_X3100                = 0x2a02, /* found in macs. Same as GMA 965? */
-} GL_Cards;
-
 #define WINE_DEFAULT_VIDMEM 64*1024*1024
 
@@ -3657,4 +3591,5 @@
   APPLE_YCBCR_422,
   APPLE_FLOAT_PIXELS,
+  APPLE_FLUSH_BUFFER_RANGE,
   /* SGI */
   SGI_VIDEO_SYNC,
@@ -4005,5 +3940,9 @@
     USE_GL_FUNC(PGLFNALPHAFRAGMENTOP2ATI,                           glAlphaFragmentOp2ATI,                      ATI_FRAGMENT_SHADER,    NULL )\
     USE_GL_FUNC(PGLFNALPHAFRAGMENTOP3ATI,                           glAlphaFragmentOp3ATI,                      ATI_FRAGMENT_SHADER,    NULL )\
-    USE_GL_FUNC(PGLFNSETFRAGMENTSHADERCONSTANTATI,                  glSetFragmentShaderConstantATI,             ATI_FRAGMENT_SHADER,    NULL )
+    USE_GL_FUNC(PGLFNSETFRAGMENTSHADERCONSTANTATI,                  glSetFragmentShaderConstantATI,             ATI_FRAGMENT_SHADER,    NULL )\
+    /* GL_APPLE_flush_buffer_range */ \
+    USE_GL_FUNC(PGLFNBUFFERPARAMETERIAPPLE,                         glBufferParameteriAPPLE,                    APPLE_FLUSH_BUFFER_RANGE,NULL)\
+    USE_GL_FUNC(PGLFNFLUSHMAPPEDBUFFERRANGEAPPLE,                   glFlushMappedBufferRangeAPPLE,              APPLE_FLUSH_BUFFER_RANGE,NULL)
+
 
 /****************************************************
@@ -4144,51 +4083,49 @@
 };
 
+struct wined3d_gl_limits
+{
+    UINT buffers;
+    UINT lights;
+    UINT textures;
+    UINT texture_stages;
+    UINT fragment_samplers;
+    UINT vertex_samplers;
+    UINT combined_samplers;
+    UINT sampler_stages;
+    UINT clipplanes;
+    UINT texture_size;
+    UINT texture3d_size;
+    float pointsize_max;
+    float pointsize_min;
+    UINT point_sprite_units;
+    UINT blends;
+    UINT anisotropy;
+    float shininess;
+
+    UINT glsl_varyings;
+    UINT glsl_vs_float_constants;
+    UINT glsl_ps_float_constants;
+
+    UINT arb_vs_float_constants;
+    UINT arb_vs_native_constants;
+    UINT arb_vs_instructions;
+    UINT arb_vs_temps;
+    UINT arb_ps_float_constants;
+    UINT arb_ps_local_constants;
+    UINT arb_ps_native_constants;
+    UINT arb_ps_instructions;
+    UINT arb_ps_temps;
+};
+
 #define USE_GL_FUNC(type, pfn, ext, replace) type pfn;
 
 struct wined3d_gl_info
 {
-    GL_Vendors gl_vendor;
-    GL_Cards gl_card;
     UINT vidmem;
-    DWORD driver_version;
-    DWORD driver_version_hipart;
-    const char *driver_description;
-
-    UINT max_buffers;
-    UINT max_lights;
-    UINT max_textures;
-    UINT max_texture_stages;
-    UINT max_fragment_samplers;
-    UINT max_vertex_samplers;
-    UINT max_combined_samplers;
-    UINT max_sampler_stages;
-    UINT max_clipplanes;
-    UINT max_texture_size;
-    UINT max_texture3d_size;
-    float max_pointsize, max_pointsizemin;
-    UINT max_point_sprite_units;
-    UINT max_blends;
-    UINT max_anisotropy;
-    UINT max_glsl_varyings;
-    float max_shininess;
-
-    unsigned int max_vshader_constantsF;
-    unsigned int max_pshader_constantsF;
-
-    unsigned int vs_arb_constantsF;
-    unsigned int vs_arb_max_instructions;
-    unsigned int vs_arb_max_temps;
-    unsigned int ps_arb_constantsF;
-    unsigned int ps_arb_max_local_constants;
-    unsigned int ps_arb_max_instructions;
-    unsigned int ps_arb_max_temps;
-    unsigned int vs_glsl_constantsF;
-    unsigned int ps_glsl_constantsF;
-
+    struct wined3d_gl_limits limits;
     DWORD reserved_glsl_constants;
-
     DWORD quirks;
-
     BOOL supported[WINED3D_GL_EXT_COUNT];
+    GLint wrap_lookup[WINED3DTADDRESS_MIRRORONCE - WINED3DTADDRESS_WRAP + 1];
 
     struct wined3d_fbo_ops fbo_ops;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c	(revision 25949)
@@ -39,4 +39,20 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
 
+struct wined3d_wndproc
+{
+    HWND window;
+    WNDPROC proc;
+    IWineD3DDeviceImpl *device;
+};
+
+struct wined3d_wndproc_table
+{
+    struct wined3d_wndproc *entries;
+    unsigned int count;
+    unsigned int size;
+};
+
+static struct wined3d_wndproc_table wndproc_table;
+
 int num_lock = 0;
 void (*CDECL wine_tsx11_lock_ptr)(void) = NULL;
@@ -335,4 +351,5 @@
 {
     DWORD wined3d_context_tls_idx = context_get_tls_idx();
+    unsigned int i;
 
     if (!TlsFree(wined3d_context_tls_idx))
@@ -342,4 +359,11 @@
     }
 
+    for (i = 0; i < wndproc_table.count; ++i)
+    {
+        struct wined3d_wndproc *entry = &wndproc_table.entries[i];
+        SetWindowLongPtrW(entry->window, GWLP_WNDPROC, (LONG_PTR)entry->proc);
+    }
+    HeapFree(GetProcessHeap(), 0, wndproc_table.entries);
+
     HeapFree(GetProcessHeap(), 0, wined3d_settings.logo);
     UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL);
@@ -358,4 +382,102 @@
 }
 
+static struct wined3d_wndproc *wined3d_find_wndproc(HWND window)
+{
+    unsigned int i;
+
+    for (i = 0; i < wndproc_table.count; ++i)
+    {
+        if (wndproc_table.entries[i].window == window)
+        {
+            return &wndproc_table.entries[i];
+        }
+    }
+
+    return NULL;
+}
+
+static LRESULT CALLBACK wined3d_wndproc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
+{
+    struct wined3d_wndproc *entry;
+    IWineD3DDeviceImpl *device;
+    WNDPROC proc;
+
+    wined3d_mutex_lock();
+    entry = wined3d_find_wndproc(window);
+
+    if (!entry)
+    {
+        wined3d_mutex_unlock();
+        ERR("Window %p is not registered with wined3d.\n", window);
+        return DefWindowProcW(window, message, wparam, lparam);
+    }
+
+    device = entry->device;
+    proc = entry->proc;
+    wined3d_mutex_unlock();
+
+    return device_process_message(device, window, message, wparam, lparam, proc);
+}
+
+BOOL wined3d_register_window(HWND window, IWineD3DDeviceImpl *device)
+{
+    struct wined3d_wndproc *entry;
+
+    wined3d_mutex_lock();
+
+    if (wndproc_table.size == wndproc_table.count)
+    {
+        unsigned int new_size = max(1, wndproc_table.size * 2);
+        struct wined3d_wndproc *new_entries;
+
+        if (!wndproc_table.entries) new_entries = HeapAlloc(GetProcessHeap(), 0, new_size * sizeof(*new_entries));
+        else new_entries = HeapReAlloc(GetProcessHeap(), 0, wndproc_table.entries, new_size * sizeof(*new_entries));
+
+        if (!new_entries)
+        {
+            wined3d_mutex_unlock();
+            ERR("Failed to grow table.\n");
+            return FALSE;
+        }
+
+        wndproc_table.entries = new_entries;
+        wndproc_table.size = new_size;
+    }
+
+    entry = &wndproc_table.entries[wndproc_table.count++];
+    entry->window = window;
+    entry->proc = (WNDPROC)SetWindowLongPtrW(window, GWLP_WNDPROC, (LONG_PTR)wined3d_wndproc);
+    entry->device = device;
+
+    wined3d_mutex_unlock();
+
+    return TRUE;
+}
+
+void wined3d_unregister_window(HWND window)
+{
+    unsigned int i;
+
+    wined3d_mutex_lock();
+    for (i = 0; i < wndproc_table.count; ++i)
+    {
+        if (wndproc_table.entries[i].window == window)
+        {
+            struct wined3d_wndproc *entry = &wndproc_table.entries[i];
+            struct wined3d_wndproc *last = &wndproc_table.entries[--wndproc_table.count];
+
+            if (GetWindowLongPtrW(window, GWLP_WNDPROC) == (LONG_PTR)wined3d_wndproc)
+                SetWindowLongPtrW(window, GWLP_WNDPROC, (LONG_PTR)entry->proc);
+            if (entry != last) *entry = *last;
+            wined3d_mutex_unlock();
+
+            return;
+        }
+    }
+    wined3d_mutex_unlock();
+
+    ERR("Window %p is not registered with wined3d.\n", window);
+}
+
 /* At process attach */
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 25947)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 25949)
@@ -36,4 +36,5 @@
 #include <stdarg.h>
 #include <math.h>
+#include <limits.h>
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
@@ -58,4 +59,5 @@
 #define WINED3D_QUIRK_GLSL_CLIP_VARYING         0x00000004
 #define WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA     0x00000008
+#define WINED3D_QUIRK_NV_CLIP_BROKEN            0x00000010
 
 /* Texture format fixups */
@@ -156,28 +158,4 @@
 #define MAX_ACTIVE_LIGHTS       8
 #define MAX_CLIPPLANES          WINED3DMAXUSERCLIPPLANES
-
-/* Used for CreateStateBlock */
-#define NUM_SAVEDPIXELSTATES_R     35
-#define NUM_SAVEDPIXELSTATES_T     18
-#define NUM_SAVEDPIXELSTATES_S     12
-#define NUM_SAVEDVERTEXSTATES_R    34
-#define NUM_SAVEDVERTEXSTATES_T    2
-#define NUM_SAVEDVERTEXSTATES_S    1
-
-extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R] DECLSPEC_HIDDEN;
-extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T] DECLSPEC_HIDDEN;
-extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S] DECLSPEC_HIDDEN;
-extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R] DECLSPEC_HIDDEN;
-extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T] DECLSPEC_HIDDEN;
-extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S] DECLSPEC_HIDDEN;
-
-typedef enum _WINELOOKUP {
-    WINELOOKUP_WARPPARAM = 0,
-    MAX_LOOKUPS          = 1
-} WINELOOKUP;
-
-extern const int minLookup[MAX_LOOKUPS] DECLSPEC_HIDDEN;
-extern const int maxLookup[MAX_LOOKUPS] DECLSPEC_HIDDEN;
-extern DWORD *stateLookup[MAX_LOOKUPS] DECLSPEC_HIDDEN;
 
 struct min_lookup
@@ -270,8 +248,4 @@
 #define VBO_NONE   0
 #define VBO_HW     1
-
-#define NP2_NONE   0
-#define NP2_REPACK 1
-#define NP2_NATIVE 2
 
 #define ORM_BACKBUFFER  0
@@ -356,11 +330,4 @@
 };
 
-typedef enum _WINED3DVS_RASTOUT_OFFSETS
-{
-    WINED3DSRO_POSITION = 0,
-    WINED3DSRO_FOG = 1,
-    WINED3DSRO_POINT_SIZE = 2,
-} WINED3DVS_RASTOUT_OFFSETS;
-
 #define WINED3DSP_NOSWIZZLE (0 | (1 << 2) | (2 << 4) | (3 << 6))
 
@@ -397,95 +364,4 @@
 } WINED3DSHADER_PARAM_DSTMOD_TYPE;
 
-typedef enum _WINED3DSHADER_INSTRUCTION_OPCODE_TYPE
-{
-    WINED3DSIO_NOP = 0,
-    WINED3DSIO_MOV = 1,
-    WINED3DSIO_ADD = 2,
-    WINED3DSIO_SUB = 3,
-    WINED3DSIO_MAD = 4,
-    WINED3DSIO_MUL = 5,
-    WINED3DSIO_RCP = 6,
-    WINED3DSIO_RSQ = 7,
-    WINED3DSIO_DP3 = 8,
-    WINED3DSIO_DP4 = 9,
-    WINED3DSIO_MIN = 10,
-    WINED3DSIO_MAX = 11,
-    WINED3DSIO_SLT = 12,
-    WINED3DSIO_SGE = 13,
-    WINED3DSIO_EXP = 14,
-    WINED3DSIO_LOG = 15,
-    WINED3DSIO_LIT = 16,
-    WINED3DSIO_DST = 17,
-    WINED3DSIO_LRP = 18,
-    WINED3DSIO_FRC = 19,
-    WINED3DSIO_M4x4 = 20,
-    WINED3DSIO_M4x3 = 21,
-    WINED3DSIO_M3x4 = 22,
-    WINED3DSIO_M3x3 = 23,
-    WINED3DSIO_M3x2 = 24,
-    WINED3DSIO_CALL = 25,
-    WINED3DSIO_CALLNZ = 26,
-    WINED3DSIO_LOOP = 27,
-    WINED3DSIO_RET = 28,
-    WINED3DSIO_ENDLOOP = 29,
-    WINED3DSIO_LABEL = 30,
-    WINED3DSIO_DCL = 31,
-    WINED3DSIO_POW = 32,
-    WINED3DSIO_CRS = 33,
-    WINED3DSIO_SGN = 34,
-    WINED3DSIO_ABS = 35,
-    WINED3DSIO_NRM = 36,
-    WINED3DSIO_SINCOS = 37,
-    WINED3DSIO_REP = 38,
-    WINED3DSIO_ENDREP = 39,
-    WINED3DSIO_IF = 40,
-    WINED3DSIO_IFC = 41,
-    WINED3DSIO_ELSE = 42,
-    WINED3DSIO_ENDIF = 43,
-    WINED3DSIO_BREAK = 44,
-    WINED3DSIO_BREAKC = 45,
-    WINED3DSIO_MOVA = 46,
-    WINED3DSIO_DEFB = 47,
-    WINED3DSIO_DEFI = 48,
-
-    WINED3DSIO_TEXCOORD = 64,
-    WINED3DSIO_TEXKILL = 65,
-    WINED3DSIO_TEX = 66,
-    WINED3DSIO_TEXBEM = 67,
-    WINED3DSIO_TEXBEML = 68,
-    WINED3DSIO_TEXREG2AR = 69,
-    WINED3DSIO_TEXREG2GB = 70,
-    WINED3DSIO_TEXM3x2PAD = 71,
-    WINED3DSIO_TEXM3x2TEX = 72,
-    WINED3DSIO_TEXM3x3PAD = 73,
-    WINED3DSIO_TEXM3x3TEX = 74,
-    WINED3DSIO_TEXM3x3DIFF = 75,
-    WINED3DSIO_TEXM3x3SPEC = 76,
-    WINED3DSIO_TEXM3x3VSPEC = 77,
-    WINED3DSIO_EXPP = 78,
-    WINED3DSIO_LOGP = 79,
-    WINED3DSIO_CND = 80,
-    WINED3DSIO_DEF = 81,
-    WINED3DSIO_TEXREG2RGB = 82,
-    WINED3DSIO_TEXDP3TEX = 83,
-    WINED3DSIO_TEXM3x2DEPTH = 84,
-    WINED3DSIO_TEXDP3 = 85,
-    WINED3DSIO_TEXM3x3 = 86,
-    WINED3DSIO_TEXDEPTH = 87,
-    WINED3DSIO_CMP = 88,
-    WINED3DSIO_BEM = 89,
-    WINED3DSIO_DP2ADD = 90,
-    WINED3DSIO_DSX = 91,
-    WINED3DSIO_DSY = 92,
-    WINED3DSIO_TEXLDD = 93,
-    WINED3DSIO_SETP = 94,
-    WINED3DSIO_TEXLDL = 95,
-    WINED3DSIO_BREAKP = 96,
-
-    WINED3DSIO_PHASE = 0xfffd,
-    WINED3DSIO_COMMENT = 0xfffe,
-    WINED3DSIO_END = 0Xffff,
-} WINED3DSHADER_INSTRUCTION_OPCODE_TYPE;
-
 /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
 #define WINED3DSI_TEXLD_PROJECT 1
@@ -551,4 +427,5 @@
     WINED3DSIH_CND,
     WINED3DSIH_CRS,
+    WINED3DSIH_CUT,
     WINED3DSIH_DCL,
     WINED3DSIH_DEF,
@@ -562,4 +439,5 @@
     WINED3DSIH_DSY,
     WINED3DSIH_ELSE,
+    WINED3DSIH_EMIT,
     WINED3DSIH_ENDIF,
     WINED3DSIH_ENDLOOP,
@@ -568,6 +446,8 @@
     WINED3DSIH_EXPP,
     WINED3DSIH_FRC,
+    WINED3DSIH_IADD,
     WINED3DSIH_IF,
     WINED3DSIH_IFC,
+    WINED3DSIH_IGE,
     WINED3DSIH_LABEL,
     WINED3DSIH_LIT,
@@ -576,4 +456,5 @@
     WINED3DSIH_LOOP,
     WINED3DSIH_LRP,
+    WINED3DSIH_LT,
     WINED3DSIH_M3x2,
     WINED3DSIH_M3x3,
@@ -835,5 +716,6 @@
 
 struct vs_compile_args {
-    WORD                        fog_src;
+    BYTE                        fog_src;
+    BYTE                        clip_enabled;
     WORD                        swizzle_map;   /* MAX_ATTRIBS, 16 */
 };
@@ -885,8 +767,5 @@
 /* GL related defines */
 /* ------------------ */
-#define GL_SUPPORT(ExtName)           (GLINFO_LOCATION.supported[ExtName] != 0)
-#define GL_LIMITS(ExtName)            (GLINFO_LOCATION.max_##ExtName)
 #define GL_EXTCALL(FuncName)          (GLINFO_LOCATION.FuncName)
-#define GL_VEND(_VendName)            (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
 
 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
@@ -910,6 +789,4 @@
 /* --------------------- */
 #define MAX_MIP_LEVELS 32  /* Maximum number of mipmap levels. */
-#define MAX_STREAMS  16  /* Maximum possible streams - used for fixed size arrays
-                            See MaxStreams in MSDN under GetDeviceCaps */
 #define HIGHEST_TRANSFORMSTATE WINED3DTS_WORLDMATRIX(255) /* Highest value in WINED3DTRANSFORMSTATETYPE */
 
@@ -948,26 +825,9 @@
 } while (0)
 
-/* Macro to dump out the current state of the light chain */
-#define DUMP_LIGHT_CHAIN()                    \
-do {                                          \
-  PLIGHTINFOEL *el = This->stateBlock->lights;\
-  while (el) {                                \
-    TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
-    el = el->next;                            \
-  }                                           \
-} while(0)
-
 /* Trace vector and strided data information */
-#define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w)
 #define TRACE_STRIDED(si, name) do { if (si->use_map & (1 << name)) \
         TRACE( #name "=(data:%p, stride:%d, format:%#x, vbo %d, stream %u)\n", \
         si->elements[name].data, si->elements[name].stride, si->elements[name].format_desc->format, \
         si->elements[name].buffer_object, si->elements[name].stream_idx); } while(0)
-
-/* Defines used for optimizations */
-
-/*    Only reapply what is necessary */
-#define REAPPLY_ALPHAOP  0x0001
-#define REAPPLY_ALL      0xFFFF
 
 /* Advance declaration of structures to satisfy compiler */
@@ -976,4 +836,5 @@
 typedef struct IWineD3DPaletteImpl    IWineD3DPaletteImpl;
 typedef struct IWineD3DDeviceImpl     IWineD3DDeviceImpl;
+typedef struct IWineD3DSwapChainImpl  IWineD3DSwapChainImpl;
 
 /* Global variables */
@@ -1187,5 +1048,5 @@
     DWORD                   dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
     DWORD                   numDirtyEntries;
-    DWORD                   isStateDirty[STATE_HIGHEST/32 + 1]; /* Bitmap to find out quickly if a state is dirty */
+    DWORD isStateDirty[STATE_HIGHEST / (sizeof(DWORD) * CHAR_BIT) + 1]; /* Bitmap to find out quickly if a state is dirty */
 
     IWineD3DSurface         *surface;
@@ -1204,9 +1065,9 @@
     WORD last_was_ckey : 1;
     WORD fog_coord : 1;
-    WORD isPBuffer : 1;
     WORD fog_enabled : 1;
     WORD num_untracked_materials : 2;   /* Max value 2 */
     WORD current : 1;
     WORD destroyed : 1;
+    WORD valid : 1;
     BYTE texShaderBumpMap;              /* MAX_TEXTURES, 8 */
     BYTE lastWasPow2Texture;            /* MAX_TEXTURES, 8 */
@@ -1220,4 +1081,7 @@
 
     /* The actual opengl context */
+    UINT level;
+    HGLRC restore_ctx;
+    HDC restore_dc;
     HGLRC                   glCtx;
     HWND                    win_handle;
@@ -1229,4 +1093,5 @@
     UINT                    fbo_entry_count;
     struct list             fbo_list;
+    struct list             fbo_destroy_list;
     struct fbo_entry        *current_fbo;
     GLuint                  src_fbo;
@@ -1321,9 +1186,6 @@
 } ContextUsage;
 
-struct wined3d_context *ActivateContext(IWineD3DDeviceImpl *This,
+struct wined3d_context *context_acquire(IWineD3DDeviceImpl *This,
         IWineD3DSurface *target, enum ContextUsage usage) DECLSPEC_HIDDEN;
-struct wined3d_context *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win,
-        BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms) DECLSPEC_HIDDEN;
-void DestroyContext(IWineD3DDeviceImpl *This, struct wined3d_context *context) DECLSPEC_HIDDEN;
 void context_alloc_event_query(struct wined3d_context *context,
         struct wined3d_event_query *query) DECLSPEC_HIDDEN;
@@ -1337,9 +1199,14 @@
 void context_attach_surface_fbo(const struct wined3d_context *context,
         GLenum fbo_target, DWORD idx, IWineD3DSurface *surface) DECLSPEC_HIDDEN;
+struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win,
+        BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *present_parameters) DECLSPEC_HIDDEN;
+void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context) DECLSPEC_HIDDEN;
 void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
 void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
 struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN;
 DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN;
+void context_release(struct wined3d_context *context) DECLSPEC_HIDDEN;
 BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN;
+void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) DECLSPEC_HIDDEN;
 void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
 
@@ -1353,17 +1220,12 @@
 #define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
 
-/* Default callbacks for implicit object destruction */
-extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface) DECLSPEC_HIDDEN;
-
 /*****************************************************************************
  * Internal representation of a light
  */
-typedef struct PLIGHTINFOEL PLIGHTINFOEL;
-struct PLIGHTINFOEL {
+struct wined3d_light_info
+{
     WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
     DWORD        OriginalIndex;
     LONG         glIndex;
-    BOOL         changed;
-    BOOL         enabledChanged;
     BOOL         enabled;
 
@@ -1393,13 +1255,112 @@
 } WineD3D_PixelFormat;
 
+enum wined3d_pci_vendor
+{
+    VENDOR_WINE                     = 0x0000,
+    VENDOR_MESA                     = 0x0001,
+    VENDOR_ATI                      = 0x1002,
+    VENDOR_NVIDIA                   = 0x10de,
+    VENDOR_INTEL                    = 0x8086,
+};
+
+enum wined3d_pci_device
+{
+    CARD_WINE                       = 0x0000,
+
+    CARD_ATI_RAGE_128PRO            = 0x5246,
+    CARD_ATI_RADEON_7200            = 0x5144,
+    CARD_ATI_RADEON_8500            = 0x514c,
+    CARD_ATI_RADEON_9500            = 0x4144,
+    CARD_ATI_RADEON_XPRESS_200M     = 0x5955,
+    CARD_ATI_RADEON_X700            = 0x5e4c,
+    CARD_ATI_RADEON_X1600           = 0x71c2,
+    CARD_ATI_RADEON_HD2300          = 0x7210,
+    CARD_ATI_RADEON_HD2600          = 0x9581,
+    CARD_ATI_RADEON_HD2900          = 0x9400,
+    CARD_ATI_RADEON_HD3200          = 0x9620,
+    CARD_ATI_RADEON_HD4350          = 0x954f,
+    CARD_ATI_RADEON_HD4550          = 0x9540,
+    CARD_ATI_RADEON_HD4600          = 0x9495,
+    CARD_ATI_RADEON_HD4650          = 0x9498,
+    CARD_ATI_RADEON_HD4670          = 0x9490,
+    CARD_ATI_RADEON_HD4700          = 0x944e,
+    CARD_ATI_RADEON_HD4770          = 0x94b3,
+    CARD_ATI_RADEON_HD4800          = 0x944c, /* Picked one value between 9440, 944c, 9442, 9460 */
+    CARD_ATI_RADEON_HD4830          = 0x944c,
+    CARD_ATI_RADEON_HD4850          = 0x9442,
+    CARD_ATI_RADEON_HD4870          = 0x9440,
+    CARD_ATI_RADEON_HD4890          = 0x9460,
+    CARD_ATI_RADEON_HD5700          = 0x68BE, /* Picked HD5750 */
+    CARD_ATI_RADEON_HD5750          = 0x68BE,
+    CARD_ATI_RADEON_HD5770          = 0x68B8,
+    CARD_ATI_RADEON_HD5800          = 0x6898, /* Picked HD5850 */
+    CARD_ATI_RADEON_HD5850          = 0x6898,
+    CARD_ATI_RADEON_HD5870          = 0x6899,
+
+    CARD_NVIDIA_RIVA_128            = 0x0018,
+    CARD_NVIDIA_RIVA_TNT            = 0x0020,
+    CARD_NVIDIA_RIVA_TNT2           = 0x0028,
+    CARD_NVIDIA_GEFORCE             = 0x0100,
+    CARD_NVIDIA_GEFORCE2_MX         = 0x0110,
+    CARD_NVIDIA_GEFORCE2            = 0x0150,
+    CARD_NVIDIA_GEFORCE3            = 0x0200,
+    CARD_NVIDIA_GEFORCE4_MX         = 0x0170,
+    CARD_NVIDIA_GEFORCE4_TI4200     = 0x0253,
+    CARD_NVIDIA_GEFORCEFX_5200      = 0x0320,
+    CARD_NVIDIA_GEFORCEFX_5600      = 0x0312,
+    CARD_NVIDIA_GEFORCEFX_5800      = 0x0302,
+    CARD_NVIDIA_GEFORCE_6200        = 0x014f,
+    CARD_NVIDIA_GEFORCE_6600GT      = 0x0140,
+    CARD_NVIDIA_GEFORCE_6800        = 0x0041,
+    CARD_NVIDIA_GEFORCE_7400        = 0x01d8,
+    CARD_NVIDIA_GEFORCE_7300        = 0x01d7, /* GeForce Go 7300 */
+    CARD_NVIDIA_GEFORCE_7600        = 0x0391,
+    CARD_NVIDIA_GEFORCE_7800GT      = 0x0092,
+    CARD_NVIDIA_GEFORCE_8100        = 0x084F,
+    CARD_NVIDIA_GEFORCE_8200        = 0x0849, /* Other PCI ID 0x084B */
+    CARD_NVIDIA_GEFORCE_8300GS      = 0x0423,
+    CARD_NVIDIA_GEFORCE_8400GS      = 0x0404,
+    CARD_NVIDIA_GEFORCE_8500GT      = 0x0421,
+    CARD_NVIDIA_GEFORCE_8600GT      = 0x0402,
+    CARD_NVIDIA_GEFORCE_8600MGT     = 0x0407,
+    CARD_NVIDIA_GEFORCE_8800GTS     = 0x0193,
+    CARD_NVIDIA_GEFORCE_9200        = 0x086d,
+    CARD_NVIDIA_GEFORCE_9400GT      = 0x042c,
+    CARD_NVIDIA_GEFORCE_9500GT      = 0x0640,
+    CARD_NVIDIA_GEFORCE_9600GT      = 0x0622,
+    CARD_NVIDIA_GEFORCE_9800GT      = 0x0614,
+    CARD_NVIDIA_GEFORCE_GTX260      = 0x05e2,
+    CARD_NVIDIA_GEFORCE_GTX275      = 0x05e6,
+    CARD_NVIDIA_GEFORCE_GTX280      = 0x05e1,
+    CARD_NVIDIA_GEFORCE_GT240       = 0x0ca3,
+
+    CARD_INTEL_845G                 = 0x2562,
+    CARD_INTEL_I830G                = 0x3577,
+    CARD_INTEL_I855G                = 0x3582,
+    CARD_INTEL_I865G                = 0x2572,
+    CARD_INTEL_I915G                = 0x2582,
+    CARD_INTEL_I915GM               = 0x2592,
+    CARD_INTEL_I945GM               = 0x27a2, /* Same as GMA 950? */
+    CARD_INTEL_X3100                = 0x2a02, /* Found in Macs. Same as GMA 965? */
+};
+
+struct wined3d_driver_info
+{
+    enum wined3d_pci_vendor vendor;
+    enum wined3d_pci_device device;
+    const char *name;
+    const char *description;
+    DWORD version_high;
+    DWORD version_low;
+};
+
 /* The adapter structure */
-struct WineD3DAdapter
-{
-    UINT                    num;
+struct wined3d_adapter
+{
+    UINT ordinal;
     BOOL                    opengl;
     POINT                   monitorPoint;
     struct wined3d_gl_info  gl_info;
-    const char              *driver;
-    const char              *description;
+    struct wined3d_driver_info driver_info;
     WCHAR                   DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */
     int                     nCfgs;
@@ -1408,7 +1369,8 @@
     unsigned int            TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */
     unsigned int            UsedTextureRam;
-};
-
-extern BOOL initPixelFormats(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
+    LUID luid;
+};
+
+BOOL initPixelFormats(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor) DECLSPEC_HIDDEN;
 BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
 extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram) DECLSPEC_HIDDEN;
@@ -1505,9 +1467,11 @@
 
     UINT adapter_count;
-    struct WineD3DAdapter adapters[1];
+    struct wined3d_adapter adapters[1];
 } IWineD3DImpl;
 
 extern const IWineD3DVtbl IWineD3D_Vtbl DECLSPEC_HIDDEN;
 
+BOOL wined3d_register_window(HWND window, struct IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
+void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
 BOOL InitAdapters(IWineD3DImpl *This) DECLSPEC_HIDDEN;
 
@@ -1532,6 +1496,6 @@
     IUnknown               *parent;
     IWineD3DDeviceParent   *device_parent;
-    IWineD3D               *wineD3D;
-    struct WineD3DAdapter  *adapter;
+    IWineD3D *wined3d;
+    struct wined3d_adapter *adapter;
 
     /* Window styles to restore when switching fullscreen mode */
@@ -1572,5 +1536,6 @@
     WORD useDrawStridedSlow : 1;
     WORD instancedDraw : 1;
-    WORD padding : 4;
+    WORD filter_messages : 1;
+    WORD padding : 3;
 
     BYTE fixed_function_usage_map;      /* MAX_TEXTURES, 8 */
@@ -1586,6 +1551,6 @@
     /* Internal use fields  */
     WINED3DDEVICE_CREATION_PARAMETERS createParms;
-    UINT                            adapterNo;
     WINED3DDEVTYPE                  devType;
+    HWND focus_window;
 
     IWineD3DSwapChain     **swapchains;
@@ -1629,7 +1594,4 @@
     UINT                          dummyTextureName[MAX_TEXTURES];
 
-    /* Device state management */
-    HRESULT                 state;
-
     /* DirectDraw stuff */
     DWORD ddraw_width, ddraw_height;
@@ -1660,11 +1622,14 @@
 };
 
-extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl DECLSPEC_HIDDEN;
-
+HRESULT device_init(IWineD3DDeviceImpl *device, IWineD3DImpl *wined3d,
+        UINT adapter_idx, WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags,
+        IUnknown *parent, IWineD3DDeviceParent *device_parent) DECLSPEC_HIDDEN;
+LRESULT device_process_message(IWineD3DDeviceImpl *device, HWND window,
+        UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN;
 void device_resource_add(IWineD3DDeviceImpl *This, IWineD3DResource *resource) DECLSPEC_HIDDEN;
 void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resource) DECLSPEC_HIDDEN;
 void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
         BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup) DECLSPEC_HIDDEN;
-void device_stream_info_from_strided(IWineD3DDeviceImpl *This,
+void device_stream_info_from_strided(const struct wined3d_gl_info *gl_info,
         const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info) DECLSPEC_HIDDEN;
 HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, DWORD Count,
@@ -1672,8 +1637,9 @@
 void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This) DECLSPEC_HIDDEN;
 void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state) DECLSPEC_HIDDEN;
+
 static inline BOOL isStateDirty(struct wined3d_context *context, DWORD state)
 {
-    DWORD idx = state >> 5;
-    BYTE shift = state & 0x1f;
+    DWORD idx = state / (sizeof(*context->isStateDirty) * CHAR_BIT);
+    BYTE shift = state & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
     return context->isStateDirty[idx] & (1 << shift);
 }
@@ -1707,5 +1673,5 @@
     IUnknown               *parent;
     WINED3DRESOURCETYPE     resourceType;
-    IWineD3DDeviceImpl     *wineD3DDevice;
+    IWineD3DDeviceImpl *device;
     WINED3DPOOL             pool;
     UINT                    size;
@@ -1729,5 +1695,4 @@
 void resource_cleanup(IWineD3DResource *iface) DECLSPEC_HIDDEN;
 HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID guid) DECLSPEC_HIDDEN;
-HRESULT resource_get_device(IWineD3DResource *iface, IWineD3DDevice **device) DECLSPEC_HIDDEN;
 HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **parent) DECLSPEC_HIDDEN;
 DWORD resource_get_priority(IWineD3DResource *iface) DECLSPEC_HIDDEN;
@@ -1801,4 +1766,6 @@
 
 void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb) DECLSPEC_HIDDEN;
+BOOL surface_init_sysmem(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+BOOL surface_is_offscreen(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
 
 typedef struct IWineD3DBaseTextureImpl
@@ -1812,6 +1779,7 @@
 
 void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
-        const DWORD texture_states[WINED3D_HIGHEST_TEXTURE_STATE + 1],
-        const DWORD sampler_states[WINED3D_HIGHEST_SAMPLER_STATE + 1]) DECLSPEC_HIDDEN;
+        const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
+        const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
+        const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
 HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc) DECLSPEC_HIDDEN;
 void basetexture_cleanup(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
@@ -2048,5 +2016,4 @@
 ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent) DECLSPEC_HIDDEN;
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice) DECLSPEC_HIDDEN;
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface,
         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) DECLSPEC_HIDDEN;
@@ -2189,5 +2156,4 @@
  * IWineD3DVertexDeclaration implementation structure
  */
-#define MAX_ATTRIBS 16
 
 struct wined3d_vertex_declaration_element
@@ -2210,5 +2176,5 @@
     IUnknown                *parent;
     const struct wined3d_parent_ops *parent_ops;
-    IWineD3DDeviceImpl      *wineD3DDevice;
+    IWineD3DDeviceImpl *device;
 
     struct wined3d_vertex_declaration_element *elements;
@@ -2239,5 +2205,4 @@
     DWORD textureState[MAX_TEXTURES];           /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
     WORD samplerState[MAX_COMBINED_SAMPLERS];   /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
-    DWORD textures;                             /* MAX_COMBINED_SAMPLERS, 20 */
     DWORD clipplane;                            /* WINED3DMAXUSERCLIPPLANES, 32 */
     WORD pixelShaderConstantsB;                 /* MAX_CONST_B, 16 */
@@ -2247,13 +2212,14 @@
     WORD vertexShaderConstantsI;                /* MAX_CONST_I, 16 */
     BOOL *vertexShaderConstantsF;
-    WORD primitive_type : 1;
-    WORD indices : 1;
-    WORD material : 1;
-    WORD viewport : 1;
-    WORD vertexDecl : 1;
-    WORD pixelShader : 1;
-    WORD vertexShader : 1;
-    WORD scissorRect : 1;
-    WORD padding : 1;
+    DWORD textures : 20;                        /* MAX_COMBINED_SAMPLERS, 20 */
+    DWORD primitive_type : 1;
+    DWORD indices : 1;
+    DWORD material : 1;
+    DWORD viewport : 1;
+    DWORD vertexDecl : 1;
+    DWORD pixelShader : 1;
+    DWORD vertexShader : 1;
+    DWORD scissorRect : 1;
+    DWORD padding : 4;
 } SAVEDSTATES;
 
@@ -2270,6 +2236,5 @@
 
     /* IWineD3DStateBlock information */
-    IUnknown                 *parent;
-    IWineD3DDeviceImpl       *wineD3DDevice;
+    IWineD3DDeviceImpl *device;
     WINED3DSTATEBLOCKTYPE     blockType;
 
@@ -2310,6 +2275,6 @@
 #define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
-    struct list               lightMap[LIGHTMAP_SIZE]; /* Mashmap containing the lights */
-    PLIGHTINFOEL             *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
+    struct list               lightMap[LIGHTMAP_SIZE]; /* Hash map containing the lights */
+    const struct wined3d_light_info *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
 
     /* Clipping */
@@ -2369,8 +2334,7 @@
 };
 
-extern void stateblock_savedstates_set(IWineD3DStateBlock *iface, SAVEDSTATES *states, BOOL value) DECLSPEC_HIDDEN;
-extern void stateblock_copy(IWineD3DStateBlock *destination, IWineD3DStateBlock *source) DECLSPEC_HIDDEN;
-
-extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl DECLSPEC_HIDDEN;
+HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock,
+        IWineD3DDeviceImpl *device, WINED3DSTATEBLOCKTYPE type) DECLSPEC_HIDDEN;
+void stateblock_init_contained_states(IWineD3DStateBlockImpl *object) DECLSPEC_HIDDEN;
 
 /* Direct3D terminology with little modifications. We do not have an issued state
@@ -2392,10 +2356,5 @@
 
     IUnknown                 *parent;
-    /*TODO: replace with iface usage */
-#if 0
-    IWineD3DDevice         *wineD3DDevice;
-#else
-    IWineD3DDeviceImpl       *wineD3DDevice;
-#endif
+    IWineD3DDeviceImpl *device;
 
     /* IWineD3DQuery fields */
@@ -2422,9 +2381,15 @@
 };
 
+struct wined3d_map_range
+{
+    UINT offset;
+    UINT size;
+};
+
 #define WINED3D_BUFFER_OPTIMIZED    0x01    /* Optimize has been called for the buffer */
-#define WINED3D_BUFFER_DIRTY        0x02    /* Buffer data has been modified */
-#define WINED3D_BUFFER_HASDESC      0x04    /* A vertex description has been found */
-#define WINED3D_BUFFER_CREATEBO     0x08    /* Attempt to create a buffer object next PreLoad */
-#define WINED3D_BUFFER_DOUBLEBUFFER 0x10    /* Use a vbo and local allocated memory */
+#define WINED3D_BUFFER_HASDESC      0x02    /* A vertex description has been found */
+#define WINED3D_BUFFER_CREATEBO     0x04    /* Attempt to create a buffer object next PreLoad */
+#define WINED3D_BUFFER_DOUBLEBUFFER 0x08    /* Use a vbo and local allocated memory */
+#define WINED3D_BUFFER_FLUSH        0x10    /* Manual unmap flushing */
 
 struct wined3d_buffer
@@ -2442,10 +2407,10 @@
     DWORD flags;
 
-    UINT dirty_start;
-    UINT dirty_end;
     LONG lock_count;
+    struct wined3d_map_range *maps;
+    ULONG maps_size, modified_areas;
 
     /* conversion stuff */
-    UINT conversion_count;
+    UINT decl_change_count, full_conversion_count;
     UINT draw_count;
     UINT stride;                                            /* 0 if no conversion */
@@ -2478,5 +2443,5 @@
  */
 
-typedef struct IWineD3DSwapChainImpl
+struct IWineD3DSwapChainImpl
 {
     /*IUnknown part*/
@@ -2485,5 +2450,5 @@
 
     IUnknown                 *parent;
-    IWineD3DDeviceImpl       *wineD3DDevice;
+    IWineD3DDeviceImpl *device;
 
     /* IWineD3DSwapChain fields */
@@ -2494,4 +2459,5 @@
     WINED3DFORMAT             orig_fmt;
     WINED3DGAMMARAMP          orig_gamma;
+    BOOL                      render_to_fbo;
 
     long prev_time, frames;   /* Performance tracking */
@@ -2502,7 +2468,6 @@
 
     HWND                    win_handle;
-} IWineD3DSwapChainImpl;
-
-extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl DECLSPEC_HIDDEN;
+};
+
 const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl DECLSPEC_HIDDEN;
 void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc) DECLSPEC_HIDDEN;
@@ -2530,5 +2495,9 @@
         WINED3DGAMMARAMP *pRamp) DECLSPEC_HIDDEN;
 
-struct wined3d_context *IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
+struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
+HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface_type,
+        IWineD3DDeviceImpl *device, WINED3DPRESENT_PARAMETERS *present_parameters, IUnknown *parent) DECLSPEC_HIDDEN;
+void swapchain_restore_fullscreen_window(IWineD3DSwapChainImpl *swapchain) DECLSPEC_HIDDEN;
+void swapchain_setup_fullscreen_window(IWineD3DSwapChainImpl *swapchain, UINT w, UINT h) DECLSPEC_HIDDEN;
 
 #define DEFAULT_REFRESH_RATE 0
@@ -2569,5 +2538,5 @@
         DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords,
-        BOOL transformed, DWORD coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
+        BOOL transformed, WINED3DFORMAT coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
 void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock,
         struct wined3d_context *context) DECLSPEC_HIDDEN;
@@ -2588,5 +2557,5 @@
 
 void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect) DECLSPEC_HIDDEN;
-GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain) DECLSPEC_HIDDEN;
+GLenum surface_get_gl_buffer(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
 void surface_load_ds_location(IWineD3DSurface *iface, struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
 void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location) DECLSPEC_HIDDEN;
@@ -2605,4 +2574,12 @@
 UINT wined3d_log2i(UINT32 x) DECLSPEC_HIDDEN;
 unsigned int count_bits(unsigned int mask) DECLSPEC_HIDDEN;
+
+const struct blit_shader *select_blit_implementation(struct wined3d_adapter *adapter,
+        WINED3DDEVTYPE device_type) DECLSPEC_HIDDEN;
+const struct fragment_pipeline *select_fragment_implementation(struct wined3d_adapter *adapter,
+        WINED3DDEVTYPE device_type) DECLSPEC_HIDDEN;
+const shader_backend_t *select_shader_backend(struct wined3d_adapter *adapter,
+        WINED3DDEVTYPE device_type) DECLSPEC_HIDDEN;
+void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected) DECLSPEC_HIDDEN;
 
 typedef struct local_constant {
@@ -2677,4 +2654,7 @@
     shader_reg_maps reg_maps;
 
+    struct wined3d_shader_signature_element input_signature[max(MAX_ATTRIBS, MAX_REG_INPUT)];
+    struct wined3d_shader_signature_element output_signature[MAX_REG_OUTPUT];
+
     /* Pointer to the parent device */
     IWineD3DDevice *device;
@@ -2703,6 +2683,5 @@
         const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx) DECLSPEC_HIDDEN;
 HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
-        struct shader_reg_maps *reg_maps, struct wined3d_shader_attribute *attributes,
-        struct wined3d_shader_signature_element *input_signature,
+        struct shader_reg_maps *reg_maps, struct wined3d_shader_signature_element *input_signature,
         struct wined3d_shader_signature_element *output_signature,
         const DWORD *byte_code, DWORD constf_size) DECLSPEC_HIDDEN;
@@ -2712,4 +2691,5 @@
 const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token) DECLSPEC_HIDDEN;
 void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *pFunction) DECLSPEC_HIDDEN;
+WINED3DDECLUSAGE shader_usage_from_semantic_name(const char *semantic_name) DECLSPEC_HIDDEN;
 
 static inline BOOL shader_is_pshader_version(enum wined3d_shader_type type)
@@ -2785,7 +2765,6 @@
     IWineD3DBaseShaderClass     baseShader;
 
-    /* Vertex shader input and output semantics */
+    /* Vertex shader attributes. */
     struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
-    struct wined3d_shader_signature_element output_signature[MAX_REG_OUTPUT];
 
     UINT                       min_rel_offset, max_rel_offset;
@@ -2796,4 +2775,14 @@
         struct vs_compile_args *args) DECLSPEC_HIDDEN;
 HRESULT vertexshader_init(IWineD3DVertexShaderImpl *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+
+struct wined3d_geometryshader
+{
+    const struct IWineD3DGeometryShaderVtbl *vtbl;
+    IWineD3DBaseShaderClass base_shader;
+};
+
+HRESULT geometryshader_init(struct wined3d_geometryshader *shader, IWineD3DDeviceImpl *device,
         const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
         IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
@@ -2828,5 +2817,4 @@
 
     /* Pixel shader input semantics */
-    struct wined3d_shader_signature_element input_signature[MAX_REG_INPUT];
     DWORD                 input_reg_map[MAX_REG_INPUT];
     BOOL                  input_reg_used[MAX_REG_INPUT];
@@ -2865,5 +2853,5 @@
 
     IUnknown                   *parent;
-    IWineD3DDeviceImpl         *wineD3DDevice;
+    IWineD3DDeviceImpl *device;
 
     /* IWineD3DPalette */
@@ -2941,11 +2929,10 @@
     return (stateblock->vertexShader
             && !((IWineD3DVertexDeclarationImpl *)stateblock->vertexDecl)->position_transformed
-            && stateblock->wineD3DDevice->vs_selected_mode != SHADER_NONE);
+            && stateblock->device->vs_selected_mode != SHADER_NONE);
 }
 
 static inline BOOL use_ps(IWineD3DStateBlockImpl *stateblock)
 {
-    return (stateblock->pixelShader
-            && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE);
+    return (stateblock->pixelShader && stateblock->device->ps_selected_mode != SHADER_NONE);
 }
 
@@ -2957,3 +2944,7 @@
 #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
 
+#define WINEMAKEFOURCC(ch0, ch1, ch2, ch3) \
+        ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
+        ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
+
 #endif
