' ########################################################################################
' Microsoft Windows
' File: WIMGAPI.inc
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_WIMGAPI_PBI)
#DEFINE PBX_WIMGAPI_PBI
%EQUATE `WIMGAPI_INC = 1
#INCLUDE ONCE "Core/Windows.inc"
'//
'// Defined Value(s):
'//
'// WIMCreateFile:
'//
%EQUATE `WIM_GENERIC_READ = %GENERIC_READ
%EQUATE `WIM_GENERIC_WRITE = %GENERIC_WRITE
%EQUATE `WIM_CREATE_NEW = %CREATE_NEW
%EQUATE `WIM_CREATE_ALWAYS = %CREATE_ALWAYS
%EQUATE `WIM_OPEN_EXISTING = %OPEN_EXISTING
%EQUATE `WIM_OPEN_ALWAYS = %OPEN_ALWAYS
' enum
%EQUATE `WIM_COMPRESS_NONE = 0
%EQUATE `WIM_COMPRESS_XPRESS = 1
%EQUATE `WIM_COMPRESS_LZX = 2
' enum
%EQUATE `WIM_CREATED_NEW = 0
%EQUATE `WIM_OPENED_EXISTING = 1
'// WIMCreateFile, WIMCaptureImage, WIMApplyImage flags:
'//
%EQUATE `WIM_FLAG_RESERVED = &H00000001
%EQUATE `WIM_FLAG_VERIFY = &H00000002
%EQUATE `WIM_FLAG_INDEX = &H00000004
%EQUATE `WIM_FLAG_NO_APPLY = &H00000008
%EQUATE `WIM_FLAG_NO_DIRACL = &H00000010
%EQUATE `WIM_FLAG_NO_FILEACL = &H00000020
%EQUATE `WIM_FLAG_SHARE_WRITE = &H00000040
%EQUATE `WIM_FLAG_FILEINFO = &H00000080
%EQUATE `WIM_FLAG_NO_RP_FIX = &H00000100 ' // do not fix up reparse point tag
 ' // only used in WIMCaptureImage
'// WIMSetReferenceFile
'//
%EQUATE `WIM_REFERENCE_APPEND = &H00010000
%EQUATE `WIM_REFERENCE_REPLACE = &H00020000
'// WIMExportImage
'//
%EQUATE `WIM_EXPORT_ALLOW_DUPLICATES = &H00000001
%EQUATE `WIM_EXPORT_ONLY_RESOURCES = &H00000002
%EQUATE `WIM_EXPORT_ONLY_METADATA = &H00000004
'// WIMRegisterMessageCallback:
'//
%EQUATE `INVALID_CALLBACK_VALUE = &HFFFFFFFF
'// WIMCopyFile
'//
%EQUATE `WIM_COPY_FILE_RETRY = &H01000000
'// WIMMessageCallback Notifications:
'//
' enum
%EQUATE `WIM_MSG = %WM_APP + &H1476
%EQUATE `WIM_MSG_TEXT = %WIM_MSG + 1
%EQUATE `WIM_MSG_PROGRESS = %WIM_MSG_TEXT + 1
%EQUATE `WIM_MSG_PROCESS = %WIM_MSG_PROGRESS + 1
%EQUATE `WIM_MSG_SCANNING = %WIM_MSG_PROCESS + 1
%EQUATE `WIM_MSG_SETRANGE = %WIM_MSG_SCANNING + 1
%EQUATE `WIM_MSG_SETPOS = %WIM_MSG_SETRANGE + 1
%EQUATE `WIM_MSG_STEPIT = %WIM_MSG_SETPOS + 1
%EQUATE `WIM_MSG_COMPRESS = %WIM_MSG_STEPIT + 1
%EQUATE `WIM_MSG_ERROR = %WIM_MSG_COMPRESS + 1
%EQUATE `WIM_MSG_ALIGNMENT = %WIM_MSG_ERROR + 1
%EQUATE `WIM_MSG_RETRY = %WIM_MSG_ALIGNMENT + 1
%EQUATE `WIM_MSG_SPLIT = %WIM_MSG_RETRY + 1
%EQUATE `WIM_MSG_FILEINFO = %WIM_MSG_SPLIT + 1
%EQUATE `WIM_MSG_INFO = %WIM_MSG_FILEINFO + 1
%EQUATE `WIM_MSG_WARNING = %WIM_MSG_INFO + 1
%EQUATE `WIM_MSG_CHK_PROCESS = %WIM_MSG_WARNING + 1
'//
'// WIMMessageCallback Return codes:
'//
%EQUATE `WIM_MSG_SUCCESS = %ERROR_SUCCESS
%EQUATE `WIM_MSG_DONE = &HFFFFFFF0
%EQUATE `WIM_MSG_SKIP_ERROR = &HFFFFFFFE
%EQUATE `WIM_MSG_ABORT_IMAGE = &HFFFFFFFF
'//
'// WIM_INFO dwFlags values:
'//
%EQUATE `WIM_ATTRIBUTE_NORMAL = &H00000000
%EQUATE `WIM_ATTRIBUTE_RESOURCE_ONLY = &H00000001
%EQUATE `WIM_ATTRIBUTE_METADATA_ONLY = &H00000002
%EQUATE `WIM_ATTRIBUTE_VERIFY_DATA = &H00000004
%EQUATE `WIM_ATTRIBUTE_RP_FIX = &H00000008
%EQUATE `WIM_ATTRIBUTE_SPANNED = &H00000010
%EQUATE `WIM_ATTRIBUTE_READONLY = &H00000020
'//
'// The WIM_INFO structure used by WIMGetAttributes:
'//
' // Size = 564 bytes
TYPE WIM_INFO DWORD
 WimPath AS WSTRINGZ * %MAX_PATH ' WCHAR[MAX_PATH]
 Guid AS GUID ' GUID
 ImageCount AS DWORD
 CompressionType AS DWORD
 PartNumber AS WORD ' USHORT
 TotalParts AS WORD ' USHORT
 BootIndex AS DWORD
 WimAttributes AS DWORD
 WimFlagsAndAttr AS DWORD
