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 控件?


- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01