Link to home
Start Free TrialLog in
Avatar of Roadrunner100598
Roadrunner100598

asked on

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)?
Avatar of inthe
inthe


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;
Avatar of Roadrunner100598

ASKER

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
Oops - in GDI32.DLL there is DeviceCapabilitiesExA
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;
I tried to set the Port to NIL and it works just fine.

Thanks a lot, Guido

Please post an answere!
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Indeed!

Live long and prosper...