Implemented Rtl*ByteSwap() functions, based on a patch by Jon
[wine/multimedia.git] / dlls / rpcrt4 / cstub.c
blobd9f2c98fa88f53fcf60792fed48d602c4d6593d6
1 /*
2 * COM stub (CStdStubBuffer) implementation
4 * Copyright 2001 Ove Kåven, TransGaming Technologies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winerror.h"
25 #include "objbase.h"
27 #include "rpcproxy.h"
29 #include "wine/debug.h"
31 #include "cpsf.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ole);
35 #define STUB_HEADER(This) (((CInterfaceStubHeader*)((This)->lpVtbl))[-1])
37 HRESULT WINAPI CStdStubBuffer_Construct(REFIID riid,
38 LPUNKNOWN pUnkServer,
39 CInterfaceStubVtbl *vtbl,
40 LPPSFACTORYBUFFER pPSFactory,
41 LPRPCSTUBBUFFER *ppStub)
43 CStdStubBuffer *This;
45 TRACE("(%p,%p,%p,%p)\n", pUnkServer, vtbl, pPSFactory, ppStub);
46 TRACE("iid=%s\n", debugstr_guid(vtbl->header.piid));
47 TRACE("vtbl=%p\n", &vtbl->Vtbl);
49 if (!IsEqualGUID(vtbl->header.piid, riid)) {
50 ERR("IID mismatch during stub creation\n");
51 return RPC_E_UNEXPECTED;
54 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CStdStubBuffer));
55 if (!This) return E_OUTOFMEMORY;
57 This->lpVtbl = &vtbl->Vtbl;
58 This->RefCount = 1;
59 This->pvServerObject = pUnkServer;
60 This->pPSFactory = pPSFactory;
61 *ppStub = (LPRPCSTUBBUFFER)This;
63 IPSFactoryBuffer_AddRef(pPSFactory);
64 return S_OK;
67 HRESULT WINAPI CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface,
68 REFIID riid,
69 LPVOID *obj)
71 ICOM_THIS(CStdStubBuffer,iface);
72 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
74 if (IsEqualGUID(&IID_IUnknown,riid) ||
75 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
76 *obj = This;
77 This->RefCount++;
78 return S_OK;
80 return E_NOINTERFACE;
83 ULONG WINAPI CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface)
85 ICOM_THIS(CStdStubBuffer,iface);
86 TRACE("(%p)->AddRef()\n",This);
87 return ++(This->RefCount);
90 ULONG WINAPI NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface,
91 LPPSFACTORYBUFFER pPSF)
93 ICOM_THIS(CStdStubBuffer,iface);
94 TRACE("(%p)->Release()\n",This);
96 if (!--(This->RefCount)) {
97 if(This->pvServerObject)
98 IUnknown_Release(This->pvServerObject);
99 if(This->pPSFactory)
100 IPSFactoryBuffer_Release(This->pPSFactory);
101 HeapFree(GetProcessHeap(),0,This);
102 return 0;
104 return This->RefCount;
107 HRESULT WINAPI CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface,
108 LPUNKNOWN lpUnkServer)
110 ICOM_THIS(CStdStubBuffer,iface);
111 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
112 This->pvServerObject = lpUnkServer;
113 return S_OK;
116 void WINAPI CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface)
118 ICOM_THIS(CStdStubBuffer,iface);
119 TRACE("(%p)->Disconnect()\n",This);
120 This->pvServerObject = NULL;
123 HRESULT WINAPI CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface,
124 PRPCOLEMESSAGE pMsg,
125 LPRPCCHANNELBUFFER pChannel)
127 ICOM_THIS(CStdStubBuffer,iface);
128 DWORD dwPhase = STUB_UNMARSHAL;
129 TRACE("(%p)->Invoke(%p,%p)\n",This,pMsg,pChannel);
131 STUB_HEADER(This).pDispatchTable[pMsg->iMethod](iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
132 return S_OK;
135 LPRPCSTUBBUFFER WINAPI CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface,
136 REFIID riid)
138 ICOM_THIS(CStdStubBuffer,iface);
139 TRACE("(%p)->IsIIDSupported(%s)\n",This,debugstr_guid(riid));
140 return IsEqualGUID(STUB_HEADER(This).piid, riid) ? iface : NULL;
143 ULONG WINAPI CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface)
145 ICOM_THIS(CStdStubBuffer,iface);
146 TRACE("(%p)->CountRefs()\n",This);
147 return This->RefCount;
150 HRESULT WINAPI CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
151 LPVOID *ppv)
153 ICOM_THIS(CStdStubBuffer,iface);
154 TRACE("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
155 return S_OK;
158 void WINAPI CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface,
159 LPVOID pv)
161 ICOM_THIS(CStdStubBuffer,iface);
162 TRACE("(%p)->DebugServerRelease(%p)\n",This,pv);