Publish DotNet component as Active-X

Posted on 2012-03-27
Medium Priority
Last Modified: 2012-03-29
* I have a collegue working in Visual Studio (Enterprise edition I think)
* He is creating DotNet objects which include DotNet components, but for some of them we wish to provide an Active-X wrapper so that they can be used from within Visual Basic 6 (and Delphi-7)
* At present he is doing this manually, but it is fairly time consuming.
* I would have expected that since DotNet provides access to component properties using reflection that there would be a way of automatically publishing all the component properties in the Active-X component in Visual Studio but we have not been able to find one.
* If there is a way of doing this within Visual Studio I would be very happy to hear about it.
* Alternatively is there a tool available which would allow us to pick up a DotNet component and provide an Active-X wrapper and .tlb file to allow it to be used in a VB6 Project
* The language in use is C#
Question by:GHG-RCH
  • 2
  • 2
LVL 40
ID: 37775385
You are asking for a lot or problems.

Microsoft did a good work of enabling .NET application to work with Active-X (COM) components, but could not do the reverse. .NET came out some 10-15 years after COM. They could not know when they designed COM what would be in .NET, and some feature of .NET components are not available at all to COM applications. They did not expect a lot of programmers to do it, so there is not tool to automatically create a wrapper in this direction like the Interop mechanism does when you want .NET to reference COM.

The main problem comes from data types. Some of them, such as Date, have changed their format. Others, such as Long, did not exist in VB6 (The VB6 Long is the .NET Integer - Long is bigger in .NET and there is nothing similar to a .NET Long in a VB6 application).

The question is not one of a wrapper, it is one of designing the .NET component so that it is compatible with COM. The only ones I encountered where Long and Date, but there are probably others. I did only one very simple thing of that type, so I did not have time to discover all the possible problems.

As far as those are concerned, you should not use Long in your .NET component. Methods  and properties that return ou accept dates should accept dates and return dates that are compatible with the COM format, that is to use the FromOADate and ToOADate methods of the Date type for conversions. There is probably a similar problem with the VB6 Currency type, because there are FromOACurrency and ToOACurrency methods also available, although I did not have to check those because there was no Currency type involved in the project that I worked with.

Another thing that gave me problems is overloading, that did not exist in COM. You need to use optional parameters instead.

An important thing to do, once the component has been designed with those types of things in mind is to set a few compilation properties. In the project's Properties window, under Assembly Information in the Application tab, make sure that you have a GUID that the Make assembly COM-Visible checkbox is checked. This will generate the necessary informations so that the .NET dll will be registered in the registry upon installation.

You also need to make sure that the dll is properly registered, which is a prerequisite for COM to be able to find a dll. .NET dlls do not need to be registered, so by default they are not. Most tools that creates installations have a property, an option or a switch somewhere that enables you to specify that the dll must be registered upon installation.

Author Comment

ID: 37781225
Thanks this was helpful and we can now access the component from within VB6, except that the properties and methods are not visible in the VB6 Intellisense system. This means that when we type ObjectName. or InterfaceName. we do not get the list of properties

The object we are trying to use is the DotNet rich text box and the definition in use in C# is shown below.

Do you know what we need to do to be able to use the VB6 Intellisense?



[ClassInterface(ClassInterfaceType.AutoDispatch), ComVisible(true), Docking(DockingBehavior.Ask), Designer("System.Windows.Forms.Design.RichTextBoxDesigner, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]

public partial class TPRichTextBox : System.Windows.Forms.RichTextBox, iTPRichTextBox



LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 2000 total points
ID: 37782570
You need to create an interface that defines the properties and methods you want to expose and implement that interface in your class.

Microsoft has a straigthforward article about that in their Knowledge Base (http://support.microsoft.com/kb/813809/e)

Author Closing Comment

ID: 37782735
Thanks very much for this it looks like it will resolve our issue.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question