Delphi Getprinter - HP multi tray

Posted on 2007-10-05
Last Modified: 2013-12-15
We have a problem with HP Multi-tray printers, Assistance Urgently required.

In a stand alone application the code below works fine for all printers& however when the code below is used within our main application with the default printer set to a HP-multi tray, any reference to he printer object causes the CPU window to be popped up (in the dev environment) although an exception is not thrown.

A subsequent call to GetPrinter again displays the CPU window.

A call to DeviceCapabilities then returns the fail code, -1.

We also use QuickReports so on the stand alone test harness application we tried various tests, including together with quickreport components to see if it falls over.
And in our main application we have tested the code below at the start of our application before anything else is called.  

Note. We are testing this using a HP Laserjet 1320TN, 4 of our clients, using our application are using other HP Multi-tray printers and have this problem.

We are puzzled about:
1). Why the CPU window pops up in the development environment (Delphi 7 Studio Professional) when an exception is not thrown
2). Why the same code works in the test environment and not in the live app
3). Why it is only HP printers that seem to cause the problem

The code follows:
procedure Tform1.GetBinnames2( sl: TStrings );
  TBinName      = array [0..23] of Char;
  TBinNameArray = array [1..High(Integer) div SizeOf(TBinName)] of TBinName;
  PBinnameArray = ^TBinNameArray;
  TBinArray     = array [1..High(Integer) div SizeOf(Word)] of Word;
  PBinArray     = ^TBinArray;
  Device, Driver, Port: Array [0..255] of Char;
  hDevMode: THandle;
  i, numBinNames, numBins, temp: Integer;
  pBinNames: PBinnameArray;
  pBins: PBinArray;
  Printer.PrinterIndex := -1;
  Printer.GetPrinter(Device, Driver, Port, hDevmode);
  numBinNames :=
    WinSpool.DeviceCapabilities( Device, Port, DC_BINNAMES, Nil, Nil );
  numBins :=
    WinSpool.DeviceCapabilities( Device, Port, DC_BINS, Nil, Nil );
  If numBins <> numBinNames then
    raise Exception.Create(
            'DeviceCapabilities reports different number of bins and '+
            'bin names!');

  If numBinNames > 0 then
    pBins := Nil;
    GetMem( pBinNames, numBinNames * Sizeof( TBinname ));
    GetMem( pBins, numBins * Sizeof(Word));
      WinSpool.DeviceCapabilities( Device, Port, DC_BINNAMES,
                                   Pchar( pBinNames ), Nil);
      WinSpool.DeviceCapabilities( Device, Port, DC_BINS,
                                   Pchar( pBins ), Nil );
      For i:= 1 To numBinNames Do Begin
        temp := pBins^[i];
        sl.addObject( pBinNames^[i], TObject( temp ));
      FreeMem( pBinNames );
      If pBins <> Nil Then
        FreeMem( pBins );
Question by:MartinCasey
    LVL 21

    Accepted Solution

    A quick search confirmed my suspicions.  The following link is a quick reports FAQ and contains information about printing to a multi try HP priner.  They believe the problem is with the driver trying to reorder the trays.

    They did mention that using a different print driver could get you around the issue.

    Let me know if this helps.
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Causes of paper jams:The following are the main causes of paper jams. Guides:If the guides for the paper are not set correctly they may cause the paper to enter at an angle. You should ensure that the guides are set correctly for the paper type a…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now