Sync to Wine-20050830:
Francois Gouget <fgouget@free.fr>
- Use LPSTORAGE to better match the PSDK.
  Document the real SEGPTR type using the standard documentation
  mechanisms. Fixes winapi_check warnings.
Robert Shearman <rob@codeweavers.com>
- Remove unused thread handle entry from the apartment structure.
- Implement IMarshal on proxies so that we don't end up with proxies
  to proxies, causing potential deadlock issues and performance
  problems.
- Add a test for this situation and remove the todo_wine from another
  test that now succeeds.
- Add stub for CoAllowSetForegroundWindow.
Vincent Beron <vberon@mecano.gme.usherb.ca>
- Remove local declarations already in included public headers.
- Correct mismatches between spec files and comments about export
  number.
Alexandre Julliard <julliard@winehq.org>
- Uncomment the typedef in the DECLARE_INTERFACE macro, and get rid of
  duplicate typedefs.
- Use the proper WOW functions everywhere instead of the K32WOW variant.
- Don't prefix the functions DllCanUnloadNow, DllGetClassObject and
  Dll(Un)RegisterServer with the dll name so that the compiler can check
  the prototypes.
- Remove duplicate definition of FILE_BEGIN.
- Replace the _ICOM_THIS_From macros by inline functions the way it's
  already done in shelllink.c.
Mike McCormack <mike@codeweavers.com>
- Warning fixes for gcc 4.0.
- Fix some gcc 4.0 warnings.
- return a precomputed result for a NULL string
- pass strlen an LPSTR to eliminate a sign warning
Marcus Meissner <marcus@jet.franken.de>
- Implemented ILockBytes16 (memorystream) support for the 16bit compound
  storage implementation.
- Added ReadClassStg, OleDoAutoConvert, GetConvertStg
  implementations/stubs.
Marcus Meissner <meissner@suse.de>
- Added CoCreateInstance16, CoGetClassObject16, OleLoad16 stubs.
Modified: trunk/reactos/lib/ole32/antimoniker.c
Modified: trunk/reactos/lib/ole32/compobj.c
Modified: trunk/reactos/lib/ole32/compobj.spec
Modified: trunk/reactos/lib/ole32/compobj_private.h
Modified: trunk/reactos/lib/ole32/compositemoniker.c
Modified: trunk/reactos/lib/ole32/datacache.c
Modified: trunk/reactos/lib/ole32/defaulthandler.c
Modified: trunk/reactos/lib/ole32/errorinfo.c
Modified: trunk/reactos/lib/ole32/filemoniker.c
Modified: trunk/reactos/lib/ole32/ftmarshal.c
Modified: trunk/reactos/lib/ole32/ifs.h
Modified: trunk/reactos/lib/ole32/itemmoniker.c
Modified: trunk/reactos/lib/ole32/marshal.c
Modified: trunk/reactos/lib/ole32/moniker.c
Modified: trunk/reactos/lib/ole32/moniker.h
Modified: trunk/reactos/lib/ole32/ole16.c
Modified: trunk/reactos/lib/ole32/ole2.c
Modified: trunk/reactos/lib/ole32/ole2.spec
Modified: trunk/reactos/lib/ole32/ole2_16.c
Modified: trunk/reactos/lib/ole32/ole32.spec
Modified: trunk/reactos/lib/ole32/oleproxy.c
Modified: trunk/reactos/lib/ole32/stg_prop.c
Modified: trunk/reactos/lib/ole32/storage.c
Modified: trunk/reactos/lib/ole32/storage.spec
Modified: trunk/reactos/lib/ole32/storage32.c

Modified: trunk/reactos/lib/ole32/antimoniker.c
--- trunk/reactos/lib/ole32/antimoniker.c	2005-09-05 21:47:21 UTC (rev 17677)
+++ trunk/reactos/lib/ole32/antimoniker.c	2005-09-05 21:56:14 UTC (rev 17678)
@@ -53,7 +53,12 @@
 
 } AntiMonikerImpl;
 
+static inline IMoniker *impl_from_IROTData( IROTData *iface )
+{
+    return (IMoniker *)((char*)iface - FIELD_OFFSET(AntiMonikerImpl, lpvtbl2));
+}
 
+
 /*******************************************************************************
  *        AntiMoniker_QueryInterface
  *******************************************************************************/
@@ -485,7 +490,7 @@
 static HRESULT WINAPI
 AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
 {
-    ICOM_THIS_From_IROTData(IMoniker, iface);
+    IMoniker *This = impl_from_IROTData(iface);
 
     TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
 
@@ -497,7 +502,7 @@
  */
 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
 {
-    ICOM_THIS_From_IROTData(IMoniker, iface);
+    IMoniker *This = impl_from_IROTData(iface);
 
     TRACE("(%p)\n",iface);
 
@@ -509,7 +514,7 @@
  */
 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
 {
-    ICOM_THIS_From_IROTData(IMoniker, iface);
+    IMoniker *This = impl_from_IROTData(iface);
 
     TRACE("(%p)\n",iface);
 

Modified: trunk/reactos/lib/ole32/compobj.c
--- trunk/reactos/lib/ole32/compobj.c	2005-09-05 21:47:21 UTC (rev 17677)
+++ trunk/reactos/lib/ole32/compobj.c	2005-09-05 21:56:14 UTC (rev 17678)
@@ -224,9 +224,6 @@
 
     apt = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*apt));
     apt->tid = GetCurrentThreadId();
-    DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
-                    GetCurrentProcess(), &apt->thread,
-                    THREAD_ALL_ACCESS, FALSE, 0);
 
     list_init(&apt->proxies);
     list_init(&apt->stubmgrs);
