Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I use "EnumPrinters" function?

Posted on 2000-03-20
8
Medium Priority
?
507 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 120 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
Independent Software Vendors: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

688 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