gpt4 book ai didi

c++ - 在终端服务器中打印原始数据

转载 作者:行者123 更新时间:2023-11-28 08:13:34 24 4
gpt4 key购买 nike

场景如下:

  • 我有一台带终端服务器的 Windows Server 2008(没有域 Controller ,没有加入域)
  • 我有一台更新了 Windows XP SP3(.NET 3.0 SP1 和 .NET 4.0)的客户端机器
  • 我正在使用 Embarcadero C++Builder (BCB6)
  • 我有票据打印机(热敏打印机、POS 打印机、Epson、Zebra 等)

当我连接到终端服务器时,打印机工作正常。我测试了打印测试页。

当我在本地计算机上使用我的软件发送终端服务器中的原始数据时,出现此错误:

Windows Presentation Foundation terminal server print W has encountered a
problem and needs to close. We are sorry for the inconvenience.

我听从了这个 support page 的建议没有运气。

我以前直接打印到 LPT1:,但是在 Windows Server 2008 中,这项工作变得越来越困难,所以我们必须改变我们打印到这种打印机的方式。

这是我正在使用的代码。我在本地测试它工作正常,但在终端服务器上不起作用:

bool TForm1::RawDataToPrinter(char* szPrinterName, char* lpData, unsigned int dwCount )
{
int BytesWritten;
HANDLE hPrinter;
TDocInfo1 DocInfo;
bool bStatus = false;
int dwJob = 0;
unsigned long dwBytesWritten = 0;

// Open a handle to the printer.
bStatus = OpenPrinter( szPrinterName, &hPrinter, NULL );

if( bStatus )
{
// Fill in the structure with info about this "document."
DocInfo.pDocName = "My Document";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "RAW";

// to indicate that the application will be sending document data to the printer.
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo );

if ( dwJob > 0 )
{
// Start a page.
bStatus = StartPagePrinter( hPrinter );
bStatus = true;

if( bStatus )
{
// Send the data to the printer.
bStatus = WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten );
EndPagePrinter ( hPrinter );
}

// Inform the spooler that the document is ending.
EndDocPrinter( hPrinter );
}
// Close the printer handle.
ClosePrinter( hPrinter );
}
// Check to see if correct number of bytes were written.
if (!bStatus || (dwBytesWritten != dwCount))
bStatus = false;
else
bStatus = true;

return bStatus;
}

我从 Microsoft 支持的示例中复制了这段代码。我也尝试将“RAW”更改为“TEXT”,但我得到了同样的错误。

我试过这段代码,因为它使用 GDI 打印:

long pageline;

char prueba[255];

Printer()->SetPrinter(ListBox1->Items->Strings[ListBox1->ItemIndex].c_str(), "WINSPOOL", "", NULL);
Printer()->BeginDoc();

pageline = 0;
while(pageline < Memo1->Lines->Count)
{
Printer()->Canvas->TextOut(10, (10 + Printer()->Canvas->TextHeight("Hi! There")) * pageline, Memo1->Lines->Strings[pageline]);
pageline++;
}

Printer()->EndDoc();

这是我在 Embarcadero 论坛中找到的示例。

我还验证了 TsWpfWrp.exe。我尝试用服务器中的那个替换它,但它什么也没做,不发送错误,但也不会发送任何数据。

还有别的办法吗?我的代码有问题吗?

我感谢任何帮助或见解。

最佳答案

我发现了问题,是 Easy Print 驱动程序,它期望在 RAW 模式下使用 XPS 规范,但我只发送文本。

我禁用了 Easy Print 以将打印机置于后备模式(类似那样),这是终端服务器所在的位置,它首先查找已安装的驱动程序,然后查找 Easy Print(这可以在高级选项中的打印机)。

现在可以了,谢谢。

关于c++ - 在终端服务器中打印原始数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8371205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com