b80ccc90bd7e453f0b300682c12b7aad1432b5fd
[reactos.git] / reactos / dll / directx / d3d9 / d3d9_helpers.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS ReactX
4 * FILE: dll/directx/d3d9/d3d9_helpers.c
5 * PURPOSE: d3d9.dll helper functions
6 * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
7 */
8
9 #include "d3d9_helpers.h"
10 #include <stdio.h>
11 #include <ddraw.h>
12
13 #include "d3d9_private.h"
14
15 static LPCSTR D3dDebugRegPath = "Software\\Microsoft\\Direct3D";
16
17
18 BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize)
19 {
20 HKEY hKey;
21 DWORD Type;
22 LONG Ret;
23
24 if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, D3dDebugRegPath, 0, KEY_QUERY_VALUE, &hKey))
25 return FALSE;
26
27 Ret = RegQueryValueEx(hKey, ValueName, 0, &Type, DataBuffer, DataBufferSize);
28
29 RegCloseKey(hKey);
30
31 if (ERROR_SUCCESS != Ret)
32 return FALSE;
33
34 if (Type != ValueType)
35 return FALSE;
36
37 return TRUE;
38 }
39
40 HRESULT FormatDebugString(IN OUT LPSTR Buffer, IN LONG BufferSize, IN LPCSTR FormatString, ... )
41 {
42 int BytesWritten;
43 va_list vargs;
44
45 if (BufferSize == 0)
46 return DDERR_INVALIDPARAMS;
47
48 va_start(vargs, FormatString);
49 BytesWritten = _vsnprintf(Buffer, BufferSize-1, FormatString, vargs);
50
51 if (BytesWritten < BufferSize)
52 return DDERR_GENERIC;
53
54 Buffer[BufferSize-1] = '\0';
55
56 return 0;
57 }
58
59 HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9)
60 {
61 LPDIRECTD3D9_INT pDirect3D9;
62
63 if (ppDirect3D9 == 0)
64 return DDERR_INVALIDPARAMS;
65
66 pDirect3D9 = HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTD3D9_INT));
67
68 if (0 == pDirect3D9)
69 return DDERR_OUTOFMEMORY;
70
71 pDirect3D9->unknown000007 = 0;
72 pDirect3D9->lpInt = 0;
73
74 pDirect3D9->lpVtbl = &Direct3D9_Vtbl;
75 pDirect3D9->dwProcessId = GetCurrentThreadId();
76 pDirect3D9->dwRefCnt = 1;
77
78 *ppDirect3D9 = (IDirect3D9*)pDirect3D9;
79
80 return ERROR_SUCCESS;
81 }