Sync to Wine-0_9_1:
Huw Davies <huw@codeweavers.com>
- Treat paramflags == 0 like PARAMFLAG_FIN.
- Don't call Release on a null ptr.
- Deal with pExcepInfo == NULL.
Robert Shearman <rob@codeweavers.com>
- Add IFontEventsDisp and IProvideMultipleClassInfo.
- Make sure to clean up properly on error.
- Restrict the critical section to getting the channel buffer and
  adding a reference to it.
- There is no need to call IUnknown_QueryInterface since getting the
  correct object is handled by the proxy manager.
- Forward IDispatch functions to the MIDL-generated proxy.
- Remove special cases caused by previous marshaling of IDispatch &
  IUnknown that is no longer done.
- Add error messages if an IUnknown or IDispatch method is called when
  it no longer should be.
- Cleanup formating of DispCallFunc.
- Fix DispCallFunc for functions with return values.
- Don't rely on _copy_arg as it is going away soon.
- Make wParamFlags in the paramdesc dumping function human readable.
- Enums should be VT_I4 instead of VT_INT.
- Trace the return value from the ITypeInfo_fnInvoke.
- Read DLL name from modules in MSFT typelibs.
- A name offset of -1 for a parameter means that it has the same name
  as the function.
- Print an error if a ReadName is attempted with an offset of -1,
  since this will read garbage.
- Implement ITypeInfo_GetDllEntry.
- Fix a crash during +variant logging caused by a typo causing an array
  to be one element less than expected.
- The PSDispatch PS class factory can manage both typelib marshalled and
  IDispatch, which is NDR marshalled, so we need a wrapper to call the
  appropriate CreateProxy or CreateStub function.
Alex Villacís Lasso <a_villacis@palosanto.com>
- Implement complete VarDecDiv() for any valid DECIMAL.
- Implement complete VarDecMul() for any valid DECIMAL.
- Implement complete VarBstrFromDec() for any valid DECIMAL, with
  internationalization support borrowed from VARIANT_BstrFromReal(). The
  decimal fix for VARIANT_BstrFromReal was encapsulated in a separate
  function and reused.
Michael Stefaniuc <mstefani@redhat.de>
- Handle VT_DECIMAL in VarCmp().
- Handle VT_CY in VarDiv().
Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
- Extend VarCmp() and add test cases.
Marcus Meissner <marcus@jet.franken.de>
- Added support of loading of IPicture data from non-statable
  IStreams. Added testcases for this.
- Added support for VT_I8/VT_UI8 marshalling.
- Fixed FMT_DATE_GENERAL and FMT_DATE_TIME_SYS cases in
  VARIANT_FormatDate.
Modified: trunk/reactos/include/wine/ocidl.h
Modified: trunk/reactos/lib/oleaut32/oleaut.c
Modified: trunk/reactos/lib/oleaut32/oleaut32.rc
Added: trunk/reactos/lib/oleaut32/oleaut32_Ko.rc
Modified: trunk/reactos/lib/oleaut32/olepicture.c
Modified: trunk/reactos/lib/oleaut32/regsvr.c
Modified: trunk/reactos/lib/oleaut32/tmarshal.c
Modified: trunk/reactos/lib/oleaut32/typelib.c
Modified: trunk/reactos/lib/oleaut32/typelib.h
Modified: trunk/reactos/lib/oleaut32/usrmarshal.c
Modified: trunk/reactos/lib/oleaut32/varformat.c
Modified: trunk/reactos/lib/oleaut32/variant.c
Modified: trunk/reactos/lib/oleaut32/vartype.c
Modified: trunk/reactos/w32api/include/oaidl.h

Modified: trunk/reactos/include/wine/ocidl.h
--- trunk/reactos/include/wine/ocidl.h	2005-11-17 21:35:56 UTC (rev 19312)
+++ trunk/reactos/include/wine/ocidl.h	2005-11-17 21:52:13 UTC (rev 19313)
@@ -5,6 +5,7 @@
 
 DEFINE_GUID(IID_IFont, 0xbef6e002, 0xa874, 0x101a, 0x8b,0xba, 0x00,0xaa,0x00,0x30,0x0c,0xab);
 DEFINE_GUID(IID_IFontDisp, 0xbef6e003, 0xa874, 0x101a, 0x8b,0xba, 0x00,0xaa,0x00,0x30,0x0c,0xab);
+DEFINE_GUID(IID_IFontEventsDisp, 0x4ef6100a, 0xaf88, 0x11d0, 0x98,0x46, 0x00,0xc0,0x4f,0xc2,0x99,0x93);
 DEFINE_GUID(IID_IPicture, 0x7bf80980, 0xbf32, 0x101a, 0x8b,0xbb, 0x00,0xaa,0x00,0x30,0x0c,0xab);
 DEFINE_GUID(IID_IPictureDisp, 0x7bf80981, 0xbf32, 0x101a, 0x8b,0xbb, 0x00,0xaa,0x00,0x30,0x0c,0xab);
 DEFINE_GUID(IID_IOleControl, 0xb196b288, 0xbab4, 0x101a, 0xb6,0x9c, 0x00,0xaa,0x00,0x34,0x1d,0x07);
@@ -16,6 +17,7 @@
 DEFINE_GUID(IID_IViewObjectEx, 0x3af24292, 0x0c96, 0x11ce, 0xa0,0xcf, 0x00,0xaa,0x00,0x60,0x0a,0xb8);
 DEFINE_GUID(IID_IProvideClassInfo, 0xb196b283, 0xbab4, 0x101a, 0xb6,0x9c, 0x00,0xaa,0x00,0x34,0x1d,0x07);
 DEFINE_GUID(IID_IProvideClassInfo2, 0xa6bc3ac0, 0xdbaa, 0x11ce, 0x9d,0xe3, 0x00,0xaa,0x00,0x4b,0xb8,0x51);
