PrinterInstall Class Reference

Base class for installing and removing printer drivers. More...

#include <PrinterInstall.h>

Inherited by CCPDFPrinterInstaller.

List of all members.

Public Member Functions

 PrinterInstall (LPCTSTR lpPrinterName, LPCTSTR lpPortName, LPCTSTR lpDriverName, LPCTSTR lpHardwareID, const LPCTSTR *pFiles)
 Constructor with installation data.
 PrinterInstall ()
 Default constructor.
int GetError () const
 Retrieves the last error number.
int GetLastError () const
 Retrieves the last error description.
void InitializePrinterData (LPCTSTR lpPrinterName, LPCTSTR lpPortName, LPCTSTR lpDriverName, LPCTSTR lpHardwareID, const LPCTSTR *pFiles)
 Initializes the printer driver data.
int Install (LPCTSTR lpFilesPath, HWND hParent)
 Install the printer driver.
int Uninstall (HWND hParent)
 Remove the printer driver.
bool DoCommandLine (int nArgs, TCHAR **pArgs, bool &bNoUI, LPCTSTR lpRelativeDriverFolder)
 Installs or removes the printer driver according to the command line parameters.
bool AddPortMonitor (LPCTSTR lpMonitorName, LPCTSTR lpMonitorFile, LPCTSTR lpFilePath)
 Add a port monitor.
bool RemovePortMonitor (LPCTSTR lpMonitorName)
 Remove a port monitor.
bool IsPrinterInstalled (bool &bInstalled)
 Tests if the printer is installed.

Protected Member Functions

bool DoAddPort ()
 Add a printer port to windows.
bool DoDeletePort (HWND hWnd)
 Remove a printer port from windows.
bool DoCopyFiles (LPCTSTR lpCopyFrom)
 Copy driver files from a folder to the windows printer drivers folder.
bool DoRemoveFiles ()
 Remove the printer driver files from the windows folder.
bool DoInstallPrinterDriver ()
 Install the printer driver.
bool DoUninstallPrinterDriver ()
 Remove the printer driver.
bool DoAddPrinter ()
 Add a printer.
bool DoRemovePrinter (LPTSTR lpName)
 Remove the printer.
bool DoRemovePrinters ()
 Remove all the printers for this driver.
void SetError (int nError)
 Set an error.
void ResetError ()
 Reset the error members.

Protected Attributes

std::tstring m_sPrinterName
 Printer name.
std::tstring m_sPortName
 Printer port name.
std::tstring m_sDriverName
 Printer driver name.
std::tstring m_sHardwareID
 Hardware ID (should be unique to the driver).
std::tstring m_sPortMonitor
 Port monitor name.
STRARRAY m_arFiles
 Array of files to install.
int m_nError
 Last error number.
int m_nLastError
 Last error description.
bool m_bLockError
 Flag to keep the previous error number and message.

Detailed Description

Base class for installing and removing printer drivers.

Definition at line 51 of file PrinterInstall.h.


Constructor & Destructor Documentation

PrinterInstall::PrinterInstall ( LPCTSTR  lpPrinterName,
LPCTSTR  lpPortName,
LPCTSTR  lpDriverName,
LPCTSTR  lpHardwareID,
const LPCTSTR *  pFiles 
)

Constructor with installation data.

Parameters:
lpPrinterName Name of printer to install
lpPortName Name of port to create
lpDriverName Name of printer driver
lpHardwareID Unique hardware ID for the printer
pFiles Pointer to array of files to install

Definition at line 160 of file PrinterInstall.cpp.

References m_arFiles.


Member Function Documentation

bool PrinterInstall::AddPortMonitor ( LPCTSTR  lpMonitorName,
LPCTSTR  lpMonitorFile,
LPCTSTR  lpFilePath 
)

Add a port monitor.

Parameters:
lpMonitorName Name of port monitor
lpMonitorFile Port monitor DLL filename
lpFilePath Path where the port monitor file currently resides
Returns:
true if installed successfully, false if failed

