急:看看,我这个打印程序哪里不对?
需要在DLL中调用一个设备的打印功能,在网上找了个例子,改写如下:
int STDMETHODCALLTYPE DC_PrintCard (DC_PrintInfo Data)
/*********************************************************************
说明: 打印卡片信息
参数: PrintCardType,打印机类型:
Data,打印数据
返回: >0,成功返回ATR长度
<0,错误码
*********************************************************************/
{
int Response;
HDC printDC;
DOCINFO docInfo;
int size=4096;
unsigned long sizeNeeded=0;
unsigned long numPrinters;
int ColHeight = 50;
int StartY = 200;
PPRINTER_INFO_1 pPrinters;
string tt;
pPrinters=(PPRINTER_INFO_1)LocalAlloc((LMEM_FIXED/LMEM_ZEROINIT),size);
int ret=EnumPrinters(PRINTER_ENUM_CONNECTIONS,NULL,1,(LPBYTE)pPrinters,size,&sizeNeeded,&numPrinters);
if(!pPrinters[0].pName)
return -1;
DeviceCapabilities(pPrinters[0].pName,"UG285",DC_ENUMRESOLUTIONS,pps,NULL);
// 第 1步:获得打印机的 DC
printDC = CreateDC(NULL,pPrinters[0].pName, NULL, NULL);
// 第 2步:调用 StartDoc()
docInfo.cbSize = sizeof(docInfo) ;
docInfo.lpszDocName =NULL;
docInfo.lpszOutput = NULL;
docInfo.lpszDatatype = NULL;
docInfo.fwType = 0;
Response = StartDoc(printDC, &docInfo) ;
if (Response <= 0)
return-2;
// 第3步:调用StartPage()
Response = StartPage(printDC);
if (Response <= 0)
return -3;
// 第4步:打印数据
tt = Data.PR_ICCardNo ;//身份证号
TextOut(printDC, 150,StartY+ColHeight,tt, tt.length );
// 第5步:调用EndPage()
Response = EndPage(printDC);
if (Response <= 0)
return -4;
// 第6步:调用EndDOC()
EndDoc(printDC);
return S_OK;
}
但是,编译通不过,错误代码如下:
error C2065: 'PPRINTER_INFO_1' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'pPrinters'
error C2065: 'pPrinters' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'LocalAlloc'
error C2065: 'EnumPrinters' : undeclared identifier
error C2065: 'PRINTER_ENUM_CONNECTIONS' : undeclared identifier
error C2109: subscript requires array or pointer type
error C2228: left of '.pName' must have class/struct/union type
error C2109: subscript requires array or pointer type
error C2228: left of '.pName' must have class/struct/union type
error C2065: 'pps' : undeclared identifier
error C2109: subscript requires array or pointer type
error C2228: left of '.pName' must have class/struct/union type
error C2664: 'TextOutA' : cannot convert parameter 4 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
因为对该方面不是很了解,请高手帮忙了,或者,能提供个可以实现打印票据功能的简单的例子,谢谢先!