Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DeviceCapabilities() buffer

Posted on 2002-06-18
3
Medium Priority
?
407 Views
Last Modified: 2013-11-20
Hi,
I have the following problem.I'm using DeviceCapabilities() to get the paper and tray names a printer supports. However, I can't figure out how to decipher the buffer I get. Could anyone give me a sample code?

Thanks in advance
0
Comment
Question by:ICR
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7089373
Check out http://support.microsoft.com/default.aspx?scid=kb;EN-US;q81245 ("DeviceCapabilities Function Sample Code (Q81245)")
0
 

Author Comment

by:ICR
ID: 7089563
The information here is about how to use the function.I already know that. What I'm asking about, however, is how to use the buffer with the names of the papers/bins I receive - how to separate the names of the papers/bins from the single string I receive.
0
 
LVL 32

Accepted Solution

by:
jhance earned 135 total points
ID: 7089851
It seems pretty straightforward.  The SDK docs say about this:

"Retrieves the names of the printer's paper bins. The pOutput buffer receives an array of string buffers. Each string buffer is 24 characters long and contains the name of a paper bin. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 24 characters long. If pOutput is NULL, the return value is the number of bin entries required."

So you have an array of N strings, all NULL terminated and starting 24 characters apart.  The function returns how many there are.

So basically you could do:

char r[25];

DWORD dwCount = DeviceCapabilities(etc...);
if(dwCount != 0xFFFFFFFF){
  p = pBuffer;
  for(DWORD i=0; i<dwCount; i++){
    memset(r, 0, 25);
    memcpy(r, p, 24);
    AfxMessageBox(r, MB_OK);
    p += 24;
  }
}
else{
  // ERROR!!!
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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