DeviceCapabilities function

I want to extract information about a printer (bins, bin names,... ).

It should be possible to do this via the API function
  DeviceCapabilities(..)
but I just can't get it to work. (There is a difference in the declarations of the function in the VCL-source and the Win32.HLP)

So, how can I find the information for the current printer (Printer.Printerindex)?
LVL 1
Roadrunner100598Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:

From a March 1998 post by Joe Hecht:
 
Q) How can I call the DeviceCapabilities functions without getting an application error?
 
A) The prototypes for the DeviceCapabilities() function where
incorrectly documented in Delphi 2.0. The following is an example of the correct method of calling the function. The example returns the bin names of the given printer.
Example:
 
const cchBinName = 24;
 
function DeviceCapabilitiesA(pDevice : PAnsiChar;
        pPort : PAnsiChar;
        fwCapability : Word;
        pOutput : PAnsiChar;
        DevMode : PDeviceModeA): Integer; stdcall;
        external 'winspool.drv' name 'DeviceCapabilitiesA';
 
function DeviceCapabilitiesW(pDevice : PWideChar;
        pPort : PWideChar;
        fwCapability: Word;
        pOutput: PWideChar;
        DevMode: PDeviceModeW): Integer; stdcall;
        external 'winspool.drv' name 'DeviceCapabilitiesW';
 
function DeviceCapabilities(pDevice : PChar;
        pPort : PChar;
        fwCapability : Word;
        pOutput : PChar;
        DevMode: PDeviceMode): Integer; stdcall;
        external 'winspool.drv' name 'DeviceCapabilitiesA';
 
procedure TForm1.Button1Click(Sender: TObject);
var
        NumBins : integer;
        i : integer;
        p : pChar;
        pNames : pChar;
begin
  NumBins := DeviceCapabilities('HP LaserJet Series II',
            'LPT1',
            DC_BINNAMES,
            nil,
            nil);
  if NumBins > 0 then begin
        GetMem(p, NumBins * cchBinName);
        DeviceCapabilities('HP LaserJet Series II',
            'LPT1',
            DC_BINNAMES,
            p,
            nil);
        PNames := p;
        for i := 0 to (NumBins - 1) do begin
            Memo1.Lines.Add(PNames);
            pNames := @pNames[i * cchBinName]
        end;
        FreeMem(p, NumBins * cchBinName);
  end;
end;
0
Roadrunner100598Author Commented:
Thanks Inthe,

to complete the answere I would need the code to extract the correct printer name (Is it Printers[PrinterIndex]?) and port name.

GetPrinter() seems to return garbage in the port and driver params.

Do you happen to know why the function DeviceCapabilities is imported from WinSpool instead of GDI32.DLL? That was why I couldn't get it to work in the frist place.


Thanks again,

Guido
0
Roadrunner100598Author Commented:
Oops - in GDI32.DLL there is DeviceCapabilitiesExA
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

intheCommented:
i dunno how you are getting garbage from getprinter so try this way of using it as it works fine for me:

use printers;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
 Device : array[0..255] of char;
 Driver : array[0..255] of char;
 Port   : array[0..255] of char;
 hDMode : THandle;
 begin
    Printer.getprinter(device,driver,port,hdmode);
    memo1.lines.add(device);
    edit1.text := port;
 end;
0
Roadrunner100598Author Commented:
I tried to set the Port to NIL and it works just fine.

Thanks a lot, Guido

Please post an answere!
0
intheCommented:
cheers :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roadrunner100598Author Commented:
Indeed!

Live long and prosper...

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.