I am using ActiveX control and installing it by msi. The method written in ActiveX user control class are firing but UI is not visible

100 views Asked by At
<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>

I have used object tag in Htm file and have provided the classid and codebase to my code. My method Data() is calling successfully but the view of my ActiveX control is not visible. I don't want to use Caspol.exe to fix my query

1

There are 1 answers

0
CodeOptimizer On
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;
        }
    }
}

This code is written in my ActiveX class where it can be clearly seen that constructor is calling the method to Initialize form object.