Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

openprinter fails in windows 10 64bit and office 64 bit

i have been using the openprinter method to gather printer information just move over to office 64bit now the function fails.
Any solution
Private Type PRINTER_DEFAULTS: pDatatype As String: pDevMode As Long: DesiredAccess As Long: End Type
Private Declare PtrSafe Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long

   Dim pDefault As PRINTER_DEFAULTS: With pDefault: .pDatatype = vbNullString: .pDevMode = 0:  End With
res = OpenPrinter(Printer.DeviceName, mhPrinter, pDefault)
0
Svgmassive
Asked:
Svgmassive
  • 3
  • 3
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
It would be best if you could avoid the 64 bit edition of office.  Microsoft itself is still recommending the 32bit version for most.

 If not, then the call will need to be changed and you'll need to use compiler constants and/or ptrsafe to execute the right code.  That's covered here:

Compatibility Between the 32-bit and 64-bit Versions of Office 2010
http://msdn.microsoft.com/en-us/library/ee691831(office.14).aspx

Read the section "Introducing the VBA 7 Code Base" to see how the compiler constants are used.

There is also a code inspector for 64 bit:

Microsoft Office Code Compatibility Inspector user's guide
http://technet.microsoft.com/en-us/library/ee833946.aspx

 which you can use to run through your code and see what needs to be modified.

also, here are all the new 64 bit calls that were created:

http://www.microsoft.com/download/en/confirmation.aspx?displaylang=en&id=9970

and a list of all the calls that were modified for 64 bit:
http://msdn.microsoft.com/en-us/library/aa383663(VS.85).aspx

Look in this to see if the call was modified.

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
By the way, I checked and your call is correct....in what way does the call fail?

Jim.
0
 
SvgmassiveAuthor Commented:
its return zero and fails to open the printer
 res = OpenPrinter(Printer.DeviceName, mhPrinter, pDefault)
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Ah, sorry, didn't catch it first time around, the call is incorrect.   It's:


Declare PtrSafe Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As LongPtr, pDefault As PRINTER_DEFAULTS) As Long


  phPrinter is LongPtr, not long

Jim.
0
 
SvgmassiveAuthor Commented:
Jim i tried that but it still returns zero i am looking at the printer defaults
0
 
SvgmassiveAuthor Commented:
jim this works, I had to replace the pdefault with  ByVal 0&.

i am almost at the end of the routine,copymemory fails

#If VBA7 Then
Public mhPrinter As LongPtr
 Public Declare PtrSafe Function OpenPrinter Lib "winspool.drv" _
       Alias "OpenPrinterA" (ByVal pPrinterName As String, _
                             phPrn As LongPtr, pDefault As Any) As Long
#Else
Public mhPrinter As Long
 Public Declare PtrSafe Function OpenPrinter Lib "winspool.drv" _
       Alias "OpenPrinterA" (ByVal pPrinterName As String, _
                             phPrn As Long, pDefault As Any) As Long
#End If


res = OpenPrinter(Printer.DeviceName, mhPrinter, ByVal 0&)
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now