Solved

How to use EnumPrinters()?

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

Technology Partners: 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
only14 challenge 19 84
FizzBuzz challenge 9 84
Unix Command -- Challenging  question 7 101
how to use laptop or pad camera in vb.net windows application 2 103
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.

685 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