Solved

How to use EnumPrinters()?

Posted on 2002-06-16
2
1,117 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 173
iSeries DB2 Query 2 101
dog bark java program 15 132
listing all the respondents to a twitter feed - Java 5 47
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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