zoukankan      html  css  js  c++  java
  • ActiveX的AssemblyInof.cs文件 IObjectSafety  接口

    ActiveX的AssemblyInof.cs文件

    IObjectSafety  接口

    1.   [Guid("D4176A17-2A33-4903-8F37-9EBDD7CAFFD3"), ProgId("ActiveXDemo.UserControl1"), ComVisible(true)]  
    2.     public partial class UserControl1: UserControl,IObjectSafety  

    using System;
    using System.Runtime.InteropServices;
    namespace ActiveXDemo
    {
       

        [ComImport, GuidAttribute("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]//固定不变的
        [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IObjectSafety
        {
            [PreserveSig]
            int GetInterfaceSafetyOptions(ref Guid riid, [MarshalAs(UnmanagedType.U4)] ref int pdwSupportedOptions, [MarshalAs(UnmanagedType.U4)] ref int pdwEnabledOptions);

            [PreserveSig()]
            int SetInterfaceSafetyOptions(ref Guid riid, [MarshalAs(UnmanagedType.U4)] int dwOptionSetMask, [MarshalAs(UnmanagedType.U4)] int dwEnabledOptions);
        }
    }

    using System;
    using System.Windows.Forms;

    namespace ActiveXTest
    {
        using System.Runtime.InteropServices;

        [Guid("D4176A17-2A33-4903-8F37-9EBDD7CAFFD3"), ProgId("ActiveXDemo.UserControl1"), ComVisible(true)]
        public partial class UserControl1: UserControl,IObjectSafety
        {
           
            #region IObjectSafety 成员 格式固定

            private const string _IID_IDispatch = "{00020400-0000-0000-C000-000000000046}";
            private const string _IID_IDispatchEx = "{a6ef9860-c720-11d0-9337-00a0c90dcaa9}";
            private const string _IID_IPersistStorage = "{0000010A-0000-0000-C000-000000000046}";
            private const string _IID_IPersistStream = "{00000109-0000-0000-C000-000000000046}";
            private const string _IID_IPersistPropertyBag = "{37D84F60-42CB-11CE-8135-00AA004BB851}";

            private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;
            private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;
            private const int S_OK = 0;
            private const int E_FAIL = unchecked((int)0x80004005);
            private const int E_NOINTERFACE = unchecked((int)0x80004002);

            private bool _fSafeForScripting = true;
            private bool _fSafeForInitializing = true;

            public int GetInterfaceSafetyOptions(ref Guid riid, ref int pdwSupportedOptions, ref int pdwEnabledOptions)
            {
                int Rslt = E_FAIL;

                string strGUID = riid.ToString("B");
                pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
                switch (strGUID)
                {
                    case _IID_IDispatch:
                    case _IID_IDispatchEx:
                        Rslt = S_OK;
                        pdwEnabledOptions = 0;
                        if (_fSafeForScripting == true)
                            pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
                        break;
                    case _IID_IPersistStorage:
                    case _IID_IPersistStream:
                    case _IID_IPersistPropertyBag:
                        Rslt = S_OK;
                        pdwEnabledOptions = 0;
                        if (_fSafeForInitializing == true)
                            pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
                        break;
                    default:
                        Rslt = E_NOINTERFACE;
                        break;
                }

                return Rslt;
            }

            public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
            {
                int Rslt = E_FAIL;
                string strGUID = riid.ToString("B");
                switch (strGUID)
                {
                    case _IID_IDispatch:
                    case _IID_IDispatchEx:
                        if (((dwEnabledOptions & dwOptionSetMask) == INTERFACESAFE_FOR_UNTRUSTED_CALLER) && (_fSafeForScripting == true))
                            Rslt = S_OK;
                        break;
                    case _IID_IPersistStorage:
                    case _IID_IPersistStream:
                    case _IID_IPersistPropertyBag:
                        if (((dwEnabledOptions & dwOptionSetMask) == INTERFACESAFE_FOR_UNTRUSTED_DATA) && (_fSafeForInitializing == true))
                            Rslt = S_OK;
                        break;
                    default:
                        Rslt = E_NOINTERFACE;
                        break;
                }

                return Rslt;
            }

            #endregion
           

            public UserControl1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Hello");
            }
        }
    }

    1. >  
    2.   
    3. <!DOCTYPE html>  
    4.   
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head runat="server">  
    7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
    8.     <title></title>  
    9. </head>  
    10. <body>  
    11.     <div>  
    12.     <object id="ActiveX" classid="clsid:0973CD43-BED3-4468-86E9-B0D2344F54D6" codebase="test.cab"></object>  
    13.     <input type="button" onclick="alert(ActiveX.ForDefault());" value=" uuuu" />  
    14.     </div>  
    15. </body>  
    16. </html>  
  • 相关阅读:
    windows 资源管理器 运行非常缓慢或者无反应的解决办法
    RPC工作原理
    如何解决访问某些网站会跳出对话框标题为:address Book Viewer ,提示:"无法连接制定的目录服务.服务也许暂时不可用,或服务器名称不正确。"
    运行程序的时候出错MFC42D.dll找不到。
    谷歌金山词霸合作版升级后出现CBSText.dll故障
    Network drives trying to connect when offline
    解决任务挂起或冻结在Windows XP
    打开word或者office程序报错:Microsoft Visual C++ Runtime Library. Runtime Error!
    恢复officescan控制台密码
    excel中同时冻结窗格--冻结行列标题
  • 原文地址:https://www.cnblogs.com/xiangxiong/p/6419932.html
Copyright © 2011-2022 走看看