24.8 Viewing an Exported .NET Type Library

 <  Day Day Up  >  

You want to view the resulting type library exported from a .NET assembly.


Technique

Just as you use ILDasm.exe to view type information about a .NET assembly, you use the OLE/COM Object Viewer to view information about a type library. You can launch the tool from the Tools menu within Visual Studio .NET.

The tree control on the left side of the tool takes all the information from the Registry concerning registered COM objects and logically groups that information based on its type. For instance, the Type Libraries tree node displays a list of registered type libraries using the friendly name of the type library. The Interfaces tree node displays all the known interfaces within the system. We don't recommend expanding that node on a slow computer. You might have to wait a while. The easiest way to view the contents of a type library without having to search through lists is to use the View Typelib menu item on the File menu. The exported type library created in this chapter for the .NET object uses a .tlb extension and is located in the same directory as the .NET assembly.

After you open the type library, another window opens, listing all the available interfaces, dispatch interface, and co-classes. A dispatch interface is simply an interface that supports OLE automation and the IDispatch interface. Whenever scripting languages are used to call methods on your COM object, they go through the IDispatch interface to do so. A co-class is the actual COM object itself. You need two pieces to create a COM object instance. The first is the ID of the interface to use and the second is the ID of the co-class to use.

Recipe 24.7 created a .NET object that implemented three interfaces: IVehicle , IAirVehicle , and IAirplane . The class that implemented these interface was named Airplane . If you view the type library for this .NET object after it is exported using the RegAsm tool, you can see that there's almost a one-to-one correlation between the .NET interfaces and classes with the generated COM interfaces and co-classes. When you select an interface, the corresponding methods and parameters for the interface are displayed using the Interface Description Language (IDL), which is a language designed to define interfaces and associate them with co-classes. You can almost think of it as a type library in text form.

Comments

In many cases, when working in a COM environment, the most frequent errors occur during runtime. For instance, when you ask a COM object for a certain interface, the actual code compiles just fine because the binding doesn't occur until runtime. By using this tool, you can verify whether a certain COM object supports a specified interface. In other words, to ensure that your .NET object has been exported in the way you think it should have been, verify the resulting type library by opening it in the OLE/COM Object Viewer tool.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net