在终端服务器中打印原始数据
Printing Raw Data in Terminal Server
场景如下:
- 我有一个Windows Server 2008与终端服务器(没有域控制器,没有加入到域)
- 我有一台Windows XP SP3更新的客户端机器。.NET 3.0 SP1和.NET 4.0)
- 我正在使用Embarcadero c++ Builder (BCB6)
- 我有一个票据打印机(热敏打印机,POS打印机,爱普生,斑马等)
当我连接到终端服务器,打印机工作正常。我试着打印一个测试页。
当我使用我的软件在本地计算机上发送终端服务器中的原始数据时,我得到这个错误:
Windows Presentation Foundation terminal server print W has encountered a
problem and needs to close. We are sorry for the inconvenience.
我遵循了这个支持页面的建议,但运气不好。
我过去是直接打印到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;
}
我从微软的支持中复制了这段代码。我还尝试将"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++ 打印包含数据结构的数组
- 打印原始阵列和更改的阵列
- C++:将值赋值给原始数据类型(例如布尔值)是原子操作吗?
- 从USBPcap库读取原始数据
- 如何在c++中打印原始std::string/c样式的字符串
- BoostSpirit.Qi-针对原始数据类型进行边界检查
- 面临在 if 语句之外打印变量数据的问题 完成使用 Qt 编程
- Qt - 将空指针(原始数据)转换为 QImage 并将其显示在标签上
- 使用 QDataStream 对原始数据进行反序列化
- 如果构造函数和析构函数可以获取和显示(打印)数据,为什么我们需要 getter 和 setter?
- 当原始数据是常量时,修改指针指向的位置是 UB 吗?
- 将文件目录打印到数据结构中
- 如何关闭用于在程序中打印调试数据的函数
- IMAGE_SECTION_HEADER的虚拟地址和指针到原始数据的差异
- 直接从 RAM 发送原始数据
- MEX C++原始数据访问
- 服务器客户端通过原始数据错误C 发送接收结构
- 如何从C 中的卷曲中获取原始数据
- 如何打印QImage的所有原始数据,以便在内存中进行比较
- 在终端服务器中打印原始数据