+DEFINE_GUID(IID_IProvideMultipleClassInfo, 0xa7aba9c1, 0x8983, 0x11cf, 0x8f,0x20, 0x00,0x80,0x5f,0x2c,0xd0,0x64);
 DEFINE_GUID(IID_IConnectionPoint, 0xb196b286, 0xbab4, 0x101a, 0xb6,0x9c, 0x00,0xaa,0x00,0x34,0x1d,0x07);
 DEFINE_GUID(IID_IConnectionPointContainer, 0xb196b284, 0xbab4, 0x101a, 0xb6,0x9c, 0x00,0xaa,0x00,0x34,0x1d,0x07);
 DEFINE_GUID(IID_IEnumConnections, 0xb196b287, 0xbab4, 0x101a, 0xb6,0x9c, 0x00,0xaa,0x00,0x34,0x1d,0x07);

Modified: trunk/reactos/lib/oleaut32/oleaut.c
--- trunk/reactos/lib/oleaut32/oleaut.c	2005-11-17 21:35:56 UTC (rev 19312)
+++ trunk/reactos/lib/oleaut32/oleaut.c	2005-11-17 21:52:13 UTC (rev 19313)
@@ -699,6 +699,76 @@
 extern void _get_STDFONT_CF(LPVOID);
 extern void _get_STDPIC_CF(LPVOID);
 
+static HRESULT WINAPI PSDispatchFacBuf_QueryInterface(IPSFactoryBuffer *iface, REFIID riid, void **ppv)
+{
+    if (IsEqualIID(riid, &IID_IUnknown) ||
+        IsEqualIID(riid, &IID_IPSFactoryBuffer))
+    {
+        IUnknown_AddRef(iface);
+        *ppv = (void *)iface;
+        return S_OK;
+    }
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI PSDispatchFacBuf_AddRef(IPSFactoryBuffer *iface)
+{
+    return 2;
+}
+
+static ULONG WINAPI PSDispatchFacBuf_Release(IPSFactoryBuffer *iface)
+{
+    return 1;
+}
+
+static HRESULT WINAPI PSDispatchFacBuf_CreateProxy(IPSFactoryBuffer *iface, IUnknown *pUnkOuter, REFIID riid, IRpcProxyBuffer **ppProxy, void **ppv)
+{
+    IPSFactoryBuffer *pPSFB;
+    HRESULT hr;
+
+    if (IsEqualIID(riid, &IID_IDispatch))
+        hr = OLEAUTPS_DllGetClassObject(&CLSID_PSDispatch, &IID_IPSFactoryBuffer, (void **)&pPSFB);
+    else
+        hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
+
+    if (FAILED(hr)) return hr;
+
+    hr = IPSFactoryBuffer_CreateProxy(pPSFB, pUnkOuter, riid, ppProxy, ppv);
+
+    IPSFactoryBuffer_Release(pPSFB);
+    return hr;
+}
+
+static HRESULT WINAPI PSDispatchFacBuf_CreateStub(IPSFactoryBuffer *iface, REFIID riid, IUnknown *pUnkOuter, IRpcStubBuffer **ppStub)
+{
+    IPSFactoryBuffer *pPSFB;
+    HRESULT hr;
+
+    if (IsEqualIID(riid, &IID_IDispatch))
+        hr = OLEAUTPS_DllGetClassObject(&CLSID_PSDispatch, &IID_IPSFactoryBuffer, (void **)&pPSFB);
+    else
+        hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
+
+    if (FAILED(hr)) return hr;
+
+    hr = IPSFactoryBuffer_CreateStub(pPSFB, riid, pUnkOuter, ppStub);
+
+    IPSFactoryBuffer_Release(pPSFB);
+    return hr;
+}
+
+static const IPSFactoryBufferVtbl PSDispatchFacBuf_Vtbl =
+{
+    PSDispatchFacBuf_QueryInterface,
+    PSDispatchFacBuf_AddRef,
+    PSDispatchFacBuf_Release,
+    PSDispatchFacBuf_CreateProxy,
+    PSDispatchFacBuf_CreateStub
+};
+
+/* This is the whole PSFactoryBuffer object, just the vtableptr */
+static const IPSFactoryBufferVtbl *pPSDispatchFacBuf = &PSDispatchFacBuf_Vtbl;
+
 /***********************************************************************
  *		DllGetClassObject (OLEAUT32.@)
  */
@@ -719,12 +789,16 @@
 	    return S_OK;
 	}
     }
-    if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) ||
-        IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
+    if (IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
         IsEqualCLSID(rclsid, &CLSID_PSTypeLib) ||
         IsEqualCLSID(rclsid, &CLSID_PSEnumVariant)) {
         return OLEAUTPS_DllGetClassObject(&CLSID_PSDispatch, iid, ppv);
     }
+    if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) && IsEqualIID(iid, &IID_IPSFactoryBuffer)) {
+        *ppv = &pPSDispatchFacBuf;
+        IPSFactoryBuffer_AddRef((IPSFactoryBuffer *)*ppv);
+        return S_OK;
+    }
     if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
 	if (S_OK==TMARSHAL_DllGetClassObject(rclsid,iid,ppv))
 	    return S_OK;

Modified: trunk/reactos/lib/oleaut32/oleaut32.rc
--- trunk/reactos/lib/oleaut32/oleaut32.rc	2005-11-17 21:35:56 UTC (rev 19312)
+++ trunk/reactos/lib/oleaut32/oleaut32.rc	2005-11-17 21:52:13 UTC (rev 19313)
@@ -34,6 +34,7 @@
 #include "oleaut32_Hu.rc"
 #include "oleaut32_It.rc"
 #include "oleaut32_Ja.rc"
+#include "oleaut32_Ko.rc"
 #include "oleaut32_Nl.rc"
 #include "oleaut32_No.rc"
 #include "oleaut32_Pl.rc"

Copied: trunk/reactos/lib/oleaut32/oleaut32_Ko.rc (from rev 19311, vendor/wine/dlls/oleaut32/current/oleaut32_Ko.rc)
Property changes on: trunk/reactos/lib/oleaut32/oleaut32_Ko.rc ___________________________________________________________________ Name: svn:keywords   + Author Date Id Revision Name: svn:eol-style   + native
Modified: trunk/reactos/lib/oleaut32/olepicture.c
--- trunk/reactos/lib/oleaut32/olepicture.c	2005-11-17 21:35:56 UTC (rev 19312)
+++ trunk/reactos/lib/oleaut32/olepicture.c	2005-11-17 21:52:13 UTC (rev 19313)
@@ -1056,6 +1056,7 @@
 static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
   HRESULT	hr = E_FAIL;
   BOOL		headerisdata = FALSE;
+  BOOL		statfailed = FALSE;
   ULONG		xread, toread;
   BYTE 		*xbuf;
   DWORD		header[2];
@@ -1065,19 +1066,29 @@
   
   TRACE("(%p,%p)\n",This,pStm);
 
+  /****************************************************************************************
+   * Part 1: Load the data
+   */
   /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
    * out whether we do.
    *
    * UPDATE: the IStream can be mapped to a plain file instead of a stream in a
-   * compound file. This may explain most, if not all, of the cases of "no header",
-   * and the header validation should take this into account. At least in Visual Basic 6,
-   * resource streams, valid headers are
+   * compound file. This may explain most, if not all, of the cases of "no
+   * header", and the header validation should take this into account.
+   * At least in Visual Basic 6, resource streams, valid headers are
    *    header[0] == "lt\0\0",
    *    header[1] == length_of_stream.
+   *
+   * Also handle streams where we do not have a working "Stat" method by
+   * reading all data until the end of the stream.
    */
   hr=IStream_Stat(pStm,&statstg,STATFLAG_NONAME);
-  if (hr)
-      FIXME("Stat failed with hres %lx\n",hr);
+  if (hr) {
+      TRACE("stat failed with hres %lx, proceeding to read all data.\n",hr);
+      statfailed = TRUE;
+      /* we will read at least 8 byte ... just right below */
+      statstg.cbSize.QuadPart = 8;
+  }
   hr=IStream_Read(pStm,header,8,&xread);
   if (hr || xread!=8) {
       FIXME("Failure while reading picture header (hr is %lx, nread is %ld).\n",hr,xread);
@@ -1089,42 +1100,77 @@
   if (!memcmp(&(header[0]),"lt\0\0", 4) && (header[1] <= statstg.cbSize.QuadPart-8)) {
       toread = header[1];
   } else {
-      if (!memcmp(&(header[0]), "GIF8",     4)	||   /* GIF header */
-	  !memcmp(&(header[0]), "BM",       2)	||   /* BMP header */
-	  !memcmp(&(header[0]), "\xff\xd8", 2)	||   /* JPEG header */
-	  (header[1] > statstg.cbSize.QuadPart)	||   /* invalid size */
-	  (header[1]==0)
+      if (!memcmp(&(header[0]), "GIF8",     4) ||   /* GIF header */
+          !memcmp(&(header[0]), "BM",       2) ||   /* BMP header */
+          !memcmp(&(header[0]), "\xff\xd8", 2) ||   /* JPEG header */
+          (header[1] > statstg.cbSize.QuadPart)||   /* invalid size */
+          (header[1]==0)
       ) {/* Incorrect header, assume none. */
           headerisdata = TRUE;
           toread = statstg.cbSize.QuadPart-8;
-	  xread = 8;
+          xread = 8;
       } else {
-	  FIXME("Unknown stream header magic: %08lx\n", header[0]);
+          FIXME("Unknown stream header magic: %08lx\n", header[0]);
           toread = header[1];
       }
   }
 
-  This->datalen = toread+(headerisdata?8:0);
-  xbuf = This->data = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, This->datalen);
+  if (statfailed) { /* we don't know the size ... read all we get */
+      int sizeinc = 4096;
+      int origsize = sizeinc;
+      ULONG nread = 42;
 
-  if (headerisdata)
-      memcpy (xbuf, &header, 8);
+      TRACE("Reading all data from stream.\n");
+      xbuf = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, origsize);
+      if (headerisdata)
+          memcpy (xbuf, &header, 8);
+      while (1) {
+          while (xread < origsize) {
+              hr = IStream_Read(pStm,xbuf+xread,origsize-xread,&nread);
+              xread+=nread;
+              if (hr || !nread)
+                  break;
+          }
+          if (!nread || hr) /* done, or error */
+              break;
+          if (xread == origsize) {
+              origsize += sizeinc;
+              sizeinc = 2*sizeinc; /* exponential increase */
+              xbuf = HeapReAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, xbuf, origsize);
+          }
+      }
+      if (hr)
+          TRACE("hr in no-stat loader case is %08lx\n", hr);
+      TRACE("loaded %ld bytes.\n", xread);
+      This->datalen = xread;
+      This->data    = xbuf;
+  } else {
+      This->datalen = toread+(headerisdata?8:0);
+      xbuf = This->data = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, This->datalen);
 
