nsis Registering Libraries (RegDLL) Macro: Register::DLL


Example

##=
# The variable $Bit will hold either 64 or 32 depending on system architecture 
# This is used with ${Register::DLL} and ${UnRegister::DLL}
# Use this in the beginning of your code.
# This snippet should only be used once.
#
Var Bit
System::Call "kernel32::GetCurrentProcess()i.s"
System::Call "kernel32::IsWow64Process(is,*i.r0)"
StrCmpS $0 0 +3
StrCpy $Bit 64
Goto +2
StrCpy $Bit 32

##= 
#= Register::DLL
#
# USAGE:
# ${Register::DLL} "DLL Filename" /DISABLEFSR $0 $1
#
#        ::DLL       = Registers a DLL file. 
#        /DISABLEFSR = Disables redirection if x64. Use "" to skip.
#        $0          = Return after call
#        $1          =  ''      ''    ''
#
!define Register::DLL `!insertmacro _Register::DLL`
!macro _Register::DLL _DLL _FSR _ERR1 _ERR2
    StrCmpS $Bit 64 0 +4
    StrCmp ${_FSR} /DISABLEFSR 0 +3
    ExecDos::Exec /TOSTACK /DISABLEFSR `"${REGSVR}" /s "${_DLL}"`
    Goto +2
    ExecDos::Exec /TOSTACK `"${REGSVR}" /s "${_DLL}"`
    Pop ${_ERR1}
    Pop ${_ERR2}
!macroend

##= 
# Alternatively you can use this macro found in my travels 
# but you should include x64.nsh as this macro makes use
# of it's function.
#
#= USAGE:
# ${RegisterDLL} "SomeLibrary.dll"
#
!define RegisterDLL "!insertmacro _RegisterDLL"
!macro _RegisterDLL _DLL
    ${If} ${RunningX64}
        ${DisableX64FSRedirection}
        ExecWait '"$SYSDIR\regsvr32.exe" /s "${_DLL}"'
        ${EnableX64FSRedirection}
    ${Else}
        RegDLL "${DLL}"
    ${EndIf}
!macroend

The /DISABLEFSR parameter should only be used on x64 machines. However, if you mess up there's a failsafe in the macros that will dodge this bullet for you.