ReactOS 0.4.16-dev-334-g4d9f67c
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
17static 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
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)
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)
67
68 while (*Src != '\0' && DstSize > 0)
69 {
70 *Dst++ = *Src++;
71 --DstSize;
72 }
73
74 if (DstSize == 0)
75 {
76 --Dst;
78 }
79
80 return hr;
81}
82
84{
85 size_t CurrentDstLength;
86
87 if (Dst == NULL || DstSize == 0)
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
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}
Type
Definition: Type.h:7
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
HRESULT SafeCopyString(OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
Definition: d3d9_helpers.c:61
BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize)
Definition: d3d9_helpers.c:19
VOID AlignedFree(IN OUT LPVOID pObject)
Definition: d3d9_helpers.c:130
HRESULT AlignedAlloc(IN OUT LPVOID *ppObject, IN SIZE_T dwSize)
Definition: d3d9_helpers.c:95
static LPCSTR D3D9_DebugRegPath
Definition: d3d9_helpers.c:17
HRESULT SafeAppendString(IN OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
Definition: d3d9_helpers.c:83
HRESULT SafeFormatString(OUT LPSTR Buffer, IN DWORD BufferSize, IN LPCSTR FormatString,...)
Definition: d3d9_helpers.c:41
#define MEM_ALIGNMENT
Definition: d3d9_helpers.c:15
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
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:4009
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
Definition: fontview.c:34
FxAutoRegKey hKey
FxObject * pObject
#define S_OK
Definition: intsafe.h:52
#define Dst
Definition: mesh.h:153
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
long LONG
Definition: pedump.c:60
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DDERR_GENERIC
Definition: ddraw.h:72
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
HRESULT hr
Definition: shlfolder.c:183
unsigned char * LPBYTE
Definition: typedefs.h:53
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t * LPDWORD
Definition: typedefs.h:59
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define _vsnprintf
Definition: xmlstorage.h:202
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175