PCIStartup.cpp
资源名称:pciexp.zip [点击查看]
上传用户:zhuqijet
上传日期:2007-01-04
资源大小:138k
文件大小:25k
源码类别:
驱动编程
开发平台:
Visual C++
- // PCIStartup.cpp : implementation file
- //
- #include "stdafx.h"
- #include <winioctl.h>
- #include <winsvc.h> // cleverly excluded by Microsoft
- #include "PCI Explorer.h"
- #include "PCIStartup.h"
- #include "pci.h"
- #include "pciScanIoctl.h"
- #include "about.h"
- #include "GetDriveType.h"
- #include "PCI ExplorerDlg.h"
- #include "NumericEdit.h"
- #include "IDCombo.h"
- #include "DataDisplay.h"
- #include "pcidata.h"
- #include "RegVars.h"
- #include "index.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define PCISCAN _T("PCISCAN")
- static WORD UWM_RUN = ::RegisterWindowMessage(_T("UWM_RUN-{E7844BB0-105D-11d2-8379-00AA005C0507}"));
- /////////////////////////////////////////////////////////////////////////////
- // CPCIStartup dialog
- CPCIStartup::CPCIStartup(CWnd* pParent /*=NULL*/)
- : CDialog(CPCIStartup::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPCIStartup)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CPCIStartup::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPCIStartup)
- DDX_Control(pDX, IDC_DRIVER_CAPTION, c_c_Driver);
- DDX_Control(pDX, IDC_DRIVER, c_Driver);
- DDX_Control(pDX, IDC_CHANGE, c_Change);
- DDX_Control(pDX, IDC_BROWSE, c_Browse);
- DDX_Control(pDX, IDC_COMPLETED, c_Completed);
- DDX_Control(pDX, IDC_OPENING, c_Opening);
- DDX_Control(pDX, IDC_PROGRESS, c_Progress);
- DDX_Control(pDX, IDOK, c_OK);
- DDX_Control(pDX, IDC_UNINSTALLING, c_Uninstalling);
- DDX_Control(pDX, IDC_STOPPING, c_Stopping);
- DDX_Control(pDX, IDC_STATUS, c_Status);
- DDX_Control(pDX, IDC_STARTING, c_Starting);
- DDX_Control(pDX, IDC_SCM_OPEN, c_OpeningSCM);
- DDX_Control(pDX, IDC_SCANNING, c_Scanning);
- DDX_Control(pDX, IDC_INSTALLING, c_Installing);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPCIStartup, CDialog)
- //{{AFX_MSG_MAP(CPCIStartup)
- ON_WM_SYSCOMMAND()
- ON_REGISTERED_MESSAGE(UWM_RUN, OnRunPCI)
- ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
- ON_BN_CLICKED(IDC_CHANGE, OnChange)
- ON_EN_CHANGE(IDC_DRIVER, OnChangeDriver)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /****************************************************************************
- * CPCIStartup::InstallDriver
- * Inputs:
- * IN SC_HANDLE scm: Service Control Manager handle
- * IN LPCTSTR DriverName: Driver name
- * IN LPCTSTR executable: Place where it is found
- * Result: BOOL
- * TRUE if successful
- * FALSE if error
- * Effect:
- * Installs the driver
- ****************************************************************************/
- BOOL CPCIStartup::InstallDriver(SC_HANDLE scm, LPCTSTR DriverName, LPCTSTR ServiceExe)
- {
- SC_HANDLE Service;
- DWORD err;
- //
- // NOTE: This creates an entry for a standalone driver. If this
- // is modified for use with a driver that requires a Tag,
- // Group, and/or Dependencies, it may be necessary to
- // query the registry for existing driver information
- // (in order to determine a unique Tag, etc.).
- //
- Service = CreateService (scm, // SCManager database
- DriverName, // name of service
- DriverName, // name to display
- SERVICE_ALL_ACCESS, // desired access
- SERVICE_KERNEL_DRIVER, // service type
- SERVICE_DEMAND_START, // start type
- SERVICE_ERROR_NORMAL, // error control type
- ServiceExe, // full path to service's binary
- NULL, // no load ordering group
- NULL, // no tag identifier
- NULL, // no dependencies
- NULL, // LocalSystem account
- NULL // no password
- );
- if (Service == NULL)
- { /* failed */
- err = GetLastError();
- if (err == ERROR_SERVICE_EXISTS)
- { /* already installed */
- } /* already installed */
- else
- {
- printf ("failure: CreateService (0x%02x)n",
- err
- );
- }
- return FALSE;
- }
- else
- {
- printf ("CreateService SUCCESSn");
- }
- CloseServiceHandle (Service);
- return TRUE;
- }
- /****************************************************************************
- * CPCIStartup::RemoveDriver
- * Inputs:
- * SC_HANDLE scm: Service control manager handle
- * Result: BOOL
- * TRUE if successful
- * FALSE if failure
- * Effect:
- * Uninstalles the PCI driver
- ****************************************************************************/
- BOOL CPCIStartup::RemoveDriver(SC_HANDLE scm, LPCTSTR DriverName)
- {
- SC_HANDLE Service;
- BOOL ret;
- Service = OpenService (scm,
- DriverName,
- SERVICE_ALL_ACCESS
- );
- if (Service == NULL)
- {
- return FALSE;
- }
- ret = DeleteService (Service);
- if (!ret)
- { /* failed to remove it */
- } /* failed to remove it */
- CloseServiceHandle (Service);
- return ret;
- }
- /****************************************************************************
- * CPCIStartup::getErrorMessage
- * Inputs:
- * DWORD err: Error code to be displayed
- * Result: CString
- * Displayable string with superfluous rn removed
- * Effect:
- *