Re: How do I make a C# UserControl into an OCX file for VB6 use?

From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 02/04/05


Date: Fri, 4 Feb 2005 12:26:52 +0200

Dennis,

As far as I remember, this should look like something like this:

Sub Form_Load
  Dim objUserControl As Object
  Set objUserControl =
objShimControl.HostUserControl("MyNamespace.MyControl", "MyAssembly,
Version=1.0.0.0, Culture=Neutral, PublicKeyToken=null")
End Sub

-- 
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"Dennis Burdett" <deburdett@hotmail.com> wrote in message 
news:%237I9ElLCFHA.3336@TK2MSFTNGP11.phx.gbl...
> thanks Dmitriy,
>
> I have been trying to figure out how to do this most of the day and can 
> get
> it to build (at least the shim part) and I am then able to add the new dll
> to the VB6 project form BUT I guess I am just not understanding what or 
> how
> to make the changes my code to get it to actually add my UserControl to 
> the
> host shim dll so it will run my stuff within vb.
>
> Dennis
>
>
> "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.com> wrote
> in message news:exlE1MDCFHA.3096@TK2MSFTNGP14.phx.gbl...
>> Hi Dennis,
>>
>> You cannot turn a C# user control to an OCX - this possibility, as far as
> I
>> remember, was considered and partially implemented in early beta versions
> of
>> the Framework, but later Microsoft decided not to support it in the
> release
>> version. Still, you have a workaround (BTW it is widely used by 
>> developers
>> writing add-ins for VS .NET) - the so-called shim control. It is a free
>> small ActiveX control provided by Microsoft (not sure where to look for 
>> it
>> on the Microsoft website but I'm sure there are even several versions in
> the
>> "Files" section of this group: http://groups.yahoo.com/groups/vsnetaddin)
>>
>> The ActiveX has a couple of public methods designed to tell the ActiveX
>> which class from which assembly to host inside it. So you drag the 
>> ActiveX
>> to a VB6 form and then invoke its HostUserControl method - and voila, you
>> have a .NET control in your VB6 app.
>>
>> -- 
>> Sincerely,
>> Dmitriy Lapshin [C# / .NET MVP]
>> Bring the power of unit testing to the VS .NET IDE today!
>> http://www.x-unity.net/teststudio.aspx
>>
>> "Dennis Burdett" <deburdett@hotmail.com> wrote in message
>> news:O48hms$BFHA.3524@TK2MSFTNGP15.phx.gbl...
>> >I have a pretty complex control which use to be a C# windows form that I
> am
>> > trying to make into a control that can be dragged onto a VB6 form.
>> >
>> > I was able to make it into a com class that I could then go to VB6 and
> add
>> > the reference and call the object there without any problems.
>> >
>> > When I try to make it into a UserControl, I get it to build and it
>> > registers
>> > itself during the build with no errors BUT I can not add the dll to the
>> > vb6
>> > project. I can add the dll to another C# project and all the form
>> > (usercontrol) works as it should with the grid and toolbar buttons 
>> > doing
>> > their thing as planned.
>> >
>> > below is the top section of the class diff.
>> >
>> > The contructor doesn't do anything but the InitializeComponent() call.
>> >
>> > thanks for any assistance.
>> > Dennis
>> >
>> > using interop = System.Runtime.InteropServices;
>> >
>> > namespace TASAMS
>> >
>> > {
>> >
>> >    [interop.ProgId("TimeLineControl"),
>> >
>> >    interop.Guid("124B9B07-35A7-4c72-B04B-3A04E42F1E07"),
>> >
>> >    interop.ClassInterface(interop.ClassInterfaceType.AutoDispatch),
>> >
>> >    interop.ComVisible(true)]
>> >
>> >    public class TimeLineControl : System.Windows.Forms.UserControl
>> >
>> >    {
>> >
>> >    ....
>> >
>> >    }
>> >
>> >
>> >
>> >
>>
>
>