Solved

openprinter fails in windows 10 64bit and office 64 bit

Posted on 2016-11-01
6
129 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 58
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 58
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 58

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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 …

688 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