Click here to Skip to main content
Click here to Skip to main content
Go to top

Tlbexp.exe and Regasm.exe (.NET FrameWork Tools Series)

, 17 Jan 2006
Rate this:
Please Sign up or sign in to vote.
Tlbexp.exe and Regasm.exe (.NET FrameWork Tools Series)

Introduction

TlbExp.exe and Regasm.exe tools aid us in exporting assembly information to a type library so that non .NET Applications or unmanaged code use this type library information to call .NET assembly.

Just like tlbimp which works on the entire COM Component tlbexp works on the entire assembly.

The entire assembly is converted at the same time. You cannot use it to generate type information for a subset of the types.

Tbexp only generates the type library information for an assembly but it does not register the type libraries unlike regasm.exe

Let us now create an assembly for which we will create a type library and use it through Visual Basic.

  1. Open a new dotnet project (Class Library)
  2. Add a class to the project called MyClass as below

    public class MyClass
    {
        public MyClass()
        {
        }
        public int Add (int i , int j)
        {
            return i +j;
        }
        public int Mul (int i , int j)
        {
            return i *j;
        }
    }

  3. Strong name your assembly, compile the project and create the assembly
  4. Go to the Visual Studio command prompt and type tlbexp /? to explore all the options. I have enlisted them below:

    /out:FileName           File name of type library to be produced
    /nologo                 Prevents TlbExp from displaying logo
    /silent                 Prevents TlbExp from displaying success message
    /verbose                Displays extra information
    /names:FileName         A file in which each line specifies the 
                            captialization of a name in the type library.
    /? or /help             Displays this usage message

  5. To create a typelibrary from it type the following command tlbexp <application name>.dll e.g. tlbexp tlbexp.dll
  6. If the export was successful a success message diplaying the entire path and the name of the .tlb will be shown to you

    Assembly exported to F:\Net\tlbexp\bin\Debug\tlbexp.tlb

  7. You can also use the /verbose option to check out the details of the classes that were exported
  8. Although our typelibrary is created, our assembly is not yet registered. You can register the assembly using regasm tool
  9. Go to the Visual Studio command prompt and type regasm /? to explore all the options. I have enlisted them below:

    /unregister         Unregister types
    /tlb[:FileName]     Export the assembly to the specified type library 
                        and register it
    /regfile[:FileName] Generate a reg file with the specified name 
                        instead of registering the types. 
                        This option cannot be used with 
                        the  /u or /tlb options
    /codebase           Set the code base in the registry
    /registered         Only refer to already registered type libraries
    /nologo             Prevents RegAsm from displaying logo
    /silent             Silent mode. Prevents displaying of success messages
    /verbose            Displays extra information
    /? or /help         Display this usage message
    
  10. To only register the assembly, use the following command:
    regasm <application name>.dll    e.g. regasm TlbExp.dll 
  11. You can also create a .reg file containing all the registry entries:
    regasm TlbExp.dll  /regfile:myTlbExp.dll .reg
  12. You also create typelibrary from assembly using regasm tool by using /tlb option
  13. To use this component from VB 6.0 put the assembly in GAC. You can do this by either using gacutil or just dragging and dropping the assembly in <drive>/winnt/assembly folder
  14. You can now use this assembly from VB 6.0
  15. Open a VB std project. Go to references. Select the .tlb file that we generated from the list
  16. Yes, you can now use your .NET assembly from VB 6.0. The sample code of using your .NET assembly from VB:

    Dim tlbExp As tlbExp.MyClass
    Set tlbExp = New tlbExp.MyClass
    Label1.Caption = tlbExp.Add(1, 2)

Note : You cannot use tlbexp on an assembly produced by tlbimp because in that case you can directly use type library which was used to produce the assembly.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Namratha Shah
Architect
United States United States
Namratha Shah a.k.a. Nasha is from orginally from Bombay, India but currently residing NJ, USA. She has to her credit, a Bachelor’s Degree in Microbiology and Biotechnology and a Master's in Computer and Software Applications (1999-2001) from Somaiya College Bombay. She started her career with C and C++ and then moved on to Microsoft Technologies. She has over 7.5 years experience in software architecture, design and development. She is a Certified Scrum Master and a member of the CORE .NET Architecture team. She has been Awarded with Microsoft’s Prestigious Most Valuable Professional (MVP) twice consecutively in years 2005 and 2006 in Visual C#.NET for her outstanding contributions to the .NET community.

Comments and Discussions

 
QuestionI can not get the tlb file from crystal report 2008 .net dlls Pinmemberpandian7830-Oct-09 1:19 
GeneralGenerating empty implementation for COM in C# class using the VS 2005 sometimes returns CoClass or the Interface Pinmemberjaygaba19-Nov-08 21:17 
GeneralCOM and COM+ services Pinmemberzargar13-Jun-07 1:52 
GeneralNo types were registered PinmemberLiborV6-Jun-06 6:10 
GeneralRe: No types were registered Pinmembertheory200630-Nov-06 13:53 
GeneralRe: No types were registered Pinmemberian_t27-Feb-08 11:57 
GeneralRe: No types were registered PinmemberMember 61515629-Feb-08 12:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 17 Jan 2006
Article Copyright 2006 by Namratha Shah
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid