简体   繁体   中英

Create ActiveX.exe using .Net 4 and VS2010

My application is vb6 application which refer to delphi active.exe file. I need to replace this file with C# one. How can I create activeX exe with VS 2010 and C#?

(needless to say I cannot work with files other then activeX exe)

There is a tutorial by Microsoft about migrating VB6 ActiveX EXEs to .NET . It specifically states:

the Visual Basic 2005 upgrade wizard does not support upgrading Visual Basic 6 ActiveX EXEs

Therefore the Microsoft tools, at least, do not support producing an ActiveX EXE from .NET based on original VB6 code. (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.

As far as I am aware, a VB6 ActiveX EXE was essentially an out of process COM server.

(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. 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 . Note that this is similar to a technique for making cross calls between 32-bit and 64-bit.

From this Microsoft article describing one method the key points are:

  • Step 1: Build your .NET assembly with COM-visible types and interfaces

  • Step 2: Register your .NET assembly for COM interop

  • Step 3: Install your .NET assembly in the GAC

  • Step 4: Configure the default COM surrogate process for your assembly

  • Step 5: Activate your COM object using CLSCTX_LOCAL_SERVER

I think its steps 4 & 5 which are really the keys to this method.


[B1] A second approach is to create a " COM EXE Server Fully Implemented in Managed Code " by...

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.

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.

Correctly inserting Registry entries for the EXE assembly, including a LocalServer32 key.

Appropriately calling CoRegisterClassObject() and CoRevokeClassObject() on these factory classes.


[B2] What seems like a different example of this is here . 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#.

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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