Index: trunk/src/ddraw/OS2D3D.CPP
===================================================================
--- trunk/src/ddraw/OS2D3D.CPP	(revision 4135)
+++ trunk/src/ddraw/OS2D3D.CPP	(revision 4136)
@@ -1,3 +1,3 @@
-/* $Id: OS2D3D.CPP,v 1.9 1999-12-21 01:28:15 hugh Exp $ */
+/* $Id: OS2D3D.CPP,v 1.10 2000-08-31 17:57:09 sandervl Exp $ */
 
 /*
@@ -5,4 +5,6 @@
  *
  * Copyright 1998 Sander van Leeuwen
+ *
+ * Note: MUST use DDraw3D_GetThisPtr macro to access DirectDraw object!
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -44,5 +46,5 @@
 ULONG __stdcall D3DAddRef(THIS This)
 {
- OS2IDirectDraw *me = (OS2IDirectDraw *)This;
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
 
   dprintf(("DDRAW: OS2IDirectDraw::AddRef %d\n", me->Referenced+1));
@@ -53,5 +55,5 @@
 ULONG __stdcall D3DRelease(THIS This)
 {
- OS2IDirectDraw *me = (OS2IDirectDraw *)This;
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
 
   dprintf(("DDRAW: OS2IDirectDraw::Release %d\n", me->Referenced-1));
@@ -75,4 +77,6 @@
 HRESULT __stdcall D3DInitialize(THIS This, REFIID)
 {
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
+
   dprintf(("DDRAW: D3DInitialize\n"));
   return(D3D_OK);
@@ -82,4 +86,6 @@
 HRESULT __stdcall D3DEnumDevices(THIS This, LPD3DENUMDEVICESCALLBACK, LPVOID)
 {
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
+
   dprintf(("DDRAW: D3DEnumDevices\n"));
   return(D3D_OK);
@@ -89,4 +95,6 @@
 HRESULT __stdcall D3DCreateLight(THIS This, LPDIRECT3DLIGHT*, IUnknown*)
 {
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
+
   dprintf(("DDRAW: D3DCreateLight\n"));
   return(D3D_OK);
@@ -96,4 +104,6 @@
 HRESULT __stdcall D3DCreateMaterial(THIS This, LPDIRECT3DMATERIAL*, IUnknown*)
 {
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
+
   dprintf(("DDRAW: D3DCreateMaterial\n"));
   return(D3D_OK);
@@ -103,4 +113,6 @@
 HRESULT __stdcall D3DCreateViewport(THIS This, LPDIRECT3DVIEWPORT*, IUnknown*)
 {
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
+
   dprintf(("DDRAW: D3DCreateViewport\n"));
   return(D3D_OK);
@@ -110,4 +122,6 @@
 HRESULT __stdcall D3DFindDevice(THIS This, LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT)
 {
+ OS2IDirectDraw *me = DDraw3D_GetThisPtr(This);
+
   dprintf(("DDRAW: D3DCreateFindDevice\n"));
   return(D3D_OK);
Index: trunk/src/ddraw/OS2DDRAW.CPP
===================================================================
--- trunk/src/ddraw/OS2DDRAW.CPP	(revision 4135)
+++ trunk/src/ddraw/OS2DDRAW.CPP	(revision 4136)
@@ -1,3 +1,3 @@
-/* $Id: OS2DDRAW.CPP,v 1.22 2000-08-31 12:48:41 sandervl Exp $ */
+/* $Id: OS2DDRAW.CPP,v 1.23 2000-08-31 17:57:09 sandervl Exp $ */
 
 /*
@@ -243,10 +243,9 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
+HRESULT WIN32API DrawQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
 {
  OS2IDirectDraw *me = (OS2IDirectDraw *)This;
-  #ifdef DEBUG
-    dprintf(("DDRAW: OS2IDirectDraw::QueryInterface\n"));
-  #endif
+
+  dprintf(("DDRAW: OS2IDirectDraw::QueryInterface %x %x %x", This, riid, ppvObj));
 
   *ppvObj = NULL;
@@ -256,49 +255,17 @@
      !IsEqualGUID(riid, IID_IDirectDraw2) &&
      !IsEqualGUID(riid, IID_IDirectDraw4) &&
-     !IsEqualGUID(riid, IID_IDirect3D) &&
-     !IsEqualGUID(riid, IID_IUnknown))
+     !IsEqualGUID(riid, IID_IDirect3D))
+//     !IsEqualGUID(riid, IID_IUnknown))
   return E_NOINTERFACE;
 
-#if 1
-  if(IsEqualGUID(riid, IID_IUnknown)) {
-     *ppvObj = (LPVOID) This;
-     me->lpVtbl2 = me->lpVtbl;
-  }
-  else
+  // ToDo Better way of returning differnent interfaces for same class
   if(IsEqualGUID(riid, IID_IDirect3D))
   {
-     me->lpVtbl2 = (IDirectDraw4Vtbl *)&me->Vtbl3D;
-     *ppvObj = (LPVOID) &me->lpVtbl2;
-  }
-  else
-  {
-    if(IsEqualGUID(riid, IID_IDirectDraw4))
-    {
-      dprintf(("DDRAW: IID_IDirectDraw4 Interface\n"));
-      me->lpVtbl2 = (IDirectDraw4Vtbl *)&me->Vtbl4;
-      *ppvObj = (LPVOID) &me->lpVtbl2;
-    }
-    else
-    {
-      if(IsEqualGUID(riid, IID_IDirectDraw2))
-      {
-        dprintf(("DDRAW: IID_IDirectDraw2 Interface\n"));
-        me->lpVtbl2 = (IDirectDraw4Vtbl *)&me->Vtbl2;
-        *ppvObj = (LPVOID) &me->lpVtbl2;
-      }
-      else
-      {
-        dprintf(("DDRAW: IID_IDirectDraw Interface\n"));
-        me->lpVtbl2 = (IDirectDraw4Vtbl *)&me->Vtbl;
-        *ppvObj = (LPVOID) &me->lpVtbl;
-      }
-    }
-  }
-  DrawAddRef(This);
-#else
-  // ToDo Better way of returning differnent intterfaces for same class
-  if(IsEqualGUID(riid, IID_IDirect3D))
-  {
-    me->lpVtbl = (IDirectDraw4Vtbl *) &me->Vtbl3D;
+    me->lpVtbl3D         = &me->Vtbl3D;
+    me->lpVtbl3D2        = me->lpVtbl3D;
+    me->pdwUnknownData3D = me->pdwUnknownData;
+    *ppvObj = (LPVOID)&me->lpVtbl3D;
+    DrawAddRef(This);
+    return DD_OK;
   }
   else
@@ -326,11 +293,10 @@
   *ppvObj = This;
   DrawAddRef(This);
-#endif
-
-  return(DD_OK);
-}
-//******************************************************************************
-//******************************************************************************
-ULONG __stdcall DrawAddRef(THIS This)
+
+  return(DD_OK);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG WIN32API DrawAddRef(THIS This)
 {
  OS2IDirectDraw *me = (OS2IDirectDraw *)This;
@@ -344,5 +310,5 @@
 //******************************************************************************
 //******************************************************************************
-ULONG __stdcall DrawRelease(THIS This)
+ULONG WIN32API DrawRelease(THIS This)
 {
  OS2IDirectDraw *me = (OS2IDirectDraw *)This;
@@ -373,5 +339,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawCompact(THIS)
+HRESULT WIN32API DrawCompact(THIS)
 {
   #ifdef DEBUG
@@ -383,5 +349,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawCreateClipper(THIS This, DWORD, LPDIRECTDRAWCLIPPER FAR *lplpDD, IUnknown FAR * )
+HRESULT WIN32API DrawCreateClipper(THIS This, DWORD, LPDIRECTDRAWCLIPPER FAR *lplpDD, IUnknown FAR * )
 {
  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
@@ -416,5 +382,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawCreatePalette(THIS This, DWORD dwFlags,
+HRESULT WIN32API DrawCreatePalette(THIS This, DWORD dwFlags,
             LPPALETTEENTRY lpColorTable,
             LPDIRECTDRAWPALETTE FAR *lplpDD,
@@ -476,5 +442,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawCreateSurface(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc,
+HRESULT WIN32API DrawCreateSurface(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc,
             LPDIRECTDRAWSURFACE FAR *lplpDD,
             IUnknown FAR *pUnkOuter)
@@ -522,5 +488,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawCreateSurface4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
+HRESULT WIN32API DrawCreateSurface4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
             LPDIRECTDRAWSURFACE4 FAR *lplpDD,
             IUnknown FAR *pUnkOuter)
@@ -569,5 +535,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * )
+HRESULT WIN32API DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * )
 {
   #ifdef DEBUG
@@ -578,5 +544,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4 FAR * )
+HRESULT WIN32API DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4 FAR * )
 {
   #ifdef DEBUG
@@ -588,5 +554,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawEnumDisplayModes( THIS This,
+HRESULT WIN32API DrawEnumDisplayModes( THIS This,
                                         DWORD dwFlags,
                                         LPDDSURFACEDESC lpDDSurfaceDesc,
@@ -882,5 +848,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawEnumDisplayModes4(THIS This, DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
+HRESULT WIN32API DrawEnumDisplayModes4(THIS This, DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
                                        LPVOID lpContext, LPDDENUMMODESCALLBACK2 lpDDEnumModesCallback2)
 {
@@ -897,5 +863,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK )
+HRESULT WIN32API DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK )
 {
   #ifdef DEBUG
@@ -907,5 +873,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 )
+HRESULT WIN32API DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 )
 {
   #ifdef DEBUG
@@ -917,5 +883,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawFlipToGDISurface(THIS)
+HRESULT WIN32API DrawFlipToGDISurface(THIS)
 {
   #ifdef DEBUG
@@ -927,5 +893,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetCaps(THIS This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps)
+HRESULT WIN32API DrawGetCaps(THIS This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps)
 {
  DWORD dwSize;
@@ -1191,5 +1157,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetDisplayMode(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc)
+HRESULT WIN32API DrawGetDisplayMode(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc)
 {
   OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
@@ -1306,5 +1272,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetDisplayMode4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2)
+HRESULT WIN32API DrawGetDisplayMode4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2)
 {
   OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
@@ -1421,5 +1387,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetFourCCCodes(THIS This, LPDWORD lpNumCodes, LPDWORD lpCodes)
+HRESULT WIN32API DrawGetFourCCCodes(THIS This, LPDWORD lpNumCodes, LPDWORD lpCodes)
 {
 //  DWORD dwFCC[MAX_FOURCC_CODES] = {FOURCC_LUT8,FOURCC_R565,FOURCC_RGB3,FOURCC_YUY2};
@@ -1448,5 +1414,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE FAR *)
+HRESULT WIN32API DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE FAR *)
 {
   #ifdef DEBUG
@@ -1458,5 +1424,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4 FAR *)
+HRESULT WIN32API DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4 FAR *)
 {
   #ifdef DEBUG
@@ -1468,5 +1434,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetMonitorFrequency(THIS This, LPDWORD lpdwFreq)
+HRESULT WIN32API DrawGetMonitorFrequency(THIS This, LPDWORD lpdwFreq)
 {
   ULONG ulTime1, ulTime2;
@@ -1507,5 +1473,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetScanLine(THIS, LPDWORD lpdwLine)
+HRESULT WIN32API DrawGetScanLine(THIS, LPDWORD lpdwLine)
 {
   BOOL bVertBlank;
@@ -1531,5 +1497,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetVerticalBlankStatus(THIS , LPBOOL lpbIsInVB)
+HRESULT WIN32API DrawGetVerticalBlankStatus(THIS , LPBOOL lpbIsInVB)
 {
   int rc;
@@ -1559,5 +1525,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawInitialize(THIS, GUID FAR *)
+HRESULT WIN32API DrawInitialize(THIS, GUID FAR *)
 {
   #ifdef DEBUG
@@ -1569,5 +1535,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawRestoreDisplayMode(THIS)
+HRESULT WIN32API DrawRestoreDisplayMode(THIS)
 {
   #ifdef DEBUG
@@ -1579,5 +1545,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawSetCooperativeLevel(THIS This, HWND hwndClient, DWORD dwFlags)
+HRESULT WIN32API DrawSetCooperativeLevel(THIS This, HWND hwndClient, DWORD dwFlags)
 {
  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
@@ -1602,5 +1568,5 @@
 //Backwards compatibility, what's that??
 //******************************************************************************
-HRESULT __stdcall DrawSetDisplayMode2(THIS This, DWORD dwWidth, DWORD dwHeight,
+HRESULT WIN32API DrawSetDisplayMode2(THIS This, DWORD dwWidth, DWORD dwHeight,
               DWORD dwBPP, DWORD dwRefreshRate,
               DWORD dwFlags)
@@ -1647,5 +1613,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawSetDisplayMode(THIS This, DWORD dwWidth, DWORD dwHeight,
+HRESULT WIN32API DrawSetDisplayMode(THIS This, DWORD dwWidth, DWORD dwHeight,
              DWORD dwBPP)
 {
@@ -1689,5 +1655,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawWaitForVerticalBlank(THIS, DWORD dwFlags, HANDLE hEvent)
+HRESULT WIN32API DrawWaitForVerticalBlank(THIS, DWORD dwFlags, HANDLE hEvent)
 {
   HRESULT rc;
@@ -1748,5 +1714,5 @@
 //*** Added in the v2 interface ***
 //******************************************************************************
-HRESULT __stdcall DrawGetAvailableVidMem(THIS, LPDDSCAPS lpDDSCaps,
+HRESULT WIN32API DrawGetAvailableVidMem(THIS, LPDDSCAPS lpDDSCaps,
                                          LPDWORD lpdwTotal, LPDWORD lpdwFree)
 {
@@ -1773,5 +1739,5 @@
 //
 //******************************************************************************
-HRESULT __stdcall DrawGetAvailableVidMem4(THIS, LPDDSCAPS2 lpDDSCaps2,
+HRESULT WIN32API DrawGetAvailableVidMem4(THIS, LPDDSCAPS2 lpDDSCaps2,
                                          LPDWORD lpdwTotal, LPDWORD lpdwFree)
 {
@@ -1798,5 +1764,5 @@
 //*** Added in the v4 interface ***
 //******************************************************************************
-HRESULT __stdcall DrawGetSurfaceFromDC(THIS, HDC hdc, LPDIRECTDRAWSURFACE4 *)
+HRESULT WIN32API DrawGetSurfaceFromDC(THIS, HDC hdc, LPDIRECTDRAWSURFACE4 *)
 {
   #ifdef DEBUG
@@ -1808,5 +1774,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawRestoreAllSurfaces(THIS)
+HRESULT WIN32API DrawRestoreAllSurfaces(THIS)
 {
   #ifdef DEBUG
@@ -1818,5 +1784,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawTestCooperativeLevel(THIS)
+HRESULT WIN32API DrawTestCooperativeLevel(THIS)
 {
   #ifdef DEBUG
@@ -1828,5 +1794,5 @@
 //******************************************************************************
 //******************************************************************************
-HRESULT __stdcall DrawGetDeviceIdentifier( THIS, LPDDDEVICEIDENTIFIER lpdddi,
+HRESULT WIN32API DrawGetDeviceIdentifier( THIS, LPDDDEVICEIDENTIFIER lpdddi,
                                            DWORD dwFlags)
 {
Index: trunk/src/ddraw/OS2DDRAW.H
===================================================================
--- trunk/src/ddraw/OS2DDRAW.H	(revision 4135)
+++ trunk/src/ddraw/OS2DDRAW.H	(revision 4136)
@@ -1,3 +1,3 @@
-/* $Id: OS2DDRAW.H,v 1.12 2000-08-31 12:48:41 sandervl Exp $ */
+/* $Id: OS2DDRAW.H,v 1.13 2000-08-31 17:57:10 sandervl Exp $ */
 
 /*
@@ -42,4 +42,9 @@
                                        // ToDO :
                                        // debug into DirectDrawCreate and se what MS is doing !
+    //Use for Direct3D interface (This != this)
+    IDirect3DVtbl    *lpVtbl3D;
+    IDirect3DVtbl    *lpVtbl3D2;
+    DWORD            *pdwUnknownData3D;
+
     IDirectDrawVtbl  Vtbl;
     IDirectDraw2Vtbl  Vtbl2;
@@ -141,4 +146,7 @@
 };
 
+#define OFFSET_D3DVTABLE	(LONG)(&((OS2IDirectDraw *)NULL)->lpVtbl3D)
+#define DDraw3D_GetThisPtr(a)   (OS2IDirectDraw *)((ULONG)a-OFFSET_D3DVTABLE)
+
 //******************************************************************************
 HRESULT __stdcall DrawQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj);
