Search code examples
.netdllcomvb6com-interop

Can vb6 dll use a .net com visable dll that is in the gac


I have a .Net COM visible dll and a VB6 dll. I registered the .Net dll on the GAC and registered the VB6 dll. My question is can the VB6 dll reference the .Net dll that's in the GAC. If yes, how can this be done? Normally I would use the regasm on the .Net dll and everything would be fine but now the .Net dll is in the GAC so I don't think this method would be possible.


Solution

  • There isn't anything special about it that would stop this from working if you used the GAC or try to use it from a VB6 DLL project. If you want to write early bound code (actual type names, auto-completion works) then the VB6 IDE needs a type library. They are normally embedded inside the DLL but that's not the case for .NET [ComVisible] assemblies.

    Create a type library with Tlbexp.exe or with Regasm.exe's /tlb command line option. Like:

     regasm foo.dll /tlb:foo.tlb
    

    You can now use the type library in your VB6 project. In the VB6 IDE, use Project + References, click Browse and navigate to the foo.tlb file.

    Also note that while the GAC is a good way to avoid DLL Hell, you typically don't use it on your dev machine since it pollutes the machine's GAC. Use the Regasm /codebase option to have it registered in the directory the DLL is stored in, no need for the GAC then. You do get a warning from Regasm when you do this, trying to remind you that you are risking DLL Hell. But that's a problem for your user, not for you. So you can safely ignore the warning.