* Check SDKVersion and print error message if debug flag is specified.
authorGregor Brunmar <gbrunmar.ros@gmail.com>
Mon, 17 Dec 2007 21:22:40 +0000 (21:22 +0000)
committerGregor Brunmar <gbrunmar.ros@gmail.com>
Mon, 17 Dec 2007 21:22:40 +0000 (21:22 +0000)
* New CreateD3D9 internal function to create a valid IDirect3D9 object.

svn path=/trunk/; revision=31295

reactos/dll/directx/d3d9/d3d9.c
reactos/dll/directx/d3d9/d3d9_helpers.c
reactos/dll/directx/d3d9/d3d9_helpers.h
reactos/dll/directx/d3d9/d3d9_private.h

index 9fbee83..58e93e5 100644 (file)
 
 #include <debug.h>
 
-DLLAPI
+#define DEBUG_MESSAGE_BUFFER_SIZE   512
+
+static LPCSTR D3dError_WrongSdkVersion =
+    "D3D ERROR: D3D header version mismatch.\n"
+    "The application was compiled against and will only work with "
+    "D3D_SDK_VERSION (%d), but the currently installed runtime is "
+    "version (%d).\n"
+    "Recompile the application against the appropriate SDK for the installed runtime.\n"
+    "\n";
+
 HRESULT Direct3DShaderValidatorCreate9(void)
 {
     UNIMPLEMENTED
     return 0;
 }
 
-DLLAPI
 HRESULT PSGPError(void)
 {
     UNIMPLEMENTED
     return 0;
 }
 
-DLLAPI
 HRESULT PSGPSampleTexture(void)
 {
     UNIMPLEMENTED
     return 0;
 }
 
-DLLAPI
-HRESULT  DebugSetLevel(void)
+HRESULT DebugSetLevel(void)
 {
     UNIMPLEMENTED
     return 0;
 }
 
-DLLAPI
 HRESULT DebugSetMute(DWORD dw1)
 {
     UNIMPLEMENTED
     return 0;
 }
 
-DLLAPI
 IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
 {
     HINSTANCE hDebugDll;
@@ -56,6 +60,7 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
     DWORD LoadDebugDllSize;
     LPDIRECT3D9 D3D9Obj = 0;
     LPDIRECT3DCREATE9 DebugDirect3DCreate9 = 0;
+    CHAR DebugMessageBuffer[DEBUG_MESSAGE_BUFFER_SIZE];
 
     UNIMPLEMENTED
 
@@ -70,11 +75,24 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
             {
                 DebugDirect3DCreate9 = (LPDIRECT3DCREATE9)GetProcAddress(hDebugDll, "Direct3DCreate9");
 
-                D3D9Obj = DebugDirect3DCreate9(SDKVersion);
+                return DebugDirect3DCreate9(SDKVersion);
             }
         }
     }
 
+    if ((SDKVersion & 0x7FFFFFFF) != D3D_SDK_VERSION || (SDKVersion & 0x7FFFFFFF) != D3D9b_SDK_VERSION)
+    {
+        if (SDKVersion & 0x80000000)
+        {
+            FormatDebugString(DebugMessageBuffer, DEBUG_MESSAGE_BUFFER_SIZE, D3dError_WrongSdkVersion, SDKVersion, D3D_SDK_VERSION);
+            OutputDebugStringA(DebugMessageBuffer);
+        }
+
+        return NULL;
+    }
+
+    CreateD3D9(&D3D9Obj);
+
     return D3D9Obj;
 }
 
index 2592598..146eb19 100644 (file)
@@ -7,10 +7,14 @@
  */
 
 #include "d3d9_helpers.h"
+#include <stdio.h>
+#include <ddraw.h>
 
+#include "d3d9_private.h"
 
 static LPCSTR D3dDebugRegPath = "Software\\Microsoft\\Direct3D";
 
+
 BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize)
 {
     HKEY hKey;
@@ -32,3 +36,46 @@ BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataB
 
     return TRUE;
 }
+
+HRESULT FormatDebugString(IN OUT LPSTR Buffer, IN LONG BufferSize, IN LPCSTR FormatString, ... )
+{
+    int BytesWritten;
+    va_list vargs;
+
+    if (BufferSize == 0)
+        return DDERR_INVALIDPARAMS;
+
+    va_start(vargs, FormatString);
+    BytesWritten = _vsnprintf(Buffer, BufferSize-1, FormatString, vargs);
+
+    if (BytesWritten < BufferSize)
+        return DDERR_GENERIC;
+
+    Buffer[BufferSize-1] = '\0';
+
+    return 0;
+}
+
+HRESULT CreateD3D9(IDirect3D9** ppDirect3D9)
+{
+    LPDIRECTD3D9_INT pDirect3D9;
+
+    if (ppDirect3D9 == 0)
+        return DDERR_INVALIDPARAMS;
+
+    pDirect3D9 = HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTD3D9_INT));
+
+    if (0 == pDirect3D9)
+        return DDERR_OUTOFMEMORY;
+
+    pDirect3D9->unknown000007 = 0;
+    pDirect3D9->lpInt = 0;
+
+    //pDirect3D9->lpVtbl = &IDirect3D3_Vtbl;
+    pDirect3D9->dwProcessId = GetCurrentThreadId();
+    pDirect3D9->dwIntRefCnt = 1;
+
+    *ppDirect3D9 = (IDirect3D9*)pDirect3D9;
+
+    return ERROR_SUCCESS;
+}
index f17e818..c2a038d 100644 (file)
@@ -6,6 +6,14 @@
  * PROGRAMERS:      Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
  */
 
+#include <d3d9.h>
 #include <windows.h>
 
+/* Reads a registry value if it's of the correct value type */
 BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize);
+
+/* Formats debug strings */
+HRESULT FormatDebugString(IN OUT LPSTR Buffer, IN LONG BufferSize, IN LPCSTR FormatString, ... );
+
+/* Creates a Direct3D9 object */
+HRESULT CreateD3D9(IDirect3D9** ppDirect3D9);
index af30eee..06b5c3e 100644 (file)
@@ -11,9 +11,9 @@
 
 #define DLLAPI __declspec(dllexport)
 
-typedef IDirect3D9* WINAPI (*LPDIRECT3DCREATE9)(UINT);
+typedef IDirect3D9* (WINAPI *LPDIRECT3DCREATE9)(UINT);
 
-struct _tagDIRECTD3D9_INT_
+typedef struct _tagDIRECTD3D9_INT_
 {
 /* 0x0000 */    LPVOID lpVtbl; /* LPDIRECTD3D9 functoions table */
 /* 0x0004 */    CRITICAL_SECTION d3d9_cs;
@@ -4594,4 +4594,4 @@ struct _tagDIRECTD3D9_INT_
 /* 0x47ac */    DWORD unknown004587; 
 /* 0x47b0 */    DWORD unknown004588; 
 /* 0x47b4 */    DWORD unknown004589;    /*? 0x00000020 */
-} *DIRECTD3D9_INT;
+} DIRECTD3D9_INT, *LPDIRECTD3D9_INT;