Tag Archives: VBA/VB call C#/VB.NET DLL series

How to use it RegAsm.exe Register C in a development / production environment#/ VB.NET Developed DLL

The original address: http://www.geeksengine.com/article/register-dll.html thanks to original author
After you create a C# or VB.Net DLL, you need to register it on the target machine. You can use Microsoft’s RegAsm. Exe utility.
Regasm. Exe is an assembly registration tool for reading metadata in an assembly. And add the required items to the registry. The registry allows COM clients (VB6 applications or Microsoft VBA, such as Access, Excel, etc.) to create.net Framework classes. Once a class is registered, it can be used in any COM client as if it were a COM class. Class is registered only once when the assembly is installed. An instance of a class in an assembly cannot be created from COM until it is actually registered.
Description:
The PATH of Regasm. Exe is not in the PATH environment variable added by the system, so the Regasm command is not recognized. When used, DOS Windows need to switch to its storage path before running. \Windows\ Framework\ V2.0.50727 \ Different versions of the system, there may be some differences in the Numbers in the transport path, as explained below:

    2.0,3.0, 3.5, etc.Net Framework USES the same RegAsm. Exe, which is located in the.Net Framework v2.0 folder in the following path. \ \Windows\ \Microsoft \ t.NET\ (32 bit Framework) \ V2.0.50727 \ RegAsm. Exe \ Or \Windows\ \.net \Framework64 (64 bit Framework) \ V2.0.50727 \ RegAsm The Framework USES a new RegAsm. Exe, which is located in the.net Framework v4.0 folder. C:\Windows\Microsoft.NET \ Framework (32-bit) Framework Framework \ v4.0.30319 \ RegAsm exe or C:\Windows\Microsoft.NET \ Framework64 (64) Framework Framework \ v4.0.30319 \ RegAsm exe
    1: RegAsm. Exe and DLL mapping
    If you receive this error “RegAsm: error RA0000: could not load” C: \ Windows\ System32 \ Simplecalc.dll because it is not a valid.net assembly “, you may be registering with RegAsm. Exe under.Net4 version. DLL created above.

    . The.net Framework

    RegAsm. Exe default installation path

    your DLL created Framework version

    , the.net Framework 3.5/2.0/3.0

    C: \ Windows\ Microsoft t.net \ (32/64 bit Framework) \ V2.0.50727 \ RegAsm. Exe .Net Framework 2.0/3.0/3.5
    .Net Framework 4.0, 4.5, 4.6 C: \ Windows\ Microsoft t.net \ (32/64-bit Framework Framework) \ v4.0.30319 \ RegAsm. Exe .net Framework 4.0, 4.5, 4.6

    So when registering DLL assemblies created by the.NET Framework version 4 or above, we cannot register using RegAsm. Exe in the.net Framework 2.0/3.0/3.5 folder.

    2: How do I run RegAsm. Exe
    To execute RegAsm. Exe, open a command prompt window with administrator privileges, switch to the folder where RegAsm. Exe resides and run it (otherwise you will get an error message saying “RegAsm is not recognized as an internal or external command, an actionable program, or a batch file”).
    Switch to the folder where RegAsm. Exe resides and run it

    Assuming I have added my DLL to folder C: \ Windows\ System32, I can run the following command:
    C:\ Windows\ Microsoft t.NET \ Framework \ v4.0.30319 \ RegAsm. Exe Simplecalc.DLL/codebase
    Note that you do not need to specify C: \ Windows\ System32 in the command because it is the system folder. RegAsm. Exe will automatically look for simplecalc.DLL in the C: \ Windows\ System32 directory.
    The/codebase parameter is an optional parameter that adds information about a DLL to the Windows registry, which specifies the path to the assembly on disk.

    3: Regasm can also be used to log out DLLS
    If you get a DLL that does not have a type library file associated with it, you can generate it using the Regasm utility and/TLB option.
    C:\ Windows\ Microsoft t.NET \ Framework \ v4.0.30319 \ RegAsm. Exe Simplecalc.DLL/TLB: Simplecalc.TLB

    Please note that to export a type library from a DLL, you need to have administrator privileges on your computer, otherwise you will receive such an error “RegAsm: Error RA0000: Error saving exported type library: access denied… “Because the account you are running Regasm. Exe is not entitled to write to the folder.
    Note that you can create environment variables for egAsm. Exe under the.NET Framework to simplify DLL registration.

    4: Regasm can also register programs using batch commands
    If you need to register on more than one computer, or if you have a large number of DLL components to register, you can use the following batch command to register.
    @echo off
    Set the path = C:\Windows\Microsoft.NET \ Framework64 \ v4.0.30319 \; %path%
    RegAsm/codebase C: \ Windows \ System32 \ SimpleCalc DLL
    pause
    ::C:\Windows\System32\ Simplecalc. DELL for component and store full path
    : : C:\Windows\Microsoft.NET \ Framework64 \ v4.0.30319 \; Is the folder path where REGASM.EXE resides.
    Note: After saving the above batch command as CMD.bat, double-click to complete the registration. When the registration is unsuccessful, right-click on the CMd.bat file and select run as administrator to complete the registration.
    Happy coding to you!
    Other references:
    https://msdn.microsoft.com/zh-cn/library/tzat5yw6(VS.80).aspx
    http://jingyan.baidu.com/article/09ea3ede65a7c8c0aede39c1.html

    Other article series:

    (1) how to correctly create Access or Excel the DLL (or use in any Microsoft Office applications or VB6) http://blog.csdn.net/kongwei521/article/details/77921436
    (2) how to correctly will c # or VB.Net DLL in the development of machines or generate environment registered in http://blog.csdn.net/kongwei521/article/details/77929273
    (3) how to correctly reference to Access within the Access VBA or Excel VBA c # write DLL http://blog.csdn.net/kongwei521/article/details/77929277 or VB.Net