source: trunk/src/ddraw/ddmain.cpp@ 21479

Last change on this file since 21479 was 21479, checked in by dmik, 15 years ago

Get rid of dd_obj_base.h which duplicates obj_base.h creating unnecessary mess (symbol/define duplication) and conflicts when both the DDarw and other COM-related headers are included.

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