Results 1 to 15 of 15

Thread: Is there a code that tells the user that the printer has no paper when the paper ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Question Is there a code that tells the user that the printer has no paper when the paper ?

    hi

    Is there a code that tells the user that the printer has no paper when the paper runs out?

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,552

    Re: Is there a code that tells the user that the printer has no paper when the paper

    Yes. Use winspool APIs to look for PRINTER_STATUS_PAPER_OUT

    Public Declare Function EnumPrintersW Lib "winspool.drv" (ByVal flags As ENUM_PRINTER_FLAGS, ByVal name As LongPtr, ByVal Level As Long, pPrinterEnum As Any, ByVal cbBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long

    You want Level 2 (or 6, but that's undocumented and I haven't tested it)

    Code:
    Public Enum ENUM_PRINTER_FLAGS
        PRINTER_ENUM_DEFAULT  = &H00000001
        PRINTER_ENUM_LOCAL  = &H00000002
        PRINTER_ENUM_CONNECTIONS  = &H00000004
        PRINTER_ENUM_FAVORITE = &H00000004
        PRINTER_ENUM_NAME  = &H00000008
        PRINTER_ENUM_REMOTE  = &H00000010
        PRINTER_ENUM_SHARED  = &H00000020
        PRINTER_ENUM_NETWORK  = &H00000040
        PRINTER_ENUM_EXPAND  = &H00004000
        PRINTER_ENUM_CONTAINER  = &H00008000&
        PRINTER_ENUM_ICONMASK  = &H00ff0000
        PRINTER_ENUM_ICON1  = &H00010000
        PRINTER_ENUM_ICON2  = &H00020000
        PRINTER_ENUM_ICON3  = &H00040000
        PRINTER_ENUM_ICON4  = &H00080000
        PRINTER_ENUM_ICON5  = &H00100000
        PRINTER_ENUM_ICON6  = &H00200000
        PRINTER_ENUM_ICON7  = &H00400000
        PRINTER_ENUM_ICON8  = &H00800000
        PRINTER_ENUM_HIDE  = &H01000000
    ' #if (NTDDI_VERSION >= NTDDI_WINBLUE)
        PRINTER_ENUM_CATEGORY_ALL  = &H02000000
        PRINTER_ENUM_CATEGORY_3D  = &H04000000
    End Enum
    
    Public Enum PrinterAttributes
        PRINTER_ATTRIBUTE_QUEUED  = &H00000001
        PRINTER_ATTRIBUTE_DIRECT  = &H00000002
        PRINTER_ATTRIBUTE_DEFAULT  = &H00000004
        PRINTER_ATTRIBUTE_SHARED  = &H00000008
        PRINTER_ATTRIBUTE_NETWORK  = &H00000010
        PRINTER_ATTRIBUTE_HIDDEN  = &H00000020
        PRINTER_ATTRIBUTE_LOCAL  = &H00000040
        PRINTER_ATTRIBUTE_ENABLE_DEVQ  = &H00000080
        PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS  = &H00000100
        PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST  = &H00000200
        PRINTER_ATTRIBUTE_WORK_OFFLINE  = &H00000400
        PRINTER_ATTRIBUTE_ENABLE_BIDI  = &H00000800
        PRINTER_ATTRIBUTE_RAW_ONLY  = &H00001000
        PRINTER_ATTRIBUTE_PUBLISHED  = &H00002000
        PRINTER_ATTRIBUTE_FAX  = &H00004000
    '  The printer attribute pushed xxx bits below are used by the
    '  pushing printer connection code to keep track of the type
    '  of printer connection.  These bits are per user resources
    '  hence the local print provider has no knowledge about these
    '  bit and will not accepts them.  The remote print provider
    '  is responsible for storeing and persisting these bits.
        PRINTER_ATTRIBUTE_PUSHED_USER  = &H00020000
        PRINTER_ATTRIBUTE_PUSHED_MACHINE  = &H00040000
        PRINTER_ATTRIBUTE_MACHINE  = &H00080000
        PRINTER_ATTRIBUTE_FRIENDLY_NAME  = &H00100000
    '  If the redirected TS printer is installed with generic
    '  TS printer driver (TSPRINT.dll) then this attribute is set
    '  by the UMRDP service and passed on to the spooler
        PRINTER_ATTRIBUTE_TS_GENERIC_DRIVER  = &H00200000
    ' #if (NTDDI_VERSION >= NTDDI_WINBLUE) // NTDDI_WINTHRESHOLD)
    '  Defines a bit allowing a local queue to be installed as a
    '  "per-user" queue that is only usable/enumerable by that user.
        PRINTER_ATTRIBUTE_PER_USER  = &H00400000
    '  Defines a bit indicating that a queue is an enterprise
    '  cloud print queue.
        PRINTER_ATTRIBUTE_ENTERPRISE_CLOUD  = &H00800000
    End Enum
    Public Enum PRINTER_STATUS_FLAGS
        PRINTER_STATUS_PAUSED  = &H00000001
        PRINTER_STATUS_ERROR  = &H00000002
        PRINTER_STATUS_PENDING_DELETION  = &H00000004
        PRINTER_STATUS_PAPER_JAM  = &H00000008
        PRINTER_STATUS_PAPER_OUT  = &H00000010
        PRINTER_STATUS_MANUAL_FEED  = &H00000020
        PRINTER_STATUS_PAPER_PROBLEM  = &H00000040
        PRINTER_STATUS_OFFLINE  = &H00000080
        PRINTER_STATUS_IO_ACTIVE  = &H00000100
        PRINTER_STATUS_BUSY  = &H00000200
        PRINTER_STATUS_PRINTING  = &H00000400
        PRINTER_STATUS_OUTPUT_BIN_FULL  = &H00000800
        PRINTER_STATUS_NOT_AVAILABLE  = &H00001000
        PRINTER_STATUS_WAITING  = &H00002000
        PRINTER_STATUS_PROCESSING  = &H00004000
        PRINTER_STATUS_INITIALIZING = &H00008000&
        PRINTER_STATUS_WARMING_UP  = &H00010000
        PRINTER_STATUS_TONER_LOW  = &H00020000
        PRINTER_STATUS_NO_TONER  = &H00040000
        PRINTER_STATUS_PAGE_PUNT  = &H00080000
        PRINTER_STATUS_USER_INTERVENTION  = &H00100000
        PRINTER_STATUS_OUT_OF_MEMORY  = &H00200000
        PRINTER_STATUS_DOOR_OPEN  = &H00400000
        PRINTER_STATUS_SERVER_UNKNOWN  = &H00800000
        PRINTER_STATUS_POWER_SAVE  = &H01000000
        PRINTER_STATUS_SERVER_OFFLINE  = &H02000000
        PRINTER_STATUS_DRIVER_UPDATE_NEEDED  = &H04000000
    End Enum
    
    'Alias PRINTER_INFO_2 As PRINTER_INFO_2W
    Public Type PRINTER_INFO_2
        pServerName As LongPtr
        pPrinterName As LongPtr
        pShareName As LongPtr
        pPortName As LongPtr
        pDriverName As LongPtr
        pComment As LongPtr
        pLocation As LongPtr
        pDevMode As LongPtr 'LPDEVMODEW
        pSepFile As LongPtr
        pPrintProcessor As LongPtr
        pDatatype As LongPtr
        pParameters As LongPtr
        pSecurityDescriptor As LongPtr 'PSECURITY_DESCRIPTOR
        Attributes As PrinterAttributes
        Priority As Long
        DefaultPriority As Long
        StartTime As Long
        UntilTime As Long
        Status As PRINTER_STATUS_FLAGS
        cJobs As Long
        AveragePPM As Long
    End Type
    6 cuts right to the chase, if it works:

    Code:
    Public Type PRINTER_INFO_6
        dwStatus As PRINTER_STATUS_FLAGS
    End Type
    Last edited by fafalone; Nov 25th, 2023 at 08:06 AM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Exclamation Re: Is there a code that tells the user that the printer has no paper when the paper

    Quote Originally Posted by fafalone View Post
    Yes. Use winspool APIs to look for PRINTER_STATUS_PAPER_OUT

    Public Declare Function EnumPrintersW Lib "winspool.drv" (ByVal flags As ENUM_PRINTER_FLAGS, ByVal name As LongPtr, ByVal Level As Long, pPrinterEnum As Any, ByVal cbBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long

    You want Level 2 (or 6, but that's undocumented and I haven't tested it)

    Code:
    Public Enum ENUM_PRINTER_FLAGS
        PRINTER_ENUM_DEFAULT  = &H00000001
        PRINTER_ENUM_LOCAL  = &H00000002
        PRINTER_ENUM_CONNECTIONS  = &H00000004
        PRINTER_ENUM_FAVORITE = &H00000004
        PRINTER_ENUM_NAME  = &H00000008
        PRINTER_ENUM_REMOTE  = &H00000010
        PRINTER_ENUM_SHARED  = &H00000020
        PRINTER_ENUM_NETWORK  = &H00000040
        PRINTER_ENUM_EXPAND  = &H00004000
        PRINTER_ENUM_CONTAINER  = &H00008000&
        PRINTER_ENUM_ICONMASK  = &H00ff0000
        PRINTER_ENUM_ICON1  = &H00010000
        PRINTER_ENUM_ICON2  = &H00020000
        PRINTER_ENUM_ICON3  = &H00040000
        PRINTER_ENUM_ICON4  = &H00080000
        PRINTER_ENUM_ICON5  = &H00100000
        PRINTER_ENUM_ICON6  = &H00200000
        PRINTER_ENUM_ICON7  = &H00400000
        PRINTER_ENUM_ICON8  = &H00800000
        PRINTER_ENUM_HIDE  = &H01000000
    ' #if (NTDDI_VERSION >= NTDDI_WINBLUE)
        PRINTER_ENUM_CATEGORY_ALL  = &H02000000
        PRINTER_ENUM_CATEGORY_3D  = &H04000000
    End Enum
    
    Public Enum PrinterAttributes
        PRINTER_ATTRIBUTE_QUEUED  = &H00000001
        PRINTER_ATTRIBUTE_DIRECT  = &H00000002
        PRINTER_ATTRIBUTE_DEFAULT  = &H00000004
        PRINTER_ATTRIBUTE_SHARED  = &H00000008
        PRINTER_ATTRIBUTE_NETWORK  = &H00000010
        PRINTER_ATTRIBUTE_HIDDEN  = &H00000020
        PRINTER_ATTRIBUTE_LOCAL  = &H00000040
        PRINTER_ATTRIBUTE_ENABLE_DEVQ  = &H00000080
        PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS  = &H00000100
        PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST  = &H00000200
        PRINTER_ATTRIBUTE_WORK_OFFLINE  = &H00000400
        PRINTER_ATTRIBUTE_ENABLE_BIDI  = &H00000800
        PRINTER_ATTRIBUTE_RAW_ONLY  = &H00001000
        PRINTER_ATTRIBUTE_PUBLISHED  = &H00002000
        PRINTER_ATTRIBUTE_FAX  = &H00004000
    '  The printer attribute pushed xxx bits below are used by the
    '  pushing printer connection code to keep track of the type
    '  of printer connection.  These bits are per user resources
    '  hence the local print provider has no knowledge about these
    '  bit and will not accepts them.  The remote print provider
    '  is responsible for storeing and persisting these bits.
        PRINTER_ATTRIBUTE_PUSHED_USER  = &H00020000
        PRINTER_ATTRIBUTE_PUSHED_MACHINE  = &H00040000
        PRINTER_ATTRIBUTE_MACHINE  = &H00080000
        PRINTER_ATTRIBUTE_FRIENDLY_NAME  = &H00100000
    '  If the redirected TS printer is installed with generic
    '  TS printer driver (TSPRINT.dll) then this attribute is set
    '  by the UMRDP service and passed on to the spooler
        PRINTER_ATTRIBUTE_TS_GENERIC_DRIVER  = &H00200000
    ' #if (NTDDI_VERSION >= NTDDI_WINBLUE) // NTDDI_WINTHRESHOLD)
    '  Defines a bit allowing a local queue to be installed as a
    '  "per-user" queue that is only usable/enumerable by that user.
        PRINTER_ATTRIBUTE_PER_USER  = &H00400000
    '  Defines a bit indicating that a queue is an enterprise
    '  cloud print queue.
        PRINTER_ATTRIBUTE_ENTERPRISE_CLOUD  = &H00800000
    End Enum
    Public Enum PRINTER_STATUS_FLAGS
        PRINTER_STATUS_PAUSED  = &H00000001
        PRINTER_STATUS_ERROR  = &H00000002
        PRINTER_STATUS_PENDING_DELETION  = &H00000004
        PRINTER_STATUS_PAPER_JAM  = &H00000008
        PRINTER_STATUS_PAPER_OUT  = &H00000010
        PRINTER_STATUS_MANUAL_FEED  = &H00000020
        PRINTER_STATUS_PAPER_PROBLEM  = &H00000040
        PRINTER_STATUS_OFFLINE  = &H00000080
        PRINTER_STATUS_IO_ACTIVE  = &H00000100
        PRINTER_STATUS_BUSY  = &H00000200
        PRINTER_STATUS_PRINTING  = &H00000400
        PRINTER_STATUS_OUTPUT_BIN_FULL  = &H00000800
        PRINTER_STATUS_NOT_AVAILABLE  = &H00001000
        PRINTER_STATUS_WAITING  = &H00002000
        PRINTER_STATUS_PROCESSING  = &H00004000
        PRINTER_STATUS_INITIALIZING = &H00008000&
        PRINTER_STATUS_WARMING_UP  = &H00010000
        PRINTER_STATUS_TONER_LOW  = &H00020000
        PRINTER_STATUS_NO_TONER  = &H00040000
        PRINTER_STATUS_PAGE_PUNT  = &H00080000
        PRINTER_STATUS_USER_INTERVENTION  = &H00100000
        PRINTER_STATUS_OUT_OF_MEMORY  = &H00200000
        PRINTER_STATUS_DOOR_OPEN  = &H00400000
        PRINTER_STATUS_SERVER_UNKNOWN  = &H00800000
        PRINTER_STATUS_POWER_SAVE  = &H01000000
        PRINTER_STATUS_SERVER_OFFLINE  = &H02000000
        PRINTER_STATUS_DRIVER_UPDATE_NEEDED  = &H04000000
    End Enum
    
    'Alias PRINTER_INFO_2 As PRINTER_INFO_2W
    Public Type PRINTER_INFO_2
        pServerName As LongPtr
        pPrinterName As LongPtr
        pShareName As LongPtr
        pPortName As LongPtr
        pDriverName As LongPtr
        pComment As LongPtr
        pLocation As LongPtr
        pDevMode As LongPtr 'LPDEVMODEW
        pSepFile As LongPtr
        pPrintProcessor As LongPtr
        pDatatype As LongPtr
        pParameters As LongPtr
        pSecurityDescriptor As LongPtr 'PSECURITY_DESCRIPTOR
        Attributes As PrinterAttributes
        Priority As Long
        DefaultPriority As Long
        StartTime As Long
        UntilTime As Long
        Status As PRINTER_STATUS_FLAGS
        cJobs As Long
        AveragePPM As Long
    End Type
    6 cuts right to the chase, if it works:

    Code:
    Public Type PRINTER_INFO_6
        dwStatus As PRINTER_STATUS_FLAGS
    End Type
    It didn't work for me, maybe there's a mistake

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,552

    Re: Is there a code that tells the user that the printer has no paper when the paper

    Yes it's pretty complicated to use that API correctly; post what you tried I'll take a look.

  5. #5
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    978

    Re: Is there a code that tells the user that the printer has no paper when the paper

    That assumes that the printer is capable of indicating this error and that the used printer driver also correctly reports this back to the OS.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,552

    Re: Is there a code that tells the user that the printer has no paper when the paper

    True, but most modern printers have a standard driver interface that sends these kinds of status messages. Though some may have their own APIs, sometimes public, but not always.

  7. #7
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    378

    Re: Is there a code that tells the user that the printer has no paper when the paper

    You wouldnt want to go insane with Win32 API killing your brain cells, Try integrating VB.NET and VB6 with local webservers or COM port loopbacks, I think VB.NET has a builtin way or a NuGet for this, and use WebBrowser or some Basic Win32
    you cant believe a random 11 year old turkish kid using VB6 and feeling nostalgic to XP

  8. #8
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,552

    Re: Is there a code that tells the user that the printer has no paper when the paper

    Your link is talking about downloading pictures... are you lost?

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Red face Re: Is there a code that tells the user that the printer has no paper when the paper

    Quote Originally Posted by fafalone View Post
    Your link is talking about downloading pictures... are you lost?
    Thank you for trying to help us

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,046

    Re: Is there a code that tells the user that the printer has no paper when the paper

    Here is a sample GetPrinterStatus function which can be used to check out-of-paper status.

    Option Explicit

    Private Declare Sub
    CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterW" (ByVal pPrinterName As Long, phPrinter As Long, ByVal pDefault As Long) As Long
    Private Declare Function
    ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
    Private Declare Function
    GetPrinter Lib "winspool.drv" Alias "GetPrinterW" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As Long

    Public Enum
    UcsPrinterStatusEnum
        ucsPstReady
    = 0
        
    ucsPstPaused = &H1
        
    ucsPstError = &H2
        
    ucsPstPendingDeletion = &H4
        
    ucsPstPaperJam = &H8
        
    ucsPstPaperOut = &H10
        
    ucsPstManualFeed = &H20
        
    ucsPstPaperProblem = &H40
        
    ucsPstOffline = &H80
        
    ucsPstIoActive = &H100
        
    ucsPstBusy = &H200
        
    ucsPstPrinting = &H400
        
    ucsPstOutputBinFull = &H800
        
    ucsPstNotAvailable = &H1000
        
    ucsPstWaiting = &H2000
        
    ucsPstProcessing = &H4000
        
    ucsPstInitializing = &H8000&
        
    ucsPstWarmingUp = &H10000
        
    ucsPstTonerLow = &H20000
        
    ucsPstNoToner = &H40000
        
    ucsPstPagePunt = &H80000
        
    ucsPstUserIntervention = &H100000
        
    ucsPstOutOfMemory = &H200000
        
    ucsPstDoorOpen = &H400000
        
    ucsPstServerUnknown = &H800000
        
    ucsPstPowerSave = &H1000000
    End Enum

    Private Function
    GetPrinterStatus(DeviceName As String) As UcsPrinterStatusEnum
        
    Const offsetof_PRINTER_INFO_2_Status As Long = 72
        
    Dim hPrinter        As Long
        Dim
    lNeeded         As Long
        Dim
    baData()        As Byte
        
        On
    Error GoTo EH
        
    If OpenPrinter(StrPtr(DeviceName), hPrinter, 0) = 0 Then
            GoTo
    QH
        
    End If
        Call
    GetPrinter(hPrinter, 2, ByVal 0, 0, lNeeded)
        
    ReDim baData(0 To lNeeded) As Byte
        Call
    GetPrinter(hPrinter, 2, baData(0), lNeeded, lNeeded)
        
    If UBound(baData) + 1 < offsetof_PRINTER_INFO_2_Status + 4 Then
            GoTo
    QH
        
    End If
        Call
    CopyMemory(GetPrinterStatus, baData(offsetof_PRINTER_INFO_2_Status), 4)
    QH:
        
    If hPrinter <> 0 Then
            Call
    ClosePrinter(hPrinter)
        
    End If
        Exit Function
    EH:
        
    Debug.Print Err.Description & " &H" & Hex$(Err.Number), Timer
        
    Resume QH
    End Function

    Private Sub
    Form_Load()
        
    Debug.Print IIf(GetPrinterStatus(Printer.DeviceName) And ucsPstPaperOut, "Out of paper", "Ok")
    End Sub

    cheers,
    </wqw>

    Edit: p.s. Posted this code only to show off my syntax highlighter new feature -- can output *indented* inline code using [tt] instead of ordinary [code] tags which might be even more irritating than my blinking avatar. . . :-))

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: Is there a code that tells the user that the printer has no paper when the paper

    Quote Originally Posted by wqweto View Post
    Here is a sample GetPrinterStatus function which can be used to check out-of-paper status.

    Option Explicit

    Private Declare Sub
    CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterW" (ByVal pPrinterName As Long, phPrinter As Long, ByVal pDefault As Long) As Long
    Private Declare Function
    ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
    Private Declare Function
    GetPrinter Lib "winspool.drv" Alias "GetPrinterW" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As Long

    Public Enum
    UcsPrinterStatusEnum
        ucsPstReady
    = 0
        
    ucsPstPaused = &H1
        
    ucsPstError = &H2
        
    ucsPstPendingDeletion = &H4
        
    ucsPstPaperJam = &H8
        
    ucsPstPaperOut = &H10
        
    ucsPstManualFeed = &H20
        
    ucsPstPaperProblem = &H40
        
    ucsPstOffline = &H80
        
    ucsPstIoActive = &H100
        
    ucsPstBusy = &H200
        
    ucsPstPrinting = &H400
        
    ucsPstOutputBinFull = &H800
        
    ucsPstNotAvailable = &H1000
        
    ucsPstWaiting = &H2000
        
    ucsPstProcessing = &H4000
        
    ucsPstInitializing = &H8000&
        
    ucsPstWarmingUp = &H10000
        
    ucsPstTonerLow = &H20000
        
    ucsPstNoToner = &H40000
        
    ucsPstPagePunt = &H80000
        
    ucsPstUserIntervention = &H100000
        
    ucsPstOutOfMemory = &H200000
        
    ucsPstDoorOpen = &H400000
        
    ucsPstServerUnknown = &H800000
        
    ucsPstPowerSave = &H1000000
    End Enum

    Private Function
    GetPrinterStatus(DeviceName As String) As UcsPrinterStatusEnum
        
    Const offsetof_PRINTER_INFO_2_Status As Long = 72
        
    Dim hPrinter        As Long
        Dim
    lNeeded         As Long
        Dim
    baData()        As Byte
        
        On
    Error GoTo EH
        
    If OpenPrinter(StrPtr(DeviceName), hPrinter, 0) = 0 Then
            GoTo
    QH
        
    End If
        Call
    GetPrinter(hPrinter, 2, ByVal 0, 0, lNeeded)
        
    ReDim baData(0 To lNeeded) As Byte
        Call
    GetPrinter(hPrinter, 2, baData(0), lNeeded, lNeeded)
        
    If UBound(baData) + 1 < offsetof_PRINTER_INFO_2_Status + 4 Then
            GoTo
    QH
        
    End If
        Call
    CopyMemory(GetPrinterStatus, baData(offsetof_PRINTER_INFO_2_Status), 4)
    QH:
        
    If hPrinter <> 0 Then
            Call
    ClosePrinter(hPrinter)
        
    End If
        Exit Function
    EH:
        
    Debug.Print Err.Description & " &H" & Hex$(Err.Number), Timer
        
    Resume QH
    End Function

    Private Sub
    Form_Load()
        
    Debug.Print IIf(GetPrinterStatus(Printer.DeviceName) And ucsPstPaperOut, "Out of paper", "Ok")
    End Sub

    cheers,
    </wqw>

    Edit: p.s. Posted this code only to show off my syntax highlighter new feature -- can output *indented* inline code using [tt] instead of ordinary [code] tags which might be even more irritating than my blinking avatar. . . :-))
    --------------------------------------------------------------
    The code shows me a message that the printer is out of paper,
    This is not true, the printer has paper !!!!
    Where is the mistake?

  12. #12
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,046

    Re: Is there a code that tells the user that the printer has no paper when the paper

    What does Debug.Print Hex$(GetPrinterStatus("Your Printer")) print in Immediate Window?

    cheers,
    </wqw>

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Question Re: Is there a code that tells the user that the printer has no paper when the paper

    Quote Originally Posted by wqweto View Post
    What does Debug.Print Hex$(GetPrinterStatus("Your Printer")) print in Immediate Window?

    cheers,
    </wqw>
    -------------------------------

    This is the name of our printer :Brother DCP-LTOE-DW series


    When you use the printer name, an error appears in the code

  14. #14
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,552

    Re: Is there a code that tells the user that the printer has no paper when the paper

    That's why I had suggested EnumPrinters... sometimes the name it expects programmatically and the name it shows you in some places don't match. I don't have a printer to test code on though. It would be similar to wqweto's GetPrinter call-- it's the same data structure. But you'd need an array of it then loop through the names to find yours, after filling it based on the pcReturned number. A point of confusion here-- these function will include virtual printing devices like the Print to PDF driver. So if you're not using a name, you might not get what you expect... MSDN says "If [pPrinter is] NULL, it indicates the local printer server." I don't think that means "the default printer".

  15. #15
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,046

    Re: Is there a code that tells the user that the printer has no paper when the paper

    Quote Originally Posted by Mysystem View Post
    When you use the printer name, an error appears in the code
    What error? Where in the code?

    Try Debug.Print Hex$(GetPrinterStatus(Printer.DeviceName)) if unsure about your actual printer name.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width