If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

openprinter api

i am working on some code that used the openprinter api to send print code to a generic text printer. the code works fine in windows xp but when i go to run the same app on windows 7 it fails. is there a different api that needs to be used for windows 7 or is this a windows 7 security thing?
thanks

Re: openprinter api

If a user does not have permission to open a specified printer or print server with the desired access, the OpenPrinter call will fail with a return value of zero and GetLastError will return the value ERROR_ACCESS_DENIED.

You can call the OpenPrinter function to open a handle to a print server or to determine the access rights that a client has to a print server. To do so, specify the name of the print server in the pPrinterName parameter, set the pDatatype and pDevMode members of the PRINTER_DEFAULTS structure to NULL, and set the DesiredAccess member to specify a server access mask value such as SERVER_ALL_ACCESS. When you are finished with the handle, pass it to the ClosePrinter function to close it.

Re: openprinter api

the printer is a network printer that is shared off from another pc. on the windows 7 box the printer is set up to allow user 'EVERYONE' full access to the printer so i would not think it is a permissions issue. i could be wrong though.

Re: openprinter api

Oops, the final parameter in the OpenPrinter API is a structure. The default API declaration appears to be:

Code:

Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, ByRef phPrinter As Long, ByRef pDefault As Any) As Long
Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As DEVMODE
DesiredAccess As Long
End Type
Private Const CCHDEVICENAME As Long = 32
Private Const CCHFORMNAME As Long = 32
Private Const PRINTER_ACCESS_USE AS Long = 8

Re: openprinter api

dougg, did you ever resolve this? I'm having the same problem. The call worked fine under XP, then the user got a Windows 7 machine last week, and it no longer works. The code is VBA in Access 2003. I'm trying LaVolpe's suggestion, passing a PRINTER_DEFAULTS structure with DesiredAccess of 8 (it was previously just passing a NULL third argument), and it's not crashing, but it also still returns FALSE. Err.LastDllError, however, is returning 3012, unlike your case. Some other Google searching indicates this may mean "Printer Not Found".