Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

DeviceCapabilities (Enums)
 
.
Summary

C# Definition:

    using System.ComponentModel;
    using System.Collections;
    using System.Runtime.InteropServices;
    [DllImport("winspool.drv", SetLastError = true)]
    public static extern Int32 DeviceCapabilities(string pDevice, string pPort, DeviceCapabilitiesFlags fwCapability, IntPtr pOutput, IntPtr pDevMode);

    [DllImport("winspool.drv", SetLastError=true)]
    static extern Int32 DeviceCapabilities(
        string device,
        string port,
        DeviceCapabilitiesFlags capability,
        IntPtr outputBuffer,
        IntPtr deviceMode);

    public static bool GetProperties(string strDeviceName, string strPort, out bool bDuplex, out bool bColor, out string strError)
    {
        strError = "";
        bDuplex = false;
        bColor = false;

Enums

    /// <summary>
    /// device capabilities indices
    /// </summary>
    [Flags()]
    public enum DeviceCapabilitiesFlags : short
    {
        /// <summary>
        /// Returns the dmFields member of the printer driver's DEVMODE structure. The dmFields member indicates which members in the device-independent portion of the structure are supported by the printer driver.
        /// </summary>
        DC_FIELDS = 1,

        // Duplex
        int nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_DUPLEX, IntPtr.Zero, (IntPtr)null);
        if(nRes < 0)
        {
            strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
            return false;
        }
        bDuplex = nRes == 1;
        /// <summary>
        /// Retrieves a list of supported paper sizes. The pOutput buffer receives an array of WORD values that indicate the available paper sizes for the printer. The return value indicates the number of entries in the array. For a list of the possible array values, see the description of the dmPaperSize member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array.
        /// </summary>
        DC_PAPERS = 2,

        // Color
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_COLORDEVICE,    IntPtr.Zero, (IntPtr)null);
        if(nRes < 0)
        {
            strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
            return false;
        }
        bColor = nRes == 1;
        /// <summary>
        /// Retrieves the dimensions, in tenths of a millimeter, of each supported paper size. The pOutput buffer receives an array of POINT structures. Each structure contains the width (x-dimension) and length (y-dimension) of a paper size as if the paper were in the DMORIENT_PORTRAIT orientation. The return value indicates the number of entries in the array.
        /// </summary>
        DC_PAPERSIZE = 3,

        return true;
    }
        /// <summary>
        /// Returns the minimum paper size that the dmPaperLength and dmPaperWidth members of the printer driver's DEVMODE structure can specify. The LOWORD of the return value contains the minimum dmPaperWidth value, and the HIWORD contains the minimum dmPaperLength value.
        /// </summary>
        DC_MINEXTENT = 4,

    public static bool GetBins(string strDeviceName, string strPort, out ArrayList BinNr, out ArrayList BinName, out string strError)
    {
        strError = "";
        BinNr = new ArrayList();
        BinName = new ArrayList();
        /// <summary>
        /// Returns the maximum paper size that the dmPaperLength and dmPaperWidth members of the printer driver's DEVMODE structure can specify. The LOWORD of the return value contains the maximum dmPaperWidth value, and the HIWORD contains the maximum dmPaperLength value.
        /// </summary>
        DC_MAXEXTENT = 5,

        // Bins
        int nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINS, (IntPtr)null, (IntPtr)null);
        IntPtr pAddr = Marshal.AllocHGlobal((int)nRes * 2);
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINS, pAddr, (IntPtr)null);
        /// <summary>
        /// Retrieves a list of available paper bins. The pOutput buffer receives an array of WORD values that indicate the available paper sources for the printer. The return value indicates the number of entries in the array. For a list of the possible array values, see the description of the dmDefaultSource member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array.
        /// </summary>
        DC_BINS = 6,

        /// <summary>
        /// If the printer supports duplex printing, the return value is 1; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_DUPLEX = 7,

        /// <summary>
        /// Returns the dmSize member of the printer driver's DEVMODE structure.
        /// </summary>
        DC_SIZE = 8,

        /// <summary>
        /// Returns the number of bytes required for the device-specific portion of the DEVMODE structure for the printer driver.
        /// </summary>
        DC_EXTRA = 9,

        /// <summary>
        /// Returns the specification version to which the printer driver conforms.
        /// </summary>
        DC_VERSION = 10,

        /// <summary>
        /// Returns the version number of the printer driver.
        /// </summary>
        DC_DRIVER = 11,

        /// <summary>
        /// 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.
        /// </summary>
        DC_BINNAMES = 12,

        /// <summary>
        /// Retrieves a list of the resolutions supported by the printer. The pOutput buffer receives an array of LONG values. For each supported resolution, the array contains a pair of LONG values that specify the x and y dimensions of the resolution, in dots per inch. The return value indicates the number of supported resolutions. If pOutput is NULL, the return value indicates the number of supported resolutions.
        /// </summary>
        DC_ENUMRESOLUTIONS = 13,

        /// <summary>
        /// Retrieves the names of any additional files that need to be loaded when a driver is installed. The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a file. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of files.
        /// </summary>
        DC_FILEDEPENDENCIES = 14,

        /// <summary>
        /// Retrieves the abilities of the driver to use TrueType fonts. For DC_TRUETYPE, the pOutput parameter should be NULL. The return value can be one or more of the following:
        ///DCTT_BITMAP      Device can print TrueType fonts as graphics.
        ///DCTT_DOWNLOAD    Device can download TrueType fonts.
        ///DCTT_SUBDEV      Device can substitute device fonts for TrueType fonts.
        /// </summary>
        DC_TRUETYPE = 15,

        /// <summary>
        /// Retrieves a list of supported paper names (for example, Letter or Legal). The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a paper form. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of paper forms.
        /// </summary>
        DC_PAPERNAMES = 16,

        /// <summary>
        /// Returns the relationship between portrait and landscape orientations for a device, in terms of the number of degrees that portrait orientation is rotated counterclockwise to produce landscape orientation. The return value can be one of the following:
        ///0    No landscape orientation.
        ///90   Portrait is rotated 90 degrees to produce landscape.
        ///270  Portrait is rotated 270 degrees to produce landscape.
        /// </summary>
        DC_ORIENTATION = 17,

        /// <summary>
        /// Returns the number of copies the device can print.
        /// </summary>
        DC_COPIES = 18,

        DC_BINADJUST = 19,

        DC_EMF_COMPLIANT = 20,

        DC_DATATYPE_PRODUCED = 21,

        /// <summary>
        /// If the printer supports collating, the return value is 1; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_COLLATE = 22,

        DC_MANUFACTURER = 23,

        DC_MODEL = 24,

        /// <summary>
        /// Retrieves a list of printer description languages supported by the printer. The pOutput buffer receives an array of string buffers. Each buffer is 32 characters long and contains the name of a printer description language. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 32 characters long. If pOutput is NULL, the return value indicates the required number of array entries.
        /// </summary>
        DC_PERSONALITY = 25,

        /// <summary>
        /// The return value indicates the printer's print rate. The value returned for DC_PRINTRATEUNIT indicates the units of the DC_PRINTRATE value. The pOutput parameter is not used.
        /// </summary>
        DC_PRINTRATE = 26,

        /// <summary>
        /// The return value is one of the following values that indicate the print rate units for the value returned for the DC_PRINTRATE flag. The pOutput parameter is not used.
        ///PRINTRATEUNIT_CPS    Characters per second.
        ///PRINTRATEUNIT_IPM    Inches per minute.
        ///PRINTRATEUNIT_LPM    Lines per minute.
        ///PRINTRATEUNIT_PPM    Pages per minute.
        /// </summary>
        DC_PRINTRATEUNIT = 27,

        /// <summary>
        /// The return value is the amount of available printer memory, in kilobytes. The pOutput parameter is not used.
        /// </summary>
        DC_PRINTERMEM = 28,

        /// <summary>
        /// Retrieves the names of the paper forms that are currently available for use. The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a paper form. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of paper forms.
        /// </summary>
        DC_MEDIAREADY = 29,

        /// <summary>
        /// If the printer supports stapling, the return value is a nonzero value; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_STAPLE = 30,

        /// <summary>
        /// The return value indicates the printer's print rate, in pages per minute. The pOutput parameter is not used.
        /// </summary>
        DC_PRINTRATEPPM = 31,

        /// <summary>
        /// If the printer supports color printing, the return value is 1; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_COLORDEVICE = 32,

        /// <summary>
        /// Retrieves an array of integers that indicate that printer's ability to print multiple document pages per printed page. The pOutput buffer receives an array of DWORD values. Each value represents a supported number of document pages per printed page. The return value indicates the number of entries in the array. If pOutput is NULL, the return value indicates the required number of entries in the array.
        /// </summary>
        DC_NUP = 33,

        /// <summary>
        /// Retrieves the names of the supported media types. The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a supported media type. The return value indicates the number of entries in the array. The strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of media type names required. Windows 2000:  This flag is not supported.
        /// </summary>
        DC_MEDIATYPENAMES = 34,

        /// <summary>
        /// Retrieves a list of supported media types. The pOutput buffer receives an array of DWORD values that indicate the supported media types. The return value indicates the number of entries in the array. For a list of possible array values, see the description of the dmMediaType member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array. Windows 2000:  This flag is not supported.
        /// </summary>
        DC_MEDIATYPES = 35
    }

VB Definition:

    Public EnumDeviceCapabilities
        Fields=1
        Papers=2
        PaperSize=3
        MinExtent=4
        MaxExtent=5
        Bins=6
        Duplex=7
        Size=8
        Extra=9
        Version=10
        Driver=11
        BinNames=12
        EnumResolutions=13
        FileDependencies=14
        TrueType=15
        PaperNames=16
        Orientation=17
        Copies=18
        BinAdjust=19
        EmfCompliant=20
        DataTypeProduced=21
        Collate=22
        Nanufacturer=23
        Nodel=24
        Personality=25
        PrintRate=26
        PrintRateUnit=27
        PrinterMemory=28
        MediaReady=29
        Staple=30
        PrintRatePpm=31
        ColorDevice=32
        Nup=33
    End Enum

Sample Code

    using System.ComponentModel;
    using System.Collections;
    using System.Runtime.InteropServices;

    public static bool GetProperties(string strDeviceName, string strPort, out bool bDuplex, out bool bColor, out string strError)
    {
        strError = "";
        bDuplex = false;
        bColor = false;

        // Duplex
        int nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_DUPLEX, IntPtr.Zero, (IntPtr)null);
        if(nRes < 0)
        {
            strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
            return false;
        }
        short[] bins = new short[nRes];
        int offset = pAddr.ToInt32();
        for (int i = 0; i < nRes; i++)
        {
            BinNr.Add( Marshal.ReadInt16(new IntPtr(offset + i * 2)));
        }
        Marshal.FreeHGlobal(pAddr);

        // BinNames
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINNAMES, (IntPtr)null, (IntPtr)null);
        pAddr = Marshal.AllocHGlobal((int)nRes * 24);
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINNAMES, pAddr, (IntPtr)null);
        if(nRes < 0)
        {
            strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
            return false;
        }

        offset = pAddr.ToInt32();
        for(int i = 0; i < nRes; i++)
        {
            BinName.Add(Marshal.PtrToStringAnsi(new IntPtr(offset + i * 24)));
        }
        Marshal.FreeHGlobal(pAddr);

        return true;
    }
        bDuplex = nRes == 1;

