Consultor Eletrônico



Kbase P89989: How to get the printer driver name
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/22/2010
Status: Verified

GOAL:

How to get the printer driver name

GOAL:

How to get the printer driver name using 4GL and Windows API

FACT(s) (Environment):

Windows
Progress 9.x
OpenEdge 10.x

FIX:

Use the windows API GetPrinterDriver. Here is some code to use it:
/* ************************************ */
def var c_modelo as char initial "".
def var h_modulo as integer.
def var salida as integer.
def var cuantos as integer.
def var vDrvInfo as MEMPTR.
def var bDrvInfo as INTEGER.

SYSTEM-DIALOG PRINTER-SETUP.
c_modelo = SESSION:PRINTER-NAME.

DEF VAR pp AS MEMPTR NO-UNDO.

/* Initial value
Just wants to know the correct size of plpbDrvInfo MEMPTR */
set-size(vDrvInfo) = 1024.

run OpenPrinterA(c_modelo, output h_modulo,0, output salida).
run GetPrinterDriverA (
input h_modulo,
input 0,
input 2, /* Level 2 meaning that it points to DRIVER_INFO_2 structure */
output vDrvInfo ,
input 1024,
output cuantos, /* Get the size of plpbDrvInfo MEMPTR */
output salida
).

/* Set the size of plpbDrvInfo MEMPTR */
set-size(vDrvInfo) = 0.
set-size(vDrvInfo) = cuantos.

run GetPrinterDriverA (
input h_modulo,
input 0,
input 2,
output vDrvInfo ,
input GET-SIZE(vDrvInfo) ,
output cuantos,
output salida
).


/* GET-LONG(vDrvInfo,5) = name of the driver
GET-LONG(vDrvInfo,9) = the environment for which the driver was written
GET-LONG(vDrvInfo,13) = filename or full path for the file that contains
the device driver */
SET-POINTER-VALUE(pp) = GET-LONG(vDrvInfo,13).


MESSAGE get-string(pp,1) VIEW-AS ALERT-BOX.

SET-SIZE(vDrvInfo) = 0.

procedure OpenPrinterA external "winspool.drv":
define input parameter pPrinterName as char.
define output parameter phPrinter as long.
define input parameter pDefault as long.
define return parameter error as long.
end.

procedure GetPrinterDriverA external "winspool.drv":
define input parameter phPrinter as long.
define input parameter plpszEnv as long.
define input parameter pdwLevel as long.
define output parameter plpbDrvInfo as MEMPTR.
define input parameter pcbBuf as long.
define output parameter plpdwNeeded as long.
define return parameter error as long.
end.

/* ************************************** */