3

単純な.NetComActiveXを作成し、javascriptでイベントを管理できるようになりました。私は多くの投稿や記事を読みましたが、何もしません。クライアント側では、1つのjavascript構文(attachEvent、関数名など)でイベントをキャッチできません。

以下は、ActiveXに関するコードスニペットです。

[ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [Guid("61327C9D-EFC5-42B7-BA0D-4A8648797003")]
    public interface IHelloWorld
    {
        string GetText();
    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    [Guid("61327C9D-EFC5-42B7-BA0D-4A8648797003")]
    public interface IMyEvt
    {
        [DispId(1)]
        void OnMyEvt(int prm);
    }

    [ComImport()]
    [Guid("13AD0E8B-BA3F-4CDE-A7D4-8A311EC1766B")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface IObjectSafety
    {
        [PreserveSig()]
        int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions);

        [PreserveSig()]
        int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);
    }




    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("32E6AD29-DD5F-46EA-A4D1-BD2F1E3EE064")]
    [ProgId("AxControls.HelloWorld")]
    [ComSourceInterfaces(typeof(IMyEvt))]
    public class HelloWorld : UserControl, IHelloWorld, IObjectSafety
    {
        [ComVisible(false)]
        public delegate void OnMyEvtDelgate(int prm);

        [DispId(1)]
        public event OnMyEvtDelgate OnMyEvt;

        public HelloWorld()
        {
            this.OnMyEvt += new OnMyEvtDelgate(Dummy);
        }

        void Dummy(int param) { }

        #region IHelloWorld Members

        public string GetText()
        {
            return "Hello ActiveX World!";
        }

        #endregion

        #region IObjectSafety Members

        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;
        }

        #endregion

    }
4

1 に答える 1

0

次の方法でイベントを添付できるはずです。

<script type="text/javascript">     
var activex = new ActiveXObject("AxControls.HelloWorld");
        function raise() {
            eval("function activex::HelloWorld(prm) {return onHelloWorld(prm);}");
            activex.HelloWorld();
        }

        function onHelloWorld(prm) {
            alert(prm);
            return true;
        }

    </script>
于 2013-05-10T09:48:13.427 に答える