xref: /reactos/dll/directx/d3d9/d3d9.c (revision 8a978a17)
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 
19 static LPCSTR D3dError_WrongSdkVersion =
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 
27 HRESULT WINAPI Direct3DShaderValidatorCreate9(void)
28 {
29     UNIMPLEMENTED
30     return 0;
31 }
32 
33 HRESULT WINAPI PSGPError(void)
34 {
35     UNIMPLEMENTED
36     return 0;
37 }
38 
39 HRESULT WINAPI PSGPSampleTexture(void)
40 {
41     UNIMPLEMENTED
42     return 0;
43 }
44 
45 HRESULT WINAPI DebugSetLevel(void)
46 {
47     UNIMPLEMENTED
48     return 0;
49 }
50 
51 HRESULT WINAPI DebugSetMute(DWORD dw1)
52 {
53     UNIMPLEMENTED
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 }
114