The printed output is sent to a printer's port instead of to the requested output file when you try to print a file programmatically in Windows XP (907299)



The information in this article applies to:

  • Microsoft Windows XP Home Edition
  • Microsoft Windows XP Professional

SYMPTOMS

When you try to print a file programmatically in Microsoft Windows XP, the printed output is sent to a printer's port instead of to the requested output file. This problem occurs when all the following conditions are true:
  • You configure the printer to spool documents.
  • You use the DOCINFO.lpszOutput structure member to specify an output file for the print job.
  • The file that you specify in the DOCINFO.lpszOutput structure member is locked by another process or thread.

WORKAROUND

To work around this problem, follow these steps:
  1. Make sure that the file that you have specified is not locked by any other process or thread.
  2. Configure the printer to print directly to a port instead of to spool documents.
  3. Apply the hotfix that is discussed in the following Microsoft Knowledge Base (KB) article:

    905519 You experience problems when you try to print to a file programmatically in Windows XP

MORE INFORMATION

Steps to reproduce the problem

  1. Add a local printer that uses a new local port. For example, set the local port to a file path such as the following:

    Drive:\path\test_output.txt

  2. In the printer Properties dialog box, click Advanced, click Spool print documents so program finishes printing faster, and then click OK.
  3. Determine a file name for a second file that you want to receive the print job. For example, you may assign a file name for the DOCINFO.lpszOutput structure member as follows:

    DOCINFO.lpszOutput = Drive:\path\test2_output.prn

    Note A value for the DOCINFO.lpszOutput structure member is specified if you want to print to a file.
  4. Use a separate thread or process to open the Test2_output.prn file and to hold the file open.
  5. While the test2_output.prn file is open, try to print to the file by using the DOCINFO.lpszOutput structure member and the StartDoc function on the first thread or process.
The print job output is sent to the port that you set up in step 1 instead of to the file that you specified in the DOCINFO.lpszOutput structure member.

Modification Type:MajorLast Reviewed:11/23/2005
Keywords:kbtshoot kbprb KB907299 kbAudITPRO kbAudDeveloper