2014-11-05 199 views
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 

    } 
} 
} 
+0

我有点晚了,但我现在发现了这个线程。你还有这个问题吗?与C# – Roman 2015-01-12 09:54:58

+0

是的,但相同的代码工作VisualBasic,所以我添加了一个VB.NET库类到我的项目。不过,如果你知道c#有什么问题,请告诉我。谢谢!! – 2015-01-16 05:49:31

+0

我在'about'和'openport'方法中使用相同的类,但没有'SetLastError'且没有'CharSet'。我不知道这是做什么。你尝试删除它吗? – Roman 2015-01-16 07:29:36

回答

2

你的课程看起来不错。我正在使用同一个班级,但没有SetLastError,也没有CharSet,在aboutopenport方法中。我不知道这是做什么。

上述错误在指定打印机不存在时调用。

确保您的打印机名为“USB003”存在。

openport("RS11"); 

在我的例子中,打印机“RS11”必须存在。否则它会抛出这个错误。

printer

所以去你Control Panel > All Control Panel Items > Devices and Printers,并确保您的打印机没有在Printers and Faxes存在。

相关问题