Hello,
I have a code for implement minilzo.obj that works with emergence basic but not with iwb 2 :
Attach is the code (eba and the obj file)
$use "c:\\ebdev\\minilzo\\minilzo.obj"
'
Declare Import,RtlFillMemory(Destination As Pointer,Length As UInt,Fill As Char)
Declare Import,RtlMoveMemory(Destination As Pointer,Source As Pointer,Length As UInt)
'
declare cdecl _memset(memory s,uint c,char n)
declare cdecl _memcpy(memory s1, memory s2, uint n)
declare cdecl _memmove(memory dstP, memory srcP, uint numBytes)
declare cdecl _memcmp (memory s1, memory s2, uint numBytes),INT
'
declare extern _lzo1x_1_compress(memory Source,int SourceLength, memory Dest,int DestLength BYREF,memory WorkMem)
declare extern _lzo1x_decompress(memory Source,int SourceLength, memory Dest,int DestLength BYREF,memory WorkMem)
declare extern _lzo1x_decompress_safe(memory Source,int SourceLength, memory Dest,int DestLength BYREF,memory WorkMem)
declare extern _lzo_adler32(int Adler, memory Buf, int Length)
'
declare extern _lzo_version(),INT
declare extern _lzo_version_string(),INT
declare extern _lzo_version_date(),INT
'
OPENCONSOLE
print _lzo_version()
pointer p
p=_lzo_version_string()
print #<string>p
'
p=_lzo_version_date()
print #<string>p
'
compressfile(GETSTARTPATH()+"test.txt")
decompressfile(Getstartpath()+"test.txt.lzo")
WAITCON
END
sub _memset(memory s,uint c,char n)
RtlFillMemory(s,n,c)
endSUB
sub _memcpy(memory s1, memory s2, uint n)
RtlMoveMemory(s2, s1, n)
ENDSUB
sub _memmove(memory dstP, memory srcP, uint numBytes)
RtlMoveMemory(srcP, dstP, numBytes)
FREEMEM(srcP)
Endsub
global sub _memcmp (memory s1, memory s2, uint numBytes),INT
uint i
memory p1, p2
'
p1 = s1
p2 = s2
For i = 0 To numBytes -1
If p1 <> p2 THEN
If p1 < p2 THEN
Return -1
Else
Return 1
EndIf
EndIf
p1++
p2++
Next i
Return 0
ENDSUB
sub compressfile(string fname)
bfile ifilehandle
memory Buffer,cbuffer,workmem
int i,j
string dest
'
if OpenFile(ifilehandle,fname,"R")=0 THEN
i =LEN(ifilehandle)
ALLOCMEM(buffer,1,i)
read ifilehandle,buffer
'
j=i+Int(i/16)+64+3
ALLOCMEM(cbuffer,1,j)
ALLOCMEM(workmem,1,0x10000)
_lzo1x_1_compress(buffer,i,cbuffer,j,workmem)
print Str$(i)+" / "+STR$(j)
CloseFile iFileHandle
FreeMem(Buffer)
FreeMem(workmem)
'
dest=fname+".lzo"
allocmem(buffer,1,j)
readmem cbuffer,1,buffer
IF openfile (ifilehandle,dest,"W")=0 THEN
Write ifilehandle,i
Write ifilehandle, buffer
CloseFile ifilehandle
ENDIF
'
freemem(buffer)
FreeMem(cbuffer)
ENDIF
ENDSUB
sub decompressfile(string fname)
bfile iFileHandle
memory Buffer,cbuffer
int i,j
string dest
IF OpenFile(ifilehandle,fname,"R")=0 THEN
i =Len(ifilehandle)
AllocMem(buffer,1,i)
Read ifilehandle,j
read ifilehandle,buffer
'
AllocMem(cbuffer,1,j)
_lzo1x_decompress(buffer,i,cbuffer,j,0)
print Str$(i)+" / "+Str$(j)
CloseFile iFileHandle
FreeMem Buffer
'
dest=Left$(fname,Len(fname)-3)+".d"
if openfile(ifilehandle,dest,"W")=0 THEN
Write ifilehandle, cbuffer
CloseFile ifilehandle
ENDIF
'
FreeMem cbuffer
ENDIF
ENDSUB
What options should i use for iwb 2 ?
Need help...
you say it works with Eb and not IWB2.
What specifically does it not do in IWB2?
LarryMc
In IWB 2 :
The compilation work (with warnings).
The compression/decompression don't work.
In emergence : the compilation with no warning/errors and the compression/decompression work.
I don't see the problem. It may be in the obj file, I don't know.
Maybe Sapero will look at it.
LarryMc
1. All the functions in minilzo.obj file are cdecl - declare them with the CDECL modifier:
declare cdecl extern _lzo1x_1_compress(memory Source,int SourceLength, memory Dest,int DestLength BYREF,memory WorkMem)
declare cdecl extern _lzo1x_decompress(memory Source,int SourceLength, memory Dest,int DestLength BYREF,memory WorkMem)
2. You don't need the _mem** wrappers, the linker will resolve extra-decorated symbols.
3. the decompression routine is crashing - _lzo1x_decompress routine writes to a bad pointer. Check your code.
0x5D75F0 - compressed data 41 bytes
0x5D7F68 - buffer for decompressing 7403 bytes ()
0x5EE000 - write address - 16098 bytes past 0x5D7F68
This is your code after the initial cleanup:
$option "resolvelibs"
$use "minilzo.obj"
declare cdecl extern _lzo1x_1_compress(memory Source,int SourceLength, memory Dest,int DestLength BYREF,memory WorkMem)
declare cdecl extern _lzo1x_decompress(memory Source,int SourceLength, memory Dest,int DestLength BYREF,memory WorkMem)
print "compressing..."
compressfile(GETSTARTPATH()+"tmp.obj")
print "decompressing..."
decompressfile(GETSTARTPATH()+"tmp.obj.lzo")
sub compressfile(string fname)
bfile ifilehandle
memory Buffer,cbuffer,workmem
int i,j
string dest
'
if OPENFILE(ifilehandle,fname,"R")=0 THEN
i =LEN(ifilehandle)
ALLOCMEM(Buffer,1,i)
read ifilehandle,Buffer
'
j=i+Int(i/16)+64+3
ALLOCMEM(cbuffer,1,j)
ALLOCMEM(workmem,1,0x10000)
_lzo1x_1_compress(Buffer,i,cbuffer,j,workmem)
print i," / ",j
CLOSEFILE ifilehandle
FREEMEM(Buffer)
FREEMEM(workmem)
'
dest=fname+".lzo"
ALLOCMEM(Buffer,1,j)
readmem cbuffer,1,Buffer
IF OPENFILE (ifilehandle,dest,"W")=0 THEN
Write ifilehandle,i
Write ifilehandle, Buffer
CLOSEFILE ifilehandle
ENDIF
'
FREEMEM(Buffer)
FREEMEM(cbuffer)
ENDIF
ENDSUB
sub decompressfile(string fname)
bfile iFileHandle
memory Buffer,cbuffer
int i,j
string dest
IF OPENFILE(iFileHandle,fname,"R")=0 THEN
i =Len(iFileHandle)
ALLOCMEM(Buffer,1,i)
Read iFileHandle,j
read iFileHandle,Buffer
'
ALLOCMEM(cbuffer,2,j)
print "Buffer: 0x",HEX$(Buffer),"-0x",HEX$(Buffer+i-1)
print "cbuffer: 0x",HEX$(cbuffer),"-0x",HEX$(cbuffer+j-1)
try
_lzo1x_decompress(Buffer+0,i,cbuffer+0,j,0)
endtry
catch
print "exception 0x",HEX$(GetExceptionCode())
pointer p = GetExceptionInformation()
p = *<pointer>p ' EXCEPTION_RECORD
print *<uint>p[5] ? "write to " : "read from ",
print "0x", HEX$(*<uint>p[6])
end
endcatch
print "alive"
print i," / ",j
CLOSEFILE iFileHandle
FREEMEM Buffer
'
dest=LEFT$(fname,Len(fname)-3)+".d"
if OPENFILE(iFileHandle,dest,"W")=0 THEN
Write iFileHandle, cbuffer
CLOSEFILE iFileHandle
ENDIF
'
FREEMEM cbuffer
ENDIF
ENDSUB
Sapero, thanx for your work.
Sorry but the code as-is is perfect in emergence basic.
Work clean without error.
Compress and decompress : no problem.
The obj work also in pure basic and delphi.
In iwb2 the compression routine fail and then the decompression fails too.
Maybe the problem is with the routines _memset,_memcpy, _memmove, that cant communicate with the lib..
I need to add Globlal for no warning like this :
global sub cdecl _memset(pointer s,uint c,schar n)
RtlFillMemory(s,n,c)
endSUB
I continue searching...