Board index » delphi » New and again odd printer setup problem

New and again odd printer setup problem

I have another one :-)

I'm using this procedure to call printer driver's Setup dialog which should
allow user
to change and save results as new settings (during current application run).

It behaves similar as the code in "Odd printer setup problem" thread did.
When it's used on a virtual (FILE:) printer - it crashes.

---
procedure TfrmPrintDlg.btnPrinterPropertiesClick(Sender: TObject);
var
  device, driver, port: array[0..PrinterCharArraySize] of char;
  hDMode: THandle;
  DevMode: PDevMode;
  hPrinter: THandle;
begin
 Printer.PrinterIndex := Printer.PrinterIndex;

  Printer.GetPrinter(device, driver, port, hDMode);
  if (hDMode<>0) then begin
    DevMode := GlobalLock(hDMode);
    if Assigned(DevMode) then begin
     if OpenPrinter(device,hPrinter,nil) then begin
        try
          DocumentProperties(
            self.Handle,
            hPrinter,
            device,
            DevMode^,
            DevMode^,
            DM_IN_PROMPT or DM_OUT_BUFFER or DM_IN_BUFFER);
        finally
          ClosePrinter(hPrinter);
        end;
      end;

      GlobalUnlock(hDMode);
    end;
  end;

  Printer.PrinterIndex := Printer.PrinterIndex;
end;
---

Any ideas?

--
-=[ codeTroll ]=-

 

Re:New and again odd printer setup problem


Quote
CodeTroll wrote:

> I have another one :-)

> I'm using this procedure to call printer driver's Setup dialog which should
> allow user
> to change and save results as new settings (during current application run).

> It behaves similar as the code in "Odd printer setup problem" thread did.
> When it's used on a virtual (FILE:) printer - it crashes.

> ---
> procedure TfrmPrintDlg.btnPrinterPropertiesClick(Sender: TObject);
> var
>   device, driver, port: array[0..PrinterCharArraySize] of char;
>   hDMode: THandle;
>   DevMode: PDevMode;
>   hPrinter: THandle;
> begin
>  Printer.PrinterIndex := Printer.PrinterIndex;

>   Printer.GetPrinter(device, driver, port, hDMode);
>   if (hDMode<>0) then begin
>     DevMode := GlobalLock(hDMode);
>     if Assigned(DevMode) then begin
>      if OpenPrinter(device,hPrinter,nil) then begin
>         try
>           DocumentProperties(
>             self.Handle,
>             hPrinter,
>             device,
>             DevMode^,
>             DevMode^,
>             DM_IN_PROMPT or DM_OUT_BUFFER or DM_IN_BUFFER);
>         finally
>           ClosePrinter(hPrinter);
>         end;
>       end;

>       GlobalUnlock(hDMode);
>     end;
>   end;

>   Printer.PrinterIndex := Printer.PrinterIndex;
> end;
> ---

> Any ideas?

> --
> -=[ codeTroll ]=-

This is kinda fun if you aren't the one who has to get it to work :-)

It seems to me that if you set the DM_OUT_BUFFER or DM_IN_BUFFER flags,
then a whole lot of copying, merging, looking at dmFields will take
place, whereas one would think that all you have to do is set
DM_IN_PROMPT, and the updating of the settings would be done for you.
W32 help certainly reads like that. If you pass pDevModeInput as null
and don't set  DM_IN_BUFFER, then the dialog box is filled from the
printer defaults. Likewise if you don't set DM_OUT_BUFFER then you can
pass a null for pDevModeOutput.

I'm sure you've already been down the above path, so another thing that
might be worth checking is to see if the size of the DevMode structure
is being changed.... that would not be good. The dmSize and
dmDriverExtra can be used to do this.

One more thing occurs based on your previous hassle with dmFields. If
you do use DM_IN_BUFFER, and set pDevModeInput to point to the current
DevMode so that the dialog is filled with the current print settings (I
think), then it's going to do a merge with itself based on the bits set
in dmFields. Maybe you should check quite what flags are set before
calling DocumentProperties()?

Once again an uninformed opinion, but now I'm curious.

Dave

Re:New and again odd printer setup problem


Quote
"David Reeve" <drscienti...@powerup.com.au> wrote in message

news:3E23622A.DD6942A5@powerup.com.au...

Quote
> CodeTroll wrote:

> > I have another one :-)

> > I'm using this procedure to call printer driver's Setup dialog which
should
> > allow user
> > to change and save results as new settings (during current application
run).

> > It behaves similar as the code in "Odd printer setup problem" thread
did.
> > When it's used on a virtual (FILE:) printer - it crashes.

> > ---
<snip>
> This is kinda fun if you aren't the one who has to get it to work :-)

Exactly ...

Quote
> It seems to me that if you set the DM_OUT_BUFFER or DM_IN_BUFFER flags,
> then a whole lot of copying, merging, looking at dmFields will take
> place, whereas one would think that all you have to do is set
> DM_IN_PROMPT, and the updating of the settings would be done for you.
> W32 help certainly reads like that. If you pass pDevModeInput as null
> and don't set  DM_IN_BUFFER, then the dialog box is filled from the
> printer defaults. Likewise if you don't set DM_OUT_BUFFER then you can
> pass a null for pDevModeOutput.

The DM_? parameters are set exactly as they should be here.
I've been trying a lot of different combinations and only this works.
Other may work ... but the settings I change in setup dialog aren't
persistant
then. I have searched the net for solution and I found similar code in
several
places.

Quote
> I'm sure you've already been down the above path, so another thing that
> might be worth checking is to see if the size of the DevMode structure
> is being changed.... that would not be good. The dmSize and
> dmDriverExtra can be used to do this.

I will check this more thorougly and report back.
Probably not today though ... too much work (RC dead-line is near :-)).

Quote
> One more thing occurs based on your previous hassle with dmFields. If
> you do use DM_IN_BUFFER, and set pDevModeInput to point to the current
> DevMode so that the dialog is filled with the current print settings (I
> think), then it's going to do a merge with itself based on the bits set
> in dmFields. Maybe you should check quite what flags are set before
> calling DocumentProperties()?

I plan to get DevMode size and record using DocumentProperties.

Ah ... just remembered ... the prior problem and this one occur in only one
case.
It's a bit funny thing, all this is working perfectly on FinePrint (as
default) and other
printers but when I change to HP's virtual printer - it crashes!
Is that odd or what?

Quote
> Once again an uninformed opinion, but now I'm curious.

But another good reply.

Quote

> Dave

--
CodeTroll

Other Threads