📄 cstub.c
字号:
} This->stub_buffer.lpVtbl = &vtbl->Vtbl; This->stub_buffer.RefCount = 1; This->stub_buffer.pvServerObject = pvServer; This->stub_buffer.pPSFactory = pPSFactory; *ppStub = (LPRPCSTUBBUFFER)&This->stub_buffer; IPSFactoryBuffer_AddRef(pPSFactory); return S_OK;}HRESULT WINAPI CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *obj){ CStdStubBuffer *This = (CStdStubBuffer *)iface; TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj); if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IRpcStubBuffer, riid)) { IUnknown_AddRef(iface); *obj = iface; return S_OK; } *obj = NULL; return E_NOINTERFACE;}ULONG WINAPI CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface){ CStdStubBuffer *This = (CStdStubBuffer *)iface; TRACE("(%p)->AddRef()\n",This); return InterlockedIncrement(&This->RefCount);}ULONG WINAPI NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface, LPPSFACTORYBUFFER pPSF){ CStdStubBuffer *This = (CStdStubBuffer *)iface; ULONG refs; TRACE("(%p)->Release()\n",This); refs = InterlockedDecrement(&This->RefCount); if (!refs) { /* test_Release shows that native doesn't call Disconnect here. We'll leave it in for the time being. */ IRpcStubBuffer_Disconnect(iface); IPSFactoryBuffer_Release(pPSF); HeapFree(GetProcessHeap(),0,This); } return refs;}ULONG WINAPI NdrCStdStubBuffer2_Release(LPRPCSTUBBUFFER iface, LPPSFACTORYBUFFER pPSF){ cstdstubbuffer_delegating_t *This = impl_from_delegating( iface ); ULONG refs; TRACE("(%p)->Release()\n", This); refs = InterlockedDecrement(&This->stub_buffer.RefCount); if (!refs) { /* Just like NdrCStdStubBuffer_Release, we shouldn't call Disconnect here */ IRpcStubBuffer_Disconnect((IRpcStubBuffer *)&This->stub_buffer); IRpcStubBuffer_Release(This->base_stub); release_delegating_vtbl(This->base_obj); IPSFactoryBuffer_Release(pPSF); HeapFree(GetProcessHeap(), 0, This); } return refs;}HRESULT WINAPI CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN lpUnkServer){ CStdStubBuffer *This = (CStdStubBuffer *)iface; HRESULT r; IUnknown *new = NULL; TRACE("(%p)->Connect(%p)\n",This,lpUnkServer); r = IUnknown_QueryInterface(lpUnkServer, STUB_HEADER(This).piid, (void**)&new); new = InterlockedExchangePointer((void**)&This->pvServerObject, new); if(new) IUnknown_Release(new); return r;}void WINAPI CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface){ CStdStubBuffer *This = (CStdStubBuffer *)iface; IUnknown *old; TRACE("(%p)->Disconnect()\n",This); old = InterlockedExchangePointer((void**)&This->pvServerObject, NULL); if(old) IUnknown_Release(old);}HRESULT WINAPI CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface, PRPCOLEMESSAGE pMsg, LPRPCCHANNELBUFFER pChannel){ CStdStubBuffer *This = (CStdStubBuffer *)iface; DWORD dwPhase = STUB_UNMARSHAL; HRESULT hr = S_OK; TRACE("(%p)->Invoke(%p,%p)\n",This,pMsg,pChannel); __TRY { if (STUB_HEADER(This).pDispatchTable) STUB_HEADER(This).pDispatchTable[pMsg->iMethod](iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase); else /* pure interpreted */ NdrStubCall2(iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase); } __EXCEPT(stub_filter) { DWORD dwExceptionCode = GetExceptionCode(); WARN("a stub call failed with exception 0x%08x (%d)\n", dwExceptionCode, dwExceptionCode); if (FAILED(dwExceptionCode)) hr = dwExceptionCode; else hr = HRESULT_FROM_WIN32(dwExceptionCode); } __ENDTRY return hr;}LPRPCSTUBBUFFER WINAPI CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface, REFIID riid){ CStdStubBuffer *This = (CStdStubBuffer *)iface; TRACE("(%p)->IsIIDSupported(%s)\n",This,debugstr_guid(riid)); return IsEqualGUID(STUB_HEADER(This).piid, riid) ? iface : NULL;}ULONG WINAPI CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface){ CStdStubBuffer *This = (CStdStubBuffer *)iface; TRACE("(%p)->CountRefs()\n",This); return This->RefCount;}HRESULT WINAPI CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface, LPVOID *ppv){ CStdStubBuffer *This = (CStdStubBuffer *)iface; TRACE("(%p)->DebugServerQueryInterface(%p)\n",This,ppv); return S_OK;}void WINAPI CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface, LPVOID pv){ CStdStubBuffer *This = (CStdStubBuffer *)iface; TRACE("(%p)->DebugServerRelease(%p)\n",This,pv);}const IRpcStubBufferVtbl CStdStubBuffer_Vtbl ={ CStdStubBuffer_QueryInterface, CStdStubBuffer_AddRef, NULL, CStdStubBuffer_Connect, CStdStubBuffer_Disconnect, CStdStubBuffer_Invoke, CStdStubBuffer_IsIIDSupported, CStdStubBuffer_CountRefs, CStdStubBuffer_DebugServerQueryInterface, CStdStubBuffer_DebugServerRelease};static HRESULT WINAPI CStdStubBuffer_Delegating_Connect(LPRPCSTUBBUFFER iface, LPUNKNOWN lpUnkServer){ cstdstubbuffer_delegating_t *This = impl_from_delegating(iface); HRESULT r; TRACE("(%p)->Connect(%p)\n", This, lpUnkServer); r = CStdStubBuffer_Connect(iface, lpUnkServer); if(SUCCEEDED(r)) r = IRpcStubBuffer_Connect(This->base_stub, (IUnknown*)&This->base_obj); return r;}static void WINAPI CStdStubBuffer_Delegating_Disconnect(LPRPCSTUBBUFFER iface){ cstdstubbuffer_delegating_t *This = impl_from_delegating(iface); TRACE("(%p)->Disconnect()\n", This); IRpcStubBuffer_Disconnect(This->base_stub); CStdStubBuffer_Disconnect(iface);}static ULONG WINAPI CStdStubBuffer_Delegating_CountRefs(LPRPCSTUBBUFFER iface){ cstdstubbuffer_delegating_t *This = impl_from_delegating(iface); ULONG ret; TRACE("(%p)->CountRefs()\n", This); ret = CStdStubBuffer_CountRefs(iface); ret += IRpcStubBuffer_CountRefs(This->base_stub); return ret;}const IRpcStubBufferVtbl CStdStubBuffer_Delegating_Vtbl ={ CStdStubBuffer_QueryInterface, CStdStubBuffer_AddRef, NULL, CStdStubBuffer_Delegating_Connect, CStdStubBuffer_Delegating_Disconnect, CStdStubBuffer_Invoke, CStdStubBuffer_IsIIDSupported, CStdStubBuffer_Delegating_CountRefs, CStdStubBuffer_DebugServerQueryInterface, CStdStubBuffer_DebugServerRelease};const MIDL_SERVER_INFO *CStdStubBuffer_GetServerInfo(IRpcStubBuffer *iface){ CStdStubBuffer *This = (CStdStubBuffer *)iface; return STUB_HEADER(This).pServerInfo;}/************************************************************************ * NdrStubForwardingFunction [RPCRT4.@] */void __RPC_STUB NdrStubForwardingFunction( IRpcStubBuffer *iface, IRpcChannelBuffer *pChannel, PRPC_MESSAGE pMsg, DWORD *pdwStubPhase ){ /* Note pMsg is passed intact since RPCOLEMESSAGE is basically a RPC_MESSAGE. */ cstdstubbuffer_delegating_t *This = impl_from_delegating(iface); HRESULT r = IRpcStubBuffer_Invoke(This->base_stub, (RPCOLEMESSAGE*)pMsg, pChannel); if(FAILED(r)) RpcRaiseException(r); return;}/*********************************************************************** * NdrStubInitialize [RPCRT4.@] */void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg, PMIDL_STUB_DESC pStubDescriptor, LPRPCCHANNELBUFFER pRpcChannelBuffer){ TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer); NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor); pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;}/*********************************************************************** * NdrStubGetBuffer [RPCRT4.@] */void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER iface, LPRPCCHANNELBUFFER pRpcChannelBuffer, PMIDL_STUB_MESSAGE pStubMsg){ CStdStubBuffer *This = (CStdStubBuffer *)iface; HRESULT hr; TRACE("(%p, %p, %p)\n", This, pRpcChannelBuffer, pStubMsg); pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength; hr = IRpcChannelBuffer_GetBuffer(pRpcChannelBuffer, (RPCOLEMESSAGE *)pStubMsg->RpcMsg, STUB_HEADER(This).piid); if (FAILED(hr)) { RpcRaiseException(hr); return; } pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer; pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength; pStubMsg->Buffer = pStubMsg->BufferStart;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -