Jump to content

Backup Windows using libwim-15.dll


Recommended Posts

Hi everyone,

Homes32 has made a good UDF for manipulating Windows Image Files (.wim) without ImageX.exe but Windows Imaging API directly (wimgapi.dll). I want to capture and apply a system image using wimlib (libwim-15.dll) for faster and better compression. With my kitchen programming skills, I can't figure out how to make my code work with the developers documentation.

Here's what I got:

#RequireAdmin

_WimLib()

Func _WimLib()
    Local Const $Title = "WimLibGui with AutoIt3"
    Local $iResult, $WIMStruct
    Local $sSourceFolder = "Z:"
    Local $sWimFile = "A:\WimLibTest\WimLib Test 2022.WimLib"

    Local $ghWimLib = DllOpen(@ScriptDir & "\libwim-15.dll")
    If $ghWimLib = -1 Then
        MsgBox(262144+16, $Title, """libwin-15.dll"" cannot be opened." & @CRLF & @CRLF & "WimLib.")
        Return
    EndIf

    $WIMStruct = $sWimFile

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_create_new_wim", _
            "ctype", "WIMLIB_COMPRESSION_TYPE_LZX", _
            "wim_ret", $WIMStruct)
    If @error Then
        ConsoleWrite("Error ""wimlib_create_new_wim"" " & @error)
        Return
    EndIf

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_add_image", _
            "wim", $WIMStruct, _
            "source", $sSourceFolder, _
            "name", "", _
            "config_file", "", _
            "add_flags", 0)
    If @error Then
        ConsoleWrite("Error ""wimlib_add_image"" " & @error)
        Return
    EndIf

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_write", _
            "wim", $WIMStruct, _
            "path", $sWimFile, _
            "image", 1, _
            "write_flags", 1, _
            "num_threads", 0)
    If @error Then
        ConsoleWrite("Error ""wimlib_write"" " & @error)
        Return
    EndIf

    Return "Done!"

    $ghWimLib = 0
EndFunc   ;==>_WimLib

Thanks for the help!

Jonathan

 

Edited by MadDogVachon
Added a links

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Please try to read AutoIt Dllcall documentation, It seems to be  You're running without learning how to walk. 🙃

 

Saludos

 

 

Link to comment
Share on other sites

Hi Danyfirex,

Thanks for your answer. I totally agree with you. Sadly, not everyone can imitate Ironman🙃.

I read monoceres tutorial Dealing_with_Dll.pdf, DllCall documentation and Homes32 WimgapiUDF to no avail. I can't figure out how to translate the C code of WimLib documentation to Autoit. That's why I posted here. If you, or someone else, can point me where I can understand, I'm willing to learn.

Thanks again!

Jonathan

 

Edited by MadDogVachon

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Hello, It's because you're not reading/checking deeply. (but It's a little complex if you're a newbie)  

You can find header information more  simple here.

I don't have time now to convert WIMStruct to AutoIt so I'll probably write code/help  later.

 

Saludos

 

 

Link to comment
Share on other sites

Hi Danyfirex,

I finally understand what you said... 😇 And what to do...😓

Here's my improved code. Still not working but it's a step forward.

#RequireAdmin

ConsoleWrite(@CRLF & _WimLib() & @CRLF)

Func _WimLib()
    Local Const $Title = "WimLibGui with AutoIt3"
    Local $iResult
    Local $sSourceFolder = "Z:"
    Local $sWimFile = "D:\WinRE in work!\WimLib\WimLib Test 2022.WimLib"

    Local $ghWimLib = DllOpen(@ScriptDir & "\libwim-15.dll")
    If $ghWimLib = -1 Then
        MsgBox(262144+16, $Title, """libwin-15.dll"" cannot be opened." & @CRLF & @CRLF & "WimLib.")
        Return
    EndIf

    Local $WIMStruct = DllStructCreate("ptr")

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_create_new_wim", _
            "INT", 2, _                     ; ctype
            "STRUCT", $WIMStruct)           ; wim_ret
    If @error Then Return "Error ""wimlib_create_new_wim"" " & @error
    ConsoleWrite("""wimlib_create_new_wim"" " & $iResult)

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_add_image", _
            "STRUCT", $WIMStruct, _         ; wim
            "wstr", $sSourceFolder, _       ; source
            "wstr", "", _                   ; name
            "wstr", "", _                   ; config_file
            "int", 0)                       ; add_flags
    If @error Then Return "Error ""wimlib_add_image"" " & @error
    ConsoleWrite("""wimlib_add_image"" " & $iResult)

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_write", _
            "STRUCT", $WIMStruct, _         ; wim
            "wstr", $sWimFile, _            ; path
            "int", 1, _                     ; image
            "int", 1, _                     ; write_flags
            "int", 0)                       ; num_threads
    If @error Then Return "Error ""wimlib_write"" " & @error
    ConsoleWrite("""wimlib_write"" " & $iResult)

    Return "Done!"

    $ghWimLib = 0
EndFunc   ;==>_WimLib

Thanks also for pointing to the header. And yes, I'm a newbie regarding DLL.

I hope to share an improved code shortly. Thanks!

Jonathan

Edited by MadDogVachon
I'm a French Canadian who made errors...

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Shortly...

Hi everyone,

Here's my "improved" code. Still not working because I don't know to create a new structure.

#RequireAdmin

; wimlib_compression_type
Global Const $WIMLIB_COMPRESSION_TYPE_NONE                  = 0
Global Const $WIMLIB_COMPRESSION_TYPE_XPRESS                = 1     ; Chunk sizes that are powers of 2 between «2^12» and «2^16», inclusively.
Global Const $WIMLIB_COMPRESSION_TYPE_LZX                   = 2     ; Chunk sizes that are powers of 2 between «2^15» and «2^21», inclusively.
                                                                    ; Chunk sizes other than «2^15» are not compatible with the Microsoft implementation.
Global Const $WIMLIB_COMPRESSION_TYPE_LZMS                  = 3     ; Chunk sizes that are powers of 2 between «2^15» and 2^30», inclusively.
                                                                    ; This format is best used for large chunk sizes.
                                                                    ; Note: LZMS compression is only compatible with wimlib v1.6.0 and later,
                                                                    ; WIMGAPI Windows 8 and later, and DISM Windows 8.1 and later.
                                                                    ; Chunk sizes larger than «2^26» are not compatible with the Microsoft implementation.

; wimlib_progress_msg
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN       = 0
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN        = 1
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE    = 3
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS           = 4
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN   = 5
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_METADATA          = 6
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END         = 7
Global Const $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_END          = 8
Global Const $WIMLIB_PROGRESS_MSG_SCAN_BEGIN                = 9
Global Const $WIMLIB_PROGRESS_MSG_SCAN_DENTRY               = 10
Global Const $WIMLIB_PROGRESS_MSG_SCAN_END                  = 11
Global Const $WIMLIB_PROGRESS_MSG_WRITE_STREAMS             = 12
Global Const $WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN      = 13
Global Const $WIMLIB_PROGRESS_MSG_WRITE_METADATA_EN         = 14
Global Const $WIMLIB_PROGRESS_MSG_RENAME                    = 15
Global Const $WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY          = 16
Global Const $WIMLIB_PROGRESS_MSG_CALC_INTEGRITY            = 17
Global Const $WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART          = 19
Global Const $WIMLIB_PROGRESS_MSG_SPLIT_END_PART            = 20
Global Const $WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND      = 21
Global Const $WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND        = 22
Global Const $WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM       = 23
Global Const $WIMLIB_PROGRESS_MSG_WIMBOOT_EXCLUDE           = 24
Global Const $WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN             = 25
Global Const $WIMLIB_PROGRESS_MSG_DONE_WITH_FILE            = 26
Global Const $WIMLIB_PROGRESS_MSG_BEGIN_VERIFY_IMAGE        = 27
Global Const $WIMLIB_PROGRESS_MSG_END_VERIFY_IMAGE          = 28
Global Const $WIMLIB_PROGRESS_MSG_VERIFY_STREAMS            = 29

; wimlib_progress_status
Global Const $WIMLIB_PROGRESS_STATUS_CONTINUE               = 0
Global Const $WIMLIB_PROGRESS_STATUS_ABORT                  = 1

; wimlib_update_op
Global Const $WIMLIB_UPDATE_OP_ADD                          = 0

; wimlib_error_code
Global Const $WIMLIB_ERR_SUCCESS                            = 0
Global Const $WIMLIB_ERR_ALREADY_LOCKED                     = 1
Global Const $WIMLIB_ERR_DECOMPRESSION                      = 2
Global Const $WIMLIB_ERR_FUSE                               = 6
Global Const $WIMLIB_ERR_GLOB_HAD_NO_MATCHES                = 8
Global Const $WIMLIB_ERR_ICONV_NOT_AVAILABLE                = 9
Global Const $WIMLIB_ERR_IMAGE_COUNT                        = 10
Global Const $WIMLIB_ERR_IMAGE_NAME_COLLISION               = 11
Global Const $WIMLIB_ERR_INSUFFICIENT_PRIVILEGES            = 12
Global Const $WIMLIB_ERR_INTEGRITY                          = 13
Global Const $WIMLIB_ERR_INVALID_CAPTURE_CONFIG             = 14
Global Const $WIMLIB_ERR_INVALID_CHUNK_SIZE                 = 15
Global Const $WIMLIB_ERR_INVALID_COMPRESSION_TYPE           = 16
Global Const $WIMLIB_ERR_INVALID_HEADER                     = 17
Global Const $WIMLIB_ERR_INVALID_IMAGE                      = 18
Global Const $WIMLIB_ERR_INVALID_INTEGRITY_TABLE            = 19
Global Const $WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY         = 20
Global Const $WIMLIB_ERR_INVALID_METADATA_RESOURCE          = 21
Global Const $WIMLIB_ERR_INVALID_MULTIBYTE_STRING           = 22
Global Const $WIMLIB_ERR_INVALID_OVERLAY                    = 23
Global Const $WIMLIB_ERR_INVALID_PARAM                      = 24
Global Const $WIMLIB_ERR_INVALID_PART_NUMBER                = 25
Global Const $WIMLIB_ERR_INVALID_PIPABLE_WIM                = 26
Global Const $WIMLIB_ERR_INVALID_REPARSE_DATA               = 27
Global Const $WIMLIB_ERR_INVALID_RESOURCE_HASH              = 28
Global Const $WIMLIB_ERR_INVALID_UTF16_STRING               = 30
Global Const $WIMLIB_ERR_INVALID_UTF8_STRING                = 31
Global Const $WIMLIB_ERR_IS_DIRECTORY                       = 32
Global Const $WIMLIB_ERR_IS_SPLIT_WIM                       = 33
Global Const $WIMLIB_ERR_LIBXML_UTF16_HANDLER_NOT_AVAILABLE = 34
Global Const $WIMLIB_ERR_LINK                               = 35
Global Const $WIMLIB_ERR_METADATA_NOT_FOUND                 = 36
Global Const $WIMLIB_ERR_MKDIR                              = 37
Global Const $WIMLIB_ERR_MQUEUE                             = 38
Global Const $WIMLIB_ERR_NOMEM                              = 39
Global Const $WIMLIB_ERR_NOTDIR                             = 40
Global Const $WIMLIB_ERR_NOTEMPTY                           = 41
Global Const $WIMLIB_ERR_NOT_A_REGULAR_FILE                 = 42
Global Const $WIMLIB_ERR_NOT_A_WIM_FILE                     = 43
Global Const $WIMLIB_ERR_NOT_PIPABLE                        = 44
Global Const $WIMLIB_ERR_NO_FILENAME                        = 45
Global Const $WIMLIB_ERR_NTFS_3G                            = 46
Global Const $WIMLIB_ERR_OPEN                               = 47
Global Const $WIMLIB_ERR_OPENDIR                            = 48
Global Const $WIMLIB_ERR_PATH_DOES_NOT_EXIST                = 49
Global Const $WIMLIB_ERR_READ                               = 50
Global Const $WIMLIB_ERR_READLINK                           = 51
Global Const $WIMLIB_ERR_RENAME                             = 52
Global Const $WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED         = 54
Global Const $WIMLIB_ERR_RESOURCE_NOT_FOUND                 = 55
Global Const $WIMLIB_ERR_RESOURCE_ORDER                     = 56
Global Const $WIMLIB_ERR_SET_ATTRIBUTES                     = 57
Global Const $WIMLIB_ERR_SET_REPARSE_DATA                   = 58
Global Const $WIMLIB_ERR_SET_SECURITY                       = 59
Global Const $WIMLIB_ERR_SET_SHORT_NAME                     = 60
Global Const $WIMLIB_ERR_SET_TIMESTAMPS                     = 61
Global Const $WIMLIB_ERR_SPLIT_INVALID                      = 62
Global Const $WIMLIB_ERR_STAT                               = 63
Global Const $WIMLIB_ERR_UNEXPECTED_END_OF_FILE             = 65
Global Const $WIMLIB_ERR_UNICODE_STRING_NOT_REPRESENTABLE   = 66
Global Const $WIMLIB_ERR_UNKNOWN_VERSION                    = 67
Global Const $WIMLIB_ERR_UNSUPPORTED                        = 68
Global Const $WIMLIB_ERR_UNSUPPORTED_FILE                   = 69
Global Const $WIMLIB_ERR_WIM_IS_READONLY                    = 71
Global Const $WIMLIB_ERR_WRITE                              = 72
Global Const $WIMLIB_ERR_XML                                = 73
Global Const $WIMLIB_ERR_WIM_IS_ENCRYPTED                   = 74
Global Const $WIMLIB_ERR_WIMBOOT                            = 75
Global Const $WIMLIB_ERR_ABORTED_BY_PROGRESS                = 76
Global Const $WIMLIB_ERR_UNKNOWN_PROGRESS_STATUS            = 77
Global Const $WIMLIB_ERR_MKNOD                              = 78
Global Const $WIMLIB_ERR_MOUNTED_IMAGE_IS_BUSY              = 79
Global Const $WIMLIB_ERR_NOT_A_MOUNTPOINT                   = 80
Global Const $WIMLIB_ERR_NOT_PERMITTED_TO_UNMOUNT           = 81

; WIMLIB_CHANGE
Global Const $WIMLIB_CHANGE_READONLY_FLAG                       = 0x00000001
Global Const $WIMLIB_CHANGE_GUID                                = 0x00000002
Global Const $WIMLIB_CHANGE_BOOT_INDEX                          = 0x00000004
Global Const $WIMLIB_CHANGE_RPFIX_FLAG                          = 0x00000008

; WIMLIB_ADD_FLAG
Global Const $WIMLIB_ADD_FLAG_NTFS                              = 0x00000001
Global Const $WIMLIB_ADD_FLAG_DEREFERENCE                       = 0x00000002
Global Const $WIMLIB_ADD_FLAG_VERBOSE                           = 0x00000004
Global Const $WIMLIB_ADD_FLAG_BOOT                              = 0x00000008
Global Const $WIMLIB_ADD_FLAG_UNIX_DATA                         = 0x00000010
Global Const $WIMLIB_ADD_FLAG_NO_ACLS                           = 0x00000040
Global Const $WIMLIB_ADD_FLAG_EXCLUDE_VERBOSE                   = 0x00000080
Global Const $WIMLIB_ADD_FLAG_RPFIX                             = 0x00000100
Global Const $WIMLIB_ADD_FLAG_NORPFIX                           = 0x00000200
Global Const $WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE            = 0x00000400
Global Const $WIMLIB_ADD_FLAG_WINCONFIG                         = 0x00000800
Global Const $WIMLIB_ADD_FLAG_WIMBOOT                           = 0x00001000
Global Const $WIMLIB_ADD_FLAG_NO_REPLACE                        = 0x00002000
Global Const $WIMLIB_ADD_FLAG_TEST_FILE_EXCLUSION               = 0x00004000
Global Const $WIMLIB_ADD_FLAG_SNAPSHOT                          = 0x00008000
Global Const $WIMLIB_ADD_FLAG_FILE_PATHS_UNNEEDED               = 0x00010000

; WIMLIB_WRITE_FLAG
Global Const $WIMLIB_WRITE_FLAG_CHECK_INTEGRITY                 = 0x00000001
Global Const $WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY              = 0x00000002
Global Const $WIMLIB_WRITE_FLAG_PIPABLE                         = 0x00000004
Global Const $WIMLIB_WRITE_FLAG_NOT_PIPABLE                     = 0x00000008
Global Const $WIMLIB_WRITE_FLAG_RECOMPRESS                      = 0x00000010
Global Const $WIMLIB_WRITE_FLAG_FSYNC                           = 0x00000020
Global Const $WIMLIB_WRITE_FLAG_REBUILD                         = 0x00000040
Global Const $WIMLIB_WRITE_FLAG_SOFT_DELETE                     = 0x00000080
Global Const $WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG            = 0x00000100
Global Const $WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIM               = 0x00000200
Global Const $WIMLIB_WRITE_FLAG_STREAMS_OK                      = 0x00000400
Global Const $WIMLIB_WRITE_FLAG_RETAIN_GUID                     = 0x00000800
Global Const $WIMLIB_WRITE_FLAG_SOLID                           = 0x00001000
Global Const $WIMLIB_WRITE_FLAG_SEND_DONE_WITH_FILE_MESSAGES    = 0x00002000
Global Const $WIMLIB_WRITE_FLAG_NO_SOLID_SORT                   = 0x00004000
Global Const $WIMLIB_WRITE_FLAG_UNSAFE_COMPACT                  = 0x00008000

; WIMLIB_DELETE_FLAG
Global Const $WIMLIB_DELETE_FLAG_FORCE                          = 0x00000001
Global Const $WIMLIB_DELETE_FLAG_RECURSIVE                      = 0x00000002

; WIMLIB_EXPORT_FLAG
Global Const $WIMLIB_EXPORT_FLAG_BOOT                           = 0x00000001
Global Const $WIMLIB_EXPORT_FLAG_NO_NAMES                       = 0x00000002
Global Const $WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS                = 0x00000004
Global Const $WIMLIB_EXPORT_FLAG_GIFT                           = 0x00000008
Global Const $WIMLIB_EXPORT_FLAG_WIMBOOT                        = 0x00000010

; WIMLIB_UPDATE_FLAG_SEND_PROGRESS
Global Const $WIMLIB_UPDATE_FLAG_SEND_PROGRESS                  = 0x00000001


ConsoleWrite(@CRLF & _WimLib_Capture() & @CRLF)

Func _WimLib_Capture()
    Local Const $Title = "WimLibGui with AutoIt3"
    Local $iResult, $pCallBack
    Local $bSolid = True
    Local $iCompressionType = $WIMLIB_COMPRESSION_TYPE_LZX
    Local $iCompressionLevel = 50
    Local $iChunkSize = 2^15
    Local $iFlag = BitOR($WIMLIB_ADD_FLAG_VERBOSE, $WIMLIB_WRITE_FLAG_CHECK_INTEGRITY)
    Local $sSourceFolder = "Z:"
    Local $sWimFile = "D:\WinRE in work!\WimLib\WimLib Test 2022.WimLib"

    Local $ghWimLib = DllOpen(@ScriptDir & "\libwim-15.dll")
    If $ghWimLib = -1 Then
        MsgBox(262144+16, $Title, """libwin-15.dll"" cannot be opened." & @CRLF & @CRLF & "WimLib.")
        Return
    EndIf

    Local $WIMStruct = DllStructCreate("ptr")   ;????????????????????????????????????????????????????????????????????????????????????????

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_create_new_wim", _
            "INT", $WIMLIB_COMPRESSION_TYPE_LZMS, _         ; int ctype
            "STRUCT", $WIMStruct)                           ; WIMStruct wim_ret
    If @error Then Return "Error ""wimlib_create_new_wim"" " & @error & "_" & $iResult
    ConsoleWrite("""wimlib_create_new_wim"" " & $iResult)

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_add_image", _
            "STRUCT", $WIMStruct, _                         ; WIMStruct wim
            "wstr", $sSourceFolder, _                       ; const wimlib_tchar source
            "wstr", "", _                                   ; const wimlib_tchar name
            "wstr", "", _                                   ; const wimlib_tchar config_file
            "int", 0)                                       ; int add_flags
    If @error Then Return "Error ""wimlib_add_image"" " & @error & "_" & $iResult
    ConsoleWrite("""wimlib_add_image"" " & $iResult)

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_set_default_compression_level", _
            "int", $iCompressionType, _                     ; int ctype
            "uint", $iCompressionLevel)                     ; unsigned int compression_level
    If @error Then Return "Error ""wimlib_set_default_compression_level"" " & @error & "_" & $iResult
    ConsoleWrite("""wimlib_set_default_compression_level"" " & $iResult)

    If $bSolid = True Then
        $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_set_output_pack_chunk_size", _
                "STRUCT", $WIMStruct, _                         ; WIMStruct wim
                "uint", $iChunkSize)                            ; uint32_t chunk_size
        If @error Then Return "Error ""wimlib_set_output_pack_chunk_size"" " & @error & "_" & $iResult
        ConsoleWrite("""wimlib_set_output_pack_chunk_size"" " & $iResult)

        $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_set_output_pack_compression_type", _
                "STRUCT", $WIMStruct, _                         ; WIMStruct wim
                "int", $iCompressionType)                       ; int ctype
        If @error Then Return "Error ""wimlib_set_output_pack_compression_type"" " & @error & "_" & $iResult
        ConsoleWrite("""wimlib_set_output_pack_compression_type"" " & $iResult)
    Else
        $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_set_output_chunk_size", _
                "STRUCT", $WIMStruct, _                         ; WIMStruct wim
                "uint", $iChunkSize)                            ; uint32_t chunk_size
        If @error Then Return "Error ""wimlib_set_output_chunk_size"" " & @error & "_" & $iResult
        ConsoleWrite("""wimlib_set_output_chunk_size"" " & $iResult)

        $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_set_output_compression_type", _
                "STRUCT", $WIMStruct, _                         ; WIMStruct wim
                "int", $iCompressionType)                       ; int ctype
        If @error Then Return "Error ""wimlib_set_output_compression_type"" " & @error & "_" & $iResult
        ConsoleWrite("""wimlib_set_output_compression_type"" " & $iResult)
    EndIf

    $iResult = DllCall($ghWimLib, "int:cdecl", "wimlib_write", _
            "STRUCT", $WIMStruct, _                         ; WIMStruct wim
            "wstr", $sWimFile, _                            ; const wimlib_tchar path
            "int", 1, _                                     ; int image
            "int", $iFlag, _                                ; int write_flags
            "uint", 0)                                      ; unsigned num_threads
    If @error Then Return "Error ""wimlib_write"" " & @error & "_" & $iResult
    ConsoleWrite("""wimlib_write"" " & $iResult)

    $ghWimLib = 0
    DllCallbackFree($pCallBack)

    Return "Done!"
EndFunc   ;==>_WimLib_Capture

Jonathan

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Note that the WIMStruct is a file structure and as such cannot be handled as an AutoIt DllStruct. The reference to the WIMStruct file structure is a pointer. The code below is AutoIt code to obtain this pointer from the wimlib_create_new_wim() function.

Also note that the DllCall() function returns an array (as opposed to a simple variable).

The code here is 64 bit code:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#AutoIt3Wrapper_UseX64=Y

Opt( "MustDeclareVars", 1 )

WimLib()

Func WimLib()
  Local $hWimLib = DllOpen( "libwim-15-64.dll" )
  If $hWimLib = -1 Then Return ConsoleWrite( "ERR: libwin-15-64.dll open" & @CRLF )
  ConsoleWrite( "OK : libwin-15-64.dll open" & @CRLF )

  Local $aRet, $tWIMStruct = DllStructCreate( "ptr" ) ; Pointer storage for WIMStruct pointer
  $aRet = DllCall( $hWimLib, "int:cdecl", "wimlib_create_new_wim", _
                             "int", 2, _              ; ctype
                             "struct*", $tWIMStruct ) ; Store WIMStruct pointer
  If $aRet[0] Or @error Then Return ConsoleWrite( "ERR: wimlib_create_new_wim" & @CRLF & _
                                                  "$aRet[0] = " & $aRet[0] & @CRLF & _
                                                  "@error   = " & @error & @CRLF )
  ConsoleWrite( "OK : wimlib_create_new_wim" & @CRLF )
  Local $pWIMStruct = DllStructGetData( $tWIMStruct, 1 ) ; Get WIMStruct pointer from storage
  ConsoleWrite( "$pWIMStruct = " & $pWIMStruct & @CRLF )

  $hWimLib = 0
EndFunc

Output:

OK : libwin-15-64.dll open
OK : wimlib_create_new_wim
$pWIMStruct = 0x0000000000909530

 

Link to comment
Share on other sites

Hi LarsJ,

Thanks for your reply. I've implemented your code. But I have the error 36 with wimlib_add_image.

Output:

OK : libwin-15-64.dll open
OK : wimlib_create_new_wim
$pWIMStruct = 0x000001E20CF763A0
ERR: wimlib_add_image
$aRet[0] = 36
@error   = 0

Error 36 indicate failure (for different reasons) to read the metadata resource for an image over which iteration needed to be done. Sometime, I have error 10 (WIMLIB_ERR_IMAGE_COUNT) which seems be related to metadata. Other time, no error and the script stop itself without the "OK : wimlib_add_image" message.

Here's your updated code to test:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#AutoIt3Wrapper_UseX64=Y

Opt( "MustDeclareVars", 1 )

WimLib()

Func WimLib()
    Local $hWimLib = DllOpen( "libwim-15-64.dll" )
    If $hWimLib = -1 Then Exit ConsoleWrite( "ERR: libwin-15-64.dll open" & @CRLF )
    ConsoleWrite( "OK : libwin-15-64.dll open" & @CRLF )

    Local $aRet, $tWIMStruct = DllStructCreate( "ptr" ) ; Pointer storage for WIMStruct pointer
    $aRet = DllCall( $hWimLib, "int:cdecl", "wimlib_create_new_wim", _
                                "int", 2, _              ; ctype
                                "struct*", $tWIMStruct ) ; Store WIMStruct pointer
    If $aRet[0] Or @error Then Return ConsoleWrite( "ERR: wimlib_create_new_wim" & @CRLF & _
                                                  "$aRet[0] = " & $aRet[0] & & @CRLF _
                                                  DllCall($hWimLib, "wstr:cdecl", "wimlib_get_error_string", "int", $aRet[0]) & @CRLF & _
                                                  "@error   = " & @error & @CRLF )
    ConsoleWrite( "OK : wimlib_create_new_wim" & @CRLF )
    Local $pWIMStruct = DllStructGetData( $tWIMStruct, 1 ) ; Get WIMStruct pointer from storage
    ConsoleWrite( "$pWIMStruct = " & $pWIMStruct & @CRLF )

    $aRet = DllCall( $hWimLib, "int:cdecl", "wimlib_add_image", _
                                "struct*", $tWIMStruct, _   ; WIMStruct pointer
                                "wstr", "Z:", _             ; source
                                "wstr", "", _               ; name
                                "wstr", "", _               ; config_file
                                "int", 4)                   ; add_flags
    If $aRet[0] Or @error Then Return ConsoleWrite( "ERR: wimlib_add_image" & @CRLF & _
                                                  "$aRet[0] = " & $aRet[0] & @CRLF & _
                                                  DllCall($hWimLib, "wstr:cdecl", "wimlib_get_error_string", "int", $aRet[0]) & @CRLF & _
                                                  "@error   = " & @error & @CRLF )
    ConsoleWrite( "OK : wimlib_add_image" & @CRLF )

    $hWimLib = 0
EndFunc

You can see I also added DllCall($hWimLib, "wstr:cdecl", "wimlib_get_error_string", "int", $aRet[0]) to convert a wimlib error code into a string describing it. Which is not working...

Thanks again!

Jonathan

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Hey Dude.  You are embarking on a project that I started forever ago, but never really got too far on.  I am not very knowledgeable when it comes to working with C libraries and whatnot.  Guess I am just stupid.  I can provide to you what little I have done.  Hope it helps.  Maybe you can get farther than I did.

; #INDEX# =======================================================================================================================
; Title .........: wimlib
; AutoIt Version : 3.3.8.1+
; Language ......: English
; Description ...: Functions allow for the manipulation of wim files using wimlib rather than the Micrsoft Assessment and Deployment Toolkit
; Author(s) .....: William Higgs (whiggs)
; ===============================================================================================================================
#include-once
#include "C:\Users\whiggs\OneDrive\always script\wimlib_lib\wimlibconstants.au3"
#include <WinAPI.au3>
#include <Debug.au3>
;#include <_DLLStructDisplay.au3>

Global $wimstr = 0
Global $gsWimlibDLL = ""
Global $ghwimlib = 0 ; initialized by _init_WIMlib() and contains the handle to DllOpen($gsWimDLL)
Global $giWIMRef = 0 ; reference var. Value is >= 1 if $gsWimlibDLL is loaded.

Func _init_wimlib ($dllfile = "libwim-15.dll", $initflags = 0)
    $giWIMRef += 1
    If $giWIMRef > 1 Then
        Return SetExtended($ghwimlib, 0) ; dll already loaded
    EndIf

    If Not FileExists ( $dllfile ) Then
        Return SetError ( 2, 0, -1 )
    EndIf
    $gsWimlibDLL = $dllfile
    $ghwimlib = DllOpen ( $gsWimlibDLL )
    If $ghwimlib = -1 Then
        $giWIMRef = 0
        Return SetError ( 1, 0, -1 )
    EndIf
    DllCall ( $ghwimlib, "int:cdecl", "wimlib_global_init", $initflags )
    If @error Then
        Return SetError(3, 0, -1)
    EndIf

    Return SetExtended ( $ghwimlib, 0 )

EndFunc


Func _quit_wimlib ()
    If $ghwimlib = 0 Or $ghwimlib = -1 Then
        Return SetError ( 1, 0, False )
    EndIf
    $giWIMRef -= 1
    If $giWIMRef = 0 Then
        DllCall ( $ghwimlib, "none:cdecl", "wimlib_global_cleanup" )
        DllClose ( $ghwimlib )
        $ghwimlib = 0
    EndIf

EndFunc

Func _open_wim ($wimfile, $openflags = 0, $callback = Null )
    ;$tchar = DllStructCreate
    If $callback = Null Then
        $aReturn = DllCall( $ghwimlib, "int:cdecl", "wimlib_open_wim", "wstr", $wimfile, "int", $openflags, "ptr*", Null )
    Else
        $aReturn = DllCall( $ghwimlib, "int:cdecl", "wimlib_open_wim_with_progress", "wstr", $wimfile, "int", $openflags, "ptr*", Null, "ptr", DllCallbackGetPtr ( $callback ), "ptr", 0 )
    EndIf

    ;If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "wimlib_open_wim DllCall failed with @error " & @error & @CRLF & "@ewxtend: " & @extended)
    _DebugArrayDisplay($aReturn, "wimlib_open_wim $aReturn")

    ;If bad return code, then return with error
    If $aReturn[0] <> 0 Then Return SetError(1, $aReturn[0], 0)

    ;All is good, return pointer
    Return $aReturn[3] ;Pointer to WIMStruct structure

