Printer API call (long) 
Author Message
 Printer API call (long)

Hello and HELP,

I am working on a project where I need to get the status of jobs in the print queue. I am using the OpenPrinter api call to get a handle to the printer, and that seems to be fine.  I am then calling the EnumJobs function.  On the inital call it is not returning any jobs in the queue, even though I can see jobs in the queue.  I am forcing nothing to print by not providing the printer any paper.  I went to and found examples there.  Our code matches that and our code runs in VB6.  I have attached the code below.  Any help would be of great help.


Module PrintMod
    ' constants for DesiredAccess member of PRINTER_DEFAULTS
    Public Const PRINTER_ACCESS_USE = &H8

    Public Structure PRINTER_DEFAULTS
        Dim pDatatype As Long
        Dim pDevMode As Long
        Dim DesiredAccess As Long
    End Structure

    Structure SYSTEMTIME
        Dim wYear As Integer
        Dim wMonth As Integer
        Dim wDayOfWeek As Integer
        Dim wDay As Integer
        Dim wHour As Integer
        Dim wMinute As Integer
        Dim wSecond As Integer
        Dim wMilliseconds As Integer
    End Structure

    Structure JOB_INFO_1
        Dim JobId As Long
        Dim pPrinterName As Long
        Dim pMachineName As Long
        Dim pUserName As Long
        Dim pDocument As Long
        Dim pDatatype As Long
        Dim pStatus As Long
        Dim Status As Long
        Dim Priority As Long
        Dim Position As Long
        Dim TotalPages As Long
        Dim PagesPrinted As Long
        Dim Submitted As SYSTEMTIME
    End Structure

    Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _
        (ByVal pPrinterName As String, ByRef phPrinter As Long, ByRef pDefault As PRINTER_DEFAULTS) As Long

    Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" _
    (ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, _
    ByVal Level As Long, ByRef pJob As String, ByVal cdBuf As Long, _
    ByRef pcbNeeded As Long, ByRef pcReturned As Long) As Long

End Module

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Function RefreshPrinterQueue()

        Dim pd As PRINTER_DEFAULTS

        Dim hPrinter As Long
        Dim lngJobsFirstJob As Long, lngJobsEnumJob As Long, lngJobsLevel As Long
        Dim lngJobsNeeded As Long, lngJobsReturned As Long
        Dim byteJobsBuffer() As Byte, udtJobInfo1() As JOB_INFO_1
        Dim lngJobsCount As Long
        Dim lngResult As Long

        Dim byteBuffer(64) As Byte
        Dim strDocument As String, strStatus As String, strOwnerName As String

        ' set the PRINTER_DEFAULTS members
        pd.pDatatype = 0&
        pd.DesiredAccess = PRINTER_ALL_ACCESS Or pd.DesiredAccess

        lngResult = OpenPrinter("\\funnycar\mis3q", hPrinter, pd)

        lngJobsFirstJob = 0 ' zero-based position within the print queue of the first print job to enumerate

        lngJobsEnumJob = 99 ' total number of print jobs to enumerate

        lngJobsLevel = 1    ' Specifies whether the function should use JOB_INFO_1
        ' or JOB_INFO_2 structures to store data for the enumerated jobs

        lngResult = EnumJobs(hPrinter, lngJobsFirstJob, lngJobsEnumJob, _
                             lngJobsLevel, "", 0, _
                             lngJobsNeeded, lngJobsReturned)

    End Function

End Class


Lyle McNeal

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!

Wed, 24 Dec 2003 01:46:52 GMT  
 Printer API call (long)

It doesn't look to me like you have don't the VB6->VB.Net type conversion. A
VB6 Long must be converted to a VB.Net Integer. A VB6 Integer to a VB.Net
Short. This plays havoc with API declarations, particularly structures.

Reply in the newsgroup so everyone can benefit

Wed, 24 Dec 2003 02:04:03 GMT  
 Printer API call (long)
That was exactly what the problem was.  Thank you very much.

*{*filter*} himself like the bad little programmer he is*

Lyle McNeal

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!

Wed, 24 Dec 2003 02:28:20 GMT  
 Printer API call (long)

> *{*filter*} himself like the bad little programmer he is*

You made me laugh so hard.

Do you have _any_ idea of the who's who of VB/VB.Net that you join in making
this mistake???

Reply in the newsgroup so everyone can benefit

Wed, 24 Dec 2003 03:48:44 GMT  
 [ 4 post ] 

 Relevant Pages 

1. what is API call for long timer

2. API-Call to convert long filename to 8.3???

3. API call to get long filenames???!

4. Long filenames ans API calls, grmpf...

5. PROBLEM: Adding a printer via API, then creating a printer Share via API (source included)

6. Help Wanted with Printer API call's

7. API Calls to Change the Default Printer

8. Using API-call to find printers

9. Printer Orientation calling api

10. Changing default printer using API calls

11. Printer selection via API call

12. Printer Api Call


Powered by phpBB® Forum Software