Does anyone know what I am doing wrong here?
I am trying to compress a small string, here is the compression part...
...
ustr1 db "Example Input String",0
...
LOCAL src:DWORD ;source buffer
LOCAL sln:DWORD ;source size
LOCAL dest:DWORD ;dest buffer
LOCAL dln:DWORD ;dest size
...
mov eax,ustr1
mov src,eax
...
invoke compress,dest,SIZEOF dln,src,SIZEOF sln
...
I get a invalid page fault error, the zlib dll works fine...
I think that your compress statement should be
invoke compress,dest,SIZEOF dest,src,SIZEOF src
SIZEOF returns the size of the variable. In this case a DWORD,
if you are storing the size of dest in the variable dln then just pass dln.....like
invoke compress,dest,dln,src,sln
It looks to me like you are telling the compress function that the size of your string is a DWORD.
The only other thing that I can suggest is to make sure that you are passing in exactly what the function thinks it getting.....
I may be way off in my assessment as I have not use zlib before but it is something to think about.
HTH
The following is what it would look like in visual basic...
Public Function CompressString(TheString As String) As Long
OriginalSize = Len(TheString)
'Allocate string space for the buffers
Dim CmpSize As Long
Dim TBuff As String
orgSize = Len(TheString)
TBuff = String(orgSize + (orgSize * 0.01) + 12, 0)
CmpSize = Len(TBuff)
'Compress string (temporary string buffer) data
ret = compress(ByVal TBuff, CmpSize, ByVal TheString, Len(TheString))
'Set original value
OriginalSize = Len(TheString)
'Crop the string and set it to the actual string.
TheString = Left$(TBuff, CmpSize)
'Set compressed size of string.
CompressedSize = CmpSize
'Cleanup
TBuff = ""
'Return error code (if any)
CompressString = ret
End Function
I'm not sure how asm buffers work, that is probaly what is wrong?
The zlib prototype (in C) is
ZEXTERN int ZEXPORT compress OF((Bytef *dest,
uLongf *destLen,
const Bytef *source,
uLong sourceLen));
So you should code something like:
ustr1 byte "Example Input String",0
local dest:dword ; -> Destination buffer
local dln:dword ; Destination buffer size
invoke compress,
dest,
addr dln,
addr ustr1,
sizeof ustr1
That's it.
This is what you posted:
ustr1 db "Example Input String",0
...
LOCAL src:DWORD ;source buffer
LOCAL sln:DWORD ;source size
LOCAL dest:DWORD ;dest buffer
LOCAL dln:DWORD ;dest size
...
mov eax,ustr1
mov src,eax
...
invoke compress,dest,SIZEOF dln,src,SIZEOF sln
...
everything is fine but change the:
mov eax,ustr1 to mov eax,offset ustr1
If I remember correctly, zlib wants the last parameter to be a
pointer to a dword - so it can store the actual output length.
This gave me quite some queer errors back when I was using zlib
to compress/decompress my fancy new executable format for a 32bit
dos project.
It took a long time to sort out the problem. I was calling zlib from
assembly, and thus I had it's proto as all dwords. "destlen", not
"pdestlen", so you couldn't tell from the name it wanted a pointer.
I had almost given up, when I looked at the C definition, and saw
that little start telling me that I should bang my head into the
wall a couple times.
I think I should just give you a
small snipet from my Pack Rat program
that zips files.
hMem1$ dd ? ;address of memroy block Dest.
hMem2$ dd ? ;address of memory block Source
dBuffSize dd ? ;DWORD of Dest size.
sBuffSize dd ? ;DWORD of Source Size.
invoke compress2,hMem1$,addr dBuffSize,hMem2$,sBuffSize,9
Notice that the first three Params are all
address pointers this must be how you invoke this
call into the zlib DLL.
The last Param tells how much to compress the data
that value can only be from 0-9 zero meaning no
compress, while 9 equ Max.
I hope this clears up how to use zlib..
i want to work with zlib.dll but i'm unable to import function
like compress2 or uncompress.
I've: LNK2001 : unresolved external symbol _compress2@20
I've make this in my source file:
include zlibdll.inc
includelib zlibstat.lib
includelib zlibdll.lib
and this in zlibdll.inc (new file):
compress2 PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
how to include zlib in order to INVOKE compress2 and uncompress?
thank you
I don't know what zlib you are using
but what I am working with only has
zlib.lib and zlib.inc and it works
great I use compress2 it really
works easy. maybe you should tell
me if you want the vertsion I am
working with. cuz I have this one
woking and there is only one lib
and inc file to make the DLL work.
I've email you.
thanx!:)
I have sent you my whole
project with all the files
this project is not done, but
it does zip all files from a
folder into a zip file. the
compression is zip compadible
but the archive is not zip
compadible, I am still reading
about the zip archive layout..