博思得(POSTEK)打标签程序DEMO(C++版本)
一、头文件
function.h
#ifndef FUNCTION_H
#define FUNCTION_H
typedef int (*fPTK_OpenUSBPort)(unsigned int);
typedef int (*fPTK_CloseUSBPort)();
typedef int (*fPTK_PrintLabel)(unsigned int,unsigned int);
typedef int (*fPTK_DrawText)(unsigned int , unsigned int ,unsigned int , unsigned int ,
unsigned int , unsigned int ,char , const char* );
typedef int (*fPTK_ClearBuffer)();
typedef int (*fPTK_SetLabelHeight)(unsigned int lheight, unsigned int gapH,
int gapOffset,bool bFlag);
typedef int (*fPTK_SetLabelWidth)(unsigned int lwidth);
typedef int (*fPTK_DrawText_TrueType)(unsigned int x, unsigned int y, unsigned int FHeight, unsigned int
FWidth,const char* FType, unsigned int Fspin, unsigned int FWeight, bool FItalic,bool FUnline, bool FStrikeOut,
const char* data);
typedef int (*fPTK_DrawLineOr)(unsigned int px,unsigned int py,
unsigned int plength,unsigned int pH);
typedef int (*fPTK_SetDirection)(char direct);
typedef int (*fPTK_SetDarkness)(unsigned int id);
typedef int (*fPTK_SetPrintSpeed)(unsigned int px);
typedef int (*fPTK_DrawBar2D_QR)(unsigned int x,unsigned int y,
unsigned int w, unsigned int v,
unsigned int o, unsigned int r,
unsigned int m, unsigned int g,
unsigned int s,const char* pstr);
typedef int (*fPTK_SetCharSets)(unsigned int BitValue,char CharSets,const char* CountryCode);
#endif // FUNCTION_H
二、主程序
main.cpp
#include "function.h"
#include <iostream>
#include <windows.h>
HMODULE hDLL = LoadLibrary("CDFPSK.dll");//加载dll,将dll放在该工程根路径即可
fPTK_OpenUSBPort PTK_OpenUSBPort = NULL;
fPTK_CloseUSBPort PTK_CloseUSBPort = NULL;
fPTK_PrintLabel PTK_PrintLabel = NULL;
fPTK_DrawText PTK_DrawText = NULL;
fPTK_ClearBuffer PTK_ClearBuffer = NULL;
fPTK_SetLabelHeight PTK_SetLabelHeight = NULL;
fPTK_SetLabelWidth PTK_SetLabelWidth = NULL;
fPTK_DrawText_TrueType PTK_DrawText_TrueType= NULL;
fPTK_DrawLineOr PTK_DrawLineOr = NULL;
fPTK_SetDirection PTK_SetDirection = NULL;
fPTK_SetDarkness PTK_SetDarkness = NULL;
fPTK_SetPrintSpeed PTK_SetPrintSpeed = NULL;
fPTK_DrawBar2D_QR PTK_DrawBar2D_QR = NULL;
fPTK_SetCharSets PTK_SetCharSets = NULL;
int main() {
PTK_CloseUSBPort = (fPTK_CloseUSBPort)GetProcAddress(hDLL,"PTK_CloseUSBPort");
PTK_OpenUSBPort= (fPTK_OpenUSBPort)GetProcAddress(hDLL,"PTK_OpenUSBPort");
PTK_ClearBuffer= (fPTK_ClearBuffer)GetProcAddress(hDLL,"PTK_ClearBuffer");
PTK_SetCharSets= (fPTK_SetCharSets)GetProcAddress(hDLL,"PTK_SetCharSets");
PTK_SetLabelHeight= (fPTK_SetLabelHeight)GetProcAddress(hDLL,"PTK_SetLabelHeight");
PTK_ClearBuffer= (fPTK_ClearBuffer)GetProcAddress(hDLL,"PTK_ClearBuffer");
PTK_SetLabelWidth= (fPTK_SetLabelWidth)GetProcAddress(hDLL,"PTK_SetLabelWidth");
PTK_SetLabelHeight= (fPTK_SetLabelHeight)GetProcAddress(hDLL,"PTK_SetLabelHeight");
PTK_SetDirection= (fPTK_SetDirection)GetProcAddress(hDLL,"PTK_SetDirection");
PTK_SetDarkness= (fPTK_SetDarkness)GetProcAddress(hDLL,"PTK_SetDarkness");
PTK_SetPrintSpeed= (fPTK_SetPrintSpeed)GetProcAddress(hDLL,"PTK_SetPrintSpeed");
PTK_DrawText_TrueType= (fPTK_DrawText_TrueType)GetProcAddress(hDLL,"PTK_DrawText_TrueType");
PTK_DrawLineOr= (fPTK_DrawLineOr)GetProcAddress(hDLL,"PTK_DrawLineOr");
PTK_DrawText= (fPTK_DrawText)GetProcAddress(hDLL,"PTK_DrawText");
PTK_DrawBar2D_QR= (fPTK_DrawBar2D_QR)GetProcAddress(hDLL,"PTK_DrawBar2D_QR");
PTK_PrintLabel= (fPTK_PrintLabel)GetProcAddress(hDLL,"PTK_PrintLabel");
PTK_OpenUSBPort(255);
PTK_ClearBuffer();
PTK_SetCharSets (8,'G',"001"); //第二个参数设置为字符集编码方式,G为GBK;U为UTF-8
PTK_SetLabelHeight(240, 20, 0, false); // 设置打印标签高度和间隙或黑标等(单位为像素点)
PTK_SetLabelWidth(720); // 设置打印标签宽度(单位为像素点)
PTK_SetDirection('B');
PTK_SetDarkness(10); // 设置打印头发热温度
PTK_SetPrintSpeed(5); // 设置打印机打印速度
PTK_DrawText_TrueType(50, 30, 48, 0,"黑体", 1, 400, false,false,false,"POSTEK博思得黑体");
PTK_DrawLineOr(58, 130, 500, 3);
PTK_DrawText(30, 80, 0, 6, 2, 2, 'N', "测试打印文本6,ABC123");
PTK_DrawBar2D_QR(50, 150, 180, 180, 0, 3, 2, 0, 0, "Postek Electronics Co., Ltd.");
PTK_PrintLabel(1,1);
return 1;
}