home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch12 / dwspool.cls < prev    next >
Encoding:
Text File  |  1996-02-16  |  3.8 KB  |  109 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "dwSpool"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = True
  8. ' Desaware API Class library
  9. ' Copyright (c) 1995 by Desaware
  10. ' All rights reserved
  11.  
  12. ' Preliminary demonstration edition
  13.  
  14. Option Explicit
  15.  
  16. Private Declare Function apiEnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (ByVal Flags As Long, ByVal Name As String, ByVal Level As Long, pPrinterEnum As Byte, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
  17. Private Declare Function apiEnumPorts Lib "winspool.drv" Alias "EnumPortsA" (ByVal pName As String, ByVal Level As Long, lpbPorts As Byte, ByVal cbBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
  18. Private Declare Function apiEnumMonitors Lib "winspool.drv" Alias "EnumMonitorsA" (ByVal pName As String, ByVal Level As Long, pMonitors As Byte, ByVal cbBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
  19.  
  20. Private Declare Function GetLastError Lib "kernel32" () As Long
  21.  
  22.  
  23.  
  24.  
  25. ' Retrieves a collection of printer objects
  26. Public Function EnumPrinters(Flags As Long, Name As String, Level As Long) As Collection
  27.     Dim needed&
  28.     Dim returned&
  29.     Dim res&
  30.     Dim tbt As Byte
  31.     Dim usename$
  32.     Dim cprinters As New Collection
  33.     Dim x&
  34.     Dim ppi As dwPrinterInfo
  35.     If Name$ = "" Then usename$ = vbNullString Else usename$ = Name
  36.     res& = apiEnumPrinters(Flags, usename$, Level, tbt, 0, needed, returned)
  37.     If needed& = 0 Then
  38.         Set EnumPrinters = cprinters
  39.         Exit Function
  40.     End If
  41.     ReDim ResultBuffer(needed) As Byte
  42.     res& = apiEnumPrinters(Flags, usename$, Level, ResultBuffer(0), needed, needed, returned)
  43.     
  44.     ' Now enumerate create an object for each printer structure
  45.     For x = 1 To returned
  46.         Set ppi = New dwPrinterInfo
  47.         Call ppi.LoadInfo(ResultBuffer(0), Level, x - 1)
  48.         cprinters.Add ppi
  49.     Next x
  50.     Set EnumPrinters = cprinters
  51. End Function
  52.  
  53. ' Retrieves a collection of printer objects
  54. Public Function EnumPorts(Server As String, Level As Long) As Collection
  55.     Dim needed&
  56.     Dim returned&
  57.     Dim res&
  58.     Dim tbt As Byte
  59.     Dim useserver$
  60.     Dim cports As New Collection
  61.     Dim x&
  62.     Dim ppi As dwPortInfo
  63.     If Server$ = "" Then useserver$ = vbNullString Else useserver$ = Server
  64.     res& = apiEnumPorts(useserver, Level, tbt, 0, needed, returned)
  65.     If needed& = 0 Then
  66.         Set EnumPorts = cports
  67.         Exit Function
  68.     End If
  69.     ReDim ResultBuffer(needed) As Byte
  70.     res& = apiEnumPorts(useserver, Level, ResultBuffer(0), needed, needed, returned)
  71.     Debug.Print GetLastError()
  72.     ' Now enumerate create an object for each printer structure
  73.     For x = 1 To returned
  74.         Set ppi = New dwPortInfo
  75.         Call ppi.LoadInfo(ResultBuffer(0), Level, x - 1)
  76.         cports.Add ppi
  77.     Next x
  78.     Set EnumPorts = cports
  79. End Function
  80.  
  81. ' Retrieves a collection of monitor objects
  82. Public Function EnumMonitors(Server As String, Level As Long) As Collection
  83.     Dim needed&
  84.     Dim returned&
  85.     Dim res&
  86.     Dim tbt As Byte
  87.     Dim useserver$
  88.     Dim cmonitors As New Collection
  89.     Dim x&
  90.     Dim ppi As dwPrintMonitor
  91.     If Server$ = "" Then useserver$ = vbNullString Else useserver$ = Server
  92.     res& = apiEnumPorts(useserver, Level, tbt, 0, needed, returned)
  93.     If needed& = 0 Then
  94.         Set EnumMonitors = cmonitors
  95.         Exit Function
  96.     End If
  97.     ReDim ResultBuffer(needed) As Byte
  98.     res& = apiEnumMonitors(useserver, Level, ResultBuffer(0), needed, needed, returned)
  99.     Debug.Print GetLastError()
  100.     ' Now enumerate create an object for each printer structure
  101.     For x = 1 To returned
  102.         Set ppi = New dwPrintMonitor
  103.         Call ppi.LoadInfo(ResultBuffer(0), Level, x - 1)
  104.         cmonitors.Add ppi
  105.     Next x
  106.     Set EnumMonitors = cmonitors
  107. End Function
  108.  
  109.