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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
34 #include "wine/exception.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40 #define STUB_HEADER(This) (((CInterfaceStubHeader*)((This)->lpVtbl))[-1])
42 static WINE_EXCEPTION_FILTER(stub_filter)
44 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
45 return EXCEPTION_CONTINUE_SEARCH;
46 return EXCEPTION_EXECUTE_HANDLER;
49 HRESULT WINAPI CStdStubBuffer_Construct(REFIID riid,
52 CInterfaceStubVtbl *vtbl,
53 LPPSFACTORYBUFFER pPSFactory,
54 LPRPCSTUBBUFFER *ppStub)
58 TRACE("(%p,%p,%p,%p) %s\n", pUnkServer, vtbl, pPSFactory, ppStub, name);
59 TRACE("iid=%s\n", debugstr_guid(vtbl->header.piid));
60 TRACE("vtbl=%p\n", &vtbl->Vtbl);
62 if (!IsEqualGUID(vtbl->header.piid, riid)) {
63 ERR("IID mismatch during stub creation\n");
64 return RPC_E_UNEXPECTED;
67 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CStdStubBuffer));
68 if (!This) return E_OUTOFMEMORY;
70 This->lpVtbl = &vtbl->Vtbl;
72 This->pvServerObject = pUnkServer;
73 This->pPSFactory = pPSFactory;
74 *ppStub = (LPRPCSTUBBUFFER)This;
76 IUnknown_AddRef(This->pvServerObject);
77 IPSFactoryBuffer_AddRef(pPSFactory);
81 HRESULT WINAPI CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface,
85 CStdStubBuffer *This = (CStdStubBuffer *)iface;
86 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
88 if (IsEqualGUID(&IID_IUnknown,riid) ||
89 IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
97 ULONG WINAPI CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface)
99 CStdStubBuffer *This = (CStdStubBuffer *)iface;
100 TRACE("(%p)->AddRef()\n",This);
101 return ++(This->RefCount);
104 ULONG WINAPI NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface,
105 LPPSFACTORYBUFFER pPSF)
107 CStdStubBuffer *This = (CStdStubBuffer *)iface;
108 TRACE("(%p)->Release()\n",This);
110 if (!--(This->RefCount)) {
111 IRpcStubBuffer_Disconnect(iface);
113 IPSFactoryBuffer_Release(This->pPSFactory);
114 HeapFree(GetProcessHeap(),0,This);
117 return This->RefCount;
120 ULONG WINAPI NdrCStdStubBuffer2_Release(LPRPCSTUBBUFFER iface,
121 LPPSFACTORYBUFFER pPSF)
123 FIXME("Not implemented\n");
127 HRESULT WINAPI CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface,
128 LPUNKNOWN lpUnkServer)
130 CStdStubBuffer *This = (CStdStubBuffer *)iface;
131 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
132 This->pvServerObject = lpUnkServer;
136 void WINAPI CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface)
138 CStdStubBuffer *This = (CStdStubBuffer *)iface;
139 TRACE("(%p)->Disconnect()\n",This);
140 if (This->pvServerObject)
142 IUnknown_Release(This->pvServerObject);
143 This->pvServerObject = NULL;
147 HRESULT WINAPI CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface,
149 LPRPCCHANNELBUFFER pChannel)
151 CStdStubBuffer *This = (CStdStubBuffer *)iface;
152 DWORD dwPhase = STUB_UNMARSHAL;
155 TRACE("(%p)->Invoke(%p,%p)\n",This,pMsg,pChannel);
159 if (STUB_HEADER(This).pDispatchTable)
160 STUB_HEADER(This).pDispatchTable[pMsg->iMethod](iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
161 else /* pure interpreted */
162 NdrStubCall2(iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
164 __EXCEPT(stub_filter)
166 DWORD dwExceptionCode = GetExceptionCode();
167 WARN("a stub call failed with exception 0x%08lx (%ld)\n", dwExceptionCode, dwExceptionCode);
168 if (FAILED(dwExceptionCode))
169 hr = dwExceptionCode;
171 hr = HRESULT_FROM_WIN32(dwExceptionCode);
178 LPRPCSTUBBUFFER WINAPI CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface,
181 CStdStubBuffer *This = (CStdStubBuffer *)iface;
182 TRACE("(%p)->IsIIDSupported(%s)\n",This,debugstr_guid(riid));
183 return IsEqualGUID(STUB_HEADER(This).piid, riid) ? iface : NULL;
186 ULONG WINAPI CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface)
188 CStdStubBuffer *This = (CStdStubBuffer *)iface;
189 TRACE("(%p)->CountRefs()\n",This);
190 return This->RefCount;
193 HRESULT WINAPI CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
196 CStdStubBuffer *This = (CStdStubBuffer *)iface;
197 TRACE("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
201 void WINAPI CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface,
204 CStdStubBuffer *This = (CStdStubBuffer *)iface;
205 TRACE("(%p)->DebugServerRelease(%p)\n",This,pv);
208 const IRpcStubBufferVtbl CStdStubBuffer_Vtbl =
210 CStdStubBuffer_QueryInterface,
211 CStdStubBuffer_AddRef,
213 CStdStubBuffer_Connect,
214 CStdStubBuffer_Disconnect,
215 CStdStubBuffer_Invoke,
216 CStdStubBuffer_IsIIDSupported,
217 CStdStubBuffer_CountRefs,
218 CStdStubBuffer_DebugServerQueryInterface,
219 CStdStubBuffer_DebugServerRelease
222 const MIDL_SERVER_INFO *CStdStubBuffer_GetServerInfo(IRpcStubBuffer *iface)
224 CStdStubBuffer *This = (CStdStubBuffer *)iface;
225 return STUB_HEADER(This).pServerInfo;