On 03/07/07, Perl Rob <[EMAIL PROTECTED]> wrote:
When I run my code to print an image file, the standard "Print" dialog appears as expected, and my file is printed without problems if I click "OK". However, if I click "Cancel" on the dialog, Win32::Printer opens a dialog box with a cryptic error (about a printer object not being created) that my users will not understand and that I don't want them to see. Any ideas on how I can suppress (or take control of) this behavior from Win32::Printer? I expect that I need to use an eval block, but I'm not sure how to use eval (getting all sorts of syntax errors). Here's my code: my $dc = new Win32::Printer ( papersize => LETTER, dialog => NOSELECTION, description => ' Coloring Page(s)', unit => 'mm' );
Rob, I've never used Win32::Print, but did take a quick ppek at the code. I think you can do something like this (completely untested): my $dc = eval { Win32::Printer->new( ... YOUR OPTIONS HERE ... ); }; if ($@) { # There was a die() in the eval if($^E != 1223) { # Win32::Printer does SetLastError(ERROR_CANCELLED) # if user presses cancel die $@; } else { # user cancelled, do something } } Regards, Rob.