【问题标题】:How do I add resources to my AutoIt exe file?如何将资源添加到我的 AutoIt exe 文件?
【发布时间】:2016-10-03 18:23:52
【问题描述】:

我想在我的 AutoIT 应用程序中包含一些 txt 文件。

#AutoIt3Wrapper_Res_Field=#AutoIt3Wrapper_icon|C:\Scripts\AutoIt\HelpDeskIT\images\helpdesk_icon.ico
#AutoIt3Wrapper_Res_File_Add=C:\Scripts\AutoIt\HelpDeskIT\Instructions.txt
#AutoIt3Wrapper_Res_File_Add=C:\Scripts\AutoIt\HelpDeskIT\reportaproblem.txt

但它没有被添加到我的 exe 文件中。 (当我启动应用程序时,它找不到文件)

【问题讨论】:

    标签: autoit


    【解决方案1】:

    来自 SciTE4AutoIt3 帮助(在 Extra Utilities --> AutoIt3Wrapper 下)...

    添加文件:

    文件存储在 RT_RCDATA 部分,通常存储字节 为字节。如果节值设置为 -10(RT_RCDATA 在内部 评估为 10) 然后文件在添加之前被压缩:

    #AutoIt3Wrapper_Res_File_Add=file_name, RT_RCDATA     : UNCOMPRESSED 
    #AutoIt3Wrapper_Res_File_Add=file_name, 10            ; UNCOMPRESSED 
    #AutoIt3Wrapper_Res_File_Add=file_name, -10           ; COMPRESSED 
    

    当需要文件时,可以使用此代码将其提取出来。设置 $isCompressed 参数以匹配 Res_File_Add 指令:

    #include <WinAPIRes.au3> 
    #include <WinAPIInternals.au3> 
    
    Func _FileInstallFromResource($sResName, $sDest, $isCompressed = False, $iUncompressedSize = Default) 
        Local $bBytes = _GetResourceAsBytes($sResName, $isCompressed, $iUncompressedSize) 
        If @error Then Return SetError(@error, 0, 0) 
        FileDelete($sDest) 
        FileWrite($sDest, $bBytes) 
    EndFunc 
    
    Func _GetResourceAsBytes($sResName, $isCompressed = False, $iUncompressedSize = Default) 
        Local $hMod = _WinAPI_GetModuleHandle(Null) 
        Local $hRes = _WinAPI_FindResource($hMod, 10, $sResName) 
        If @error Or Not $hRes Then Return SetError(1, 0, 0) 
        Local $dSize = _WinAPI_SizeOfResource($hMod, $hRes) 
        If @error Or Not $dSize Then Return SetError(2, 0, 0) 
        Local $hLoad = _WinAPI_LoadResource($hMod, $hRes) 
        If @error Or Not $hLoad Then Return SetError(3, 0, 0) 
        Local $pData = _WinAPI_LockResource($hLoad) 
        If @error Or Not $pData Then Return SetError(4, 0, 0) 
        Local $tBuffer = DllStructCreate("byte[" & $dSize & "]") 
        _WinAPI_MoveMemory(DllStructGetPtr($tBuffer), $pData, $dSize) 
        If $isCompressed Then 
            Local $oBuffer 
           _WinAPI_LZNTDecompress($tBuffer, $oBuffer, $iUncompressedSize) 
            If @error Then Return SetError(5, 0, 0) 
            $tBuffer = $oBuffer 
        EndIf 
        Return DllStructGetData($tBuffer, 1) 
    EndFunc 
    
    Func _WinAPI_LZNTDecompress(ByRef $tInput, ByRef $tOutput, $iUncompressedSize = Default) 
        ; if no uncompressed size given, use 16x the input buffer 
        If $iUncompressedSize = Default Then $iUncompressedSize = 16 * DllStructGetSize($tInput) 
        Local $tBuffer, $ret 
        $tOutput = 0 
        $tBuffer = DllStructCreate("byte[" & $iUncompressedSize & "]") 
        If @error Then Return SetError(1, 0, 0) 
        $ret = DllCall("ntdll.dll", "long", "RtlDecompressBuffer", "ushort", 2, "struct*", $tBuffer, "ulong", $iUncompressedSize, "struct*", $tInput, "ulong", DllStructGetSize($tInput), "ulong*", 0) 
        If @error Then Return SetError(2, 0, 0) 
        If $ret[0] Then Return SetError(3, $ret[0], 0) 
        $tOutput = DllStructCreate("byte[" & $ret[6] & "]") 
        If Not _WinAPI_MoveMemory(DllStructGetPtr($tOutput), DllStructGetPtr($tBuffer), $ret[6]) Then 
            $tOutput = 0 
            Return SetError(4, 0, 0) 
        EndIf 
        Return $ret[6] 
    EndFunc
    

    【讨论】:

      猜你喜欢
      • 2012-02-15
      • 2017-06-26
      • 1970-01-01
      • 2014-01-29
      • 2015-03-14
      • 2011-10-26
      • 2014-04-22
      • 2012-05-02
      相关资源
      最近更新 更多