How to register a .NET DLL using Inno Setup

2019-04-23 05:32发布

问题:

I have written a class library using Visual Studio 2010 C# to read hardware information of a Computer (e.g. HDD/SSD). I will use this dll to create an installer using InnoSetup to read the hardware info of the target computer. Now my problems is .NET dll cannot be used directly unless it is registered already. I am trying to find a way to register the dll during InitializeSetup in InnoSetup so I can use the functions in the dll. Here is the script I wrote for installer.

function InitializeSetup(): Boolean;
var
    obj: Variant;
    diskPartitions: Integer;
    va: String;
    ErrorCode: Integer;
    b: Boolean;
begin
    ExtractTemporaryFile('SSHardwareChecker.dll');
    RegisterServer(False, ExpandConstant('{tmp}\SSHardwareChecker.dll'), False);
    obj := CreateOleObject('SSHardwareChecker.SSClass');
    va := obj.GetDiskDriveInformation;
    MsgBox(va, mbInformation, mb_Ok);
    b:=UnregisterServer(False, ExpandConstant('{tmp}\SSHardwareChecker.dll'), False);
end;

The function RegisterServer doesn't seem to work.It throws an error which says RegSvr32 failed with exit code 0x4. I read a lot of articles in the net that says .net dll shoud be registered using regasm. I dont really know how to do this, especially in Inno Setup.

Please help guys.

回答1:

Though its more than a year, I recently had the same problem and was able to rectify using the below script.

[Run]
Filename: "{dotnet20}\RegAsm.exe"; Parameters: /codebase YourDLL.dll; WorkingDir: {app}; StatusMsg: "Registering Controls..."; Flags: runminimized

If the file has be registered at initialize step, we can use one of the Inno setup's support functions.

function Exec(const Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer): Boolean;

More Info can be found in: Inno Setup Help



回答2:

To do this, you MUST..

1) make sure that .net 4.0 is installed (not by default on most machines yet)

2) extract and register the DLL (you need to call regasm.exe on the extracted DLL)

This is a lot to do just to "GetDiskDriveInformation" as the very first step of the install.

It is far better to get the information natively in Inno or call a native DLL that doesn't have the prerequisites.



标签: inno-setup