解决 莫名其妙的问题Printers.Count 2 ,改用API函数 获得默认打印机,枚举打印机等
Public Sub WinNTGetDefaultPrinter(PrinterName As String)
Dim Buffer As String
Dim DeviceName As String
Dim DriverName As String
Dim PrinterPort As Stringwww.yippeesoft.com
\’ Dim PrinterName As String
Dim r As Long
\’ Get the printer information for the currently selected
\’ printer in the list. The information is taken from the
\’ WIN.INI file.
Buffer = Space(1024)
r = GetProfileString("Windows", "device", "", _
Buffer, Len(Buffer))www.yippeesoft.com
\’ Parse the driver name anwww.yippeesoft.comd port name out of the buffer
GetDriverAndPort Buffer, DriverName, PrinterPort
PrinterName = DriverName
End Sub
Public Sub EnumeratePrinters4(iprts As Integer, str() As String)
Dim Success As Boolean, cbRequired As Long, cbBuffer As Long
Dim Buffer() As Long, nEntries As Long
Dim i As Long, PName As String, SName As String
Dim Attrib As Long, Temp As Long
cbBuffer = 3072
ReDim Buffer((cbBuffer \\ 4) – 1) As Long
Success = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
PRINTER_ENUM_LOCAL, _
vbNullString, _
4, _
Buffer(0), _
cbBuffer, _
cbRequired, _www.yippeesoft.com
nEntries)
If Success Then
If cbRequired > cbBuffer Then
cbBuffer = cbRequired
Debug.Print "Buffer too small. Trying again with " & _
cbBuffer & " bytes."
ReDim Buffer(cbBuffer \\ 4) As Long
Success = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
PRINTER_ENUM_LOCAL, _
vbNullString, _
4, _www.yippeesoft.com
Buffer(0), _
cbBuffer, _
cbRequired, _
nEntries)
If Not Success Then
Debug.Print "Error enumerating printers."
Exit Sub
End If
End If
Debug.Print "There are " & nEntries & _
" local and connected printers."
iprts = nEntrieswww.yippeesoft.com
ReDim str(nEntries)
For i = 0 To nEntries – 1
PName = Space$(StrLen(Buffer(i * 3)))
Temp = PtrToStr(PName, Buffer(i * 3))
SName = Space$(StrLen(Buffer(i * 3 + 1)))
Temp = PtrToStr(SName, Buffer(i * 3 + 1))
Attrib = Buffer(i * 3 + 2)
str(i) = PName
\’MsgBox "Printer: " & PName \’ + "Server: " & Str(SName) + "Attributes: " & Str(Hex$(Attrib))
Next i
Else
iprts = 0
End If
End Sub
For additional information on determining which 32-Bit for Windows NT 3.51, Windows NT 4.0 and Windows 95, click the article number below to view the article in the Microsoft Knowledge Base:
历史博文
- 20081118 bios aa - 2009
- 20071024 kvm uclinux error - 2008
- 20070221 cvs out of memory - 2007
- 0318 东方红 朗诵词 音乐舞蹈史诗《东方红》 - 2006
- 不可一世史館莊姜 - 2005
- Process.StandardOutput 属性 - 2005
- 莫名其妙的问题Printers.Count 2 - 2005