/* device capabilities indices */

        // Color
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_COLORDEVICE,    IntPtr.Zero, (IntPtr)null);
        if(nRes < 0)
        {
            strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
            return false;
        }
        bColor = nRes == 1;

    /// <summary>
    /// device capabilities indices
    /// </summary>
    [Flags()]
    public enum DeviceCapabilitiesFlags : short
    {
        /// <summary>
        /// Returns the dmFields member of the printer driver's DEVMODE structure. The dmFields member indicates which members in the device-independent portion of the structure are supported by the printer driver.
        /// </summary>
        DC_FIELDS = 1,
        return true;
    }

        /// <summary>
        /// Retrieves a list of supported paper sizes. The pOutput buffer receives an array of WORD values that indicate the available paper sizes for the printer. The return value indicates the number of entries in the array. For a list of the possible array values, see the description of the dmPaperSize member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array.
        /// </summary>
        DC_PAPERS = 2,
    public static bool GetBins(string strDeviceName, string strPort, out ArrayList BinNr, out ArrayList BinName, out string strError)
    {
        strError = "";
        BinNr = new ArrayList();
        BinName = new ArrayList();

        /// <summary>
        /// Retrieves the dimensions, in tenths of a millimeter, of each supported paper size. The pOutput buffer receives an array of POINT structures. Each structure contains the width (x-dimension) and length (y-dimension) of a paper size as if the paper were in the DMORIENT_PORTRAIT orientation. The return value indicates the number of entries in the array.
        /// </summary>
        DC_PAPERSIZE = 3,
        // Bins
        int nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINS, (IntPtr)null, (IntPtr)null);
        IntPtr pAddr = Marshal.AllocHGlobal((int)nRes * 2);
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINS, pAddr, (IntPtr)null);
        if(nRes < 0)
        {
            strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
            return false;
        }
        short[] bins = new short[nRes];
        int offset = pAddr.ToInt32();
        for (int i = 0; i < nRes; i++)
        {
            BinNr.Add( Marshal.ReadInt16(new IntPtr(offset + i * 2)));
        }
        Marshal.FreeHGlobal(pAddr);

        // BinNames
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINNAMES, (IntPtr)null, (IntPtr)null);
        pAddr = Marshal.AllocHGlobal((int)nRes * 24);
        nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINNAMES, pAddr, (IntPtr)null);
        if(nRes < 0)
        {
            strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
            return false;
        }

        offset = pAddr.ToInt32();
        for(int i = 0; i < nRes; i++)
        {
            BinName.Add(Marshal.PtrToStringAnsi(new IntPtr(offset + i * 24)));
        }
        Marshal.FreeHGlobal(pAddr);

        return true;
    }

        /// <summary>
        /// Returns the minimum paper size that the dmPaperLength and dmPaperWidth members of the printer driver's DEVMODE structure can specify. The LOWORD of the return value contains the minimum dmPaperWidth value, and the HIWORD contains the minimum dmPaperLength value.
        /// </summary>
        DC_MINEXTENT = 4,

        /// <summary>
        /// Returns the maximum paper size that the dmPaperLength and dmPaperWidth members of the printer driver's DEVMODE structure can specify. The LOWORD of the return value contains the maximum dmPaperWidth value, and the HIWORD contains the maximum dmPaperLength value.
        /// </summary>
        DC_MAXEXTENT = 5,

        /// <summary>
        /// Retrieves a list of available paper bins. The pOutput buffer receives an array of WORD values that indicate the available paper sources for the printer. The return value indicates the number of entries in the array. For a list of the possible array values, see the description of the dmDefaultSource member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array.
        /// </summary>
        DC_BINS = 6,

        /// <summary>
        /// If the printer supports duplex printing, the return value is 1; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_DUPLEX = 7,

        /// <summary>
        /// Returns the dmSize member of the printer driver's DEVMODE structure.
        /// </summary>
        DC_SIZE = 8,

        /// <summary>
        /// Returns the number of bytes required for the device-specific portion of the DEVMODE structure for the printer driver.
        /// </summary>
        DC_EXTRA = 9,

        /// <summary>
        /// Returns the specification version to which the printer driver conforms.
        /// </summary>
        DC_VERSION = 10,

        /// <summary>
        /// Returns the version number of the printer driver.
        /// </summary>
        DC_DRIVER = 11,

        /// <summary>
        /// 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.
        /// </summary>
        DC_BINNAMES = 12,

        /// <summary>
        /// Retrieves a list of the resolutions supported by the printer. The pOutput buffer receives an array of LONG values. For each supported resolution, the array contains a pair of LONG values that specify the x and y dimensions of the resolution, in dots per inch. The return value indicates the number of supported resolutions. If pOutput is NULL, the return value indicates the number of supported resolutions.
        /// </summary>
        DC_ENUMRESOLUTIONS = 13,

        /// <summary>
        /// Retrieves the names of any additional files that need to be loaded when a driver is installed. The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a file. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of files.
        /// </summary>
        DC_FILEDEPENDENCIES = 14,

        /// <summary>
        /// Retrieves the abilities of the driver to use TrueType fonts. For DC_TRUETYPE, the pOutput parameter should be NULL. The return value can be one or more of the following:
        ///DCTT_BITMAP      Device can print TrueType fonts as graphics.
        ///DCTT_DOWNLOAD    Device can download TrueType fonts.
        ///DCTT_SUBDEV      Device can substitute device fonts for TrueType fonts.
        /// </summary>
        DC_TRUETYPE = 15,

        /// <summary>
        /// Retrieves a list of supported paper names (for example, Letter or Legal). The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a paper form. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of paper forms.
        /// </summary>
        DC_PAPERNAMES = 16,

        /// <summary>
        /// Returns the relationship between portrait and landscape orientations for a device, in terms of the number of degrees that portrait orientation is rotated counterclockwise to produce landscape orientation. The return value can be one of the following:
        ///0    No landscape orientation.
        ///90   Portrait is rotated 90 degrees to produce landscape.
        ///270  Portrait is rotated 270 degrees to produce landscape.
        /// </summary>
        DC_ORIENTATION = 17,

        /// <summary>
        /// Returns the number of copies the device can print.
        /// </summary>
        DC_COPIES = 18,

        DC_BINADJUST = 19,

        DC_EMF_COMPLIANT = 20,

        DC_DATATYPE_PRODUCED = 21,

        /// <summary>
        /// If the printer supports collating, the return value is 1; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_COLLATE = 22,

        DC_MANUFACTURER = 23,

        DC_MODEL = 24,

        /// <summary>
        /// Retrieves a list of printer description languages supported by the printer. The pOutput buffer receives an array of string buffers. Each buffer is 32 characters long and contains the name of a printer description language. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 32 characters long. If pOutput is NULL, the return value indicates the required number of array entries.
        /// </summary>
        DC_PERSONALITY = 25,

        /// <summary>
        /// The return value indicates the printer's print rate. The value returned for DC_PRINTRATEUNIT indicates the units of the DC_PRINTRATE value. The pOutput parameter is not used.
        /// </summary>
        DC_PRINTRATE = 26,

        /// <summary>
        /// The return value is one of the following values that indicate the print rate units for the value returned for the DC_PRINTRATE flag. The pOutput parameter is not used.
        ///PRINTRATEUNIT_CPS    Characters per second.
        ///PRINTRATEUNIT_IPM    Inches per minute.
        ///PRINTRATEUNIT_LPM    Lines per minute.
        ///PRINTRATEUNIT_PPM    Pages per minute.
        /// </summary>
        DC_PRINTRATEUNIT = 27,

        /// <summary>
        /// The return value is the amount of available printer memory, in kilobytes. The pOutput parameter is not used.
        /// </summary>
        DC_PRINTERMEM = 28,

        /// <summary>
        /// Retrieves the names of the paper forms that are currently available for use. The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a paper form. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of paper forms.
        /// </summary>
        DC_MEDIAREADY = 29,

        /// <summary>
        /// If the printer supports stapling, the return value is a nonzero value; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_STAPLE = 30,

        /// <summary>
        /// The return value indicates the printer's print rate, in pages per minute. The pOutput parameter is not used.
        /// </summary>
        DC_PRINTRATEPPM = 31,

        /// <summary>
        /// If the printer supports color printing, the return value is 1; otherwise, the return value is zero. The pOutput parameter is not used.
        /// </summary>
        DC_COLORDEVICE = 32,

        /// <summary>
        /// Retrieves an array of integers that indicate that printer's ability to print multiple document pages per printed page. The pOutput buffer receives an array of DWORD values. Each value represents a supported number of document pages per printed page. The return value indicates the number of entries in the array. If pOutput is NULL, the return value indicates the required number of entries in the array.
        /// </summary>
        DC_NUP = 33,

        /// <summary>
        /// Retrieves the names of the supported media types. The pOutput buffer receives an array of string buffers. Each string buffer is 64 characters long and contains the name of a supported media type. The return value indicates the number of entries in the array. The strings are null-terminated unless the name is 64 characters long. If pOutput is NULL, the return value is the number of media type names required. Windows 2000:  This flag is not supported.
        /// </summary>
        DC_MEDIATYPENAMES = 34,

        /// <summary>
        /// Retrieves a list of supported media types. The pOutput buffer receives an array of DWORD values that indicate the supported media types. The return value indicates the number of entries in the array. For a list of possible array values, see the description of the dmMediaType member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array. Windows 2000:  This flag is not supported.
        /// </summary>
        DC_MEDIATYPES = 35
    }

