I need to uncompress large gzip file (more than 4.5 Go). I've got some trouble to do this with Delphi Seattle using the TDecompressionStream (Result file is truncated).
To avoid this problem, I choose to do this task in a C# dll and to call it from Delphi.
My C# code is working, I test it wiht a console application. I add the nugget package UnmanagedExports and compile the dll in 32 bits.
When I call my dll method from Delphi, I've got this error : "External exception E0434352"
I follow advices of this links : How to use a DLL created with C# in Delphi
but I already have this problem
My c# code
static public class UnZip
{
[DllExport("UngzipFile", CallingConvention.StdCall)]
public static int UngzipFile(string aFile)
{
int result = 0;
FileInfo fileInfo = new FileInfo(aFile);
using (FileStream fileToDecompress = fileInfo.OpenRead())
{
string decompressedFileName = Path.Combine(Path.GetDirectoryName(aFile), "temp.sql");
using (FileStream decompressedStream = File.Create(decompressedFileName))
{
using (GZipStream decompressionStream = new GZipStream(fileToDecompress, CompressionMode.Decompress))
{
try
{
decompressionStream.CopyTo(decompressedStream);
}
catch
{
result = 1;
}
}
}
}
return result;
}
}
My Delphi code
function UngzipFile(aFile : string) : Integer; stdcall; external 'UnCompress.dll';
procedure TForm1.UnzipFile(aFileName: String);
var
UnZipFileName : string;
Return : integer;
DllZipFile : PWideChar;
begin
UnZipFileName := ExtractFilePath(aFileName)+'Temp.sql';
if FileExists(UnZipFileName) then
DeleteFile(UnZipFileName);
DllZipFile := PWideChar(aFileName);
Return := UngzipFile(DllZipFile);
if Return > 0 then
raise Exception.Create('Error while uncompressing file');
end;
For the moment, when I call UngzipFile from Delphi, _I've got the external exception E0434352.
I expect to have result = 0 and my file to be uncompress.
Thanks for your help.