Solved

How can I use "EnumPrinters" function?

Posted on 2000-03-20
8
485 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 30

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
 
LVL 30

Expert Comment

by:Zoppo
ID: 2636267
Hi _Wesam,

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

ZOPPO
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 30

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 30

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

762 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