1 /** 2 * @file rpcproxy.h 3 * Copyright 2012, 2013 MinGW.org project 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 */ 24 #ifndef _RPCPROXY_H 25 #define _RPCPROXY_H 26 #pragma GCC system_header 27 #include <_mingw.h> 28 29 /* 30 * -DREGISTER_PROXY_DLL Generates DllMain, DllRegisterServer, and 31 * DllUnregisterServer 32 * -DPROXY_CLSID=clsid Specifies a class ID to be used by the proxy DLL. 33 * -DPROXY_CLSID_IS={..} Specifies the class ID to be used by the proxy DLL. 34 * -DNT35_STRICT No new features 35 */ 36 37 #if defined __cplusplus && !defined CINTERFACE 38 #warning "rpcproxy type definitions require CINTERFACE" 39 40 #else 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 #include <rpc.h> 47 #include <rpcndr.h> 48 #include <string.h> 49 50 #define CStdStubBuffer_METHODS CStdStubBuffer_QueryInterface,CStdStubBuffer_AddRef,\ 51 CStdStubBuffer_Release,CStdStubBuffer_Connect,CStdStubBuffer_Disconnect,CStdStubBuffer_Invoke,\ 52 CStdStubBuffer_IsIIDSupported,CStdStubBuffer_CountRefs,CStdStubBuffer_DebugServerQueryInterface,\ 53 CStdStubBuffer_DebugServerRelease 54 #define IID_GENERIC_CHECK_IID(name,pIID,index) memcmp(pIID,name##_ProxyVtblList[index]->header.piid,16) 55 #define IID_BS_LOOKUP_SETUP int result, low=-1; 56 #define IID_BS_LOOKUP_INITIAL_TEST(name,sz,split) if ((result = name##_CHECK_IID(split))>0) { low=sz-split;} else if (!result) { low = split; goto found_label; } 57 #define IID_BS_LOOKUP_NEXT_TEST(name,split) if ((result = name##_CHECK_IID(low+split))>=0) { low=low+split; if (!result) goto found_label; } 58 #define IID_BS_LOOKUP_RETURN_RESULT(name,sz,index) low+=1; if ((low>=sz )||(result=name##_CHECK_IID(low))) goto not_found_label; found_label: (index)=low; return 1; not_found_label: return 0; 59 #define REGISTER_PROXY_DLL_ROUTINES(pProxyFileList, pClsID) \ 60 HINSTANCE hProxyDll = 0; \ 61 BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) \ 62 { \ 63 if(fdwReason == DLL_PROCESS_ATTACH) hProxyDll = hinstDLL; \ 64 return TRUE; \ 65 } \ 66 HRESULT STDAPICALLTYPE DllRegisterServer(void) \ 67 {\ 68 return NdrDllRegisterProxy(hProxyDll, pProxyFileList, pClsID); \ 69 }\ 70 HRESULT STDAPICALLTYPE DllUnregisterServer(void)\ 71 {\ 72 return NdrDllUnregisterProxy(hProxyDll, pProxyFileList, pClsID);\ 73 } 74 75 #ifdef PROXY_CLSID 76 #define CLSID_PSFACTORYBUFFER extern CLSID PROXY_CLSID; 77 #else 78 79 #ifdef PROXY_CLSID_IS 80 #define CLSID_PSFACTORYBUFFER const CLSID CLSID_PSFactoryBuffer = PROXY_CLSID_IS; 81 #define PROXY_CLSID CLSID_PSFactoryBuffer 82 83 #else 84 #define CLSID_PSFACTORYBUFFER 85 86 #endif 87 88 #endif 89 90 #ifndef PROXY_CLSID 91 #define GET_DLL_CLSID (aProxyFileList[0]->pStubVtblList[0] != 0 ? aProxyFileList[0]->pStubVtblList[0]->header.piid : 0) 92 #else 93 #define GET_DLL_CLSID &PROXY_CLSID 94 #endif 95 96 #define EXTERN_PROXY_FILE(name) EXTERN_C const ProxyFileInfo name##_ProxyFileInfo; 97 #define PROXYFILE_LIST_START const ProxyFileInfo * aProxyFileList[] = { 98 #define REFERENCE_PROXY_FILE(name) & name##_ProxyFileInfo 99 #define PROXYFILE_LIST_END 0 }; 100 #define DLLDATA_GETPROXYDLLINFO(pPFList,pClsid) \ 101 void RPC_ENTRY GetProxyDllInfo( const ProxyFileInfo*** pInfo, const CLSID ** pId ) \ 102 { *pInfo = pPFList; *pId = pClsid; }; 103 #define DLLGETCLASSOBJECTROUTINE(pPFlist, pClsid,pFactory) HRESULT STDAPICALLTYPE DllGetClassObject(REFCLSID rclsid,REFIID riid,void **ppv) \ 104 { return NdrDllGetClassObject(rclsid,riid,ppv,pPFlist,pClsid,pFactory ); } 105 #define DLLCANUNLOADNOW(pFactory) HRESULT STDAPICALLTYPE DllCanUnloadNow(void) \ 106 { return NdrDllCanUnloadNow( pFactory ); } 107 #define DLLDUMMYPURECALL void __cdecl _purecall(void) { } 108 #define CSTDSTUBBUFFERRELEASE(pFactory) ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer *This) \ 109 { return NdrCStdStubBuffer_Release(This,(IPSFactoryBuffer *)pFactory); } 110 111 #ifdef PROXY_DELEGATION 112 #define CSTDSTUBBUFFER2RELEASE(pFactory) ULONG STDMETHODCALLTYPE CStdStubBuffer2_Release(IRpcStubBuffer *This) \ 113 { return NdrCStdStubBuffer2_Release(This,(IPSFactoryBuffer *)pFactory); } 114 #else 115 #define CSTDSTUBBUFFER2RELEASE(pFactory) 116 #endif 117 118 #ifdef REGISTER_PROXY_DLL 119 #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID ) REGISTER_PROXY_DLL_ROUTINES(pProxyFileList,pClsID) 120 #else 121 #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID) 122 #endif 123 124 #define DLLDATA_ROUTINES(pProxyFileList,pClsID) \ 125 CLSID_PSFACTORYBUFFER \ 126 CStdPSFactoryBuffer gPFactory = {0,0,0,0}; \ 127 DLLDATA_GETPROXYDLLINFO(pProxyFileList,pClsID) \ 128 DLLGETCLASSOBJECTROUTINE(pProxyFileList,pClsID,&gPFactory) \ 129 DLLCANUNLOADNOW(&gPFactory) \ 130 CSTDSTUBBUFFERRELEASE(&gPFactory) \ 131 CSTDSTUBBUFFER2RELEASE(&gPFactory) \ 132 DLLDUMMYPURECALL \ 133 DLLREGISTRY_ROUTINES(pProxyFileList, pClsID) 134 135 #define DLLDATA_STANDARD_ROUTINES DLLDATA_ROUTINES( (const ProxyFileInfo**) pProxyFileList, &CLSID_PSFactoryBuffer) 136 137 struct tagCInterfaceStubVtbl; 138 struct tagCInterfaceProxyVtbl; 139 typedef struct tagCInterfaceStubVtbl *PCInterfaceStubVtblList; 140 typedef struct tagCInterfaceProxyVtbl *PCInterfaceProxyVtblList; 141 typedef const char *PCInterfaceName; 142 typedef int __stdcall IIDLookupRtn(const IID*,int*); 143 typedef IIDLookupRtn *PIIDLookup; 144 typedef struct tagProxyFileInfo { 145 const PCInterfaceProxyVtblList *pProxyVtblList; 146 const PCInterfaceStubVtblList *pStubVtblList; 147 const PCInterfaceName * pNamesArray; 148 const IID ** pDelegatedIIDs; 149 const PIIDLookup pIIDLookupRtn; 150 unsigned short TableSize; 151 unsigned short TableVersion; 152 unsigned long Filler1; 153 unsigned long Filler2; 154 unsigned long Filler3; 155 unsigned long Filler4; 156 }ProxyFileInfo; 157 typedef ProxyFileInfo ExtendedProxyFileInfo; 158 159 typedef struct tagCInterfaceProxyHeader { 160 161 #ifdef USE_STUBLESS_PROXY 162 const void *pStublessProxyInfo; 163 #endif 164 const IID *piid; 165 } CInterfaceProxyHeader; 166 typedef struct tagCInterfaceProxyVtbl { 167 CInterfaceProxyHeader header; 168 __extension__ void *Vtbl[0]; 169 } CInterfaceProxyVtbl; 170 171 typedef void (__RPC_STUB *PRPC_STUB_FUNCTION)(IRpcStubBuffer*,IRpcChannelBuffer*,PRPC_MESSAGE,DWORD*); 172 typedef struct tagCInterfaceStubHeader { 173 const IID *piid; 174 const MIDL_SERVER_INFO *pServerInfo; 175 unsigned long DispatchTableCount; 176 const PRPC_STUB_FUNCTION *pDispatchTable; 177 } CInterfaceStubHeader; 178 typedef struct tagCInterfaceStubVtbl { 179 CInterfaceStubHeader header; 180 IRpcStubBufferVtbl Vtbl; 181 } CInterfaceStubVtbl; 182 typedef struct tagCStdStubBuffer { 183 const struct IRpcStubBufferVtbl * lpVtbl; 184 long RefCount; 185 struct IUnknown *pvServerObject; 186 const struct ICallFactoryVtbl * pCallFactoryVtbl; 187 const IID * pAsyncIID; 188 struct IPSFactoryBuffer * pPSFactory; 189 const struct IReleaseMarshalBuffersVtbl * pRMBVtbl; 190 } CStdStubBuffer; 191 typedef struct tagCStdPSFactoryBuffer { 192 const IPSFactoryBufferVtbl *lpVtbl; 193 long RefCount; 194 const ProxyFileInfo ** pProxyFileList; 195 long Filler1; 196 } CStdPSFactoryBuffer; 197 void RPC_ENTRY NdrProxyInitialize(void*,PRPC_MESSAGE,PMIDL_STUB_MESSAGE,PMIDL_STUB_DESC,unsigned int); 198 void RPC_ENTRY NdrProxyGetBuffer(void*,PMIDL_STUB_MESSAGE); 199 void RPC_ENTRY NdrProxySendReceive(void*,MIDL_STUB_MESSAGE*); 200 void RPC_ENTRY NdrProxyFreeBuffer(void*,MIDL_STUB_MESSAGE*); 201 HRESULT RPC_ENTRY NdrProxyErrorHandler(DWORD); 202 void RPC_ENTRY NdrStubInitialize(PRPC_MESSAGE,PMIDL_STUB_MESSAGE,PMIDL_STUB_DESC,IRpcChannelBuffer*); 203 void __RPC_STUB NdrStubForwardingFunction(IRpcStubBuffer*,IRpcChannelBuffer*,PRPC_MESSAGE,DWORD*); 204 void RPC_ENTRY NdrStubGetBuffer(IRpcStubBuffer*,IRpcChannelBuffer*,PMIDL_STUB_MESSAGE); 205 HRESULT RPC_ENTRY NdrStubErrorHandler(DWORD); 206 HRESULT STDMETHODCALLTYPE CStdStubBuffer_QueryInterface(IRpcStubBuffer*,REFIID,void**); 207 ULONG STDMETHODCALLTYPE CStdStubBuffer_AddRef(IRpcStubBuffer*); 208 ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer*); 209 ULONG STDMETHODCALLTYPE NdrCStdStubBuffer_Release(IRpcStubBuffer*,IPSFactoryBuffer*); 210 HRESULT STDMETHODCALLTYPE CStdStubBuffer_Connect(IRpcStubBuffer*,IUnknown*); 211 void STDMETHODCALLTYPE CStdStubBuffer_Disconnect(IRpcStubBuffer*); 212 HRESULT STDMETHODCALLTYPE CStdStubBuffer_Invoke(IRpcStubBuffer*,RPCOLEMESSAGE*,IRpcChannelBuffer*); 213 IRpcStubBuffer* STDMETHODCALLTYPE CStdStubBuffer_IsIIDSupported(IRpcStubBuffer*,REFIID); 214 ULONG STDMETHODCALLTYPE CStdStubBuffer_CountRefs(IRpcStubBuffer*); 215 HRESULT STDMETHODCALLTYPE CStdStubBuffer_DebugServerQueryInterface(IRpcStubBuffer*,void**); 216 void STDMETHODCALLTYPE CStdStubBuffer_DebugServerRelease(IRpcStubBuffer*,void*); 217 HRESULT RPC_ENTRY NdrDllGetClassObject(REFCLSID,REFIID,void**,const ProxyFileInfo**,const CLSID*,CStdPSFactoryBuffer*); 218 HRESULT RPC_ENTRY NdrDllCanUnloadNow(CStdPSFactoryBuffer*); 219 220 #ifndef NT35_STRICT 221 HRESULT RPC_ENTRY NdrDllRegisterProxy(HMODULE,const ProxyFileInfo**,const CLSID*); 222 HRESULT RPC_ENTRY NdrDllUnregisterProxy(HMODULE,const ProxyFileInfo**,const CLSID*); 223 #define STUB_FORWARDING_FUNCTION NdrStubForwardingFunction 224 ULONG STDMETHODCALLTYPE 225 CStdStubBuffer2_Release(IRpcStubBuffer*); 226 ULONG STDMETHODCALLTYPE 227 NdrCStdStubBuffer2_Release(IRpcStubBuffer*,IPSFactoryBuffer*); 228 #define CStdStubBuffer_DELEGATING_METHODS 0, 0, CStdStubBuffer2_Release, 0, 0, 0, 0, 0, 0, 0 229 #endif 230 231 #ifdef __cplusplus 232 } 233 #endif 234 235 #endif /* defined __cplusplus && !defined CINTERFACE */ 236 237 #endif /* ndef _RPCPROXY_H */ 238 239