List printers on the server

Source: Internet
Author: User
Tags arrays knowledge base
Component logic
This component is written "hard" to show how to invoke the Wivdons API in VB, and if you use the printer class in VB5, you can achieve the same function.
This component invokes the EnumPrinters function that is used by Windows2000. This function returns a list of printers in one of five formats, which is determined by the "rank" you determine. In this example, we use level fourth, which simply enumerates the names and locations of the printers that our NT servers are connected to (direct or network connections).
 
Attention
The component code shown here applies only to Windows NT, and if you run personal Web server on Windows95, use level fifth. Windows 95 treats a network printer as a local printer.
The fifth-tier print structure is slightly different from level fourth, using the VB5 API browser to copy the PRINTER_INFO_5 structure to your code.
 
This is a powerful API call that can take many different parameters. Visual C's Help file provides details on how to use the EnumPrinters function, but translating C-form syntax into a VB statement can be challenging. You can download the Microsoft Knowledge Base article Q166008 from the www.microsoft.com network to obtain additional details about how to translate.
We will return the information in a long integer group because it is easier to manipulate and index than other lower-level storage structures. By Ptrtostr and Strlen calls, we are able to convert long integer arrays into strings, which are easiest to use in VB.
When we determine how many printers are connected to the system, we ReDim (redefine) two arrays (M_adevicename and M_servername) to store the number of discovered printers. If the printer is not found, the code will not execute because the error-handling code will take over the execution of the program.
 
Writing source code
Once again, start a new VB6 ActiveX DLL project, VB shows a default code window named Class1, press F4, press the following modify property sheet:
(Name) Webprinters
Instancing 5-multiuse
Select Projects | Project 1 Properties changes the item name to Web Utils and selects unattended Execution. Option finally click the Make Table Bar of the dialog box and select Auto Increment, and press OK to save the settings.
The following code contains the source code for the printer component, which simply lists the printers on your system-you can extend the code to complete the actual print task. Unlike the previous VB component, this example uses the Get and let properties of VB. The discussion of these properties is beyond the scope of this example, but Microsoft's Visual books Online (bundled with VB5) contains a deep explanation of these two attributes.
Option Explicit
Private Declare Function enumprinters Lib "Winspool.drv" _
Alias "Enumprintersa" _

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.