Solved

openprinter fails in windows 10 64bit and office 64 bit

Posted on 2016-11-01
6
77 Views
Last Modified: 2016-11-01
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
Comment
Question by:Svgmassive
  • 3
  • 3
6 Comments
 
LVL 57
ID: 41868690
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
 
LVL 57
ID: 41868790
By the way, I checked and your call is correct....in what way does the call fail?

Jim.
0
 

Author Comment

by:Svgmassive
ID: 41868827
its return zero and fails to open the printer
 res = OpenPrinter(Printer.DeviceName, mhPrinter, pDefault)
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 41868882
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
 

Author Comment

by:Svgmassive
ID: 41868924
Jim i tried that but it still returns zero i am looking at the printer defaults
0
 

Author Comment

by:Svgmassive
ID: 41869048
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question