如何在 C# 中创建 ActiveX 控件? [英] How to create an ActiveX control in C#?

查看:24
本文介绍了如何在 C# 中创建 ActiveX 控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 C# 中创建功能正常的 ActiveX 控件;我已尝试按照教程进行操作,但没有成功.

I am not able to create a functioning ActiveX control in C#; I have tried following tutorials to do so without success.

我创建了一个包含以下代码的示例类库项目:

I create a sample Class Library project which includes this code:

namespace AACWCSurvey
{
    [ProgId("Prisoner.PrisonerControl")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Class1
    {
        public Class1()
        {
            MessageBox.Show("FIRETRUCK!!!");
        }
    }
}

然后我做了以下步骤:

  1. 属性 => 应用程序 => 程序集信息 => 使程序集 COM 可见
  2. Build => 注册 COM 互操作 TRUE(选中)
  3. 为程序集创建强名称(签名)
  4. 构建项目
  5. regasm MyDll.dll/tlb/codebase

在 tstcon32 中看不到 Prisoner.PrisonerControl =(

Can't see Prisoner.PrisonerControl in tstcon32 =(

我的操作系统是 WinXP x86.

My OS is WinXP x86.

UPD: 它适用于 VBScript:

UPD: it works from VBScript:

Dim objJava
Set objJava = WScript.CreateObject("Prisoner.PrisonerControl")

但在 tstcon32 中不可见.

but it is not visible in tstcon32.

推荐答案

如果您阅读 使用 Prisoner.PrisonerControl 控件的实际文章 使用您的控件 GUID 在该键内创建名为 Control 的子键.

If you read the actual article using the Prisoner.PrisonerControl control a sub key named Control is created inside the key with your control GUID.

在我的机器上使用 guid {9DEA5F06-E324-31A7-837B-D0F3BDE91423} 创建密钥

On my machine with the guid {9DEA5F06-E324-31A7-837B-D0F3BDE91423} creating the key

HKEY_CLASSES_ROOTCLSID{9DEA5F06-E324-31A7-837B-D0F3BDE91423}Control

使控件出现在 tstcon32 中.无论有没有它,ActiveX 都可用于 javascript

Make the control appears in tstcon32. And with or without it the ActiveX is usable for javascript

var x = new ActiveXControl("Prisoner.PrisonerControl");

<小时>

实际上,我不得不在 javascript 执行和注册表路径上都与 windows 作斗争才能在我的系统上对其进行测试,因为它是 x64 机器,但那是另一回事了.

这篇关于如何在 C# 中创建 ActiveX 控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