Create a wined3d interface, and generate a wined3d object in the d3d9
create method. Make the first (simple) call implementation into the
new wined3d interface.

diff --git a/dlls/d3d9/Makefile.in b/dlls/d3d9/Makefile.in
index f0dd634..e15f203 100644
--- a/dlls/d3d9/Makefile.in
+++ b/dlls/d3d9/Makefile.in
@@ -3,7 +3,7 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = d3d9.dll
-IMPORTS   = user32 gdi32 kernel32
+IMPORTS   = wined3d user32 gdi32 kernel32
 EXTRAINCL = @X_CFLAGS@
 EXTRALIBS = -ldxguid -luuid @X_LIBS@ @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@ @OPENGL_LIBS@
 
diff --git a/dlls/d3d9/d3d9_main.c b/dlls/d3d9/d3d9_main.c
index a99160a..7edb9bd 100644
--- a/dlls/d3d9/d3d9_main.c
+++ b/dlls/d3d9/d3d9_main.c
@@ -21,23 +21,10 @@
  */
 
 #include "config.h"
-
-#include <stdarg.h>
-
-#define NONAMELESSUNION
-#define NONAMELESSSTRUCT
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "wine/debug.h"
-
-#include "d3d9.h"
 #include "d3d9_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
 
-
 void (*wine_tsx11_lock_ptr)(void) = NULL;
 void (*wine_tsx11_unlock_ptr)(void) = NULL;
 
@@ -56,8 +43,9 @@
 
     object->lpVtbl = &Direct3D9_Vtbl;
     object->ref = 1;
+    object->WineD3D = WineDirect3DCreate(SDKVersion, 9);
 
-    TRACE("SDKVersion = %x, Created Direct3D object at %p\n", SDKVersion, object);
+    TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
 
     return (IDirect3D9*) object;
 }
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index 0e3eb2a..57efb35 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -27,7 +27,16 @@
 #endif
 
 /* THIS FILE MUST NOT CONTAIN X11 or MESA DEFINES */
-/*
+#include <stdarg.h>
+
+#define NONAMELESSUNION
+#define NONAMELESSSTRUCT
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winuser.h"
+#include "wine/debug.h"
+
 #define XMD_H 
 #include <GL/gl.h>
 #include <GL/glx.h>
@@ -35,7 +44,6 @@
 # include <GL/glext.h>
 #endif
 #undef  XMD_H
-*/
 
 #undef APIENTRY
 #undef CALLBACK
@@ -46,6 +54,10 @@
 #define WINAPI      __stdcall
 #define APIENTRY    WINAPI
 
+#include "d3d9.h"
+#include "d3d9_private.h"
+#include "wine/wined3d_interface.h"
+
 /* X11 locking */
 
 extern void (*wine_tsx11_lock_ptr)(void);
@@ -180,6 +192,9 @@
     IDirect3D9Vtbl         *lpVtbl;
     DWORD                   ref;
 
+    /* The WineD3D device */
+    IWineD3D               *WineD3D;
+
     /* IDirect3D9 fields */
     /*
     GL_Info                 gl_info;
diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c
index d85cde4..9f9ed17 100644
--- a/dlls/d3d9/directx.c
+++ b/dlls/d3d9/directx.c
@@ -75,9 +75,7 @@
 
 UINT     WINAPI  IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface) {
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
-    /* FIXME: Set to one for now to imply the display */
-    TRACE("(%p): Mostly stub, only returns primary display\n", This);
-    return 1;
+    return IWineD3D_GetAdapterCount(This->WineD3D);
 }
 
 HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) {
diff --git a/dlls/wined3d/Makefile.in b/dlls/wined3d/Makefile.in
index e550960..524fb10 100644
--- a/dlls/wined3d/Makefile.in
+++ b/dlls/wined3d/Makefile.in
@@ -3,11 +3,12 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = wined3d.dll
-IMPORTS   = user32 gdi32 kernel32
+IMPORTS   = user32 gdi32 advapi32 kernel32
 EXTRAINCL = @X_CFLAGS@
 EXTRALIBS = -ldxguid -luuid @X_LIBS@ @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@ @OPENGL_LIBS@
 
 C_SRCS = \
+	directx.c \
 	vertexshader.c \
 	wined3d_main.c
 
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
new file mode 100644
index 0000000..5d44d57
--- /dev/null
+++ b/dlls/wined3d/directx.c
@@ -0,0 +1,59 @@
+/*
+ * IWineD3D implementation
+ *
+ * Copyright 2002-2004 Jason Edmeades
+ * Copyright 2003-2004 Raphael Junqueira
+ * Copyright 2004 Christian Costa
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+#include "wined3d_private.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(d3d);
+WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
+
+UINT     WINAPI  IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
+    IWineD3DImpl *This = (IWineD3DImpl *)iface;
+
+    /* FIXME: Set to one for now to imply the display */
+    TRACE_(d3d_caps)("(%p): Mostly stub, only returns primary display\n", This);
+    return 1;
+}
+
+
+/* IUnknown parts follow: */
+HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
+{
+    return E_NOINTERFACE;
+}
+
+ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
+    return 1;
+}
+
+ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
+    return 0;
+}
+
+/* VTbl definition */
+IWineD3DVtbl IWineD3D_Vtbl =
+{
+    IWineD3DImpl_QueryInterface,
+    IWineD3DImpl_AddRef,
+    IWineD3DImpl_Release,
+    IWineD3DImpl_GetAdapterCount
+};
diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c
index 7773b9b..c3be9cc 100644
--- a/dlls/wined3d/vertexshader.c
+++ b/dlls/wined3d/vertexshader.c
@@ -37,6 +37,7 @@
 # define TRACE_VSVECTOR(name)
 #endif
 
+#if 0 /* FIXME : Needs sorting when vshader code moved in properly */
 
 /**
  * DirectX9 SDK download
@@ -845,3 +846,5 @@
     FIXME("(%p) : stub\n", This);
     return D3D_OK;
 }
+
+#endif
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index 1d01fe0..b3b4fdf 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -1 +1 @@
-@ stdcall WineDirect3DCreate(long)
+@ stdcall WineDirect3DCreate(long long)
diff --git a/dlls/wined3d/wined3d_main.c b/dlls/wined3d/wined3d_main.c
index f98b168..d913192 100644
--- a/dlls/wined3d/wined3d_main.c
+++ b/dlls/wined3d/wined3d_main.c
@@ -3,6 +3,7 @@
  *
  * Copyright 2002-2003 The wine-d3d team
  * Copyright 2002-2003 Raphael Junqueira
+ * Copyright 2004      Jason Edmeades   
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,17 +26,69 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(wine_d3d);
 
-IDirect3DImpl* WINAPI WineDirect3DCreate(UINT SDKVersion) {
-  FIXME("SDKVersion = %x, TODO\n", SDKVersion);
-  return NULL;
+int num_lock = 0;
+void (*wine_tsx11_lock_ptr)(void) = NULL;
+void (*wine_tsx11_unlock_ptr)(void) = NULL;
+int vs_mode = VS_HW;   /* Hardware by default */
+int ps_mode = PS_NONE; /* Disabled by default */
+
+IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion) {
+    IWineD3DImpl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
+    object->lpVtbl = &IWineD3D_Vtbl;
+    object->dxVersion = dxVersion;
+
+    TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
+
+    return (IWineD3D *)object;
 }
 
 /* At process attach */
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
 {
-    TRACE("wined3d DLLMain Reason=%ld\n", fdwReason);
-    if (fdwReason == DLL_PROCESS_ATTACH) {
-      DisableThreadLibraryCalls(hInstDLL);  
+    TRACE("WineD3D DLLMain Reason=%ld\n", fdwReason);
+    if (fdwReason == DLL_PROCESS_ATTACH)
+    {
+       HMODULE mod;
+       char buffer[32];
+       DWORD size = sizeof(buffer);
+       HKEY hkey = 0;
+
+       DisableThreadLibraryCalls(hInstDLL);
+
+       mod = GetModuleHandleA( "x11drv.dll" );
+       if (mod)
+       {
+           wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
+           wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
+       }
+       if ( !RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Direct3D", &hkey) )
+       {
+           if ( !RegQueryValueExA( hkey, "VertexShaderMode", 0, NULL, buffer, &size) )
+           {
+               if (!strcmp(buffer,"none"))
+               {
+                   TRACE("Disable vertex shaders\n");
+                   vs_mode = VS_NONE;
+	       }
+	       else if (!strcmp(buffer,"emulation"))
+               {
+                   TRACE("Force SW vertex shaders\n");
+                   vs_mode = VS_SW;
+               }
+           }
+           if ( !RegQueryValueExA( hkey, "PixelShaderMode", 0, NULL, buffer, &size) )
+           {
+               if (!strcmp(buffer,"enabled"))
+               {
+                   TRACE("Allow pixel shaders\n");
+                   ps_mode = PS_HW;
+	       }
+           }
+       }
+       if (vs_mode == VS_HW)
+           TRACE("Allow HW vertex shaders\n");
+       if (ps_mode == PS_NONE)
+           TRACE("Disable pixel shaders\n");
     }
     return TRUE;
 }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 8d9f3f1..76dd519 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -3,6 +3,7 @@
  *
  * Copyright 2002-2003 The wine-d3d team
  * Copyright 2002-2003 Raphael Junqueira
+ * Copyright 2004      Jason Edmeades   
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -23,18 +24,46 @@
 #define __WINE_WINED3D_PRIVATE_H
 
 #include <stdarg.h>
-
+#define NONAMELESSUNION
+#define NONAMELESSSTRUCT
 #include "windef.h"
 #include "winbase.h"
+#include "winreg.h"
 #include "wingdi.h"
 #include "winuser.h"
 #include "wine/debug.h"
 
-#include "d3d8.h"
-#include "d3d8types.h"
+#include "d3d9.h"
+#include "d3d9types.h"
 #include "wine/wined3d_interface.h"
 
+extern int vs_mode;
+#define VS_NONE 0
+#define VS_HW   1
+#define VS_SW   2
 
+extern int ps_mode;
+#define PS_NONE 0
+#define PS_HW   1
+
+/*****************************************************************************
+ * IWineD3D implementation structure
+ */
+typedef struct IWineD3DImpl
+{
+    /* IUnknown fields */
+    IWineD3DVtbl           *lpVtbl;
+    DWORD                   ref;     /* Note: Ref counting not required */
+
+    /* WineD3D Information */
+    UINT                    dxVersion;
+} IWineD3DImpl;
+
+extern IWineD3DVtbl IWineD3D_Vtbl;
+
+
+
+#if 0 /* Needs fixing during rework */
 /*****************************************************************************
  * IDirect3DVertexShaderDeclaration implementation structure
  */
@@ -86,4 +115,5 @@
   PSHADEROUTPUTDATA output;
 };
 
+#endif /* Needs fixing during rework */
 #endif
diff --git a/include/wine/wined3d_interface.h b/include/wine/wined3d_interface.h
index 0f00a95..6d2e21f 100644
--- a/include/wine/wined3d_interface.h
+++ b/include/wine/wined3d_interface.h
@@ -35,6 +35,36 @@
  * PLEASE USE wine/wined3d_gl.h INSTEAD
  */
 
+
+/*****************************************************************************
+ * WineD3D interface 
+ */
+typedef struct IWineD3D IWineD3D;
+
+#define INTERFACE IWineD3D
+#define IWineD3D_METHODS \
+    IUnknown_METHODS \
+    STDMETHOD_(UINT,GetAdapterCount             )(THIS) PURE; \
+
+DECLARE_INTERFACE_(IWineD3D,IUnknown) { IWineD3D_METHODS };
+#undef INTERFACE
+
+#ifdef COBJMACROS
+/*** IUnknown methods ***/
+#define IWineD3D_QueryInterface(p,a,b)                    (p)->lpVtbl->QueryInterface(p,a,b)
+#define IWineD3D_AddRef(p)                                (p)->lpVtbl->AddRef(p)
+#define IWineD3D_Release(p)                               (p)->lpVtbl->Release(p)
+/*** IWineD3D methods ***/
+#define IWineD3D_GetAdapterCount(p)                       (p)->lpVtbl->GetAdapterCount(p)
+#endif
+
+/* Define the main WineD3D entrypoint */
+IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion);
+
+
+
+
+#if 0 /* FIXME: During porting in from d3d8 - the following will be used */
 /*****************************************************************
  * Some defines
  */
@@ -104,15 +134,7 @@
 extern DWORD   WINAPI IDirect3DVertexShaderImpl_GetVersion(IDirect3DVertexShaderImpl* This);
 extern HRESULT WINAPI IDirect3DVertexShaderImpl_ExecuteSW(IDirect3DVertexShaderImpl* This, VSHADERINPUTDATA* input, VSHADEROUTPUTDATA* output);
 
-#ifdef __cplusplus
-extern "C" {
-#endif  /* defined(__cplusplus) */
+#endif /* Temporary #if 0 */
 
-/* Define the main entrypoint as well */
-IDirect3DImpl* WINAPI WineDirect3DCreate(UINT SDKVersion);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif /* defined(__cplusplus) */
 
 #endif