|
-
Mar 18th, 2004, 03:38 AM
#1
Thread Starter
Member
API call need help
I am trying to use the EnumJobs API. I am successful in Opening the printers and closing. Trying to use the enumjobs api is giving me error 5, Procedure call or argument is not valid. The following is the program listing. You can assume that the printer handle is correct.
I think that my problem is in passing the right parameters, especially the returned info2 array.
<DllImport("winspool.drv", EntryPoint:="EnumJobsA", SetLastError:=True, _
CharSet:=CharSet.Ansi, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function Getjobs(ByVal ptrPrnHandle As IntPtr, ByVal FirtsJob As Integer, ByVal NoJobs As Integer, ByVal InfoLvl As Integer, <OutAttribute()> ByRef JobsPtr As Byte(), ByVal JobsBuff As Integer, ByVal BufferSize As Integer, ByVal JobsREturned As Integer) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="OpenPrinterA", SetLastError:=True, _
CharSet:=CharSet.Ansi, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function openPrintDrv(ByVal strPrnName As String, ByRef intPrnHandle As IntPtr, ByVal intDefault As PRINTER_DEFAULTS) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="ClosePrinter", SetLastError:=True, _
CharSet:=CharSet.Ansi, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function ClosePrint(ByRef ptrPrnHandle As IntPtr) As Boolean
End Function
'******** Opening Printer
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim intHandle As IntPtr
Dim myint As IntPtr
Dim Currprn As New Printing.PrinterSettings
Dim IntDefault As PRINTER_DEFAULTS
Dim strPrint As String
Dim retval As Boolean
strPrint = cmbPrinters.SelectedText
IntDefault.pDatatype = Nothing
IntDefault.pDevMode = Nothing
IntDefault.DesiredAccess = PrinterAccessRights.PRINTER_ACCESS_ADMINISTER
retval = openPrintDrv(cmbPrinters.SelectedItem, intHandle, IntDefault)
lblPrnHandle.Text = intHandle.ToInt32
If retval = False Then
MessageBox.Show("Handle not created")
lblErrNo.Text = Err.LastDllError
lblError.Text = ErrorToString(Err.LastDllError)
Else
fillArray(intHandle)
End If
End Sub
Private Sub fillArray(ByRef prnHandle As IntPtr)
Dim ArrInfo2 As Byte() = {0}
Dim intFirstJob, intInfoLevel, intNoOfJobs, intBufferSize As Integer
Dim retval As Boolean
'GET the buffer size required
retval = Getjobs(prnHandle, 0, 120, 2, ArrInfo2, 0, intBufferSize, intNoOfJobs)
' ***** Retval is returning false and arrinfo2 is nothing
If retval = False Then
MessageBox.Show("Buffer size Unknown")
lblErrNo.Text = Err.LastDllError
lblError.Text = ErrorToString(Err.LastDllError)
End If
If retval = True Then
retval = Getjobs(prnHandle, 0, 500, 2, ArrInfo2, 0, intBufferSize, intNoOfJobs)
lblNoJobs.Text = intNoOfJobs
End If
retval = ClosePrint(prnHandle)
End Sub
Any Help ?
Last edited by stems; Mar 18th, 2004 at 11:27 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|