Active Safe

举报
清雨小竹 发表于 2022/09/25 00:58:18 2022/09/25
【摘要】 #include <objsafe.h> // for IObjectSafety; in ActiveX SDK //........................................................................ //ISafeObject DECLARE_INTERFA...

  
  1. #include <objsafe.h> // for IObjectSafety; in ActiveX SDK
  2. //........................................................................
  3. //ISafeObject
  4. DECLARE_INTERFACE_MAP()
  5. BEGIN_INTERFACE_PART(ObjSafe, IObjectSafety)
  6. STDMETHOD_(HRESULT, GetInterfaceSafetyOptions) (
  7. /* [in] */ REFIID riid,
  8. /* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
  9. /* [out] */ DWORD __RPC_FAR *pdwEnabledOptions
  10. );
  11. STDMETHOD_(HRESULT, SetInterfaceSafetyOptions) (
  12. /* [in] */ REFIID riid,
  13. /* [in] */ DWORD dwOptionSetMask,
  14. /* [in] */ DWORD dwEnabledOptions
  15. );
  16. END_INTERFACE_PART(ObjSafe);
  17. ///
  18. //.............................................................................
  19. // Interface map for IObjectSafety
  20. BEGIN_INTERFACE_MAP( CCameraACXCtrl, COleControl )
  21. INTERFACE_PART(CCameraACXCtrl, IID_IObjectSafety, ObjSafe)
  22. END_INTERFACE_MAP()
  23. //.............................................................................
  24. // IObjectSafety member functions
  25. // Delegate AddRef, Release, QueryInterface
  26. ULONG FAR EXPORT CCameraACXCtrl::XObjSafe::AddRef()
  27. {
  28. METHOD_PROLOGUE(CCameraACXCtrl, ObjSafe)
  29. return pThis->ExternalAddRef();
  30. }
  31. ULONG FAR EXPORT CCameraACXCtrl::XObjSafe::Release()
  32. {
  33. METHOD_PROLOGUE(CCameraACXCtrl, ObjSafe)
  34. return pThis->ExternalRelease();
  35. }
  36. HRESULT FAR EXPORT CCameraACXCtrl::XObjSafe::QueryInterface(
  37. REFIID iid, void FAR* FAR* ppvObj)
  38. {
  39. METHOD_PROLOGUE(CCameraACXCtrl, ObjSafe)
  40. return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  41. }
  42. const DWORD dwSupportedBits =
  43. INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  44. INTERFACESAFE_FOR_UNTRUSTED_DATA;
  45. const DWORD dwNotSupportedBits = ~ dwSupportedBits;
  46. //.............................................................................
  47. // CStopLiteCtrl::XObjSafe::GetInterfaceSafetyOptions
  48. // Allows container to query what interfaces are safe for what. We're
  49. // optimizing significantly by ignoring which interface the caller is
  50. // asking for.
  51. HRESULT STDMETHODCALLTYPE
  52. CCameraACXCtrl::XObjSafe::GetInterfaceSafetyOptions(
  53. /* [in] */ REFIID riid,
  54. /* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
  55. /* [out] */ DWORD __RPC_FAR *pdwEnabledOptions)
  56. {
  57. METHOD_PROLOGUE(CCameraACXCtrl, ObjSafe)
  58. HRESULT retval = ResultFromScode(S_OK);
  59. // does interface exist?
  60. IUnknown FAR* punkInterface;
  61. retval = pThis->ExternalQueryInterface(&riid,
  62. (void * *)&punkInterface);
  63. if (retval != E_NOINTERFACE) { // interface exists
  64. punkInterface->Release(); // release it--just checking!
  65. }
  66. // we support both kinds of safety and have always both set,
  67. // regardless of interface
  68. *pdwSupportedOptions = *pdwEnabledOptions = dwSupportedBits;
  69. return retval; // E_NOINTERFACE if QI failed
  70. }
  71. /
  72. // CStopLiteCtrl::XObjSafe::SetInterfaceSafetyOptions
  73. // Since we're always safe, this is a no-brainer--but we do check to make
  74. // sure the interface requested exists and that the options we're asked to
  75. // set exist and are set on (we don't support unsafe mode).
  76. HRESULT STDMETHODCALLTYPE
  77. CCameraACXCtrl::XObjSafe::SetInterfaceSafetyOptions(
  78. /* [in] */ REFIID riid,
  79. /* [in] */ DWORD dwOptionSetMask,
  80. /* [in] */ DWORD dwEnabledOptions)
  81. {
  82. METHOD_PROLOGUE(CCameraACXCtrl, ObjSafe)
  83. // does interface exist?
  84. IUnknown FAR* punkInterface;
  85. pThis->ExternalQueryInterface(&riid, (void * *)&punkInterface);
  86. if (punkInterface) { // interface exists
  87. punkInterface->Release(); // release it--just checking!
  88. }
  89. else { // interface doesn't exist
  90. return ResultFromScode(E_NOINTERFACE);
  91. }
  92. // can't set bits we don't support
  93. if (dwOptionSetMask & dwNotSupportedBits) {
  94. return ResultFromScode(E_FAIL);
  95. }
  96. // can't set bits we do support to zero
  97. dwEnabledOptions &= dwSupportedBits;
  98. // (we already know there are no extra bits in mask )
  99. if ((dwOptionSetMask & dwEnabledOptions) !=
  100. dwOptionSetMask) {
  101. return ResultFromScode(E_FAIL);
  102. }
  103. // don't need to change anything since we're always safe
  104. return ResultFromScode(S_OK);
  105. }

 
  

文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。

原文链接:zzzili.blog.csdn.net/article/details/8265514

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。