1
我得到的打印机驱动程序在用TSCLIB.dll openport方法打印时没有指定错误。我的代码看起来像这样打印机驱动程序没有用TSCLib.dll指定
public partial class TSCPrint : Form
{
[DllImport("TSCLIB.dll", EntryPoint = "about", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool about();
[DllImport("TSCLIB.dll", EntryPoint = "openport", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool openport(string printer);
[DllImport("TSCLIB.dll", EntryPoint = "barcode")]
public static extern int barcode(string x, string y, string type,
string height, string readable, string rotation,
string narrow, string wide, string code);
[DllImport("TSCLIB.dll", EntryPoint = "clearbuffer")]
public static extern int clearbuffer();
[DllImport("TSCLIB.dll", EntryPoint = "closeport")]
public static extern int closeport();
[DllImport("TSCLIB.dll", EntryPoint = "downloadpcx")]
public static extern int downloadpcx(string filename, string image_name);
[DllImport("TSCLIB.dll", EntryPoint = "formfeed")]
public static extern int formfeed();
[DllImport("TSCLIB.dll", EntryPoint = "nobackfeed")]
public static extern int nobackfeed();
[DllImport("TSCLIB.dll", EntryPoint = "printerfont")]
public static extern int printerfont(string x, string y, string fonttype,
string rotation, string xmul, string ymul,
string text);
[DllImport("TSCLIB.dll", EntryPoint = "printlabel")]
public static extern int printlabel(string set, string copy);
[DllImport("TSCLIB.dll", EntryPoint = "sendcommand")]
public static extern int sendcommand(string printercommand);
[DllImport("TSCLIB.dll", EntryPoint = "setup")]
public static extern int setup(string width, string height,
string speed, string density,
string sensor, string vertical,
String offset);
[DllImport("TSCLIB.dll", EntryPoint = "windowsfont")]
public static extern int windowsfont(int x, int y, int fontheight,
int rotation, int fontstyle, int fontunderline,
string szFaceName, string content);
public TSCPrint()
{
InitializeComponent();
about();
}
private void button1_Click(object sender, EventArgs e)
{
openport("USB003");
setup("100", "63.5", "4", "8", "0", "0", "0"); // Setup the media size and sensor type info
clearbuffer(); // Clear image buffer
barcode("100", "100", "128", "100", "1", "0", "2", "2", "Barcode Test"); // Drawing barcode
printerfont("100", "250", "3", "0", "1", "1", "Print Font Test"); // Drawing printer font
windowsfont(100, 300, 24, 0, 0, 0, "ARIAL", "Windows Arial Font Test"); // Draw windows font
//downloadpcx ("UL.PCX", "UL.PCX"); // Download PCX file into printer
//sendcommand ("PUTPCX 100,400, /" UL.PCX/""); // Drawing PCX graphic
printlabel("1", "1"); // Print labels
closeport(); // Close specified printer driver
}
}
}
我有点晚了,但我现在发现了这个线程。你还有这个问题吗?与C# – Roman 2015-01-12 09:54:58
是的,但相同的代码工作VisualBasic,所以我添加了一个VB.NET库类到我的项目。不过,如果你知道c#有什么问题,请告诉我。谢谢!! – 2015-01-16 05:49:31
我在'about'和'openport'方法中使用相同的类,但没有'SetLastError'且没有'CharSet'。我不知道这是做什么。你尝试删除它吗? – Roman 2015-01-16 07:29:36