Framework Class Library to Visual Basic 6

Costas

Administrator
Staff member
Universal CCW (deprecated)
http://sourceforge.net/projects/universalccw/
https://www.codeproject.com/articles/Universal-COM-Callable-Wrapper

Universal .Net Com Callable Wrapper (CCW) written in VB.Net. Acts as an API to the .Net framework. Allows virtual porting of most (if not all) .Net classes into any COM-enabled scripting or programming language.



Consuming .net Assemblies from VB6
http://zbz5.net/consuming-net-assemblies-vb6


Exposing .NET Framework Components to COM
https://msdn.microsoft.com/en-us/library/zsfww439.aspx


Framework Class Library from Visual Basic 6
https://msdn.microsoft.com/en-us/library/aa719110(v=vs.71).aspx


Calling a .NET Component from a COM Component
https://msdn.microsoft.com/en-us/library/ms973802.aspx


Using .NET Controls in VB6
To register the assembly, you must use the .NET equivalent of regsvr32, regasm. This is located in the framework directory, usually "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727". To register it, open a command prompt and run the following command, assuming that the framework directory and the assemblies directory are in the environment's current path.
https://www.codeproject.com/articles/Using-NET-Controls-in-VB6

Call Into The .NET Framework From Existing Visual Basic 6.0 Apps
https://learn.microsoft.com/en-us/a...framework-from-existing-visual-basic-6-0-apps
download the missing VBFusion05.exe

Registering Assemblies with COM
https://learn.microsoft.com/en-us/dotnet/framework/interop/registering-assemblies-with-com
https://stackoverflow.com/a/7850580



Export functions as standard windows DLL function entry points
http://www.codeproject.com/Articles/16310/How-to-Automate-Exporting-NET-Function-to-Unmanage

Simple Method of DLL Export without C++/CLI
https://www.codeproject.com/articles/Simple-Method-of-DLL-Export-without-C-CLI

Exporting methods from DLLs without using DllExport
https://yamakadi.com/blog/dynamically-editing-dotnet-executables
https://offensivedefence.co.uk/posts/dnlib-dllexport/

#exportdll #vb6
 

Costas

Administrator
Staff member
Registering a .net framework DLL via
regasm.exe test.dll /codebase

apart other registry keys, regasm.exe always adds
[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{dll-guid}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}\]
the {62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}
it is a specific CATID, a component category. When a COM-compatible .NET assembly is registered, adding this CATID that allows applications to list or access all components that belong to that category, simplifying client development and deployment. Indicates that the DLL is part of the integration framework between .NET and COM components.



on VS2012 on Properties dialog of a Class library

ZSWbGQs.jpeg

which is equivalent with Properties\AssemblyInfo.cs

g9yFveq.jpeg


on project properties check Register for COM interop and set x86. Then save the solution.

a9Rf7Vi.jpeg

and dont forget to sign the assembly as is requirement

xFxh6IB.jpeg

At the moment, nothing registered on the system registry. Once the user BUILD the solution those registry entries added (we searched by the GUID) :

FdlbDSO.jpeg


to be more specific, Visual Studio register the .tlb :
Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\WOW6432Node\TypeLib\{EB35161C-9A34-4EBE-896D-3975F0816061}]

[HKEY_CLASSES_ROOT\WOW6432Node\TypeLib\{EB35161C-9A34-4EBE-896D-3975F0816061}\1.0]
@="ClassLibrary1"

[HKEY_CLASSES_ROOT\WOW6432Node\TypeLib\{EB35161C-9A34-4EBE-896D-3975F0816061}\1.0\0]

[HKEY_CLASSES_ROOT\WOW6432Node\TypeLib\{EB35161C-9A34-4EBE-896D-3975F0816061}\1.0\0\win32]
@="c:\\comNET\\ClassLibrary1\\ClassLibrary1\\bin\\Debug\\ClassLibrary1.tlb"

[HKEY_CLASSES_ROOT\WOW6432Node\TypeLib\{EB35161C-9A34-4EBE-896D-3975F0816061}\1.0\FLAGS]
@="0"

[HKEY_CLASSES_ROOT\WOW6432Node\TypeLib\{EB35161C-9A34-4EBE-896D-3975F0816061}\1.0\HELPDIR]
@="c:\\comNET\\ClassLibrary1\\ClassLibrary1\\bin\\Debug"

Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Classes\Interface\{F56AF0FC-D93B-399E-8FBD-9B72CF50D7D9}]
@="_Class1"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Classes\Interface\{F56AF0FC-D93B-399E-8FBD-9B72CF50D7D9}\ProxyStubClsid32]
@="{00020424-0000-0000-C000-000000000046}"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Classes\Interface\{F56AF0FC-D93B-399E-8FBD-9B72CF50D7D9}\TypeLib]
@="{EB35161C-9A34-4EBE-896D-3975F0816061}"
"Version"="1.0"

The registry CatID 00020424-0000-0000-C000-000000000046 corresponds to the IClassFactory interface in Microsoft's COM (Component Object Model) architecture.



Added three classes
  • to make accessible the methods you must declare the class AutoDual.
  • static methods are not accessible.
  • if user prefers, can declare class GUID (otherwise assigned automatically), so do it!

C#:
using System;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
    //[ComVisible(true)]
    //[Guid("c28631ad-87bf-49ed-8a2b-d420d461e102")]
    //[ComDefaultInterface(typeof(IClass1))]  // Interface ID
    //[ComDefaultEvent(typeof(IClass1))]      // Events ID
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Class1
    {
        public string GetName(int Id)
        {
            return "testName";
        }
    }

    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Class2
    {
        public string GetAddress(int Id)
        {
            return "testAddress";
        }
    }

    public class Class3
    {
        public string GetTelephone(int Id)
        {
            return "testTelephone";
        }

    }
}

jQWDzat.jpeg

On developing machine once you have the .net framework .dll, register the .dll then generate the .tlb and register it (.tlb is only for developing) via :
Code:
c:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm.exe c:\a\ClassLibrary1.dll /tlb:c:\a\ClassLibrary1.tlb /codebase /verbose

mD43W26.jpeg

Reference the .tlb to your VB6 project.
you can unregister with :
Code:
c:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm.exe c:\a\ClassLibrary1.dll /u /tlb:C:\a\ClassLibrary1.tlb


When we deploying the application to clients we have to register the .dll as
Code:
c:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm.exe c:\a\ClassLibrary1.dll /codebase
deploy ref :
https://stackoverflow.com/a/12384131
https://github.com/PhilJollans/RegToInno
https://github.com/PhilJollans/RegSpy

when " regasm.exe c:\a\ClassLibrary1.dll " the following will be created to registry
Code:
HKEY_CLASSES_ROOT\ClassLibrary1.Class1\
HKEY_CLASSES_ROOT\ClassLibrary1.Class2\
HKEY_CLASSES_ROOT\ClassLibrary1.Class3\

and (here Class3 insert none, because later I made it static)
HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{079C0B3A-038E-37A7-B6A5-3D440862B289}\
HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{079C0B3A-038E-37A7-B6A5-3D440862B289}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}\
HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{9C0B5817-C9D1-3107-B208-C97F1F11EBF7}\
HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{9C0B5817-C9D1-3107-B208-C97F1F11EBF7}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}\

the exact same also for HKEY_LOCAL_MACHINE..

the required are the HKEY_CLASSES_ROOT\WOW6432Node entries.

The registry CatID 62C8FE65-4EBB-45e7-B440-6E39B2CDBF29 corresponds to the .NET Category for COM interop.
 
Top