source: trunk/src/ddraw/ddraw.CPP@ 4135

Last change on this file since 4135 was 4135, checked in by sandervl, 25 years ago

misc fixes for dxview + powerdvd

File size: 7.8 KB
Line 
1/* $Id: ddraw.CPP,v 1.13 2000-08-31 12:48:42 sandervl Exp $ */
2
3/*
4 * DXDraw DLL implementaion
5 *
6 * Copyright 1998 Sander va Leeuwen
7 * Copyright 1999 Markus Montkowski
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13#include <memory.h>
14#include <stdio.h>
15#include <builtin.h>
16#define INITGUID
17#define ICOM_CINTERFACE 1
18#define CINTERFACE
19
20#include "os2ddraw.h"
21#include "winerror.h"
22// define the following as we include winnt.h
23#define _OS2WIN_H
24#define FAR
25
26#include <misc.h>
27
28//******************************************************************************
29//******************************************************************************
30HRESULT WIN32API OS2DirectDrawCreate( GUID FAR *lpGUID,
31 LPDIRECTDRAW FAR *lplpDD,
32 IUnknown FAR *pUnkOuter)
33{
34 OS2IDirectDraw *newdraw;
35 HRESULT rc;
36
37 dprintf(("DDRAW: DirectDrawCreate %X %X %X\n", lpGUID, lplpDD, pUnkOuter));
38
39 newdraw = new OS2IDirectDraw(lpGUID);
40
41 if(newdraw == NULL)
42 {
43 rc = DDERR_NODIRECTDRAWHW;
44 }
45 else
46 {
47 newdraw->Vtbl.AddRef((IDirectDraw2 *)newdraw);
48 rc = newdraw->GetLastError();
49 if(rc != DD_OK)
50 {
51 *lplpDD = NULL;
52
53 delete newdraw;
54 }
55 else
56 *lplpDD = (LPDIRECTDRAW)newdraw;
57 }
58 return(rc);
59}
60//******************************************************************************
61//******************************************************************************
62HRESULT WIN32API DirectDrawCreateEx(LPGUID lpGUID, LPVOID* lplpDD, REFIID iid, LPUNKNOWN pUnkOuter)
63{
64 dprintf(("DirectDrawCreateEx: %x %x %x %x", lpGUID, lplpDD, iid, pUnkOuter));
65 /* I don't know about what functionality is unique to Ex */
66 return OS2DirectDrawCreate(lpGUID,(LPDIRECTDRAW*)lplpDD,pUnkOuter);
67}
68
69//******************************************************************************
70typedef BOOL (FAR PASCAL * LPDDENUMCALLBACKA)(GUID FAR *, LPSTR, LPSTR, LPVOID);
71//******************************************************************************
72HRESULT WIN32API OS2DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback,
73 LPVOID lpContext)
74{
75 dprintf(("DDRAW: DirectDrawEnumerateA\n Callback for DIVE\n"));
76 //call it twice for the DirectDraw & Direct3D classes
77 if(lpCallback(NULL, "DIVE DirectDraw for OS/2",
78 "DirectDraw/2 v0.2", lpContext) == DDENUMRET_CANCEL)
79 {
80 dprintf(("DDRAW: Cancel Callback\n"));
81 return(DD_OK);
82 }
83//SvL: Crashes dxview.exe; expects a different vtbl when creating
84// an IID_IDirect3D object
85#if 0
86 else //now for Direct3D
87 {
88 dprintf(("DDRAW: Callback for 3Dfx Voodoo"));
89 if(lpCallback((GUID *)&IID_IDirect3D, "3Dfx Voodoo Direct3D/2",
90 "Direct3D/2 v0.2", lpContext) == DDENUMRET_CANCEL)
91 {
92 dprintf(("DDRAW: Cancel Callback\n"));
93 return(DD_OK);
94 }
95 }
96#endif
97 dprintf(("DDRAW: Done Enumeration\n\n"));
98
99 return(DD_OK);
100}
101
102//******************************************************************************
103typedef struct
104{
105 LPDDENUMCALLBACKEXA lpCallbackEx;
106 LPVOID lpContext;
107} ENUMDATA, *PENUMDATA;
108
109BOOL FAR PASCAL SimpleEnum ( GUID FAR *lpGUID,
110 LPSTR lpDriverDescription,
111 LPSTR lpDriverName,
112 LPVOID lpContext)
113{
114 BOOL rc;
115 PENUMDATA pData;
116
117 dprintf(("DDRAW: SimpleEnum\n"));
118
119 pData = (PENUMDATA)lpContext;
120 rc = pData->lpCallbackEx( lpGUID,
121 lpDriverDescription,
122 lpDriverName,
123 pData->lpContext,
124 NULL);
125
126 dprintf(("DDRAW: Callback returned\n"));
127 return rc;
128}
129
130//******************************************************************************
131HRESULT WIN32API OS2DirectDrawEnumerateExA( LPDDENUMCALLBACKEXA lpCallbackEx,
132 LPVOID lpContext,
133 DWORD dwFlags)
134{
135 ENUMDATA data;
136
137 dprintf(("DDRAW: DirectDrawEnumerateExA\n"));
138
139 data.lpCallbackEx = lpCallbackEx;
140 data.lpContext = lpContext;
141
142 OS2DirectDrawEnumerateA( SimpleEnum,
143 &data);
144 return (DD_OK);
145}
146//******************************************************************************
147//******************************************************************************
148DWORD WIN32API DDHAL32_VidMemFree(DWORD address)
149{
150 dprintf(("DDRAW: DDHAL32_VidMemFree, not supported\n"));
151 return(0);
152}
153//******************************************************************************
154//******************************************************************************
155DWORD WIN32API DDHAL32_VidMemAlloc(DWORD size)
156{
157 dprintf(("DDRAW: DDHAL32_VidMemAlloc, not supported\n"));
158 return(0);
159}
160//******************************************************************************
161
162/*******************************************************************************
163 * DirectDraw ClassFactory
164 *
165 */
166
167typedef struct
168{
169 /* IUnknown fields */
170 ICOM_VTABLE(IClassFactory) *lpvtbl;
171 DWORD ref;
172} IClassFactoryImpl;
173
174static HRESULT WINAPI
175DDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
176{
177 ICOM_THIS(IClassFactoryImpl,iface);
178 char buf[80];
179
180 if (HIWORD(riid))
181 WINE_StringFromCLSID(riid,buf);
182 else
183 sprintf(buf,"<guid-0x%04x>",LOWORD(riid));
184 dprintf(("DDRAW:(%p)->(%s,%p),stub!\n",This,buf,ppobj));
185 return E_NOINTERFACE;
186}
187
188static ULONG WINAPI
189DDCF_AddRef(LPCLASSFACTORY iface)
190{
191 ICOM_THIS(IClassFactoryImpl,iface);
192 return ++(This->ref);
193}
194
195static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface)
196{
197 ICOM_THIS(IClassFactoryImpl,iface);
198 /* static class, won't be freed */
199 return --(This->ref);
200}
201
202static HRESULT WINAPI DDCF_CreateInstance( LPCLASSFACTORY iface,
203 LPUNKNOWN pOuter,
204 REFIID riid,
205 LPVOID *ppobj)
206{
207 ICOM_THIS(IClassFactoryImpl,iface);
208 LPGUID lpGUID;
209 lpGUID = (LPGUID) riid;
210
211 dprintf(("DDRAW:DDCF_CreateInstance\n"));
212 if( lpGUID &&
213 ( (*lpGUID == IID_IDirectDraw ) ||
214 (*lpGUID == IID_IDirectDraw2) ||
215 (*lpGUID == IID_IDirectDraw4))
216 )
217 {
218 /* FIXME: reuse already created DirectDraw if present? */
219 return OS2DirectDrawCreate(lpGUID,(LPDIRECTDRAW*)ppobj,pOuter);
220 }
221 return E_NOINTERFACE;
222}
223
224static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
225{
226 ICOM_THIS(IClassFactoryImpl,iface);
227 dprintf(("DDRAW:(%p)->(%d),stub!\n",This,dolock));
228 return S_OK;
229}
230
231static ICOM_VTABLE(IClassFactory) DDCF_Vtbl =
232{
233 DDCF_QueryInterface,
234 DDCF_AddRef,
235 DDCF_Release,
236 DDCF_CreateInstance,
237 DDCF_LockServer
238};
239
240static IClassFactoryImpl DDRAW_CF = {&DDCF_Vtbl, 1 };
241
242
243HRESULT WINAPI DllGetClassObject( REFCLSID rclsid,
244 REFIID riid,
245 LPVOID *ppv)
246{
247 char buf[80],xbuf[80];
248
249 if (HIWORD(rclsid))
250 WINE_StringFromCLSID(rclsid,xbuf);
251 else
252 sprintf(xbuf,"<guid-0x%04x>",LOWORD(rclsid));
253 if (HIWORD(riid))
254 WINE_StringFromCLSID(riid,buf);
255 else
256 sprintf(buf,"<guid-0x%04x>",LOWORD(riid));
257 WINE_StringFromCLSID(riid,xbuf);
258
259 dprintf(("DDRAW:(%p,%p,%p)\n", xbuf, buf, ppv));
260 if (!memcmp(riid,&IID_IClassFactory,sizeof(IID_IClassFactory)))
261 {
262 *ppv = (LPVOID)&DDRAW_CF;
263 DDRAW_CF.lpvtbl->AddRef((IClassFactory*)&DDRAW_CF);
264 return S_OK;
265 }
266 dprintf(("DDRAW: (%p,%p,%p): no interface found.\n", xbuf, buf, ppv));
267 return E_NOINTERFACE;
268}
269
270
271/*******************************************************************************
272 * DllCanUnloadNow [DDRAW.12] Determines whether the DLL is in use.
273 *
274 * RETURNS
275 * Success: S_OK
276 * Failure: S_FALSE
277 */
278HRESULT WINAPI DllCanUnloadNow(void)
279{
280 dprintf(("DllCanUnloadNow(void) stub\n"));
281 return S_FALSE;
282}//******************************************************************************
283
Note: See TracBrowser for help on using the repository browser.