Ben,
This can be done with a bit of fiddling with the registry when registering
the control. It's not without its problems though - I've only done it with a
simple control and although it works, the dreaded Dr.Watson rears his head a
little to often for my liking.
In order to get your dotnet usercontrol to be registered as an ActiveX
control, use the following code (watch out for linefeeds in this post):
------------------------
<ComClass(DotNetControl.ClassId, _
DotNetControl.InterfaceId, _
DotNetControl.EventsId)> _
Public Class DotNetControl
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
'...........
#End Region
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "570032C3-0613-403A-B9AA-73A82458FE07"
Public Const InterfaceId As String =
"1F97CA44-59FA-466D-A149-9598C84DC9EF"
Public Const EventsId As String = "051A142E-284C-46AB-9FA9-2B7CE7F56E00"
#End Region
' This function is called when registered
<ComRegisterFunction()> _
Private Shared Sub ComRegister(ByVal t As Type)
Dim keyName As String = "CLSID\" & t.GUID.ToString("B")
Dim key As RegistryKey = Registry.ClassesRoot.OpenSubKey(keyName, True)
key.CreateSubKey("Control").Close()
Dim subkey As RegistryKey = key.CreateSubKey("MiscStatus")
subkey.SetValue("", "131457")
subkey = key.CreateSubKey("TypeLib")
Dim libid As Guid = Marshal.GetTypeLibGuidForAssembly(t.Assembly)
subkey.SetValue("", libid.ToString("B"))
subkey = key.CreateSubKey("Version")
Dim ver As Version = t.Assembly.GetName().Version
Dim version As String = String.Format("{0}.{1}", ver.Major, ver.Minor)
If version = "0.0" Then version = "1.0"
subkey.SetValue("", version)
End Sub
' This is called when unregistering
<ComUnregisterFunction()> _
Private Shared Sub ComUnregister(ByVal t As Type)
' Delete entire CLSID\{clsid} subtree
Dim keyName As String = "CLSID\" + t.GUID.ToString("B")
Registry.ClassesRoot.DeleteSubKeyTree(keyName)
End Sub
' Rest of control implementation ......
End Class
------------------------
Sorry about the messy nature of the code above - I got it a while ago in C#
and simply ran it through one of those C# to VB convertors.
Hope this helps.
Trev.
"Ben Reese" <b_*******@hotmail.com> wrote in message
news:07****************************@phx.gbl...
Is it possible to compile or register a user control
created in VB.net for use as an ActiveX OCX in VB6?
The reason I want to do this is that I have a third party
application (Ascent Capture 5.5) which is customisable
through OCX plugins and I want to build these in .Net.
There is plenty of discussion in msdn (and other
literature) about COM to .Net interop in both directions
for DLLs and how to convert ActiveX OCXs for use in .net
forms. However I cannot find any discussion about the
reverse process.
I am able to specify UserControl classes as COM
registerable and use the publicly exposed methods from VB6
having created a reference to the Dll but this does not
give me access to any of the GUI funcionality. Attempting
to add the .Net dll to controls results in the error "...
was not registerable as an ActiveX component". I have even
resorted to attempting to fudge it in by maually editing
the .vbp and .frm files with the correct GUIDs. This
(unsuprisingly) resulted in the pair of erros "Unable to
load ...dll" followed by "... is not a loaded control
class".
Am I simply barking up the wrong tree or is there a way?
Thanks in advance