几年来,我一直在我的代码中使用以下函数,现在在32位版本的AutoCAD上,现在我的公司正在切换到64位,我很难让它工作。如果有人有时间看一看,看看他们是否知道为什么它可能无法正常工作,我将不胜感激。非常感谢。
- Function GetCurrentPrinters() As Variant
-
- Dim Buffer() As Long
- Dim PrintInfo() As PRINTER_INFO_4
- Dim NumBytes As Long, NumNeeded As Long, NumPrinters As Long
- Dim RetVal As Long, c As Long, Success As Boolean
- Dim AllPrinters() As String
-
- NumBytes = 3072
- ReDim Buffer(0 To (NumBytes \ 4) - 1) As Long
-
- Success = EnumPrinters(PRINTER_ENUM_LOCAL + PRINTER_ENUM_CONNECTIONS, "", 4, Buffer(0), NumBytes, NumNeeded, NumPrinters)
- If Success Then
- If NumNeeded > NumBytes Then
- NumBytes = NumNeeded
- ReDim Buffer(0 To (NumBytes \ 4) - 1) As Long
- Success = EnumPrinters(PRINTER_ENUM_LOCAL + PRINTER_ENUM_CONNECTIONS, "", 4, Buffer(0), NumBytes, NumNeeded, NumPrinters)
- If Not Success Then
- MsgBox "Error Enumerating Printers", vbInformation, "Message"
- End If
- End If
- Else
- MsgBox "Error Enumerating Printers", vbInformation, "Message"
- End If
- If Success And NumPrinters > 0 Then
- ReDim PrintInfo(0 To NumPrinters - 1) As PRINTER_INFO_4
- For c = 0 To NumPrinters - 1
- PrintInfo(c).pPrinterName = Space(StrLen(Buffer(c * 3)))
- RetVal = PtrToStr(PrintInfo(c).pPrinterName, Buffer(c * 3))
- PrintInfo(c).pServerName = Space(StrLen(Buffer(c * 3 + 1)))
- RetVal = PtrToStr(PrintInfo(c).pServerName, Buffer(c * 3 + 1))
- PrintInfo(c).Attributes = Buffer(c * 3 + 2)
-
- Next c
-
- ReDim Preserve AllPrinters(NumPrinters)
- For c = 0 To NumPrinters - 1
-
-
- AllPrinters(c) = PrintInfo(c).pPrinterName
-
- Next c
- Else
- MsgBox "No Printers Found", vbInformation, "Message"
- End If
- GetCurrentPrinters = AllPrinters
-
-
- End Function
|