我正在使用ActiveX控件并通过msi安装它.用ActiveX用户控件类编写的方法正在触发,但UI不可见

本文关键字:控件 ActiveX 方法 UI 用户 msi 安装 | 更新日期: 2023-09-27 17:54:00

<object name="Form" id='Form' classid='2F76566A-964F-4547-BD48-EE498AE1A7A2' 
       codebase='ActiveXControl.cab#version=1,0,0,0'
       width="500px" height="500px" style="background-color:Blue">
</object>
<script type="text/javascript" language="javascript">
    var x = new ActiveXObject("ActiveXControl.ControlClass");
    x.UserTxt = "Aashish";
    x.password = "Rockstar";
    x.getmethod();
    alert(x.Data());
</script>

我在Htm文件中使用了对象标签,并为我的代码提供了分类和代码库。我的方法Data()正在成功调用,但我的ActiveX控件的视图不可见。我不想使用Caspol.exe来修复我的查询

我正在使用ActiveX控件并通过msi安装它.用ActiveX用户控件类编写的方法正在触发,但UI不可见

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ActiveXControl
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("2F76566A-964F-4547-BD48-EE498AE1A7A2")]
    [ProgId("ActiveXControl.ControlClass")]
    [ComDefaultInterface(typeof(Intermediate))]
    public partial class ControlClass : UserControl, Intermediate, IObjectSafety
    {
        public ControlClass()
        {
            InitializeComponent();
        }
        public string UserTxt { get; set; }
        public string password { get; set; }
        public void getmethod()
        {
            textBox1.Text = UserTxt;
            textBox2.Text = password;
        }
        public string Data()
        {
            return textBox1.Text +" " + textBox2.Text;
        }
        public enum ObjectSafetyOptions
        {
            INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001,
            INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002,
            INTERFACE_USES_DISPEX = 0x00000004,
            INTERFACE_USES_SECURITY_MANAGER = 0x00000008
        };
        public int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
        {
            ObjectSafetyOptions m_options = ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER | ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA;
            pdwSupportedOptions = (int)m_options;
            pdwEnabledOptions = (int)m_options;
            return 0;
        }
        public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
        {
            return 0;
        }
    }
}

这段代码是在我的ActiveX类中编写的,可以清楚地看到构造函数正在调用初始化表单对象的方法。