VB Definition:

    Public EnumDeviceCapabilities
        Fields=1
        Papers=2
        PaperSize=3
        MinExtent=4
        MaxExtent=5
        Bins=6
        Duplex=7
        Size=8
        Extra=9
        Version=10
        Driver=11
        BinNames=12
        EnumResolutions=13
        FileDependencies=14
        TrueType=15
        PaperNames=16
        Orientation=17
        Copies=18
        BinAdjust=19
        EmfCompliant=20
        DataTypeProduced=21
        Collate=22
        Nanufacturer=23
        Nodel=24
        Personality=25
        PrintRate=26
        PrintRateUnit=27
        PrinterMemory=28
        MediaReady=29
        Staple=30
        PrintRatePpm=31
        ColorDevice=32
        Nup=33
    End Enum

EXAMPLES

    using System.ComponentModel;
    using System.Collections;
    using System.Runtime.InteropServices;

    public static bool GetProperties(string strDeviceName, string strPort, out bool bDuplex, out bool bColor, out string strError)
    {
    strError = "";
    bDuplex = false;
    bColor = false;

    // Duplex
    int nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_DUPLEX, IntPtr.Zero, (IntPtr)null);
    if(nRes < 0)
    {
        strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
        return false;
    }
    bDuplex = nRes == 1;

    // Color
    nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_COLORDEVICE,    IntPtr.Zero, (IntPtr)null);
    if(nRes < 0)
    {
        strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
        return false;
    }
    bColor = nRes == 1;

    return true;
    }

    public static bool GetBins(string strDeviceName, string strPort, out ArrayList BinNr, out ArrayList BinName, out string strError)
    {
    strError = "";
    BinNr = new ArrayList();
    BinName = new ArrayList();

    // Bins
    int nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINS, (IntPtr)null, (IntPtr)null);
    IntPtr pAddr = Marshal.AllocHGlobal((int)nRes * 2);
    nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINS, pAddr, (IntPtr)null);
    if(nRes < 0)
    {
        strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
        return false;
    }
    short[] bins = new short[nRes];
    int offset = pAddr.ToInt32();
    for (int i = 0; i < nRes; i++)
    {
        BinNr.Add( Marshal.ReadInt16(new IntPtr(offset + i * 2)));
    }
    Marshal.FreeHGlobal(pAddr);

    // BinNames
    nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINNAMES, (IntPtr)null, (IntPtr)null);
    pAddr = Marshal.AllocHGlobal((int)nRes * 24);
    nRes = DeviceCapabilities(strDeviceName, strPort, DeviceCapabilitiesFlags.DC_BINNAMES, pAddr, (IntPtr)null);
    if(nRes < 0)
    {
        strError = new Win32Exception(Marshal.GetLastWin32Error()).Message + "["+ strDeviceName +": "+ strPort +"]";
        return false;
    }

    offset = pAddr.ToInt32();
    for(int i = 0; i < nRes; i++)
    {
        BinName.Add(Marshal.PtrToStringAnsi(new IntPtr(offset + i * 24)));
    }
    Marshal.FreeHGlobal(pAddr);

    return true;
    }

Notes:

None.

Documentation
 

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it!

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions