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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
intheConnect With a Mentor Commented:
cheers :-)
0
 
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Roadrunner100598Author Commented:
Oops - in GDI32.DLL there is DeviceCapabilitiesExA
0
 
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
 
Roadrunner100598Author Commented:
Indeed!

Live long and prosper...

0
All Courses

From novice to tech pro — start learning today.