Solved

How can I use "EnumPrinters" function?

Posted on 2000-03-20
8
499 Views
Last Modified: 2012-05-04
Hi friends,

I've got a problem using EnumPrinters (and behind the scenes EnumJobs). The problem is that, in the explanation of declaration, they an array of PRINT_INFO_2 (or others) is expected as a parameter, but in the declaration itself, an LPBYTE variable is expected ?? how can an LPBYTE variable be used as an array that receives information about the printers??
 This problem is crucial in my project and any kind of help will be appreciated.

Thank you,

Wesam
0
Comment
Question by:_Wesam
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2635398
Hi _Wesam,

do it like this:

call the EnumPrinters() function once with pPrinterEnum arg set to NULL and cbBuf set to 0. Then return value then should be the number of bytes needed to save the info. Then allocate these number of bytes somehow like this:

int num = EnumPrinters(...);// with pointer set to NULL
BYTE* pBuf = new BYTE[num];
DWORD count = 0;
EnumPrinters(..., &count );// with the allocated pointer passed
//now you can cast the pointer to PRINT_INFO_2 pointer
PRINT_INFO_2* pPrintInfo = (PRINT_INFO_2)pBuf;
for ( int i = 0; i < count; i++ )
{
 // acces the PRINT_INFO_2 with pPrintInfo[i] here
}



hope that helps,

ZOPPO
0
 

Accepted Solution

by:
wardkd earned 30 total points
ID: 2635410
Simply use a cast to LPBYTE in the call to EnumPrinters().

0
 

Author Comment

by:_Wesam
ID: 2636257
Thank you all for your help. It worked perfectly.

Wesam
0
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!

 
LVL 31

Expert Comment

by:Zoppo
ID: 2636267
Hi _Wesam,

JFI, do you use more part's from my comment or from wardkd's?

ZOPPO
0
 

Author Comment

by:_Wesam
ID: 2636292
Well, I had to modify your code to get it work, I did what wardkd say. Anyway I wanted to ACCEPT your ANSWER, but the browser showed me only an ACCEPT button to wardkd's answer ????
Thank you for your help,

Wesam.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2636330
Now, listen, you should never accept an answer you did not use!!!

You always have possibility to 'reject' an answer.

It's a matter of fairness to award points to those experts which helped you most ar at least as first.
0
 

Expert Comment

by:wardkd
ID: 2639937
The question was:
"how can an LPBYTE variable be used as an array that receives information about the printers?"

Which I believe I answered correctly.

However, if this is going to cause grief for anyone, I'd rather not take the points.

NOTE: If you want something that you say to be taken as THE ANSWER, then submit an answer!
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2639995
I just think it's a bad habit to answer a question AS ANSWER when other experts already posted senseful comments ... and, I think it's good habit posting even an answer AS COMMENT, because it doesn't lock the question and so doesn't decrease other expert's interest.

BTW, who cares .........
0

Featured Post

Industry Leaders: 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

729 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