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