Results 1 to 9 of 9
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    API call - printer properties Duplexing +more

    (Edited by HansV to activate URL - see <!help=19>Help 19<!/help>)

    HI

    I'm a Word VBA programmer but new to API programming.
    I've found the following code 'Set Duplex Printing for Word Automation' in <!mskb=230743>Microsoft Knowledge Base Article 230743<!/mskb>.

    Ive managed to get this working.
    Our printers have other features that I would like to utilise via code. ie stapling, multiple pages per sheet etc well any of the printer features really I would like to be able to use.

    Theres public constants defined in this code ie
    Public Const DM_DUPLEX = &H1000&
    Public Const DM_IN_BUFFER = 8

    Public Const DM_OUT_BUFFER = 2
    Public Const PRINTER_ACCESS_ADMINISTER = &H4
    Public Const PRINTER_ACCESS_USE = &H8
    Public Const STANDARD_RIGHTS_REQUIRED = &HF0000

    If I wanted to add stapling & multiple pages (& use the other printer features) I was thinking of adding addditional var's in eg

    Public Type DEVMODE
    dmStaple as integer
    dmMultiplePagesPerSheet as integer
    End Type

    The variable DM_DUPLEX is assigned a fixed constant. (is that a hexidecimal?)
    I was thinking I would have to assign a constant to Stapling & MultiplePagesPersheet.

    Is the DM_DUPLEX constant a hexidecimal number?
    How would I go about obtaining this value for Stapling & MultiplePagesPersheet.

    I've been reading about API programming & it seems a more powerful & flexible way to program. would that be correct?
    Am I heading down the correct path to do this?
    Has anyone done any API programming/calls?

    many thanks
    Diana [img]/forums/images/smilies/ohmy.gif[/img]

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: API call - printer properties Duplexing +more

    Hi Diana,

    Microsoft makes a part of the functionality of Windows and of the Office apps available through VB/VBA. Sometimes, programmers want to do things in Windows that are not available in VB/VBA by default. In such cases, you can try to see if the layer below VB/VBA can do what you want. This layer, Windows API's, allows you to do things that standard VBA doesn't, but you have to work hard for it. You also have much more opportunities to mess things up in a spectacular way.

    Windows APIs are very powerful, but they require you to do things just so. For instance, you can't just go and add a few custom constants to the DevMode type. DevMode is a type with a very specific structure; if you modify it, the Windows functions that use DeveMode will not work correctly, or not at all, or crash your macro. I don't think that extras such as stapling are available in code.

    The constant declarations starting with & H (no space between them) use hexadecimal numbers indeed. The decimal system uses 10 as base, and hexadecimal uses what we call 16 as base. Counting in hexadecimal starts normally, but it has extra digits:

    <table border=1><td align=right>Decimal</td><td align=right>Hexadecimal</td><td align=right>8</td><td align=right>8</td><td align=right>9</td><td align=right>9</td><td align=right>10</td><td align=right>A</td><td align=right>11</td><td align=right>B</td><td align=right>12</td><td align=right>C</td><td align=right>13</td><td align=right>D</td><td align=right>14</td><td align=right>E</td><td align=right>15</td><td align=right>F</td><td align=right>16</td><td align=right>10</td><td align=right>17</td><td align=right>11</td><td align=right>...</td><td align=right>...</td><td align=right>25</td><td align=right>19</td><td align=right>26</td><td align=right>1A</td><td align=right>...</td><td align=right>...</td><td align=right>31</td><td align=right>1F</td><td align=right>32</td><td align=right>20</td><td align=right>33</td><td align=right>21</td></table>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: API call - printer properties Duplexing +more

    > How would I go about obtaining this value for Stapling & MultiplePagesPersheet.

    Your printer vendor and/or printer driver supplier should be able to tell you these values, as well as the manner in which they must be passed. If you get documentation for C/C++, try posting it here anyway. There are some who are conversant enough to give you VB style declarations.

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: API call - printer properties Duplexing +more

    Thanks Hans/Jscher

    Hans from you post...as I understand it API calls are like 'fixed' code which obtains info from windows.
    So the following variables are declared in DEVMODE:

    Public Type DEVMODE
    dmDeviceName As String * 32

    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * 32
    dmUnusedPadding As Integer
    dmBitsPerPel As Integer
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
    dmICMMethod As Long
    dmICMIntent As Long
    dmMediaType As Long
    dmDitherType As Long
    dmReserved1 As Long
    dmReserved2 As Long
    End Type

    & I just cant declare my own variables like dmStapling & dmMultipePagesPerSheet.

    However if the printer/printer driver supports these features ie stapling & multiplePagesPerSheet then that information must be stored somewhere in Windows to be able to extract & set the settings?
    How would I get access to that information?
    Would that be another API call to get & set the information?

    Diana
    Note: the vendors dont know this type of information.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: API call - printer properties Duplexing +more

    Those are not variables in the sense you mean. They are more like fields in a table or elements in an array. They're declared as part of the DEVMODE type, so that the programmer can make easier use of the information returned by Windows. The information is returned in a masked string and the code that handles it extracts the particular bits of information from that string and assigns them to the elements of the type so the programmer can work with them. The vendor is the only one who can tell you what the length and shape of that string is like. If the printer driver supports stapling, then the printer vendor has to tell you how that information is returned to Windows and whether it is actually exposed by the driver.
    Charlotte

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: API call - printer properties Duplexing +more

    Hi Charlotte

    The vendor is Xerox however the guys are salespeople.
    To obtain the information I required to staple & print multiplePagesPerSheet would it be best to speak to a programmer at Xerox, & probaly Xerox US would be the best source?

    Diana

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: API call - printer properties Duplexing +more

    Salespersons certainly won't be able to help you directly, but in theory they should be able to bring you into contact with tech support, either in Oz or in the US.

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: API call - printer properties Duplexing +more

    Hi Hans

    To get some insight, I spoke to a Xerox programmer (although hes not in the product development team - which is the printer driver area) - thats my next port-of-call.
    He advised that I can actually get the values for Stapling & nUP(nUP = 2UP ie multiple pages per sheet)

    The DEVMODE type - dmDriverExtras stores private information & will return the stapling & nUP byte values ie the exact byte location.
    However for the different operating systems the mapping will be different & may move an extra byte, therefore the information being set/sent will be incorrect.
    & that DEVMODE or windows needs an extra 100bytes.

    He mentioned that I can obtain the bytes & store as an array & save as a file >then load back into the code to be read.
    I have no idea how to do go about doing this?
    How would I go about obtaining/returning these values - the values I need?

    Diana :0

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: API call - printer properties Duplexing +more

    The DEVMODE type itself is fixed. The default for dmDriverExtra is 0, indicating no extra space; if it's non-zero, <dmDriverExtra> bytes of device-specific info will follow immediately after the standard DEVMODE structure. You still have to know where the Stapling and nUp information is located inside this extra space. Xerox will have to provide this information.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •