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)?
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)?
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
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
ASKER
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,por t,hdmode);
memo1.lines.add(device);
edit1.text := port;
end;
use printers;
procedure TForm1.BitBtn1Click(Sender
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,
memo1.lines.add(device);
edit1.text := port;
end;
ASKER
I tried to set the Port to NIL and it works just fine.
Thanks a lot, Guido
Please post an answere!
Thanks a lot, Guido
Please post an answere!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Indeed!
Live long and prosper...
Live long and prosper...
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(pDevic
pPort : PAnsiChar;
fwCapability : Word;
pOutput : PAnsiChar;
DevMode : PDeviceModeA): Integer; stdcall;
external 'winspool.drv' name 'DeviceCapabilitiesA';
function DeviceCapabilitiesW(pDevic
pPort : PWideChar;
fwCapability: Word;
pOutput: PWideChar;
DevMode: PDeviceModeW): Integer; stdcall;
external 'winspool.drv' name 'DeviceCapabilitiesW';
function DeviceCapabilities(pDevice
pPort : PChar;
fwCapability : Word;
pOutput : PChar;
DevMode: PDeviceMode): Integer; stdcall;
external 'winspool.drv' name 'DeviceCapabilitiesA';
procedure TForm1.Button1Click(Sender
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;