home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / msinc.pak / RPCPROXY.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  16KB  |  537 lines

  1. /*++
  2.  
  3. Copyright (c) 1992-1995 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     rpcproxy.h
  8.  
  9. Abstract:
  10.  
  11.     Definitions for rpc proxy  stubs. 
  12.  
  13. Compiler switches:
  14.  
  15.     -DREGISTER_PROXY_DLL 
  16.         Generates DllMain, DllRegisterServer, and DllUnregisterServer functions
  17.         for automatically registering a proxy DLL.
  18.  
  19.     -DPROXY_CLSID=clsid
  20.         Specifies a class ID to be used by the proxy DLL.
  21.  
  22.     -DPROXY_CLSID_IS={0x6f11fe5c,0x2fc5,0x101b,{0x9e,0x45,0x00,0x00,0x0b,0x65,0xc7,0xef}}
  23.         Specifies the value of the class ID to be used by the proxy DLL.
  24.  
  25.     -DNT35_STRICT 
  26.         Specifies that the target platform is Windows NT 3.5. This switch disables
  27.         the new functions added after the Windows NT 3.5 release.
  28.  
  29. --*/
  30.  
  31. #ifndef __RPCPROXY_H__
  32. #define __RPCPROXY_H__
  33. #define __midl_proxy
  34.  
  35. #ifndef INC_OLE2
  36. #define INC_OLE2
  37. #endif
  38.  
  39. #if !defined(__RPC_DOS__) && !defined(__RPC_WIN16__)
  40.  
  41. //We need to define REFIID, REFCLSID and REFGUID here so that the
  42. //proxy code won't get the const GUID *const definition.
  43. #ifndef GUID_DEFINED
  44. #define GUID_DEFINED
  45. typedef struct _GUID
  46. {
  47.     unsigned long Data1;
  48.     unsigned short Data2;
  49.     unsigned short Data3;
  50.     unsigned char Data4[8];
  51. } GUID;
  52. #endif /* GUID_DEFINED */
  53.  
  54. #if !defined( __IID_DEFINED__ )
  55.     #define __IID_DEFINED__
  56.  
  57.     typedef GUID IID;
  58.     typedef IID *LPIID;
  59.     #define IID_NULL            GUID_NULL
  60.     #define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
  61.     typedef GUID CLSID;
  62.     typedef CLSID *LPCLSID;
  63.     #define CLSID_NULL          GUID_NULL
  64.     #define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
  65.  
  66.     #ifndef _REFGUID_DEFINED
  67.         #define _REFGUID_DEFINED
  68.         typedef const GUID *REFGUID;
  69.     #endif // !_REFGUID_DEFINED
  70.  
  71.     #ifndef _REFIID_DEFINED
  72.         #define _REFIID_DEFINED
  73.         typedef const IID *REFIID;
  74.     #endif // !_REFIID_DEFINED
  75.  
  76.     #ifndef _REFCLSID_DEFINED
  77.         #define _REFCLSID_DEFINED
  78.         typedef const CLSID *REFCLSID;
  79.     #endif // !_REFCLSID_DEFINED
  80.  
  81. #endif // !__IID_DEFINED__
  82.  
  83. // forward declarations
  84. struct tagCInterfaceStubVtbl;
  85. struct tagCInterfaceProxyVtbl;
  86.  
  87. typedef struct tagCInterfaceStubVtbl *  PCInterfaceStubVtblList;
  88. typedef struct tagCInterfaceProxyVtbl *  PCInterfaceProxyVtblList;
  89. typedef const char *                    PCInterfaceName;
  90. typedef int __stdcall IIDLookupRtn( const IID * pIID, int * pIndex );
  91. typedef IIDLookupRtn * PIIDLookup;
  92.  
  93. // pointers to arrays of CInterfaceProxyVtbl's and CInterfaceStubVtbls
  94. typedef struct tagProxyFileInfo
  95. {
  96.     const PCInterfaceProxyVtblList *pProxyVtblList;
  97.     const PCInterfaceStubVtblList *pStubVtblList;
  98.     const PCInterfaceName *     pNamesArray;
  99.     const IID **                pDelegatedIIDs;
  100.     const PIIDLookup            pIIDLookupRtn;
  101.     unsigned short              TableSize;
  102.     unsigned short              TableVersion;
  103.     unsigned long               Filler1;
  104.     unsigned long               Filler2;
  105.     unsigned long               Filler3;
  106.     unsigned long               Filler4;
  107. }ProxyFileInfo;
  108.  
  109. // extended info with list of interface names
  110. typedef ProxyFileInfo ExtendedProxyFileInfo;
  111.  
  112. #include <rpc.h>
  113. #include <rpcndr.h>
  114. #include <string.h>
  115. #include <memory.h>
  116.  
  117. typedef struct tagCInterfaceProxyHeader
  118. {
  119.     //
  120.     // New fields should be added here, at the beginning of the structure.
  121.     //
  122. #ifdef USE_STUBLESS_PROXY
  123.     const void *    pStublessProxyInfo;
  124. #endif
  125.     const IID *     piid;
  126. } CInterfaceProxyHeader;
  127.  
  128. #pragma warning( disable:4200 )
  129. typedef struct tagCInterfaceProxyVtbl
  130. {
  131.     CInterfaceProxyHeader header;
  132.     void *Vtbl[];
  133. } CInterfaceProxyVtbl;
  134. #pragma warning( default:4200 )
  135.  
  136. typedef
  137. void
  138. (__RPC_STUB __RPC_FAR * PRPC_STUB_FUNCTION) (
  139.     IRpcStubBuffer *This,
  140.     IRpcChannelBuffer * _pRpcChannelBuffer,
  141.     PRPC_MESSAGE _pRpcMessage,
  142.     DWORD __RPC_FAR *pdwStubPhase);
  143.  
  144. typedef struct tagCInterfaceStubHeader
  145. {
  146.     //New fields should be added here, at the beginning of the structure.
  147.     const IID *piid;
  148.     const MIDL_SERVER_INFO *pServerInfo;
  149.     unsigned long DispatchTableCount;
  150.     const PRPC_STUB_FUNCTION *pDispatchTable;
  151. } CInterfaceStubHeader;
  152.  
  153. typedef struct tagCInterfaceStubVtbl
  154. {
  155.     CInterfaceStubHeader header;
  156.     IRpcStubBufferVtbl Vtbl;
  157. } CInterfaceStubVtbl;
  158.  
  159. typedef struct tagCStdStubBuffer
  160. {
  161.     const struct IRpcStubBufferVtbl *   lpVtbl; //Points to Vtbl field in CInterfaceStubVtbl.
  162.     long                                RefCount;
  163.     struct IUnknown *                   pvServerObject;
  164. } CStdStubBuffer;
  165.  
  166. typedef struct tagCStdPSFactoryBuffer
  167. {
  168.     const IPSFactoryBufferVtbl *lpVtbl;
  169.     long                    RefCount;
  170.     const ProxyFileInfo **  pProxyFileList;
  171.     long                    Filler1;  //Reserved for future use.
  172. } CStdPSFactoryBuffer;
  173.  
  174. void RPC_ENTRY
  175. NdrProxyInitialize(
  176.     void *              This,
  177.     PRPC_MESSAGE        pRpcMsg, 
  178.     PMIDL_STUB_MESSAGE  pStubMsg,
  179.     PMIDL_STUB_DESC     pStubDescriptor,
  180.     unsigned int        ProcNum );
  181.  
  182. void RPC_ENTRY
  183. NdrProxyGetBuffer(
  184.     void *              This,
  185.     PMIDL_STUB_MESSAGE pStubMsg);
  186.  
  187. void RPC_ENTRY
  188. NdrProxySendReceive(
  189.     void                *This,
  190.     MIDL_STUB_MESSAGE   *pStubMsg);
  191.  
  192. void RPC_ENTRY
  193. NdrProxyFreeBuffer(
  194.     void                *This,
  195.     MIDL_STUB_MESSAGE   *pStubMsg);
  196.  
  197. HRESULT RPC_ENTRY
  198. NdrProxyErrorHandler(
  199.     DWORD dwExceptionCode);
  200.  
  201. void RPC_ENTRY
  202. NdrStubInitialize(
  203.     PRPC_MESSAGE        pRpcMsg, 
  204.     PMIDL_STUB_MESSAGE  pStubMsg, 
  205.     PMIDL_STUB_DESC     pStubDescriptor,
  206.     IRpcChannelBuffer * pRpcChannelBuffer);
  207.  
  208. void __RPC_STUB NdrStubForwardingFunction(
  209.     IN  IRpcStubBuffer *    This,
  210.     IN  IRpcChannelBuffer * pChannel,
  211.     IN  PRPC_MESSAGE        pmsg,
  212.     OUT DWORD __RPC_FAR *   pdwStubPhase);
  213.  
  214. void RPC_ENTRY
  215. NdrStubGetBuffer(
  216.     IRpcStubBuffer *    This,
  217.     IRpcChannelBuffer * pRpcChannelBuffer, 
  218.     PMIDL_STUB_MESSAGE  pStubMsg);
  219.  
  220. HRESULT RPC_ENTRY
  221. NdrStubErrorHandler(
  222.     DWORD dwExceptionCode);
  223.  
  224. HRESULT STDMETHODCALLTYPE
  225. CStdStubBuffer_QueryInterface(
  226.     IRpcStubBuffer *This, 
  227.     REFIID riid, 
  228.     void **ppvObject);
  229.  
  230. ULONG STDMETHODCALLTYPE
  231. CStdStubBuffer_AddRef(
  232.     IRpcStubBuffer *This);
  233.  
  234. ULONG STDMETHODCALLTYPE
  235. CStdStubBuffer_Release(
  236.     IRpcStubBuffer *This);
  237.  
  238. ULONG STDMETHODCALLTYPE
  239. NdrCStdStubBuffer_Release(
  240.     IRpcStubBuffer *This,
  241.     IPSFactoryBuffer * pPSF);
  242.  
  243. HRESULT STDMETHODCALLTYPE
  244. CStdStubBuffer_Connect(
  245.     IRpcStubBuffer *This, 
  246.     IUnknown *pUnkServer);
  247.  
  248. void STDMETHODCALLTYPE
  249. CStdStubBuffer_Disconnect(
  250.     IRpcStubBuffer *This);
  251.  
  252. HRESULT STDMETHODCALLTYPE
  253. CStdStubBuffer_Invoke(
  254.     IRpcStubBuffer *This,
  255.     RPCOLEMESSAGE *pRpcMsg,
  256.     IRpcChannelBuffer *pRpcChannelBuffer);
  257.  
  258. IRpcStubBuffer * STDMETHODCALLTYPE
  259. CStdStubBuffer_IsIIDSupported(
  260.     IRpcStubBuffer *This,
  261.     REFIID riid);
  262.  
  263. ULONG STDMETHODCALLTYPE
  264. CStdStubBuffer_CountRefs(
  265.     IRpcStubBuffer *This);
  266.  
  267. HRESULT STDMETHODCALLTYPE
  268. CStdStubBuffer_DebugServerQueryInterface(
  269.     IRpcStubBuffer *This, 
  270.     void **ppv);
  271.  
  272. void STDMETHODCALLTYPE
  273. CStdStubBuffer_DebugServerRelease(
  274.     IRpcStubBuffer *This,
  275.     void *pv);
  276.  
  277. #define CStdStubBuffer_METHODS \
  278.     CStdStubBuffer_QueryInterface,\
  279.     CStdStubBuffer_AddRef, \
  280.     CStdStubBuffer_Release, \
  281.     CStdStubBuffer_Connect, \
  282.     CStdStubBuffer_Disconnect, \
  283.     CStdStubBuffer_Invoke, \
  284.     CStdStubBuffer_IsIIDSupported, \
  285.     CStdStubBuffer_CountRefs, \
  286.     CStdStubBuffer_DebugServerQueryInterface, \
  287.     CStdStubBuffer_DebugServerRelease
  288.  
  289. //+-------------------------------------------------------------------------
  290. //
  291. //  Macro definitions for the proxy file
  292. //
  293. //--------------------------------------------------------------------------
  294.  
  295. #define IID_GENERIC_CHECK_IID(name,pIID,index) memcmp( pIID, name##_ProxyVtblList[ index ]->header.piid, 16 )
  296.  
  297. #define IID_BS_LOOKUP_SETUP     int result, low=-1;
  298.  
  299. #define IID_BS_LOOKUP_INITIAL_TEST(name, sz, split)   \
  300.     if ( ( result = name##_CHECK_IID( split ) ) > 0 ) \
  301.         { low = sz - split; }                      \
  302.     else if ( !result )                               \
  303.         { low = split; goto found_label; }
  304.  
  305. #define IID_BS_LOOKUP_NEXT_TEST(name, split )         \
  306.     if ( ( result = name##_CHECK_IID( low + split )) >= 0 )  \
  307.         { low = low + split; if ( !result ) goto found_label; }
  308.  
  309. #define IID_BS_LOOKUP_RETURN_RESULT(name, sz, index )                  \
  310.     low = low + 1;                                          \
  311.     if ( ( low >= sz ) || (result = name##_CHECK_IID( low ) )) goto not_found_label; \
  312.     found_label: (index) = low; return 1;                         \
  313.     not_found_label: return 0;
  314.  
  315. //+-------------------------------------------------------------------------
  316. //
  317. //  Macro and routine definitions for the dlldata file
  318. //
  319. //--------------------------------------------------------------------------
  320.  
  321. /****************************************************************************
  322.  * Proxy Dll APIs
  323.  ****************************************************************************/
  324.  
  325. HRESULT RPC_ENTRY 
  326. NdrDllGetClassObject (
  327.     IN  REFCLSID                rclsid,
  328.     IN  REFIID                  riid,
  329.     OUT void **                 ppv,
  330.     IN const ProxyFileInfo **   pProxyFileList, 
  331.     IN const CLSID *            pclsid,
  332.     IN CStdPSFactoryBuffer *    pPSFactoryBuffer);
  333.  
  334. HRESULT RPC_ENTRY 
  335. NdrDllCanUnloadNow(
  336.     IN CStdPSFactoryBuffer * pPSFactoryBuffer);
  337.  
  338. /*************************************************************************
  339. The following new functions were added after the Windows NT 3.5 release.
  340. Programs intended to run on Windows NT 3.5 should define NT35_STRICT to 
  341. ensure that no new functions are used.
  342. *************************************************************************/
  343. #ifndef NT35_STRICT
  344.  
  345. HRESULT RPC_ENTRY NdrDllRegisterProxy(
  346.     IN HMODULE                  hDll,
  347.     IN const ProxyFileInfo **   pProxyFileList, 
  348.     IN const CLSID *            pclsid);
  349.  
  350. HRESULT RPC_ENTRY NdrDllUnregisterProxy(
  351.     IN HMODULE                  hDll,
  352.     IN const ProxyFileInfo **   pProxyFileList, 
  353.     IN const CLSID *            pclsid);
  354.  
  355.  
  356. #define REGISTER_PROXY_DLL_ROUTINES(pProxyFileList, pClsID) \
  357.     \
  358.     HINSTANCE hProxyDll = 0; \
  359.     \
  360.     /*DllMain saves the DLL module handle for later use by DllRegisterServer */ \
  361.     BOOL WINAPI DllMain( \
  362.         HINSTANCE  hinstDLL, \
  363.         DWORD  fdwReason, \
  364.         LPVOID  lpvReserved) \
  365.     { \
  366.         if(fdwReason == DLL_PROCESS_ATTACH) \
  367.             hProxyDll = hinstDLL; \
  368.         return TRUE; \
  369.     } \
  370.     \
  371.     /* DllRegisterServer registers the interfaces contained in the proxy DLL. */ \
  372.     HRESULT STDAPICALLTYPE DllRegisterServer() \
  373.     { \
  374.         return NdrDllRegisterProxy(hProxyDll, pProxyFileList, pClsID); \
  375.     }  \
  376.     \
  377.     /* DllUnregisterServer unregisters the interfaces contained in the proxy DLL. */ \
  378.     HRESULT STDAPICALLTYPE DllUnregisterServer() \
  379.     { \
  380.         return NdrDllUnregisterProxy(hProxyDll, pProxyFileList, pClsID); \
  381.     }  
  382.  
  383. //Delegation support.
  384. #define STUB_FORWARDING_FUNCTION        NdrStubForwardingFunction
  385.  
  386. ULONG STDMETHODCALLTYPE
  387. CStdStubBuffer2_Release(IRpcStubBuffer *This);
  388.  
  389. ULONG STDMETHODCALLTYPE
  390. NdrCStdStubBuffer2_Release(IRpcStubBuffer *This,IPSFactoryBuffer * pPSF);
  391.  
  392. #define CStdStubBuffer_DELEGATING_METHODS 0, 0, CStdStubBuffer2_Release, 0, 0, 0, 0, 0, 0, 0
  393.  
  394. #endif //NT35_STRICT
  395. /*************************************************************************
  396. End of new functions.
  397. *************************************************************************/
  398.  
  399. // PROXY_CLSID has precedence over PROXY_CLSID_IS
  400.  
  401. #ifdef PROXY_CLSID
  402.  
  403. #define CLSID_PSFACTORYBUFFER extern CLSID PROXY_CLSID;
  404.  
  405. #else // PROXY_CLSID
  406.  
  407. #ifdef PROXY_CLSID_IS
  408. #define CLSID_PSFACTORYBUFFER const CLSID CLSID_PSFactoryBuffer = PROXY_CLSID_IS;
  409. #define PROXY_CLSID     CLSID_PSFactoryBuffer
  410. #else // PROXY_CLSID_IS
  411. #define CLSID_PSFACTORYBUFFER
  412. #endif //PROXY_CLSID_IS
  413.  
  414. #endif //PROXY_CLSID
  415.  
  416. // if the user specified an override for the class id, it is
  417. // PROXY_CLSID at this point
  418.  
  419. #ifndef PROXY_CLSID
  420. #define GET_DLL_CLSID   \
  421.     ( aProxyFileList[0]->pStubVtblList[0] != 0 ? \
  422.     aProxyFileList[0]->pStubVtblList[0]->header.piid : 0)
  423. #else  //PROXY_CLSID
  424. #define GET_DLL_CLSID   &PROXY_CLSID
  425. #endif //PROXY_CLSID
  426.  
  427.  
  428.  
  429.  
  430. #define EXTERN_PROXY_FILE(name) \
  431.     EXTERN_C const ProxyFileInfo name##_ProxyFileInfo;
  432.  
  433. #define PROXYFILE_LIST_START    \
  434.     const ProxyFileInfo  *  aProxyFileList[]    = {
  435.  
  436. #define REFERENCE_PROXY_FILE(name)  \
  437.     & name##_ProxyFileInfo 
  438.  
  439. #define PROXYFILE_LIST_END      \
  440.     0 };
  441.  
  442. // return pointers to the class information
  443.  
  444. #define DLLDATA_GETPROXYDLLINFO(pPFList,pClsid) \
  445.     void RPC_ENTRY GetProxyDllInfo( const ProxyFileInfo*** pInfo, const CLSID ** pId )  \
  446.         {   \
  447.         *pInfo  = pPFList;  \
  448.         *pId    = pClsid;   \
  449.         };
  450.  
  451. // ole entry points:
  452. #define DLLGETCLASSOBJECTROUTINE(pPFlist, pClsid,pFactory)    \
  453.  HRESULT STDAPICALLTYPE DllGetClassObject ( \
  454.      REFCLSID rclsid, \
  455.      REFIID riid, \
  456.      void ** ppv ) \
  457.         { \
  458.         return  \
  459.             NdrDllGetClassObject(rclsid,riid,ppv,pPFlist,pClsid,pFactory ); \
  460.         }
  461.  
  462. #define DLLCANUNLOADNOW(pFactory)   \
  463.  HRESULT STDAPICALLTYPE DllCanUnloadNow()    \
  464.     {   \
  465.     return NdrDllCanUnloadNow( pFactory );    \
  466.     }
  467.  
  468.    
  469. #define DLLDUMMYPURECALL    \
  470.     void __cdecl _purecall(void)    \
  471.         {   \
  472.         }
  473.  
  474. #define CSTDSTUBBUFFERRELEASE(pFactory)   \
  475. ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer *This) \
  476.     {   \
  477.     return NdrCStdStubBuffer_Release(This,(IPSFactoryBuffer *)pFactory);   \
  478.     }   \
  479.  
  480. #ifdef PROXY_DELEGATION
  481. #define CSTDSTUBBUFFER2RELEASE(pFactory)   \
  482. ULONG STDMETHODCALLTYPE CStdStubBuffer2_Release(IRpcStubBuffer *This) \
  483.     {   \
  484.     return NdrCStdStubBuffer2_Release(This,(IPSFactoryBuffer *)pFactory);   \
  485.     }
  486. #else
  487. #define CSTDSTUBBUFFER2RELEASE(pFactory)   
  488. #endif //PROXY_DELEGATION
  489.  
  490.  
  491. #ifdef REGISTER_PROXY_DLL
  492. #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID ) REGISTER_PROXY_DLL_ROUTINES(pProxyFileList,pClsID )
  493. #else
  494. #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID )    
  495. #endif //REGISTER_PROXY_DLL
  496.  
  497.  
  498. // the dll entry points that must be defined
  499. #define DLLDATA_ROUTINES(pProxyFileList,pClsID )    \
  500.     \
  501.     CLSID_PSFACTORYBUFFER \
  502.     \
  503.     CStdPSFactoryBuffer       gPFactory = {0,0,0,0};  \
  504.     \
  505.     DLLDATA_GETPROXYDLLINFO(pProxyFileList,pClsID) \
  506.     \
  507.     DLLGETCLASSOBJECTROUTINE(pProxyFileList,pClsID,&gPFactory)    \
  508.     \
  509.     DLLCANUNLOADNOW(&gPFactory)   \
  510.     \
  511.     CSTDSTUBBUFFERRELEASE(&gPFactory)   \
  512.     \
  513.     CSTDSTUBBUFFER2RELEASE(&gPFactory) \
  514.     \
  515.     DLLDUMMYPURECALL    \
  516.     \
  517.     DLLREGISTRY_ROUTINES(pProxyFileList, pClsID) \
  518.     \
  519.  
  520.     // more code goes here...
  521.  
  522.  
  523. #define DLLDATA_STANDARD_ROUTINES   \
  524.     DLLDATA_ROUTINES( (const ProxyFileInfo**) pProxyFileList, &CLSID_PSFactoryBuffer )  \
  525.  
  526. #else  // !defined(__RPC_DOS__) && !defined(__RPC_WIN16__)
  527.  
  528. //+-------------------------------------------------------------------------
  529. //
  530. //  16-bit definitions (all empty)
  531. //
  532. //--------------------------------------------------------------------------
  533.  
  534. #endif // !defined(__RPC_DOS__) && !defined(__RPC_WIN16__)
  535.  
  536. #endif // __RPCPROXY_H__
  537.