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.

513 lines
17 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: comstl/util/rot_functions.h (originally MORotFns.h, ::SynesisCom)
  3. *
  4. * Purpose: COM ROT (Running Object Table) functions.
  5. *
  6. * Created: 21st October 1998
  7. * Updated: 29th July 2010
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1998-2010, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file comstl/util/rot_functions.h
  40. *
  41. * \brief [C++ only; requires COM] COM ROT (Running Object Table) functions
  42. * (\ref group__library__utility__com "COM Utility" Library).
  43. */
  44. #ifndef COMSTL_INCL_COMSTL_UTIL_H_ROT_FUNCTIONS
  45. #define COMSTL_INCL_COMSTL_UTIL_H_ROT_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define COMSTL_VER_COMSTL_UTIL_H_ROT_FUNCTIONS_MAJOR 5
  48. # define COMSTL_VER_COMSTL_UTIL_H_ROT_FUNCTIONS_MINOR 1
  49. # define COMSTL_VER_COMSTL_UTIL_H_ROT_FUNCTIONS_REVISION 3
  50. # define COMSTL_VER_COMSTL_UTIL_H_ROT_FUNCTIONS_EDIT 65
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef COMSTL_INCL_COMSTL_H_COMSTL
  56. # include <comstl/comstl.h>
  57. #endif /* !COMSTL_INCL_COMSTL_H_COMSTL */
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Namespace
  60. */
  61. #if !defined(_COMSTL_NO_NAMESPACE) && \
  62. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  63. # if defined(_STLSOFT_NO_NAMESPACE)
  64. /* There is no stlsoft namespace, so must define ::comstl */
  65. namespace comstl
  66. {
  67. # else
  68. /* Define stlsoft::comstl_project */
  69. namespace stlsoft
  70. {
  71. namespace comstl_project
  72. {
  73. # endif /* _STLSOFT_NO_NAMESPACE */
  74. #endif /* !_COMSTL_NO_NAMESPACE */
  75. /* /////////////////////////////////////////////////////////////////////////
  76. * C functions
  77. */
  78. /** \brief [C only] Registers an object in the Running Object Table
  79. *
  80. * \ingroup group__library__utility__com
  81. *
  82. * Registers an object and its identifying moniker in the Running Object Table (ROT).
  83. *
  84. * \param grfFlags Registration options
  85. * \param punkObject Pointer to the object being registered
  86. * \param pmkObjectName Pointer to the moniker of the object being registered
  87. * \param pdwRegister Pointer to the value identifying the registration
  88. * \return An HRESULT indicating success or failure
  89. */
  90. STLSOFT_INLINE HRESULT comstl_C_Rot_Register(
  91. DWORD grfFlags
  92. , LPUNKNOWN punkObject
  93. , LPMONIKER pmkObjectName
  94. , DWORD* pdwRegister
  95. )
  96. {
  97. LPRUNNINGOBJECTTABLE prot;
  98. HRESULT hr = STLSOFT_NS_GLOBAL(GetRunningObjectTable)(0, &prot);
  99. if(SUCCEEDED(hr))
  100. {
  101. hr = COMSTL_ITF_CALL(prot)->Register(COMSTL_ITF_THIS(prot) grfFlags, punkObject, pmkObjectName, pdwRegister);
  102. COMSTL_ITF_CALL(prot)->Release(COMSTL_ITF_THIS0(prot));
  103. }
  104. return hr;
  105. }
  106. /** \brief [C only] Removes an object from the Running Object Table
  107. *
  108. * \ingroup group__library__utility__com
  109. *
  110. * Removes from the Running Object Table (ROT) an entry that was previously
  111. * registered by a call to Rot_Register().
  112. *
  113. * \param dwRegister Value identifying registration to be revoked
  114. * \return An HRESULT indicating success or failure
  115. */
  116. STLSOFT_INLINE HRESULT comstl_C_Rot_Revoke(DWORD dwRegister)
  117. {
  118. LPRUNNINGOBJECTTABLE prot;
  119. HRESULT hr = STLSOFT_NS_GLOBAL(GetRunningObjectTable)(0, &prot);
  120. if(SUCCEEDED(hr))
  121. {
  122. hr = COMSTL_ITF_CALL(prot)->Revoke(COMSTL_ITF_THIS(prot) dwRegister);
  123. COMSTL_ITF_CALL(prot)->Release(COMSTL_ITF_THIS0(prot));
  124. }
  125. return hr;
  126. }
  127. /** \brief [C only] Determines if object current in the Running Object Table
  128. *
  129. * \ingroup group__library__utility__com
  130. *
  131. * Determines whether the object identified by the specified moniker is
  132. * currently running. This method looks for the moniker in the Running Object
  133. * Table (ROT).
  134. *
  135. * \param pmkObjectName Pointer to the moniker of the object whose status is desired
  136. * \return An HRESULT indicating success or failure
  137. */
  138. STLSOFT_INLINE HRESULT comstl_C_Rot_IsRunning(LPMONIKER pmkObjectName)
  139. {
  140. LPRUNNINGOBJECTTABLE prot;
  141. HRESULT hr = STLSOFT_NS_GLOBAL(GetRunningObjectTable)(0, &prot);
  142. if(SUCCEEDED(hr))
  143. {
  144. hr = COMSTL_ITF_CALL(prot)->IsRunning(COMSTL_ITF_THIS(prot) pmkObjectName);
  145. COMSTL_ITF_CALL(prot)->Release(COMSTL_ITF_THIS0(prot));
  146. }
  147. return hr;
  148. }
  149. /** \brief [C only] Retrieves the object from the Running Object Table
  150. *
  151. * \ingroup group__library__utility__com
  152. *
  153. * Determines whether the object identified by the specified moniker is running,
  154. * and if it is, retrieves a pointer to that object. This method looks for the
  155. * moniker in the Running Object Table (ROT), and retrieves the pointer
  156. * registered there.
  157. *
  158. * \param pmkObjectName Pointer to the moniker of the object
  159. * \param ppunkObject Address of output variable that receives the IUnknown interface pointer
  160. * \return An HRESULT indicating success or failure
  161. */
  162. STLSOFT_INLINE HRESULT comstl_C_Rot_GetObject(
  163. LPMONIKER pmkObjectName
  164. , LPUNKNOWN* ppunkObject
  165. )
  166. {
  167. LPRUNNINGOBJECTTABLE prot;
  168. HRESULT hr = STLSOFT_NS_GLOBAL(GetRunningObjectTable)(0, &prot);
  169. if(SUCCEEDED(hr))
  170. {
  171. hr = COMSTL_ITF_CALL(prot)->GetObject(COMSTL_ITF_THIS(prot) pmkObjectName, ppunkObject);
  172. COMSTL_ITF_CALL(prot)->Release(COMSTL_ITF_THIS0(prot));
  173. }
  174. return hr;
  175. }
  176. /** \brief [C only] Retrieves the last modification time of a running object in the Running Object Table
  177. *
  178. * \ingroup group__library__utility__com
  179. *
  180. * Records the time that a running object was last modified. The object must
  181. * have previously been registered with the Running Object Table (ROT). This
  182. * method stores the time of last change in the ROT.
  183. *
  184. * \param dwRegister Value identifying registration being updated
  185. * \param lpfiletime Pointer to structure containing object's last change time
  186. * \return An HRESULT indicating success or failure
  187. */
  188. STLSOFT_INLINE HRESULT comstl_C_Rot_NoteChangeTime(
  189. DWORD dwRegister
  190. , FILETIME* lpfiletime
  191. )
  192. {
  193. LPRUNNINGOBJECTTABLE prot;
  194. HRESULT hr = STLSOFT_NS_GLOBAL(GetRunningObjectTable)(0, &prot);
  195. if(SUCCEEDED(hr))
  196. {
  197. hr = COMSTL_ITF_CALL(prot)->NoteChangeTime(COMSTL_ITF_THIS(prot) dwRegister, lpfiletime);
  198. COMSTL_ITF_CALL(prot)->Release(COMSTL_ITF_THIS0(prot));
  199. }
  200. return hr;
  201. }
  202. /** \brief [C only] Retrieves the last modification time of an object in the Running Object Table
  203. *
  204. * \ingroup group__library__utility__com
  205. *
  206. * Returns the time that an object was last modified. The object must have
  207. * previously been registered with the Running Object Table (ROT). This method
  208. * looks for the last change time recorded in the ROT.
  209. *
  210. * \param pmkObjectName Pointer to moniker on the object whose status is desired
  211. * \param lpfiletime Pointer to structure containing object's last change time
  212. * \return An HRESULT indicating success or failure
  213. */
  214. STLSOFT_INLINE HRESULT comstl_C_Rot_GetTimeOfLastChange(
  215. LPMONIKER pmkObjectName
  216. , FILETIME* lpfiletime
  217. )
  218. {
  219. LPRUNNINGOBJECTTABLE prot;
  220. HRESULT hr = STLSOFT_NS_GLOBAL(GetRunningObjectTable)(0, &prot);
  221. if(SUCCEEDED(hr))
  222. {
  223. hr = COMSTL_ITF_CALL(prot)->GetTimeOfLastChange(COMSTL_ITF_THIS(prot) pmkObjectName, lpfiletime);
  224. COMSTL_ITF_CALL(prot)->Release(COMSTL_ITF_THIS0(prot));
  225. }
  226. return hr;
  227. }
  228. /** \brief [C only] Queries the current set of objects in the Running Object Table
  229. *
  230. * \ingroup group__library__utility__com
  231. *
  232. * Creates and returns a pointer to an enumerator that can list the monikers of
  233. * all the objects currently registered in the Running Object Table (ROT).
  234. *
  235. * \param ppenumMoniker Address of output variable that receives the IEnumMoniker interface pointer
  236. * \return An HRESULT indicating success or failure
  237. */
  238. STLSOFT_INLINE HRESULT comstl_C_Rot_EnumRunning(IEnumMoniker** ppenumMoniker)
  239. {
  240. LPRUNNINGOBJECTTABLE prot;
  241. HRESULT hr = STLSOFT_NS_GLOBAL(GetRunningObjectTable)(0, &prot);
  242. if(SUCCEEDED(hr))
  243. {
  244. hr = COMSTL_ITF_CALL(prot)->EnumRunning(COMSTL_ITF_THIS(prot) ppenumMoniker);
  245. COMSTL_ITF_CALL(prot)->Release(COMSTL_ITF_THIS0(prot));
  246. }
  247. return hr;
  248. }
  249. /* /////////////////////////////////////////////////////////////////////////
  250. * Obsolete symbols
  251. *
  252. * NOTE: these are only defined if:
  253. *
  254. * - we're generating documentation, or
  255. * - STLSOFT_OBSOLETE is specified, or
  256. * - it's STLSoft 1.9 (or earlier)
  257. */
  258. #if defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) || \
  259. defined(STLSOFT_OBSOLETE) || \
  260. _STLSOFT_VER < 0x010a0000
  261. /** \def comstl__Rot_Register
  262. *
  263. * \deprecated Use comstl_C_Rot_Register
  264. */
  265. # define comstl__Rot_Register comstl_C_Rot_Register
  266. /** \def comstl__Rot_Revoke
  267. *
  268. * \deprecated Use comstl_C_Rot_Revoke
  269. */
  270. # define comstl__Rot_Revoke comstl_C_Rot_Revoke
  271. /** \def comstl__Rot_IsRunning
  272. *
  273. * \deprecated Use comstl_C_Rot_IsRunning
  274. */
  275. # define comstl__Rot_IsRunning comstl_C_Rot_IsRunning
  276. /** \def comstl__Rot_GetObject
  277. *
  278. * \deprecated Use comstl_C_Rot_GetObject
  279. */
  280. # define comstl__Rot_GetObject comstl_C_Rot_GetObject
  281. /** \def comstl__Rot_NoteChangeTime
  282. *
  283. * \deprecated Use comstl_C_Rot_NoteChangeTime
  284. */
  285. # define comstl__Rot_NoteChangeTime comstl_C_Rot_NoteChangeTime
  286. /** \def comstl__Rot_GetTimeOfLastChange
  287. *
  288. * \deprecated Use comstl_C_Rot_GetTimeOfLastChange
  289. */
  290. # define comstl__Rot_GetTimeOfLastChange comstl_C_Rot_GetTimeOfLastChange
  291. /** \def comstl__Rot_EnumRunning
  292. *
  293. * \deprecated Use comstl_C_Rot_EnumRunning
  294. */
  295. # define comstl__Rot_EnumRunning comstl_C_Rot_EnumRunning
  296. #endif /* obsolete || 1.9 */
  297. /* /////////////////////////////////////////////////////////////////////////
  298. * Namespace
  299. */
  300. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  301. namespace comstl
  302. {
  303. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  304. /* /////////////////////////////////////////////////////////////////////////
  305. * C++ functions
  306. */
  307. #ifdef __cplusplus
  308. /** \brief Registers an object in the Running Object Table
  309. *
  310. * \ingroup group__library__utility__com
  311. *
  312. * Registers an object and its identifying moniker in the Running Object Table (ROT).
  313. *
  314. * \param grfFlags Registration options
  315. * \param punkObject Pointer to the object being registered
  316. * \param pmkObjectName Pointer to the moniker of the object being registered
  317. * \param pdwRegister Pointer to the value identifying the registration
  318. * \return An HRESULT indicating success or failure
  319. */
  320. inline HRESULT Rot_Register(
  321. DWORD grfFlags
  322. , LPUNKNOWN punkObject
  323. , LPMONIKER pmkObjectName
  324. , DWORD* pdwRegister
  325. )
  326. {
  327. return comstl__Rot_Register(grfFlags, punkObject, pmkObjectName, pdwRegister);
  328. }
  329. /** \brief Removes an object from the Running Object Table
  330. *
  331. * \ingroup group__library__utility__com
  332. *
  333. * Removes from the Running Object Table (ROT) an entry that was previously
  334. * registered by a call to Rot_Register().
  335. *
  336. * \param dwRegister Value identifying registration to be revoked
  337. * \return An HRESULT indicating success or failure
  338. */
  339. inline HRESULT Rot_Revoke(DWORD dwRegister)
  340. {
  341. return comstl__Rot_Revoke(dwRegister);
  342. }
  343. /** \brief Determines if object current in the Running Object Table
  344. *
  345. * \ingroup group__library__utility__com
  346. *
  347. * Determines whether the object identified by the specified moniker is
  348. * currently running. This method looks for the moniker in the Running Object
  349. * Table (ROT).
  350. *
  351. * \param pmkObjectName Pointer to the moniker of the object whose status is desired
  352. * \return An HRESULT indicating success or failure
  353. */
  354. inline HRESULT Rot_IsRunning(LPMONIKER pmkObjectName)
  355. {
  356. return comstl__Rot_IsRunning(pmkObjectName);
  357. }
  358. /** \brief Retrieves the object from the Running Object Table
  359. *
  360. * \ingroup group__library__utility__com
  361. *
  362. * Determines whether the object identified by the specified moniker is running,
  363. * and if it is, retrieves a pointer to that object. This method looks for the
  364. * moniker in the Running Object Table (ROT), and retrieves the pointer
  365. * registered there.
  366. *
  367. * \param pmkObjectName Pointer to the moniker of the object
  368. * \param ppunkObject Address of output variable that receives the IUnknown interface pointer
  369. * \return An HRESULT indicating success or failure
  370. */
  371. inline HRESULT Rot_GetObject(
  372. LPMONIKER pmkObjectName
  373. , LPUNKNOWN* ppunkObject
  374. )
  375. {
  376. return comstl__Rot_GetObject(pmkObjectName, ppunkObject);
  377. }
  378. /** \brief Retrieves the last modification time of a running object in the Running Object Table
  379. *
  380. * \ingroup group__library__utility__com
  381. *
  382. * Records the time that a running object was last modified. The object must
  383. * have previously been registered with the Running Object Table (ROT). This
  384. * method stores the time of last change in the ROT.
  385. *
  386. * \param dwRegister Value identifying registration being updated
  387. * \param lpfiletime Pointer to structure containing object's last change time
  388. * \return An HRESULT indicating success or failure
  389. */
  390. inline HRESULT Rot_NoteChangeTime(
  391. DWORD dwRegister
  392. , FILETIME* lpfiletime
  393. )
  394. {
  395. return comstl__Rot_NoteChangeTime(dwRegister, lpfiletime);
  396. }
  397. /** \brief Retrieves the last modification time of an object in the Running Object Table
  398. *
  399. * \ingroup group__library__utility__com
  400. *
  401. * Returns the time that an object was last modified. The object must have
  402. * previously been registered with the Running Object Table (ROT). This method
  403. * looks for the last change time recorded in the ROT.
  404. *
  405. * \param pmkObjectName Pointer to moniker on the object whose status is desired
  406. * \param lpfiletime Pointer to structure containing object's last change time
  407. * \return An HRESULT indicating success or failure
  408. */
  409. inline HRESULT Rot_GetTimeOfLastChange(
  410. LPMONIKER pmkObjectName
  411. , FILETIME* lpfiletime
  412. )
  413. {
  414. return comstl__Rot_GetTimeOfLastChange(pmkObjectName, lpfiletime);
  415. }
  416. /** \brief Queries the current set of objects in the Running Object Table
  417. *
  418. * \ingroup group__library__utility__com
  419. *
  420. * Creates and returns a pointer to an enumerator that can list the monikers of
  421. * all the objects currently registered in the Running Object Table (ROT).
  422. *
  423. * \param ppenumMoniker Address of output variable that receives the IEnumMoniker interface pointer
  424. * \return An HRESULT indicating success or failure
  425. */
  426. inline HRESULT Rot_EnumRunning(IEnumMoniker** ppenumMoniker)
  427. {
  428. return comstl__Rot_EnumRunning(ppenumMoniker);
  429. }
  430. #endif /* __cplusplus */
  431. /* /////////////////////////////////////////////////////////////////////////
  432. * Unit-testing
  433. */
  434. #ifdef STLSOFT_UNITTEST
  435. # include "./unittest/rot_functions_unittest_.h"
  436. #endif /* STLSOFT_UNITTEST */
  437. /* ////////////////////////////////////////////////////////////////////// */
  438. #ifndef _COMSTL_NO_NAMESPACE
  439. # if defined(_STLSOFT_NO_NAMESPACE) || \
  440. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  441. } /* namespace comstl */
  442. # else
  443. } /* namespace stlsoft::comstl_project */
  444. } /* namespace stlsoft */
  445. # endif /* _STLSOFT_NO_NAMESPACE */
  446. #endif /* !_COMSTL_NO_NAMESPACE */
  447. /* ////////////////////////////////////////////////////////////////////// */
  448. #endif /* !COMSTL_INCL_COMSTL_UTIL_H_ROT_FUNCTIONS */
  449. /* ///////////////////////////// end of file //////////////////////////// */