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
Solved

How to use EnumPrinters()?

Posted on 2002-06-16
2
1,092 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
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 51
Expand macro to include alternate header placement and naming 5 75
Separate files macro - Errors on larger data set 18 73
post4 challenge 28 104
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

790 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