c# - 如何从 dll 依赖项创建 CCW

标签 c# javascript asp.net ccw

我正在为 C# 类库创建一个 CCW 组件,该库包含一些第三方 DLL。

  1. 此用户控件必须在Classic Asp 页面中使用

  2. 为此生成了一个 CCW Wrapper 类

  3. 在 Wrapper 类中为函数声明创建接口(interface)。

此接口(interface)和类包含 C# 类库 DLL 和第三方 DLL 的引用

界面

[ComVisible(true)]
    [Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]//GUID for this interface
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]//Enable early as well as late binding
    public interface IInterface
    {
        [DispId(1)]
        void Init();

        [DispId(2)]
        void OpenFile(string FileName);

        [DispId(3)]
        void Dispose();

        [DispId(4)]
        THirdPartyDLLClass ThirdPartyMethod();
    }

接口(interface)实现类

    [ComVisible(true)]
    [Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]//GUID for this class
    [ClassInterface(ClassInterfaceType.None)]//Don't generate any interface  automatically.  We will explicitly create one
    [ComSourceInterfaces(typeof(IInterface))]//Expose events
    [ProgId("CCWTEST.ClassMath")]//Friendly name of the class. Used while creating object without using 'New' keyword
    public class ClassMath : IInterface
    {
      [ComVisible(false)]//Don't expose to COM. Can be used internally.
      private ViewerControl objViewerControl = new ViewerControl(); //ref dll class file

      [ComVisible(true)]
       public void Init()
        {
         objViewerControl.Init();
        }

       [ComVisible(true)]
        public void OpenFile(string FileName)
         {
          objViewerControl.OpenFile(FileName);
         }

       [ComVisible(true)]
        public void Dispose()
         {
          objViewerControl.Dispose();
         }

       [ComVisible(true)]// 
        public THirdPartyDLLClass  ThirdPartyMethod()
         {
           return THirdPartyDLLClass.ThirdPartyClassProperty;
          }
       }

经典 ASP 中的 JavaScript

window.onload = onLoad;
        function onLoad()
        {
            try
            {                
                var obj = new ActiveXObject("CCWTEST.ClassMath");           

            }
            catch (e)
            {
                alert(e.Message);
            }
        }

在将此 DLL 注册到 gacutil/i 并尝试将这些 dll 访问到我的 java 脚本代码后,它给我一个“未定义” 错误。我不知道这会出什么问题。为此必须将第三方 DLL 和 C# 类库安装到 GAC 中

最佳答案

尝试使用 regsvr32.exe CCWTEST.ClassMath.ocx(您的 COM .ocx 组件文件)代替 gacutil 来注册您的 COM 组件。

关于c# - 如何从 dll 依赖项创建 CCW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16813738/

相关文章:

javascript - 将鼠标悬停在 anchor 旁边的图像上时显示隐藏 Div?

javascript - 无法确定单选按钮是否被选中

c# - 使用 C# 处理字节数组中的 _bstr_t 并返回

C#快速图表近似比较算法

javascript - 在带有溢出的 div 中使用 AOS(滚动动画)

javascript - 优化React中的功能。有 setState key 作为 Prop 吗?

c# - 需要帮助提高 SQL DELETE 性能

C# SQlite 连接字符串格式

javascript - 巫毒魔法干扰了我的 javascript,我快疯了

asp.net - DIV 中 Google map 的正确大小(以百分比表示)