PDA

View Full Version : HELP: Compiling CLS libraries using GCC/MSVC


TheGeekyGamer
15-07-2018, 01:00
Hi, everyone

There is an add-on in FreeArc to compile cls libraries

How do i add compression algorithm to the simple_codec.cpp file ?

I am new to C/C++ programming. Anyone with knowledge of C, please help me out..

#include "cls.h"

int ClsMain (int op, CLS_CALLBACK callback, void* instance)
{
switch(op)
{
case CLS_COMPRESS:
case CLS_DECOMPRESS:
{
char param[100];
callback(instance, CLS_GET_PARAMSTR, param, 100); // Get method parameters as single string

const int BUFSIZE = 4096;
char buf[BUFSIZE];
for (int len; (len=callback(instance, CLS_PARTIAL_READ, buf, BUFSIZE)) != 0; )
{
if (len<0) return len; // Return errcode on error
int result = callback(instance, CLS_FULL_WRITE, buf, len);
if (result != len) return result<0? result : CLS_ERROR_WRITE;
}
return CLS_OK;
}

default:
return CLS_ERROR_NOT_IMPLEMENTED;
}
}

kassane
15-07-2018, 05:30
InnoSetup is make in delphi, but when it comes to C++ as an extension (*.dll) the ideal is to use MSVC since C++ Builder itself uses this compiler as a template to make it compatible. Although initially many avoid using it due to the dependencies of "vcredist (2005..2017)".

But if you develop an executable application could use mingw without problem, since it would only need to instantiate the initialization of it through command lines.

TheGeekyGamer
15-07-2018, 05:38
Alright. But how do i add compression command to the above given code. Can u give me an example ? eg lolz -dto0 - dtd1 -dtm1

kassane
15-07-2018, 05:40
Alright. But how do i add compression command to the above given code. Can u give me an example ? eg lolz -dto0 - dtd1 -dtm1


Yes!

TheGeekyGamer
15-07-2018, 05:42
Alright. But how do i add compression command under CLS_COMPRESS section? Eg: lolz -dto0 -dtd1

TheGeekyGamer
15-07-2018, 05:46
Do u mean like this ?

#include "cls.h"

int ClsMain (int op, CLS_CALLBACK callback, void* instance)
{
switch(op)
{
case CLS_COMPRESS:
{
pzlib e -c200m -mc1023
}
case CLS_DECOMPRESS:
{
char param[100];
callback(instance, CLS_GET_PARAMSTR, param, 100); // Get method parameters as single string

const int BUFSIZE = 4096;
char buf[BUFSIZE];
for (int len; (len=callback(instance, CLS_PARTIAL_READ, buf, BUFSIZE)) != 0; )
{
if (len<0) return len; // Return errcode on error
int result = callback(instance, CLS_FULL_WRITE, buf, len);
if (result != len) return result<0? result : CLS_ERROR_WRITE;
}
return CLS_OK;
}

default:
return CLS_ERROR_NOT_IMPLEMENTED;
}
}

kassane
15-07-2018, 05:56
See this! (https://fileforums.com/showthread.php?t=99510)

kassane
15-07-2018, 06:01
In which case which compiler will you use?
For example pzlib, ztool and xtools do not require cls-dll.

If you are using mingw compile an executable example without necessarily using the cls-dll extension code.

TheGeekyGamer
15-07-2018, 08:02
I wanted to create cls dll of pzlib for compression as the razor12911s dll did not work. I want to compress an archive using pzlib+lzma in freearc.

Gupta
15-07-2018, 08:16
just use cmake(check attached archive), i used it with msys2 and msvc
PS: for using the boost in msvc, I have handwritten the paths in CMakeList.txt, you probably have to change it according to your environment, it works just fine with msys2(use pacman)
also remember the arc is 32 bit so you have to use 32 bit environment for both msvc and msys2

in C++ you just need to inherit from ClsCompressor class and overwrite compress and decompress function
f.e:

class ClsLzhamCompressor : public ClsCompressor {
public:
template <typename... Types>
ClsLzhamCompressor(Types... Args) : ClsCompressor{Args...} {}

protected:
// overwrite this method for your compression
// see ClsCompressor defination in cls.h and use read_exactly(...) and equivalent functions for required operation
void decompress() override;

};


your main will look like:

extern "C" int __cdecl ClsMain(int operation, CLS_CALLBACK callback,
void *instance) {
return ClsLzhamCompressor(operation, callback, instance).run();
}