将ActiveX调用到不同的项目

时间:2017-09-15 06:14:52

标签: javascript asp.net activex

我正在使用ActiveX for IE。我只需要知道用户有一些" ABC"软件安装与否。我创建了一个ActiveX控件,当我在同一个项目上调用这个ActiveX时,这是完美的工作,这是示例代码

namespace DemoActiveX
{
    [ProgId("DemoCSharpActiveX.HelloWorld")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [Guid("415D09B9-3C9F-43F4-BB5C-C056263EF270")]
    [ComVisible(true)]
    public class HelloWord
    {
        [ComVisible(true)]
        public bool IsApplictionInstalled(string p_name)
        {
            string displayName;
            RegistryKey key;

            // search in: CurrentUser
            key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
            foreach (String keyName in key.GetSubKeyNames())
            {
                RegistryKey subkey = key.OpenSubKey(keyName);
                displayName = subkey.GetValue("DisplayName") as string;
                if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
                {
                    return true;
                }
            }

            // search in: LocalMachine_32
            key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
            foreach (String keyName in key.GetSubKeyNames())
            {
                RegistryKey subkey = key.OpenSubKey(keyName);
                displayName = subkey.GetValue("DisplayName") as string;
                if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
                {
                    return true;
                }
            }

            // search in: LocalMachine_64
            key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
            foreach (String keyName in key.GetSubKeyNames())
            {
                RegistryKey subkey = key.OpenSubKey(keyName);
                displayName = subkey.GetValue("DisplayName") as string;
                if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
                {
                    return true;
                }
            }

            // NOT FOUND
            return false;
        }

        //[ComVisible(true)]
        //public String SayHello()
        //{
        //    return "DemoActiveX";
        //}
    }
}    

我的JavaScript是

    <html>
<head>
    <title>DemoCSharpActiveX webpage</title>
</head>
<body>
    <OBJECT id="DemoActiveX" classid="clsid:415D09B9-3C9F-43F4-BB5C-C056263EF270" codebase="DemoActiveX.cab"></OBJECT>

    <script type="text/javascript">
        try {
            debugger;
                var pluginName = "Zoom";
                var obj = document.DemoActiveX;
                if (obj) {
                    var status = obj.IsApplictionInstalled(pluginName);
                    if (status) {
                        alert("Client have Zoom installed! Happiee");
                    }
                    else {
                        alert("Client don't have Zoom! Sad");
                    }

                } else {
                    alert("Object is not created!");
                }
            } catch (ex) {
                alert("Some error happens, error message is: " + ex.Description);
            }

    </script>
</body>
</html>

我也建立并注册我的dll如下 C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319&gt; regasm / codebase 也 在AssemblyInfo.cs文件中将ComVisible设置为true。

[assembly:ComVisible(true)]

现在的主要问题是,当我在ActiveX创建的同一个项目中创建这个HTML页面工作正常并且通过引用将此ActiveX调用到其他项目时,我得到var obj = document.DemoActiveX obj对象但是obj没有

obj.IsApplictionInstalled(pluginName); 

功能。所以我的代码总是异常。

我知道我错过了一些东西,但我无法纠正它。 &#34;我如何在保存解决方案但不同的类库项目中访问ActiveX代码&#34;

Please Look this Image

0 个答案:

没有答案