
#ifndef EncLib_H
#define EncLib_H

//-- type declarations -------------------------------------------------------
typedef bool TMatrix[144][144];
typedef unsigned char Byte;
//-- var, const, procedure ---------------------------------------------------

// possible param value for SetDefaultEncodeType

const int encAuto     =    0  ;  // Default
const int encC40      =  230  ;
const int encBase256  =  231  ;
const int encANSIX12  =  238  ;
const int encText     =  239  ;
const int encEDIFACT  =  240  ;
const int encASCII    =  254  ;



// possible first param value for CheckMatrixSize

const int  ms_auto       =  -1 ;
const int  ms_10_10      =   0 ;
const int  ms_12_12      =   1 ;
const int  ms_14_14      =   2 ;
const int  ms_16_16      =   3 ;
const int  ms_18_18      =   4 ;
const int  ms_20_20      =   5 ;
const int  ms_22_22      =   6 ;
const int  ms_24_24      =   7 ;
const int  ms_26_26      =   8 ;
const int  ms_32_32      =   9 ;
const int  ms_36_36      =  10 ;
const int  ms_40_40      =  11 ;
const int  ms_44_44      =  12 ;
const int  ms_48_48      =  13 ;
const int  ms_52_52      =  14 ;
const int  ms_64_64      =  15 ;
const int  ms_72_72      =  16 ;
const int  ms_80_80      =  17 ;
const int  ms_88_88      =  18 ;
const int  ms_96_96      =  19 ;
const int  ms_104_104    =  20 ;
const int  ms_120_120    =  21 ;
const int  ms_132_132    =  22 ;
const int  ms_144_144    =  23 ;

const int  ms_18_8       =  24 ;
const int  ms_32_8       =  25 ;
const int  ms_26_12      =  26 ;
const int  ms_36_12      =  27 ;
const int  ms_36_16      =  28 ;
const int  ms_48_16      =  29 ;



//Function's prototypes


typedef void (__stdcall *TClearEncode)(void);
//Prepares the encoding software for new encoding.

typedef void (__stdcall *TSetDefaultEncodeType)(int EncodeType);
//Sets a type of encoding (look above)

typedef void (__stdcall *TAddToEncode)(const char * Source);
//Adds array of characters with null terminator to the message for encode.
//It can be called several times.

typedef void (__stdcall *TAddBufToEncode)(const unsigned char * Source, int Length);
//Adds array of any symbols by length to the message for encode.
//It can be called several times.


typedef void  (__stdcall *TSetStructAppend)(unsigned char Pos,unsigned char Count,int FI);

// 6.6
// Count  --  Total Number of Matrix Symbols
// Pos    --  Symbol Position
// FI     --  File Identification (1--64516)
//
//  call before Make_ecc200

typedef  int (__stdcall *TCheckMatrixSize)(int NM, int &Height, int &Width);
/*
Checks or sets depending on value of parameter 1 the size of
Data Matrix symbol in modules (elementary cells).
For parameter 1 look above.
Input parameter:
In case of parameter 1 is set to "ms_auto", the function calculates minimal
possible size of the Data Matrix symbol by inserting special switch latches of encodation in optimal positions of the initiall message

In the all other cases the function checks whether the message could be encoded in the Data Matrix symbol with its size set by parameter 1. (In these cases the parameter 1 is an index
of possible Data Matrix symbols )

Output parameters:
Height, Width - height and width of Data Matrix symbol in modules (elementary cells)
The function returns the following results:
> 0   Everything is OK, result one of the const values ms_10_10 .. ms_144_144 ,...,
                                                       ms_18_8 .. ms_48_16
-1    Error  Too long text for this matrix size
-2    Error  Too long text
-3    Error  Unresolved character  for ANSIX12 encodation
-4    Error  Unresolved character  for Edifact encodation
*/


typedef void (__stdcall *TMake_ecc200)(TMatrix &Matrix);
/*Gets the matrix of a Data Matrix symbol
  (array[144][144] each 0/1 of its value corresponts to
  an white or black module of the Data Matrix symbol)
*/

typedef void (__stdcall *TMapToCanvas)(TMatrix &Matrix,int Height, int Width, HDC Destination, int LeftMargin, int TopMargin	, int Step, int PatternSize, int Type);
/*
An auxiliary function
Draws an Data Matrix symbol on  "h_Dest" device context
Input parameters
Matrix      - matrix of DataMatrix symbol (look Make_ecc200)
h_Dest      - Handle of an device context
LeftMargin  - left position of the Data Matrix symbols (in pixels)
TopMargin   - top position of the Data Matrix symbols (in pixels)
Step        - step between neighbouring modules of Data Matrix symbol(in pixels). Can be more or less than size of the modules.

PatternSize - size of a module (one side of square module) of the Data Matrix symbol(in pixels)
Type        - Zero, if the square module
              One, if the round module
*/


class TEncLib
{

public:
 TClearEncode           ClearEncode;
 TSetDefaultEncodeType  SetDefaultEncodeType;
 TAddToEncode           AddToEncode;
 TAddBufToEncode        AddBufToEncode;
 TCheckMatrixSize       CheckMatrixSize;
 TMake_ecc200           Make_ecc200;
 TMapToCanvas           MapToCanvas;
 TSetStructAppend       SetStructAppend;
private:
  HINSTANCE   dllinstance;

public:
  TEncLib() {
    dllinstance = ::LoadLibrary("EncLib.dll");
    if (dllinstance!=NULL) {
      Make_ecc200            = (TMake_ecc200              )::GetProcAddress(dllinstance,"Make_ecc200");
      SetDefaultEncodeType   = (TSetDefaultEncodeType     )::GetProcAddress(dllinstance,"SetDefaultEncodeType");
      CheckMatrixSize        = (TCheckMatrixSize          )::GetProcAddress(dllinstance,"CheckMatrixSize");
      MapToCanvas            = (TMapToCanvas              )::GetProcAddress(dllinstance,"MapToCanvas");
      ClearEncode            = (TClearEncode              )::GetProcAddress(dllinstance,"ClearEncode");
      AddToEncode            = (TAddToEncode              )::GetProcAddress(dllinstance,"AddToEncode");
      AddBufToEncode         = (TAddBufToEncode           )::GetProcAddress(dllinstance,"AddBufToEncode");
      SetStructAppend        = (TSetStructAppend          )::GetProcAddress(dllinstance,"SetStructAppend");
    }
  };
 ~TEncLib()
  {
    if (dllinstance)
      ::FreeLibrary(dllinstance);
  }


private:
  TEncLib(const TEncLib&);
  TEncLib& operator=(const TEncLib&);
};

//-- end unit ----------------------------------------------------------------
#endif	// EncLib
