可以预加载 AutoIt DLL 吗?

AutoIt DLL preloading possible?

有没有比每次打开并调用.dll文件更好的方法?

Func getLife()    
    Local $hDLL = DllOpen("MyFirstDll.dll")
    Local $result = DllCall($hDLL, "int:cdecl", "getLife")
    If @error > 0 Then
        MsgBox(0, "Error", "Oh ups.. dll loading fail")
        Else
        MsgBox(0, "Result", $result[0])
    EndIf
    DllClose($hDLL)
EndFunc

在 AutoHotkey 中可以预加载 .dll 文件。这在 AutoIt 中是否也可行(以节省性能)?

Is there a better way than opening and calling a .dll file every time?

加载并关闭 .dll 文件一次(而不是每次函数调用)。示例(未经测试):

Global Const $g_sFileDll      = 'MyFirstDll.dll'
Global Const $g_sErrorDllLoad = 'Failed to load .dll file.' & @LF
Global Const $g_sErrorDllCall = 'Failed to call .dll file.' & @LF
Global Const $g_iCountDllCall = 10
Global Const $g_iDelayDllCall = 1000

Global       $g_hDLL          = DllOpen($g_sFileDll)

If $g_hDLL = -1 Then    
    ConsoleWrite($g_sErrorDllLoad)
    Exit    
EndIf

For $i1 = 1 To $g_iCountDllCall
    getLife($g_hDLL)
    Sleep($g_iDelayDllCall)    
Next

DllClose($g_hDLL)
Exit

Func getLife(ByRef $hDLL)
    Local $aResult = DllCall($hDLL, "int:cdecl", "getLife")

    If @error Then    
        ConsoleWrite($g_sErrorDllCall)    
    Else    
        ConsoleWrite('Result: ' & $aResult[0] & @LF)    
    EndIf

EndFunc