巨集暫存器 DLL

##=
# 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

/ DISABLEFSR 引數只應在 x64 計算機上使用。但是,如果你陷入困境,那麼巨集中的故障保護會為你躲避這個子彈。