Consultor Eletrônico



Kbase P107640: 4GL: How to get the information of all currently connected network printers?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   06/04/2011
Status: Verified

GOAL:

4GL: How to get the Printer Server Names of all currently connected network printers?

GOAL:

4GL: How to get the Printer Names of all currently connected network printers?

GOAL:

4GL: How to get the Printer Share Names of all currently connected network printers?

GOAL:

4GL: How to get the Printer Port Names of all currently connected network printers?

GOAL:

4GL: How to get the Printer Driver Names of all currently connected network printers?

GOAL:

4GL: How to get the Printer Locations of all currently connected network printers?

GOAL:

4GL: How to call Windows API EnumPrintersA function

FACT(s) (Environment):

Windows
Progress 9.x
OpenEdge 10.x

FIX:

This solution invokes Windows API EnumPrintersA function to retrieve the Server Names , Printer Names, Share Names,Port Names, Driver Names, Comments and Locations of all the printers currently connected to the 4GL client:
&GLOBAL-DEFINE PRINTER_ENUM_CONNECTIONS 4
&GLOBAL-DEFINE PRINTER_INFO_2 2
DEFINE VARIABLE mpPrinterInfo2 AS MEMPTR NO-UNDO.
DEFINE VARIABLE iFlags AS INTEGER NO-UNDO.
DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iLevel AS INTEGER NO-UNDO.
DEFINE VARIABLE mpPrinterEnum AS MEMPTR NO-UNDO.
DEFINE VARIABLE icdBuf AS INTEGER NO-UNDO.
DEFINE VARIABLE ipcbNeeded AS INTEGER NO-UNDO.
DEFINE VARIABLE ipcReturned AS INTEGER NO-UNDO.
DEFINE VARIABLE iResult AS INTEGER NO-UNDO.
ASSIGN
iFlags = {&PRINTER_ENUM_CONNECTIONS}
cName = ""
iLevel = {&PRINTER_INFO_2}
SET-SIZE(mpPrinterEnum)= 4096.
/* Get the correct size of the mpPrinterEnum buffer needed */
RUN EnumPrintersA(
INPUT iFlags,
INPUT cName,
INPUT iLevel,
INPUT-OUTPUT mpPrinterEnum,
INPUT GET-SIZE(mpPrinterEnum),
OUTPUT ipcbNeeded,
OUTPUT ipcReturned,
OUTPUT iResult).
/* Set the correct size of the mpPrinterEnum buffer as needed */
SET-SIZE(mpPrinterEnum)= 0.
SET-SIZE(mpPrinterEnum)= ipcbNeeded.
/* Get printer information into the mpPrinterEnum buffer */
RUN EnumPrintersA(
INPUT iFlags,
INPUT cName,
INPUT iLevel,
INPUT-OUTPUT mpPrinterEnum,
INPUT GET-SIZE(mpPrinterEnum),
OUTPUT ipcbNeeded,
OUTPUT ipcReturned,
OUTPUT iResult).
/* Loop through all printers information returned and print selected data */
RUN GetPrinterInfoData.
PROCEDURE GetPrinterInfoData:
DEFINE VARIABLE cServerName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPrinterName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cShareName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPortName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cDriverName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cComment AS CHARACTER NO-UNDO.
DEFINE VARIABLE cLocation AS CHARACTER NO-UNDO.
DEFINE VARIABLE mBuffer AS MEMPTR NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.

DO iCounter = 0 TO ipcReturned - 1:
SET-POINTER-VALUE(mpPrinterInfo2) = GET-POINTER-VALUE(mpPrinterEnu.m) + (iCounter * 84 ).
SET-POINTER-VALUE(mBuffer) = GET-LONG(mpPrinterInfo2,1).
cServerName = GET-STRING(mBuffer,1).

SET-POINTER-VALUE(mBuffer) = GET-LONG(mpPrinterInfo2,5).
cPrinterName = GET-STRING(mBuffer,1).

SET-POINTER-VALUE(mBuffer) = GET-LONG(mpPrinterInfo2,9).
cShareName = GET-STRING(mBuffer,1).

SET-POINTER-VALUE(mBuffer) = GET-LONG(mpPrinterInfo2,13).
cPortName = GET-STRING(mBuffer,1).

SET-POINTER-VALUE(mBuffer) = GET-LONG(mpPrinterInfo2,17).
cDriverName = GET-STRING(mBuffer,1).

SET-POINTER-VALUE(mBuffer) = GET-LONG(mpPrinterInfo2,21).
cComment = GET-STRING(mBuffer,1).

SET-POINTER-VALUE(mBuffer) = GET-LONG(mpPrinterInfo2,25).
cLocation = GET-STRING(mBuffer,1).

MESSAGE
"Server Name:" "~t" cServerName "~n"
"Printer Name:" "~t" cPrinterName "~n"
"Share Name:" "~t" cShareName "~n"
"Port Name:" "~t" cPortName "~n"
"Driver Name:" "~t" cDriverNAME "~n"
"Comment:" "~t" cComment "~n"
"Location:" "~t" cLocation "~n"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
END PROCEDURE.
PROCEDURE EnumPrintersA EXTERNAL "winspool.drv":
DEFINE INPUT PARAMETER Flags AS LONG.
DEFINE INPUT PARAMETER Name AS CHARACTER.
DEFINE INPUT PARAMETER Level AS LONG.
DEFINE INPUT-OUTPUT PARAMETER pPrinterEnum AS MEMPTR.
DEFINE INPUT PARAMETER cdBuf AS LONG.
DEFINE OUTPUT PARAMETER pcbNeeded AS LONG.
DEFINE OUTPUT PARAMETER pcReturned AS LONG.
DEFINE RETURN PARAMETER iResult AS LONG.
END PROCEDURE..