Solved

How to use EnumPrinters()?

Posted on 2002-06-16
2
1,141 Views
Last Modified: 2013-11-20
Hi,
could anyone please post an example code of how to use the EnumPrinters() function? I tried using it,but I get an access violation if I try to access the second (or higher) printer in the returned array - I have more than one printer (network).
Thanks in advance
0
Comment
Question by:ICR
[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
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
Crius earned 50 total points
ID: 7084171
   DWORD              pcbNeeded=0,pcReturned=0,dwBytesNeeded=0,dwReturned=0;
    PRINTER_INFO_4 *   pinfo4 = NULL;

    while(!EnumPrinters(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL, NULL, 4, (LPBYTE) pinfo4, dwBytesNeeded, &dwBytesNeeded, &dwReturned))
        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
        {
            if (pinfo4) LocalFree (pinfo4);
            pinfo4 = (PRINTER_INFO_4 *) LocalAlloc (LPTR, dwBytesNeeded);
        }

    for(i=0;i<(int)dwReturned;i++)
     ((CComboBox *)GetDlgItem(IDC_CmbPrinter))->AddString(pinfo4[i].pPrinterName);
    LocalFree(pinfo4);
0
 
LVL 3

Expert Comment

by:Crius
ID: 7084180
Actually, looks like you don't need the pcbNeeded=0,pcReturned=0 in the code provided.

I copied and pasted from my own project, and it also got the default printer and selected it, etc.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

627 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