Solved

openprinter fails in windows 10 64bit and office 64 bit

Posted on 2016-11-01
6
97 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

726 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