Discussion Locked

How do I use EnumJobs API in VB6

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do I use the EnumJobs API in VB6 to get the status of print jobs in the spooler?

8 replies

by mohammad_m_saggaf

Hi,Source code U can use.
Type SYSTEMTIME
Type JOB_INFO_1
Type FILETIME
Declare Function EnumJobs ...
Declare Function OpenPrinter ...
Declare Function lstrcpy ...
Declare Sub MoveMemory ...
Declare Function FileTimeToLocalFileTime ...
Declare Function FileTimeToSystemTime ...
Declare Function SystemTimeToFileTime ...
Sub Form_Load()
Dim Result1,Result2,nJobs,I
Dim TheJob() As JOB_INFO_1,ByteBuf() As Byte,ReturnedBytes,NumOfJobs,STime As String,PrntH
Dim UFT As FILETIME,LFT As FILETIME,LST As SYSTEMTIME
nJobs=9
LVPrinterJobs.ListItems.Clear
Result1=OpenPrinter(Printer.DeviceName,PrntH,ByVal vbNull)
If Result1>0 Then
Result2=EnumJobs(PrntH,0,nJobs,1,ByVal "",0,ReturnedBytes,NumOfJobs)
If ReturnedBytes=0 Then Exit Sub'NoJobs
ReDim TheJob(ReturnedBytes-1)
ReDim ByteBuf(ReturnedBytes-1)
Result2=EnumJobs(PrntH,0,nJobs,1,ByteBuf(0),ReturnedBytes,ReturnedBytes,NumOfJobs)
If Result2>0 Then
MoveMemory TheJob(0),ByteBuf(0),Len(TheJob(0))* NumOfJobs
For I=0 To NumOfJobs-1
Result1=SystemTimeToFileTime(TheJob(I).Submitted,UFT)
Result1=FileTimeToLocalFileTime(UFT,LFT)
Result1=FileTimeToSystemTime(LFT,LST)
STime=LST.wHour & ":" & LST.wMinute
With LVPrinterJobs
.ListItems.Add,,TheJob(I).JobId
.ListItems(.ListItems.Count).ListSubItems.Add 1,,LPSTRtoVBString(TheJob(I).pPrinterName)
'Cont. to add to LV.
End With
Next
End If
End If
End Sub
Function LPSTRtoVBString(ByVal LPSTR As String,Optional ByVal maxlen As Long =256) As String
Dim sBuff As String
If LPSTR <> "" Then
sBuff = String$(maxlen,0)
If 0<>lstrcpy(StrPtr(sBuff),LPSTR) Then
LPSTRtoVBString=Left$(sBuff,InStr(sBuff,vbNullChar)-1)
LPSTRtoVBString=StrConv(LPSTRtoVBString,vbUnicode)
End If
End If
End Function
Function GetStatus(JStatus As Long) As String
If JStatus=0 Then Exit Function
'Get status string
End Function
I Hope I helped.Coz size limit I cut the code.If u want source file contact me.

This discussion is closed to new replies.