home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 May / PCWorld_2001-05_cd.bin / Software / Vyzkuste / devc / _SETUP.5 / Group3 / rpcproxy.h < prev    next >
C/C++ Source or Header  |  1999-11-07  |  8KB  |  186 lines

  1. /*
  2.     -DREGISTER_PROXY_DLL Generates DllMain, DllRegisterServer, and DllUnregisterServer
  3.     -DPROXY_CLSID=clsid Specifies a class ID to be used by the proxy DLL.
  4.     -DPROXY_CLSID_IS={..} Specifies the class ID to be used by the proxy DLL.
  5.     -DNT35_STRICT No new features
  6. */
  7. #ifndef _RPCPROXY_H
  8. #define _RPCPROXY_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <rpc.h>
  13. #include <rpcndr.h>
  14. #include <string.h>
  15.  
  16. #define CStdStubBuffer_METHODS CStdStubBuffer_QueryInterface,CStdStubBuffer_AddRef,\
  17. CStdStubBuffer_Release,CStdStubBuffer_Connect,CStdStubBuffer_Disconnect,CStdStubBuffer_Invoke,\
  18. CStdStubBuffer_IsIIDSupported,CStdStubBuffer_CountRefs,CStdStubBuffer_DebugServerQueryInterface,\
  19. CStdStubBuffer_DebugServerRelease
  20. #define IID_GENERIC_CHECK_IID(name,pIID,index) memcmp(pIID,name##_ProxyVtblList[index]->header.piid,16)
  21. #define IID_BS_LOOKUP_SETUP int result, low=-1;
  22. #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; }
  23. #define IID_BS_LOOKUP_NEXT_TEST(name,split) if ((result = name##_CHECK_IID(low+split))>=0) { low=low+split; if (!result) goto found_label; }
  24. #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;
  25. #define REGISTER_PROXY_DLL_ROUTINES(pProxyFileList, pClsID) \
  26. HINSTANCE hProxyDll = 0; \
  27. BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) \
  28. { \
  29. if(fdwReason == DLL_PROCESS_ATTACH) hProxyDll = hinstDLL; \
  30. return TRUE; \
  31. } \
  32. HRESULT STDAPICALLTYPE DllRegisterServer() \
  33. {\
  34. return NdrDllRegisterProxy(hProxyDll, pProxyFileList, pClsID); \
  35. }\
  36. HRESULT STDAPICALLTYPE DllUnregisterServer()\
  37. {\
  38. return NdrDllUnregisterProxy(hProxyDll, pProxyFileList, pClsID);\
  39. }
  40. #ifdef PROXY_CLSID
  41. #define CLSID_PSFACTORYBUFFER extern CLSID PROXY_CLSID;
  42. #else
  43. #ifdef PROXY_CLSID_IS
  44. #define CLSID_PSFACTORYBUFFER const CLSID CLSID_PSFactoryBuffer = PROXY_CLSID_IS;
  45. #define PROXY_CLSID CLSID_PSFactoryBuffer
  46. #else
  47. #define CLSID_PSFACTORYBUFFER
  48. #endif
  49. #endif
  50. #ifndef PROXY_CLSID
  51. #define GET_DLL_CLSID (aProxyFileList[0]->pStubVtblList[0] != 0 ? aProxyFileList[0]->pStubVtblList[0]->header.piid : 0)
  52. #else
  53. #define GET_DLL_CLSID &PROXY_CLSID
  54. #endif
  55. #define EXTERN_PROXY_FILE(name) EXTERN_C const ProxyFileInfo name##_ProxyFileInfo;
  56. #define PROXYFILE_LIST_START const ProxyFileInfo * aProxyFileList[] = {
  57. #define REFERENCE_PROXY_FILE(name) & name##_ProxyFileInfo
  58. #define PROXYFILE_LIST_END 0 };
  59. #define DLLDATA_GETPROXYDLLINFO(pPFList,pClsid) \
  60. void RPC_ENTRY GetProxyDllInfo( const ProxyFileInfo*** pInfo, const CLSID ** pId ) \
  61. { *pInfo = pPFList; *pId = pClsid; };
  62. #define DLLGETCLASSOBJECTROUTINE(pPFlist, pClsid,pFactory) HRESULT STDAPICALLTYPE DllGetClassObject(REFCLSID rclsid,REFIID riid,void **ppv) \
  63. { return NdrDllGetClassObject(rclsid,riid,ppv,pPFlist,pClsid,pFactory ); }
  64. #define DLLCANUNLOADNOW(pFactory) HRESULT STDAPICALLTYPE DllCanUnloadNow() \
  65. { return NdrDllCanUnloadNow( pFactory ); }
  66. #define DLLDUMMYPURECALL void __cdecl _purecall(void) { }
  67. #define CSTDSTUBBUFFERRELEASE(pFactory) ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer *This) \
  68. { return NdrCStdStubBuffer_Release(This,(IPSFactoryBuffer *)pFactory); }
  69. #ifdef PROXY_DELEGATION
  70. #define CSTDSTUBBUFFER2RELEASE(pFactory) ULONG STDMETHODCALLTYPE CStdStubBuffer2_Release(IRpcStubBuffer *This) \
  71. { return NdrCStdStubBuffer2_Release(This,(IPSFactoryBuffer *)pFactory); }
  72. #else
  73. #define CSTDSTUBBUFFER2RELEASE(pFactory)
  74. #endif
  75.  
  76. #ifdef REGISTER_PROXY_DLL
  77. #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID ) REGISTER_PROXY_DLL_ROUTINES(pProxyFileList,pClsID)
  78. #else
  79. #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID)
  80. #endif
  81. #define DLLDATA_ROUTINES(pProxyFileList,pClsID) \
  82. CLSID_PSFACTORYBUFFER \
  83. CStdPSFactoryBuffer gPFactory = {0,0,0,0}; \
  84. DLLDATA_GETPROXYDLLINFO(pProxyFileList,pClsID) \
  85. DLLGETCLASSOBJECTROUTINE(pProxyFileList,pClsID,&gPFactory) \
  86. DLLCANUNLOADNOW(&gPFactory) \
  87. CSTDSTUBBUFFERRELEASE(&gPFactory) \
  88. CSTDSTUBBUFFER2RELEASE(&gPFactory) \
  89. DLLDUMMYPURECALL \
  90. DLLREGISTRY_ROUTINES(pProxyFileList, pClsID)
  91.  
  92. #define DLLDATA_STANDARD_ROUTINES DLLDATA_ROUTINES( (const ProxyFileInfo**) pProxyFileList, &CLSID_PSFactoryBuffer)
  93.  
  94. struct tagCInterfaceStubVtbl;
  95. struct tagCInterfaceProxyVtbl;
  96. typedef struct tagCInterfaceStubVtbl *PCInterfaceStubVtblList;
  97. typedef struct tagCInterfaceProxyVtbl *PCInterfaceProxyVtblList;
  98. typedef const char *PCInterfaceName;
  99. typedef int __stdcall IIDLookupRtn(const IID*,int*);
  100. typedef IIDLookupRtn *PIIDLookup;
  101. typedef struct tagProxyFileInfo {
  102.     const PCInterfaceProxyVtblList *pProxyVtblList;
  103.     const PCInterfaceStubVtblList *pStubVtblList;
  104.     const PCInterfaceName * pNamesArray;
  105.     const IID ** pDelegatedIIDs;
  106.     const PIIDLookup pIIDLookupRtn;
  107.     unsigned short TableSize;
  108.     unsigned short TableVersion;
  109.     unsigned long Filler1;
  110.     unsigned long Filler2;
  111.     unsigned long Filler3;
  112.     unsigned long Filler4;
  113. }ProxyFileInfo;
  114. typedef ProxyFileInfo ExtendedProxyFileInfo;
  115.  
  116. typedef struct tagCInterfaceProxyHeader {
  117. #ifdef USE_STUBLESS_PROXY
  118.     const void *pStublessProxyInfo;
  119. #endif
  120.     const IID *piid;
  121. } CInterfaceProxyHeader;
  122. typedef struct tagCInterfaceProxyVtbl {
  123.     CInterfaceProxyHeader header;
  124.     void *Vtbl[0];
  125. } CInterfaceProxyVtbl;
  126. typedef void (__RPC_STUB *PRPC_STUB_FUNCTION)(IRpcStubBuffer*,IRpcChannelBuffer*,PRPC_MESSAGE,DWORD*);
  127. typedef struct tagCInterfaceStubHeader {
  128.     const IID *piid;
  129.     const MIDL_SERVER_INFO *pServerInfo;
  130.     unsigned long DispatchTableCount;
  131.     const PRPC_STUB_FUNCTION *pDispatchTable;
  132. } CInterfaceStubHeader;
  133. typedef struct tagCInterfaceStubVtbl {
  134.     CInterfaceStubHeader header;
  135.     IRpcStubBufferVtbl Vtbl;
  136. } CInterfaceStubVtbl;
  137. typedef struct tagCStdStubBuffer {
  138.     const struct IRpcStubBufferVtbl * lpVtbl;
  139.     long RefCount;
  140.     struct IUnknown *pvServerObject;
  141. } CStdStubBuffer;
  142. typedef struct tagCStdPSFactoryBuffer {
  143.     const IPSFactoryBufferVtbl *lpVtbl;
  144.     long RefCount;
  145.     const ProxyFileInfo ** pProxyFileList;
  146.     long Filler1;
  147. } CStdPSFactoryBuffer;
  148. void RPC_ENTRY NdrProxyInitialize(void*,PRPC_MESSAGE,PMIDL_STUB_MESSAGE,PMIDL_STUB_DESC,unsigned int);
  149. void RPC_ENTRY NdrProxyGetBuffer(void*,PMIDL_STUB_MESSAGE);
  150. void RPC_ENTRY NdrProxySendReceive(void*,MIDL_STUB_MESSAGE*);
  151. void RPC_ENTRY NdrProxyFreeBuffer(void*,MIDL_STUB_MESSAGE*);
  152. HRESULT RPC_ENTRY NdrProxyErrorHandler(DWORD);
  153. void RPC_ENTRY NdrStubInitialize(PRPC_MESSAGE,PMIDL_STUB_MESSAGE,PMIDL_STUB_DESC,IRpcChannelBuffer*);
  154. void __RPC_STUB NdrStubForwardingFunction(IRpcStubBuffer*,IRpcChannelBuffer*,PRPC_MESSAGE,DWORD*);
  155. void RPC_ENTRY NdrStubGetBuffer(IRpcStubBuffer*,IRpcChannelBuffer*,PMIDL_STUB_MESSAGE);
  156. HRESULT RPC_ENTRY NdrStubErrorHandler(DWORD);
  157. HRESULT STDMETHODCALLTYPE CStdStubBuffer_QueryInterface(IRpcStubBuffer*,REFIID,void**);
  158. ULONG STDMETHODCALLTYPE CStdStubBuffer_AddRef(IRpcStubBuffer*);
  159. ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer*);
  160. ULONG STDMETHODCALLTYPE NdrCStdStubBuffer_Release(IRpcStubBuffer*,IPSFactoryBuffer*);
  161. HRESULT STDMETHODCALLTYPE CStdStubBuffer_Connect(IRpcStubBuffer*,IUnknown*);
  162. void STDMETHODCALLTYPE CStdStubBuffer_Disconnect(IRpcStubBuffer*);
  163. HRESULT STDMETHODCALLTYPE CStdStubBuffer_Invoke(IRpcStubBuffer*,RPCOLEMESSAGE*,IRpcChannelBuffer*);
  164. IRpcStubBuffer* STDMETHODCALLTYPE CStdStubBuffer_IsIIDSupported(IRpcStubBuffer*,REFIID);
  165. ULONG STDMETHODCALLTYPE CStdStubBuffer_CountRefs(IRpcStubBuffer*);
  166. HRESULT STDMETHODCALLTYPE CStdStubBuffer_DebugServerQueryInterface(IRpcStubBuffer*,void**);
  167. void STDMETHODCALLTYPE CStdStubBuffer_DebugServerRelease(IRpcStubBuffer*,void*);
  168. HRESULT RPC_ENTRY NdrDllGetClassObject(REFCLSID,REFIID,void**,const ProxyFileInfo**,const CLSID*,CStdPSFactoryBuffer*);
  169. HRESULT RPC_ENTRY NdrDllCanUnloadNow(CStdPSFactoryBuffer*);
  170. #ifndef NT35_STRICT
  171. HRESULT RPC_ENTRY NdrDllRegisterProxy(HMODULE,const ProxyFileInfo**,const CLSID*);
  172. HRESULT RPC_ENTRY NdrDllUnregisterProxy(HMODULE,const ProxyFileInfo**,const CLSID*);
  173. #define STUB_FORWARDING_FUNCTION NdrStubForwardingFunction
  174. ULONG STDMETHODCALLTYPE
  175. CStdStubBuffer2_Release(IRpcStubBuffer*);
  176. ULONG STDMETHODCALLTYPE
  177. NdrCStdStubBuffer2_Release(IRpcStubBuffer*,IPSFactoryBuffer*);
  178. #define CStdStubBuffer_DELEGATING_METHODS 0, 0, CStdStubBuffer2_Release, 0, 0, 0, 0, 0, 0, 0
  179. #endif
  180.  
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif
  185.  
  186.