#include"stdafx.h"
#include "cpcl_printer_base.h"

char* cstringtocharstring(CString str)
{

	int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
	char* ch = new char[len + 1];
	WideCharToMultiByte(CP_ACP, 0, str, -1, ch, len, NULL, NULL);
	return ch;
}
char cstringtochar(CString str)
{
	int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
	char* ch = new char[len + 1];
	WideCharToMultiByte(CP_ACP, 0, str, -1, ch, len, NULL, NULL);
	return ch[0];
}

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

 CPCL_AddLabel                                DemAddLabel;
 CPCL_SetAlign                                DemSetAlign;
 CPCL_AddText                                 DemAddText;
 CPCL_AddBarCode                              DemAddBarCode;
 CPCL_AddBarCodeText                          DemAddBarCodeText;
 CPCL_AddQRCode                               DemAddQRCode;
 CPCL_AddPDF417                               DemAddPDF417;
 CPCL_AddBox                                  DemAddBox;
 CPCL_AddLine                                 DemAddLine;
 CPCL_AddImage                                DemAddImage;
 CPCL_AddImageData                            DemAddImageData;
 CPCL_SetFontSize                             DemSetFontSize;
 CPCL_SetDensity                              DemSetDensity;
 CPCL_SetSpeed                                DemSetSpeed;
 CPCL_SetTextSpacing                          DemSetTextSpacing;
 CPCL_SetLeftMargin                           DemSetLeftMargin;
 CPCL_SetTextBold                             DemSetTextBold;
 CPCL_SetTextUnderline                        DemSetTextUnderline;
 CPCL_Abort                                   DemAbort;
 CPCL_Print                                   DemPrint;
 CPCL_NextLabelPos                            DemNextLabelPos;
 CPCL_PreFeed                                 DemPreFeed;
 CPCL_PostFeed                                DemPostFeed;
 HMODULE m_hDll;
 void* hprinter;
 void UnloadDll()
 {
	 FreeLibrary(m_hDll);
 }
 BOOL LoadDll()
 {
	 m_hDll = LoadLibrary(_T("CPCL_SDK.dll"));
	 if (m_hDll == 0)
	 {
		 return FALSE;
	 }
	 else
	 {
		 DemFormatError = (FormatError)GetProcAddress(m_hDll, "FormatError");
		 DemPrinterCreator = (PrinterCreator)GetProcAddress(m_hDll, "PrinterCreator");
		 DemPrinterCreatorS = (PrinterCreatorS)GetProcAddress(m_hDll, "PrinterCreatorS");
		 DemPrinterDestroy = (PrinterDestroy)GetProcAddress(m_hDll, "PrinterDestroy");
		 DemPortOpen = (PortOpen)GetProcAddress(m_hDll, "PortOpen");
		 DemPortClose = (PortClose)GetProcAddress(m_hDll, "PortClose");
		 DemDirectIO = (DirectIO)GetProcAddress(m_hDll, "DirectIO");

		 DemAddLabel = (CPCL_AddLabel)GetProcAddress(m_hDll, "CPCL_AddLabel");
		 DemSetAlign = (CPCL_SetAlign)GetProcAddress(m_hDll, "CPCL_SetAlign");
		 DemAddText = (CPCL_AddText)GetProcAddress(m_hDll, "CPCL_AddText");
		 DemAddBarCode = (CPCL_AddBarCode)GetProcAddress(m_hDll, "CPCL_AddBarCode");
		 DemAddBarCodeText = (CPCL_AddBarCodeText)GetProcAddress(m_hDll, "CPCL_AddBarCodeText");
		 DemAddQRCode = (CPCL_AddQRCode)GetProcAddress(m_hDll, "CPCL_AddQRCode");
		 DemAddPDF417 = (CPCL_AddPDF417)GetProcAddress(m_hDll, "CPCL_AddPDF417");
		 DemAddBox = (CPCL_AddBox)GetProcAddress(m_hDll, "CPCL_AddBox");
		 DemAddLine = (CPCL_AddLine)GetProcAddress(m_hDll, "CPCL_AddLine");
		 DemAddImage = (CPCL_AddImage)GetProcAddress(m_hDll, "CPCL_AddImage");
		 DemAddImageData = (CPCL_AddImageData)GetProcAddress(m_hDll, "CPCL_AddImageData");
		 DemSetFontSize = (CPCL_SetFontSize)GetProcAddress(m_hDll, "CPCL_SetFontSize");
		 DemSetDensity = (CPCL_SetDensity)GetProcAddress(m_hDll, "CPCL_SetDensity");
		 DemSetSpeed = (CPCL_SetSpeed)GetProcAddress(m_hDll, "CPCL_SetSpeed");
		 DemSetTextSpacing = (CPCL_SetTextSpacing)GetProcAddress(m_hDll, "CPCL_SetTextSpacing");
		 DemSetLeftMargin = (CPCL_SetLeftMargin)GetProcAddress(m_hDll, "CPCL_SetLeftMargin");
		 DemSetTextBold = (CPCL_SetTextBold)GetProcAddress(m_hDll, "CPCL_SetTextBold");
		 DemSetTextUnderline = (CPCL_SetTextUnderline)GetProcAddress(m_hDll, "CPCL_SetTextUnderline");
		 DemAbort = (CPCL_Abort)GetProcAddress(m_hDll, "CPCL_Abort");
		 DemPrint = (CPCL_Print)GetProcAddress(m_hDll, "CPCL_Print");
		 DemNextLabelPos = (CPCL_NextLabelPos)GetProcAddress(m_hDll, "CPCL_NextLabelPos");
		 DemPreFeed = (CPCL_PreFeed)GetProcAddress(m_hDll, "CPCL_PreFeed");
		 DemPostFeed = (CPCL_PostFeed)GetProcAddress(m_hDll, "CPCL_PostFeed");
		 return TRUE;
	 }
 }