ReactOS 0.4.16-dev-117-g38f21f9
d3d9_helpers.h File Reference
#include "d3d9_common.h"
#include "d3d9_private.h"
Include dependency graph for d3d9_helpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOL ReadRegistryValue (IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize)
 
HRESULT SafeFormatString (IN OUT LPSTR Buffer, IN DWORD BufferSize, IN LPCSTR FormatString,...)
 
HRESULT SafeCopyString (OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
 
HRESULT SafeAppendString (IN OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
 
HRESULT AlignedAlloc (IN OUT LPVOID *ppObject, IN SIZE_T dwSize)
 
VOID AlignedFree (IN OUT LPVOID pObject)
 

Function Documentation

◆ AlignedAlloc()

HRESULT AlignedAlloc ( IN OUT LPVOID ppObject,
IN SIZE_T  dwSize 
)

Definition at line 95 of file d3d9_helpers.c.

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}
#define MEM_ALIGNMENT
Definition: d3d9_helpers.c:15
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define ULONG_PTR
Definition: config.h:101
#define S_OK
Definition: intsafe.h:52
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
char CHAR
Definition: xmlstorage.h:175

Referenced by CreateD3D9(), CreateD3D9Cursor(), CreateD3D9HalDevice(), CreateD3D9MipMap(), CreateDirect3DSwapChain9(), InitD3D9BaseDevice(), and InitD3D9ResourceManager().

◆ AlignedFree()

VOID AlignedFree ( IN OUT LPVOID  pObject)

Definition at line 130 of file d3d9_helpers.c.

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}
#define HeapFree(x, y, z)
Definition: compat.h:735
FxObject * pObject

Referenced by CreateD3D9(), CreateD3D9HalDevice(), D3D9BaseObject_Destroy(), IDirect3D9Impl_Release(), and IDirect3DDevice9Base_Release().

◆ ReadRegistryValue()

BOOL ReadRegistryValue ( IN DWORD  ValueType,
IN LPCSTR  ValueName,
OUT LPBYTE  DataBuffer,
IN OUT LPDWORD  DataBufferSize 
)

Definition at line 19 of file d3d9_helpers.c.

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}
Type
Definition: Type.h:7
#define RegCloseKey(hKey)
Definition: registry.h:49
static LPCSTR D3D9_DebugRegPath
Definition: d3d9_helpers.c:17
#define ERROR_SUCCESS
Definition: deptool.c:10
#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
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
long LONG
Definition: pedump.c:60
_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

Referenced by CreateInternalDeviceData(), Direct3DCreate9(), CRegistryFolder::FormatContentsForDisplay(), and GetD3D9DriverInfo().

◆ SafeAppendString()

HRESULT SafeAppendString ( IN OUT LPSTR  Dst,
IN DWORD  DstSize,
IN LPCSTR  Src 
)

Definition at line 83 of file d3d9_helpers.c.

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}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
HRESULT SafeCopyString(OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
Definition: d3d9_helpers.c:61
#define Dst
Definition: mesh.h:153

Referenced by GetDriverName().

◆ SafeCopyString()

HRESULT SafeCopyString ( OUT LPSTR  Dst,
IN DWORD  DstSize,
IN LPCSTR  Src 
)

Definition at line 61 of file d3d9_helpers.c.

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}
#define DDERR_GENERIC
Definition: ddraw.h:72
HRESULT hr
Definition: shlfolder.c:183

Referenced by CreateInternalDeviceData(), and SafeAppendString().

◆ SafeFormatString()

HRESULT SafeFormatString ( IN OUT LPSTR  Buffer,
IN DWORD  BufferSize,
IN LPCSTR  FormatString,
  ... 
)