Using a converted tlb-Library in C# .NET 2005

Hello .NET-Friends,

I have to use a type library (.tlb) in C# .NET 2005 which was once build in VB6.
It's not possible to import or point to the library without converting it to an .NET-Library. So I used the TlbImp.exe which is included in the .NET SDK and converted my (three) libraries to .NET DLLs.

All this worked fine, but now its not possible, to create an instance of the included class in this new DLLs. The Objectbrowser in .NET shows me, that there is a class inside named BF_APIClass with many nice methods.

Now I always get an exception at:
private BF_APIClass obj = new BF_APIClass();

Exception thrown (german edition):
Die COM-Klassenfactory fur die Komponente mit CLSID {BF000005-1000-0000-0006-0004760EDB72} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80040154.

I also tried to register my DLLs with "regsvr32.exe C:\WINDOWS\system32\BFAPICMXLib.dll", but then I get an error, that there is no EntryPoint for the DLL (because of being .NET Libs).

So I used the .NET-DLL Register-Tool from the .NET 2.0 Framework: RegAsm.exe
Now my Libs seem to be registered, I got:
RegAsm.exe BFAPICMXLib.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully

But always when I try to instance an object, I get the exception again .
So i would be very glad, if there is someone outside who could help me.

Thanks, Andreas



Answer this question

Using a converted tlb-Library in C# .NET 2005

  • Petter Harnes

    Please see this article to get started on calling COM components from .Net: http://msdn.microsoft.com/netframework/programming/interop/default.aspx pull=/library/en-us/dndotnet/html/callcomcomp.asp

    Do you have the VB6 component that the tlb describes That component is the one that needs to be registered on the system in order for you to call it from .Net through the tlb.


  • Andrew Gorobez

    Ok, thank you for your answer.
    I have read much about interop and I found many useful tutorials about creating an Type Library out of an existing .NET-program or .NET-DLL, but there is nowhere an instuction about using type libraries from older assemblies so far .

    I agree with you, that the runtime found my librariy and I agree with you, that it might be possible, that the native tlb is not found, but its not possible for me to register this tlb.
    How can I do this
    RegSvr32.exe cancels with "....tlb ist nicht eine ausfuhrbare Datei und es ist kein Registrieungshilfeprogramm fur diesen Dateityp registiert." which means in english, that my *.tlb is not an executable File and there is no helping program registered to register this filetype.

    So far, I get my .NET-converted-DLLs registered, but not the native TLBs which seem to be important, when an instance has to be created with .NET.

    Hope, anyone could help me.
    Thanks!

    Andreas


  • Michael Rich

    This is a good webpage to help get you started on interop: http://msdn.microsoft.com/netframework/programming/interop/default.aspx

    Tlbimp is the tool that you need to use to enable C# to call into COM. Regasm and Regsrv32 are used for the other direction (COM calling into C#) so you don't need to use them here.

    From what i can tell by looking at your exception message (with my exteremely limited german translation skills) the runtime was able to find the assembly that was created with tlbimp but not the native (VB6) com component that implemented the functionality. Are you sure that the component corresponding to your tlb is registered


  • Using a converted tlb-Library in C# .NET 2005