-  while (xread < This->datalen) {
-      ULONG nread;
-      hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
-      xread+=nread;
-      if (hr || !nread)
-	break;
+      if (headerisdata)
+          memcpy (xbuf, &header, 8);
+
+      while (xread < This->datalen) {
+          ULONG nread;
+          hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
+          xread+=nread;
+          if (hr || !nread)
+              break;
+      }
+      if (xread != This->datalen)
+          FIXME("Could only read %ld of %d bytes out of stream?\n",xread,This->datalen);
   }
-  if (xread != This->datalen)
-      FIXME("Could only read %ld of %d bytes out of stream?\n",xread,This->datalen);
-
-  if (This->datalen == 0) {	/* Marks the "NONE" picture */
+  if (This->datalen == 0) { /* Marks the "NONE" picture */
       This->desc.picType = PICTYPE_NONE;
       return S_OK;
   }
 
+
+  /****************************************************************************************
+   * Part 2: Process the loaded data
+   */
+
   magic = xbuf[0] + (xbuf[1]<<8);
   switch (magic) {
   case 0x4947: { /* GIF */

Modified: trunk/reactos/lib/oleaut32/regsvr.c
--- trunk/reactos/lib/oleaut32/regsvr.c	2005-11-17 21:35:56 UTC (rev 19312)
+++ trunk/reactos/lib/oleaut32/regsvr.c	2005-11-17 21:52:13 UTC (rev 19313)
@@ -544,15 +544,6 @@
 /***********************************************************************
  *		interface list
  */
-
-/* FIXME: these interfaces should be defined in ocidl.idl */
-
-static IID const IID_IFontEventsDisp = {
-    0x4EF6100A, 0xAF88, 0x11D0, {0x98,0x46,0x00,0xC0,0x4F,0xC2,0x99,0x93} };
-
-static IID const IID_IProvideMultipleClassInfo = {
-    0xA7ABA9C1, 0x8983, 0x11CF, {0x8F,0x20,0x00,0x80,0x5F,0x2C,0xD0,0x64} };
-
 static struct regsvr_interface const interface_list[] = {
     {   &IID_IDispatch,
 	"IDispatch",

Modified: trunk/reactos/lib/oleaut32/tmarshal.c
--- trunk/reactos/lib/oleaut32/tmarshal.c	2005-11-17 21:35:56 UTC (rev 19312)
+++ trunk/reactos/lib/oleaut32/tmarshal.c	2005-11-17 21:52:13 UTC (rev 19313)
@@ -45,11 +45,7 @@
 #include "typelib.h"
 #include "wine/debug.h"
 
-static const WCHAR riidW[5] = {'r','i','i','d',0};
-static const WCHAR pdispparamsW[] = {'p','d','i','s','p','p','a','r','a','m','s',0};
-static const WCHAR ppvObjectW[] = {'p','p','v','O','b','j','e','c','t',0};
 static const WCHAR IDispatchW[] = { 'I','D','i','s','p','a','t','c','h',0};
-static const WCHAR GetIDsOfNamesW[] = { 'G','e','t','I','D','s','O','f','N','a','m','e','s',0};
 
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 WINE_DECLARE_DEBUG_CHANNEL(olerelay);
@@ -60,9 +56,6 @@
     LPBYTE	base;
     int		size;
     int		curoff;
-
-    BOOL	thisisiid;
-    IID		iid;	/* HACK: for VT_VOID */
 } marshal_state;
 
 /* used in the olerelay code to avoid having the L"" stuff added by debugstr_w */
@@ -360,6 +353,7 @@
     IID					iid;
     CRITICAL_SECTION	crit;
     IUnknown				*outerunknown;
+    IDispatch				*dispatch;
 } TMProxyImpl;
 
 static HRESULT WINAPI
@@ -396,6 +390,7 @@
 
     if (!refCount)
     {
+        if (This->dispatch) IDispatch_Release(This->dispatch);
         DeleteCriticalSection(&This->crit);
         if (This->chanbuf) IRpcChannelBuffer_Release(This->chanbuf);
         VirtualFree(This->asmstubs, 0, MEM_RELEASE);
@@ -450,6 +445,8 @@
 int
 _argsize(DWORD vt) {
     switch (vt) {
+    case VT_UI8:
+	return 8/sizeof(DWORD);
     case VT_R8:
         return sizeof(double)/sizeof(DWORD);
     case VT_CY:
@@ -478,6 +475,9 @@
 	    arrsize *= adesc->rgbounds[i].cElements;
 	return arrsize*_xsize(&adesc->tdescElem);
     }
+    case VT_UI8:
+    case VT_I8:
+	return 8;
     case VT_UI2:
     case VT_I2:
 	return 2;
@@ -506,6 +506,13 @@
     switch (tdesc->vt) {
     case VT_EMPTY: /* nothing. empty variant for instance */
 	return S_OK;
+    case VT_I8:
+    case VT_UI8:
+	hres = S_OK;
+	if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
+	if (writeit)
+	    hres = xbuf_add(buf,(LPBYTE)arg,8);
+	return hres;
     case VT_BOOL:
     case VT_ERROR:
     case VT_UINT:
@@ -726,8 +733,6 @@
 		if (debugout && (i<(tattr->cVars-1)))
 		    TRACE_(olerelay)(",");
 	    }
-	    if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
-		memcpy(&(buf->iid),arg,sizeof(buf->iid));
 	    if (debugout) TRACE_(olerelay)("}");
 	    break;
 	}
@@ -773,296 +778,7 @@
     }
 }
 
-/* IDL desc:
- * HRESULT GetIDsOfNames(
- *   [in] REFIID riid,					args[1]
- *   [in, size_is(cNames)] LPOLESTR *rgszNames,		args[2]
- *   [in] UINT cNames,					args[3]
- *   [in] LCID lcid,					args[4]
- *   [out, size_is(cNames)] DISPID *rgDispId);		args[5]
- *
- * line format:
- *	IID	iid;
- *	DWORD 	cNames;
- *	LPOLESTR rgszNames[cNames];
- *		DWORD bytestrlen	(incl 0)
- *		BYTE data[bytestrlen]	(incl 0)
- *	LCID
- */
 static HRESULT
-serialize_IDispatch_GetIDsOfNames(
-    BOOL		inputparams,
-    BOOL		debugout,
-    DWORD		*args,
-    marshal_state	*buf)
-{
-    HRESULT	hres;
-    DWORD	cNames = args[2];
-    LPOLESTR    *rgszNames = (LPOLESTR*)args[1];
-    int		i;
-
-    if (inputparams) {
-	if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
-	hres = xbuf_add(buf, (LPBYTE)args[0], sizeof(IID));
-	if (hres) {
-	    FIXME("serialize of IID failed.\n");
-	    return hres;
-	}
-	if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
-	hres = xbuf_add(buf, (LPBYTE)&cNames, sizeof(DWORD));
-	if (hres) {
-	    FIXME("serialize of cNames failed.\n");
-	    return hres;
-	}
-	if (debugout) TRACE_(olerelay)("rgszNames=[");
-        for (i=0;i<cNames;i++) {
-	    DWORD len = 2*(lstrlenW(rgszNames[i])+1);
-
-	    if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
-	    hres = xbuf_add(buf, (LPBYTE)&len, sizeof(DWORD));
-	    if (hres) {
-		FIXME("serialize of len failed.\n");
-		return hres;
-	    }
-	    hres = xbuf_add(buf, (LPBYTE)rgszNames[i], len);
-	    if (hres) {
-		FIXME("serialize of rgszNames[i] failed.\n");
-		return hres;
-	    }
-        }
-	if (debugout) TRACE_(olerelay)("],lcid=%04lx)",args[3]);
-	hres = xbuf_add(buf, (LPBYTE)&args[3], sizeof(DWORD));
-	if (hres) {
-	    FIXME("serialize of lcid failed.\n");
-	    return hres;
-	}
-    } else {
-	DISPID *rgDispId = (DISPID*)args[4];
-
-	hres = xbuf_add(buf, (LPBYTE)rgDispId, sizeof(DISPID) * cNames);
-	if (hres) {
-	    FIXME("serialize of rgDispId failed.\n");
-	    return hres;
-	}
-	if (debugout) {
-	    TRACE_(olerelay)("riid=[in],rgszNames=[in],cNames=[in],rgDispId=[");
-	    for (i=0;i<cNames;i++)
-		TRACE_(olerelay)("%08lx,",rgDispId[i]);
-	    TRACE_(olerelay)("])");
-	}
-	HeapFree(GetProcessHeap(),0,(IID*)args[0]);
-	rgszNames = (LPOLESTR*)args[1];
-	for (i=0;i<cNames;i++) HeapFree(GetProcessHeap(),0,rgszNames[i]);
-	HeapFree(GetProcessHeap(),0,rgszNames);
-	HeapFree(GetProcessHeap(),0,rgDispId);
-    }
-    return S_OK;
-}
-
-static HRESULT
-deserialize_IDispatch_GetIDsOfNames(
-    BOOL		inputparams,
-    BOOL		debugout,
-    DWORD		*args,
-    marshal_state	*buf)
-{
-    HRESULT	hres;
-    DWORD	cNames;
-    LPOLESTR    *rgszNames;
-    int		i;
-
-    if (inputparams) {
-	args[0] = (DWORD)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IID));
-	if (!args[0]) return E_FAIL;
-	hres = xbuf_get(buf, (LPBYTE)args[0], sizeof(IID));
-	if (hres) {
-	    FIXME("deserialize of IID failed.\n");
-	    return hres;
-	}
-	if (debugout) TRACE_(olerelay)("riid=%s,",debugstr_guid((REFIID)args[0]));
-
-	hres = xbuf_get(buf, (LPBYTE)&cNames, sizeof(DWORD));
-	if (hres) {
-	    FIXME("deserialize of cNames failed.\n");
-	    return hres;
-	}
-        args[2] = cNames;
-	if (debugout) TRACE_(olerelay)("cNames=%ld,",cNames);
-	if (debugout) TRACE_(olerelay)("rgszNames=[");
-        rgszNames = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPOLESTR) * cNames);
-	if (!rgszNames) return E_FAIL;
-	args[1] = (DWORD)rgszNames;
-        for (i=0;i<cNames;i++) {
-	    DWORD len;
-
-	    hres = xbuf_get(buf, (LPBYTE)&len, sizeof(DWORD));
-	    if (hres) {
-		FIXME("serialize of len failed.\n");
-		return hres;
-	    }
-	    rgszNames[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
-	    if (!rgszNames[i]) {
-		FIXME("heapalloc of %ld bytes failed\n", len);
-		return E_FAIL;
-	    }
-	    hres = xbuf_get(buf, (LPBYTE)rgszNames[i], len);
-	    if (hres) {
-		FIXME("serialize of rgszNames[i] failed.\n");
-		return hres;
-	    }
-	    if (debugout) TRACE_(olerelay)("%s,",relaystr(rgszNames[i]));
-        }
-	hres = xbuf_get(buf, (LPBYTE)&args[3], sizeof(DWORD));
-	if (hres) {
-	    FIXME("deserialize of lcid failed.\n");
-	    return hres;
-	}
-	if (debugout) TRACE_(olerelay)("],lcid=%04lx,rgDispId=[out])",args[3]);
-        args[4] = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID) * cNames);
-    } else {
-	hres = xbuf_get(buf, (LPBYTE)args[4], sizeof(DISPID) * args[2]);
-	if (hres) {
-	    FIXME("serialize of rgDispId failed.\n");
-	    return hres;
-	}
-	if (debugout) {
-	    TRACE_(olerelay)("dispid=[");
-	    for (i=0;i<args[2];i++)
-		TRACE_(olerelay)("%08lx,",((DISPID*)args[4])[i]);
-	    TRACE_(olerelay)("])");
-	}
-    }
-    return S_OK;
-}
-
-static HRESULT
-serialize_LPVOID_ptr(
-    ITypeInfo		*tinfo,
-    BOOL		writeit,
-    BOOL		debugout,
-    BOOL		dealloc,
-    TYPEDESC		*tdesc,
-    DWORD		*arg,
-    marshal_state	*buf)
-{
-    HRESULT	hres;
-    DWORD	cookie;
-
-    if ((tdesc->vt != VT_PTR)			||
-	(tdesc->u.lptdesc->vt != VT_PTR)	||
-	(tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
-    ) {
-	FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
-	return E_FAIL;
-    }
-    cookie = (*(DWORD*)*arg) ? 0x42424242: 0x0;
-    if (writeit) {
-	hres = xbuf_add(buf, (LPVOID)&cookie, sizeof(cookie));
-	if (hres)
-	    return hres;
-    }
-    if (!*(DWORD*)*arg) {
-	if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
-	return S_OK;
-    }
-    if (debugout)
-	TRACE_(olerelay)("ppv(%p)",*(LPUNKNOWN*)*arg);
-    if (writeit) {
-	hres = _marshal_interface(buf,&(buf->iid),*(LPUNKNOWN*)*arg);
-	if (hres)
-	    return hres;
-    }
-    if (dealloc)
-	HeapFree(GetProcessHeap(),0,(LPVOID)*arg);
-    return S_OK;
-}
-
-static HRESULT
-serialize_DISPPARAM_ptr(
-    ITypeInfo		*tinfo,
-    BOOL		writeit,
-    BOOL		debugout,
-    BOOL		dealloc,
-    TYPEDESC		*tdesc,
-    DWORD		*arg,
-    marshal_state	*buf)
-{
-    DWORD	cookie;
-    HRESULT	hres;
-    DISPPARAMS	*disp;
-    int		i;
-
-    if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
-	FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
-	return E_FAIL;
-    }
-
-    cookie = *arg ? 0x42424242 : 0x0;
-    if (writeit) {
-	hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
-	if (hres)
-	    return hres;
-    }
-    if (!*arg) {
-	if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
-	return S_OK;
-    }
-    disp = (DISPPARAMS*)*arg;
-    if (writeit) {
-	hres = xbuf_add(buf,(LPBYTE)&disp->cArgs,sizeof(disp->cArgs));
-	if (hres)
-	    return hres;
-    }
-    if (debugout) TRACE_(olerelay)("D{");
-    for (i=0;i<disp->cArgs;i++) {
-	TYPEDESC	vtdesc;
-
-	vtdesc.vt = VT_VARIANT;
-	serialize_param(
-	    tinfo,
-	    writeit,
-	    debugout,
-	    dealloc,
-	    &vtdesc,
-	    (DWORD*)(disp->rgvarg+i),
-	    buf
-        );
-	if (debugout && (i<disp->cArgs-1))
-	    TRACE_(olerelay)(",");
-    }
-    if (dealloc)
-	HeapFree(GetProcessHeap(),0,disp->rgvarg);
-    if (writeit) {
-	hres = xbuf_add(buf,(LPBYTE)&disp->cNamedArgs,sizeof(disp->cNamedArgs));
-	if (hres)
-	    return hres;
-    }
-    if (debugout) TRACE_(olerelay)("}{");
-    for (i=0;i<disp->cNamedArgs;i++) {
-	TYPEDESC	vtdesc;
-
-	vtdesc.vt = VT_UINT;
-	serialize_param(
-	    tinfo,
-	    writeit,
-	    debugout,
-	    dealloc,
-	    &vtdesc,
-	    (DWORD*)(disp->rgdispidNamedArgs+i),
-	    buf
-	);
-	if (debugout && (i<disp->cNamedArgs-1))
-	    TRACE_(olerelay)(",");
-    }
-    if (debugout) TRACE_(olerelay)("}");
-    if (dealloc) {
-	HeapFree(GetProcessHeap(),0,disp->rgdispidNamedArgs);
-	HeapFree(GetProcessHeap(),0,disp);
-    }
-    return S_OK;
-}
-
-static HRESULT
 deserialize_param(
     ITypeInfo		*tinfo,
     BOOL		readit,
@@ -1107,6 +823,14 @@
 		return S_OK;
 	    }
 	}
