|
|
#include "devprinter.h"
|
|
|
#include "devprinterstr.h"
|
|
|
#include <QList>
|
|
|
#include "global.h"
|
|
|
|
|
|
//保存所有生成的 charaddrdllstr对象指针
|
|
|
QList<devprinterstr *> gprtList;
|
|
|
|
|
|
devprinterstr * GetDevprinterPtr(HANDLE phandle, bool isRemove = false)
|
|
|
{
|
|
|
devprinterstr * ptr = (devprinterstr *)phandle;
|
|
|
if(! ptr)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
for(int i=0; i<gprtList.size(); i++)
|
|
|
{
|
|
|
if (gprtList.at(i) == ptr)
|
|
|
{
|
|
|
if(isRemove)
|
|
|
{
|
|
|
gprtList.removeAt(i);
|
|
|
}
|
|
|
return ptr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
extern "C" DEVPRINTER_EXPORT HRESULT __cdecl PRN_Init()
|
|
|
{
|
|
|
return S_OK;
|
|
|
}
|
|
|
|
|
|
extern "C" DEVPRINTER_EXPORT HRESULT __cdecl PRN_UnInit()
|
|
|
{
|
|
|
return S_OK;
|
|
|
}
|
|
|
|
|
|
extern "C" DEVPRINTER_EXPORT HANDLE __cdecl PRN_CreatePrinter(int nPrnVer, char* sPrintPort,
|
|
|
int nColMax, int nLineMax, int nHeightAdj,
|
|
|
char* sPortAddr,char* sFormat, char *sCutPaper)
|
|
|
{
|
|
|
int iRet;
|
|
|
|
|
|
|
|
|
if((! sPrintPort) || (! sFormat) || (! sCutPaper))
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
if(( nColMax <1) || (nLineMax <1))
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
devprinterstr *p = new devprinterstr();
|
|
|
if (!p)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
iRet = p->PRN_CreatePrinter(nPrnVer, sPrintPort,
|
|
|
nColMax, nLineMax, nHeightAdj,
|
|
|
sPortAddr, sFormat, sCutPaper);
|
|
|
if(iRet<0)
|
|
|
{
|
|
|
delete p;
|
|
|
//Write_Log("生成打印设备失败");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
gprtList.append(p);
|
|
|
return HANDLE(p);
|
|
|
}
|
|
|
|
|
|
extern "C" DEVPRINTER_EXPORT HRESULT __cdecl PRN_Close(HANDLE hHandle)
|
|
|
{
|
|
|
devprinterstr *p = GetDevprinterPtr(hHandle,true);
|
|
|
|
|
|
if(! p)
|
|
|
{
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
p->PRN_Close();
|
|
|
delete p;
|
|
|
|
|
|
// WriteLog("关闭打印设备 设备Id = %d",(int)hHandle);
|
|
|
return S_OK;
|
|
|
}
|
|
|
|
|
|
extern "C" DEVPRINTER_EXPORT HRESULT __cdecl PRN_CheckPrinter(HANDLE hHandle, INT32 &iStatus)
|
|
|
{
|
|
|
devprinterstr *p = GetDevprinterPtr(hHandle);
|
|
|
|
|
|
if(! p)
|
|
|
{
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
return p->PRN_CheckPrinter(iStatus);
|
|
|
}
|
|
|
|
|
|
|
|
|
extern "C" DEVPRINTER_EXPORT HRESULT __cdecl PRN_Print(HANDLE hHandle, char *pInfo)
|
|
|
{
|
|
|
devprinterstr *p = GetDevprinterPtr(hHandle);
|
|
|
|
|
|
if(! p)
|
|
|
{
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
// WriteLog("打印票证 设备Id = %d,内容 = %s",(int)hHandle,pInfo);
|
|
|
return p->PRN_Print(pInfo);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
HRESULT __cdecl PRN_PaperCut(HANDLE hHandle)
|
|
|
{
|
|
|
devprinterstr *p = getdevprinterptr( hHandle);
|
|
|
|
|
|
if(! p)
|
|
|
{
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
WriteLog("打印机切纸 设备Id = %d",(int)hHandle);
|
|
|
return p->PRN_PaperCut();
|
|
|
}
|
|
|
|
|
|
char* __cdecl PRN_GetErrorStr (INT32 ErrorCode)
|
|
|
{
|
|
|
return GetErrStr(ErrorCode);
|
|
|
}
|
|
|
|
|
|
*/
|