@@ -360,7 +357,6 @@
 
         DEBUG_CLEAR_CRITSEC_NAME(&apt->cs);
         DeleteCriticalSection(&apt->cs);
-        CloseHandle(apt->thread);
 
         HeapFree(GetProcessHeap(), 0, apt);
     }
@@ -813,27 +809,29 @@
  */
 HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id)
 {
-  const BYTE *s = (const BYTE *) idstr;
+  const BYTE *s;
   int	i;
   BYTE table[256];
 
-  if (!s)
-	  s = "{00000000-0000-0000-0000-000000000000}";
-  else {  /* validate the CLSID string */
+  if (!idstr) {
+    memset( id, 0, sizeof (CLSID) );
+    return S_OK;
+  }
 
-      if (strlen(s) != 38)
-          return CO_E_CLASSSTRING;
+  /* validate the CLSID string */
+  if (strlen(idstr) != 38)
+    return CO_E_CLASSSTRING;
 
-      if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
-          return CO_E_CLASSSTRING;
+  s = (const BYTE *) idstr;
+  if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
+    return CO_E_CLASSSTRING;
 
-      for (i=1; i<37; i++) {
-          if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
-          if (!(((s[i] >= '0') && (s[i] <= '9'))  ||
-                ((s[i] >= 'a') && (s[i] <= 'f'))  ||
-                ((s[i] >= 'A') && (s[i] <= 'F'))))
-              return CO_E_CLASSSTRING;
-      }
+  for (i=1; i<37; i++) {
+    if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
+    if (!(((s[i] >= '0') && (s[i] <= '9'))  ||
+          ((s[i] >= 'a') && (s[i] <= 'f'))  ||
+          ((s[i] >= 'A') && (s[i] <= 'F'))))
+       return CO_E_CLASSSTRING;
   }
 
   TRACE("%s -> %p\n", s, id);
@@ -1026,7 +1024,7 @@
 
   if (ret == S_OK)
   {
-    DWORD progidlen = 0;
+    LONG progidlen = 0;
 
     if (RegQueryValueW(hkey, NULL, NULL, &progidlen))
       ret = REGDB_E_CLASSNOTREG;
@@ -1064,7 +1062,7 @@
 HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid)
 {
 	char	*buf,buf2[80];
-	DWORD	buf2len;
+	LONG	buf2len;
 	HRESULT	err;
 	HKEY	xhkey;
 
@@ -1101,7 +1099,7 @@
 {
     static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 };
     WCHAR buf2[CHARS_IN_GUID];
-    DWORD buf2len = sizeof(buf2);
+    LONG buf2len = sizeof(buf2);
     HKEY xhkey;
 
     WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
@@ -1166,7 +1164,7 @@
     static const WCHAR wszPSC[] = {'\\','P','r','o','x','y','S','t','u','b','C','l','s','i','d','3','2',0};
     WCHAR path[ARRAYSIZE(wszInterface) - 1 + CHARS_IN_GUID - 1 + ARRAYSIZE(wszPSC)];
     WCHAR value[CHARS_IN_GUID];
-    DWORD len;
+    LONG len;
     HKEY hkey;
 
     TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
@@ -1562,7 +1560,6 @@
 }
 
 /***********************************************************************
- *           CoGetClassObject [COMPOBJ.7]
  *           CoGetClassObject [OLE32.@]
  *
  * FIXME.  If request allows of several options and there is a failure
@@ -1664,7 +1661,24 @@
 
     return hres;
 }
+
 /***********************************************************************
+ *           CoGetClassObject [COMPOBJ.7]
+ *
+ */
+HRESULT WINAPI CoGetClassObject16(
+    REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
+    REFIID iid, LPVOID *ppv)
+{
+    FIXME(", stub!\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
+
+    if (pServerInfo) {
+	FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
+	FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
+    }
+    return E_NOTIMPL;
+}
+/***********************************************************************
  *        CoResumeClassObjects (OLE32.@)
  *
  * Resumes all class objects registered with REGCLS_SUSPENDED.
@@ -1772,8 +1786,8 @@
 
     return MK_E_INVALIDEXTENSION;
 }
+
 /***********************************************************************
- *           CoCreateInstance [COMPOBJ.13]
  *           CoCreateInstance [OLE32.@]
  */
 HRESULT WINAPI CoCreateInstance(
@@ -1841,6 +1855,23 @@
 }
 
 /***********************************************************************
+ *           CoCreateInstance [COMPOBJ.13]
+ */
+HRESULT WINAPI CoCreateInstance16(
+	REFCLSID rclsid,
+	LPUNKNOWN pUnkOuter,
+	DWORD dwClsContext,
+	REFIID iid,
+	LPVOID *ppv)
+{
+  FIXME("(%s, %p, %lx, %s, %p), stub!\n", 
+	debugstr_guid(rclsid), pUnkOuter, dwClsContext, debugstr_guid(iid),
+	ppv
+  );
+  return E_NOTIMPL;
+}
+
+/***********************************************************************
  *           CoCreateInstanceEx [OLE32.@]
  */
 HRESULT WINAPI CoCreateInstanceEx(
@@ -2173,7 +2204,7 @@
     static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
     HKEY hkey = NULL;
     WCHAR buf[CHARS_IN_GUID];
-    DWORD len;
+    LONG len;
     HRESULT res = S_OK;
 
     if (ERROR_SUCCESS != COM_OpenKeyForCLSID(clsidOld, KEY_READ, &hkey))
@@ -2459,6 +2490,16 @@
 
     return TRUE;
 }
+
+/***********************************************************************
+ *           CoAllowSetForegroundWindow [OLE32.@]
+ *
+ */
+HRESULT WINAPI CoAllowSetForegroundWindow(IUnknown *pUnk, void *pvReserved)
+{
+    FIXME("(%p, %p): stub\n", pUnk, pvReserved);
+    return S_OK;
+}
  
 /***********************************************************************
  *           CoQueryProxyBlanket [OLE32.@]

Modified: trunk/reactos/lib/ole32/compobj.spec
--- trunk/reactos/lib/ole32/compobj.spec	2005-09-05 21:47:21 UTC (rev 17677)
+++ trunk/reactos/lib/ole32/compobj.spec	2005-09-05 21:56:14 UTC (rev 17678)
@@ -4,13 +4,13 @@
 4 pascal CoGetMalloc(long ptr) CoGetMalloc16
 5 pascal CoRegisterClassObject(ptr ptr long long ptr) CoRegisterClassObject16
 6 pascal CoRevokeClassObject(long) CoRevokeClassObject16
-7 pascal CoGetClassObject(ptr long ptr ptr ptr) CoGetClassObject
+7 pascal CoGetClassObject(ptr long ptr ptr ptr) CoGetClassObject16
 8 stub COMARSHALINTERFACE
 9 stub COUNMARSHALINTERFACE
 10 stub COLOADLIBRARY
 11 stub COFREELIBRARY
 12 stub COFREEALLLIBRARIES
-13 pascal CoCreateInstance(ptr ptr long ptr ptr) CoCreateInstance
+13 pascal CoCreateInstance(ptr ptr long ptr ptr) CoCreateInstance16
 14 stub STRINGFROMIID
 15 pascal CoDisconnectObject(ptr long) CoDisconnectObject
 16 stub CORELEASEMARSHALDATA

Modified: trunk/reactos/lib/ole32/compobj_private.h
--- trunk/reactos/lib/ole32/compobj_private.h	2005-09-05 21:47:21 UTC (rev 17677)
+++ trunk/reactos/lib/ole32/compobj_private.h	2005-09-05 21:56:14 UTC (rev 17678)
@@ -96,8 +96,8 @@
   struct list entry;       /* entry in proxy_manager list (CS parent->cs) */
   struct proxy_manager *parent; /* owning proxy_manager (RO) */
   LPVOID iface;            /* interface pointer (RO) */
+  STDOBJREF stdobjref;     /* marshal data that represents this object (RO) */
   IID iid;                 /* interface ID (RO) */
-  IPID ipid;               /* imported interface ID (RO) */
   LPRPCPROXYBUFFER proxy;  /* interface proxy (RO) */
   DWORD refs;              /* imported (public) references (MUTEX parent->remoting_mutex) */
   IRpcChannelBuffer *chan; /* channel to object (CS parent->cs) */
@@ -107,6 +107,7 @@
 struct proxy_manager
 {
   const IMultiQIVtbl *lpVtbl;
+  const IMarshalVtbl *lpVtblMarshal;
   struct apartment *parent; /* owning apartment (RO) */
   struct list entry;        /* entry in apartment (CS parent->cs) */
   OXID oxid;                /* object exported ID (RO) */
@@ -127,7 +128,6 @@
   LONG  refs;              /* refcount of the apartment (LOCK) */
   DWORD model;             /* threading model (RO) */
   DWORD tid;               /* thread id (RO) */
-  HANDLE thread;           /* thread handle (RO) */
   OXID oxid;               /* object exporter ID (RO) */
   LONG ipidc;              /* interface pointer ID counter, starts at 1 (LOCK) */
   HWND win;                /* message window (RO) */

Modified: trunk/reactos/lib/ole32/compositemoniker.c
--- trunk/reactos/lib/ole32/compositemoniker.c	2005-09-05 21:47:21 UTC (rev 17677)
+++ trunk/reactos/lib/ole32/compositemoniker.c	2005-09-05 21:56:14 UTC (rev 17678)
@@ -80,6 +80,10 @@
 
 } EnumMonikerImpl;
 
+static inline IMoniker *impl_from_IROTData( IROTData *iface )
+{
+    return (IMoniker *)((char*)iface - FIELD_OFFSET(CompositeMonikerImpl, lpvtbl2));
+}
 
 static HRESULT EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker,ULONG tabSize,ULONG currentPos,BOOL leftToRigth,IEnumMoniker ** ppmk);
 
@@ -1208,7 +1212,7 @@
                VOID** ppvObject)
 {
 
-    ICOM_THIS_From_IROTData(IMoniker, iface);
+    IMoniker *This = impl_from_IROTData(iface);
 
     TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
 
@@ -1221,7 +1225,7 @@
 static ULONG WINAPI
 CompositeMonikerROTDataImpl_AddRef(IROTData *iface)
 {
-    ICOM_THIS_From_IROTData(IMoniker, iface);
+    IMoniker *This = impl_from_IROTData(iface);
 
     TRACE("(%p)\n",iface);
 
@@ -1233,7 +1237,7 @@
  */
 static ULONG WINAPI CompositeMonikerROTDataImpl_Release(IROTData* iface)
 {
-    ICOM_THIS_From_IROTData(IMoniker, iface);
+    IMoniker *This = impl_from_IROTData(iface);
 
     TRACE("(%p)\n",iface);
 

Modified: trunk/reactos/lib/ole32/datacache.c
--- trunk/reactos/lib/ole32/datacache.c	2005-09-05 21:47:21 UTC (rev 17677)
+++ trunk/reactos/lib/ole32/datacache.c	2005-09-05 21:56:14 UTC (rev 17678)
@@ -93,12 +93,12 @@
   /*
    * List all interface VTables here
    */
-  const IDataObjectVtbl*      lpvtbl1;
-  const IUnknownVtbl*         lpvtbl2;
-  const IPersistStorageVtbl*  lpvtbl3;
-  const IViewObject2Vtbl*     lpvtbl4;
-  const IOleCache2Vtbl*       lpvtbl5;
-  const IOleCacheControlVtbl* lpvtbl6;
+  const IDataObjectVtbl*      lpVtbl;
+  const IUnknownVtbl*         lpvtblNDIUnknown;
+  const IPersistStorageVtbl*  lpvtblIPersistStorage;
+  const IViewObject2Vtbl*     lpvtblIViewObject;
+  const IOleCache2Vtbl*       lpvtblIOleCache2;
+  const IOleCacheControlVtbl* lpvtblIOleCacheControl;
 
   /*
    * Reference count of this object
@@ -136,13 +136,38 @@
  * There is a version to accommodate all of the VTables implemented
  * by this object.
  */
-#define _ICOM_THIS_From_IDataObject(class,name)       class* this = (class*)name
-#define _ICOM_THIS_From_NDIUnknown(class, name)       class* this = (class*)(((char*)name)-sizeof(void*))
-#define _ICOM_THIS_From_IPersistStorage(class, name)  class* this = (class*)(((char*)name)-2*sizeof(void*))
-#define _ICOM_THIS_From_IViewObject2(class, name)     class* this = (class*)(((char*)name)-3*sizeof(void*))
-#define _ICOM_THIS_From_IOleCache2(class, name)       class* this = (class*)(((char*)name)-4*sizeof(void*))
-#define _ICOM_THIS_From_IOleCacheControl(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*))
 
+static inline DataCache *impl_from_IDataObject( IDataObject *iface )
+{
+    return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpVtbl));
+}
+
+static inline DataCache *impl_from_NDIUnknown( IUnknown *iface )
+{
+    return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblNDIUnknown));
+}
+
+static inline DataCache *impl_from_IPersistStorage( IPersistStorage *iface )
+{
+    return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIPersistStorage));
+}
+
+static inline DataCache *impl_from_IViewObject2( IViewObject2 *iface )
+{
+    return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIViewObject));
+}
+
+static inline DataCache *impl_from_IOleCache2( IOleCache2 *iface )
+{
+    return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIOleCache2));
+}
+
+static inline DataCache *impl_from_IOleCacheControl( IOleCacheControl *iface )
+{
+    return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIOleCacheControl));
+}
+
+
 /*
  * Prototypes for the methods of the DataCache class.
  */
@@ -489,7 +514,7 @@
             REFIID         riid,
             void**         ppvObject)
 {
-  _ICOM_THIS_From_NDIUnknown(DataCache, iface);
+  DataCache *this = impl_from_NDIUnknown(iface);
 
   /*
    * Perform a sanity check on the parameters.
@@ -511,26 +536,26 @@
   }
   else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0)
   {
-    *ppvObject = (IDataObject*)&(this->lpvtbl1);
+    *ppvObject = (IDataObject*)&(this->lpVtbl);
   }
   else if ( (memcmp(&IID_IPersistStorage, riid, sizeof(IID_IPersistStorage)) == 0)  ||
 	    (memcmp(&IID_IPersist, riid, sizeof(IID_IPersist)) == 0) )
   {
-    *ppvObject = (IPersistStorage*)&(this->lpvtbl3);
+    *ppvObject = (IPersistStorage*)&(this->lpvtblIPersistStorage);
   }
   else if ( (memcmp(&IID_IViewObject, riid, sizeof(IID_IViewObject)) == 0) ||
 	    (memcmp(&IID_IViewObject2, riid, sizeof(IID_IViewObject2)) == 0) )
   {
-    *ppvObject = (IViewObject2*)&(this->lpvtbl4);
+    *ppvObject = (IViewObject2*)&(this->lpvtblIViewObject);
   }
   else if ( (memcmp(&IID_IOleCache, riid, sizeof(IID_IOleCache)) == 0) ||
 	    (memcmp(&IID_IOleCache2, riid, sizeof(IID_IOleCache2)) == 0) )
   {
-    *ppvObject = (IOleCache2*)&(this->lpvtbl5);
+    *ppvObject = (IOleCache2*)&(this->lpvtblIOleCache2);
   }
   else if (memcmp(&IID_IOleCacheControl, riid, sizeof(IID_IOleCacheControl)) == 0)
   {
-    *ppvObject = (IOleCacheControl*)&(this->lpvtbl6);
+    *ppvObject = (IOleCacheControl*)&(this->lpvtblIOleCacheControl);
   }
 
   /*
@@ -562,7 +587,7 @@
 static ULONG WINAPI DataCache_NDIUnknown_AddRef(
             IUnknown*      iface)
 {
-  _ICOM_THIS_From_NDIUnknown(DataCache, iface);
+  DataCache *this = impl_from_NDIUnknown(iface);
   return InterlockedIncrement(&this->ref);
 }
 
@@ -577,7 +602,7 @@
 static ULONG WINAPI DataCache_NDIUnknown_Release(
             IUnknown*      iface)
 {
-  _ICOM_THIS_From_NDIUnknown(DataCache, iface);
+  DataCache *this = impl_from_NDIUnknown(iface);
   ULONG ref;
 
   /*
@@ -608,7 +633,7 @@
             REFIID           riid,
             void**           ppvObject)
 {
-  _ICOM_THIS_From_IDataObject(DataCache, iface);
+  DataCache *this = impl_from_IDataObject(iface);
 
   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
 }
@@ -621,7 +646,7 @@
 static ULONG WINAPI DataCache_IDataObject_AddRef(
             IDataObject*     iface)
 {
-  _ICOM_THIS_From_IDataObject(DataCache, iface);
+  DataCache *this = impl_from_IDataObject(iface);
 
   return IUnknown_AddRef(this->outerUnknown);
 }
@@ -634,7 +659,7 @@
 static ULONG WINAPI DataCache_IDataObject_Release(
             IDataObject*     iface)
 {
-  _ICOM_THIS_From_IDataObject(DataCache, iface);
+  DataCache *this = impl_from_IDataObject(iface);
 
   return IUnknown_Release(this->outerUnknown);
 }
@@ -886,7 +911,7 @@
             REFIID           riid,
             void**           ppvObject)
 {
-  _ICOM_THIS_From_IPersistStorage(DataCache, iface);
+  DataCache *this = impl_from_IPersistStorage(iface);
 
   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
 }
@@ -899,7 +924,7 @@
 static ULONG WINAPI DataCache_IPersistStorage_AddRef(
             IPersistStorage* iface)
 {
-  _ICOM_THIS_From_IPersistStorage(DataCache, iface);
+  DataCache *this = impl_from_IPersistStorage(iface);
 
   return IUnknown_AddRef(this->outerUnknown);
 }
@@ -912,7 +937,7 @@
 static ULONG WINAPI DataCache_IPersistStorage_Release(
             IPersistStorage* iface)
 {
-  _ICOM_THIS_From_IPersistStorage(DataCache, iface);
+  DataCache *this = impl_from_IPersistStorage(iface);
 
   return IUnknown_Release(this->outerUnknown);
 }
@@ -979,7 +1004,7 @@
             IPersistStorage* iface,
 	    IStorage*        pStg)
 {
-  _ICOM_THIS_From_IPersistStorage(DataCache, iface);
+  DataCache *this = impl_from_IPersistStorage(iface);
 
   TRACE("(%p, %p)\n", iface, pStg);
 
@@ -1012,7 +1037,7 @@
 	    IStorage*        pStg,
 	    BOOL             fSameAsLoad)
 {
-  _ICOM_THIS_From_IPersistStorage(DataCache, iface);
+  DataCache *this = impl_from_IPersistStorage(iface);
 
   TRACE("(%p, %p, %d)\n", iface, pStg, fSameAsLoad);
 
@@ -1072,7 +1097,7 @@
 static HRESULT WINAPI DataCache_HandsOffStorage(
             IPersistStorage* iface)
 {
-  _ICOM_THIS_From_IPersistStorage(DataCache, iface);
+  DataCache *this = impl_from_IPersistStorage(iface);
 
   TRACE("(%p)\n", iface);
 
@@ -1100,7 +1125,7 @@
             REFIID           riid,
             void**           ppvObject)
 {
-  _ICOM_THIS_From_IViewObject2(DataCache, iface);
+  DataCache *this = impl_from_IViewObject2(iface);
 
   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
 }
@@ -1113,7 +1138,7 @@
 static ULONG WINAPI DataCache_IViewObject2_AddRef(
             IViewObject2* iface)
 {
-  _ICOM_THIS_From_IViewObject2(DataCache, iface);
+  DataCache *this = impl_from_IViewObject2(iface);
 
   return IUnknown_AddRef(this->outerUnknown);
 }
@@ -1126,7 +1151,7 @@
 static ULONG WINAPI DataCache_IViewObject2_Release(
             IViewObject2* iface)
 {
-  _ICOM_THIS_From_IViewObject2(DataCache, iface);
+  DataCache *this = impl_from_IViewObject2(iface);
 
   return IUnknown_Release(this->outerUnknown);
 }
@@ -1156,7 +1181,7 @@
   HMETAFILE              presMetafile = 0;
   HRESULT                hres;
 
-  _ICOM_THIS_From_IViewObject2(DataCache, iface);
+  DataCache *this = impl_from_IViewObject2(iface);
 
   TRACE("(%p, %lx, %ld, %p, %p, %p, %p, %p, %p, %lx)\n",
 	iface,
@@ -1295,7 +1320,7 @@
 	    DWORD           advf,
 	    IAdviseSink*    pAdvSink)
 {
-  _ICOM_THIS_From_IViewObject2(DataCache, iface);
+  DataCache *this = impl_from_IViewObject2(iface);
 
   TRACE("(%p, %lx, %lx, %p)\n", iface, aspects, advf, pAdvSink);
 
@@ -1350,7 +1375,7 @@
 	    DWORD*          pAdvf,
 	    IAdviseSink**   ppAdvSink)
 {
-  _ICOM_THIS_From_IViewObject2(DataCache, iface);
+  DataCache *this = impl_from_IViewObject2(iface);
 
   TRACE("(%p, %p, %p, %p)\n", iface, pAspects, pAdvf, ppAdvSink);
 
@@ -1390,7 +1415,7 @@
   PresentationDataHeader presData;
   HRESULT                hres = E_FAIL;
 
-  _ICOM_THIS_From_IViewObject2(DataCache, iface);
+  DataCache *this = impl_from_IViewObject2(iface);
 
   TRACE("(%p, %lx, %ld, %p, %p)\n",
 	iface, dwDrawAspect, lindex, ptd, lpsizel);
@@ -1459,7 +1484,7 @@
             REFIID          riid,
             void**          ppvObject)
 {
-  _ICOM_THIS_From_IOleCache2(DataCache, iface);
+  DataCache *this = impl_from_IOleCache2(iface);
 
   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
 }
@@ -1472,7 +1497,7 @@
 static ULONG WINAPI DataCache_IOleCache2_AddRef(
             IOleCache2*     iface)
 {
-  _ICOM_THIS_From_IOleCache2(DataCache, iface);
+  DataCache *this = impl_from_IOleCache2(iface);
 
   return IUnknown_AddRef(this->outerUnknown);
 }
@@ -1485,7 +1510,7 @@
 static ULONG WINAPI DataCache_IOleCache2_Release(
             IOleCache2*     iface)
 {
-  _ICOM_THIS_From_IOleCache2(DataCache, iface);
+  DataCache *this = impl_from_IOleCache2(iface);
 
   return IUnknown_Release(this->outerUnknown);
 }
@@ -1568,7 +1593,7 @@
             REFIID            riid,
             void**            ppvObject)
 {
-  _ICOM_THIS_From_IOleCacheControl(DataCache, iface);
+  DataCache *this = impl_from_IOleCacheControl(iface);
 
   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
 }
@@ -1581,7 +1606,7 @@
 static ULONG WINAPI DataCache_IOleCacheControl_AddRef(
             IOleCacheControl* iface)
 {
-  _ICOM_THIS_From_IOleCacheControl(DataCache, iface);
+  DataCache *this = impl_from_IOleCacheControl(iface);
 
   return IUnknown_AddRef(this->outerUnknown);
 }
@@ -1594,7 +1619,7 @@
 static ULONG WINAPI DataCache_IOleCacheControl_Release(
             IOleCacheControl* iface)
 {
-  _ICOM_THIS_From_IOleCacheControl(DataCache, iface);
+  DataCache *this = impl_from_IOleCacheControl(iface);
 
   return IUnknown_Release(this->outerUnknown);
 }
@@ -1735,13 +1760,13 @@
   /*
    * Make sure it supports the interface required by the caller.
    */
-  hr = IUnknown_QueryInterface((IUnknown*)&(newCache->lpvtbl2), riid, ppvObj);
+  hr = IUnknown_QueryInterface((IUnknown*)&(newCache->lpvtblNDIUnknown), riid, ppvObj);
 
   /*
    * Release the reference obtained in the constructor. If
    * the QueryInterface was unsuccessful, it will free the class.
    */
-  IUnknown_Release((IUnknown*)&(newCache->lpvtbl2));
+  IUnknown_Release((IUnknown*)&(newCache->lpvtblNDIUnknown));
 
   return hr;
 }