+        case VT_I8:
+        case VT_UI8:
+	    if (readit) {
+		hres = xbuf_get(buf,(LPBYTE)arg,8);
+		if (hres) ERR("Failed to read integer 8 byte\n");
+	    }
+	    if (debugout) TRACE_(olerelay)("%lx%lx",arg[0],arg[1]);
+	    return hres;
         case VT_ERROR:
 	case VT_BOOL:
         case VT_I4:
@@ -1331,8 +1055,6 @@
 			);
 		        if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
 		    }
-		    if (buf->thisisiid && (tattr->cbSizeInstance==sizeof(GUID)))
-			memcpy(&(buf->iid),(LPBYTE)*arg,sizeof(buf->iid));
 		    if (debugout) TRACE_(olerelay)("}");
 		    break;
 		}
@@ -1383,130 +1105,6 @@
     }
 }
 
-static HRESULT
-deserialize_LPVOID_ptr(
-    ITypeInfo		*tinfo,
-    BOOL		readit,
-    BOOL		debugout,
-    BOOL		alloc,
-    TYPEDESC		*tdesc,
-    DWORD		*arg,
-    marshal_state	*buf
-) {
-    HRESULT	hres;
-    DWORD	cookie;
-
-    if ((tdesc->vt != VT_PTR)			||
-	(tdesc->u.lptdesc->vt != VT_PTR)	||
-	(tdesc->u.lptdesc->u.lptdesc->vt != VT_VOID)
-    ) {
-	FIXME("ppvObject not expressed as VT_PTR -> VT_PTR -> VT_VOID?\n");
-	return E_FAIL;
-    }
-    if (alloc)
-	*arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LPVOID));
-    if (readit) {
-	hres = xbuf_get(buf, (LPVOID)&cookie, sizeof(cookie));
-	if (hres)
-	    return hres;
-	if (cookie != 0x42424242) {
-	    *(DWORD*)*arg = 0;
-	    if (debugout) TRACE_(olerelay)("<lpvoid NULL>");
-	    return S_OK;
-	}
-    }
-    if (readit) {
-	hres = _unmarshal_interface(buf,&buf->iid,(LPUNKNOWN*)*arg);
-	if (hres) {
-	    FIXME("_unmarshal_interface of %s , %p failed with %lx\n", debugstr_guid(&buf->iid), (LPUNKNOWN*)*arg, hres);
-	    return hres;
-	}
-    }
-    if (debugout) TRACE_(olerelay)("ppv(%p)",(LPVOID)*arg);
-    return S_OK;
-}
-
-static HRESULT
-deserialize_DISPPARAM_ptr(
-    ITypeInfo		*tinfo,
-    BOOL		readit,
-    BOOL		debugout,
-    BOOL		alloc,
-    TYPEDESC		*tdesc,
-    DWORD		*arg,
-    marshal_state	*buf)
-{
-    DWORD	cookie;
-    DISPPARAMS	*disps;
-    HRESULT	hres;
-    int		i;
-
-    if ((tdesc->vt != VT_PTR) || (tdesc->u.lptdesc->vt != VT_USERDEFINED)) {
-	FIXME("DISPPARAMS not expressed as VT_PTR -> VT_USERDEFINED?\n");
-	return E_FAIL;
-    }
-    if (readit) {
-	hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
-	if (hres)
-	    return hres;
-	if (cookie == 0) {
-	    *arg = 0;
-	    if (debugout) TRACE_(olerelay)("<DISPPARAMS NULL>");
-	    return S_OK;
-	}
-    }
-    if (alloc)
-	*arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPPARAMS));
-    disps = (DISPPARAMS*)*arg;
-    if (!readit)
-	return S_OK;
-    hres = xbuf_get(buf, (LPBYTE)&disps->cArgs, sizeof(disps->cArgs));
-    if (hres)
-	return hres;
-    if (alloc)
-        disps->rgvarg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(VARIANT)*disps->cArgs);
-    if (debugout) TRACE_(olerelay)("D{");
-    for (i=0; i< disps->cArgs; i++) {
-        TYPEDESC vdesc;
-
-	vdesc.vt = VT_VARIANT;
-	hres = deserialize_param(
-	    tinfo,
-	    readit,
-	    debugout,
-	    alloc,
-	    &vdesc,
-	    (DWORD*)(disps->rgvarg+i),
-	    buf
-	);
-    }
-    if (debugout) TRACE_(olerelay)("}{");
-    hres = xbuf_get(buf, (LPBYTE)&disps->cNamedArgs, sizeof(disps->cNamedArgs));
-    if (hres)
-	return hres;
-    if (disps->cNamedArgs) {
-	if (alloc)
-	    disps->rgdispidNamedArgs = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DISPID)*disps->cNamedArgs);
-	for (i=0; i< disps->cNamedArgs; i++) {
-	    TYPEDESC vdesc;
-
-	    vdesc.vt = VT_UINT;
-	    hres = deserialize_param(
-		tinfo,
-		readit,
-		debugout,
-		alloc,
-		&vdesc,
-		(DWORD*)(disps->rgdispidNamedArgs+i),
-		buf
-	    );
-	    if (debugout && i<(disps->cNamedArgs-1)) TRACE_(olerelay)(",");
-	}
-    }
-    if (debugout) TRACE_(olerelay)("}");
-    return S_OK;
-}
-
 /* Searches function, also in inherited interfaces */
 static HRESULT
 _get_funcdesc(
@@ -1575,18 +1173,18 @@
     BSTR		fname,iname;
     BSTR		names[10];
     UINT		nrofnames;
-    int			is_idispatch_getidsofnames = 0;
     DWORD		remoteresult = 0;
     ITypeInfo 		*tinfo;
+    IRpcChannelBuffer *chanbuf;
 
     EnterCriticalSection(&tpinfo->crit);
 
     hres = _get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname);
     if (hres) {
-	ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
+        ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
         ITypeInfo_Release(tinfo);
         LeaveCriticalSection(&tpinfo->crit);
-	return E_FAIL;
+        return E_FAIL;
     }
 
     if (!tpinfo->chanbuf)
