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