END TYPE
'//
'// The WIM_MOUNT_LIST structure used for getting the list of mounted images.
'//
' // Size = 1048 bytes
TYPE WIM_MOUNT_LIST DWORD
 WimPath AS WSTRINGZ * %MAX_PATH ' WCHAR[MAX_PATH]
 MountPath AS WSTRINGZ * %MAX_PATH ' WCHAR[MAX_PATH]
 ImageIndex AS DWORD
 MountedForRW AS LONG
END TYPE
'//
'// Exported Function Prototypes:
'//
DECLARE FUNCTION WIMCreateFile LIB "wimgapi.dll" ALIAS "WIMCreateFile" ( BYREF lpszWimPath AS WSTRINGZ , BYVAL dwDesiredAccess AS QUAD , BYVAL dwCreationDisposition AS QUAD , BYVAL dwFlagsAndAttributes AS QUAD , BYVAL dwCompressionType AS QUAD , OPTIONAL BYREF lpdwCreationResult AS QUAD ) AS QUAD
DECLARE FUNCTION WIMCloseHandle LIB "wimgapi.dll" ALIAS "WIMCloseHandle" ( BYVAL hObject AS QUAD
 ) AS LONG
DECLARE FUNCTION WIMSetTemporaryPath LIB "wimgapi.dll" ALIAS "WIMSetTemporaryPath" ( BYVAL hWim AS DWORD
 , BYREF lpszPath AS WSTRINGZ
 ) AS LONG