@@ -1596,7 +1194,11 @@
         LeaveCriticalSection(&tpinfo->crit);
         return RPC_E_DISCONNECTED;
     }
+    chanbuf = tpinfo->chanbuf;
+    IRpcChannelBuffer_AddRef(chanbuf);
 
+    LeaveCriticalSection(&tpinfo->crit);
+
     if (relaydeb) {
        TRACE_(olerelay)("->");
 	if (iname)
@@ -1607,34 +1209,12 @@
 	    TRACE_(olerelay)("%d",method);
 	TRACE_(olerelay)("(");
     }
-    if (iname && fname && !lstrcmpW(iname,IDispatchW) && !lstrcmpW(fname,GetIDsOfNamesW))
-        is_idispatch_getidsofnames = 1;
 
     if (iname) SysFreeString(iname);
     if (fname) SysFreeString(fname);
 
     memset(&buf,0,sizeof(buf));
-    buf.iid = IID_IUnknown;
 
-    /* Special IDispatch::GetIDsOfNames() serializer */
-    if (is_idispatch_getidsofnames) {
-	hres = serialize_IDispatch_GetIDsOfNames(TRUE,relaydeb,args,&buf);
-	if (hres != S_OK) {
-	    FIXME("serialize of IDispatch::GetIDsOfNames failed!\n");
-            ITypeInfo_Release(tinfo);
-            LeaveCriticalSection(&tpinfo->crit);
-	    return hres;
-	}
-	goto afterserialize;
-    }
-
-    /* special QueryInterface serialize */
-    if (method == 0) {
-	xbuf_add(&buf,(LPBYTE)args[0],sizeof(IID));
-	if (relaydeb) TRACE_(olerelay)("riid=%s,[out])",debugstr_guid((REFIID)args[0]));
-	goto afterserialize;
-    }
-
     /* normal typelib driven serializing */
 
     /* Need them for hack below */
