| |

VerySource

 Forgot password?
 Register
Search
View: 1024|Reply: 6

Neighborhoods OpenPrinter2 function

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-5 20:00:01
| Show all posts |Read mode
To get the handle of the specified printer, use the following statement:

Dim pd As PRINTER_DEFAULTS
Dim PrinterHandle As Long
Dim Result As Long
Dim PrinterName As String
    pd.pDataType = vbNullString
    pd.pDevMode = 0&
    pd.DesiredAccess = PRINTER_ALL_ACCESS
    PrinterName = "Canno S220SP"
    Result = OpenPrinter2 (PrinterName, PrinterHandle, pd)

For local printer name:
PrinterName = "Canno S220SP"
Execution was successful,

But shared this printer, on another machine via the network printer name:
PrinterName = "\\A003\Canno S220SP"
To get PrinterHandle, but it doesn't work!

Ask the heroes, how to use OpenPrinter2 to get the PrinterHandle of the printer on the network?
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-5 10:15:01
| Show all posts
PrinterName = "\\A003\Canno S220SP"

    If OpenPrinter (PrinterName, hPrinter, 0&) <> 0 Then
hPrinter is what you want

Public Declare Function OpenPrinter Lib "winspool.drv" Alias ​​"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-8-12 22:15:01
| Show all posts
The hero upstairs misunderstood, OpenPrinter is ok, I am using OpenPrinter2 and there is a problem
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-14 16:45:01
| Show all posts
The original poster, which library does this function of OpenPrinter2 come from?
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-8-19 14:15:01
| Show all posts
rajah1982brother:

The definitions of OpenPrinter and OpenPrinter2 are as follows

Private Declare Function OpenPrinter2 Lib "winspool.drv" Alias ​​"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-8-24 22:30:01
| Show all posts
Is anyone here?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 09:30:01
| Show all posts
After I opened the handle obtained by OpenPrinter with GetPrinter, the status member in the PRINTER_INFO_2 structure could not find the error code "Unable to connect", but Windows 2003 itself can determine if a network printer is in the [Printers and Faxes] list due to network connection. Nowhere, "Unable to connect" will be displayed in the [Status] column. I don't know how Windows does it.
I guess that you may use OpenPrinter2, an undocumented API, and use the PRINTER_OPTIONS parameter to obtain a remote handle because there are the following options for PRINTER_OPTIONS in msdn

The PRINTER_OPTION_FLAGS enumeration is used to specify the caching of a handle for a printer opened with OpenPrinter2.

typedef enum
{
  PRINTER_OPTION_NO_CACHE,
  PRINTER_OPTION_CACHE,
  PRINTER_OPTION_CLIENT_CHANGE
} PRINTER_OPTION_FLAGS;

PRINTER_OPTION_NO_CACHE
The handle is not cached. All functions applied to a handle returned by OpenPrinter2 will go to the remote computer.
PRINTER_OPTION_CACHE
The handle is cached. All functions applied to a handle returned by OpenPrinter2 will go to the local cache.
PRINTER_OPTION_CLIENT_CHANGE
The handle returned by OpenPrinter2 can be used by SetPrinter to rename the printer connection.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list