[OLE32]
[reactos.git] / reactos / dll / win32 / ole32 / marshal.c
index 11cceda..411f508 100644 (file)
@@ -92,7 +92,8 @@ static inline HRESULT get_facbuf_for_iid(REFIID riid, IPSFactoryBuffer **facbuf)
     HRESULT       hr;
     CLSID         clsid;
 
-    if ((hr = CoGetPSClsid(riid, &clsid)))
+    hr = CoGetPSClsid(riid, &clsid);
+    if (hr != S_OK)
         return hr;
     return CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER | WINE_CLSCTX_DONT_HOST,
         NULL, &IID_IPSFactoryBuffer, (LPVOID*)facbuf);
@@ -1150,15 +1151,17 @@ HRESULT apartment_disconnectproxies(struct apartment *apt)
 /********************** StdMarshal implementation ****************************/
 typedef struct _StdMarshalImpl
 {
-    const IMarshalVtbl *lpvtbl;
-    LONG               ref;
-
-    IID                        iid;
-    DWORD              dwDestContext;
-    LPVOID             pvDestContext;
-    DWORD              mshlflags;
+    IMarshal IMarshal_iface;
+    LONG     ref;
+    DWORD    dest_context;
+    void    *dest_context_data;
 } StdMarshalImpl;
 
+static inline StdMarshalImpl *impl_from_StdMarshal(IMarshal *iface)
+{
+    return CONTAINING_RECORD(iface, StdMarshalImpl, IMarshal_iface);
+}
+
 static HRESULT WINAPI 
 StdMarshalImpl_QueryInterface(IMarshal *iface, REFIID riid, void **ppv)
 {
@@ -1174,16 +1177,16 @@ StdMarshalImpl_QueryInterface(IMarshal *iface, REFIID riid, void **ppv)
 }
 
 static ULONG WINAPI
-StdMarshalImpl_AddRef(LPMARSHAL iface)
+StdMarshalImpl_AddRef(IMarshal *iface)
 {
-    StdMarshalImpl *This = (StdMarshalImpl *)iface;
+    StdMarshalImpl *This = impl_from_StdMarshal(iface);
     return InterlockedIncrement(&This->ref);
 }
 
 static ULONG WINAPI