@@ -1647,62 +1227,27 @@
     xargs = args;
     for (i=0;i<fdesc->cParams;i++) {
 	ELEMDESC	*elem = fdesc->lprgelemdescParam+i;
-	BOOL	isserialized = FALSE;
 	if (relaydeb) {
 	    if (i) TRACE_(olerelay)(",");
 	    if (i+1<nrofnames && names[i+1])
 		TRACE_(olerelay)("%s=",relaystr(names[i+1]));
 	}
 	/* No need to marshal other data than FIN and any VT_PTR. */
-	if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN) && (elem->tdesc.vt != VT_PTR)) {
+	if (!(elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags) && (elem->tdesc.vt != VT_PTR)) {
 	    xargs+=_argsize(elem->tdesc.vt);
 	    if (relaydeb) TRACE_(olerelay)("[out]");
 	    continue;
 	}
-	if (((i+1)<nrofnames) && !IsBadStringPtrW(names[i+1],1)) {
-	    /* If the parameter is 'riid', we use it as interface IID
-	     * for a later ppvObject serialization.
-	     */
-	    buf.thisisiid = !lstrcmpW(names[i+1],riidW);
+	hres = serialize_param(
+	    tinfo,
+	    elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags,
+	    relaydeb,
+	    FALSE,
+	    &elem->tdesc,
+	    xargs,
+	    &buf
+	);
 
-	    /* DISPPARAMS* needs special serializer */
-	    if (!lstrcmpW(names[i+1],pdispparamsW)) {
-		hres = serialize_DISPPARAM_ptr(
-		    tinfo,
-		    elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
-		    relaydeb,
-		    FALSE,
-		    &elem->tdesc,
-		    xargs,
-		    &buf
-		);
-		isserialized = TRUE;
-	    }
-	    if (!lstrcmpW(names[i+1],ppvObjectW)) {
-		hres = serialize_LPVOID_ptr(
-		    tinfo,
-		    elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
-		    relaydeb,
-		    FALSE,
-		    &elem->tdesc,
-		    xargs,
-		    &buf
-		);
-		if (hres == S_OK)
-		    isserialized = TRUE;
-	    }
-	}
-	if (!isserialized)
-	    hres = serialize_param(
-		tinfo,
-		elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN,
-		relaydeb,
-		FALSE,
-		&elem->tdesc,
-		xargs,
-		&buf
-	    );
-
 	if (hres) {
 	    ERR("Failed to serialize param, hres %lx\n",hres);
 	    break;
@@ -1711,23 +1256,20 @@
     }
     if (relaydeb) TRACE_(olerelay)(")");
 
-afterserialize:
     memset(&msg,0,sizeof(msg));
     msg.cbBuffer = buf.curoff;
     msg.iMethod  = method;
-    hres = IRpcChannelBuffer_GetBuffer(tpinfo->chanbuf,&msg,&(tpinfo->iid));
+    hres = IRpcChannelBuffer_GetBuffer(chanbuf,&msg,&(tpinfo->iid));
     if (hres) {
 	ERR("RpcChannelBuffer GetBuffer failed, %lx\n",hres);
-        LeaveCriticalSection(&tpinfo->crit);
-	return hres;
+	goto exit;
     }
     memcpy(msg.Buffer,buf.base,buf.curoff);
[truncated at 1000 lines; 1954 more skipped]