简体   繁体   English

使用 .Net 4 和 VS2010 创建 ActiveX.exe

[英]Create ActiveX.exe using .Net 4 and VS2010

My application is vb6 application which refer to delphi active.exe file.我的应用程序是 vb6 应用程序,它引用 delphi active.exe 文件。 I need to replace this file with C# one.我需要用 C# 替换这个文件。 How can I create activeX exe with VS 2010 and C#?如何使用 VS 2010 和 C# 创建 activeX exe?

(needless to say I cannot work with files other then activeX exe) (不用说我不能使用除 activeX exe 之外的文件)

There is a tutorial by Microsoft about migrating VB6 ActiveX EXEs to .NET .微软有一个关于将 VB6 ActiveX EXEs 迁移到 .NET的教程。 It specifically states:它特别指出:

the Visual Basic 2005 upgrade wizard does not support upgrading Visual Basic 6 ActiveX EXEs Visual Basic 2005 升级向导不支持升级 Visual Basic 6 ActiveX EXE

Therefore the Microsoft tools, at least, do not support producing an ActiveX EXE from .NET based on original VB6 code.因此,Microsoft 工具至少不支持基于原始 VB6 代码从 .NET 生成 ActiveX EXE。 (That does not mean that another route might not be possible.) (这并不意味着可能不可能有另一条路线。)

An alternative approach could be to convert it to a regular .NET COM Interop DLL which is a lot easier, but you may require it to run out-of-process which a DLL cannot do. An alternative approach could be to convert it to a regular .NET COM Interop DLL which is a lot easier, but you may require it to run out-of-process which a DLL cannot do.

As far as I am aware, a VB6 ActiveX EXE was essentially an out of process COM server.据我所知,VB6 ActiveX EXE 本质上是一个进程外的 COM 服务器。

(There could well be some subtleties which mean those are not strictly identical concepts, but I think that was the main idea). (很可能有一些微妙之处,这意味着它们不是严格相同的概念,但我认为这是主要思想)。

There certainly seem to be several ways of creating out of process COM servers from .NET.似乎有几种方法可以从 .NET 创建进程外 COM 服务器。 This other question has several good answers .这个其他问题有几个很好的答案

Below is a summary of all the distinct basic techniques I have read about.下面是我读过的所有不同的基本技术的总结。


[A] One approach is to use a "surrogate" process to host the DLL . [A] 一种方法是使用“代理”进程来托管 DLL Note that this is similar to a technique for making cross calls between 32-bit and 64-bit.请注意,这类似于在 32 位和 64 位之间进行交叉调用的技术。

From this Microsoft article describing one method the key points are:这篇描述一种方法的微软文章中,关键点是:

  • Step 1: Build your .NET assembly with COM-visible types and interfaces第 1 步:使用 COM 可见类型和接口构建 .NET 组件

  • Step 2: Register your .NET assembly for COM interop第 2 步:为 COM 互操作注册您的 .NET 组件

  • Step 3: Install your .NET assembly in the GAC第 3 步:在 GAC 中安装 .NET 组件

  • Step 4: Configure the default COM surrogate process for your assembly第 4 步:为您的装配配置默认的 COM 代理过程

  • Step 5: Activate your COM object using CLSCTX_LOCAL_SERVER第 5 步:使用 CLSCTX_LOCAL_SERVER 激活您的 COM object

I think its steps 4 & 5 which are really the keys to this method.我认为它的第 4 步和第 5 步确实是这种方法的关键。


[B1] A second approach is to create a " COM EXE Server Fully Implemented in Managed Code " by... [B1] 第二种方法是创建一个“在托管代码中完全实现的 COM EXE 服务器 ...

completely dressing up a .NET EXE assembly as a COM Local Server by fulfilling all the requirements of such a server as stipulated by the COM specifications.通过满足 COM 规范规定的此类服务器的所有要求,将 .NET EXE 程序集完全装扮成 COM 本地服务器。

It states that doing this meets the following requirements and shows an example:它指出这样做符合以下要求并显示了一个示例:

Providing a class factory class (which implements the COM IClassFactory interface) for every .NET class that we want to export to COM. Providing a class factory class (which implements the COM IClassFactory interface) for every .NET class that we want to export to COM.

Correctly inserting Registry entries for the EXE assembly, including a LocalServer32 key.正确插入 EXE 程序集的注册表项,包括 LocalServer32 项。

Appropriately calling CoRegisterClassObject() and CoRevokeClassObject() on these factory classes.在这些工厂类上适当地调用 CoRegisterClassObject() 和 CoRevokeClassObject()。


[B2] What seems like a different example of this is here . [B2] 这似乎是一个不同的例子 It states:它指出:

The sample demonstrates an out-of-process COM server in the form of local server (EXE), which is implemented entirely in Visual C#.该示例演示了本地服务器 (EXE) 形式的进程外 COM 服务器,该服务器完全在 Visual C# 中实现。

This may differ in some technical details (I haven't really assessed how fundamentally different this might be.)这可能在某些技术细节上有所不同(我还没有真正评估过这可能有多么根本的不同。)


[C] Possibly another approach is to "create COM+ components using System.EnterpriseServices.ServicedComponent " (which is briefly described on SO at this link ). [C] 可能另一种方法是“使用System.EnterpriseServices.ServicedComponent创建 COM+ 组件”(在此链接的 SO 上有简要描述)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM