微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

winspool.Drv ClosePrinter 实际上并不打印,但我可以在队列 c# 中看到它

如何解决winspool.Drv ClosePrinter 实际上并不打印,但我可以在队列 c# 中看到它

我的代码

// Open the printer.
if (OpenPrinter(szPrinterName,out hPrinter,defaults))
{
    // 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();
    throw new Win32Exception(dwError);
}

结果是我可以在打印机队列中看到假脱机

enter image description here

但它实际上并没有打印......打印机什么都不做......

我有 Windows 10,我的打印机连接到我的个人电脑,我正在使用 VPN 连接在其他电脑上工作。

这样我读取数据/指针

public static bool SendFiletoPrinter(string szPrinterName,string szFileName)
{
    // Open the file.
    FileStream fs = new FileStream(szFileName,FileMode.Open);
    // Create a BinaryReader on the file.
    BinaryReader br = new BinaryReader(fs);
    // Dim an array of bytes big enough to hold the file's contents.
    Byte[] bytes = new Byte[fs.Length];
    bool bSuccess = false;
    // Your unmanaged pointer.
    IntPtr pUnmanagedBytes = new IntPtr(0);
    
    int nLength;
    nLength = Convert.ToInt32(fs.Length);
    // Read the contents of the file into the array.
    bytes = br.ReadBytes(nLength);
    // Allocate some unmanaged memory for those bytes.
    pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
    // copy the managed byte array into the unmanaged array.
    Marshal.copy(bytes,pUnmanagedBytes,nLength);
    // Send the unmanaged bytes to the printer.
    bSuccess = SendBytesToPrinter(szPrinterName,nLength);
    // Free the unmanaged memory that you allocated earlier.
    Marshal.FreeCoTaskMem(pUnmanagedBytes);
    return bSuccess;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。