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 (将#修改为@)