Can I use a *.tlb file without using Regasm to register it on the computer

孤者浪人 提交于 2020-01-02 12:09:43

问题


We are supporting an aging VB6 system that we have written new code for in .Net, put the code into assemblies and then exported *.tlb files for use with the VB6 codebase.

My question is, on every computer I wish to run the code on, do I have to use Regasm to register the type libraries?

I ask because it gets difficult to keep track of type library installations as computers break, new computers get added etc. Also, if we update the .Net code, we need to go around every computer and re-register the type library.

To sum up, is it possible to run .Net code from VB6 without having to register the type library on each computer the code is running on?

Thankyou


回答1:


Regasm.exe only creates a type library when you run it with the /tlb:filename.tlb command line option. Which you then use in a VB6 project with Project + References, Browse button to pick the .tlb file. Running Tlbexp.exe is another way to get it, minus the registration. And the one you ought to prefer, the "Register for COM interop" option in the IDE. You however have to run VS elevated so it can write the registry. Right-click the shortcut and select "Run as Administrator".

Having it appear in the VB6 list is a small convenience but that is hard to get. The standard .NET registration code called by Regasm.exe doesn't write the required "Programmable" key to get VB6 to add the component to its list automatically. You have to write a custom registration function decorated by the [ComRegisterFunction] attribute that writes the missing key. It isn't worth it when you can simply click Browse.

Also note that you do not have to register the type library on the user's machine. It is only needed by the VB6 compiler. You do have to register the [ComVisible] classes, it is easy with a Setup project. Just set the Register property of the DLL to vsdrpCOM.



来源:https://stackoverflow.com/questions/10774685/can-i-use-a-tlb-file-without-using-regasm-to-register-it-on-the-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!