@@ -1766,12 +1791,12 @@
   /*
    * Initialize the virtual function table.
    */
-  newObject->lpvtbl1 = &DataCache_IDataObject_VTable;
-  newObject->lpvtbl2 = &DataCache_NDIUnknown_VTable;
-  newObject->lpvtbl3 = &DataCache_IPersistStorage_VTable;
-  newObject->lpvtbl4 = &DataCache_IViewObject2_VTable;
-  newObject->lpvtbl5 = &DataCache_IOleCache2_VTable;
-  newObject->lpvtbl6 = &DataCache_IOleCacheControl_VTable;
+  newObject->lpVtbl = &DataCache_IDataObject_VTable;
+  newObject->lpvtblNDIUnknown = &DataCache_NDIUnknown_VTable;
+  newObject->lpvtblIPersistStorage = &DataCache_IPersistStorage_VTable;
+  newObject->lpvtblIViewObject = &DataCache_IViewObject2_VTable;
+  newObject->lpvtblIOleCache2 = &DataCache_IOleCache2_VTable;
+  newObject->lpvtblIOleCacheControl = &DataCache_IOleCacheControl_VTable;
 
   /*
    * Start with one reference count. The caller of this function
@@ -1786,7 +1811,7 @@
    * lifetime.
    */
   if (pUnkOuter==NULL)
