#ERR_FIMP_NONE = 0
#ERR_FIMP_TOOSHORT = -1
#ERR_FIMP_UNKNOWNFORMAT = -2
#ERR_FIMP_COMPNOTEVEN = -3
#ERR_FIMP_COMPTOOSHORT = -4
#ERR_FIMP_NOTENOUGHDATA = -5
#ERR_FIMP_OUTPUTLTINPUT = -6
#ERR_FIMP_CANNOTALLOCMEM = -7
#ERR_FIMP_CANNOTDEPLODE = -8
Structure FIMP
*DLL
*GetExplodeSize
*Explode
*Implode
EndStructure : Global IMP.FIMP
IMP\DLL = OpenLibrary(#PB_Any, "..\..\dll\fimp.dll")
With IMP
If \DLL
\GetExplodeSize = GetFunction(\DLL, "impGetExplodeSize")
\Implode = GetFunction(\DLL, "impImplode")
\Explode = GetFunction(\DLL, "impExplode")
Else
Debug "Error: cannot initialize fimp.dll"
End
EndIf
EndWith
#FIMP = 0
CompilerIf #FIMP = 0
Debug "Implode..."
InFile.s = "test\SOTB-TITLE.mod"
OutFile.s = "C:\SOTB-TITLE.imp"
CMode = 1
hF = ReadFile(#PB_Any, InFile)
If hF
In_Len = Lof(hF)
*In = AllocateMemory(In_Len)
ReadData(hF, *In, In_Len)
CloseFile(hF)
Else
Debug "Error: cannot open - " + InFile
End
EndIf
Out_Len = CallCFunctionFast(IMP\Implode, *In, In_Len, CMode)
If Out_Len > 0
hF = CreateFile(#PB_Any, OutFile)
If hF
WriteData(hF, *In, Out_Len)
CloseFile(hF)
Else
Debug "Error: cannot create - " + OutFile
EndIf
Else
Debug "Error: cannot implode file - " + Str(Out_Len)
EndIf
CompilerElse
Debug "Explode..."
InFile.s = "test\SOTB-TITLE.imp"
OutFile.s = "C:\SOTB-TITLE.mod"
hF = ReadFile(#PB_Any, InFile)
If hF
In_Len = Lof(hF)
*In = AllocateMemory(In_Len)
ReadData(hF, *In, In_Len)
CloseFile(hF)
Else
Debug "Error: cannot open - " + InFile
End
EndIf
Out_Len = CallCFunctionFast(IMP\GetExplodeSize, *In)
If Out_Len > 0
*Out = AllocateMemory(Out_Len)
n = CallCFunctionFast(IMP\Explode, *In, In_Len, *Out, Out_Len)
If n = #ERR_FIMP_NONE
hF = CreateFile(#PB_Any, OutFile)
If hF
WriteData(hF, *Out, Out_Len)
CloseFile(hF)
Else
Debug "Error: cannot create - " + OutFile
EndIf
Else
Debug "Error: cannot explode file - " + Str(n)
EndIf
EndIf
CompilerEndIf
CloseLibrary(IMP\DLL)
Debug "InFile: " + InFile + " - Size: " + Str(In_Len)
Debug "OutFile: " + OutFile + " - Size: " + Str(Out_Len)
If *In : FreeMemory(*In) : EndIf
If *Out : FreeMemory(*Out) : EndIf
End