* Renamed internal IDirect3D9 structure
authorGregor Brunmar <gbrunmar.ros@gmail.com>
Wed, 19 Dec 2007 20:44:43 +0000 (20:44 +0000)
committerGregor Brunmar <gbrunmar.ros@gmail.com>
Wed, 19 Dec 2007 20:44:43 +0000 (20:44 +0000)
* Made Direct3D9Impl's IUnknown interface more robust thanks to hpoussin
* Inited more values in internal struct

svn path=/trunk/; revision=31335

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

index b80ccc9..0643147 100644 (file)
 
 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 FormatDebugString(IN OUT LPSTR Buffer, IN LONG BufferSize, IN LPCSTR For
 
 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 @@ HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9)
     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;
 }
index 90ae464..fa8f098 100644 (file)
@@ -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 @@ HRESULT FormatDebugString(IN OUT LPSTR Buffer, IN LONG BufferSize, IN LPCSTR For
 
 /* Creates a Direct3D9 object */
 HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9);
+
+#endif // _D3D9_HELPERS_H_
index 90f713d..fa49a50 100644 (file)
@@ -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 HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface, REFIID ri
 
 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_AddRef(LPDIRECT3D9 iface)
 
 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)
index 316bef7..04fb706 100644 (file)
@@ -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 @@ typedef IDirect3D9* (WINAPI *LPDIRECT3DCREATE9)(UINT);
 
 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 @@ typedef struct _tagDIRECTD3D9_INT_
 /* 0x47ac */    DWORD unknown004587; 
 /* 0x47b0 */    DWORD unknown004588; 
 /* 0x47b4 */    DWORD unknown004589;    /*? 0x00000020 */
-} DIRECTD3D9_INT, *LPDIRECTD3D9_INT;
+} DIRECT3D9_INT, *LPDIRECT3D9_INT;
+
+#endif // _D3D9_PRIVATE_H_