-    pUnkOuter = (IUnknown*)&(newObject->lpvtbl2);
+    pUnkOuter = (IUnknown*)&(newObject->lpvtblNDIUnknown);
 
   newObject->outerUnknown = pUnkOuter;
 

Modified: trunk/reactos/lib/ole32/defaulthandler.c
--- trunk/reactos/lib/ole32/defaulthandler.c	2005-09-05 21:47:21 UTC (rev 17677)
+++ trunk/reactos/lib/ole32/defaulthandler.c	2005-09-05 21:56:14 UTC (rev 17678)
@@ -70,10 +70,10 @@
   /*
    * List all interface VTables here
    */
-  const IOleObjectVtbl*      lpvtbl1;
-  const IUnknownVtbl*        lpvtbl2;
-  const IDataObjectVtbl*     lpvtbl3;
-  const IRunnableObjectVtbl* lpvtbl4;
+  const IOleObjectVtbl*      lpVtbl;
+  const IUnknownVtbl*        lpvtblIUnknown;
+  const IDataObjectVtbl*     lpvtblIDataObject;
+  const IRunnableObjectVtbl* lpvtblIRunnableObject;
 
   /*
    * Reference count of this object
@@ -82,7 +82,7 @@
 
   /*
    * IUnknown implementation of the outer object.
-   */
+p   */
   IUnknown* outerUnknown;
 
   /*
@@ -123,16 +123,32 @@
 typedef struct DefaultHandler DefaultHandler;
 
 /*
- * Here, I define utility macros to help with the casting of the
+ * Here, I define utility functions to help with the casting of the
  * "this" parameter.
  * There is a version to accommodate all of the VTables implemented
  * by this object.
  */
