using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.InteropServices;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
namespace Vanara.PInvoke
{
public static partial class WinSpool
{
///
/// The printer driver and all the files in the printer driver directory must be added. The file time stamps are ignored when
/// dwFlags has a value of IPDFP_COPY_ALL_FILES.
///
public const uint IPDFP_COPY_ALL_FILES = 0x00000001;
/// The options for copying the driver files.
[PInvokeData("winspool.h", MSDNShortId = "472adb7d-39cc-4c76-b96c-610ff9d276ad")]
[Flags]
public enum APD
{
///
/// Add the printer driver only if all the files in the printer-driver directory are newer than any corresponding files
/// currently in use.
///
APD_STRICT_UPGRADE = 0x00000001,
///
/// Add the printer driver only if all the files in the printer-driver directory are older than any corresponding files
/// currently in use.
///
APD_STRICT_DOWNGRADE = 0x00000002,
///
/// Add the printer driver and copy all the files in the printer-driver directory. The file time stamps are ignored with this option.
///
APD_COPY_ALL_FILES = 0x00000004,
///
/// Add the printer driver and copy the files in the printer-driver directory that are newer than any corresponding files that
/// are currently in use. This flag emulates the behavior of AddPrinterDriver.
///
APD_COPY_NEW_FILES = 0x00000008,
///
/// Add the printer driver using the fully qualified file names specified in the DRIVER_INFO_6 structure. This flag is ORed in
/// conjunction with one of the other copy flags. If this flag is set, AddPrinterDriverEx will fail if the files do not exist
/// where they are specified to exist by the DRIVER_INFO_6 structure. The files do not need to be copied to the system's
/// printer-driver directory. See the Remarks. Windows 2000: This flag is not supported.
///
APD_COPY_FROM_DIRECTORY = 0x00000010,
}
/// The options for deleting files and versions of the driver.
[PInvokeData("winspool.h", MSDNShortId = "1a3d7c7f-1d45-4877-a8f7-a77f40e3c319")]
[Flags]
public enum DPD
{
/// Removes any unused driver files.
DPD_DELETE_UNUSED_FILES = 0x00000001,
///
/// Deletes the version specified in dwVersionFlag. This does not ensure that the driver will be removed from the list of
/// supported drivers for the server.
///
DPD_DELETE_SPECIFIC_VERSION = 0x00000002,
///
/// Deletes the driver only if all its associated files can be removed. The delete operation fails if any of the driver's files
/// are being used by some other installed driver.
///
DPD_DELETE_ALL_FILES = 0x00000004,
}
/// Options for UploadPrinterDriverPackage.
[PInvokeData("winspool.h", MSDNShortId = "dd3b3a3b-8ded-44ae-85dd-e630bc62e898")]
[Flags]
public enum UPDP
{
/// The UI will not be shown during the upload.
UPDP_SILENT_UPLOAD = 0x00000001,
/// The files will be uploaded even if the package is already in the server's driver store.
UPDP_UPLOAD_ALWAYS = 0x00000002,
///
/// The server's driver store will be checked before upload to see if the package is already there. This setting is ignored if
/// UPDP_UPLOAD_ALWAYS is set.
///
UPDP_CHECK_DRIVERSTORE = 0x00000004,
}
/// The AddMonitor function installs a local port monitor and links the configuration, data, and monitor files.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the monitor should be installed. For
/// systems that support only local installation of monitors, this string should be NULL.
///
/// The version of the structure to which pMonitors points. This value must be 2.
///
///
/// A pointer to a MONITOR_INFO_2 structure. If the pEnvironment member of the pMonitors structure is NULL, the
/// current environment of the caller (client), not of the destination (server), is used.
///
///
/// Note that the call will fail if the environment does not match the environment of the server, that is, you can only add a
/// monitor that was written for the architecture of the server.
///
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
/// The caller must have the SeLoadDriverPrivilege.
///
/// Before an application calls the AddMonitor function, all files required by the monitor must be copied to the SYSTEM32 directory.
///
/// To determine the port monitors that are currently installed, call the EnumMonitors function.
/// To remove a monitor added by AddMonitor, call the DeleteMonitor function.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/addmonitor BOOL AddMonitor( _In_ LPTSTR pName, _In_ DWORD Level, _In_
// LPBYTE pMonitors );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "6a556422-5360-42d2-b177-dba0498c06d8")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddMonitor([Optional] string pName, uint Level, [In] IntPtr pMonitors);
/// The AddMonitor function installs a local port monitor and links the configuration, data, and monitor files.
/// The type of the structure to which pMonitors points. This value must be MONITOR_INFO_2.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the monitor should be installed. For
/// systems that support only local installation of monitors, this string should be NULL.
///
///
///
/// A MONITOR_INFO_2 structure. If the pEnvironment member of the pMonitors structure is NULL, the current
/// environment of the caller (client), not of the destination (server), is used.
///
///
/// Note that the call will fail if the environment does not match the environment of the server, that is, you can only add a
/// monitor that was written for the architecture of the server.
///
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
/// The caller must have the SeLoadDriverPrivilege.
///
/// Before an application calls the AddMonitor function, all files required by the monitor must be copied to the SYSTEM32 directory.
///
/// To determine the port monitors that are currently installed, call the EnumMonitors function.
/// To remove a monitor added by AddMonitor, call the DeleteMonitor function.
///
[PInvokeData("winspool.h", MSDNShortId = "6a556422-5360-42d2-b177-dba0498c06d8")]
public static bool AddMonitor([Optional] string pName, in T pMonitors) where T : struct
{
if (!TryGetLevel("MONITOR_INFO_", out var lvl))
throw new ArgumentException($"{nameof(AddMonitor)} cannot process a structure of type {typeof(T).Name}.");
using var mem = SafeCoTaskMemHandle.CreateFromStructure(pMonitors);
return AddMonitor(pName, lvl, mem);
}
///
/// The AddPort function adds the name of a port to the list of supported ports. The AddPort function is exported by
/// the port monitor.
///
///
/// A pointer to a zero-terminated string that specifies the name of the server to which the port is connected. If this parameter is
/// NULL, the port is local.
///
/// A handle to the parent window of the AddPort dialog box.
/// A pointer to a zero-terminated string that specifies the monitor associated with the port.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
///
/// The AddPort function browses the network to find existing ports, and displays a dialog box for the user. The
/// AddPort function should validate the port name entered by the user by calling EnumPorts to ensure that no
/// duplicate names exist.
///
///
/// The caller of the AddPort function must have SERVER_ACCESS_ADMINISTER access to the server to which the port is connected.
///
///
/// To add a port without displaying a dialog box, call the XcvData function instead of AddPort. For more information
/// about XcvData, see the Microsoft Windows Driver Development Kit (DDK).
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/addport BOOL AddPort( _In_ LPTSTR pName, _In_ HWND hWnd, _In_ LPTSTR
// pMonitorName );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "9191d507-9167-4488-a4b4-286590a8a62a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddPort([Optional] string pName, HWND hWnd, string pMonitorName);
///
///
/// The AddPrinterDriver function installs a local or remote printer driver and associates the configuration, data, and
/// driver files.
///
///
/// For more flexibility in installing or upgrading printer drivers, use the AddPrinterDriverEx function because it allows
/// strict upgrade, strict downgrade, copying of newer files only, and copying of all files (regardless of the file time stamps).
///
///
///
/// A pointer to a null-terminated string that specifies the name of the server on which the driver should be installed.
/// If pName is NULL, the driver will be installed locally.
///
///
/// The version of the structure to which pDriverInfo points.
/// This value can be 2, 3, 4, 6, or 8.
///
///
/// A pointer to a structure containing printer driver information. This depends on the value of Level.
///
///
/// Value
/// Printer Drive Structure
///
/// -
/// 2
/// DRIVER_INFO_2
///
/// -
/// 3
/// DRIVER_INFO_3
///
/// -
/// 4
/// DRIVER_INFO_4
///
/// -
/// 6
/// DRIVER_INFO_6
///
/// -
/// 8
/// DRIVER_INFO_8
///
///
///
/// If the pEnvironment member of the structure pointed to by pDriverInfo is NULL, the current environment of the
/// caller/client (not of the destination/server) is used.
///
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
/// The caller must have the SeLoadDriverPrivilege.
///
/// Before an application calls the AddPrinterDriver function, all files required by the driver must be copied to the
/// system's printer-driver directory. An application can retrieve the name of this directory by calling the
/// GetPrinterDriverDirectory function.
///
/// An application can determine which printer drivers are currently installed by calling the EnumPrinterDrivers function.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/addprinterdriver BOOL AddPrinterDriver( _In_ LPTSTR pName, _In_ DWORD
// Level, _In_ LPBYTE pDriverInfo );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "0f762800-f5a5-40ea-8be1-7fd8bda23788")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddPrinterDriver([Optional] string pName, uint Level, [In] IntPtr pDriverInfo);
///
/// The AddPrinterDriverEx function installs a local or remote printer driver and links the configuration, data, and driver
/// files. Besides having the capabilities of AddPrinterDriver, it also has options that permit strict upgrade, strict
/// downgrade, copying of newer files only, and copying of all files (regardless of file time stamps).
///
/// The type of the structure containing printer driver information.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the driver should be installed. If this
/// parameter is NULL, the function installs the driver on the local computer.
///
///
/// A structure containing printer driver information. It can be one of the following.
///
///
/// Value of Level
/// DRIVER_INFO_* Structure
///
/// -
/// 2
/// DRIVER_INFO_2
///
/// -
/// 3
/// DRIVER_INFO_3
///
/// -
/// 4
/// DRIVER_INFO_4
///
/// -
/// 6
/// DRIVER_INFO_6
///
/// -
/// 8
/// DRIVER_INFO_8
///
///
///
/// If the pEnvironment member of the structure pointed to by pDriverInfo is NULL, the function uses the current
/// environment of the caller/client, not the environment of the destination/server.
///
///
///
/// The options for copying the driver files. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// APD_COPY_ALL_FILES
///
/// Add the printer driver and copy all the files in the printer-driver directory. The file time stamps are ignored with this option.
///
///
/// -
/// APD_COPY_FROM_DIRECTORY
///
/// Add the printer driver using the fully qualified file names specified in the DRIVER_INFO_6 structure. This flag is ORed in
/// conjunction with one of the other copy flags. If this flag is set, AddPrinterDriverEx will fail if the files do not exist where
/// they are specified to exist by the DRIVER_INFO_6 structure. The files do not need to be copied to the system's printer-driver
/// directory. See the Remarks. Windows 2000: This flag is not supported.
///
///
/// -
/// APD_COPY_NEW_FILES
///
/// Add the printer driver and copy the files in the printer-driver directory that are newer than any corresponding files that are
/// currently in use. This flag emulates the behavior of AddPrinterDriver.
///
///
/// -
/// APD_STRICT_DOWNGRADE
///
/// Add the printer driver only if all the files in the printer-driver directory are older than any corresponding files currently in use.
///
///
/// -
/// APD_STRICT_UPGRADE
///
/// Add the printer driver only if all the files in the printer-driver directory are newer than any corresponding files currently in use.
///
///
///
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
/// If the printer driver is known to have problems working with the operating system, AddPrinterDriverEx will fail with one
/// of the following error codes:
///
///
///
/// Error Code
/// Meaning
///
/// -
/// ERROR_PRINTER_DRIVER_BLOCKED
/// The driver does not work on the operating system.
///
/// -
/// ERROR_PRINTER_DRIVER_WARNED
///
/// The driver is unreliable on the operating system. However, if APD_INSTALL_WARNED_DRIVER is specified, the driver is installed
/// and no warning is given.
///
///
///
/// For more information, see the Remarks.
///
///
/// The caller must have the SeLoadDriverPrivilege.
///
/// Before calling the AddPrinterDriverEx function, all files required by the driver must be copied to the system's
/// printer-driver directory. To retrieve the name of this directory, call the GetPrinterDriverDirectory function.
///
/// To determine which printer drivers are currently installed, call the EnumPrinterDrivers function.
///
/// If the printer driver has been successfully added, the function calls the DrvDriverEvent (DRIVER_EVENT_INITIALIZE, Level,
/// DRIVER_INFO_*, lparam ) function to allow the driver to perform any initializations required during the installation of a
/// printer driver. For more information about DrvDriverEvent, see the Microsoft Windows Driver Development Kit (DDK)
///
///
/// The driver should not use a UI call during the call to DrvDriverEvent. To do UI-related jobs, the installer should either
/// use the VendorSetup entry in the printer's .inf file or, for Plug and Play devices, the installer can use a device-specific
/// co-installer. For more information about VendorSetup, see the DDK.
///
///
/// The files that are referenced in the DRIVER_INFO_6 structure must be local to the machine from which the call is made. A
/// file name can be a UNC name as long as the UNC name is the local machine.
///
///
[PInvokeData("winspool.h", MSDNShortId = "472adb7d-39cc-4c76-b96c-610ff9d276ad")]
public static bool AddPrinterDriverEx([Optional] string pName, in T pDriverInfo, APD dwFileCopyFlags = APD.APD_COPY_NEW_FILES) where T : struct
{
if (!TryGetLevel("DRIVER_INFO_", out var lvl))
throw new ArgumentException($"{nameof(AddPrinterDriverEx)} cannot process a structure of type {typeof(T).Name}.");
using var mem = SafeCoTaskMemHandle.CreateFromStructure(pDriverInfo);
return AddPrinterDriverEx(pName, lvl, mem, dwFileCopyFlags);
}
///
/// The AddPrinterDriverEx function installs a local or remote printer driver and links the configuration, data, and driver
/// files. Besides having the capabilities of AddPrinterDriver, it also has options that permit strict upgrade, strict
/// downgrade, copying of newer files only, and copying of all files (regardless of file time stamps).
///
///
/// A pointer to a null-terminated string that specifies the name of the server on which the driver should be installed. If this
/// parameter is NULL, the function installs the driver on the local computer.
///
/// The version of the structure to which pDriverInfo points. This value can be 2, 3, 4, 6, or 8.
///
/// A pointer to a structure containing printer driver information. It can be one of the following.
///
///
/// Value of Level
/// DRIVER_INFO_* Structure
///
/// -
/// 2
/// DRIVER_INFO_2
///
/// -
/// 3
/// DRIVER_INFO_3
///
/// -
/// 4
/// DRIVER_INFO_4
///
/// -
/// 6
/// DRIVER_INFO_6
///
/// -
/// 8
/// DRIVER_INFO_8
///
///
///
/// If the pEnvironment member of the structure pointed to by pDriverInfo is NULL, the function uses the current
/// environment of the caller/client, not the environment of the destination/server.
///
///
///
/// The options for copying the driver files. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// APD_COPY_ALL_FILES
///
/// Add the printer driver and copy all the files in the printer-driver directory. The file time stamps are ignored with this option.
///
///
/// -
/// APD_COPY_FROM_DIRECTORY
///
/// Add the printer driver using the fully qualified file names specified in the DRIVER_INFO_6 structure. This flag is ORed in
/// conjunction with one of the other copy flags. If this flag is set, AddPrinterDriverEx will fail if the files do not exist where
/// they are specified to exist by the DRIVER_INFO_6 structure. The files do not need to be copied to the system's printer-driver
/// directory. See the Remarks. Windows 2000: This flag is not supported.
///
///
/// -
/// APD_COPY_NEW_FILES
///
/// Add the printer driver and copy the files in the printer-driver directory that are newer than any corresponding files that are
/// currently in use. This flag emulates the behavior of AddPrinterDriver.
///
///
/// -
/// APD_STRICT_DOWNGRADE
///
/// Add the printer driver only if all the files in the printer-driver directory are older than any corresponding files currently in use.
///
///
/// -
/// APD_STRICT_UPGRADE
///
/// Add the printer driver only if all the files in the printer-driver directory are newer than any corresponding files currently in use.
///
///
///
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
/// If the printer driver is known to have problems working with the operating system, AddPrinterDriverEx will fail with one
/// of the following error codes:
///
///
///
/// Error Code
/// Meaning
///
/// -
/// ERROR_PRINTER_DRIVER_BLOCKED
/// The driver does not work on the operating system.
///
/// -
/// ERROR_PRINTER_DRIVER_WARNED
///
/// The driver is unreliable on the operating system. However, if APD_INSTALL_WARNED_DRIVER is specified, the driver is installed
/// and no warning is given.
///
///
///
/// For more information, see the Remarks.
///
///
/// The caller must have the SeLoadDriverPrivilege.
///
/// Before calling the AddPrinterDriverEx function, all files required by the driver must be copied to the system's
/// printer-driver directory. To retrieve the name of this directory, call the GetPrinterDriverDirectory function.
///
/// To determine which printer drivers are currently installed, call the EnumPrinterDrivers function.
///
/// If the printer driver has been successfully added, the function calls the DrvDriverEvent (DRIVER_EVENT_INITIALIZE, Level,
/// DRIVER_INFO_*, lparam ) function to allow the driver to perform any initializations required during the installation of a
/// printer driver. For more information about DrvDriverEvent, see the Microsoft Windows Driver Development Kit (DDK)
///
///
/// The driver should not use a UI call during the call to DrvDriverEvent. To do UI-related jobs, the installer should either
/// use the VendorSetup entry in the printer's .inf file or, for Plug and Play devices, the installer can use a device-specific
/// co-installer. For more information about VendorSetup, see the DDK.
///
///
/// The files that are referenced in the DRIVER_INFO_6 structure must be local to the machine from which the call is made. A
/// file name can be a UNC name as long as the UNC name is the local machine.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/addprinterdriverex BOOL AddPrinterDriverEx( _In_ LPTSTR pName, _In_
// DWORD Level, _Inout_ LPBYTE pDriverInfo, _In_ DWORD dwFileCopyFlags );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "472adb7d-39cc-4c76-b96c-610ff9d276ad")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddPrinterDriverEx([Optional] string pName, uint Level, [In, Out] IntPtr pDriverInfo, APD dwFileCopyFlags);
///
/// The AddPrintProcessor function installs a print processor on the specified server and adds the print-processor name to
/// the list of supported print processors.
///
///
/// A pointer to a null-terminated string that specifies the name of the server on which the print processor should be installed. If
/// this parameter is NULL, the print processor is installed locally.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the caller/client (not of the destination/server) is used.
///
///
/// A pointer to a null-terminated string that specifies the name of the file that contains the print processor. This file must be
/// in the system print-processor directory.
///
/// A pointer to a null-terminated string that specifies the name of the print processor.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
/// The caller must have the SeLoadDriverPrivilege.
///
/// Before calling the AddPrintProcessor function, an application should verify that the file containing the print processor
/// is stored in the system print-processor directory. An application can retrieve the name of the system print-processor directory
/// by calling the GetPrintProcessorDirectory function.
///
/// An application can determine the name of existing print processors by calling the EnumPrintProcessors function.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/addprintprocessor BOOL AddPrintProcessor( _In_ LPTSTR pName, _In_ LPTSTR
// pEnvironment, _In_ LPTSTR pPathName, _In_ LPTSTR pPrintProcessorName );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "99899cee-f74d-4405-8ea5-616e3769aba9")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddPrintProcessor([Optional] string pName, [Optional] string pEnvironment, string pPathName, string pPrintProcessorName);
///
/// The AddPrintProvidor function installs a local print provider and links the configuration, data, and provider files.
///
///
/// A pointer to a null-terminated string that specifies the name of the server on which the provider should be installed. For
/// systems that only support local installation of providers, this parameter should be NULL.
///
///
/// The level of the structure to which pProviderInfo points. It can be one of the following.
///
///
/// Value
/// Meaning
///
/// -
/// 1
/// Function uses a PROVIDOR_INFO_1 structure.
///
/// -
/// 2
/// Function uses a PROVIDOR_INFO_2 structure.
///
///
///
/// A pointer to a print provider structure, as indicated by Level.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
///
/// Before an application calls the AddPrintProvidor function, all files required by the provider must be copied to the
/// SYSTEM32 directory.
///
/// A provider added by AddPrintProvidor may be removed by calling DeletePrintProvidor.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/addprintprovidor BOOL AddPrintProvidor( _In_ LPTSTR pName, _In_ DWORD
// Level, _In_ LPBYTE pProviderInfo );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "f34549c3-0474-48ba-9307-5b36f02dbe1c")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddPrintProvidor([Optional] string pName, uint Level, [In] IntPtr pProviderInfo);
///
/// The AddPrintProvidor function installs a local print provider and links the configuration, data, and provider files.
///
/// The type of the structure containing print provider information.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the provider should be installed. For
/// systems that only support local installation of providers, this parameter should be NULL.
///
///
/// A print provider structure. It can be one of the following.
///
/// -
/// Function uses a PROVIDOR_INFO_1 structure.
///
/// -
/// Function uses a PROVIDOR_INFO_2 structure.
///
///
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
///
///
/// Before an application calls the AddPrintProvidor function, all files required by the provider must be copied to the
/// SYSTEM32 directory.
///
/// A provider added by AddPrintProvidor may be removed by calling DeletePrintProvidor.
///
[PInvokeData("winspool.h", MSDNShortId = "f34549c3-0474-48ba-9307-5b36f02dbe1c")]
public static bool AddPrintProvidor([Optional] string pName, in T pProviderInfo) where T : struct
{
if (!TryGetLevel("DRIVER_INFO_", out var lvl))
throw new ArgumentException($"{nameof(AddPrintProvidor)} cannot process a structure of type {typeof(T).Name}.");
using var mem = SafeCoTaskMemHandle.CreateFromStructure(pProviderInfo);
return AddPrintProvidor(pName, lvl, mem);
}
///
/// The CorePrinterDriverInstalled function reports whether a core printer driver with a specified GUID, date, and version is installed.
///
///
/// Pointer to a constant, null-terminated string that specifies the name of the print server. Use NULL for the local computer.
///
///
/// Pointer to a constant, null-terminated string that specifies the processor architecture (for example, Windows NT x86). This can
/// be NULL.
///
/// The GUID of the core printer driver.
/// The date of the core printer driver.
/// The version of the core printer driver.
/// A pointer to TRUE if the driver, or a newer version, is installed, FALSE otherwise.
///
/// If the operation succeeds, the return value is S_OK, otherwise the HRESULT will contain an error code.
/// For more information about COM error codes, see Error Handling.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/coreprinterdriverinstalled HRESULT CorePrinterDriverInstalled( _In_
// LPCTSTR pszServer, _In_ LPCTSTR pszEnvironment, _In_ GUID CoreDriverGUID, _In_ FILETIME ftDriverDate, _In_ DWORDLONG
// dwlDriverVersion, _Out_ BOOL *pbDriverInstalled );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "fb859aca-bb7b-495d-bd38-16ffa084c240")]
public static extern HRESULT CorePrinterDriverInstalled([Optional] string pszServer, [Optional] string pszEnvironment, Guid CoreDriverGUID, FILETIME ftDriverDate, ulong dwlDriverVersion, [MarshalAs(UnmanagedType.Bool)] out bool pbDriverInstalled);
/// The DeleteMonitor function removes a port monitor added by the AddMonitor function.
///
/// A pointer to a null-terminated string that specifies the name of the server from which the monitor is to be removed. If this
/// parameter is NULL, the port monitor is removed locally.
///
///
/// A pointer to a null-terminated string that specifies the environment from which the monitor is to be removed (for example,
/// Windows x86, Windows IA64, or Windows x64). If this parameter is NULL, the monitor is removed from the current
/// environment of the calling application and client machine (not of the destination application and print server).
///
/// A pointer to a null-terminated string that specifies the name of the monitor to be removed.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
/// The caller must have SeLoadDriverPrivilege.
// https://docs.microsoft.com/en-us/windows/win32/printdocs/deletemonitor BOOL DeleteMonitor( _In_ LPTSTR pName, _In_ LPTSTR
// pEnvironment, _In_ LPTSTR pMonitorName );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "32548d4f-830a-471d-8a72-c0f62f43ffa2")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteMonitor([Optional] string pName, [Optional] string pEnvironment, string pMonitorName);
/// The DeletePort function displays a dialog box that allows the user to delete a port name.
///
/// A pointer to a zero-terminated string that specifies the name of the server for which the port should be deleted. If this
/// parameter is NULL, a local port is deleted.
///
/// A handle to the parent window of the port-deletion dialog box.
/// A pointer to a zero-terminated string that specifies the name of the port that should be deleted.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
/// An application can retrieve the names of valid ports by calling the EnumPorts function.
/// The DeletePort function returns an error if a printer is currently connected to the specified port.
///
/// The caller of the DeletePort function must have SERVER_ACCESS_ADMINISTER access to the server to which the port is connected.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/deleteport BOOL DeletePort( _In_ LPTSTR pName, _In_ HWND hWnd, _In_
// LPTSTR pPortName );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "5f5788c2-c781-4106-abd2-98556d0a22de")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeletePort([Optional] string pName, HWND hWnd, string pPortName);
///
///
/// The DeletePrinterDriver function removes the specified printer-driver name from the list of names of supported drivers on
/// a server.
///
///
/// To delete the files associated with the driver in addition to removing the specified printer-driver name from the list of names
/// of supported drivers for a server, use the DeletePrinterDriverEx function.
///
///
/// DeletePrinterDriver deletes a driver only if no version of the driver is in use for the specified environment.
/// DeletePrinterDriverEx can delete specific versions of the driver.
///
///
///
/// A pointer to a null-terminated string that specifies the name of the server from which the driver is to be deleted. If this
/// parameter is NULL, the printer-driver name will be removed locally.
///
///
/// A pointer to a null-terminated string that specifies the environment from which the driver is to be deleted (for example,
/// Windows x86, Windows IA64, or Windows x64). If this parameter is NULL, the driver name is deleted from the current
/// environment of the calling application and client machine (not of the destination application and print server).
///
/// A pointer to a null-terminated string specifying the name of the driver that should be deleted.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
/// The caller must have the SeLoadDriverPrivilege.
///
/// The DeletePrinterDriver function does not delete the associated files, it merely removes the driver name from the list
/// returned by the EnumPrinterDrivers function.
///
/// Before calling DeletePrinterDriver, you must delete all printer objects that use the printer driver.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/deleteprinterdriver BOOL DeletePrinterDriver( _In_ LPTSTR pName, _In_
// LPTSTR pEnvironment, _In_ LPTSTR pDriverName );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "b159bd8b-3416-44a5-91bf-c0447ed6b465")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeletePrinterDriver([Optional] string pName, [Optional] string pEnvironment, string pDriverName);
///
/// The DeletePrinterDriverEx function removes the specified printer-driver name from the list of names of supported drivers
/// on a server and deletes the files associated with the driver. This function can also delete specific versions of the driver.
///
///
/// A pointer to a null-terminated string that specifies the name of the server from which the driver is to be deleted. If this
/// parameter is NULL, the function deletes the printer-driver from the local computer.
///
///
/// A pointer to a null-terminated string that specifies the environment from which the driver is to be deleted (for example,
/// Windows NT x86, Windows IA64, or Windows x64). If this parameter is NULL, the driver name is deleted from the current
/// environment of the calling application and client computer (not of the destination application and print server).
///
/// A pointer to a null-terminated string specifying the name of the driver to delete.
///
/// The options for deleting files and versions of the driver. This parameter can be one or more of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// DPD_DELETE_SPECIFIC_VERSION
///
/// Deletes the version specified in dwVersionFlag. This does not ensure that the driver will be removed from the list of supported
/// drivers for the server.
///
///
/// -
/// DPD_DELETE_UNUSED_FILES
/// Removes any unused driver files.
///
/// -
/// DPD_DELETE_ALL_FILES
///
/// Deletes the driver only if all its associated files can be removed. The delete operation fails if any of the driver's files are
/// being used by some other installed driver.
///
///
///
///
/// If DPD_DELETE_SPECIFIC_VERSION is not specified, the function deletes all versions of the driver if none of them is in use. If
/// neither DPD_DELETE_UNUSED_FILES nor DPD_DELETE_ALL_FILES is specified, the function does not delete driver files.
///
///
///
/// The version of the driver to be deleted. This parameter can be 0, 1, 2 or 3. This parameter is used only if dwDeleteFlag
/// includes the DPD_DELETE_SPECIFIC_VERSION flag.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
///
/// Before the function deletes the driver files, it calls the driver's DrvDriverEvent function, allowing the driver to
/// remove any private files that are not used. For more information about DrvDriverEvent, see the Microsoft Windows Driver
/// Development Kit (DDK).
///
/// If the driver files are currently loaded, the function moves them to a temp directory and marks them for deletion on restart.
/// Before calling DeletePrinterDriverEx, you must delete all printer objects that use the printer driver.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/deleteprinterdriverex BOOL DeletePrinterDriverEx( _In_ LPTSTR pName,
// _In_ LPTSTR pEnvironment, _In_ LPTSTR pDriverName, _In_ DWORD dwDeleteFlag, _In_ DWORD dwVersionFlag );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "1a3d7c7f-1d45-4877-a8f7-a77f40e3c319")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeletePrinterDriverEx([Optional] string pName, [Optional] string pEnvironment, string pDriverName, DPD dwDeleteFlag, uint dwVersionFlag);
/// Deletes a printer driver package from the driver store.
///
/// A pointer to a constant, null-terminated string that specifies the name of the print server from which the driver package is
/// being deleted. A NULL pointer value means the local computer.
///
/// A pointer to a constant, null-terminated string that specifies the path to the driver's *.inf file.
///
/// A pointer to a constant, null-terminated string that specifies the processor architecture (for example, Windows NT x86). This
/// can be NULL.
///
///
/// S_OK, if the operation succeeds.
/// E_ACCESSDENIED, if the package was shipped with Windows.
/// HRESULT_CODE(ERROR_PRINT_DRIVER_PACKAGE_IN_USE), if the package is being used.
/// Otherwise the HRESULT will contain an error code.
/// For more information about COM error codes, see Error Handling.
///
///
/// The driver store is typically %windir%\inf or %windir%\System32\DriverStore\FileRepository.
/// A driver package that shipped with Windows cannot be removed with this function.
/// The user must have printer administration privileges.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/deleteprinterdriverpackage HRESULT DeletePrinterDriverPackage( _In_
// LPCTSTR pszServer, _In_ LPCTSTR pszInfPath, _In_ LPCTSTR pszEnvironment );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "a43a94d1-097e-457c-bce9-d4c434ecfa93")]
public static extern HRESULT DeletePrinterDriverPackage([Optional] string pszServer, string pszInfPath, [Optional] string pszEnvironment);
/// The DeletePrintProcessor function removes a print processor added by the AddPrintProcessor function.
///
/// A pointer to a null-terminated string that specifies the name of the server from which the processor is to be removed. If this
/// parameter is NULL, the printer processor is removed locally.
///
///
/// A pointer to a null-terminated string that specifies the environment from which the processor is to be removed (for example,
/// Windows NT x86, Windows IA64, or Windows x64). If this parameter is NULL, the processor is removed from the current
/// environment of the calling application and client machine (not of the destination application and print server). NULL is
/// the recommended value, as it provides maximum portability.
///
/// A pointer to a null-terminated string that specifies the name of the processor to be removed.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
/// The caller must have the SeLoadDriverPrivilege.
// https://docs.microsoft.com/en-us/windows/win32/printdocs/deleteprintprocessor BOOL DeletePrintProcessor( _In_ LPTSTR pName, _In_
// LPTSTR pEnvironment, _In_ LPTSTR pPrintProcessorName );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "65c77874-aa2c-4b4c-b218-fad361270a3e")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeletePrintProcessor([Optional] string pName, [Optional] string pEnvironment, string pPrintProcessorName);
/// The DeletePrintProvidor function removes a print provider added by the AddPrintProvidor function.
/// Reserved; must be NULL.
///
/// A pointer to a null-terminated string that specifies the environment from which the provider is to be removed (for example,
/// Windows NT x86, Windows IA64, or Windows x64). If this parameter is NULL, the provider is removed from the current
/// environment of the calling application and client machine (not of the destination application and print server). NULL is
/// the recommended value because it provides maximum portability.
///
/// A pointer to a null-terminated string that specifies the name of the provider to be removed.
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/deleteprintprovidor BOOL DeletePrintProvidor( _In_ LPTSTR pName, _In_
// LPTSTR pEnvironment, _In_ LPTSTR pPrintProviderName );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "b7104f9a-111c-4904-a355-063bb4cc81f1")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeletePrintProvidor([Optional] string pName, [Optional] string pEnvironment, string pPrintProviderName);
/// The EnumMonitors function retrieves information about the port monitors installed on the specified server.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the monitors reside. If this parameter is
/// NULL, the local monitors are enumerated.
///
///
/// The version of the structure pointed to by pMonitors.
/// This value can be 1 or 2.
///
///
///
/// A pointer to a buffer that receives an array of structures. The buffer must be large enough to store the strings referenced by
/// the structure members.
///
///
/// To determine the required buffer size, call EnumMonitors with cbBuf set to zero. EnumMonitors fails,
/// GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter returns the size, in bytes, of the buffer
/// required to hold the array of structures and their data.
///
///
/// The buffer receives an array of MONITOR_INFO_1 structures if Level is 1, or MONITOR_INFO_2 structures if Level is 2.
///
///
/// The size, in bytes, of the buffer pointed to by pMonitors.
///
/// A pointer to a variable that receives the number of bytes copied if the function succeeds or the number of bytes required if
/// cbBuf is too small.
///
///
/// A pointer to a variable that receives the number of structures that were returned in the buffer pointed to by pMonitors.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/enummonitors BOOL EnumMonitors( _In_ LPTSTR pName, _In_ DWORD Level,
// _Out_ LPBYTE pMonitors, _In_ DWORD cbBuf, _Out_ LPDWORD pcbNeeded, _Out_ LPDWORD pcReturned );
[DllImport(Lib.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "4d4fbed2-193f-426c-8463-eeb6b1eaf316")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumMonitors([Optional] string pName, uint Level, IntPtr pMonitors, uint cbBuf, out uint pcbNeeded, out uint pcReturned);
/// The EnumMonitors function retrieves information about the port monitors installed on the specified server.
/// The type of form information to enumerate. This must be either MONITOR_INFO_1 or MONITOR_INFO_2.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the monitors reside. If this parameter is
/// NULL, the local monitors are enumerated.
///
/// A sequence of MONITOR_INFO_1 structures or MONITOR_INFO_2 structures.
///
[PInvokeData("winspool.h", MSDNShortId = "4d4fbed2-193f-426c-8463-eeb6b1eaf316")]
public static IEnumerable EnumMonitors([Optional] string pName) where T : struct
{
if (!TryGetLevel("MONITOR_INFO_", out var lvl))
throw new ArgumentException($"{nameof(EnumMonitors)} cannot process a structure of type {typeof(T).Name}.");
if (!EnumMonitors(pName, lvl, default, 0, out var bytes, out var count))
Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER);
if (bytes == 0)
return new T[0];
using var mem = new SafeCoTaskMemHandle(bytes);
if (!EnumMonitors(pName, lvl, mem, mem.Size, out bytes, out count))
Win32Error.ThrowLastError();
return mem.ToArray((int)count);
}
/// The EnumPorts function enumerates the ports that are available for printing on a specified server.
///
/// A pointer to a null-terminated string that specifies the name of the server whose printer ports you want to enumerate.
/// If pName is NULL, the function enumerates the local machine's printer ports.
///
///
/// The type of information returned in the pPorts buffer. If Level is 1, pPorts receives an array of PORT_INFO_1 structures.
/// If Level is 2, pPorts receives an array of PORT_INFO_2 structures.
///
///
///
/// A pointer to a buffer that receives an array of PORT_INFO_1 or PORT_INFO_2 structures. Each structure contains
/// data that describes an available printer port. The buffer must be large enough to store the strings pointed to by the structure members.
///
///
/// To determine the required buffer size, call EnumPorts with cbBuf set to zero. EnumPorts fails, GetLastError
/// returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter returns the size, in bytes, of the buffer required to hold the
/// array of structures and their data.
///
///
/// The size, in bytes, of the buffer pointed to by pPorts.
///
/// A pointer to a variable that receives the number of bytes copied to the pPorts buffer. If the buffer is too small, the function
/// fails and the variable receives the number of bytes required.
///
///
/// A pointer to a variable that receives the number of PORT_INFO_1 or PORT_INFO_2 structures returned in the pPorts
/// buffer. This is the number of printer ports that are available on the specified server.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
/// The EnumPorts function can succeed even if the server specified by pName does not have a printer defined.
// https://docs.microsoft.com/en-us/windows/win32/printdocs/enumports BOOL EnumPorts( _In_ LPTSTR pName, _In_ DWORD Level, _Out_
// LPBYTE pPorts, _In_ DWORD cbBuf, _Out_ LPDWORD pcbNeeded, _Out_ LPDWORD pcReturned );
[DllImport(Lib.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "72ea0e35-bf26-4c12-9451-8f6941990d82")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumPorts([Optional] string pName, uint Level, IntPtr pPorts, uint cbBuf, out uint pcbNeeded, out uint pcReturned);
/// The EnumPorts function enumerates the ports that are available for printing on a specified server.
/// The type of form information to enumerate. This must be either PORT_INFO_1 or PORT_INFO_2.
///
/// A pointer to a null-terminated string that specifies the name of the server whose printer ports you want to enumerate.
/// If pName is NULL, the function enumerates the local machine's printer ports.
///
/// A sequence of PORT_INFO_1 structures or PORT_INFO_2 structures.
/// The EnumPorts function can succeed even if the server specified by pName does not have a printer defined.
[PInvokeData("winspool.h", MSDNShortId = "72ea0e35-bf26-4c12-9451-8f6941990d82")]
public static IEnumerable EnumPorts([Optional] string pName) where T : struct
{
if (!TryGetLevel("PORT_INFO_", out var lvl))
throw new ArgumentException($"{nameof(EnumPorts)} cannot process a structure of type {typeof(T).Name}.");
if (!EnumPorts(pName, lvl, default, 0, out var bytes, out var count))
Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER);
if (bytes == 0)
return new T[0];
using var mem = new SafeCoTaskMemHandle(bytes);
if (!EnumPorts(pName, lvl, mem, mem.Size, out bytes, out count))
Win32Error.ThrowLastError();
return mem.ToArray((int)count);
}
/// The EnumPrinterDrivers function enumerates the printer drivers installed on a specified printer server.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the printer drivers are enumerated.
/// If pName is NULL, the function enumerates the local printer drivers.
///
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, Windows x64, or
/// Windows NT R4000). If this parameter is NULL, the function uses the current environment of the caller/client (not of the destination/server).
///
///
/// If the pEnvironment string specifies "all", EnumPrinterDrivers enumerates printer drivers for all platforms installed on
/// the specified server.
///
///
///
/// The type of information structure returned in the pDriverInfo buffer. It can be one of the following.
///
///
/// Value
/// Meaning
///
/// -
/// 1
/// DRIVER_INFO_1
///
/// -
/// 2
/// DRIVER_INFO_2
///
/// -
/// 3
/// DRIVER_INFO_3
///
/// -
/// 4
/// DRIVER_INFO_4
///
/// -
/// 5
/// DRIVER_INFO_5
///
/// -
/// 6
/// DRIVER_INFO_6
///
/// -
/// 8
/// DRIVER_INFO_8
///
///
///
///
///
/// A pointer to a buffer that receives an array of DRIVER_INFO_* structures, as specified by Level. Each structure contains data
/// that describes an available printer driver. The buffer must be large enough to receive the array of structures and any strings
/// or other data to which the structure members point.
///
///
/// To determine the required buffer size, call EnumPrinterDrivers with cbBuf set to zero. EnumPrinterDrivers fails,
/// GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter returns the size, in bytes, of the buffer
/// required to hold the array of structures and their data.
///
///
/// The size, in bytes, of the buffer pointed to by pDriverInfo
///
/// A pointer to a variable that receives the number of bytes copied to the pDriverInfo buffer if the function succeeds. If the
/// buffer is too small, the function fails and the variable receives the number of bytes required.
///
///
/// A pointer to a variable that receives the number of structures returned in the pDriverInfo buffer. This is the number of printer
/// drivers installed on the specified print server.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/enumprinterdrivers BOOL EnumPrinterDrivers( _In_ LPTSTR pName, _In_
// LPTSTR pEnvironment, _In_ DWORD Level, _Out_ LPBYTE pDriverInfo, _In_ DWORD cbBuf, _Out_ LPDWORD pcbNeeded, _Out_ LPDWORD
// pcReturned );
[DllImport(Lib.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "fa3d8cf4-70bc-4362-833e-e4217ed5d43b")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumPrinterDrivers([Optional] string pName, [Optional] string pEnvironment, uint Level, IntPtr pDriverInfo, uint cbBuf, out uint pcbNeeded, out uint pcReturned);
/// The EnumPrinterDrivers function enumerates the printer drivers installed on a specified printer server.
///
/// The type of form information to enumerate. This must be either DRIVER_INFO_1, DRIVER_INFO_2, DRIVER_INFO_3,
/// DRIVER_INFO_4, DRIVER_INFO_5, DRIVER_INFO_6, or DRIVER_INFO_8.
///
///
/// A pointer to a null-terminated string that specifies the name of the server on which the printer drivers are enumerated.
/// If pName is NULL, the function enumerates the local printer drivers.
///
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, Windows x64, or
/// Windows NT R4000). If this parameter is NULL, the function uses the current environment of the caller/client (not of the destination/server).
///
///
/// If the pEnvironment string specifies "all", EnumPrinterDrivers enumerates printer drivers for all platforms installed on
/// the specified server.
///
///
///
/// A sequence of DRIVER_INFO_1, DRIVER_INFO_2, DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5,
/// DRIVER_INFO_6, or DRIVER_INFO_8 structures.
///
[PInvokeData("winspool.h", MSDNShortId = "fa3d8cf4-70bc-4362-833e-e4217ed5d43b")]
public static IEnumerable EnumPrinterDrivers([Optional] string pName, [Optional] string pEnvironment) where T : struct
{
if (!TryGetLevel("DRIVER_INFO_", out var lvl))
throw new ArgumentException($"{nameof(EnumPrinterDrivers)} cannot process a structure of type {typeof(T).Name}.");
if (!EnumPrinterDrivers(pName, pEnvironment, lvl, default, 0, out var bytes, out var count))
Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER);
if (bytes == 0)
return new T[0];
using var mem = new SafeCoTaskMemHandle(bytes);
if (!EnumPrinterDrivers(pName, pEnvironment, lvl, mem, mem.Size, out bytes, out count))
Win32Error.ThrowLastError();
return mem.ToArray((int)count);
}
/// The EnumPrintProcessorDatatypes function enumerates the data types that a specified print processor supports.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the print processor resides. If this
/// parameter is NULL, the data types for the local print processor are enumerated.
///
///
/// A pointer to a null-terminated string that specifies the name of the print processor whose data types are enumerated.
///
/// The type of information returned in the pDatatypes buffer. This parameter must be 1.
///
///
/// A pointer to a buffer that receives an array of DATATYPES_INFO_1 structures. Each structure describes an available data
/// type. The buffer must be large enough to receive the array of structures and any strings or other data to which the structure
/// members point.
///
///
/// To determine the required buffer size, call EnumPrintProcessorDatatypes with cbBuf set to zero.
/// EnumPrintProcessorDatatypes fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter
/// returns the size, in bytes, of the buffer required to hold the array of structures and their data.
///
///
/// The size, in bytes, of the buffer pointed to by pDatatypes.
///
/// A pointer to a variable that receives the number of bytes copied to the pDatatypes buffer if the function succeeds. If the
/// buffer is too small, the function fails and the variable receives the number of bytes required.
///
///
/// A pointer to a variable that receives the number of structures returned in the pDatatypes buffer. This is the number of
/// supported data types.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
/// v
/// Starting with Windows Vista, the data type information from remote print servers is retrieved from a local cache.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/enumprintprocessordatatypes BOOL EnumPrintProcessorDatatypes( _In_
// LPTSTR pName, _In_ LPTSTR pPrintProcessorName, _In_ DWORD Level, _Out_ LPBYTE pDatatypes, _In_ DWORD cbBuf, _Out_ LPDWORD
// pcbNeeded, _Out_ LPDWORD pcReturned );
[DllImport(Lib.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "27b6e074-d303-446b-9e5f-6cfa55c30d26")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumPrintProcessorDatatypes([Optional] string pName, string pPrintProcessorName, uint Level, IntPtr pDatatypes, uint cbBuf, out uint pcbNeeded, out uint pcReturned);
/// The EnumPrintProcessorDatatypes function enumerates the data types that a specified print processor supports.
/// The type of form information to enumerate. This must be DATATYPES_INFO_1.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the print processor resides. If this
/// parameter is NULL, the data types for the local print processor are enumerated.
///
///
/// A pointer to a null-terminated string that specifies the name of the print processor whose data types are enumerated.
///
/// A sequence of DATATYPES_INFO_1 structures.
/// Starting with Windows Vista, the data type information from remote print servers is retrieved from a local cache.
[PInvokeData("winspool.h", MSDNShortId = "27b6e074-d303-446b-9e5f-6cfa55c30d26")]
public static IEnumerable EnumPrintProcessorDatatypes([Optional] string pName, string pPrintProcessorName) where T : struct
{
if (!TryGetLevel("DATATYPES_INFO_", out var lvl))
throw new ArgumentException($"{nameof(EnumPrintProcessorDatatypes)} cannot process a structure of type {typeof(T).Name}.");
if (!EnumPrintProcessorDatatypes(pName, pPrintProcessorName, lvl, default, 0, out var bytes, out var count))
Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER);
if (bytes == 0)
return new T[0];
using var mem = new SafeCoTaskMemHandle(bytes);
if (!EnumPrintProcessorDatatypes(pName, pPrintProcessorName, lvl, mem, mem.Size, out bytes, out count))
Win32Error.ThrowLastError();
return mem.ToArray((int)count);
}
/// The EnumPrintProcessors function enumerates the print processors installed on the specified server.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the print processors reside. If this
/// parameter is NULL, the local print processors are enumerated.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
/// The type of information returned in the pPrintProcessorInfo buffer. This parameter must be 1.
///
///
/// A pointer to a buffer that receives an array of PRINTPROCESSOR_INFO_1 structures. Each structure describes an available
/// print processor. The buffer must be large enough to receive the array of structures and any strings to which the structure
/// members point.
///
///
/// To determine the required buffer size, call EnumPrintProcessors with cbBuf set to zero. EnumPrintProcessors fails,
/// GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter returns the size, in bytes, of the buffer
/// required to hold the array of structures and their data.
///
///
/// The size, in bytes, of the buffer pointed to by pPrintProcessorInfo.
///
/// A pointer to a variable that receives the number of bytes copied to the pPrintProcessorInfo buffer if the function succeeds. If
/// the buffer is too small, the function fails and the variable receives the number of bytes required.
///
///
/// A pointer to a variable that receives the number of structures returned in the pPrintProcessorInfo buffer.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/enumprintprocessors BOOL EnumPrintProcessors( _In_ LPTSTR pName, _In_
// LPTSTR pEnvironment, _In_ DWORD Level, _Out_ LPBYTE pPrintProcessorInfo, _In_ DWORD cbBuf, _Out_ LPDWORD pcbNeeded, _Out_ LPDWORD
// pcReturned );
[DllImport(Lib.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "98c9185c-c89d-4b4e-8c1e-7e22b315f188")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumPrintProcessors([Optional] string pName, [Optional] string pEnvironment, uint Level, IntPtr pPrintProcessorInfo, uint cbBuf, out uint pcbNeeded, out uint pcReturned);
/// The EnumPrintProcessors function enumerates the print processors installed on the specified server.
/// The type of form information to enumerate. This must be PRINTPROCESSOR_INFO_1.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the print processors reside. If this
/// parameter is NULL, the local print processors are enumerated.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
/// A sequence of PRINTPROCESSOR_INFO_1 structures.
[PInvokeData("winspool.h", MSDNShortId = "98c9185c-c89d-4b4e-8c1e-7e22b315f188")]
public static IEnumerable EnumPrintProcessors([Optional] string pName, [Optional] string pEnvironment) where T : struct
{
if (!TryGetLevel("PRINTPROCESSOR_INFO_", out var lvl))
throw new ArgumentException($"{nameof(EnumPrintProcessors)} cannot process a structure of type {typeof(T).Name}.");
if (!EnumPrintProcessors(pName, pEnvironment, lvl, default, 0, out var bytes, out var count))
Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER);
if (bytes == 0)
return new T[0];
using var mem = new SafeCoTaskMemHandle(bytes);
if (!EnumPrintProcessors(pName, pEnvironment, lvl, mem, mem.Size, out bytes, out count))
Win32Error.ThrowLastError();
return mem.ToArray((int)count);
}
/// Retrieves GUID, version, and date of the specified core printer drivers and the path to their packages.
///
/// A pointer to a constant, null-terminated string that specifies the name of the print server. Use NULL for the local computer.
///
///
/// A pointer to a constant, null-terminated string that specifies the processor architecture (for example, Windows NT x86). This
/// can be NULL.
///
/// A list of strings with the GUIDs of the core printer drivers.
/// The number of strings in pszzCoreDriverDependencies.
/// A pointer to an array of one or more CORE_PRINTER_DRIVER structures.
///
/// If the operation succeeds, the return value is S_OK, otherwise the HRESULT will contain an error code.
/// For more information about COM error codes, see Error Handling.
///
///
/// This is a blocking or synchronous function and might not return immediately. How quickly this function returns depends on
/// run-time factors such as network status, print server configuration, and printer driver implementation factors that are
/// difficult to predict when writing an application. Calling this function from a thread that manages interaction with the user
/// interface could make the application appear to be unresponsive.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/getcoreprinterdrivers HRESULT GetCorePrinterDrivers( _In_ LPCTSTR
// pszServer, _In_ LPCTSTR pszEnvironment, _In_ LPCTSTR pszzCoreDriverDependencies, _In_ DWORD cCorePrinterDrivers, _Out_
// PCORE_PRINTER_DRIVER pCorePrinterDrivers );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "98acad48-cd42-4d2b-be58-81c1366f6912")]
public static extern HRESULT GetCorePrinterDrivers([Optional] string pszServer, [Optional] string pszEnvironment,
[In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(NullTermStringArrayMarshaler), MarshalCookie = "Auto")] string[] pszzCoreDriverDependencies,
uint cCorePrinterDrivers, [Out] CORE_PRINTER_DRIVER[] pCorePrinterDrivers);
///
/// The GetPrinterDriver function retrieves driver data for the specified printer. If the driver is not installed on the
/// local computer, GetPrinterDriver installs it.
///
///
/// A handle to the printer for which the driver data should be retrieved. Use the OpenPrinter or AddPrinter function
/// to retrieve a printer handle.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
///
/// The printer driver structure returned in the pDriverInfo buffer. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// 1
/// DRIVER_INFO_1
///
/// -
/// 2
/// DRIVER_INFO_2
///
/// -
/// 3
/// DRIVER_INFO_3
///
/// -
/// 4
/// DRIVER_INFO_4
///
/// -
/// 5
/// DRIVER_INFO_5
///
/// -
/// 6
/// DRIVER_INFO_6
///
/// -
/// 8
/// DRIVER_INFO_8
///
///
///
///
///
/// A pointer to a buffer that receives a structure containing information about the driver, as specified by Level. The buffer must
/// be large enough to store the strings pointed to by the structure members.
///
///
/// To determine the required buffer size, call GetPrinterDriver with cbBuf set to zero. GetPrinterDriver fails,
/// GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter returns the size, in bytes, of the buffer
/// required to hold the array of structures and their data.
///
///
/// The size, in bytes, of the array at which pDriverInfo points.
///
/// A pointer to a value that receives the number of bytes copied if the function succeeds or the number of bytes required if cbBuf
/// is too small.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
/// For a non-existent driver, the function returns ERROR_UNKNOWN_PRINTER_DRIVER.
///
///
/// The DRIVER_INFO_2, DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5, and DRIVER_INFO_6 structures
/// contain the file name or the full path and file name of the printer driver in the pDriverPath member. An application can
/// use the path and file name to load a printer driver by calling the LoadLibrary function and supplying the path and file
/// name as the single argument.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/getprinterdriver BOOL GetPrinterDriver( _In_ HANDLE hPrinter, _In_
// LPTSTR pEnvironment, _In_ DWORD Level, _Out_ LPBYTE pDriverInfo, _In_ DWORD cbBuf, _Out_ LPDWORD pcbNeeded );
[DllImport(Lib.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "93f859b4-1005-4359-8029-9536d6eeb7e7")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPrinterDriver(HPRINTER hPrinter, [Optional] string pEnvironment, uint Level, IntPtr pDriverInfo, uint cbBuf, out uint pcbNeeded);
///
/// The GetPrinterDriver function retrieves driver data for the specified printer. If the driver is not installed on the
/// local computer, GetPrinterDriver installs it.
///
///
/// The type of driver information to enumerate. This must be either DRIVER_INFO_1, DRIVER_INFO_2,
/// DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5, DRIVER_INFO_6, or DRIVER_INFO_8.
///
///
/// A handle to the printer for which the driver data should be retrieved. Use the OpenPrinter or AddPrinter function
/// to retrieve a printer handle.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
/// A structure containing information about the driver, as specified by .
///
/// The DRIVER_INFO_2, DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5, and DRIVER_INFO_6 structures
/// contain the file name or the full path and file name of the printer driver in the pDriverPath member. An application can
/// use the path and file name to load a printer driver by calling the LoadLibrary function and supplying the path and file
/// name as the single argument.
///
[PInvokeData("winspool.h", MSDNShortId = "93f859b4-1005-4359-8029-9536d6eeb7e7")]
public static T GetPrinterDriver(HPRINTER hPrinter, [Optional] string pEnvironment) where T : struct
{
if (!TryGetLevel("DRIVER_INFO_", out var lvl))
throw new ArgumentException($"{nameof(GetPrinterDriver)} cannot process a structure of type {typeof(T).Name}.");
if (!GetPrinterDriver(hPrinter, pEnvironment, lvl, default, 0, out var sz))
Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER);
using var mem = new SafeCoTaskMemHandle(sz);
if (!GetPrinterDriver(hPrinter, pEnvironment, lvl, mem, mem.Size, out sz))
Win32Error.ThrowLastError();
return mem.ToStructure();
}
///
/// The GetPrinterDriver2 function retrieves driver data for the specified printer. If the driver is not installed on the
/// local computer, GetPrinterDriver2 installs it and displays any user interface to the specified window.
///
///
/// A handle of the window that will be used as the parent window of any user interface, such as a dialog box, that the driver
/// displays during installation. If the value of this parameter is NULL, the driver's user interface will still be displayed
/// to the user during installation, but it will not have a parent window.
///
///
/// A handle to the printer for which the driver data should be retrieved. Use the OpenPrinter or AddPrinter function
/// to retrieve a printer handle.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
///
/// The printer driver structure returned in the pDriverInfo buffer. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// 1
/// DRIVER_INFO_1
///
/// -
/// 2
/// DRIVER_INFO_2
///
/// -
/// 3
/// DRIVER_INFO_3
///
/// -
/// 4
/// DRIVER_INFO_4
///
/// -
/// 5
/// DRIVER_INFO_5
///
/// -
/// 6
/// DRIVER_INFO_6
///
/// -
/// 8
/// DRIVER_INFO_8
///
///
///
///
///
/// A pointer to a buffer that receives a structure containing information about the driver, as specified by Level. The buffer must
/// be large enough to store the strings pointed to by the structure members.
///
///
/// To determine the required buffer size, call GetPrinterDriver2 with cbBuf set to zero. GetPrinterDriver2 fails,
/// GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the pcbNeeded parameter returns the size, in bytes, of the
/// buffer required to hold the array of structures and their data.
///
///
/// The size, in bytes, of the array at which pDriverInfo points.
///
/// A pointer to a value that receives the number of bytes copied if the function succeeds or the number of bytes required if cbBuf
/// is too small.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero. To get the return status, call GetLastError.
///
///
///
/// The DRIVER_INFO_2, DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5, DRIVER_INFO_6, and
/// DRIVER_INFO_8 structures contain the file name or the full path and file name of the printer driver in the
/// pDriverPath member. An application can use the path and file name to load a printer driver by calling the
/// LoadLibrary function and supplying the path and file name as the single argument.
///
/// The ANSI version of this function, GetPrinterDriver2A is not supported and returns ERROR_NOT_SUPPORTED.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/getprinterdriver2 BOOL GetPrinterDriver2( _In_opt_ HWND hWnd, _In_
// HANDLE hPrinter, _In_opt_ LPTSTR pEnvironment, _In_ DWORD Level, _Out_ LPBYTE pDriverInfo, _In_ DWORD cbBuf, _Out_ LPDWORD
// pcbNeeded );
[DllImport(Lib.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "0d482d28-7668-4734-ba71-5b355c18ddec")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPrinterDriver2([Optional] HWND hWnd, HPRINTER hPrinter, [Optional] string pEnvironment, uint Level, IntPtr pDriverInfo, uint cbBuf, out uint pcbNeeded);
///
/// The GetPrinterDriver2 function retrieves driver data for the specified printer. If the driver is not installed on the
/// local computer, GetPrinterDriver2 installs it and displays any user interface to the specified window.
///
///
/// The type of driver information to enumerate. This must be either DRIVER_INFO_1, DRIVER_INFO_2,
/// DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5, DRIVER_INFO_6, or DRIVER_INFO_8.
///
///
/// A handle to the printer for which the driver data should be retrieved. Use the OpenPrinter or AddPrinter function
/// to retrieve a printer handle.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
///
/// A handle of the window that will be used as the parent window of any user interface, such as a dialog box, that the driver
/// displays during installation. If the value of this parameter is NULL, the driver's user interface will still be displayed
/// to the user during installation, but it will not have a parent window.
///
/// A structure containing information about the driver, as specified by .
///
///
///
/// The DRIVER_INFO_2, DRIVER_INFO_3, DRIVER_INFO_4, DRIVER_INFO_5, DRIVER_INFO_6, and
/// DRIVER_INFO_8 structures contain the file name or the full path and file name of the printer driver in the
/// pDriverPath member. An application can use the path and file name to load a printer driver by calling the
/// LoadLibrary function and supplying the path and file name as the single argument.
///
/// The ANSI version of this function, GetPrinterDriver2A is not supported and returns ERROR_NOT_SUPPORTED.
///
[PInvokeData("winspool.h", MSDNShortId = "0d482d28-7668-4734-ba71-5b355c18ddec")]
public static T GetPrinterDriver2(HPRINTER hPrinter, [Optional] string pEnvironment, [Optional] HWND hWnd) where T : struct
{
if (!TryGetLevel("DRIVER_INFO_", out var lvl))
throw new ArgumentException($"{nameof(GetPrinterDriver2)} cannot process a structure of type {typeof(T).Name}.");
if (!GetPrinterDriver2(hWnd, hPrinter, pEnvironment, lvl, default, 0, out var sz))
Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER);
using var mem = new SafeCoTaskMemHandle(sz);
if (!GetPrinterDriver2(hWnd, hPrinter, pEnvironment, lvl, mem, mem.Size, out sz))
Win32Error.ThrowLastError();
return mem.ToStructure();
}
/// The GetPrinterDriverDirectory function retrieves the path of the printer-driver directory.
///
/// A pointer to a null-terminated string that specifies the name of the server on which the printer driver resides. If this
/// parameter is NULL, the local driver-directory path is retrieved.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
/// The structure level. This value must be 1.
/// A pointer to a buffer that receives the path.
/// The size of the buffer to which pDriverDirectory points.
///
/// A pointer to a value that specifies the number of bytes copied if the function succeeds, or the number of bytes required if
/// cbBuf is too small.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/getprinterdriverdirectory BOOL GetPrinterDriverDirectory( _In_ LPTSTR
// pName, _In_ LPTSTR pEnvironment, _In_ DWORD Level, _Out_ LPBYTE pDriverDirectory, _In_ DWORD cbBuf, _Out_ LPDWORD pcbNeeded );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "69c9cc87-d7e3-496a-b631-b3ae30cdb3fd")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPrinterDriverDirectory([Optional] string pName, [Optional] string pEnvironment, uint Level, StringBuilder pDriverDirectory, uint cbBuf, out uint pcbNeeded);
/// Retrieves the path to the specified printer driver package on a print server.
///
/// A pointer to a constant, null-terminated string that specifies the name of the print server. Use NULL for the local computer.
///
///
/// A pointer to a constant, null-terminated string that specifies the processor architecture (for example, Windows NT x86). This
/// can be NULL.
///
///
/// A pointer to a constant, null-terminated string that specifies the Multilingual User Interface language for the driver being
/// installed. This can be NULL.
///
/// A pointer to a constant, null-terminated string that specifies the ID of the driver package.
///
/// A pointer to a null-terminated string that specifies the path to the cabinet file for the driver package. This can be
/// NULL. See Remarks.
///
/// The size, in characters, of the pszDriverPackageCab buffer. This can be NULL.
/// A pointer to the required size of the pszDriverPackageCab buffer.
///
/// If the operation succeeds, the return value is S_OK, otherwise the HRESULT will contain an error code.
/// For more information about COM error codes, see Error Handling.
///
///
///
/// To obtain a value for cchDriverPackageCab, call the function with NULL as the value of pszDriverPackageCab. Use the value
/// returned in pcchRequiredSize as the value of cchDriverPackageCab and call the function again.
///
/// The pszPackageID is typically obtained from a call to GetCorePrinterDrivers.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/getprinterdriverpackagepath HRESULT GetPrinterDriverPackagePath( _In_
// LPCTSTR pszServer, _In_ LPCTSTR pszEnvironment, _In_ LPCTSTR pszLanguage, _In_ LPCTSTR pszPackageID, _Inout_ LPTSTR
// pszDriverPackageCab, _In_ DWORD cchDriverPackageCab, _Out_ LPDWORD pcchRequiredSize );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "e88e984b-d2c0-43b4-8f70-b05ec202ab14")]
public static extern HRESULT GetPrinterDriverPackagePath([Optional] string pszServer, [Optional] string pszEnvironment, [Optional] string pszLanguage, string pszPackageID, StringBuilder pszDriverPackageCab, uint cchDriverPackageCab, out uint pcchRequiredSize);
///
/// The GetPrintProcessorDirectory function retrieves the path to the print processor directory on the specified server.
///
///
/// A pointer to a null-terminated string that specifies the name of the server. If this parameter is NULL, a local path is returned.
///
///
/// A pointer to a null-terminated string that specifies the environment (for example, Windows x86, Windows IA64, or Windows x64).
/// If this parameter is NULL, the current environment of the calling application and client machine (not of the destination
/// application and print server) is used.
///
/// The structure level. This value must be 1.
///
/// A pointer to a buffer that receives the path. Note that, for operating systems prior to Windows Server 2003 SP 1, the path is in
/// the local format for the server, not the true remote format. For example, the path is given as
/// "%Windir%\System32\Spool\Prtprocs\%Environment%" instead of "\\ServerName\Print$\Prtprocs\%Environment%", even when called for a
/// remote server. For the operating systems Windows Server 2003 SP 1 and later, the true remote path is returned.
///
/// The size of the buffer pointed to by pPrintProcessorInfo.
///
/// A pointer to a value that specifies the number of bytes copied if the function succeeds, or the number of bytes required if
/// cbBuf is too small.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero.
///
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/getprintprocessordirectory BOOL GetPrintProcessorDirectory( _In_ LPTSTR
// pName, _In_ LPTSTR pEnvironment, _In_ DWORD Level, _Out_ LPBYTE pPrintProcessorInfo, _In_ DWORD cbBuf, _Out_ LPDWORD pcbNeeded );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "a2443cfd-e5ba-41c6-aaf4-45051a3d0e26")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPrintProcessorDirectory([Optional] string pName, [Optional] string pEnvironment, uint Level, StringBuilder pPrintProcessorInfo, uint cbBuf, out uint pcbNeeded);
/// Installs a printer driver from a driver package that is in the print server's driver store.
///
/// A pointer to a constant, null-terminated string that specifies the name of the print server. NULL means the local computer.
///
///
/// A pointer to a constant, null-terminated string that specifies the driver store path to the print driver's .inf file.
/// NULL means the driver is in an inf file that shipped with Windows.
///
/// A pointer to a constant, null-terminated string that specifies the name of the driver.
///
/// A pointer to a constant, null-terminated string that specifies the processor architecture (for example, Windows NT x86). This
/// can be NULL.
///
///
/// This can only be 0 or IPDFP_COPY_ALL_FILES. A value of 0 means that the printer driver must be added and any files in the
/// printer driver directory that are newer than corresponding files currently in use must be copied. A value of
/// IPDFP_COPY_ALL_FILES means the printer driver and all the files in the printer driver directory must be added. The file time
/// stamps are ignored when dwFlags has a value of IPDFP_COPY_ALL_FILES.
///
///
/// If the operation succeeds, the return value is S_OK, otherwise the HRESULT will contain an error code.
/// For more information about COM error codes, see Error Handling.
///
///
/// The driver store is typically either %windir%\inf or %windir%\System32\DriverStore\FileRepository.
/// InstallPrinterDriverFromPackage also installs other files in the package, such as color profiles and print processors.
///
/// Users must have printer administration rights to install either on a remote computer or on the local computer when the user is
/// logged in with Terminal Services.
///
/// Only signed packages can be installed on a remote computer.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/installprinterdriverfrompackage HRESULT InstallPrinterDriverFromPackage(
// _In_ LPCTSTR pszServer, _In_ LPCTSTR pszInfPath, _In_ LPCTSTR pszDriverName, _In_ LPCTSTR pszEnvironment, _In_ DWORD dwFlags );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "5906d9c6-9fbf-4ec6-81ce-112a9ef6d7c0")]
public static extern HRESULT InstallPrinterDriverFromPackage([Optional] string pszServer, [Optional] string pszInfPath, string pszDriverName, [Optional] string pszEnvironment, uint dwFlags);
/// Uploads a printer driver to the print server's driver store so that it can be installed by calling InstallPrinterDriverFromPackage.
///
/// A pointer to a constant, null-terminated string that specifies the name of the print server. Use NULL if the server is
/// the local computer.
///
///
/// A pointer to a constant ,null-terminated string that specifies the source path to the driver's .inf file.
///
///
/// A pointer to a constant, null-terminated string that specifies the server's processor architecture (for example, Windows NT
/// x86). This can be NULL.
///
///
/// This can be any of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// UPDP_SILENT_UPLOAD
/// The UI will not be shown during the upload.
///
/// -
/// UPDP_UPLOAD_ALWAYS
/// The files will be uploaded even if the package is already in the server's driver store.
///
/// -
/// UPDP_CHECK_DRIVERSTORE
///
/// The server's driver store will be checked before upload to see if the package is already there. This setting is ignored if
/// UPDP_UPLOAD_ALWAYS is set.
///
///
///
///
/// A handle to the copying user interface.
/// A pointer to the destination path, in the driver store, to which the driver's .inf file was copied.
///
/// On input, specifies the size, in characters, of the pszDestInfPath buffer. On output, receives the size, in characters, of the
/// path string, including the terminating null character.
///
///
/// If the operation succeeds, the return value is S_OK, otherwise the HRESULT will contain an error code.
/// For more information about COM error codes, see Error Handling.
///
///
/// The driver store is typically either %windir%\inf or %windir%\System32\DriverStore\FileRepository.
/// Only one package at a time can be uploaded. If a package is dependent on others, they must be uploaded separately.
/// Only signed driver packages can be uploaded.
///
// https://docs.microsoft.com/en-us/windows/win32/printdocs/uploadprinterdriverpackage HRESULT UploadPrinterDriverPackage( _In_
// LPCTSTR pszServer, _In_ LPCTSTR pszInfPath, _In_ LPCTSTR pszEnvironment, _In_ DWORD dwFlags, _In_ HWND hwnd, _Out_ LPTSTR
// pszDestInfPath, _Inout_ PULONG pcchDestInfPath );
[DllImport(Lib.Winspool, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winspool.h", MSDNShortId = "dd3b3a3b-8ded-44ae-85dd-e630bc62e898")]
public static extern HRESULT UploadPrinterDriverPackage([Optional] string pszServer, string pszInfPath, [Optional] string pszEnvironment, UPDP dwFlags, HWND hwnd, StringBuilder pszDestInfPath, ref uint pcchDestInfPath);
}
}