Device Context of Network Printer


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Device Context of Network Printer

  1. #1
    Tim Miller Guest

    Device Context of Network Printer

    Can anyone help me figure this out.

    I'm using VB6 and I need to retrieve the device context of a network
    printer. This printer will not be in my list of printers so I need to be
    able to refer to it using unc syntax.

    I have tried using OpenPrinter api. This returns a handle to the printer.
    Then I use GetDC which accepts a handle to the device and is supposed to
    return a hDC. It seems to work but I am unable to get anything to print when
    using this hDC.

    If I use a hDC of one of my built-in printer objects everything works fine.

    Here is some sample code I have been trying to get to work:

    I have a shared printer here on my network on a machine named inetsrv called
    bro1 (\\inetsrv\bro1).

    I try CreateDC to get the device context.

    ' Works with printer in my printer list (even though not a local printer)
    hDC = CreateDC("", "Brother HL-1240 series", 0, ByVal CLng(0))

    ' This does not work
    hDC = CreateDC("", "\\INETSRV\BRO1", 0, ByVal CLng(0))


    I try to use GetDC. GetDC requires a handle to the printer. So I use
    OpenPrinter to get the handle.

    ' Returns a handle and seems to return a dc but nothing gets printed.
    I'm not sure it is a valid dc
    nRes = OpenPrinter("Brother HL-1240 series", hPrinter, 0&)
    hDC = GetDC(hPrinter)

    ' Returns a handle and seems to return a dc but nothing gets printed.
    I'm not sure it is a valid dc
    nRes = OpenPrinter("\\INETSRV\BRO1", hPrinter, 0&)
    hDC = GetDC(hPrinter)

    Thanks in advance.

    Tim



  2. #2
    R. Shroff Guest

    Re: Device Context of Network Printer


    Hello Tim,

    Before you can access any printer, you must "install" that printer on the
    loacl machine.

    In your example "\\INETSRV\BRO1" is in effect the "port" that you would use
    when installing the printer.

    In VB the Printers collection holds a collection of VB.Printer objects.
    Each VB.Printer has the following
    "Device Name" ( friendly name to refer to that printer),
    "Driver name" ( the name of the device driver) and
    "Port" in your case "\\INETSRV\BRO1"

    I hope the above helps.

    Regards, Roomy.


    "Tim Miller" <tmiller@aicsoft.com> wrote:
    >Can anyone help me figure this out.
    >
    >I'm using VB6 and I need to retrieve the device context of a network
    >printer. This printer will not be in my list of printers so I need to be
    >able to refer to it using unc syntax.
    >
    >I have tried using OpenPrinter api. This returns a handle to the printer.
    >Then I use GetDC which accepts a handle to the device and is supposed to
    >return a hDC. It seems to work but I am unable to get anything to print

    when
    >using this hDC.
    >
    >If I use a hDC of one of my built-in printer objects everything works fine.
    >
    >Here is some sample code I have been trying to get to work:
    >
    >I have a shared printer here on my network on a machine named inetsrv called
    >bro1 (\\inetsrv\bro1).
    >
    >I try CreateDC to get the device context.
    >
    > ' Works with printer in my printer list (even though not a local printer)
    > hDC = CreateDC("", "Brother HL-1240 series", 0, ByVal CLng(0))
    >
    > ' This does not work
    > hDC = CreateDC("", "\\INETSRV\BRO1", 0, ByVal CLng(0))
    >
    >
    >I try to use GetDC. GetDC requires a handle to the printer. So I use
    >OpenPrinter to get the handle.
    >
    > ' Returns a handle and seems to return a dc but nothing gets printed.
    >I'm not sure it is a valid dc
    > nRes = OpenPrinter("Brother HL-1240 series", hPrinter, 0&)
    > hDC = GetDC(hPrinter)
    >
    > ' Returns a handle and seems to return a dc but nothing gets printed.
    >I'm not sure it is a valid dc
    > nRes = OpenPrinter("\\INETSRV\BRO1", hPrinter, 0&)
    > hDC = GetDC(hPrinter)
    >
    >Thanks in advance.
    >
    >Tim
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center