ReactOS  0.4.14-dev-115-g4576127
d3d9.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS ReactX
4  * FILE: dll/directx/d3d9/d3d9.c
5  * PURPOSE: d3d9.dll implementation
6  * PROGRAMERS: Magnus Olsen <greatlrd (at) reactos (dot) org>
7  * Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
8  */
9 
10 #include <d3d9.h>
11 #include "d3d9_helpers.h"
12 #include "d3d9_create.h"
13 #include <debug.h>
14 
15 #define DEBUG_MESSAGE_BUFFER_SIZE 512
16 
17 typedef IDirect3D9* (WINAPI *LPDIRECT3DCREATE9)(UINT);
18 
20  "D3D ERROR: D3D header version mismatch.\n"
21  "The application was compiled against and will only work with "
22  "D3D_SDK_VERSION (%d), but the currently installed runtime is "
23  "version (%d).\n"
24  "Recompile the application against the appropriate SDK for the installed runtime.\n"
25  "\n";
26 
28 {
30  return 0;
31 }
32 
34 {
36  return 0;
37 }
38 
40 {
42  return 0;
43 }
44 
46 {
48  return 0;
49 }
50 
52 {
54  return 0;
55 }
56 
57 IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
58 {
59  HINSTANCE hDebugDll;
60  DWORD LoadDebugDll;
61  DWORD LoadDebugDllSize;
62  LPDIRECT3D9 D3D9Obj = 0;
63  LPDIRECT3DCREATE9 DebugDirect3DCreate9 = 0;
64  CHAR DebugMessageBuffer[DEBUG_MESSAGE_BUFFER_SIZE];
65  UINT NoDebugSDKVersion = SDKVersion & ~DX_D3D9_DEBUG;
66 
67  LoadDebugDllSize = sizeof(LoadDebugDll);
68  if (ReadRegistryValue(REG_DWORD, "LoadDebugRuntime", (LPBYTE)&LoadDebugDll, &LoadDebugDllSize))
69  {
70  if (0 != LoadDebugDll)
71  {
72  hDebugDll = LoadLibraryA("d3d9d.dll");
73 
74  if (0 != hDebugDll)
75  {
76  DebugDirect3DCreate9 = (LPDIRECT3DCREATE9)GetProcAddress(hDebugDll, "Direct3DCreate9");
77 
78  return DebugDirect3DCreate9(SDKVersion);
79  }
80  }
81  }
82 
83  if (NoDebugSDKVersion != D3D_SDK_VERSION && NoDebugSDKVersion != D3D9b_SDK_VERSION)
84  {
85  if (SDKVersion & DX_D3D9_DEBUG)
86  {
87  HRESULT hResult;
88  hResult = SafeFormatString(DebugMessageBuffer, DEBUG_MESSAGE_BUFFER_SIZE, D3dError_WrongSdkVersion, NoDebugSDKVersion, D3D_SDK_VERSION);
89  if (SUCCEEDED(hResult))
90  OutputDebugStringA(DebugMessageBuffer);
91  }
92 
93  return NULL;
94  }
95 
96  CreateD3D9(&D3D9Obj, SDKVersion);
97 
98  return D3D9Obj;
99 }
100 
101 BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
102 {
103  switch (ul_reason_for_call)
104  {
105  case DLL_PROCESS_ATTACH:
106  case DLL_THREAD_ATTACH:
107  case DLL_THREAD_DETACH:
108  case DLL_PROCESS_DETACH:
109  break;
110  }
111 
112  return TRUE;
113 }
#define TRUE
Definition: types.h:120
IDirect3D9 *(WINAPI * LPDIRECT3DCREATE9)(UINT)
Definition: d3d9.c:17
#define DLL_THREAD_ATTACH
Definition: compat.h:121
#define DX_D3D9_DEBUG
Definition: d3d9_common.h:15
char CHAR
Definition: xmlstorage.h:175
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
struct IDirect3D9 * LPDIRECT3D9
Definition: d3d9.h:124
IDirect3D9 *WINAPI Direct3DCreate9(UINT SDKVersion)
Definition: d3d9.c:57
#define DLL_THREAD_DETACH
Definition: compat.h:122
HRESULT WINAPI PSGPSampleTexture(void)
Definition: d3d9.c:39
HRESULT WINAPI DebugSetLevel(void)
Definition: d3d9.c:45
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9, UINT SDKVersion)
Definition: d3d9_create.c:237
smooth NULL
Definition: ftsmooth.c:416
#define DEBUG_MESSAGE_BUFFER_SIZE
Definition: d3d9.c:15
const char * LPCSTR
Definition: xmlstorage.h:183
HRESULT WINAPI PSGPError(void)
Definition: d3d9.c:33
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
Definition: d3d9.c:101
#define DLL_PROCESS_DETACH
Definition: compat.h:119
#define D3D_SDK_VERSION
Definition: d3d8.h:56
LONG HRESULT
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT WINAPI DebugSetMute(DWORD dw1)
Definition: d3d9.c:51
BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize)
Definition: d3d9_helpers.c:19
HRESULT SafeFormatString(OUT LPSTR Buffer, IN DWORD BufferSize, IN LPCSTR FormatString,...)
Definition: d3d9_helpers.c:41
unsigned int UINT
Definition: ndis.h:50
HRESULT WINAPI Direct3DShaderValidatorCreate9(void)
Definition: d3d9.c:27
#define UNIMPLEMENTED
Definition: debug.h:114
#define GetProcAddress(x, y)
Definition: compat.h:410
static LPCSTR D3dError_WrongSdkVersion
Definition: d3d9.c:19
#define REG_DWORD
Definition: sdbapi.c:596
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18
#define APIENTRY
Definition: api.h:79
#define SUCCEEDED(hr)
Definition: intsafe.h:57
HMODULE hModule
Definition: animate.c:44