473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

.Net user control as OCX through interop

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
Nov 22 '05 #1
3 7385
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

Nov 22 '05 #2
I forgot to mention that in addition to doing the extra registry stuff, you
have to dynamically add the control to the form in VB6 at run time, instead
of design time like this:

VB6------------------------
Me.Controls.Add "DotNetActiveXControlTest.DotNetControl", "dotnet"
Me.Controls("dotnet").Visible = True

---------------------------

where

Me = the form
"DotNetActiveXControlTest.DotNetControl" = the full namespace of your
control
"dotnet" = the identifier (name) of the control on the form.

you can then access properties on the control by using

With Me.Controls("dotnet")

.Left = 0
.Width = Me.Width / 2
.Height = Me.Height / 2
.Top = 0

End With

to access the properties and methods on your dotnet class use

Me.Controls("dotnet").object.MethodName

where "MethodName" is the name of the method or property you want to use.

Hope this helps,

Trev.
Nov 22 '05 #3
Thanks Trev

this has worked a treat for putting the control on a VB6
form

unfortunately my 3rd Party App does not like it.
I guess I'll have to stick to legacy technologies for my
legacy products.

Ben
-----Original Message-----
I forgot to mention that in addition to doing the extra registry stuff, youhave to dynamically add the control to the form in VB6 at run time, insteadof design time like this:

VB6------------------------
Me.Controls.Add "DotNetActiveXControlTest.DotNetControl", "dotnet"Me.Controls("dotnet").Visible = True

---------------------------

where

Me = the form
"DotNetActiveXControlTest.DotNetControl" = the full namespace of yourcontrol
"dotnet" = the identifier (name) of the control on the form.
you can then access properties on the control by using

With Me.Controls("dotnet")

.Left = 0
.Width = Me.Width / 2
.Height = Me.Height / 2
.Top = 0

End With

to access the properties and methods on your dotnet class use
Me.Controls("dotnet").object.MethodName

where "MethodName" is the name of the method or property you want to use.
Hope this helps,

Trev.
.

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ben Reese | last post by:
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...
0
by: Markus Poehler | last post by:
Hi my program should run on terminal server. I open Acrobat process and I have to kill them at some points in my application. This fails cause of insufficient rights on terminal server. the...
5
by: john | last post by:
I searched http://www.sellsbrothers.com. and could not find anything about this subject. How do I make C# User Controls Visible to Visual Basic 6.0 Applications? Thanks, John
3
by: Tamir Khason | last post by:
I have unmanaged COM wich is ActiveX I want to use it as signed interop user control so doing aximp MyComActiveX.dll /keyfile:MyKey.snk it builds MyComActiveLibX.dll wich is signed and...
2
by: Mehr H | last post by:
I have been working on this for several days and am still have had no success in achieving this. Pleae help. It seems that documentation for this is very limited. I have looked in several books and...
1
by: Mehr H | last post by:
I have been working on this for several days and am still have had no success in achieving this. Pleae help. It seems that documentation for this is very limited. I have looked in several books and...
9
by: Srinivas | last post by:
hi all how to access the outlook user profiles through VB.net any help.... thanks in advanc Srinivas
7
by: Michelangelo | last post by:
Hi All, I hace created a sample user control in Visual Studio .NET (2003); I have been able to compile and use it (add it to a form) in a test standard windows application, but when I try to...
8
by: Lou | last post by:
How do I create a User Control or .dll in VB .Net to be used in VB6? -Lou
9
by: timnels | last post by:
I have an issue where I have a user control that is launched into a floating form. At some point later, I allow the user to "unfloat" the user control by reparenting it on a split container in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.