📄 driverloader.h
字号:
/*++
Module name:
DriverLoader.h
Author:
Tom
Mode:
User mode
Declarations:
headef file of class DriverLoader, This class implement loading as well as unloading
driver dynamatically.
This class only support
--*/
#ifndef _DRIVER_LOADER_H_
#define _DRIVER_LOADER_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "winsvc.h"
#include "stdio.h"
#include "tchar.h"
#define CheckRight() if( !m_bInitializeOk || OsType==INVALIDOS ) \
return FALSE;
//
// For error control
//
#ifdef _DEBUG
#define ERROR_DUMP( FuncName, ErrorString ) { dwErrorCode = GetLastError(); \
_stprintf( ErrorBuf, _T("%s : %d\n%s\n%s"), __FILE__,__LINE__,FuncName, ErrorString );}
#else
#define ERROR_DUMP
#endif //_DEBUG
typedef enum _OSTYPE
{
INVALIDOS,
WIN32s, //Unsupported
WIN95=1, //if OSTYPE=0,then all access denied
WIN98,
WINNTW, //NT workstations
WINNTS, //NT Server
WIN2KP, //win2000 professional
WIN2KS, //win2000 server
WINXP
}OSTYPE;
typedef enum _DRIVER_STATE
{
STOPPED = 1,
PAUSED = 2, //started but paused
STARTED = 2, //started but not running
RUNNING = 4
}DRIVER_STATE;
class DriverLoader
{
protected:
//
// Driver device information,Driver management
//
TCHAR * DriverLinkName; //The symbolic link of your offered Driver
TCHAR * DriverFileName; //assumption as DriverLinkName.sys
HANDLE DrvHandle; // The handle to the device driver
DRIVER_STATE m_nDriverState;
TCHAR driverPath[ MAX_PATH ]; //target executive path of driver(\system32\drivers)
TCHAR CurDir[ MAX_PATH ]; //current directory(work directory)
//
// Operating system information
//
static DWORD OsVersion;
static OSTYPE OsType;
static TCHAR systemRoot[ MAX_PATH ]; //"\winnt\system32\" as NT
//
// Result of any operation,Error control . For debug only
//
#ifdef _DEBUG
static DWORD dwErrorCode; //get by GetLastError()
static TCHAR ErrorBuf[1024]; //buffer for loading error string
#endif //_DEBUG
//
// Program/ instance management,all interfaces are valid only when
// the variable was set.
//
BOOL m_bInitializeOk;
private:
/*
The user can not use this class to create instance,if he / she wants
to use this class to drive driver,he/she must creaet a class delivered
from this class .
*/
DriverLoader(); //Default constructor
DriverLoader( const DriverLoader & );//You are not recommended to use this two constructors
protected:
DriverLoader(const TCHAR* ); //symbolink name as parameter
virtual ~DriverLoader();
//======================================================================
//Some others routine related with SCM operation
//======================================================================
//
// Remove the legacy driver in considering of the incompatibility
// It will be called by some public function
// at mostly ,it will be called by LoadDeviceDriver and Unload related
//
BOOL RemoveDriver( SC_HANDLE SchSCManager, LPCTSTR DriverLinkName );
//
// Install driver, add registry in fact.
//
BOOL InstallDriver( SC_HANDLE SchSCManager, LPCTSTR DriverLinkName, LPCTSTR DrvSysPath );
//
// Start my device dynamicly
//
BOOL StartDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverLinkName );
//
// stop your device dynamicly
//
BOOL StopDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverLinkName );
//
// OpenDevice,called by LoadDeviceDriver
//
BOOL OpenDevice( IN LPCTSTR DriverLinkName, HANDLE * hDevice );
//
// LoadDeviceDriver
// Thie most important routine,it will call other helper functions
//
BOOL LoadDeviceDriver( const TCHAR * Name, const TCHAR * Path, HANDLE * lphDevice );
BOOL UnloadDeviceDriver( const TCHAR * Name );
BOOL SetDriverInfo(void);
BOOL Initialize(void);
BOOL RunDriver();
public:
static BOOL QueryOsInfo(void);
//
// Error handling
//
DWORD GetErrorCode();
TCHAR * GetErrorString();
protected:
//-----------------------------------------------------------------------
// You are not recommended to call this function,but I just leave it here
// instead of deleting it for the update in the future
//-----------------------------------------------------------------------
DriverLoader& operator =(const DriverLoader &);
};
#endif // _DRIVER_LOADER_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -