Hallo Liebe Delphi Gemeinde
Ich versuche gerade auf einem Nadeldrucker mit Endlospapier auszudrucken jedoch macht er mit immer wenn ich eine Zeile drucke ein Formfeed und zieht eine ganze "Seite" des Endlospapiers durch.
Nach anfrage beim Druckerhersteller hieß es das Endlosdruck unter Windows XP eigentlich nicht mehr funktioniert!
Nach einigem suchen habe ich dann den folgenden KnowledgeBase Artikel von Microsoft gefunden.
support.microsoft.com/kb/124649/en-us
Dort ist eine Treiberdatei zum Download angeboten und ein Softwarebeispiel wie man damit Zeichen auf dem Drucker ausgibt,
jedoch ist das beispiel in C verfasst ich brauche jedoch die Funktion in Delphi.
Der Ursprungsquellcode sieht so aus:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95:
| // The Abort Procedure for printing (a generic AbortProc) // This procedure needs to listed be in the Exports section // of the .def file BOOL CALLBACK AbortProc( HDC hDC, int Error ) { MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, TRUE)) { TranslateMessage(&msg); DispatchMessage(&msg); } return TRUE; }
// The function that prints one line without formfeed BOOL PrintLineNow( char *pData, WORD cbBytes ) { #define LINEBUFFER_LENGTH 80 //or dynamically alloc enough space HDC hDC; char pOutput[LINEBUFFER_LENGTH+sizeof(WORD)]; DOCINFO di; ABORTPROC lpfnAbortProc;
// Buffer size is LINEBUFFER_LENGTH bytes if( cbBytes > LINEBUFFER_LENGTH ) return FALSE;
// Get the DC using the RAW.DRV driver if( (hDC = CreateDC( "RAW", NULL, "LPT1", NULL ) ) == NULL ) return FALSE;
// Set up an Abort Procedure if((lpfnAbortProc = MakeProcInstance(AbortProc, hInst)) == NULL) { DeleteDC( hDC ); return FALSE; } if( SetAbortProc( hDC, lpfnAbortProc ) <= 0 ) { DeleteDC( hDC ); FreeProcInstance( lpfnAbortProc ); return FALSE; }
// Start a Document di.cbSize = sizeof( DOCINFO ); di.lpszDocName = "MyDoc"; di.lpszOutput = NULL; if( StartDoc( hDC, &di ) <= 0 ) { DeleteDC( hDC ); FreeProcInstance( lpfnAbortProc ); return FALSE; }
// The start of a page if( StartPage( hDC ) <= 0 ) { DeleteDC( hDC ); FreeProcInstance( lpfnAbortProc ); return FALSE; }
// Put data in the buffer and send to the printer *(WORD *)pOutput = cbBytes; memcpy( &(pOutput[sizeof(WORD)]), pData, cbBytes ); if( Escape( hDC, PASSTHROUGH, 0, pOutput, NULL ) <= 0 ) { DeleteDC( hDC ); FreeProcInstance( lpfnAbortProc ); return FALSE; }
// The end of the page if( EndPage( hDC ) < 0 ) { DeleteDC( hDC ); FreeProcInstance( lpfnAbortProc ); return FALSE; }
// End the Document if( EndDoc( hDC ) < 0 ) { DeleteDC( hDC ); FreeProcInstance( lpfnAbortProc ); return FALSE; }
// Clean up DeleteDC( hDC ); FreeProcInstance( lpfnAbortProc ); return TRUE; // Success } |
Was von mir bisher portiert wurde sieht so aus :
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101:
| // The Abort Procedure for printing (a generic AbortProc) // This procedure needs to listed be in the Exports section // of the .def file function AbortProc( HDCpla: hDC; Error: integer ):boolean; var MSGtest: msg; begin while(PeekMessage({@amp,}MSGtest, NULL, 0, 0, 1)) do begin TranslateMessage(&MSGtest); DispatchMessage(&MSGtest); end; result:= TRUE; end ;
// The function that prints one line without formfeed function PrintLineNow( pData: PChar; cbBytes:Word ):boolean; var LINEBUFFER_LENGTH :integer; //or dynamically alloc enough space HDCtest : hDC; pOutput{[LINEBUFFER_LENGTH+sizeof(WORD)]}: STRING[82]; di : DoCINFO; PointerZeiger: pointer; lpfnAbortProc : ABORTPROC; //In dieser Zeile Fehler:E2007 Konstante oder Typenbezeichner erwartet var help: string; begin LINEBUFFER_LENGTH:=80; // Buffer size is LINEBUFFER_LENGTH bytes if( cbBytes > LINEBUFFER_LENGTH )then result:= FALSE;
// Get the DC using the RAW.DRV driver if( (HDCtest = CreateDC( 'RAW', nil, 'LPT1', nil ) ) = NULL ) then result:= FALSE;
// Set up an Abort Procedure if((lpfnAbortProc := MakeProcInstance(AbortProc, hInst)) = NULL) then // In dieser Zeile // E2029 ')' erwartet, aber ':=' gefunden begin DeleteDC( HDCtest ); result:= FALSE; end; if( SetAbortProc( HDCtest, lpfnAbortProc ) <= 0 ) then begin DeleteDC( HDCtest ); FreeProcInstance( lpfnAbortProc ); result:= FALSE; end;
// Start a Document di.cbSize := sizeof( DOCINFO ); di.lpszDocName := 'MyDoc'; di.lpszOutput := nil; if( StartDoc( HDCtest, &di ) <= 0 ) then begin DeleteDC( HDCtest ); FreeProcInstance( lpfnAbortProc ); result:= FALSE; end;
// The start of a page if( StartPage( HDCtest ) <= 0 ) then begin DeleteDC( HDCtest ); FreeProcInstance( lpfnAbortProc ); result:= FALSE; end;
// Put data in the buffer and send to the printer pOutput[0] := char(LO(cbBytes)); pOutput[1] := char(HI(cbBytes)); PointerZeiger:= @(pOutput[2]); move( pData,PointerZeiger, cbBytes ); help:=pOutput; if( Escape( HDCtest, PASSTHROUGH, 0, Pchar(help), NIL ) <= 0 ) then begin DeleteDC( HDCtest ); FreeProcInstance( lpfnAbortProc ); result:= FALSE; end;
// The end of the page if( EndPage( HDCtest ) < 0 ) then begin DeleteDC( HDCtest ); FreeProcInstance( lpfnAbortProc ); result:= FALSE; end;
// End the Document if( EndDoc( HDCtest ) < 0 ) then begin DeleteDC( HDCtest ); FreeProcInstance( lpfnAbortProc ); result:= FALSE; end;
// Clean up DeleteDC( HDCtest ); FreeProcInstance( lpfnAbortProc ); result:= TRUE; // Success end; |
Nun bekomme ich folgende Fehlermeldungen:
E2007 Konstante oder Typenbezeichner erwartet
E2029 ')' erwartet, aber ':=' gefunden
Die Stellen an denen die Fehler auftreten habe ich im Quellcode kommentiert.
Ich hoffe Ihr könnt mir hierbei weiterhelfen. Wäre auch sehr dankbar wenn jemand mit besseren C Kenntnissen mir sagen könnte ob ich den Code richtig portiert habe!