ReactOS 0.4.16-dev-905-gc1b8c4f
main.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: dll/directx/ddraw/main.c
5 * PURPOSE: DirectDraw Library
6 * PROGRAMMER: Magnus Olsen (greatlrd)
7 *
8 */
9
10
11#include "rosdraw.h"
13
15
16// This function is exported by the dll
17
18typedef struct
19{
23
24BOOL
27 LPSTR lpDriverDescription,
28 LPSTR lpDriverName,
29 LPVOID lpContext,
30 HMONITOR hm)
31{
33 return ((LPDDENUMCALLBACKA) pEPD->lpCallback)(lpGUID, lpDriverDescription, lpDriverName, pEPD->lpContext);
34}
35
36/*++
37* @name DirectDrawCreateClipper
38*
39* The DirectDrawCreateClipper routine <FILLMEIN>.
40*
41* @param dwFlags
42* <FILLMEIN>.
43*
44* @param lplpDDClipper
45* <FILLMEIN>.
46*
47* @param pUnkOuter
48* <FILLMEIN>.
49*
50* @return <FILLMEIN>.
51*
52* @remarks None.
53*
54*--*/
56 LPDIRECTDRAWCLIPPER* lplpDDClipper, LPUNKNOWN pUnkOuter)
57{
59
60 return Main_DirectDraw_CreateClipper(NULL, dwFlags, lplpDDClipper, pUnkOuter);
61}
62
63/*++
64* @name DirectDrawCreate
65*
66* The DirectDrawCreate routine <FILLMEIN>.
67*
68* @param lpGUID
69* <FILLMEIN>.
70*
71* @param lplpDD
72* <FILLMEIN>.
73*
74* @param pUnkOuter
75* Always set to NULL otherwise DirectDrawCreate will fail and return
76* error code CLASS_E_NOAGGREGATION
77*
78* @return <FILLMEIN>.
79*
80* @remarks None.
81*
82*--*/
83
87 LPDIRECTDRAW* lplpDD,
88 LPUNKNOWN pUnkOuter)
89{
90 HRESULT retVal = DDERR_GENERIC;
91 /*
92 remove this when UML diagram is in place
93 this api is finished and is working as it should
94 */
95
98 {
99 /* check if pUnkOuter is null or not */
100 if (pUnkOuter)
101 {
102 retVal = CLASS_E_NOAGGREGATION;
103 }
104 else
105 {
106 retVal = Create_DirectDraw (lpGUID, (LPDIRECTDRAW*)lplpDD, &IID_IDirectDraw, FALSE);
107 }
108 }
110 {
111 }
112 _SEH2_END;
113
114 return retVal;
115}
116
117/*++
118* @name DirectDrawCreateEx
119*
120* The DirectDrawCreateEx routine <FILLMEIN>.
121*
122* @param lpGUID
123* <FILLMEIN>.
124*
125* @param lplpDD
126* <FILLMEIN>.
127*
128* @param pUnkOuter
129* Always set to NULL otherwise DirectDrawCreateEx will fail and return
130* error code CLASS_E_NOAGGREGATION
131*
132* @return <FILLMEIN>.
133*
134* @remarks None.
135*
136*--*/
138WINAPI
140 LPVOID* lplpDD,
141 REFIID id,
142 LPUNKNOWN pUnkOuter)
143{
144 HRESULT retVal = DDERR_GENERIC;
145 /*
146 remove this when UML diagram is in place
147 this api is finished and is working as it should
148 */
150
152 {
153 /* check see if pUnkOuter is null or not */
154 if (pUnkOuter)
155 {
156 /* we are using same error code as MS*/
157 retVal = CLASS_E_NOAGGREGATION;
158 }/* Is it a DirectDraw 7 Request or not */
159 else if (!IsEqualGUID(id, &IID_IDirectDraw7))
160 {
161 retVal = DDERR_INVALIDPARAMS;
162 }
163 else
164 {
165 retVal = Create_DirectDraw (lpGUID, (LPDIRECTDRAW*)lplpDD, id, FALSE);
166 }
167
168 /* Create our DirectDraw interface */
169 }
171 {
172 }
173 _SEH2_END;
174
175 return retVal;
176}
177
179WINAPI
180DirectDrawEnumerateA( LPDDENUMCALLBACKA lpCallback,
181 LPVOID lpContext)
182{
183 HRESULT retValue;
185
187
188 epd.lpCallback = (LPVOID) lpCallback;
189 epd.lpContext = lpContext;
190
191 if (!IsBadCodePtr((LPVOID)lpCallback))
192 {
193 return DirectDrawEnumerateExA((LPDDENUMCALLBACKEXA)TranslateCallbackA, &epd, DDENUM_NONDISPLAYDEVICES);
194 }
195 else
196 {
197 retValue = DDERR_INVALIDPARAMS;
198 }
199 return retValue;
200}
201
202/*
203 * UNIMPLEMENT
204 */
205
207WINAPI
208DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback,
209 LPVOID lpContext,
211{
212 HKEY hKey;
213 DWORD cbData = 0;
214 DWORD Value = 0;
215 LONG rc;
216 BOOL EnumerateAttachedSecondaries = FALSE;
217 DWORD privateDWFlags = 0;
218 CHAR strMsg[RC_STRING_MAX_SIZE];
220
222
223 if ((IsBadCodePtr((LPVOID)lpCallback) == 0) &&
227 {
229
231 if (rc == ERROR_SUCCESS)
232 {
233 /* Enumerate Attached Secondaries */
234 cbData = sizeof(DWORD);
235 rc = RegQueryValueExA(hKey, "EnumerateAttachedSecondaries", NULL, NULL, (LPBYTE)&Value, &cbData);
236 if (rc == ERROR_SUCCESS)
237 {
238 if (Value != 0)
239 {
240 EnumerateAttachedSecondaries = TRUE;
241 privateDWFlags = DDENUM_ATTACHEDSECONDARYDEVICES;
242 }
243 }
245 }
246
247 /* Call the user supplied callback function */
248 rc = lpCallback(NULL, strMsg, "display", lpContext, NULL);
249
250 /* If the callback function returns DDENUMRET_CANCEL, we will stop enumerating devices */
251 if(rc == DDENUMRET_CANCEL)
252 {
253 retVal = DD_OK;
254 }
255 else
256 {
257 // not finished
258 retVal = DDERR_UNSUPPORTED;
259 }
260 }
261
262 return retVal;
263}
264
266WINAPI
267DirectDrawEnumerateW(LPDDENUMCALLBACKW lpCallback,
268 LPVOID lpContext)
269{
271
272 return DDERR_UNSUPPORTED;
273}
274
276WINAPI
277DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW lpCallback,
278 LPVOID lpContext,
280{
282
283 return DDERR_UNSUPPORTED;
284}
285
286
287
288
289/*
290 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/Display_d/hh/Display_d/d3d_21ac30ea-9803-401e-b541-6b08af79653d.xml.asp (DEAD_LINK)
291
292 for more info about this command see msdn documentation
293
294 The buffer start with D3DHAL_DP2COMMAND struct afer that follows either one struct or
295 no struct at at all
296 example for command D3DDP2OP_VIEWPORTINFO
297
298 then lpCmd will look like this
299 ----------------------------------------
300 | struct | Pos |
301 ----------------------------------------
302 | D3DHAL_DP2COMMAND | 0x00 - 0x03 |
303 ---------------------------------------
304 | D3DHAL_DP2VIEWPORTINFO | 0x04 - xxxx |
305 ---------------------------------------
306
307 to calculate the end of the lpCmd buffer in this example
308 D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO);
309 now you got number of bytes but we need to add the size of D3DHAL_DP2COMMAND
310 to get this right. the end should be
311 sizeof(D3DHAL_DP2COMMAND) + ( D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO));
312 to get the xxxx end positions.
313 */
314
315/*++
316* @name D3DParseUnknownCommand
317*
318* The D3DParseUnknownCommand routine <FILLMEIN>.
319*
320* @param lpCmd
321* Is a typecast to LPD3DHAL_DP2COMMAND struct
322* typedef struct _D3DHAL_DP2COMMAND
323* {
324* BYTE bCommand;
325* BYTE bReserved;
326* union
327* {
328* WORD wPrimitiveCount;
329* WORD wStateCount;
330* };
331* } D3DHAL_DP2COMMAND, *LPD3DHAL_DP2COMMAND;
332*
333* lpCmd->bCommand
334* only accept D3DDP2OP_VIEWPORTINFO, and undocumented command 0x0D
335* anything else will result in an error
336*
337 Command 0x0D
338* dp2command->bReserved
339* is the size of the struct we got in wStateCount or how many wStateCount we got
340* do not known more about it, no info in msdn about it either.
341*
342* Command D3DDP2OP_VIEWPORTINFO
343* <FILLMEIN>.
344*
345* @param lpRetCmd
346* <FILLMEIN>.
347*
348* @return <FILLMEIN>.
349*
350* @remarks
351
352*
353*--*/
354
357 LPVOID *lpRetCmd)
358{
359 DWORD retCode = DD_OK;
360 LPD3DHAL_DP2COMMAND dp2command = lpCmd;
361
363
364 /* prevent it crash if null pointer are being sent */
365 if ( (lpCmd == NULL) || (lpRetCmd == NULL) )
366 {
367 return E_FAIL;
368 }
369
370 *lpRetCmd = lpCmd;
371
372 switch (dp2command->bCommand)
373 {
374 /* check for valid command, only 3 commands are valid */
376 *(PBYTE)lpRetCmd += ((dp2command->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO)) + sizeof(D3DHAL_DP2COMMAND));
377 break;
378
379 case D3DDP2OP_WINFO:
380 *(PBYTE)lpRetCmd += (dp2command->wStateCount * sizeof(D3DHAL_DP2WINFO)) + sizeof(D3DHAL_DP2COMMAND);
381 break;
382
383 case 0x0d: /* Undocumented in MSDN */
384 *(PBYTE)lpRetCmd += ((dp2command->wStateCount * dp2command->bReserved) + sizeof(D3DHAL_DP2COMMAND));
385 break;
386
387
388 /* set the error code */
389 default:
390
391 if ( (dp2command->bCommand <= D3DDP2OP_INDEXEDTRIANGLELIST) || // dp2command->bCommand <= with 0 to 3
392 (dp2command->bCommand == D3DDP2OP_RENDERSTATE) || // dp2command->bCommand == with 8
393 (dp2command->bCommand >= D3DDP2OP_LINELIST) ) // dp2command->bCommand >= with 15 to 255
394 {
395 /* set error code for command 0 to 3, 8 and 15 to 255 */
396 retCode = DDERR_INVALIDPARAMS;
397 }
398 else
399 { /* set error code for 4 - 7, 9 - 12, 14 */
400 retCode = D3DERR_COMMAND_UNPARSED;
401 }
402
403 }
404
405 return retCode;
406}
407
408
409VOID
410WINAPI
412{
414
416}
417
418VOID
419WINAPI
421{
423
425}
426
427
430{
431
433
435
436
437 switch(ul_reason_for_call)
438 {
441 break;
442
448 break;
449
450 default:
451 break;
452 }
453
454 return TRUE;
455}
static DWORD const LPVOID const lpReserved
#define RC_STRING_MAX_SIZE
Definition: resource.h:3
#define RegCloseKey(hKey)
Definition: registry.h:49
#define D3DERR_COMMAND_UNPARSED
Definition: d3dhal.h:49
struct _D3DHAL_DP2COMMAND D3DHAL_DP2COMMAND
@ D3DDP2OP_WINFO
Definition: d3dhal.h:350
@ D3DDP2OP_RENDERSTATE
Definition: d3dhal.h:335
@ D3DDP2OP_INDEXEDTRIANGLELIST
Definition: d3dhal.h:334
@ D3DDP2OP_LINELIST
Definition: d3dhal.h:336
@ D3DDP2OP_VIEWPORTINFO
Definition: d3dhal.h:349
#define E_FAIL
Definition: ddrawi.h:102
#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
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: main.c:26
HRESULT WINAPI Main_DirectDraw_CreateClipper(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwFlags, LPDIRECTDRAWCLIPPER *ppClipper, IUnknown *pUnkOuter)
Definition: ddraw_stubs.c:17
VOID WINAPI AcquireDDThreadLock()
Definition: main.c:411
HRESULT WINAPI DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW lpCallback, LPVOID lpContext, DWORD dwFlags)
Definition: main.c:277
HRESULT WINAPI DirectDrawEnumerateW(LPDDENUMCALLBACKW lpCallback, LPVOID lpContext)
Definition: main.c:267
BOOL CALLBACK TranslateCallbackA(GUID *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
Definition: main.c:26
HRESULT WINAPI DirectDrawCreateClipper(DWORD dwFlags, LPDIRECTDRAWCLIPPER *lplpDDClipper, LPUNKNOWN pUnkOuter)
Definition: main.c:55
HRESULT WINAPI DirectDrawCreateEx(LPGUID lpGUID, LPVOID *lplpDD, REFIID id, LPUNKNOWN pUnkOuter)
Definition: main.c:139
HRESULT WINAPI DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback, LPVOID lpContext)
Definition: main.c:180
VOID WINAPI ReleaseDDThreadLock()
Definition: main.c:420
HMODULE hDllModule
Definition: main.c:12
HRESULT WINAPI D3DParseUnknownCommand(LPVOID lpCmd, LPVOID *lpRetCmd)
Definition: main.c:356
CRITICAL_SECTION ddcs
Definition: main.c:14
HRESULT WINAPI DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags)
Definition: main.c:208
HRESULT WINAPI DirectDrawCreate(LPGUID lpGUID, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter)
Definition: main.c:86
#define STR_PRIMARY_DISPLAY
Definition: resource.h:5
#define APIENTRY
Definition: api.h:79
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3234
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
HMODULE hModule
Definition: animate.c:44
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define CALLBACK
Definition: compat.h:35
BOOL NTAPI IsBadCodePtr(FARPROC lpfn)
Definition: except.c:872
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
static LPUNKNOWN
Definition: ndr_ole.c:49
#define DWORD
Definition: nt_native.h:44
#define LPVOID
Definition: nt_native.h:45
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define DX_WINDBG_trace()
Definition: rosdraw.h:262
HRESULT WINAPI Create_DirectDraw(LPGUID pGUID, LPDIRECTDRAW *pIface, REFIID id, BOOL ex)
Definition: startup.c:20
#define REGSTR_PATH_DDHW
Definition: ddraw.h:199
struct IDirectDrawClipper * LPDIRECTDRAWCLIPPER
Definition: ddraw.h:723
struct IDirectDraw * LPDIRECTDRAW
Definition: ddraw.h:712
#define DDENUMRET_CANCEL
Definition: ddraw.h:190
#define DDENUM_ATTACHEDSECONDARYDEVICES
Definition: ddraw.h:193
#define DD_OK
Definition: ddraw.h:188
#define DDERR_UNSUPPORTED
Definition: ddraw.h:129
#define DDERR_GENERIC
Definition: ddraw.h:74
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:81
#define DDENUM_DETACHEDSECONDARYDEVICES
Definition: ddraw.h:194
#define DDENUM_NONDISPLAYDEVICES
Definition: ddraw.h:195
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
unsigned char * LPBYTE
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WINAPI
Definition: msvc.h:6
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPSTR lpBuffer, _In_ int cchBufferMax)
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175