From 1533c7c52800162864dfd2eba704b0bd237cf8f1 Mon Sep 17 00:00:00 2001 From: Gregor Brunmar Date: Mon, 17 Dec 2007 21:22:40 +0000 Subject: [PATCH] * Check SDKVersion and print error message if debug flag is specified. * New CreateD3D9 internal function to create a valid IDirect3D9 object. svn path=/trunk/; revision=31295 --- reactos/dll/directx/d3d9/d3d9.c | 34 +++++++++++++----- reactos/dll/directx/d3d9/d3d9_helpers.c | 47 +++++++++++++++++++++++++ reactos/dll/directx/d3d9/d3d9_helpers.h | 8 +++++ reactos/dll/directx/d3d9/d3d9_private.h | 6 ++-- 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/reactos/dll/directx/d3d9/d3d9.c b/reactos/dll/directx/d3d9/d3d9.c index 9fbee835621..58e93e59d39 100644 --- a/reactos/dll/directx/d3d9/d3d9.c +++ b/reactos/dll/directx/d3d9/d3d9.c @@ -13,42 +13,46 @@ #include -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; } diff --git a/reactos/dll/directx/d3d9/d3d9_helpers.c b/reactos/dll/directx/d3d9/d3d9_helpers.c index 25925984a93..146eb197f69 100644 --- a/reactos/dll/directx/d3d9/d3d9_helpers.c +++ b/reactos/dll/directx/d3d9/d3d9_helpers.c @@ -7,10 +7,14 @@ */ #include "d3d9_helpers.h" +#include +#include +#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; +} diff --git a/reactos/dll/directx/d3d9/d3d9_helpers.h b/reactos/dll/directx/d3d9/d3d9_helpers.h index f17e818ee3a..c2a038dded2 100644 --- a/reactos/dll/directx/d3d9/d3d9_helpers.h +++ b/reactos/dll/directx/d3d9/d3d9_helpers.h @@ -6,6 +6,14 @@ * PROGRAMERS: Gregor Brunmar */ +#include #include +/* 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); diff --git a/reactos/dll/directx/d3d9/d3d9_private.h b/reactos/dll/directx/d3d9/d3d9_private.h index af30eee55fc..06b5c3e724e 100644 --- a/reactos/dll/directx/d3d9/d3d9_private.h +++ b/reactos/dll/directx/d3d9/d3d9_private.h @@ -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;