0

I am working on printer set up function. Microsoft has DeviceCapabilities API, let you retrieve printers setting information.

The function uses dmPaperSize for paper size, DMPAPER_A4 is one of the members in dmPaperSize. A4 paper is defined as DMPAPER_A4 that has value 9 in my printer. My question is whether DMPAPER_A4 is always 9 for all the printers?

Also for dmDefaultSource, do all the member of dmDefaultSource has same value across every printers (if it can be installed in windows)?

Thanks.

Carey Gregory
  • 6,836
  • 2
  • 26
  • 47
peter
  • 1,009
  • 3
  • 15
  • 23

1 Answers1

0

Yes, DMPAPER_A4 is defined in the Windows SDK header files as 9. That means A4 paper size will be identified with the value 9 on all printers. So if you need to check for that value on a platform where you can't use the Windows header files, you can safely assume 9 is A4 paper size.

Theoretically, Microsoft could change that value because they only guarantee the constant DMPAPER_A4 will represent A4 paper and not that it will always have the value 9. But in practice there's no way Microsoft would ever do that. They would break hundreds of applications with such a move so you should be safe coding the value 9 if you have no way of using the official constant names.

As for dmDefaultSource, all the members of the Win32 printing subsystem that have documented names or values are the same for all printers. A printer that didn't adhere to the Windows standards wouldn't work on Windows.

Carey Gregory
  • 6,836
  • 2
  • 26
  • 47
  • I just found my printer HP Officejet Pro 8500 A910 has bin number 15, 259, 258, 257 and bin name are Automatically Select, Printer Auto Select, Tray 1, Tray 2. – peter Oct 23 '15 at 00:53
  • and My pdf995 has bin number 15, 157, names are Automatically Select, onlyone. OnlyOne should be number 1. and 15 should be DMBIN_FORMSOURCE. It seems printers does not conform to ms standard. – peter Oct 23 '15 at 00:57
  • @peter It would be no surprise that a virtual printer like pdf995 doesn't conform, but an HP printer should. I'm not sure what you're saying you think doesn't conform about the HP. – Carey Gregory Oct 23 '15 at 01:19
  • Thank you for your help. I think the bin name for the bin number 15 should be DMBIN_FORMSOURCE or FORMSOURCE. Automatically Select should be DMBIN_AUTO = 7. I am not sure if I am correct. – peter Oct 25 '15 at 22:17
  • You need to pose a new question. I answered the one you asked as best I can but what you're asking now isn't clear at all. – Carey Gregory Oct 26 '15 at 04:33
  • "Theoretically, Microsoft could change that value because they only guarantee the constant DMPAPER_A4 will represent A4 paper and not that it will always have the value 9." -- Well, no. There is no constant DMPAPER_A4 in any executable, just the number. The constant is only for the programmer's convenience, nothing beyond that. So they can't change it under any circumstances without risking blowing up everything. Besides, there always is a way to use the constant names, it's just that: `const int DMPAPER_A4 = 9;` – Gábor Jun 28 '17 at 13:41
  • @Gábor Um, sure they can. Microsoft can change the actual value behind any constant any time they want. Yes, that will break existing programs unless the product owners obtain the new header files and recompile, but they _can_ do it and _have_ done it. I do agree it's very unlikely they would do it, however. – Carey Gregory Jun 28 '17 at 13:47
  • @Carey Gregory Ok, ok, it wasn't a question of whether they have the power to do. :-) What I meant was that there were no two separate entities, a constant and a value, so that you can change one without affecting the other. There is only one entitiy, the value. The constant doesn't exist in the running program. – Gábor Jun 28 '17 at 18:48
  • 1
    @Gábor I understand that. It's basic C++. I kind of figured anyone writing code for the Win32 API most likely understands it. – Carey Gregory Jun 28 '17 at 19:56
  • @Gábor, the reason the answer says Microsoft would break hundreds of applications if they changed the value, is because the author of this answer already knew how macros worked. Not sure what your comment adds to the discussion. – Ed Bayiates Jun 28 '17 at 20:05
  • I really didn't want to drag it out that much. :-) It was meant as a very mild remark on a sentence that isn't really correct: "Theoretically, Microsoft could change that value because they only guarantee the constant DMPAPER_A4 will represent A4 paper and not that it will always have the value 9." There is no distinction between name and value, they are the same for all intents and purposes. They practically guarantee either both or none. But let's drop it, it's not worth that much. :-) – Gábor Jun 29 '17 at 08:04