Solved

How can I use "EnumPrinters" function?

Posted on 2000-03-20
8
492 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

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