How to create an ActiveX control in C#?(如何在 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!!!");
}
}
}
然后我做了以下步骤:
- 属性 => 应用程序 => 程序集信息 => 使程序集 COM 可见
- Build => 注册 COM 互操作 TRUE(选中)
- 为程序集创建强名称(签名)
- 构建项目
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 控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 C# 中创建 ActiveX 控件?
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 如果条件可以为空 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
