nlandry83 Posted March 21, 2016 Posted March 21, 2016 (edited) I've been using the following function in my code for a few years now on a 32bit version of AutoCAD and now that my company is switching to 64bit I am having trouble getting it to work. If anyone has the time to take a look and see if they know why it might not be working correctly, I would greatly appreciate it. Thank you. 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 Edited March 21, 2016 by nlandry83 Quote
BIGAL Posted March 22, 2016 Posted March 22, 2016 I had a problem with vba 2013 code not working in 2016 simple fix was vbaman open code got to TOOLS then Reference and in my case it had a 2013 library file linked that was no longer there, untick box save etc and works fine now. Quote
yosso Posted March 22, 2016 Posted March 22, 2016 LongPtr vs Long http://blog.nkadesign.com/2013/vba-for-32-and-64-bit-systems/ Quote
nlandry83 Posted March 22, 2016 Author Posted March 22, 2016 Thank you BIGAL and yosso for your replies. I've tried both of your suggestions but unfortunately, neither seemed to work. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.