I tried to use zlib static library from WinImage Site .I made an include file with l2inca.I have tried crc32 function and compiled it wanted additional libraries Libc.lib,Oldnames.lib I took these files from VC folder and CRC32 function worked correctly.However when I try to use compress function it gives Z_BUF_ERROR.Is it possible to use zlib with masm or am I dreaming :)


FAQ about ziplib
MANUAL



.386
.model flat, stdcall
option casemap :none

include /masm32/include/windows.inc
include /masm32/include/user32.inc
include /masm32/include/kernel32.inc
include /masm32/include/gdi32.inc
include /masm32/include/shell32.inc
include /masm32/include/masm32.inc
include /masm32/include/uuid.inc
include zlibstat.inc

includelib /masm32/lib/gdi32.lib
includelib /masm32/lib/shell32.lib
includelib /masm32/lib/user32.lib
includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/masm32.lib
includelib /masm32/lib/uuid.lib

includelib zlibstat.lib
includelib libc.lib
includelib Oldnames.lib

.data

aaaa db 'xxxxx',0
testme db 'testourcrc'
szBuffer db 20 dup(0)
fmat db '%8X',0

szSource db 'hello'
slen dd sizeof szSource
szDest db 20 dup(0)
dlen dd sizeof szSource+1
.code

start:

invoke compress,addr szDest,addr dlen,addr szSource,addr slen
end start
Posted on 2002-07-23 07:37:15 by LaptoniC
LaptoniC,

Just make sure you are using the correct calling convention. The zlib stuff is probably C calling convention where MASM32 will default to STDCALL so you will need to specify C if they are.

Regards,

hutch@movsd.com
Posted on 2002-07-23 08:04:48 by hutch--
In the manual for CRC32 it says uLong crc32 (uLong crc, const Bytef *buf, uInt len);
so I used as
invoke crc32,0,addr teststring,sizeof teststring
and it worked.In manual compress function is defined as
compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen
I called as
invoke compress,addr szDest,addr dlen,addr szSource,addr slen
so I guess my notation is correct.
Posted on 2002-07-23 08:16:55 by LaptoniC
It does not want a pointer to source length, but source length itself. Read the prototype more carefully.
Posted on 2002-07-23 11:25:52 by comrade
I have read the prototype carefully, but you are wrong.If you pass just dword value it crashes at below point
;ebx=sizeofdest
mov eax, ;it should be offset
I guess it just dont work.I get always -4 as error code which is Z_MEM_ERROR.I debugged and also saw that it is because of HeapAlloc function in the lib.It pushes 0 as hHeap.So it cant allocate any memory I have tried to get hHeap by GetProcessHeap and put to that location but it didnt worked either.Anyway no one can say that I havent tried.Thanks all for your suggestions.
Posted on 2002-07-23 12:27:47 by LaptoniC
No, you are wrong.
Posted on 2002-07-23 13:34:43 by comrade
uLong defines the value, not a pointer to the value... I think comrade is right...
Posted on 2002-07-23 14:04:49 by JCP
I dont know C I dont know the notation but I am sure that when I pass just numofbytes
mov eax, make app crashes which ebx=size of destination buffer.If you compile and debug you will see.I guess it doesnt work because it needs some initializaion values.
Posted on 2002-07-23 15:42:50 by LaptoniC
It should be

mov eax, ebx... not mov eax,
Posted on 2002-07-23 15:47:37 by JCP
I am not using mov eax, this code *in* the library itself.If you pass just number what will hapen ie for example for number 100, mov eax,[100] which crashes.My english is very bad I guess I can't even express basic things :rolleyes:
Posted on 2002-07-23 18:06:37 by LaptoniC
I've checked the source to find out which type is exactly uLong and I found this :



typedef unsigned long uLong; /* 32 bits or more */


so, a dword, not a pointer to a dword...

Now, the prototype...

According to the documentation:


int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least 0.1% larger than sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to compress a whole file at once if the input file is mmap'ed.


Bytef *dest : pointer to a byte array (unsigned char) for destination (compressed data)

uLongf *destLen : pointer to the destination lenght.
It passes a pointer to it because the function modifies the variable... in C, parameters are passed by value, not by reference (address), so you need to pass the address to it if you want to modify a variable outside the function...

Bytef *source : pointer to a byte array (unsigned char), a pointer to the memory block you want to compress.

uLong sourceLen : the byte lenght of the memory block you want to compress, the value itself...

From the example.c source from the zlib package:



err = compress(compr, &comprLen, (const Bytef*)hello, len);


In &comprLen, the & means "address of"... you are passing the address of the variable to the function, not its value... but the last argument (len) is the value itself.

I hope it will help you even if you don't know C. :)
Posted on 2002-07-24 01:14:55 by JCP
First of all sorry comrade when I was reading your post it was 1-2 AM.I havent read your post correctly I guess I read as you should define all length as value.
I guess correct notation is as you all pointed out
invoke compress,addr szDest,addr dlen,addr szSource,slen
however it doesnt work too.I have tried this by using staticlibrary and import library staticlibrary failed import library worked.I guess it is c specific library.Thanks all of you for your patience :stupid:
Posted on 2002-07-24 08:46:32 by LaptoniC