Announcement

Collapse
No announcement yet.

Printing the way you did in DOS using PB/DLL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lance Edmonds
    replied
    I hate to rain on your parade, but if the target printer is a GDI or Windows-Only model, this code most likely wont work since the printer won't be able to handle the data stream. GDI and Windows-Only printers use a proprietary "BMP-like" data stream, not ASCII.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Andy Flowers
    started a topic Printing the way you did in DOS using PB/DLL

    Printing the way you did in DOS using PB/DLL

    The following is an example of how you can print the way you did in
    DOS using PB/DLL. The program first get your default Printer (locally attached
    or via a Network) then uses the 'OPEN' Command.

    [CODE]
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"

    DECLARE FUNCTION GetDefaultPrinter AS STRING

    FUNCTION PBMAIN()
    LOCAL PFile AS LONG
    LOCAL Printer AS STRING
    Printer = GetDefaultPrinter
    PFile = FREEFILE
    OPEN Printer FOR OUTPUT AS PFile
    IF ERR THEN
    MSGBOX "Error initializing printer " & Printer
    ELSE
    PRINT #PFile, "Printer is working fine......."
    END IF

    CLOSE #PFile
    MSGBOX "Printer Information Printed successfully"

    END FUNCTION


    FUNCTION GetDefaultPrinter AS STRING

    LOCAL PN AS LONG
    LOCAL hPrn AS LONG
    LOCAL cbNeeded AS LONG
    LOCAL cdBuf AS LONG
    LOCAL numElm AS LONG
    LOCAL cbSize AS LONG
    LOCAL fRet AS LONG
    LOCAL Printer AS STRING

    LOCAL PShare AS ASCIIZ * 255
    LOCAL PPort AS ASCIIZ * 255
    LOCAL PServer AS ASCIIZ * 255
    LOCAL PrinterName AS ASCIIZ * 255
    LOCAL PInfo2() AS PRINTER_INFO_2
    REDIM PInfo2(0)

    cbSize = SIZEOF(PInfo2(0))
    GetProfileString "WINDOWS", "DEVICE", ",,,", PrinterName, SIZEOF(PrinterName)
    PN = INSTR(PrinterName, ",")
    Printer = MID$(PrinterName,1,PN -1)
    fRet = OpenPrinter(BYCOPY Printer, hPrn, BYVAL %NULL)
    fRet = GetPrinter(hPrn, 2, BYVAL VARPTR(PInfo2(0)), cdBuf, cbNeeded)
    cdBuf = cbNeeded
    numElm = cbNeeded\cbSize
    REDIM PInfo2(numElm)
    fRet = GetPrinter(hPrn, 2, BYVAL VARPTR(PInfo2(0)), BYVAL cdBuf, cbNeeded)
    PServer = PInfo2(0)[email protected]
    PShare = PInfo2(0)[email protected]
    PPort = PInfo2(0)[email protected]

    IF LEN(TRIM$(PServer))=0 OR LEN(TRIM$(PShare))=0 AND LEN(TRIM$(PPort))>0 THEN
    FUNCTION = PPort
    ELSE
    FUNCTION = PServer+"\"+PShare
    END IF

    END FUNCTION


    ------------------
Working...
X