Definition at line 806 of file PrinterInstall.cpp.

References ConcatPaths(), ENVIRONMENT, ExistsAsFile(), GetLastError(), m_sPortMonitor, SetError(), and tstring.

Referenced by CCPDFPrinterInstaller::DoInstall().

bool PrinterInstall::DoAddPort (  )  [protected]

Add a printer port to windows.

Returns:
true if the port was added succesfully, false if failed

Definition at line 221 of file PrinterInstall.cpp.

References GetLastError(), m_sPortMonitor, m_sPortName, MakeWideString(), SetError(), and tstring.

Referenced by Install().

bool PrinterInstall::DoAddPrinter (  )  [protected]

Add a printer.

Returns:
true if the printer was added successfully, false if failed

Definition at line 480 of file PrinterInstall.cpp.

References GetLastError(), m_sDriverName, m_sPortName, m_sPrinterName, PRINTER_DATA_TYPE, and SetError().

Referenced by Install().

bool PrinterInstall::DoCommandLine ( int  nArgs,
TCHAR **  pArgs,
bool &  bNoUI,
LPCTSTR  lpRelativeDriverFolder 
)

Installs or removes the printer driver according to the command line parameters.

Parameters:
nArgs Number of command line arguments
pArgs Pointer to an array of command line arguments
bNoUI Reference to a silent command flag, filled upon exit
lpRelativeDriverFolder Folder name (relative to the current module) where the printer driver files can be found
Returns:
true if any command lines variables were detected and acted upon

Command line usage: To install the printer: <app.exe> [/NoUI] /InstallPrinter To uninstall the printer: <app.exe> [/NoUI] /UninstallPrinter Note that the object must be initialized for this to work!

Definition at line 750 of file PrinterInstall.cpp.

References Install(), PARAM_INSTALLPRINTER, PARAM_NOUI, PARAM_REMOVEPRINTER, ResetError(), SetError(), and Uninstall().

bool PrinterInstall::DoCopyFiles ( LPCTSTR  lpCopyFrom  )  [protected]

Copy driver files from a folder to the windows printer drivers folder.

Parameters:
lpCopyFrom Folder to copy the printer driver files from
Returns:
true if copied successfully, false if failed

Definition at line 281 of file PrinterInstall.cpp.

References ConcatPaths(), GetLastError(), m_arFiles, SetError(), and tstring.

Referenced by Install().

bool PrinterInstall::DoDeletePort ( HWND  hWnd  )  [protected]

Remove a printer port from windows.

Parameters:
hWnd Handle to the parent window
Returns:
true if the port was deleted successfully, false if failed

Definition at line 261 of file PrinterInstall.cpp.

References GetLastError(), m_sPortName, and MakeWideString().

Referenced by Install(), and Uninstall().

bool PrinterInstall::DoInstallPrinterDriver (  )  [protected]

Install the printer driver.

Returns:
true if the printer driver is installed successfully, false if failed

Definition at line 365 of file PrinterInstall.cpp.

References DATA_FILE_NUM, DRIVER_DATA_TYPE, DRIVER_FILE_NUM, DRIVER_MANUFACTURER, ENVIRONMENT, GetLastError(), HELP_FILE_NUM, m_arFiles, m_sDriverName, m_sHardwareID, SetError(), and UI_FILE_NUM.

Referenced by Install().

bool PrinterInstall::DoRemoveFiles (  )  [protected]

Remove the printer driver files from the windows folder.

Returns:
true if the printer driver files were removed successfully, false if failed

Definition at line 329 of file PrinterInstall.cpp.

References ConcatPaths(), GetLastError(), m_arFiles, SetError(), and tstring.

Referenced by Install().

bool PrinterInstall::DoRemovePrinter ( LPTSTR  lpName  )  [protected]

Remove the printer.

Parameters:
lpName Name of printer to delete
Returns:
true if the printer was deleted successfully, false if failed

Definition at line 515 of file PrinterInstall.cpp.

References GetLastError(), and SetError().

Referenced by DoRemovePrinters().

