How To Create Activex Control In Vb6 0
-
Create ActiveX (OCX) in VB.Net
Does anyone know how to create an Active X control (with GUI) in VB.Net?
"Register for COM interop" VB.Net project setting appears to only allow me to set a reference from VB/VBA, but not to create an ActiveX control that I could, for example, add to the toolbar in VB6.
-
VB.NET uses managed code (code without pointers), and thus cannot generate an Active X control, which requires pointers.
You can very easily create .NET controls, but not ActiveX. OCX files are not used in .NET, were controls are now classes like any other, and are included in a DLL file.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
Well....
VB.Net can create what VB6 called an "ActiveX DLL", by creating a DLL and then selecting "Register for COM Interop" on the Project settings.
ActiveX OCX's are similar to this, but include a user interface. I would guess that this can be done, although it may not be well known.
-
darren,
It is my understanding that VB.Net cannot be used to create ActiveX ocx controls.
Kerry Moorman
-
-
The problem with that example is that is does not register the control, and the example will only work for putting it in a web page.
I did get this to work. The .Net user control can be hosted in VB6, VBA web forms, but not, I found, all ActiveX containers. Here are the details for those interested in what I did.
1. Create a VB.NEt user control (VB 2005)
2. Put a button on the control
3. Set project property "Register for COM interop"
4. Modify the usercontrol1.vb as show below
BUILD VB.Net user control which will register the ActiveX control
5. In VB6, add control (assembly namespace.MyControl")Code:
Imports System.Runtime.InteropServices Imports System.Text Imports System.IO Imports System.Reflection Imports Microsoft.Win32 Imports System Imports System.Threading Imports System.Math <ComClass(MyControl.ClassId, _ MyControl.InterfaceId, _ MyControl.EventsId)> _ Public Class MyControl ' MAKE SURE WE HAVE 1 PUBLIC SUB in this class #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. 'You should create your own 3 GUIDS using GuidGen Public Const ClassId As String = "8D6CC4E9-1AE1-4909-94AF-8A4CDC10C466" Public Const InterfaceId As String = "D901FC53-EEC2-4634-A1B5-BB4E41B24521" Public Const EventsId As String = "7458968F-F760-4f53-A2E4-30C1D8CD691B" #End Region #Region "REQUIRED FOR ACTIVEX" ' This function is called when registered (no need to change it) <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("", "131201") 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 (no need to change it) <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 #End Region Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show("OK") End Sub End Class
-
All this is a question of semantics. If you look at the real stuff, it is not possible to create an ActiveX control in .NET unless you uses C++ that permits unmanaged code.
You can use a .NET dll / control in an ActiveX environment, but that does not make it an ActiveX control. It's not because you can register it with COM that it is an ActiveX control.
It is still a .NET control.
The entry points built by the compiler are not similar.
ActiveX controls use Variant variables that are not use in .NET.
Even types with the same name are different. An ActiveX Integer is 16 bits while a .Net Integer is 32 bits.
.Net has 64 bits Integer (the .NET Long) that ActiveX does not have.
A Date in ActiveX is actually a Double while a Date in .NET is a Long.
I could go on like that for hours (well... a lot of minutes).
They can be mixed together up to a certain point because you can easily map a 16 bits ActiveX Integer to a 16 bits .NET Short.
But they are not the same.
And while .NET can easily use most ActiveX classes through an interop (a translator of types is some way), the reverse is harder. If a .NET dll returns a Long (64 bits), it cannot be used in VB6 for instance. That is one of the reasons, while even if you can register a .NET control in COM, it will not work in an ActiveX environment.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
- Hi,
Originally Posted by darren
The problem with that example is that is does not register the control, and the example will only work for putting it in a web page.
I did get this to work. The .Net user control can be hosted in VB6, VBA web forms, but not, I found, all ActiveX containers. Here are the details for those interested in what I did.
1. Create a VB.NEt user control (VB 2005)
2. Put a button on the control
3. Set project property "Register for COM interop"
4. Modify the usercontrol1.vb as show below
BUILD VB.Net user control which will register the ActiveX control
5. In VB6, add control (assembly namespace.MyControl")Code:
Bunch o' cool code[...]
first of all, a big THANK YOU for this code snippet, it's solved my life as I needed to build an ActiveX (or something remotely close) in VB.NET, and this is the only one to have done the trick, so THANKS!
I'm new to VB programming (I was originally trained as a Java programmer), and VB.NET seems even harder. Thing is I desperately needed a way to migrate a VB6 ActiveX to VB.NET, that had the same functionality, which now I archieved thanks to Darren after a week (5 days, 9 hours each) at full speed just googling the net and doing project tests.A little doubt I have though. The usual ActiveX control ends up in "C:\WINDOWS\Downloaded Program Files", but the one I compiled using this code, even being recognized as an ActiveX control by IE, doesn't seem to be stored in that folder. Everything works just fine, but my engineer here needs to know how is this being done now. Anyone has an idea where is it being stored or if it's being used in cache mode or something?
Thanks and cheers
- Just do a Start/Search - punch in the name of your compiled control, and let the OS find it for you.
Originally Posted by Mix-martes86
A little doubt I have though. The usual ActiveX control ends up in "C:\WINDOWS\Downloaded Program Files", but the one I compiled using this code, even being recognized as an ActiveX control by IE, doesn't seem to be stored in that folder. Everything works just fine, but my engineer here needs to know how is this being done now. Anyone has an idea where is it being stored or if it's being used in cache mode or something?
I suspect it will be located in, or near, its .NET project folder.
- Negative, the only thing I find is the compiled output in the build folders from the project (the files that I create when I build the project), and the control in the web server ready for download, but no trace that it's being downloaded to any place in the drives, so my guess is that it's either being cached or used directly from the website, or that it's temporarily stored while it's being used by the web-app, but this should allow me to find that temporary store, thing that hasn't happened, so...
Originally Posted by Hack
Just do a Start/Search - punch in the name of your compiled control, and let the OS find it for you.
I suspect it will be located in, or near, its .NET project folder.
Thanks anyway.
Cheers
-
Hi again,
sorry to bump an old thread again, feel free to split it if you see it fit.
I have successfully migrated 2 activex components, but I'm still having problems with one that implements a card reader API. Thing is, the VB6 component had 2 CLSIDs for 2 classes within the same component. Having in mind the intention to preserve the code as close to the original structures as possible, I assigned each class its own CLSID, while the component itself has a different assembly GUID. Then, 2 objects are created in ASP, each one with its respective CLSID, while the component assembly GUID remains unused. I suspect that's the problem, but I'm not sure. Could any of you confirm me this fact or if it's something else?
Thanks in advance
EDIT: Oops, forgot to mention that the specific problem is that, while the other 2 components I migrated, get recognised and work fine, this one doesn't, giving me the typical "X is not a valid property or method of Y" in IE6, that coming out because the object appears set to Nothing in debug, obviously not initializing for some reason.
Last edited by Mix-martes86; 02-17-2009 at 10:24 AM.
-
Hi again,
after some testing, I fixed it. It seems that if you have 2 classes, each one with its own CLSID, and an assembly GUID, but you instantiate your objects directly referencing each class ID and not the assembly, it doesn't work, so you have to take the assembly GUID out of the equation.
I still have problems, but that comes from the activex component code now, which I can't get to debug from a call from a html object. I tried some solutions, but so far, I've only been able to start the project in debug mode, and go through the vbscript code in the html, but the breakpoints don't hit the component source.
Anyone can help?Cheers
-
More things:
I managed to get some stuff up and running, but the most important part, the one that tells me if the card is inserted, is not working yet. I discovered that I had to marshall all parameters to the library functions. It took me a while to figure out which format pairs were the adequate, since the component wasn't displaying any msgboxes with errors, other than the ErrDescription.
Anyways, I post you here a declaration example so you see with which type to pair your variables:
I'm still stuck with the debugging the component part, as I don't seem to be able to get the debugger to enter the component's source.Code:
Public Declare Function fx Lib "MyLib.dll" _ (<MarshalAs(UnmanagedType.IUnknown)> ByRef mo As Object, _ <MarshalAs(UnmanagedType.I4, SizeConst:=100)> ByRef int As Integer, _ <MarshalAs(UnmanagedType.VBByRefStr, SizeConst:=100)> ByRef str As String, _ <MarshalAs(UnmanagedType.U1, SizeConst:=100)> ByRef b As Byte, _ <MarshalAs(UnmanagedType.U2, SizeConst:=100)> ByRef s As Short, _ <VBFixedArray(35), MarshalAs(UnmanagedType.ByValArray, SizeConst:=35)> ByVal a() As Integer, _ <MarshalAs(UnmanagedType.Struct)> ByRef st As MYSTRUCTURE) _ As <MarshalAs(UnmanagedType.I4, SizeConst:=100)> Integer
Even though I've been able to figure out for myself some of the stuff I was asking, I'd still appreciate your advice with this last problem.
Cheers
Similar Threads
-
Replies: 7
Last Post: 06-27-2007, 07:18 PM
-
Replies: 4
Last Post: 04-14-2006, 09:09 AM
-
Replies: 1
Last Post: 10-04-2002, 09:49 AM
-
Replies: 1
Last Post: 04-29-2002, 06:54 AM
-
Replies: 2
Last Post: 06-19-2001, 12:30 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
- BB code is On
- Smilies are On
- [IMG] code is Off
- [VIDEO] code is Off
- HTML code is Off
Forum Rules
| |
| |
How To Create Activex Control In Vb6 0
Source: https://forums.devx.com/showthread.php?168158-Create-ActiveX-%28OCX%29-in-VB.Net
Posted by: spencereaccon1998.blogspot.com

0 Response to "How To Create Activex Control In Vb6 0"
Post a Comment