REGASM, COM and Type Libraries
If you've ever done any work with making .NET components that are exposed to COM, you're familiar with REGASM. This utility makes registry entries to make your .NET object look like a COM object. In its simplest form, you can do:
REGASM MyAssembly.dll
Now, all of the COM-compatible classes are registered as COM objects. You can fire up VB6 and start writing code:
Dim net As Object Set obj = CreateObject("NETProject.Foo") obj.Move
Pretty easy. Except that you're late binding because you don't have a COM type library.
No problem! REGASM can generate a type library for you and even register it:
REGASM MyAssembly.dll /tlb:MyAssembly.tlb
Now, in VB6 you can add a reference to the type library and use early binding:
Dim net As Foo Set obj = New NETProject.Foo obj.Move
Suppose you want to "unregister" this assembly? REGASM has a "/unregister" switch:
REGASM /u MyAssembly.dll
The thing you want to watch out for (and the real reason for this post) is that if you used the /tlb option to register a type library, you need to make sure you include the /tlb option when unregistering. If you don't, only the COM object is unregistered, but the type library is still registered. And you can't unregister the type library by itself.
So, rule of thumb:
REGASM MyAssembly.dll /tlb:MyAssembly.tlb
Balance that with:
REGASM /u MyAssembly.dll /tlb:MyAssembly.tlb