473,607 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.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 7403
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(DotNe tControl.ClassI d, _
DotNetControl.I nterfaceId, _
DotNetControl.E ventsId)> _
Public Class DotNetControl
Inherits System.Windows. Forms.UserContr ol

#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
<ComRegisterFun ction()> _
Private Shared Sub ComRegister(ByV al t As Type)

Dim keyName As String = "CLSID\" & t.GUID.ToString ("B")
Dim key As RegistryKey = Registry.Classe sRoot.OpenSubKe y(keyName, True)
key.CreateSubKe y("Control").Cl ose()
Dim subkey As RegistryKey = key.CreateSubKe y("MiscStatus ")
subkey.SetValue ("", "131457")
subkey = key.CreateSubKe y("TypeLib")
Dim libid As Guid = Marshal.GetType LibGuidForAssem bly(t.Assembly)
subkey.SetValue ("", libid.ToString( "B"))
subkey = key.CreateSubKe y("Version")
Dim ver As Version = t.Assembly.GetN ame().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
<ComUnregisterF unction()> _
Private Shared Sub ComUnregister(B yVal t As Type)
' Delete entire CLSID\{clsid} subtree
Dim keyName As String = "CLSID\" + t.GUID.ToString ("B")
Registry.Classe sRoot.DeleteSub KeyTree(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_*******@hotm ail.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 "DotNetActiveXC ontrolTest.DotN etControl", "dotnet"
Me.Controls("do tnet").Visible = True

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

where

Me = the form
"DotNetActiveXC ontrolTest.DotN etControl" = 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("do tnet")

.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("do tnet").object.M ethodName

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.Ad d "DotNetActiveXC ontrolTest.DotN etControl", "dotnet"Me.Controls("d otnet").Visible = True

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

where

Me = the form
"DotNetActiveX ControlTest.Dot NetControl" = 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("do tnet")

.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("d otnet").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
2019
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 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
0
3322
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 lines: Dim p As New Process For Each p In Process.GetProcesses If LCase(p.ProcessName) = "acrord32" Then 'p.Kill()
5
524
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
2243
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 AxMyComActiveXLib.dll wich is interoped ActiveX control. This one Ax... DOES NOT SIGNED !!! and when using it inside the form I recieve "Assembly generation failed -- Referenced assembly 'AxMyComActiveXLib' does not have a strong name What is the...
2
1791
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 they all seem to say either nothing about this or that this is "out of the scope of this book", even "Professional ASP.NET". I have a ActiveX component that I'd like to expose through a .NET wrapper so in the case that a client browses to my...
1
3103
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 they all seem to say either nothing about this or that this is "out of the scope of this book", even "Professional ASP.NET". I have a ActiveX component that I'd like to expose through a .NET wrapper so in the case that a client browses to my...
9
6725
by: Srinivas | last post by:
hi all how to access the outlook user profiles through VB.net any help.... thanks in advanc Srinivas
7
2389
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 register it in another system, an error comes out saying the dll does not have the DllRegisterServer function. I have tried to add the check box "Register for COM Interop" in the Project properties, but it does not help.
8
3023
by: Lou | last post by:
How do I create a User Control or .dll in VB .Net to be used in VB6? -Lou
9
2426
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 another form. Problem is if I wake a tooltip when the window is floated, and then try the same thing when it is reparented, the app crashes with " Cannot access a disposed object.Object name: 'Form'. Presumably, this is a result of the tooltips...
0
8049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7985
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8469
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8322
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6803
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5997
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2461
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.