DECLARE FUNCTION WIMSetReferenceFile LIB "wimgapi.dll" ALIAS "WIMSetReferenceFile" ( BYVAL hWim AS DWORD
 , BYREF lpszPath AS WSTRINGZ
 , BYVAL dwFlags AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMSplitFile LIB "wimgapi.dll" ALIAS "WIMSplitFile" ( BYVAL hWim AS DWORD
 , BYREF lpszPartPath AS WSTRINGZ
 , BYREF pliPartSize AS ANY
 , BYVAL dwFlags AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMExportImage LIB "wimgapi.dll" ALIAS "WIMExportImage" ( BYVAL hImage AS DWORD
 , BYVAL hWin AS DWORD
 , BYVAL dwFlags AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMDeleteImage LIB "wimgapi.dll" ALIAS "WIMDeleteImage" ( BYVAL hWim AS DWORD
 , BYVAL dwImageIndex AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMGetImageCount LIB "wimgapi.dll" ALIAS "WIMGetImageCount" ( BYVAL hWim AS DWORD
 ) AS DWORD
DECLARE FUNCTION WIMGetAttributes LIB "wimgapi.dll" ALIAS "WIMGetAttributes" ( BYVAL hWim AS DWORD
 , BYREF lpWimInfo AS WIM_INFO
 , BYVAL cbWimInfo AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMSetBootImage LIB "wimgapi.dll" ALIAS "WIMSetBootImage" ( BYVAL hWim AS DWORD
 , BYVAL dwImageIndex AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMCaptureImage LIB "wimgapi.dll" ALIAS "WIMCaptureImage" ( BYVAL hWim AS DWORD
 , BYREF lpszPath AS WSTRINGZ
 , BYVAL dwCaptureFlags AS DWORD
 ) AS DWORD
DECLARE FUNCTION WIMLoadImage LIB "wimgapi.dll" ALIAS "WIMLoadImage" ( BYVAL hWim AS DWORD
 , BYVAL dwImageIndex AS DWORD
 ) AS DWORD
DECLARE FUNCTION WIMApplyImage LIB "wimgapi.dll" ALIAS "WIMApplyImage" ( BYVAL hImage AS DWORD
 , BYREF lpszPath AS WSTRINGZ
 , BYVAL dwApplyFlags AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMGetImageInformation LIB "wimgapi.dll" ALIAS "WIMGetImageInformation" ( BYVAL hImage AS DWORD
 , BYREF lplpvImageInfo AS DWORD
 , BYREF lpcbImageInfo AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMSetImageInformation LIB "wimgapi.dll" ALIAS "WIMSetImageInformation" ( BYVAL hImage AS DWORD
 , BYVAL lplpvImageInfo AS DWORD
 , BYVAL lpcbImageInfo AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMGetMessageCallbackCount LIB "wimgapi.dll" ALIAS "WIMGetMessageCallbackCount" ( OPTIONAL BYVAL hWim AS DWORD
 ) AS DWORD
DECLARE FUNCTION WIMRegisterMessageCallback LIB "wimgapi.dll" ALIAS "WIMRegisterMessageCallback" ( BYVAL hWim AS DWORD
 , BYVAL fpMessageProc AS DWORD
 , OPTIONAL BYVAL lpvUserData AS DWORD
 ) AS DWORD
DECLARE FUNCTION WIMUnregisterMessageCallback LIB "wimgapi.dll" ALIAS "WIMUnregisterMessageCallback" ( BYVAL hImage AS DWORD
 , OPTIONAL BYVAL fpMessageProc AS DWORD
 ) AS LONG
' An application-defined function used with the WIMRegisterMessageCallback or WIMUnregisterMessageCallback functions.
'FUNCTION WIMMessageCallback ( ' BYVAL dwMessageId AS DWORD
' , BYVAL wParam AS DWORD
' , BYVAL lParam AS LONG
' , BYVAL lpvUserData AS DWORD
' ) AS DWORD
DECLARE FUNCTION WIMCopyFile LIB "wimgapi.dll" ALIAS "WIMCopyFile" ( BYREF lpszExistingFileName AS WSTRINGZ
 , BYREF lpszNewFileName AS WSTRINGZ
 , BYVAL lpProgressRoutine AS DWORD
 , BYVAL lpvData AS DWORD
 , BYVAL pbCancel AS LONG
 , BYVAL dwCopyFlags AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMMountImage LIB "wimgapi.dll" ALIAS "WIMMountImage" ( BYREF lpszMountPath AS WSTRINGZ
 , BYREF lpszWimFileName AS WSTRINGZ
 , BYVAL dwImageIndex AS DWORD
 , OPTIONAL BYREF lpszTempPath AS WSTRINGZ
 ) AS LONG
DECLARE FUNCTION WIMUnmountImage LIB "wimgapi.dll" ALIAS "WIMUnmountImage" ( BYREF lpszMountPath AS WSTRINGZ
 , BYREF lpszWimFileName AS WSTRINGZ
 , BYVAL dwImageIndex AS DWORD
 , BYVAL bCommitChanges AS LONG
 ) AS LONG
DECLARE FUNCTION WIMGetMountedImages LIB "wimgapi.dll" ALIAS "WIMGetMountedImages" ( BYREF lpMountList AS WIM_MOUNT_LIST
 , BYREF lpcbBufferSize AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMInitFileIOCallbacks LIB "wimgapi.dll" ALIAS "WIMInitFileIOCallbacks" ( OPTIONAL BYVAL lpCallbacks AS DWORD
 ) AS LONG
DECLARE FUNCTION WIMSetFileIOCallbackTemporaryPath LIB "wimgapi.dll" ALIAS "WIMSetFileIOCallbackTemporaryPath" ( OPTIONAL BYVAL lpszPath AS DWORD
 ) AS LONG
'//
'// File I/O callback prototypes
'//
'typedef VOID * PFILEIOCALLBACK_SESSION;
'typedef
'PFILEIOCALLBACK_SESSION
'(CALLBACK * FileIOCallbackOpenFile)(
' LPCWSTR lpFileName
' );
'FUNCTION FileIOCallbackOpenFile ( ' BYREF lpFileName AS WSTRINGZ ' LPCWSTR lpFileName
' ) AS DWORD ' PFILEIOCALLBACK_SESSION
'typedef
'(CALLBACK * FileIOCallbackCloseFile)(
' PFILEIOCALLBACK_SESSION hFile
' );
'FUNCTION FileIOCallbackCloseFile ( ' BYVAL hFile AS DWORD ' PFILEIOCALLBACK_SESSION hFile
' ) AS LONG
'typedef
'(CALLBACK * FileIOCallbackReadFile)(
' PFILEIOCALLBACK_SESSION hFile,
' LPVOID lpBuffer,
' DWORD nNumberOfBytesToRead,
' LPDWORD lpNumberOfBytesRead,
' LPOVERLAPPED lpOverlapped
' );
'FUNCTION FileIOCallbackReadFile ( ' BYVAL hFile AS DWORD ' PFILEIOCALLBACK_SESSION hFile
' , BYVAL lpBuffer AS DWORD ' LPVOID lpBuffer
' , BYVAL nNumberOfBytesToRead AS DWORD ' DWORD nNumberOfBytesToRead
' , BYREF lpNumberOfBytesRead AS DWORD ' LPDWORD lpNumberOfBytesRead
' , BYREF lpOverlapped AS OVERLAPPED ' LPOVERLAPPED lpOverlapped
' ) AS LONG
'typedef
'(CALLBACK * FileIOCallbackSetFilePointer)(
' PFILEIOCALLBACK_SESSION hFile,
' LARGE_INTEGER liDistanceToMove,
' PLARGE_INTEGER lpNewFilePointer,
' DWORD dwMoveMethod
' );
'FUNCTION FileIOCallbackSetFilePointer ( ' BYVAL hFile AS DWORD ' PFILEIOCALLBACK_SESSION hFile
' , BYVAL liDistanceToMove AS QUAD ' LARGE_INTEGER liDistanceToMove
' , BYREF lpNewFilePointer AS QUAD ' PLARGE_INTEGER lpNewFilePointer
' , BYVAL dwMoveMethod AS DWORD ' DWORD dwMoveMethod
' ) AS LONG
'typedef
'(CALLBACK * FileIOCallbackGetFileSize)(
' HANDLE hFile,
' PLARGE_INTEGER lpFileSize
' );
'FUNCTION FileIOCallbackGetFileSize ( ' BYVAL hFile AS DWORD ' PFILEIOCALLBACK_SESSION hFile
' , BYREF lpFileSize AS QUAD ' PLARGE_INTEGER lpFileSize
' ) AS LONG
' // Size = 20 bytes
TYPE SFileIOCallbackInfo DWORD
 pfnOpenFile AS DWORD ' FileIOCallbackOpenFile
 pfnCloseFile AS DWORD ' FileIOCallbackCloseFile
 pfnReadFile AS DWORD ' FileIOCallbackReadFile
 pfnSetFilePointer AS DWORD ' FileIOCallbackSetFilePointer
 pfnGetFileSize AS DWORD ' FileIOCallbackGetFileSize
END TYPE
#ENDIF