-#define _ICOM_THIS_From_IOleObject(class,name)       class* this = (class*)name
-#define _ICOM_THIS_From_NDIUnknown(class, name)      class* this = (class*)(((char*)name)-sizeof(void*))
-#define _ICOM_THIS_From_IDataObject(class, name)     class* this = (class*)(((char*)name)-2*sizeof(void*))
-#define _ICOM_THIS_From_IRunnableObject(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*))
+static inline DefaultHandler *impl_from_IOleObject( IOleObject *iface )
+{
+    return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpVtbl));
+}
 
+static inline DefaultHandler *impl_from_NDIUnknown( IUnknown *iface )
+{
+    return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIUnknown));
+}
+
+static inline DefaultHandler *impl_from_IDataObject( IDataObject *iface )
+{
+    return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIDataObject));
+}
+
+static inline DefaultHandler *impl_from_IRunnableObject( IRunnableObject *iface )
+{
+    return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIRunnableObject));
+}
+
+
 /*
  * Prototypes for the methods of the DefaultHandler class.
  */
@@ -432,13 +448,13 @@
   /*
    * Make sure it supports the interface required by the caller.
    */
-  hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtbl2), riid, ppvObj);
+  hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtblIUnknown), riid, ppvObj);
 
   /*
    * Release the reference obtained in the constructor. If
    * the QueryInterface was unsuccessful, it will free the class.
    */