-StdMarshalImpl_Release(LPMARSHAL iface)
+StdMarshalImpl_Release(IMarshal *iface)
 {
-    StdMarshalImpl *This = (StdMarshalImpl *)iface;
+    StdMarshalImpl *This = impl_from_StdMarshal(iface);
     ULONG ref = InterlockedDecrement(&This->ref);
 
     if (!ref) HeapFree(GetProcessHeap(),0,This);
@@ -1192,7 +1195,7 @@ StdMarshalImpl_Release(LPMARSHAL iface)
 
 static HRESULT WINAPI
 StdMarshalImpl_GetUnmarshalClass(
-    LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
+    IMarshal *iface, REFIID riid, void* pv, DWORD dwDestContext,
     void* pvDestContext, DWORD mshlflags, CLSID* pCid)
 {
     *pCid = CLSID_DfMarshal;
@@ -1201,7 +1204,7 @@ StdMarshalImpl_GetUnmarshalClass(
 
 static HRESULT WINAPI
 StdMarshalImpl_GetMarshalSizeMax(
-    LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
+    IMarshal *iface, REFIID riid, void* pv, DWORD dwDestContext,
     void* pvDestContext, DWORD mshlflags, DWORD* pSize)
 {
     *pSize = sizeof(STDOBJREF);
@@ -1210,7 +1213,7 @@ StdMarshalImpl_GetMarshalSizeMax(
 
 static HRESULT WINAPI
 StdMarshalImpl_MarshalInterface(
-    LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dest_context,
+    IMarshal *iface, IStream *pStm,REFIID riid, void* pv, DWORD dest_context,
     void* dest_context_data, DWORD mshlflags)
 {
     STDOBJREF             stdobjref;
@@ -1312,9 +1315,9 @@ static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt,
 }
 
 static HRESULT WINAPI
-StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv)
+StdMarshalImpl_UnmarshalInterface(IMarshal *iface, IStream *pStm, REFIID riid, void **ppv)
 {
-    StdMarshalImpl *This = (StdMarshalImpl *)iface;
+    StdMarshalImpl *This = impl_from_StdMarshal(iface);
     struct stub_manager *stubmgr = NULL;
     STDOBJREF stdobjref;
     ULONG res;
@@ -1380,8 +1383,8 @@ StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, v
             wine_dbgstr_longlong(stdobjref.oxid));
 
     if (hres == S_OK)
-        hres = unmarshal_object(&stdobjref, apt, This->dwDestContext,
-                                This->pvDestContext, riid,
+        hres = unmarshal_object(&stdobjref, apt, This->dest_context,
+                                This->dest_context_data, riid,
                                 stubmgr ? &stubmgr->oxid_info : NULL, ppv);
 
     if (stubmgr) stub_manager_int_release(stubmgr);
@@ -1394,7 +1397,7 @@ StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, v
 }
 
 static HRESULT WINAPI
-StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
+StdMarshalImpl_ReleaseMarshalData(IMarshal *iface, IStream *pStm)
 {
     STDOBJREF            stdobjref;
     ULONG                res;
@@ -1436,13 +1439,13 @@ StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
 }
 
 static HRESULT WINAPI
-StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved)
+StdMarshalImpl_DisconnectObject(IMarshal *iface, DWORD dwReserved)
 {
     FIXME("(), stub!\n");
     return S_OK;
 }
 
-static const IMarshalVtbl VT_StdMarshal =
+static const IMarshalVtbl StdMarshalVtbl =
 {
     StdMarshalImpl_QueryInterface,
     StdMarshalImpl_AddRef,
@@ -1455,15 +1458,24 @@ static const IMarshalVtbl VT_StdMarshal =
     StdMarshalImpl_DisconnectObject
 };
 
-static HRESULT StdMarshalImpl_Construct(REFIID riid, void** ppvObject)
+static HRESULT StdMarshalImpl_Construct(REFIID riid, DWORD dest_context, void *dest_context_data, void** ppvObject)
 {
-    StdMarshalImpl * pStdMarshal = 
-        HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(StdMarshalImpl));
+    HRESULT hr;
+
+    StdMarshalImpl *pStdMarshal = HeapAlloc(GetProcessHeap(), 0, sizeof(StdMarshalImpl));
     if (!pStdMarshal)
         return E_OUTOFMEMORY;
-    pStdMarshal->lpvtbl = &VT_StdMarshal;
+
+    pStdMarshal->IMarshal_iface.lpVtbl = &StdMarshalVtbl;
     pStdMarshal->ref = 0;
-    return IMarshal_QueryInterface((IMarshal*)pStdMarshal, riid, ppvObject);
+    pStdMarshal->dest_context = dest_context;
+    pStdMarshal->dest_context_data = dest_context_data;
+
+    hr = IMarshal_QueryInterface(&pStdMarshal->IMarshal_iface, riid, ppvObject);
+    if (FAILED(hr))
+        HeapFree(GetProcessHeap(), 0, pStdMarshal);
+
+    return hr;
 }
 
 /***********************************************************************
@@ -1493,8 +1505,6 @@ HRESULT WINAPI CoGetStandardMarshal(REFIID riid, IUnknown *pUnk,
                                     DWORD dwDestContext, LPVOID pvDestContext,
                                     DWORD mshlflags, LPMARSHAL *ppMarshal)
 {
-    StdMarshalImpl *dm;
-
     if (pUnk == NULL)
     {
         FIXME("(%s,NULL,%x,%p,%x,%p), unimplemented yet.\n",
@@ -1503,17 +1513,8 @@ HRESULT WINAPI CoGetStandardMarshal(REFIID riid, IUnknown *pUnk,
     }
     TRACE("(%s,%p,%x,%p,%x,%p)\n",
         debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags,ppMarshal);
-    *ppMarshal = HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl));
-    dm = (StdMarshalImpl*) *ppMarshal;
-    if (!dm) return E_FAIL;
-    dm->lpvtbl         = &VT_StdMarshal;
-    dm->ref            = 1;
-
-    dm->iid            = *riid;
-    dm->dwDestContext  = dwDestContext;
-    dm->pvDestContext  = pvDestContext;
-    dm->mshlflags      = mshlflags;
-    return S_OK;
+
+    return StdMarshalImpl_Construct(&IID_IMarshal, dwDestContext, pvDestContext, (void**)ppMarshal);
 }
 
 /***********************************************************************
@@ -1570,7 +1571,7 @@ static HRESULT get_unmarshaler_from_stream(IStream *stream, IMarshal **marshal,
     if (objref.flags & OBJREF_STANDARD)
     {
         TRACE("Using standard unmarshaling\n");
-        hr = StdMarshalImpl_Construct(&IID_IMarshal, (LPVOID*)marshal);
+        hr = StdMarshalImpl_Construct(&IID_IMarshal, 0, NULL, (LPVOID*)marshal);
     }
     else if (objref.flags & OBJREF_CUSTOM)
     {
@@ -2007,7 +2008,7 @@ static HRESULT WINAPI StdMarshalCF_CreateInstance(LPCLASSFACTORY iface,
     LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
 {
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IMarshal))
-        return StdMarshalImpl_Construct(riid, ppv);
+        return StdMarshalImpl_Construct(riid, 0, NULL, ppv);
 
     FIXME("(%s), not supported.\n",debugstr_guid(riid));
     return E_NOINTERFACE;