Solved

How to use EnumPrinters()?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now