Function LZNV_Encode_File_wCOM_Obj
8.1.5.1 LZNV SDK MFC App File Contents
8.1.5.1 Function LZNV Encode File
LZNV_Encode_File_wCOM_Obj is a sample function that performs file compression without the need of any prior buffer manipulation, using the LZNV COM Object
/// \brief LZNV_Encode_File performs a straight forward file compression without the need of any prior buffer manipulation.
/// \note The function will perform internal buffering. If you want to perform your own buffering, please use LZNV_Encode_File_wBuffer.
/// \prior The function need to access the registered LZNV COM Object. see _load_COM_Obj
/// \param[in] pLZNV_COM_Object_obj: Instantiated object of type LZNV_COM_Obj::ILZNV_COM_ObjPtr.
/// \param[in] _encoding_method: One of the methods _LZNV_ULTRAFAST_COMPRESSION to _LZNV_BETTER_COMPRESSION or _LZNV_HUFFMAN_COMPRESSION to _LZNV_RLE64_COMPRESSION.
/// \param[in] _memory_level: The working size of the LZ algorithm. _LZNV_BUFFER_SIZE_256KB_INDX to _LZNV_BUFFER_SIZE_16MB_INDX.
/// \param[in] _wchr_filename_to_compress: Input file path to compress. Unicode WCHAR.
/// \param[in] _wchr_output_filename: Output file path to compress. Unicode WCHAR.
/// \return returns NO_ERROR (0) in case of no errors or one of the error codes defined in LZNV_Defines.h header file
/// possible values:
/// - _LZNV_ERROR_INVALID_COMPRESSION_METHOD
/// - _LZNV_ERROR_INVALID_BUFFER_SIZE
/// - _LZNV_ERROR_EXPORTED_MAIN_FUNC_NOT_FOUND
/// - _LZNV_ERROR_INVALID_PROCESS_SIZE
int32_t LZNV_SDK_COM_Obj_MFC_App_Client_Dlg::LZNV_Encode_File_wCOM_Obj(LZNV_COM_Obj::ILZNV_COM_ObjPtr pLZNV_COM_Object_obj,
const uint8_t _encoding_method, const uint8_t _memory_level, // chunk_size == 0 -> read whole file in memory
const wchar_t* _wchr_filename_to_compress, const wchar_t* _wchr_output_filename)
{
HRESULT _hres = S_OK; // ((HRESULT)0L)
ASSERT(pLZNV_COM_Object_obj);
if (pLZNV_COM_Object_obj == nullptr) {
return 0;
}
ASSERT(_wchr_output_filename);
ASSERT(_wchr_filename_to_compress);
if ((!_wchr_filename_to_compress) || (!_wchr_output_filename)) {
MessageBox(L"LZNV DLL passed NULL parameters...", L"Error", IDOK);
return 1;
}
ASSERT(_encoding_method < _LZNV_MAX_LZ_ALGORITHMS);
ASSERT(_memory_level < _LZNV_MAX_BUFFER_SIZE_INDX);
{
LZNV_FILE_COMMAND_PARAMS _com_obj_file_cmd_struct = { 0 };
_com_obj_file_cmd_struct._encoding_method = _encoding_method;
_com_obj_file_cmd_struct._memory_level = _memory_level;
_com_obj_file_cmd_struct._command_to_execute = _LZNV_COMMAND_ENCODE;
_com_obj_file_cmd_struct._cpu_priority_level = _LZNV_NORMAL_PRIORITY_CLASS;
ASSERT(_wchr_filename_to_compress);
wcsncpy_s(_com_obj_file_cmd_struct._source_file_path, _wchr_filename_to_compress, _LZNV_MAXPATH_);
ASSERT(_wchr_output_filename);
wcsncpy_s(_com_obj_file_cmd_struct._target_file_path, _wchr_output_filename, _LZNV_MAXPATH_);
if (pLZNV_COM_Object_obj)
{
_hres = pLZNV_COM_Object_obj->LZNV_Main_((LZNV_COM_Obj::_LZNV_FILE_PARAM_TYPE*)&_com_obj_file_cmd_struct); //"->" overloading in action
ASSERT(SUCCEEDED(_hres));
}
}
CString csStrResult;
csStrResult.Format(L"LZNV COM Obj returned result = %d", (int32_t)_hres);
m_stEncodeResult.SetWindowText(csStrResult);
return (int32_t)_hres;
}