📄 tdriver.h
字号:
#if !defined(TDRIVER_CLASS)
#define TDRIVER_CLASS
#pragma once
#include "winsvc.h"
//ERROR CODES
#define DRV_SUCCESS (DWORD)0 //ALL OK
#define DRV_ERROR_SCM (DWORD)-1 //ERROR at Open de Service Manager
#define DRV_ERROR_SERVICE (DWORD)-2 //ERROR at create service
#define DRV_ERROR_MEMORY (DWORD)-3 //ERROR at reserving memory
#define DRV_ERROR_INVALID_PATH_OR_FILE (DWORD)-4 //ERROR, the path gived is not valid
#define DRV_ERROR_INVALID_HANDLE (DWORD)-5 //ERROR, driver handle is not valid
#define DRV_ERROR_STARTING (DWORD)-6 //ERROR at starting the driver
#define DRV_ERROR_STOPPING (DWORD)-7 //ERROR at stopping the driver
#define DRV_ERROR_REMOVING (DWORD)-8 //ERROR at removing the driver "service"
#define DRV_ERROR_IO (DWORD)-9 //ERROR at io operation
#define DRV_ERROR_NO_INITIALIZED (DWORD)-10 //ERROR, class not initialized
#define DRV_ERROR_ALREADY_INITIALIZED (DWORD)-11 //ERROR, class already initialized
#define DRV_ERROR_NULL_POINTER (DWORD)-12 //ERROR, pointer introduced is NULL
#define DRV_ERROR_UNKNOWN (DWORD)-13 //UNKNOWN ERROR
#include "winsvc.h"
#include <atlstr.h>
class CServiceControl {
//
// private data
//
private:
HANDLE driverHandle;
SC_HANDLE SchSCManager;
CString DriverName;
CString BinaryPath;
CString DosDevice;
DWORD lastError;
BOOL RemoveInDestructor;
DWORD attributes;
BOOL UnloadInDestructor;
BOOL ChangeIfExists;
//
// constructor/destructor
//
private:
CServiceControl& operator=(const CServiceControl& lhs);
CServiceControl(const CServiceControl& lhs);
public:
//
// input:
//
// Name -- the display name for the driver.
//
// flagsAndAttributes -- how the device will be opened.
//
// Path -- the fully qualified path of the driver executible.
// DEFAULT VALUE %SYSTEMROOT%\system32\drivers\"Name".sys,
//
// DosName -- the user space visible device name (dos device name) used to access devices
// supported by the driver.
// DEFAULT VALUE "Name". (i.e. \\.\Name)
//
CServiceControl();
~CServiceControl();
DWORD init(LPCTSTR Name,
DWORD flagsAndAttributes=FILE_ATTRIBUTE_NORMAL,
LPCTSTR Path=NULL,
LPCTSTR DosName=NULL);
DWORD getError() { return lastError; }
void ChangeConfig(BOOL val) { ChangeIfExists = val; }
//
// public methods
//
public:
void RemoveDriverOnExit(BOOL val);
HANDLE handle() { return driverHandle; }
void UnloadDriverOnExit(BOOL val) { UnloadInDestructor = val; }
//
// private methods
//
public:
void LoadDriver();
void UnloadDriver();
BOOL InstallDriver();
BOOL StartDriver();
BOOL OpenDevice();
BOOL StopDriver();
BOOL RemoveDriver();
SC_HANDLE closeSVC(SC_HANDLE scHandle)
{
CloseServiceHandle(scHandle);
return (SC_HANDLE) INVALID_HANDLE_VALUE;
}
void closeDevice()
{
CloseHandle(driverHandle); driverHandle = INVALID_HANDLE_VALUE;
}
//function to get driver handle
HANDLE GetDriverHandle(void);
public:
//funtions to make IO operation with driver
DWORD WriteIo(DWORD code, PVOID buffer, DWORD count);
DWORD ReadIo(DWORD code, PVOID buffer, DWORD count);
DWORD RawIo(DWORD code, PVOID inBuffer, DWORD inCount, PVOID outBuffer, DWORD outCount);
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -