#pragma once
/****************************************************************************
CONST DEFINE
****************************************************************************/
#define E_SUCCESS			0

/* Text Alignment*/
#define HPRT_TEXT_ALIGNMENT_LEFT    0
#define HPRT_TEXT_ALIGNMENT_CENTER  1
#define HPRT_TEXT_ALIGNMENT_RIGHT   2

//Text Align
#define HPRT_ALIGNMENT_LEFT         0
#define HPRT_ALIGNMENT_CENTER       1
#define HPRT_ALIGNMENT_RIGHT        2
#define HPRT_ALIGNMENT_TOP			0
#define HPRT_ALIGNMENT_BOTTOM       2

//Text Font
#define HPRT_TEXT_FONT_A            0
#define HPRT_TEXT_FONT_B            1
#define HPRT_TEXT_FONT_C            2

#define HPRT_TEXT_SIZE_0WIDTH       0
#define HPRT_TEXT_SIZE_1WIDTH       16
#define HPRT_TEXT_SIZE_2WIDTH       32
#define HPRT_TEXT_SIZE_3WIDTH       48
#define HPRT_TEXT_SIZE_4WIDTH       64
#define HPRT_TEXT_SIZE_5WIDTH       80
#define HPRT_TEXT_SIZE_6WIDTH       96
#define HPRT_TEXT_SIZE_7WIDTH       112

#define HPRT_TEXT_SIZE_0HEIGHT      0
#define HPRT_TEXT_SIZE_1HEIGHT      1
#define HPRT_TEXT_SIZE_2HEIGHT      2
#define HPRT_TEXT_SIZE_3HEIGHT      3
#define HPRT_TEXT_SIZE_4HEIGHT      4
#define HPRT_TEXT_SIZE_5HEIGHT      5
#define HPRT_TEXT_SIZE_6HEIGHT      6
#define HPRT_TEXT_SIZE_7HEIGHT      7

#define HPRT_TEXT_NORMAL_MODE            0
#define HPRT_TEXT_FONT_EMPHASIZED        2
#define HPRT_TEXT_FONT_UNDERLINE_MODE    4
#define HPRT_TEXT_FONT_REVERSE           8
#define HPRT_TEXT_FONT_DH_MODE           16
#define HPRT_TEXT_FONT_DW_MODE           32
#define HPRT_TEXT_FONT_DW_DH_MODE        48

/* Upside down mode*/
#define HPRT_UPSIDE_DOWN_MODE_ON        1
#define HPRT_UPSIDE_DOWN_MODE_OFF       0

/*Characters Font */
#define HPRT_LANG_ALP                   1
#define HPRT_LANG_JAN                   2
#define HPRT_LANG_KRO                   3
#define HPRT_LANG_SIM_CHN               4
#define HPRT_LANG_SIM_CHN_2             5
#define HPRT_LANG_TRA_CHN               6
#define HPRT_LANG_TRA_CHN_2             7

/* HRI Font */
#define HPRT_CHARACTER_FONT_A           0
#define HPRT_CHARACTER_FONT_B           1

/* Smooth Mode */
#define HPRT_CHARACTER_SMOOTH_ON        1
#define HPRT_CHARACTER_SMOOTH_OFF       0

/* Character Mode */
#define HPRT_CHARACTER_DEFAULT				   0
#define HPRT_CHARACTER_WHITE_BLACK_REVERSE_ON  1
#define HPRT_CHARACTER_WHITE_BLACK_REVERSE_OFF 0
#define HPRT_CHARACTER_UNDERLINE_MODE_ON       1
#define HPRT_CHARACTER_UNDERLINE_MODE_OFF      0
#define HPRT_CHARACTER_EMPHASIZED_MODE_ON      1
#define HPRT_CHARACTER_EMPHASIZED_MODE_OFF     0
#define HPRT_CHARACTER_DOUBLE_STRIKE_MODE_ON   1
#define HPRT_CHARACTER_DOUBLE_STRIKE_MODE_OFF  0 

/* Bar Code Type */
#define HPRT_BARCODE_TYPE_UPC_A			65
#define HPRT_BARCODE_TYPE_UPC_E			66
#define HPRT_BARCODE_TYPE_EAN13			67
#define HPRT_BARCODE_TYPE_JAN13			67
#define HPRT_BARCODE_TYPE_EAN8			68
#define HPRT_BARCODE_TYPE_JAN8			68
#define HPRT_BARCODE_TYPE_CODE39		69
#define HPRT_BARCODE_TYPE_ITF			70
#define HPRT_BARCODE_TYPE_CODABAR		71
#define HPRT_BARCODE_TYPE_CODE93		72
#define HPRT_BARCODE_TYPE_CODE128		73

#define HPRT_BARCODE_STANDARD_PDF417	101
#define HPRT_BARCODE_TRUNCATED_PDF417	102
#define HPRT_BARCODE_QRCODE1			103
#define HPRT_BARCODE_QRCODE2			104
//PDF417 Code error correction level
#define HPRT_PDF417_ERROR_SET_LEVEL  48
#define HPRT_PDF417_ERROR_SET_RATIO  49

#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_0  48
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_1  49
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_2  50
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_3  51
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_4  52
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_5  53
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_6  54
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_7  55
#define HPRT_PDF417_ERROR_CORRECTION_LEVEL_8  56

//QR Code error correction level
#define HPRT_QRCODE_ERROR_CORRECTION_LEVEL_L  48
#define HPRT_QRCODE_ERROR_CORRECTION_LEVEL_M  49
#define HPRT_QRCODE_ERROR_CORRECTION_LEVEL_Q  50
#define HPRT_QRCODE_ERROR_CORRECTION_LEVEL_H  51
/* Print HRI Position */
#define HPRT_PRINT_POSITION_HRI_NONE  0
#define HPRT_PRINT_POSITION_HRI_ABOVE 1
#define HPRT_PRINT_POSITION_HRI_BELOW 2
#define HPRT_PRINT_POSITION_HRI_BOTH  3

/* Cut Feed Mode */
#define HPRT_FULL_CUT			0
#define HPRT_PARTIAL_CUT		1

#define HPRT_CUT_MODE_NO_FEED   0
#define HPRT_CUT_MODE_FEED      1

/* Print Drawer Pin */
#define HPRT_PRINT_DRAWER_1     0
#define HPRT_PRINT_DRAWER_2     1

/* Print Drawer Time Mode*/
#define HPRT_PRINT_DRAWER_ON_TIME_100     100
#define HPRT_PRINT_DRAWER_ON_TIME_200     200
#define HPRT_PRINT_DRAWER_ON_TIME_300     300
#define HPRT_PRINT_DRAWER_ON_TIME_400     400
#define HPRT_PRINT_DRAWER_ON_TIME_500     500

/* Select print direction in page mode */
#define HPRT_PRINT_DIRECTION_LR		0			
#define HPRT_PRINT_DIRECTION_BT		1		
#define HPRT_PRINT_DIRECTION_RL		2
#define HPRT_PRINT_DIRECTION_TB		3

/* Print Image ScaleMode */
#define HPRT_PRINT_IMAGE_NORMAL				0
#define HPRT_PRINT_IMAGE_DOUBLE_WIDTH		1
#define HPRT_PRINT_IMAGE_DOUBLE_HEIGHT		2
#define HPRT_PRINT_IMAGE_QUADRUPLE			3

/* Printer Status*/
#define HPRT_STS_NORMAL				0
#define HPRT_STS_PAPEREMPTY			1
#define HPRT_STS_COVEROPEN			2
#define HPRT_STS_PAPERNEAREND		4
#define HPRT_STS_MSR_READY			8
#define HPRT_STS_SMARTCARD_READY	16
#define HPRT_STS_ERROR				32
#define HPRT_STS_NOT_OPEN			64
#define HPRT_STS_OFFLINE			128

#define  HPRT_TRACK_FULL			0
#define  HPRT_TRACK_NO_1			1
#define  HPRT_TRACE_NO_2			2
#define  HPRT_TRACE_NO_3			3
#define  HPRT_TRACE_NO_1_2			4
/* Encrypt Head */
#define HPRT_MSR_CRYPT_FIX		1
#define HPRT_MSR_CRYPT_DUKPT	2

#define HPRT_MSR_CRYPT_NONE		0
#define HPRT_MSR_CRYPT_3DES		1
#define HPRT_MSR_CRYPT_AES		2

typedef struct hprt_printer_status_struct
{
	int     cb;
	unsigned char offline;
	unsigned char cover_open;
	unsigned char paper_nearend;
	unsigned char paper_empty;
}printerstatus;
typedef struct hprt_printer_status2_struct
{
	unsigned char offline;
	unsigned char cover_open;
	unsigned char paper_empty;
	unsigned char temperature_too_high;
	unsigned char voltage_error;
	unsigned char isbusy;
}printerstatus2;

char* cstringtocharstring(CString str);
char cstringtochar(CString str);


/******************************************************************************************
IMPORT
******************************************************************************************/
void UnloadDll();
BOOL LoadDll();

#ifdef __cplusplus
#define PRINTER_API extern "C" __declspec(dllimport)
#else
#define PRINTER_WIN32_SDK_API __declspec(dllimport)
#endif

typedef int(*FormatError)(int, int, char*, int, int);
typedef int(*PrinterCreator)(void**, const char*);
typedef int(*PrinterCreatorS)(char*);
typedef int(*PortOpen)(void*, const char*);
typedef int(*PortClose)(void*);
typedef int(*PrinterDestroy)(void*);
typedef int(*DirectIO)(void* handle, unsigned char writedata[], unsigned int writenum, unsigned char readdata[], unsigned int readnum, unsigned int* preadednum);

typedef int(*TSPL_SelfTest)(void*);
typedef int(*TSPL_BitMap)(void* , int, int , int , const char*);
typedef int(*TSPL_Setup)(void* , int , int , int , int , int , int, int );
typedef int(*TSPL_ClearBuffer)(void* );
typedef int(*TSPL_Box)(void* , int , int , int , int , int );
typedef int(*TSPL_BarCode)(void* , int , int , int , int , int , int , int , int , const char* );
typedef int(*TSPL_QrCode)(void* , int , int , int , int , int , int , int , int , const char* );
typedef int(*TSPL_Text)(void* , int , int , int , int , int , int , const char* );
typedef int(*TSPL_Print)(void* , int , int );
typedef int(*TSPL_FormFeed)(void* );
typedef int(*TSPL_SetTear)(void* , int );
typedef int(*TSPL_SetRibbon)(void*, int);
typedef int(*TSPL_Offset)(void* , int );
typedef int(*TSPL_Direction)(void* , int );


typedef int(*TSPL_Feed)(void* , int );
typedef int(*TSPL_Home)(void* );
typedef int(*TSPL_Learn)(void* );
typedef int(*TSPL_GetDllVersion)(void* );
typedef int(*TSPL_GetSN)(void* , char* );
typedef int(*TSPL_GetPrinterStatus)(void*, int*);
typedef int(*TSPL_SetCodePag)(void*, int);

extern void* hprinter;
extern HMODULE m_Dll;


extern FormatError                                  DemFormatError;
extern PrinterCreator                               DemPrinterCreator;
extern PrinterCreatorS                              DemPrinterCreatorS;
extern PrinterDestroy                               DemPrinterDestroy;
extern PortOpen                                     DemPortOpen;
extern PortClose                                    DemPortClose;
extern DirectIO                                     DemDirectIO;

extern TSPL_SelfTest                                DemSelfTest;
extern TSPL_BitMap                                  DemBitMap;
extern TSPL_Setup                                   DemSetup;
extern TSPL_ClearBuffer                             DemClearBuffer;
extern TSPL_Box                                     DemBox;
extern TSPL_BarCode                                 DemBarCode;
extern TSPL_QrCode                                  DemQrCode;
extern TSPL_Text                                    DemText;
extern TSPL_Print                                   DemPrint;
extern TSPL_FormFeed                                DemFormFeed;
extern TSPL_SetTear                                 DemSetTear;

extern TSPL_SetRibbon                               DemSetRibbon;
extern TSPL_Offset                                  DemOffset;
extern TSPL_Direction                               DemDirection;
extern TSPL_Feed                                    DemFeed;
extern TSPL_Home                                    DemHome;
extern TSPL_Learn                                   DemLearn;

extern TSPL_GetSN                                   DemGetSN;
extern TSPL_GetPrinterStatus                        DemStatus;
extern TSPL_SetCodePag                              DemCodePag;