シナリオは次のとおりです。
- ターミナルサーバーを備えたWindowsServer2008を使用しています(ドメインコントローラーなし、ドメインへの参加なし)
- Windows XP SP3が更新されたクライアントマシンがあります(.NET 3.0SP1および.NET4.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;
}
このコードは、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();
これは私がエンバカデロフォーラムで見つけた例です。
TsWpfWrp.exeも確認しました。サーバー内のものに置き換えてみましたが、何も実行されず、エラーが送信されず、データも送信されません。
これを行う別の方法はありますか?コードに何か問題がありますか?
私はどんな助けや洞察にも感謝します。