Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

535 lines
15 KiB

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