The registry entries for the .NET COM Interop class in this case are: -
HKEY_CLASSES_ROOT\myComLib.testObject
containing the CLSID value and the CLSID element itself
HKEY_CLASSES_ROOT\CLSID\<<myComLib.testObject\CLSID value>>
They are also replicated to
HKEY_LOCAL_MACHINE\SOFTWARE\Classes
CreateObject uses the HKEY_CLASSES_ROOT records to get information about the passed class name, so if they are missing, you will get
Runtime Error '429': ActiveX component cannot create object
Inside the VB6 IDE, adding a reference to a DLL (in the case of building .NET through a tlb file) bypasses this registry search, thereby allowing early binding to work without entries in the COM registry.
The class must be correctly registered for CreateObject to work. This should happen as part of the Visual Studio build process, otherwise you must manually register it with Regasm.
You can verify this behavior by doing the following: -
1) Create a new myComLib project for VB.NET for COM interoperability in the project. Compile properties and add testObject class
Public Class testObject Public Property TestProperty As String Public Function TestFunction() As String Return "return" End Function End Class
2) Create myComLib
3) Create a new VB6 project, add two commands to Form1 and the following code
Private Sub Command1_Click() Dim b As Object Set b = New myComLib.testObject b.TestProperty = "Hello" MsgBox b.TestProperty, vbOKOnly, b.TestFunction() End Sub Private Sub Command2_Click() Dim b As Object Set b = CreateObject("myComLib.testObject") b.TestProperty = "Hello" MsgBox b.TestProperty, vbOKOnly, b.TestFunction() End Sub
4) Run the VB6 project (without full compilation, as this will not work)
Command2 will display a message box, command 1 will end with
Compilation error: user type not defined.
5) Stop the project and add a link to myComLib via the tlb file
6) Run the VB6 project, and both buttons should now work
7) Go to the registry and delete the entry HKEY_CLASSES_ROOT \ myComLib.testObject (this can be recreated using the rebuild of the .NET component, you will need to close VB6 to perform the rebuild)
Command2 now fails with
Runtime Error '429': ActiveX component cannot create object
until a registry entry is added.