bool PrinterInstall::DoRemovePrinters (  )  [protected]

Remove all the printers for this driver.

Returns:
true if all the printers connected to this printer driver were removed, false if failed

Definition at line 594 of file PrinterInstall.cpp.

References DoRemovePrinter(), m_sDriverName, and SetError().

Referenced by Uninstall().

bool PrinterInstall::DoUninstallPrinterDriver (  )  [protected]

Remove the printer driver.

Returns:
true if the printer driver was uninstalled successfully, false if failed

Definition at line 457 of file PrinterInstall.cpp.

References ENVIRONMENT, GetLastError(), m_sDriverName, and SetError().

Referenced by Install(), and Uninstall().

int PrinterInstall::GetError (  )  const [inline]

Retrieves the last error number.

Returns:
The last error number

Definition at line 90 of file PrinterInstall.h.

References m_nError.

Referenced by CCPDFPrinterInstaller::DoInstall(), and CCPDFPrinterInstaller::DoRemove().

int PrinterInstall::GetLastError (  )  const [inline]
void PrinterInstall::InitializePrinterData ( LPCTSTR  lpPrinterName,
LPCTSTR  lpPortName,
LPCTSTR  lpDriverName,
LPCTSTR  lpHardwareID,
const LPCTSTR *  pFiles 
)

Initializes the printer driver data.

Parameters:
lpPrinterName Name of printer to install
lpPortName Name of port to create
lpDriverName Name of printer driver
lpHardwareID Unique hardware ID for the printer
pFiles Pointer to array of files to install

Definition at line 184 of file PrinterInstall.cpp.

References m_arFiles, m_sDriverName, m_sHardwareID, m_sPortName, and m_sPrinterName.

int PrinterInstall::Install ( LPCTSTR  lpFilesPath,
HWND  hParent 
)

Install the printer driver.

Parameters:
lpFilesPath Path of printer driver files
hParent Handle to parent window
Returns:
0 if succeeded, any other number for error

Definition at line 642 of file PrinterInstall.cpp.

References DoAddPort(), DoAddPrinter(), DoCopyFiles(), DoDeletePort(), DoInstallPrinterDriver(), DoRemoveFiles(), DoUninstallPrinterDriver(), m_nError, m_sPrinterName, ResetError(), and SetError().

Referenced by DoCommandLine(), and CCPDFPrinterInstaller::DoInstall().

bool PrinterInstall::IsPrinterInstalled ( bool &  bInstalled  ) 

Tests if the printer is installed.

Parameters:
bInstalled Reference to the installed flag, filled upon return
Returns:
true if tested successfully, false if failed to test

Definition at line 554 of file PrinterInstall.cpp.

References m_sDriverName, and SetError().

Referenced by CCPDFPrinterInstaller::IsPrinterInstalled().

bool PrinterInstall::RemovePortMonitor ( LPCTSTR  lpMonitorName  ) 

Remove a port monitor.

Parameters:
lpMonitorName Name of port monitor
Returns:
true if port monitor was deleted successfully, false if failed

Definition at line 896 of file PrinterInstall.cpp.

References ENVIRONMENT, GetLastError(), and SetError().

Referenced by CCPDFPrinterInstaller::DoInstall(), and CCPDFPrinterInstaller::DoRemove().

void PrinterInstall::SetError ( int  nError  )  [protected]
int PrinterInstall::Uninstall ( HWND  hParent  ) 

Remove the printer driver.

Parameters:
hParent Handle to the parent window
Returns:
0 if succeeded, any other number for error

Definition at line 697 of file PrinterInstall.cpp.

References DoDeletePort(), DoRemovePrinters(), DoUninstallPrinterDriver(), m_nError, m_sPrinterName, ResetError(), and SetError().

Referenced by DoCommandLine(), CCPDFPrinterInstaller::DoInstall(), and CCPDFPrinterInstaller::DoRemove().


The documentation for this class was generated from the following files:

Generated on Mon Jun 18 12:52:51 2012 for Excel to PDF Converter by doxygen 1.6.1