1

尽管研究了我在网上找到的几篇关于该主题的文章,但我一直在努力尝试让一个简单的ActiveX DLL 工作但没有成功。

我怀疑我有几件事编码不正确,因为我对此并不熟悉,而且大多数关于该主题的文章都已过时。我正在使用Visual Studio 2008,并且一直在使用Windows SDK v7.1 进行数字签名。

我想要做的是将客户端 machineName 从环境类返回到网页(并最终返回到 Web 服务器)。

这是我的 C# 类:

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Win32;

namespace GetClientInfo101
{
    [Guid("121C3E0E-DC6E-45dc-952B-A6617F0FAA32")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [ComVisible(true)]
    public interface IGetClient
    {
        [DispId(1)]
        string GetClient();
    }
    [Guid("5085C918-0236-4828-BDFA-063FEE57C69B")]
    [ProgId("getClientInfoAx.CGetClient")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(IGetClient))]
    [System.ComponentModel.ToolboxItem(true)]
    [ComVisible(true)]
    public class CGetClient : IGetClient
    {
        public string GetClient()
        {
           return Environment.MachineName;
        }
    }
}

这是我的组装:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("GetClientInfo101")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GetClientInfo101")]
[assembly: AssemblyCopyright("Copyright © N/A 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1bf2a0bc-f9cb-4f68-8990-5caaf3ab525d")]

// Version information for an assembly consists of the following four values:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")

这是我网站母版页上的对象标签和脚本。**注意:我收到错误

Microsoft JScript 运行时错误:自动化服务器无法创建对象

关于“var”执行**:

<object id="getClientInfo" name="GetClientInfo101" classid="clsid:5085C918-0236-4828-BDFA-063FEE57C69B"
        codebase="GetClientInfo/GetClientInfoAX.cab#version=1,0,0,0">
</object>

<script type="text/javascript">
    function OpenActiveX()
    {
        var objGetClientInfo = new ActiveXObject("GetClientInfoAx.CGetClient");
        if(objGetClientInfo != null)
         {
             //For testing only
             alert(objGetClientInfo.GetClient());
         }
     }
</script>

然后我手动创建了一个 .inf 文件,如下所示:

[version]
    signature="$CHICAGO$"
    AdvancedINF=2.0
[Add.Code]
    GetClientInfo101.dll=GetClientInfo101.dll
    GetClientInfo101.inf=GetClientInfo101.inf
[GetClientInfo101.dll]
    file-win32-x86=thiscab
    clsid={5085C918-0236-4828-BDFA-063FEE57C69B}
    FileVersion=1,0,0,0
    RegisterServer=yes
[GetClientInfo101.inf]
    file=thiscab

但是,当我构建我的.cab文件时,我也得到一个.OSD文件输出.cab如下(我担心同一个文件中同时存在一个文件.inf和一个文件。这是正确的,它会导致问题吗?我不知道如何告诉 Visual Studio 不要构建文件。.OSD.cab.OSD

<?XML version="1.0" ENCODING='UTF-8'?>
<!DOCTYPE SOFTPKG SYSTEM "http://www.microsoft.com/standards/osd/osd.dtd">
<?XML::namespace href="http://www.microsoft.com/standards/osd/msicd.dtd" as="MSICD"?>
<SOFTPKG NAME="GetClientInfoAX" VERSION="1,0,0,0">
    <TITLE> GetClientInfoAX </TITLE>
    <MSICD::NATIVECODE>
        <CODE NAME="GetClientInfo101">
            <IMPLEMENTATION>
                <CODEBASE FILENAME="GetClientInfo101.dll">
                </CODEBASE>
            </IMPLEMENTATION>
        </CODE>
    </MSICD::NATIVECODE>
</SOFTPKG>

无论如何,试图拼凑所有细节是一场噩梦。对于解决此问题的任何帮助,我将不胜感激。

好的,代码项目文章A Complete Scriptable ActiveX Web Control Tutorial Using ATL是我用作签署.cab文件的指南。请参阅标题为“签署 cab 文件”的部分。

这是我使用的命令。请注意,我使用 Visual Studio 创建 cab 文件而不是 CABARC。另请注意,我仅使用测试证书:

makecert -sv "getclientinfocert.pvk" -n "CN=My Company" getclientinfocert.cer

cert2spc getclientinfocert.cer getclientinfocert.spc

pvk2pfx -pvk getclientinfocert.pvk -pi AOTC20467cert -spc getclientinfocert.spc -pfx getclientinfocert.pfx -po AOTC81396pass –f

signtool sign /f getclientinfocert.pfx /p AOTC81396pass /t http://timestamp.verisign.com/scripts/timstamp.dll /v GetClientInfo101.dll

signtool sign /f getclientinfocert.pfx /p AOTC81396pass /t http://timestamp.verisign.com/scripts/timstamp.dll /v GetClientInfoAX.cab

用于certmgr将“根代理”证书导出​​和导入到受信任的根证书:

signtool verify /v /a GetClientInfoAX.cab

请注意,我将我的 DLL 复制到我的 Windows SDK 文件夹,对其进行签名,将其复制回我的cab文件,然后我将其复制到我的 SDK 文件,对cab文件进行签名。最后,我将文件复制cab到我的网站项目中。

注意:请参阅第一个答案末尾的评论。我从Comodo购买了签名证书并安装了该证书,即使证书状态为“OK”,我现在也会收到“Unknown Publisher”错误。DLL 和 CAB 文件均已签名。

我相信我现在的问题是控件需要被标记为安全的脚本。我发现了最近的一篇文章,使用 C# 在 .NET 中创建 ActiveX 控件,看起来很有帮助。

4

1 回答 1

0

ComVisible co 类中与版本无关的 progid 设置为

  [ProgId("getClientInfoAx.CGetClient")] 

而在 JScript 代码中,实例化代码为

  var objGetClientInfo = new ActiveXObject("GetClientInfoAx.CGetClient");

请先验证区分大小写并确认行为?

于 2010-10-11T15:32:33.943 回答