-  IUnknown_Release((IUnknown*)&(newHandler->lpvtbl2));
+  IUnknown_Release((IUnknown*)&(newHandler->lpvtblIUnknown));
 
   return hr;
 }
@@ -463,10 +479,10 @@
   /*
    * Initialize the virtual function table.
    */
-  newObject->lpvtbl1 = &DefaultHandler_IOleObject_VTable;
-  newObject->lpvtbl2 = &DefaultHandler_NDIUnknown_VTable;
-  newObject->lpvtbl3 = &DefaultHandler_IDataObject_VTable;
-  newObject->lpvtbl4 = &DefaultHandler_IRunnableObject_VTable;
+  newObject->lpVtbl = &DefaultHandler_IOleObject_VTable;
+  newObject->lpvtblIUnknown = &DefaultHandler_NDIUnknown_VTable;
+  newObject->lpvtblIDataObject = &DefaultHandler_IDataObject_VTable;
+  newObject->lpvtblIRunnableObject = &DefaultHandler_IRunnableObject_VTable;
 
   /*
    * Start with one reference count. The caller of this function
@@ -481,7 +497,7 @@
    * lifetime.
    */
   if (pUnkOuter==NULL)
-    pUnkOuter = (IUnknown*)&(newObject->lpvtbl2);
+    pUnkOuter = (IUnknown*)&(newObject->lpvtblIUnknown);
 
   newObject->outerUnknown = pUnkOuter;
 
