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.

523 lines
20 KiB

  1. // olerem.h - private defintions for OLE implementation of REMoting
  2. #if !defined( _OLEREM_H_ )
  3. #define _OLEREM_H_
  4. // name changes
  5. #define ILrpc IRpcChannel
  6. #define IStub IRpcStub
  7. #define IProxy IRpcProxy
  8. #define Dispatch Invoke
  9. #define IID_ILrpc IID_IRpcChannel
  10. #define IID_IStub IID_IRpcStub
  11. #define IID_IProxy IID_IRpcProxy
  12. // -----------------------------------------------------------------------
  13. // init/term
  14. STDAPI RemInitialize(void);
  15. STDAPI_(void) RemUninitialize(void);
  16. #ifdef _MAC
  17. // entry point for lrpc HLE's
  18. STDAPI RemProcessLrpcHLE(EventRecord *pHle);
  19. #endif
  20. // -----------------------------------------------------------------------
  21. // Communications Layer
  22. typedef LONG OID;
  23. STDAPI_(OID) RemAllocOID(interface IStubManager FAR* pSM);
  24. STDAPI_(BOOL) RemFreeOID(OID oid);
  25. // NOTE: ILrpc defined in stdps.h
  26. STDAPI RemConnectToObject(OID oid, ILrpc FAR* FAR* ppLrpc);
  27. STDAPI RemDisconnectObject(OID oid, DWORD dwReserved);
  28. // -----------------------------------------------------------------------
  29. // State Management
  30. // Class Factory Table
  31. STDAPI RemRegisterFactory(REFCLSID rclsid, IUnknown FAR* pUnk, DWORD dwContext,
  32. DWORD flags, LPDWORD lpdwRegister);
  33. STDAPI RemRevokeFactory(DWORD dwRegister, LPCLSID lpclsid,
  34. IUnknown FAR* FAR* ppUnk, LPDWORD lpdwContext);
  35. STDAPI RemLookupFactory(REFCLSID rclsid, BOOL fHide, OID FAR *pOid);
  36. // Handler Table
  37. interface IProxyManager : public IUnknown
  38. {
  39. STDMETHOD(CreateServer)(REFCLSID rclsid) = 0;
  40. STDMETHOD(Connect)(OID oid, REFCLSID rclsid) = 0;
  41. STDMETHOD(LockConnection)(BOOL fLock, BOOL fLastUnlockReleases) = 0;
  42. STDMETHOD_(void, GetClassID)(CLSID FAR* pClsid) = 0;
  43. STDMETHOD_(OID, GetOID)() = 0;
  44. STDMETHOD_(BOOL, IsConnected)(void) = 0;
  45. STDMETHOD(EstablishIID)(REFIID iid, LPVOID FAR* ppv) = 0;
  46. STDMETHOD_(void, Disconnect)() = 0;
  47. };
  48. INTERNAL RemSetHandler(OID oid, REFCLSID clsid, IProxyManager FAR* pPM);
  49. INTERNAL RemClearHandler(OID oid, IProxyManager FAR* pPM);
  50. // Server Table
  51. interface IStubManager : public IUnknown
  52. {
  53. STDMETHOD_(void, SetReg)(OID oid) = 0;
  54. STDMETHOD_(void, Connect)(IUnknown FAR* pUnk) = 0;
  55. STDMETHOD_(void, Disconnect)() = 0;
  56. STDMETHOD_(OID, GetOID)() = 0;
  57. STDMETHOD_(IUnknown FAR*, GetServer)(BOOL fAddRef) = 0;
  58. STDMETHOD_(void, AddRefRegConn)(DWORD mshlflags) = 0;
  59. STDMETHOD_(void, ReleaseRegConn)(DWORD mshlflags, BOOL fLastUR) = 0;
  60. STDMETHOD (Dispatch)(REFIID iid, int iMethod, IStream FAR* pIStream,
  61. DWORD dwDestCtx, LPVOID lpvDestCtx, BOOL FAR* lpfStrongConn) = 0;
  62. };
  63. // tables are now merged; combined registration:
  64. // MSHLHDR: first part of what is written to marshal stream
  65. struct FAR MSHLHDR
  66. {
  67. CLSID clsid; // oid == NULL -> unmarshal class
  68. // oid != NULL -> class of handler
  69. OID oid; // global id for object
  70. DWORD mshlflags; // marshal flags
  71. };
  72. struct FAR SHREG
  73. {
  74. MSHLHDR m_hdr; // simplifies things; see below
  75. IUnknown FAR* m_pUnkLookup; // NOTE: no addref
  76. IStubManager FAR* m_pSM; // if NULL, have handler
  77. };
  78. // There are two forms of SHREG:
  79. // 1. server registration:
  80. // m_hdr.clsid is class of handler
  81. // m_hdr.oid is non-NULL
  82. // m_hdr.mshlflags is NULL
  83. // m_pUnkLookup = non-addref'd pointer to server; not necessarily valid
  84. // (not valid when stubmgr disconnected, but still registered)
  85. // m_pSM = addref'd pointer to stubmgr.
  86. //
  87. // 2. handler registration (when connected to server)
  88. // m_hdr.clsid is class of handler (same as above)
  89. // m_hdr.oid is non-NULL
  90. // m_hdr.mshlflags is NULL
  91. // m_pUnkLookup = non-addref'd pProxyManager of handler; always valid
  92. // m_pSM = NULL
  93. //
  94. // NOTE: the MSHLHDR is present in the SHREG so as to make CoMarshalInterface
  95. // faster. The m_hdr.mshlflags is always zero in a reg entry; is set before
  96. // writing the hdr to a stream.
  97. //
  98. // We get and save the clsid so that we don't have to figure it out each
  99. // time we marshal the interface.
  100. // see olerem2.h for inline functions that manipulate SHREGs.
  101. STDAPI RemRegisterServer(IUnknown FAR* pUnk, DWORD mshlflags, SHREG FAR* pshreg);
  102. STDAPI RemRevokeServer(OID oid);
  103. STDAPI RemLookupSHOID(OID oid, IProxyManager FAR* FAR* ppPM,
  104. IStubManager FAR* FAR* ppSM);
  105. STDAPI RemLookupSHUnk(IUnknown FAR* pUnkGiven, IUnknown FAR* FAR* ppUnkServer, SHREG FAR* pshreg);
  106. // -----------------------------------------------------------------------
  107. // Other Routines
  108. STDAPI RemCreateRemoteHandler(REFCLSID rclsid, IUnknown FAR* pUnkOuter, REFIID riid, void FAR* FAR* ppv);
  109. INTERNAL RemCreateRHClassObject(REFCLSID rclsid, IID iid, void FAR* FAR* ppv);
  110. INTERNAL RemEnsureLocalClassObject(REFCLSID rclsid, OID FAR* pOidCF);
  111. INTERNAL RemEnsureUniqueHandler(REFCLSID rclsid, OID oid,
  112. IUnknown FAR* FAR* ppUnk, IProxyManager FAR* FAR* ppPM);
  113. // REVIEW MM2 (craigwi): these aren't used much; do we keep them?
  114. /* -----------------------------------------------------------------------
  115. * Proxy/Stub macros
  116. *
  117. * The follwoing macros can be used to implement Proxy/Stub classes for
  118. * classes that support only one or more interfaces other then IUnknown
  119. * (and maybe IDebug). The resulting classes will support IProxy, IStub
  120. * interface in addition to the interfaces supported by the original class.
  121. * Assuming the interfaces supported is IName and it is implemented
  122. * by a class CName:
  123. *
  124. * Declaration (in *.h):
  125. *
  126. * class CName { class CNameProxy { class CNameStub {
  127. * ............ ............ ............
  128. * STDUNKDECL(CName,Name) STDUNKDECL(CNameProxy,NameProxy) STDUNKDECL(CNameStub,NameStub)
  129. * STDDEBDECL(CName,Name) STDDEBDECL(CNameProxy,NameProxy) STDDEBDECL(CNameStub,NameStub)
  130. * STDPROXYDECL(CNameProxy,NameProxy) STDSTUBDECL(NameStub,1)
  131. * <IName Declaration> <IName for proxy> <IName for stub>
  132. * ............ ............ ............
  133. * }; }; };
  134. *
  135. * Implementation (in *.cpp):
  136. *
  137. * For original object:
  138. *
  139. * STDUNKIMPL(Name)
  140. *
  141. * STDUNK_QI_IMPL(Name,Name)
  142. *
  143. * STDUNKIMPL_FORDERIVED(Name,NameImpl)
  144. *
  145. * <Implementation of IName: CNameImpl>
  146. *
  147. *
  148. * For proxy object:
  149. *
  150. * STDUNKIMPL(NameProxy)
  151. *
  152. * STDUNK_PROXY_QI_IMPL(NameProxy,Name)
  153. *
  154. * STDUNKIMPL_FORDERIVED(NameProxy,NameProxyImpl)
  155. *
  156. * STDPROXYIMPL(NameProxy)
  157. *
  158. * <Implementation of IName: CNameProxyImpl>
  159. *
  160. *
  161. * For stub object:
  162. *
  163. * STDUNKIMPL(NameStub)
  164. *
  165. * STDUNK_STUB_QI_IMPL(NameStub,Name)
  166. *
  167. * STDUNKIMPL_FORDERIVED(NameStub,NameStubImpl)
  168. *
  169. * STDSTUBIMPL(NameStub)
  170. *
  171. * <Implementation of IName: CNameStubImpl>
  172. *
  173. *
  174. */
  175. // Mattp: I have moved the body of destructor to the implementation macro. ( STDPROXYIMPL)
  176. #define STDPROXYDECL(ignore, classname) \
  177. implement CProxy : IProxy { public: \
  178. CProxy(C##classname FAR* p##classname) \
  179. { m_p##classname = p##classname; } \
  180. ~CProxy(void); \
  181. STDMETHOD(QueryInterface)(REFIID iid, LPLPVOID ppvObj);\
  182. STDMETHOD_(ULONG,AddRef)(void); \
  183. STDMETHOD_(ULONG,Release)(void); \
  184. STDMETHOD(Connect)(ILrpc FAR* pILrpc); \
  185. STDMETHOD_(void, Disconnect)(void); \
  186. private: C##classname FAR* m_p##classname; }; \
  187. DECLARE_NC(C##classname,CProxy) \
  188. CProxy m_Proxy;
  189. #define STDSTUBDECL(ignore, classname,cIface) \
  190. implement CStub : IStub { public: \
  191. CStub(C##classname FAR* p##classname) \
  192. { m_p##classname = p##classname; m_pUnkObject = NULL; } \
  193. ~CStub(void) \
  194. { M_PROLOG(m_p##classname); if (m_pUnkObject != NULL) m_pUnkObject->Release(); } \
  195. INTERNAL_(BOOL) Init(IUnknown FAR* pUnkObject); \
  196. STDMETHOD(QueryInterface)(REFIID iid, LPLPVOID ppvObj);\
  197. STDMETHOD_(ULONG,AddRef)(void); \
  198. STDMETHOD_(ULONG,Release)(void); \
  199. STDMETHOD(Connect)(IUnknown FAR* pUnkObject); \
  200. STDMETHOD_(void, Disconnect)(void); \
  201. STDMETHOD(Dispatch)(REFIID iid, int iMethod, IStream FAR* pIStream, \
  202. DWORD dwDestCtx, LPVOID lpvDestCtx); \
  203. STDMETHOD_(BOOL, IsIIDSupported)(REFIID iid); \
  204. STDMETHOD_(ULONG, CountRefs)(void); \
  205. private: C##classname FAR* m_p##classname; \
  206. IUnknown FAR* m_pUnkObject; \
  207. IUnknown FAR* m_aStubIface[cIface]; }; \
  208. DECLARE_NC(C##classname,CStub) \
  209. CStub m_Stub;
  210. #define CONSTRUCT_PROXY m_Proxy(this),
  211. #define CONSTRUCT_STUB m_Stub(this),
  212. #define STDUNK_PROXY_QI_IMPL(classname,interfacename) \
  213. STDMETHODIMP NC(C##classname,CUnknownImpl)::QueryInterface \
  214. (REFIID iidInterface, void FAR* FAR* ppv) { \
  215. M_PROLOG(m_p##classname); \
  216. if (iidInterface == IID_IUnknown) \
  217. { *ppv = (void FAR*)&m_p##classname->m_Unknown; AddRef(); noError; } \
  218. else if (iidInterface == IID_I##interfacename) \
  219. { *ppv = (void FAR*) &(m_p##classname->m_##classname); \
  220. m_p##classname->m_pUnkOuter->AddRef(); noError; } \
  221. else if (iidInterface == IID_IProxy) \
  222. { *ppv = (void FAR*) &(m_p##classname->m_Proxy); AddRef(); noError; } \
  223. else \
  224. STDDEB_QI(classname) \
  225. { *ppv = NULL; return ResultFromScode(E_NOINTERFACE); } \
  226. }
  227. #define STDUNK_STUB_QI_IMPL(classname,interfacename) \
  228. STDMETHODIMP NC(C##classname,CUnknownImpl)::QueryInterface \
  229. (REFIID iidInterface, void FAR* FAR* ppv) { \
  230. A5_PROLOG(m_p##classname); \
  231. if (iidInterface == IID_IUnknown) \
  232. *ppv = (void FAR*)&m_p##classname->m_Unknown; \
  233. else if (iidInterface == IID_IStub) \
  234. *ppv = (void FAR*) &(m_p##classname->m_Stub); \
  235. else \
  236. STDDEB_QI(classname) \
  237. { *ppv = NULL; RESTORE_A5(); return ResultFromScode(E_NOINTERFACE); } \
  238. ++(m_p##classname->m_refs); RESTORE_A5(); noError; }
  239. // Mattp: The destructor implementation has been moved to here to allow us the outer
  240. // reference to 'm_pILrpc'.
  241. #define STDPROXYIMPL(classname) \
  242. NC(C##classname,CProxy)::~CProxy(void) \
  243. { M_PROLOG(m_p##classname);if (m_p##classname->m_pILrpc) m_p##classname->m_pILrpc->Release();}\
  244. STDMETHODIMP NC(C##classname,CProxy)::QueryInterface(REFIID iid, LPLPVOID ppvObj) \
  245. { M_PROLOG(m_p##classname);return m_p##classname->m_Unknown.QueryInterface (iid, ppvObj); } \
  246. STDMETHODIMP_(ULONG) NC(C##classname,CProxy)::AddRef(void) \
  247. { M_PROLOG(m_p##classname);return m_p##classname->m_Unknown.AddRef(); } \
  248. STDMETHODIMP_(ULONG) NC(C##classname,CProxy)::Release(void) \
  249. { M_PROLOG(m_p##classname);return m_p##classname->m_Unknown.Release(); } \
  250. STDMETHODIMP NC(C##classname,CProxy)::Connect(ILrpc FAR* pILrpc) \
  251. { \
  252. M_PROLOG(m_p##classname); \
  253. if (pILrpc) { \
  254. pILrpc->AddRef(); \
  255. m_p##classname->m_pILrpc = pILrpc; \
  256. return NOERROR; \
  257. } else \
  258. return ResultFromScode(E_UNSPEC); \
  259. } \
  260. STDMETHODIMP_(void) NC(C##classname,CProxy)::Disconnect(void) \
  261. { \
  262. M_PROLOG(m_p##classname); \
  263. if (m_p##classname->m_pILrpc) \
  264. m_p##classname->m_pILrpc->Release(); \
  265. m_p##classname->m_pILrpc = NULL; \
  266. }
  267. #define STDSTUBIMPL(classname) STDUNKIMPL_FORDERIVED(classname,Stub) \
  268. STDMETHODIMP NC(C##classname,CStub)::Connect(IUnknown FAR* pUnkObject) \
  269. { M_PROLOG(m_p##classname);return Init(pUnkObject) ? NOERROR : ResultFromScode(E_UNSPEC); } \
  270. STDMETHODIMP_(void) NC(C##classname,CStub)::Disconnect(void) \
  271. {M_PROLOG(m_p##classname); Init(NULL); }
  272. /*
  273. * Ole2 marshalling stuff
  274. *
  275. * REVIEW: this should go into ole2sp.h, but ILrpc is defined here and
  276. * olerem.h is included after ole2sp.h ...
  277. */
  278. //
  279. // MOP is a single instruction to the interpreter that encodes,
  280. // decodes parameters sent via LRPC. A string of Mops describes how to
  281. // marshal, unmarshal function's paramaters.
  282. //
  283. //
  284. typedef enum MOP {
  285. NilMop,
  286. // Basic types size of type (win3.1)
  287. Void, // No value 0b
  288. This, // FAR* this -- Not used
  289. Int, // (INT == int) 2b
  290. uInt, // (UINT == unsigned int) 2b
  291. Long, // (LONG == long) 4b
  292. uLong, // (ULONG == unsigned long) 4b
  293. Word, // WORD 2b
  294. dWord, // DWORD 4b
  295. Bool, // BOOL 2b
  296. lpStr, // LPSTR -- (zero terminated)
  297. lplpStr, // LPLPSTR -- (zero terminated)
  298. pBuf, // void FAR* -- (size in following long)
  299. // Windows types
  300. wParam, // WPARAM 2b
  301. lParam, // LPARAM 4b
  302. _Handle, // HANDLE 2b
  303. hWnd, // HWND 2b
  304. hDc, // HDC 2b
  305. hRgn, // HRGN 2b
  306. hClip, // HANDLE 2b
  307. _Point, // POINT 4b
  308. _Size, // SIZE 4b
  309. _Rect, // RECT 8b
  310. Msg, // MSG 18b
  311. // Ole/Win32 types
  312. _Pointl, // POINTL 8b
  313. _Sizel, // SIZEL 8b
  314. _Rectl, // RECTL 16b
  315. // Ole types
  316. Hresult, // HRESULT 4b
  317. Cid, // CID 16b
  318. Iid, // IID 16b
  319. wChar, // WCHAR 2b
  320. Time, // TIME_T 4b
  321. StatStg, // STATSTG > 38b + size of member lpstr
  322. Layout, // OLELAYOUT 2b bad size
  323. ClipFor, // CLIPFORMAT 2b MAC bad size
  324. DAspect, // DVASPECT 4b
  325. TyMed, // TYMED 4b
  326. Verb, // OLEVERB > 14b + size of member lpstr
  327. TDev, // DVTARGETDEVICE > 16b
  328. SMedium, // STGMEDIUM > 12b + size of member lpstr
  329. ForEtc, // FORMATETC > 18b + size of member tdev
  330. StatDat, // STATDATA > 48b + size of member foretc
  331. IFace, // interface FAR* > 40b
  332. MenuWidths, // OLEMENUGROUP_WIDTHS 24b
  333. hMenu, // HMENU 2b
  334. hOMenu, // HOLEMENU 2b
  335. hAccel, // HACCEL 2b
  336. FrameInfo, // OLEINPLACEFRAMEINFO 10b
  337. BindOpt, // BIND_OPTS 12b might change (02/15/2000-- not likely)
  338. LogPal, // LOGPALETTE > 8b
  339. ArraySize, // the following is an array arg list
  340. GenMops, // generic mop: used for with eg. Enum Next
  341. RunArg, // inidicates a run modifier: Min or Mout based of return or not
  342. // ->see example
  343. // Modifiers
  344. MMask = 0xc0,
  345. MIn = 0x40, // FAR Pointer to in parameter
  346. MOut = 0x80, // FAR Pointer to out parameter
  347. MIO = 0xc0, // FAR Pointer to in, out parameter
  348. // Interface indexes (overlap mop values)
  349. ILast = 1, // Use last marshalled interface
  350. IUnk, // IUnknown
  351. IMnk, // IMoniker
  352. IStg, // IStorage
  353. IDObj, // IDataObject
  354. IVObj, // IViewObject
  355. IOleObj, // IOleObject
  356. IIpObj, // IOleInPlaceObject
  357. ICSite, // IOleClientSite
  358. IIpSite, // IOleInPlaceSite
  359. IAdvSink, // IAdviseSink
  360. IPDName, // IParseDisplayName
  361. IOleCont, // IOleContainer
  362. IOleItemCont, // IOleItemContainer
  363. IBCtx, // IBindCtx
  364. IEStatData, // IEnumSTATDATA
  365. IEForEtc, // IEnumFORMATETC
  366. IEStr, // IEnumString
  367. IEVerbs, // IEnumOLEVERB
  368. IEMnk, // IEnumMoniker
  369. IOleWnd, // IOleWIndow
  370. IIpUiWnd, // IOleInPlaceUIWindow
  371. IIpFrame, // IOleInPlaceFrame
  372. IIpAObj, // IOleInPlaceActiveObject
  373. IStStream,
  374. IEnumStatStg
  375. } MOP;
  376. //
  377. // Modifiers combine with other types to indicate pointer to the type:
  378. // - MIn values are passed on call, but not updated upon return
  379. // - MOut values are not passed on call, but are updated upon return
  380. // - MIO values are passed on call, and updated upon return.
  381. //
  382. // M** indicates the argument is a pointer to the type. For types
  383. // which imply pointer (lpStr, pBuf, IMnk) M** indicates pointer to a pointer
  384. // (as in LPSTR FAR*, IEnumClipFormat FAR* FAR*). For MOut the value pointed
  385. // (i.e. the interface pointer) is ignored. MIn, MIO not supported.
  386. //
  387. // Interface indexes follow IFace mop to specify type of interface being
  388. // marshalled. ILast specify last IID marshalled.
  389. //
  390. // By convention the return value is always an HRESULT.
  391. //
  392. // MOP is an 8-bit value; it fits in a BYTE. Example:
  393. //
  394. // static mopsSomeFunc[] { pBuf | MIn, uLong, IFace, IDObj, ..., NilMop };
  395. //
  396. // Example for generic mops!
  397. // static BYTE ForEtcMop[] = { MopSize(22), ClipFor, RunArg, TDev, DAspect, Long, TyMed, NilMop };
  398. // static BYTE mopsForEtcNext[] = { uLong, ArraySize, GenMops | MOut, MopPtr(ForEtcMop), uLong | MOut, NilMop };
  399. //
  400. // FNI describes how to marshal, unmarshal specific function
  401. //
  402. typedef int FNITYPE;
  403. #define FNITYPE_NilFni 0
  404. #define FNITYPE_RevArg 0x01 // Arguments pushed left-to-right (pascal)
  405. #define FNITYPE_Clean 0x02 // Callee cleans stack (pascal)
  406. #define FNITYPE_Method 0x04 // Class method.
  407. #define FNITYPE_Virtual 0x08 // Virtual function
  408. #define FNITYPE_Send 0x10 // Use SendMessage (not PostMessage)
  409. #define FNITYPE_NoWait 0x20 // Do not wait for reply (only when PostMessage)
  410. struct FAR FNI { // Static data for function marshalling
  411. FNITYPE m_type; // Function description
  412. struct { // For virtual function
  413. const IID FAR* lpIID;// far pointer to Interface ID
  414. int iMethod; // Method index
  415. } m_loc; // ----
  416. UINT m_cbStk; // Stack space for pushing all arguments
  417. UINT m_cbStm; // Stream space for marshalling arguments
  418. UINT m_cbExtStm; // Additional stream space for strings, buffers
  419. BYTE FAR* m_args; // Arguments MOPs
  420. };
  421. //
  422. // Example
  423. //
  424. //static FNI fniSomeFunc = {
  425. // FNITYPE_Method | FNITYPE_Virtual,
  426. // { //interface and method Indices
  427. // &_IID_ISomeIface,
  428. // IFUNC_SomeFunc
  429. // },
  430. // 64, // Stack space
  431. // 96, // Minimun Stream space
  432. // 48, // Estimated extra stream space
  433. // mopsSomeFunc // The mops
  434. //};
  435. //
  436. // _IID_ISomeIface is the IID for the interface of this object,
  437. // IIFACE_SomeFunc is the index of this method within the interface.
  438. //
  439. STDAPI LrpcCall(ILrpc FAR* pILrpc, FNI FAR* pfni, void FAR* pFirstArg);
  440. STDAPI LrpcDispatch(IStream FAR* pIStream, FNI FAR* pfni, void FAR* pObj);
  441. BOOL IsValidOID(OID oid);
  442. #endif // _OLEREM_H