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.

577 lines
16 KiB

  1. /*++
  2. Copyright (c) 1992-1995 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(WIN32) || defined(_MPPC_)
  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 IIDLookupRtn( const IID * pIID, int * pIndex );
  68. typedef IIDLookupRtn * PIIDLookup;
  69. // pointers to arrays of CInterfaceProxyVtbl's and CInterfaceStubVtbls
  70. typedef struct tagProxyFileInfo
  71. {
  72. const PCInterfaceProxyVtblList *pProxyVtblList;
  73. const PCInterfaceStubVtblList *pStubVtblList;
  74. const PCInterfaceName * pNamesArray;
  75. const IID ** pDelegatedIIDs;
  76. const PIIDLookup pIIDLookupRtn;
  77. unsigned short TableSize;
  78. unsigned short TableVersion;
  79. unsigned long Filler1;
  80. unsigned long Filler2;
  81. unsigned long Filler3;
  82. unsigned long Filler4;
  83. }ProxyFileInfo;
  84. // extended info with list of interface names
  85. typedef ProxyFileInfo ExtendedProxyFileInfo;
  86. #include <rpc.h>
  87. #include <rpcndr.h>
  88. #include <string.h>
  89. #include <memory.h>
  90. typedef struct tagCInterfaceProxyHeader
  91. {
  92. //
  93. // New fields should be added here, at the beginning of the structure.
  94. //
  95. #ifdef USE_STUBLESS_PROXY
  96. const void * pStublessProxyInfo;
  97. #endif
  98. const IID * piid;
  99. } CInterfaceProxyHeader;
  100. // Macro used for ANSI compatible stubs.
  101. #if defined(_MPPC_)
  102. #define CINTERFACE_PROXY_VTABLE( n ) \
  103. struct \
  104. { \
  105. CInterfaceProxyHeader header; \
  106. void * pDummyEntryForPowerMac; \
  107. void *Vtbl[ n ]; \
  108. }
  109. #else
  110. #define CINTERFACE_PROXY_VTABLE( n ) \
  111. struct \
  112. { \
  113. CInterfaceProxyHeader header; \
  114. void *Vtbl[ n ]; \
  115. }
  116. #endif
  117. #pragma warning( disable:4200 )
  118. typedef struct tagCInterfaceProxyVtbl
  119. {
  120. CInterfaceProxyHeader header;
  121. #if defined(_MPPC_)
  122. void * pDummyEntryForPowerMac;
  123. #endif
  124. #if defined( _MSC_VER )
  125. void *Vtbl[];
  126. #else
  127. void *Vtbl[1];
  128. #endif
  129. } CInterfaceProxyVtbl;
  130. #pragma warning( default:4200 )
  131. typedef
  132. void
  133. (__RPC_STUB __RPC_FAR * PRPC_STUB_FUNCTION) (
  134. IRpcStubBuffer *This,
  135. IRpcChannelBuffer * _pRpcChannelBuffer,
  136. PRPC_MESSAGE _pRpcMessage,
  137. DWORD __RPC_FAR *pdwStubPhase);
  138. typedef struct tagCInterfaceStubHeader
  139. {
  140. //New fields should be added here, at the beginning of the structure.
  141. const IID *piid;
  142. const MIDL_SERVER_INFO *pServerInfo;
  143. unsigned long DispatchTableCount;
  144. const PRPC_STUB_FUNCTION *pDispatchTable;
  145. } CInterfaceStubHeader;
  146. typedef struct tagCInterfaceStubVtbl
  147. {
  148. CInterfaceStubHeader header;
  149. IRpcStubBufferVtbl Vtbl;
  150. } CInterfaceStubVtbl;
  151. typedef struct tagCStdStubBuffer
  152. {
  153. const struct IRpcStubBufferVtbl * lpVtbl; //Points to Vtbl field in CInterfaceStubVtbl.
  154. long RefCount;
  155. struct IUnknown * pvServerObject;
  156. } CStdStubBuffer;
  157. typedef struct tagCStdPSFactoryBuffer
  158. {
  159. const IPSFactoryBufferVtbl *lpVtbl;
  160. long RefCount;
  161. const ProxyFileInfo ** pProxyFileList;
  162. long Filler1; //Reserved for future use.
  163. } CStdPSFactoryBuffer;
  164. void RPC_ENTRY
  165. NdrProxyInitialize(
  166. void * This,
  167. PRPC_MESSAGE pRpcMsg,
  168. PMIDL_STUB_MESSAGE pStubMsg,
  169. PMIDL_STUB_DESC pStubDescriptor,
  170. unsigned int ProcNum );
  171. void RPC_ENTRY
  172. NdrProxyGetBuffer(
  173. void * This,
  174. PMIDL_STUB_MESSAGE pStubMsg);
  175. void RPC_ENTRY
  176. NdrProxySendReceive(
  177. void *This,
  178. MIDL_STUB_MESSAGE *pStubMsg);
  179. void RPC_ENTRY
  180. NdrProxyFreeBuffer(
  181. void *This,
  182. MIDL_STUB_MESSAGE *pStubMsg);
  183. HRESULT RPC_ENTRY
  184. NdrProxyErrorHandler(
  185. DWORD dwExceptionCode);
  186. void RPC_ENTRY
  187. NdrStubInitialize(
  188. PRPC_MESSAGE pRpcMsg,
  189. PMIDL_STUB_MESSAGE pStubMsg,
  190. PMIDL_STUB_DESC pStubDescriptor,
  191. IRpcChannelBuffer * pRpcChannelBuffer);
  192. void __RPC_STUB NdrStubForwardingFunction(
  193. IN IRpcStubBuffer * This,
  194. IN IRpcChannelBuffer * pChannel,
  195. IN PRPC_MESSAGE pmsg,
  196. OUT DWORD __RPC_FAR * pdwStubPhase);
  197. void RPC_ENTRY
  198. NdrStubGetBuffer(
  199. IRpcStubBuffer * This,
  200. IRpcChannelBuffer * pRpcChannelBuffer,
  201. PMIDL_STUB_MESSAGE pStubMsg);
  202. HRESULT RPC_ENTRY
  203. NdrStubErrorHandler(
  204. DWORD dwExceptionCode);
  205. HRESULT STDMETHODCALLTYPE
  206. CStdStubBuffer_QueryInterface(
  207. IRpcStubBuffer *This,
  208. REFIID riid,
  209. void **ppvObject);
  210. ULONG STDMETHODCALLTYPE
  211. CStdStubBuffer_AddRef(
  212. IRpcStubBuffer *This);
  213. ULONG STDMETHODCALLTYPE
  214. CStdStubBuffer_Release(
  215. IRpcStubBuffer *This);
  216. ULONG STDMETHODCALLTYPE
  217. NdrCStdStubBuffer_Release(
  218. IRpcStubBuffer *This,
  219. IPSFactoryBuffer * pPSF);
  220. HRESULT STDMETHODCALLTYPE
  221. CStdStubBuffer_Connect(
  222. IRpcStubBuffer *This,
  223. IUnknown *pUnkServer);
  224. void STDMETHODCALLTYPE
  225. CStdStubBuffer_Disconnect(
  226. IRpcStubBuffer *This);
  227. HRESULT STDMETHODCALLTYPE
  228. CStdStubBuffer_Invoke(
  229. IRpcStubBuffer *This,
  230. RPCOLEMESSAGE *pRpcMsg,
  231. IRpcChannelBuffer *pRpcChannelBuffer);
  232. IRpcStubBuffer * STDMETHODCALLTYPE
  233. CStdStubBuffer_IsIIDSupported(
  234. IRpcStubBuffer *This,
  235. REFIID riid);
  236. ULONG STDMETHODCALLTYPE
  237. CStdStubBuffer_CountRefs(
  238. IRpcStubBuffer *This);
  239. HRESULT STDMETHODCALLTYPE
  240. CStdStubBuffer_DebugServerQueryInterface(
  241. IRpcStubBuffer *This,
  242. void **ppv);
  243. void STDMETHODCALLTYPE
  244. CStdStubBuffer_DebugServerRelease(
  245. IRpcStubBuffer *This,
  246. void *pv);
  247. #if defined(_MPPC_)
  248. #define CStdStubBuffer_METHODS \
  249. 0, /* a PowerMac dummy */ \
  250. CStdStubBuffer_QueryInterface,\
  251. CStdStubBuffer_AddRef, \
  252. CStdStubBuffer_Release, \
  253. CStdStubBuffer_Connect, \
  254. CStdStubBuffer_Disconnect, \
  255. CStdStubBuffer_Invoke, \
  256. CStdStubBuffer_IsIIDSupported, \
  257. CStdStubBuffer_CountRefs, \
  258. CStdStubBuffer_DebugServerQueryInterface, \
  259. CStdStubBuffer_DebugServerRelease
  260. #else
  261. #define CStdStubBuffer_METHODS \
  262. CStdStubBuffer_QueryInterface,\
  263. CStdStubBuffer_AddRef, \
  264. CStdStubBuffer_Release, \
  265. CStdStubBuffer_Connect, \
  266. CStdStubBuffer_Disconnect, \
  267. CStdStubBuffer_Invoke, \
  268. CStdStubBuffer_IsIIDSupported, \
  269. CStdStubBuffer_CountRefs, \
  270. CStdStubBuffer_DebugServerQueryInterface, \
  271. CStdStubBuffer_DebugServerRelease
  272. #endif
  273. //+-------------------------------------------------------------------------
  274. //
  275. // Macro definitions for the proxy file
  276. //
  277. //--------------------------------------------------------------------------
  278. #define IID_GENERIC_CHECK_IID(name,pIID,index) memcmp( pIID, name##_ProxyVtblList[ index ]->header.piid, 16 )
  279. #define IID_BS_LOOKUP_SETUP int result, low=-1;
  280. #define IID_BS_LOOKUP_INITIAL_TEST(name, sz, split) \
  281. if ( ( result = name##_CHECK_IID( split ) ) > 0 ) \
  282. { low = sz - split; } \
  283. else if ( !result ) \
  284. { low = split; goto found_label; }
  285. #define IID_BS_LOOKUP_NEXT_TEST(name, split ) \
  286. if ( ( result = name##_CHECK_IID( low + split )) >= 0 ) \
  287. { low = low + split; if ( !result ) goto found_label; }
  288. #define IID_BS_LOOKUP_RETURN_RESULT(name, sz, index ) \
  289. low = low + 1; \
  290. if ( ( low >= sz ) || (result = name##_CHECK_IID( low ) )) goto not_found_label; \
  291. found_label: (index) = low; return 1; \
  292. not_found_label: return 0;
  293. //+-------------------------------------------------------------------------
  294. //
  295. // Macro and routine definitions for the dlldata file
  296. //
  297. //--------------------------------------------------------------------------
  298. /****************************************************************************
  299. * Proxy Dll APIs
  300. ****************************************************************************/
  301. HRESULT RPC_ENTRY
  302. NdrDllGetClassObject (
  303. IN REFCLSID rclsid,
  304. IN REFIID riid,
  305. OUT void ** ppv,
  306. IN const ProxyFileInfo ** pProxyFileList,
  307. IN const CLSID * pclsid,
  308. IN CStdPSFactoryBuffer * pPSFactoryBuffer);
  309. HRESULT RPC_ENTRY
  310. NdrDllCanUnloadNow(
  311. IN CStdPSFactoryBuffer * pPSFactoryBuffer);
  312. /*************************************************************************
  313. The following new functions were added after the Windows NT 3.5 release.
  314. Programs intended to run on Windows NT 3.5 should define NT35_STRICT to
  315. ensure that no new functions are used.
  316. *************************************************************************/
  317. #ifndef NT35_STRICT
  318. HRESULT RPC_ENTRY NdrDllRegisterProxy(
  319. IN HMODULE hDll,
  320. IN const ProxyFileInfo ** pProxyFileList,
  321. IN const CLSID * pclsid);
  322. HRESULT RPC_ENTRY NdrDllUnregisterProxy(
  323. IN HMODULE hDll,
  324. IN const ProxyFileInfo ** pProxyFileList,
  325. IN const CLSID * pclsid);
  326. #define REGISTER_PROXY_DLL_ROUTINES(pProxyFileList, pClsID) \
  327. \
  328. HINSTANCE hProxyDll = 0; \
  329. \
  330. /*DllMain saves the DLL module handle for later use by DllRegisterServer */ \
  331. BOOL WINAPI DllMain( \
  332. HINSTANCE hinstDLL, \
  333. DWORD fdwReason, \
  334. LPVOID lpvReserved) \
  335. { \
  336. if(fdwReason == DLL_PROCESS_ATTACH) \
  337. hProxyDll = hinstDLL; \
  338. return TRUE; \
  339. } \
  340. \
  341. /* DllRegisterServer registers the interfaces contained in the proxy DLL. */ \
  342. HRESULT STDAPICALLTYPE DllRegisterServer() \
  343. { \
  344. return NdrDllRegisterProxy(hProxyDll, pProxyFileList, pClsID); \
  345. } \
  346. \
  347. /* DllUnregisterServer unregisters the interfaces contained in the proxy DLL. */ \
  348. HRESULT STDAPICALLTYPE DllUnregisterServer() \
  349. { \
  350. return NdrDllUnregisterProxy(hProxyDll, pProxyFileList, pClsID); \
  351. }
  352. //Delegation support.
  353. #define STUB_FORWARDING_FUNCTION NdrStubForwardingFunction
  354. ULONG STDMETHODCALLTYPE
  355. CStdStubBuffer2_Release(IRpcStubBuffer *This);
  356. ULONG STDMETHODCALLTYPE
  357. NdrCStdStubBuffer2_Release(IRpcStubBuffer *This,IPSFactoryBuffer * pPSF);
  358. #define CStdStubBuffer_DELEGATING_METHODS 0, 0, CStdStubBuffer2_Release, 0, 0, 0, 0, 0, 0, 0
  359. #endif //NT35_STRICT
  360. /*************************************************************************
  361. End of new functions.
  362. *************************************************************************/
  363. // PROXY_CLSID has precedence over PROXY_CLSID_IS
  364. #ifdef PROXY_CLSID
  365. #define CLSID_PSFACTORYBUFFER extern CLSID PROXY_CLSID;
  366. #else // PROXY_CLSID
  367. #ifdef PROXY_CLSID_IS
  368. #define CLSID_PSFACTORYBUFFER const CLSID CLSID_PSFactoryBuffer = PROXY_CLSID_IS;
  369. #define PROXY_CLSID CLSID_PSFactoryBuffer
  370. #else // PROXY_CLSID_IS
  371. #define CLSID_PSFACTORYBUFFER
  372. #endif //PROXY_CLSID_IS
  373. #endif //PROXY_CLSID
  374. // if the user specified an override for the class id, it is
  375. // PROXY_CLSID at this point
  376. #ifndef PROXY_CLSID
  377. #define GET_DLL_CLSID \
  378. ( aProxyFileList[0]->pStubVtblList[0] != 0 ? \
  379. aProxyFileList[0]->pStubVtblList[0]->header.piid : 0)
  380. #else //PROXY_CLSID
  381. #define GET_DLL_CLSID &PROXY_CLSID
  382. #endif //PROXY_CLSID
  383. #define EXTERN_PROXY_FILE(name) \
  384. EXTERN_C const ProxyFileInfo name##_ProxyFileInfo;
  385. #define PROXYFILE_LIST_START \
  386. const ProxyFileInfo * aProxyFileList[] = {
  387. #define REFERENCE_PROXY_FILE(name) \
  388. & name##_ProxyFileInfo
  389. #define PROXYFILE_LIST_END \
  390. 0 };
  391. // return pointers to the class information
  392. #define DLLDATA_GETPROXYDLLINFO(pPFList,pClsid) \
  393. void RPC_ENTRY GetProxyDllInfo( const ProxyFileInfo*** pInfo, const CLSID ** pId ) \
  394. { \
  395. *pInfo = pPFList; \
  396. *pId = pClsid; \
  397. };
  398. // ole entry points:
  399. #define DLLGETCLASSOBJECTROUTINE(pPFlist, pClsid,pFactory) \
  400. HRESULT STDAPICALLTYPE DllGetClassObject ( \
  401. REFCLSID rclsid, \
  402. REFIID riid, \
  403. void ** ppv ) \
  404. { \
  405. return \
  406. NdrDllGetClassObject(rclsid,riid,ppv,pPFlist,pClsid,pFactory ); \
  407. }
  408. #define DLLCANUNLOADNOW(pFactory) \
  409. HRESULT STDAPICALLTYPE DllCanUnloadNow() \
  410. { \
  411. return NdrDllCanUnloadNow( pFactory ); \
  412. }
  413. #define DLLDUMMYPURECALL \
  414. void __cdecl _purecall(void) \
  415. { \
  416. }
  417. #define CSTDSTUBBUFFERRELEASE(pFactory) \
  418. ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer *This) \
  419. { \
  420. return NdrCStdStubBuffer_Release(This,(IPSFactoryBuffer *)pFactory); \
  421. } \
  422. #ifdef PROXY_DELEGATION
  423. #define CSTDSTUBBUFFER2RELEASE(pFactory) \
  424. ULONG STDMETHODCALLTYPE CStdStubBuffer2_Release(IRpcStubBuffer *This) \
  425. { \
  426. return NdrCStdStubBuffer2_Release(This,(IPSFactoryBuffer *)pFactory); \
  427. }
  428. #else
  429. #define CSTDSTUBBUFFER2RELEASE(pFactory)
  430. #endif //PROXY_DELEGATION
  431. #ifdef REGISTER_PROXY_DLL
  432. #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID ) REGISTER_PROXY_DLL_ROUTINES(pProxyFileList,pClsID )
  433. #else
  434. #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID )
  435. #endif //REGISTER_PROXY_DLL
  436. // the dll entry points that must be defined
  437. #define DLLDATA_ROUTINES(pProxyFileList,pClsID ) \
  438. \
  439. CLSID_PSFACTORYBUFFER \
  440. \
  441. CStdPSFactoryBuffer gPFactory = {0,0,0,0}; \
  442. \
  443. DLLDATA_GETPROXYDLLINFO(pProxyFileList,pClsID) \
  444. \
  445. DLLGETCLASSOBJECTROUTINE(pProxyFileList,pClsID,&gPFactory) \
  446. \
  447. DLLCANUNLOADNOW(&gPFactory) \
  448. \
  449. CSTDSTUBBUFFERRELEASE(&gPFactory) \
  450. \
  451. CSTDSTUBBUFFER2RELEASE(&gPFactory) \
  452. \
  453. DLLDUMMYPURECALL \
  454. \
  455. DLLREGISTRY_ROUTINES(pProxyFileList, pClsID) \
  456. \
  457. // more code goes here...
  458. #define DLLDATA_STANDARD_ROUTINES \
  459. DLLDATA_ROUTINES( (const ProxyFileInfo**) pProxyFileList, &CLSID_PSFactoryBuffer ) \
  460. #else // !defined(__RPC_DOS__) && !defined(__RPC_WIN16__)
  461. //+-------------------------------------------------------------------------
  462. //
  463. // 16-bit definitions (all empty)
  464. //
  465. //--------------------------------------------------------------------------
  466. #endif // WIN32 or _MPPC_
  467. #endif // __RPCPROXY_H__
  468.