- BZip2 c++ error
- Posted by Geky on May 14th, 2007
I'm trying to use BZip2 library but I receive always an access
violation error. I use two different codes:
bz_stream bzstream;
ZeroMemory(&bzstream, sizeof(bzstream));
bzstream.bzalloc=NULL;
bzstream.bzfree=NULL;
bzstream.opaque=NULL;
int x = BZ2_bzCompressInit(&bzstream, 5, 0, 30);
BZ2_bzCompressInit(&bzstream, 5, 0, 30); <-- HERE IT RETURN
THE ERROR
if I use "bz_stream* bzstream" in place of "bz_stream bzstream" my
compiler says that "local variable 'bzstream' used without having been
initialized" :-(.
+++++++++++++++++++++++++++++
char pOrig[256], pComp[256], pDec[256];
unsigned int OrigLen, CompLen, DecLen;
strcpy(pOrig, "OMFG PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG
PIE! OMFG
PIE!OMFG PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG
PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG PIE! OMFG
PIE!");
OrigLen = strlen(pOrig) + 1;
printf("Original:\t%s\nOrig Len:\t%d\n\n", pOrig, OrigLen);
CompLen = 256;
BZ2_bzBuffToBuffCompress(pComp, &CompLen, pOrig, OrigLen, 9,
0, 30); <-- HERE THERE IS THE ERROR AGAIN
I can't understand why there is this access violation always here and
with two different codes
Anyone know how to use bzlib?
- Posted by Ulrich Eckhardt on May 15th, 2007
Geky wrote:
FYI: sizeof has two ways of invokation:
sizeof object
sizeof (type)
while you are using
sizeof (object)
The brackets are redundant.
I don't know the library, but it seems to me that you are supposed to fill
these function pointers with something meaningful. In general, giving an
URL for the lib and one to the documentation would help.
Well, it's because you're doing something wrong. Seriously, there is by far
not enough info to give any real answer.
This shows that you don't know the difference between an object and a
pointer to an object. Seriously, this is very basic C, and without it you
obviously can't use these correctly. I'd go to the ACCU website and pick a
good book on C from the reviews section there.
Access violation means that you were accessing memory you shouldn't have
been accessing. This typically is caused by dereferencing a null pointer or
invalid pointer ("uninitialised").
Uli
--
Sator Laser GmbH
Geschäftsführer: Ronald Boers, Amtsgericht Hamburg HR B62 932
- Posted by Thomas J. Gritzan on May 15th, 2007
Ulrich Eckhardt wrote:
A null pointer is meaningful here; the library uses malloc/free then.
True.
Missing info: What error is returned?
The OP should provide a complete compilable example of what he tried. His
second example (BZ2_bzBuffToBuffCompress) should work.
--
Thomas
http://www.netmeister.org/news/learn2quote.html
- Posted by Geky on May 15th, 2007
<<<<<<<<<<
This shows that you don't know the difference between an object and a
pointer to an object.
<<<<<<<<<<
I know that difference. bz_stream is a structure of bzlib. I can't
find over the net an example that can help me. All the code about
bzip2 are all carbon copy of the original code of bzip2 web pages and
there I can't solve my question.
- PeaZip 1.0 released; supports: 001, 7z, 7zip sfx, Bzip2, Gzip, Pea, Tar, Z, Zip (Software & Applications) by giorgio.tani
- Exchange error 85010014 ,server error or user error?! (Mobile Devices) by lynx
- Error Loading (Error 101) Error 1904 Module (Microsoft Windows) by mikesdad
- 3 Problems - Media Center Error, Date/Time Error, Downloading Updates Error (Microsoft Windows) by angieangie
- Office Update Error, Detect & Repair Error, Uninstall Error (Home and office) by Murali

