CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Using TLB

  1. #1
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Using TLB

    I created very simple Class Library in VB 2005 (let's call it COMInterop). I
    set Register For COM Interop property to true to make it accessible by VB6
    program.
    After I compiled it, I got COMInterop.dll and COMInterop.tlb files, I have
    no problem with using both of them on the machine where the project was
    compiled - TLB with VB6 clients and DLL with VB 2005 clients.
    I copied the tlb and dll files onto another machine and registered TLB file
    with regtlib.exe. I've got a message about successful registration.
    I created a new VB 2005 Windows Form project, added the reference to
    COMInterop.dll and it works fine.
    I created VB6 project, added a reference to this TLB. I'm trying to use it
    with the simple code which works with VB 2005, but produces an error in VB6:
    Run time error '429':
    ActiveX component can't create object

    The code in client:
    Private obj As COMInteropTest.COMInterop
    Private Sub Command1_Click()
    Set obj = New COMInteropTest.COMInterop 'The error occurs on this line
    MsgBox obj.myFunction
    End Sub

    What am I missing? How do I make VB6 client work with TLB on any machine,
    not only on the machine it was created?

    Thank you

  2. #2
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Using TLB

    I made it work by doing this:
    1. Created COMInterop5.dll with VB 2005 and copied it to another machine in the application folder. 'Register for COM interop was checked, without this it did not work.
    2. Although TLB was created too, I did not copy it at all
    3. In my VB6 clien app in Form_Load event I added this line:
    Shell "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe " & """" & App.Path & "\COMInterop5.dll" & """"
    4. In Command_Click I added this:
    Dim obj5 As Object
    Set obj5 = CreateObject("COMInterop5.COM")
    MsgBox obj5.myFunc5

    5. Compiled and started client EXE. Everything is working.
    6. Tried to run from VB, it did not work.

    Now I have a freedome to add functionality to my dll and not to worry about new setup for every change I make in dll and client, because I have some approaches to compare files on server and workstation and in case they are different to copy them from the server onto workstation.

    Now I'm wondering if this approach is good.
    What is going on with the system if the dll with the same name is processed by RegAsm many times? Does this approach create multiple entries somewhere, or just make changes in the existing entry if it exists and creates a new one if it doesn't?

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured