Publish DotNet component as Active-X

* 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#
Clive HensonTechnical DirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
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.
Clive HensonTechnical DirectorAuthor Commented:
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?

[ProgId("TPScratchy.RichTextBox")]

[Guid("8fb7f710-0881-40ea-a128-625c968689e0")]

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

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

{

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

}
Jacques Bourgeois (James Burger)PresidentCommented:
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)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Clive HensonTechnical DirectorAuthor Commented:
Thanks very much for this it looks like it will resolve our issue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.