ReactOS 0.4.15-dev-8235-gcd88a97
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/
291 Display_d/hh/Display_d/d3d_21ac30ea-9803-401e-b541-6b08af79653d.xml.asp
292
293 for more info about this command see msdn documentation
294
295 The buffer start with D3DHAL_DP2COMMAND struct afer that follows either one struct or
296 no struct at at all
297 example for command D3DDP2OP_VIEWPORTINFO
298
299 then lpCmd will look like this
300 ----------------------------------------
301 | struct | Pos |
302 ----------------------------------------
303 | D3DHAL_DP2COMMAND | 0x00 - 0x03 |
304 ---------------------------------------
305 | D3DHAL_DP2VIEWPORTINFO | 0x04 - xxxx |
306 ---------------------------------------
307
308 to calculate the end of the lpCmd buffer in this example
309 D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO);
310 now you got number of bytes but we need to add the size of D3DHAL_DP2COMMAND
311 to get this right. the end should be
312 sizeof(D3DHAL_DP2COMMAND) + ( D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO));
313 to get the xxxx end positions.
314 */
315
316/*++
317* @name D3DParseUnknownCommand
318*
319* The D3DParseUnknownCommand routine <FILLMEIN>.
320*
321* @param lpCmd
322* Is a typecast to LPD3DHAL_DP2COMMAND struct
323* typedef struct _D3DHAL_DP2COMMAND
324* {
325* BYTE bCommand;
326* BYTE bReserved;
327* union
328* {
329* WORD wPrimitiveCount;
330* WORD wStateCount;
331* };
332* } D3DHAL_DP2COMMAND, *LPD3DHAL_DP2COMMAND;
333*
334* lpCmd->bCommand
335* only accept D3DDP2OP_VIEWPORTINFO, and undocumented command 0x0D
336* anything else will result in an error
337*
338 Command 0x0D
339* dp2command->bReserved
340* is the size of the struct we got in wStateCount or how many wStateCount we got
341* do not known more about it, no info in msdn about it either.
342*
343* Command D3DDP2OP_VIEWPORTINFO
344* <FILLMEIN>.
345*
346* @param lpRetCmd
347* <FILLMEIN>.
348*
349* @return <FILLMEIN>.
350*
351* @remarks
352
353*
354*--*/
355
358 LPVOID *lpRetCmd)
359{
360 DWORD retCode = DD_OK;
361 LPD3DHAL_DP2COMMAND dp2command = lpCmd;
362
364
365 /* prevent it crash if null pointer are being sent */
366 if ( (lpCmd == NULL) || (lpRetCmd == NULL) )
367 {
368 return E_FAIL;
369 }
370
371 *lpRetCmd = lpCmd;
372
373 switch (dp2command->bCommand)
374 {
375 /* check for valid command, only 3 commands are valid */
377 *(PBYTE)lpRetCmd += ((dp2command->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO)) + sizeof(D3DHAL_DP2COMMAND));
378 break;
379
380 case D3DDP2OP_WINFO:
381 *(PBYTE)lpRetCmd += (dp2command->wStateCount * sizeof(D3DHAL_DP2WINFO)) + sizeof(D3DHAL_DP2COMMAND);
382 break;
383
384 case 0x0d: /* Undocumented in MSDN */
385 *(PBYTE)lpRetCmd += ((dp2command->wStateCount * dp2command->bReserved) + sizeof(D3DHAL_DP2COMMAND));
386 break;
387
388
389 /* set the error code */
390 default:
391
392 if ( (dp2command->bCommand <= D3DDP2OP_INDEXEDTRIANGLELIST) || // dp2command->bCommand <= with 0 to 3
393 (dp2command->bCommand == D3DDP2OP_RENDERSTATE) || // dp2command->bCommand == with 8
394 (dp2command->bCommand >= D3DDP2OP_LINELIST) ) // dp2command->bCommand >= with 15 to 255
395 {
396 /* set error code for command 0 to 3, 8 and 15 to 255 */
397 retCode = DDERR_INVALIDPARAMS;
398 }
399 else
400 { /* set error code for 4 - 7, 9 - 12, 14 */
401 retCode = D3DERR_COMMAND_UNPARSED;
402 }
403
404 }
405
406 return retCode;
407}
408
409
410VOID
411WINAPI
413{
415
417}
418
419VOID
420WINAPI
422{
424
426}
427
428
430DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
431{
432
434
436
437
438 switch(ul_reason_for_call)
439 {
442 break;
443
449 break;
450
451 default:
452 break;
453 }
454
455 return TRUE;
456}
#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:412
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:421
HMODULE hDllModule
Definition: main.c:12
HRESULT WINAPI D3DParseUnknownCommand(LPVOID lpCmd, LPVOID *lpRetCmd)
Definition: main.c:357
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
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
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:85
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:66
#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:197
struct IDirectDrawClipper * LPDIRECTDRAWCLIPPER
Definition: ddraw.h:721
struct IDirectDraw * LPDIRECTDRAW
Definition: ddraw.h:710
#define DDENUMRET_CANCEL
Definition: ddraw.h:188
#define DDENUM_ATTACHEDSECONDARYDEVICES
Definition: ddraw.h:191
#define DD_OK
Definition: ddraw.h:186
#define DDERR_UNSUPPORTED
Definition: ddraw.h:127
#define DDERR_GENERIC
Definition: ddraw.h:72
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
#define DDENUM_DETACHEDSECONDARYDEVICES
Definition: ddraw.h:192
#define DDENUM_NONDISPLAYDEVICES
Definition: ddraw.h:193
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