Jump to content

Trouble getting code to work on 64 bit


nlandry83

Recommended Posts

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 by nlandry83
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Thank you BIGAL and yosso for your replies. I've tried both of your suggestions but unfortunately, neither seemed to work.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...