none
使用 winspool.Drv 调用打印机问题(windows10)

    问题

  • 我在使用winspool.Drv中的StartDocPrinter方法时,发现在windows10上面会修改我的默认打印机,而windows7-8上面不会有此问题。

    意思就是假设我有 打印机一,打印机二两台打印机,打印机一为默认打印机,此时我调用StartDocPrinter用打印机二打印内容,这个时候

    系统默认打印机变成了打印机二,请问如何解决,下面附上我的代码

    Int32 dwError = 0, dwWritten = 0;
    IntPtr hPrinter = new IntPtr(0);
    DOCINFOA di = new DOCINFOA();
    bool bSuccess = false; // Assume failure unless you specifically succeed.

    di.pDocName = "My C#.NET RAW Document";
    di.pDataType = "RAW";

    // Open the printer.
    if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
    {
    // Start a document.
    if (StartDocPrinter(hPrinter, 1, di))
    {
    // Start a page.
    if (StartPagePrinter(hPrinter))
    {
    // Write your bytes.
    bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
    EndPagePrinter(hPrinter);
    }
    EndDocPrinter(hPrinter);
    }
    ClosePrinter(hPrinter);
    }
    // If you did not succeed, GetLastError may give more information
    // about why not.
    if (bSuccess == false)
    {
    dwError = Marshal.GetLastWin32Error();
    }
    return bSuccess;

    2016年1月13日 4:06

答案

全部回复