Article View: comp.os.ms-windows.programmer.win32
Article #2190Printing With Win32 API, MSDN example gives error
From: szuchymj
Date: Sun, 04 Sep 2005 00:45
Date: Sun, 04 Sep 2005 00:45
73 lines
3828 bytes
3828 bytes
I am trying to print using the Win32 API in Delphi. The reason being
that a user has reported problems with TPrinter printing upon switching
to a certain Lexmark printer, even though other applications print
without problems. I have been able to replicate similar behaviour in a
VMWare virtual machine using Windows SP2 and the Docucom PDF driver: my
application and a simple prototype created with TPrinter do not print,
but other applications (notepad, word, IE) print just fine.
Regardless of your opinion of the quality of Docucom PDF driver or
Lexmark printers, the problem remains that other applications are
printing fine on these devices but mine is not. I am guessing these
other applications use MFC classes, Visual Basic 6.0, or the Win32 API.
Because I am using Delphi my only option of the three is Win32 API.
So, I wrote some printing code based on the MSDN example (
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_1wfn.asp
) for printing with the Win32 API. It prints without error on
everything except the Docucom PDF driver, for which it says code 6
"invalid handle" upon StartPage. Even though StartDoc works fine. What
is the key difference between my code, and other applications' code,
that causes the Docucom PDF driver to print without error?
procedure printingMain;
var
pd:TPrintDlg;
di:TDocInfo;
begin
//begin setup PRINTDLG structure
FillChar(pd, SizeOf(pd), 0);
pd.lStructSize := sizeof(pd);
pd.hWndOwner:=application.Handle;
pd.hDevMode := thandle(nil);
pd.hDevNames := thandle(nil);
pd.Flags := PD_RETURNDC;
pd.hwndOwner := Application.Handle;
pd.hDC := hdc(nil);
pd.nFromPage := 1;
pd.nToPage := 1;
pd.nMinPage := 1;
pd.nMaxPage := 10;
pd.nCopies := 1;
pd.hInstance := thandle(nil);
pd.lCustData := 0;
pd.lpfnPrintHook := nil;
pd.lpfnSetupHook := nil;
pd.lpPrintTemplateName := pchar(nil);
pd.lpSetupTemplateName := pchar(nil);
pd.hPrintTemplate := thandle(nil);
pd.hSetupTemplate := thandle(nil);
//end setup PRINTDLG structure
PrintDlg(pd);
SetAbortProc(pd.hDC, AbortProc);
//begin setup DOCINFO structure
FillChar(di, SizeOf(di), 0);
di.cbSize := sizeof(di);
di.lpszDocName := pchar('');//'Bitmap Printing Test';
di.lpszOutput := pchar('');
di.lpszDatatype := pchar('');
di.fwType := 0;
//end setup DOCINFO structure
startdoc(pd.hDC, di);
StartPage(pd.hDC);
TextOut(pd.hDC, 10, 10, pchar('test123'),length('test123'));
EndPage(pd.hDC);
EndDoc(pd.hDC);
DeleteDC(pd.hDC);
end;
function AbortProc(Prn: HDC; Error: Integer): Bool; stdcall;
begin
Application.ProcessMessages;
Result := false;
end;
Technical Details
Message-ID:
<1125794713.945948.34130@g43g2000cwa.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 113dfb,24b6e7811432affe,start X-Google-Thread: 1091e5,24b6e7811432affe,start X-Google-Attributes: gid113dfb,gid1091e5,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mail From: szuchymj@jmu.edu Newsgroups: comp.os.ms-windows.programmer.win32,borland.public.delphi.winapi Subject: Printing With Win32 API, MSDN example gives error Date: 3 Sep 2005 17:45:13 -0700 Organization: http://groups.google.com Lines: 74 Message-ID: <1125794713.945948.34130@g43g2000cwa.googlegroups.com> NNTP-Posting-Host: 66.83.218.130 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1125794719 22441 127.0.0.1 (4 Sep 2005 00:45:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 4 Sep 2005 00:45:19 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.3) Gecko/20040910,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g43g2000cwa.googlegroups.com; posting-host=66.83.218.130; posting-account=h-CzxBMAAACeKXWvd0mMfZjAXz9xvSTYFf_H1NiezujMeUnvRCeTLg