Author: gbrunmar Date: Wed Dec 19 23:44:43 2007 New Revision: 31335
URL: http://svn.reactos.org/svn/reactos?rev=31335&view=rev Log: * Renamed internal IDirect3D9 structure * Made Direct3D9Impl's IUnknown interface more robust thanks to hpoussin * Inited more values in internal struct
Modified: trunk/reactos/dll/directx/d3d9/d3d9_helpers.c trunk/reactos/dll/directx/d3d9/d3d9_helpers.h trunk/reactos/dll/directx/d3d9/d3d9_impl.c trunk/reactos/dll/directx/d3d9/d3d9_private.h
Modified: trunk/reactos/dll/directx/d3d9/d3d9_helpers.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_helpe... ============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_helpers.c (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_helpers.c Wed Dec 19 23:44:43 2007 @@ -14,6 +14,10 @@
static LPCSTR D3dDebugRegPath = "Software\Microsoft\Direct3D";
+LPDIRECT3D9_INT impl_from_IDirect3D9(LPDIRECT3D9 iface) +{ + return (LPDIRECT3D9_INT)((ULONG_PTR)iface - FIELD_OFFSET(DIRECT3D9_INT, lpVtbl)); +}
BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize) { @@ -58,12 +62,12 @@
HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9) { - LPDIRECTD3D9_INT pDirect3D9; + LPDIRECT3D9_INT pDirect3D9;
if (ppDirect3D9 == 0) return DDERR_INVALIDPARAMS;
- pDirect3D9 = HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTD3D9_INT)); + pDirect3D9 = HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECT3D9_INT));
if (0 == pDirect3D9) return DDERR_OUTOFMEMORY; @@ -75,7 +79,16 @@ pDirect3D9->dwProcessId = GetCurrentThreadId(); pDirect3D9->dwRefCnt = 1;
- *ppDirect3D9 = (IDirect3D9*)pDirect3D9; + pDirect3D9->unknown004576 = 0; + pDirect3D9->unknown004578 = 0; + pDirect3D9->unknown004579 = 0; + pDirect3D9->unknown004580 = 0; + pDirect3D9->unknown004581 = 0; + pDirect3D9->unknown004582 = 0; + pDirect3D9->unknown004583 = 0; + pDirect3D9->unknown004589 = 0; + + *ppDirect3D9 = (LPDIRECT3D9)&pDirect3D9->lpVtbl;
return ERROR_SUCCESS; }
Modified: trunk/reactos/dll/directx/d3d9/d3d9_helpers.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_helpe... ============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_helpers.h (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_helpers.h Wed Dec 19 23:44:43 2007 @@ -5,9 +5,13 @@ * PURPOSE: d3d9.dll helper functions * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se> */ +#ifndef _D3D9_HELPERS_H_ +#define _D3D9_HELPERS_H_
-#include <d3d9.h> -#include <windows.h> +#include "d3d9_private.h" + +/* Convert a IDirect3D9 pointer safely to the internal implementation struct */ +LPDIRECT3D9_INT impl_from_IDirect3D9(LPDIRECT3D9 iface);
/* 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); @@ -17,3 +21,5 @@
/* Creates a Direct3D9 object */ HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9); + +#endif // _D3D9_HELPERS_H_
Modified: trunk/reactos/dll/directx/d3d9/d3d9_impl.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_impl.... ============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_impl.c (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_impl.c Wed Dec 19 23:44:43 2007 @@ -5,20 +5,18 @@ * PURPOSE: IDirect3D9 implementation * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se> */ -#include "d3d9_private.h" +#include "d3d9_helpers.h"
#include <debug.h> - -static ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9 iface);
/* IDirect3D9: IUnknown implementation */ static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface, REFIID riid, LPVOID* ppvObject) { - LPDIRECTD3D9_INT This = (LPDIRECTD3D9_INT)iface; + LPDIRECT3D9_INT This = impl_from_IDirect3D9(iface);
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDirect3D9)) { - IDirect3D9Impl_AddRef(iface); + IUnknown_AddRef(iface); *ppvObject = &This->lpVtbl; return S_OK; } @@ -29,7 +27,7 @@
static ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9 iface) { - LPDIRECTD3D9_INT This = (LPDIRECTD3D9_INT)iface; + LPDIRECT3D9_INT This = impl_from_IDirect3D9(iface); ULONG ref = InterlockedIncrement(&This->dwRefCnt);
return ref; @@ -37,7 +35,7 @@
static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9 iface) { - LPDIRECTD3D9_INT This = (LPDIRECTD3D9_INT)iface; + LPDIRECT3D9_INT This = impl_from_IDirect3D9(iface); ULONG ref = InterlockedDecrement(&This->dwRefCnt);
if (ref == 0)
Modified: trunk/reactos/dll/directx/d3d9/d3d9_private.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_priva... ============================================================================== --- trunk/reactos/dll/directx/d3d9/d3d9_private.h (original) +++ trunk/reactos/dll/directx/d3d9/d3d9_private.h Wed Dec 19 23:44:43 2007 @@ -5,7 +5,10 @@ * PURPOSE: d3d9.dll helper functions * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se> */ +#ifndef _D3D9_PRIVATE_H_ +#define _D3D9_PRIVATE_H_
+#define COBJMACROS #include <windows.h> #include <d3d9.h>
@@ -15,7 +18,7 @@
extern const IDirect3D9Vtbl Direct3D9_Vtbl;
-typedef struct _tagDIRECTD3D9_INT_ +typedef struct _tagDIRECT3D9_INT_ { /* 0x0000 */ const IDirect3D9Vtbl *lpVtbl; /* LPDIRECTD3D9 functoions table */ /* 0x0004 */ CRITICAL_SECTION d3d9_cs; @@ -4596,4 +4599,6 @@ /* 0x47ac */ DWORD unknown004587; /* 0x47b0 */ DWORD unknown004588; /* 0x47b4 */ DWORD unknown004589; /*? 0x00000020 */ -} DIRECTD3D9_INT, *LPDIRECTD3D9_INT; +} DIRECT3D9_INT, *LPDIRECT3D9_INT; + +#endif // _D3D9_PRIVATE_H_