/*$T BYBARP~1.H GC 1.137 09/13/05 08:37:52 */
#ifndef ByBarPrinterH
#define ByBarPrinterH
#include "vcl.h"
#define BPLA_OK 1000 //一切正常
///
#define BPLA_COMERROR 1001 //通讯错或者未联接打印机
#define BPLA_PARAERROR 1002 //参数错误
#define BPLA_FILEOPENERROR 1003 //文件打开错误
#define BPLA_FILEREADERROR 1004 //文件读错误
#define BPLA_FILEWRITEERROR 1005 //文件写错误
#define BPLA_FILEERROR 1006 //文件不合要求
#define BPLA_NUMBEROVER 1007 //指定的接收信息数量过大
#define BPLA_IMAGETYPEERROR 1008 //图象文件格式不正确
#define BPLA_PAPERSHORT 1009 //缺纸
#define BPLA_RIBBIONSHORT 1010 //缺色带
#define BPLA_BUSY 1011 //解释器忙
#define BPLA_PAUSE 1012 //暂停
///中
#define BPLA_HEADHEAT 1013 //打印头过热
#define BPLA_HEADOVER 1014 //打印头抬起
#define BPLA_CUT 1015 //切刀错
#define BPLA_READERROR 1016 //read error
//打开端口
typedef int (__stdcall *mBY_Open_Port) (int devtype, int porttype, char *opencode, int codelength, int baudrate);
//打印
typedef int (__stdcall *mBY_Print_Label)
(
int LabelType,
const char *JiDaJu,
const char *FenFaJu,
const char *TiaoMaXinXi,
const char *HaoMa,
const char *JianShu,
const char *ZhongLiang,
const char *ZhuanKouJuDaiHao,
const char *XingHao,
const char *BeiZhu,
const char *BiaoPaiBianHao,
const char *ZhongLeiJianCheng,
const char *BenZhuan,
int Pieces
);
//查询状态
typedef int (__stdcall *mBY_Query_Status) ();
//关闭端口
typedef int (__stdcall *mBY_Close_Port) (char *closecode, long codelength);
class PACKAGE CByBarPrinter
{
public:
long OpenPort(long nPcIndex, long nPortIndex, long baudrate);
void ClosePort(void);
long PrintLabel
(
long LabelType,
String JiDaJu,
String FenFaJu,
String TiaoMaXinXi,
String HaoMa,
String JianShu,
String ZhongLiang,
String ZhuanKouJuDaiHao,
String XingHao,
String BeiZhu,
String BiaoPaiBianHao,
String ZhongLeiJianCheng,
String BenZhuan,
long Pieces
);
CByBarPrinter(void);
long GetStatus(void);
private:
HINSTANCE m_hDll;
bool LoadLib(void);
};
#endif
/*$T BYBARP~1.CPP GC 1.137 09/13/05 08:37:52 */
#pragma hdrstop
#include "ByBarPrinter.h"
/* ---------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------- */
CByBarPrinter::CByBarPrinter(void)
{
m_hDll = NULL;
}
/* ---------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------- */
bool CByBarPrinter::LoadLib(void)
{
if(m_hDll == NULL) m_hDll = ::LoadLibrary("byprndll.dll");
if(m_hDll == NULL)
return false;
else
return true;
}
/* ---------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------- */
long CByBarPrinter::OpenPort(long nPcIndex, long nPortIndex, long baudrate)
{
long retCode;
if(!LoadLib())
{
retCode = -2;
return retCode;
}
mBY_Open_Port BY_Open_Port;
BY_Open_Port = (mBY_Open_Port) GetProcAddress(m_hDll, "BY_Open_Port");
if(BY_Open_Port == NULL)
{
retCode = -1;
}
else
{
String szCom;
szCom = "COM";
szCom += IntToStr(nPortIndex);
int nLen = szCom.Length();
retCode = BY_Open_Port(nPcIndex, nPortIndex, szCom.c_str(), nLen, 19200);
}
return retCode;
}
/* ---------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------- */
void CByBarPrinter::ClosePort(void)
{
if(!LoadLib()) return;
mBY_Close_Port BY_Close_Port;
BY_Close_Port = (mBY_Close_Port) GetProcAddress(m_hDll, "BY_Close_Port");
char CloseCode[50];
int CodeLength = 0;
memset(CloseCode, 0, 50);
BY_Close_Port(CloseCode, CodeLength);
//FreeLibrary(m_hDll);
delete[] CloseCode;
return;
}
/* ---------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------- */
long CByBarPrinter::PrintLabel
(
long LabelType,
String JiDaJu,
String FenFaJu,
String TiaoMaXinXi,
String HaoMa,
String JianShu,
String ZhongLiang,
String ZhuanKouJuDaiHao,
String XingHao,
String BeiZhu,
String BiaoPaiBianHao,
String ZhongLeiJianCheng,
String BenZhuan,
long Pieces
)
{
long retCode;
if(!LoadLib())
{
retCode = -2;
return retCode;
}
//USES_CONVERSION;
mBY_Print_Label BY_Print_Label;
BY_Print_Label = (mBY_Print_Label) GetProcAddress(m_hDll, "BY_Print_Label");
if(BY_Print_Label == NULL)
{
retCode = -1;
return S_OK;
}
retCode = BY_Print_Label
(
LabelType,
JiDaJu.c_str(),
FenFaJu.c_str(),
TiaoMaXinXi.c_str(),
HaoMa.c_str(),
JianShu.c_str(),
ZhongLiang.c_str(),
ZhuanKouJuDaiHao.c_str(),
XingHao.c_str(),
BeiZhu.c_str(),
BiaoPaiBianHao.c_str(),
ZhongLeiJianCheng.c_str(),
BenZhuan.c_str(),
Pieces
);
return retCode;
}
/* ---------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------- */
long CByBarPrinter::GetStatus(void)
{
long state;
if(!LoadLib())
{
state = -1;
return state;
}
mBY_Query_Status BY_Query_Status;
BY_Query_Status = (mBY_Query_Status) GetProcAddress(m_hDll, "BY_Query_Status");
if(BY_Query_Status == NULL)
state = -1;
else
state = BY_Query_Status();
return state;
}
#pragma package(smart_init)
posted on 2005-10-31 13:54
surffish 阅读(243)
评论(0) 编辑 收藏