ReactOS  0.4.14-dev-614-gbfd8a84
d3d9_helpers.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_helpers.c
5  * PURPOSE: d3d9.dll helper functions
6  * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
7  */
8 
9 #include <d3d9.h>
10 #include "d3d9_helpers.h"
11 #include <stdio.h>
12 #include <ddraw.h>
13 #include <debug.h>
14 
15 #define MEM_ALIGNMENT 0x20
16 
17 static LPCSTR D3D9_DebugRegPath = "Software\\Microsoft\\Direct3D";
18 
20 {
21  HKEY hKey;
22  DWORD Type;
23  LONG Ret;
24 
26  return FALSE;
27 
28  Ret = RegQueryValueExA(hKey, ValueName, 0, &Type, DataBuffer, DataBufferSize);
29 
30  RegCloseKey(hKey);
31 
32  if (ERROR_SUCCESS != Ret)
33  return FALSE;
34 
35  if (Type != ValueType)
36  return FALSE;
37 
38  return TRUE;
39 }
40 
42 {
44  va_list vargs;
45 
46  if (BufferSize == 0)
47  return DDERR_INVALIDPARAMS;
48 
49  va_start(vargs, FormatString);
51  va_end(vargs);
52 
54  return DDERR_GENERIC;
55 
56  Buffer[BufferSize-1] = '\0';
57 
58  return ERROR_SUCCESS;
59 }
60 
62 {
64 
65  if (Dst == NULL || DstSize == 0 || Src == NULL)
66  return DDERR_INVALIDPARAMS;
67 
68  while (*Src != '\0' && DstSize > 0)
69  {
70  *Dst++ = *Src++;
71  --DstSize;
72  }
73 
74  if (DstSize == 0)
75  {
76  --Dst;
77  hr = DDERR_GENERIC;
78  }
79 
80  return hr;
81 }
82 
84 {
85  size_t CurrentDstLength;
86 
87  if (Dst == NULL || DstSize == 0)
88  return DDERR_INVALIDPARAMS;
89 
90  CurrentDstLength = strlen(Dst);
91 
92  return SafeCopyString(Dst + CurrentDstLength, DstSize - CurrentDstLength, Src);
93 }
94 
96 {
97  ULONG_PTR AddressOffset;
98  ULONG AlignedMask = MEM_ALIGNMENT - 1;
99  CHAR *AlignedPtr;
100  ULONG_PTR *AlignedOffsetPtr;
101 
102  if (ppObject == 0)
103  return DDERR_INVALIDPARAMS;
104 
105  if (dwSize == 0)
106  {
107  *ppObject = NULL;
108  return S_OK;
109  }
110 
112 
113  AlignedPtr = (CHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
114 
115  if (AlignedPtr == 0)
116  return DDERR_OUTOFMEMORY;
117 
118  AddressOffset = MEM_ALIGNMENT - ((ULONG_PTR)AlignedPtr & AlignedMask);
119 
120  AlignedPtr += AddressOffset;
121 
122  AlignedOffsetPtr = (ULONG_PTR *)(AlignedPtr - sizeof(ULONG));
123  *AlignedOffsetPtr = AddressOffset;
124 
125  *ppObject = (ULONG_PTR *)AlignedPtr;
126 
127  return S_OK;
128 }
129 
131 {
132  CHAR *NonAlignedPtr = pObject;
133  ULONG_PTR *AlignedPtr = pObject;
134 
135  if (pObject == 0)
136  return;
137 
138  NonAlignedPtr -= *(AlignedPtr - 1);
139 
140  HeapFree(GetProcessHeap(), 0, NonAlignedPtr);
141 }
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
VOID AlignedFree(IN OUT LPVOID pObject)
Definition: d3d9_helpers.c:130
#define IN
Definition: typedefs.h:38
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
#define MEM_ALIGNMENT
Definition: d3d9_helpers.c:15
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4016
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
Definition: fontview.c:49
char * LPSTR
Definition: xmlstorage.h:182
HRESULT SafeCopyString(OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
Definition: d3d9_helpers.c:61
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define va_end(ap)
Definition: acmsvcex.h:90
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
HRESULT AlignedAlloc(IN OUT LPVOID *ppObject, IN SIZE_T dwSize)
Definition: d3d9_helpers.c:95
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
const char * LPCSTR
Definition: xmlstorage.h:183
#define DDERR_GENERIC
Definition: ddraw.h:72
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
#define BufferSize
Definition: classpnp.h:419
static LPCSTR D3D9_DebugRegPath
Definition: d3d9_helpers.c:17
unsigned long DWORD
Definition: ntddk_ex.h:95
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
#define Dst
Definition: mesh.h:153
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define S_OK
Definition: intsafe.h:59
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
HRESULT SafeAppendString(IN OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
Definition: d3d9_helpers.c:83
#define _vsnprintf
Definition: xmlstorage.h:202
#define OUT
Definition: typedefs.h:39
uint32_t * LPDWORD
Definition: typedefs.h:57
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12