@@ -580,7 +596,7 @@
             REFIID         riid,
             void**         ppvObject)
 {
-  _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_NDIUnknown(iface);
 
   /*
    * Perform a sanity check on the parameters.
@@ -602,15 +618,15 @@
   }
   else if (memcmp(&IID_IOleObject, riid, sizeof(IID_IOleObject)) == 0)
   {
-    *ppvObject = (IOleObject*)&(this->lpvtbl1);
+    *ppvObject = (IOleObject*)&(this->lpVtbl);
   }
   else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0)
   {
-    *ppvObject = (IDataObject*)&(this->lpvtbl3);
+    *ppvObject = (IDataObject*)&(this->lpvtblIDataObject);
   }
   else if (memcmp(&IID_IRunnableObject, riid, sizeof(IID_IRunnableObject)) == 0)
   {
-    *ppvObject = (IRunnableObject*)&(this->lpvtbl4);
+    *ppvObject = (IRunnableObject*)&(this->lpvtblIRunnableObject);
   }
   else
   {
@@ -650,7 +666,7 @@
 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef(
             IUnknown*      iface)
 {
-  _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_NDIUnknown(iface);
   return InterlockedIncrement(&this->ref);
 }
 
@@ -665,7 +681,7 @@
 static ULONG WINAPI DefaultHandler_NDIUnknown_Release(
             IUnknown*      iface)
 {
-  _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_NDIUnknown(iface);
   ULONG ref;
 
   /*
@@ -696,7 +712,7 @@
             REFIID           riid,
             void**           ppvObject)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
 }
@@ -709,7 +725,7 @@
 static ULONG WINAPI DefaultHandler_AddRef(
             IOleObject*        iface)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   return IUnknown_AddRef(this->outerUnknown);
 }
@@ -722,7 +738,7 @@
 static ULONG WINAPI DefaultHandler_Release(
             IOleObject*        iface)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   return IUnknown_Release(this->outerUnknown);
 }
@@ -739,7 +755,7 @@
 	    IOleObject*        iface,
 	    IOleClientSite*    pClientSite)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %p)\n", iface, pClientSite);
 
@@ -774,7 +790,7 @@
 	    IOleObject*        iface,
 	    IOleClientSite**   ppClientSite)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   /*
    * Sanity check.
@@ -805,7 +821,7 @@
 	    LPCOLESTR          szContainerApp,
 	    LPCOLESTR          szContainerObj)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %s, %s)\n",
 	iface,
@@ -888,7 +904,7 @@
 	    DWORD              dwWhichMoniker,
 	    IMoniker**         ppmk)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %ld, %ld, %p)\n",
 	iface, dwAssign, dwWhichMoniker, ppmk);
@@ -967,7 +983,7 @@
 	    IOleObject*        iface,
 	    IEnumOLEVERB**     ppEnumOleVerb)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
 
@@ -1007,7 +1023,7 @@
 	    IOleObject*        iface,
 	    CLSID*             pClsid)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %p)\n", iface, pClsid);
 
@@ -1035,7 +1051,7 @@
 	    DWORD              dwFormOfType,
 	    LPOLESTR*          pszUserType)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType);
 
@@ -1076,7 +1092,7 @@
   IViewObject2*   cacheView = NULL;
   HRESULT         hres;
 
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel);
 
@@ -1123,7 +1139,7 @@
 	    DWORD*             pdwConnection)
 {
   HRESULT hres = S_OK;
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
 
@@ -1157,7 +1173,7 @@
 	    IOleObject*        iface,
 	    DWORD              dwConnection)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %ld)\n", iface, dwConnection);
 
@@ -1184,7 +1200,7 @@
 	    IOleObject*        iface,
 	    IEnumSTATDATA**    ppenumAdvise)
 {
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %p)\n", iface, ppenumAdvise);
 
@@ -1220,7 +1236,7 @@
 	    DWORD*             pdwStatus)
 {
   HRESULT hres;
-  _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IOleObject(iface);
 
   TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus);
 
@@ -1262,7 +1278,7 @@
            REFIID           riid,
             void**           ppvObject)
 {
-  _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
+  DefaultHandler *this = impl_from_IDataObject(iface);
 
   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
 }
@@ -1275,7 +1291,7 @@
 static ULONG WINAPI DefaultHandler_IDataObject_AddRef(
             IDataObject*     iface)
[truncated at 1000 lines; 2685 more skipped]