EndFunc

Func _wimlib_free($pWimStruct)
    ;Free winstruct resources
    If Not IsPtr ( $pWimStruct ) Then
        Return SetError ( 1, 0 )
    EndIf

    DllCall( $ghwimlib, "none:cdecl", "wimlib_free", "ptr", $pWimStruct )
    If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "wimlib_free DllCall failed with @error " & @error)
    ;All is good
    Return SetExtended( _WinAPI_GetLastError() )
EndFunc
Func _wimlib_register_progress_function ( $Wimstruct, $progfunc, $progctx = Null )
    $mesresult = DllCall ( $ghwimlib, "none:cdecl", "wimlib_register_progress_function", "ptr", $Wimstruct, "ptr", $progfunc, "ptr", $progctx )
EndFunc

Func _wimlib_verify_wim ( $Wimstruct, $progressfunc = Null, $pvUserData = 0 )
    If Not IsPtr ( $Wimstruct ) Then
        Return SetError ( 1, 0, Null )
    EndIf
    ;If $withprogress Then
        ;$str = DllStructCreate ( $tagwimlib_progress_info_verify_image )
        ;$progfun = DllCallbackRegister ( "prog", "
    ;Else
        $verresult = DllCall ( $ghwimlib, "int:cdecl", "wimlib_verify_wim", "ptr", $Wimstruct, "int", 0 )
    ;EndIf

    If @error Then
        Return SetError ( 2, -1 )
    EndIf
    _DebugArrayDisplay($verresult, "wimlib_verify_wim $verresult")
    Return $verresult[0]
EndFunc
Func _wimlib_get_image_name ( $Wimstruct, $image )
    If Not IsPtr ( $Wimstruct ) Then
        Return SetError ( 1, 0, Null )
    EndIf
    $imnaresult = DllCall ( $ghwimlib, "wstr:cdecl", "wimlib_get_image_name", "ptr", $Wimstruct, "int", $image )
    If @error Then
        Return SetError ( 2, 0 )
    EndIf
    Return $imnaresult[0]
EndFunc
Func _wimlib_get_xml_data ( $Wimstruct )
    If Not IsPtr ( $Wimstruct ) Then
        Return SetError ( 1, 0, Null )
    EndIf
    Local $aReturn[2]
    Local $ppvImageInfo = DllStructCreate("ptr") ; Buffer for XML Data
    Local $pcbImageInfo = DllStructCreate("dword") ; Size of buffer in bytes

    $xmlresult = DllCall ( $ghwimlib, "int:cdecl", "wimlib_get_xml_data", "ptr", $Wimstruct, "ptr", DllStructGetPtr ( $ppvImageInfo ), "ptr", DllStructGetPtr ( $pcbImageInfo ) )
    If @error Then
        Return SetError ( 2, 0, Null )
    EndIf

    _DebugArrayDisplay($xmlresult, "wimlib_get_xml_data $xmlresult")
    Local $xml = DllStructCreate("byte [" & DllStructGetData($pcbImageInfo, 1) & "]", DllStructGetData($ppvImageInfo, 1))
    $aReturn[0] = $xmlresult[0]
    $aReturn[1] = BinaryToString(DllStructGetData($xml, 1), 2)
    _WinAPI_LocalFree($ppvImageInfo)
    _WinAPI_LocalFree($xml)
    Return $aReturn[1]
    ;Return DllStructGetData ( $ppvImageInfo, 1 )
EndFunc

Func _wimlib_get_wim_info ( $Wimstruct )
    If Not IsPtr ( $Wimstruct ) Then
        Return SetError ( 1, 0, Null )
    EndIf
    $infostruct = DllStructCreate ( $tagwimlib_wim_info )
    $wiminforesult = DllCall ( $ghwimlib, "int:cdecl", "wimlib_get_wim_info", "ptr", $Wimstruct, "ptr", DllStructGetPtr ( $infostruct ) )
    If @error Then
        Return SetError ( 2, 0, Null )
    EndIf
    _DebugArrayDisplay($wiminforesult, "wimlib_get_wim_info $wiminforesult")
    Return $wiminforesult[2]
EndFunc

And this is what I have for wimlibconstants:

#include-once

; #INDEX# =======================================================================================================================
; Title .........: WIMLib_Constants
; AutoIt Version : 3.3.15.0
; Description ...: Constants for WIMlib functions.
; Author(s) .....: Higgs, William (whiggs)
; ===============================================================================================================================

; #CONSTANTS# ===================================================================================================================
#region ### START $WIMLib Constants ###

Global Enum $WIMLIB_ERR_SUCCESS, $WIMLIB_ERR_ALREADY_LOCKED, $WIMLIB_ERR_DECOMPRESSION, $WIMLIB_ERR_FUSE = 6, $WIMLIB_ERR_GLOB_HAD_NO_MATCHES = 8, $WIMLIB_ERR_IMAGE_COUNT = 10, $WIMLIB_ERR_IMAGE_NAME_COLLISION, $WIMLIB_ERR_INSUFFICIENT_PRIVILEGES, $WIMLIB_ERR_INTEGRITY, $WIMLIB_ERR_INVALID_CAPTURE_CONFIG, $WIMLIB_ERR_INVALID_CHUNK_SIZE, $WIMLIB_ERR_INVALID_COMPRESSION_TYPE, $WIMLIB_ERR_INVALID_HEADER, $WIMLIB_ERR_INVALID_IMAGE, $WIMLIB_ERR_INVALID_INTEGRITY_TABLE, $WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY, $WIMLIB_ERR_INVALID_METADATA_RESOURCE, $WIMLIB_ERR_INVALID_OVERLAY = 23, $WIMLIB_ERR_INVALID_PARAM, $WIMLIB_ERR_INVALID_PART_NUMBER, $WIMLIB_ERR_INVALID_PIPABLE_WIM, $WIMLIB_ERR_INVALID_REPARSE_DATA, $WIMLIB_ERR_INVALID_RESOURCE_HASH, $WIMLIB_ERR_INVALID_UTF16_STRING = 30, $WIMLIB_ERR_INVALID_UTF8_STRING, $WIMLIB_ERR_IS_DIRECTORY, $WIMLIB_ERR_IS_SPLIT_WIM, $WIMLIB_ERR_LINK = 35, $WIMLIB_ERR_METADATA_NOT_FOUND, $WIMLIB_ERR_MKDIR, $WIMLIB_ERR_MQUEUE, $WIMLIB_ERR_NOMEM, $WIMLIB_ERR_NOTDIR, $WIMLIB_ERR_NOTEMPTY, $WIMLIB_ERR_NOT_A_REGULAR_FILE, $WIMLIB_ERR_NOT_A_WIM_FILE, $WIMLIB_ERR_NOT_PIPABLE, $WIMLIB_ERR_NO_FILENAME, $WIMLIB_ERR_NTFS_3G, $WIMLIB_ERR_OPEN, $WIMLIB_ERR_OPENDIR, $WIMLIB_ERR_PATH_DOES_NOT_EXIST, $WIMLIB_ERR_READ, $WIMLIB_ERR_READLINK, $WIMLIB_ERR_RENAME, $WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED = 54, $WIMLIB_ERR_RESOURCE_NOT_FOUND, $WIMLIB_ERR_RESOURCE_ORDER, $WIMLIB_ERR_SET_ATTRIBUTES, $WIMLIB_ERR_SET_REPARSE_DATA, $WIMLIB_ERR_SET_SECURITY, $WIMLIB_ERR_SET_SHORT_NAME, $WIMLIB_ERR_SET_TIMESTAMPS, $WIMLIB_ERR_SPLIT_INVALID, $WIMLIB_ERR_STAT, $WIMLIB_ERR_UNEXPECTED_END_OF_FILE = 65, $WIMLIB_ERR_UNICODE_STRING_NOT_REPRESENTABLE, $WIMLIB_ERR_UNKNOWN_VERSION, $WIMLIB_ERR_UNSUPPORTED, $WIMLIB_ERR_UNSUPPORTED_FILE, $WIMLIB_ERR_WIM_IS_READONLY = 71, $WIMLIB_ERR_WRITE, $WIMLIB_ERR_XML, $WIMLIB_ERR_WIM_IS_ENCRYPTED, $WIMLIB_ERR_WIMBOOT, $WIMLIB_ERR_ABORTED_BY_PROGRESS, $WIMLIB_ERR_UNKNOWN_PROGRESS_STATUS, $WIMLIB_ERR_MKNOD, $WIMLIB_ERR_MOUNTED_IMAGE_IS_BUSY, $WIMLIB_ERR_NOT_A_MOUNTPOINT, $WIMLIB_ERR_NOT_PERMITTED_TO_UNMOUNT, $WIMLIB_ERR_FVE_LOCKED_VOLUME, $WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG, $WIMLIB_ERR_WIM_IS_INCOMPLETE, $WIMLIB_ERR_COMPACTION_NOT_POSSIBLE, $WIMLIB_ERR_IMAGE_HAS_MULTIPLE_REFERENCES, $WIMLIB_ERR_DUPLICATE_EXPORTED_IMAGE, $WIMLIB_ERR_CONCURRENT_MODIFICATION_DETECTED, $WIMLIB_ERR_SNAPSHOT_FAILURE, $WIMLIB_ERR_INVALID_XATTR, $WIMLIB_ERR_SET_XATTR

Global Enum $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN, $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN, $WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE = 3, $WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS, $WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN, $WIMLIB_PROGRESS_MSG_EXTRACT_METADATA, $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END, $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_END, $WIMLIB_PROGRESS_MSG_SCAN_BEGIN, $WIMLIB_PROGRESS_MSG_SCAN_DENTRY, $WIMLIB_PROGRESS_MSG_SCAN_END, $WIMLIB_PROGRESS_MSG_WRITE_STREAMS, $WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN, $WIMLIB_PROGRESS_MSG_WRITE_METADATA_END, $WIMLIB_PROGRESS_MSG_RENAME, $WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY, $WIMLIB_PROGRESS_MSG_CALC_INTEGRITY, $WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART = 19, $WIMLIB_PROGRESS_MSG_SPLIT_END_PART, $WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND, $WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND, $WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM, $WIMLIB_PROGRESS_MSG_WIMBOOT_EXCLUDE, $WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN, $WIMLIB_PROGRESS_MSG_DONE_WITH_FILE, $WIMLIB_PROGRESS_MSG_BEGIN_VERIFY_IMAGE, $WIMLIB_PROGRESS_MSG_END_VERIFY_IMAGE, $WIMLIB_PROGRESS_MSG_VERIFY_STREAMS, $WIMLIB_PROGRESS_MSG_TEST_FILE_EXCLUSION, $WIMLIB_PROGRESS_MSG_HANDLE_ERROR

Global Enum $WIMLIB_PROGRESS_STATUS_CONTINUE, $WIMLIB_PROGRESS_STATUS_ABORT
Global Enum $WIMLIB_UPDATE_OP_ADD, $WIMLIB_UPDATE_OP_DELETE, $WIMLIB_UPDATE_OP_RENAME
Global Const $WIMLIB_ADD_FLAG_BOOT = 0x00000008
Global Const $WIMLIB_ADD_FLAG_DEREFERENCE = 0x00000002
Global Const $WIMLIB_ADD_FLAG_EXCLUDE_VERBOSE = 0x00000080
Global Const $WIMLIB_ADD_FLAG_FILE_PATHS_UNNEEDED = 0x00010000
Global Const $WIMLIB_ADD_FLAG_NO_ACLS = 0x00000020
Global Const $WIMLIB_ADD_FLAG_NO_REPLACE = 0x00002000
Global Const $WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE = 0x00000400
Global Const $WIMLIB_ADD_FLAG_NORPFIX = 0x00000200
Global Const $WIMLIB_ADD_FLAG_NTFS = 0x00000001
Global Const $WIMLIB_ADD_FLAG_RPFIX = 0x00000100
Global Const $WIMLIB_ADD_FLAG_SNAPSHOT = 0x00008000
Global Const $WIMLIB_ADD_FLAG_STRICT_ACLS = 0x00000040
Global Const $WIMLIB_ADD_FLAG_TEST_FILE_EXCLUSION = 0x00004000
Global Const $WIMLIB_ADD_FLAG_UNIX_DATA = 0x00000010
Global Const $WIMLIB_ADD_FLAG_VERBOSE = 0x00000004
Global Const $WIMLIB_ADD_FLAG_WIMBOOT = 0x00001000
Global Const $WIMLIB_ADD_FLAG_WINCONFIG = 0x00000800
Global Const $WIMLIB_ALL_IMAGES = -1
Global Const $WIMLIB_CHANGE_BOOT_INDEX = 0x00000004
Global Const $WIMLIB_CHANGE_GUID = 0x00000002
Global Const $WIMLIB_CHANGE_READONLY_FLAG = 0x00000001
Global Const $WIMLIB_CHANGE_RPFIX_FLAG = 0x00000008
Global Const $WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE = 0x80000000
Global Const $WIMLIB_DELETE_FLAG_FORCE = 0x00000001
Global Const $WIMLIB_DELETE_FLAG_RECURSIVE = 0x00000002
Global Const $WIMLIB_EXPORT_FLAG_BOOT = 0x00000001
Global Const $WIMLIB_EXPORT_FLAG_GIFT = 0x00000008
Global Const $WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS = 0x00000004
Global Const $WIMLIB_EXPORT_FLAG_NO_NAMES = 0x00000002
Global Const $WIMLIB_EXPORT_FLAG_WIMBOOT = 0x00000010
Global Const $WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS = 0x00001000
Global Const $WIMLIB_EXTRACT_FLAG_COMPACT_LZX = 0x08000000
Global Const $WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K = 0x04000000
Global Const $WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K = 0x01000000
Global Const $WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K = 0x02000000
Global Const $WIMLIB_EXTRACT_FLAG_GLOB_PATHS = 0x00040000
Global Const $WIMLIB_EXTRACT_FLAG_NO_ACLS = 0x00000040
Global Const $WIMLIB_EXTRACT_FLAG_NO_ATTRIBUTES = 0x00100000
Global Const $WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE = 0x00200000
Global Const $WIMLIB_EXTRACT_FLAG_NORPFIX = 0x00000200
Global Const $WIMLIB_EXTRACT_FLAG_NTFS = 0x00000001
Global Const $WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES = 0x00000800
Global Const $WIMLIB_EXTRACT_FLAG_RPFIX = 0x00000100
Global Const $WIMLIB_EXTRACT_FLAG_STRICT_ACLS = 0x00000080
Global Const $WIMLIB_EXTRACT_FLAG_STRICT_GLOB = 0x00080000
Global Const $WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES = 0x00004000
Global Const $WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS = 0x00008000
Global Const $WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS = 0x00002000
Global Const $WIMLIB_EXTRACT_FLAG_TO_STDOUT = 0x00000400
Global Const $WIMLIB_EXTRACT_FLAG_UNIX_DATA = 0x00000020
Global Const $WIMLIB_EXTRACT_FLAG_WIMBOOT = 0x00400000
Global Const $WIMLIB_FILE_ATTRIBUTE_ARCHIVE = 0x00000020
Global Const $WIMLIB_FILE_ATTRIBUTE_COMPRESSED = 0x00000800
Global Const $WIMLIB_FILE_ATTRIBUTE_DEVICE = 0x00000040
Global Const $WIMLIB_FILE_ATTRIBUTE_DIRECTORY = 0x00000010
Global Const $WIMLIB_FILE_ATTRIBUTE_ENCRYPTED = 0x00004000
Global Const $WIMLIB_FILE_ATTRIBUTE_HIDDEN = 0x00000002
Global Const $WIMLIB_FILE_ATTRIBUTE_NORMAL = 0x00000080
Global Const $WIMLIB_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000
Global Const $WIMLIB_FILE_ATTRIBUTE_OFFLINE = 0x00001000
Global Const $WIMLIB_FILE_ATTRIBUTE_READONLY = 0x00000001
Global Const $WIMLIB_FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
Global Const $WIMLIB_FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200
Global Const $WIMLIB_FILE_ATTRIBUTE_SYSTEM = 0x00000004
Global Const $WIMLIB_FILE_ATTRIBUTE_TEMPORARY = 0x00000100
Global Const $WIMLIB_FILE_ATTRIBUTE_VIRTUAL = 0x00010000
Global Const $WIMLIB_GUID_LEN = 16
Global Const $WIMLIB_INIT_FLAG_ASSUME_UTF8 = 0x00000001
Global Const $WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE = 0x00000020
Global Const $WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE = 0x00000010
Global Const $WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES = 0x00000002
Global Const $WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES = 0x00000008
Global Const $WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES = 0x00000004
;Global Const $WIMLIB_IS_WIM_ROOT_PATH
Global Const $WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN = 0x00000002
Global Const $WIMLIB_ITERATE_DIR_TREE_FLAG_RECURSIVE = 0x00000001
Global Const $WIMLIB_ITERATE_DIR_TREE_FLAG_RESOURCES_NEEDED = 0x00000004
Global Const $WIMLIB_MAJOR_VERSION = 1
Global Const $WIMLIB_MINOR_VERSION = 2
Global Const $WIMLIB_MOUNT_FLAG_ALLOW_OTHER = 0x00000040
Global Const $WIMLIB_MOUNT_FLAG_DEBUG = 0x00000002
Global Const $WIMLIB_MOUNT_FLAG_READWRITE = 0x00000001
Global Const $WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE = 0x00000004
Global Const $WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS = 0x00000010
Global Const $WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR = 0x00000008
Global Const $WIMLIB_MOUNT_FLAG_UNIX_DATA = 0x00000020
Global Const $WIMLIB_NO_IMAGE = 0
Global Const $WIMLIB_OPEN_FLAG_CHECK_INTEGRITY = 0x00000001
Global Const $WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT = 0x00000002
Global Const $WIMLIB_OPEN_FLAG_WRITE_ACCESS = 0x00000004
Global Const $WIMLIB_PATCH_VERSION = 5
Global Const $WIMLIB_REF_FLAG_GLOB_ENABLE = 0x00000001
Global Const $WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH = 0x00000002
Global Const $WIMLIB_REPARSE_TAG_DFS = 0x8000000A
Global Const $WIMLIB_REPARSE_TAG_DFSR = 0x80000012
Global Const $WIMLIB_REPARSE_TAG_DRIVER_EXTENDER = 0x80000005
Global Const $WIMLIB_REPARSE_TAG_FILTER_MANAGER = 0x8000000B
Global Const $WIMLIB_REPARSE_TAG_HSM = 0xC0000004
Global Const $WIMLIB_REPARSE_TAG_HSM2 = 0x80000006
Global Const $WIMLIB_REPARSE_TAG_MOUNT_POINT = 0xA0000003
Global Const $WIMLIB_REPARSE_TAG_RESERVED_ONE = 0x00000001
Global Const $WIMLIB_REPARSE_TAG_RESERVED_ZERO = 0x00000000
Global Const $WIMLIB_REPARSE_TAG_SIS = 0x80000007
Global Const $WIMLIB_REPARSE_TAG_SYMLINK = 0xA000000C
Global Const $WIMLIB_REPARSE_TAG_WOF = 0x80000017
Global Const $WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY = 0x00000001
Global Const $WIMLIB_UNMOUNT_FLAG_COMMIT = 0x00000002
Global Const $WIMLIB_UNMOUNT_FLAG_FORCE = 0x00000010
Global Const $WIMLIB_UNMOUNT_FLAG_NEW_IMAGE = 0x00000020
Global Const $WIMLIB_UNMOUNT_FLAG_REBUILD = 0x00000004
Global Const $WIMLIB_UNMOUNT_FLAG_RECOMPRESS = 0x00000008
Global Const $WIMLIB_UPDATE_FLAG_SEND_PROGRESS = 0x00000001
Global Const $WIMLIB_WIM_PATH_SEPARATOR = "\"
Global Const $WIMLIB_WIM_PATH_SEPARATOR_STRING = "\"
Global Const $WIMLIB_WIM_ROOT_PATH = $WIMLIB_WIM_PATH_SEPARATOR_STRING
Global Const $WIMLIB_WRITE_FLAG_CHECK_INTEGRITY = 0x00000001
Global Const $WIMLIB_WRITE_FLAG_FSYNC = 0x00000020
Global Const $WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG = 0x00000100
Global Const $WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY = 0x00000002
Global Const $WIMLIB_WRITE_FLAG_NO_SOLID_SORT = 0x00004000
Global Const $WIMLIB_WRITE_FLAG_NOT_PIPABLE = 0x00000008
Global Const $WIMLIB_WRITE_FLAG_PIPABLE = 0x00000004
Global Const $WIMLIB_WRITE_FLAG_REBUILD = 0x00000040
Global Const $WIMLIB_WRITE_FLAG_RECOMPRESS = 0x00000010
Global Const $WIMLIB_WRITE_FLAG_RETAIN_GUID = 0x00000800
Global Const $WIMLIB_WRITE_FLAG_SEND_DONE_WITH_FILE_MESSAGES = 0x00002000
Global Const $WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS = 0x00000200
Global Const $WIMLIB_WRITE_FLAG_SOFT_DELETE = 0x00000080
Global Const $WIMLIB_WRITE_FLAG_SOLID = 0x00001000
Global Const $WIMLIB_WRITE_FLAG_STREAMS_OK = 0x00000400
Global Const $WIMLIB_WRITE_FLAG_UNSAFE_COMPACT = 0x00008000



Global Const $tagwimlib_wim_info = "byte guid[" & $WIMLIB_GUID_LEN & "];dword image_count;dword boot_index;dword wim_version;dword chunk_size;word part_number;word total_parts;int compression_type;UINT64 total_bytes;DWORD has_integrity_table;DWORD opened_from_file;DWORD is_readonly;DWORD has_rpfix;DWORD is_marked_readonly;DWORD spanned;DWORD write_in_progress;DWORD metadata_only;DWORD resource_only;DWORD pipable;DWORD reserved_flags;DWORD reserved[9]"

Global Const $tagwimlib_progress_info_write_streams = "UINT64 total_bytes;UINT64 total_streams;UINT64 completed_bytes;UINT64 completed_streams;UINT num_threads;UINT compression_type;UINT total_parts;UINT completed_parts"
Global Const $tagwimlib_progress_info_scan = "wstr ;wstr "
Global Const $tagwimlib_progress_info_done_with_file = "wstr path_to_file"
Global Const $tagwimlib_progress_info_integrity = "UINT64 total_bytes;UINT64 completed_bytes;dword total_chunks;dword completed_chunks;dword chunk_size;wstr filename"
Global Const $tagwimlib_progress_info_verify_image = "wstr wimfile;UINT total_images;UINT current_image"

 

Edited by MattHiggs
Link to comment
Share on other sites

Link to comment
Share on other sites

@LarsJ

Thanks, it works! It blocks elsewhere, but I will try to solve before asking for help.

@MattHiggs

I didn't plan to make an UDF. But I'm tempted... Let's see where it goes.😊

Jonathan

Edited by MadDogVachon

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Hi everyone,

Now, I struggle with wimlib_set_output_pack_chunk_size. Using LZX, this format supports chunk sizes that are powers of 2 between 2^15 and 2^21, inclusively. Default value "0" works, but others not. I made a loop to test a valid value and no result. Can someone help me find the solution?

The code:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#AutoIt3Wrapper_UseX64=Y

Opt( "MustDeclareVars", 1 )

WimLib()

Func WimLib()
    Local $hWimLib = DllOpen( "libwim-15-64.dll" )
    If $hWimLib = -1 Then Exit ConsoleWrite( "ERR: libwin-15-64.dll open" & @CRLF )
    ConsoleWrite( "OK : libwin-15-64.dll open" & @CRLF )

    Local $aRet, $tWIMStruct = DllStructCreate( "ptr" ) ; Pointer storage for WIMStruct pointer
    $aRet = DllCall( $hWimLib, "int:cdecl", "wimlib_create_new_wim", _
                                "int", 2, _              ; ctype
                                "struct*", $tWIMStruct ) ; Store WIMStruct pointer
    If $aRet[0] Or @error Then Return ConsoleWrite( "ERR: wimlib_create_new_wim" & @CRLF & _
                                                  "$aRet[0] = " & $aRet[0] & @CRLF & _
                                                  DllCall($hWimLib, "wstr:cdecl", "wimlib_get_error_string", "int", $aRet[0]) & @CRLF & _
                                                  "@error   = " & @error & @CRLF )
    ConsoleWrite( "OK : wimlib_create_new_wim" & @CRLF )
    Local $pWIMStruct = DllStructGetData( $tWIMStruct, 1 ) ; Get WIMStruct pointer from storage
    ConsoleWrite( "$pWIMStruct = " & $pWIMStruct & @CRLF )

    $aRet = DllCall( $hWimLib, "int:cdecl", "wimlib_add_image", _
                                "ptr", $pWIMStruct, _       ; WIMStruct pointer
                                "wstr", "Z:", _             ; source
                                "wstr", "", _               ; name
                                "wstr", Null, _             ; config_file
                                "int", BitAND(4,800))       ; add_flags
    If $aRet[0] Or @error Then Return ConsoleWrite( "ERR: wimlib_add_image" & @CRLF & _
                                                  "$aRet[0] = " & $aRet[0] & @CRLF & _
                                                  DllCall($hWimLib, "wstr:cdecl", "wimlib_get_error_string", "int", $aRet[0]) & @CRLF & _
                                                  "@error   = " & @error & @CRLF )
    ConsoleWrite( "OK : wimlib_add_image" & @CRLF )

    $aRet = DllCall($hWimLib, "int:cdecl", "wimlib_set_default_compression_level", _
                                "int", 2, _                 ; int ctype
                                "uint", 50)                 ; unsigned int compression_level
    If $aRet[0] Or @error Then Return ConsoleWrite("ERR: wimlib_set_default_compression_level" & @CRLF & "$aRet[0] = " & $aRet[0] & @CRLF & "@error   = " & @error & @CRLF)
    ConsoleWrite("OK: wimlib_set_default_compression_level" & @CRLF)

    $aRet = DllCall($hWimLib, "int:cdecl", "wimlib_set_output_pack_chunk_size", _
                                "struct*", $tWIMStruct, _   ; WIMStruct wim
                                "uint", 0)                  ; uint32_t chunk_size
    If $aRet[0] Or @error Then Return ConsoleWrite("ERR: wimlib_set_output_pack_chunk_size" & @CRLF & "$aRet[0] = " & $aRet[0] & @CRLF & "@error   = " & @error & @CRLF)
    ConsoleWrite("OK: wimlib_set_output_pack_chunk_size" & @CRLF)


    For $ii = 2^0 To 2^22
        If Mod($ii, 100000) = 0 Then ToolTip($ii)
        $aRet = DllCall($hWimLib, "int:cdecl", "wimlib_set_output_pack_chunk_size", _
                                    "struct*", $tWIMStruct, _   ; WIMStruct wim
                                    "uint", $ii)                ; uint32_t chunk_size
        If not ($aRet[0] Or @error) Then ConsoleWrite("OK: " & $ii & " wimlib_set_output_pack_chunk_size" & @CRLF)
    Next


    $hWimLib = 0
EndFunc

Thanks!

Jonathan

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Hi everyone,

I began to write WimLibUDF.au3. It's still alpha version and very much incompleted.

I'm currently working with progress status (the reason why I want to use wimlib-15???.dll instead of wimlib-imagex.exe). Here's what I could write based on Homes UDF:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#AutoIt3Wrapper_UseX64=Y

Opt( "MustDeclareVars", 1 )

Global $sSourceFolder = "Z:"
Global $sWimFile = "D:\WinRE in work!\WimLib\WimLib Test 2022.WimLib"

Global $hWimLib = DllOpen( "libwim-15-64.dll" )
If $hWimLib = -1 Then Exit ConsoleWrite( "ERR: libwin-15-64.dll open" & @CRLF )
ConsoleWrite( "OK : libwin-15-64.dll open" & @CRLF )

WimLib()

Func WimLib()
    Local $aRet, $tWIMStruct = DllStructCreate( "ptr" ) ; Pointer storage for WIMStruct pointer
    $aRet = DllCall( $hWimLib, "int:cdecl", "wimlib_create_new_wim", _
                                "int", 2, _              ; ctype
                                "struct*", $tWIMStruct ) ; Store WIMStruct pointer
    If $aRet[0] Then Return ConsoleWrite("ERR: wimlib_create_new_wim" & @CRLF & "$aRet[0] = " & $aRet[0] & ": " & _WimLib_ErrorMessage($aRet[0]) & @CRLF)
    ConsoleWrite( "OK : wimlib_create_new_wim" & @CRLF )
    Local $pWIMStruct = DllStructGetData( $tWIMStruct, 1 ) ; Get WIMStruct pointer from storage
    ConsoleWrite( "$pWIMStruct = " & $pWIMStruct & @CRLF )

    ProgressOn("Capturing", "Capture of """ & $sSourceFolder & """", "Starting...", -1, -1, 16)

    Local $pCallBack = DllCallbackRegister('_WimLib_CallBack', 'none:cdecl', 'dword;WPARAM;LPARAM;dword')
    $aRet = DllCall($hWimLib, "none", "wimlib_register_progress_function", _
                                "ptr", $pWIMStruct, _                   ; WIMStruct wim
                                "ptr", DllCallbackGetPtr($pCallBack), _ ; wimlib_progress_func_t progfunc
                                "none", Null)                           ; void progctx
    If $aRet[0] Then Return ConsoleWrite("ERR: wimlib_register_progress_function" & @CRLF & "$aRet[0] = " & $aRet[0] & ": " & _WimLib_ErrorMessage($aRet[0]) & @CRLF)
    ConsoleWrite("OK: wimlib_register_progress_function" & @CRLF)

    $aRet = DllCall( $hWimLib, "int:cdecl", "wimlib_add_image", _
                                "ptr", $pWIMStruct, _       ; WIMStruct pointer
                                "wstr", $sSourceFolder, _   ; source
                                "wstr", "", _               ; name
                                "wstr", Null, _             ; config_file
                                "int", BitAND(4,800))       ; add_flags     $WIMLIB_ADD_FLAG_VERBOSE = 4, $WIMLIB_ADD_FLAG_WINCONFIG = 800
    If $aRet[0] Then Return ConsoleWrite( "ERR: wimlib_add_image" & @CRLF & _
                                                  "$aRet[0] = " & $aRet[0] & ": " & _WimLib_ErrorMessage($aRet[0]) & @CRLF & _
                                                  DllCall($hWimLib, "wstr:cdecl", "wimlib_get_error_string", "int", $aRet[0]) & @CRLF & _
                                                  "@error   = " & @error & @CRLF )
    ConsoleWrite( "OK : wimlib_add_image" & @CRLF )

    $aRet = DllCall($hWimLib, "int:cdecl", "wimlib_set_default_compression_level", _
                                "int", 2, _                 ; int ctype
                                "uint", 50)                 ; unsigned int compression_level
    If $aRet[0] Then Return ConsoleWrite("ERR: wimlib_set_default_compression_level" & @CRLF & "$aRet[0] = " & $aRet[0] & ": " & _WimLib_ErrorMessage($aRet[0]) & @CRLF)
    ConsoleWrite("OK: wimlib_set_default_compression_level" & @CRLF)


    $aRet = DllCall($hWimLib, "int:cdecl", "wimlib_set_output_chunk_size", _
                                "ptr", $pWIMStruct, _           ; WIMStruct wim
                                "uint", 2^15)                   ; uint32_t chunk_size
    If $aRet[0] Then Return ConsoleWrite("ERR: wimlib_set_output_chunk_size" & @CRLF & "$aRet[0] = " & $aRet[0] & ": " & _WimLib_ErrorMessage($aRet[0]) & @CRLF)
    ConsoleWrite("OK: wimlib_set_output_chunk_size" & @CRLF)

    If FileExists($sWimFile) Then FileDelete($sWimFile)
    $aRet = DllCall($hWimLib, "int:cdecl", "wimlib_write", _
                                "ptr", $pWIMStruct, _           ; WIMStruct wim
                                "wstr", $sWimFile, _            ; const wimlib_tchar path
                                "int", 1, _                     ; int image
                                "int", 0, _                     ; int write_flags
                                "uint", 0)                      ; unsigned num_threads
    If $aRet[0] Then Return ConsoleWrite("ERR: wimlib_write" & @CRLF & "$aRet[0] = " & $aRet[0] & ": " & _WimLib_ErrorMessage($aRet[0]) & @CRLF)
    ConsoleWrite("OK: wimlib_write" & @CRLF)

    $aRet = DllCall($hWimLib, "none:cdecl", "wimlib_free", _
            "ptr", $pWIMStruct)                             ; WIMStruct wim
    If $aRet[0] Then Return ConsoleWrite("ERR: wimlib_free" & @CRLF &  "$aRet[0] = " & $aRet[0] & ": " & _WimLib_ErrorMessage($aRet[0]) & @CRLF)
    ConsoleWrite("OK: wimlib_free" & @CRLF)

    $hWimLib = 0
    Return ConsoleWrite("Done!" & @CRLF)

;~     ProgressOff()
EndFunc

Func _WimLib_ErrorMessage($iValue)
    Local $a_WimLib_ErrorMessage = DllCall($hWimLib, "wstr:cdecl", "wimlib_get_error_string", "int", $iValue)
    Return $iValue & ": " & $a_WimLib_ErrorMessage[0]
EndFunc

Func _WimLib_CallBack($msgId, $param1, $param2, $unused)
    Local $Percent, $rTime, $filePath
    Switch $msgId

        ; wimlib_add_image
        Case 9 ; $WIMLIB_PROGRESS_MSG_SCAN_BEGIN = 9
            ProgressSet(0, "Listing files """ & $sWimFile & """", "Starting")
        Case 11 ; $WIMLIB_PROGRESS_MSG_SCAN_END = 11
            ProgressSet(0, "Listing files """ & $sWimFile & """", "Done")
        Case 10 ; $WIMLIB_PROGRESS_MSG_SCAN_DENTRY = 10
            ; ???

        ; wimlib_write
        Case 12 ; $WIMLIB_PROGRESS_MSG_WRITE_STREAMS = 12
            ; ???
            $Percent = $param1

            If $param2 = 0 Then
                $rTime = ""
            Else
                $rTime = StringFormat('Remaining: %i sec.', $param2 / 1000)
            EndIf

            ProgressSet($Percent, StringFormat('%3i%% completed.      %snn   %s', $Percent, $rTime, $filePath), 'Capture ' & $sWimFile)
        Case 13 ; $WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN = 13
            ProgressSet(0, "Capturing """ & $sWimFile & """", "Starting")
        Case 14 ; $WIMLIB_PROGRESS_MSG_WRITE_METADATA_END = 14
            ProgressSet(0, "Capturing """ & $sWimFile & """", "Done")

    EndSwitch

    Return 0
EndFunc   ;==>_WimLib_CallBack

Can anyone complete/correct my code? Thanks!

Jonathan

Edited by MadDogVachon
Few corrections to code...

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Hi everyone,

I managed to complete only the capture part of the UDF (easy part) and improve the progress. I went further in the code for the progress display. However, I don't know how to go further and successfully view the information when adding files.

So, Here my Alfa UDF. It currently only has capturing and verifying capabilities:

#RequireAdmin
#include-once
#include <WinAPI.au3>
 #include <array.au3>
Opt( "MustDeclareVars", 1 )

; #INDEX# =======================================================================================================================
; Title .........: Wimgapi vBeta (99/99/2022)
; AutoIt Version : 3.3.14.5
; Description ...: Functions for creating and manipulating WIM images.
; Author(s) .....: Jonathan Larochelle (MadDogVachon)
; Dll ...........: libwim-15.dll, libwim-15-64.dll
; ===============================================================================================================================

; #VARIABLES# ===================================================================================================================
Global $sWimLibDLL
If FileExists(@SystemDir & "\libwim-15-64.dll") Then    ; path to libwim-15*.dll
    $sWimLibDLL = @SystemDir & "\libwim-15-64.dll"
ElseIf FileExists(@SystemDir & "\libwim-15.dll") Then
    $sWimLibDLL = @SystemDir & "\libwim-15.dll"
ElseIf FileExists("libwim-15-64.dll") Then
    $sWimLibDLL = "libwim-15-64.dll"
Else
    $sWimLibDLL = "libwim-15.dll"
EndIf
Global $hWimLibDLL = 0 ; initialized by _WimLib_Startup() and contains the handle to DllOpen($sWimLibDLL)
Global $iWIMLibRef = 0 ; reference var. Value is >= 1 if $sWimLibDLL is loaded.
Global $bProgressBar = True ; Show or not progress bar when possible
; ===============================================================================================================================

; #CONSTANTS# ===================================================================================================================
; WimLib_compression_type
Global Enum $WIMLIB_COMPRESSION_TYPE_NONE, $WIMLIB_COMPRESSION_TYPE_XPRESS, $WIMLIB_COMPRESSION_TYPE_LZX, $WIMLIB_COMPRESSION_TYPE_LZMS
; WimLib_progress_msg
Global Enum $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN, $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN, $WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE = 3, $WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS, $WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN, _
        $WIMLIB_PROGRESS_MSG_EXTRACT_METADATA, $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END, $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_END, $WIMLIB_PROGRESS_MSG_SCAN_BEGIN, $WIMLIB_PROGRESS_MSG_SCAN_DENTRY, $WIMLIB_PROGRESS_MSG_SCAN_END, _
        $WIMLIB_PROGRESS_MSG_WRITE_STREAMS, $WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN, $WIMLIB_PROGRESS_MSG_WRITE_METADATA_EN, $WIMLIB_PROGRESS_MSG_RENAME, $WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY, $WIMLIB_PROGRESS_MSG_CALC_INTEGRITY, _
        $WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART = 19, $WIMLIB_PROGRESS_MSG_SPLIT_END_PART, $WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND, $WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND, $WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM, _
        $WIMLIB_PROGRESS_MSG_WIMBOOT_EXCLUDE, $WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN, $WIMLIB_PROGRESS_MSG_DONE_WITH_FILE, $WIMLIB_PROGRESS_MSG_BEGIN_VERIFY_IMAGE, $WIMLIB_PROGRESS_MSG_END_VERIFY_IMAGE, $WIMLIB_PROGRESS_MSG_VERIFY_STREAMS, _
        $WIMLIB_PROGRESS_MSG_TEST_FILE_EXCLUSION, $WIMLIB_PROGRESS_MSG_HANDLE_ERROR
; WimLib_progress_status
Global Enum $WIMLIB_PROGRESS_STATUS_CONTINUE, $WIMLIB_PROGRESS_STATUS_ABORT
; WimLib_update_op
Global Const $WIMLIB_UPDATE_OP_ADD = 0
; WimLib_error_code
Global Enum $WIMLIB_ERR_SUCCESS, $WIMLIB_ERR_ALREADY_LOCKED, $WIMLIB_ERR_DECOMPRESSION, $WIMLIB_ERR_FUSE = 6, $WIMLIB_ERR_GLOB_HAD_NO_MATCHES = 8, $WIMLIB_ERR_ICONV_NOT_AVAILABLE, $WIMLIB_ERR_IMAGE_COUNT, $WIMLIB_ERR_IMAGE_NAME_COLLISION, _
        $WIMLIB_ERR_INSUFFICIENT_PRIVILEGES, $WIMLIB_ERR_INTEGRITY, $WIMLIB_ERR_INVALID_CAPTURE_CONFIG, $WIMLIB_ERR_INVALID_CHUNK_SIZE, $WIMLIB_ERR_INVALID_COMPRESSION_TYPE, $WIMLIB_ERR_INVALID_HEADER, $WIMLIB_ERR_INVALID_IMAGE, _
        $WIMLIB_ERR_INVALID_INTEGRITY_TABLE, $WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY, $WIMLIB_ERR_INVALID_METADATA_RESOURCE, $WIMLIB_ERR_INVALID_MULTIBYTE_STRING, $WIMLIB_ERR_INVALID_OVERLAY, $WIMLIB_ERR_INVALID_PARAM, _
        $WIMLIB_ERR_INVALID_PART_NUMBER, $WIMLIB_ERR_INVALID_PIPABLE_WIM, $WIMLIB_ERR_INVALID_REPARSE_DATA, $WIMLIB_ERR_INVALID_RESOURCE_HASH, $WIMLIB_ERR_INVALID_UTF16_STRING = 30, $WIMLIB_ERR_INVALID_UTF8_STRING, $WIMLIB_ERR_IS_DIRECTORY, _
        $WIMLIB_ERR_IS_SPLIT_WIM, $WIMLIB_ERR_LIBXML_UTF16_HANDLER_NOT_AVAILABLE, $WIMLIB_ERR_LINK, $WIMLIB_ERR_METADATA_NOT_FOUND, $WIMLIB_ERR_MKDIR, $WIMLIB_ERR_MQUEUE, $WIMLIB_ERR_NOMEM, $WIMLIB_ERR_NOTDIR, $WIMLIB_ERR_NOTEMPTY, _
        $WIMLIB_ERR_NOT_A_REGULAR_FILE, $WIMLIB_ERR_NOT_A_WIM_FILE, $WIMLIB_ERR_NOT_PIPABLE, $WIMLIB_ERR_NO_FILENAME, $WIMLIB_ERR_NTFS_3G, $WIMLIB_ERR_OPEN, $WIMLIB_ERR_OPENDIR, $WIMLIB_ERR_PATH_DOES_NOT_EXIST, $WIMLIB_ERR_READ, _
        $WIMLIB_ERR_READLINK, $WIMLIB_ERR_RENAME, $WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED = 54, $WIMLIB_ERR_RESOURCE_NOT_FOUND, $WIMLIB_ERR_RESOURCE_ORDER, $WIMLIB_ERR_SET_ATTRIBUTES, $WIMLIB_ERR_SET_REPARSE_DATA, $WIMLIB_ERR_SET_SECURITY, _
        $WIMLIB_ERR_SET_SHORT_NAME, $WIMLIB_ERR_SET_TIMESTAMPS, $WIMLIB_ERR_SPLIT_INVALID, $WIMLIB_ERR_STAT, $WIMLIB_ERR_UNEXPECTED_END_OF_FILE = 65, $WIMLIB_ERR_UNICODE_STRING_NOT_REPRESENTABLE, $WIMLIB_ERR_UNKNOWN_VERSION, $WIMLIB_ERR_UNSUPPORTED, _
        $WIMLIB_ERR_UNSUPPORTED_FILE, $WIMLIB_ERR_WIM_IS_READONLY = 71, $WIMLIB_ERR_WRITE, $WIMLIB_ERR_XML, $WIMLIB_ERR_WIM_IS_ENCRYPTED, $WIMLIB_ERR_WIMBOOT, $WIMLIB_ERR_ABORTED_BY_PROGRESS, $WIMLIB_ERR_UNKNOWN_PROGRESS_STATUS, _
        $WIMLIB_ERR_MKNOD, $WIMLIB_ERR_MOUNTED_IMAGE_IS_BUSY, $WIMLIB_ERR_NOT_A_MOUNTPOINT, $WIMLIB_ERR_NOT_PERMITTED_TO_UNMOUNT, $WIMLIB_ERR_FVE_LOCKED_VOLUME, $WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG, $WIMLIB_ERR_WIM_IS_INCOMPLETE, _
        $WIMLIB_ERR_COMPACTION_NOT_POSSIBLE, $WIMLIB_ERR_IMAGE_HAS_MULTIPLE_REFERENCES, $WIMLIB_ERR_DUPLICATE_EXPORTED_IMAGE, $WIMLIB_ERR_CONCURRENT_MODIFICATION_DETECTED, $WIMLIB_ERR_SNAPSHOT_FAILURE, $WIMLIB_ERR_INVALID_XATTR, $WIMLIB_ERR_SET_XATTR
; WimLib_CHANGE
Global Const $WIMLIB_CHANGE_READONLY_FLAG                       = 0x00000001
Global Const $WIMLIB_CHANGE_GUID                                = 0x00000002
Global Const $WIMLIB_CHANGE_BOOT_INDEX                          = 0x00000004
Global Const $WIMLIB_CHANGE_RPFIX_FLAG                          = 0x00000008
; WimLib_ADD_FLAG
Global Const $WIMLIB_ADD_FLAG_NTFS                              = 0x00000001
Global Const $WIMLIB_ADD_FLAG_DEREFERENCE                       = 0x00000002
Global Const $WIMLIB_ADD_FLAG_VERBOSE                           = 0x00000004
Global Const $WIMLIB_ADD_FLAG_BOOT                              = 0x00000008
Global Const $WIMLIB_ADD_FLAG_UNIX_DATA                         = 0x00000010
Global Const $WIMLIB_ADD_FLAG_NO_ACLS                           = 0x00000040
Global Const $WIMLIB_ADD_FLAG_EXCLUDE_VERBOSE                   = 0x00000080
Global Const $WIMLIB_ADD_FLAG_RPFIX                             = 0x00000100
Global Const $WIMLIB_ADD_FLAG_NORPFIX                           = 0x00000200
Global Const $WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE            = 0x00000400
Global Const $WIMLIB_ADD_FLAG_WINCONFIG                         = 0x00000800
Global Const $WIMLIB_ADD_FLAG_WIMBOOT                           = 0x00001000
Global Const $WIMLIB_ADD_FLAG_NO_REPLACE                        = 0x00002000
Global Const $WIMLIB_ADD_FLAG_TEST_FILE_EXCLUSION               = 0x00004000
Global Const $WIMLIB_ADD_FLAG_SNAPSHOT                          = 0x00008000
Global Const $WIMLIB_ADD_FLAG_FILE_PATHS_UNNEEDED               = 0x00010000
; WimLib_WRITE_FLAG
Global Const $WIMLIB_WRITE_FLAG_CHECK_INTEGRITY                 = 0x00000001
Global Const $WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY              = 0x00000002
Global Const $WIMLIB_WRITE_FLAG_PIPABLE                         = 0x00000004
Global Const $WIMLIB_WRITE_FLAG_NOT_PIPABLE                     = 0x00000008
Global Const $WIMLIB_WRITE_FLAG_RECOMPRESS                      = 0x00000010
Global Const $WIMLIB_WRITE_FLAG_FSYNC                           = 0x00000020
Global Const $WIMLIB_WRITE_FLAG_REBUILD                         = 0x00000040
Global Const $WIMLIB_WRITE_FLAG_SOFT_DELETE                     = 0x00000080
Global Const $WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG            = 0x00000100
Global Const $WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIM               = 0x00000200
Global Const $WIMLIB_WRITE_FLAG_STREAMS_OK                      = 0x00000400
Global Const $WIMLIB_WRITE_FLAG_RETAIN_GUID                     = 0x00000800
Global Const $WIMLIB_WRITE_FLAG_SOLID                           = 0x00001000
Global Const $WIMLIB_WRITE_FLAG_SEND_DONE_WITH_FILE_MESSAGES    = 0x00002000
Global Const $WIMLIB_WRITE_FLAG_NO_SOLID_SORT                   = 0x00004000
Global Const $WIMLIB_WRITE_FLAG_UNSAFE_COMPACT                  = 0x00008000
; WimLib_DELETE_FLAG
Global Const $WIMLIB_DELETE_FLAG_FORCE                          = 0x00000001
Global Const $WIMLIB_DELETE_FLAG_RECURSIVE                      = 0x00000002
; WimLib_EXPORT_FLAG
Global Const $WIMLIB_EXPORT_FLAG_BOOT                           = 0x00000001
Global Const $WIMLIB_EXPORT_FLAG_NO_NAMES                       = 0x00000002
Global Const $WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS                = 0x00000004
Global Const $WIMLIB_EXPORT_FLAG_GIFT                           = 0x00000008
Global Const $WIMLIB_EXPORT_FLAG_WIMBOOT                        = 0x00000010
; WimLib_UPDATE_FLAG_SEND_PROGRESS
Global Const $WIMLIB_UPDATE_FLAG_SEND_PROGRESS                  = 0x00000001
; WimLib_Mount_FLAG
Global Const $WIMLIB_MOUNT_FLAG_READWRITE                       = 0x00000001
Global Const $WIMLIB_MOUNT_FLAG_DEBUG                           = 0x00000002
Global Const $WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE           = 0x00000004
Global Const $WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR          = 0x00000008
Global Const $WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS        = 0x00000010
Global Const $WIMLIB_MOUNT_FLAG_UNIX_DATA                       = 0x00000020
Global Const $WIMLIB_MOUNT_FLAG_ALLOW_OTHER                     = 0x00000040
; WimLib_Unmount_FLAG
Global Const $WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY               = 0x00000001
Global Const $WIMLIB_UNMOUNT_FLAG_COMMIT                        = 0x00000002
Global Const $WIMLIB_UNMOUNT_FLAG_REBUILD                       = 0x00000004
Global Const $WIMLIB_UNMOUNT_FLAG_RECOMPRESS                    = 0x00000008
Global Const $WIMLIB_UNMOUNT_FLAG_FORCE                         = 0x00000010
Global Const $WIMLIB_UNMOUNT_FLAG_NEW_IMAGE                     = 0x00000020
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Description ...: Applies an image to a directory path from a Windows image (.wim) file.
; ===============================================================================================================================
Func _WimLib_AddImage(ByRef $pWIMStruct, $sSourceFolder, $sName = "", $sConfigIni = Null, $iAddFlag = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    If $sConfigIni = "" Then $sConfigIni = Null
    Local $aResult, $hCallBack

    If $bProgressBar = True Then
        $iAddFlag = BitAND($iAddFlag, $WIMLIB_ADD_FLAG_VERBOSE)

        $hCallBack = DllCallbackRegister("_WimLib_ProgressFunc_t", 'none:cdecl', 'int;wstr;wstr;uint;uint;uint')
        $aResult = DllCall($hWimLibDLL, "none:cdecl", "wimlib_register_progress_function", "ptr", $pWIMStruct, "ptr", DllCallbackGetPtr($hCallBack), "none", Null)
        Return SetError(@error, $aResult[0], "wimlib_register_progress_function")

;~      ProgressOn("Capturing", "Capture of """ & $sSourceFolder & """", "Starting...", -1, -1, 16)
    EndIf
    If $sConfigIni = Null Then $iAddFlag = BitAND($iAddFlag, $WIMLIB_ADD_FLAG_WINCONFIG)

    $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_add_image", "ptr", $pWIMStruct, "wstr", $sSourceFolder, "wstr", $sName, "wstr", $sConfigIni, "int", $iAddFlag)
    If $bProgressBar = True Then
        DllCallbackFree($hCallBack)
;~      ProgressOff()
    EndIf

    Return SetError(@error, $aResult[0], "wimlib_add_image")
EndFunc   ;==>_WimLib_AddImage

; #FUNCTION# ====================================================================================================================
; Description ...: Callback to show progres messages while processing Wim.
; ===============================================================================================================================
Func _WimLib_ProgressFunc_t($msgId, $param1 = 0, $param2 = 0, $param3 = 0, $param4 = 0, $param5 = 0, $param6 = 0, $param7 = 0, $param8 = 0, $param9 = 0, $param10 = 0, $param11 = 0, $param12 = 0, $param13 = 0, $param14 = 0, $param15 = 0, $param16 = 0)

    Switch $msgId

        Case $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN
        Case $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN
        Case $WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE
        Case $WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS
        Case $WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN
        Case $WIMLIB_PROGRESS_MSG_EXTRACT_METADATA
        Case $WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END
        Case $WIMLIB_PROGRESS_MSG_EXTRACT_TREE_END

#cs
    /** Valid on messages ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
     * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY, and
     * ::WIMLIB_PROGRESS_MSG_SCAN_END.  */
    struct wimlib_progress_info_scan {

        const wimlib_tchar *source;
        const wimlib_tchar *cur_path;

        /** Dentry scan status, valid on
         * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY.  */
        enum {
            WIMLIB_SCAN_DENTRY_OK = 0,
            WIMLIB_SCAN_DENTRY_EXCLUDED = 1,
            WIMLIB_SCAN_DENTRY_UNSUPPORTED = 2,
            WIMLIB_SCAN_DENTRY_FIXED_SYMLINK = 3,
            WIMLIB_SCAN_DENTRY_NOT_FIXED_SYMLINK = 4,
        } status;

        union {
            /** Target path in the image.  Only valid on messages
             * ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN and
             * ::WIMLIB_PROGRESS_MSG_SCAN_END.  */
            const wimlib_tchar *wim_target_path;

            /** For ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY and a status
             * of @p WIMLIB_SCAN_DENTRY_FIXED_SYMLINK or @p
             * WIMLIB_SCAN_DENTRY_NOT_FIXED_SYMLINK, this is the
             * target of the absolute symbolic link or junction.  */
            const wimlib_tchar *symlink_target;
        };

        uint64_t num_dirs_scanned;

        uint64_t num_nondirs_scanned;

        uint64_t num_bytes_scanned;
    } scan;
#ce
        ;wimlib_add_image
        Case $WIMLIB_PROGRESS_MSG_SCAN_BEGIN
;~          ProgressSet(0, "Listing files """ & $sWimFile & """", "Starting")

        Case $WIMLIB_PROGRESS_MSG_SCAN_DENTRY
            ; ???
            SplashTextOn("wimlib_add_image", "$msgId: " & $msgId & @CRLF _
                    & "$param1: " & $param1 & @CRLF _
                    & "$param2: " & $param2 & @CRLF _
                    & "$param3: " & $param3 & @CRLF _
                    & "$param4: " & $param4 & @CRLF _
                    & "$param5: " & $param5 & @CRLF _
                    & "$param6: " & $param6 & @CRLF _
                    & "$param7: " & $param7 & @CRLF _
                    & "$param8: " & $param8 & @CRLF _
                    & "$param9: " & $param9 & @CRLF _
                    & "$param10: " & $param10 & @CRLF _
                    & "$param11: " & $param11 & @CRLF _
                    & "$param12: " & $param12 & @CRLF _
                    & "$param13: " & $param13 & @CRLF _
                    & "$param14: " & $param14 & @CRLF _
                    & "$param15: " & $param15 & @CRLF _
                    & "$param16: " & $param16)

        Case $WIMLIB_PROGRESS_MSG_SCAN_END
;~          ProgressSet(0, "Listing files """ & $sWimFile & """", "Done")

        Case $WIMLIB_PROGRESS_MSG_WRITE_STREAMS
        Case $WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN
        Case $WIMLIB_PROGRESS_MSG_WRITE_METADATA_EN

        Case $WIMLIB_PROGRESS_MSG_RENAME

        Case $WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY
        Case $WIMLIB_PROGRESS_MSG_CALC_INTEGRITY

        Case $WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART
        Case $WIMLIB_PROGRESS_MSG_SPLIT_END_PART

        Case $WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND
        Case $WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND

        Case $WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM

        Case $WIMLIB_PROGRESS_MSG_WIMBOOT_EXCLUDE

        Case $WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN

        Case $WIMLIB_PROGRESS_MSG_DONE_WITH_FILE

        Case $WIMLIB_PROGRESS_MSG_BEGIN_VERIFY_IMAGE
        Case $WIMLIB_PROGRESS_MSG_END_VERIFY_IMAGE
        Case $WIMLIB_PROGRESS_MSG_VERIFY_STREAMS

        Case $WIMLIB_PROGRESS_MSG_TEST_FILE_EXCLUSION

        Case $WIMLIB_PROGRESS_MSG_HANDLE_ERROR

    EndSwitch

    Return 0
EndFunc   ;==>_WimLib_ProgressFunc_t

; #FUNCTION# ====================================================================================================================
; Description ...: Set a WIMStruct's output compression chunk size.
; Note: XPRESS  This format supports chunk sizes that are powers of 2 between «2^12» and «2^16», inclusively.
;       LZX     This format supports chunk sizes that are powers of 2 between «2^15» and «2^21», inclusively.
;               Chunk sizes other than «2^15» are not compatible with the Microsoft implementation.
;       LZMS    This format supports chunk sizes that are powers of 2 between «2^15» and 2^30», inclusively.  This format is best used for large chunk sizes.
;               LZMS compression is only compatible with wimlib v1.6.0 and later, WIMGAPI Windows 8 and later, and DISM Windows 8.1 and later.
;               Also, chunk sizes larger than «2^26» are not compatible with the Microsoft implementation.
; ===============================================================================================================================
Func _WimLib_ChunkSize(ByRef $pWIMStruct, $iChunk = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_set_output_chunk_size", "ptr", $pWIMStruct, "uint", $iChunk)
    Return SetError(@error, $aResult[0], "wimlib_set_output_chunk_size")
EndFunc   ;==>_WimLib_ChunkSize

; #FUNCTION# ====================================================================================================================
; Description ...: Set a WIMStruct's output compression chunk size, but set the chunk size for writing solid resources.
; ===============================================================================================================================
Func _WimLib_ChunkSizeSolid(ByRef $pWIMStruct, $iChunk = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_set_output_pack_chunk_size", "ptr", $pWIMStruct, "uint", $iChunk)
    Return SetError(@error, $aResult[0], "wimlib_set_output_pack_chunk_size")
EndFunc   ;==>_WimLib_ChunkSizeSolid

; #FUNCTION# ====================================================================================================================
; Description ...: Set the default compression level for the specified compression type.
; ===============================================================================================================================
Func _WimLib_CompressionLevel($iType, $iLevel = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_set_default_compression_level", "int", $iType, "uint", $iLevel)
    Return SetError(@error, $aResult[0], "wimlib_set_default_compression_level")
EndFunc   ;==>_WimLib_CompressionLevel

; #FUNCTION# ====================================================================================================================
; Description ...: Set a WIMStruct's output compression type.
; ===============================================================================================================================
Func _WimLib_CompressionType(ByRef $pWIMStruct, $iType = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_set_output_compression_type", "ptr", $pWIMStruct, "int", $iType)
    Return SetError(@error, $aResult[0], "wimlib_set_output_compression_type")
EndFunc   ;==>_WimLib_CompressionType

; #FUNCTION# ====================================================================================================================
; Description ...: Set a WIMStruct's output compression type, but set the compression type for writing solid resources.
; ===============================================================================================================================
Func _WimLib_CompressionTypeSolid(ByRef $pWIMStruct, $iType = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_set_output_pack_compression_type", "ptr", $pWIMStruct, "int", $iType)
    Return SetError(@error, $aResult[0], "wimlib_set_output_pack_compression_type")
EndFunc   ;==>_WimLib_CompressionTypeSolid

; #FUNCTION# ====================================================================================================================
; Description ...: Convert a wimlib error code into a string describing it.
; ===============================================================================================================================
Func _WimLib_ErrorMessage($iError)
    If $hWimLibDLL = 0 Or $iError = -1 Then Return "-1: DLL not loaded. ""_WimLib_Startup()"" function needed prior."

    Local $a_WimLib_ErrorMessage = DllCall($hWimLibDLL, "wstr:cdecl", "wimlib_get_error_string", "int", $iError)
    Return $iError & ": " & $a_WimLib_ErrorMessage[0]
EndFunc   ;==>_WimLib_ErrorMessage

; #FUNCTION# ====================================================================================================================
; Description ...: Write error to console.
; ===============================================================================================================================
Func _WimLib_ErrorHandling($iError, $iExtended, $sValue)
    If $iError Or $iExtended Then Return ConsoleWrite("ERR: " & $sValue & @CRLF & "$aResult[0] = " & $iExtended & ": " & _WimLib_ErrorMessage($iExtended) & @CRLF & "@error   = " & $iError & @CRLF)
    ConsoleWrite("OK: " & $sValue & @CRLF)
EndFunc   ;==>_WimLib_ErrorMessage

; #FUNCTION# ====================================================================================================================
; Description ...: Closes an open Windows imaging (.wim) file or image handle.
; ===============================================================================================================================
Func _WimLib_Free(ByRef $pWIMStruct)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $aResult = DllCall($hWimLibDLL, "none:cdecl", "wimlib_free", "ptr", $pWIMStruct)
    Return SetError(@error, $aResult[0], "wimlib_free")
EndFunc   ;==>_WimLib_Free

; #FUNCTION# ====================================================================================================================
; Description ...: Unload libwim-15*.dll
; ===============================================================================================================================
Func _WimLib_Shutdown()
    If $hWimLibDLL = 0 Then Return SetError(-1, -1, False) ; handle is already closed.

    $iWIMLibRef -= 1
    If $iWIMLibRef = 0 Then
        Local $aResult = DllCall($hWimLibDLL, "none:cdecl", "wimlib_global_cleanup", "none", Null)
        Return SetError(@error, $aResult[0], "wimlib_global_cleanup")
        DllClose($hWimLibDLL)
        $hWimLibDLL = 0
    EndIf
    Return SetError(0, 0, "wimlib_global_cleanup")
EndFunc   ;==>_WimLib_Shutdown

; #FUNCTION# ====================================================================================================================
; Description ...: Load libwim-15*.dll
; ===============================================================================================================================
Func _WimLib_Startup()
    $iWIMLibRef += 1
    If $iWIMLibRef > 1 Then Return SetExtended($hWimLibDLL, 0) ; dll already loaded

    If Not FileExists($sWimLibDLL) Then Return SetError(2, 0, -1) ; $sWimLibDLL does not exist

    $hWimLibDLL = DllOpen($sWimLibDLL) ; remember $hWimLibDLL is Global
    If $hWimLibDLL = -1 Then Return SetError(1, 0, -1) ; Error opening dll
    Return SetExtended($hWimLibDLL, 0) ; success!
EndFunc   ;==>_WimLib_Startup

; #FUNCTION# ====================================================================================================================
; Description ...: This function is intended for safety checking and/or debugging.
; ===============================================================================================================================
Func _WimLib_VerifyWim(ByRef $pWIMStruct, $iVerifyFlag = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_verify_wim", "ptr", $pWIMStruct, "int", $iVerifyFlag)
    Return SetError(@error, $aResult[0], "wimlib_verify_wim")
EndFunc   ;==>_WimLib_VerifyWim

And now, my test code:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_UseX64=Y
#include-once
#include "WimLibUDF.au3"
Opt( "MustDeclareVars", 1 )

$bProgressBar = True

_WimLib_Startup()

_WimLib_Capture("Z:", "D:\WinRE in work!\WimLib\WimLib Test 2022.WimLib", 0, $WIMLIB_COMPRESSION_TYPE_LZMS, True, "", Null, 0, 0)
If @error Then MsgBox(262144 + 16, "Test", _WimLib_ErrorMessage(@error))

_WimLib_Shutdown()



; #FUNCTION# ====================================================================================================================
; Description ...: Captures an image from a directory path and stores it in an image file.
; ===============================================================================================================================
Func _WimLib_Capture($sSourceFolder, $sWimFile, $iWriteFlag = 0, $iCompressionType = $WIMLIB_COMPRESSION_TYPE_XPRESS, $bSolid = False, _
            $sName = "", $sConfigIni = Null, $iChunkSize = 0, $iCompressionLevel = 0)
    If $hWimLibDLL = 0 Then Return SetError(-1)

    Local $tWIMStruct = DllStructCreate("ptr")  ; Pointer storage for WIMStruct pointer
    Local $sResult, $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_create_new_wim", "int", $iCompressionType, "struct*", $tWIMStruct)
    _WimLib_ErrorHandling(@error, $aResult[0], "wimlib_create_new_wim")
    Local $pWIMStruct = DllStructGetData($tWIMStruct, 1) ; Get Wim structure pointer from storage

    $sResult = _WimLib_AddImage($pWIMStruct, $sSourceFolder, $sName, $sConfigIni, Default)
    _WimLib_ErrorHandling(@error, @extended, $sResult)

    $sResult = _WimLib_CompressionLevel($iCompressionType, $iCompressionLevel)
    _WimLib_ErrorHandling(@error, @extended, $sResult)

    If $bSolid = True Then
        $sResult = _WimLib_CompressionTypeSolid($pWIMStruct, $iCompressionType)
        _WimLib_ErrorHandling(@error, @extended, $sResult)

        $sResult = _WimLib_ChunkSizeSolid($pWIMStruct, $iChunkSize)
        _WimLib_ErrorHandling(@error, @extended, $sResult)
    Else
        $sResult = _WimLib_CompressionType($pWIMStruct, $iCompressionType)
        _WimLib_ErrorHandling(@error, @extended, $sResult)

        $sResult = _WimLib_ChunkSize($pWIMStruct, $iChunkSize)
        _WimLib_ErrorHandling(@error, @extended, $sResult)
    EndIf

    If FileExists($sWimFile) Then FileDelete($sWimFile)
    $aResult = DllCall($hWimLibDLL, "int:cdecl", "wimlib_write", "ptr", $pWIMStruct, "wstr", $sWimFile, "int", 1, "int", $iWriteFlag, "uint", 0)
    _WimLib_ErrorHandling(@error, $aResult[0], "wimlib_write")

    _WimLib_CompressionLevel($iCompressionType) ; Reset compression level to default value
EndFunc   ;==>_WimLib_Capture

Does someone can help to make the wimlib_add_image part to show messages? Thanks!

Jonathan

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Hi everyone,

Just to mention that I stopped continuing the project. First, because something is not working properly. Once set with wimlib_create_new_wim, compression type, compression level and block size cannot be changed even if I use "working" code as described in the documentation. Secondly, I lack knowledge about dll and/or reading authors' documetation.

So, good luck for the one who wants to go further!

Jonathan

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...