Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Printing no longer works on Windows 10


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Apr 21, 2018 12:46 AM Last Post By: Peter Below Threads: [ Previous | Next ]
Nico Callewaert

Posts: 22
Registered: 5/9/02
Printing no longer works on Windows 10  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 2:43 PM
Hi,

I have this code that worked without problem for years, until the customer switched to windows 10 and all of a sudden, it stopped working.
The purpose of the code is to select a certain printer by it's name and print a file to it. This is my code that worked before :

var
S: string;
Device, Driver, Port: array [0 .. 255] of Char;
hDeviceMode: THandle;
begin
Printer.PrinterIndex := Printer.Printers.IndexOf(<printername>);
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
ShellExecute(handle, PChar('printto'), PChar(<FileName>), PChar(S), nil, SW_HIDE);

Changing the Char to WideChar and changing the string to Widestring didn't help either :

var
S: Widestring;
Device, Driver, Port: array [0 .. 255] of WideChar;
hDeviceMode: THandle;
begin
Printer.PrinterIndex := Printer.Printers.IndexOf(<printername>);
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
ShellExecute(handle, PWideChar('printto'), PWideChar(<FileName>), PWideChar(S), nil, SW_HIDE);

Nothing is coming out of the printer.
Any idea what I'm doing wrong?

Many thanks in advance!
Best regards
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Printing no longer works on Windows 10  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 11:00 PM   in response to: Nico Callewaert in response to: Nico Callewaert
Nico Callewaert wrote:

Hi,

I have this code that worked without problem for years, until the
customer switched to windows 10 and all of a sudden, it stopped
working. The purpose of the code is to select a certain printer by
it's name and print a file to it. This is my code that worked before :

var
S: string;
Device, Driver, Port: array [0 .. 255] of Char;
hDeviceMode: THandle;
begin
Printer.PrinterIndex := Printer.Printers.IndexOf(<printername>);

HAve you verified that the printer actually appears under this name in
the Printers collection?

Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
ShellExecute(handle, PChar('printto'), PChar(<FileName>),
PChar(S), nil, SW_HIDE);

What type of file are you trying to print? The application handling
this file type may simply not support printto on windows 10, or, if you
try to print to a specific printer type (e.g. a label printer) Windows
10 may not support that anymore, if it is an older make.

--
Peter Below
TeamB

Nico Callewaert

Posts: 22
Registered: 5/9/02
Re: Printing no longer works on Windows 10  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 11:44 PM   in response to: Peter Below in response to: Peter Below
HAve you verified that the printer actually appears under this name in
the Printers collection?

What type of file are you trying to print? The application handling
this file type may simply not support printto on windows 10, or, if you
try to print to a specific printer type (e.g. a label printer) Windows
10 may not support that anymore, if it is an older make.

--
Peter Below
TeamB


Hi Peter,

The files to be printed are pictures, simply jpeg files.
The GetPrinter is fine, that's working, it's the actual ShellExecute call. Maybe I will just try if the standardprinter is working, so no need to lookup the other printer by name.
I was wondering if the code that used to work before should still work on windows 10? I mean PChar vs. PWideChar. I don't know the type of hardware, but since it's pictures, I assume it's just a normal printer. But I will verify with the customer.

Thx !

Edited by: Nico Callewaert on Apr 18, 2018 11:45 PM

Edited by: Nico Callewaert on Apr 18, 2018 11:46 PM

Edited by: Nico Callewaert on Apr 18, 2018 11:53 PM
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Printing no longer works on Windows 10 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 19, 2018 10:58 PM   in response to: Nico Callewaert in response to: Nico Callewaert
Nico Callewaert wrote:

HAve you verified that the printer actually appears under this name
in the Printers collection?

What type of file are you trying to print? The application handling
this file type may simply not support printto on windows 10, or, if
you try to print to a specific printer type (e.g. a label printer)
Windows 10 may not support that anymore, if it is an older make.

--
Peter Below
TeamB


Hi Peter,

The files to be printed are pictures, simply jpeg files.
The GetPrinter is fine, that's working, it's the actual ShellExecute
call.

Mh. On my Win10 system there is still a printto action registered for
the jpegfile file type. The command is

"%SystemRoot%\System32\rundll32.exe"
"%SystemRoot%\System32\shimgvw.dll",ImageView_PrintTo /pt "%1" "%2"
"%3" "%4"

Have your customer fire up regedit and check if there is a the registry
key HKEY_CLASSES_ROOT\jpegfile\shell\printto\command

I don't have the time right now (have to get to work) but i'll try to
remember to run a test on my system tomorrow.

Maybe I will just try if the standardprinter is working, so no
need to lookup the other printer by name. I was wondering if the
code that used to work before should still work on windows 10? I mean
PChar vs. PWideChar. I don't know the type of hardware, but since
it's pictures, I assume it's just a normal printer. But I will verify
with the customer.

Thx !

Edited by: Nico Callewaert on Apr 18, 2018 11:45 PM

Edited by: Nico Callewaert on Apr 18, 2018 11:46 PM

Edited by: Nico Callewaert on Apr 18, 2018 11:53 PM


--
Peter Below
TeamB

Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Printing no longer works on Windows 10 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 21, 2018 12:46 AM   in response to: Nico Callewaert in response to: Nico Callewaert
Nico Callewaert wrote:

HAve you verified that the printer actually appears under this name
in the Printers collection?

What type of file are you trying to print? The application handling
this file type may simply not support printto on windows 10, or, if
you try to print to a specific printer type (e.g. a label printer)
Windows 10 may not support that anymore, if it is an older make.

--
Peter Below
TeamB


Hi Peter,

The files to be printed are pictures, simply jpeg files.
The GetPrinter is fine, that's working, it's the actual ShellExecute
call.

I ran a simple test case on my PC and it works with my trusty old
Brother HL-1540.

procedure PrintJpg(const path: string; index: integer);
var
S: string;
Device, Driver, Port: array [0 .. 255] of Char;
hDeviceMode: THandle;
N: Cardinal;
begin
Printer.PrinterIndex := index;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
WriteLn('Device, driver, port: ', S);
N:= ShellExecute(0, 'printto', PChar(path), PChar(S), nil, SW_HIDE);
WriteLn('Return code: ', N);
end;

See
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx
You may want to make sure the COM subsystem has been initialized before
you call ShellExecute. If your application does not use COM elsewhere
that will not be taken care of by the runtime library.

--
Peter Below
TeamB

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02